source: rtems-libbsd/testsuite/media01/test_main.c @ 64c663c

55-freebsd-126-freebsd-12
Last change on this file since 64c663c was 64c663c, checked in by Sebastian Huber <sebastian.huber@…>, on 01/10/17 at 07:04:58

ARP(8): Port to RTEMS

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * Copyright (c) 2010-2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <assert.h>
33#include <stdio.h>
34#include <stdlib.h>
35
36#include <rtems/bdbuf.h>
37#include <rtems/console.h>
38#include <rtems/ftpd.h>
39#include <rtems/media.h>
40#include <rtems/shell.h>
41#include <rtems/telnetd.h>
42
43#define TEST_NAME "LIBBSD MEDIA 1"
44
45struct rtems_ftpd_configuration rtems_ftpd_configuration = {
46        /* FTPD task priority */
47        .priority = 100,
48
49        /* Maximum buffersize for hooks */
50        .max_hook_filesize = 0,
51
52        /* Well-known port */
53        .port = 21,
54
55        /* List of hooks */
56        .hooks = NULL,
57
58        /* Root for FTPD or NULL for "/" */
59        .root = NULL,
60
61        /* Max. connections */
62        .tasks_count = 4,
63
64        /* Idle timeout in seconds  or 0 for no (infinite) timeout */
65        .idle = 5 * 60,
66
67        /* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */
68        .access = 0
69};
70
71static rtems_status_code
72media_listener(rtems_media_event event, rtems_media_state state,
73    const char *src, const char *dest, void *arg)
74{
75        printf(
76                "media listener: event = %s, state = %s, src = %s",
77                rtems_media_event_description(event),
78                rtems_media_state_description(state),
79                src
80        );
81
82        if (dest != NULL) {
83                printf(", dest = %s", dest);
84        }
85
86        if (arg != NULL) {
87                printf(", arg = %p\n", arg);
88        }
89
90        printf("\n");
91
92        if (event == RTEMS_MEDIA_EVENT_MOUNT && state == RTEMS_MEDIA_STATE_SUCCESS) {
93                char name[256];
94                int n = snprintf(&name[0], sizeof(name), "%s/test.txt", dest);
95                FILE *file;
96
97                assert(n < (int) sizeof(name));
98
99                printf("write file %s\n", &name[0]);
100                file = fopen(&name[0], "w");
101                if (file != NULL) {
102                        const char hello[] = "Hello, world!\n";
103
104                        fwrite(&hello[0], sizeof(hello) - 1, 1, file);
105                        fclose(file);
106                }
107        }
108
109        return RTEMS_SUCCESSFUL;
110}
111
112static void
113telnet_shell(char *name, void *arg)
114{
115        rtems_shell_env_t env;
116
117        memset(&env, 0, sizeof(env));
118
119        env.devname = name;
120        env.taskname = "TLNT";
121        env.login_check = NULL;
122        env.forever = false;
123
124        rtems_shell_main_loop(&env);
125}
126
127rtems_telnetd_config_table rtems_telnetd_config = {
128        .command = telnet_shell,
129        .arg = NULL,
130        .priority = 0,
131        .stack_size = 0,
132        .login_check = NULL,
133        .keep_stdio = false
134};
135
136static void
137test_main(void)
138{
139        int rv;
140        rtems_status_code sc;
141
142        rv = rtems_initialize_ftpd();
143        assert(rv == 0);
144
145        sc = rtems_telnetd_initialize();
146        assert(sc == RTEMS_SUCCESSFUL);
147
148        sc = rtems_shell_init("SHLL", 16 * 1024, 1, CONSOLE_DEVICE_NAME,
149            false, true, NULL);
150        assert(sc == RTEMS_SUCCESSFUL);
151
152        exit(0);
153}
154
155#define DEFAULT_EARLY_INITIALIZATION
156
157static void
158early_initialization(void)
159{
160        rtems_status_code sc;
161
162        sc = rtems_bdbuf_init();
163        assert(sc == RTEMS_SUCCESSFUL);
164
165        sc = rtems_media_initialize();
166        assert(sc == RTEMS_SUCCESSFUL);
167
168        sc = rtems_media_listener_add(media_listener, NULL);
169        assert(sc == RTEMS_SUCCESSFUL);
170
171        sc = rtems_media_server_initialize(
172                200,
173                32 * 1024,
174                RTEMS_DEFAULT_MODES,
175                RTEMS_DEFAULT_ATTRIBUTES
176        );
177        assert(sc == RTEMS_SUCCESSFUL);
178}
179
180#define DEFAULT_NETWORK_DHCPCD_ENABLE
181
182#define CONFIGURE_MICROSECONDS_PER_TICK 1000
183
184#define CONFIGURE_MAXIMUM_DRIVERS 32
185
186#define CONFIGURE_FILESYSTEM_DOSFS
187
188#define CONFIGURE_SMP_APPLICATION
189
190#define CONFIGURE_SMP_MAXIMUM_PROCESSORS 32
191
192#include <rtems/bsd/test/default-network-init.h>
193
194#define CONFIGURE_SHELL_COMMANDS_INIT
195
196#include <bsp/irq-info.h>
197
198#include <rtems/netcmds-config.h>
199
200#define CONFIGURE_SHELL_USER_COMMANDS \
201  &bsp_interrupt_shell_command, \
202  &rtems_shell_ARP_Command, \
203  &rtems_shell_BSD_Command, \
204  &rtems_shell_HOSTNAME_Command, \
205  &rtems_shell_PING_Command, \
206  &rtems_shell_ROUTE_Command, \
207  &rtems_shell_NETSTAT_Command, \
208  &rtems_shell_SYSCTL_Command, \
209  &rtems_shell_IFCONFIG_Command, \
210  &rtems_shell_VMSTAT_Command
211
212#define CONFIGURE_SHELL_COMMAND_CPUUSE
213#define CONFIGURE_SHELL_COMMAND_PERIODUSE
214#define CONFIGURE_SHELL_COMMAND_STACKUSE
215#define CONFIGURE_SHELL_COMMAND_PROFREPORT
216
217#define CONFIGURE_SHELL_COMMAND_CP
218#define CONFIGURE_SHELL_COMMAND_PWD
219#define CONFIGURE_SHELL_COMMAND_LS
220#define CONFIGURE_SHELL_COMMAND_LN
221#define CONFIGURE_SHELL_COMMAND_LSOF
222#define CONFIGURE_SHELL_COMMAND_CHDIR
223#define CONFIGURE_SHELL_COMMAND_CD
224#define CONFIGURE_SHELL_COMMAND_MKDIR
225#define CONFIGURE_SHELL_COMMAND_RMDIR
226#define CONFIGURE_SHELL_COMMAND_CAT
227#define CONFIGURE_SHELL_COMMAND_MV
228#define CONFIGURE_SHELL_COMMAND_RM
229#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
230
231#define CONFIGURE_SHELL_COMMAND_FDISK
232#define CONFIGURE_SHELL_COMMAND_BLKSTATS
233#define CONFIGURE_SHELL_COMMAND_BLKSYNC
234#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
235#define CONFIGURE_SHELL_COMMAND_DF
236#define CONFIGURE_SHELL_COMMAND_MOUNT
237#define CONFIGURE_SHELL_COMMAND_UNMOUNT
238#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
239
240#include <rtems/shellconfig.h>
Note: See TracBrowser for help on using the repository browser.