Debian Codegraph @

testsuite/lib/stap_run2.exp

raw
1 # stap_run2.exp
2 #
3 # Simple script for testing multiple lines of exact output.
4
5 # stap_run2 TEST_NAME
6 # TEST_NAME is path to the current test
7 # Additional arguments are passed to stap as-is.
8 #
9 # global result_string must be set to the expected output
10
11 proc stap_run2 { TEST_NAME args } {
12 # zap the srcdir prefix
13 set TEST_FILE $TEST_NAME
14 set TEST_NAME [regsub {.*/testsuite/} $TEST_NAME ""]
15 if {[llength $args] == 0} {
16 stap_run3 $TEST_NAME $TEST_FILE
17 } else {
18 eval stap_run3 "{$TEST_NAME $args} $TEST_FILE $args"
19 }
20 }
21
22 # stap_run3 TEST_NAME args
23 # TEST_NAME is the name of the test as shown in PASS/FAIL/SKIPPED messages.
24 # Additional arguments are passed to stap as-is, including likely a TEST_FILE name.
25 #
26 # global result_string must be set to the expected output
27
28 proc stap_run3 { TEST_NAME args } {
29 if {[info procs installtest_p] != "" && ![installtest_p]} { untested $TEST_NAME; return }
30
31 set cmd [concat stap $args]
32 send_log "executing: $cmd\n"
33 catch {eval exec $cmd} res
34
35 set n 0
36 set expected [split $::result_string "\n"]
37 foreach line [split $res "\n"] {
38 if {![string equal $line [lindex $expected $n]]} {
39 fail "$TEST_NAME"
40 send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\"\n"
41 send_log "Got \"$line\"\n"
42 set m 0
43 foreach line2 [split $res "\n"] {
44 if {$m > $n} {
45 send_log " \"$line2\"\n"
46 }
47 incr m
48 }
49 return
50 }
51 incr n
52 }
53 if {[expr $n == [llength $expected]]} {
54 pass "$TEST_NAME"
55 } else {
56 fail "$TEST_NAME"
57 send_log "too few lines of output, got $n, expected [llength $expected]\n"
58 }
59 }