Skip to content

Commit ca1b6bc

Browse files
committed
twister: unittests: align tests with changes for shared apps
Fixed unittests after adding shared apps feature. Signed-off-by: Grzegorz Chwierut <[email protected]>
1 parent 07a1e8e commit ca1b6bc

File tree

2 files changed

+51
-55
lines changed

2 files changed

+51
-55
lines changed

scripts/tests/twister/test_handlers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,31 +1540,28 @@ def mock_process(pid):
15401540
(
15411541
True,
15421542
os.path.join('self', 'dummy_dir', '1'),
1543-
mock.PropertyMock(return_value=os.path.join('dummy_dir', '1')),
1544-
os.path.join('dummy_dir', '1')
1543+
os.path.join('self', 'dummy_dir', '1', 'domain_name')
15451544
),
15461545
(
15471546
False,
15481547
os.path.join('self', 'dummy_dir', '2'),
1549-
mock.PropertyMock(return_value=os.path.join('dummy_dir', '2')),
15501548
os.path.join('self', 'dummy_dir', '2')
15511549
),
15521550
]
15531551

15541552
@pytest.mark.parametrize(
1555-
'self_sysbuild, self_build_dir, build_dir, expected',
1553+
'self_sysbuild, self_build_dir, expected',
15561554
TESTDATA_19,
15571555
ids=['domains build dir', 'self build dir']
15581556
)
15591557
def test_qemuhandler_get_default_domain_build_dir(
15601558
mocked_instance,
15611559
self_sysbuild,
15621560
self_build_dir,
1563-
build_dir,
15641561
expected
15651562
):
15661563
get_default_domain_mock = mock.Mock()
1567-
type(get_default_domain_mock()).build_dir = build_dir
1564+
type(get_default_domain_mock()).name = 'domain_name'
15681565
domains_mock = mock.Mock(get_default_domain=get_default_domain_mock)
15691566
from_file_mock = mock.Mock(return_value=domains_mock)
15701567

scripts/tests/twister/test_runner.py

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import os
1212
import pathlib
1313
import pytest
14-
import queue
1514
import re
1615
import subprocess
1716
import sys
1817
import yaml
1918

19+
from collections import deque
2020
from contextlib import nullcontext
2121
from elftools.elf.sections import SymbolTableSection
2222
from typing import List
@@ -859,7 +859,7 @@ def mock_getsize(filename, *args, **kwargs):
859859

860860

