source: rtems-libbsd/testsuite/media01/test_main.c @ 666a568

55-freebsd-126-freebsd-12
Last change on this file since 666a568 was 666a568, checked in by Sebastian Huber <sebastian.huber@…>, on 08/25/17 at 12:23:18

Include missing <string.h> and <limits.h>

Fix warnings.

Update #2132.
Update #2133.

  • 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#include <string.h>
36
37#include <rtems/bdbuf.h>
38#include <rtems/console.h>
39#include <rtems/ftpd.h>
40#include <rtems/media.h>
41#include <rtems/shell.h>
42#include <rtems/telnetd.h>
43
44#define TEST_NAME "LIBBSD MEDIA 1"
45
46struct rtems_ftpd_configuration rtems_ftpd_configuration = {
47        /* FTPD task priority */
48        .priority = 100,
49
50        /* Maximum buffersize for hooks */
51        .max_hook_filesize = 0,
52
53        /* Well-known port */
54        .port = 21,
55
56        /* List of hooks */
57        .hooks = NULL,
58
59        /* Root for FTPD or NULL for "/" */
60        .root = NULL,
61
62        /* Max. connections */
63        .tasks_count = 4,
64
65        /* Idle timeout in seconds  or 0 for no (infinite) timeout */
66        .idle = 5 * 60,
67
68        /* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */
69        .access = 0
70};
71
72static rtems_status_code
73media_listener(rtems_media_event event, rtems_media_state state,
74    const char *src, const char *dest, void *arg)
75{
76        printf(
77                "media listener: event = %s, state = %s, src = %s",
78                rtems_media_event_description(event),
79                rtems_media_state_description(state),
80                src
81        );
82
83        if (dest != NULL) {
84                printf(", dest = %s", dest);
85        }
86
87        if (arg != NULL) {
88                printf(", arg = %p\n", arg);
89        }
90
91        printf("\n");
92
93        if (event == RTEMS_MEDIA_EVENT_MOUNT && state == RTEMS_MEDIA_STATE_SUCCESS) {
94                char name[256];
95                int n = snprintf(&name[0], sizeof(name), "%s/test.txt", dest);
96                FILE *file;
97
98                assert(n < (int) sizeof(name));
99
100                printf("write file %s\n", &name[0]);
101                file = fopen(&name[0], "w");
102                if (file != NULL) {
103                        const char hello[] = "Hello, world!\n";
104
105                        fwrite(&hello[0], sizeof(hello) - 1, 1, file);
106                        fclose(file);
107                }
108        }
109
110        return RTEMS_SUCCESSFUL;
111}
112
113static void
114telnet_shell(char *name, void *arg)
115{
116        rtems_shell_env_t env;
117
118        memset(&env, 0, sizeof(env));
119
120        env.devname = name;
121        env.taskname = "TLNT";
122        env.login_check = NULL;
123        env.forever = false;
124
125        rtems_shell_main_loop(&env);
126}
127
128rtems_telnetd_config_table rtems_telnetd_config = {
129        .command = telnet_shell,
130        .arg = NULL,
131        .priority = 0,
132        .stack_size = 0,
133        .login_check = NULL,
134        .keep_stdio = false
135};
136
137static void
138test_main(void)
139{
140        int rv;
141        rtems_status_code sc;
142
143        rv = rtems_initialize_ftpd();
144        assert(rv == 0);
145
146        sc = rtems_telnetd_initialize();
147        assert(sc == RTEMS_SUCCESSFUL);
148
149        sc = rtems_shell_init("SHLL", 16 * 1024, 1, CONSOLE_DEVICE_NAME,
150            false, true, NULL);
151        assert(sc == RTEMS_SUCCESSFUL);
152
153        exit(0);
154}
155
156#define DEFAULT_EARLY_INITIALIZATION
157
158static void
159early_initialization(void)
160{
161        rtems_status_code sc;
162
163        sc = rtems_bdbuf_init();
164        assert(sc == RTEMS_SUCCESSFUL);
165
166        sc = rtems_media_initialize();
167        assert(sc == RTEMS_SUCCESSFUL);
168
169        sc = rtems_media_listener_add(media_listener, NULL);
170        assert(sc == RTEMS_SUCCESSFUL);
171
172        sc = rtems_media_server_initialize(
173                200,
174                32 * 1024,
175                RTEMS_DEFAULT_MODES,
176                RTEMS_DEFAULT_ATTRIBUTES
177        );
178        assert(sc == RTEMS_SUCCESSFUL);
179}
180
181#define DEFAULT_NETWORK_DHCPCD_ENABLE
182
183#define CONFIGURE_MICROSECONDS_PER_TICK 1000
184
185#define CONFIGURE_MAXIMUM_DRIVERS 32
186
187#define CONFIGURE_FILESYSTEM_DOSFS
188
189#define CONFIGURE_MAXIMUM_PROCESSORS 32
190
191#include <rtems/bsd/test/default-network-init.h>
192
193#define CONFIGURE_SHELL_COMMANDS_INIT
194
195#include <bsp/irq-info.h>
196
197#include <rtems/netcmds-config.h>
198
199#define CONFIGURE_SHELL_USER_COMMANDS \
200  &bsp_interrupt_shell_command, \
201  &rtems_shell_ARP_Command, \
202  &rtems_shell_HOSTNAME_Command, \
203  &rtems_shell_PING_Command, \
204  &rtems_shell_ROUTE_Command, \
205  &rtems_shell_NETSTAT_Command, \
206  &rtems_shell_SYSCTL_Command, \
207  &rtems_shell_IFCONFIG_Command, \
208  &rtems_shell_VMSTAT_Command
209
210#define CONFIGURE_SHELL_COMMAND_CPUINFO
211#define CONFIGURE_SHELL_COMMAND_CPUUSE
212#define CONFIGURE_SHELL_COMMAND_PERIODUSE
213#define CONFIGURE_SHELL_COMMAND_STACKUSE
214#define CONFIGURE_SHELL_COMMAND_PROFREPORT
215
216#define CONFIGURE_SHELL_COMMAND_CP
217#define CONFIGURE_SHELL_COMMAND_PWD
218#define CONFIGURE_SHELL_COMMAND_LS
219#define CONFIGURE_SHELL_COMMAND_LN
220#define CONFIGURE_SHELL_COMMAND_LSOF
221#define CONFIGURE_SHELL_COMMAND_CHDIR
222#define CONFIGURE_SHELL_COMMAND_CD
223#define CONFIGURE_SHELL_COMMAND_MKDIR
224#define CONFIGURE_SHELL_COMMAND_RMDIR
225#define CONFIGURE_SHELL_COMMAND_CAT
226#define CONFIGURE_SHELL_COMMAND_MV
227#define CONFIGURE_SHELL_COMMAND_RM
228#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
229
230#define CONFIGURE_SHELL_COMMAND_FDISK
231#define CONFIGURE_SHELL_COMMAND_BLKSTATS
232#define CONFIGURE_SHELL_COMMAND_BLKSYNC
233#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
234#define CONFIGURE_SHELL_COMMAND_DF
235#define CONFIGURE_SHELL_COMMAND_MOUNT
236#define CONFIGURE_SHELL_COMMAND_UNMOUNT
237#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
238
239#include <rtems/shellconfig.h>
Note: See TracBrowser for help on using the repository browser.