Wrap more of ocspapitest.c in OPENSSL_NO_OCSP
[openssl.git] / test / run_tests.pl
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
8
9 use strict;
10 use warnings;
11
12 # Recognise VERBOSE and V which is common on other projects.
13 BEGIN {
14     $ENV{HARNESS_VERBOSE} = "yes" if $ENV{VERBOSE} || $ENV{V};
15 }
16
17 use File::Spec::Functions qw/catdir catfile curdir abs2rel rel2abs/;
18 use File::Basename;
19 use FindBin;
20 use lib "$FindBin::Bin/../util/perl";
21 use OpenSSL::Glob;
22 use Module::Load::Conditional qw(can_load);
23
24 my $TAP_Harness = can_load(modules => { 'TAP::Harness' => undef }) 
25     ? 'TAP::Harness' : 'OpenSSL::TAP::Harness';
26
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"));
31
32 my %tapargs =
33     ( verbosity => $ENV{VERBOSE} || $ENV{V} || $ENV{HARNESS_VERBOSE} ? 1 : 0,
34       lib       => [ $libdir ],
35       switches  => '-w',
36       merge     => 1
37     );
38
39 my @tests = ( "alltests" );
40 if (@ARGV) {
41     @tests = @ARGV;
42 }
43 my $list_mode = scalar(grep /^list$/, @tests) != 0;
44 if (grep /^(alltests|list)$/, @tests) {
45     @tests = grep {
46         basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
47     } glob(catfile($recipesdir,"*.t"));
48 } else {
49     my @t = ();
50     foreach (@tests) {
51         push @t, grep {
52             basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
53         } glob(catfile($recipesdir,"*-$_.t"));
54     }
55     @tests = @t;
56 }
57
58 if ($list_mode) {
59     @tests = map { $_ = basename($_); $_ =~ s/^[0-9][0-9]-//; $_ =~ s/\.t$//;
60                    $_ } @tests;
61     print join("\n", @tests), "\n";
62 } else {
63     @tests = map { abs2rel($_, rel2abs(curdir())); } @tests;
64
65     my $harness = $TAP_Harness->new(\%tapargs);
66     my $ret = $harness->runtests(sort @tests);
67
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");
74
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.
78 }
79
80
81 # Fake TAP::Harness in case it's not loaded
82 use Test::Harness;
83 package OpenSSL::TAP::Harness;
84
85 sub new {
86     my $class = shift;
87     my %args = %{ shift() };
88
89     return bless { %args }, $class;
90 }
91
92 sub runtests {
93     my $self = shift;
94
95     my @switches = ();
96     if ($self->{switches}) {
97         push @switches, $self->{switches};
98     }
99     if ($self->{lib}) {
100         foreach (@{$self->{lib}}) {
101             my $l = $_;
102
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";
108         }
109     }
110
111     $Test::Harness::switches = join(' ', @switches);
112     Test::Harness::runtests(@_);
113 }