Debian Codegraph @

testsuite/lib/stap_run.exp

raw
1 # stap_run TEST_NAME LOAD_GEN_FUNCTION OUTPUT_CHECK_STRING
2 # TEST_NAME is a test name string
3 # LOAD_GEN_FUNCTION (optional) to produce something to measure
4 # returns 0 if successful
5 # returns 1 if there was a problem
6 # OUTPUT_CHECK_STRING (optional) examines the output of experiment
7 # returns 0 if successful
8 # returns 1 if there was a problem
9 # Additional arguments are passed to stap as-is, including a test file .stp name.
10 #
11 # As a side-effect, global 'probe_errors' and 'skipped_probes' are set
12 # to the number of probe errors and skipped probes seen while
13 # running the probe.
14 proc stap_run { TEST_NAME {LOAD_GEN_FUNCTION ""} {OUTPUT_CHECK_STRING ""} args } {
15 global probe_errors
16 global skipped_probes
17
18 # zap the srcdir prefix
19 set test_file_name $TEST_NAME
20 set TEST_NAME [regsub {.*/testsuite/} $TEST_NAME ""]
21 if {[file readable $test_file_name] && $args != ""} {
22 # If args contains a '--runtime=RUNTIME' option, append
23 # RUNTIME to the test name.
24 if {[regexp -- {--runtime=(\w+)} "$args" match runtime]} {
25 lappend TEST_NAME "(${runtime})"
26 }
27 }
28
29 # initialize probe_errors and skipped_probes to 0
30 set probe_errors 0
31 set skipped_probes 0
32 set warning_regexp {^WARNING: Number of errors: ([0-9]+), skipped probes: ([0-9]+)\r\n}
33 set warning_child_regexp {^WARNING: Child process exited with signal [0-9]+ \(.*\)\r\n}
34
35 if {[info procs installtest_p] != "" && ![installtest_p]} { untested $TEST_NAME; return }
36
37 set cmd [concat stap -v $args]
38
39 # don't the following: ... $test_file_name could be some transient or leftover file
40 # if [file readable $test_file_name] { lappend cmd $test_file_name }
41
42 send_log "executing: $cmd\n"
43 eval spawn $cmd
44 set mypid [exp_pid -i $spawn_id]
45 expect {
46 -timeout 180
47 -re {^WARNING: cannot find module [^\r]*DWARF[^\r]*\r\n} {exp_continue}
48 -re {^WARNING: No unwind data for /.+\r\n} {exp_continue}
49 -re {^Pass\ ([1234]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms\.\r\n}
50 {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)"; exp_continue}
51 -re {^Pass\ ([34]): using cached [^\r]+\r\n}
52 {set pass$expect_out(1,string) "\t0\t0\t0"; exp_continue}
53 -re {^Passes: via server [^\r]* using [^\r]* in [0-9]+usr/[0-9]+sys/[0-9]+real ms\.\r\n} {exp_continue}
54 -re {^Pass 5: starting run.\r\n} {exp_continue}
55 -re "^systemtap starting probe\r\n" {
56 pass "$TEST_NAME startup"
57 if {$LOAD_GEN_FUNCTION != ""} then {
58 #run the interesting test here
59 if {[eval $LOAD_GEN_FUNCTION] == 0} then {
60 pass "$TEST_NAME load generation"
61 } else {
62 fail "$TEST_NAME load generation"
63 }
64 }
65
66 kill -INT -$mypid
67
68 # check the output to see if it is sane
69 set output "^systemtap ending probe\r\n$OUTPUT_CHECK_STRING"
70
71 # By default, "expect -re" will match up to 2000 chars.
72 # Increase this to 8K worth of data.
73 exp_match_max 8192
74
75 # Avoid PR17274 to propagate
76 set origexpinternal 1
77 if {"[exp_internal -info]" == "0"} {set origexpinternal 0}
78 exp_internal 0
79
80 expect {
81 -timeout 20
82 -re $warning_regexp {
83 set probe_errors $expect_out(1,string)
84 set skipped_probes $expect_out(2,string)
85 exp_continue}
86 -re $warning_child_regexp {
87 exp_continue}
88 -re $output {
89 pass "$TEST_NAME shutdown and output"
90 expect {
91 -timeout -1
92 -re {^Pass\ ([5]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms\.\r\n}
93 {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)"
94 verbose -log "metric:\t$TEST_NAME $pass1$pass2$pass3$pass4$pass5"}
95 -re $warning_regexp {
96 set probe_errors $expect_out(1,string)
97 set skipped_probes $expect_out(2,string)}
98 -re {^WARNING: Missing unwind data for a module[^\r\n]*\r\n} {exp_continue}
99 default {
100 fail "$TEST_NAME unexpected output (after passing output)"
101 }
102 }
103 }
104 default {
105 fail "$TEST_NAME unexpected output"
106 }
107 timeout {
108 fail "$TEST_NAME shutdown (timeout)"
109 kill -INT -$mypid
110 }
111 eof { fail "$TEST_NAME shutdown (eof)" }
112 }
113 exp_internal $origexpinternal
114 }
115 -re "semantic error:" { fail "$TEST_NAME compilation" }
116 timeout {
117 fail "$TEST_NAME startup (timeout)"
118 kill -INT -$mypid
119 }
120 eof { fail "$TEST_NAME startup (eof)" }
121 }
122 # again for good measure with KILL after 3s
123 kill -INT -$mypid 3
124 catch close
125 wait
126 }
127
128 proc no_load {} {
129 # nothing in here
130 # load to use when nothing is needed
131 return 0
132 }
133
134 proc wait_n_secs {N_SECS} {
135 if {[file executable /usr/bin/stress]} {
136 # stress package is installed
137 set STRESS /usr/bin/stress
138 }
139 if {$N_SECS > 0 && [info exists STRESS]} {
140 set ncpu [exec getconf _NPROCESSORS_CONF]
141 if {$ncpu > 2} {
142 set ncpu [expr $ncpu - 2]
143 }
144 send_log "executing: timeout $N_SECS*2 -k 1 $STRESS -c $ncpu -t $N_SECS"
145 exec timeout --kill=1 [expr $N_SECS * 2] $STRESS -c $ncpu -t $N_SECS
146 } else {
147 # fallback method
148 # Tcl_Sleep does not always handle the system clock jumping,
149 # so instead of the built-in "after", use /usr/bin/sleep.
150 catch { exec sleep $N_SECS }
151 }
152 return 0;
153 }
154
155
156 # Load function to use when you need to wait 5 seconds.
157 proc wait_5_secs {} {
158 return [wait_n_secs 5];
159 }
160
161 proc print_system_info {} {
162 global Host Snapshot Distro GCC_FullVersion SElinux CPUFlags Lockdown
163
164 clone_output "\nHost: $Host"
165 if {[string compare $Snapshot "unknown"]!=0} {
166 clone_output "Snapshot: $Snapshot"
167 }
168 clone_output "GCC: $GCC_FullVersion"
169 clone_output "Distro: $Distro"
170 clone_output "SElinux: $SElinux"
171 clone_output "CPUFlags: $CPUFlags"
172 clone_output "Lockdown: $Lockdown"
173 clone_output "\n"
174 }
175
176 # tests better all be true
177 #
178 # BZ692445 was fixed by removing the '$' at the end of
179 # all_pass_string. Yet another expect regular expression oddity. The
180 # '\r\n' is good enough at finding the EOL.
181 set all_pass_string "systemtap test success\r\n"