winIDEA SDK
Loading...
Searching...
No Matches
persistent_vars.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 verifyResult(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() -> ic.ConnectionMgr:
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.download()
debug_ctrl.runUntilFunction("main")
debug_ctrl.waitUntilStopped()
return cmgr
def run_tests(cmgr: ic.ConnectionMgr):
test_case = it.PTestCase(cmgr)
itest_ctrl = ic.CSystemTestController(cmgr)
itest_ctrl.createPersistentVariable('myvar1', 'int')
itest_ctrl.createPersistentVariable('myvar2', 'int')
itest_ctrl.createPersistentVariable('myvar3', 'int')
itest_ctrl.initPersistentVars()
itest_ctrl.modify('myvar1', '123')
itest_ctrl.modify('myvar2', '456')
itest_ctrl.modify('myvar3', '789')
print('Variable exists before the test: ', itest_ctrl.evaluate('myvar1,d'))
print('Variable exists before the test: ', itest_ctrl.evaluate('myvar2,d'))
print('Variable exists before the test: ', itest_ctrl.evaluate('myvar3,d'))
test_case.itest(
"""
func: [sum, [myvar1, myvar2, myvar3], retVal]
expect:
- myvar1 == 123
- myvar2 == 456
- myvar3 == 789
- retVal == 1368
""",
None, False)
verifyResult(test_case.getTestResultsContainer())
print('Variable exists between tests: ', itest_ctrl.evaluate('myvar1,d'))
print('Variable exists between tests: ', itest_ctrl.evaluate('myvar2,d'))
print('Variable exists between tests: ', itest_ctrl.evaluate('myvar3,d'))
test_case.itest(
"""
func: [sum, [123, 456, 789], retVal]
expect:
- myvar1 == 123
- myvar2 == 456
- myvar3 == 789
- retVal == (myvar1 + myvar2 + myvar3)
""",
None, False)
verifyResult(test_case.getTestResultsContainer())
print('Variable exists after tests: ', itest_ctrl.evaluate('myvar1,d'))
print('Variable exists after tests: ', itest_ctrl.evaluate('myvar2,d'))
print('Variable exists after tests: ', itest_ctrl.evaluate('myvar3,d'))
itest_ctrl.cleanPersistentVars()
try:
print('Variable should no longer exist after cleanup: ', itest_ctrl.evaluate('myvar1,d'))
print('Variable should no longer exist after cleanup: ', itest_ctrl.evaluate('myvar2,d'))
print('Variable should no longer exist after cleanup: ', itest_ctrl.evaluate('myvar3,d'))
except OSError:
print('\nPersistent variables no longer exist.')
else:
raise Exception('Variable should no longer exist after cleanup!')
def main():
cmgr = init_target()
run_tests(cmgr)
if __name__ == '__main__':
main()