80-test_ssl_new.t 2.8 KB
Newer Older
R
Rich Salz 已提交
1 2 3 4 5 6 7 8
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (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

E
Emilia Kasper 已提交
9 10 11 12 13 14

use strict;
use warnings;

use File::Basename;
use File::Compare qw/compare_text/;
15
use if $^O ne "VMS", 'File::Glob' => qw/glob/;
E
Emilia Kasper 已提交
16 17 18 19 20 21 22 23

use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file/;
use OpenSSL::Test::Utils qw/disabled alldisabled available_protocols/;

setup("test_ssl_new");

$ENV{TEST_CERTS_DIR} = srctop_dir("test", "certs");

24
my @conf_srcs =  glob(srctop_file("test", "ssl-tests", "*.conf.in"));
R
Richard Levitte 已提交
25
map { s/;.*// } @conf_srcs if $^O eq "VMS";
26 27
my @conf_files = map { basename($_) } @conf_srcs;
map { s/\.in// } @conf_files;
E
Emilia Kasper 已提交
28 29 30 31 32 33 34 35 36 37

# 02-protocol-version.conf test results depend on the configuration of enabled
# protocols. We only verify generated sources in the default configuration.
my $is_default = (disabled("ssl3") && !disabled("tls1") &&
                  !disabled("tls1_1") && !disabled("tls1_2"));

my %conf_dependent_tests = ("02-protocol-version.conf" => 1);

foreach my $conf (@conf_files) {
    subtest "Test configuration $conf" => sub {
38 39
        test_conf($conf,
                  $conf_dependent_tests{$conf} || $^O eq "VMS" ?  0 : 1);
E
Emilia Kasper 已提交
40 41 42 43 44
    }
}

# We hard-code the number of tests to double-check that the globbing above
# finds all files as expected.
T
Todd Short 已提交
45
plan tests => 6;  # = scalar @conf_srcs
E
Emilia Kasper 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

sub test_conf {
    plan tests => 3;

    my ($conf, $check_source) = @_;

    my $conf_file = srctop_file("test", "ssl-tests", $conf);
    my $tmp_file = "${conf}.$$.tmp";
    my $run_test = 1;

  SKIP: {
      # "Test" 1. Generate the source.
      my $input_file = $conf_file . ".in";

      skip 'failure', 2 unless
        ok(run(perltest(["generate_ssl_tests.pl", $input_file],
62
                        interpreter_args => [ "-I", srctop_dir("test", "testlib")],
E
Emilia Kasper 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
                        stdout => $tmp_file)),
           "Getting output from generate_ssl_tests.pl.");

    SKIP: {
        # Test 2. Compare against existing output in test/ssl_tests.conf.
        skip "Skipping generated source test for $conf", 1
          if !$check_source;

        $run_test = is(cmp_text($tmp_file, $conf_file), 0,
                       "Comparing generated sources.");
      }

      # Test 3. Run the test.
      my $no_tls = alldisabled(available_protocols("tls"));
      skip "No TLS tests available; skipping tests", 1 if $no_tls;
      skip "Stale sources; skipping tests", 1 if !$run_test;

      ok(run(test(["ssl_test", $tmp_file])), "running ssl_test $conf");
    }

    unlink glob $tmp_file;
}

sub cmp_text {
    return compare_text(@_, sub {
        $_[0] =~ s/\R//g;
        $_[1] =~ s/\R//g;
        return $_[0] ne $_[1];
    });
}