EGD info, as requested.
[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 print "Checking compiler...\n";
75 if (open(TEST,">test.c")) {
76     print TEST "#include <stdio.h>\nmain(){printf(\"Hello world\\n\");}\n";
77     close(TEST);
78     system("$cc -o cctest test.c");
79     if (`./cctest` !~ /Hello world/) {
80         print OUT "Compiler doesn't work.\n";
81         goto err;
82     }
83 } else {
84     print OUT "Can't create test.c\n";
85 }
86 if (open(TEST,">test.c")) {
87     print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
88     close(TEST);
89     system("$cc -o cctest -Iinclude test.c");
90     $cctest = `./cctest`;
91     if ($cctest !~ /OpenSSL $version/) {
92         if ($cctest =~ /OpenSSL/) {
93             print OUT "#include uses headers from different OpenSSL version!\n";
94         } else {
95             print OUT "Can't compile test program!\n";
96         }
97         goto err;
98     }
99 } else {
100     print OUT "Can't create test.c\n";
101 }
102
103 print "Running make...\n";
104 if (system("make 2>&1 | tee make.log") > 255) {
105
106     print OUT "make failed!\n";
107     if (open(IN,"<make.log")) {
108         print OUT $sep;
109         while (<IN>) {
110             print OUT;
111         }
112         close(IN);
113         print OUT $sep;
114     } else {
115         print OUT "make.log not found!\n";
116     }
117     goto err;
118 }
119
120 print "Running make test...\n";
121 if (system("make test 2>&1 | tee make.log") > 255)
122  {
123     print OUT "make test failed!\n";
124 } else {
125     $ok=1;
126 }
127
128 if ($ok and open(IN,"<make.log")) {
129     while (<IN>) {
130         $ok=2 if /^platform: $platform/;
131     }
132     close(IN);
133 }
134
135 if ($ok != 2) {
136     print OUT "Failure!\n";
137     if (open(IN,"<make.log")) {
138         print OUT $sep;
139         while (<IN>) {
140             print OUT;
141         }
142         close(IN);
143         print OUT $sep;
144     } else {
145         print OUT "make.log not found!\n";
146     }
147 } else {
148     print OUT "Test passed.\n";
149 }
150 err:
151 close(OUT);
152
153 print "\n";
154 open(IN,"<$report") or die;
155 while (<IN>) {
156     last if /$sep/;
157     print;
158 }
159 print "Test report in file $report\n";
160