source: rtems-libbsd/testsuite/rcconf02/test_main.c @ 573b1982

5-freebsd-12freebsd-9.3
Last change on this file since 573b1982 was 573b1982, checked in by Chris Johns <chrisj@…>, on Jun 29, 2016 at 11:19:52 PM

Add DHCP support to rc.conf.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright 2016 Chris Johns <chrisj@rtems.org>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/*
27 * Tests:
28 *
29 * 1. rc.conf processing
30 *  1.1  syslog_priority
31 *  1.2  create_args_*
32 *  1.3  hostname
33 *  1.4  ifconfig_<iface>
34 *  1.5  vlans_<iface>
35 *  1.6  ifconfig_<iface>.<vlan>
36 *  1.7  defaultrouter
37 *  1.8  defaultroute_delay
38 *  1.9  ftp_enable
39 *  1.10 ftp_options
40 *  1.11 dhcpcd_priority
41 *  1.12 dhcpcd_options
42 *
43 * 2. dhcpcd (via vlan, should timeout unless VLAN is present)
44 *
45 * 3. get route, the defaultrouter sets a default route and the vlan DHCP
46 *    interface requires the default route be probed and found.
47 *
48 * 4. ftpd
49 */
50
51#include <rtems/bsd/sys/param.h>
52
53#include <assert.h>
54#include <ctype.h>
55#include <errno.h>
56#include <string.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <sys/stat.h>
60#include <sysexits.h>
61#include <unistd.h>
62
63#include <machine/rtems-bsd-commands.h>
64#include <machine/rtems-bsd-rc-conf.h>
65#include <machine/rtems-bsd-rc-conf-services.h>
66
67#include <rtems/bsd/test/network-config.h>
68
69#include <rtems/console.h>
70#include <rtems/shell.h>
71
72#if DEFINE_FOR_TESTING
73#define RCCONF02_HAS_SHELL
74#endif
75
76#define TEST_NAME "LIBBSD RC.CONF 2"
77
78#define IFACE_IPV4(iface) \
79  "ifconfig_" # iface "=\"inet " NET_CFG_SELF_IP " netmask " NET_CFG_NETMASK "\"\n"
80
81
82#define RC_CONF_IFACES \
83  IFACE_IPV4(dmc0)  \
84  IFACE_IPV4(sm0)   \
85  IFACE_IPV4(cgem0) \
86  IFACE_IPV4(fec0)  \
87  IFACE_IPV4(em0)   \
88  IFACE_IPV4(re0)
89
90#define IFACE_VLAN(iface) \
91  "vlans_" # iface "=\"101 102\"\n" \
92  "ifconfig_" # iface "_101=\"inet 192.0.101.1/24\"\n" \
93  "ifconfig_" # iface "_102=\"DHCP\"\n"
94
95#define RC_CONF_VLANS \
96  IFACE_VLAN(dmc0)  \
97  IFACE_VLAN(sm0)   \
98  IFACE_VLAN(cgem0) \
99  IFACE_VLAN(fec0)  \
100  IFACE_VLAN(em0)   \
101  IFACE_VLAN(re0)
102
103static const char* rc_conf_text =                          \
104  "#\n"                                                    \
105  "# Tests rc.conf. Add every NIC\n"                       \
106  "#\n"                                                    \
107  "\n"                                                     \
108  "syslog_priority=\"debug\"\n"                            \
109  "\n"                                                     \
110  "hostname=\"rctest\"\n"                                  \
111  "\n"                                                     \
112  "create_args_myvlan=\"vlan 102\"\n"                      \
113  "create_args_yourvlan=\"vlan 202\"\n"                    \
114  "\n"                                                     \
115  RC_CONF_IFACES                                           \
116  "\n"                                                     \
117  RC_CONF_VLANS                                            \
118  "\n"                                                     \
119  "defaultrouter=\"" NET_CFG_GATEWAY_IP "\"\n"             \
120  "defaultroute_delay=\"5\"\n"                             \
121  "\n"                                                     \
122  "dhcpcd_options=\"-h foobar\"\n"                         \
123  "\n"                                                     \
124  "ftpd_enable=\"YES\"\n"                                  \
125  "ftpd_options=\"-v -p 21 -C 10 -P 150 -L -I 10 -R /\"\n" \
126  "n";
127
128static void
129test_rc_conf_script(void)
130{
131  const char* ifconfg_args[] = {
132    "ifconfig", NULL
133  };
134  const char* netstat_args[] = {
135    "netstat", "-rn", NULL
136  };
137
138  printf("--------------- rc.conf -----------------\n");
139  printf(rc_conf_text);
140  printf("-----------------------------------------\n");
141
142  assert(rtems_bsd_run_rc_conf_script("internal", rc_conf_text, 15, true) == 0);
143
144  printf("-------------- IFCONFIG -----------------\n");
145  rtems_bsd_command_ifconfig(1, (char**) ifconfg_args);
146  printf("-------------- NETSTAT ------------------\n");
147  rtems_bsd_command_netstat(2, (char**) netstat_args);
148  printf("-----------------------------------------\n");
149}
150
151static void
152test_main(void)
153{
154  test_rc_conf_script();
155
156#if defined(RCCONF02_HAS_SHELL)
157  rtems_shell_init(
158    "SHLL",
159    32 * 1024,
160    1,
161    CONSOLE_DEVICE_NAME,
162    false,
163    true,
164    NULL
165    );
166#else
167  printf("RCCONF02 sleeping for 10s\n");
168  sleep(10);
169#endif /* RCCONF02_HAS_SHELL */
170
171  exit(0);
172}
173
174/*
175 * Optional shell for testing this test.
176 */
177#if defined(RCCONF02_HAS_SHELL)
178
179#define CONFIGURE_SHELL_COMMANDS_INIT
180
181#include <bsp/irq-info.h>
182
183#include <rtems/netcmds-config.h>
184
185#define CONFIGURE_SHELL_USER_COMMANDS \
186  &bsp_interrupt_shell_command, \
187  &rtems_shell_BSD_Command, \
188  &rtems_shell_HOSTNAME_Command, \
189  &rtems_shell_PING_Command, \
190  &rtems_shell_ROUTE_Command, \
191  &rtems_shell_NETSTAT_Command, \
192  &rtems_shell_IFCONFIG_Command, \
193  &rtems_shell_TCPDUMP_Command, \
194  &rtems_shell_SYSCTL_Command
195
196#define CONFIGURE_SHELL_COMMAND_CPUUSE
197#define CONFIGURE_SHELL_COMMAND_PERIODUSE
198#define CONFIGURE_SHELL_COMMAND_STACKUSE
199#define CONFIGURE_SHELL_COMMAND_PROFREPORT
200
201#define CONFIGURE_SHELL_COMMAND_CP
202#define CONFIGURE_SHELL_COMMAND_PWD
203#define CONFIGURE_SHELL_COMMAND_LS
204#define CONFIGURE_SHELL_COMMAND_LN
205#define CONFIGURE_SHELL_COMMAND_LSOF
206#define CONFIGURE_SHELL_COMMAND_CHDIR
207#define CONFIGURE_SHELL_COMMAND_CD
208#define CONFIGURE_SHELL_COMMAND_MKDIR
209#define CONFIGURE_SHELL_COMMAND_RMDIR
210#define CONFIGURE_SHELL_COMMAND_CAT
211#define CONFIGURE_SHELL_COMMAND_MV
212#define CONFIGURE_SHELL_COMMAND_RM
213#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
214#define CONFIGURE_SHELL_COMMAND_SHUTDOWN
215
216#include <rtems/shellconfig.h>
217#endif /* RCCONF02_HAS_SHELL */
218
219#define RTEMS_BSD_CONFIG_BSP_CONFIG
220#define RTEMS_BSD_CONFIG_SERVICE_FTPD
221
222#include <rtems/bsd/test/default-init.h>
Note: See TracBrowser for help on using the repository browser.