blob: 8a5bb937dc6186927e4478c5943a059a42d5c142 [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#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
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.
Gilles Peskine15db8502018-12-14 18:23:13 +010019
20=head1 SYNOPSIS
21
22Execute all the test suites and print a summary of the results.
23
Gilles Peskineac372cc2018-11-29 10:15:06 +000024 run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]]
Gilles Peskine15db8502018-12-14 18:23:13 +010025
26Options:
27
28 -v|--verbose Print detailed failure information.
29 -v 2|--verbose=2 Print detailed failure information and summary messages.
30 -v 3|--verbose=3 Print detailed information about every test case.
Gilles Peskineac372cc2018-11-29 10:15:06 +000031 --skip=SUITE[,SUITE...]
32 Skip the specified SUITE(s). This option can be used
33 multiple times.
Gilles Peskine15db8502018-12-14 18:23:13 +010034
35=cut
SimonBad8fbc02016-03-11 17:33:39 +000036
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010037use warnings;
38use strict;
39
40use utf8;
41use open qw(:std utf8);
42
Gilles Peskineac372cc2018-11-29 10:15:06 +000043use Getopt::Long qw(:config auto_help gnu_compat);
Gilles Peskine15db8502018-12-14 18:23:13 +010044use Pod::Usage;
SimonBad8fbc02016-03-11 17:33:39 +000045
Jaeden Amero8396a712018-10-05 13:23:35 +010046my $verbose = 0;
Gilles Peskineac372cc2018-11-29 10:15:06 +000047my @skip_patterns = ();
Gilles Peskine15db8502018-12-14 18:23:13 +010048GetOptions(
Gilles Peskineac372cc2018-11-29 10:15:06 +000049 'skip=s' => \@skip_patterns,
Gilles Peskine15db8502018-12-14 18:23:13 +010050 'verbose|v:1' => \$verbose,
51 ) or die;
SimonBad8fbc02016-03-11 17:33:39 +000052
Manuel Pégourié-Gonnard38860e22022-11-07 10:05:49 +010053# All test suites = executable files derived from a .data file.
54my @suites = ();
55for my $data_file (glob 'suites/test_suite_*.data') {
56 (my $base = $data_file) =~ s#^suites/(.*)\.data$#$1#;
57 push @suites, $base if -x $base;
58 push @suites, "$base.exe" if -e "$base.exe";
59}
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
Manuel Pégourié-Gonnardac6c6702022-10-11 10:48:32 +020079my (@failed_suites, $total_tests_run, $failed, $suite_cases_passed,
SimonBad8fbc02016-03-11 17:33:39 +000080 $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 {
Manuel Pégourié-Gonnardac6c6702022-10-11 10:48:32 +0200117 push @failed_suites, $suite;
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100118 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";
Manuel Pégourié-Gonnardac6c6702022-10-11 10:48:32 +0200144print @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
Manuel Pégourié-Gonnardac6c6702022-10-11 10:48:32 +0200150if( $verbose && @failed_suites ) {
151 # the output can be very long, so provide a summary of which suites failed
152 print " failed suites : @failed_suites\n";
153}
154
Jaeden Amero8396a712018-10-05 13:23:35 +0100155if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000156 print " test cases passed :", $total_cases_passed, "\n";
157 print " failed :", $total_cases_failed, "\n";
158 print " skipped :", $total_cases_skipped, "\n";
159 print " of tests executed :", ( $total_cases_passed + $total_cases_failed ),
160 "\n";
161 print " of available tests :",
162 ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ),
Gilles Peskineac372cc2018-11-29 10:15:06 +0000163 "\n";
164 if( $suites_skipped != 0 ) {
165 print "Note: $suites_skipped suites were skipped.\n";
SimonBad8fbc02016-03-11 17:33:39 +0000166 }
Gilles Peskineac372cc2018-11-29 10:15:06 +0000167}
SimonBad8fbc02016-03-11 17:33:39 +0000168
Manuel Pégourié-Gonnardac6c6702022-10-11 10:48:32 +0200169exit( @failed_suites ? 1 : 0 );
SimonBad8fbc02016-03-11 17:33:39 +0000170