diff options
author | yanxk <yanxk.fnst@fujitsu.com> | 2022-09-03 16:24:32 +0800 |
---|---|---|
committer | Xinkuan Yan <yanxk.fnst@fujitsu.com> | 2022-12-02 00:56:09 +0000 |
commit | 85e3c12681faca0519ca995a82feeb7709397ca2 (patch) | |
tree | ff4cff2addafab155353175e45b61e50a1840e52 /tests/crashme | |
parent | ef29f9077a89038525e20a517d972453f2cc4d62 (diff) |
agl-test-framework: add test 'crashme'
'agl-test' modified, now, usr would not run dangerous
tests like this 'crashme' unless they do self selection
by '-m' pytest option. Set default to 'not dangerous'.
a new marker 'dangerous' has been add to the pytest.ini.
add new method into the agl_test_base.py, to help get path
of the 'spec.json', this file help stress tests like 'crashme'
to run under different stress levels.
for run_tests.py, modifications focus on how to run 'crashme'
under that different levels.
new marker 'order' would always ensure this 'crashme' test to
be placed as the so called 'last' test of all.
Bug-AGL: SPEC-4345
Signed-off-by: yanxk <yanxk.fnst@fujitsu.com>
Change-Id: Icb36d7c5c52430d89787f4373a2852b1b03ec8a6
Diffstat (limited to 'tests/crashme')
-rw-r--r-- | tests/crashme/__init__.py | 0 | ||||
-rw-r--r-- | tests/crashme/run_tests.py | 95 | ||||
-rw-r--r-- | tests/crashme/spec.json | 20 |
3 files changed, 115 insertions, 0 deletions
diff --git a/tests/crashme/__init__.py b/tests/crashme/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/crashme/__init__.py diff --git a/tests/crashme/run_tests.py b/tests/crashme/run_tests.py new file mode 100644 index 0000000..93f62cd --- /dev/null +++ b/tests/crashme/run_tests.py @@ -0,0 +1,95 @@ +import pytest +import subprocess +import pathlib +import os +import json + +from plugins.agl_test_base import AGLBaseTest + +class CrashmeBase(AGLBaseTest): + def __init__(self): + super().__init__(name="crashme") + + def setup_runtest_params(self): + # Get env 'STRESS_LEVEL' + env_dist=os.environ + local_stress_level = str(env_dist.get("STRESS_LEVEL")) + + # If not set correctly or just not set, set default to "low" + if local_stress_level not in ("low", "mid", "high"): + local_stress_level = "low" + + # Read dictionary data out of spec.json + spec_file_location = self.get_spec_path() + fp = open(spec_file_location, 'r') + + json_data = fp.read() + spec_dict = json.loads(json_data) + + dict_key="stress_level_" + str(local_stress_level) + + local_param_nbytes = spec_dict[dict_key]['NBYTES'] + local_param_srand = spec_dict[dict_key]['SRAND'] + local_param_ntries = spec_dict[dict_key]['NTRIES'] + local_param_nsub = spec_dict[dict_key]['NSUB'] + + param_string = str(local_param_nbytes) + ' ' \ + + str(local_param_srand) + ' ' \ + + str(local_param_ntries) + ' ' \ + + str(local_param_nsub) + + return param_string + + def run_test_fun(self): + log_file = self.get_logfile() + cwd_buf = self.get_temp_logdir() + oss_workdir = self.get_workdir() + runtest_param_buf = self.setup_runtest_params() + + run_test_cmd = oss_workdir + 'crashme ' + runtest_param_buf + \ + ' | grep "^Test complete\\|^exit status\\|' + \ + '^child_kill_count\\|[.]\\{3\\}\\|^Number of distinct cases"' + + with open(log_file, 'w') as log_f: + run_test_crashme = subprocess.run(run_test_cmd, shell=True, + cwd=cwd_buf, stdout=log_f, stderr=subprocess.DEVNULL) + log_f.close() + + if (run_test_crashme.returncode == 0): + self.case_info_list = {'test_crashme': + ['test_crashme', str(run_test_crashme.returncode), 'passed']} + else: + self.case_info_list = {'test_crashme': + ['test_crashme', str(run_test_crashme.returncode), 'failed']} + + def precheck(self): + test_file_location = self.get_workdir() + "/crashme" + path_checker = pathlib.Path(test_file_location) + return super().precheck() and path_checker.is_file() + +@pytest.fixture(scope='module') +def testbase(): + #init instance for test + instance = CrashmeBase() + + #run test scripts + instance.run_test_fun() + + yield instance + + #package log files and make report file + instance.log_report() + +def precheck(): + instance = CrashmeBase() + return instance.precheck() +skip_msg = "The current environment does not match the test requirements." +pytestmark = pytest.mark.skipif(precheck() == False, reason = skip_msg) + +@pytest.mark.dangerous +@pytest.mark.order("last") +def test_crashme(testbase: CrashmeBase): + assert testbase.case_info_list['test_crashme'][1] == '0' + +if __name__ == '__main__': + pytest.main("-s run_tests") diff --git a/tests/crashme/spec.json b/tests/crashme/spec.json new file mode 100644 index 0000000..0d47b8c --- /dev/null +++ b/tests/crashme/spec.json @@ -0,0 +1,20 @@ +{ + "stress_level_low": { + "NBYTES": "+2000", + "SRAND": "666", + "NTRIES": "100", + "NSUB": "00:15:00" + }, + "stress_level_mid": { + "NBYTES": "+3000", + "SRAND": "666", + "NTRIES": "150", + "NSUB": "00:30:00" + }, + "stress_level_high": { + "NBYTES": "+8000", + "SRAND": "666", + "NTRIES": "800", + "NSUB": "01:00:00" + } +} |