Received: by 10.223.164.202 with SMTP id h10csp5514340wrb; Tue, 21 Nov 2017 10:54:39 -0800 (PST) X-Google-Smtp-Source: AGs4zMb7em5oYCdSUfDqPRE+F3fJ+JhyEqG5brqpbPqKJjWoXgRilxqMW+3m768ysxzzeU8Ro/Ft X-Received: by 10.101.76.139 with SMTP id m11mr18377316pgt.103.1511290479669; Tue, 21 Nov 2017 10:54:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511290479; cv=none; d=google.com; s=arc-20160816; b=iZ6y9yHUCxA5cjrzgNA/Urfcwkc7Hci1MilSFJB5AHZt5X93ApTuL12SaWoouB+zo4 R0XLh4rqPEWHbpWnNswuQXi/eHXuUAB/M3M5pBnSgfzjsFEgwxhXcgXLntFqA14E35ZP NRCaW3NVos15melm42+pg/bBpzEqOl85DAxnQ7v5PnCcIwK/0o6vdsZ8gb+icWqdfrr0 hNQQWfRWWGrCq/eC0/2pUaVGF9lsoyvutAzQV1jOfAWkMjyTb42ICl5/O3oNny5ygLxj LYWgwsyQCHzFlbvAV5bc7liQgGWjvVYV56Bp2ZgBsPvCI4cEvDzwXu4N9ZUOJ2OnqMRi QOGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:references:subject:arc-authentication-results; bh=NI4zKbgAT3WnI/laJfZpkoIFcJ/faQhPyw+Pf52ncIY=; b=nSjTxxCSLx1mUDfbgjx3fqhokAOOi3FjhHKfagwQNErbTOhJyPkxFSkRdN2ZV6zSqC avdKVhHatjkZ8QDvr7uKZaVKQ64/BptyQeOtR4jwAyhp4LQPnZK/icP+qxPSsfludct4 rIBUg+XjvLfqHdCBWHiN8yTnsqwY1sVtAjThoroxBP1PIL45dm2c1xp1HNrdfEkK9xSs HJo80ZcTYlexIl4RU23ODhPHrnPZmTPCTWy7WLT3FPx+Y08A0ydZ1j4CVeCbdJhYvj/b DwQPKWGWEy7AW2FhdnNdtZ4gSDm50xCfVDK8x7e/wcyNGOkjSslBxD5pwDK1yPuZAyuF SrXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si12852021pfj.342.2017.11.21.10.54.28; Tue, 21 Nov 2017 10:54:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751425AbdKUSxq (ORCPT + 76 others); Tue, 21 Nov 2017 13:53:46 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:48670 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750772AbdKUSxl (ORCPT ); Tue, 21 Nov 2017 13:53:41 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vALIrbpf021898 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Nov 2017 18:53:38 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vALIrbdX025638 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Nov 2017 18:53:37 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vALIrbaO023528; Tue, 21 Nov 2017 18:53:37 GMT Received: from [10.1.10.119] (/173.161.222.85) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 21 Nov 2017 10:53:37 -0800 Subject: [PATCH 2/2][RFC]Ktest: Use dodie for critial failures References: <20171120173738.34823-3-tianyang.chen@oracle.com> To: rostedt@goodmis.org, linux-kernel@vger.kernel.org Cc: dhaval.giani@oracle.com From: Tim Tianyang Chen X-Forwarded-Message-Id: <20171120173738.34823-3-tianyang.chen@oracle.com> Message-ID: Date: Tue, 21 Nov 2017 10:53:35 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20171120173738.34823-3-tianyang.chen@oracle.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Users should get emails when the script dies because of a critical failure. Critical failures are defined as any errors that could terminate the script, via die(). In order to add email support, this patch converts all die() to dodie() except: * when '-v' is used as an option to get the version of the script. * in Sig-Int handeler because it's not a fatal error to cancel the script. * the die() in dodie() itself actually kills the script. Suggested-by: Dhaval Giani Signed-off-by: Tim Tianyang Chen --- ktest.pl | 88 +++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/ktest.pl b/ktest.pl index 2e38647..763a83e 100755 --- a/ktest.pl +++ b/ktest.pl @@ -464,9 +464,11 @@ $config_help{"REBOOT_SCRIPT"} = << "EOF" EOF ; +sub dodie; + sub _logit { if (defined($opt{"LOG_FILE"})) { - open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; + open(OUT, ">> $opt{LOG_FILE}") or dodie "Can't write to $opt{LOG_FILE}"; print OUT @_; close(OUT); } @@ -751,7 +753,7 @@ sub set_value { if ($override) { $extra = "In the same override section!\n"; } - die "$name: $.: Option $lvalue defined more than once!\n$extra"; + dodie "$name: $.: Option $lvalue defined more than once!\n$extra"; } ${$overrides}{$lvalue} = $prvalue; } @@ -863,7 +865,7 @@ sub process_expression { if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) { my $ret = process_compare($1, $2, $3); if ($ret < 0) { - die "$name: $.: Unable to process comparison\n"; + dodie "$name: $.: Unable to process comparison\n"; } return $ret; } @@ -882,7 +884,7 @@ sub process_expression { return 1; } - die ("$name: $.: Undefined content $val in if statement\n"); + dodie ("$name: $.: Undefined content $val in if statement\n"); } sub process_if { @@ -899,7 +901,7 @@ sub __read_config { my ($config, $current_test_num) = @_; my $in; - open($in, $config) || die "can't read file $config"; + open($in, $config) || dodie "can't read file $config"; my $name = $config; $name =~ s,.*/(.*),$1,; @@ -936,7 +938,7 @@ sub __read_config { if ($type eq "TEST_START") { if ($num_tests_set) { - die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; + dodie "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; } $old_test_num = $test_num; @@ -959,7 +961,7 @@ sub __read_config { if ($rest =~ s/\sELSE\b//) { if (!$if) { - die "$name: $.: ELSE found with out matching IF section\n$_"; + dodie "$name: $.: ELSE found with out matching IF section\n$_"; } $if = 0; @@ -997,7 +999,7 @@ sub __read_config { } if (!$skip && $rest !~ /^\s*$/) { - die "$name: $.: Gargbage found after $type\n$_"; + dodie "$name: $.: Gargbage found after $type\n$_"; } if ($skip && $type eq "TEST_START") { @@ -1007,7 +1009,7 @@ sub __read_config { } elsif (/^\s*ELSE\b(.*)$/) { if (!$if) { - die "$name: $.: ELSE found with out matching IF section\n$_"; + dodie "$name: $.: ELSE found with out matching IF section\n$_"; } $rest = $1; if ($if_set) { @@ -1030,7 +1032,7 @@ sub __read_config { } if ($rest !~ /^\s*$/) { - die "$name: $.: Gargbage found after DEFAULTS\n$_"; + dodie "$name: $.: Gargbage found after DEFAULTS\n$_"; } } elsif (/^\s*INCLUDE\s+(\S+)/) { @@ -1038,7 +1040,7 @@ sub __read_config { next if ($skip); if (!$default) { - die "$name: $.: INCLUDE can only be done in default sections\n$_"; + dodie "$name: $.: INCLUDE can only be done in default sections\n$_"; } my $file = process_variables($1); @@ -1053,7 +1055,7 @@ sub __read_config { } if ( ! -r $file ) { - die "$name: $.: Can't read file $file\n$_"; + dodie "$name: $.: Can't read file $file\n$_"; } if (__read_config($file, \$test_num)) { @@ -1085,15 +1087,15 @@ sub __read_config { ($lvalue eq "NUM_TESTS" || $lvalue eq "LOG_FILE" || $lvalue eq "CLEAR_LOG")) { - die "$name: $.: $lvalue must be set in DEFAULTS section\n"; + dodie "$name: $.: $lvalue must be set in DEFAULTS section\n"; } if ($lvalue eq "NUM_TESTS") { if ($test_num) { - die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; + dodie "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; } if (!$default) { - die "$name: $.: NUM_TESTS must be set in default section\n"; + dodie "$name: $.: NUM_TESTS must be set in default section\n"; } $num_tests_set = 1; } @@ -1125,7 +1127,7 @@ sub __read_config { set_variable($lvalue, $rvalue); } else { - die "$name: $.: Garbage found in config\n$_"; + dodie "$name: $.: Garbage found in config\n$_"; } } @@ -1311,7 +1313,7 @@ sub eval_option { # Check for recursive evaluations. # 100 deep should be more than enough. if ($r++ > 100) { - die "Over 100 evaluations accurred with $option\n" . + dodie "Over 100 evaluations accurred with $option\n" . "Check for recursive variables\n"; } $prev = $option; @@ -1442,7 +1444,7 @@ sub dodie { run_command $post_test; } - die @_, "\n"; + die "Aborted.\n"; } sub create_pty { @@ -1484,7 +1486,7 @@ sub exec_console { close($pts); exec $console or - die "Can't open console $console"; + dodie "Can't open console $console"; } sub open_console { @@ -1632,7 +1634,7 @@ sub save_logs { if (!-d $dir) { mkpath($dir) or - die "can't create $dir"; + dodie "can't create $dir"; } my %files = ( @@ -1645,7 +1647,7 @@ sub save_logs { while (my ($name, $source) = each(%files)) { if (-f "$source") { cp "$source", "$dir/$name" or - die "failed to copy $source"; + dodie "failed to copy $source"; } } @@ -1819,7 +1821,7 @@ sub get_grub2_index { $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g; open(IN, "$ssh_grub |") - or die "unable to get $grub_file"; + or dodie "unable to get $grub_file"; my $found = 0; @@ -1834,7 +1836,7 @@ sub get_grub2_index { } close(IN); - die "Could not find '$grub_menu' in $grub_file on $machine" + dodie "Could not find '$grub_menu' in $grub_file on $machine" if (!$found); doprint "$grub_number\n"; $last_grub_menu = $grub_menu; @@ -1862,7 +1864,7 @@ sub get_grub_index { $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g; open(IN, "$ssh_grub |") - or die "unable to get menu.lst"; + or dodie "unable to get menu.lst"; my $found = 0; @@ -1877,7 +1879,7 @@ sub get_grub_index { } close(IN); - die "Could not find '$grub_menu' in /boot/grub/menu on $machine" + dodie "Could not find '$grub_menu' in /boot/grub/menu on $machine" if (!$found); doprint "$grub_number\n"; $last_grub_menu = $grub_menu; @@ -1990,7 +1992,7 @@ sub monitor { my $full_line = ""; open(DMESG, "> $dmesg") or - die "unable to write to $dmesg"; + dodie "unable to write to $dmesg"; reboot_to; @@ -2878,9 +2880,9 @@ sub bisect { my $result; - die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good)); - die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad)); - die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type)); + dodie "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good)); + dodie "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad)); + dodie "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type)); my $good = $bisect_good; my $bad = $bisect_bad; @@ -2966,7 +2968,7 @@ sub bisect { # checkout where we started run_command "git checkout $head" or - die "Failed to checkout $head"; + dodie "Failed to checkout $head"; } run_command "git bisect start$start_files" or @@ -3423,9 +3425,9 @@ sub patchcheck_reboot { sub patchcheck { my ($i) = @_; - die "PATCHCHECK_START[$i] not defined\n" + dodie "PATCHCHECK_START[$i] not defined\n" if (!defined($patchcheck_start)); - die "PATCHCHECK_TYPE[$i] not defined\n" + dodie "PATCHCHECK_TYPE[$i] not defined\n" if (!defined($patchcheck_type)); my $start = $patchcheck_start; @@ -3503,7 +3505,7 @@ sub patchcheck { doprint "\nProcessing commit \"$item\"\n\n"; run_command "git checkout $sha1" or - die "Failed to checkout $sha1"; + dodie "Failed to checkout $sha1"; # only clean on the first and last patch if ($item eq $list[0] || @@ -3594,7 +3596,7 @@ sub read_kconfig { } open(KIN, "$kconfig") - or die "Can't open $kconfig"; + or dodie "Can't open $kconfig"; while () { chomp; @@ -3755,7 +3757,7 @@ sub get_depends { $dep =~ s/^[^$valid]*[$valid]+//; } else { - die "this should never happen"; + dodie "this should never happen"; } } @@ -4016,7 +4018,7 @@ sub make_min_config { # update new ignore configs if (defined($ignore_config)) { open (OUT, ">$temp_config") - or die "Can't write to $temp_config"; + or dodie "Can't write to $temp_config"; foreach my $config (keys %save_configs) { print OUT "$save_configs{$config}\n"; } @@ -4044,7 +4046,7 @@ sub make_min_config { # Save off all the current mandatory configs open (OUT, ">$temp_config") - or die "Can't write to $temp_config"; + or dodie "Can't write to $temp_config"; foreach my $config (keys %keep_configs) { print OUT "$keep_configs{$config}\n"; } @@ -4113,7 +4115,7 @@ if ($#ARGV == 0) { if (! -f $ktest_config) { $newconfig = 1; get_test_case; - open(OUT, ">$ktest_config") or die "Can not create $ktest_config"; + open(OUT, ">$ktest_config") or dodie "Can not create $ktest_config"; print OUT << "EOF" # Generated by ktest.pl # @@ -4148,7 +4150,7 @@ if (defined($opt{"LOG_FILE"})) { my @new_configs = keys %entered_configs; if ($#new_configs >= 0) { print "\nAppending entered in configs to $ktest_config\n"; - open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config"; + open(OUT, ">>$ktest_config") or dodie "Can not append to $ktest_config"; foreach my $config (@new_configs) { print OUT "$config = $entered_configs{$config}\n"; $opt{$config} = process_variables($entered_configs{$config}); @@ -4286,11 +4288,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { $outputdir = set_test_option("OUTPUT_DIR", $i); $builddir = set_test_option("BUILD_DIR", $i); - chdir $builddir || die "can't change directory to $builddir"; + chdir $builddir || dodie "can't change directory to $builddir"; if (!-d $outputdir) { mkpath($outputdir) or - die "can't create $outputdir"; + dodie "can't create $outputdir"; } $make = "$makecmd O=$outputdir"; @@ -4321,7 +4323,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { if (!-d $tmpdir) { mkpath($tmpdir) or - die "can't create $tmpdir"; + dodie "can't create $tmpdir"; } $ENV{"SSH_USER"} = $ssh_user; @@ -4394,7 +4396,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { if (defined($checkout)) { run_command "git checkout $checkout" or - die "failed to checkout $checkout"; + dodie "failed to checkout $checkout"; } $no_reboot = 0; -- 1.8.3.1 From 1582904993313285384@xxx Wed Nov 01 22:37:17 +0000 2017 X-GM-THRID: 1582665622280232801 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread