1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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")
|