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

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 7831313 was 7831313, checked in by Sebastian Huber <sebastian.huber@…>, on 01/20/14 at 14:27:13

Add and use RTEMS_BSD_ARGC()

  • Property mode set to 100644
File size: 4.6 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 <assert.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <sysexits.h>
36
37#include <machine/rtems-bsd-commands.h>
38
39#include <rtems.h>
40#include <rtems/stackchk.h>
41#include <rtems/bsd/test/network-config.h>
42#include <rtems/bsd/bsd.h>
43
44static void
45default_network_set_self_prio(rtems_task_priority prio)
46{
47        rtems_status_code sc;
48
49        sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio);
50        assert(sc == RTEMS_SUCCESSFUL);
51}
52
53static void
54default_network_ifconfig_lo0(void)
55{
56        int exit_code;
57        char *lo0[] = {
58                "ifconfig",
59                "lo0",
60                "inet",
61                "127.0.0.1",
62                "netmask",
63                "255.255.255.0",
64                NULL
65        };
66        char *lo0_inet6[] = {
67                "ifconfig",
68                "lo0",
69                "inet6",
70                "::1",
71                "prefixlen",
72                "128",
73                NULL
74        };
75
76        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0), lo0);
77        assert(exit_code == EX_OK);
78
79        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0_inet6), lo0_inet6);
80        assert(exit_code == EX_OK);
81}
82
83static void
84default_network_ifconfig_interface_0(void)
85{
86        int exit_code;
87        char *iface0[] = {
88                "ifconfig",
89                NET_CFG_INTERFACE_0,
90                "inet",
91                NET_CFG_SELF_IP,
92                "netmask",
93                NET_CFG_NETMASK,
94                NULL
95        };
96
97        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(iface0), iface0);
98        assert(exit_code == EX_OK);
99}
100
101static void
102default_network_route(void)
103{
104        int exit_code;
105        char *dflt_route[] = {
106                "route",
107                "add",
108                "-host",
109                NET_CFG_GATEWAY_IP,
110                "-iface",
111                NET_CFG_INTERFACE_0,
112                NULL
113        };
114        char *dflt_route2[] = {
115                "route",
116                "add",
117                "default",
118                NET_CFG_GATEWAY_IP,
119                NULL
120        };
121
122        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route), dflt_route);
123        assert(exit_code == EXIT_SUCCESS);
124
125        exit_code = rtems_bsd_command_route(RTEMS_BSD_ARGC(dflt_route2), dflt_route2);
126        assert(exit_code == EXIT_SUCCESS);
127}
128
129static void
130default_network_on_exit(int exit_code, void *arg)
131{
132        rtems_stack_checker_report_usage_with_plugin(NULL,
133            rtems_printf_plugin);
134
135        if (exit_code == 0) {
136                puts("*** END OF TEST " TEST_NAME " ***");
137        }
138}
139
140static void
141Init(rtems_task_argument arg)
142{
143        rtems_status_code sc;
144
145        puts("*** " TEST_NAME " TEST ***");
146
147        on_exit(default_network_on_exit, NULL);
148
149        /* Let other tasks run to complete background work */
150        default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1);
151
152        rtems_bsd_initialize();
153
154        /* Let the callout timer allocate its resources */
155        sc = rtems_task_wake_after(2);
156        assert(sc == RTEMS_SUCCESSFUL);
157
158        default_network_ifconfig_lo0();
159        default_network_ifconfig_interface_0();
160        default_network_route();
161
162        test_main();
163
164        assert(0);
165}
166
167#include <machine/rtems-bsd-sysinit.h>
168
169SYSINIT_NEED_NET_PF_UNIX;
170
171#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
172#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
173
174#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
175
176#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
177
178#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
179
180#define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 32
181#define CONFIGURE_UNLIMITED_OBJECTS
182#define CONFIGURE_UNIFIED_WORK_AREAS
183
184#define CONFIGURE_STACK_CHECKER_ENABLED
185
186#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
187
188#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
189#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
190#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
191
192#define CONFIGURE_INIT
193
194#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.