hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/testing/ktest/ktest.pl
....@@ -1,7 +1,7 @@
11 #!/usr/bin/perl -w
2
+# SPDX-License-Identifier: GPL-2.0-only
23 #
34 # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4
-# Licensed under the terms of the GNU GPL License version 2
55 #
66
77 use strict;
....@@ -11,6 +11,7 @@
1111 use File::Copy qw(cp);
1212 use FileHandle;
1313 use FindBin;
14
+use IO::Handle;
1415
1516 my $VERSION = "0.2";
1617
....@@ -30,7 +31,7 @@
3031 "EMAIL_WHEN_STARTED" => 0,
3132 "NUM_TESTS" => 1,
3233 "TEST_TYPE" => "build",
33
- "BUILD_TYPE" => "randconfig",
34
+ "BUILD_TYPE" => "oldconfig",
3435 "MAKE_CMD" => "make",
3536 "CLOSE_CONSOLE_SIGNAL" => "INT",
3637 "TIMEOUT" => 120,
....@@ -58,11 +59,13 @@
5859 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
5960 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
6061 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
62
+ "REBOOT_RETURN_CODE" => 255,
6163 "STOP_AFTER_SUCCESS" => 10,
6264 "STOP_AFTER_FAILURE" => 60,
6365 "STOP_TEST_AFTER" => 600,
6466 "MAX_MONITOR_WAIT" => 1800,
6567 "GRUB_REBOOT" => "grub2-reboot",
68
+ "GRUB_BLS_GET" => "grubby --info=ALL",
6669 "SYSLINUX" => "extlinux",
6770 "SYSLINUX_PATH" => "/boot/extlinux",
6871 "CONNECT_TIMEOUT" => 25,
....@@ -78,6 +81,8 @@
7881 "LOG_FILE" => undef,
7982 "IGNORE_UNUSED" => 0,
8083 );
84
+
85
+my $test_log_start = 0;
8186
8287 my $ktest_config = "ktest.conf";
8388 my $version;
....@@ -96,6 +101,7 @@
96101 my $pre_ktest;
97102 my $post_ktest;
98103 my $pre_test;
104
+my $pre_test_die;
99105 my $post_test;
100106 my $pre_build;
101107 my $post_build;
....@@ -105,6 +111,7 @@
105111 my $reboot_script;
106112 my $power_cycle;
107113 my $reboot;
114
+my $reboot_return_code;
108115 my $reboot_on_error;
109116 my $switch_to_good;
110117 my $switch_to_test;
....@@ -123,6 +130,7 @@
123130 my $grub_file;
124131 my $grub_number;
125132 my $grub_reboot;
133
+my $grub_bls_get;
126134 my $syslinux;
127135 my $syslinux_path;
128136 my $syslinux_label;
....@@ -170,6 +178,7 @@
170178 my $store_successes;
171179 my $test_name;
172180 my $timeout;
181
+my $run_timeout;
173182 my $connect_timeout;
174183 my $config_bisect_exec;
175184 my $booted_timeout;
....@@ -219,6 +228,7 @@
219228 my $mailto;
220229 my $mailer;
221230 my $mail_path;
231
+my $mail_max_size;
222232 my $mail_command;
223233 my $email_on_error;
224234 my $email_when_finished;
....@@ -255,6 +265,7 @@
255265 "MAILTO" => \$mailto,
256266 "MAILER" => \$mailer,
257267 "MAIL_PATH" => \$mail_path,
268
+ "MAIL_MAX_SIZE" => \$mail_max_size,
258269 "MAIL_COMMAND" => \$mail_command,
259270 "EMAIL_ON_ERROR" => \$email_on_error,
260271 "EMAIL_WHEN_FINISHED" => \$email_when_finished,
....@@ -269,6 +280,7 @@
269280 "PRE_KTEST" => \$pre_ktest,
270281 "POST_KTEST" => \$post_ktest,
271282 "PRE_TEST" => \$pre_test,
283
+ "PRE_TEST_DIE" => \$pre_test_die,
272284 "POST_TEST" => \$post_test,
273285 "BUILD_TYPE" => \$build_type,
274286 "BUILD_OPTIONS" => \$build_options,
....@@ -278,6 +290,7 @@
278290 "POST_BUILD_DIE" => \$post_build_die,
279291 "POWER_CYCLE" => \$power_cycle,
280292 "REBOOT" => \$reboot,
293
+ "REBOOT_RETURN_CODE" => \$reboot_return_code,
281294 "BUILD_NOCLEAN" => \$noclean,
282295 "MIN_CONFIG" => \$minconfig,
283296 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
....@@ -292,6 +305,7 @@
292305 "GRUB_MENU" => \$grub_menu,
293306 "GRUB_FILE" => \$grub_file,
294307 "GRUB_REBOOT" => \$grub_reboot,
308
+ "GRUB_BLS_GET" => \$grub_bls_get,
295309 "SYSLINUX" => \$syslinux,
296310 "SYSLINUX_PATH" => \$syslinux_path,
297311 "SYSLINUX_LABEL" => \$syslinux_label,
....@@ -327,6 +341,7 @@
327341 "STORE_SUCCESSES" => \$store_successes,
328342 "TEST_NAME" => \$test_name,
329343 "TIMEOUT" => \$timeout,
344
+ "RUN_TIMEOUT" => \$run_timeout,
330345 "CONNECT_TIMEOUT" => \$connect_timeout,
331346 "CONFIG_BISECT_EXEC" => \$config_bisect_exec,
332347 "BOOTED_TIMEOUT" => \$booted_timeout,
....@@ -437,7 +452,7 @@
437452 ;
438453 $config_help{"REBOOT_TYPE"} = << "EOF"
439454 Way to reboot the box to the test kernel.
440
- Only valid options so far are "grub", "grub2", "syslinux", and "script".
455
+ Only valid options so far are "grub", "grub2", "grub2bls", "syslinux", and "script".
441456
442457 If you specify grub, it will assume grub version 1
443458 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
....@@ -450,6 +465,8 @@
450465
451466 If you specify grub2, then you also need to specify both \$GRUB_MENU
452467 and \$GRUB_FILE.
468
+
469
+ If you specify grub2bls, then you also need to specify \$GRUB_MENU.
453470
454471 If you specify syslinux, then you may use SYSLINUX to define the syslinux
455472 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
....@@ -476,6 +493,9 @@
476493 menu must be a non-nested menu. Add the quotes used in the menu
477494 to guarantee your selection, as the first menuentry with the content
478495 of \$GRUB_MENU that is found will be used.
496
+
497
+ For grub2bls, \$GRUB_MENU is searched on the result of \$GRUB_BLS_GET
498
+ command for the lines that begin with "title".
479499 EOF
480500 ;
481501 $config_help{"GRUB_FILE"} = << "EOF"
....@@ -496,9 +516,7 @@
496516
497517 sub _logit {
498518 if (defined($opt{"LOG_FILE"})) {
499
- open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
500
- print OUT @_;
501
- close(OUT);
519
+ print LOG @_;
502520 }
503521 }
504522
....@@ -692,7 +710,7 @@
692710 }
693711 }
694712
695
- if ($rtype eq "grub") {
713
+ if (($rtype eq "grub") or ($rtype eq "grub2bls")) {
696714 get_mandatory_config("GRUB_MENU");
697715 }
698716
....@@ -898,6 +916,12 @@
898916 }
899917 }
900918
919
+ if ($val =~ s/^\s*NOT\s+(.*)//) {
920
+ my $express = $1;
921
+ my $ret = process_expression($name, $express);
922
+ return !$ret;
923
+ }
924
+
901925 if ($val =~ /^\s*0\s*$/) {
902926 return 0;
903927 } elsif ($val =~ /^\s*\d+\s*$/) {
....@@ -1019,7 +1043,7 @@
10191043 }
10201044
10211045 if (!$skip && $rest !~ /^\s*$/) {
1022
- die "$name: $.: Gargbage found after $type\n$_";
1046
+ die "$name: $.: Garbage found after $type\n$_";
10231047 }
10241048
10251049 if ($skip && $type eq "TEST_START") {
....@@ -1052,7 +1076,7 @@
10521076 }
10531077
10541078 if ($rest !~ /^\s*$/) {
1055
- die "$name: $.: Gargbage found after DEFAULTS\n$_";
1079
+ die "$name: $.: Garbage found after DEFAULTS\n$_";
10561080 }
10571081
10581082 } elsif (/^\s*INCLUDE\s+(\S+)/) {
....@@ -1143,7 +1167,7 @@
11431167 # on of these sections that have SKIP defined.
11441168 # The save variable can be
11451169 # defined multiple times and the new one simply overrides
1146
- # the prevous one.
1170
+ # the previous one.
11471171 set_variable($lvalue, $rvalue);
11481172
11491173 } else {
....@@ -1223,7 +1247,7 @@
12231247 foreach my $option (keys %not_used) {
12241248 print "$option\n";
12251249 }
1226
- print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1250
+ print "Set IGNORE_UNUSED = 1 to have ktest ignore unused variables\n";
12271251 if (!read_yn "Do you want to continue?") {
12281252 exit -1;
12291253 }
....@@ -1334,7 +1358,7 @@
13341358 # Check for recursive evaluations.
13351359 # 100 deep should be more than enough.
13361360 if ($r++ > 100) {
1337
- die "Over 100 evaluations accurred with $option\n" .
1361
+ die "Over 100 evaluations occurred with $option\n" .
13381362 "Check for recursive variables\n";
13391363 }
13401364 $prev = $option;
....@@ -1411,7 +1435,8 @@
14111435
14121436 # Still need to wait for the reboot to finish
14131437 wait_for_monitor($time, $reboot_success_line);
1414
-
1438
+ }
1439
+ if ($powercycle || $time) {
14151440 end_monitor;
14161441 }
14171442 }
....@@ -1437,15 +1462,26 @@
14371462
14381463 my $in_die = 0;
14391464
1465
+sub get_test_name() {
1466
+ my $name;
1467
+
1468
+ if (defined($test_name)) {
1469
+ $name = "$test_name:$test_type";
1470
+ } else {
1471
+ $name = $test_type;
1472
+ }
1473
+ return $name;
1474
+}
1475
+
14401476 sub dodie {
14411477
1442
- # avoid recusion
1478
+ # avoid recursion
14431479 return if ($in_die);
14441480 $in_die = 1;
14451481
1446
- doprint "CRITICAL FAILURE... ", @_, "\n";
1447
-
14481482 my $i = $iteration;
1483
+
1484
+ doprint "CRITICAL FAILURE... [TEST $i] ", @_, "\n";
14491485
14501486 if ($reboot_on_error && !do_not_reboot) {
14511487
....@@ -1462,8 +1498,32 @@
14621498 }
14631499
14641500 if ($email_on_error) {
1465
- send_email("KTEST: critical failure for your [$test_type] test",
1466
- "Your test started at $script_start_time has failed with:\n@_\n");
1501
+ my $name = get_test_name;
1502
+ my $log_file;
1503
+
1504
+ if (defined($opt{"LOG_FILE"})) {
1505
+ my $whence = 2; # End of file
1506
+ my $log_size = tell LOG;
1507
+ my $size = $log_size - $test_log_start;
1508
+
1509
+ if (defined($mail_max_size)) {
1510
+ if ($size > $mail_max_size) {
1511
+ $size = $mail_max_size;
1512
+ }
1513
+ }
1514
+ my $pos = - $size;
1515
+ $log_file = "$tmpdir/log";
1516
+ open (L, "$opt{LOG_FILE}") or die "Can't open $opt{LOG_FILE} to read)";
1517
+ open (O, "> $tmpdir/log") or die "Can't open $tmpdir/log\n";
1518
+ seek(L, $pos, $whence);
1519
+ while (<L>) {
1520
+ print O;
1521
+ }
1522
+ close O;
1523
+ close L;
1524
+ }
1525
+ send_email("KTEST: critical failure for test $i [$name]",
1526
+ "Your test started at $script_start_time has failed with:\n@_\n", $log_file);
14671527 }
14681528
14691529 if ($monitor_cnt) {
....@@ -1485,7 +1545,7 @@
14851545 my $TIOCGPTN = 0x80045430;
14861546
14871547 sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
1488
- dodie "Cant open /dev/ptmx";
1548
+ dodie "Can't open /dev/ptmx";
14891549
14901550 # unlockpt()
14911551 $tmp = pack("i", 0);
....@@ -1737,9 +1797,18 @@
17371797 my $dord = 0;
17381798 my $dostdout = 0;
17391799 my $pid;
1800
+ my $command_orig = $command;
17401801
17411802 $command =~ s/\$SSH_USER/$ssh_user/g;
17421803 $command =~ s/\$MACHINE/$machine/g;
1804
+
1805
+ if (!defined($timeout)) {
1806
+ $timeout = $run_timeout;
1807
+ }
1808
+
1809
+ if (!defined($timeout)) {
1810
+ $timeout = -1; # tell wait_for_input to wait indefinitely
1811
+ }
17431812
17441813 doprint("$command ... ");
17451814 $start_time = time;
....@@ -1748,8 +1817,6 @@
17481817 (fail "unable to exec $command" and return 0);
17491818
17501819 if (defined($opt{"LOG_FILE"})) {
1751
- open(LOG, ">>$opt{LOG_FILE}") or
1752
- dodie "failed to write to log";
17531820 $dolog = 1;
17541821 }
17551822
....@@ -1769,13 +1836,10 @@
17691836
17701837 while (1) {
17711838 my $fp = \*CMD;
1772
- if (defined($timeout)) {
1773
- doprint "timeout = $timeout\n";
1774
- }
17751839 my $line = wait_for_input($fp, $timeout);
17761840 if (!defined($line)) {
17771841 my $now = time;
1778
- if (defined($timeout) && (($now - $start_time) >= $timeout)) {
1842
+ if ($timeout >= 0 && (($now - $start_time) >= $timeout)) {
17791843 doprint "Hit timeout of $timeout, killing process\n";
17801844 $hit_timeout = 1;
17811845 kill 9, $pid;
....@@ -1791,8 +1855,12 @@
17911855 # shift 8 for real exit status
17921856 $run_command_status = $? >> 8;
17931857
1858
+ if ($command_orig eq $default{REBOOT} &&
1859
+ $run_command_status == $reboot_return_code) {
1860
+ $run_command_status = 0;
1861
+ }
1862
+
17941863 close(CMD);
1795
- close(LOG) if ($dolog);
17961864 close(RD) if ($dord);
17971865
17981866 $end_time = time;
....@@ -1850,36 +1918,46 @@
18501918 return run_scp($src, $dst, $cp_scp);
18511919 }
18521920
1853
-sub get_grub2_index {
1921
+sub _get_grub_index {
1922
+
1923
+ my ($command, $target, $skip, $submenu) = @_;
18541924
18551925 return if (defined($grub_number) && defined($last_grub_menu) &&
18561926 $last_grub_menu eq $grub_menu && defined($last_machine) &&
18571927 $last_machine eq $machine);
18581928
1859
- doprint "Find grub2 menu ... ";
1929
+ doprint "Find $reboot_type menu ... ";
18601930 $grub_number = -1;
18611931
18621932 my $ssh_grub = $ssh_exec;
1863
- $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1933
+ $ssh_grub =~ s,\$SSH_COMMAND,$command,g;
18641934
18651935 open(IN, "$ssh_grub |")
1866
- or dodie "unable to get $grub_file";
1936
+ or dodie "unable to execute $command";
18671937
18681938 my $found = 0;
18691939
1940
+ my $submenu_number = 0;
1941
+
18701942 while (<IN>) {
1871
- if (/^menuentry.*$grub_menu/) {
1943
+ if (/$target/) {
18721944 $grub_number++;
18731945 $found = 1;
18741946 last;
1875
- } elsif (/^menuentry\s|^submenu\s/) {
1947
+ } elsif (defined($submenu) && /$submenu/) {
1948
+ $submenu_number++;
1949
+ $grub_number = -1;
1950
+ } elsif (/$skip/) {
18761951 $grub_number++;
18771952 }
18781953 }
18791954 close(IN);
18801955
1881
- dodie "Could not find '$grub_menu' in $grub_file on $machine"
1956
+ dodie "Could not find '$grub_menu' through $command on $machine"
18821957 if (!$found);
1958
+ if ($submenu_number > 0) {
1959
+ $grub_number = "$submenu_number>$grub_number";
1960
+ }
18831961 doprint "$grub_number\n";
18841962 $last_grub_menu = $grub_menu;
18851963 $last_machine = $machine;
....@@ -1887,45 +1965,36 @@
18871965
18881966 sub get_grub_index {
18891967
1890
- if ($reboot_type eq "grub2") {
1891
- get_grub2_index;
1968
+ my $command;
1969
+ my $target;
1970
+ my $skip;
1971
+ my $submenu;
1972
+ my $grub_menu_qt;
1973
+
1974
+ if ($reboot_type !~ /^grub/) {
18921975 return;
18931976 }
18941977
1895
- if ($reboot_type ne "grub") {
1978
+ $grub_menu_qt = quotemeta($grub_menu);
1979
+
1980
+ if ($reboot_type eq "grub") {
1981
+ $command = "cat /boot/grub/menu.lst";
1982
+ $target = '^\s*title\s+' . $grub_menu_qt . '\s*$';
1983
+ $skip = '^\s*title\s';
1984
+ } elsif ($reboot_type eq "grub2") {
1985
+ $command = "cat $grub_file";
1986
+ $target = '^\s*menuentry.*' . $grub_menu_qt;
1987
+ $skip = '^\s*menuentry';
1988
+ $submenu = '^\s*submenu\s';
1989
+ } elsif ($reboot_type eq "grub2bls") {
1990
+ $command = $grub_bls_get;
1991
+ $target = '^title=.*' . $grub_menu_qt;
1992
+ $skip = '^title=';
1993
+ } else {
18961994 return;
18971995 }
1898
- return if (defined($grub_number) && defined($last_grub_menu) &&
1899
- $last_grub_menu eq $grub_menu && defined($last_machine) &&
1900
- $last_machine eq $machine);
19011996
1902
- doprint "Find grub menu ... ";
1903
- $grub_number = -1;
1904
-
1905
- my $ssh_grub = $ssh_exec;
1906
- $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1907
-
1908
- open(IN, "$ssh_grub |")
1909
- or dodie "unable to get menu.lst";
1910
-
1911
- my $found = 0;
1912
-
1913
- while (<IN>) {
1914
- if (/^\s*title\s+$grub_menu\s*$/) {
1915
- $grub_number++;
1916
- $found = 1;
1917
- last;
1918
- } elsif (/^\s*title\s/) {
1919
- $grub_number++;
1920
- }
1921
- }
1922
- close(IN);
1923
-
1924
- dodie "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1925
- if (!$found);
1926
- doprint "$grub_number\n";
1927
- $last_grub_menu = $grub_menu;
1928
- $last_machine = $machine;
1997
+ _get_grub_index($command, $target, $skip, $submenu);
19291998 }
19301999
19312000 sub wait_for_input
....@@ -1941,6 +2010,11 @@
19412010
19422011 if (!defined($time)) {
19432012 $time = $timeout;
2013
+ }
2014
+
2015
+ if ($time < 0) {
2016
+ # Negative number means wait indefinitely
2017
+ undef $time;
19442018 }
19452019
19462020 $rin = '';
....@@ -1988,8 +2062,8 @@
19882062
19892063 if ($reboot_type eq "grub") {
19902064 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1991
- } elsif ($reboot_type eq "grub2") {
1992
- run_ssh "$grub_reboot $grub_number";
2065
+ } elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) {
2066
+ run_ssh "$grub_reboot \"'$grub_number'\"";
19932067 } elsif ($reboot_type eq "syslinux") {
19942068 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
19952069 } elsif (defined $reboot_script) {
....@@ -3168,6 +3242,8 @@
31683242 doprint "***************************************\n\n";
31693243 }
31703244
3245
+my $pass = 1;
3246
+
31713247 sub run_config_bisect {
31723248 my ($good, $bad, $last_result) = @_;
31733249 my $reset = "";
....@@ -3190,11 +3266,15 @@
31903266
31913267 $ret = run_config_bisect_test $config_bisect_type;
31923268 if ($ret) {
3193
- doprint "NEW GOOD CONFIG\n";
3269
+ doprint "NEW GOOD CONFIG ($pass)\n";
3270
+ system("cp $output_config $tmpdir/good_config.tmp.$pass");
3271
+ $pass++;
31943272 # Return 3 for good config
31953273 return 3;
31963274 } else {
3197
- doprint "NEW BAD CONFIG\n";
3275
+ doprint "NEW BAD CONFIG ($pass)\n";
3276
+ system("cp $output_config $tmpdir/bad_config.tmp.$pass");
3277
+ $pass++;
31983278 # Return 4 for bad config
31993279 return 4;
32003280 }
....@@ -3706,9 +3786,10 @@
37063786 # .config to make sure it is missing the config that
37073787 # we had before
37083788 my %configs = %min_configs;
3709
- delete $configs{$config};
3789
+ $configs{$config} = "# $config is not set";
37103790 make_new_config ((values %configs), (values %keep_configs));
37113791 make_oldconfig;
3792
+ delete $configs{$config};
37123793 undef %configs;
37133794 assign_configs \%configs, $output_config;
37143795
....@@ -4057,8 +4138,12 @@
40574138 }
40584139 }
40594140
4060
-if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
4061
- unlink $opt{"LOG_FILE"};
4141
+if (defined($opt{"LOG_FILE"})) {
4142
+ if ($opt{"CLEAR_LOG"}) {
4143
+ unlink $opt{"LOG_FILE"};
4144
+ }
4145
+ open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
4146
+ LOG->autoflush(1);
40624147 }
40634148
40644149 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
....@@ -4151,7 +4236,7 @@
41514236 }
41524237
41534238 sub do_send_mail {
4154
- my ($subject, $message) = @_;
4239
+ my ($subject, $message, $file) = @_;
41554240
41564241 if (!defined($mail_path)) {
41574242 # find the mailer
....@@ -4161,16 +4246,30 @@
41614246 }
41624247 }
41634248
4249
+ my $header_file = "$tmpdir/header";
4250
+ open (HEAD, ">$header_file") or die "Can not create $header_file\n";
4251
+ print HEAD "To: $mailto\n";
4252
+ print HEAD "Subject: $subject\n\n";
4253
+ print HEAD "$message\n";
4254
+ close HEAD;
4255
+
41644256 if (!defined($mail_command)) {
41654257 if ($mailer eq "mail" || $mailer eq "mailx") {
4166
- $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< \'\$MESSAGE\'";
4258
+ $mail_command = "cat \$HEADER_FILE \$BODY_FILE | \$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO";
41674259 } elsif ($mailer eq "sendmail" ) {
4168
- $mail_command = "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | \$MAIL_PATH/\$MAILER -t \$MAILTO";
4260
+ $mail_command = "cat \$HEADER_FILE \$BODY_FILE | \$MAIL_PATH/\$MAILER -t \$MAILTO";
41694261 } else {
41704262 die "\nYour mailer: $mailer is not supported.\n";
41714263 }
41724264 }
41734265
4266
+ if (defined($file)) {
4267
+ $mail_command =~ s/\$BODY_FILE/$file/g;
4268
+ } else {
4269
+ $mail_command =~ s/\$BODY_FILE//g;
4270
+ }
4271
+
4272
+ $mail_command =~ s/\$HEADER_FILE/$header_file/g;
41744273 $mail_command =~ s/\$MAILER/$mailer/g;
41754274 $mail_command =~ s/\$MAIL_PATH/$mail_path/g;
41764275 $mail_command =~ s/\$MAILTO/$mailto/g;
....@@ -4197,8 +4296,12 @@
41974296 }
41984297
41994298 sub cancel_test {
4299
+ if ($monitor_cnt) {
4300
+ end_monitor;
4301
+ }
42004302 if ($email_when_canceled) {
4201
- send_email("KTEST: Your [$test_type] test was cancelled",
4303
+ my $name = get_test_name;
4304
+ send_email("KTEST: Your [$name] test was cancelled",
42024305 "Your test started at $script_start_time was cancelled: sig int");
42034306 }
42044307 die "\nCaught Sig Int, test interrupted: $!\n"
....@@ -4252,7 +4355,8 @@
42524355 run_command $pre_ktest;
42534356 }
42544357 if ($email_when_started) {
4255
- send_email("KTEST: Your [$test_type] test was started",
4358
+ my $name = get_test_name;
4359
+ send_email("KTEST: Your [$name] test was started",
42564360 "Your test was started on $script_start_time");
42574361 }
42584362 }
....@@ -4283,7 +4387,7 @@
42834387
42844388 if (!$buildonly) {
42854389 $target = "$ssh_user\@$machine";
4286
- if ($reboot_type eq "grub") {
4390
+ if (($reboot_type eq "grub") or ($reboot_type eq "grub2bls")) {
42874391 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
42884392 } elsif ($reboot_type eq "grub2") {
42894393 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
....@@ -4321,10 +4425,19 @@
43214425 }
43224426
43234427 doprint "\n\n";
4428
+
4429
+ if (defined($opt{"LOG_FILE"})) {
4430
+ $test_log_start = tell(LOG);
4431
+ }
4432
+
43244433 doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
43254434
43264435 if (defined($pre_test)) {
4327
- run_command $pre_test;
4436
+ my $ret = run_command $pre_test;
4437
+ if (!$ret && defined($pre_test_die) &&
4438
+ $pre_test_die) {
4439
+ dodie "failed to pre_test\n";
4440
+ }
43284441 }
43294442
43304443 unlink $dmesg;
....@@ -4403,7 +4516,9 @@
44034516 }
44044517
44054518 if (defined($final_post_ktest)) {
4406
- run_command $final_post_ktest;
4519
+
4520
+ my $cp_final_post_ktest = eval_kernel_version $final_post_ktest;
4521
+ run_command $cp_final_post_ktest;
44074522 }
44084523
44094524 if ($opt{"POWEROFF_ON_SUCCESS"}) {
....@@ -4419,7 +4534,13 @@
44194534 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
44204535
44214536 if ($email_when_finished) {
4422
- send_email("KTEST: Your [$test_type] test has finished!",
4537
+ send_email("KTEST: Your test has finished!",
44234538 "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
44244539 }
4540
+
4541
+if (defined($opt{"LOG_FILE"})) {
4542
+ print "\n See $opt{LOG_FILE} for the record of results.\n\n";
4543
+ close LOG;
4544
+}
4545
+
44254546 exit 0;