[rtems-net-legacy PATCH] testsuites: Build testsuites/support as a static library

chrisj at rtems.org chrisj at rtems.org
Mon Jun 5 02:00:21 UTC 2023


From: Chris Johns <chrisj at rtems.org>

This avoids dependency issues if the source files are added
to separate program builds.
---
 netlegacy.py                    | 56 +++++----------------------------
 testsuites/ftp01/wscript        |  4 ++-
 testsuites/loopback/wscript     |  5 +--
 testsuites/networking01/wscript |  5 +--
 testsuites/pppd/wscript         |  4 ++-
 testsuites/resolve/wscript      |  8 ++---
 testsuites/support/wscript      | 47 +++++++++++++++++++++++++++
 testsuites/syscall01/wscript    |  5 +--
 testsuites/telnetd01/wscript    |  4 ++-
 testsuites/telnetd02/wscript    |  8 ++---
 testsuites/wscript              | 50 ++++++++++++++++++++++++++++-
 11 files changed, 130 insertions(+), 66 deletions(-)
 create mode 100644 testsuites/support/wscript

diff --git a/netlegacy.py b/netlegacy.py
index c1882e6..009b8b7 100644
--- a/netlegacy.py
+++ b/netlegacy.py
@@ -51,48 +51,7 @@ def version_header(bld):
     bld(target='include/machine/rtems-net-legacy.h',
         source='include/machine/rtems-net-legacy.h.in',
         rule=sed + ' < ${SRC} > ${TGT}',
-        update_outputs=True)
-
-
-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',
-        'NET_CFG_DOMAINNAME', 'NET_CFG_DNS_IP', 'NET_CFG_NTP_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)
+        shell=True)
 
 
 def options(opt):
@@ -105,10 +64,11 @@ def options(opt):
                      default='-O2',
                      dest='optimization',
                      help='Optimaization level (default: %default)')
-    copts.add_option('--enable-warnings',
-                     action='store_true',
-                     dest='warnings',
-                     help='Enable warnings for all sources (default: %default)')
+    copts.add_option(
+        '--enable-warnings',
+        action='store_true',
+        dest='warnings',
+        help='Enable warnings for all sources (default: %default)')
 
 
 def bsp_configure(conf, arch_bsp, mandatory=True):
@@ -164,7 +124,6 @@ def build(bld):
     ab = rtems.arch_bsp_name(bld.env.RTEMS_ARCH_BSP)
 
     version_header(bld)
-    net_config_header(bld)
 
     bld.add_group()
 
@@ -215,6 +174,7 @@ def build(bld):
                 header)
     bld.install_as(
         os.path.join(bld.env.PREFIX, arch_inc_path, 'machine',
-                     'rtems-net-legacy.h'), 'include/machine/rtems-net-legacy.h')
+                     'rtems-net-legacy.h'),
+        'include/machine/rtems-net-legacy.h')
 
     bld.add_group()
diff --git a/testsuites/ftp01/wscript b/testsuites/ftp01/wscript
index 550b0b5..6826584 100644
--- a/testsuites/ftp01/wscript
+++ b/testsuites/ftp01/wscript
@@ -39,11 +39,13 @@ def configure(conf):
 
 def build(bld):
     source = ['init.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='ftp01.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
                 lib=['ftpfs', 'ftpd', 'networking'],
                 libpath=['.'],
+                use=['testsupport'],
                 source=source,
                 install_path=False)
diff --git a/testsuites/loopback/wscript b/testsuites/loopback/wscript
index bc7bd9a..0350388 100644
--- a/testsuites/loopback/wscript
+++ b/testsuites/loopback/wscript
@@ -39,10 +39,11 @@ def configure(conf):
 
 def build(bld):
     source = ['init.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='loopback.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
-                use=['networking'],
+                use=['testsuppoprt', 'networking'],
                 source=source,
                 install_path=False)
diff --git a/testsuites/networking01/wscript b/testsuites/networking01/wscript
index d9917ff..c217577 100644
--- a/testsuites/networking01/wscript
+++ b/testsuites/networking01/wscript
@@ -39,10 +39,11 @@ def configure(conf):
 
 def build(bld):
     source = ['init.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='networking01.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
-                use=['networking'],
+                use=['testsupport', 'networking'],
                 source=source,
                 install_path=False)
diff --git a/testsuites/pppd/wscript b/testsuites/pppd/wscript
index a99cf5e..248c10b 100644
--- a/testsuites/pppd/wscript
+++ b/testsuites/pppd/wscript
@@ -39,11 +39,13 @@ def configure(conf):
 
 def build(bld):
     source = ['init.c', 'pppdapp.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld(target='pppd.exe',
         features='c cprogram',
-        cflags=bld.env.OPTIMIZATION + ['-g'],
+        cflags=cflags,
         includes=bld.env.IFLAGS,
         lib=['pppd', 'networking'],
+        use=['testsupport'],
         libpath=['.'],
         source=source,
         install_path=False)
