1 # Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
3 # Licensed under the Apache License 2.0 (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>
57 =item B<anydisabled ARRAY>
59 In an array context returns an array with each element set to 1 if the
60 corresponding feature is disabled and 0 otherwise.
62 In a scalar context, alldisabled returns 1 if all of the features in
63 ARRAY are disabled, while anydisabled returns 1 if any of them are
66 =item B<config STRING>
68 Returns an item from the %config hash in \$TOP/configdata.pm.
74 Return true if IPv4 / IPv6 is possible to use on the current system.
80 our %available_protocols;
83 my $configdata_loaded = 0;
86 # We eval it so it doesn't run at compile time of this file.
87 # The latter would have bldtop_file() complain that setup() hasn't
89 my $configdata = bldtop_file("configdata.pm");
90 eval { require $configdata;
91 %available_protocols = %configdata::available_protocols;
92 %disabled = %configdata::disabled;
93 %config = %configdata::config;
95 $configdata_loaded = 1;
99 # list of 1s and 0s, coming from check_disabled()
102 foreach (@_) { $x += $_ }
107 # list of 1s and 0s, coming from check_disabled()
110 foreach (@_) { $x *= $_ }
115 # list of strings, all of them should be names of features
116 # that can be disabled.
117 # returns a list of 1s (if the corresponding feature is disabled)
118 # and 0s (if it isn't)
120 return map { exists $disabled{lc $_} ? 1 : 0 } @_;
123 # Exported functions #################################################
126 # list of features to check
128 load_configdata() unless $configdata_loaded;
129 my @ret = check_disabled(@_);
130 return @ret if wantarray;
135 # list of features to check
137 load_configdata() unless $configdata_loaded;
138 my @ret = check_disabled(@_);
139 return @ret if wantarray;
143 # !!! Kept for backward compatibility
150 sub available_protocols {
151 load_configdata() unless $configdata_loaded;
152 my $protocol_class = shift;
153 if (exists $available_protocols{lc $protocol_class}) {
154 return @{$available_protocols{lc $protocol_class}}
160 load_configdata() unless $configdata_loaded;
161 return $config{$_[0]};
164 # IPv4 / IPv6 checker
169 my $listenaddress = shift;
172 require IO::Socket::IP;
173 my $s = IO::Socket::IP->new(
174 LocalAddr => $listenaddress,
186 require IO::Socket::INET6;
187 my $s = IO::Socket::INET6->new(
188 LocalAddr => $listenaddress,
200 require IO::Socket::INET;
201 my $s = IO::Socket::INET->new(
202 LocalAddr => $listenaddress,
217 if ($have_IPv4 < 0) {
218 $have_IPv4 = check_IP("127.0.0.1");
224 if ($have_IPv6 < 0) {
225 $have_IPv6 = check_IP("::1");
236 Stephen Henson E<lt>steve@openssl.orgE<gt> and
237 Richard Levitte E<lt>levitte@openssl.orgE<gt>