source: rtems-libbsd/testsuite/include/rtems/bsd/test/default-network-init.h @ 338f300

5-freebsd-12
Last change on this file since 338f300 was 338f300, checked in by Christian Mauderer <christian.mauderer@…>, on Apr 25, 2018 at 2:28:00 PM

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: 9.2 KB
Line 
1/*
2 * Copyright (c) 2013-2014 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 <sys/stat.h>
33#include <sys/socket.h>
34
35#include <net/if.h>
36
37#include <assert.h>
38#include <fcntl.h>
39#include <ifaddrs.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <sysexits.h>
43
44#include <machine/rtems-bsd-commands.h>
45
46#include <rtems.h>
47#include <rtems/printer.h>
48#include <rtems/stackchk.h>
49#include <rtems/bsd/bsd.h>
50#include <rtems/bsd/modules.h>
51
52#if defined(DEFAULT_NETWORK_DHCPCD_ENABLE) && \
53    !defined(DEFAULT_NETWORK_NO_STATIC_IFCONFIG)
54#define DEFAULT_NETWORK_NO_STATIC_IFCONFIG
55#endif
56
57#ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
58#include <rtems/bsd/test/network-config.h>
59#endif
60
61#ifdef DEFAULT_NETWORK_SHELL
62#include <rtems/console.h>
63#include <rtems/shell.h>
64#endif
65
66static void
67default_network_set_self_prio(rtems_task_priority prio)
68{
69        rtems_status_code sc;
70
71        sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio);
72        assert(sc == RTEMS_SUCCESSFUL);
73}
74
75#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
76static void
77default_network_ifconfig_hwif0(char *ifname)
78{
79        int exit_code;
80        char *ifcfg[] = {
81                "ifconfig",
82                ifname,
83#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
84                "up",
85#else
86                "inet",
87                NET_CFG_SELF_IP,
88                "netmask",
89                NET_CFG_NETMASK,
90#endif
91                NULL
92        };
93
94        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg);
95        assert(exit_code == EX_OK);
96}
97
98static void
99default_network_route_hwif0(char *ifname)
100{
101#ifndef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
102        int exit_code;
103        char *dflt_route[] = {
104                "route",
105                "add",
106                "-host",
107                NET_CFG_GATEWAY_IP,
108                "-iface",
109                ifname,
110                NULL
111        };
112        char *dflt_route2[] = {
113                "route",
114                "add",
115                "default",
116                NET_CFG_GATEWAY_IP,
117                NULL
118        };
119
120        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route), dflt_route);
121        assert(exit_code == EXIT_SUCCESS);
122
123        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route2), dflt_route2);
124        assert(exit_code == EXIT_SUCCESS);
125#endif
126}
127#endif
128
129#ifdef DEFAULT_NETWORK_DHCPCD_ENABLE
130static void
131default_network_dhcpcd_task(rtems_task_argument arg)
132{
133        static const char default_cfg[] = "clientid libbsd test client\n";
134        int exit_code;
135        char *dhcpcd[] = {
136                "dhcpcd",
137                NULL
138        };
139        int fd;
140        int rv;
141        ssize_t n;
142
143        (void)arg;
144
145        fd = open("/etc/dhcpcd.conf", O_CREAT | O_WRONLY,
146            S_IRWXU | S_IRWXG | S_IRWXO);
147        assert(fd >= 0);
148
149        n = write(fd, default_cfg, sizeof(default_cfg));
150        assert(n == (ssize_t) sizeof(default_cfg));
151
152#ifdef DEFAULT_NETWORK_DHCPCD_NO_DHCP_DISCOVERY
153        static const char nodhcp_cfg[] = "nodhcp\nnodhcp6\n";
154
155        n = write(fd, nodhcp_cfg, sizeof(nodhcp_cfg));
156        assert(n == (ssize_t) sizeof(nodhcp_cfg));
157#endif
158
159        rv = close(fd);
160        assert(rv == 0);
161
162        exit_code = rtems_bsd_command_dhcpcd(RTEMS_BSD_ARGC(dhcpcd), dhcpcd);
163        assert(exit_code == EXIT_SUCCESS);
164}
165#endif
166
167static void
168default_network_dhcpcd(void)
169{
170#ifdef DEFAULT_NETWORK_DHCPCD_ENABLE
171        rtems_status_code sc;
172        rtems_id id;
173
174        sc = rtems_task_create(
175                rtems_build_name('D', 'H', 'C', 'P'),
176                RTEMS_MAXIMUM_PRIORITY - 1,
177                2 * RTEMS_MINIMUM_STACK_SIZE,
178                RTEMS_DEFAULT_MODES,
179                RTEMS_FLOATING_POINT,
180                &id
181        );
182        assert(sc == RTEMS_SUCCESSFUL);
183
184        sc = rtems_task_start(id, default_network_dhcpcd_task, 0);
185        assert(sc == RTEMS_SUCCESSFUL);
186#endif
187}
188
189static void
190default_network_on_exit(int exit_code, void *arg)
191{
192        rtems_printer printer;
193
194        (void)arg;
195
196        rtems_print_printer_printf(&printer);
197        rtems_stack_checker_report_usage_with_plugin(&printer);
198
199        if (exit_code == 0) {
200                puts("*** END OF TEST " TEST_NAME " ***");
201        }
202}
203
204static void
205Init(rtems_task_argument arg)
206{
207        rtems_status_code sc;
208#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
209#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
210        char ifnamebuf[IF_NAMESIZE];
211#endif
212        char *ifname;
213#endif
214
215        /*
216         * Default the syslog priority to 'debug' to aid developers.
217         */
218        rtems_bsd_setlogpriority("debug");
219
220        (void)arg;
221        puts("*** " TEST_NAME " TEST ***");
222
223        on_exit(default_network_on_exit, NULL);
224
225#ifdef DEFAULT_EARLY_INITIALIZATION
226        early_initialization();
227#endif
228
229        /* Let other tasks run to complete background work */
230        default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1U);
231
232#ifdef DEFAULT_NETWORK_SHELL
233        sc = rtems_shell_init(
234                "SHLL",
235                32 * 1024,
236                1,
237                CONSOLE_DEVICE_NAME,
238                false,
239                false,
240                NULL
241        );
242        assert(sc == RTEMS_SUCCESSFUL);
243#endif
244
245        rtems_bsd_initialize();
246
247#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
248#ifdef DEFAULT_NETWORK_NO_STATIC_IFCONFIG
249        ifname = if_indextoname(1, &ifnamebuf[0]);
250        assert(ifname != NULL);
251#else
252        ifname = NET_CFG_INTERFACE_0;
253#endif
254#endif
255
256        /* Let the callout timer allocate its resources */
257        sc = rtems_task_wake_after(2);
258        assert(sc == RTEMS_SUCCESSFUL);
259
260        rtems_bsd_ifconfig_lo0();
261#ifndef DEFAULT_NETWORK_NO_INTERFACE_0
262        default_network_ifconfig_hwif0(ifname);
263        default_network_route_hwif0(ifname);
264#endif
265        default_network_dhcpcd();
266
267        test_main();
268
269        assert(0);
270}
271
272/*
273 * Configure LibBSD.
274 */
275
276#if defined(LIBBSP_I386_PC386_BSP_H)
277#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (64 * 1024 * 1024)
278#elif defined(LIBBSP_POWERPC_QORIQ_BSP_H)
279#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (32 * 1024 * 1024)
280#endif
281
282#define RTEMS_BSD_CONFIG_NET_PF_UNIX
283#define RTEMS_BSD_CONFIG_NET_IP_MROUTE
284#define RTEMS_BSD_CONFIG_NET_IP6_MROUTE
285#define RTEMS_BSD_CONFIG_NET_IF_BRIDGE
286#define RTEMS_BSD_CONFIG_NET_IF_LAGG
287#define RTEMS_BSD_CONFIG_NET_IF_VLAN
288#define RTEMS_BSD_CONFIG_BSP_CONFIG
289#define RTEMS_BSD_CONFIG_INIT
290
291#include <machine/rtems-bsd-config.h>
292
293#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
294#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
295#define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
296#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER
297#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
298
299#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
300
301#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
302
303#define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 32
304#define CONFIGURE_UNLIMITED_OBJECTS
305#define CONFIGURE_UNIFIED_WORK_AREAS
306
307#define CONFIGURE_STACK_CHECKER_ENABLED
308
309#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (64 * 1024)
310#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4
311#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024)
312
313#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
314
315#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
316#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
317#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
318
319#define CONFIGURE_INIT
320
321#include <rtems/confdefs.h>
322
323#ifdef DEFAULT_NETWORK_SHELL
324
325#define CONFIGURE_SHELL_COMMANDS_INIT
326
327#include <bsp/irq-info.h>
328
329#include <rtems/netcmds-config.h>
330
331#ifdef RTEMS_BSD_MODULE_USER_SPACE_WLANSTATS
332  #define SHELL_WLANSTATS_COMMAND &rtems_shell_WLANSTATS_Command,
333#else
334  #define SHELL_WLANSTATS_COMMAND
335#endif
336
337#ifdef RTEMS_BSD_MODULE_USR_SBIN_WPA_SUPPLICANT
338  #define SHELL_WPA_SUPPLICANT_COMMAND &rtems_shell_WPA_SUPPLICANT_Command,
339#else
340  #define SHELL_WPA_SUPPLICANT_COMMAND
341#endif
342
343#define CONFIGURE_SHELL_USER_COMMANDS \
344  SHELL_WLANSTATS_COMMAND \
345  SHELL_WPA_SUPPLICANT_COMMAND \
346  &bsp_interrupt_shell_command, \
347  &rtems_shell_ARP_Command, \
348  &rtems_shell_HOSTNAME_Command, \
349  &rtems_shell_PING_Command, \
350  &rtems_shell_ROUTE_Command, \
351  &rtems_shell_NETSTAT_Command, \
352  &rtems_shell_IFCONFIG_Command, \
353  &rtems_shell_TCPDUMP_Command, \
354  &rtems_shell_SYSCTL_Command, \
355  &rtems_shell_VMSTAT_Command
356
357#define CONFIGURE_SHELL_COMMAND_CPUINFO
358#define CONFIGURE_SHELL_COMMAND_CPUUSE
359#define CONFIGURE_SHELL_COMMAND_PERIODUSE
360#define CONFIGURE_SHELL_COMMAND_STACKUSE
361#define CONFIGURE_SHELL_COMMAND_PROFREPORT
362
363#define CONFIGURE_SHELL_COMMAND_CP
364#define CONFIGURE_SHELL_COMMAND_PWD
365#define CONFIGURE_SHELL_COMMAND_LS
366#define CONFIGURE_SHELL_COMMAND_LN
367#define CONFIGURE_SHELL_COMMAND_LSOF
368#define CONFIGURE_SHELL_COMMAND_CHDIR
369#define CONFIGURE_SHELL_COMMAND_CD
370#define CONFIGURE_SHELL_COMMAND_MKDIR
371#define CONFIGURE_SHELL_COMMAND_RMDIR
372#define CONFIGURE_SHELL_COMMAND_CAT
373#define CONFIGURE_SHELL_COMMAND_MV
374#define CONFIGURE_SHELL_COMMAND_RM
375#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
376#define CONFIGURE_SHELL_COMMAND_SHUTDOWN
377
378#include <rtems/shellconfig.h>
379
380#endif /* DEFAULT_NETWORK_SHELL */
Note: See TracBrowser for help on using the repository browser.