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"; 22my $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 24open(OUT,">$report") or die; 25 26print OUT "OpenSSL self-test report:\n\n"; 27 28$uname=`uname -a`; 29$uname="??\n" if $uname eq ""; 30 31$c=`sh config -t`; 32foreach $_ (split("\n",$c)) { 33 $os=$1 if (/Operating system: (.*)$/); 34 $platform0=$1 if (/Configuring for (.*)$/); 35} 36 37system "sh config" if (! -f "Makefile"); 38 39if (open(IN,"<Makefile")) { 40 while (<IN>) { 41 $version=$1 if (/^VERSION=(.*)$/); 42 $platform=$1 if (/^PLATFORM=(.*)$/); 43 $options=$1 if (/^OPTIONS=(.*)$/); 44 $cc=$1 if (/^CC= *(.*)$/); 45 } 46 close(IN); 47} else { 48 print OUT "Error running config!\n"; 49} 50 51$cversion=`$cc -v 2>&1`; 52$cversion=`$cc -V 2>&1` if $cversion =~ "usage"; 53$cversion=`$cc -V |head -1` if $cversion =~ "Error"; 54$cversion=`$cc --version` if $cversion eq ""; 55$cversion =~ s/Reading specs.*\n//; 56$cversion =~ s/usage.*\n//; 57chomp $cversion; 58 59if (open(IN,"<CHANGES")) { 60 while(<IN>) { 61 if (/\*\) (.{0,55})/ && !/applies to/) { 62 $last=$1; 63 last; 64 } 65 } 66 close(IN); 67} 68 69print OUT "OpenSSL version: $version\n"; 70print OUT "Last change: $last...\n"; 71print OUT "Options: $options\n" if $options ne ""; 72print OUT "OS (uname): $uname"; 73print OUT "OS (config): $os\n"; 74print OUT "Target (default): $platform0\n"; 75print OUT "Target: $platform\n"; 76print OUT "Compiler: $cversion\n"; 77print OUT "\n"; 78 79print "Checking compiler...\n"; 80if (open(TEST,">cctest.c")) { 81 print TEST "#include <stdio.h>\n#include <errno.h>\nmain(){printf(\"Hello world\\n\");}\n"; 82 close(TEST); 83 system("$cc -o cctest cctest.c"); 84 if (`./cctest` !~ /Hello world/) { 85 print OUT "Compiler doesn't work.\n"; 86 print OUT $not_our_fault; 87 goto err; 88 } 89 system("ar r cctest.a /dev/null"); 90 if (not -f "cctest.a") { 91 print OUT "Check your archive tool (ar).\n"; 92 print OUT $not_our_fault; 93 goto err; 94 } 95} else { 96 print OUT "Can't create cctest.c\n"; 97} 98if (open(TEST,">cctest.c")) { 99 print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n"; 100 close(TEST); 101 system("$cc -o cctest -Iinclude cctest.c"); 102 $cctest = `./cctest`; 103 if ($cctest !~ /OpenSSL $version/) { 104 if ($cctest =~ /OpenSSL/) { 105 print OUT "#include uses headers from different OpenSSL version!\n"; 106 } else { 107 print OUT "Can't compile test program!\n"; 108 } 109 print OUT $not_our_fault; 110 goto err; 111 } 112} else { 113 print OUT "Can't create cctest.c\n"; 114} 115 116print "Running make...\n"; 117if (system("make 2>&1 | tee make.log") > 255) { 118 119 print OUT "make failed!\n"; 120 if (open(IN,"<make.log")) { 121 print OUT $sep; 122 while (<IN>) { 123 print OUT; 124 } 125 close(IN); 126 print OUT $sep; 127 } else { 128 print OUT "make.log not found!\n"; 129 } 130 goto err; 131} 132 133$_=$options; 134s/no-asm//; 135s/no-shared//; 136s/no-krb5//; 137if (/no-/) 138{ 139 print OUT "Test skipped.\n"; 140 goto err; 141} 142 143print "Running make test...\n"; 144if (system("make test 2>&1 | tee maketest.log") > 255) 145 { 146 print OUT "make test failed!\n"; 147} else { 148 $ok=1; 149} 150 151if ($ok and open(IN,"<maketest.log")) { 152 while (<IN>) { 153 $ok=2 if /^platform: $platform/; 154 } 155 close(IN); 156} 157 158if ($ok != 2) { 159 print OUT "Failure!\n"; 160 if (open(IN,"<make.log")) { 161 print OUT $sep; 162 while (<IN>) { 163 print OUT; 164 } 165 close(IN); 166 print OUT $sep; 167 } else { 168 print OUT "make.log not found!\n"; 169 } 170 if (open(IN,"<maketest.log")) { 171 while (<IN>) { 172 print OUT; 173 } 174 close(IN); 175 print OUT $sep; 176 } else { 177 print OUT "maketest.log not found!\n"; 178 } 179} else { 180 print OUT "Test passed.\n"; 181} 182err: 183close(OUT); 184 185print "\n"; 186open(IN,"<$report") or die; 187while (<IN>) { 188 if (/$sep/) { 189 print "[...]\n"; 190 last; 191 } 192 print; 193} 194print "\nTest report in file $report\n"; 195 196