diff options
Diffstat (limited to 'tests/LTP/posix_conformance_tests/run_tests.py')
-rw-r--r-- | tests/LTP/posix_conformance_tests/run_tests.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/LTP/posix_conformance_tests/run_tests.py b/tests/LTP/posix_conformance_tests/run_tests.py new file mode 100644 index 0000000..5806fca --- /dev/null +++ b/tests/LTP/posix_conformance_tests/run_tests.py @@ -0,0 +1,109 @@ +import os +import re +import pytest +import pathlib +import subprocess + +from tests.LTP.agl_test_ltp_base import LTPBase + +class Conformance_Base(LTPBase): + def __init__(self): + super().__init__(test_name="posix_conformance_tests") + + def precheck(self): + # 1, check bin/run-tests.sh exists + general_script_path = pathlib.Path( self.LTPDIR+ "./bin/run-tests.sh") + check_script = general_script_path.is_file() + # 2, check if /opt/ltp/conformance/ exists + conformance_dir_path = pathlib.Path( self.LTPDIR+ "./conformance/") + check_dir = conformance_dir_path.is_dir() + return check_script and check_dir + + # "aio_suspend_1-1.run-test" >> "aio_suspend_1.1" is the name + def init_param_list(self): + case_name_list = [] + # root path + root_dir = pathlib.Path(self.LTPDIR + "./conformance/interfaces/") + # search case name by .run-test/.sh files without run.sh + for child in root_dir.iterdir(): + if child.is_file(): + continue + for item in child.iterdir(): + if (item.suffix == ".run-test" or item.suffix == ".sh") and item.name != "run.sh": + case_name_list.append(item.stem) + return case_name_list + + # in run test function, log would be automatically generated + def run_all_tests(self): + # get logfile path from function "get_logfile()" + log_file_path = self.get_log_file() + # export env variable "LOGFILE" as path to logfile + os.environ['LOGFILE'] = str(log_file_path) + # get all folder names + root_dir = pathlib.Path(self.LTPDIR + "./conformance/interfaces/") + # go into each and every folder run "run.sh" + for child in root_dir.iterdir(): + # only if item is folder do + if child.is_file(): + continue + # folder name + run.sh = command buffer + run_script_cmd = str(child) + "/run.sh" + cwd_buf = str(child) + # run script files in subprocesses + subprocess.run(run_script_cmd, shell=True, cwd=cwd_buf, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + # parser function + def log_parser(self, log_file): + # example: conformance/interfaces/aio_suspend/(aio_suspend_5-1): execution: (UNSUPPORTED): Output: + # set regex rule + reRule="^conformance/interfaces/[a-z_]+/([a-z0-9_-]+): execution: ([A-Z]+)[:]?.?" + reObj = re.compile(reRule) + # init a dictionary, it stores the return result + case_list = dict() + # open file + test_log = open(log_file, 'r') + # start to read the new line + line = test_log.readline() + while line: + # checking regex status in line + matchs = reObj.search(line) + # if the line fits the regex rule + if matchs: + # spliting elements into a tuple + groups = matchs.groups() + case_list[groups[0]] = [groups[0], groups[1], ""] + # jump out if-else, read next line + line = test_log.readline() + test_log.close() + return case_list + + def log_process(self): + log_file_path = self.get_log_file() + self.case_info_list = self.log_parser(log_file_path) + +@pytest.fixture(scope='module') +def testbase(): + # init instance + instance = Conformance_Base() + # run all cases + instance.run_all_tests() + # do log process + instance.log_process() + yield instance + #package log files and make report file + instance.log_report() + +def local_precheck(): + checker = Conformance_Base() + return checker.precheck() +skip_msg = "The current environment does not match the test requirements." +pytestmark = pytest.mark.skipif(local_precheck() == False, reason = skip_msg) + +instance_paramtrize = Conformance_Base() +@pytest.mark.parametrize('case_name', instance_paramtrize.init_param_list()) +def test_posix_conformance(testbase: Conformance_Base, case_name): + testbase.run_case(case_name) + +if __name__ == '__main__': + pytest.main("-s run_tests") |