blob: a434b46b284c7ad504d0b1582404733ec51eb5eb [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +02002
Simon Butcherf95c1762016-11-10 17:25:58 +00003# test-ref-configs.pl
4#
5# This file is part of mbed TLS (https://tls.mbed.org)
6#
7# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
8#
9# Purpose
10#
11# For each reference configuration file in the configs directory, build the
12# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020013#
14# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020015
16use warnings;
17use strict;
18
19my %configs = (
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020020 'config-mini-tls1_1.h' => {
Gilles Peskinea708dae2019-09-16 15:06:03 +020021 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #'
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020022 },
23 'config-suite-b.h' => {
24 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
25 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020026 'config-ccm-psk-tls1_2.h' => {
27 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
28 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020029 'config-thread.h' => {
30 'opt' => '-f ECJPAKE.*nolog',
31 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020032);
33
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020034# If no config-name is provided, use all known configs.
35# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010036if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020037 my %configs_ori = ( %configs );
38 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010039
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020040 foreach my $conf_name (@ARGV) {
41 if( ! exists $configs_ori{$conf_name} ) {
42 die "Unknown configuration: $conf_name\n";
43 } else {
44 $configs{$conf_name} = $configs_ori{$conf_name};
45 }
Paul Bakker30a30622013-12-19 17:09:49 +010046 }
Paul Bakker30a30622013-12-19 17:09:49 +010047}
48
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020049-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
50
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000051my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020052
53system( "cp $config_h $config_h.bak" ) and die;
54sub abort {
55 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020056 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020057 warn $_[0];
58 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020059}
60
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020061while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020062 system( "cp $config_h.bak $config_h" ) and die;
63 system( "make clean" ) and die;
64
65 print "\n******************************************\n";
66 print "* Testing configuration: $conf\n";
67 print "******************************************\n";
68
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +020069 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020070 and abort "Failed to activate $conf\n";
71
Simon Butcherf95c1762016-11-10 17:25:58 +000072 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010073 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020074
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020075 my $compat = $data->{'compat'};
76 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020077 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020078 print "\nrunning compat.sh $compat\n";
79 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020080 and abort "Failed compat.sh: $conf\n";
81 }
82 else
83 {
84 print "\nskipping compat.sh\n";
85 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020086
87 my $opt = $data->{'opt'};
88 if( $opt )
89 {
90 print "\nrunning ssl-opt.sh $opt\n";
91 system( "tests/ssl-opt.sh $opt" )
92 and abort "Failed ssl-opt.sh: $conf\n";
93 }
94 else
95 {
96 print "\nskipping ssl-opt.sh\n";
97 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020098}
99
100system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
101system( "make clean" );
102exit 0;