source: rtems-libbsd/testsuite/commands01/test_main.c @ 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: 6.8 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/param.h>
33
34#include <assert.h>
35#include <errno.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <sysexits.h>
39
40#include <machine/rtems-bsd-commands.h>
41
42#include <rtems/libcsupport.h>
43#include <rtems/bsd/modules.h>
44
45#define TEST_NAME "LIBBSD COMMANDS 1"
46
47#define ARGC(x) RTEMS_BSD_ARGC(x)
48
49static void
50test_route_without_if(void)
51{
52        rtems_resource_snapshot snapshot;
53        int exit_code;
54        char *flush[] = {
55                "route",
56                "flush",
57                NULL
58        };
59        char *dflt_route[] = {
60                "route",
61                "add",
62                "default",
63                "192.168.96.1",
64                NULL
65        };
66        char *invalid[] = {
67                "route",
68                "blub",
69                NULL
70        };
71
72        exit_code = rtems_bsd_command_route(ARGC(flush), flush);
73        assert(exit_code == EX_OK);
74
75        rtems_resource_snapshot_take(&snapshot);
76
77        exit_code = rtems_bsd_command_route(ARGC(flush), flush);
78        assert(exit_code == EX_OK);
79
80        assert(rtems_resource_snapshot_check(&snapshot));
81
82        exit_code = rtems_bsd_command_route(ARGC(dflt_route), dflt_route);
83        assert(exit_code == EXIT_FAILURE);
84
85        rtems_resource_snapshot_take(&snapshot);
86
87        exit_code = rtems_bsd_command_route(ARGC(dflt_route), dflt_route);
88        assert(exit_code == EXIT_FAILURE);
89
90        assert(rtems_resource_snapshot_check(&snapshot));
91
92        exit_code = rtems_bsd_command_route(ARGC(invalid), invalid);
93        assert(exit_code == EX_USAGE);
94
95        assert(rtems_resource_snapshot_check(&snapshot));
96}
97
98static void
99test_ifconfig_lo0(void)
100{
101        rtems_resource_snapshot snapshot;
102        int exit_code;
103        char *lo0[] = {
104                "ifconfig",
105                "lo0",
106                "inet",
107                "127.0.0.1",
108                "netmask",
109                "255.255.255.0",
110                NULL
111        };
112#ifdef RTEMS_BSD_MODULE_NETINET6
113        char *lo0_inet6[] = {
114                "ifconfig",
115                "lo0",
116                "inet6",
117                "::1",
118                "prefixlen",
119                "128",
120                NULL
121        };
122#endif /* RTEMS_BSD_MODULE_NETINET6 */
123        char *status[] = {
124                "ifconfig",
125                "lo0",
126                "inet",
127                NULL
128        };
129#ifdef RTEMS_BSD_MODULE_NETINET6
130        char *status_inet6[] = {
131                "ifconfig",
132                "lo0",
133                "inet6",
134                NULL
135        };
136#endif /* RTEMS_BSD_MODULE_NETINET6 */
137
138        exit_code = rtems_bsd_command_ifconfig(ARGC(lo0), lo0);
139        assert(exit_code == EX_OK);
140
141#ifdef RTEMS_BSD_MODULE_NETINET6
142        exit_code = rtems_bsd_command_ifconfig(ARGC(lo0_inet6), lo0_inet6);
143        assert(exit_code == EX_OK);
144#endif /* RTEMS_BSD_MODULE_NETINET6 */
145
146        rtems_resource_snapshot_take(&snapshot);
147
148        exit_code = rtems_bsd_command_ifconfig(ARGC(status), status);
149        assert(exit_code == EX_OK);
150
151#ifdef RTEMS_BSD_MODULE_NETINET6
152        exit_code = rtems_bsd_command_ifconfig(ARGC(status_inet6), status_inet6);
153        assert(exit_code == EX_OK);
154#endif /* RTEMS_BSD_MODULE_NETINET6 */
155
156        rtems_resource_snapshot_take(&snapshot);
157
158#ifdef RTEMS_BSD_MODULE_NETINET6
159        exit_code = rtems_bsd_command_ifconfig(ARGC(status_inet6), status_inet6);
160        assert(exit_code == EX_OK);
161#endif /* RTEMS_BSD_MODULE_NETINET6 */
162
163        assert(rtems_resource_snapshot_check(&snapshot));
164}
165
166static void
167test_route_with_lo0(void)
168{
169        int exit_code;
170        char *dflt_route[] = {
171                "route",
172                "add",
173                "default",
174                "127.0.0.1",
175                NULL
176        };
177
178        exit_code = rtems_bsd_command_route(ARGC(dflt_route), dflt_route);
179        assert(exit_code == EXIT_SUCCESS);
180}
181
182static void
183test_ping(void)
184{
185        rtems_resource_snapshot snapshot;
186        int exit_code;
187        char *ping[] = {
188                "ping",
189                "-c",
190                "3",
191                "127.0.0.1",
192                NULL
193        };
194
195        exit_code = rtems_bsd_command_ping(ARGC(ping), ping);
196        assert(exit_code == EXIT_SUCCESS);
197
198        rtems_resource_snapshot_take(&snapshot);
199
200        exit_code = rtems_bsd_command_ping(ARGC(ping), ping);
201        assert(exit_code == EXIT_SUCCESS);
202
203        assert(rtems_resource_snapshot_check(&snapshot));
204}
205
206static void
207test_ping6(void)
208{
209#ifdef RTEMS_BSD_MODULE_NETINET6
210        rtems_resource_snapshot snapshot;
211        int exit_code;
212        char *ping6[] = {
213                "ping6",
214                "-c",
215                "1",
216                "::1",
217                NULL
218        };
219
220        exit_code = rtems_bsd_command_ping6(ARGC(ping6), ping6);
221        assert(exit_code == EXIT_SUCCESS);
222
223        rtems_resource_snapshot_take(&snapshot);
224
225        exit_code = rtems_bsd_command_ping6(ARGC(ping6), ping6);
226        assert(exit_code == EXIT_SUCCESS);
227
228        assert(rtems_resource_snapshot_check(&snapshot));
229#endif
230}
231
232static void
233test_netstat(void)
234{
235        rtems_resource_snapshot snapshot;
236        int exit_code;
237        char *netstat[] = {
238                "netstat",
239                NULL
240        };
241        char *netstat_s[] = {
242                "netstat",
243                "-s",
244                NULL
245        };
246        char *netstat_r[] = {
247                "netstat",
248                "-r",
249                NULL
250        };
251
252        exit_code = rtems_bsd_command_netstat(ARGC(netstat), netstat);
253        assert(exit_code == EXIT_SUCCESS);
254
255        rtems_resource_snapshot_take(&snapshot);
256
257        exit_code = rtems_bsd_command_netstat(ARGC(netstat_s), netstat_s);
258        assert(exit_code == EXIT_SUCCESS);
259
260        assert(rtems_resource_snapshot_check(&snapshot));
261
262        exit_code = rtems_bsd_command_netstat(ARGC(netstat_r), netstat_r);
263        assert(exit_code == EXIT_SUCCESS);
264
265        rtems_resource_snapshot_take(&snapshot);
266
267        exit_code = rtems_bsd_command_netstat(ARGC(netstat_r), netstat_r);
268        assert(exit_code == EXIT_SUCCESS);
269
270        assert(rtems_resource_snapshot_check(&snapshot));
271}
272
273static void
274test_wlanstats(void)
275{
276#ifdef RTEMS_BSD_MODULE_USER_SPACE_WLANSTATS
277        rtems_resource_snapshot snapshot;
278        char *wlanstats[] = {
279                "wlanstats",
280                NULL
281        };
282
283        /* Without a WLAN device, only the basic call can be tested. */
284        rtems_bsd_command_wlanstats(ARGC(wlanstats), wlanstats);
285        rtems_resource_snapshot_take(&snapshot);
286        rtems_bsd_command_wlanstats(ARGC(wlanstats), wlanstats);
287        assert(rtems_resource_snapshot_check(&snapshot));
288#endif /* RTEMS_BSD_MODULE_USER_SPACE_WLANSTATS */
289}
290
291static void
292test_main(void)
293{
294        test_route_without_if();
295        test_ifconfig_lo0();
296        test_route_with_lo0();
297        test_ping();
298        test_ping6();
299        test_netstat();
300        test_wlanstats();
301
302        exit(0);
303}
304
305#include <rtems/bsd/test/default-init.h>
Note: See TracBrowser for help on using the repository browser.