blob: 055023a5f2cf7b0a375694b1b19f03a657d6c295 [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 Rodgman16799db2023-11-02 19:47:20 +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 Bai8b5c3822021-12-02 08:43:35 +000020 'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Andrzej Kurek01005b92022-01-17 15:32:02 +010021 'test_again_with_use_psa' => 1
Gilles Peskine7a78a1f2020-11-09 14:44:04 +010022 },
Gilles Peskine168f17c2022-02-25 19:28:00 +010023 'config-ccm-psk-dtls1_2.h' => {
24 'compat' => '-m dtls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Gilles Peskinec6d197b2022-02-25 21:00:16 +010025 'opt' => ' ',
26 'opt_needs_debug' => 1,
Gilles Peskine168f17c2022-02-25 19:28:00 +010027 'test_again_with_use_psa' => 1
28 },
Gilles Peskine25fdebf2020-11-09 15:15:17 +010029 'config-no-entropy.h' => {
30 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020031 'config-suite-b.h' => {
Xiaofei Bai8b5c3822021-12-02 08:43:35 +000032 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
Andrzej Kurek01005b92022-01-17 15:32:02 +010033 'test_again_with_use_psa' => 1,
Gilles Peskinec6d197b2022-02-25 21:00:16 +010034 'opt' => ' ',
35 'opt_needs_debug' => 1,
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020036 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010037 'config-symmetric-only.h' => {
Andrzej Kurek01005b92022-01-17 15:32:02 +010038 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice
Gilles Peskine12230eb2020-02-26 19:02:33 +010039 },
Gilles Peskine5baf6672023-09-06 17:17:10 +020040 'config-tfm.h' => {
41 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice
42 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010043 'config-thread.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010044 'opt' => '-f ECJPAKE.*nolog',
Andrzej Kurek01005b92022-01-17 15:32:02 +010045 'test_again_with_use_psa' => 1,
Gilles Peskine12230eb2020-02-26 19:02:33 +010046 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020047);
48
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020049# If no config-name is provided, use all known configs.
50# Otherwise, use the provided names only.
Gilles Peskined7df8772022-02-26 18:16:07 +010051my @configs_to_test = sort keys %configs;
Paul Bakker30a30622013-12-19 17:09:49 +010052if ($#ARGV >= 0) {
Gilles Peskined7df8772022-02-26 18:16:07 +010053 foreach my $conf_name ( @ARGV ) {
54 if( ! exists $configs{$conf_name} ) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020055 die "Unknown configuration: $conf_name\n";
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020056 }
Paul Bakker30a30622013-12-19 17:09:49 +010057 }
Gilles Peskined7df8772022-02-26 18:16:07 +010058 @configs_to_test = @ARGV;
Paul Bakker30a30622013-12-19 17:09:49 +010059}
60
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020061-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
62
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020063my $config_h = 'include/mbedtls/mbedtls_config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020064
65system( "cp $config_h $config_h.bak" ) and die;
66sub abort {
67 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020068 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020069 warn $_[0];
70 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020071}
72
Gilles Peskine581bfcf2019-10-11 17:19:45 +020073# Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
74# For test purposes, this doesn't have to be cryptographically random.
75if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
76 local *SEEDFILE;
77 open SEEDFILE, ">tests/seedfile" or die;
78 print SEEDFILE "*" x 64 or die;
79 close SEEDFILE or die;
80}
81
Andrzej Kurek01005b92022-01-17 15:32:02 +010082sub perform_test {
Gilles Peskinea2665412022-03-14 19:05:48 +010083 my $conf_file = $_[0];
Andrzej Kurek01005b92022-01-17 15:32:02 +010084 my $data = $_[1];
85 my $test_with_psa = $_[2];
86
Gilles Peskinea2665412022-03-14 19:05:48 +010087 my $conf_name = $conf_file;
88 if ( $test_with_psa )
89 {
90 $conf_name .= "+PSA";
91 }
92
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020093 system( "cp $config_h.bak $config_h" ) and die;
94 system( "make clean" ) and die;
95
96 print "\n******************************************\n";
Gilles Peskinea2665412022-03-14 19:05:48 +010097 print "* Testing configuration: $conf_name\n";
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020098 print "******************************************\n";
Andrzej Kurek01005b92022-01-17 15:32:02 +010099
Gilles Peskinea2665412022-03-14 19:05:48 +0100100 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200101
Gilles Peskinea2665412022-03-14 19:05:48 +0100102 system( "cp configs/$conf_file $config_h" )
103 and abort "Failed to activate $conf_file\n";
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200104
Andrzej Kurek01005b92022-01-17 15:32:02 +0100105 if ( $test_with_psa )
106 {
107 system( "scripts/config.py set MBEDTLS_PSA_CRYPTO_C" );
108 system( "scripts/config.py set MBEDTLS_USE_PSA_CRYPTO" );
109 }
110
Gilles Peskinea2665412022-03-14 19:05:48 +0100111 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
112 system( "make test" ) and abort "Failed test suite: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100113
114 my $compat = $data->{'compat'};
115 if( $compat )
116 {
Gilles Peskinea2665412022-03-14 19:05:48 +0100117 print "\nrunning compat.sh $compat ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100118 system( "tests/compat.sh $compat" )
Gilles Peskinea2665412022-03-14 19:05:48 +0100119 and abort "Failed compat.sh: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100120 }
121 else
122 {
Gilles Peskinea2665412022-03-14 19:05:48 +0100123 print "\nskipping compat.sh ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100124 }
125
126 my $opt = $data->{'opt'};
127 if( $opt )
128 {
Gilles Peskinec6d197b2022-02-25 21:00:16 +0100129 if( $data->{'opt_needs_debug'} )
130 {
Gilles Peskinea2665412022-03-14 19:05:48 +0100131 print "\nrebuilding with debug traces for ssl-opt ($conf_name)\n";
132 $conf_name .= '+DEBUG';
133 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
Gilles Peskinec6d197b2022-02-25 21:00:16 +0100134 system( "make clean" );
135 system( "scripts/config.py set MBEDTLS_DEBUG_C" );
136 system( "scripts/config.py set MBEDTLS_ERROR_C" );
Gilles Peskinea2665412022-03-14 19:05:48 +0100137 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
Gilles Peskinec6d197b2022-02-25 21:00:16 +0100138 }
139
Gilles Peskinea2665412022-03-14 19:05:48 +0100140 print "\nrunning ssl-opt.sh $opt ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100141 system( "tests/ssl-opt.sh $opt" )
Gilles Peskinea2665412022-03-14 19:05:48 +0100142 and abort "Failed ssl-opt.sh: $conf_name\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100143 }
144 else
145 {
Gilles Peskinea2665412022-03-14 19:05:48 +0100146 print "\nskipping ssl-opt.sh ($conf_name)\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +0100147 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200148}
149
Gilles Peskined7df8772022-02-26 18:16:07 +0100150foreach my $conf ( @configs_to_test ) {
151 my $test_with_psa = $configs{$conf}{'test_again_with_use_psa'};
Andrzej Kurek01005b92022-01-17 15:32:02 +0100152 if ( $test_with_psa )
153 {
Gilles Peskined7df8772022-02-26 18:16:07 +0100154 perform_test( $conf, $configs{$conf}, $test_with_psa );
Andrzej Kurek01005b92022-01-17 15:32:02 +0100155 }
Gilles Peskined7df8772022-02-26 18:16:07 +0100156 perform_test( $conf, $configs{$conf}, 0 );
Andrzej Kurek01005b92022-01-17 15:32:02 +0100157}
158
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200159system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
160system( "make clean" );
161exit 0;