]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
ha-tester: allow to continue harness on test failure
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 1 Jul 2021 12:51:45 +0000 (14:51 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 1 Jul 2021 14:00:51 +0000 (16:00 +0200)
To see if just a bit or many tests are broken it is useful to
sometimes run all, and not just exit after first failure.

Allow this as opt-in feature.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/test/ha-tester.pl

index 1cd6dc966392b26c32414a9c0fb299463c70366b..73f15e4f41ee46fc62f7e22e6d17e63418c26adc 100755 (executable)
@@ -7,13 +7,17 @@ use Getopt::Long;
 use File::Path qw(make_path remove_tree);
 
 my $opt_nodiff;
+my $opt_nofail;
 
-if (!GetOptions ("nodiff"   => \$opt_nodiff)) {
-    print "usage: $0 testdir [--nodiff]\n";
+if (!GetOptions(
+    "no-diff" => \$opt_nodiff,
+    "c|continue-on-fail" => \$opt_nofail,
+)) {
+    print "usage: $0 testdir [--no-diff] [-c | --continue-on-fail]\n";
     exit -1;
 }
 
-sub run_test {
+sub do_run_test {
     my $dir = shift;
 
     $dir =~ s!/+$!!;
@@ -24,19 +28,38 @@ sub run_test {
     my $logexpect = "$dir/log.expect";
 
     my $res = system("perl -I ../ ../pve-ha-tester $dir");
-    die "Test '$dir' failed\n" if $res != 0;
+    return "Test '$dir' failed\n" if $res != 0;
 
     return if $opt_nodiff;
 
     if (-f $logexpect) {
        my $cmd = ['diff', '-u', $logexpect, $logfile]; 
        $res = system(@$cmd);
-       die "test '$dir' failed\n" if $res != 0;
+       return "test '$dir' failed\n" if $res != 0;
     } else {
        $res = system('cp', $logfile, $logexpect);
-       die "test '$dir' failed\n" if $res != 0;
+       return "test '$dir' failed\n" if $res != 0;
     }
     print "end: $dir (success)\n";
+
+    return undef;
+}
+
+my sub handle_test_result {
+    my ($res, $test) = @_;
+
+    return if !defined($res); # undef -> passed
+
+    die "$res\n" if !$opt_nofail;
+    warn "$res\n";
+}
+
+sub run_test {
+    my $dir = shift;
+
+    my $res = do_run_test($dir);
+
+    handle_test_result($res, $dir);
 }
 
 if (my $testdir = shift) {