PlatSim_Genova/TestEnvironment/scripts/GRIFO_test_debug.py
2026-01-30 16:38:33 +01:00

106 lines
4.3 KiB
Python

import time,sys
import __init__
from leo_sdr_common import *
from test_common_function import *
from leo_sdr_test_report import testReport
from logger import logger_setup
from leo_sdr_xsct import theXSCTInterface
def test_proc():
report = testReport(sys.argv[0])
test_name = 'RBT_test_debug'
logger_setup(f'{test_name}.log')
# per instrumentare il codice a livello di debug dei breakpoints si inseriscono a lato della riga di
# codice uno o piu commenti nella forma : __XSCT_DEBUG__@<test_name>:BP#<id>
# fatto questo findBreakPoints trovera tutti i breakpoints organizzati in un dizionario ha chiave multipla test_name/file/id
res = theXSCTInterface.findBreakPoints('BLACK',test_name)
logging.info(res)
#organizzo i risulati ( che devo cmq. aver noto )
ln0 = res[test_name]['src_ct_oe/Services/SC_BiteService/CSCBiteService.cpp']['0']
ln1 = res[test_name]['src_ct_oe/CfCtrl/SC_SysCtrl/CSCSysCtrlBitIf.cpp']['1']
ln2 = res[test_name]['src_ct_oe/CfCtrl/SC_SysCtrl/CSCSysCtrlBitIf.cpp']['2']
#organizzo i dizionari dei brekpoints
bp0 = dict(file='src_ct_oe/Services/SC_BiteService/CSCBiteService.cpp', line=ln0, id=None, address=None)
bp1 = dict(file='src_ct_oe/CfCtrl/SC_SysCtrl/CSCSysCtrlBitIf.cpp', line=ln1, id=None, address=None)
bp2 = dict(file='src_ct_oe/CfCtrl/SC_SysCtrl/CSCSysCtrlBitIf.cpp', line=ln2, id=None, address=None)
# li metto in uma lista ( per comodita'
breakpoints = ( bp0, bp1, bp2 )
report.open_session('Pre Conditions')
# mi collego al demone che gira du SDK
setValue(theXSCTInterface,True,'Connect')
# configuro il debugger per il tipo di target ( RED|BLACK )
setValue(theXSCTInterface,'BLACK','Init')
# itero sui breakpoints per recuperare i'id e il relativo indirizzo ( esco in caso di errore )
for b in breakpoints:
b['id'],err = getValue(theXSCTInterface,'BreakPointSet',b['file'],b['line'])
if err :
return
b['address'],err = getValue(theXSCTInterface,'BreakPointAddress',b['id'])
if err :
return
report.close_session()
print(breakpoints)
try:
############ BEGIN STEPS ############
report.open_session('Test Execution')
# il primo breakpoint e' per default sulla prima istruzione del main ...
# gli dico al debugger di fare run/continue con un timeout massimo di 10 secondi
setValue(theXSCTInterface,10,'Continue')
# leggo l'indirizzo corrente
cur,err = getValue(theXSCTInterface,'CurrentAddress',hex=True)
logging.info(f'cur address is 0x{cur:X}')
#
# .. continuo il debugger ( sara' in statio running )
setValue(theXSCTInterface,10,'Continue')
# uscito dalla funzione ( o perche sono in un breakpoint o perche sono trascorsi 10 secondi ) leggo lo stack
cur,err = getValue(theXSCTInterface,'Stack')
logging.info(f'stacktrace:\n{cur}')
# controllo che l'indirizzo dello stack effettivamente coincide con quello del breakpoint # 0
check(theXSCTInterface,bp0['address'],'CurrentAddress',hex=True)
# modifico la variabile locale a_ul32LastV = 1
# valore, funz, nome variabile
setValue(theXSCTInterface,1,'SetVar', 'a_ul32LastV')
# continuo ...
setValue(theXSCTInterface,10,'Continue')
# controllo che l'indirizzo dello stack effettivamente coincide con quello del breakpoint # 1
check(theXSCTInterface,bp1['address'],'CurrentAddress',hex=True)
# continuo ...
setValue(theXSCTInterface,10,'Continue')
# mi rifermero al primo bp e ...
check(theXSCTInterface,bp0['address'],'CurrentAddress',hex=True)
# ri-modifico la variabile locale a_ul32LastV = 0
setValue(theXSCTInterface,0,'SetVar', 'a_ul32LastV')
# .. cosi facendo dovrei fermarmi al secondo bp
setValue(theXSCTInterface,10,'Continue')
check(theXSCTInterface,bp2['address'],'CurrentAddress',hex=True)
except Exception as e:
report.add_comment(f"Test terminated unexpectedly :{e}")
finally:
report.close_session()
############ END STEPS ############
report.open_session('Post Conditions')
#getVectorCastDump()
report.close_session()
report.generate_pdf()
if __name__ == '__main__':
test_proc()