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 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 7 | |
| 8 | =head1 SYNOPSIS |
| 9 | |
| 10 | Execute all the test suites and print a summary of the results. |
| 11 | |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 12 | run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]] |
Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 13 | |
| 14 | Options: |
| 15 | |
| 16 | -v|--verbose Print detailed failure information. |
| 17 | -v 2|--verbose=2 Print detailed failure information and summary messages. |
| 18 | -v 3|--verbose=3 Print detailed information about every test case. |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 19 | --skip=SUITE[,SUITE...] |
| 20 | Skip the specified SUITE(s). This option can be used |
| 21 | multiple times. |
Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 22 | |
| 23 | =cut |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 24 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 25 | use warnings; |
| 26 | use strict; |
| 27 | |
| 28 | use utf8; |
| 29 | use open qw(:std utf8); |
| 30 | |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 31 | use Getopt::Long qw(:config auto_help gnu_compat); |
Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 32 | use Pod::Usage; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 33 | |
Jaeden Amero | 8396a71 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 34 | my $verbose = 0; |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 35 | my @skip_patterns = (); |
Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 36 | GetOptions( |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 37 | 'skip=s' => \@skip_patterns, |
Gilles Peskine | 15db850 | 2018-12-14 18:23:13 +0100 | [diff] [blame] | 38 | 'verbose|v:1' => \$verbose, |
| 39 | ) or die; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 40 | |
Gilles Peskine | 298f781 | 2022-11-15 23:54:26 +0100 | [diff] [blame] | 41 | # All test suites = executable files with a .datax file. |
Manuel Pégourié-Gonnard | 38860e2 | 2022-11-07 10:05:49 +0100 | [diff] [blame] | 42 | my @suites = (); |
Gilles Peskine | 298f781 | 2022-11-15 23:54:26 +0100 | [diff] [blame] | 43 | for my $data_file (glob 'test_suite_*.datax') { |
| 44 | (my $base = $data_file) =~ s/\.datax$//; |
Manuel Pégourié-Gonnard | 38860e2 | 2022-11-07 10:05:49 +0100 | [diff] [blame] | 45 | push @suites, $base if -x $base; |
| 46 | push @suites, "$base.exe" if -e "$base.exe"; |
| 47 | } |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 48 | die "$0: no test suite found\n" unless @suites; |
| 49 | |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 50 | # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" |
| 51 | # but not "test_suite_foobar". |
| 52 | my $skip_re = |
| 53 | ( '\Atest_suite_(' . |
| 54 | join('|', map { |
| 55 | s/[ ,;]/|/g; # allow any of " ,;|" as separators |
| 56 | s/\./\./g; # "." in the input means ".", not "any character" |
| 57 | $_ |
| 58 | } @skip_patterns) . |
| 59 | ')(\z|\.)' ); |
| 60 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 61 | # in case test suites are linked dynamically |
Ronald Cron | 72d1888 | 2024-07-16 10:19:44 +0200 | [diff] [blame^] | 62 | if (-d '../../tf-psa-crypto') { |
| 63 | $ENV{'LD_LIBRARY_PATH'} = '../../library'; |
| 64 | $ENV{'DYLD_LIBRARY_PATH'} = '../../library'; |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | $ENV{'LD_LIBRARY_PATH'} = '../library'; |
| 69 | $ENV{'DYLD_LIBRARY_PATH'} = '../library'; |
| 70 | } |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 71 | |
| 72 | my $prefix = $^O eq "MSWin32" ? '' : './'; |
| 73 | |
Manuel Pégourié-Gonnard | ac6c670 | 2022-10-11 10:48:32 +0200 | [diff] [blame] | 74 | my (@failed_suites, $total_tests_run, $failed, $suite_cases_passed, |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 75 | $suite_cases_failed, $suite_cases_skipped, $total_cases_passed, |
| 76 | $total_cases_failed, $total_cases_skipped ); |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 77 | my $suites_skipped = 0; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 78 | |
Jaeden Amero | 79e4f4e | 2018-10-05 12:21:15 +0100 | [diff] [blame] | 79 | sub pad_print_center { |
| 80 | my( $width, $padchar, $string ) = @_; |
| 81 | my $padlen = ( $width - length( $string ) - 2 ) / 2; |
| 82 | print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n"; |
| 83 | } |
| 84 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 85 | for my $suite (@suites) |
| 86 | { |
| 87 | print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 88 | if( $suite =~ /$skip_re/o ) { |
| 89 | print "SKIP\n"; |
| 90 | ++$suites_skipped; |
| 91 | next; |
| 92 | } |
| 93 | |
Jaeden Amero | 79e4f4e | 2018-10-05 12:21:15 +0100 | [diff] [blame] | 94 | my $command = "$prefix$suite"; |
| 95 | if( $verbose ) { |
| 96 | $command .= ' -v'; |
| 97 | } |
| 98 | my $result = `$command`; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 99 | |
| 100 | $suite_cases_passed = () = $result =~ /.. PASS/g; |
| 101 | $suite_cases_failed = () = $result =~ /.. FAILED/g; |
| 102 | $suite_cases_skipped = () = $result =~ /.. ----/g; |
| 103 | |
Gilles Peskine | 8b5389f | 2019-10-21 19:08:07 +0200 | [diff] [blame] | 104 | if( $? == 0 ) { |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 105 | print "PASS\n"; |
Jaeden Amero | 8396a71 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 106 | if( $verbose > 2 ) { |
| 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 | } else { |
Manuel Pégourié-Gonnard | ac6c670 | 2022-10-11 10:48:32 +0200 | [diff] [blame] | 112 | push @failed_suites, $suite; |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 113 | print "FAIL\n"; |
Jaeden Amero | 79e4f4e | 2018-10-05 12:21:15 +0100 | [diff] [blame] | 114 | if( $verbose ) { |
| 115 | pad_print_center( 72, '-', "Begin $suite" ); |
| 116 | print $result; |
| 117 | pad_print_center( 72, '-', "End $suite" ); |
| 118 | } |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 119 | } |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 120 | |
| 121 | my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/; |
| 122 | $total_tests_run += $tests - $skipped; |
| 123 | |
Jaeden Amero | 8396a71 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 124 | if( $verbose > 1 ) { |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 125 | print "(test cases passed:", $suite_cases_passed, |
| 126 | " failed:", $suite_cases_failed, |
| 127 | " skipped:", $suite_cases_skipped, |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 128 | " of total:", ($suite_cases_passed + $suite_cases_failed + |
| 129 | $suite_cases_skipped), |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 130 | ")\n" |
| 131 | } |
| 132 | |
| 133 | $total_cases_passed += $suite_cases_passed; |
| 134 | $total_cases_failed += $suite_cases_failed; |
| 135 | $total_cases_skipped += $suite_cases_skipped; |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | print "-" x 72, "\n"; |
Manuel Pégourié-Gonnard | ac6c670 | 2022-10-11 10:48:32 +0200 | [diff] [blame] | 139 | print @failed_suites ? "FAILED" : "PASSED"; |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 140 | printf( " (%d suites, %d tests run%s)\n", |
| 141 | scalar(@suites) - $suites_skipped, |
| 142 | $total_tests_run, |
| 143 | $suites_skipped ? ", $suites_skipped suites skipped" : "" ); |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 144 | |
Manuel Pégourié-Gonnard | ac6c670 | 2022-10-11 10:48:32 +0200 | [diff] [blame] | 145 | if( $verbose && @failed_suites ) { |
| 146 | # the output can be very long, so provide a summary of which suites failed |
| 147 | print " failed suites : @failed_suites\n"; |
| 148 | } |
| 149 | |
Jaeden Amero | 8396a71 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 150 | if( $verbose > 1 ) { |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 151 | print " test cases passed :", $total_cases_passed, "\n"; |
| 152 | print " failed :", $total_cases_failed, "\n"; |
| 153 | print " skipped :", $total_cases_skipped, "\n"; |
| 154 | print " of tests executed :", ( $total_cases_passed + $total_cases_failed ), |
| 155 | "\n"; |
| 156 | print " of available tests :", |
| 157 | ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ), |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 158 | "\n"; |
| 159 | if( $suites_skipped != 0 ) { |
| 160 | print "Note: $suites_skipped suites were skipped.\n"; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 161 | } |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 162 | } |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 163 | |
Manuel Pégourié-Gonnard | ac6c670 | 2022-10-11 10:48:32 +0200 | [diff] [blame] | 164 | exit( @failed_suites ? 1 : 0 ); |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 165 | |