861861
TESTDATA_6 = [
862-
(
862+
( # filter, failed
863863
{'op': 'filter'},
864864
TwisterStatus.FAIL,
865865
'Failed',
@@ -881,7 +881,7 @@ def mock_getsize(filename, *args, **kwargs):
881881
0,
882882
None
883883
),
884-
(
884+
( # filter, cmake res
885885
{'op': 'filter'},
886886
TwisterStatus.PASS,
887887
mock.ANY,
@@ -903,7 +903,7 @@ def mock_getsize(filename, *args, **kwargs):
903903
1,
904904
(TwisterStatus.SKIP,)
905905
),
906-
(
906+
( # filter, no cmake res
907907
{'op': 'filter'},
908908
TwisterStatus.PASS,
909909
mock.ANY,
@@ -925,7 +925,7 @@ def mock_getsize(filename, *args, **kwargs):
925925
0,
926926
None
927927
),
928-
(
928+
( # cmake, failed
929929
{'op': 'cmake'},
930930
TwisterStatus.ERROR,
931931
'dummy error',
@@ -947,7 +947,7 @@ def mock_getsize(filename, *args, **kwargs):
947947
0,
948948
None
949949
),
950-
(
950+
( # cmake, cmake_only, no status
951951
{'op': 'cmake'},
952952
TwisterStatus.NONE,
953953
mock.ANY,
@@ -969,7 +969,7 @@ def mock_getsize(filename, *args, **kwargs):
969969
0,
970970
None
971971
),
972-
(
972+
( # cmake, cmake_only
973973
{'op': 'cmake'},
974974
'success',
975975
mock.ANY,
@@ -991,7 +991,7 @@ def mock_getsize(filename, *args, **kwargs):
991991
0,
992992
None
993993
),
994-
(
994+
( # cmake, no cmake_only, cmake res
995995
{'op': 'cmake'},
996996
'success',
997997
mock.ANY,
@@ -1013,7 +1013,7 @@ def mock_getsize(filename, *args, **kwargs):
10131013
1,
10141014
(TwisterStatus.SKIP,)
10151015
),
1016-
(
1016+
( # cmake, no cmake_only, no cmake res
10171017
{'op': 'cmake'},
10181018
'success',
10191019
mock.ANY,
@@ -1035,7 +1035,7 @@ def mock_getsize(filename, *args, **kwargs):
10351035
0,
10361036
None
10371037
),
1038-
(
1038+
( # build, no build res
10391039
{'op': 'build'},
10401040
mock.ANY,
10411041
None,
@@ -1057,7 +1057,7 @@ def mock_getsize(filename, *args, **kwargs):
10571057
0,
10581058
None
10591059
),
1060-
(
1060+
( # build, skipped
10611061
{'op': 'build'},
10621062
TwisterStatus.SKIP,
10631063
mock.ANY,
@@ -1080,7 +1080,7 @@ def mock_getsize(filename, *args, **kwargs):
10801080
1,
10811081
(TwisterStatus.SKIP, mock.ANY)
10821082
),
1083-
(
1083+
( # build, blocked
10841084
{'op': 'build'},
10851085
TwisterStatus.PASS,
10861086
mock.ANY,
@@ -1102,7 +1102,7 @@ def mock_getsize(filename, *args, **kwargs):
11021102
0,
11031103
(TwisterStatus.BLOCK, mock.ANY)
11041104
),
1105-
(
1105+
( # build, determine testcases
11061106
{'op': 'build'},
11071107
'success',
11081108
mock.ANY,
@@ -1125,7 +1125,7 @@ def mock_getsize(filename, *args, **kwargs):
11251125
0,
11261126
None
11271127
),
1128-
(
1128+
( # build, determine testcases Error
11291129
{'op': 'build'},
11301130
'success',
11311131
mock.ANY,
@@ -1148,7 +1148,7 @@ def mock_getsize(filename, *args, **kwargs):
11481148
0,
11491149
None
11501150
),
1151-
(
1151+
( # gather metrics, run and ready handler
11521152
{'op': 'gather_metrics'},
11531153
mock.ANY,
11541154
mock.ANY,
@@ -1169,8 +1169,8 @@ def mock_getsize(filename, *args, **kwargs):
11691169
mock.ANY,
11701170
0,
11711171
None
1172-
), # 'gather metrics, run and ready handler'
1173-
(
1172+
),
1173+
( # gather metrics
11741174
{'op': 'gather_metrics'},
11751175
mock.ANY,
11761176
mock.ANY,
@@ -1191,8 +1191,8 @@ def mock_getsize(filename, *args, **kwargs):
11911191
mock.ANY,
11921192
0,
11931193
None
1194-
), # 'gather metrics'
1195-
(
1194+
),
1195+
( # build ok, gather metrics fail
11961196
{'op': 'gather_metrics'},
11971197
mock.ANY,
11981198
mock.ANY,
@@ -1213,8 +1213,8 @@ def mock_getsize(filename, *args, **kwargs):
12131213
'Build Failure at gather_metrics.',
12141214
0,
12151215
None
1216-
), # 'build ok, gather metrics fail',
1217-
(
1216+
),
1217+
( # run
12181218
{'op': 'run'},
12191219
'success',
12201220
'OK',
@@ -1237,7 +1237,7 @@ def mock_getsize(filename, *args, **kwargs):
12371237
0,
12381238
None
12391239
),
1240-
(
1240+
( # run, Pipeline Runtime Error
12411241
{'op': 'run'},
12421242
TwisterStatus.FAIL,
12431243
mock.ANY,
@@ -1261,7 +1261,7 @@ def mock_getsize(filename, *args, **kwargs):
12611261
0,
12621262
None
12631263
),
1264-
(
1264+
( # report, prep artifacts for testing
12651265
{'op': 'report'},
12661266
mock.ANY,
12671267
mock.ANY,
@@ -1283,7 +1283,7 @@ def mock_getsize(filename, *args, **kwargs):
12831283
0,
12841284
None
12851285
),
1286-
(
1286+
( # report, runtime artifact cleanup pass, status passed
12871287
{'op': 'report'},
12881288
TwisterStatus.PASS,
12891289
mock.ANY,
@@ -1305,7 +1305,7 @@ def mock_getsize(filename, *args, **kwargs):
13051305
0,
13061306
None
13071307
),
1308-
(
1308+
( # report, runtime artifact cleanup all
13091309
{'op': 'report'},
13101310
mock.ANY,
13111311
mock.ANY,
@@ -1327,7 +1327,7 @@ def mock_getsize(filename, *args, **kwargs):
13271327
0,
13281328
None
13291329
),
1330-
(
1330+
( # report, no message put
13311331
{'op': 'report'},
13321332
mock.ANY,
13331333
mock.ANY,
@@ -1349,7 +1349,7 @@ def mock_getsize(filename, *args, **kwargs):
13491349
0,
13501350
None
13511351
),
1352-
(
1352+
( # cleanup, device
13531353
{'op': 'cleanup', 'mode': 'device'},
13541354
mock.ANY,
13551355
mock.ANY,
@@ -1371,7 +1371,7 @@ def mock_getsize(filename, *args, **kwargs):
13711371
0,
13721372
None
13731373
),
1374-
(
1374+
( # cleanup, mode passed
13751375
{'op': 'cleanup', 'mode': 'passed'},
13761376
mock.ANY,
13771377
mock.ANY,
@@ -1393,7 +1393,7 @@ def mock_getsize(filename, *args, **kwargs):
13931393
0,
13941394
None
13951395
),
1396-
(
1396+
( # cleanup, mode all
13971397
{'op': 'cleanup', 'mode': 'all'},
13981398
mock.ANY,
13991399
'Valgrind error',
@@ -1415,7 +1415,7 @@ def mock_getsize(filename, *args, **kwargs):
14151415
0,
14161416
None
14171417
),
1418-
(
1418+
( # cleanup, mode all, cmake build failure
14191419
{'op': 'cleanup', 'mode': 'all'},
14201420
mock.ANY,
14211421
'Cmake build failure',
@@ -1489,7 +1489,7 @@ def test_projectbuilder_process(
14891489
expected_skipped,
14901490
expected_missing
14911491
):
1492-
def mock_pipeline_put(msg):
1492+
def mock_pipeline_append(msg):
14931493
if isinstance(pipeline_runtime_error, type) and \
14941494
issubclass(pipeline_runtime_error, Exception):
14951495
raise RuntimeError('Pipeline Error!')
@@ -1526,7 +1526,7 @@ def mock_determine_testcases(res):
15261526
pb.run = mock.Mock()
15271527
pb.gather_metrics = mock.Mock(return_value=metrics_res)
15281528

1529-
pipeline_mock = mock.Mock(put=mock.Mock(side_effect=mock_pipeline_put))
1529+
pipeline_mock = mock.Mock(append=mock.Mock(side_effect=mock_pipeline_append))
15301530
done_mock = mock.Mock()
15311531
lock_mock = mock.Mock(
15321532
__enter__=mock.Mock(return_value=(mock.Mock(), mock.Mock())),
@@ -1540,7 +1540,7 @@ def mock_determine_testcases(res):
15401540
assert all([log in caplog.text for log in expected_logs])
15411541

15421542
if resulting_message:
1543-
pipeline_mock.put.assert_called_with(resulting_message)
1543+
pipeline_mock.append.assert_called_with(resulting_message)
15441544

15451545
assert pb.instance.status == expected_status
15461546
assert pb.instance.reason == expected_reason
@@ -2422,18 +2422,17 @@ def mock_client_from_environ(jobs):
24222422
jobclient_mock = mock.Mock()
24232423
jobclient_mock().name='JobClient'
24242424

2425-
pipeline_q = queue.LifoQueue()
2426-
done_q = queue.LifoQueue()
2425+
pipeline_q = deque()
2426+
done_q = dict()
24272427
done_instance = mock.Mock(
24282428
metrics={'k2': 'v2'},
24292429
execution_time=30
24302430
)
24312431
done_instance.name='dummy instance'
2432-
done_q.put(done_instance)
2432+
done_q[done_instance.name] = done_instance
24332433
manager_mock = mock.Mock()
2434-
manager_mock().LifoQueue = mock.Mock(
2435-
side_effect=iter([pipeline_q, done_q])
2436-
)
2434+
manager_mock().deque = mock.Mock(return_value=pipeline_q)
2435+
manager_mock().get_dict = mock.Mock(return_value=done_q)
24372436

24382437
results_mock = mock.Mock()
24392438
results_mock().error = 1
@@ -2586,11 +2585,11 @@ def mock_get_cmake_filter_stages(filter, keys):
25862585
return [filter]
25872586

25882587
instances = {
2589-
'dummy1': mock.Mock(run=True, retries=0, status=TwisterStatus.PASS, build_dir="/tmp"),
2590-
'dummy2': mock.Mock(run=True, retries=0, status=TwisterStatus.SKIP, build_dir="/tmp"),
2591-
'dummy3': mock.Mock(run=True, retries=0, status=TwisterStatus.FILTER, build_dir="/tmp"),
2592-
'dummy4': mock.Mock(run=True, retries=0, status=TwisterStatus.ERROR, build_dir="/tmp"),
2593-
'dummy5': mock.Mock(run=True, retries=0, status=TwisterStatus.FAIL, build_dir="/tmp")
2588+
'dummy1': mock.Mock(run=True, retries=0, status=TwisterStatus.PASS, build_dir="/tmp", no_own_image=False),
2589+
'dummy2': mock.Mock(run=True, retries=0, status=TwisterStatus.SKIP, build_dir="/tmp", no_own_image=False),
2590+
'dummy3': mock.Mock(run=True, retries=0, status=TwisterStatus.FILTER, build_dir="/tmp", no_own_image=False),
2591+
'dummy4': mock.Mock(run=True, retries=0, status=TwisterStatus.ERROR, build_dir="/tmp", no_own_image=False),
2592+
'dummy5': mock.Mock(run=True, retries=0, status=TwisterStatus.FAIL, build_dir="/tmp", no_own_image=False)
25942593
}
25952594
instances['dummy4'].testsuite.filter = 'some'
25962595
instances['dummy5'].testsuite.filter = 'full'
@@ -2619,10 +2618,10 @@ def mock_get_cmake_filter_stages(filter, keys):
26192618
if retry_build_errors:
26202619
tr.get_cmake_filter_stages.assert_any_call('some', mock.ANY)
26212620

2622-
print(pipeline_mock.put.call_args_list)
2621+
print(pipeline_mock.append.call_args_list)
26232622
print([mock.call(el) for el in expected_pipeline_elements])
26242623

2625-
assert pipeline_mock.put.call_args_list == \
2624+
assert pipeline_mock.append.call_args_list == \
26262625
[mock.call(el) for el in expected_pipeline_elements]
26272626

26282627

@@ -2641,8 +2640,8 @@ def mock_get_nowait():
26412640
nonlocal counter
26422641
counter += 1
26432642
if counter > 5:
2644-
raise queue.Empty()
2645-
return {'test': 'dummy'}
2643+
raise IndexError
2644+
return {'test': mock.Mock(required_images=False)}
26462645

26472646
instances = {}
26482647
suites = []
@@ -2656,7 +2655,7 @@ def mock_get_nowait():
26562655
)
26572656

26582657
pipeline_mock = mock.Mock()
2659-
pipeline_mock.get_nowait = mock.Mock(side_effect=mock_get_nowait)
2658+
pipeline_mock.pop = mock.Mock(side_effect=mock_get_nowait)
26602659
done_queue_mock = mock.Mock()
26612660
lock_mock = mock.Mock()
26622661
results_mock = mock.Mock()

0 commit comments

Comments
 (0)