winIDEA SDK
filter_tests.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6import isystem.itest as it
7from typing import List
8
9
10winidea_id = ''
11
12
13def init_target() -> ic.ConnectionMgr:
14 connection_mgr = ic.ConnectionMgr()
15 connection_mgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
16
17 debug_ctrl = ic.CDebugFacade(connection_mgr)
18 debug_ctrl.reset()
19 debug_ctrl.runUntilFunction('main')
20 debug_ctrl.waitUntilStopped()
21
22 return connection_mgr
23
24
25def run_tests_recursive(test_case: it.PTestCase, test_spec: ic.CTestSpecification,
26 filter_tag: str, results: List[ic.CTestResult]):
27 """
28 This method runs derived tests recursively. Some basic filtering
29 is performed on tags.
30 """
31
32 if test_spec.getRunFlag():
33
34 merged_test_spec = test_spec.merge()
35
36 tags = ic.StrVector()
37 merged_test_spec.getTags(tags)
38
39 if filter_tag in tags:
40 # merge base test spec and the derived one into one test spec
41
42 print('executing:', merged_test_spec.getTestId())
43 test_case.itest(merged_test_spec, None)
44 results.append(test_case.getTestResultsContainer().nextTestResult())
45
46 num_derived_test_specs = test_spec.getNoOfDerivedSpecs()
47 for idx in range(0, num_derived_test_specs):
48 run_tests_recursive(test_case, test_spec.getDerivedTestSpec(idx), filter_tag, results)
49
50
51def run_tests(connection_mgr: ic.ConnectionMgr) -> List[ic.CTestResult]:
52 print("Should run only tests with IDs 'test-2' and 'test-2-1'")
53
54 test_case = it.PTestCase(connection_mgr)
55
56 test_case.reset() # just in case there's something left from previous run
57
58 # Load test spec from file
59 test_bench = ic.CTestBench.load('test_min_int.iyaml', 0)
60 root_test_spec = test_bench.getTestSpecification(True)
61 # Root test specification is only a container - mark it as not executable
62 root_test_spec.setRunFlag(False)
63
64 test_results = []
65
66 tag_used_for_test_filtering = 'extended'
67 run_tests_recursive(test_case, root_test_spec, tag_used_for_test_filtering, test_results)
68
69 return test_results
70
71
72def print_test_results(test_results: List[ic.CTestResult]):
73 for test_result in test_results:
74 if test_result.isError():
75 print("Error: ", test_result.getTestId())
76 else:
77 print("OK: ", test_result.getTestId())
78
79
80def main():
81 cmgr = init_target()
82 test_results = run_tests(cmgr)
83 print_test_results(test_results)
84
85
86if __name__ == '__main__':
87 main()