diff --git a/testsuites/resolve/wscript b/testsuites/resolve/wscript
index 18ce5ea..6546ee5 100644
--- a/testsuites/resolve/wscript
+++ b/testsuites/resolve/wscript
@@ -37,13 +37,13 @@ def configure(conf):
 
 
 def build(bld):
-    legacy_config = bld.path.parent.find_node('support/net-legacy-config.c')
-    source = ['init.c', 'getaddrinfo_test.c', legacy_config]
+    source = ['init.c', 'getaddrinfo_test.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='resolve.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
-                lib=['networking'],
+                use=['testsupport', 'networking'],
                 libpath=['.'],
                 source=source,
                 install_path=False)
diff --git a/testsuites/support/wscript b/testsuites/support/wscript
new file mode 100644
index 0000000..433ee29
--- /dev/null
+++ b/testsuites/support/wscript
@@ -0,0 +1,47 @@
+#
+# RTEMS Project (https://www.rtems.org/)
+#
+# Copyright (c) 2023 Chris Johns <chris at contemporary.software>
+# 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 COPYRIGHT HOLDERS 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 COPYRIGHT
+#  OWNER 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.
+
+from rtems_waf import rtems
+
+
+def init(ctx):
+    pass
+
+
+def configure(conf):
+    pass
+
+
+def build(bld):
+    source = ['net-legacy-config.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
+    bld.stlib(target='testsupport',
+              features='c',
+              cflags=cflags,
+              includes=bld.env.IFLAGS,
+              source=source,
+              install_path=False)
diff --git a/testsuites/syscall01/wscript b/testsuites/syscall01/wscript
index c8fd30b..fd4bfad 100644
--- a/testsuites/syscall01/wscript
+++ b/testsuites/syscall01/wscript
@@ -39,10 +39,11 @@ def configure(conf):
 
 def build(bld):
     source = ['init.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='syscall01.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
-                use=['networking'],
+                use=['tetssupport', 'networking'],
                 source=source,
                 install_path=False)
diff --git a/testsuites/telnetd01/wscript b/testsuites/telnetd01/wscript
index fe8a447..6b9cf5e 100644
--- a/testsuites/telnetd01/wscript
+++ b/testsuites/telnetd01/wscript
@@ -39,11 +39,13 @@ def configure(conf):
 
 def build(bld):
     source = ['init.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='telnetd01.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
                 lib=['telnetd', 'networking'],
                 libpath=['.'],
+                use=['testsupport'],
                 source=source,
                 install_path=False)
diff --git a/testsuites/telnetd02/wscript b/testsuites/telnetd02/wscript
index 9a04c59..380b461 100644
--- a/testsuites/telnetd02/wscript
+++ b/testsuites/telnetd02/wscript
@@ -38,14 +38,14 @@ def configure(conf):
 
 
 def build(bld):
-    legacy_config = bld.path.parent.find_node('support/net-legacy-config.c')
-    source = ['init.c', legacy_config]
+    source = ['init.c']
+    cflags = bld.env.OPTIMIZATION + bld.env.WARNINGS + ['-g']
     bld.program(target='telnetd02.exe',
                 features='c cprogram',
-                cflags=bld.env.OPTIMIZATION + ['-g'],
+                cflags=cflags,
                 includes=bld.env.IFLAGS,
                 lib=['telnetd', 'networking'],
                 libpath=['.'],
                 source=source,
-                use=['networking'],
+                use=['testsupport', 'networking'],
                 install_path=False)
diff --git a/testsuites/wscript b/testsuites/wscript
index c0fd37d..0a7d997 100644
--- a/testsuites/wscript
+++ b/testsuites/wscript
@@ -26,13 +26,57 @@
 #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 #  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import os
+
 from rtems_waf import rtems
 
 subdirs = [
-    'ftp01', 'loopback', 'networking01', 'pppd', 'resolve', 'syscall01', 'telnetd01', 'telnetd02'
+    'ftp01', 'loopback', 'networking01', 'pppd', 'resolve', 'syscall01',
+    'telnetd01', 'telnetd02'
 ]
 
 
+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',
+        'NET_CFG_DOMAINNAME', 'NET_CFG_DNS_IP', 'NET_CFG_NTP_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=bld.path.find_node('include/network-config.h.in'),
+        rule=sed + ' < ${SRC} > ${TGT}',
+        shell=True)
+
+
 def recurse(ctx):
     for sd in subdirs:
         ctx.recurse(sd)
@@ -55,4 +99,8 @@ def configure(conf):
 
 
 def build(bld):
+    net_config_header(bld)
+    bld.add_group()
+    bld.recurse('support')
+    bld.add_group()
     recurse(bld)
-- 
2.37.1



More information about the devel mailing list