]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/run_tests.pl
2 # Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
12 # Recognise VERBOSE and V which is common on other projects.
13 # Additionally, also recognise VERBOSE_FAILURE and VF.
15 $ENV{HARNESS_VERBOSE
} = "yes" if $ENV{VERBOSE
} || $ENV{V
};
16 $ENV{HARNESS_VERBOSE_FAILURE
} = "yes" if $ENV{VERBOSE_FAILURE
} || $ENV{VF
};
19 use File
::Spec
::Functions qw
/catdir catfile curdir abs2rel rel2abs/;
22 use lib
"$FindBin::Bin/../util/perl";
25 my $srctop = $ENV{SRCTOP
} || $ENV{TOP
};
26 my $bldtop = $ENV{BLDTOP
} || $ENV{TOP
};
27 my $recipesdir = catdir
($srctop, "test", "recipes");
28 my $libdir = rel2abs
(catdir
($srctop, "util", "perl"));
30 $ENV{OPENSSL_CONF
} = catdir
($srctop, "apps", "openssl.cnf");
33 ( verbosity
=> $ENV{HARNESS_VERBOSE
} ?
1 : 0,
39 # Additional OpenSSL special TAP arguments. Because we can't pass them via
40 # TAP::Harness->new(), they will be accessed directly, see the
41 # TAP::Parser::OpenSSL implementation further down
42 my %openssl_args = ();
44 $openssl_args{'failure_verbosity'} =
45 $ENV{HARNESS_VERBOSE_FAILURE
} && $tapargs{verbosity
} < 1 ?
1 : 0;
47 my $outfilename = $ENV{HARNESS_TAP_COPY
};
48 open $openssl_args{'tap_copy'}, ">$outfilename"
49 or die "Trying to create $outfilename: $!\n"
50 if defined $outfilename;
52 my @alltests = find_matching_tests
("*");
56 foreach my $arg (@ARGV ?
@ARGV : ('alltests')) {
59 (my $x = basename
($_)) =~ s
|^[0-9][0-9]-(.*)\
.t
$|$1|;
64 if ($arg eq 'alltests') {
65 warn "'alltests' encountered, ignoring everything before that...\n"
67 %tests = map { $_ => basename
($_) } @alltests;
68 } elsif ($arg =~ m/^(-?)(.*)/) {
71 my @matches = find_matching_tests
($test);
73 # If '-foo' is the first arg, it's short for 'alltests -foo'
74 if ($sign eq '-' && $initial_arg) {
75 %tests = map { $_ => basename
($_) } @alltests;
78 if (scalar @matches == 0) {
79 warn "Test $test found no match, skipping ",
80 ($sign eq '-' ?
"removal" : "addition"),
83 foreach $test (@matches) {
87 $tests{$test} = basename
($test);
92 warn "I don't know what '$arg' is about, ignoring...\n";
98 sub find_matching_tests
{
101 if ($glob =~ m
|^[\d\
[\
]\?\
-]+$|) {
102 return glob(catfile
($recipesdir,"$glob-*.t"));
104 return glob(catfile
($recipesdir,"*-$glob.t"));
107 # The following is quite a bit of hackery to adapt to both TAP::Harness
108 # and Test::Harness, depending on what's available.
109 # The TAP::Harness hack allows support for HARNESS_VERBOSE_FAILURE and
110 # HARNESS_TAP_COPY, while the Test::Harness hack can't, because the pre
111 # TAP::Harness Test::Harness simply doesn't have support for this sort of
114 # We use eval to avoid undue interruption if TAP::Harness isn't present.
120 package TAP
::Parser
::OpenSSL
;
121 use parent
'TAP::Parser';
125 my %opts = %{ shift() };
127 # We rely heavily on perl closures to make failure verbosity work
128 # We need to do so, because there's no way to safely pass extra
129 # objects down all the way to the TAP::Parser::Result object
130 my @failure_output = ();
132 if ($openssl_args{failure_verbosity
}
133 || defined $openssl_args{tap_copy
}) {
134 $callbacks{ALL
} = sub {
136 my $fh = $openssl_args{tap_copy
};
138 print $fh $self->as_string, "\n"
140 push @failure_output, $self->as_string
141 if $openssl_args{failure_verbosity
} > 0;
145 if ($openssl_args{failure_verbosity
} > 0) {
146 $callbacks{EOF
} = sub {
149 # We know we are a TAP::Parser::Aggregator object
150 if (scalar $self->failed > 0 && @failure_output) {
151 # We add an extra empty line, because in the case of a
152 # progress counter, we're still at the end of that progress
154 print $_, "\n" foreach (("", @failure_output));
159 if (keys %callbacks) {
160 # If %opts already has a callbacks element, the order here
161 # ensures we do not override it
162 %opts = ( callbacks
=> { %callbacks }, %opts );
165 return $class->SUPER::new
({ %opts });
168 package TAP
::Harness
::OpenSSL
;
169 use parent
'TAP::Harness';
173 $tapargs{parser_class
} = "TAP::Parser::OpenSSL";
174 $package = 'TAP::Harness::OpenSSL';
177 unless (defined $eres) {
179 # Fake TAP::Harness in case it's not loaded
180 package TAP
::Harness
::fake
;
181 use parent
'Test::Harness';
185 my %args = %{ shift() };
187 return bless { %args }, $class;
193 # Pre TAP::Harness Test::Harness doesn't support [ filename, name ]
194 # elements, so convert such elements to just be the filename
195 my @args = map { ref($_) eq 'ARRAY' ?
$_->[0] : $_ } @_;
198 if ($self->{switches
}) {
199 push @switches, $self->{switches
};
202 foreach (@
{$self->{lib
}}) {
205 # It seems that $switches is getting interpreted with 'eval'
206 # or something like that, and that we need to take care of
207 # backslashes or they will disappear along the way.
208 $l =~ s
|\\|\\\\|g
if $^O
eq "MSWin32";
209 push @switches, "-I$l";
213 $Test::Harness
::switches
= join(' ', @switches);
214 Test
::Harness
::runtests
(@args);
218 $package = 'TAP::Harness::fake';
222 unless (defined $eres) {
228 my $harness = $package->new(\
%tapargs);
230 $harness->runtests(map { [ abs2rel
($_, rel2abs
(curdir
())), $tests{$_} ] }
233 # $ret->has_errors may be any number, not just 0 or 1. On VMS, numbers
234 # from 2 and on are used as is as VMS statuses, which has severity encoded
235 # in the lower 3 bits. 0 and 1, on the other hand, generate SUCCESS and
236 # FAILURE, so for currect reporting on all platforms, we make sure the only
237 # exit codes are 0 and 1. Double-bang is the trick to do so.
238 exit !!$ret->has_errors if (ref($ret) eq "TAP::Parser::Aggregator");
240 # If this isn't a TAP::Parser::Aggregator, it's the pre-TAP test harness,
241 # which simply dies at the end if any test failed, so we don't need to bother
242 # with any exit code in that case.