VMS: throw away [.util]shareable_image_wrap.c.in and add replacement scripts
[openssl.git] / util / selftest.pl
1 #! /usr/bin/env perl
2 # Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
9 # Run the test suite and generate a report
10
11 if (! -f "Configure") {
12     print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
13     exit 1;
14 }
15
16 my $report="testlog";
17 my $os="??";
18 my $version="??";
19 my $platform0="??";
20 my $platform="??";
21 my $options="??";
22 my $last="??";
23 my $ok=0;
24 my $cc="cc";
25 my $cversion="??";
26 my $sep="-----------------------------------------------------------------------------\n";
27 my $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";
28
29 open(OUT,">$report") or die;
30
31 print OUT "OpenSSL self-test report:\n\n";
32
33 $uname=`uname -a`;
34 $uname="??\n" if $uname eq "";
35
36 $c=`sh config -t`;
37 foreach $_ (split("\n",$c)) {
38     $os=$1 if (/Operating system: (.*)$/);
39     $platform0=$1 if (/Configuring for (.*)$/);
40 }
41
42 system "sh config" if (! -f "Makefile");
43
44 if (open(IN,"<Makefile")) {
45     while (<IN>) {
46         $version=$1 if (/^VERSION=(.*)$/);
47         $platform=$1 if (/^PLATFORM=(.*)$/);
48         $options=$1 if (/^OPTIONS=(.*)$/);
49         $cc=$1 if (/^CC= *(.*)$/);
50     }
51     close(IN);
52 } else {
53     print OUT "Error running config!\n";
54 }
55
56 $cversion=`$cc -v 2>&1`;
57 $cversion=`$cc -V 2>&1` if $cversion =~ "[Uu]sage";
58 $cversion=`$cc -V |head -1` if $cversion =~ "Error";
59 $cversion=`$cc --version` if $cversion eq "";
60 $cversion =~ s/Reading specs.*\n//;
61 $cversion =~ s/usage.*\n//;
62 $cversion =~ s|\R$||;
63
64 if (open(IN,"<CHANGES")) {
65     while(<IN>) {
66         if (/\*\) (.{0,55})/ && !/applies to/) {
67             $last=$1;
68             last;
69         }
70     }
71     close(IN);
72 }
73
74 print OUT "OpenSSL version:  $version\n";
75 print OUT "Last change:      $last...\n";
76 print OUT "Options:          $options\n" if $options ne "";
77 print OUT "OS (uname):       $uname";
78 print OUT "OS (config):      $os\n";
79 print OUT "Target (default): $platform0\n";
80 print OUT "Target:           $platform\n";
81 print OUT "Compiler:         $cversion\n";
82 print OUT "\n";
83
84 print "Checking compiler...\n";
85 if (open(TEST,">cctest.c")) {
86     print TEST "#include <stdio.h>\n#include <stdlib.h>\n#include <errno.h>\nmain(){printf(\"Hello world\\n\");}\n";
87     close(TEST);
88     system("$cc -o cctest cctest.c");
89     if (`./cctest` !~ /Hello world/) {
90         print OUT "Compiler doesn't work.\n";
91         print OUT $not_our_fault;
92         goto err;
93     }
94     system("ar r cctest.a /dev/null");
95     if (not -f "cctest.a") {
96         print OUT "Check your archive tool (ar).\n";
97         print OUT $not_our_fault;
98         goto err;
99     }
100 } else {
101     print OUT "Can't create cctest.c\n";
102 }
103 if (open(TEST,">cctest.c")) {
104     print TEST "#include <stdio.h>\n#include <stdlib.h>\n#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
105     close(TEST);
106     system("$cc -o cctest -Iinclude cctest.c");
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         }
114         print OUT $not_our_fault;
115         goto err;
116     }
117 } else {
118     print OUT "Can't create cctest.c\n";
119 }
120
121 print "Running make...\n";
122 if (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
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 #}
153
154 print "Running make test...\n";
155 if (system("make test 2>&1 | tee maketest.log") > 255)
156  {
157     print OUT "make test failed!\n";
158 } else {
159     $ok=1;
160 }
161
162 if ($ok and open(IN,"<maketest.log")) {
163     while (<IN>) {
164         $ok=2 if /^platform: $platform/;
165     }
166     close(IN);
167 }
168
169 if ($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     }
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     }
190 } else {
191     print OUT "Test passed.\n";
192 }
193 err:
194 close(OUT);
195
196 print "\n";
197 open(IN,"<$report") or die;
198 while (<IN>) {
199     if (/$sep/) {
200         print "[...]\n";
201         last;
202     }
203     print;
204 }
205 print "\nTest report in file $report\n";
206
207 die if $ok != 2;