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 | # |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 5 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 6 | # |
Gilles Peskine | 0626ebb | 2018-12-14 18:23:13 +0100 | [diff] [blame^] | 7 | # Copyright (c) 2015-2018, ARM Limited, All Rights Reserved |
| 8 | |
| 9 | =head1 SYNOPSIS |
| 10 | |
| 11 | Execute all the test suites and print a summary of the results. |
| 12 | |
| 13 | run-test-suites.pl [[-v|--verbose] [VERBOSITY]] |
| 14 | |
| 15 | Options: |
| 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. |
| 20 | |
| 21 | =cut |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 22 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 23 | use warnings; |
| 24 | use strict; |
| 25 | |
| 26 | use utf8; |
| 27 | use open qw(:std utf8); |
| 28 | |
Gilles Peskine | 0626ebb | 2018-12-14 18:23:13 +0100 | [diff] [blame^] | 29 | use Getopt::Long qw(:config auto_help); |
| 30 | use Pod::Usage; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 31 | |
Jaeden Amero | 9bd4904 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 32 | my $verbose = 0; |
Gilles Peskine | 0626ebb | 2018-12-14 18:23:13 +0100 | [diff] [blame^] | 33 | GetOptions( |
| 34 | 'verbose|v:1' => \$verbose, |
| 35 | ) or die; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 36 | |
Gilles Peskine | 071db41 | 2017-05-03 16:26:47 +0200 | [diff] [blame] | 37 | # All test suites = executable files, excluding source files, debug |
| 38 | # and profiling information, etc. We can't just grep {! /\./} because |
Simon Butcher | d620f6f | 2018-06-27 16:16:39 +0100 | [diff] [blame] | 39 | # some of our test cases' base names contain a dot. |
Gilles Peskine | 071db41 | 2017-05-03 16:26:47 +0200 | [diff] [blame] | 40 | my @suites = grep { -x $_ || /\.exe$/ } glob 'test_suite_*'; |
Simon Butcher | eb21939 | 2018-09-30 21:57:34 +0100 | [diff] [blame] | 41 | @suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites; |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 42 | die "$0: no test suite found\n" unless @suites; |
| 43 | |
| 44 | # in case test suites are linked dynamically |
| 45 | $ENV{'LD_LIBRARY_PATH'} = '../library'; |
Andres Amaya Garcia | 28d97e1 | 2018-03-27 19:57:58 +0100 | [diff] [blame] | 46 | $ENV{'DYLD_LIBRARY_PATH'} = '../library'; |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 47 | |
| 48 | my $prefix = $^O eq "MSWin32" ? '' : './'; |
| 49 | |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 50 | my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed, |
| 51 | $suite_cases_failed, $suite_cases_skipped, $total_cases_passed, |
| 52 | $total_cases_failed, $total_cases_skipped ); |
| 53 | |
Jaeden Amero | 5758d8c | 2018-10-05 12:21:15 +0100 | [diff] [blame] | 54 | sub pad_print_center { |
| 55 | my( $width, $padchar, $string ) = @_; |
| 56 | my $padlen = ( $width - length( $string ) - 2 ) / 2; |
| 57 | print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n"; |
| 58 | } |
| 59 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 60 | for my $suite (@suites) |
| 61 | { |
| 62 | print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; |
Jaeden Amero | 5758d8c | 2018-10-05 12:21:15 +0100 | [diff] [blame] | 63 | my $command = "$prefix$suite"; |
| 64 | if( $verbose ) { |
| 65 | $command .= ' -v'; |
| 66 | } |
| 67 | my $result = `$command`; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 68 | |
| 69 | $suite_cases_passed = () = $result =~ /.. PASS/g; |
| 70 | $suite_cases_failed = () = $result =~ /.. FAILED/g; |
| 71 | $suite_cases_skipped = () = $result =~ /.. ----/g; |
| 72 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 73 | if( $result =~ /PASSED/ ) { |
| 74 | print "PASS\n"; |
Jaeden Amero | 9bd4904 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 75 | if( $verbose > 2 ) { |
| 76 | pad_print_center( 72, '-', "Begin $suite" ); |
| 77 | print $result; |
| 78 | pad_print_center( 72, '-', "End $suite" ); |
| 79 | } |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 80 | } else { |
| 81 | $failed_suites++; |
| 82 | print "FAIL\n"; |
Jaeden Amero | 5758d8c | 2018-10-05 12:21:15 +0100 | [diff] [blame] | 83 | if( $verbose ) { |
| 84 | pad_print_center( 72, '-', "Begin $suite" ); |
| 85 | print $result; |
| 86 | pad_print_center( 72, '-', "End $suite" ); |
| 87 | } |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 88 | } |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 89 | |
| 90 | my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/; |
| 91 | $total_tests_run += $tests - $skipped; |
| 92 | |
Jaeden Amero | 9bd4904 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 93 | if( $verbose > 1 ) { |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 94 | print "(test cases passed:", $suite_cases_passed, |
| 95 | " failed:", $suite_cases_failed, |
| 96 | " skipped:", $suite_cases_skipped, |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 97 | " of total:", ($suite_cases_passed + $suite_cases_failed + |
| 98 | $suite_cases_skipped), |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 99 | ")\n" |
| 100 | } |
| 101 | |
| 102 | $total_cases_passed += $suite_cases_passed; |
| 103 | $total_cases_failed += $suite_cases_failed; |
| 104 | $total_cases_skipped += $suite_cases_skipped; |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | print "-" x 72, "\n"; |
| 108 | print $failed_suites ? "FAILED" : "PASSED"; |
| 109 | printf " (%d suites, %d tests run)\n", scalar @suites, $total_tests_run; |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 110 | |
Jaeden Amero | 9bd4904 | 2018-10-05 13:23:35 +0100 | [diff] [blame] | 111 | if( $verbose > 1 ) { |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 112 | print " test cases passed :", $total_cases_passed, "\n"; |
| 113 | print " failed :", $total_cases_failed, "\n"; |
| 114 | print " skipped :", $total_cases_skipped, "\n"; |
| 115 | print " of tests executed :", ( $total_cases_passed + $total_cases_failed ), |
| 116 | "\n"; |
| 117 | print " of available tests :", |
| 118 | ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ), |
| 119 | "\n" |
| 120 | } |
| 121 | |
Manuel Pégourié-Gonnard | 8511384 | 2015-07-08 21:20:03 +0100 | [diff] [blame] | 122 | exit( $failed_suites ? 1 : 0 ); |
SimonB | ad8fbc0 | 2016-03-11 17:33:39 +0000 | [diff] [blame] | 123 | |