source: rtems-libbsd/testsuite/rcconf02/test_main.c @ 90873cc

5-freebsd-12freebsd-9.3
Last change on this file since 90873cc was 90873cc, checked in by Chris Johns <chrisj@…>, on Jun 28, 2016 at 3:32:01 AM

Add ftpd as a service. Add rtems-bsd-config.h for app libbsd set up.

  • Property mode set to 100644
File size: 5.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#include <rtems/bsd/sys/param.h>
27
28#include <assert.h>
29#include <ctype.h>
30#include <errno.h>
31#include <string.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <sys/stat.h>
35#include <sysexits.h>
36#include <unistd.h>
37
38#include <machine/rtems-bsd-commands.h>
39#include <machine/rtems-bsd-rc-conf.h>
40#include <machine/rtems-bsd-rc-conf-services.h>
41
42#include <rtems/bsd/test/network-config.h>
43
44#include <rtems/console.h>
45#include <rtems/shell.h>
46
47#define RCCONF02_HAS_SHELL
48
49#define TEST_NAME "LIBBSD RC.CONF 2"
50
51#define IFACE_IPV4(iface) \
52  "ifconfig_" # iface " inet " NET_CFG_SELF_IP " netmask " NET_CFG_NETMASK "\n"
53
54#define RC_CONF_IFACES \
55  IFACE_IPV4(dmc0)  \
56  IFACE_IPV4(sm0)   \
57  IFACE_IPV4(cgem0) \
58  IFACE_IPV4(fec0)  \
59  IFACE_IPV4(em0)   \
60  IFACE_IPV4(re0)
61
62#define IFACE_VLAN(iface) \
63  "vlans_" # iface "=\"101 102\"\n" \
64  "ifconfig_" # iface "_101=\"inet 192.0.101.1/24\n" \
65  "ifconfig_" # iface "_102=\"inet 192.0.102.1/24\n"
66
67#define RC_CONF_VLANS \
68  IFACE_VLAN(dmc0)  \
69  IFACE_VLAN(sm0)   \
70  IFACE_VLAN(cgem0) \
71  IFACE_VLAN(fec0)  \
72  IFACE_VLAN(em0)   \
73  IFACE_VLAN(re0)
74
75static const char* rc_conf_text =                       \
76  "#\n"                                                 \
77  "# Tests rc.conf. Add every NIC\n"                    \
78  "#\n"                                                 \
79  "hostname=\"rctest\"\n"                               \
80  "\n"                                                  \
81  "create_args_myvlan=\"vlan 102\"\n"                   \
82  "create_args_yourvlan=\"vlan 202\"\n"                 \
83  "\n"                                                  \
84  RC_CONF_IFACES                                        \
85  "\n"                                                  \
86  RC_CONF_VLANS                                         \
87  "\n"                                                  \
88  "defaultrouter=\"" NET_CFG_GATEWAY_IP "\"\n"          \
89  "\n"                                                  \
90  "ftpd_enable=\"YES\"\n"                               \
91  "ftpd_options=\"-v -p 21 -C 10 -P 150 -L -I 10 -R /\"\n" \
92  "n";
93
94static void
95test_rc_conf_script(void)
96{
97  const char* ifconfg_args[] = {
98    "ifconfig", NULL
99  };
100  const char* netstat_args[] = {
101    "netstat", "-rn", NULL
102  };
103
104  printf("--------------- rc.conf -----------------\n");
105  printf(rc_conf_text);
106  printf("-----------------------------------------\n");
107
108  assert(rtems_bsd_run_rc_conf_script("internal", rc_conf_text, 15, true) == 0);
109
110  printf("-------------- IFCONFIG -----------------\n");
111  rtems_bsd_command_ifconfig(1, (char**) ifconfg_args);
112  printf("-------------- NETSTAT ------------------\n");
113  rtems_bsd_command_netstat(2, (char**) netstat_args);
114  printf("-----------------------------------------\n");
115}
116
117static void
118test_main(void)
119{
120  test_rc_conf_script();
121
122#if defined(RCCONF02_HAS_SHELL)
123  rtems_shell_init(
124    "SHLL",
125    32 * 1024,
126    1,
127    CONSOLE_DEVICE_NAME,
128    false,
129    true,
130    NULL
131    );
132#endif /* RCCONF02_HAS_SHELL */
133
134  exit(0);
135}
136
137/*
138 * Optional shell for testing this test.
139 */
140#if defined(RCCONF02_HAS_SHELL)
141
142#define CONFIGURE_SHELL_COMMANDS_INIT
143
144#include <bsp/irq-info.h>
145
146#include <rtems/netcmds-config.h>
147
148#define CONFIGURE_SHELL_USER_COMMANDS \
149  &bsp_interrupt_shell_command, \
150  &rtems_shell_BSD_Command, \
151  &rtems_shell_HOSTNAME_Command, \
152  &rtems_shell_PING_Command, \
153  &rtems_shell_ROUTE_Command, \
154  &rtems_shell_NETSTAT_Command, \
155  &rtems_shell_IFCONFIG_Command, \
156  &rtems_shell_TCPDUMP_Command, \
157  &rtems_shell_SYSCTL_Command
158
159#define CONFIGURE_SHELL_COMMAND_CPUUSE
160#define CONFIGURE_SHELL_COMMAND_PERIODUSE
161#define CONFIGURE_SHELL_COMMAND_STACKUSE
162#define CONFIGURE_SHELL_COMMAND_PROFREPORT
163
164#define CONFIGURE_SHELL_COMMAND_CP
165#define CONFIGURE_SHELL_COMMAND_PWD
166#define CONFIGURE_SHELL_COMMAND_LS
167#define CONFIGURE_SHELL_COMMAND_LN
168#define CONFIGURE_SHELL_COMMAND_LSOF
169#define CONFIGURE_SHELL_COMMAND_CHDIR
170#define CONFIGURE_SHELL_COMMAND_CD
171#define CONFIGURE_SHELL_COMMAND_MKDIR
172#define CONFIGURE_SHELL_COMMAND_RMDIR
173#define CONFIGURE_SHELL_COMMAND_CAT
174#define CONFIGURE_SHELL_COMMAND_MV
175#define CONFIGURE_SHELL_COMMAND_RM
176#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
177#define CONFIGURE_SHELL_COMMAND_SHUTDOWN
178
179#include <rtems/shellconfig.h>
180#endif /* RCCONF02_HAS_SHELL */
181
182#define RTEMS_BSD_CONFIG_BSP_CONFIG
183#define RTEMS_BSD_CONFIG_SERVICE_FTPD
184
185#include <rtems/bsd/test/default-init.h>
Note: See TracBrowser for help on using the repository browser.