blob: e55d08336ac15b4853f0827d5a9d289590df6d8a [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#
SimonB8ca7bc42016-04-17 23:24:50 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine15db8502018-12-14 18:23:13 +01007# Copyright (c) 2015-2018, ARM Limited, All Rights Reserved
8
9=head1 SYNOPSIS
10
11Execute all the test suites and print a summary of the results.
12
Gilles Peskineac372cc2018-11-29 10:15:06 +000013 run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]]
Gilles Peskine15db8502018-12-14 18:23:13 +010014
15Options:
16
17 -v|--verbose Print detailed failure information.
18 -v 2|--verbose=2 Print detailed failure information and summary messages.
19 -v 3|--verbose=3 Print detailed information about every test case.
Gilles Peskineac372cc2018-11-29 10:15:06 +000020 --skip=SUITE[,SUITE...]
21 Skip the specified SUITE(s). This option can be used
22 multiple times.
Gilles Peskine15db8502018-12-14 18:23:13 +010023
24=cut
SimonBad8fbc02016-03-11 17:33:39 +000025
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010026use warnings;
27use strict;
28
29use utf8;
30use open qw(:std utf8);
31
Gilles Peskineac372cc2018-11-29 10:15:06 +000032use Getopt::Long qw(:config auto_help gnu_compat);
Gilles Peskine15db8502018-12-14 18:23:13 +010033use Pod::Usage;
SimonBad8fbc02016-03-11 17:33:39 +000034
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050035my $verbose = 0;
Gilles Peskineac372cc2018-11-29 10:15:06 +000036my @skip_patterns = ();
Gilles Peskine15db8502018-12-14 18:23:13 +010037GetOptions(
Gilles Peskineac372cc2018-11-29 10:15:06 +000038 'skip=s' => \@skip_patterns,
Gilles Peskine15db8502018-12-14 18:23:13 +010039 'verbose|v:1' => \$verbose,
40 ) or die;
SimonBad8fbc02016-03-11 17:33:39 +000041
Gilles Peskine071db412017-05-03 16:26:47 +020042# All test suites = executable files, excluding source files, debug
43# and profiling information, etc. We can't just grep {! /\./} because
Simon Butcher597dbf82018-06-27 16:16:39 +010044# some of our test cases' base names contain a dot.
Gilles Peskine071db412017-05-03 16:26:47 +020045my @suites = grep { -x $_ || /\.exe$/ } glob 'test_suite_*';
Simon Butcher6e3606e2018-09-30 21:53:16 +010046@suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites;
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010047die "$0: no test suite found\n" unless @suites;
48
Gilles Peskineac372cc2018-11-29 10:15:06 +000049# "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar"
50# but not "test_suite_foobar".
51my $skip_re =
52 ( '\Atest_suite_(' .
53 join('|', map {
54 s/[ ,;]/|/g; # allow any of " ,;|" as separators
55 s/\./\./g; # "." in the input means ".", not "any character"
56 $_
57 } @skip_patterns) .
58 ')(\z|\.)' );
59
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010060# in case test suites are linked dynamically
Jaeden Amero30b340a2018-10-25 17:37:00 +010061$ENV{'LD_LIBRARY_PATH'} = '../library:../crypto/library';
62$ENV{'DYLD_LIBRARY_PATH'} = '../library:../crypto/library';
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010063
64my $prefix = $^O eq "MSWin32" ? '' : './';
65
SimonBad8fbc02016-03-11 17:33:39 +000066my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed,
67 $suite_cases_failed, $suite_cases_skipped, $total_cases_passed,
68 $total_cases_failed, $total_cases_skipped );
Gilles Peskineac372cc2018-11-29 10:15:06 +000069my $suites_skipped = 0;
SimonBad8fbc02016-03-11 17:33:39 +000070
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050071sub pad_print_center {
72 my( $width, $padchar, $string ) = @_;
73 my $padlen = ( $width - length( $string ) - 2 ) / 2;
74 print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n";
75}
76
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010077for my $suite (@suites)
78{
79 print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
Gilles Peskineac372cc2018-11-29 10:15:06 +000080 if( $suite =~ /$skip_re/o ) {
81 print "SKIP\n";
82 ++$suites_skipped;
83 next;
84 }
85
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050086 my $command = "$prefix$suite";
87 if( $verbose ) {
88 $command .= ' -v';
89 }
90 my $result = `$command`;
SimonBad8fbc02016-03-11 17:33:39 +000091
92 $suite_cases_passed = () = $result =~ /.. PASS/g;
93 $suite_cases_failed = () = $result =~ /.. FAILED/g;
94 $suite_cases_skipped = () = $result =~ /.. ----/g;
95
Gilles Peskinece35cb32019-10-21 19:08:07 +020096 if( $? == 0 ) {
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +010097 print "PASS\n";
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050098 if( $verbose > 2 ) {
99 pad_print_center( 72, '-', "Begin $suite" );
100 print $result;
101 pad_print_center( 72, '-', "End $suite" );
102 }
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100103 } else {
104 $failed_suites++;
105 print "FAIL\n";
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500106 if( $verbose ) {
107 pad_print_center( 72, '-', "Begin $suite" );
108 print $result;
109 pad_print_center( 72, '-', "End $suite" );
110 }
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100111 }
SimonBad8fbc02016-03-11 17:33:39 +0000112
113 my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/;
114 $total_tests_run += $tests - $skipped;
115
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500116 if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000117 print "(test cases passed:", $suite_cases_passed,
118 " failed:", $suite_cases_failed,
119 " skipped:", $suite_cases_skipped,
SimonB8ca7bc42016-04-17 23:24:50 +0100120 " of total:", ($suite_cases_passed + $suite_cases_failed +
121 $suite_cases_skipped),
SimonBad8fbc02016-03-11 17:33:39 +0000122 ")\n"
123 }
124
125 $total_cases_passed += $suite_cases_passed;
126 $total_cases_failed += $suite_cases_failed;
127 $total_cases_skipped += $suite_cases_skipped;
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100128}
129
130print "-" x 72, "\n";
131print $failed_suites ? "FAILED" : "PASSED";
Gilles Peskineac372cc2018-11-29 10:15:06 +0000132printf( " (%d suites, %d tests run%s)\n",
133 scalar(@suites) - $suites_skipped,
134 $total_tests_run,
135 $suites_skipped ? ", $suites_skipped suites skipped" : "" );
SimonBad8fbc02016-03-11 17:33:39 +0000136
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500137if( $verbose > 1 ) {
SimonBad8fbc02016-03-11 17:33:39 +0000138 print " test cases passed :", $total_cases_passed, "\n";
139 print " failed :", $total_cases_failed, "\n";
140 print " skipped :", $total_cases_skipped, "\n";
141 print " of tests executed :", ( $total_cases_passed + $total_cases_failed ),
142 "\n";
143 print " of available tests :",
144 ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ),
Gilles Peskineac372cc2018-11-29 10:15:06 +0000145 "\n";
146 if( $suites_skipped != 0 ) {
147 print "Note: $suites_skipped suites were skipped.\n";
SimonBad8fbc02016-03-11 17:33:39 +0000148 }
Gilles Peskineac372cc2018-11-29 10:15:06 +0000149}
SimonBad8fbc02016-03-11 17:33:39 +0000150
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100151exit( $failed_suites ? 1 : 0 );
SimonBad8fbc02016-03-11 17:33:39 +0000152