Debugging is generally done manually, but for testing and automation you can develop scripts to run in an automated fashion. For this you have to use the Debugger Shell as the command-line debugger and use the TCL as the scripting language. You can perform automation and scripting with the debugger from basic access to memory, to stepping and controlling the execution up to programming the flash memory.
The Debugger shell uses TCL as scripting language. And instead typing in commands, you can save them into a file (for example, myScript.tcl) and execute it with the source command:
source myScript.tcl
For creating a test automation, you have to perform the following steps:
Before creating a TCL script file, execute the commands in the Debugger Shell view, as listed below:
debug
bp -auto Test_LED.c 9 1
# run program
go
The debugger stops on line 9, as the following figure shows:
step over
The debugger jumps to line 10, as the following figure shows:
set test_nofErrors 0
set test_expected 0x40000
set test_val [evaluate reg]
if {$test_expected != $test_val} {set test_nofErrors [expr {$test_nofErrors + 1}]}
bp all off
puts "Number of errors: $test_nofErrors"
kill
You can use the wait command to suspend things to follow the flow while the program runs. For example, to wait for one second:
wait 1000
Now create a script file (myScript.tcl), as listed below:
01 # start debug session using current active debug configuration 02 debug; 03 04 # wait for 1 second 05 wait 1000; 06 07 # set auto breakpoint in Test_Led.c at line 9, column 1 08 bp -auto Test_LED.c 9 1; 09 10 # resume execution, run to breakpoint 11 go; 12 13 # wait for the breakpoint to get hit for 1 second 14 wait 1000; 15 16 # remove all breakpoints 17 bp all off; 18 19 # step over line of code 20 step over; 21 22 # define error counter variable 23 set test_nofErrors 0; 24 25 ######################################################### 26 # TEST: register value shall be 0x40000 27 ######################################################### 28 # define test expected value variable to the expected value 29 set test_expected 0x40000; 30 31 # evaluate 'reg' variable and define a variable with it 32 set test_val [evaluate reg]; 33 34 #compare the expected value with the actual value 35 if {$test_expected != $test_val} {set test_nofErrors [expr {$test_nofErrors + 1}]}; 36 37 ######################################################### 38 # TEST: LED shall be off 39 ######################################################### 40 step over; 41 set test_expected 0 42 set test_val [evaluate val]; 43 if {$test_expected != $test_val} {set test_nofErrors [expr {$test_nofErrors + 1}]}; 44 45 ######################################################### 46 # TEST: LED shall be on 47 ######################################################### 48 step over; 49 step over; 50 set test_expected 1 51 set test_val [evaluate val]; 52 if {$test_expected != $test_val} {set test_nofErrors [expr {$test_nofErrors + 1}]}; 53 54 ######################################################### 55 # print number of errors 56 puts "*** Number of errors: $test_nofErrors ***"; 57 58 # terminate the debug session 59 kill;
The following figure shows the output in the Debugger Shell: