1#!/usr/bin/perl
2
3# run-test-suites.pl
4#
5# This file is part of mbed TLS (https://tls.mbed.org)
6#
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
21use warnings;
22use strict;
23
24use utf8;
25use open qw(:std utf8);
26
27use constant FALSE => 0;
28use constant TRUE => 1;
29
30my $verbose;
31my $switch = shift;
32if ( defined($switch) && ( $switch eq "-v" || $switch eq "--verbose" ) ) {
33    $verbose = TRUE;
34}
35
36my @suites = grep { ! /\.(?:c|gcno|gcda|dSYM)$/ } glob 'test_suite_*';
37die "$0: no test suite found\n" unless @suites;
38
39# in case test suites are linked dynamically
40$ENV{'LD_LIBRARY_PATH'} = '../library';
41
42my $prefix = $^O eq "MSWin32" ? '' : './';
43
44my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed,
45    $suite_cases_failed, $suite_cases_skipped, $total_cases_passed,
46    $total_cases_failed, $total_cases_skipped );
47
48for my $suite (@suites)
49{
50    print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
51    my $result = `$prefix$suite`;
52
53    $suite_cases_passed = () = $result =~ /.. PASS/g;
54    $suite_cases_failed = () = $result =~ /.. FAILED/g;
55    $suite_cases_skipped = () = $result =~ /.. ----/g;
56
57    if( $result =~ /PASSED/ ) {
58        print "PASS\n";
59    } else {
60        $failed_suites++;
61        print "FAIL\n";
62    }
63
64    my ($passed, $tests, $skipped) = $result =~ /([0-9]*) \/ ([0-9]*) tests.*?([0-9]*) skipped/;
65    $total_tests_run += $tests - $skipped;
66
67    if ( $verbose ) {
68        print "(test cases passed:", $suite_cases_passed,
69                " failed:", $suite_cases_failed,
70                " skipped:", $suite_cases_skipped,
71                " of total:", ($suite_cases_passed + $suite_cases_failed +
72                               $suite_cases_skipped),
73                ")\n"
74    }
75
76    $total_cases_passed += $suite_cases_passed;
77    $total_cases_failed += $suite_cases_failed;
78    $total_cases_skipped += $suite_cases_skipped;
79}
80
81print "-" x 72, "\n";
82print $failed_suites ? "FAILED" : "PASSED";
83printf " (%d suites, %d tests run)\n", scalar @suites, $total_tests_run;
84
85if ( $verbose ) {
86    print "  test cases passed :", $total_cases_passed, "\n";
87    print "             failed :", $total_cases_failed, "\n";
88    print "            skipped :", $total_cases_skipped, "\n";
89    print "  of tests executed :", ( $total_cases_passed + $total_cases_failed ),
90            "\n";
91    print " of available tests :",
92            ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ),
93            "\n"
94    }
95
96exit( $failed_suites ? 1 : 0 );
97
98