Skip to content
Snippets Groups Projects
Commit 542cf688 authored by Maël Madon's avatar Maël Madon
Browse files

test: cleaning test files and add html report

parent c2275619
No related branches found
No related tags found
No related merge requests found
......@@ -31,4 +31,8 @@ nix-shell -A test
pytest
```
Run in verbose mode (`pytest -v`) to get a little more information on the tests. And `pytest -k EXPRESSION` only runs tests matching the given substring expression.
[Nix]: https://nixos.org/nix/
......@@ -59,8 +59,9 @@ let
# Batmen integration tests.
test = pkgs.stdenv.mkDerivation rec {
pname = "batmen-integration-tests";
version = toString builtins.currentTime; # Forces rebuild
name = "batmen-integration-tests";
# version = toString builtins.currentTime; # Forces rebuild
version = 0;
src = pkgs.lib.sourceByRegex ./. [
"^test"
"^test/.*\.py"
......@@ -72,41 +73,14 @@ let
"^test/schedconf/.*\.json"
"^test/expected_log"
"^test/expected_log/.*\.csv"
];
buildInputs = with pkgs.python38Packages; [
batsim_sg330
batsim
batmen
batexpe
pytest
pandas
pytest-html # for html export of test results
];
preBuild = pkgs.lib.optionalString doCoverage ''
mkdir -p gcda
export GCOV_PREFIX=$(realpath gcda)
export GCOV_PREFIX_STRIP=5
'';
buildPhase = ''
runHook preBuild
set +e
pytest
echo $? > ./pytest_returncode
set -e
'';
checkPhase = ''
pytest_return_code=$(cat ./pytest_returncode)
echo "pytest return code: $pytest_return_code"
if [ $pytest_return_code -ne 0 ] ; then
exit 1
fi
'';
inherit doCheck;
installPhase = ''
mkdir -p $out
mv ./report/* ./pytest_returncode $out/
'' + pkgs.lib.optionalString doCoverage ''
mv ./gcda $out/
'';
};
};
......
[pytest]
addopts = --html=test-out/test_report.html --self-contained-html
\ No newline at end of file
......@@ -44,40 +44,7 @@ def pytest_generate_tests(metafunc):
filename=abspath(workload_file)) for workload_file in workload_files]
metafunc.parametrize('workload_multiC', workloads)
if 'monitoring_period' in metafunc.fixturenames:
metafunc.parametrize('monitoring_period', [600])
if 'inertial_function' in metafunc.fixturenames:
metafunc.parametrize('inertial_function', ['x2', 'p1'])
if 'idle_time_to_sedate' in metafunc.fixturenames:
metafunc.parametrize('idle_time_to_sedate', [0, 120])
if 'sedate_idle_on_classical_events' in metafunc.fixturenames:
metafunc.parametrize('sedate_idle_on_classical_events', [True, False])
if 'allow_future_switches' in metafunc.fixturenames:
metafunc.parametrize('allow_future_switches', [True])
if 'upper_llh_threshold' in metafunc.fixturenames:
metafunc.parametrize('upper_llh_threshold', [60])
# @pytest.fixture(scope="session", autouse=True)
# def manage_redis_server(request):
# print('Trying to run a redis-server...')
# proc = subprocess.Popen('redis-server', stdout=subprocess.PIPE)
# try:
# out, _ = proc.communicate(timeout=1)
# if 'Address already in use' in str(out):
# print("Could not run redis-server (address already in use).")
# print("Assuming that the process using the TCP port is another redis-server instance and going on.")
# else:
# raise Exception("Could not run redis-server (unhandled reason), aborting.")
# except subprocess.TimeoutExpired:
# print('redis-server has been running for 1 second.')
# print('Assuming redis-server has started successfully and going on.')
# def on_finalize():
# print('Killing the spawned redis-server (if any)...')
# proc.kill()
# request.addfinalizer(on_finalize)
# def pytest_cmdline_preparse(config, args):
# html_file = "test-out/testreport.html"
# print('HTML report file:', html_file)
# args.extend(['--html', html_file, '--self-contained-html'])
\ No newline at end of file
import json
from helper import *
# def energy_model_instance():
# return {
# "power_sleep":9.75,
# "power_idle":95,test_algo_perso
# "energy_switch_on":19030,
# "power_compute":190.738,
# "energy_switch_off":620,
# "time_switch_off":6.1,
# "pstate_sleep":13,
# "pstate_compute":0,
# "time_switch_on":152
# }
# def test_inertial_shutdown(platform, workload,
# monitoring_period,
# allow_future_switches,
# upper_llh_threshold ,
# inertial_function,
# idle_time_to_sedate,
# sedate_idle_on_classical_events):
# algo = 'energy_bf_monitoring_inertial'
# test_name = f'{algo}-{platform.name}-{workload.name}-{inertial_function}-{idle_time_to_sedate}-{sedate_idle_on_classical_events}'
# output_dir, robin_filename, schedconf_filename = init_instance(test_name)
# batcmd = gen_batsim_cmd(platform.filename, workload.filename, output_dir, "--energy")
# schedconf_content = {
# "output_dir": output_dir,
# "monitoring_period": monitoring_period,
# "trace_output_filename": f'{output_dir}/batsched_llh.trace',
# "allow_future_switches": allow_future_switches,
# "upper_llh_threshold": upper_llh_threshold,
# "inertial_alteration": inertial_function,
# "idle_time_to_sedate": idle_time_to_sedate,
# "sedate_idle_on_classical_events": sedate_idle_on_classical_events
# }
# schedconf_content = dict(schedconf_content, **energy_model_instance())
# write_file(schedconf_filename, json.dumps(schedconf_content))
# instance = RobinInstance(output_dir=output_dir,
# batcmd=batcmd,
# schedcmd=f"batsched -v '{algo}' --variant_options_filepath '{schedconf_filename}'",
# simulation_timeout=30, ready_timeout=5,
# success_timeout=10, failure_timeout=0
# )
# instance.to_file(robin_filename)
# ret = run_robin(robin_filename)
# assert ret.returncode == 0
# def test_sleeper(platform, workload):
# algo = 'sleeper'
# test_name = f'{algo}-{platform.name}-{workload.name}'
# output_dir, robin_filename, schedconf_filename = init_instance(test_name)
# batcmd = gen_batsim_cmd(platform.filename, workload.filename, output_dir, "--energy")
# schedconf_content = energy_model_instance()
# write_file(schedconf_filename, json.dumps(schedconf_content))
# instance = RobinInstance(output_dir=output_dir,
# batcmd=batcmd,
# schedcmd=f"batsched -v '{algo}' --variant_options_filepath '{schedconf_filename}'",
# simulation_timeout=30, ready_timeout=5,
# success_timeout=10, failure_timeout=0
# )
# instance.to_file(robin_filename)
# ret = run_robin(robin_filename)
# assert ret.returncode == 0
......@@ -20,27 +20,4 @@ def test_basic_algo_no_param(platform_monoC, workload_monoC, basic_algo_no_param
instance.to_file(robin_filename)
ret = run_robin(robin_filename)
assert ret.returncode == 0
# def test_easy_bf_plot_llh(platform, workload):
# algo = 'easy_bf_plot_liquid_load_horizon'
# test_name = f'{algo}-{platform.name}-{workload.name}'
# output_dir, robin_filename, schedconf_filename = init_instance(test_name)
# batcmd = gen_batsim_cmd(platform.filename, workload.filename, output_dir, "--energy")
# schedconf_content = {
# "trace_output_filename": f'{output_dir}/batsched_llh.trace'
# }
# write_file(schedconf_filename, json.dumps(schedconf_content))
# instance = RobinInstance(output_dir=output_dir,
# batcmd=batcmd,
# schedcmd=f"batsched -v '{algo}' --variant_options_filepath '{schedconf_filename}'",
# simulation_timeout=30, ready_timeout=5,
# success_timeout=10, failure_timeout=0
# )
# instance.to_file(robin_filename)
# ret = run_robin(robin_filename)
# assert ret.returncode == 0
assert ret.returncode == 0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment