From 71c1fba5a0dfab4264e843adeff8fcbd6f1e89bc Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Sat, 1 Apr 2023 17:02:06 -0300 Subject: [PATCH] build: do not build the test object library when tests are disabled --- build-support/macros-and-definitions.cmake | 6 ++---- utils/tests/test-ns3.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 34476a9f5..e5e74e567 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -410,6 +410,8 @@ macro(process_options) if(${NS3_TESTS} OR ${ns3rc_tests_enabled}) set(ENABLE_TESTS ON) enable_testing() + else() + list(REMOVE_ITEM libs_to_build test) endif() set(profiles_without_suffixes release) @@ -1929,10 +1931,6 @@ macro( unset(dependencies) unset(contrib_dependencies) endforeach() - - if(core IN_LIST ${libs_to_build}) - list(APPEND ${libs_to_build} test) # include test module - endif() endif() if(${NS3_DISABLED_MODULES} OR ${ns3rc_disabled_modules}) diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index c0b33810e..43103a44f 100755 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -970,7 +970,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertLess(len(get_enabled_modules()), len(self.ns3_modules)) self.assertIn("ns3-lte", enabled_modules) self.assertTrue(get_test_enabled()) - self.assertGreaterEqual(len(get_programs_list()), len(self.ns3_executables)) + self.assertLessEqual(len(get_programs_list()), len(self.ns3_executables)) # Replace the ns3rc file with the wifi module, enabling examples and disabling tests with open(ns3rc_script, "w") as f: @@ -1839,6 +1839,21 @@ class NS3ConfigureTestCase(NS3BaseTestCase): except DockerException as e: self.assertTrue(False, "Precompiled headers should have been enabled") + def test_24_CheckTestSettings(self): + """! + Check for regressions in test object build. + @return None + """ + return_code, stdout, stderr = run_ns3('configure') + self.assertEqual(return_code, 0) + + test_module_cache = os.path.join(ns3_path, "cmake-cache", "src", "test") + self.assertFalse(os.path.exists(test_module_cache)) + + return_code, stdout, stderr = run_ns3('configure --enable-tests') + self.assertEqual(return_code, 0) + self.assertTrue(os.path.exists(test_module_cache)) + class NS3BuildBaseTestCase(NS3BaseTestCase): """!