1111import os
1212import pathlib
1313import pytest
14- import queue
1514import re
1615import subprocess
1716import sys
1817import yaml
1918
19+ from collections import deque
2020from contextlib import nullcontext
2121from elftools .elf .sections import SymbolTableSection
2222from typing import List
@@ -859,7 +859,7 @@ def mock_getsize(filename, *args, **kwargs):
859859
860860
861861TESTDATA_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