Manuel Pégourié-Gonnard | 42a4d30 | 2017-06-06 10:54:01 +0200 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 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. |
| 23 | |
| 24 | use warnings; |
| 25 | use strict; |
| 26 | |
| 27 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 28 | |
| 29 | my $config_h = 'include/mbedtls/config.h'; |
| 30 | |
| 31 | # as many SSL options depend on specific hashes, |
| 32 | # and SSL is not in the test suites anyways, |
| 33 | # disable it to avoid dependcies issues |
| 34 | my $ssl_sed_cmd = 's/^#define \(MBEDTLS_SSL.*\)/\1/p'; |
| 35 | my @ssl = split( /\s+/, `sed -n -e '$ssl_sed_cmd' $config_h` ); |
| 36 | |
| 37 | my $mdx_sed_cmd = 's/^#define \(MBEDTLS_MD..*_C\)/\1/p'; |
| 38 | my $sha_sed_cmd = 's/^#define \(MBEDTLS_SHA.*_C\)/\1/p'; |
| 39 | my @hashes = split( /\s+/, |
| 40 | `sed -n -e '$mdx_sed_cmd' -e '$sha_sed_cmd' $config_h` ); |
| 41 | system( "cp $config_h $config_h.bak" ) and die; |
| 42 | sub abort { |
| 43 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 44 | die $_[0]; |
| 45 | } |
| 46 | |
| 47 | for my $hash (@hashes) { |
| 48 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 49 | system( "make clean" ) and die; |
| 50 | |
| 51 | print "\n******************************************\n"; |
| 52 | print "* Testing without hash: $hash\n"; |
| 53 | print "******************************************\n"; |
| 54 | |
| 55 | system( "scripts/config.pl unset $hash" ) |
| 56 | and abort "Failed to disable $hash\n"; |
| 57 | |
| 58 | for my $opt (@ssl) { |
| 59 | system( "scripts/config.pl unset $opt" ) |
| 60 | and abort "Failed to disable $opt\n"; |
| 61 | } |
| 62 | |
| 63 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) |
| 64 | and abort "Failed to build lib: $hash\n"; |
| 65 | system( "cd tests && make" ) and abort "Failed to build tests: $hash\n"; |
| 66 | system( "make test" ) and abort "Failed test suite: $hash\n"; |
| 67 | } |
| 68 | |
| 69 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 70 | system( "make clean" ) and die; |
| 71 | exit 0; |