blob: 3b91553b06f6a080c13bf788b337ae4ff8711a94 [file] [log] [blame]
fbrosson3a745712018-04-04 22:26:56 +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úti4e9f7122020-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úti09b4f192020-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úti4e9f7122020-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úti09b4f192020-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 },
66 'config-picocoin.h' => {
67 },
68 'config-ccm-psk-tls1_2.h' => {
69 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
70 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020071 'config-thread.h' => {
72 'opt' => '-f ECJPAKE.*nolog',
73 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020074);
75
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020076# If no config-name is provided, use all known configs.
77# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010078if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020079 my %configs_ori = ( %configs );
80 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010081
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020082 foreach my $conf_name (@ARGV) {
83 if( ! exists $configs_ori{$conf_name} ) {
84 die "Unknown configuration: $conf_name\n";
85 } else {
86 $configs{$conf_name} = $configs_ori{$conf_name};
87 }
Paul Bakker30a30622013-12-19 17:09:49 +010088 }
Paul Bakker30a30622013-12-19 17:09:49 +010089}
90
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020091-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
92
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020094
95system( "cp $config_h $config_h.bak" ) and die;
96sub abort {
97 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnardfa973e02017-10-26 09:47:36 +020098 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnardb26b28a2017-07-12 12:15:24 +020099 warn $_[0];
100 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200101}
102
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200103while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200104 system( "cp $config_h.bak $config_h" ) and die;
105 system( "make clean" ) and die;
106
107 print "\n******************************************\n";
108 print "* Testing configuration: $conf\n";
109 print "******************************************\n";
110
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +0200111 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200112 and abort "Failed to activate $conf\n";
113
Simon Butcherf95c1762016-11-10 17:25:58 +0000114 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +0100115 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200116
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200117 my $compat = $data->{'compat'};
118 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200119 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +0200120 print "\nrunning compat.sh $compat\n";
121 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +0200122 and abort "Failed compat.sh: $conf\n";
123 }
124 else
125 {
126 print "\nskipping compat.sh\n";
127 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +0200128
129 my $opt = $data->{'opt'};
130 if( $opt )
131 {
132 print "\nrunning ssl-opt.sh $opt\n";
133 system( "tests/ssl-opt.sh $opt" )
134 and abort "Failed ssl-opt.sh: $conf\n";
135 }
136 else
137 {
138 print "\nskipping ssl-opt.sh\n";
139 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200140}
141
142system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
143system( "make clean" );
144exit 0;