[rtems-net-legacy PATCH v2 1/2] waf: Add test network configuration support
chrisj at rtems.org
chrisj at rtems.org
Thu Apr 6 05:15:36 UTC 2023
From: Chris Johns <chrisj at rtems.org>
- Add a support call to use the configuration
---
config.inc | 6 ++
netlegacy.py | 82 ++++++++++++++++++++++++--
testsuites/include/net-legacy-config.h | 18 ++++++
testsuites/include/network-config.h.in | 41 +++++++++++++
testsuites/support/net-legacy-config.c | 53 +++++++++++++++++
wscript | 6 ++
6 files changed, 201 insertions(+), 5 deletions(-)
create mode 100644 config.inc
create mode 100644 testsuites/include/net-legacy-config.h
create mode 100755 testsuites/include/network-config.h.in
create mode 100644 testsuites/support/net-legacy-config.c
diff --git a/config.inc b/config.inc
new file mode 100644
index 0000000..56497b3
--- /dev/null
+++ b/config.inc
@@ -0,0 +1,6 @@
+NET_CFG_IFACE = lo0
+NET_CFG_BOOT_PROT = dhcp
+NET_CFG_SELF_IP = 127.0.0.1
+NET_CFG_NETMASK = 255.0.0.0
+NET_CFG_MAC_ADDR = 00:00:00:00:00:00
+NET_CFG_GATEWAY_IP = 0.0.0.0
diff --git a/netlegacy.py b/netlegacy.py
index 7897a2c..60775dc 100644
--- a/netlegacy.py
+++ b/netlegacy.py
@@ -35,8 +35,56 @@ import bsp_drivers
import netsources
+def net_config_header(bld):
+ if not os.path.exists(bld.env.NET_CONFIG):
+ bld.fatal('network configuraiton \'%s\' not found' %
+ (bld.env.NET_CONFIG))
+ net_tags = [
+ 'NET_CFG_IFACE', 'NET_CFG_BOOT_PROT', 'NET_CFG_SELF_IP',
+ 'NET_CFG_NETMASK', 'NET_CFG_MAC_ADDR', 'NET_CFG_GATEWAY_IP'
+ ]
+ try:
+ net_cfg_lines = open(bld.env.NET_CONFIG).readlines()
+ except:
+ bld.fatal('network configuraiton \'%s\' read failed' %
+ (bld.env.NET_CONFIG))
+ lc = 0
+ sed = 'sed '
+ net_defaults = {}
+ for l in net_cfg_lines:
+ lc += 1
+ if not l.strip().startswith('NET_CFG_'):
+ bld.fatal('network configuration \'%s\' ' \
+ 'invalid config: %d: %s' % (bld.env.NET_CONFIG, lc, l))
+ ls = l.split('=')
+ if len(ls) != 2:
+ bld.fatal('network configuration \'%s\' ' \
+ 'parse error: %d: %s' % (bld.env.NET_CONFIG, lc, l))
+ lhs = ls[0].strip()
+ rhs = ls[1].strip()
+ if lhs in net_tags:
+ net_defaults[lhs] = rhs
+ else:
+ bld.fatal('network configuration \'%s\' ' \
+ 'invalid config: %d: %s' % (bld.env.NET_CONFIG, lc, l))
+ for cfg in net_defaults:
+ sed += "-e 's/@%s@/%s/' " % (cfg, net_defaults[cfg])
+ bld(target=bld.env.NETWORK_CONFIG,
+ source='testsuites/include/network-config.h.in',
+ rule=sed + ' < ${SRC} > ${TGT}',
+ update_outputs=True)
+
+
def options(opt):
- pass
+ copts = opt.option_groups['configure options']
+ copts.add_option('--net-test-config',
+ default='config.inc',
+ dest='net_config',
+ help='Network test configuration (default: %default)')
+ copts.add_option('--optimization',
+ default='-O2',
+ dest='optimization',
+ help='Optimaization level (default: %default)')
def bsp_configure(conf, arch_bsp, mandatory=True):
@@ -49,15 +97,39 @@ def bsp_configure(conf, arch_bsp, mandatory=True):
]
if ab in bsp_drivers.include:
includes += bsp_drivers.include[ab]
- conf.env.IFLAGS = [str(conf.path.find_node(i))
- for i in includes] + conf.env.IFLAGS
- conf.env.OPTIMIZATION = ['-O2']
+ bld_inc = conf.path.get_bld().find_or_declare('include')
+ conf.env.NETWORK_CONFIG = str(bld_inc.find_or_declare('network-config.h'))
+ conf.env.IFLAGS = [str(bld_inc)
+ ] + [str(conf.path.find_node(i))
+ for i in includes] + conf.env.IFLAGS
+ conf.env.OPTIMIZATION = [conf.options.optimization]
+ #
+ # BSPs must define:
+ # - RTEMS_BSP_NETWORK_DRIVER_NAME
+ # - RTEMS_BSP_NETWORK_DRIVER_ATTACH
+ #
+ for define in [
+ 'RTEMS_BSP_NETWORK_DRIVER_NAME', 'RTEMS_BSP_NETWORK_DRIVER_ATTACH'
+ ]:
+ code = ['#include <bspopts.h>']
+ code += ['#include <bsp.h>']
+ code += ['#ifndef %s' % (define)]
+ code += [' #error %s not defined' % (define)]
+ code += ['#endif']
+ try:
+ conf.check_cc(fragment=rtems.test_application(code),
+ execute=False,
+ msg='Checking for %s' % (define))
+ except conf.errors.WafError:
+ conf.fatal(ab + ' does not provide %s' % (define))
def build(bld):
arch_bsp = bld.env.RTEMS_ARCH_BSP
ab = rtems.arch(arch_bsp) + '/' + rtems.bsp(arch_bsp)
+ net_config_header(bld)
+
if ab in bsp_drivers.source:
bld(target='bspobjs',
features='c',
@@ -94,7 +166,7 @@ def build(bld):
bld.env.RTEMS_ARCH_BSP)
bld.install_files(os.path.join(bld.env.PREFIX, arch_lib_path),
- ["libnetworking.a", 'libpppd.a', 'libnfs.a'])
+ ['libnetworking.a', 'libpppd.a', 'libnfs.a'])
for inc_dir in netsources.header:
for header in netsources.header[inc_dir]:
hname = os.path.basename(header)
diff --git a/testsuites/include/net-legacy-config.h b/testsuites/include/net-legacy-config.h
new file mode 100644
index 0000000..e4e5579
--- /dev/null
+++ b/testsuites/include/net-legacy-config.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2023 Chris Johns. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _NET_LEGACY_CONFIG_H
+#define _NET_LEGACY_CONFIG_H
+
+#include <stdbool.h>
+
+struct rtems_bsdnet_config;
+
+bool rtems_net_legacy_config(struct rtems_bsdnet_config* bsd);
+
+#endif
diff --git a/testsuites/include/network-config.h.in b/testsuites/include/network-config.h.in
new file mode 100755
index 0000000..756e3b5
--- /dev/null
+++ b/testsuites/include/network-config.h.in
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023 Chris Johns. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef _TEST_NETWORK_CONFIG_H_
+#define _TEST_NETWORK_CONFIG_H_
+
+#define NET_CFG_IFACE "@NET_CFG_IFACE@"
+
+#define NET_CFG_BOOT_PROT "@NET_CFG_BOOT_PROT@"
+
+#define NET_CFG_SELF_IP "@NET_CFG_SELF_IP@"
+
+#define NET_CFG_NETMASK "@NET_CFG_NETMASK@"
+
+#define NET_CFG_MAC_ADDR "@NET_CFG_MAC_ADDR@"
+
+#define NET_CFG_GATEWAY_IP "@NET_CFG_GATEWAY_IP@"
+
+#endif /* _TEST_NETWORK_CONFIG_H_ */
diff --git a/testsuites/support/net-legacy-config.c b/testsuites/support/net-legacy-config.c
new file mode 100644
index 0000000..bb512d2
--- /dev/null
+++ b/testsuites/support/net-legacy-config.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023 Chris Johns. All rights reserved.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <bsp.h>
+#include <rtems.h>
+#include <rtems/dhcp.h>
+#include <rtems/rtems_bsdnet.h>
+
+#include <net-legacy-config.h>
+#include <network-config.h>
+
+static char* iface = NET_CFG_IFACE;
+static char* boot_prot = NET_CFG_BOOT_PROT;
+static char* ip = NET_CFG_SELF_IP;
+static char* netmask = NET_CFG_NETMASK;
+static char* gateway = NET_CFG_GATEWAY_IP;
+static struct rtems_bsdnet_ifconfig ifcfg = {
+ RTEMS_BSP_NETWORK_DRIVER_NAME,
+ RTEMS_BSP_NETWORK_DRIVER_ATTACH
+};
+
+bool rtems_net_legacy_config(struct rtems_bsdnet_config* bsd) {
+ if (bsd->ifconfig == NULL) {
+ bsd->ifconfig = &ifcfg;
+ }
+ ifcfg.name = iface;
+ ifcfg.ip_address = ip;
+ ifcfg.ip_netmask = netmask;
+ bsd->gateway = gateway;
+ if (strcmp(boot_prot, "static") == 0) {
+ bsd->bootp = NULL;
+ } else if (strcmp(boot_prot, "bootp") == 0) {
+ bsd->bootp = rtems_bsdnet_do_bootp;
+ } else if (strcmp(boot_prot, "dhcp") == 0) {
+ bsd->bootp = rtems_bsdnet_do_dhcp;
+ } else {
+ printf("%s: %d: invalid network configuration: %s\n",
+ __FILE__, __LINE__, boot_prot);
+ return false;
+ }
+ return true;
+}
diff --git a/wscript b/wscript
index b146db6..c365f14 100644
--- a/wscript
+++ b/wscript
@@ -51,6 +51,11 @@ def init(ctx):
def options(opt):
rtems.options(opt)
netlegacy.options(opt)
+ copts = opt.option_groups['configure options']
+ copts.add_option('--net-test-config',
+ default='config.inc',
+ dest='net_config',
+ help='Network test configuration (default: %default)')
def bsp_configure(conf, arch_bsp):
@@ -63,6 +68,7 @@ def bsp_configure(conf, arch_bsp):
def configure(conf):
+ conf.env.NET_CONFIG = conf.options.net_config
rtems.configure(conf, bsp_configure)
--
2.37.1
More information about the devel
mailing list