]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/selftest.pl
Copyright consolidation: perl files
[thirdparty/openssl.git] / util / selftest.pl
CommitLineData
e0a65194
RS
1#! /usr/bin/env perl
2# Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
720b590f 3#
e0a65194
RS
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
720b590f 9# Run the test suite and generate a report
720b590f
UM
10
11if (! -f "Configure") {
12 print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
13 exit 1;
14}
15
16my $report="testlog";
17my $os="??";
18my $version="??";
19my $platform0="??";
20my $platform="??";
21my $options="??";
22my $last="??";
23my $ok=0;
24my $cc="cc";
d7f0ab5f 25my $cversion="??";
720b590f 26my $sep="-----------------------------------------------------------------------------\n";
e7cae747 27my $not_our_fault="\nPlease ask your system administrator/vendor for more information.\n[Problems with your operating system setup should not be reported\nto the OpenSSL project.]\n";
720b590f
UM
28
29open(OUT,">$report") or die;
30
31print OUT "OpenSSL self-test report:\n\n";
32
33$uname=`uname -a`;
c7fecee8 34$uname="??\n" if $uname eq "";
720b590f
UM
35
36$c=`sh config -t`;
37foreach $_ (split("\n",$c)) {
38 $os=$1 if (/Operating system: (.*)$/);
39 $platform0=$1 if (/Configuring for (.*)$/);
40}
41
69af4fae 42system "sh config" if (! -f "Makefile");
720b590f 43
69af4fae 44if (open(IN,"<Makefile")) {
720b590f
UM
45 while (<IN>) {
46 $version=$1 if (/^VERSION=(.*)$/);
47 $platform=$1 if (/^PLATFORM=(.*)$/);
48 $options=$1 if (/^OPTIONS=(.*)$/);
d7f0ab5f 49 $cc=$1 if (/^CC= *(.*)$/);
720b590f
UM
50 }
51 close(IN);
52} else {
d7f0ab5f 53 print OUT "Error running config!\n";
720b590f
UM
54}
55
d7f0ab5f 56$cversion=`$cc -v 2>&1`;
7a5ad5d5 57$cversion=`$cc -V 2>&1` if $cversion =~ "[Uu]sage";
7b4c588f 58$cversion=`$cc -V |head -1` if $cversion =~ "Error";
4c5fac4a 59$cversion=`$cc --version` if $cversion eq "";
d7f0ab5f
UM
60$cversion =~ s/Reading specs.*\n//;
61$cversion =~ s/usage.*\n//;
9ba96fbb 62$cversion =~ s|\R$||;
d7f0ab5f 63
720b590f
UM
64if (open(IN,"<CHANGES")) {
65 while(<IN>) {
e29f478a 66 if (/\*\) (.{0,55})/ && !/applies to/) {
720b590f
UM
67 $last=$1;
68 last;
69 }
70 }
71 close(IN);
72}
73
74print OUT "OpenSSL version: $version\n";
75print OUT "Last change: $last...\n";
4c5fac4a 76print OUT "Options: $options\n" if $options ne "";
720b590f
UM
77print OUT "OS (uname): $uname";
78print OUT "OS (config): $os\n";
79print OUT "Target (default): $platform0\n";
80print OUT "Target: $platform\n";
d7f0ab5f 81print OUT "Compiler: $cversion\n";
720b590f
UM
82print OUT "\n";
83
84print "Checking compiler...\n";
331b5921 85if (open(TEST,">cctest.c")) {
e5fa864f 86 print TEST "#include <stdio.h>\n#include <stdlib.h>\n#include <errno.h>\nmain(){printf(\"Hello world\\n\");}\n";
720b590f 87 close(TEST);
331b5921 88 system("$cc -o cctest cctest.c");
71308c3b 89 if (`./cctest` !~ /Hello world/) {
720b590f 90 print OUT "Compiler doesn't work.\n";
e7cae747 91 print OUT $not_our_fault;
720b590f
UM
92 goto err;
93 }
b313adc4 94 system("ar r cctest.a /dev/null");
c7fecee8 95 if (not -f "cctest.a") {
0cff2550 96 print OUT "Check your archive tool (ar).\n";
e7cae747 97 print OUT $not_our_fault;
c7fecee8
UM
98 goto err;
99 }
720b590f 100} else {
331b5921 101 print OUT "Can't create cctest.c\n";
720b590f 102}
331b5921 103if (open(TEST,">cctest.c")) {
e5fa864f 104 print TEST "#include <stdio.h>\n#include <stdlib.h>\n#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
720b590f 105 close(TEST);
331b5921 106 system("$cc -o cctest -Iinclude cctest.c");
720b590f
UM
107 $cctest = `./cctest`;
108 if ($cctest !~ /OpenSSL $version/) {
109 if ($cctest =~ /OpenSSL/) {
110 print OUT "#include uses headers from different OpenSSL version!\n";
111 } else {
112 print OUT "Can't compile test program!\n";
113 }
e7cae747 114 print OUT $not_our_fault;
720b590f
UM
115 goto err;
116 }
117} else {
331b5921 118 print OUT "Can't create cctest.c\n";
720b590f
UM
119}
120
121print "Running make...\n";
122if (system("make 2>&1 | tee make.log") > 255) {
123
124 print OUT "make failed!\n";
125 if (open(IN,"<make.log")) {
126 print OUT $sep;
127 while (<IN>) {
128 print OUT;
129 }
130 close(IN);
131 print OUT $sep;
132 } else {
133 print OUT "make.log not found!\n";
134 }
135 goto err;
136}
137
34f0b264
RL
138# Not sure why this is here. The tests themselves can detect if their
139# particular feature isn't included, and should therefore skip themselves.
140# To skip *all* tests just because one algorithm isn't included is like
141# shooting mosquito with an elephant gun...
142# -- Richard Levitte, inspired by problem report 1089
143#
144#$_=$options;
145#s/no-asm//;
146#s/no-shared//;
147#s/no-krb5//;
148#if (/no-/)
149#{
150# print OUT "Test skipped.\n";
151# goto err;
152#}
4c5fac4a 153
720b590f 154print "Running make test...\n";
c7fecee8 155if (system("make test 2>&1 | tee maketest.log") > 255)
720b590f
UM
156 {
157 print OUT "make test failed!\n";
158} else {
159 $ok=1;
160}
161
c7fecee8 162if ($ok and open(IN,"<maketest.log")) {
720b590f
UM
163 while (<IN>) {
164 $ok=2 if /^platform: $platform/;
165 }
166 close(IN);
167}
168
169if ($ok != 2) {
170 print OUT "Failure!\n";
171 if (open(IN,"<make.log")) {
172 print OUT $sep;
173 while (<IN>) {
174 print OUT;
175 }
176 close(IN);
177 print OUT $sep;
178 } else {
179 print OUT "make.log not found!\n";
180 }
c7fecee8
UM
181 if (open(IN,"<maketest.log")) {
182 while (<IN>) {
183 print OUT;
184 }
185 close(IN);
186 print OUT $sep;
187 } else {
188 print OUT "maketest.log not found!\n";
189 }
720b590f
UM
190} else {
191 print OUT "Test passed.\n";
192}
193err:
194close(OUT);
195
196print "\n";
197open(IN,"<$report") or die;
198while (<IN>) {
4c5fac4a
UM
199 if (/$sep/) {
200 print "[...]\n";
201 last;
202 }
720b590f
UM
203 print;
204}
4c5fac4a 205print "\nTest report in file $report\n";
d7f0ab5f 206
e36ce2d9 207die if $ok != 2;