hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/testing/ktest/ktest.pl
....@@ -178,6 +178,7 @@
178178 my $store_successes;
179179 my $test_name;
180180 my $timeout;
181
+my $run_timeout;
181182 my $connect_timeout;
182183 my $config_bisect_exec;
183184 my $booted_timeout;
....@@ -340,6 +341,7 @@
340341 "STORE_SUCCESSES" => \$store_successes,
341342 "TEST_NAME" => \$test_name,
342343 "TIMEOUT" => \$timeout,
344
+ "RUN_TIMEOUT" => \$run_timeout,
343345 "CONNECT_TIMEOUT" => \$connect_timeout,
344346 "CONFIG_BISECT_EXEC" => \$config_bisect_exec,
345347 "BOOTED_TIMEOUT" => \$booted_timeout,
....@@ -1433,7 +1435,8 @@
14331435
14341436 # Still need to wait for the reboot to finish
14351437 wait_for_monitor($time, $reboot_success_line);
1436
-
1438
+ }
1439
+ if ($powercycle || $time) {
14371440 end_monitor;
14381441 }
14391442 }
....@@ -1799,6 +1802,14 @@
17991802 $command =~ s/\$SSH_USER/$ssh_user/g;
18001803 $command =~ s/\$MACHINE/$machine/g;
18011804
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
+ }
1812
+
18021813 doprint("$command ... ");
18031814 $start_time = time;
18041815
....@@ -1825,13 +1836,10 @@
18251836
18261837 while (1) {
18271838 my $fp = \*CMD;
1828
- if (defined($timeout)) {
1829
- doprint "timeout = $timeout\n";
1830
- }
18311839 my $line = wait_for_input($fp, $timeout);
18321840 if (!defined($line)) {
18331841 my $now = time;
1834
- if (defined($timeout) && (($now - $start_time) >= $timeout)) {
1842
+ if ($timeout >= 0 && (($now - $start_time) >= $timeout)) {
18351843 doprint "Hit timeout of $timeout, killing process\n";
18361844 $hit_timeout = 1;
18371845 kill 9, $pid;
....@@ -1912,7 +1920,7 @@
19121920
19131921 sub _get_grub_index {
19141922
1915
- my ($command, $target, $skip) = @_;
1923
+ my ($command, $target, $skip, $submenu) = @_;
19161924
19171925 return if (defined($grub_number) && defined($last_grub_menu) &&
19181926 $last_grub_menu eq $grub_menu && defined($last_machine) &&
....@@ -1929,11 +1937,16 @@
19291937
19301938 my $found = 0;
19311939
1940
+ my $submenu_number = 0;
1941
+
19321942 while (<IN>) {
19331943 if (/$target/) {
19341944 $grub_number++;
19351945 $found = 1;
19361946 last;
1947
+ } elsif (defined($submenu) && /$submenu/) {
1948
+ $submenu_number++;
1949
+ $grub_number = -1;
19371950 } elsif (/$skip/) {
19381951 $grub_number++;
19391952 }
....@@ -1942,6 +1955,9 @@
19421955
19431956 dodie "Could not find '$grub_menu' through $command on $machine"
19441957 if (!$found);
1958
+ if ($submenu_number > 0) {
1959
+ $grub_number = "$submenu_number>$grub_number";
1960
+ }
19451961 doprint "$grub_number\n";
19461962 $last_grub_menu = $grub_menu;
19471963 $last_machine = $machine;
....@@ -1952,6 +1968,7 @@
19521968 my $command;
19531969 my $target;
19541970 my $skip;
1971
+ my $submenu;
19551972 my $grub_menu_qt;
19561973
19571974 if ($reboot_type !~ /^grub/) {
....@@ -1966,8 +1983,9 @@
19661983 $skip = '^\s*title\s';
19671984 } elsif ($reboot_type eq "grub2") {
19681985 $command = "cat $grub_file";
1969
- $target = '^menuentry.*' . $grub_menu_qt;
1970
- $skip = '^menuentry\s|^submenu\s';
1986
+ $target = '^\s*menuentry.*' . $grub_menu_qt;
1987
+ $skip = '^\s*menuentry';
1988
+ $submenu = '^\s*submenu\s';
19711989 } elsif ($reboot_type eq "grub2bls") {
19721990 $command = $grub_bls_get;
19731991 $target = '^title=.*' . $grub_menu_qt;
....@@ -1976,7 +1994,7 @@
19761994 return;
19771995 }
19781996
1979
- _get_grub_index($command, $target, $skip);
1997
+ _get_grub_index($command, $target, $skip, $submenu);
19801998 }
19811999
19822000 sub wait_for_input
....@@ -1992,6 +2010,11 @@
19922010
19932011 if (!defined($time)) {
19942012 $time = $timeout;
2013
+ }
2014
+
2015
+ if ($time < 0) {
2016
+ # Negative number means wait indefinitely
2017
+ undef $time;
19952018 }
19962019
19972020 $rin = '';
....@@ -2040,7 +2063,7 @@
20402063 if ($reboot_type eq "grub") {
20412064 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
20422065 } elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) {
2043
- run_ssh "$grub_reboot $grub_number";
2066
+ run_ssh "$grub_reboot \"'$grub_number'\"";
20442067 } elsif ($reboot_type eq "syslinux") {
20452068 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
20462069 } elsif (defined $reboot_script) {
....@@ -3763,9 +3786,10 @@
37633786 # .config to make sure it is missing the config that
37643787 # we had before
37653788 my %configs = %min_configs;
3766
- delete $configs{$config};
3789
+ $configs{$config} = "# $config is not set";
37673790 make_new_config ((values %configs), (values %keep_configs));
37683791 make_oldconfig;
3792
+ delete $configs{$config};
37693793 undef %configs;
37703794 assign_configs \%configs, $output_config;
37713795
....@@ -4272,6 +4296,9 @@
42724296 }
42734297
42744298 sub cancel_test {
4299
+ if ($monitor_cnt) {
4300
+ end_monitor;
4301
+ }
42754302 if ($email_when_canceled) {
42764303 my $name = get_test_name;
42774304 send_email("KTEST: Your [$name] test was cancelled",