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

4.115-freebsd-12freebsd-9.3
Last change on this file since d617293 was d617293, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 13, 2013 at 2:27:40 PM

ping01: New test

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