aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-11-02 14:57:01 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-11-18 11:23:06 -0500
commit5c42fc5b975869e73bb8b6c279dd2da81eab5607 (patch)
tree7988c58c1b33fe3af3cc8d84255522224236f7c7 /tools/testing
parent2545eb6198e7e1ec50daa0cfc64a4cdfecf24ec9 (diff)
ktest: New features: noclean, dodie, poweroff on error and success
Added dodie function to have a bit more control over die calls. BUILD_NOCLEAN to not run make mrproper or remove .config. POWEROFF_ON_{SUCCESS,ERROR} to turn off the power after tests. Skip backtrace calls that were done by the backtrace tests. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/ktest/ktest.pl115
1 files changed, 94 insertions, 21 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 81fb2e431058..1acb0e1ab0f4 100644
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -18,12 +18,16 @@ $opt{"MAKE_CMD"} = "make";
18$opt{"TIMEOUT"} = 50; 18$opt{"TIMEOUT"} = 50;
19$opt{"TMP_DIR"} = "/tmp/autotest"; 19$opt{"TMP_DIR"} = "/tmp/autotest";
20$opt{"SLEEP_TIME"} = 60; # sleep time between tests 20$opt{"SLEEP_TIME"} = 60; # sleep time between tests
21$opt{"BUILD_NOCLEAN"} = 0;
22$opt{"POWEROFF_ON_ERROR"} = 0;
23$opt{"POWEROFF_ON_SUCCESS"} = 0;
21 24
22my $version; 25my $version;
23my $install_mods; 26my $install_mods;
24my $grub_number; 27my $grub_number;
25my $target; 28my $target;
26my $make; 29my $make;
30my $noclean;
27 31
28sub read_config { 32sub read_config {
29 my ($config) = @_; 33 my ($config) = @_;
@@ -56,6 +60,16 @@ sub doprint {
56 } 60 }
57} 61}
58 62
63sub dodie {
64 doprint "CRITICAL FAILURE... ", @_;
65
66 if ($opt{"POWEROFF_ON_ERROR"} && defined($opt{"POWER_OFF"})) {
67 doprint "POWERING OFF\n";
68 `$opt{"POWER_OFF"}`;
69 }
70 die @_;
71}
72
59sub run_command { 73sub run_command {
60 my ($command) = @_; 74 my ($command) = @_;
61 my $redirect = ""; 75 my $redirect = "";
@@ -121,21 +135,22 @@ sub monitor {
121 my $bug = 0; 135 my $bug = 0;
122 my $pid; 136 my $pid;
123 my $doopen2 = 0; 137 my $doopen2 = 0;
138 my $skip_call_trace = 0;
124 139
125 if ($doopen2) { 140 if ($doopen2) {
126 $pid = open2(\*IN, \*OUT, $opt{CONSOLE}); 141 $pid = open2(\*IN, \*OUT, $opt{CONSOLE});
127 if ($pid < 0) { 142 if ($pid < 0) {
128 die "Failed to connect to the console"; 143 dodie "Failed to connect to the console";
129 } 144 }
130 } else { 145 } else {
131 $pid = open(IN, "$opt{CONSOLE} |"); 146 $pid = open(IN, "$opt{CONSOLE} |");
132 } 147 }
133 148
134 $flags = fcntl(IN, F_GETFL, 0) or 149 $flags = fcntl(IN, F_GETFL, 0) or
135 die "Can't get flags for the socket: $!\n"; 150 dodie "Can't get flags for the socket: $!\n";
136 151
137 $flags = fcntl(IN, F_SETFL, $flags | O_NONBLOCK) or 152 $flags = fcntl(IN, F_SETFL, $flags | O_NONBLOCK) or
138 die "Can't set flags for the socket: $!\n"; 153 dodie "Can't set flags for the socket: $!\n";
139 154
140 my $line; 155 my $line;
141 my $full_line = ""; 156 my $full_line = "";
@@ -163,7 +178,19 @@ sub monitor {
163 $booted = 1; 178 $booted = 1;
164 } 179 }
165 180
181 if ($full_line =~ /\[ backtrace testing \]/) {
182 $skip_call_trace = 1;
183 }
184
166 if ($full_line =~ /call trace:/i) { 185 if ($full_line =~ /call trace:/i) {
186 $bug = 1 if (!$skip_call_trace);
187 }
188
189 if ($full_line =~ /\[ end of backtrace testing \]/) {
190 $skip_call_trace = 0;
191 }
192
193 if ($full_line =~ /Kernel panic -/) {
167 $bug = 1; 194 $bug = 1;
168 } 195 }
169 196
@@ -179,57 +206,90 @@ sub monitor {
179 close(IN); 206 close(IN);
180 207
181 if (!$booted) { 208 if (!$booted) {
182 die "failed - never got a boot prompt.\n"; 209 dodie "failed - never got a boot prompt.\n";
183 } 210 }
184 211
185 if ($bug) { 212 if ($bug) {
186 die "failed - got a bug report\n"; 213 dodie "failed - got a bug report\n";
187 } 214 }
188} 215}
189 216
190sub install { 217sub install {
191 218
192 if (run_command "scp $opt{OUTPUT_DIR}/$opt{BUILD_TARGET} $target:$opt{TARGET_IMAGE}") { 219 if (run_command "scp $opt{OUTPUT_DIR}/$opt{BUILD_TARGET} $target:$opt{TARGET_IMAGE}") {
193 die "failed to copy image"; 220 dodie "failed to copy image";
194 } 221 }
195 222
196 if ($install_mods) { 223 if ($install_mods) {
197 my $modlib = "/lib/modules/$version"; 224 my $modlib = "/lib/modules/$version";
225 my $modtar = "autotest-mods.tar.bz2";
198 226
199 if (run_command "ssh $target rm -rf $modlib") { 227 if (run_command "ssh $target rm -rf $modlib") {
200 die "failed to remove old mods: $modlib"; 228 dodie "failed to remove old mods: $modlib";
229 }
230
231 # would be nice if scp -r did not follow symbolic links
232 if (run_command "cd $opt{TMP_DIR}; tar -cjf $modtar lib/modules/$version") {
233 dodie "making tarball";
201 } 234 }
202 235
203 if (run_command "scp -r $opt{TMP_DIR}/lib $target:/lib/modules/$version") { 236 if (run_command "scp $opt{TMP_DIR}/$modtar $target:/tmp") {
204 die "failed to copy modules"; 237 dodie "failed to copy modules";
238 }
239
240 unlink "$opt{TMP_DIR}/$modtar";
241
242 if (run_command "ssh $target '(cd / && tar xf /tmp/$modtar)'") {
243 dodie "failed to tar modules";
205 } 244 }
245
246 run_command "ssh $target rm -f /tmp/$modtar";
206 } 247 }
207 248
208} 249}
209 250
210sub build { 251sub build {
211 my ($type) = @_; 252 my ($type) = @_;
253 my $defconfig = "";
254 my $append = "";
255
256 # old config can ask questions
257 if ($type eq "oldconfig") {
258 $append = "yes ''|";
259 if (run_command "mv $opt{OUTPUT_DIR}/.config $opt{OUTPUT_DIR}/config_temp") {
260 dodie "moving .config";
261 }
212 262
213 unlink "$opt{OUTPUT_DIR}/.config"; 263 if (!$noclean && run_command "$make mrproper") {
264 dodie "make mrproper";
265 }
214 266
215 run_command "$make mrproper"; 267 if (run_command "mv $opt{OUTPUT_DIR}/config_temp $opt{OUTPUT_DIR}/.config") {
268 dodie "moving config_temp";
269 }
270
271 } elsif (!$noclean) {
272 unlink "$opt{OUTPUT_DIR}/.config";
273 if (run_command "$make mrproper") {
274 dodie "make mrproper";
275 }
276 }
216 277
217 # add something to distinguish this build 278 # add something to distinguish this build
218 open(OUT, "> $opt{OUTPUT_DIR}/localversion") or die("Can't make localversion file"); 279 open(OUT, "> $opt{OUTPUT_DIR}/localversion") or dodie("Can't make localversion file");
219 print OUT "$opt{LOCALVERSION}\n"; 280 print OUT "$opt{LOCALVERSION}\n";
220 close(OUT); 281 close(OUT);
221 282
222 if (run_command "$make $opt{$type}") { 283 if (defined($opt{"MIN_CONFIG"})) {
223 die "failed make config"; 284 $defconfig = "KCONFIG_ALLCONFIG=$opt{MIN_CONFIG}";
224 } 285 }
225 286
226 if (defined($opt{"MIN_CONFIG"})) { 287 if (run_command "$defconfig $append $make $type") {
227 run_command "cat $opt{MIN_CONFIG} >> $opt{OUTPUT_DIR}/.config"; 288 dodie "failed make config";
228 run_command "yes '' | $make oldconfig";
229 } 289 }
230 290
231 if (run_command "$make $opt{BUILD_OPTIONS}") { 291 if (run_command "$make $opt{BUILD_OPTIONS}") {
232 die "failed build"; 292 dodie "failed build";
233 } 293 }
234} 294}
235 295
@@ -275,6 +335,13 @@ $make = "$opt{MAKE_CMD} O=$opt{OUTPUT_DIR}";
275for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) { 335for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
276 my $type = "BUILD_TYPE[$i]"; 336 my $type = "BUILD_TYPE[$i]";
277 337
338 if (defined($opt{"BUILD_NOCLEAN[$i]"}) &&
339 $opt{"BUILD_NOCLEAN[$i]"} != 0) {
340 $noclean = 1;
341 } else {
342 $noclean = $opt{"BUILD_NOCLEAN"};
343 }
344
278 if (!defined($opt{$type})) { 345 if (!defined($opt{$type})) {
279 $opt{$type} = $opt{"DEFAULT_BUILD_TYPE"}; 346 $opt{$type} = $opt{"DEFAULT_BUILD_TYPE"};
280 } 347 }
@@ -283,7 +350,7 @@ for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
283 doprint "RUNNING TEST $i of $opt{NUM_BUILDS} with option $opt{$type}\n\n"; 350 doprint "RUNNING TEST $i of $opt{NUM_BUILDS} with option $opt{$type}\n\n";
284 351
285 if ($opt{$type} ne "nobuild") { 352 if ($opt{$type} ne "nobuild") {
286 build $type; 353 build $opt{$type};
287 } 354 }
288 355
289 # get the release name 356 # get the release name
@@ -294,7 +361,7 @@ for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
294 361
295 # should we process modules? 362 # should we process modules?
296 $install_mods = 0; 363 $install_mods = 0;
297 open(IN, "$opt{OUTPUT_DIR}/.config") or die("Can't read config file"); 364 open(IN, "$opt{OUTPUT_DIR}/.config") or dodie("Can't read config file");
298 while (<IN>) { 365 while (<IN>) {
299 if (/CONFIG_MODULES(=y)?/) { 366 if (/CONFIG_MODULES(=y)?/) {
300 $install_mods = 1 if (defined($1)); 367 $install_mods = 1 if (defined($1));
@@ -305,7 +372,7 @@ for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
305 372
306 if ($install_mods) { 373 if ($install_mods) {
307 if (run_command "$make INSTALL_MOD_PATH=$opt{TMP_DIR} modules_install") { 374 if (run_command "$make INSTALL_MOD_PATH=$opt{TMP_DIR} modules_install") {
308 die "Failed to install modules"; 375 dodie "Failed to install modules";
309 } 376 }
310 } else { 377 } else {
311 doprint "No modules needed\n"; 378 doprint "No modules needed\n";
@@ -331,4 +398,10 @@ for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
331 sleep "$opt{SLEEP_TIME}"; 398 sleep "$opt{SLEEP_TIME}";
332} 399}
333 400
401if ($opt{"POWEROFF_ON_SUCCESS"}) {
402 if (run_command "ssh $target halt" && defined($opt{"POWER_OFF"})) {
403 # nope? the zap it!
404 run_command "$opt{POWER_OFF}";
405 }
406}
334exit 0; 407exit 0;