build: Drop lib prefix from module targets

This commit is contained in:
Gabriel Ferreira
2024-06-11 17:51:25 +02:00
parent e0714d3119
commit 0d051e6705
4 changed files with 81 additions and 78 deletions

View File

@@ -23,6 +23,7 @@ Test suite for the ns3 wrapper script
import glob
import os
import platform
import re
import shutil
import subprocess
@@ -54,6 +55,7 @@ cmake_build_target_command = partial(
win32 = sys.platform == "win32"
platform_makefiles = "MinGW Makefiles" if win32 else "Unix Makefiles"
ext = ".exe" if win32 else ""
arch = platform.machine()
def run_ns3(args, env=None, generator=platform_makefiles):
@@ -695,7 +697,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
# Build core to check if profile suffixes match the expected.
return_code, stdout, stderr = run_ns3("build core")
self.assertEqual(return_code, 0)
self.assertIn("Built target libcore", stdout)
self.assertIn("Built target core", stdout)
libraries = get_libraries_list()
self.assertGreater(len(libraries), 0)
@@ -726,7 +728,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase):
# Build core to check if profile suffixes match the expected
return_code, stdout, stderr = run_ns3("build core")
self.assertEqual(return_code, 0)
self.assertIn("Built target libcore", stdout)
self.assertIn("Built target core", stdout)
libraries = get_libraries_list()
self.assertGreater(len(libraries), 0)
@@ -888,7 +890,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
# If nothing went wrong, this should have worked
self.assertEqual(return_code, 0)
self.assertIn("Built target libcore-test", stdout)
self.assertIn("Built target core-test", stdout)
# Now we disabled the tests
return_code, stdout, stderr = run_ns3('configure -G "{generator}" --disable-tests')
@@ -1079,7 +1081,9 @@ 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.assertLessEqual(len(get_programs_list()), len(self.ns3_executables))
self.assertLessEqual(
len(get_programs_list()), len(self.ns3_executables) + (1 if win32 else 0)
)
# Replace the ns3rc file with the wifi module, enabling examples and disabling tests
with open(ns3rc_script, "w", encoding="utf-8") as f:
@@ -1359,6 +1363,14 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
f.write("")
# Reload the cmake cache to pick them up
# It will fail because the empty scratch has no main function
return_code, stdout, stderr = run_ns3('configure -G "{generator}"')
self.assertEqual(return_code, 1)
# Remove the empty.cc file and try again
empty = "scratch/empty.cc"
os.remove(empty)
test_files.remove(empty)
return_code, stdout, stderr = run_ns3('configure -G "{generator}"')
self.assertEqual(return_code, 0)
@@ -1388,7 +1400,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertEqual(return_code, 1)
run_ns3("clean")
with DockerContainerManager(self, "ubuntu:20.04") as container:
with DockerContainerManager(self, "ubuntu:22.04") as container:
container.execute("apt-get update")
container.execute("apt-get install -y python3 cmake g++ ninja-build")
try:
@@ -1632,7 +1644,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
# Check if we can build this library
return_code, stdout, stderr = run_ns3("build calibre")
self.assertEqual(return_code, 0)
self.assertIn(cmake_build_target_command(target="libcalibre"), stdout)
self.assertIn(cmake_build_target_command(target="calibre"), stdout)
shutil.rmtree("contrib/calibre", ignore_errors=True)
@@ -1816,12 +1828,12 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertTrue(False, "Build with lld failed")
# Now add mold to the PATH
if not os.path.exists("./mold-1.4.2-x86_64-linux.tar.gz"):
if not os.path.exists(f"./mold-1.4.2-{arch}-linux.tar.gz"):
container.execute(
"wget https://github.com/rui314/mold/releases/download/v1.4.2/mold-1.4.2-x86_64-linux.tar.gz"
f"wget https://github.com/rui314/mold/releases/download/v1.4.2/mold-1.4.2-{arch}-linux.tar.gz"
)
container.execute(
"tar xzfC mold-1.4.2-x86_64-linux.tar.gz /usr/local --strip-components=1"
f"tar xzfC mold-1.4.2-{arch}-linux.tar.gz /usr/local --strip-components=1"
)
# Configure should detect and use mold
@@ -1842,7 +1854,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
self.assertTrue(False, "Build with mold failed")
# Delete mold leftovers
os.remove("./mold-1.4.2-x86_64-linux.tar.gz")
os.remove(f"./mold-1.4.2-{arch}-linux.tar.gz")
# Disable use of fast linkers
container.execute("./ns3 configure -G Ninja -- -DNS3_FAST_LINKERS=OFF")
@@ -1862,14 +1874,14 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
"""
run_ns3("clean")
with DockerContainerManager(self, "ubuntu:20.04") as container:
with DockerContainerManager(self, "ubuntu:22.04") as container:
container.execute("apt-get update")
container.execute("apt-get install -y python3 ninja-build cmake clang-10")
container.execute("apt-get install -y python3 ninja-build cmake clang-12")
# Enable ClangTimeTrace without git (it should fail)
try:
container.execute(
"./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-10 -DNS3_CLANG_TIMETRACE=ON"
"./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -DNS3_CLANG_TIMETRACE=ON"
)
except DockerException as e:
self.assertIn("could not find git for clone of ClangBuildAnalyzer", e.stderr)
@@ -1879,7 +1891,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
# Enable ClangTimeTrace without git (it should succeed)
try:
container.execute(
"./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-10 -DNS3_CLANG_TIMETRACE=ON"
"./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -DNS3_CLANG_TIMETRACE=ON"
)
except DockerException as e:
self.assertIn("could not find git for clone of ClangBuildAnalyzer", e.stderr)
@@ -1901,7 +1913,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
# Now try with GCC, which should fail during the configuration
run_ns3("clean")
container.execute("apt-get install -y g++")
container.execute("apt-get remove -y clang-10")
container.execute("apt-get remove -y clang-12")
try:
container.execute(
@@ -2008,18 +2020,6 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
run_ns3("clean")
# Ubuntu 20.04 ships with:
# - cmake 3.16: does support PCH
# - ccache 3.7: incompatible with pch
with DockerContainerManager(self, "ubuntu:20.04") as container:
container.execute("apt-get update")
container.execute("apt-get install -y python3 cmake ccache g++")
try:
container.execute("./ns3 configure")
except DockerException as e:
self.assertIn("incompatible with ccache", e.stderr)
run_ns3("clean")
# Ubuntu 22.04 ships with:
# - cmake 3.22: does support PCH
# - ccache 4.5: compatible with pch
@@ -2054,7 +2054,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
run_ns3("clean")
with DockerContainerManager(self, "ubuntu:20.04") as container:
with DockerContainerManager(self, "ubuntu:22.04") as container:
container.execute("apt-get update")
container.execute("apt-get install -y python3 cmake g++")
return_code = 0
@@ -2089,7 +2089,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
"""
return_code, stdout, stderr = run_ns3("build core")
self.assertEqual(return_code, 0)
self.assertIn("Built target libcore", stdout)
self.assertIn("Built target core", stdout)
def test_02_BuildNonExistingTargets(self):
"""!
@@ -2340,8 +2340,8 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
# Import ns-3 libraries with as a CMake package
cmake_find_package_import = """
list(APPEND CMAKE_PREFIX_PATH ./{lib}/cmake/ns3)
find_package(ns3 {version} COMPONENTS libcore)
target_link_libraries(test PRIVATE ns3::libcore)
find_package(ns3 {version} COMPONENTS core)
target_link_libraries(test PRIVATE ns3::core)
""".format(
lib=("lib64" if lib64 else "lib"), version=version
)
@@ -2394,7 +2394,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
stderr.replace("\n", ""),
)
elif import_method == pkgconfig_import:
self.assertIn("A required package was not found", stderr.replace("\n", ""))
self.assertIn("not found", stderr.replace("\n", ""))
else:
raise Exception("Unknown import type")
else:
@@ -2405,7 +2405,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
return_code, stdout, stderr = run_program("cmake", "--build .", cwd=install_prefix)
if version == "3.00":
self.assertEqual(return_code, 2)
self.assertEqual(return_code, 2, msg=stdout + stderr)
self.assertGreater(len(stderr), 0)
else:
self.assertEqual(return_code, 0)
@@ -2524,6 +2524,14 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
Test if we can build a static ns-3 library and link it to static programs
@return None
"""
if (not win32) and (arch == "aarch64"):
if platform.libc_ver()[0] == "glibc":
from packaging.version import Version
if Version(platform.libc_ver()[1]) < Version("2.37"):
self.skipTest(
"Static linking on ARM64 requires glibc 2.37 where fPIC was enabled (fpic is limited in number of GOT entries)"
)
# First enable examples and static build
return_code, stdout, stderr = run_ns3(
@@ -3150,6 +3158,7 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase):
return_code, stdout, stderr = run_ns3("clean")
self.assertEqual(return_code, 0)
if arch != "aarch64":
# Install VcPkg dependencies
container.execute("apt-get install -y zip unzip tar curl")