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