blob: dc0f120e4401656cfa8492153c198f631470fc73 [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 Bai8b5c3822021-12-02 08:43:35 +000032 'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Andrzej Kurek01005b92022-01-17 15:32:02 +010033 'test_again_with_use_psa' => 1
Gilles Peskine7a78a1f2020-11-09 14:44:04 +010034 },
Gilles Peskine25fdebf2020-11-09 15:15:17 +010035 'config-no-entropy.h' => {
36 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020037 'config-suite-b.h' => {
Xiaofei Bai8b5c3822021-12-02 08:43:35 +000038 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
Andrzej Kurek01005b92022-01-17 15:32:02 +010039 'test_again_with_use_psa' => 1,
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020040 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010041 'config-symmetric-only.h' => {
Andrzej Kurek01005b92022-01-17 15:32:02 +010042 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice
Gilles Peskine12230eb2020-02-26 19:02:33 +010043 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010044 'config-thread.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010045 'opt' => '-f ECJPAKE.*nolog',
Andrzej Kurek01005b92022-01-17 15:32:02 +010046 'test_again_with_use_psa' => 1,
Gilles Peskine12230eb2020-02-26 19:02:33 +010047 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020048);
49
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020050# If no config-name is provided, use all known configs.
51# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010052if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020053 my %configs_ori = ( %configs );
54 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010055
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020056 foreach my $conf_name (@ARGV) {
57 if( ! exists $configs_ori{$conf_name} ) {
58 die "Unknown configuration: $conf_name\n";
59 } else {
60 $configs{$conf_name} = $configs_ori{$conf_name};
61 }
Paul Bakker30a30622013-12-19 17:09:49 +010062 }
Paul Bakker30a30622013-12-19 17:09:49 +010063}
64
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020065-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
66
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020067my $config_h = 'include/mbedtls/mbedtls_config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020068
69system( "cp $config_h $config_h.bak" ) and die;
70sub abort {
71 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020072 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020073 warn $_[0];
74 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020075}
76
Gilles Peskine581bfcf2019-10-11 17:19:45 +020077# Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
78# For test purposes, this doesn't have to be cryptographically random.
79if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
80 local *SEEDFILE;
81 open SEEDFILE, ">tests/seedfile" or die;
82 print SEEDFILE "*" x 64 or die;
83 close SEEDFILE or die;
84}
85
Andrzej Kurek01005b92022-01-17 15:32:02 +010086sub perform_test {
87 my $conf = $_[0];
88 my $data = $_[1];
89 my $test_with_psa = $_[2];
90
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020091 system( "cp $config_h.bak $config_h" ) and die;
92 system( "make clean" ) and die;
93
94 print "\n******************************************\n";
95 print "* Testing configuration: $conf\n";
Andrzej Kurek01005b92022-01-17 15:32:02 +010096 if ( $test_with_psa )
97 {
98 print "* ENABLING MBEDTLS_PSA_CRYPTO_C and MBEDTLS_USE_PSA_CRYPTO \n";
99 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200100 print "******************************************\n";
Andrzej Kurek01005b92022-01-17 15:32:02 +0100101
Gilles Peskinea9478ba2019-09-18 18:45:35 +0200102 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200103
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +0200104 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200105 and abort "Failed to activate $conf\n";
106
Andrzej Kurek01005b92022-01-17 15:32:02 +0100107 if ( $test_with_psa )
108 {
109 system( "scripts/config.py set MBEDTLS_PSA_CRYPTO_C" );
110 system( "scripts/config.py set MBEDTLS_USE_PSA_CRYPTO" );
111 }
112
Simon Butcherf95c1762016-11-10 17:25:58 +0000113 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +0100114 system( "make test" ) and abort "Failed test suite: $conf\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100115
116 my $compat = $data->{'compat'};
117 if( $compat )
118 {
119 print "\nrunning compat.sh $compat\n";
120 system( "tests/compat.sh $compat" )
121 and abort "Failed compat.sh: $conf\n";
122 }
123 else
124 {
125 print "\nskipping compat.sh\n";
126 }
127
128 my $opt = $data->{'opt'};
129 if( $opt )
130 {
131 print "\nrunning ssl-opt.sh $opt\n";
132 system( "tests/ssl-opt.sh $opt" )
133 and abort "Failed ssl-opt.sh: $conf\n";
134 }
135 else
136 {
137 print "\nskipping ssl-opt.sh\n";
138 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200139}
140
Andrzej Kurek01005b92022-01-17 15:32:02 +0100141while( my ($conf, $data) = each %configs ) {
142 my $test_with_psa = $data->{'test_again_with_use_psa'};
143 if ( $test_with_psa )
144 {
145 perform_test( $conf, $data, $test_with_psa );
146 }
147 perform_test( $conf, $data, 0 );
148}
149
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200150system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
151system( "make clean" );
152exit 0;