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' => { |
| 32 | 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'', |
| 33 | }, |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 34 | 'config-mini-tls1_1.h' => { |
Gilles Peskine | 7415f2f | 2019-09-16 15:06:03 +0200 | [diff] [blame] | 35 | 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #' |
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' => { |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 40 | 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS", |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 41 | }, |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 42 | 'config-symmetric-only.h' => { |
| 43 | }, |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 44 | 'config-thread.h' => { |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 45 | 'opt' => '-f ECJPAKE.*nolog', |
Gilles Peskine | 12230eb | 2020-02-26 19:02:33 +0100 | [diff] [blame] | 46 | }, |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 47 | ); |
| 48 | |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 49 | # If no config-name is provided, use all known configs. |
| 50 | # Otherwise, use the provided names only. |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 51 | if ($#ARGV >= 0) { |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 52 | my %configs_ori = ( %configs ); |
| 53 | %configs = (); |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 55 | foreach my $conf_name (@ARGV) { |
| 56 | if( ! exists $configs_ori{$conf_name} ) { |
| 57 | die "Unknown configuration: $conf_name\n"; |
| 58 | } else { |
| 59 | $configs{$conf_name} = $configs_ori{$conf_name}; |
| 60 | } |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 61 | } |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 64 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 65 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 66 | my $config_h = 'include/mbedtls/config.h'; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 67 | |
| 68 | system( "cp $config_h $config_h.bak" ) and die; |
| 69 | sub abort { |
| 70 | 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] | 71 | # 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] | 72 | warn $_[0]; |
| 73 | exit 1; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Gilles Peskine | 581bfcf | 2019-10-11 17:19:45 +0200 | [diff] [blame] | 76 | # Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED. |
| 77 | # For test purposes, this doesn't have to be cryptographically random. |
| 78 | if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) { |
| 79 | local *SEEDFILE; |
| 80 | open SEEDFILE, ">tests/seedfile" or die; |
| 81 | print SEEDFILE "*" x 64 or die; |
| 82 | close SEEDFILE or die; |
| 83 | } |
| 84 | |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 85 | while( my ($conf, $data) = each %configs ) { |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 86 | system( "cp $config_h.bak $config_h" ) and die; |
| 87 | system( "make clean" ) and die; |
| 88 | |
| 89 | print "\n******************************************\n"; |
| 90 | print "* Testing configuration: $conf\n"; |
| 91 | print "******************************************\n"; |
Gilles Peskine | a9478ba | 2019-09-18 18:45:35 +0200 | [diff] [blame] | 92 | $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 93 | |
Manuel Pégourié-Gonnard | 0bc1f23 | 2014-04-30 11:53:50 +0200 | [diff] [blame] | 94 | system( "cp configs/$conf $config_h" ) |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 95 | and abort "Failed to activate $conf\n"; |
| 96 | |
Simon Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 97 | system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n"; |
Manuel Pégourié-Gonnard | 1780f89 | 2015-07-08 22:08:02 +0100 | [diff] [blame] | 98 | system( "make test" ) and abort "Failed test suite: $conf\n"; |
Gilles Peskine | 7dc9704 | 2020-02-26 19:48:43 +0100 | [diff] [blame] | 99 | |
| 100 | my $compat = $data->{'compat'}; |
| 101 | if( $compat ) |
| 102 | { |
| 103 | print "\nrunning compat.sh $compat\n"; |
| 104 | system( "tests/compat.sh $compat" ) |
| 105 | and abort "Failed compat.sh: $conf\n"; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | print "\nskipping compat.sh\n"; |
| 110 | } |
| 111 | |
| 112 | my $opt = $data->{'opt'}; |
| 113 | if( $opt ) |
| 114 | { |
| 115 | print "\nrunning ssl-opt.sh $opt\n"; |
| 116 | system( "tests/ssl-opt.sh $opt" ) |
| 117 | and abort "Failed ssl-opt.sh: $conf\n"; |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | print "\nskipping ssl-opt.sh\n"; |
| 122 | } |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 126 | system( "make clean" ); |
| 127 | exit 0; |