blob: a8bfa6e904fbf6c0fd635946e1573126eafba022 [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#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02005# Copyright The Mbed TLS Contributors
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#
Simon Butcherf95c1762016-11-10 17:25:58 +000047# Purpose
48#
49# For each reference configuration file in the configs directory, build the
50# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020051#
52# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020053
54use warnings;
55use strict;
56
57my %configs = (
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020058 'config-mini-tls1_1.h' => {
59 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
60 },
61 'config-suite-b.h' => {
62 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
63 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020064 'config-ccm-psk-tls1_2.h' => {
65 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
66 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020067 'config-thread.h' => {
68 'opt' => '-f ECJPAKE.*nolog',
69 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020070);
71
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020072# If no config-name is provided, use all known configs.
73# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010074if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020075 my %configs_ori = ( %configs );
76 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010077
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020078 foreach my $conf_name (@ARGV) {
79 if( ! exists $configs_ori{$conf_name} ) {
80 die "Unknown configuration: $conf_name\n";
81 } else {
82 $configs{$conf_name} = $configs_ori{$conf_name};
83 }
Paul Bakker30a30622013-12-19 17:09:49 +010084 }
Paul Bakker30a30622013-12-19 17:09:49 +010085}
86
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020087-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
88
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000089my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020090
91system( "cp $config_h $config_h.bak" ) and die;
92sub abort {
93 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020094 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020095 warn $_[0];
96 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020097}
98
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020099while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200100 system( "cp $config_h.bak $config_h" ) and die;
101 system( "make clean" ) and die;
102
103 print "\n******************************************\n";
104 print "* Testing configuration: $conf\n";
105 print "******************************************\n";
106
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +0200107 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200108 and abort "Failed to activate $conf\n";
109
Simon Butcherf95c1762016-11-10 17:25:58 +0000110 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +0100111 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200112
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200113 my $compat = $data->{'compat'};
114 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200115 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200116 print "\nrunning compat.sh $compat\n";
117 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200118 and abort "Failed compat.sh: $conf\n";
119 }
120 else
121 {
122 print "\nskipping compat.sh\n";
123 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +0200124
125 my $opt = $data->{'opt'};
126 if( $opt )
127 {
128 print "\nrunning ssl-opt.sh $opt\n";
129 system( "tests/ssl-opt.sh $opt" )
130 and abort "Failed ssl-opt.sh: $conf\n";
131 }
132 else
133 {
134 print "\nskipping ssl-opt.sh\n";
135 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200136}
137
138system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
139system( "make clean" );
140exit 0;