blob: d5b66e0a2da4415ad992334a399065dba41f0119 [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
Dave Rodgman7ff79652023-11-03 12:04:52 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02007#
Simon Butcherf95c1762016-11-10 17:25:58 +00008# Purpose
9#
10# For each reference configuration file in the configs directory, build the
Gilles Peskine7dc97042020-02-26 19:48:43 +010011# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020012#
13# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020014
15use warnings;
16use strict;
17
18my %configs = (
Gilles Peskine7a78a1f2020-11-09 14:44:04 +010019 'config-ccm-psk-tls1_2.h' => {
Xiaofei Baif40545d2021-12-02 08:43:35 +000020 'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010021 'test_again_with_use_psa' => 1
Gilles Peskine7a78a1f2020-11-09 14:44:04 +010022 },
Gilles Peskine8c5c2932022-02-25 19:28:00 +010023 'config-ccm-psk-dtls1_2.h' => {
24 'compat' => '-m dtls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Gilles Peskinedcb13af2022-02-25 21:00:16 +010025 'opt' => ' ',
26 'opt_needs_debug' => 1,
Gilles Peskine8c5c2932022-02-25 19:28:00 +010027 'test_again_with_use_psa' => 1
28 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010029 'config-mini-tls1_1.h' => {
Gilles Peskine8f5722a2024-05-30 15:17:28 +020030 # Include DES; exclude (EC)DH; only pure-RSA key exchanges
Gilles Peskine5a63e2f2024-05-31 13:36:55 +020031 'compat' => '-m tls1_1 -e \'NULL\|RC4\|ARCFOUR\|ARIA\|CAMELLIA\|DH\|PSK\' -t RSA',
Gilles Peskinedcb13af2022-02-25 21:00:16 +010032 ## Skip ssl-opt testing for now because ssl-opt.sh is missing a lot
33 ## of requires_xxx so it would try to run tests that don't apply.
34 # 'opt' => ' ',
35 # 'opt_needs_debug' => 1,
Andrzej Kurek19d6ab02022-01-27 11:01:24 -050036 'test_again_with_use_psa' => 1
Gilles Peskinefec30642019-10-10 20:30:54 +020037 },
Gilles Peskine25fdebf2020-11-09 15:15:17 +010038 'config-no-entropy.h' => {
39 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020040 'config-suite-b.h' => {
Xiaofei Baif40545d2021-12-02 08:43:35 +000041 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010042 'test_again_with_use_psa' => 1,
Gilles Peskinedcb13af2022-02-25 21:00:16 +010043 'opt' => ' ',
44 'opt_needs_debug' => 1,
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020045 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010046 'config-symmetric-only.h' => {
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010047 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice
Gilles Peskine12230eb2020-02-26 19:02:33 +010048 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010049 'config-thread.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010050 'opt' => '-f ECJPAKE.*nolog',
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010051 'test_again_with_use_psa' => 1,
Gilles Peskine12230eb2020-02-26 19:02:33 +010052 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020053);
54
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020055# If no config-name is provided, use all known configs.
56# Otherwise, use the provided names only.
Gilles Peskine20e25b92022-02-26 18:16:07 +010057my @configs_to_test = sort keys %configs;
Paul Bakker30a30622013-12-19 17:09:49 +010058if ($#ARGV >= 0) {
Gilles Peskine20e25b92022-02-26 18:16:07 +010059 foreach my $conf_name ( @ARGV ) {
60 if( ! exists $configs{$conf_name} ) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020061 die "Unknown configuration: $conf_name\n";
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020062 }
Paul Bakker30a30622013-12-19 17:09:49 +010063 }
Gilles Peskine20e25b92022-02-26 18:16:07 +010064 @configs_to_test = @ARGV;
Paul Bakker30a30622013-12-19 17:09:49 +010065}
66
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020067-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
68
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020070
71system( "cp $config_h $config_h.bak" ) and die;
72sub abort {
73 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020074 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020075 warn $_[0];
76 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020077}
78
Gilles Peskine581bfcf2019-10-11 17:19:45 +020079# Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
80# For test purposes, this doesn't have to be cryptographically random.
81if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
82 local *SEEDFILE;
83 open SEEDFILE, ">tests/seedfile" or die;
84 print SEEDFILE "*" x 64 or die;
85 close SEEDFILE or die;
86}
87
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010088sub perform_test {
Gilles Peskinedef0e142022-03-14 19:05:48 +010089 my $conf_file = $_[0];
Andrzej Kurek19e83fa2022-01-17 16:05:43 +010090 my $data = $_[1];
91 my $test_with_psa = $_[2];
92
Gilles Peskinedef0e142022-03-14 19:05:48 +010093 my $conf_name = $conf_file;
94 if ( $test_with_psa )
95 {
96 $conf_name .= "+PSA";
97 }
98
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020099 system( "cp $config_h.bak $config_h" ) and die;
100 system( "make clean" ) and die;
101
102 print "\n******************************************\n";
Gilles Peskinedef0e142022-03-14 19:05:48 +0100103 print "* Testing configuration: $conf_name\n";
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200104 print "******************************************\n";
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100105
Gilles Peskinedef0e142022-03-14 19:05:48 +0100106 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200107
Gilles Peskinedef0e142022-03-14 19:05:48 +0100108 system( "cp configs/$conf_file $config_h" )
109 and abort "Failed to activate $conf_file\n";
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200110
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100111 if ( $test_with_psa )
112 {
113 system( "scripts/config.py set MBEDTLS_PSA_CRYPTO_C" );
114 system( "scripts/config.py set MBEDTLS_USE_PSA_CRYPTO" );
115 }
116
Gilles Peskinedef0e142022-03-14 19:05:48 +0100117 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
118 system( "make test" ) and abort "Failed test suite: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100119
120 my $compat = $data->{'compat'};
121 if( $compat )
122 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100123 print "\nrunning compat.sh $compat ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100124 system( "tests/compat.sh $compat" )
Gilles Peskinedef0e142022-03-14 19:05:48 +0100125 and abort "Failed compat.sh: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100126 }
127 else
128 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100129 print "\nskipping compat.sh ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100130 }
131
132 my $opt = $data->{'opt'};
133 if( $opt )
134 {
Gilles Peskinedcb13af2022-02-25 21:00:16 +0100135 if( $data->{'opt_needs_debug'} )
136 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100137 print "\nrebuilding with debug traces for ssl-opt ($conf_name)\n";
138 $conf_name .= '+DEBUG';
139 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
Gilles Peskinedcb13af2022-02-25 21:00:16 +0100140 system( "make clean" );
141 system( "scripts/config.py set MBEDTLS_DEBUG_C" );
142 system( "scripts/config.py set MBEDTLS_ERROR_C" );
Gilles Peskinedef0e142022-03-14 19:05:48 +0100143 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
Gilles Peskinedcb13af2022-02-25 21:00:16 +0100144 }
145
Gilles Peskinedef0e142022-03-14 19:05:48 +0100146 print "\nrunning ssl-opt.sh $opt ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100147 system( "tests/ssl-opt.sh $opt" )
Gilles Peskinedef0e142022-03-14 19:05:48 +0100148 and abort "Failed ssl-opt.sh: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100149 }
150 else
151 {
Gilles Peskinedef0e142022-03-14 19:05:48 +0100152 print "\nskipping ssl-opt.sh ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100153 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200154}
155
Gilles Peskine20e25b92022-02-26 18:16:07 +0100156foreach my $conf ( @configs_to_test ) {
157 my $test_with_psa = $configs{$conf}{'test_again_with_use_psa'};
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100158 if ( $test_with_psa )
159 {
Gilles Peskine20e25b92022-02-26 18:16:07 +0100160 perform_test( $conf, $configs{$conf}, $test_with_psa );
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100161 }
Gilles Peskine20e25b92022-02-26 18:16:07 +0100162 perform_test( $conf, $configs{$conf}, 0 );
Andrzej Kurek19e83fa2022-01-17 16:05:43 +0100163}
164
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200165system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
166system( "make clean" );
167exit 0;