forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: tests: Blackbox test expansion - testlist
Adds tests related to the flags creating testlists: * -E, --save-tests * -F, --load-tests Signed-off-by: Lukasz Mrugala <[email protected]>
- Loading branch information
1 parent
8b1ef28
commit dc68b11
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2024 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
Blackbox tests for twister's command line functions related to saving and loading a testlist. | ||
""" | ||
|
||
import importlib | ||
import mock | ||
import os | ||
import pytest | ||
import sys | ||
import json | ||
|
||
from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock, clear_log_in_test | ||
from twisterlib.testplan import TestPlan | ||
|
||
|
||
class TestTestlist: | ||
@classmethod | ||
def setup_class(cls): | ||
apath = os.path.join(ZEPHYR_BASE, 'scripts', 'twister') | ||
cls.loader = importlib.machinery.SourceFileLoader('__main__', apath) | ||
cls.spec = importlib.util.spec_from_loader(cls.loader.name, cls.loader) | ||
cls.twister_module = importlib.util.module_from_spec(cls.spec) | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
pass | ||
|
||
@mock.patch.object(TestPlan, 'TESTSUITE_FILENAME', testsuite_filename_mock) | ||
def test_save_tests(self, out_path): | ||
test_platforms = ['qemu_x86', 'frdm_k64f'] | ||
path = os.path.join(TEST_DATA, 'tests', 'dummy', 'agnostic') | ||
saved_tests_file_path = os.path.realpath(os.path.join(out_path, '..', 'saved-tests.json')) | ||
args = ['-i', '--outdir', out_path, '-T', path, '-y'] + \ | ||
['--save-tests', saved_tests_file_path] + \ | ||
[val for pair in zip( | ||
['-p'] * len(test_platforms), test_platforms | ||
) for val in pair] | ||
|
||
# Save agnostics tests | ||
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \ | ||
pytest.raises(SystemExit) as sys_exit: | ||
self.loader.exec_module(self.twister_module) | ||
|
||
assert str(sys_exit.value) == '0' | ||
|
||
clear_log_in_test() | ||
|
||
# Load all | ||
path = os.path.join(TEST_DATA, 'tests', 'dummy') | ||
args = ['-i', '--outdir', out_path, '-T', path, '-y'] + \ | ||
['--load-tests', saved_tests_file_path] + \ | ||
[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) | ||
|
||
assert str(sys_exit.value) == '0' | ||
|
||
with open(os.path.join(out_path, 'testplan.json')) as f: | ||
j = json.load(f) | ||
filtered_j = [ | ||
(ts['platform'], ts['name'], tc['identifier']) \ | ||
for ts in j['testsuites'] \ | ||
for tc in ts['testcases'] if 'reason' not in tc | ||
] | ||
|
||
assert len(filtered_j) == 5 |