blob: cf4175af2c53d25779574755c84eb91019c26684 [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úti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-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#
Simon Butcherf95c1762016-11-10 17:25:58 +000020# Purpose
21#
22# For each reference configuration file in the configs directory, build the
Gilles Peskine7dc97042020-02-26 19:48:43 +010023# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020024#
25# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020026
27use warnings;
28use strict;
29
30my %configs = (
Gilles Peskine7a78a1f2020-11-09 14:44:04 +010031 'config-ccm-psk-tls1_2.h' => {
32 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
33 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010034 'config-mini-tls1_1.h' => {
Gilles Peskine7415f2f2019-09-16 15:06:03 +020035 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #'
Gilles Peskinefec30642019-10-10 20:30:54 +020036 },
Gilles Peskine25fdebf2020-11-09 15:15:17 +010037 'config-no-entropy.h' => {
38 },
39 'config-psa-crypto.h' => {
40 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020041 'config-suite-b.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010042 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020043 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010044 'config-symmetric-only.h' => {
45 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010046 'config-thread.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010047 'opt' => '-f ECJPAKE.*nolog',
Gilles Peskine12230eb2020-02-26 19:02:33 +010048 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020049);
50
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020051# If no config-name is provided, use all known configs.
52# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010053if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020054 my %configs_ori = ( %configs );
55 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010056
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020057 foreach my $conf_name (@ARGV) {
58 if( ! exists $configs_ori{$conf_name} ) {
59 die "Unknown configuration: $conf_name\n";
60 } else {
61 $configs{$conf_name} = $configs_ori{$conf_name};
62 }
Paul Bakker30a30622013-12-19 17:09:49 +010063 }
Paul Bakker30a30622013-12-19 17:09:49 +010064}
65
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020066-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
67
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000068my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020069
70system( "cp $config_h $config_h.bak" ) and die;
71sub abort {
72 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020073 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020074 warn $_[0];
75 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020076}
77
Gilles Peskine581bfcf2019-10-11 17:19:45 +020078# Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
79# For test purposes, this doesn't have to be cryptographically random.
80if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
81 local *SEEDFILE;
82 open SEEDFILE, ">tests/seedfile" or die;
83 print SEEDFILE "*" x 64 or die;
84 close SEEDFILE or die;
85}
86
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020087while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020088 system( "cp $config_h.bak $config_h" ) and die;
89 system( "make clean" ) and die;
90
91 print "\n******************************************\n";
92 print "* Testing configuration: $conf\n";
93 print "******************************************\n";
Gilles Peskinea9478ba2019-09-18 18:45:35 +020094 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020095
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +020096 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020097 and abort "Failed to activate $conf\n";
98
Simon Butcherf95c1762016-11-10 17:25:58 +000099 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +0100100 system( "make test" ) and abort "Failed test suite: $conf\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100101
102 my $compat = $data->{'compat'};
103 if( $compat )
104 {
105 print "\nrunning compat.sh $compat\n";
106 system( "tests/compat.sh $compat" )
107 and abort "Failed compat.sh: $conf\n";
108 }
109 else
110 {
111 print "\nskipping compat.sh\n";
112 }
113
114 my $opt = $data->{'opt'};
115 if( $opt )
116 {
117 print "\nrunning ssl-opt.sh $opt\n";
118 system( "tests/ssl-opt.sh $opt" )
119 and abort "Failed ssl-opt.sh: $conf\n";
120 }
121 else
122 {
123 print "\nskipping ssl-opt.sh\n";
124 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200125}
126
127system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
128system( "make clean" );
129exit 0;