From bf6effc9203e0b0a2bd393f0c0d4968541080f78 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Wed, 11 May 2022 16:01:48 -0300 Subject: [PATCH] build: Improve ns3rc parsing to support multiline list/skip comments --- build-support/macros-and-definitions.cmake | 12 +++++++ utils/tests/test-ns3.py | 41 +++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 0c6dff4b3..b380a2e12 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -1733,8 +1733,20 @@ function(parse_ns3rc enabled_modules examples_enabled tests_enabled) string(REPLACE "'" "" ${enabled_modules} "${${enabled_modules}}") string(REPLACE "\"" "" ${enabled_modules} "${${enabled_modules}}") string(REPLACE " " "" ${enabled_modules} "${${enabled_modules}}") + string(REPLACE "\n" ";" ${enabled_modules} "${${enabled_modules}}") + list(SORT ${enabled_modules}) + + # Remove possibly empty entry + list(REMOVE_ITEM ${enabled_modules} "") + foreach(element ${${enabled_modules}}) + # Inspect each element for comments + if(${element} MATCHES "#.*") + list(REMOVE_ITEM ${enabled_modules} ${element}) + endif() + endforeach() endif() endif() + # Match examples_enabled flag if(ns3rc_contents MATCHES "examples_enabled = (True|False)") set(${examples_enabled} ${CMAKE_MATCH_1}) diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index ebb0bc030..05a5216ab 100644 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -672,7 +672,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertTrue(get_test_enabled()) self.assertEqual(len(get_programs_list()), len(self.ns3_executables)) - # Replace the ns3rc file + # Replace the ns3rc file with the wifi module, enabling examples and disabling tests with open(ns3rc_script, "w") as f: f.write(ns3rc_template.format(modules="'wifi'", examples="True", tests="False")) @@ -687,6 +687,45 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertFalse(get_test_enabled()) self.assertGreater(len(get_programs_list()), len(self.ns3_executables)) + # Replace the ns3rc file with multiple modules + with open(ns3rc_script, "w") as f: + f.write(ns3rc_template.format(modules="'core','network'", examples="True", tests="False")) + + # Reconfigure + return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"") + self.config_ok(return_code, stdout) + + # Check + enabled_modules = get_enabled_modules() + self.assertLess(len(get_enabled_modules()), len(self.ns3_modules)) + self.assertIn("ns3-core", enabled_modules) + self.assertIn("ns3-network", enabled_modules) + self.assertFalse(get_test_enabled()) + self.assertGreater(len(get_programs_list()), len(self.ns3_executables)) + + # Replace the ns3rc file with multiple modules, + # in various different ways and with comments + with open(ns3rc_script, "w") as f: + f.write(ns3rc_template.format(modules="""'core', #comment + 'lte', + #comment2, + #comment3 + 'network', 'internet','wimax'""", examples="True", tests="True")) + + # Reconfigure + return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\"") + self.config_ok(return_code, stdout) + + # Check + enabled_modules = get_enabled_modules() + self.assertLess(len(get_enabled_modules()), len(self.ns3_modules)) + self.assertIn("ns3-core", enabled_modules) + self.assertIn("ns3-internet", enabled_modules) + self.assertIn("ns3-lte", enabled_modules) + self.assertIn("ns3-wimax", enabled_modules) + self.assertTrue(get_test_enabled()) + self.assertGreater(len(get_programs_list()), len(self.ns3_executables)) + # Then we roll back by removing the ns3rc config file os.remove(ns3rc_script)