| fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 2 |  | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 3 | # run-test-suites.pl | 
|  | 4 | # | 
| SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 5 | # This file is part of mbed TLS (https://tls.mbed.org) | 
|  | 6 | # | 
| Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 7 | # Copyright (c) 2015-2018, ARM Limited, All Rights Reserved | 
|  | 8 |  | 
|  | 9 | =head1 SYNOPSIS | 
|  | 10 |  | 
|  | 11 | Execute all the test suites and print a summary of the results. | 
|  | 12 |  | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 13 | run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]] | 
| Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 14 |  | 
|  | 15 | Options: | 
|  | 16 |  | 
|  | 17 | -v|--verbose        Print detailed failure information. | 
|  | 18 | -v 2|--verbose=2    Print detailed failure information and summary messages. | 
|  | 19 | -v 3|--verbose=3    Print detailed information about every test case. | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 20 | --skip=SUITE[,SUITE...] | 
|  | 21 | Skip the specified SUITE(s). This option can be used | 
|  | 22 | multiple times. | 
| Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 23 |  | 
|  | 24 | =cut | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 25 |  | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 26 | use warnings; | 
|  | 27 | use strict; | 
|  | 28 |  | 
|  | 29 | use utf8; | 
|  | 30 | use open qw(:std utf8); | 
|  | 31 |  | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 32 | use Getopt::Long qw(:config auto_help gnu_compat); | 
| Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 33 | use Pod::Usage; | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 34 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 35 | my $verbose = 0; | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 36 | my @skip_patterns = (); | 
| Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 37 | GetOptions( | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 38 | 'skip=s' => \@skip_patterns, | 
| Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 39 | 'verbose|v:1' => \$verbose, | 
|  | 40 | ) or die; | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 41 |  | 
| Gilles Peskine | 071db41 | 2017-05-03 16:26:47 +0200 | [diff] [blame] | 42 | # All test suites = executable files, excluding source files, debug | 
|  | 43 | # and profiling information, etc. We can't just grep {! /\./} because | 
| Simon Butcher | 597dbf8 | 2018-06-27 16:16:39 +0100 | [diff] [blame] | 44 | # some of our test cases' base names contain a dot. | 
| Gilles Peskine | 071db41 | 2017-05-03 16:26:47 +0200 | [diff] [blame] | 45 | my @suites = grep { -x $_ || /\.exe$/ } glob 'test_suite_*'; | 
| Simon Butcher | 6e3606e | 2018-09-30 21:53:16 +0100 | [diff] [blame] | 46 | @suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites; | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 47 | die "$0: no test suite found\n" unless @suites; | 
|  | 48 |  | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 49 | # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" | 
|  | 50 | # but not "test_suite_foobar". | 
|  | 51 | my $skip_re = | 
|  | 52 | ( '\Atest_suite_(' . | 
|  | 53 | join('|', map { | 
|  | 54 | s/[ ,;]/|/g; # allow any of " ,;|" as separators | 
|  | 55 | s/\./\./g; # "." in the input means ".", not "any character" | 
|  | 56 | $_ | 
|  | 57 | } @skip_patterns) . | 
|  | 58 | ')(\z|\.)' ); | 
|  | 59 |  | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 60 | # in case test suites are linked dynamically | 
| Jaeden Amero | 30b340a | 2018-10-25 17:37:00 +0100 | [diff] [blame] | 61 | $ENV{'LD_LIBRARY_PATH'} = '../library:../crypto/library'; | 
|  | 62 | $ENV{'DYLD_LIBRARY_PATH'} = '../library:../crypto/library'; | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 63 |  | 
|  | 64 | my $prefix = $^O eq "MSWin32" ? '' : './'; | 
|  | 65 |  | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 66 | my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed, | 
|  | 67 | $suite_cases_failed, $suite_cases_skipped, $total_cases_passed, | 
|  | 68 | $total_cases_failed, $total_cases_skipped ); | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 69 | my $suites_skipped = 0; | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 70 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 71 | sub pad_print_center { | 
|  | 72 | my( $width, $padchar, $string ) = @_; | 
|  | 73 | my $padlen = ( $width - length( $string ) - 2 ) / 2; | 
|  | 74 | print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n"; | 
|  | 75 | } | 
|  | 76 |  | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 77 | for my $suite (@suites) | 
|  | 78 | { | 
|  | 79 | print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 80 | if( $suite =~ /$skip_re/o ) { | 
|  | 81 | print "SKIP\n"; | 
|  | 82 | ++$suites_skipped; | 
|  | 83 | next; | 
|  | 84 | } | 
|  | 85 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 86 | my $command = "$prefix$suite"; | 
|  | 87 | if( $verbose ) { | 
|  | 88 | $command .= ' -v'; | 
|  | 89 | } | 
|  | 90 | my $result = `$command`; | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 91 |  | 
|  | 92 | $suite_cases_passed = () = $result =~ /.. PASS/g; | 
|  | 93 | $suite_cases_failed = () = $result =~ /.. FAILED/g; | 
|  | 94 | $suite_cases_skipped = () = $result =~ /.. ----/g; | 
|  | 95 |  | 
| Gilles Peskine | ce35cb3 | 2019-10-21 19:08:07 +0200 | [diff] [blame] | 96 | if( $? == 0 ) { | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 97 | print "PASS\n"; | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 98 | if( $verbose > 2 ) { | 
|  | 99 | pad_print_center( 72, '-', "Begin $suite" ); | 
|  | 100 | print $result; | 
|  | 101 | pad_print_center( 72, '-', "End $suite" ); | 
|  | 102 | } | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 103 | } else { | 
|  | 104 | $failed_suites++; | 
|  | 105 | print "FAIL\n"; | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 106 | if( $verbose ) { | 
|  | 107 | pad_print_center( 72, '-', "Begin $suite" ); | 
|  | 108 | print $result; | 
|  | 109 | pad_print_center( 72, '-', "End $suite" ); | 
|  | 110 | } | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 111 | } | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 112 |  | 
|  | 113 | my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/; | 
|  | 114 | $total_tests_run += $tests - $skipped; | 
|  | 115 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 116 | if( $verbose > 1 ) { | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 117 | print "(test cases passed:", $suite_cases_passed, | 
|  | 118 | " failed:", $suite_cases_failed, | 
|  | 119 | " skipped:", $suite_cases_skipped, | 
| SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 120 | " of total:", ($suite_cases_passed + $suite_cases_failed + | 
|  | 121 | $suite_cases_skipped), | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 122 | ")\n" | 
|  | 123 | } | 
|  | 124 |  | 
|  | 125 | $total_cases_passed += $suite_cases_passed; | 
|  | 126 | $total_cases_failed += $suite_cases_failed; | 
|  | 127 | $total_cases_skipped += $suite_cases_skipped; | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
|  | 130 | print "-" x 72, "\n"; | 
|  | 131 | print $failed_suites ? "FAILED" : "PASSED"; | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 132 | printf( " (%d suites, %d tests run%s)\n", | 
|  | 133 | scalar(@suites) - $suites_skipped, | 
|  | 134 | $total_tests_run, | 
|  | 135 | $suites_skipped ? ", $suites_skipped suites skipped" : "" ); | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 136 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 137 | if( $verbose > 1 ) { | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 138 | print "  test cases passed :", $total_cases_passed, "\n"; | 
|  | 139 | print "             failed :", $total_cases_failed, "\n"; | 
|  | 140 | print "            skipped :", $total_cases_skipped, "\n"; | 
|  | 141 | print "  of tests executed :", ( $total_cases_passed + $total_cases_failed ), | 
|  | 142 | "\n"; | 
|  | 143 | print " of available tests :", | 
|  | 144 | ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ), | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 145 | "\n"; | 
|  | 146 | if( $suites_skipped != 0 ) { | 
|  | 147 | print "Note: $suites_skipped suites were skipped.\n"; | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 148 | } | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 149 | } | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 150 |  | 
| Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 151 | exit( $failed_suites ? 1 : 0 ); | 
| SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 152 |  |