2
0

generate_ssl_tests.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #! /usr/bin/env perl
  2. # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  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
  8. ## SSL testcase generator
  9. use strict;
  10. use warnings;
  11. use File::Basename;
  12. use File::Spec::Functions;
  13. use OpenSSL::Test qw/srctop_dir srctop_file/;
  14. use OpenSSL::Test::Utils;
  15. # This block needs to run before 'use lib srctop_dir' directives.
  16. BEGIN {
  17. OpenSSL::Test::setup("no_test_here");
  18. }
  19. use lib srctop_dir("util"); # for with_fallback
  20. use lib srctop_dir("test", "ssl-tests"); # for ssltests_base
  21. use with_fallback qw(Text::Template);
  22. use vars qw/@ISA/;
  23. push (@ISA, qw/Text::Template/);
  24. use ssltests_base;
  25. sub print_templates {
  26. my $source = srctop_file("test", "ssl_test.tmpl");
  27. my $template = Text::Template->new(TYPE => 'FILE', SOURCE => $source);
  28. print "# Generated with generate_ssl_tests.pl\n\n";
  29. my $num = scalar @ssltests::tests;
  30. # Add the implicit base configuration.
  31. foreach my $test (@ssltests::tests) {
  32. $test->{"server"} = { (%ssltests::base_server, %{$test->{"server"}}) };
  33. $test->{"client"} = { (%ssltests::base_client, %{$test->{"client"}}) };
  34. }
  35. # ssl_test expects to find a
  36. #
  37. # num_tests = n
  38. #
  39. # directive in the file. It'll then look for configuration directives
  40. # for n tests, that each look like this:
  41. #
  42. # test-n = test-section
  43. #
  44. # [test-section]
  45. # (SSL modules for client and server configuration go here.)
  46. #
  47. # [test-n]
  48. # (Test configuration goes here.)
  49. print "num_tests = $num\n\n";
  50. # The conf module locations must come before everything else, because
  51. # they look like
  52. #
  53. # test-n = test-section
  54. #
  55. # and you can't mix and match them with sections.
  56. my $idx = 0;
  57. foreach my $test (@ssltests::tests) {
  58. my $testname = "${idx}-" . $test->{'name'};
  59. print "test-$idx = $testname\n";
  60. $idx++;
  61. }
  62. $idx = 0;
  63. foreach my $test (@ssltests::tests) {
  64. my $testname = "${idx}-" . $test->{'name'};
  65. my $text = $template->fill_in(
  66. HASH => [{ idx => $idx, testname => $testname } , $test],
  67. DELIMITERS => [ "{-", "-}" ]);
  68. print "# ===========================================================\n\n";
  69. print "$text\n";
  70. $idx++;
  71. }
  72. }
  73. # Shamelessly copied from Configure.
  74. sub read_config {
  75. my $fname = shift;
  76. open(INPUT, "< $fname")
  77. or die "Can't open input file '$fname'!\n";
  78. local $/ = undef;
  79. my $content = <INPUT>;
  80. close(INPUT);
  81. eval $content;
  82. warn $@ if $@;
  83. }
  84. my $input_file = shift;
  85. # Reads the tests into ssltests::tests.
  86. read_config($input_file);
  87. print_templates();
  88. 1;