fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 2 | |
| 3 | # depends-hashes.pl |
| 4 | # |
| 5 | # Copyright (c) 2017, ARM Limited, All Rights Reserved |
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 | # |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 47 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 48 | # |
| 49 | # Purpose |
| 50 | # |
| 51 | # To test the code dependencies on individual hashes in each test suite. This |
| 52 | # is a verification step to ensure we don't ship test suites that do not work |
| 53 | # for some build options. |
| 54 | # |
| 55 | # The process is: |
| 56 | # for each possible hash |
| 57 | # build the library and test suites with the hash disabled |
| 58 | # execute the test suites |
| 59 | # |
| 60 | # And any test suite with the wrong dependencies will fail. |
| 61 | # |
| 62 | # Usage: tests/scripts/depends-hashes.pl |
| 63 | # |
| 64 | # 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] | 65 | # |
| 66 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 67 | # that includes -Werror. |
Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 68 | |
| 69 | use warnings; |
| 70 | use strict; |
| 71 | |
| 72 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 73 | |
| 74 | my $config_h = 'include/mbedtls/config.h'; |
| 75 | |
| 76 | # as many SSL options depend on specific hashes, |
| 77 | # and SSL is not in the test suites anyways, |
| 78 | # disable it to avoid dependcies issues |
| 79 | my $ssl_sed_cmd = 's/^#define \(MBEDTLS_SSL.*\)/\1/p'; |
| 80 | my @ssl = split( /\s+/, `sed -n -e '$ssl_sed_cmd' $config_h` ); |
| 81 | |
Manuel Pégourié-Gonnard | 7766a2c | 2017-08-21 10:57:57 +0200 | [diff] [blame] | 82 | # for md we want to catch MD5_C but not MD_C, hence the extra dot |
Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 83 | my $mdx_sed_cmd = 's/^#define \(MBEDTLS_MD..*_C\)/\1/p'; |
| 84 | my $sha_sed_cmd = 's/^#define \(MBEDTLS_SHA.*_C\)/\1/p'; |
| 85 | my @hashes = split( /\s+/, |
| 86 | `sed -n -e '$mdx_sed_cmd' -e '$sha_sed_cmd' $config_h` ); |
| 87 | system( "cp $config_h $config_h.bak" ) and die; |
| 88 | sub abort { |
| 89 | 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] | 90 | # 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] | 91 | warn $_[0]; |
| 92 | exit 1; |
Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | for my $hash (@hashes) { |
| 96 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 97 | system( "make clean" ) and die; |
| 98 | |
| 99 | print "\n******************************************\n"; |
| 100 | print "* Testing without hash: $hash\n"; |
| 101 | print "******************************************\n"; |
| 102 | |
| 103 | system( "scripts/config.pl unset $hash" ) |
| 104 | and abort "Failed to disable $hash\n"; |
| 105 | |
| 106 | for my $opt (@ssl) { |
| 107 | system( "scripts/config.pl unset $opt" ) |
| 108 | and abort "Failed to disable $opt\n"; |
| 109 | } |
| 110 | |
| 111 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) |
| 112 | and abort "Failed to build lib: $hash\n"; |
| 113 | system( "cd tests && make" ) and abort "Failed to build tests: $hash\n"; |
| 114 | system( "make test" ) and abort "Failed test suite: $hash\n"; |
| 115 | } |
| 116 | |
| 117 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 118 | system( "make clean" ) and die; |
| 119 | exit 0; |