fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 2 | |
Simon Butcher | 3000f78 | 2016-03-04 23:26:57 +0000 | [diff] [blame] | 3 | # curves.pl |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 4 | # |
Simon Butcher | 3000f78 | 2016-03-04 23:26:57 +0000 | [diff] [blame] | 5 | # Copyright (c) 2014-2016, ARM Limited, All Rights Reserved |
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 | # |
| 20 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Simon Butcher | 3000f78 | 2016-03-04 23:26:57 +0000 | [diff] [blame] | 21 | # |
| 22 | # Purpose |
| 23 | # |
| 24 | # To test the code dependencies on individual curves in each test suite. This |
| 25 | # is a verification step to ensure we don't ship test suites that do not work |
| 26 | # for some build options. |
| 27 | # |
| 28 | # The process is: |
| 29 | # for each possible curve |
| 30 | # build the library and test suites with the curve disabled |
| 31 | # execute the test suites |
| 32 | # |
| 33 | # And any test suite with the wrong dependencies will fail. |
| 34 | # |
Manuel Pégourié-Gonnard | 9ba9dfb | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 35 | # Usage: tests/scripts/curves.pl |
Simon Butcher | 3000f78 | 2016-03-04 23:26:57 +0000 | [diff] [blame] | 36 | # |
| 37 | # This script should be executed from the root of the project directory. |
Manuel Pégourié-Gonnard | 9ba9dfb | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 38 | # |
| 39 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 40 | # that includes -Werror. |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 41 | |
| 42 | use warnings; |
| 43 | use strict; |
| 44 | |
| 45 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 46 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 47 | my $sed_cmd = 's/^#define \(MBEDTLS_ECP_DP.*_ENABLED\)/\1/p'; |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 48 | my $config_h = 'include/mbedtls/config.h'; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 49 | my @curves = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` ); |
| 50 | |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 51 | system( "cp $config_h $config_h.bak" ) and die; |
| 52 | sub abort { |
| 53 | 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] | 54 | # 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] | 55 | warn $_[0]; |
| 56 | exit 1; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | for my $curve (@curves) { |
| 60 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
Manuel Pégourié-Gonnard | a7c4c8a | 2017-07-12 12:15:24 +0200 | [diff] [blame] | 61 | system( "make clean" ) and die; |
| 62 | |
Manuel Pégourié-Gonnard | 8a7a189 | 2015-10-20 16:56:12 +0200 | [diff] [blame] | 63 | # depends on a specific curve. Also, ignore error if it wasn't enabled |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 64 | system( "scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED" ); |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 65 | |
| 66 | print "\n******************************************\n"; |
| 67 | print "* Testing without curve: $curve\n"; |
| 68 | print "******************************************\n"; |
Gilles Peskine | 9004a17 | 2019-09-16 15:20:36 +0200 | [diff] [blame] | 69 | $ENV{MBEDTLS_TEST_CONFIGURATION} = "-$curve"; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 70 | |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 71 | system( "scripts/config.py unset $curve" ) |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 72 | and abort "Failed to disable $curve\n"; |
| 73 | |
Simon Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 74 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) |
| 75 | and abort "Failed to build lib: $curve\n"; |
Andrzej Kurek | 098b16c | 2019-04-17 09:01:31 -0400 | [diff] [blame] | 76 | system( "make" ) and abort "Failed to build tests: $curve\n"; |
Manuel Pégourié-Gonnard | 1780f89 | 2015-07-08 22:08:02 +0100 | [diff] [blame] | 77 | system( "make test" ) and abort "Failed test suite: $curve\n"; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 78 | |
| 79 | } |
| 80 | |
| 81 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 82 | system( "make clean" ) and die; |
| 83 | exit 0; |