ktest.pl (c043ccbfc6d83fa21512f842c5d2ba4060cee5fe) ktest.pl (6a0f3652952c7bba83af66c115a311d4a2164ebb)
1#!/usr/bin/perl -w
2# SPDX-License-Identifier: GPL-2.0-only
3#
4# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
5#
6
7use strict;
8use IPC::Open2;

--- 498 unchanged lines hidden (view full) ---

507EOF
508 ;
509$config_help{"REBOOT_SCRIPT"} = << "EOF"
510 A script to reboot the target into the test kernel
511 (Only mandatory if REBOOT_TYPE = script)
512EOF
513 ;
514
1#!/usr/bin/perl -w
2# SPDX-License-Identifier: GPL-2.0-only
3#
4# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
5#
6
7use strict;
8use IPC::Open2;

--- 498 unchanged lines hidden (view full) ---

507EOF
508 ;
509$config_help{"REBOOT_SCRIPT"} = << "EOF"
510 A script to reboot the target into the test kernel
511 (Only mandatory if REBOOT_TYPE = script)
512EOF
513 ;
514
515# used with process_expression()
516my $d = 0;
517
518# defined before get_test_name()
519my $in_die = 0;
520
521# defined before process_warning_line()
522my $check_build_re = ".*:.*(warning|error|Error):.*";
523my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
524
525# defined before child_finished()
526my $child_done;
527
528# config_ignore holds the configs that were set (or unset) for
529# a good config and we will ignore these configs for the rest
530# of a config bisect. These configs stay as they were.
531my %config_ignore;
532
533# config_set holds what all configs were set as.
534my %config_set;
535
536# config_off holds the set of configs that the bad config had disabled.
537# We need to record them and set them in the .config when running
538# olddefconfig, because olddefconfig keeps the defaults.
539my %config_off;
540
541# config_off_tmp holds a set of configs to turn off for now
542my @config_off_tmp;
543
544# config_list is the set of configs that are being tested
545my %config_list;
546my %null_config;
547
548my %dependency;
549
550# found above run_config_bisect()
551my $pass = 1;
552
553# found above add_dep()
554
555my %depends;
556my %depcount;
557my $iflevel = 0;
558my @ifdeps;
559
560# prevent recursion
561my %read_kconfigs;
562
563# found above test_this_config()
564my %min_configs;
565my %keep_configs;
566my %save_configs;
567my %processed_configs;
568my %nochange_config;
569
570#
571# These are first defined here, main function later on
572#
573sub run_command;
574sub start_monitor;
575sub end_monitor;
576sub wait_for_monitor;
577
515sub _logit {
516 if (defined($opt{"LOG_FILE"})) {
517 print LOG @_;
518 }
519}
520
521sub logit {
522 if (defined($opt{"LOG_FILE"})) {

--- 837 unchanged lines hidden (view full) ---

1360 $option = __eval_option($name, $option, $i);
1361 }
1362
1363 $option = process_evals($name, $option, $i);
1364
1365 return $option;
1366}
1367
578sub _logit {
579 if (defined($opt{"LOG_FILE"})) {
580 print LOG @_;
581 }
582}
583
584sub logit {
585 if (defined($opt{"LOG_FILE"})) {

--- 837 unchanged lines hidden (view full) ---

1423 $option = __eval_option($name, $option, $i);
1424 }
1425
1426 $option = process_evals($name, $option, $i);
1427
1428 return $option;
1429}
1430
1368sub run_command;
1369sub start_monitor;
1370sub end_monitor;
1371sub wait_for_monitor;
1372
1373sub reboot {
1374 my ($time) = @_;
1375 my $powercycle = 0;
1376
1377 # test if the machine can be connected to within a few seconds
1378 my $stat = run_ssh("echo check machine status", $connect_timeout);
1379 if (!$stat) {
1380 doprint("power cycle\n");

--- 68 unchanged lines hidden (view full) ---

1449 my $i = $iteration;
1450
1451 return $test_type eq "build" || $no_reboot ||
1452 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1453 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build") ||
1454 ($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq "build");
1455}
1456
1431sub reboot {
1432 my ($time) = @_;
1433 my $powercycle = 0;
1434
1435 # test if the machine can be connected to within a few seconds
1436 my $stat = run_ssh("echo check machine status", $connect_timeout);
1437 if (!$stat) {
1438 doprint("power cycle\n");

--- 68 unchanged lines hidden (view full) ---

1507 my $i = $iteration;
1508
1509 return $test_type eq "build" || $no_reboot ||
1510 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1511 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build") ||
1512 ($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq "build");
1513}
1514
1457my $in_die = 0;
1458
1459sub get_test_name() {
1460 my $name;
1461
1462 if (defined($test_name)) {
1463 $name = "$test_name:$test_type";
1464 } else {
1465 $name = $test_type;
1466 }

--- 870 unchanged lines hidden (view full) ---

2337 get_grub_index;
2338 get_version;
2339 install;
2340
2341 start_monitor if (defined $console);
2342 return monitor;
2343}
2344
1515sub get_test_name() {
1516 my $name;
1517
1518 if (defined($test_name)) {
1519 $name = "$test_name:$test_type";
1520 } else {
1521 $name = $test_type;
1522 }

--- 870 unchanged lines hidden (view full) ---

2393 get_grub_index;
2394 get_version;
2395 install;
2396
2397 start_monitor if (defined $console);
2398 return monitor;
2399}
2400
2345my $check_build_re = ".*:.*(warning|error|Error):.*";
2346my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2347
2348sub process_warning_line {
2349 my ($line) = @_;
2350
2351 chomp $line;
2352
2353 # for distcc heterogeneous systems, some compilers
2354 # do things differently causing warning lines
2355 # to be slightly different. This makes an attempt

--- 333 unchanged lines hidden (view full) ---

2689 $poweroff_on_error = 0;
2690 $die_on_failure = 1;
2691
2692 run_command $run_test, $testlog;
2693
2694 exit $run_command_status;
2695}
2696
2401sub process_warning_line {
2402 my ($line) = @_;
2403
2404 chomp $line;
2405
2406 # for distcc heterogeneous systems, some compilers
2407 # do things differently causing warning lines
2408 # to be slightly different. This makes an attempt

--- 333 unchanged lines hidden (view full) ---

2742 $poweroff_on_error = 0;
2743 $die_on_failure = 1;
2744
2745 run_command $run_test, $testlog;
2746
2747 exit $run_command_status;
2748}
2749
2697my $child_done;
2698
2699sub child_finished {
2700 $child_done = 1;
2701}
2702
2703sub do_run_test {
2704 my $child_pid;
2705 my $child_exit;
2706 my $line;

--- 384 unchanged lines hidden (view full) ---

3091 run_command "git bisect reset" or
3092 dodie "could not reset git bisect";
3093
3094 doprint "Bad commit was [$bisect_bad_commit]\n";
3095
3096 success $i;
3097}
3098
2750sub child_finished {
2751 $child_done = 1;
2752}
2753
2754sub do_run_test {
2755 my $child_pid;
2756 my $child_exit;
2757 my $line;

--- 384 unchanged lines hidden (view full) ---

3142 run_command "git bisect reset" or
3143 dodie "could not reset git bisect";
3144
3145 doprint "Bad commit was [$bisect_bad_commit]\n";
3146
3147 success $i;
3148}
3149
3099# config_ignore holds the configs that were set (or unset) for
3100# a good config and we will ignore these configs for the rest
3101# of a config bisect. These configs stay as they were.
3102my %config_ignore;
3103
3104# config_set holds what all configs were set as.
3105my %config_set;
3106
3107# config_off holds the set of configs that the bad config had disabled.
3108# We need to record them and set them in the .config when running
3109# olddefconfig, because olddefconfig keeps the defaults.
3110my %config_off;
3111
3112# config_off_tmp holds a set of configs to turn off for now
3113my @config_off_tmp;
3114
3115# config_list is the set of configs that are being tested
3116my %config_list;
3117my %null_config;
3118
3119my %dependency;
3120
3121sub assign_configs {
3122 my ($hash, $config) = @_;
3123
3124 doprint "Reading configs from $config\n";
3125
3126 open (IN, $config) or
3127 dodie "Failed to read $config";
3128

--- 78 unchanged lines hidden (view full) ---

3207 $diffexec = "$builddir/scripts/diffconfig";
3208 }
3209 doprint "\n\n***************************************\n";
3210 doprint "No more config bisecting possible.\n";
3211 run_command "$diffexec $good $bad", 1;
3212 doprint "***************************************\n\n";
3213}
3214
3150sub assign_configs {
3151 my ($hash, $config) = @_;
3152
3153 doprint "Reading configs from $config\n";
3154
3155 open (IN, $config) or
3156 dodie "Failed to read $config";
3157

--- 78 unchanged lines hidden (view full) ---

3236 $diffexec = "$builddir/scripts/diffconfig";
3237 }
3238 doprint "\n\n***************************************\n";
3239 doprint "No more config bisecting possible.\n";
3240 run_command "$diffexec $good $bad", 1;
3241 doprint "***************************************\n\n";
3242}
3243
3215my $pass = 1;
3216
3217sub run_config_bisect {
3218 my ($good, $bad, $last_result) = @_;
3219 my $reset = "";
3220 my $cmd;
3221 my $ret;
3222
3223 if (!length($last_result)) {
3224 $reset = "-r";

--- 275 unchanged lines hidden (view full) ---

3500 print_times;
3501 }
3502 $in_patchcheck = 0;
3503 success $i;
3504
3505 return 1;
3506}
3507
3244sub run_config_bisect {
3245 my ($good, $bad, $last_result) = @_;
3246 my $reset = "";
3247 my $cmd;
3248 my $ret;
3249
3250 if (!length($last_result)) {
3251 $reset = "-r";

--- 275 unchanged lines hidden (view full) ---

3527 print_times;
3528 }
3529 $in_patchcheck = 0;
3530 success $i;
3531
3532 return 1;
3533}
3534
3508my %depends;
3509my %depcount;
3510my $iflevel = 0;
3511my @ifdeps;
3512
3513# prevent recursion
3514my %read_kconfigs;
3515
3516sub add_dep {
3517 # $config depends on $dep
3518 my ($config, $dep) = @_;
3519
3520 if (defined($depends{$config})) {
3521 $depends{$config} .= " " . $dep;
3522 } else {
3523 $depends{$config} = $dep;

--- 184 unchanged lines hidden (view full) ---

3708 } else {
3709 dodie "this should never happen";
3710 }
3711 }
3712
3713 return @configs;
3714}
3715
3535sub add_dep {
3536 # $config depends on $dep
3537 my ($config, $dep) = @_;
3538
3539 if (defined($depends{$config})) {
3540 $depends{$config} .= " " . $dep;
3541 } else {
3542 $depends{$config} = $dep;

--- 184 unchanged lines hidden (view full) ---

3727 } else {
3728 dodie "this should never happen";
3729 }
3730 }
3731
3732 return @configs;
3733}
3734
3716my %min_configs;
3717my %keep_configs;
3718my %save_configs;
3719my %processed_configs;
3720my %nochange_config;
3721
3722sub test_this_config {
3723 my ($config) = @_;
3724
3725 my $found;
3726
3727 # if we already processed this config, skip it
3728 if (defined($processed_configs{$config})) {
3729 return undef;

--- 312 unchanged lines hidden (view full) ---

4042 }
4043 close(IN);
4044
4045 close(OUT);
4046
4047 success $i;
4048}
4049
3735sub test_this_config {
3736 my ($config) = @_;
3737
3738 my $found;
3739
3740 # if we already processed this config, skip it
3741 if (defined($processed_configs{$config})) {
3742 return undef;

--- 312 unchanged lines hidden (view full) ---

4055 }
4056 close(IN);
4057
4058 close(OUT);
4059
4060 success $i;
4061}
4062
4050$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
4051
4052if ($#ARGV == 0) {
4053 $ktest_config = $ARGV[0];
4054 if (! -f $ktest_config) {
4055 print "$ktest_config does not exist.\n";
4056 if (!read_yn "Create it?") {
4057 exit 0;
4058 }
4059 }
4060}
4061
4062if (! -f $ktest_config) {
4063 $newconfig = 1;
4064 get_test_case;
4065 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
4066 print OUT << "EOF"
4067# Generated by ktest.pl
4068#
4069
4070# PWD is a ktest.pl variable that will result in the process working
4071# directory that ktest.pl is executed in.
4072
4073# THIS_DIR is automatically assigned the PWD of the path that generated
4074# the config file. It is best to use this variable when assigning other
4075# directory paths within this directory. This allows you to easily
4076# move the test cases to other locations or to other machines.
4077#
4078THIS_DIR := $variable{"PWD"}
4079
4080# Define each test with TEST_START
4081# The config options below it will override the defaults
4082TEST_START
4083TEST_TYPE = $default{"TEST_TYPE"}
4084
4085DEFAULTS
4086EOF
4087;
4088 close(OUT);
4089}
4090read_config $ktest_config;
4091
4092if (defined($opt{"LOG_FILE"})) {
4093 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
4094}
4095
4096# Append any configs entered in manually to the config file.
4097my @new_configs = keys %entered_configs;
4098if ($#new_configs >= 0) {
4099 print "\nAppending entered in configs to $ktest_config\n";
4100 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
4101 foreach my $config (@new_configs) {
4102 print OUT "$config = $entered_configs{$config}\n";
4103 $opt{$config} = process_variables($entered_configs{$config});
4104 }
4105}
4106
4107if (defined($opt{"LOG_FILE"})) {
4108 if ($opt{"CLEAR_LOG"}) {
4109 unlink $opt{"LOG_FILE"};
4110 }
4111 open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
4112 LOG->autoflush(1);
4113}
4114
4115doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
4116
4117for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4118
4119 if (!$i) {
4120 doprint "DEFAULT OPTIONS:\n";
4121 } else {
4122 doprint "\nTEST $i OPTIONS";
4123 if (defined($repeat_tests{$i})) {
4124 $repeat = $repeat_tests{$i};
4125 doprint " ITERATE $repeat";
4126 }
4127 doprint "\n";
4128 }
4129
4130 foreach my $option (sort keys %opt) {
4131
4132 if ($option =~ /\[(\d+)\]$/) {
4133 next if ($i != $1);
4134 } else {
4135 next if ($i);
4136 }
4137
4138 doprint "$option = $opt{$option}\n";
4139 }
4140}
4141
4142sub option_defined {
4143 my ($option) = @_;
4144
4145 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
4146 return 1;
4147 }
4148
4149 return 0;

