2 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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
9 ## SSL testcase generator
15 use File::Spec::Functions;
17 use OpenSSL::Test qw/srctop_dir srctop_file/;
18 use OpenSSL::Test::Utils;
20 # This block needs to run before 'use lib srctop_dir' directives.
22 OpenSSL::Test::setup("no_test_here");
26 use lib "$FindBin::Bin/../util/perl";
27 use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
28 use Text::Template 1.46;
30 use lib "$FindBin::Bin/ssl-tests";
33 push (@ISA, qw/Text::Template/);
38 my $source = srctop_file("test", "ssl_test.tmpl");
39 my $template = Text::Template->new(TYPE => 'FILE', SOURCE => $source);
41 print "# Generated with generate_ssl_tests.pl\n\n";
43 my $num = scalar @ssltests::tests;
45 # Add the implicit base configuration.
46 foreach my $test (@ssltests::tests) {
47 $test->{"server"} = { (%ssltests::base_server, %{$test->{"server"}}) };
48 if (defined $test->{"server2"}) {
49 $test->{"server2"} = { (%ssltests::base_server, %{$test->{"server2"}}) };
51 if ($test->{"server"}->{"extra"} &&
52 defined $test->{"server"}->{"extra"}->{"ServerNameCallback"}) {
53 # Default is the same as server.
54 $test->{"reuse_server2"} = 1;
56 # Do not emit an empty/duplicate "server2" section.
57 $test->{"server2"} = { };
59 if (defined $test->{"resume_server"}) {
60 $test->{"resume_server"} = { (%ssltests::base_server, %{$test->{"resume_server"}}) };
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;
67 # Do not emit an empty/duplicate "resume-server" section.
68 $test->{"resume_server"} = { };
70 $test->{"client"} = { (%ssltests::base_client, %{$test->{"client"}}) };
71 if (defined $test->{"resume_client"}) {
72 $test->{"resume_client"} = { (%ssltests::base_client, %{$test->{"resume_client"}}) };
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;
79 # Do not emit an empty/duplicate "resume-client" section.
80 $test->{"resume_client"} = { };
84 # ssl_test expects to find a
88 # directive in the file. It'll then look for configuration directives
89 # for n tests, that each look like this:
91 # test-n = test-section
94 # (SSL modules for client and server configuration go here.)
97 # (Test configuration goes here.)
98 print "num_tests = $num\n\n";
100 # The conf module locations must come before everything else, because
103 # test-n = test-section
105 # and you can't mix and match them with sections.
108 foreach my $test (@ssltests::tests) {
109 my $testname = "${idx}-" . $test->{'name'};
110 print "test-$idx = $testname\n";
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";
127 # Shamelessly copied from Configure.
130 open(INPUT, "< $fname") or die "Can't open input file '$fname'!\n";
132 my $content = <INPUT>;
138 my $input_file = shift;
139 # Reads the tests into ssltests::tests.
140 read_config($input_file);