Skip to content

Commit

Permalink
Test runner also with waf-based versions of ns-3
Browse files Browse the repository at this point in the history
  • Loading branch information
pagmatt committed Feb 9, 2024
1 parent 03b5d41 commit 6ac0113
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
24 changes: 22 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def ns_3_compiled(tmpdir):

# Relocate build by running the same command in the new directory
if subprocess.call([build_program, 'configure', '--disable-gtk',
'--build-profile=optimized', '--enable-modules=core',
'--build-profile=optimized', '--enable-modules=core', '--enable-examples',
'--out=build/optimized'],
cwd=ns_3_tempdir,
stdout=subprocess.DEVNULL,
Expand Down Expand Up @@ -70,7 +70,7 @@ def ns_3_compiled_debug(tmpdir):

# Relocate build by running the same command in the new directory
if subprocess.call([build_program, 'configure', '--disable-gtk',
'--build-profile=debug', '--enable-modules=core',
'--build-profile=debug', '--enable-modules=core', '--enable-examples',
'--out=build'],
cwd=ns_3_tempdir,
stdout=subprocess.DEVNULL,
Expand All @@ -85,6 +85,26 @@ def ns_3_compiled_debug(tmpdir):

return ns_3_tempdir

@pytest.fixture(scope='function')
def ns_3_compiled_examples():
# Configure and build WAF-based ns-3
build_program = get_build_program(ns_3_examples)

if subprocess.call([build_program, 'configure', '--disable-gtk',
'--build-profile=optimized', '--enable-modules=core',
'--out=build/optimized'],
cwd=ns_3_examples,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT) != 0:
raise Exception("Examples configuration failed.")

if subprocess.call([build_program, 'build'],
cwd=ns_3_examples,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) > 0:
raise Exception("Examples build failed.")

return ns_3_examples

@pytest.fixture(scope='function')
def config(tmpdir, ns_3_compiled):
Expand Down
27 changes: 19 additions & 8 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,44 @@
# Runner creation #
###################

"""
First param: Runner type
Second param: Whether to use optimized build
Third param: Whether to use the CMake-version of ns-3
"""
@pytest.fixture(scope='function', params=[['ParallelRunner', True, True],
['ParallelRunner', True, False]])
def runner(ns_3_compiled, ns_3_compiled_debug, ns_3_compiled_examples, config, request):
ns_3_folder = ns_3_compiled
if request.param[1] is False:
ns_3_folder = ns_3_compiled_debug
if request.param[2] is True:
assert(request.param[1] is True)
ns_3_folder = ns_3_compiled_examples

@pytest.fixture(scope='function', params=[['ParallelRunner', True],
['ParallelRunner', False]])
def runner(ns_3_compiled, ns_3_compiled_debug, config, request):
ns_3_folder = ns_3_compiled if request.param[1] is True else ns_3_compiled_debug
if request.param[0] == 'SimulationRunner':
return SimulationRunner(ns_3_folder, config['script'],
optimized=request.param[1])
elif request.param[0] == 'ParallelRunner':
return ParallelRunner(ns_3_folder, config['script'],
optimized=request.param[1])


def test_get_available_parameters(runner, config):
# Try getting the available parameters of the script
assert runner.get_available_parameters() == config['params']


@pytest.mark.parametrize('runner',
[
['SimulationRunner', True],
['ParallelRunner', True],
['SimulationRunner', True, True],
['ParallelRunner', True, True],
['ParallelRunner', True, False],
],
indirect=True)
def test_run_simulations(runner, config,
parameter_combination):
# Make sure that simulations run without any issue
# Make sure that simulations run without any issue,
# with CMake optimized and debug builds, and Waf optimized builds
data_dir = os.path.join(config['campaign_dir'], 'data')
list(runner.run_simulations([parameter_combination], data_dir))

Expand Down

0 comments on commit 6ac0113

Please sign in to comment.