| 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 | 
|  | 6 | # | 
|  | 7 | # Purpose | 
|  | 8 | # | 
|  | 9 | # To test the code dependencies on individual hashes in each test suite. This | 
|  | 10 | # is a verification step to ensure we don't ship test suites that do not work | 
|  | 11 | # for some build options. | 
|  | 12 | # | 
|  | 13 | # The process is: | 
|  | 14 | #       for each possible hash | 
|  | 15 | #           build the library and test suites with the hash disabled | 
|  | 16 | #           execute the test suites | 
|  | 17 | # | 
|  | 18 | # And any test suite with the wrong dependencies will fail. | 
|  | 19 | # | 
|  | 20 | # Usage: tests/scripts/depends-hashes.pl | 
|  | 21 | # | 
|  | 22 | # 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] | 23 | # | 
|  | 24 | # For best effect, run either with cmake disabled, or cmake enabled in a mode | 
|  | 25 | # that includes -Werror. | 
| Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 26 |  | 
|  | 27 | use warnings; | 
|  | 28 | use strict; | 
|  | 29 |  | 
|  | 30 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; | 
|  | 31 |  | 
|  | 32 | my $config_h = 'include/mbedtls/config.h'; | 
|  | 33 |  | 
|  | 34 | # as many SSL options depend on specific hashes, | 
|  | 35 | # and SSL is not in the test suites anyways, | 
|  | 36 | # disable it to avoid dependcies issues | 
|  | 37 | my $ssl_sed_cmd = 's/^#define \(MBEDTLS_SSL.*\)/\1/p'; | 
|  | 38 | my @ssl = split( /\s+/, `sed -n -e '$ssl_sed_cmd' $config_h` ); | 
|  | 39 |  | 
| Manuel Pégourié-Gonnard | 7766a2c | 2017-08-21 10:57:57 +0200 | [diff] [blame] | 40 | # 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] | 41 | my $mdx_sed_cmd = 's/^#define \(MBEDTLS_MD..*_C\)/\1/p'; | 
|  | 42 | my $sha_sed_cmd = 's/^#define \(MBEDTLS_SHA.*_C\)/\1/p'; | 
|  | 43 | my @hashes = split( /\s+/, | 
|  | 44 | `sed -n -e '$mdx_sed_cmd' -e '$sha_sed_cmd' $config_h` ); | 
|  | 45 | system( "cp $config_h $config_h.bak" ) and die; | 
|  | 46 | sub abort { | 
|  | 47 | 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] | 48 | # 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] | 49 | warn $_[0]; | 
|  | 50 | exit 1; | 
| Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame] | 51 | } | 
|  | 52 |  | 
|  | 53 | for my $hash (@hashes) { | 
|  | 54 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; | 
|  | 55 | system( "make clean" ) and die; | 
|  | 56 |  | 
|  | 57 | print "\n******************************************\n"; | 
|  | 58 | print "* Testing without hash: $hash\n"; | 
|  | 59 | print "******************************************\n"; | 
|  | 60 |  | 
|  | 61 | system( "scripts/config.pl unset $hash" ) | 
|  | 62 | and abort "Failed to disable $hash\n"; | 
|  | 63 |  | 
|  | 64 | for my $opt (@ssl) { | 
|  | 65 | system( "scripts/config.pl unset $opt" ) | 
|  | 66 | and abort "Failed to disable $opt\n"; | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) | 
|  | 70 | and abort "Failed to build lib: $hash\n"; | 
|  | 71 | system( "cd tests && make" ) and abort "Failed to build tests: $hash\n"; | 
|  | 72 | system( "make test" ) and abort "Failed test suite: $hash\n"; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; | 
|  | 76 | system( "make clean" ) and die; | 
|  | 77 | exit 0; |