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