winIDEA SDK
Loading...
Searching...
No Matches
itest_sample.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
winidea_id = ''
def verify_result(results):
while results.hasNextTestResult():
result = results.nextTestResult()
if result.isError():
out = ic.CStringStream()
emitter = ic.EmitterFactory.createYamlEmitter(out)
emitter.startStream()
emitter.startDocument(False)
result.serializeErrorsOnly(emitter, None)
emitter.endDocument(False)
emitter.endStream()
print(out.getString())
else:
print("OK")
def init_target() -> it.PTestCase:
cmgr = ic.ConnectionMgr()
cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
debug_ctrl = ic.CDebugFacade(cmgr)
# initialize the target - this may differ in your environment
debug_ctrl.reset()
debug_ctrl.runUntilFunction("main")
debug_ctrl.waitUntilStopped()
test_case = it.PTestCase(cmgr)
return test_case
def run_test_case(test_case: it.PTestCase):
# The simplest test case, not very useful for testing,
# but may be used to call functions on the target, for example
# for initialization.
test_case.itest("func: [get_random]", None)
print("'get_random' finished!")
# Simple test of function: int funcTestInt2(int a, int b, int c)
test_case.itest(
"""
func: [sum, [3, 4, 5], retVal]
expect:
- retVal == 12
""",
None, True)
print('Test result:', end=' ')
verify_result(test_case.getTestResultsContainer())
# Intentional error
def run_test_case_with_error(test_case: it.PTestCase):
test_case.itest(
"""
func: [return_smaller, [3, 2], retVal]
expect:
- retVal == 2
""",
None)
print('return_smaller test result if error:', end=' ')
verify_result(test_case.getTestResultsContainer())
def main():
test_case = init_target()
run_test_case(test_case)
run_test_case_with_error(test_case)
if __name__ == '__main__':
main()