Raise an error on syscall failure in tls_retry_write_records
[openssl.git] / test / generate_ssl_tests.pl
index ac584fd92dadf1c64d1c3d9a6a45e0ed19d2e553..9ff556c0a931a493a2f3c280dccc90832f4fc4f1 100644 (file)
@@ -1,7 +1,7 @@
 #! /usr/bin/env perl
-# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
 #
-# Licensed under the OpenSSL license (the "License").  You may not use
+# Licensed under the Apache License 2.0 (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
 # in the file LICENSE in the source distribution or at
 # https://www.openssl.org/source/license.html
 use strict;
 use warnings;
 
+use Cwd qw/abs_path/;
 use File::Basename;
 use File::Spec::Functions;
 
 use OpenSSL::Test qw/srctop_dir srctop_file/;
 use OpenSSL::Test::Utils;
 
-# This block needs to run before 'use lib srctop_dir' directives.
+use FindBin;
+use lib "$FindBin::Bin/../util/perl";
+use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
+use Text::Template 1.46;
+
+my $input_file;
+my $provider;
+
 BEGIN {
-    OpenSSL::Test::setup("no_test_here");
-}
+    #Input file may be relative to cwd, but setup below changes the cwd, so
+    #figure out the absolute path first
+    $input_file = abs_path(shift);
+    $provider = shift // '';
 
-use lib srctop_dir("util");  # for with_fallback
-use lib srctop_dir("test", "ssl-tests");  # for ssltests_base
+    OpenSSL::Test::setup("no_test_here", quiet => 1);
+}
 
-use with_fallback qw(Text::Template);
+use lib "$FindBin::Bin/ssl-tests";
 
 use vars qw/@ISA/;
 push (@ISA, qw/Text::Template/);
@@ -43,7 +53,40 @@ sub print_templates {
     # Add the implicit base configuration.
     foreach my $test (@ssltests::tests) {
         $test->{"server"} = { (%ssltests::base_server, %{$test->{"server"}}) };
+        if (defined $test->{"server2"}) {
+            $test->{"server2"} = { (%ssltests::base_server, %{$test->{"server2"}}) };
+        } else {
+            if ($test->{"server"}->{"extra"} &&
+                defined $test->{"server"}->{"extra"}->{"ServerNameCallback"}) {
+                # Default is the same as server.
+                $test->{"reuse_server2"} = 1;
+            }
+            # Do not emit an empty/duplicate "server2" section.
+            $test->{"server2"} = { };
+        }
+        if (defined $test->{"resume_server"}) {
+            $test->{"resume_server"} = { (%ssltests::base_server, %{$test->{"resume_server"}}) };
+        } else {
+            if (defined $test->{"test"}->{"HandshakeMode"} &&
+                 $test->{"test"}->{"HandshakeMode"} eq "Resume") {
+                # Default is the same as server.
+                $test->{"reuse_resume_server"} = 1;
+            }
+            # Do not emit an empty/duplicate "resume-server" section.
+            $test->{"resume_server"} = { };
+        }
         $test->{"client"} = { (%ssltests::base_client, %{$test->{"client"}}) };
+        if (defined $test->{"resume_client"}) {
+            $test->{"resume_client"} = { (%ssltests::base_client, %{$test->{"resume_client"}}) };
+        } else {
+            if (defined $test->{"test"}->{"HandshakeMode"} &&
+                 $test->{"test"}->{"HandshakeMode"} eq "Resume") {
+                # Default is the same as client.
+                $test->{"reuse_resume_client"} = 1;
+            }
+            # Do not emit an empty/duplicate "resume-client" section.
+            $test->{"resume_client"} = { };
+        }
     }
 
     # ssl_test expects to find a
@@ -92,8 +135,12 @@ sub print_templates {
 # Shamelessly copied from Configure.
 sub read_config {
     my $fname = shift;
-    open(INPUT, "< $fname")
-       or die "Can't open input file '$fname'!\n";
+    my $provider = shift;
+    local $ssltests::fips_mode = $provider eq "fips";
+    local $ssltests::no_deflt_libctx =
+        $provider eq "default" || $provider eq "fips";
+
+    open(INPUT, "< $fname") or die "Can't open input file '$fname'!\n";
     local $/ = undef;
     my $content = <INPUT>;
     close(INPUT);
@@ -101,9 +148,8 @@ sub read_config {
     warn $@ if $@;
 }
 
-my $input_file = shift;
 # Reads the tests into ssltests::tests.
-read_config($input_file);
+read_config($input_file, $provider);
 print_templates();
 
 1;