selftest.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/usr/local/bin/perl -w
  2. #
  3. # Run the test suite and generate a report
  4. #
  5. if (! -f "Configure") {
  6. print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
  7. exit 1;
  8. }
  9. my $report="testlog";
  10. my $os="??";
  11. my $version="??";
  12. my $platform0="??";
  13. my $platform="??";
  14. my $options="??";
  15. my $last="??";
  16. my $ok=0;
  17. my $cc="cc";
  18. my $cversion="??";
  19. my $sep="-----------------------------------------------------------------------------\n";
  20. my $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";
  21. open(OUT,">$report") or die;
  22. print OUT "OpenSSL self-test report:\n\n";
  23. $uname=`uname -a`;
  24. $uname="??\n" if $uname eq "";
  25. $c=`sh config -t`;
  26. foreach $_ (split("\n",$c)) {
  27. $os=$1 if (/Operating system: (.*)$/);
  28. $platform0=$1 if (/Configuring for (.*)$/);
  29. }
  30. system "sh config" if (! -f "Makefile");
  31. if (open(IN,"<Makefile")) {
  32. while (<IN>) {
  33. $version=$1 if (/^VERSION=(.*)$/);
  34. $platform=$1 if (/^PLATFORM=(.*)$/);
  35. $options=$1 if (/^OPTIONS=(.*)$/);
  36. $cc=$1 if (/^CC= *(.*)$/);
  37. }
  38. close(IN);
  39. } else {
  40. print OUT "Error running config!\n";
  41. }
  42. $cversion=`$cc -v 2>&1`;
  43. $cversion=`$cc -V 2>&1` if $cversion =~ "[Uu]sage";
  44. $cversion=`$cc -V |head -1` if $cversion =~ "Error";
  45. $cversion=`$cc --version` if $cversion eq "";
  46. $cversion =~ s/Reading specs.*\n//;
  47. $cversion =~ s/usage.*\n//;
  48. chomp $cversion;
  49. if (open(IN,"<CHANGES")) {
  50. while(<IN>) {
  51. if (/\*\) (.{0,55})/ && !/applies to/) {
  52. $last=$1;
  53. last;
  54. }
  55. }
  56. close(IN);
  57. }
  58. print OUT "OpenSSL version: $version\n";
  59. print OUT "Last change: $last...\n";
  60. print OUT "Options: $options\n" if $options ne "";
  61. print OUT "OS (uname): $uname";
  62. print OUT "OS (config): $os\n";
  63. print OUT "Target (default): $platform0\n";
  64. print OUT "Target: $platform\n";
  65. print OUT "Compiler: $cversion\n";
  66. print OUT "\n";
  67. print "Checking compiler...\n";
  68. if (open(TEST,">cctest.c")) {
  69. print TEST "#include <stdio.h>\n#include <errno.h>\nmain(){printf(\"Hello world\\n\");}\n";
  70. close(TEST);
  71. system("$cc -o cctest cctest.c");
  72. if (`./cctest` !~ /Hello world/) {
  73. print OUT "Compiler doesn't work.\n";
  74. print OUT $not_our_fault;
  75. goto err;
  76. }
  77. system("ar r cctest.a /dev/null");
  78. if (not -f "cctest.a") {
  79. print OUT "Check your archive tool (ar).\n";
  80. print OUT $not_our_fault;
  81. goto err;
  82. }
  83. } else {
  84. print OUT "Can't create cctest.c\n";
  85. }
  86. if (open(TEST,">cctest.c")) {
  87. print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
  88. close(TEST);
  89. system("$cc -o cctest -Iinclude cctest.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. print OUT $not_our_fault;
  98. goto err;
  99. }
  100. } else {
  101. print OUT "Can't create cctest.c\n";
  102. }
  103. print "Running make...\n";
  104. if (system("make 2>&1 | tee make.log") > 255) {
  105. print OUT "make failed!\n";
  106. if (open(IN,"<make.log")) {
  107. print OUT $sep;
  108. while (<IN>) {
  109. print OUT;
  110. }
  111. close(IN);
  112. print OUT $sep;
  113. } else {
  114. print OUT "make.log not found!\n";
  115. }
  116. goto err;
  117. }
  118. # Not sure why this is here. The tests themselves can detect if their
  119. # particular feature isn't included, and should therefore skip themselves.
  120. # To skip *all* tests just because one algorithm isn't included is like
  121. # shooting mosquito with an elephant gun...
  122. # -- Richard Levitte, inspired by problem report 1089
  123. #
  124. #$_=$options;
  125. #s/no-asm//;
  126. #s/no-shared//;
  127. #s/no-krb5//;
  128. #if (/no-/)
  129. #{
  130. # print OUT "Test skipped.\n";
  131. # goto err;
  132. #}
  133. print "Running make test...\n";
  134. if (system("make test 2>&1 | tee maketest.log") > 255)
  135. {
  136. print OUT "make test failed!\n";
  137. } else {
  138. $ok=1;
  139. }
  140. if ($ok and open(IN,"<maketest.log")) {
  141. while (<IN>) {
  142. $ok=2 if /^platform: $platform/;
  143. }
  144. close(IN);
  145. }
  146. if ($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. if (open(IN,"<maketest.log")) {
  159. while (<IN>) {
  160. print OUT;
  161. }
  162. close(IN);
  163. print OUT $sep;
  164. } else {
  165. print OUT "maketest.log not found!\n";
  166. }
  167. } else {
  168. print OUT "Test passed.\n";
  169. }
  170. err:
  171. close(OUT);
  172. print "\n";
  173. open(IN,"<$report") or die;
  174. while (<IN>) {
  175. if (/$sep/) {
  176. print "[...]\n";
  177. last;
  178. }
  179. print;
  180. }
  181. print "\nTest report in file $report\n";