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