2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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.
14 $ENV{HARNESS_VERBOSE} = "yes" if $ENV{VERBOSE} || $ENV{V};
17 use File::Spec::Functions qw/catdir catfile curdir abs2rel rel2abs/;
20 use lib "$FindBin::Bin/../util/perl";
22 use Module::Load::Conditional qw(can_load);
24 my $TAP_Harness = can_load(modules => { 'TAP::Harness' => undef })
25 ? 'TAP::Harness' : 'OpenSSL::TAP::Harness';
27 my $srctop = $ENV{SRCTOP} || $ENV{TOP};
28 my $bldtop = $ENV{BLDTOP} || $ENV{TOP};
29 my $recipesdir = catdir($srctop, "test", "recipes");
30 my $libdir = rel2abs(catdir($srctop, "util", "perl"));
33 ( verbosity => $ENV{VERBOSE} || $ENV{V} || $ENV{HARNESS_VERBOSE} ? 1 : 0,
39 my @tests = ( "alltests" );
43 my $list_mode = scalar(grep /^list$/, @tests) != 0;
44 if (grep /^(alltests|list)$/, @tests) {
46 basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
47 } glob(catfile($recipesdir,"*.t"));
52 basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
53 } glob(catfile($recipesdir,"*-$_.t"));
59 @tests = map { $_ = basename($_); $_ =~ s/^[0-9][0-9]-//; $_ =~ s/\.t$//;
61 print join("\n", @tests), "\n";
63 @tests = map { abs2rel($_, rel2abs(curdir())); } @tests;
65 my $harness = $TAP_Harness->new(\%tapargs);
66 my $ret = $harness->runtests(sort @tests);
68 # $ret->has_errors may be any number, not just 0 or 1. On VMS, numbers
69 # from 2 and on are used as is as VMS statuses, which has severity encoded
70 # in the lower 3 bits. 0 and 1, on the other hand, generate SUCCESS and
71 # FAILURE, so for currect reporting on all platforms, we make sure the only
72 # exit codes are 0 and 1. Double-bang is the trick to do so.
73 exit !!$ret->has_errors if (ref($ret) eq "TAP::Parser::Aggregator");
75 # If this isn't a TAP::Parser::Aggregator, it's the pre-TAP test harness,
76 # which simply dies at the end if any test failed, so we don't need to
77 # bother with any exit code in that case.
81 # Fake TAP::Harness in case it's not loaded
83 package OpenSSL::TAP::Harness;
87 my %args = %{ shift() };
89 return bless { %args }, $class;
96 if ($self->{switches}) {
97 push @switches, $self->{switches};
100 foreach (@{$self->{lib}}) {
103 # It seems that $switches is getting interpreted with 'eval' or
104 # something like that, and that we need to take care of backslashes
105 # or they will disappear along the way.
106 $l =~ s|\\|\\\\|g if $^O eq "MSWin32";
107 push @switches, "-I$l";
111 $Test::Harness::switches = join(' ', @switches);
112 Test::Harness::runtests(@_);