Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ktest: Add prompt to use OUTPUT_MIN_CONFIG

If the defined OUTPUT_MIN_CONFIG in the make_min_config test exists,
then give a prompt to ask the user if they want to use that config
instead, as it is very often the case, especially when the test has been
interrupted. The OUTPUT_MIN_CONFIG is usually the config that one wants
to use to continue the test where they left off.

But if START_MIN_CONFIG is defined (thus the MIN_CONFIG is not the
default), then do not prompt, as it will be annoying if the user has
this as one of many tests, and the test pauses waiting for input, while
the user is sleeping.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Steven Rostedt and committed by
Steven Rostedt
35ce5952 b9066f6c

+59 -14
+56 -14
tools/testing/ktest/ktest.pl
··· 87 87 my $noclean; 88 88 my $minconfig; 89 89 my $start_minconfig; 90 + my $start_minconfig_defined; 90 91 my $output_minconfig; 91 92 my $ignore_config; 92 93 my $addconfig; ··· 218 217 EOF 219 218 ; 220 219 220 + sub read_yn { 221 + my ($prompt) = @_; 222 + 223 + my $ans; 224 + 225 + for (;;) { 226 + print "$prompt [Y/n] "; 227 + $ans = <STDIN>; 228 + chomp $ans; 229 + if ($ans =~ /^\s*$/) { 230 + $ans = "y"; 231 + } 232 + last if ($ans =~ /^y$/i || $ans =~ /^n$/i); 233 + print "Please answer either 'y' or 'n'.\n"; 234 + } 235 + if ($ans !~ /^y$/i) { 236 + return 0; 237 + } 238 + return 1; 239 + } 221 240 222 241 sub get_ktest_config { 223 242 my ($config) = @_; ··· 2466 2445 if (!defined($output_minconfig)) { 2467 2446 fail "OUTPUT_MIN_CONFIG not defined" and return; 2468 2447 } 2448 + 2449 + # If output_minconfig exists, and the start_minconfig 2450 + # came from min_config, than ask if we should use 2451 + # that instead. 2452 + if (-f $output_minconfig && !$start_minconfig_defined) { 2453 + print "$output_minconfig exists\n"; 2454 + if (read_yn " Use it as minconfig?") { 2455 + $start_minconfig = $output_minconfig; 2456 + } 2457 + } 2458 + 2469 2459 if (!defined($start_minconfig)) { 2470 2460 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return; 2471 2461 } 2462 + 2463 + my $temp_config = "$tmpdir/temp_config"; 2472 2464 2473 2465 # First things first. We build an allnoconfig to find 2474 2466 # out what the defaults are that we can't touch. ··· 2615 2581 # this config is needed, add it to the ignore list. 2616 2582 $keep_configs{$config} = $min_configs{$config}; 2617 2583 delete $min_configs{$config}; 2584 + 2585 + # update new ignore configs 2586 + if (defined($ignore_config)) { 2587 + open (OUT, ">$temp_config") 2588 + or die "Can't write to $temp_config"; 2589 + foreach my $config (keys %keep_configs) { 2590 + print OUT "$keep_configs{$config}\n"; 2591 + } 2592 + close OUT; 2593 + run_command "mv $temp_config $ignore_config" or 2594 + dodie "failed to copy update to $ignore_config"; 2595 + } 2596 + 2618 2597 } else { 2619 2598 # We booted without this config, remove it from the minconfigs. 2620 2599 doprint "$config is not needed, disabling\n"; ··· 2646 2599 } 2647 2600 2648 2601 # Save off all the current mandidory configs 2649 - open (OUT, ">$output_minconfig") 2650 - or die "Can't write to $output_minconfig"; 2602 + open (OUT, ">$temp_config") 2603 + or die "Can't write to $temp_config"; 2651 2604 foreach my $config (keys %keep_configs) { 2652 2605 print OUT "$keep_configs{$config}\n"; 2653 2606 } ··· 2655 2608 print OUT "$min_configs{$config}\n"; 2656 2609 } 2657 2610 close OUT; 2611 + 2612 + run_command "mv $temp_config $output_minconfig" or 2613 + dodie "failed to copy update to $output_minconfig"; 2658 2614 } 2659 2615 2660 2616 doprint "Reboot and wait $sleep_time seconds\n"; ··· 2677 2627 $ktest_config = $ARGV[0]; 2678 2628 if (! -f $ktest_config) { 2679 2629 print "$ktest_config does not exist.\n"; 2680 - my $ans; 2681 - for (;;) { 2682 - print "Create it? [Y/n] "; 2683 - $ans = <STDIN>; 2684 - chomp $ans; 2685 - if ($ans =~ /^\s*$/) { 2686 - $ans = "y"; 2687 - } 2688 - last if ($ans =~ /^y$/i || $ans =~ /^n$/i); 2689 - print "Please answer either 'y' or 'n'.\n"; 2690 - } 2691 - if ($ans !~ /^y$/i) { 2630 + if (!read_yn "Create it?") { 2692 2631 exit 0; 2693 2632 } 2694 2633 } ··· 2843 2804 $target_image = set_test_option("TARGET_IMAGE", $i); 2844 2805 $localversion = set_test_option("LOCALVERSION", $i); 2845 2806 2807 + $start_minconfig_defined = 1; 2808 + 2846 2809 if (!defined($start_minconfig)) { 2810 + $start_minconfig_defined = 0; 2847 2811 $start_minconfig = $minconfig; 2848 2812 } 2849 2813
+3
tools/testing/ktest/sample.conf
··· 854 854 # this file as your new min config, and use it to continue the test. 855 855 # This file does not need to exist on start of test. 856 856 # This file is not created until a config is found that can be removed. 857 + # If this file exists, you will be prompted if you want to use it 858 + # as the min_config (overriding MIN_CONFIG) if START_MIN_CONFIG 859 + # is not defined. 857 860 # (required field) 858 861 # 859 862 # START_MIN_CONFIG is the config to use to start the test with.