source: rtems-libbsd/testsuite/media01/test_main.c @ 338f300

55-freebsd-126-freebsd-12
Last change on this file since 338f300 was 338f300, checked in by Christian Mauderer <christian.mauderer@…>, on 04/25/18 at 14:28:00

buildset: Add minimal and everything config.

This adds two new buildset configurations: One that leaves out as much
features as possible and one that enables all features. For the default
configuration WiFi? support is now disabled.

To disable IPv6 for the minimal configuration, all -DINET6 are
eliminated in libbsd.py. They are now replaced by a #ifdef that checks
for RTEMS_BSD_MODULE_NETINET6 instead.

Close #3351.

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