]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/generate_ssl_tests.pl
Deprecate EC_KEY + Update ec apps to use EVP_PKEY
[thirdparty/openssl.git] / test / generate_ssl_tests.pl
CommitLineData
6aa36e8e 1#! /usr/bin/env perl
33388b44 2# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
6aa36e8e 3#
909f1a2e 4# Licensed under the Apache License 2.0 (the "License"). You may not use
6aa36e8e
RS
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
453dfd8d
EK
8
9## SSL testcase generator
10
11use strict;
12use warnings;
13
14use File::Basename;
15use File::Spec::Functions;
16
17use OpenSSL::Test qw/srctop_dir srctop_file/;
18use OpenSSL::Test::Utils;
19
20# This block needs to run before 'use lib srctop_dir' directives.
21BEGIN {
eeacf7d0 22 OpenSSL::Test::setup("no_test_here", quiet => 1);
453dfd8d
EK
23}
24
1935a586
RL
25use FindBin;
26use lib "$FindBin::Bin/../util/perl";
27use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
28use Text::Template 1.46;
453dfd8d 29
1935a586 30use lib "$FindBin::Bin/ssl-tests";
453dfd8d
EK
31
32use vars qw/@ISA/;
33push (@ISA, qw/Text::Template/);
34
35use ssltests_base;
36
37sub print_templates {
38 my $source = srctop_file("test", "ssl_test.tmpl");
39 my $template = Text::Template->new(TYPE => 'FILE', SOURCE => $source);
40
41 print "# Generated with generate_ssl_tests.pl\n\n";
42
43 my $num = scalar @ssltests::tests;
44
45 # Add the implicit base configuration.
46 foreach my $test (@ssltests::tests) {
47 $test->{"server"} = { (%ssltests::base_server, %{$test->{"server"}}) };
590ed3d7 48 if (defined $test->{"server2"}) {
b0292980
EK
49 $test->{"server2"} = { (%ssltests::base_server, %{$test->{"server2"}}) };
50 } else {
9f48bbac
EK
51 if ($test->{"server"}->{"extra"} &&
52 defined $test->{"server"}->{"extra"}->{"ServerNameCallback"}) {
d0c4415d
EK
53 # Default is the same as server.
54 $test->{"reuse_server2"} = 1;
55 }
56 # Do not emit an empty/duplicate "server2" section.
b0292980
EK
57 $test->{"server2"} = { };
58 }
590ed3d7
EK
59 if (defined $test->{"resume_server"}) {
60 $test->{"resume_server"} = { (%ssltests::base_server, %{$test->{"resume_server"}}) };
590ed3d7 61 } else {
d0c4415d
EK
62 if (defined $test->{"test"}->{"HandshakeMode"} &&
63 $test->{"test"}->{"HandshakeMode"} eq "Resume") {
64 # Default is the same as server.
65 $test->{"reuse_resume_server"} = 1;
66 }
67 # Do not emit an empty/duplicate "resume-server" section.
590ed3d7
EK
68 $test->{"resume_server"} = { };
69 }
453dfd8d 70 $test->{"client"} = { (%ssltests::base_client, %{$test->{"client"}}) };
11279b13
EK
71 if (defined $test->{"resume_client"}) {
72 $test->{"resume_client"} = { (%ssltests::base_client, %{$test->{"resume_client"}}) };
11279b13 73 } else {
d0c4415d
EK
74 if (defined $test->{"test"}->{"HandshakeMode"} &&
75 $test->{"test"}->{"HandshakeMode"} eq "Resume") {
76 # Default is the same as client.
77 $test->{"reuse_resume_client"} = 1;
78 }
79 # Do not emit an empty/duplicate "resume-client" section.
11279b13
EK
80 $test->{"resume_client"} = { };
81 }
453dfd8d
EK
82 }
83
84 # ssl_test expects to find a
85 #
86 # num_tests = n
87 #
88 # directive in the file. It'll then look for configuration directives
89 # for n tests, that each look like this:
90 #
91 # test-n = test-section
92 #
93 # [test-section]
94 # (SSL modules for client and server configuration go here.)
95 #
96 # [test-n]
97 # (Test configuration goes here.)
98 print "num_tests = $num\n\n";
99
100 # The conf module locations must come before everything else, because
101 # they look like
102 #
103 # test-n = test-section
104 #
105 # and you can't mix and match them with sections.
106 my $idx = 0;
107
108 foreach my $test (@ssltests::tests) {
109 my $testname = "${idx}-" . $test->{'name'};
110 print "test-$idx = $testname\n";
111 $idx++;
112 }
113
114 $idx = 0;
115
116 foreach my $test (@ssltests::tests) {
117 my $testname = "${idx}-" . $test->{'name'};
118 my $text = $template->fill_in(
119 HASH => [{ idx => $idx, testname => $testname } , $test],
120 DELIMITERS => [ "{-", "-}" ]);
121 print "# ===========================================================\n\n";
122 print "$text\n";
123 $idx++;
124 }
125}
126
127# Shamelessly copied from Configure.
128sub read_config {
129 my $fname = shift;
ab5a02f7 130 my $provider = shift;
682bc861
MC
131 local $ssltests::fips_mode = $provider eq "fips";
132 local $ssltests::no_deflt_libctx =
133 $provider eq "default" || $provider eq "fips";
ab5a02f7 134
b0292980 135 open(INPUT, "< $fname") or die "Can't open input file '$fname'!\n";
453dfd8d
EK
136 local $/ = undef;
137 my $content = <INPUT>;
138 close(INPUT);
139 eval $content;
140 warn $@ if $@;
141}
142
143my $input_file = shift;
ab5a02f7 144my $provider = shift;
453dfd8d 145# Reads the tests into ssltests::tests.
ab5a02f7 146read_config($input_file, $provider);
453dfd8d
EK
147print_templates();
148
1491;