diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index 5006bd8c3..ffa42972c 100755 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -701,9 +701,6 @@ class NS3BaseTestCase(unittest.TestCase): Generic test case with basic function inherited by more complex tests. """ - ## when cleaned_once is False, clean up build artifacts and reconfigure # noqa - cleaned_once = False - def config_ok(self, return_code, stdout): """! Check if configuration for release mode worked normally @@ -727,12 +724,10 @@ class NS3BaseTestCase(unittest.TestCase): if os.path.exists(ns3rc_script): os.remove(ns3rc_script) - # We only clear it once and then update the settings by changing flags or consuming ns3rc. - if not NS3BaseTestCase.cleaned_once: - NS3BaseTestCase.cleaned_once = True - run_ns3("clean") - return_code, stdout, stderr = run_ns3("configure -G \"{generator}\" -d release --enable-verbose") - self.config_ok(return_code, stdout) + # Reconfigure from scratch before each test + run_ns3("clean") + return_code, stdout, stderr = run_ns3("configure -G \"{generator}\" -d release --enable-verbose") + self.config_ok(return_code, stdout) # Check if .lock-ns3 exists, then read to get list of executables. self.assertTrue(os.path.exists(ns3_lock_filename)) @@ -750,17 +745,11 @@ class NS3ConfigureTestCase(NS3BaseTestCase): Test ns3 configuration options """ - ## when cleaned_once is False, clean up build artifacts and reconfigure # noqa - cleaned_once = False - def setUp(self): """! Reuse cleaning/release configuration from NS3BaseTestCase if flag is cleaned @return None """ - if not NS3ConfigureTestCase.cleaned_once: - NS3ConfigureTestCase.cleaned_once = True - NS3BaseTestCase.cleaned_once = False super().setUp() def test_01_Examples(self): @@ -1189,7 +1178,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): """ return_code, stdout, stderr = run_ns3("show profile") self.assertEqual(return_code, 0) - self.assertIn("Build profile: default", stdout) + self.assertIn("Build profile: release", stdout) def test_12_CheckVersion(self): """! @@ -1484,9 +1473,6 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertIn("--profiling-format=google-trace --profiling-output=../cmake_performance_trace.log", stdout) self.assertTrue(os.path.exists(os.path.join(ns3_path, "cmake_performance_trace.log"))) - # Reconfigure to clean leftovers before the next test - NS3ConfigureTestCase.cleaned_once = False - def test_18_CheckBuildVersionAndVersionCache(self): """! Check if ENABLE_BUILD_VERSION and version.cache are working @@ -1568,9 +1554,6 @@ class NS3ConfigureTestCase(NS3BaseTestCase): if os.path.exists(version_cache_file): os.remove(version_cache_file) - # Reconfigure to clean leftovers before the next test - NS3ConfigureTestCase.cleaned_once = False - def test_19_FilterModuleExamplesAndTests(self): """! Test filtering in examples and tests from specific modules @@ -1664,8 +1647,13 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # Delete mold leftovers os.remove("./mold-1.4.2-x86_64-linux.tar.gz") - # Clean leftovers before proceeding - run_ns3("clean") + # Disable use of fast linkers + container.execute("./ns3 configure -G Ninja -- -DNS3_FAST_LINKERS=OFF") + + # Check if configuration properly disabled lld/mold usage + self.assertTrue(os.path.exists(os.path.join(ns3_path, "cmake-cache", "build.ninja"))) + with open(os.path.join(ns3_path, "cmake-cache", "build.ninja"), "r") as f: + self.assertNotIn("-fuse-ld=mold", f.read()) def test_21_ClangTimeTrace(self): """! @@ -1721,9 +1709,6 @@ class NS3ConfigureTestCase(NS3BaseTestCase): except DockerException as e: self.assertIn("TimeTrace is a Clang feature", e.stderr) - # Clean leftovers before proceeding - run_ns3("clean") - def test_22_NinjaTrace(self): """! Check if NS3_NINJA_TRACE feature is working @@ -1807,9 +1792,6 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # Check if timetrace's trace is bigger than the original trace (it should be) self.assertGreater(timetrace_size, trace_size) - # Clean leftovers before proceeding - run_ns3("clean") - def test_23_PrecompiledHeaders(self): """! Check if precompiled headers are being enabled correctly. @@ -1852,26 +1834,17 @@ class NS3ConfigureTestCase(NS3BaseTestCase): except DockerException as e: self.assertTrue(False, "Precompiled headers should have been enabled") - # Clean build system leftovers - run_ns3("clean") - class NS3BuildBaseTestCase(NS3BaseTestCase): """! Tests ns3 regarding building the project """ - ## when cleaned_once is False, clean up build artifacts and reconfigure # noqa - cleaned_once = False - def setUp(self): """! Reuse cleaning/release configuration from NS3BaseTestCase if flag is cleaned @return None """ - if not NS3BuildBaseTestCase.cleaned_once: - NS3BuildBaseTestCase.cleaned_once = True - NS3BaseTestCase.cleaned_once = False super().setUp() self.ns3_libraries = get_libraries_list() @@ -1937,9 +1910,6 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): return_code, stdout, stderr = run_ns3("build") self.assertEqual(return_code, 0) - # Reset flag to let it clean the build - NS3BuildBaseTestCase.cleaned_once = False - def test_06_TestVersionFile(self): """! Test if changing the version file affects the library names @@ -1984,9 +1954,6 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): with open(version_file, "w") as f: f.write("3-dev\n") - # Reset flag to let it clean the build. - NS3BuildBaseTestCase.cleaned_once = False - def test_07_OutputDirectory(self): """! Try setting a different output directory and if everything is @@ -2212,9 +2179,6 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): with open(version_file, "w") as f: f.write("3-dev\n") - # Reset flag to let it clean the build - NS3BuildBaseTestCase.cleaned_once = False - def test_09_Scratches(self): """! Tries to build scratch-simulator and subdir/scratch-simulator-subdir @@ -2242,8 +2206,6 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): stdout = stdout.replace("scratch_%s" % target_cmake, "") # remove build lines self.assertIn(target_to_run.split("/")[-1].replace(".cc", ""), stdout) - NS3BuildBaseTestCase.cleaned_once = False - def test_10_AmbiguityCheck(self): """! Test if ns3 can alert correctly in case a shortcut collision happens @@ -2298,8 +2260,6 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): # Remove second os.remove("./scratch/second.cc") - NS3BuildBaseTestCase.cleaned_once = False - def test_11_StaticBuilds(self): """! Test if we can build a static ns-3 library and link it to static programs @@ -2325,7 +2285,6 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): self.assertIn("Built target", stdout) # Maybe check the built binary for shared library references? Using objdump, otool, etc - NS3BuildBaseTestCase.cleaned_once = False def test_12_CppyyBindings(self): """! @@ -2362,24 +2321,19 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase): Tests ns3 usage in more realistic scenarios """ - ## when cleaned_once is False, clean up build artifacts and reconfigure # noqa - cleaned_once = False - def setUp(self): """! Reuse cleaning/release configuration from NS3BaseTestCase if flag is cleaned Here examples, tests and documentation are also enabled. @return None """ - if not NS3ExpectedUseTestCase.cleaned_once: - NS3ExpectedUseTestCase.cleaned_once = True - NS3BaseTestCase.cleaned_once = False - super().setUp() - # On top of the release build configured by NS3ConfigureTestCase, also enable examples, tests and docs. - return_code, stdout, stderr = run_ns3( - "configure -d release -G \"{generator}\" --enable-examples --enable-tests") - self.config_ok(return_code, stdout) + super().setUp() + + # On top of the release build configured by NS3ConfigureTestCase, also enable examples, tests and docs. + return_code, stdout, stderr = run_ns3( + "configure -d release -G \"{generator}\" --enable-examples --enable-tests") + self.config_ok(return_code, stdout) # Check if .lock-ns3 exists, then read to get list of executables. self.assertTrue(os.path.exists(ns3_lock_filename)) @@ -2441,6 +2395,9 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase): Try to run test-runner without building @return None """ + return_code, stdout, stderr = run_ns3('build test-runner') + self.assertEqual(return_code, 0) + return_code, stdout, stderr = run_ns3('run "test-runner --list" --no-build --verbose') self.assertEqual(return_code, 0) self.assertNotIn("Built target test-runner", stdout) @@ -2472,6 +2429,9 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase): if shutil.which("gdb") is None: self.skipTest("Missing gdb") + return_code, stdout, stderr = run_ns3("build scratch-simulator") + self.assertEqual(return_code, 0) + return_code, stdout, stderr = run_ns3("run scratch-simulator --gdb --verbose --no-build", env={"gdb_eval": "1"}) self.assertEqual(return_code, 0) self.assertIn("scratch-simulator", stdout) @@ -2488,6 +2448,9 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase): if shutil.which("valgrind") is None: self.skipTest("Missing valgrind") + return_code, stdout, stderr = run_ns3("build scratch-simulator") + self.assertEqual(return_code, 0) + return_code, stdout, stderr = run_ns3("run scratch-simulator --valgrind --verbose --no-build") self.assertEqual(return_code, 0) self.assertIn("scratch-simulator", stderr) @@ -2947,9 +2910,6 @@ class NS3QualityControlTestCase(unittest.TestCase): self.assertEqual(return_code, 0) test_return_code, stdout, stderr = run_program("test.py", "", python=True) - - return_code, stdout, stderr = run_ns3("clean") - self.assertEqual(return_code, 0) self.assertEqual(test_return_code, 0) def test_03_CheckImageBrightness(self):