twister: tests: fix tests by mocking platform attributes

We were missing mocking for normalized_name and board detection was not
working correctly after moving to hwmv2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2024-03-04 11:04:00 -05:00
parent f1f6b72c76
commit 668f6d87ec
8 changed files with 79 additions and 0 deletions

View file

@ -23,6 +23,7 @@ class Platform:
"""
self.name = ""
self.normalized_name = ""
self.twister = True
# if no RAM size is specified by the board, take a default of 128K
self.ram = 128

View file

@ -0,0 +1,14 @@
boards:
- name: demo_board_1
vendor: zephyr
socs:
- name: unit_testing
- name: demo_board_2
vendor: zephyr
socs:
- name: unit_testing
- name: demo_board_3
vendor: zephyr
socs:
- name: unit_testing

View file

@ -77,6 +77,7 @@ def test_robot_configure():
#Arrange
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [])
mock_testsuite.name = "mock_testsuite"
@ -100,6 +101,7 @@ def test_robot_handle():
#Arrange
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [])
mock_testsuite.name = "mock_testsuite"
@ -140,6 +142,7 @@ def test_robot_run_robot_test(caplog, exp_out, returncode, expected_status):
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [mock.Mock()])
mock_testsuite.name = "mock_testsuite"
@ -184,6 +187,7 @@ def test_console_configure(type, num_patterns):
#Arrange
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [])
mock_testsuite.name = "mock_testsuite"
@ -222,6 +226,7 @@ TEST_DATA_4 = [("one_line", True, "passed", "line", False, False),
def test_console_handle(line_type, ordered_val, exp_state, line, exp_fault, exp_capture):
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [])
mock_testsuite.name = "mock_testsuite"
@ -277,6 +282,7 @@ def test_pytest__generate_parameters_for_hardware(pty_value, hardware_value):
#Arrange
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [])
mock_testsuite.name = "mock_testsuite"
@ -359,6 +365,7 @@ def test_pytest_run(caplog):
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [], source_dir = 'source_dir', harness_config = {})
mock_testsuite.name = "mock_testsuite"
@ -416,6 +423,7 @@ def test_test_handle(caplog, exp_out, line, exp_suite_name, exp_status, ztest, s
line = line
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock(id = 'id', testcases = [])
mock_testsuite.name = "mock_testsuite"
@ -445,6 +453,7 @@ def test_test_handle(caplog, exp_out, line, exp_suite_name, exp_status, ztest, s
def gtest(tmp_path):
mock_platform = mock.Mock()
mock_platform.name = "mock_platform"
mock_platform.normalized_name = "mock_platform"
mock_testsuite = mock.Mock()
mock_testsuite.name = "mock_testsuite"
mock_testsuite.detailed_test_id = True

View file

@ -207,6 +207,7 @@ def test_testinstance_init(all_testsuites_dict, class_testplan, platforms_list,
testsuite = class_testplan.testsuites.get(testsuite_path)
testsuite.detailed_test_id = detailed_test_id
class_testplan.platforms = platforms_list
print(class_testplan.platforms)
platform = class_testplan.get_platform("demo_board_2")
testinstance = TestInstance(testsuite, platform, class_testplan.env.outdir)

View file

@ -728,6 +728,18 @@ def test_testplan_load(
testplan.platforms[9].name = 'lt-p2'
testplan.platforms[10].name = 'lt-p3'
testplan.platforms[11].name = 'lt-p4'
testplan.platforms[0].normalized_name = 't-p1'
testplan.platforms[1].normalized_name = 't-p2'
testplan.platforms[2].normalized_name = 't-p3'
testplan.platforms[3].normalized_name = 't-p4'
testplan.platforms[4].normalized_name = 'ts-p1'
testplan.platforms[5].normalized_name = 'ts-p2'
testplan.platforms[6].normalized_name = 'ts-p3'
testplan.platforms[7].normalized_name = 'ts-p4'
testplan.platforms[8].normalized_name = 'lt-p1'
testplan.platforms[9].normalized_name = 'lt-p2'
testplan.platforms[10].normalized_name = 'lt-p3'
testplan.platforms[11].normalized_name = 'lt-p4'
testplan.generate_subset = mock.Mock()
testplan.apply_filters = mock.Mock()
@ -1098,6 +1110,21 @@ def test_testplan_add_configurations(
tmp_p1_dir = tmp_arch1_dir / 'p1'
tmp_p1_dir.mkdir()
p1e1_bs_yaml = """\
boards:
- name: ple1
vendor: zephyr
socs:
- name: unit_testing
- name: ple2
vendor: zephyr
socs:
- name: unit_testing
"""
p1e1_yamlfile = tmp_p1_dir / 'board.yml'
p1e1_yamlfile.write_text(p1e1_bs_yaml)
p1e1_yaml = """\
identifier: p1e1
name: Platform 1 Edition 1
@ -1126,6 +1153,21 @@ toolchain:
tmp_p2_dir = tmp_arch1_dir / 'p2'
tmp_p2_dir.mkdir()
p2_bs_yaml = """\
boards:
- name: p2
vendor: zephyr
socs:
- name: unit_testing
- name: p2_2
vendor: zephyr
socs:
- name: unit_testing
"""
p2_yamlfile = tmp_p2_dir / 'board.yml'
p2_yamlfile.write_text(p2_bs_yaml)
p2_yaml = """\
identifier: p2
name: Platform 2
@ -1164,6 +1206,17 @@ toolchain:
tmp_p3_dir = tmp_arch2_dir / 'p3'
tmp_p3_dir.mkdir()
p3_bs_yaml = """\
boards:
- name: p3
vendor: zephyr
socs:
- name: unit_testing
"""
p3_yamlfile = tmp_p3_dir / 'board.yml'
p3_yamlfile.write_text(p3_bs_yaml)
p3_yaml = """\
identifier: p3
name: Platform 3
@ -1375,6 +1428,7 @@ def test_testplan_load_from_file(caplog, device_testing, expected_tfilter):
def get_platform(name):
p = mock.Mock()
p.name = name
p.normalized_name = name
return p
ts1tc1 = mock.Mock()