winIDEA SDK
Loading...
Searching...
No Matches
filter_tests.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
import isystem.itest as it
from typing import List
winidea_id = ''
def init_target() -> ic.ConnectionMgr:
connection_mgr = ic.ConnectionMgr()
connection_mgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debug_ctrl = ic.CDebugFacade(connection_mgr)
debug_ctrl.reset()
debug_ctrl.runUntilFunction('main')
debug_ctrl.waitUntilStopped()
return connection_mgr
def run_tests_recursive(test_case: it.PTestCase, test_spec: ic.CTestSpecification,
filter_tag: str, results: List[ic.CTestResult]):
"""
This method runs derived tests recursively. Some basic filtering
is performed on tags.
"""
if test_spec.getRunFlag():
merged_test_spec = test_spec.merge()
tags = ic.StrVector()
merged_test_spec.getTags(tags)
if filter_tag in tags:
# merge base test spec and the derived one into one test spec
print('executing:', merged_test_spec.getTestId())
test_case.itest(merged_test_spec, None)
results.append(test_case.getTestResultsContainer().nextTestResult())
num_derived_test_specs = test_spec.getNoOfDerivedSpecs()
for idx in range(0, num_derived_test_specs):
run_tests_recursive(test_case, test_spec.getDerivedTestSpec(idx), filter_tag, results)
def run_tests(connection_mgr: ic.ConnectionMgr) -> List[ic.CTestResult]:
print("Should run only tests with IDs 'test-2' and 'test-2-1'")
test_case = it.PTestCase(connection_mgr)
test_case.reset() # just in case there's something left from previous run
# Load test spec from file
test_bench = ic.CTestBench.load('test_min_int.iyaml', 0)
root_test_spec = test_bench.getTestSpecification(True)
# Root test specification is only a container - mark it as not executable
root_test_spec.setRunFlag(False)
test_results = []
tag_used_for_test_filtering = 'extended'
run_tests_recursive(test_case, root_test_spec, tag_used_for_test_filtering, test_results)
return test_results
def print_test_results(test_results: List[ic.CTestResult]):
for test_result in test_results:
if test_result.isError():
print("Error: ", test_result.getTestId())
else:
print("OK: ", test_result.getTestId())
def main():
cmgr = init_target()
test_results = run_tests(cmgr)
print_test_results(test_results)
if __name__ == '__main__':
main()