blob: 45823c0a0b14ff39111adfc5b4d4ab71219eecd3 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +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 Peskine15db8502018-12-14 18:23:13 +01005# Copyright (c) 2015-2018, ARM Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# This file is part of Mbed TLS (https://tls.mbed.org)
Gilles Peskine15db8502018-12-14 18:23:13 +010021
22=head1 SYNOPSIS
23
24Execute all the test suites and print a summary of the results.
25
Gilles Peskineac372cc2018-11-29 10:15:06 +000026 run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]]
Gilles Peskine15db8502018-12-14 18:23:13 +010027
28Options:
29
30 -v|--verbose Print detailed failure information.
31 -v 2|--verbose=2 Print detailed failure information and summary messages.
32 -v 3|--verbose=3 Print detailed information about every test case.
Gilles Peskineac372cc2018-11-29 10:15:06 +000033 --skip=SUITE[,SUITE...]
34 Skip the specified SUITE(s). This option can be used
35 multiple times.
Gilles Peskine15db8502018-12-14 18:23:13 +010036
37=cut
SimonBad8fbc02016-03-11 17:33:39 +000038
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010039use warnings;
40use strict;
41
42use utf8;
43use open qw(:std utf8);
44
Gilles Peskineac372cc2018-11-29 10:15:06 +000045use Getopt::Long qw(:config auto_help gnu_compat);
Gilles Peskine15db8502018-12-14 18:23:13 +010046use Pod::Usage;
SimonBad8fbc02016-03-11 17:33:39 +000047
Jaeden Amero8396a712018-10-05 13:23:35 +010048my $verbose = 0;
Gilles Peskineac372cc2018-11-29 10:15:06 +000049my @skip_patterns = ();
Gilles Peskine15db8502018-12-14 18:23:13 +010050GetOptions(
Gilles Peskineac372cc2018-11-29 10:15:06 +000051 'skip=s' => \@skip_patterns,
Gilles Peskine15db8502018-12-14 18:23:13 +010052 'verbose|v:1' => \$verbose,
53 ) or die;
SimonBad8fbc02016-03-11 17:33:39 +000054
Gilles Peskine071db412017-05-03 16:26:47 +020055# All test suites = executable files, excluding source files, debug
56# and profiling information, etc. We can't just grep {! /\./} because
Simon Butcher597dbf82018-06-27 16:16:39 +010057# some of our test cases' base names contain a dot.
Gilles Peskine071db412017-05-03 16:26:47 +020058my @suites = grep { -x $_ || /\.exe$/ } glob 'test_suite_*';
Simon Butcher6e3606e2018-09-30 21:53:16 +010059@suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites;
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010060die "$0: no test suite found\n" unless @suites;
61
Gilles Peskineac372cc2018-11-29 10:15:06 +000062# "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar"
63# but not "test_suite_foobar".
64my $skip_re =
65 ( '\Atest_suite_(' .
66 join('|', map {
67 s/[ ,;]/|/g; # allow any of " ,;|" as separators
68 s/\./\./g; # "." in the input means ".", not "any character"
69 $_
70 } @skip_patterns) .
71 ')(\z|\.)' );
72
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010073# in case test suites are linked dynamically
74$ENV{'LD_LIBRARY_PATH'} = '../library';
Andres Amaya Garcia79db9332018-03-27 19:57:58 +010075$ENV{'DYLD_LIBRARY_PATH'} = '../library';
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010076
77my $prefix = $^O eq "MSWin32" ? '' : './';
78
SimonBad8fbc02016-03-11 17:33:39 +000079my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed,
80 $suite_cases_failed, $suite_cases_skipped, $total_cases_passed,
81 $total_cases_failed, $total_cases_skipped );
Gilles Peskineac372cc2018-11-29 10:15:06 +000082my $suites_skipped = 0;
SimonBad8fbc02016-03-11 17:33:39 +000083
Jaeden Amero79e4f4e2018-10-05 12:21:15 +010084sub pad_print_center {
85 my( $width, $padchar, $string ) = @_;
86 my $padlen = ( $width - length( $string ) - 2 ) / 2;
87 print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n";
88}
89
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010090for my $suite (@suites)
91{
92 print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
Gilles Peskineac372cc2018-11-29 10:15:06 +000093 if( $suite =~ /$skip_re/o ) {
94 print "SKIP\n";
95 ++$suites_skipped;
96 next;
97 }
98
Jaeden Amero79e4f4e2018-10-05 12:21:15 +010099 my $command = "$prefix$suite";
100 if( $verbose ) {
101 $command .= ' -v';
102 }
103 my $result = `$command`;
SimonBad8fbc02016-03-11 17:33:39 +0000104
105 $suite_cases_passed = () = $result =~ /.. PASS/g;
106 $suite_cases_failed = () = $result =~ /.. FAILED/g;
107 $suite_cases_skipped = () = $result =~ /.. ----/g;
108
Gilles Peskine8b5389f2019-10-21 19:08:07 +0200109 if( $? == 0 ) {
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100110 print "PASS\n";
Jaeden Amero8396a712018-10-05 13:23:35 +0100111 if( $verbose > 2 ) {
112 pad_print_center( 72, '-', "Begin $suite" );
113 print $result;
114 pad_print_center( 72, '-', "End $suite" );
115 }
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100116 } else {
117 $failed_suites++;
118 print "FAIL\n";
Jaeden Amero79e4f4e2018-10-05 12:21:15 +0100119 if( $verbose ) {
120 pad_print_center( 72, '-', "Begin $suite" );
121 print $result;
122 pad_print_center( 72, '-', "End $suite" );
123 }
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100124 }
SimonBad8fbc02016-03-11 17:33:39 +0000125
126 my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/;
127 $total_tests_run += $tests - $skipped;
128
Jaeden Amero8396a712018-10-05 13:23:35 +0100129 if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000130 print "(test cases passed:", $suite_cases_passed,
131 " failed:", $suite_cases_failed,
132 " skipped:", $suite_cases_skipped,
SimonB8ca7bc42016-04-17 23:24:50 +0100133 " of total:", ($suite_cases_passed + $suite_cases_failed +
134 $suite_cases_skipped),
SimonBad8fbc02016-03-11 17:33:39 +0000135 ")\n"
136 }
137
138 $total_cases_passed += $suite_cases_passed;
139 $total_cases_failed += $suite_cases_failed;
140 $total_cases_skipped += $suite_cases_skipped;
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100141}
142
143print "-" x 72, "\n";
144print $failed_suites ? "FAILED" : "PASSED";
Gilles Peskineac372cc2018-11-29 10:15:06 +0000145printf( " (%d suites, %d tests run%s)\n",
146 scalar(@suites) - $suites_skipped,
147 $total_tests_run,
148 $suites_skipped ? ", $suites_skipped suites skipped" : "" );
SimonBad8fbc02016-03-11 17:33:39 +0000149
Jaeden Amero8396a712018-10-05 13:23:35 +0100150if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000151 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 Peskineac372cc2018-11-29 10:15:06 +0000158 "\n";
159 if( $suites_skipped != 0 ) {
160 print "Note: $suites_skipped suites were skipped.\n";
SimonBad8fbc02016-03-11 17:33:39 +0000161 }
Gilles Peskineac372cc2018-11-29 10:15:06 +0000162}
SimonBad8fbc02016-03-11 17:33:39 +0000163
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100164exit( $failed_suites ? 1 : 0 );
SimonBad8fbc02016-03-11 17:33:39 +0000165