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