run-test-suites.pl 5.0 KB

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