Skip to content

Commit 9451ee2

Browse files
committed
Merge tag 'ktest-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest
Pull ktest updates from Steven Rostedt: "Here's some basic updates to ktest.pl. They include: - add config to modify the signal to terminate console - update to documentation (missing some config options) - add KERNEL_VERSION variable to use for other configs - add '=~' to let configs eval other configs - add BISECT_TRIES to run multiple tests per git bisect good" * tag 'ktest-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest: ktest: Add BISECT_TRIES to bisect test ktest: Add eval '=~' command to modify variables in config file ktest: Add special variable ${KERNEL_VERSION} ktest: Add documentation of CLOSE_CONSOLE_SIGNAL ktest: Make the signal to terminate the console configurable
2 parents edde1fb + 961d9ca commit 9451ee2

File tree

2 files changed

+147
-32
lines changed

2 files changed

+147
-32
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 126 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
my %opt;
1919
my %repeat_tests;
2020
my %repeats;
21+
my %evals;
2122

2223
#default opts
2324
my %default = (
2425
"NUM_TESTS" => 1,
2526
"TEST_TYPE" => "build",
2627
"BUILD_TYPE" => "randconfig",
2728
"MAKE_CMD" => "make",
29+
"CLOSE_CONSOLE_SIGNAL" => "INT",
2830
"TIMEOUT" => 120,
2931
"TMP_DIR" => "/tmp/ktest/\${MACHINE}",
3032
"SLEEP_TIME" => 60, # sleep time between tests
@@ -39,6 +41,7 @@
3941
"CLEAR_LOG" => 0,
4042
"BISECT_MANUAL" => 0,
4143
"BISECT_SKIP" => 1,
44+
"BISECT_TRIES" => 1,
4245
"MIN_CONFIG_TYPE" => "boot",
4346
"SUCCESS_LINE" => "login:",
4447
"DETECT_TRIPLE_FAULT" => 1,
@@ -137,6 +140,7 @@
137140
my $reverse_bisect;
138141
my $bisect_manual;
139142
my $bisect_skip;
143+
my $bisect_tries;
140144
my $config_bisect_good;
141145
my $bisect_ret_good;
142146
my $bisect_ret_bad;
@@ -163,6 +167,7 @@
163167
my $booted_timeout;
164168
my $detect_triplefault;
165169
my $console;
170+
my $close_console_signal;
166171
my $reboot_success_line;
167172
my $success_line;
168173
my $stop_after_success;
@@ -273,6 +278,7 @@
273278
"IGNORE_ERRORS" => \$ignore_errors,
274279
"BISECT_MANUAL" => \$bisect_manual,
275280
"BISECT_SKIP" => \$bisect_skip,
281+
"BISECT_TRIES" => \$bisect_tries,
276282
"CONFIG_BISECT_GOOD" => \$config_bisect_good,
277283
"BISECT_RET_GOOD" => \$bisect_ret_good,
278284
"BISECT_RET_BAD" => \$bisect_ret_bad,
@@ -285,6 +291,7 @@
285291
"TIMEOUT" => \$timeout,
286292
"BOOTED_TIMEOUT" => \$booted_timeout,
287293
"CONSOLE" => \$console,
294+
"CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
288295
"DETECT_TRIPLE_FAULT" => \$detect_triplefault,
289296
"SUCCESS_LINE" => \$success_line,
290297
"REBOOT_SUCCESS_LINE" => \$reboot_success_line,
@@ -445,6 +452,27 @@
445452
EOF
446453
;
447454

455+
sub _logit {
456+
if (defined($opt{"LOG_FILE"})) {
457+
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
458+
print OUT @_;
459+
close(OUT);
460+
}
461+
}
462+
463+
sub logit {
464+
if (defined($opt{"LOG_FILE"})) {
465+
_logit @_;
466+
} else {
467+
print @_;
468+
}
469+
}
470+
471+
sub doprint {
472+
print @_;
473+
_logit @_;
474+
}
475+
448476
sub read_prompt {
449477
my ($cancel, $prompt) = @_;
450478

@@ -662,6 +690,22 @@ sub set_value {
662690
}
663691
}
664692

693+
sub set_eval {
694+
my ($lvalue, $rvalue, $name) = @_;
695+
696+
my $prvalue = process_variables($rvalue);
697+
my $arr;
698+
699+
if (defined($evals{$lvalue})) {
700+
$arr = $evals{$lvalue};
701+
} else {
702+
$arr = [];
703+
$evals{$lvalue} = $arr;
704+
}
705+
706+
push @{$arr}, $rvalue;
707+
}
708+
665709
sub set_variable {
666710
my ($lvalue, $rvalue) = @_;
667711

@@ -947,6 +991,20 @@ sub __read_config {
947991
$test_case = 1;
948992
}
949993

994+
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
995+
996+
next if ($skip);
997+
998+
my $lvalue = $1;
999+
my $rvalue = $2;
1000+
1001+
if ($default || $lvalue =~ /\[\d+\]$/) {
1002+
set_eval($lvalue, $rvalue, $name);
1003+
} else {
1004+
my $val = "$lvalue\[$test_num\]";
1005+
set_eval($val, $rvalue, $name);
1006+
}
1007+
9501008
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
9511009

9521010
next if ($skip);
@@ -1126,6 +1184,10 @@ sub __eval_option {
11261184
} elsif (defined($opt{$var})) {
11271185
$o = $opt{$var};
11281186
$retval = "$retval$o";
1187+
} elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1188+
# special option KERNEL_VERSION uses kernel version
1189+
get_version();
1190+
$retval = "$retval$version";
11291191
} else {
11301192
$retval = "$retval\$\{$var\}";
11311193
}
@@ -1140,6 +1202,33 @@ sub __eval_option {
11401202
return $retval;
11411203
}
11421204

1205+
sub process_evals {
1206+
my ($name, $option, $i) = @_;
1207+
1208+
my $option_name = "$name\[$i\]";
1209+
my $ev;
1210+
1211+
my $old_option = $option;
1212+
1213+
if (defined($evals{$option_name})) {
1214+
$ev = $evals{$option_name};
1215+
} elsif (defined($evals{$name})) {
1216+
$ev = $evals{$name};
1217+
} else {
1218+
return $option;
1219+
}
1220+
1221+
for my $e (@{$ev}) {
1222+
eval "\$option =~ $e";
1223+
}
1224+
1225+
if ($option ne $old_option) {
1226+
doprint("$name changed from '$old_option' to '$option'\n");
1227+
}
1228+
1229+
return $option;
1230+
}
1231+
11431232
sub eval_option {
11441233
my ($name, $option, $i) = @_;
11451234

@@ -1160,28 +1249,9 @@ sub eval_option {
11601249
$option = __eval_option($name, $option, $i);
11611250
}
11621251

1163-
return $option;
1164-
}
1252+
$option = process_evals($name, $option, $i);
11651253

1166-
sub _logit {
1167-
if (defined($opt{"LOG_FILE"})) {
1168-
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1169-
print OUT @_;
1170-
close(OUT);
1171-
}
1172-
}
1173-
1174-
sub logit {
1175-
if (defined($opt{"LOG_FILE"})) {
1176-
_logit @_;
1177-
} else {
1178-
print @_;
1179-
}
1180-
}
1181-
1182-
sub doprint {
1183-
print @_;
1184-
_logit @_;
1254+
return $option;
11851255
}
11861256

11871257
sub run_command;
@@ -1296,7 +1366,7 @@ sub close_console {
12961366
my ($fp, $pid) = @_;
12971367

12981368
doprint "kill child process $pid\n";
1299-
kill 2, $pid;
1369+
kill $close_console_signal, $pid;
13001370

13011371
print "closing!\n";
13021372
close($fp);
@@ -2517,12 +2587,29 @@ sub run_bisect {
25172587
$buildtype = "useconfig:$minconfig";
25182588
}
25192589

2520-
my $ret = run_bisect_test $type, $buildtype;
2590+
# If the user sets bisect_tries to less than 1, then no tries
2591+
# is a success.
2592+
my $ret = 1;
25212593

2522-
if ($bisect_manual) {
2594+
# Still let the user manually decide that though.
2595+
if ($bisect_tries < 1 && $bisect_manual) {
25232596
$ret = answer_bisect;
25242597
}
25252598

2599+
for (my $i = 0; $i < $bisect_tries; $i++) {
2600+
if ($bisect_tries > 1) {
2601+
my $t = $i + 1;
2602+
doprint("Running bisect trial $t of $bisect_tries:\n");
2603+
}
2604+
$ret = run_bisect_test $type, $buildtype;
2605+
2606+
if ($bisect_manual) {
2607+
$ret = answer_bisect;
2608+
}
2609+
2610+
last if (!$ret);
2611+
}
2612+
25262613
# Are we looking for where it worked, not failed?
25272614
if ($reverse_bisect && $ret >= 0) {
25282615
$ret = !$ret;
@@ -3916,6 +4003,18 @@ sub set_test_option {
39164003

39174004
my $makecmd = set_test_option("MAKE_CMD", $i);
39184005

4006+
$outputdir = set_test_option("OUTPUT_DIR", $i);
4007+
$builddir = set_test_option("BUILD_DIR", $i);
4008+
4009+
chdir $builddir || die "can't change directory to $builddir";
4010+
4011+
if (!-d $outputdir) {
4012+
mkpath($outputdir) or
4013+
die "can't create $outputdir";
4014+
}
4015+
4016+
$make = "$makecmd O=$outputdir";
4017+
39194018
# Load all the options into their mapped variable names
39204019
foreach my $opt (keys %option_map) {
39214020
${$option_map{$opt}} = set_test_option($opt, $i);
@@ -3940,13 +4039,9 @@ sub set_test_option {
39404039
$start_minconfig = $minconfig;
39414040
}
39424041

3943-
chdir $builddir || die "can't change directory to $builddir";
3944-
3945-
foreach my $dir ($tmpdir, $outputdir) {
3946-
if (!-d $dir) {
3947-
mkpath($dir) or
3948-
die "can't create $dir";
3949-
}
4042+
if (!-d $tmpdir) {
4043+
mkpath($tmpdir) or
4044+
die "can't create $tmpdir";
39504045
}
39514046

39524047
$ENV{"SSH_USER"} = $ssh_user;
@@ -3955,7 +4050,6 @@ sub set_test_option {
39554050
$buildlog = "$tmpdir/buildlog-$machine";
39564051
$testlog = "$tmpdir/testlog-$machine";
39574052
$dmesg = "$tmpdir/dmesg-$machine";
3958-
$make = "$makecmd O=$outputdir";
39594053
$output_config = "$outputdir/.config";
39604054

39614055
if (!$buildonly) {

tools/testing/ktest/sample.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@
328328
# For a virtual machine with guest name "Guest".
329329
#CONSOLE = virsh console Guest
330330

331+
# Signal to send to kill console.
332+
# ktest.pl will create a child process to monitor the console.
333+
# When the console is finished, ktest will kill the child process
334+
# with this signal.
335+
# (default INT)
336+
#CLOSE_CONSOLE_SIGNAL = HUP
337+
331338
# Required version ending to differentiate the test
332339
# from other linux builds on the system.
333340
#LOCALVERSION = -test
@@ -1021,6 +1028,20 @@
10211028
# BISECT_BAD with BISECT_CHECK = good or
10221029
# BISECT_CHECK = bad, respectively.
10231030
#
1031+
# BISECT_TRIES = 5 (optional, default 1)
1032+
#
1033+
# For those cases that it takes several tries to hit a bug,
1034+
# the BISECT_TRIES is useful. It is the number of times the
1035+
# test is ran before it says the kernel is good. The first failure
1036+
# will stop trying and mark the current SHA1 as bad.
1037+
#
1038+
# Note, as with all race bugs, there's no guarantee that if
1039+
# it succeeds, it is really a good bisect. But it helps in case
1040+
# the bug is some what reliable.
1041+
#
1042+
# You can set BISECT_TRIES to zero, and all tests will be considered
1043+
# good, unless you also set BISECT_MANUAL.
1044+
#
10241045
# BISECT_RET_GOOD = 0 (optional, default undefined)
10251046
#
10261047
# In case the specificed test returns something other than just

0 commit comments

Comments
 (0)