test: test-ns3.py case to check if modules from src can depend on contrib

This commit is contained in:
Gabriel Ferreira
2023-04-01 13:07:02 -03:00
parent 5b6083250c
commit 2b98ccb9e2
10 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
build_lib(
LIBNAME test-contrib-dependency
SOURCE_FILES contrib-source.cc
HEADER_FILES contrib-header.h
LIBRARIES_TO_LINK ${libcore}
)

View File

@@ -0,0 +1,6 @@
#ifndef NS3_CONTRIB_HEADER_H
#define NS3_CONTRIB_HEADER_H
void testPrint();
#endif // NS3_CONTRIB_HEADER_H

View File

@@ -0,0 +1,9 @@
#include "contrib-header.h"
#include <ns3/simulator.h>
void
testPrint()
{
std::cout << ns3::Simulator::Now() << std::endl;
}

View File

@@ -0,0 +1,8 @@
build_lib(
LIBNAME test-src-dependant-on-contrib
SOURCE_FILES src-source.cc
HEADER_FILES src-header.h
LIBRARIES_TO_LINK ${libcore}
${libtest-contrib-dependency}
)

View File

@@ -0,0 +1,6 @@
build_lib_example(
NAME source-example
SOURCE_FILES source-example.cc
LIBRARIES_TO_LINK
${libtest-src-dependant-on-contrib}
)

View File

@@ -0,0 +1,8 @@
#include <ns3/src-header.h>
int
main()
{
testPrint2();
return 0;
}

View File

@@ -0,0 +1,6 @@
#ifndef NS3_SRC_SOURCE2_H
#define NS3_SRC_SOURCE2_H
void testPrint2();
#endif // NS3_SOURCE_H

View File

@@ -0,0 +1,7 @@
#include <ns3/contrib-header.h>
void
testPrint2()
{
testPrint();
}

View File

@@ -76,3 +76,6 @@ inout
#Utils
filetest
#test-ns3.py
dependant

View File

@@ -2338,6 +2338,40 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
return_code, stdout, stderr = run_ns3("build brite click openflow")
self.assertEqual(return_code, 0)
def test_14_LinkContribModuleToSrcModule(self):
"""!
Test if we can link contrib modules to src modules
@return None
"""
if shutil.which("git") is None:
self.skipTest("Missing git")
destination_contrib = os.path.join(ns3_path, "contrib/test-contrib-dependency")
destination_src = os.path.join(ns3_path, "src/test-src-dependant-on-contrib")
# Remove pre-existing directories
if os.path.exists(destination_contrib):
shutil.rmtree(destination_contrib)
if os.path.exists(destination_src):
shutil.rmtree(destination_src)
# Always use a fresh copy
shutil.copytree(os.path.join(ns3_path, "build-support/test-files/test-contrib-dependency"),
destination_contrib)
shutil.copytree(os.path.join(ns3_path, "build-support/test-files/test-src-dependant-on-contrib"),
destination_src)
# Then configure
return_code, stdout, stderr = run_ns3("configure --enable-examples")
self.assertEqual(return_code, 0)
# Build the src module that depend on a contrib module
return_code, stdout, stderr = run_ns3("run source-example")
self.assertEqual(return_code, 0)
# Remove module copies
shutil.rmtree(destination_contrib)
shutil.rmtree(destination_src)
class NS3ExpectedUseTestCase(NS3BaseTestCase):
"""!