Skip to content

Commit 022ee30

Browse files
committed
scripts: Adapt twister lib to support TOOLCHAIN_VARIANT_COMPILER
Add TOOLCHAIN_VARIANT_COMPILER to the test path, then adapt tests to support this new value. Signed-off-by: Keith Packard <keithp@keithp.com>
1 parent 0ee55f3 commit 022ee30

File tree

5 files changed

+67
-28
lines changed

5 files changed

+67
-28
lines changed

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ def run_cmake(self, args="", filter_stages=None):
665665
if self.instance.toolchain:
666666
cmake_args.append(f'-DZEPHYR_TOOLCHAIN_VARIANT={self.instance.toolchain}')
667667

668+
if self.instance.compiler:
669+
cmake_args.append(f'-DTOOLCHAIN_VARIANT_COMPILER={self.instance.compiler}')
670+
668671
# If needed, run CMake using the package_helper script first, to only run
669672
# a subset of all cmake modules. This output will be used to filter
670673
# testcases, and the full CMake configuration will be run for

scripts/pylib/twister/twisterlib/testinstance.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TestInstance:
4949

5050
__test__ = False
5151

52-
def __init__(self, testsuite, platform, toolchain, outdir):
52+
def __init__(self, testsuite, platform, toolchain, outdir, compiler='gnu'):
5353

5454
self.testsuite: TestSuite = testsuite
5555
self.platform: Platform = platform
@@ -66,7 +66,8 @@ def __init__(self, testsuite, platform, toolchain, outdir):
6666
self.build_time = 0
6767
self.retries = 0
6868
self.toolchain = toolchain
69-
self.name = os.path.join(platform.name, toolchain, testsuite.name)
69+
self.compiler = compiler
70+
self.name = os.path.join(platform.name, toolchain, compiler, testsuite.name)
7071
self.dut = None
7172
self.suite_repeat = None
7273
self.test_repeat = None

