Lines Matching +full:setup +full:- +full:test +full:- +full:env
1 # Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
8 package OpenSSL::Test;
13 use Test::More 0.96;
19 @EXPORT = (@Test::More::EXPORT, qw(setup run indir cmd app fuzz test
21 @EXPORT_OK = (@Test::More::EXPORT_OK, qw(bldtop_dir bldtop_file
31 OpenSSL::Test - a private extension of Test::More
35 use OpenSSL::Test;
37 setup("my_test_name");
44 ok(run(test(["sometest", "arg1"], stdout => "foo.txt")),
50 This module is a private extension of L<Test::More> for testing OpenSSL.
51 In addition to the Test::More functions, it also provides functions that
59 With each test recipe, a parallel data directory with (almost) the same name
61 recipe C<$SRCTOP/test/recipes/99-foo.t>, there could be a directory
62 C<$SRCTOP/test/recipes/99-foo_data/>.
76 # The name of the test. This is set by setup() and is used in the other
77 # functions to verify that setup() has been used.
80 # Directories we want to keep track of TOP, APPS, TEST and RESULTS are the
91 # tests or not. This is set by setup() if the environment variable STOPTEST
92 # is defined with a non-empty value.
113 The following functions are exported by default when using C<OpenSSL::Test>.
119 =item B<setup "NAME">
121 C<setup> is used for initial setup, and it is mandatory that it's used.
122 If it's not used in a OpenSSL test recipe, the rest of the recipe will
125 C<setup> checks for environment variables (see L</ENVIRONMENT> below),
128 variable if defined, otherwise C<$BLDTOP/test-runs> or C<$TOP/test-runs>,
135 sub setup { subroutine
140 BAIL_OUT("setup() must receive a name") unless $test_name;
141 warn "setup() detected test name change. Innocuous, so we continue...\n"
146 BAIL_OUT("setup() needs \$TOP or \$SRCTOP and \$BLDTOP to be defined")
147 unless $ENV{TOP} || ($ENV{SRCTOP} && $ENV{BLDTOP});
148 BAIL_OUT("setup() found both \$TOP and \$SRCTOP or \$BLDTOP...")
149 if $ENV{TOP} && ($ENV{SRCTOP} || $ENV{BLDTOP});
153 BAIL_OUT("setup() expects the file Configure in the source top directory")
154 unless -f srctop_file("Configure");
156 note "The results of this test will end up in $directories{RESULTS}"
167 the one C<setup> moved into, usually a subdirectory, given by SUBDIR.
207 $codeblock->();
244 =item B<test ARRAYREF, OPTS>
253 C<test> expects to find the given command (the first item in the given list
254 reference) as an executable in C<$TEST_D> (if defined, otherwise C<$TOP/test>
255 or C<$BLDTOP/test>).
257 Also, for both C<app> and C<test>, the command may be prefixed with
267 interpreted to reside in the same location as C<app> and C<test>.
284 interpreter_args => [ "-I", srctop_dir("test") ])));
290 One might wonder over the complexity of C<apps>, C<fuzz>, C<test>, ...
331 exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
342 exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
346 sub test { subroutine
353 exe_shell => $ENV{EXE_SHELL}, %opts) -> (shift);
367 @prog, @cmdargs ], %opts) -> (shift);
381 @prog, @cmdargs ], %opts) -> (shift);
412 or C<not ok > that can disturb Test::Harness.
431 my ($cmd, $display_cmd) = shift->(0);
445 die "OpenSSL::Test::run(): statusvar value not a scalar reference"
454 # In non-verbose, we want to shut up the command interpreter, in case
457 if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) {
465 $ENV{HARNESS_OSSL_LEVEL} = $level + 1;
475 open($pipe, '-|', "$prefix$cmd") or die "Can't start command: $!";
486 $ENV{HARNESS_OSSL_PREFIX} = "# ";
488 delete $ENV{HARNESS_OSSL_PREFIX};
491 $r = $hooks{exit_checker}->($e);
498 if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) {
506 if !$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE};
512 # there are Test::More versions that get picky if we leave it
513 # non-zero.
524 my $tb = Test::More->builder;
525 my $failure = scalar(grep { $_ == 0; } $tb->summary);
533 The following functions are exported on request when using C<OpenSSL::Test>.
536 use OpenSSL::Test qw/bldtop_file srctop_file/;
539 use OpenSSL::Test qw/:DEFAULT bldtop_file/;
624 associated with the test (see L</DESCRIPTION> above).
641 associated with the test (see L</DESCRIPTION> above) and FILENAME is the name
657 C<result_dir> returns the directory where test output files should be placed
665 BAIL_OUT("Must run setup() first") if (! $test_name);
674 FILENAME is the name of a test output file.
676 prepending to the file name the path to the directory where test output files
684 BAIL_OUT("Must run setup() first") if (! $test_name);
694 LIST is a list of CODEREFs returned by C<app> or C<test>, from which C<pipe>
696 pipe. C<pipe> returns a new CODEREF in the same manner as C<app> or C<test>,
712 my ($c, $dc, @el) = $_->(++$counter);
764 $codeblock->();
775 C<cmdstr> takes a CODEREF from C<app> or C<test> and simply returns the
801 my ($cmd, $display_cmd) = shift->(0);
832 run(test(['versions']), capture => 1);
845 are the same as used by C<ok> which is an expression EXPR followed by the test
858 compared using eq or ne, followed by a test description TEST_NAME.
870 that can be compared using ne or eq, followed by a test description TEST_NAME.
881 return ok(!$_[0], @_[1..$#_]) if defined $ENV{FIPS_MODE};
886 return isnt($_[0], $_[1], @_[2..$#_]) if defined $ENV{FIPS_MODE};
891 return is($_[0], $_[1], @_[2..$#_]) if defined $ENV{FIPS_MODE};
900 OpenSSL::Test depends on some environment variables.
906 This environment variable is mandatory. C<setup> will check that it's
908 If this isn't so, C<setup> will C<BAIL_OUT>.
917 If defined, its value should be the directory where the test applications
918 are located. Defaults to C<$TOP/test> (adapted to the operating system).
928 B<ok_nofips>, B<is_nofips> and B<isnt_nofips> to invert test results
938 $directories{SRCTOP} = abs_path($ENV{SRCTOP} || $ENV{TOP});
939 $directories{BLDTOP} = abs_path($ENV{BLDTOP} || $ENV{TOP});
940 $directories{BLDAPPS} = $ENV{BIN_D} || __bldtop_dir("apps");
944 $directories{BLDTEST} = $ENV{TEST_D} || __bldtop_dir("test");
945 $directories{SRCTEST} = __srctop_dir("test");
946 $directories{SRCDATA} = __srctop_dir("test", "recipes",
948 $directories{RESULTTOP} = $ENV{RESULT_D} || __bldtop_dir("test-runs");
957 delete $directories{SRCDATA} unless -d $directories{SRCDATA};
959 push @direnv, "TOP" if $ENV{TOP};
960 push @direnv, "SRCTOP" if $ENV{SRCTOP};
961 push @direnv, "BLDTOP" if $ENV{BLDTOP};
962 push @direnv, "BIN_D" if $ENV{BIN_D};
963 push @direnv, "TEST_D" if $ENV{TEST_D};
964 push @direnv, "RESULT_D" if $ENV{RESULT_D};
966 $end_with_bailout = $ENV{STOPTEST} ? 1 : 0;
971 # therefore on the proper use of setup() and when needed, indir().
978 BAIL_OUT("Must run setup() first") if (! $test_name);
985 BAIL_OUT("Must run setup() first") if (! $test_name);
991 BAIL_OUT("Must run setup() first") if (! $test_name);
998 BAIL_OUT("Must run setup() first") if (! $test_name);
1013 return $ENV{"EXE_EXT"} || $ext;
1017 # relative to the test/, apps/ or fuzz/ directory in the build tree or the
1026 BAIL_OUT("Must run setup() first") if (! $test_name);
1031 $out = catfile($directories{SRCTEST},@_,$f) unless -f $out;
1036 BAIL_OUT("Must run setup() first") if (! $test_name);
1041 $out = catfile($directories{SRCAPPS},@_,$f) unless -f $out;
1046 BAIL_OUT("Must run setup() first") if (! $test_name);
1051 $out = catfile($directories{SRCFUZZ},@_,$f) unless -f $out;
1056 BAIL_OUT("Must run setup() first") if (! $test_name);
1065 BAIL_OUT("Must run setup() first") if (! $test_name);
1137 if (!file_name_is_absolute($ENV{$_})) {
1138 my $oldpath = abs_path($ENV{$_});
1141 print STDERR "DEBUG: [env $_] old path: $oldpath\n";
1142 print STDERR "DEBUG: [env $_] new base: $absdir\n";
1143 print STDERR "DEBUG: [env $_] resulting new path: $newpath\n";
1159 $ENV{$_} = $tmp_ENV{$_};
1246 BAIL_OUT("Must run setup() first") if (! $test_name);
1259 $stdin = " < ".$fileornull->($opts{stdin}) if exists($opts{stdin});
1260 $stdout= " > ".$fileornull->($opts{stdout}) if exists($opts{stdout});
1261 $stderr=" 2> ".$fileornull->($opts{stderr}) if exists($opts{stderr});
1268 unless $stderr || !$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE};
1283 L<Test::More>, L<Test::Harness>
1296 Test::More::subtest @_;
1298 $level--;