1 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 # Licensed under the OpenSSL license (the "License"). You may not use
4 # this file except in compliance with the License. You can obtain a copy
5 # in the file LICENSE in the source distribution or at
6 # https://www.openssl.org/source/license.html
8 package OpenSSL::Test::Utils;
14 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
17 @EXPORT = qw(alldisabled anydisabled disabled config available_protocols
22 OpenSSL::Test::Utils - test utility functions
26 use OpenSSL::Test::Utils;
28 my @tls = available_protocols("tls");
29 my @dtls = available_protocols("dtls");
30 alldisabled("dh", "dsa");
31 anydisabled("dh", "dsa");
40 This module provides utility functions for the testing framework.
44 use OpenSSL::Test qw/:DEFAULT bldtop_file/;
48 =item B<available_protocols STRING>
50 Returns a list of strings for all the available SSL/TLS versions if
51 STRING is "tls", or for all the available DTLS versions if STRING is
52 "dtls". Otherwise, it returns the empty list. The strings in the
53 returned list can be used with B<alldisabled> and B<anydisabled>.
55 =item B<alldisabled ARRAY>
56 =item B<anydisabled ARRAY>
58 In an array context returns an array with each element set to 1 if the
59 corresponding feature is disabled and 0 otherwise.
61 In a scalar context, alldisabled returns 1 if all of the features in
62 ARRAY are disabled, while anydisabled returns 1 if any of them are
65 =item B<config STRING>
67 Returns an item from the %config hash in \$TOP/configdata.pm.
72 Return true if IPv4 / IPv6 is possible to use on the current system.
78 our %available_protocols;
81 my $configdata_loaded = 0;
84 # We eval it so it doesn't run at compile time of this file.
85 # The latter would have bldtop_file() complain that setup() hasn't
87 my $configdata = bldtop_file("configdata.pm");
88 eval { require $configdata;
89 %available_protocols = %configdata::available_protocols;
90 %disabled = %configdata::disabled;
91 %config = %configdata::config;
93 $configdata_loaded = 1;
97 # list of 1s and 0s, coming from check_disabled()
100 foreach (@_) { $x += $_ }
105 # list of 1s and 0s, coming from check_disabled()
108 foreach (@_) { $x *= $_ }
113 # list of strings, all of them should be names of features
114 # that can be disabled.
115 # returns a list of 1s (if the corresponding feature is disabled)
116 # and 0s (if it isn't)
118 return map { exists $disabled{lc $_} ? 1 : 0 } @_;
121 # Exported functions #################################################
124 # list of features to check
126 load_configdata() unless $configdata_loaded;
127 my @ret = check_disabled(@_);
128 return @ret if wantarray;
133 # list of features to check
135 load_configdata() unless $configdata_loaded;
136 my @ret = check_disabled(@_);
137 return @ret if wantarray;
141 # !!! Kept for backward compatibility
148 sub available_protocols {
149 load_configdata() unless $configdata_loaded;
150 my $protocol_class = shift;
151 if (exists $available_protocols{lc $protocol_class}) {
152 return @{$available_protocols{lc $protocol_class}}
158 load_configdata() unless $configdata_loaded;
159 return $config{$_[0]};
162 # IPv4 / IPv6 checker
167 my $listenaddress = shift;
170 require IO::Socket::IP;
171 my $s = IO::Socket::IP->new(
172 LocalAddr => $listenaddress,
184 require IO::Socket::INET6;
185 my $s = IO::Socket::INET6->new(
186 LocalAddr => $listenaddress,
198 require IO::Socket::INET;
199 my $s = IO::Socket::INET->new(
200 LocalAddr => $listenaddress,
215 if ($have_IPv4 < 0) {
216 $have_IPv4 = check_IP("127.0.0.1");
222 if ($have_IPv6 < 0) {
223 $have_IPv6 = check_IP("::1");
235 Stephen Henson E<lt>steve@openssl.orgE<gt> and
236 Richard Levitte E<lt>levitte@openssl.orgE<gt>