2 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
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
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");
25 use lib srctop_dir("util"); # for with_fallback
26 use lib srctop_dir("test", "ssl-tests"); # for ssltests_base
28 use with_fallback qw(Text::Template);
31 push (@ISA, qw/Text::Template/);
36 my $source = srctop_file("test", "ssl_test.tmpl");
37 my $template = Text::Template->new(TYPE => 'FILE', SOURCE => $source);
39 print "# Generated with generate_ssl_tests.pl\n\n";
41 my $num = scalar @ssltests::tests;
43 # Add the implicit base configuration.
44 foreach my $test (@ssltests::tests) {
45 $test->{"server"} = { (%ssltests::base_server, %{$test->{"server"}}) };
46 if (defined $test->{"server2"}) {
47 $test->{"server2"} = { (%ssltests::base_server, %{$test->{"server2"}}) };
49 if (defined $test->{"test"}->{"ServerNameCallback"}) {
50 # Default is the same as server.
51 $test->{"reuse_server2"} = 1;
53 # Do not emit an empty/duplicate "server2" section.
54 $test->{"server2"} = { };
56 if (defined $test->{"resume_server"}) {
57 $test->{"resume_server"} = { (%ssltests::base_server, %{$test->{"resume_server"}}) };
59 if (defined $test->{"test"}->{"HandshakeMode"} &&
60 $test->{"test"}->{"HandshakeMode"} eq "Resume") {
61 # Default is the same as server.
62 $test->{"reuse_resume_server"} = 1;
64 # Do not emit an empty/duplicate "resume-server" section.
65 $test->{"resume_server"} = { };
67 $test->{"client"} = { (%ssltests::base_client, %{$test->{"client"}}) };
68 if (defined $test->{"resume_client"}) {
69 $test->{"resume_client"} = { (%ssltests::base_client, %{$test->{"resume_client"}}) };
71 if (defined $test->{"test"}->{"HandshakeMode"} &&
72 $test->{"test"}->{"HandshakeMode"} eq "Resume") {
73 # Default is the same as client.
74 $test->{"reuse_resume_client"} = 1;
76 # Do not emit an empty/duplicate "resume-client" section.
77 $test->{"resume_client"} = { };
81 # ssl_test expects to find a
85 # directive in the file. It'll then look for configuration directives
86 # for n tests, that each look like this:
88 # test-n = test-section
91 # (SSL modules for client and server configuration go here.)
94 # (Test configuration goes here.)
95 print "num_tests = $num\n\n";
97 # The conf module locations must come before everything else, because
100 # test-n = test-section
102 # and you can't mix and match them with sections.
105 foreach my $test (@ssltests::tests) {
106 my $testname = "${idx}-" . $test->{'name'};
107 print "test-$idx = $testname\n";
113 foreach my $test (@ssltests::tests) {
114 my $testname = "${idx}-" . $test->{'name'};
115 my $text = $template->fill_in(
116 HASH => [{ idx => $idx, testname => $testname } , $test],
117 DELIMITERS => [ "{-", "-}" ]);
118 print "# ===========================================================\n\n";
124 # Shamelessly copied from Configure.
127 open(INPUT, "< $fname") or die "Can't open input file '$fname'!\n";
129 my $content = <INPUT>;
135 my $input_file = shift;
136 # Reads the tests into ssltests::tests.
137 read_config($input_file);