run_tests.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. use strict;
  9. use warnings;
  10. # Recognise VERBOSE and V which is common on other projects.
  11. BEGIN {
  12. $ENV{HARNESS_VERBOSE} = "yes" if $ENV{VERBOSE} || $ENV{V};
  13. }
  14. use File::Spec::Functions qw/catdir catfile curdir abs2rel rel2abs/;
  15. use File::Basename;
  16. use FindBin;
  17. use lib "$FindBin::Bin/../util/perl";
  18. use OpenSSL::Glob;
  19. use Module::Load::Conditional qw(can_load);
  20. my $TAP_Harness = can_load(modules => { 'TAP::Harness' => undef })
  21. ? 'TAP::Harness' : 'OpenSSL::TAP::Harness';
  22. my $srctop = $ENV{SRCTOP} || $ENV{TOP};
  23. my $bldtop = $ENV{BLDTOP} || $ENV{TOP};
  24. my $recipesdir = catdir($srctop, "test", "recipes");
  25. my $libdir = rel2abs(catdir($srctop, "util", "perl"));
  26. my %tapargs =
  27. ( verbosity => $ENV{VERBOSE} || $ENV{V} || $ENV{HARNESS_VERBOSE} ? 1 : 0,
  28. lib => [ $libdir ],
  29. switches => '-w',
  30. merge => 1
  31. );
  32. my @tests = ( "alltests" );
  33. if (@ARGV) {
  34. @tests = @ARGV;
  35. }
  36. my $list_mode = scalar(grep /^list$/, @tests) != 0;
  37. if (grep /^(alltests|list)$/, @tests) {
  38. @tests = grep {
  39. basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
  40. } glob(catfile($recipesdir,"*.t"));
  41. } else {
  42. my @t = ();
  43. foreach (@tests) {
  44. push @t, grep {
  45. basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
  46. } glob(catfile($recipesdir,"*-$_.t"));
  47. }
  48. @tests = @t;
  49. }
  50. if ($list_mode) {
  51. @tests = map { $_ = basename($_); $_ =~ s/^[0-9][0-9]-//; $_ =~ s/\.t$//;
  52. $_ } @tests;
  53. print join("\n", @tests), "\n";
  54. } else {
  55. @tests = map { abs2rel($_, rel2abs(curdir())); } @tests;
  56. my $harness = $TAP_Harness->new(\%tapargs);
  57. my $ret = $harness->runtests(sort @tests);
  58. # $ret->has_errors may be any number, not just 0 or 1. On VMS, numbers
  59. # from 2 and on are used as is as VMS statuses, which has severity encoded
  60. # in the lower 3 bits. 0 and 1, on the other hand, generate SUCCESS and
  61. # FAILURE, so for currect reporting on all platforms, we make sure the only
  62. # exit codes are 0 and 1. Double-bang is the trick to do so.
  63. exit !!$ret->has_errors if (ref($ret) eq "TAP::Parser::Aggregator");
  64. # If this isn't a TAP::Parser::Aggregator, it's the pre-TAP test harness,
  65. # which simply dies at the end if any test failed, so we don't need to
  66. # bother with any exit code in that case.
  67. }
  68. # Fake TAP::Harness in case it's not loaded
  69. use Test::Harness;
  70. package OpenSSL::TAP::Harness;
  71. sub new {
  72. my $class = shift;
  73. my %args = %{ shift() };
  74. return bless { %args }, $class;
  75. }
  76. sub runtests {
  77. my $self = shift;
  78. my @switches = ();
  79. if ($self->{switches}) {
  80. push @switches, $self->{switches};
  81. }
  82. if ($self->{lib}) {
  83. foreach (@{$self->{lib}}) {
  84. my $l = $_;
  85. # It seems that $switches is getting interpreted with 'eval' or
  86. # something like that, and that we need to take care of backslashes
  87. # or they will disappear along the way.
  88. $l =~ s|\\|\\\\|g if $^O eq "MSWin32";
  89. push @switches, "-I$l";
  90. }
  91. }
  92. $Test::Harness::switches = join(' ', @switches);
  93. Test::Harness::runtests(@_);
  94. }