blob: 78e01fce9ab54353fba1c1c9524c8e8af206b169 [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' => {
Xiaofei Baif40545d2021-12-02 08:43:35 +000032 'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010033 'test_again_with_use_psa' => 1
Gilles Peskine7a78a1f2020-11-09 14:44:04 +010034 },
Gilles Peskine8c5c2932022-02-25 19:28:00 +010035 'config-ccm-psk-dtls1_2.h' => {
36 'compat' => '-m dtls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Gilles Peskinedcb13af2022-02-25 21:00:16 +010037 'opt' => ' ',
38 'opt_needs_debug' => 1,
Gilles Peskine8c5c2932022-02-25 19:28:00 +010039 'test_again_with_use_psa' => 1
40 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010041 'config-mini-tls1_1.h' => {
Andrzej Kurek19d6ab02022-01-27 11:01:24 -050042 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #',
Gilles Peskinedcb13af2022-02-25 21:00:16 +010043 ## Skip ssl-opt testing for now because ssl-opt.sh is missing a lot
44 ## of requires_xxx so it would try to run tests that don't apply.
45 # 'opt' => ' ',
46 # 'opt_needs_debug' => 1,
Andrzej Kurek19d6ab02022-01-27 11:01:24 -050047 'test_again_with_use_psa' => 1
Gilles Peskinefec30642019-10-10 20:30:54 +020048 },
Gilles Peskine25fdebf2020-11-09 15:15:17 +010049 'config-no-entropy.h' => {
50 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020051 'config-suite-b.h' => {
Xiaofei Baif40545d2021-12-02 08:43:35 +000052 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010053 'test_again_with_use_psa' => 1,
Gilles Peskinedcb13af2022-02-25 21:00:16 +010054 'opt' => ' ',
55 'opt_needs_debug' => 1,
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020056 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010057 'config-symmetric-only.h' => {
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010058 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice
Gilles Peskine12230eb2020-02-26 19:02:33 +010059 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010060 'config-thread.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010061 'opt' => '-f ECJPAKE.*nolog',
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010062 'test_again_with_use_psa' => 1,
Gilles Peskine12230eb2020-02-26 19:02:33 +010063 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020064);
65
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020066# If no config-name is provided, use all known configs.
67# Otherwise, use the provided names only.
Gilles Peskine20e25b92022-02-26 18:16:07 +010068my @configs_to_test = sort keys %configs;
Paul Bakker30a30622013-12-19 17:09:49 +010069if ($#ARGV >= 0) {
Gilles Peskine20e25b92022-02-26 18:16:07 +010070 foreach my $conf_name ( @ARGV ) {
71 if( ! exists $configs{$conf_name} ) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020072 die "Unknown configuration: $conf_name\n";
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020073 }
Paul Bakker30a30622013-12-19 17:09:49 +010074 }
Gilles Peskine20e25b92022-02-26 18:16:07 +010075 @configs_to_test = @ARGV;
Paul Bakker30a30622013-12-19 17:09:49 +010076}
77
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020078-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
79
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000080my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020081
82system( "cp $config_h $config_h.bak" ) and die;
83sub abort {
84 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020085 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020086 warn $_[0];
87 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020088}
89
Gilles Peskine581bfcf2019-10-11 17:19:45 +020090# Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
91# For test purposes, this doesn't have to be cryptographically random.
92if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
93 local *SEEDFILE;
94 open SEEDFILE, ">tests/seedfile" or die;
95 print SEEDFILE "*" x 64 or die;
96 close SEEDFILE or die;
97}
98
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010099sub perform_test {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100100 my $conf_file = $_[0];
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100101 my $data = $_[1];
102 my $test_with_psa = $_[2];
103
Gilles Peskinedef0e142022-03-14 19:05:48 +0100104 my $conf_name = $conf_file;
105 if ( $test_with_psa )
106 {
107 $conf_name .= "+PSA";
108 }
109
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200110 system( "cp $config_h.bak $config_h" ) and die;
111 system( "make clean" ) and die;
112
113 print "\n******************************************\n";
Gilles Peskinedef0e142022-03-14 19:05:48 +0100114 print "* Testing configuration: $conf_name\n";
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200115 print "******************************************\n";
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100116
Gilles Peskinedef0e142022-03-14 19:05:48 +0100117 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200118
Gilles Peskinedef0e142022-03-14 19:05:48 +0100119 system( "cp configs/$conf_file $config_h" )
120 and abort "Failed to activate $conf_file\n";
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200121
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100122 if ( $test_with_psa )
123 {
124 system( "scripts/config.py set MBEDTLS_PSA_CRYPTO_C" );
125 system( "scripts/config.py set MBEDTLS_USE_PSA_CRYPTO" );
126 }
127
Gilles Peskinedef0e142022-03-14 19:05:48 +0100128 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
129 system( "make test" ) and abort "Failed test suite: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100130
131 my $compat = $data->{'compat'};
132 if( $compat )
133 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100134 print "\nrunning compat.sh $compat ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100135 system( "tests/compat.sh $compat" )
Gilles Peskinedef0e142022-03-14 19:05:48 +0100136 and abort "Failed compat.sh: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100137 }
138 else
139 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100140 print "\nskipping compat.sh ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100141 }
142
143 my $opt = $data->{'opt'};
144 if( $opt )
145 {
Gilles Peskinedcb13af2022-02-25 21:00:16 +0100146 if( $data->{'opt_needs_debug'} )
147 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100148 print "\nrebuilding with debug traces for ssl-opt ($conf_name)\n";
149 $conf_name .= '+DEBUG';
150 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
Gilles Peskinedcb13af2022-02-25 21:00:16 +0100151 system( "make clean" );
152 system( "scripts/config.py set MBEDTLS_DEBUG_C" );
153 system( "scripts/config.py set MBEDTLS_ERROR_C" );
Gilles Peskinedef0e142022-03-14 19:05:48 +0100154 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
Gilles Peskinedcb13af2022-02-25 21:00:16 +0100155 }
156
Gilles Peskinedef0e142022-03-14 19:05:48 +0100157 print "\nrunning ssl-opt.sh $opt ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100158 system( "tests/ssl-opt.sh $opt" )
Gilles Peskinedef0e142022-03-14 19:05:48 +0100159 and abort "Failed ssl-opt.sh: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100160 }
161 else
162 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100163 print "\nskipping ssl-opt.sh ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100164 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200165}
166
Gilles Peskine20e25b92022-02-26 18:16:07 +0100167foreach my $conf ( @configs_to_test ) {
168 my $test_with_psa = $configs{$conf}{'test_again_with_use_psa'};
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100169 if ( $test_with_psa )
170 {
Gilles Peskine20e25b92022-02-26 18:16:07 +0100171 perform_test( $conf, $configs{$conf}, $test_with_psa );
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100172 }
Gilles Peskine20e25b92022-02-26 18:16:07 +0100173 perform_test( $conf, $configs{$conf}, 0 );
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100174}
175
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200176system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
177system( "make clean" );
178exit 0;