Debian Codegraph @

testsuite/systemtap.examples/check.exp

raw
1 # check.exp
2 #
3 # This script searches the systemtap.examples directory for .meta files
4 # The .meta files contain information categorizing the script. The
5 # .meta files are composed of lines of tags. Each tag is followed by a
6 # value.
7 #
8 # To restrict scripts to test, set the CHECK_ONLY environment variable.
9 # For example, to only test the badname and fntimes scripts, run:
10 #
11 # make installcheck RUNTESTFLAGS="check.exp" CHECK_ONLY="badname fntimes"
12
13 #open the file and read in all the lines of data in FILE
14 #return a string with the data
15 proc get_meta_data { FILE } {
16 set meta_data ""
17 catch {
18 set fl [open "$FILE" RDONLY]
19 set meta_data [read -nonewline $fl]
20 close $fl
21 }
22 return $meta_data
23 }
24
25 #extract value for TAG from string META_DATA
26 #if there is no matching tag return ""
27 proc extract_tag { META_DATA TAG } {
28 set taglines ""
29 set value ""
30 set expr "^$TAG: \[^\r\n\]*"
31 regexp -line -all $expr $META_DATA taglines
32 set expr "^$TAG: "
33 regsub -line $expr $taglines "" value
34 verbose -log "meta taglines '$taglines' tag '$TAG' value '$value'"
35 return $value
36 }
37
38 proc run_command { test action command } {
39 #FIXME tcl says that single quotes not dealt with
40 if { $command != "" } then {
41 # use stress instead of sleep if time >= 1
42 if {[file executable /usr/bin/stress]} {
43 regsub {sleep ([1-9])} $command {mkdir /tmp/$$; cd /tmp/$$; timeout --kill=1 30 stress -c 4 -i 4 -m 4 --vm-bytes 32M -d 4 --hdd-bytes 32M -t \1} command
44 }
45 verbose -log "attempting command $command"
46 set res [catch {exec sh -c $command 2>@1} value]
47 verbose -log "OUT $value"
48 verbose -log "RC $res"
49 if { $res != 0 } { # allow failure for support
50 if { $action != "support" } { fail "$test $action" }
51 return $res
52 } else {
53 pass "$test $action"
54 return $res
55 }
56 } else {
57 untested "$test $action"
58 return 0
59 }
60 }
61
62
63 set src_examples [fullpath $srcdir/systemtap.examples]
64
65 if {[info exists env(CHECK_ONLY)]} {
66 set name_match "-false"
67 foreach file $env(CHECK_ONLY) {
68 set name_match "$name_match -o -name $file.meta"
69 }
70 set meta_files [lsort [eval exec find $src_examples -path "*.meta" $name_match]]
71 } else {
72 set meta_files [lsort [exec find $src_examples -path "*.meta"]]
73 }
74
75 set curdir [pwd]
76 verbose -log "SAVED PWD=$curdir"
77
78 foreach file $meta_files {
79 cd $curdir
80 verbose -log "PRETEST PWD=[pwd]"
81
82 set dir [file dirname $file]
83 set test [regsub {.*/testsuite/} $file ""]
84 set test [regsub {.meta} $test ""]
85
86 set meta_data [get_meta_data $file]
87 set test_support [extract_tag "$meta_data" "test_support"]
88
89 # Do this after get_meta_data, as $file/$srcdir may be relative,
90 # and become invalid after cd $dir.
91 cd $dir
92 verbose -log "TEST PWD=[pwd]"
93
94 # If the test has an associated tcl file, run it. More complicated
95 # feature testing can be done there.
96 set test_tcl_file [file tail ${test}.tcl]
97 if {[file exists $test_tcl_file]} {
98 verbose -log "sourcing $test_tcl_file for $test"
99 source $test_tcl_file
100 }
101
102 set command $test_support
103 set supported_p 1
104 if { $command != "" } { # need to test support
105 set res [run_command "$test" "support" $command]
106 if { $res != 0 } { set supported_p 0 }
107 }
108
109 set build_p 1
110 if { $supported_p == 1 } {
111 set test_check [extract_tag "$meta_data" "test_check"]
112 set command $test_check
113 set res [run_command "$test" "build" $command]
114 if { $res != 0 } { set build_p 0 }
115 } else {
116 untested "$test build"
117 continue
118 }
119
120 set test_installcheck [extract_tag "$meta_data" "test_installcheck"]
121 # The pass/fail logic too simple and fails for some examples
122 # FIXME would like to be able to run more complicated test code
123 if {[info procs installtest_p] != "" && [installtest_p]
124 && $test_installcheck != "" } then {
125 if { $supported_p == 1 && $build_p == 1} {
126 set command $test_installcheck
127 run_command "$test" "run" $command
128 } else {
129 untested "$test run"
130 }
131 }
132
133 # Now run the same thing but with BPF
134 if {[bpf_p]} {
135 set test_check_bpf [extract_tag "$meta_data" "test_check_bpf"]
136 set test_installcheck_bpf [extract_tag "$meta_data" "test_installcheck_bpf"]
137
138 set build_bpf_p 1
139 if { $test_check_bpf != "" } {
140 if { $supported_p == 1 } {
141 set command $test_check_bpf
142 set res [run_command "$test" "build_bpf" $command]
143 if { $res != 0 } { set build_bpf_p 0 }
144 } else {
145 untested "$test build_bpf"
146 continue
147 }
148 }
149 if {[info procs installtest_p] != "" && [installtest_p]
150 && $test_installcheck_bpf != "" } then {
151 if { $supported_p == 1 && $build_bpf_p == 1 } {
152 set command $test_installcheck
153 run_command "$test" "run_bpf" $command
154 } else {
155 untested "$test run_bpf"
156 }
157 }
158 }
159
160 # Now run the same thing but with Dyninst
161 if {[dyninst_p]} {
162 set test_check_dyninst [extract_tag "$meta_data" "test_check_dyninst"]
163 set test_installcheck_dyninst [extract_tag "$meta_data" "test_installcheck_dyninst"]
164
165 set build_dyninst_p 1
166 if { $test_check_dyninst != "" } {
167 if { $supported_p == 1 } {
168 set command $test_check_dyninst
169 set res [run_command "$test" "build_dyninst" $command]
170 if { $res != 0 } { set build_dyninst_p 0 }
171 } else {
172 untested "$test build_dyninst"
173 continue
174 }
175 }
176 if {[info procs installtest_p] != "" && [installtest_p]
177 && $test_installcheck_dyninst != "" } then {
178 if { $supported_p == 1 && $build_dyninst_p == 1 } {
179 set command $test_installcheck
180 run_command "$test" "run_dyninst" $command
181 } else {
182 untested "$test run_dyninst"
183 }
184 }
185 }
186
187 # NB: Don't try to clean up; too dangerous & can error-out
188 # set output_type [extract_tag "$meta_data" "output"]
189 # if {$output_type == "file"} {
190 # regexp {\-o\s+([A-Za-z0-9_\-\.]+)} $command match outfile
191 # eval exec /bin/rm -f $dir/[glob -nocomplain $outfile*]
192 # }
193 }
194
195 # get back to starting point
196 cd $curdir
197 verbose -log "RESTORED PWD=[pwd]"