blob: 54bc777287e119429442f9e50fc808cebe978ba5 [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útif744bd72020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Bence Szépkúti51b41d52020-05-26 01:54:15 +020013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkútif744bd72020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
Bence Szépkúti51b41d52020-05-26 01:54:15 +020047# This file is part of Mbed TLS (https://tls.mbed.org)
Simon Butcherf95c1762016-11-10 17:25:58 +000048#
49# Purpose
50#
51# For each reference configuration file in the configs directory, build the
52# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020053#
54# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020055
56use warnings;
57use strict;
58
59my %configs = (
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020060 'config-mini-tls1_1.h' => {
61 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
62 },
63 'config-suite-b.h' => {
64 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
65 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020066 'config-ccm-psk-tls1_2.h' => {
67 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
68 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020069 'config-thread.h' => {
70 'opt' => '-f ECJPAKE.*nolog',
71 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020072);
73
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020074# If no config-name is provided, use all known configs.
75# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010076if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020077 my %configs_ori = ( %configs );
78 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010079
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020080 foreach my $conf_name (@ARGV) {
81 if( ! exists $configs_ori{$conf_name} ) {
82 die "Unknown configuration: $conf_name\n";
83 } else {
84 $configs{$conf_name} = $configs_ori{$conf_name};
85 }
Paul Bakker30a30622013-12-19 17:09:49 +010086 }
Paul Bakker30a30622013-12-19 17:09:49 +010087}
88
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020089-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
90
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000091my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020092
93system( "cp $config_h $config_h.bak" ) and die;
94sub abort {
95 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020096 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020097 warn $_[0];
98 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020099}
100
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200101while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200102 system( "cp $config_h.bak $config_h" ) and die;
103 system( "make clean" ) and die;
104
105 print "\n******************************************\n";
106 print "* Testing configuration: $conf\n";
107 print "******************************************\n";
108
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +0200109 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200110 and abort "Failed to activate $conf\n";
111
Simon Butcherf95c1762016-11-10 17:25:58 +0000112 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +0100113 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200114
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200115 my $compat = $data->{'compat'};
116 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200117 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200118 print "\nrunning compat.sh $compat\n";
119 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200120 and abort "Failed compat.sh: $conf\n";
121 }
122 else
123 {
124 print "\nskipping compat.sh\n";
125 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +0200126
127 my $opt = $data->{'opt'};
128 if( $opt )
129 {
130 print "\nrunning ssl-opt.sh $opt\n";
131 system( "tests/ssl-opt.sh $opt" )
132 and abort "Failed ssl-opt.sh: $conf\n";
133 }
134 else
135 {
136 print "\nskipping ssl-opt.sh\n";
137 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200138}
139
140system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
141system( "make clean" );
142exit 0;