]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/testlib/OpenSSL/Test/Utils.pm
1 package OpenSSL
::Test
::Utils
;
7 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
10 @EXPORT = qw(alldisabled anydisabled disabled config available_protocols
15 OpenSSL::Test::Utils - test utility functions
19 use OpenSSL::Test::Utils;
21 my @tls = available_protocols("tls");
22 my @dtls = available_protocols("dtls");
23 alldisabled("dh", "dsa");
24 anydisabled("dh", "dsa");
33 This module provides utility functions for the testing framework.
37 use OpenSSL
::Test qw
/:DEFAULT top_file/;
41 =item B<available_protocols STRING>
43 Returns a list of strings for all the available SSL/TLS versions if
44 STRING is "tls", or for all the available DTLS versions if STRING is
45 "dtls". Otherwise, it returns the empty list. The strings in the
46 returned list can be used with B<alldisabled> and B<anydisabled>.
48 =item B<alldisabled ARRAY>
49 =item B<anydisabled ARRAY>
51 In an array context returns an array with each element set to 1 if the
52 corresponding feature is disabled and 0 otherwise.
54 In a scalar context, alldisabled returns 1 if all of the features in
55 ARRAY are disabled, while anydisabled returns 1 if any of them are
58 =item B<config STRING>
60 Returns an item from the %config hash in \$TOP/configdata.pm.
65 Return true if IPv4 / IPv6 is possible to use on the current system.
71 our %available_protocols;
74 my $configdata_loaded = 0;
77 # We eval it so it doesn't run at compile time of this file.
78 # The latter would have top_dir() complain that setup() hasn't
80 my $configdata = top_file
("configdata.pm");
81 eval { require $configdata;
82 %available_protocols = %configdata::available_protocols
;
83 %disabled = %configdata::disabled
;
84 %config = %configdata::config
;
86 $configdata_loaded = 1;
90 # list of 1s and 0s, coming from check_disabled()
93 foreach (@_) { $x += $_ }
98 # list of 1s and 0s, coming from check_disabled()
101 foreach (@_) { $x *= $_ }
106 # list of strings, all of them should be names of features
107 # that can be disabled.
108 # returns a list of 1s (if the corresponding feature is disabled)
109 # and 0s (if it isn't)
111 return map { exists $disabled{lc $_} ?
1 : 0 } @_;
114 # Exported functions #################################################
117 # list of features to check
119 load_configdata
() unless $configdata_loaded;
120 my @ret = check_disabled
(@_);
121 return @ret if wantarray;
126 # list of features to check
128 load_configdata
() unless $configdata_loaded;
129 my @ret = check_disabled
(@_);
130 return @ret if wantarray;
134 #!!! Kept for backward compatibility
141 sub available_protocols
{
142 load_configdata
() unless $configdata_loaded;
143 my $protocol_class = shift;
144 if (exists $available_protocols{lc $protocol_class}) {
145 return @
{$available_protocols{lc $protocol_class}}
151 return $config{$_[0]};
154 # IPv4 / IPv6 checker
159 my $listenaddress = shift;
162 require IO
::Socket
::IP
;
163 my $s = IO
::Socket
::IP
->new(
164 LocalAddr
=> $listenaddress,
176 require IO
::Socket
::INET6
;
177 my $s = IO
::Socket
::INET6
->new(
178 LocalAddr
=> $listenaddress,
190 require IO
::Socket
::INET
;
191 my $s = IO
::Socket
::INET
->new(
192 LocalAddr
=> $listenaddress,
207 if ($have_IPv4 < 0) {
208 $have_IPv4 = check_IP
("127.0.0.1");
214 if ($have_IPv6 < 0) {
215 $have_IPv6 = check_IP
("::1");
227 Stephen Henson E<lt>steve@openssl.orgE<gt> and
228 Richard Levitte E<lt>levitte@openssl.orgE<gt>