--- 114 unchanged lines hidden (view full) ---

4264 if ($email_when_canceled) {
4265 my $name = get_test_name;
4266 send_email("KTEST: Your [$name] test was cancelled",
4267 "Your test started at $script_start_time was cancelled: sig int");
4268 }
4269 die "\nCaught Sig Int, test interrupted: $!\n"
4270}
4271
4063sub option_defined {
4064 my ($option) = @_;
4065
4066 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
4067 return 1;
4068 }
4069
4070 return 0;

--- 114 unchanged lines hidden (view full) ---

4185 if ($email_when_canceled) {
4186 my $name = get_test_name;
4187 send_email("KTEST: Your [$name] test was cancelled",
4188 "Your test started at $script_start_time was cancelled: sig int");
4189 }
4190 die "\nCaught Sig Int, test interrupted: $!\n"
4191}
4192
4193$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
4194
4195if ($#ARGV == 0) {
4196 $ktest_config = $ARGV[0];
4197 if (! -f $ktest_config) {
4198 print "$ktest_config does not exist.\n";
4199 if (!read_yn "Create it?") {
4200 exit 0;
4201 }
4202 }
4203}
4204
4205if (! -f $ktest_config) {
4206 $newconfig = 1;
4207 get_test_case;
4208 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
4209 print OUT << "EOF"
4210# Generated by ktest.pl
4211#
4212
4213# PWD is a ktest.pl variable that will result in the process working
4214# directory that ktest.pl is executed in.
4215
4216# THIS_DIR is automatically assigned the PWD of the path that generated
4217# the config file. It is best to use this variable when assigning other
4218# directory paths within this directory. This allows you to easily
4219# move the test cases to other locations or to other machines.
4220#
4221THIS_DIR := $variable{"PWD"}
4222
4223# Define each test with TEST_START
4224# The config options below it will override the defaults
4225TEST_START
4226TEST_TYPE = $default{"TEST_TYPE"}
4227
4228DEFAULTS
4229EOF
4230;
4231 close(OUT);
4232}
4233read_config $ktest_config;
4234
4235if (defined($opt{"LOG_FILE"})) {
4236 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
4237}
4238
4239# Append any configs entered in manually to the config file.
4240my @new_configs = keys %entered_configs;
4241if ($#new_configs >= 0) {
4242 print "\nAppending entered in configs to $ktest_config\n";
4243 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
4244 foreach my $config (@new_configs) {
4245 print OUT "$config = $entered_configs{$config}\n";
4246 $opt{$config} = process_variables($entered_configs{$config});
4247 }
4248}
4249
4250if (defined($opt{"LOG_FILE"})) {
4251 if ($opt{"CLEAR_LOG"}) {
4252 unlink $opt{"LOG_FILE"};
4253 }
4254 open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
4255 LOG->autoflush(1);
4256}
4257
4258doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
4259
4260for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4261
4262 if (!$i) {
4263 doprint "DEFAULT OPTIONS:\n";
4264 } else {
4265 doprint "\nTEST $i OPTIONS";
4266 if (defined($repeat_tests{$i})) {
4267 $repeat = $repeat_tests{$i};
4268 doprint " ITERATE $repeat";
4269 }
4270 doprint "\n";
4271 }
4272
4273 foreach my $option (sort keys %opt) {
4274 if ($option =~ /\[(\d+)\]$/) {
4275 next if ($i != $1);
4276 } else {
4277 next if ($i);
4278 }
4279
4280 doprint "$option = $opt{$option}\n";
4281 }
4282}
4283
4272$SIG{INT} = qw(cancel_test);
4273
4274# First we need to do is the builds
4275for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
4276
4277 # Do not reboot on failing test options
4278 $no_reboot = 1;
4279 $reboot_success = 0;

--- 237 unchanged lines hidden ---
4284$SIG{INT} = qw(cancel_test);
4285
4286# First we need to do is the builds
4287for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
4288
4289 # Do not reboot on failing test options
4290 $no_reboot = 1;
4291 $reboot_success = 0;

--- 237 unchanged lines hidden ---