scripts: tests: twister_blackbox: Add more tests to test_report.py
add tests to test_report.py: - log-file - coverage - enable-coverage Signed-off-by: Paszkiet Kamil <kamilx.paszkiet@intel.com>
This commit is contained in:
parent
64423e269e
commit
0e2f19a564
1 changed files with 111 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ Blackbox tests for twister's command line functions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import re
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -98,6 +100,32 @@ class TestReport:
|
||||||
"OUT_DIR"
|
"OUT_DIR"
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
TESTDATA_6 = [
|
||||||
|
(
|
||||||
|
os.path.join(TEST_DATA, 'tests', 'dummy', 'agnostic'),
|
||||||
|
['qemu_x86'],
|
||||||
|
"TEST_LOG_FILE.log"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
TESTDATA_7 = [
|
||||||
|
(
|
||||||
|
os.path.join(TEST_DATA, 'tests', 'dummy', 'agnostic'),
|
||||||
|
['qemu_x86'],
|
||||||
|
[
|
||||||
|
'coverage.log', 'coverage.json',
|
||||||
|
'coverage'
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
TESTDATA_8 = [
|
||||||
|
(
|
||||||
|
os.path.join(TEST_DATA, 'tests', 'dummy', 'agnostic'),
|
||||||
|
['qemu_x86'],
|
||||||
|
[
|
||||||
|
'GCOV_COVERAGE_DUMP_START', 'GCOV_COVERAGE_DUMP_END'
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_class(cls):
|
def setup_class(cls):
|
||||||
|
|
@ -294,3 +322,86 @@ class TestReport:
|
||||||
twister_path = os.path.join(ZEPHYR_BASE, dir_name)
|
twister_path = os.path.join(ZEPHYR_BASE, dir_name)
|
||||||
if os.path.exists(twister_path):
|
if os.path.exists(twister_path):
|
||||||
shutil.rmtree(twister_path)
|
shutil.rmtree(twister_path)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'test_path, test_platforms, file_name',
|
||||||
|
TESTDATA_6,
|
||||||
|
ids=[
|
||||||
|
'log_file',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_log_file(self, capfd, test_path, test_platforms, out_path, file_name):
|
||||||
|
args = ['-i','--outdir', out_path, '-T', test_path, "--log-file", file_name] + \
|
||||||
|
[val for pair in zip(
|
||||||
|
['-p'] * len(test_platforms), test_platforms
|
||||||
|
) for val in pair]
|
||||||
|
|
||||||
|
file_path = os.path.join(ZEPHYR_BASE, file_name)
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
os.remove(file_path)
|
||||||
|
|
||||||
|
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \
|
||||||
|
pytest.raises(SystemExit) as sys_exit:
|
||||||
|
self.loader.exec_module(self.twister_module)
|
||||||
|
|
||||||
|
out, err = capfd.readouterr()
|
||||||
|
sys.stdout.write(out)
|
||||||
|
sys.stderr.write(err)
|
||||||
|
|
||||||
|
assert os.path.exists(file_path), 'file not found {f_name}'
|
||||||
|
|
||||||
|
assert str(sys_exit.value) == '0'
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'test_path, test_platforms, file_name',
|
||||||
|
TESTDATA_7,
|
||||||
|
ids=[
|
||||||
|
'coverage',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_coverage(self, capfd, test_path, test_platforms, out_path, file_name):
|
||||||
|
args = ['-i','--outdir', out_path, '-T', test_path, '--coverage', '--coverage-tool', 'gcovr'] + \
|
||||||
|
[val for pair in zip(
|
||||||
|
['-p'] * len(test_platforms), test_platforms
|
||||||
|
) for val in pair]
|
||||||
|
|
||||||
|
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \
|
||||||
|
pytest.raises(SystemExit) as sys_exit:
|
||||||
|
self.loader.exec_module(self.twister_module)
|
||||||
|
|
||||||
|
out, err = capfd.readouterr()
|
||||||
|
sys.stdout.write(out)
|
||||||
|
sys.stderr.write(err)
|
||||||
|
|
||||||
|
for f_name in file_name:
|
||||||
|
path = os.path.join(out_path, f_name)
|
||||||
|
assert os.path.exists(path), f'file not found {f_name}'
|
||||||
|
|
||||||
|
assert str(sys_exit.value) == '0'
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'test_path, test_platforms, expected',
|
||||||
|
TESTDATA_8,
|
||||||
|
ids=[
|
||||||
|
'enable_coverage',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_enable_coverage(self, capfd, test_path, test_platforms, out_path, expected):
|
||||||
|
args = ['-i','--outdir', out_path, '-T', test_path, '--enable-coverage', '-vv'] + \
|
||||||
|
[val for pair in zip(
|
||||||
|
['-p'] * len(test_platforms), test_platforms
|
||||||
|
) for val in pair]
|
||||||
|
|
||||||
|
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \
|
||||||
|
pytest.raises(SystemExit) as sys_exit:
|
||||||
|
self.loader.exec_module(self.twister_module)
|
||||||
|
|
||||||
|
out, err = capfd.readouterr()
|
||||||
|
sys.stdout.write(out)
|
||||||
|
sys.stderr.write(err)
|
||||||
|
|
||||||
|
for line in expected:
|
||||||
|
match = re.search(line, err)
|
||||||
|
assert match, f'line not found: {line}'
|
||||||
|
|
||||||
|
assert str(sys_exit.value) == '0'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue