blob: f950972de10f4f031c2a86de6a41240dc0f3c279 [file] [log] [blame]
fbrosson3a745712018-04-04 22:26:56 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +01002
SimonBad8fbc02016-03-11 17:33:39 +00003# run-test-suites.pl
4#
Gilles Peskine0626ebb2018-12-14 18:23:13 +01005# Copyright (c) 2015-2018, ARM Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02006# 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úti09b4f192020-05-26 01:54:15 +020013#
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úti4e9f7122020-06-05 13:02:18 +020026# **********
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úti09b4f192020-05-26 01:54:15 +020047# This file is part of Mbed TLS (https://tls.mbed.org)
Gilles Peskine0626ebb2018-12-14 18:23:13 +010048
49=head1 SYNOPSIS
50
51Execute all the test suites and print a summary of the results.
52
Gilles Peskinebda9abf2018-11-29 10:15:06 +000053 run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]]
Gilles Peskine0626ebb2018-12-14 18:23:13 +010054
55Options:
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 Peskinebda9abf2018-11-29 10:15:06 +000060 --skip=SUITE[,SUITE...]
61 Skip the specified SUITE(s). This option can be used
62 multiple times.
Gilles Peskine0626ebb2018-12-14 18:23:13 +010063
64=cut
SimonBad8fbc02016-03-11 17:33:39 +000065
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010066use warnings;
67use strict;
68
69use utf8;
70use open qw(:std utf8);
71
Gilles Peskinebda9abf2018-11-29 10:15:06 +000072use Getopt::Long qw(:config auto_help gnu_compat);
Gilles Peskine0626ebb2018-12-14 18:23:13 +010073use Pod::Usage;
SimonBad8fbc02016-03-11 17:33:39 +000074
Jaeden Amero9bd49042018-10-05 13:23:35 +010075my $verbose = 0;
Gilles Peskinebda9abf2018-11-29 10:15:06 +000076my @skip_patterns = ();
Gilles Peskine0626ebb2018-12-14 18:23:13 +010077GetOptions(
Gilles Peskinebda9abf2018-11-29 10:15:06 +000078 'skip=s' => \@skip_patterns,
Gilles Peskine0626ebb2018-12-14 18:23:13 +010079 'verbose|v:1' => \$verbose,
80 ) or die;
SimonBad8fbc02016-03-11 17:33:39 +000081
Gilles Peskine071db412017-05-03 16:26:47 +020082# All test suites = executable files, excluding source files, debug
83# and profiling information, etc. We can't just grep {! /\./} because
Simon Butcherd620f6f2018-06-27 16:16:39 +010084# some of our test cases' base names contain a dot.
Gilles Peskine071db412017-05-03 16:26:47 +020085my @suites = grep { -x $_ || /\.exe$/ } glob 'test_suite_*';
Simon Butchereb219392018-09-30 21:57:34 +010086@suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites;
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010087die "$0: no test suite found\n" unless @suites;
88
Gilles Peskinebda9abf2018-11-29 10:15:06 +000089# "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar"
90# but not "test_suite_foobar".
91my $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é-Gonnard85113842015-07-08 21:20:03 +0100100# in case test suites are linked dynamically
101$ENV{'LD_LIBRARY_PATH'} = '../library';
Andres Amaya Garcia28d97e12018-03-27 19:57:58 +0100102$ENV{'DYLD_LIBRARY_PATH'} = '../library';
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100103
104my $prefix = $^O eq "MSWin32" ? '' : './';
105
SimonBad8fbc02016-03-11 17:33:39 +0000106my ($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 Peskinebda9abf2018-11-29 10:15:06 +0000109my $suites_skipped = 0;
SimonBad8fbc02016-03-11 17:33:39 +0000110
Jaeden Amero5758d8c2018-10-05 12:21:15 +0100111sub 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é-Gonnard85113842015-07-08 21:20:03 +0100117for my $suite (@suites)
118{
119 print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
Gilles Peskinebda9abf2018-11-29 10:15:06 +0000120 if( $suite =~ /$skip_re/o ) {
121 print "SKIP\n";
122 ++$suites_skipped;
123 next;
124 }
125
Jaeden Amero5758d8c2018-10-05 12:21:15 +0100126 my $command = "$prefix$suite";
127 if( $verbose ) {
128 $command .= ' -v';
129 }
130 my $result = `$command`;
SimonBad8fbc02016-03-11 17:33:39 +0000131
132 $suite_cases_passed = () = $result =~ /.. PASS/g;
133 $suite_cases_failed = () = $result =~ /.. FAILED/g;
134 $suite_cases_skipped = () = $result =~ /.. ----/g;
135
Gilles Peskine5ee14d72019-10-21 19:08:07 +0200136 if( $? == 0 ) {
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100137 print "PASS\n";
Jaeden Amero9bd49042018-10-05 13:23:35 +0100138 if( $verbose > 2 ) {
139 pad_print_center( 72, '-', "Begin $suite" );
140 print $result;
141 pad_print_center( 72, '-', "End $suite" );
142 }
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100143 } else {
144 $failed_suites++;
145 print "FAIL\n";
Jaeden Amero5758d8c2018-10-05 12:21:15 +0100146 if( $verbose ) {
147 pad_print_center( 72, '-', "Begin $suite" );
148 print $result;
149 pad_print_center( 72, '-', "End $suite" );
150 }
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100151 }
SimonBad8fbc02016-03-11 17:33:39 +0000152
153 my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/;
154 $total_tests_run += $tests - $skipped;
155
Jaeden Amero9bd49042018-10-05 13:23:35 +0100156 if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000157 print "(test cases passed:", $suite_cases_passed,
158 " failed:", $suite_cases_failed,
159 " skipped:", $suite_cases_skipped,
SimonB8ca7bc42016-04-17 23:24:50 +0100160 " of total:", ($suite_cases_passed + $suite_cases_failed +
161 $suite_cases_skipped),
SimonBad8fbc02016-03-11 17:33:39 +0000162 ")\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é-Gonnard85113842015-07-08 21:20:03 +0100168}
169
170print "-" x 72, "\n";
171print $failed_suites ? "FAILED" : "PASSED";
Gilles Peskinebda9abf2018-11-29 10:15:06 +0000172printf( " (%d suites, %d tests run%s)\n",
173 scalar(@suites) - $suites_skipped,
174 $total_tests_run,
175 $suites_skipped ? ", $suites_skipped suites skipped" : "" );
SimonBad8fbc02016-03-11 17:33:39 +0000176
Jaeden Amero9bd49042018-10-05 13:23:35 +0100177if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000178 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 Peskinebda9abf2018-11-29 10:15:06 +0000185 "\n";
186 if( $suites_skipped != 0 ) {
187 print "Note: $suites_skipped suites were skipped.\n";
SimonBad8fbc02016-03-11 17:33:39 +0000188 }
Gilles Peskinebda9abf2018-11-29 10:15:06 +0000189}
SimonBad8fbc02016-03-11 17:33:39 +0000190
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100191exit( $failed_suites ? 1 : 0 );
SimonBad8fbc02016-03-11 17:33:39 +0000192