summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/util/selftest.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/util/selftest.pl')
-rw-r--r--src/lib/libcrypto/util/selftest.pl174
1 files changed, 174 insertions, 0 deletions
diff --git a/src/lib/libcrypto/util/selftest.pl b/src/lib/libcrypto/util/selftest.pl
new file mode 100644
index 0000000000..91e962a312
--- /dev/null
+++ b/src/lib/libcrypto/util/selftest.pl
@@ -0,0 +1,174 @@
1#!/usr/local/bin/perl -w
2#
3# Run the test suite and generate a report
4#
5
6if (! -f "Configure") {
7 print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
8 exit 1;
9}
10
11my $report="testlog";
12my $os="??";
13my $version="??";
14my $platform0="??";
15my $platform="??";
16my $options="??";
17my $last="??";
18my $ok=0;
19my $cc="cc";
20my $cversion="??";
21my $sep="-----------------------------------------------------------------------------\n";
22
23open(OUT,">$report") or die;
24
25print OUT "OpenSSL self-test report:\n\n";
26
27$uname=`uname -a`;
28$uname="??" if $uname eq "";
29
30$c=`sh config -t`;
31foreach $_ (split("\n",$c)) {
32 $os=$1 if (/Operating system: (.*)$/);
33 $platform0=$1 if (/Configuring for (.*)$/);
34}
35
36system "sh config" if (! -f "Makefile.ssl");
37
38if (open(IN,"<Makefile.ssl")) {
39 while (<IN>) {
40 $version=$1 if (/^VERSION=(.*)$/);
41 $platform=$1 if (/^PLATFORM=(.*)$/);
42 $options=$1 if (/^OPTIONS=(.*)$/);
43 $cc=$1 if (/^CC= *(.*)$/);
44 }
45 close(IN);
46} else {
47 print OUT "Error running config!\n";
48}
49
50$cversion=`$cc -v 2>&1`;
51$cversion=`$cc -V 2>&1` if $cversion =~ "usage";
52$cversion=`$cc --version` if $cversion eq "";
53$cversion =~ s/Reading specs.*\n//;
54$cversion =~ s/usage.*\n//;
55chomp $cversion;
56
57if (open(IN,"<CHANGES")) {
58 while(<IN>) {
59 if (/\*\) (.{0,55})/) {
60 $last=$1;
61 last;
62 }
63 }
64 close(IN);
65}
66
67print OUT "OpenSSL version: $version\n";
68print OUT "Last change: $last...\n";
69print OUT "Options: $options\n" if $options ne "";
70print OUT "OS (uname): $uname";
71print OUT "OS (config): $os\n";
72print OUT "Target (default): $platform0\n";
73print OUT "Target: $platform\n";
74print OUT "Compiler: $cversion\n";
75print OUT "\n";
76
77print "Checking compiler...\n";
78if (open(TEST,">cctest.c")) {
79 print TEST "#include <stdio.h>\nmain(){printf(\"Hello world\\n\");}\n";
80 close(TEST);
81 system("$cc -o cctest cctest.c");
82 if (`./cctest` !~ /Hello world/) {
83 print OUT "Compiler doesn't work.\n";
84 goto err;
85 }
86} else {
87 print OUT "Can't create cctest.c\n";
88}
89if (open(TEST,">cctest.c")) {
90 print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
91 close(TEST);
92 system("$cc -o cctest -Iinclude cctest.c");
93 $cctest = `./cctest`;
94 if ($cctest !~ /OpenSSL $version/) {
95 if ($cctest =~ /OpenSSL/) {
96 print OUT "#include uses headers from different OpenSSL version!\n";
97 } else {
98 print OUT "Can't compile test program!\n";
99 }
100 goto err;
101 }
102} else {
103 print OUT "Can't create cctest.c\n";
104}
105
106print "Running make...\n";
107if (system("make 2>&1 | tee make.log") > 255) {
108
109 print OUT "make failed!\n";
110 if (open(IN,"<make.log")) {
111 print OUT $sep;
112 while (<IN>) {
113 print OUT;
114 }
115 close(IN);
116 print OUT $sep;
117 } else {
118 print OUT "make.log not found!\n";
119 }
120 goto err;
121}
122
123$_=$options;
124s/no-asm//;
125if (/no-/)
126{
127 print OUT "Test skipped.\n";
128 goto err;
129}
130
131print "Running make test...\n";
132if (system("make test 2>&1 | tee make.log") > 255)
133 {
134 print OUT "make test failed!\n";
135} else {
136 $ok=1;
137}
138
139if ($ok and open(IN,"<make.log")) {
140 while (<IN>) {
141 $ok=2 if /^platform: $platform/;
142 }
143 close(IN);
144}
145
146if ($ok != 2) {
147 print OUT "Failure!\n";
148 if (open(IN,"<make.log")) {
149 print OUT $sep;
150 while (<IN>) {
151 print OUT;
152 }
153 close(IN);
154 print OUT $sep;
155 } else {
156 print OUT "make.log not found!\n";
157 }
158} else {
159 print OUT "Test passed.\n";
160}
161err:
162close(OUT);
163
164print "\n";
165open(IN,"<$report") or die;
166while (<IN>) {
167 if (/$sep/) {
168 print "[...]\n";
169 last;
170 }
171 print;
172}
173print "\nTest report in file $report\n";
174