Add a services base test.

This commit is contained in:
Chris Johns 2016-06-27 13:25:48 +10:00
parent 55c564a028
commit 7439724ac3
3 changed files with 236 additions and 58 deletions

View File

@ -2540,6 +2540,7 @@ def tests(mm):
mod.addTest(mm.generator['test']('lagg01', ['test_main'], netTest = True))
mod.addTest(mm.generator['test']('log01', ['test_main']))
mod.addTest(mm.generator['test']('rcconf01', ['test_main']))
mod.addTest(mm.generator['test']('rcconf02', ['test_main']))
return mod
#

View File

@ -1389,6 +1389,16 @@ def build(bld):
lib = ["m", "z"],
install_path = None)
test_rcconf02 = ['testsuite/rcconf02/test_main.c']
bld.program(target = "rcconf02.exe",
features = "cprogram",
cflags = cflags,
includes = includes,
source = test_rcconf02,
use = ["bsd"],
lib = ["m", "z"],
install_path = None)
test_rwlock01 = ['testsuite/rwlock01/test_main.c']
bld.program(target = "rwlock01.exe",
features = "cprogram",

View File

@ -0,0 +1,167 @@
/*
* Copyright 2016 Chris Johns <chrisj@rtems.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <rtems/bsd/sys/param.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sysexits.h>
#include <unistd.h>
#include <machine/rtems-bsd-commands.h>
#include <machine/rtems-bsd-rc-conf.h>
#include <machine/rtems-bsd-rc-conf-services.h>
#include <rtems/bsd/test/network-config.h>
#include <rtems/console.h>
#include <rtems/shell.h>
#define TEST_NAME "LIBBSD RC.CONF 2"
#define IFACE_IPV4(iface) \
"ifconfig_" # iface " inet " NET_CFG_SELF_IP " netmask " NET_CFG_NETMASK "\n"
#define RC_CONF_IFACES \
IFACE_IPV4(dmc0) \
IFACE_IPV4(sm0) \
IFACE_IPV4(cgem0) \
IFACE_IPV4(fec0) \
IFACE_IPV4(em0) \
IFACE_IPV4(re0)
#define IFACE_VLAN(iface) \
"vlans_" # iface "=\"101 102\"\n" \
"ifconfig_" # iface "_101=\"inet 192.0.101.1/24\n" \
"ifconfig_" # iface "_102=\"inet 192.0.102.1/24\n"
#define RC_CONF_VLANS \
IFACE_VLAN(dmc0) \
IFACE_VLAN(sm0) \
IFACE_VLAN(cgem0) \
IFACE_VLAN(fec0) \
IFACE_VLAN(em0) \
IFACE_VLAN(re0)
static const char* rc_conf_text = \
"#\n" \
"# Tests rc.conf. Add every NIC\n" \
"#\n" \
"hostname=\"rctest\"\n" \
"\n" \
"create_args_myvlan=\"vlan 102\"\n" \
"create_args_yourvlan=\"vlan 202\"\n" \
"\n" \
RC_CONF_IFACES \
"\n" \
RC_CONF_VLANS \
"\n" \
"defaultrouter=\"" NET_CFG_GATEWAY_IP "\"\n" \
"n";
static void
test_rc_conf_script(void)
{
const char* ifconfg_args[] = {
"ifconfig", NULL
};
const char* netstat_args[] = {
"netstat", "-rn", NULL
};
printf("--------------- rc.conf -----------------\n");
printf(rc_conf_text);
printf("-----------------------------------------\n");
assert(rtems_bsd_run_rc_conf_script("internal", rc_conf_text, 15, true) == 0);
printf("-------------- IFCONFIG -----------------\n");
rtems_bsd_command_ifconfig(1, (char**) ifconfg_args);
printf("-------------- NETSTAT ------------------\n");
rtems_bsd_command_netstat(2, (char**) netstat_args);
printf("-----------------------------------------\n");
}
static void
test_main(void)
{
test_rc_conf_script();
rtems_shell_init(
"SHLL",
32 * 1024,
1,
CONSOLE_DEVICE_NAME,
false,
true,
NULL
);
exit(0);
}
#define CONFIGURE_SHELL_COMMANDS_INIT
#include <bsp/irq-info.h>
#include <rtems/netcmds-config.h>
#define CONFIGURE_SHELL_USER_COMMANDS \
&bsp_interrupt_shell_command, \
&rtems_shell_BSD_Command, \
&rtems_shell_HOSTNAME_Command, \
&rtems_shell_PING_Command, \
&rtems_shell_ROUTE_Command, \
&rtems_shell_NETSTAT_Command, \
&rtems_shell_IFCONFIG_Command, \
&rtems_shell_TCPDUMP_Command, \
&rtems_shell_SYSCTL_Command
#define CONFIGURE_SHELL_COMMAND_CPUUSE
#define CONFIGURE_SHELL_COMMAND_PERIODUSE
#define CONFIGURE_SHELL_COMMAND_STACKUSE
#define CONFIGURE_SHELL_COMMAND_PROFREPORT
#define CONFIGURE_SHELL_COMMAND_CP
#define CONFIGURE_SHELL_COMMAND_PWD
#define CONFIGURE_SHELL_COMMAND_LS
#define CONFIGURE_SHELL_COMMAND_LN
#define CONFIGURE_SHELL_COMMAND_LSOF
#define CONFIGURE_SHELL_COMMAND_CHDIR
#define CONFIGURE_SHELL_COMMAND_CD
#define CONFIGURE_SHELL_COMMAND_MKDIR
#define CONFIGURE_SHELL_COMMAND_RMDIR
#define CONFIGURE_SHELL_COMMAND_CAT
#define CONFIGURE_SHELL_COMMAND_MV
#define CONFIGURE_SHELL_COMMAND_RM
#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
#define CONFIGURE_SHELL_COMMAND_SHUTDOWN
#include <rtems/shellconfig.h>
#include <rtems/bsd/test/default-init.h>