.. | .. |
---|
1 | 1 | #!/usr/bin/perl -w |
---|
| 2 | +# SPDX-License-Identifier: GPL-2.0-only |
---|
2 | 3 | # |
---|
3 | 4 | # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc. |
---|
4 | | -# Licensed under the terms of the GNU GPL License version 2 |
---|
5 | 5 | # |
---|
6 | 6 | |
---|
7 | 7 | use strict; |
---|
.. | .. |
---|
11 | 11 | use File::Copy qw(cp); |
---|
12 | 12 | use FileHandle; |
---|
13 | 13 | use FindBin; |
---|
| 14 | +use IO::Handle; |
---|
14 | 15 | |
---|
15 | 16 | my $VERSION = "0.2"; |
---|
16 | 17 | |
---|
.. | .. |
---|
30 | 31 | "EMAIL_WHEN_STARTED" => 0, |
---|
31 | 32 | "NUM_TESTS" => 1, |
---|
32 | 33 | "TEST_TYPE" => "build", |
---|
33 | | - "BUILD_TYPE" => "randconfig", |
---|
| 34 | + "BUILD_TYPE" => "oldconfig", |
---|
34 | 35 | "MAKE_CMD" => "make", |
---|
35 | 36 | "CLOSE_CONSOLE_SIGNAL" => "INT", |
---|
36 | 37 | "TIMEOUT" => 120, |
---|
.. | .. |
---|
58 | 59 | "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE", |
---|
59 | 60 | "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}", |
---|
60 | 61 | "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot", |
---|
| 62 | + "REBOOT_RETURN_CODE" => 255, |
---|
61 | 63 | "STOP_AFTER_SUCCESS" => 10, |
---|
62 | 64 | "STOP_AFTER_FAILURE" => 60, |
---|
63 | 65 | "STOP_TEST_AFTER" => 600, |
---|
64 | 66 | "MAX_MONITOR_WAIT" => 1800, |
---|
65 | 67 | "GRUB_REBOOT" => "grub2-reboot", |
---|
| 68 | + "GRUB_BLS_GET" => "grubby --info=ALL", |
---|
66 | 69 | "SYSLINUX" => "extlinux", |
---|
67 | 70 | "SYSLINUX_PATH" => "/boot/extlinux", |
---|
68 | 71 | "CONNECT_TIMEOUT" => 25, |
---|
.. | .. |
---|
78 | 81 | "LOG_FILE" => undef, |
---|
79 | 82 | "IGNORE_UNUSED" => 0, |
---|
80 | 83 | ); |
---|
| 84 | + |
---|
| 85 | +my $test_log_start = 0; |
---|
81 | 86 | |
---|
82 | 87 | my $ktest_config = "ktest.conf"; |
---|
83 | 88 | my $version; |
---|
.. | .. |
---|
96 | 101 | my $pre_ktest; |
---|
97 | 102 | my $post_ktest; |
---|
98 | 103 | my $pre_test; |
---|
| 104 | +my $pre_test_die; |
---|
99 | 105 | my $post_test; |
---|
100 | 106 | my $pre_build; |
---|
101 | 107 | my $post_build; |
---|
.. | .. |
---|
105 | 111 | my $reboot_script; |
---|
106 | 112 | my $power_cycle; |
---|
107 | 113 | my $reboot; |
---|
| 114 | +my $reboot_return_code; |
---|
108 | 115 | my $reboot_on_error; |
---|
109 | 116 | my $switch_to_good; |
---|
110 | 117 | my $switch_to_test; |
---|
.. | .. |
---|
123 | 130 | my $grub_file; |
---|
124 | 131 | my $grub_number; |
---|
125 | 132 | my $grub_reboot; |
---|
| 133 | +my $grub_bls_get; |
---|
126 | 134 | my $syslinux; |
---|
127 | 135 | my $syslinux_path; |
---|
128 | 136 | my $syslinux_label; |
---|
.. | .. |
---|
219 | 227 | my $mailto; |
---|
220 | 228 | my $mailer; |
---|
221 | 229 | my $mail_path; |
---|
| 230 | +my $mail_max_size; |
---|
222 | 231 | my $mail_command; |
---|
223 | 232 | my $email_on_error; |
---|
224 | 233 | my $email_when_finished; |
---|
.. | .. |
---|
255 | 264 | "MAILTO" => \$mailto, |
---|
256 | 265 | "MAILER" => \$mailer, |
---|
257 | 266 | "MAIL_PATH" => \$mail_path, |
---|
| 267 | + "MAIL_MAX_SIZE" => \$mail_max_size, |
---|
258 | 268 | "MAIL_COMMAND" => \$mail_command, |
---|
259 | 269 | "EMAIL_ON_ERROR" => \$email_on_error, |
---|
260 | 270 | "EMAIL_WHEN_FINISHED" => \$email_when_finished, |
---|
.. | .. |
---|
269 | 279 | "PRE_KTEST" => \$pre_ktest, |
---|
270 | 280 | "POST_KTEST" => \$post_ktest, |
---|
271 | 281 | "PRE_TEST" => \$pre_test, |
---|
| 282 | + "PRE_TEST_DIE" => \$pre_test_die, |
---|
272 | 283 | "POST_TEST" => \$post_test, |
---|
273 | 284 | "BUILD_TYPE" => \$build_type, |
---|
274 | 285 | "BUILD_OPTIONS" => \$build_options, |
---|
.. | .. |
---|
278 | 289 | "POST_BUILD_DIE" => \$post_build_die, |
---|
279 | 290 | "POWER_CYCLE" => \$power_cycle, |
---|
280 | 291 | "REBOOT" => \$reboot, |
---|
| 292 | + "REBOOT_RETURN_CODE" => \$reboot_return_code, |
---|
281 | 293 | "BUILD_NOCLEAN" => \$noclean, |
---|
282 | 294 | "MIN_CONFIG" => \$minconfig, |
---|
283 | 295 | "OUTPUT_MIN_CONFIG" => \$output_minconfig, |
---|
.. | .. |
---|
292 | 304 | "GRUB_MENU" => \$grub_menu, |
---|
293 | 305 | "GRUB_FILE" => \$grub_file, |
---|
294 | 306 | "GRUB_REBOOT" => \$grub_reboot, |
---|
| 307 | + "GRUB_BLS_GET" => \$grub_bls_get, |
---|
295 | 308 | "SYSLINUX" => \$syslinux, |
---|
296 | 309 | "SYSLINUX_PATH" => \$syslinux_path, |
---|
297 | 310 | "SYSLINUX_LABEL" => \$syslinux_label, |
---|
.. | .. |
---|
437 | 450 | ; |
---|
438 | 451 | $config_help{"REBOOT_TYPE"} = << "EOF" |
---|
439 | 452 | Way to reboot the box to the test kernel. |
---|
440 | | - Only valid options so far are "grub", "grub2", "syslinux", and "script". |
---|
| 453 | + Only valid options so far are "grub", "grub2", "grub2bls", "syslinux", and "script". |
---|
441 | 454 | |
---|
442 | 455 | If you specify grub, it will assume grub version 1 |
---|
443 | 456 | and will search in /boot/grub/menu.lst for the title \$GRUB_MENU |
---|
.. | .. |
---|
450 | 463 | |
---|
451 | 464 | If you specify grub2, then you also need to specify both \$GRUB_MENU |
---|
452 | 465 | and \$GRUB_FILE. |
---|
| 466 | + |
---|
| 467 | + If you specify grub2bls, then you also need to specify \$GRUB_MENU. |
---|
453 | 468 | |
---|
454 | 469 | If you specify syslinux, then you may use SYSLINUX to define the syslinux |
---|
455 | 470 | command (defaults to extlinux), and SYSLINUX_PATH to specify the path to |
---|
.. | .. |
---|
476 | 491 | menu must be a non-nested menu. Add the quotes used in the menu |
---|
477 | 492 | to guarantee your selection, as the first menuentry with the content |
---|
478 | 493 | of \$GRUB_MENU that is found will be used. |
---|
| 494 | + |
---|
| 495 | + For grub2bls, \$GRUB_MENU is searched on the result of \$GRUB_BLS_GET |
---|
| 496 | + command for the lines that begin with "title". |
---|
479 | 497 | EOF |
---|
480 | 498 | ; |
---|
481 | 499 | $config_help{"GRUB_FILE"} = << "EOF" |
---|
.. | .. |
---|
496 | 514 | |
---|
497 | 515 | sub _logit { |
---|
498 | 516 | 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); |
---|
| 517 | + print LOG @_; |
---|
502 | 518 | } |
---|
503 | 519 | } |
---|
504 | 520 | |
---|
.. | .. |
---|
692 | 708 | } |
---|
693 | 709 | } |
---|
694 | 710 | |
---|
695 | | - if ($rtype eq "grub") { |
---|
| 711 | + if (($rtype eq "grub") or ($rtype eq "grub2bls")) { |
---|
696 | 712 | get_mandatory_config("GRUB_MENU"); |
---|
697 | 713 | } |
---|
698 | 714 | |
---|
.. | .. |
---|
898 | 914 | } |
---|
899 | 915 | } |
---|
900 | 916 | |
---|
| 917 | + if ($val =~ s/^\s*NOT\s+(.*)//) { |
---|
| 918 | + my $express = $1; |
---|
| 919 | + my $ret = process_expression($name, $express); |
---|
| 920 | + return !$ret; |
---|
| 921 | + } |
---|
| 922 | + |
---|
901 | 923 | if ($val =~ /^\s*0\s*$/) { |
---|
902 | 924 | return 0; |
---|
903 | 925 | } elsif ($val =~ /^\s*\d+\s*$/) { |
---|
.. | .. |
---|
1019 | 1041 | } |
---|
1020 | 1042 | |
---|
1021 | 1043 | if (!$skip && $rest !~ /^\s*$/) { |
---|
1022 | | - die "$name: $.: Gargbage found after $type\n$_"; |
---|
| 1044 | + die "$name: $.: Garbage found after $type\n$_"; |
---|
1023 | 1045 | } |
---|
1024 | 1046 | |
---|
1025 | 1047 | if ($skip && $type eq "TEST_START") { |
---|
.. | .. |
---|
1052 | 1074 | } |
---|
1053 | 1075 | |
---|
1054 | 1076 | if ($rest !~ /^\s*$/) { |
---|
1055 | | - die "$name: $.: Gargbage found after DEFAULTS\n$_"; |
---|
| 1077 | + die "$name: $.: Garbage found after DEFAULTS\n$_"; |
---|
1056 | 1078 | } |
---|
1057 | 1079 | |
---|
1058 | 1080 | } elsif (/^\s*INCLUDE\s+(\S+)/) { |
---|
.. | .. |
---|
1143 | 1165 | # on of these sections that have SKIP defined. |
---|
1144 | 1166 | # The save variable can be |
---|
1145 | 1167 | # defined multiple times and the new one simply overrides |
---|
1146 | | - # the prevous one. |
---|
| 1168 | + # the previous one. |
---|
1147 | 1169 | set_variable($lvalue, $rvalue); |
---|
1148 | 1170 | |
---|
1149 | 1171 | } else { |
---|
.. | .. |
---|
1223 | 1245 | foreach my $option (keys %not_used) { |
---|
1224 | 1246 | print "$option\n"; |
---|
1225 | 1247 | } |
---|
1226 | | - print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n"; |
---|
| 1248 | + print "Set IGNORE_UNUSED = 1 to have ktest ignore unused variables\n"; |
---|
1227 | 1249 | if (!read_yn "Do you want to continue?") { |
---|
1228 | 1250 | exit -1; |
---|
1229 | 1251 | } |
---|
.. | .. |
---|
1334 | 1356 | # Check for recursive evaluations. |
---|
1335 | 1357 | # 100 deep should be more than enough. |
---|
1336 | 1358 | if ($r++ > 100) { |
---|
1337 | | - die "Over 100 evaluations accurred with $option\n" . |
---|
| 1359 | + die "Over 100 evaluations occurred with $option\n" . |
---|
1338 | 1360 | "Check for recursive variables\n"; |
---|
1339 | 1361 | } |
---|
1340 | 1362 | $prev = $option; |
---|
.. | .. |
---|
1437 | 1459 | |
---|
1438 | 1460 | my $in_die = 0; |
---|
1439 | 1461 | |
---|
| 1462 | +sub get_test_name() { |
---|
| 1463 | + my $name; |
---|
| 1464 | + |
---|
| 1465 | + if (defined($test_name)) { |
---|
| 1466 | + $name = "$test_name:$test_type"; |
---|
| 1467 | + } else { |
---|
| 1468 | + $name = $test_type; |
---|
| 1469 | + } |
---|
| 1470 | + return $name; |
---|
| 1471 | +} |
---|
| 1472 | + |
---|
1440 | 1473 | sub dodie { |
---|
1441 | 1474 | |
---|
1442 | | - # avoid recusion |
---|
| 1475 | + # avoid recursion |
---|
1443 | 1476 | return if ($in_die); |
---|
1444 | 1477 | $in_die = 1; |
---|
1445 | 1478 | |
---|
1446 | | - doprint "CRITICAL FAILURE... ", @_, "\n"; |
---|
1447 | | - |
---|
1448 | 1479 | my $i = $iteration; |
---|
| 1480 | + |
---|
| 1481 | + doprint "CRITICAL FAILURE... [TEST $i] ", @_, "\n"; |
---|
1449 | 1482 | |
---|
1450 | 1483 | if ($reboot_on_error && !do_not_reboot) { |
---|
1451 | 1484 | |
---|
.. | .. |
---|
1462 | 1495 | } |
---|
1463 | 1496 | |
---|
1464 | 1497 | 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"); |
---|
| 1498 | + my $name = get_test_name; |
---|
| 1499 | + my $log_file; |
---|
| 1500 | + |
---|
| 1501 | + if (defined($opt{"LOG_FILE"})) { |
---|
| 1502 | + my $whence = 2; # End of file |
---|
| 1503 | + my $log_size = tell LOG; |
---|
| 1504 | + my $size = $log_size - $test_log_start; |
---|
| 1505 | + |
---|
| 1506 | + if (defined($mail_max_size)) { |
---|
| 1507 | + if ($size > $mail_max_size) { |
---|
| 1508 | + $size = $mail_max_size; |
---|
| 1509 | + } |
---|
| 1510 | + } |
---|
| 1511 | + my $pos = - $size; |
---|
| 1512 | + $log_file = "$tmpdir/log"; |
---|
| 1513 | + open (L, "$opt{LOG_FILE}") or die "Can't open $opt{LOG_FILE} to read)"; |
---|
| 1514 | + open (O, "> $tmpdir/log") or die "Can't open $tmpdir/log\n"; |
---|
| 1515 | + seek(L, $pos, $whence); |
---|
| 1516 | + while (<L>) { |
---|
| 1517 | + print O; |
---|
| 1518 | + } |
---|
| 1519 | + close O; |
---|
| 1520 | + close L; |
---|
| 1521 | + } |
---|
| 1522 | + send_email("KTEST: critical failure for test $i [$name]", |
---|
| 1523 | + "Your test started at $script_start_time has failed with:\n@_\n", $log_file); |
---|
1467 | 1524 | } |
---|
1468 | 1525 | |
---|
1469 | 1526 | if ($monitor_cnt) { |
---|
.. | .. |
---|
1485 | 1542 | my $TIOCGPTN = 0x80045430; |
---|
1486 | 1543 | |
---|
1487 | 1544 | sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or |
---|
1488 | | - dodie "Cant open /dev/ptmx"; |
---|
| 1545 | + dodie "Can't open /dev/ptmx"; |
---|
1489 | 1546 | |
---|
1490 | 1547 | # unlockpt() |
---|
1491 | 1548 | $tmp = pack("i", 0); |
---|
.. | .. |
---|
1737 | 1794 | my $dord = 0; |
---|
1738 | 1795 | my $dostdout = 0; |
---|
1739 | 1796 | my $pid; |
---|
| 1797 | + my $command_orig = $command; |
---|
1740 | 1798 | |
---|
1741 | 1799 | $command =~ s/\$SSH_USER/$ssh_user/g; |
---|
1742 | 1800 | $command =~ s/\$MACHINE/$machine/g; |
---|
.. | .. |
---|
1748 | 1806 | (fail "unable to exec $command" and return 0); |
---|
1749 | 1807 | |
---|
1750 | 1808 | if (defined($opt{"LOG_FILE"})) { |
---|
1751 | | - open(LOG, ">>$opt{LOG_FILE}") or |
---|
1752 | | - dodie "failed to write to log"; |
---|
1753 | 1809 | $dolog = 1; |
---|
1754 | 1810 | } |
---|
1755 | 1811 | |
---|
.. | .. |
---|
1791 | 1847 | # shift 8 for real exit status |
---|
1792 | 1848 | $run_command_status = $? >> 8; |
---|
1793 | 1849 | |
---|
| 1850 | + if ($command_orig eq $default{REBOOT} && |
---|
| 1851 | + $run_command_status == $reboot_return_code) { |
---|
| 1852 | + $run_command_status = 0; |
---|
| 1853 | + } |
---|
| 1854 | + |
---|
1794 | 1855 | close(CMD); |
---|
1795 | | - close(LOG) if ($dolog); |
---|
1796 | 1856 | close(RD) if ($dord); |
---|
1797 | 1857 | |
---|
1798 | 1858 | $end_time = time; |
---|
.. | .. |
---|
1850 | 1910 | return run_scp($src, $dst, $cp_scp); |
---|
1851 | 1911 | } |
---|
1852 | 1912 | |
---|
1853 | | -sub get_grub2_index { |
---|
| 1913 | +sub _get_grub_index { |
---|
| 1914 | + |
---|
| 1915 | + my ($command, $target, $skip) = @_; |
---|
1854 | 1916 | |
---|
1855 | 1917 | return if (defined($grub_number) && defined($last_grub_menu) && |
---|
1856 | 1918 | $last_grub_menu eq $grub_menu && defined($last_machine) && |
---|
1857 | 1919 | $last_machine eq $machine); |
---|
1858 | 1920 | |
---|
1859 | | - doprint "Find grub2 menu ... "; |
---|
| 1921 | + doprint "Find $reboot_type menu ... "; |
---|
1860 | 1922 | $grub_number = -1; |
---|
1861 | 1923 | |
---|
1862 | 1924 | my $ssh_grub = $ssh_exec; |
---|
1863 | | - $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g; |
---|
| 1925 | + $ssh_grub =~ s,\$SSH_COMMAND,$command,g; |
---|
1864 | 1926 | |
---|
1865 | 1927 | open(IN, "$ssh_grub |") |
---|
1866 | | - or dodie "unable to get $grub_file"; |
---|
| 1928 | + or dodie "unable to execute $command"; |
---|
1867 | 1929 | |
---|
1868 | 1930 | my $found = 0; |
---|
1869 | 1931 | |
---|
1870 | 1932 | while (<IN>) { |
---|
1871 | | - if (/^menuentry.*$grub_menu/) { |
---|
| 1933 | + if (/$target/) { |
---|
1872 | 1934 | $grub_number++; |
---|
1873 | 1935 | $found = 1; |
---|
1874 | 1936 | last; |
---|
1875 | | - } elsif (/^menuentry\s|^submenu\s/) { |
---|
| 1937 | + } elsif (/$skip/) { |
---|
1876 | 1938 | $grub_number++; |
---|
1877 | 1939 | } |
---|
1878 | 1940 | } |
---|
1879 | 1941 | close(IN); |
---|
1880 | 1942 | |
---|
1881 | | - dodie "Could not find '$grub_menu' in $grub_file on $machine" |
---|
| 1943 | + dodie "Could not find '$grub_menu' through $command on $machine" |
---|
1882 | 1944 | if (!$found); |
---|
1883 | 1945 | doprint "$grub_number\n"; |
---|
1884 | 1946 | $last_grub_menu = $grub_menu; |
---|
.. | .. |
---|
1887 | 1949 | |
---|
1888 | 1950 | sub get_grub_index { |
---|
1889 | 1951 | |
---|
1890 | | - if ($reboot_type eq "grub2") { |
---|
1891 | | - get_grub2_index; |
---|
| 1952 | + my $command; |
---|
| 1953 | + my $target; |
---|
| 1954 | + my $skip; |
---|
| 1955 | + my $grub_menu_qt; |
---|
| 1956 | + |
---|
| 1957 | + if ($reboot_type !~ /^grub/) { |
---|
1892 | 1958 | return; |
---|
1893 | 1959 | } |
---|
1894 | 1960 | |
---|
1895 | | - if ($reboot_type ne "grub") { |
---|
| 1961 | + $grub_menu_qt = quotemeta($grub_menu); |
---|
| 1962 | + |
---|
| 1963 | + if ($reboot_type eq "grub") { |
---|
| 1964 | + $command = "cat /boot/grub/menu.lst"; |
---|
| 1965 | + $target = '^\s*title\s+' . $grub_menu_qt . '\s*$'; |
---|
| 1966 | + $skip = '^\s*title\s'; |
---|
| 1967 | + } elsif ($reboot_type eq "grub2") { |
---|
| 1968 | + $command = "cat $grub_file"; |
---|
| 1969 | + $target = '^menuentry.*' . $grub_menu_qt; |
---|
| 1970 | + $skip = '^menuentry\s|^submenu\s'; |
---|
| 1971 | + } elsif ($reboot_type eq "grub2bls") { |
---|
| 1972 | + $command = $grub_bls_get; |
---|
| 1973 | + $target = '^title=.*' . $grub_menu_qt; |
---|
| 1974 | + $skip = '^title='; |
---|
| 1975 | + } else { |
---|
1896 | 1976 | return; |
---|
1897 | 1977 | } |
---|
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); |
---|
1901 | 1978 | |
---|
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; |
---|
| 1979 | + _get_grub_index($command, $target, $skip); |
---|
1929 | 1980 | } |
---|
1930 | 1981 | |
---|
1931 | 1982 | sub wait_for_input |
---|
.. | .. |
---|
1988 | 2039 | |
---|
1989 | 2040 | if ($reboot_type eq "grub") { |
---|
1990 | 2041 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; |
---|
1991 | | - } elsif ($reboot_type eq "grub2") { |
---|
| 2042 | + } elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) { |
---|
1992 | 2043 | run_ssh "$grub_reboot $grub_number"; |
---|
1993 | 2044 | } elsif ($reboot_type eq "syslinux") { |
---|
1994 | 2045 | run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path"; |
---|
.. | .. |
---|
3168 | 3219 | doprint "***************************************\n\n"; |
---|
3169 | 3220 | } |
---|
3170 | 3221 | |
---|
| 3222 | +my $pass = 1; |
---|
| 3223 | + |
---|
3171 | 3224 | sub run_config_bisect { |
---|
3172 | 3225 | my ($good, $bad, $last_result) = @_; |
---|
3173 | 3226 | my $reset = ""; |
---|
.. | .. |
---|
3190 | 3243 | |
---|
3191 | 3244 | $ret = run_config_bisect_test $config_bisect_type; |
---|
3192 | 3245 | if ($ret) { |
---|
3193 | | - doprint "NEW GOOD CONFIG\n"; |
---|
| 3246 | + doprint "NEW GOOD CONFIG ($pass)\n"; |
---|
| 3247 | + system("cp $output_config $tmpdir/good_config.tmp.$pass"); |
---|
| 3248 | + $pass++; |
---|
3194 | 3249 | # Return 3 for good config |
---|
3195 | 3250 | return 3; |
---|
3196 | 3251 | } else { |
---|
3197 | | - doprint "NEW BAD CONFIG\n"; |
---|
| 3252 | + doprint "NEW BAD CONFIG ($pass)\n"; |
---|
| 3253 | + system("cp $output_config $tmpdir/bad_config.tmp.$pass"); |
---|
| 3254 | + $pass++; |
---|
3198 | 3255 | # Return 4 for bad config |
---|
3199 | 3256 | return 4; |
---|
3200 | 3257 | } |
---|
.. | .. |
---|
4057 | 4114 | } |
---|
4058 | 4115 | } |
---|
4059 | 4116 | |
---|
4060 | | -if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { |
---|
4061 | | - unlink $opt{"LOG_FILE"}; |
---|
| 4117 | +if (defined($opt{"LOG_FILE"})) { |
---|
| 4118 | + if ($opt{"CLEAR_LOG"}) { |
---|
| 4119 | + unlink $opt{"LOG_FILE"}; |
---|
| 4120 | + } |
---|
| 4121 | + open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; |
---|
| 4122 | + LOG->autoflush(1); |
---|
4062 | 4123 | } |
---|
4063 | 4124 | |
---|
4064 | 4125 | doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; |
---|
.. | .. |
---|
4151 | 4212 | } |
---|
4152 | 4213 | |
---|
4153 | 4214 | sub do_send_mail { |
---|
4154 | | - my ($subject, $message) = @_; |
---|
| 4215 | + my ($subject, $message, $file) = @_; |
---|
4155 | 4216 | |
---|
4156 | 4217 | if (!defined($mail_path)) { |
---|
4157 | 4218 | # find the mailer |
---|
.. | .. |
---|
4161 | 4222 | } |
---|
4162 | 4223 | } |
---|
4163 | 4224 | |
---|
| 4225 | + my $header_file = "$tmpdir/header"; |
---|
| 4226 | + open (HEAD, ">$header_file") or die "Can not create $header_file\n"; |
---|
| 4227 | + print HEAD "To: $mailto\n"; |
---|
| 4228 | + print HEAD "Subject: $subject\n\n"; |
---|
| 4229 | + print HEAD "$message\n"; |
---|
| 4230 | + close HEAD; |
---|
| 4231 | + |
---|
4164 | 4232 | if (!defined($mail_command)) { |
---|
4165 | 4233 | if ($mailer eq "mail" || $mailer eq "mailx") { |
---|
4166 | | - $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< \'\$MESSAGE\'"; |
---|
| 4234 | + $mail_command = "cat \$HEADER_FILE \$BODY_FILE | \$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO"; |
---|
4167 | 4235 | } elsif ($mailer eq "sendmail" ) { |
---|
4168 | | - $mail_command = "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | \$MAIL_PATH/\$MAILER -t \$MAILTO"; |
---|
| 4236 | + $mail_command = "cat \$HEADER_FILE \$BODY_FILE | \$MAIL_PATH/\$MAILER -t \$MAILTO"; |
---|
4169 | 4237 | } else { |
---|
4170 | 4238 | die "\nYour mailer: $mailer is not supported.\n"; |
---|
4171 | 4239 | } |
---|
4172 | 4240 | } |
---|
4173 | 4241 | |
---|
| 4242 | + if (defined($file)) { |
---|
| 4243 | + $mail_command =~ s/\$BODY_FILE/$file/g; |
---|
| 4244 | + } else { |
---|
| 4245 | + $mail_command =~ s/\$BODY_FILE//g; |
---|
| 4246 | + } |
---|
| 4247 | + |
---|
| 4248 | + $mail_command =~ s/\$HEADER_FILE/$header_file/g; |
---|
4174 | 4249 | $mail_command =~ s/\$MAILER/$mailer/g; |
---|
4175 | 4250 | $mail_command =~ s/\$MAIL_PATH/$mail_path/g; |
---|
4176 | 4251 | $mail_command =~ s/\$MAILTO/$mailto/g; |
---|
.. | .. |
---|
4198 | 4273 | |
---|
4199 | 4274 | sub cancel_test { |
---|
4200 | 4275 | if ($email_when_canceled) { |
---|
4201 | | - send_email("KTEST: Your [$test_type] test was cancelled", |
---|
| 4276 | + my $name = get_test_name; |
---|
| 4277 | + send_email("KTEST: Your [$name] test was cancelled", |
---|
4202 | 4278 | "Your test started at $script_start_time was cancelled: sig int"); |
---|
4203 | 4279 | } |
---|
4204 | 4280 | die "\nCaught Sig Int, test interrupted: $!\n" |
---|
.. | .. |
---|
4252 | 4328 | run_command $pre_ktest; |
---|
4253 | 4329 | } |
---|
4254 | 4330 | if ($email_when_started) { |
---|
4255 | | - send_email("KTEST: Your [$test_type] test was started", |
---|
| 4331 | + my $name = get_test_name; |
---|
| 4332 | + send_email("KTEST: Your [$name] test was started", |
---|
4256 | 4333 | "Your test was started on $script_start_time"); |
---|
4257 | 4334 | } |
---|
4258 | 4335 | } |
---|
.. | .. |
---|
4283 | 4360 | |
---|
4284 | 4361 | if (!$buildonly) { |
---|
4285 | 4362 | $target = "$ssh_user\@$machine"; |
---|
4286 | | - if ($reboot_type eq "grub") { |
---|
| 4363 | + if (($reboot_type eq "grub") or ($reboot_type eq "grub2bls")) { |
---|
4287 | 4364 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
---|
4288 | 4365 | } elsif ($reboot_type eq "grub2") { |
---|
4289 | 4366 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
---|
.. | .. |
---|
4321 | 4398 | } |
---|
4322 | 4399 | |
---|
4323 | 4400 | doprint "\n\n"; |
---|
| 4401 | + |
---|
| 4402 | + if (defined($opt{"LOG_FILE"})) { |
---|
| 4403 | + $test_log_start = tell(LOG); |
---|
| 4404 | + } |
---|
| 4405 | + |
---|
4324 | 4406 | doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n"; |
---|
4325 | 4407 | |
---|
4326 | 4408 | if (defined($pre_test)) { |
---|
4327 | | - run_command $pre_test; |
---|
| 4409 | + my $ret = run_command $pre_test; |
---|
| 4410 | + if (!$ret && defined($pre_test_die) && |
---|
| 4411 | + $pre_test_die) { |
---|
| 4412 | + dodie "failed to pre_test\n"; |
---|
| 4413 | + } |
---|
4328 | 4414 | } |
---|
4329 | 4415 | |
---|
4330 | 4416 | unlink $dmesg; |
---|
.. | .. |
---|
4403 | 4489 | } |
---|
4404 | 4490 | |
---|
4405 | 4491 | if (defined($final_post_ktest)) { |
---|
4406 | | - run_command $final_post_ktest; |
---|
| 4492 | + |
---|
| 4493 | + my $cp_final_post_ktest = eval_kernel_version $final_post_ktest; |
---|
| 4494 | + run_command $cp_final_post_ktest; |
---|
4407 | 4495 | } |
---|
4408 | 4496 | |
---|
4409 | 4497 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
---|
.. | .. |
---|
4419 | 4507 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; |
---|
4420 | 4508 | |
---|
4421 | 4509 | if ($email_when_finished) { |
---|
4422 | | - send_email("KTEST: Your [$test_type] test has finished!", |
---|
| 4510 | + send_email("KTEST: Your test has finished!", |
---|
4423 | 4511 | "$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!"); |
---|
4424 | 4512 | } |
---|
| 4513 | + |
---|
| 4514 | +if (defined($opt{"LOG_FILE"})) { |
---|
| 4515 | + print "\n See $opt{LOG_FILE} for the record of results.\n\n"; |
---|
| 4516 | + close LOG; |
---|
| 4517 | +} |
---|
| 4518 | + |
---|
4425 | 4519 | exit 0; |
---|