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 | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 7 | # |
| 8 | # This file is provided under the Apache License 2.0, or the |
| 9 | # GNU General Public License v2.0 or later. |
| 10 | # |
| 11 | # ********** |
| 12 | # Apache License 2.0: |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 13 | # |
| 14 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 15 | # not use this file except in compliance with the License. |
| 16 | # You may obtain a copy of the License at |
| 17 | # |
| 18 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | # |
| 20 | # Unless required by applicable law or agreed to in writing, software |
| 21 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 22 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | # See the License for the specific language governing permissions and |
| 24 | # limitations under the License. |
| 25 | # |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 26 | # ********** |
| 27 | # |
| 28 | # ********** |
| 29 | # GNU General Public License v2.0 or later: |
| 30 | # |
| 31 | # This program is free software; you can redistribute it and/or modify |
| 32 | # it under the terms of the GNU General Public License as published by |
| 33 | # the Free Software Foundation; either version 2 of the License, or |
| 34 | # (at your option) any later version. |
| 35 | # |
| 36 | # This program is distributed in the hope that it will be useful, |
| 37 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 38 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 39 | # GNU General Public License for more details. |
| 40 | # |
| 41 | # You should have received a copy of the GNU General Public License along |
| 42 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 43 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 44 | # |
| 45 | # ********** |
| 46 | # |
Simon Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 47 | # Purpose |
| 48 | # |
| 49 | # For each reference configuration file in the configs directory, build the |
| 50 | # configuration, run the test suites and compat.sh |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 51 | # |
| 52 | # Usage: tests/scripts/test-ref-configs.pl [config-name [...]] |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 53 | |
| 54 | use warnings; |
| 55 | use strict; |
| 56 | |
| 57 | my %configs = ( |
Gilles Peskine | 0ac6e0a | 2020-11-09 14:44:04 +0100 | [diff] [blame] | 58 | 'config-ccm-psk-tls1_2.h' => { |
| 59 | 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'', |
| 60 | }, |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 61 | 'config-mini-tls1_1.h' => { |
| 62 | 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', |
| 63 | }, |
Gilles Peskine | 43f2f4e | 2020-11-09 15:15:17 +0100 | [diff] [blame^] | 64 | 'config-no-entropy.h' => { |
| 65 | }, |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 66 | 'config-suite-b.h' => { |
| 67 | 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS", |
| 68 | }, |
Manuel Pégourié-Gonnard | ca700b2 | 2015-10-20 14:47:00 +0200 | [diff] [blame] | 69 | 'config-thread.h' => { |
| 70 | 'opt' => '-f ECJPAKE.*nolog', |
| 71 | }, |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 72 | ); |
| 73 | |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 74 | # If no config-name is provided, use all known configs. |
| 75 | # Otherwise, use the provided names only. |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 76 | if ($#ARGV >= 0) { |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 77 | my %configs_ori = ( %configs ); |
| 78 | %configs = (); |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 79 | |
Manuel Pégourié-Gonnard | 827b6ce | 2014-04-30 12:05:29 +0200 | [diff] [blame] | 80 | foreach my $conf_name (@ARGV) { |
| 81 | if( ! exists $configs_ori{$conf_name} ) { |
| 82 | die "Unknown configuration: $conf_name\n"; |
| 83 | } else { |
| 84 | $configs{$conf_name} = $configs_ori{$conf_name}; |
| 85 | } |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 86 | } |
Paul Bakker | 30a3062 | 2013-12-19 17:09:49 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 89 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 90 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 91 | my $config_h = 'include/mbedtls/config.h'; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 92 | |
| 93 | system( "cp $config_h $config_h.bak" ) and die; |
| 94 | sub abort { |
| 95 | 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] | 96 | # 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] | 97 | warn $_[0]; |
| 98 | exit 1; |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 101 | while( my ($conf, $data) = each %configs ) { |
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"; |
| 106 | print "* Testing configuration: $conf\n"; |
| 107 | print "******************************************\n"; |
| 108 | |
Manuel Pégourié-Gonnard | 0bc1f23 | 2014-04-30 11:53:50 +0200 | [diff] [blame] | 109 | system( "cp configs/$conf $config_h" ) |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 110 | and abort "Failed to activate $conf\n"; |
| 111 | |
Simon Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 112 | 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] | 113 | system( "make test" ) and abort "Failed test suite: $conf\n"; |
Manuel Pégourié-Gonnard | 43b2986 | 2014-06-24 11:25:43 +0200 | [diff] [blame] | 114 | |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 115 | my $compat = $data->{'compat'}; |
| 116 | if( $compat ) |
Manuel Pégourié-Gonnard | 43b2986 | 2014-06-24 11:25:43 +0200 | [diff] [blame] | 117 | { |
Manuel Pégourié-Gonnard | eb47b87 | 2015-10-20 14:07:03 +0200 | [diff] [blame] | 118 | print "\nrunning compat.sh $compat\n"; |
| 119 | system( "tests/compat.sh $compat" ) |
Manuel Pégourié-Gonnard | 43b2986 | 2014-06-24 11:25:43 +0200 | [diff] [blame] | 120 | and abort "Failed compat.sh: $conf\n"; |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | print "\nskipping compat.sh\n"; |
| 125 | } |
Manuel Pégourié-Gonnard | ca700b2 | 2015-10-20 14:47:00 +0200 | [diff] [blame] | 126 | |
| 127 | my $opt = $data->{'opt'}; |
| 128 | if( $opt ) |
| 129 | { |
| 130 | print "\nrunning ssl-opt.sh $opt\n"; |
| 131 | system( "tests/ssl-opt.sh $opt" ) |
| 132 | and abort "Failed ssl-opt.sh: $conf\n"; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | print "\nskipping ssl-opt.sh\n"; |
| 137 | } |
Manuel Pégourié-Gonnard | 6498540 | 2013-09-20 16:22:42 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 141 | system( "make clean" ); |
| 142 | exit 0; |