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