fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 2 | |
Simon Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 3 | # test-ref-configs.pl |
| 4 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 6 | # 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 Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 20 | # Purpose |
| 21 | # |
| 22 | # For each reference configuration file in the configs directory, build the |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 23 | # configuration, run the test suites and compat.sh |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 24 | # |
| 25 | # Usage: tests/scripts/test-ref-configs.pl [config-name [...]] |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 26 | |
| 27 | use warnings; |
| 28 | use strict; |
| 29 | |
| 30 | my %configs = ( |
Gilles Peskine | 7a78a1f | 2020-11-09 14:44:04 +0100 | [diff] [blame] | 31 | 'config-ccm-psk-tls1_2.h' => { |
Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 32 | 'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'', |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 33 | 'test_again_with_use_psa' => 1 |
Gilles Peskine | 7a78a1f | 2020-11-09 14:44:04 +0100 | [diff] [blame] | 34 | }, |
Gilles Peskine | 168f17c | 2022-02-25 19:28:00 +0100 | [diff] [blame] | 35 | 'config-ccm-psk-dtls1_2.h' => { |
| 36 | 'compat' => '-m dtls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'', |
Gilles Peskine | c6d197b | 2022-02-25 21:00:16 +0100 | [diff] [blame] | 37 | 'opt' => ' ', |
| 38 | 'opt_needs_debug' => 1, |
Gilles Peskine | 168f17c | 2022-02-25 19:28:00 +0100 | [diff] [blame] | 39 | 'test_again_with_use_psa' => 1 |
| 40 | }, |
Gilles Peskine | 25fdebf | 2020-11-09 15:15:17 +0100 | [diff] [blame] | 41 | 'config-no-entropy.h' => { |
| 42 | }, |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 43 | 'config-suite-b.h' => { |
Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 44 | 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS", |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 45 | 'test_again_with_use_psa' => 1, |
Gilles Peskine | c6d197b | 2022-02-25 21:00:16 +0100 | [diff] [blame] | 46 | 'opt' => ' ', |
| 47 | 'opt_needs_debug' => 1, |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 48 | }, |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 49 | 'config-symmetric-only.h' => { |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 50 | 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 51 | }, |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 52 | 'config-thread.h' => { |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 53 | 'opt' => '-f ECJPAKE.*nolog', |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 54 | 'test_again_with_use_psa' => 1, |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 55 | }, |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 56 | ); |
| 57 | |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 58 | # If no config-name is provided, use all known configs. |
| 59 | # Otherwise, use the provided names only. |
Gilles Peskine | d7df877 | 2022-02-26 18:16:07 +0100 | [diff] [blame] | 60 | my @configs_to_test = sort keys %configs; |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 61 | if ($#ARGV >= 0) { |
Gilles Peskine | d7df877 | 2022-02-26 18:16:07 +0100 | [diff] [blame] | 62 | foreach my $conf_name ( @ARGV ) { |
| 63 | if( ! exists $configs{$conf_name} ) { |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 64 | die "Unknown configuration: $conf_name\n"; |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 65 | } |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 66 | } |
Gilles Peskine | d7df877 | 2022-02-26 18:16:07 +0100 | [diff] [blame] | 67 | @configs_to_test = @ARGV; |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 70 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 71 | |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 72 | my $config_h = 'include/mbedtls/mbedtls_config.h'; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 73 | |
| 74 | system( "cp $config_h $config_h.bak" ) and die; |
| 75 | sub abort { |
| 76 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
Manuel Pégourié-Gonnard | 254eec8 | 2017-10-26 09:47:36 +0200 | [diff] [blame] | 77 | # use an exit code between 1 and 124 for git bisect (die returns 255) |
Manuel Pégourié-Gonnard | a7c4c8a | 2017-07-12 12:15:24 +0200 | [diff] [blame] | 78 | warn $_[0]; |
| 79 | exit 1; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 80 | } |
| 81 | |
Gilles Peskine | 581bfcf | 2019-10-11 17:19:45 +0200 | [diff] [blame] | 82 | # Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED. |
| 83 | # For test purposes, this doesn't have to be cryptographically random. |
| 84 | if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) { |
| 85 | local *SEEDFILE; |
| 86 | open SEEDFILE, ">tests/seedfile" or die; |
| 87 | print SEEDFILE "*" x 64 or die; |
| 88 | close SEEDFILE or die; |
| 89 | } |
| 90 | |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 91 | sub perform_test { |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 92 | my $conf_file = $_[0]; |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 93 | my $data = $_[1]; |
| 94 | my $test_with_psa = $_[2]; |
| 95 | |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 96 | my $conf_name = $conf_file; |
| 97 | if ( $test_with_psa ) |
| 98 | { |
| 99 | $conf_name .= "+PSA"; |
| 100 | } |
| 101 | |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 102 | system( "cp $config_h.bak $config_h" ) and die; |
| 103 | system( "make clean" ) and die; |
| 104 | |
| 105 | print "\n******************************************\n"; |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 106 | print "* Testing configuration: $conf_name\n"; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 107 | print "******************************************\n"; |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 108 | |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 109 | $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 110 | |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 111 | system( "cp configs/$conf_file $config_h" ) |
| 112 | and abort "Failed to activate $conf_file\n"; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 113 | |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 114 | if ( $test_with_psa ) |
| 115 | { |
| 116 | system( "scripts/config.py set MBEDTLS_PSA_CRYPTO_C" ); |
| 117 | system( "scripts/config.py set MBEDTLS_USE_PSA_CRYPTO" ); |
| 118 | } |
| 119 | |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 120 | system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n"; |
| 121 | system( "make test" ) and abort "Failed test suite: $conf_name\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 122 | |
| 123 | my $compat = $data->{'compat'}; |
| 124 | if( $compat ) |
| 125 | { |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 126 | print "\nrunning compat.sh $compat ($conf_name)\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 127 | system( "tests/compat.sh $compat" ) |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 128 | and abort "Failed compat.sh: $conf_name\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 129 | } |
| 130 | else |
| 131 | { |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 132 | print "\nskipping compat.sh ($conf_name)\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | my $opt = $data->{'opt'}; |
| 136 | if( $opt ) |
| 137 | { |
Gilles Peskine | c6d197b | 2022-02-25 21:00:16 +0100 | [diff] [blame] | 138 | if( $data->{'opt_needs_debug'} ) |
| 139 | { |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 140 | print "\nrebuilding with debug traces for ssl-opt ($conf_name)\n"; |
| 141 | $conf_name .= '+DEBUG'; |
| 142 | $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name; |
Gilles Peskine | c6d197b | 2022-02-25 21:00:16 +0100 | [diff] [blame] | 143 | system( "make clean" ); |
| 144 | system( "scripts/config.py set MBEDTLS_DEBUG_C" ); |
| 145 | system( "scripts/config.py set MBEDTLS_ERROR_C" ); |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 146 | system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n"; |
Gilles Peskine | c6d197b | 2022-02-25 21:00:16 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 149 | print "\nrunning ssl-opt.sh $opt ($conf_name)\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 150 | system( "tests/ssl-opt.sh $opt" ) |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 151 | and abort "Failed ssl-opt.sh: $conf_name\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 152 | } |
| 153 | else |
| 154 | { |
Gilles Peskine | a266541 | 2022-03-14 19:05:48 +0100 | [diff] [blame] | 155 | print "\nskipping ssl-opt.sh ($conf_name)\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 156 | } |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Gilles Peskine | d7df877 | 2022-02-26 18:16:07 +0100 | [diff] [blame] | 159 | foreach my $conf ( @configs_to_test ) { |
| 160 | my $test_with_psa = $configs{$conf}{'test_again_with_use_psa'}; |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 161 | if ( $test_with_psa ) |
| 162 | { |
Gilles Peskine | d7df877 | 2022-02-26 18:16:07 +0100 | [diff] [blame] | 163 | perform_test( $conf, $configs{$conf}, $test_with_psa ); |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 164 | } |
Gilles Peskine | d7df877 | 2022-02-26 18:16:07 +0100 | [diff] [blame] | 165 | perform_test( $conf, $configs{$conf}, 0 ); |
Andrzej Kurek | 01005b9 | 2022-01-17 15:32:02 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 168 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 169 | system( "make clean" ); |
| 170 | exit 0; |