run-test-suites.pl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/usr/bin/env perl
  2. # run-test-suites.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. #
  7. # This file is provided under the Apache License 2.0, or the
  8. # GNU General Public License v2.0 or later.
  9. #
  10. # **********
  11. # Apache License 2.0:
  12. #
  13. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  14. # not use this file except in compliance with the License.
  15. # You may obtain a copy of the License at
  16. #
  17. # http://www.apache.org/licenses/LICENSE-2.0
  18. #
  19. # Unless required by applicable law or agreed to in writing, software
  20. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. # See the License for the specific language governing permissions and
  23. # limitations under the License.
  24. #
  25. # **********
  26. #
  27. # **********
  28. # GNU General Public License v2.0 or later:
  29. #
  30. # This program is free software; you can redistribute it and/or modify
  31. # it under the terms of the GNU General Public License as published by
  32. # the Free Software Foundation; either version 2 of the License, or
  33. # (at your option) any later version.
  34. #
  35. # This program is distributed in the hope that it will be useful,
  36. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. # GNU General Public License for more details.
  39. #
  40. # You should have received a copy of the GNU General Public License along
  41. # with this program; if not, write to the Free Software Foundation, Inc.,
  42. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  43. #
  44. # **********
  45. =head1 SYNOPSIS
  46. Execute all the test suites and print a summary of the results.
  47. run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]]
  48. Options:
  49. -v|--verbose Print detailed failure information.
  50. -v 2|--verbose=2 Print detailed failure information and summary messages.
  51. -v 3|--verbose=3 Print detailed information about every test case.
  52. --skip=SUITE[,SUITE...]
  53. Skip the specified SUITE(s). This option can be used
  54. multiple times.
  55. =cut
  56. use warnings;
  57. use strict;
  58. use utf8;
  59. use open qw(:std utf8);
  60. use Getopt::Long qw(:config auto_help gnu_compat);
  61. use Pod::Usage;
  62. my $verbose = 0;
  63. my @skip_patterns = ();
  64. GetOptions(
  65. 'skip=s' => \@skip_patterns,
  66. 'verbose|v:1' => \$verbose,
  67. ) or die;
  68. # All test suites = executable files, excluding source files, debug
  69. # and profiling information, etc. We can't just grep {! /\./} because
  70. # some of our test cases' base names contain a dot.
  71. my @suites = grep { -x $_ || /\.exe$/ } glob 'test_suite_*';
  72. @suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites;
  73. die "$0: no test suite found\n" unless @suites;
  74. # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar"
  75. # but not "test_suite_foobar".
  76. my $skip_re =
  77. ( '\Atest_suite_(' .
  78. join('|', map {
  79. s/[ ,;]/|/g; # allow any of " ,;|" as separators
  80. s/\./\./g; # "." in the input means ".", not "any character"
  81. $_
  82. } @skip_patterns) .
  83. ')(\z|\.)' );
  84. # in case test suites are linked dynamically
  85. $ENV{'LD_LIBRARY_PATH'} = '../library';
  86. $ENV{'DYLD_LIBRARY_PATH'} = '../library';
  87. my $prefix = $^O eq "MSWin32" ? '' : './';
  88. my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed,
  89. $suite_cases_failed, $suite_cases_skipped, $total_cases_passed,
  90. $total_cases_failed, $total_cases_skipped );
  91. my $suites_skipped = 0;
  92. sub pad_print_center {
  93. my( $width, $padchar, $string ) = @_;
  94. my $padlen = ( $width - length( $string ) - 2 ) / 2;
  95. print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n";
  96. }
  97. for my $suite (@suites)
  98. {
  99. print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
  100. if( $suite =~ /$skip_re/o ) {
  101. print "SKIP\n";
  102. ++$suites_skipped;
  103. next;
  104. }
  105. my $command = "$prefix$suite";
  106. if( $verbose ) {
  107. $command .= ' -v';
  108. }
  109. my $result = `$command`;
  110. $suite_cases_passed = () = $result =~ /.. PASS/g;
  111. $suite_cases_failed = () = $result =~ /.. FAILED/g;
  112. $suite_cases_skipped = () = $result =~ /.. ----/g;
  113. if( $? == 0 ) {
  114. print "PASS\n";
  115. if( $verbose > 2 ) {
  116. pad_print_center( 72, '-', "Begin $suite" );
  117. print $result;
  118. pad_print_center( 72, '-', "End $suite" );
  119. }
  120. } else {
  121. $failed_suites++;
  122. print "FAIL\n";
  123. if( $verbose ) {
  124. pad_print_center( 72, '-', "Begin $suite" );
  125. print $result;
  126. pad_print_center( 72, '-', "End $suite" );
  127. }
  128. }
  129. my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/;
  130. $total_tests_run += $tests - $skipped;
  131. if( $verbose > 1 ) {
  132. print "(test cases passed:", $suite_cases_passed,
  133. " failed:", $suite_cases_failed,
  134. " skipped:", $suite_cases_skipped,
  135. " of total:", ($suite_cases_passed + $suite_cases_failed +
  136. $suite_cases_skipped),
  137. ")\n"
  138. }
  139. $total_cases_passed += $suite_cases_passed;
  140. $total_cases_failed += $suite_cases_failed;
  141. $total_cases_skipped += $suite_cases_skipped;
  142. }
  143. print "-" x 72, "\n";
  144. print $failed_suites ? "FAILED" : "PASSED";
  145. printf( " (%d suites, %d tests run%s)\n",
  146. scalar(@suites) - $suites_skipped,
  147. $total_tests_run,
  148. $suites_skipped ? ", $suites_skipped suites skipped" : "" );
  149. if( $verbose > 1 ) {
  150. print " test cases passed :", $total_cases_passed, "\n";
  151. print " failed :", $total_cases_failed, "\n";
  152. print " skipped :", $total_cases_skipped, "\n";
  153. print " of tests executed :", ( $total_cases_passed + $total_cases_failed ),
  154. "\n";
  155. print " of available tests :",
  156. ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ),
  157. "\n";
  158. if( $suites_skipped != 0 ) {
  159. print "Note: $suites_skipped suites were skipped.\n";
  160. }
  161. }
  162. exit( $failed_suites ? 1 : 0 );