*** empty log message ***
[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 $sep="-----------------------------------------------------------------------------\n";
21
22 open(OUT,">$report") or die;
23
24 print OUT "OpenSSL self-test report:\n\n";
25
26 $uname=`uname -a`;
27
28 $c=`sh config -t`;
29 foreach $_ (split("\n",$c)) {
30     $os=$1 if (/Operating system: (.*)$/);
31     $platform0=$1 if (/Configuring for (.*)$/);
32 }
33
34 system "sh config" if (! -f "Makefile.ssl");
35
36 if (open(IN,"<Makefile.ssl")) {
37     while (<IN>) {
38         $version=$1 if (/^VERSION=(.*)$/);
39         $platform=$1 if (/^PLATFORM=(.*)$/);
40         $options=$1 if (/^OPTIONS=(.*)$/);
41         $cc=$1 if (/^CC=(.*)$/);
42     }
43     close(IN);
44 } else {
45     print OUT "Error running config: no Makefile.ssl!\n";
46 }
47
48 if (open(IN,"<CHANGES")) {
49     while(<IN>) {
50         if (/\*\) (.{0,55})/) {
51             $last=$1;
52             last;
53         }
54     }
55     close(IN);
56 }
57
58 print OUT "OpenSSL version:  $version\n";
59 print OUT "Last change:      $last...\n";
60 print OUT "OS (uname):       $uname";
61 print OUT "OS (config):      $os\n";
62 print OUT "Target (default): $platform0\n";
63 print OUT "Target:           $platform\n";
64 print OUT "\n";
65
66 print "Checking compiler...\n";
67 if (open(TEST,">test.c")) {
68     print TEST "#include <stdio.h>\nmain(){printf(\"Hello world\\n\");}\n";
69     close(TEST);
70     system("$cc -o cctest test.c");
71     if (`./cctest` !~ /Hello world/) {
72         print OUT "Compiler doesn't work.\n";
73         goto err;
74     }
75 } else {
76     print OUT "Can't create test.c\n";
77 }
78 if (open(TEST,">test.c")) {
79     print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
80     close(TEST);
81     system("$cc -o cctest -Iinclude test.c");
82     $cctest = `./cctest`;
83     if ($cctest !~ /OpenSSL $version/) {
84         if ($cctest =~ /OpenSSL/) {
85             print OUT "#include uses headers from different OpenSSL version!\n";
86         } else {
87             print OUT "Can't compile test program!\n";
88         }
89         goto err;
90     }
91 } else {
92     print OUT "Can't create test.c\n";
93 }
94
95 print "Running make...\n";
96 if (system("make 2>&1 | tee make.log") > 255) {
97
98     print OUT "make failed!\n";
99     if (open(IN,"<make.log")) {
100         print OUT $sep;
101         while (<IN>) {
102             print OUT;
103         }
104         close(IN);
105         print OUT $sep;
106     } else {
107         print OUT "make.log not found!\n";
108     }
109     goto err;
110 }
111
112 print "Running make test...\n";
113 if (system("make test 2>&1 | tee make.log") > 255)
114  {
115     print OUT "make test failed!\n";
116 } else {
117     $ok=1;
118 }
119
120 if ($ok and open(IN,"<make.log")) {
121     while (<IN>) {
122         $ok=2 if /^platform: $platform/;
123     }
124     close(IN);
125 }
126
127 if ($ok != 2) {
128     print OUT "Failure!\n";
129     if (open(IN,"<make.log")) {
130         print OUT $sep;
131         while (<IN>) {
132             print OUT;
133         }
134         close(IN);
135         print OUT $sep;
136     } else {
137         print OUT "make.log not found!\n";
138     }
139 } else {
140     print OUT "Test passed.\n";
141 }
142 err:
143 close(OUT);
144
145 print "\n";
146 open(IN,"<$report") or die;
147 while (<IN>) {
148     last if /$sep/;
149     print;
150 }
151 print "Test report in file $report\n";