Skip to content

Commit 4c4ab12

Browse files
Steven Rostedtrostedt
authored andcommitted
ktest: Add test type make_min_config
After doing a make localyesconfig, your kernel configuration may not be the most useful minimum configuration. Having a true minimum config that you can use against other configs is very useful if someone else has a config that breaks on your code. By only forcing those configurations that are truly required to boot your machine will give you less of a chance that one of your set configurations will make the bug go away. This will give you a better chance to be able to reproduce the reported bug matching the broken config. Note, this does take some time, and may require you to run the test over night, or perhaps over the weekend. But it also allows you to interrupt it, and gives you the current minimum config that was found till that time. Note, this test automatically assumes a BUILD_TYPE of oldconfig and its test type acts like boot. TODO: add a test version that makes the config do more than just boot, like having network access. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 0df213c commit 4c4ab12

2 files changed

Lines changed: 301 additions & 4 deletions

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 251 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
my $post_install;
8787
my $noclean;
8888
my $minconfig;
89+
my $start_minconfig;
90+
my $output_minconfig;
91+
my $ignore_config;
8992
my $addconfig;
9093
my $in_bisect = 0;
9194
my $bisect_bad = "";
@@ -1189,7 +1192,11 @@ sub apply_min_config {
11891192

11901193
sub make_oldconfig {
11911194

1192-
apply_min_config;
1195+
my @force_list = keys %force_config;
1196+
1197+
if ($#force_list >= 0) {
1198+
apply_min_config;
1199+
}
11931200

11941201
if (!run_command "$make oldnoconfig") {
11951202
# Perhaps oldnoconfig doesn't exist in this version of the kernel
@@ -1678,21 +1685,27 @@ sub bisect {
16781685

16791686
my %dependency;
16801687

1681-
sub process_config_ignore {
1682-
my ($config) = @_;
1688+
sub assign_configs {
1689+
my ($hash, $config) = @_;
16831690

16841691
open (IN, $config)
16851692
or dodie "Failed to read $config";
16861693

16871694
while (<IN>) {
16881695
if (/^((CONFIG\S*)=.*)/) {
1689-
$config_ignore{$2} = $1;
1696+
${$hash}{$2} = $1;
16901697
}
16911698
}
16921699

16931700
close(IN);
16941701
}
16951702

1703+
sub process_config_ignore {
1704+
my ($config) = @_;
1705+
1706+
assign_configs \%config_ignore, $config;
1707+
}
1708+
16961709
sub read_current_config {
16971710
my ($config_ref) = @_;
16981711

@@ -2149,6 +2162,226 @@ sub patchcheck {
21492162
return 1;
21502163
}
21512164

2165+
sub read_config_list {
2166+
my ($config) = @_;
2167+
2168+
open (IN, $config)
2169+
or dodie "Failed to read $config";
2170+
2171+
while (<IN>) {
2172+
if (/^((CONFIG\S*)=.*)/) {
2173+
if (!defined($config_ignore{$2})) {
2174+
$config_list{$2} = $1;
2175+
}
2176+
}
2177+
}
2178+
2179+
close(IN);
2180+
}
2181+
2182+
sub read_output_config {
2183+
my ($config) = @_;
2184+
2185+
assign_configs \%config_ignore, $config;
2186+
}
2187+
2188+
sub make_new_config {
2189+
my @configs = @_;
2190+
2191+
open (OUT, ">$output_config")
2192+
or dodie "Failed to write $output_config";
2193+
2194+
foreach my $config (@configs) {
2195+
print OUT "$config\n";
2196+
}
2197+
close OUT;
2198+
}
2199+
2200+
sub make_min_config {
2201+
my ($i) = @_;
2202+
2203+
if (!defined($output_minconfig)) {
2204+
fail "OUTPUT_MIN_CONFIG not defined" and return;
2205+
}
2206+
if (!defined($start_minconfig)) {
2207+
fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2208+
}
2209+
2210+
# First things first. We build an allnoconfig to find
2211+
# out what the defaults are that we can't touch.
2212+
# Some are selections, but we really can't handle selections.
2213+
2214+
my $save_minconfig = $minconfig;
2215+
undef $minconfig;
2216+
2217+
run_command "$make allnoconfig" or return 0;
2218+
2219+
process_config_ignore $output_config;
2220+
my %keep_configs;
2221+
2222+
if (defined($ignore_config)) {
2223+
# make sure the file exists
2224+
`touch $ignore_config`;
2225+
assign_configs \%keep_configs, $ignore_config;
2226+
}
2227+
2228+
doprint "Load initial configs from $start_minconfig\n";
2229+
2230+
# Look at the current min configs, and save off all the
2231+
# ones that were set via the allnoconfig
2232+
my %min_configs;
2233+
assign_configs \%min_configs, $start_minconfig;
2234+
2235+
my @config_keys = keys %min_configs;
2236+
2237+
# Remove anything that was set by the make allnoconfig
2238+
# we shouldn't need them as they get set for us anyway.
2239+
foreach my $config (@config_keys) {
2240+
# Remove anything in the ignore_config
2241+
if (defined($keep_configs{$config})) {
2242+
my $file = $ignore_config;
2243+
$file =~ s,.*/(.*?)$,$1,;
2244+
doprint "$config set by $file ... ignored\n";
2245+
delete $min_configs{$config};
2246+
next;
2247+
}
2248+
# But make sure the settings are the same. If a min config
2249+
# sets a selection, we do not want to get rid of it if
2250+
# it is not the same as what we have. Just move it into
2251+
# the keep configs.
2252+
if (defined($config_ignore{$config})) {
2253+
if ($config_ignore{$config} ne $min_configs{$config}) {
2254+
doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2255+
doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2256+
$keep_configs{$config} = $min_configs{$config};
2257+
} else {
2258+
doprint "$config set by allnoconfig ... ignored\n";
2259+
}
2260+
delete $min_configs{$config};
2261+
}
2262+
}
2263+
2264+
my %nochange_config;
2265+
2266+
my $done = 0;
2267+
2268+
while (!$done) {
2269+
2270+
my $config;
2271+
my $found;
2272+
2273+
# Now disable each config one by one and do a make oldconfig
2274+
# till we find a config that changes our list.
2275+
2276+
# Put configs that did not modify the config at the end.
2277+
my @test_configs = keys %min_configs;
2278+
my $reset = 1;
2279+
for (my $i = 0; $i < $#test_configs; $i++) {
2280+
if (!defined($nochange_config{$test_configs[0]})) {
2281+
$reset = 0;
2282+
last;
2283+
}
2284+
# This config didn't change the .config last time.
2285+
# Place it at the end
2286+
my $config = shift @test_configs;
2287+
push @test_configs, $config;
2288+
}
2289+
2290+
# if every test config has failed to modify the .config file
2291+
# in the past, then reset and start over.
2292+
if ($reset) {
2293+
undef %nochange_config;
2294+
}
2295+
2296+
foreach my $config (@test_configs) {
2297+
2298+
# Remove this config from the list of configs
2299+
# do a make oldnoconfig and then read the resulting
2300+
# .config to make sure it is missing the config that
2301+
# we had before
2302+
my %configs = %min_configs;
2303+
delete $configs{$config};
2304+
make_new_config ((values %configs), (values %keep_configs));
2305+
make_oldconfig;
2306+
undef %configs;
2307+
assign_configs \%configs, $output_config;
2308+
2309+
if (!defined($configs{$config})) {
2310+
$found = $config;
2311+
last;
2312+
}
2313+
2314+
doprint "disabling config $config did not change .config\n";
2315+
2316+
# oh well, try another config
2317+
$nochange_config{$config} = 1;
2318+
}
2319+
2320+
if (!defined($found)) {
2321+
doprint "No more configs found that we can disable\n";
2322+
$done = 1;
2323+
last;
2324+
}
2325+
2326+
$config = $found;
2327+
2328+
doprint "Test with $config disabled\n";
2329+
2330+
# set in_bisect to keep build and monitor from dieing
2331+
$in_bisect = 1;
2332+
2333+
my $failed = 0;
2334+
build "oldconfig";
2335+
start_monitor_and_boot or $failed = 1;
2336+
end_monitor;
2337+
2338+
$in_bisect = 0;
2339+
2340+
if ($failed) {
2341+
doprint "$config is needed to boot the box... keeping\n";
2342+
# this config is needed, add it to the ignore list.
2343+
$keep_configs{$config} = $min_configs{$config};
2344+
delete $min_configs{$config};
2345+
} else {
2346+
# We booted without this config, remove it from the minconfigs.
2347+
doprint "$config is not needed, disabling\n";
2348+
2349+
delete $min_configs{$config};
2350+
2351+
# Also disable anything that is not enabled in this config
2352+
my %configs;
2353+
assign_configs \%configs, $output_config;
2354+
my @config_keys = keys %min_configs;
2355+
foreach my $config (@config_keys) {
2356+
if (!defined($configs{$config})) {
2357+
doprint "$config is not set, disabling\n";
2358+
delete $min_configs{$config};
2359+
}
2360+
}
2361+
2362+
# Save off all the current mandidory configs
2363+
open (OUT, ">$output_minconfig")
2364+
or die "Can't write to $output_minconfig";
2365+
foreach my $config (keys %keep_configs) {
2366+
print OUT "$keep_configs{$config}\n";
2367+
}
2368+
foreach my $config (keys %min_configs) {
2369+
print OUT "$min_configs{$config}\n";
2370+
}
2371+
close OUT;
2372+
}
2373+
2374+
doprint "Reboot and wait $sleep_time seconds\n";
2375+
reboot;
2376+
start_monitor;
2377+
wait_for_monitor $sleep_time;
2378+
end_monitor;
2379+
}
2380+
2381+
success $i;
2382+
return 1;
2383+
}
2384+
21522385
$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
21532386

21542387
if ($#ARGV == 0) {
@@ -2294,6 +2527,9 @@ sub set_test_option {
22942527
$reboot = set_test_option("REBOOT", $i);
22952528
$noclean = set_test_option("BUILD_NOCLEAN", $i);
22962529
$minconfig = set_test_option("MIN_CONFIG", $i);
2530+
$output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
2531+
$start_minconfig = set_test_option("START_MIN_CONFIG", $i);
2532+
$ignore_config = set_test_option("IGNORE_CONFIG", $i);
22972533
$run_test = set_test_option("TEST", $i);
22982534
$addconfig = set_test_option("ADD_CONFIG", $i);
22992535
$reboot_type = set_test_option("REBOOT_TYPE", $i);
@@ -2329,6 +2565,10 @@ sub set_test_option {
23292565
$target_image = set_test_option("TARGET_IMAGE", $i);
23302566
$localversion = set_test_option("LOCALVERSION", $i);
23312567

2568+
if (!defined($start_minconfig)) {
2569+
$start_minconfig = $minconfig;
2570+
}
2571+
23322572
chdir $builddir || die "can't change directory to $builddir";
23332573

23342574
if (!-d $tmpdir) {
@@ -2361,6 +2601,10 @@ sub set_test_option {
23612601
$run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
23622602
}
23632603

2604+
if ($test_type eq "make_min_config") {
2605+
$run_type = "";
2606+
}
2607+
23642608
# mistake in config file?
23652609
if (!defined($run_type)) {
23662610
$run_type = "ERROR";
@@ -2396,6 +2640,9 @@ sub set_test_option {
23962640
} elsif ($test_type eq "patchcheck") {
23972641
patchcheck $i;
23982642
next;
2643+
} elsif ($test_type eq "make_min_config") {
2644+
make_min_config $i;
2645+
next;
23992646
}
24002647

24012648
if ($build_type ne "nobuild") {

‎tools/testing/ktest/sample.conf‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,53 @@
814814
# MIN_CONFIG = /home/test/config-min
815815
# BISECT_MANUAL = 1
816816
#
817+
#
818+
#
819+
# For TEST_TYPE = make_min_config
820+
#
821+
# After doing a make localyesconfig, your kernel configuration may
822+
# not be the most useful minimum configuration. Having a true minimum
823+
# config that you can use against other configs is very useful if
824+
# someone else has a config that breaks on your code. By only forcing
825+
# those configurations that are truly required to boot your machine
826+
# will give you less of a chance that one of your set configurations
827+
# will make the bug go away. This will give you a better chance to
828+
# be able to reproduce the reported bug matching the broken config.
829+
#
830+
# Note, this does take some time, and may require you to run the
831+
# test over night, or perhaps over the weekend. But it also allows
832+
# you to interrupt it, and gives you the current minimum config
833+
# that was found till that time.
834+
#
835+
# Note, this test automatically assumes a BUILD_TYPE of oldconfig
836+
# and its test type acts like boot.
837+
# TODO: add a test version that makes the config do more than just
838+
# boot, like having network access.
839+
#
840+
# OUTPUT_MIN_CONFIG is the path and filename of the file that will
841+
# be created from the MIN_CONFIG. If you interrupt the test, set
842+
# this file as your new min config, and use it to continue the test.
843+
# This file does not need to exist on start of test.
844+
# This file is not created until a config is found that can be removed.
845+
# (required field)
846+
#
847+
# START_MIN_CONFIG is the config to use to start the test with.
848+
# you can set this as the same OUTPUT_MIN_CONFIG, but if you do
849+
# the OUTPUT_MIN_CONFIG file must exist.
850+
# (default MIN_CONFIG)
851+
#
852+
# IGNORE_CONFIG is used to specify a config file that has configs that
853+
# you already know must be set. Configs are written here that have
854+
# been tested and proved to be required. It is best to define this
855+
# file if you intend on interrupting the test and running it where
856+
# it left off. New configs that it finds will be written to this file
857+
# and will not be tested again in later runs.
858+
# (optional)
859+
#
860+
# Example:
861+
#
862+
# TEST_TYPE = make_min_config
863+
# OUTPUT_MIN_CONFIG = /path/to/config-new-min
864+
# START_MIN_CONFIG = /path/to/config-min
865+
# IGNORE_CONFIG = /path/to/config-tested
866+
#

0 commit comments

Comments
 (0)