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