scripts/tests/twister/test_environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,10 @@ def mock_popen(command, *args, **kwargs):
548548
(
549549
{
550550
'returncode': 0,
551-
'stdout': '{\"ZEPHYR_TOOLCHAIN_VARIANT\": \"dummy toolchain\"}'
551+
'stdout': '{\"ZEPHYR_TOOLCHAIN_VARIANT\": \"dummy toolchain\", \"TOOLCHAIN_VARIANT_COMPILER\": \"gnu\"}'
552552
},
553553
None,
554-
'Using \'dummy toolchain\' toolchain.'
554+
'Using \'dummy toolchain/gnu\' toolchain variant.'
555555
),
556556
(
557557
{'returncode': 1},

scripts/tests/twister/test_runner.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ def mock_popen(*args, **kwargs):
382382
'-DEXTRA_GEN_EDT_ARGS=--edtlib-Werror', '-Gdummy_generator',
383383
f'-DPython3_EXECUTABLE={pathlib.Path(sys.executable).as_posix()}',
384384
'-DZEPHYR_TOOLCHAIN_VARIANT=zephyr',
385+
'-DTOOLCHAIN_VARIANT_COMPILER=gnu',
385386
'-S' + os.path.join('source', 'dir'),
386387
'arg1', 'arg2',
387388
'-DBOARD=<platform name>',
@@ -398,6 +399,7 @@ def mock_popen(*args, **kwargs):
398399
'-DEXTRA_GEN_EDT_ARGS=', '-Gdummy_generator',
399400
f'-DPython3_EXECUTABLE={pathlib.Path(sys.executable).as_posix()}',
400401
'-DZEPHYR_TOOLCHAIN_VARIANT=zephyr',
402+
'-DTOOLCHAIN_VARIANT_COMPILER=gnu',
401403
'-Szephyr_base/share/sysbuild',
402404
'-DAPP_DIR=' + os.path.join('source', 'dir'),
403405
'arg1', 'arg2',
@@ -454,6 +456,7 @@ def mock_popen(*args, **kwargs):
454456
instance_mock.status = TwisterStatus.NONE
455457
instance_mock.reason = None
456458
instance_mock.toolchain = 'zephyr'
459+
instance_mock.compiler = 'gnu'
457460
instance_mock.testsuite = mock.Mock()
458461
instance_mock.testsuite.name = 'testcase'
459462
instance_mock.testsuite.required_snippets = ['dummy snippet 1', 'ds2']
@@ -727,6 +730,7 @@ def mock_pickle(datafile):
727730
instance_mock = mock.Mock()
728731
instance_mock.sysbuild = 'sysbuild' if sysbuild else None
729732
instance_mock.toolchain = 'zephyr'
733+
instance_mock.compiler = 'gnu'
730734
fb.instance = instance_mock
731735
fb.env = mock.Mock()
732736
fb.env.options = mock.Mock()
@@ -2085,6 +2089,7 @@ def test_projectbuilder_report_out(
20852089
instance_mock.status = status
20862090
instance_mock.reason = 'dummy reason'
20872091
instance_mock.toolchain = 'zephyr'
2092+
instance_mock.compiler = 'gnu'
20882093
instance_mock.testsuite.name = 'dummy.testsuite.name'
20892094
skip_mock_tc = mock.Mock(status=TwisterStatus.SKIP, reason=None)
20902095
skip_mock_tc.name = 'mocked_testcase_to_skip'

scripts/tests/twister/test_testplan.py

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -268,34 +268,34 @@ def test_add_instances_short(tmp_path, class_env, all_testsuites_dict, platforms
268268
instance_list.append(instance)
269269
plan.add_instances(instance_list)
270270
assert list(plan.instances.keys()) == \
271-
[platform.name + '/zephyr/' + s for s in list(all_testsuites_dict.keys())]
271+
[platform.name + '/zephyr/gnu/' + s for s in list(all_testsuites_dict.keys())]
272272
assert all(isinstance(n, TestInstance) for n in list(plan.instances.values()))
273273
assert list(plan.instances.values()) == instance_list
274274

275275

276276
QUARANTINE_BASIC = {
277-
'demo_board_1/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1' : 'a1 on board_1 and board_3',
278-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1' : 'a1 on board_1 and board_3'
277+
'demo_board_1/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1' : 'a1 on board_1 and board_3',
278+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1' : 'a1 on board_1 and board_3'
279279
}
280280

281281
QUARANTINE_WITH_REGEXP = {
282-
'demo_board_2/unit_testing/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_2' : 'a2 and c2 on x86',
283-
'demo_board_1/unit_testing/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all test_d',
284-
'demo_board_3/unit_testing/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all test_d',
285-
'demo_board_2/unit_testing/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all test_d',
286-
'demo_board_2/unit_testing/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_c/test_c.check_2' : 'a2 and c2 on x86'
282+
'demo_board_2/unit_testing/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_2' : 'a2 and c2 on x86',
283+
'demo_board_1/unit_testing/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all test_d',
284+
'demo_board_3/unit_testing/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all test_d',
285+
'demo_board_2/unit_testing/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all test_d',
286+
'demo_board_2/unit_testing/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_c/test_c.check_2' : 'a2 and c2 on x86'
287287
}
288288

289289
QUARANTINE_PLATFORM = {
290-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1' : 'all on board_3',
291-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_2' : 'all on board_3',
292-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all on board_3',
293-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_b/test_b.check_1' : 'all on board_3',
294-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_b/test_b.check_2' : 'all on board_3',
295-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_c/test_c.check_1' : 'all on board_3',
296-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_c/test_c.check_2' : 'all on board_3',
297-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_e/test_e.check_1' : 'all on board_3',
298-
'demo_board_3/zephyr/scripts/tests/twister/test_data/testsuites/tests/test_config/test_config.main' : 'all on board_3'
290+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1' : 'all on board_3',
291+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_2' : 'all on board_3',
292+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_d/test_d.check_1' : 'all on board_3',
293+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_b/test_b.check_1' : 'all on board_3',
294+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_b/test_b.check_2' : 'all on board_3',
295+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_c/test_c.check_1' : 'all on board_3',
296+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_c/test_c.check_2' : 'all on board_3',
297+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_e/test_e.check_1' : 'all on board_3',
298+
'demo_board_3/zephyr/gnu/scripts/tests/twister/test_data/testsuites/tests/test_config/test_config.main' : 'all on board_3'
299299
}
300300

301301
QUARANTINE_MULTIFILES = {
@@ -621,24 +621,28 @@ def test_testplan_load(
621621
"name": "ts1",
622622
"platform": "t-p1",
623623
"toolchain": "zephyr",
624+
"compiler": "gnu",
624625
"testcases": []
625626
},
626627
{
627628
"name": "ts1",
628629
"platform": "t-p2",
629630
"toolchain": "zephyr",
631+
"compiler": "gnu",
630632
"testcases": []
631633
},
632634
{
633635
"name": "ts2",
634636
"platform": "t-p3",
635637
"toolchain": "zephyr",
638+
"compiler": "gnu",
636639
"testcases": []
637640
},
638641
{
639642
"name": "ts2",
640643
"platform": "t-p4",
641644
"toolchain": "zephyr",
645+
"compiler": "gnu",
642646
"testcases": []
643647
}
644648
]
@@ -654,24 +658,28 @@ def test_testplan_load(
654658
"name": "ts1",
655659
"platform": "ts-p1",
656660
"toolchain": "zephyr",
661+
"compiler": "gnu",
657662
"testcases": []
658663
},
659664
{
660665
"name": "ts1",
661666
"platform": "ts-p2",
662667
"toolchain": "zephyr",
668+
"compiler": "gnu",
663669
"testcases": []
664670
},
665671
{
666672
"name": "ts2",
667673
"platform": "ts-p3",
668674
"toolchain": "zephyr",
675+
"compiler": "gnu",
669676
"testcases": []
670677
},
671678
{
672679
"name": "ts2",
673680
"platform": "ts-p4",
674681
"toolchain": "zephyr",
682+
"compiler": "gnu",
675683
"testcases": []
676684
}
677685
]
@@ -687,24 +695,28 @@ def test_testplan_load(
687695
"name": "ts1",
688696
"platform": "lt-p1",
689697
"toolchain": "zephyr",
698+
"compiler": "gnu",
690699
"testcases": []
691700
},
692701
{
693702
"name": "ts1",
694703
"platform": "lt-p2",
695704
"toolchain": "zephyr",
705+
"compiler": "gnu",
696706
"testcases": []
697707
},
698708
{
699709
"name": "ts2",
700710
"platform": "lt-p3",
701711
"toolchain": "zephyr",
702-
\"testcases": []
712+
"compiler": "gnu",
713+
"testcases": []
703714
},
704715
{
705716
"name": "ts2",
706717
"platform": "lt-p4",
707718
"toolchain": "zephyr",
719+
"compiler": "gnu",
708720
"testcases": []
709721
}
710722
]
@@ -1376,24 +1388,29 @@ def get_platform(name):
13761388
ts1 = mock.Mock(testcases=[ts1tc1])
13771389
ts1.name = 'TestSuite 1'
13781390
ts1.toolchain = 'zephyr'
1391+
ts1.compiler = 'gnu'
13791392
ts2 = mock.Mock(testcases=[])
13801393
ts2.name = 'TestSuite 2'
13811394
ts2.toolchain = 'zephyr'
1395+
ts2.compiler = 'gnu'
13821396
ts3tc1 = mock.Mock()
13831397
ts3tc1.name = 'TS3.tc1'
13841398
ts3tc2 = mock.Mock()
13851399
ts3tc2.name = 'TS3.tc2'
13861400
ts3 = mock.Mock(testcases=[ts3tc1, ts3tc2])
13871401
ts3.name = 'TestSuite 3'
13881402
ts3.toolchain = 'zephyr'
1403+
ts3.compiler = 'gnu'
13891404
ts4tc1 = mock.Mock()
13901405
ts4tc1.name = 'TS4.tc1'
13911406
ts4 = mock.Mock(testcases=[ts4tc1])
13921407
ts4.name = 'TestSuite 4'
13931408
ts4.toolchain = 'zephyr'
1409+
ts4.compiler = 'gnu'
13941410
ts5 = mock.Mock(testcases=[])
13951411
ts5.name = 'TestSuite 5'
13961412
ts5.toolchain = 'zephyr'
1413+
ts5.compiler = 'gnu'
13971414

13981415
testplan = TestPlan(env=mock.Mock(outdir=os.path.join('out', 'dir')))
13991416
testplan.options = mock.Mock(device_testing=device_testing, test_only=True, report_summary=None)
@@ -1421,6 +1438,7 @@ def get_platform(name):
14211438
"available_rom": 1047552,
14221439
"status": "passed",
14231440
"toolchain": "zephyr",
1441+
"compiler": "gnu",
14241442
"reason": "OK",
14251443
"testcases": [
14261444
{
@@ -1435,7 +1453,8 @@ def get_platform(name):
14351453
{
14361454
"name": "TestSuite 2",
14371455
"platform": "Platform 1",
1438-
"toolchain": "zephyr"
1456+
"toolchain": "zephyr",
1457+
"compiler": "gnu"
14391458
},
14401459
{
14411460
"name": "TestSuite 3",
@@ -1448,6 +1467,7 @@ def get_platform(name):
14481467
"available_rom": 1047552,
14491468
"status": "error",
14501469
"toolchain": "zephyr",
1470+
"compiler": "gnu",
14511471
"reason": "File Not Found Error",
14521472
"testcases": [
14531473
{
@@ -1472,6 +1492,7 @@ def get_platform(name):
14721492
"available_rom": 1047552,
14731493
"status": "skipped",
14741494
"toolchain": "zephyr",
1495+
"compiler": "gnu",
14751496
"reason": "Not in requested test list.",
14761497
"testcases": [
14771498
{
@@ -1489,7 +1510,8 @@ def get_platform(name):
14891510
{
14901511
"name": "TestSuite 5",
14911512
"platform": "Platform 2",
1492-
"toolchain": "zephyr"
1513+
"toolchain": "zephyr",
1514+
"compiler": "gnu"
14931515
}
14941516
]
14951517
}
@@ -1505,7 +1527,8 @@ def get_platform(name):
15051527
testplan.load_from_file('dummy.yaml', filter_platform)
15061528

15071529
expected_instances = {
1508-
'Platform 1/zephyr/TestSuite 1': {
1530+
'Platform 1/zephyr/gnu/TestSuite 1': {
1531+
'compiler': 'gnu',
15091532
'metrics': {
15101533
'handler_time': 60.0,
15111534
'used_ram': 4096,
@@ -1515,6 +1538,7 @@ def get_platform(name):
15151538
},
15161539
'retries': 0,
15171540
'toolchain': 'zephyr',
1541+
"compiler": "gnu",
15181542
'testcases': {
15191543
'TS1.tc1': {
15201544
'status': TwisterStatus.PASS,
@@ -1524,7 +1548,8 @@ def get_platform(name):
15241548
}
15251549
}
15261550
},
1527-
'Platform 1/zephyr/TestSuite 2': {
1551+
'Platform 1/zephyr/gnu/TestSuite 2': {
1552+
'compiler': 'gnu',
15281553
'metrics': {
15291554
'handler_time': 0,
15301555
'used_ram': 0,
@@ -1534,9 +1559,11 @@ def get_platform(name):
15341559
},
15351560
'retries': 0,
15361561
'toolchain': 'zephyr',
1562+
"compiler": "gnu",
15371563
'testcases': []
15381564
},
1539-
'Platform 1/zephyr/TestSuite 3': {
1565+
'Platform 1/zephyr/gnu/TestSuite 3': {
1566+
'compiler': 'gnu',
15401567
'metrics': {
15411568
'handler_time': 360.0,
15421569
'used_ram': 4096,
@@ -1546,6 +1573,7 @@ def get_platform(name):
15461573
},
15471574
'retries': 1,
15481575
'toolchain': 'zephyr',
1576+
"compiler": "gnu",
15491577
'testcases': {
15501578
'TS3.tc1': {
15511579
'status': TwisterStatus.ERROR,
@@ -1561,7 +1589,8 @@ def get_platform(name):
15611589
}
15621590
}
15631591
},
1564-
'Platform 1/zephyr/TestSuite 4': {
1592+
'Platform 1/zephyr/gnu/TestSuite 4': {
1593+
'compiler': 'gnu',
15651594
'metrics': {
15661595
'handler_time': 360.0,
15671596
'used_ram': 4096,
@@ -1571,6 +1600,7 @@ def get_platform(name):
15711600
},
15721601
'retries': 0,
15731602
'toolchain': 'zephyr',
1603+
"compiler": "gnu",
15741604
'testcases': {
15751605
'TS4.tc1': {
15761606
'status': TwisterStatus.SKIP,

0 commit comments

Comments
 (0)