blob: ea5754f010e44751e3375ae91baa437a9abfb075 [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#
Simon Butcherf95c1762016-11-10 17:25:58 +00005# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
Bence Szépkúti51b41d52020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# This file is part of Mbed TLS (https://tls.mbed.org)
Simon Butcherf95c1762016-11-10 17:25:58 +000021#
22# Purpose
23#
24# For each reference configuration file in the configs directory, build the
25# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020026#
27# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020028
29use warnings;
30use strict;
31
32my %configs = (
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020033 'config-mini-tls1_1.h' => {
34 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
35 },
36 'config-suite-b.h' => {
37 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
38 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020039 'config-ccm-psk-tls1_2.h' => {
40 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
41 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020042 'config-thread.h' => {
43 'opt' => '-f ECJPAKE.*nolog',
44 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020045);
46
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020047# If no config-name is provided, use all known configs.
48# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010049if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020050 my %configs_ori = ( %configs );
51 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010052
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020053 foreach my $conf_name (@ARGV) {
54 if( ! exists $configs_ori{$conf_name} ) {
55 die "Unknown configuration: $conf_name\n";
56 } else {
57 $configs{$conf_name} = $configs_ori{$conf_name};
58 }
Paul Bakker30a30622013-12-19 17:09:49 +010059 }
Paul Bakker30a30622013-12-19 17:09:49 +010060}
61
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020062-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
63
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000064my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020065
66system( "cp $config_h $config_h.bak" ) and die;
67sub abort {
68 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020069 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020070 warn $_[0];
71 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020072}
73
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020074while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020075 system( "cp $config_h.bak $config_h" ) and die;
76 system( "make clean" ) and die;
77
78 print "\n******************************************\n";
79 print "* Testing configuration: $conf\n";
80 print "******************************************\n";
81
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +020082 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020083 and abort "Failed to activate $conf\n";
84
Simon Butcherf95c1762016-11-10 17:25:58 +000085 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010086 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020087
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020088 my $compat = $data->{'compat'};
89 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020090 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020091 print "\nrunning compat.sh $compat\n";
92 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020093 and abort "Failed compat.sh: $conf\n";
94 }
95 else
96 {
97 print "\nskipping compat.sh\n";
98 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020099
100 my $opt = $data->{'opt'};
101 if( $opt )
102 {
103 print "\nrunning ssl-opt.sh $opt\n";
104 system( "tests/ssl-opt.sh $opt" )
105 and abort "Failed ssl-opt.sh: $conf\n";
106 }
107 else
108 {
109 print "\nskipping ssl-opt.sh\n";
110 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200111}
112
113system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
114system( "make clean" );
115exit 0;