Manuel Pégourié-Gonnard | 902bb6a | 2017-06-06 12:42:41 +0200 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # depends-pkalgs.pl |
| 4 | # |
| 5 | # Copyright (c) 2017, ARM Limited, All Rights Reserved |
| 6 | # |
| 7 | # Purpose |
| 8 | # |
| 9 | # To test the code dependencies on individual PK algs 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 PK alg |
| 15 | # build the library and test suites with that alg disabled |
| 16 | # execute the test suites |
| 17 | # |
| 18 | # And any test suite with the wrong dependencies will fail. |
| 19 | # |
| 20 | # Usage: tests/scripts/depends-pkalgs.pl |
| 21 | # |
| 22 | # This script should be executed from the root of the project directory. |
| 23 | # |
| 24 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 25 | # that includes -Werror. |
| 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 algs |
| 35 | # and SSL is not in the test suites anyways, |
| 36 | # disable it to avoid dependcies issues |
| 37 | my $ssl_sed = 's/^#define \(MBEDTLS_SSL.*\)/\1/p'; |
| 38 | my $kex_sed = 's/^#define \(MBEDTLS_KEY_EXCHANGE.*\)/\1/p'; |
| 39 | my @ssl = split( /\s+/, `sed -n -e '$ssl_sed' -e '$kex_sed' $config_h` ); |
| 40 | |
| 41 | my %algs = ( |
| 42 | 'MBEDTLS_ECDSA_C' => [], |
| 43 | 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C', 'MBEDTLS_ECDH_C'], |
| 44 | 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [], |
| 45 | 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'], |
| 46 | 'MBEDTLS_PKCS1_V15' => [], |
| 47 | 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'], |
| 48 | ); |
| 49 | |
| 50 | system( "cp $config_h $config_h.bak" ) and die; |
| 51 | sub abort { |
| 52 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 53 | die $_[0]; |
| 54 | } |
| 55 | |
| 56 | while( my ($alg, $extras) = each %algs ) { |
| 57 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 58 | system( "make clean" ) and die; |
| 59 | |
| 60 | print "\n******************************************\n"; |
| 61 | print "* Testing without alg: $alg\n"; |
| 62 | print "******************************************\n"; |
| 63 | |
| 64 | system( "scripts/config.pl unset $alg" ) |
| 65 | and abort "Failed to disable $alg\n"; |
| 66 | for my $opt (@$extras) { |
| 67 | system( "scripts/config.pl unset $opt" ) |
| 68 | and abort "Failed to disable $opt\n"; |
| 69 | } |
| 70 | |
| 71 | for my $opt (@ssl) { |
| 72 | system( "scripts/config.pl unset $opt" ) |
| 73 | and abort "Failed to disable $opt\n"; |
| 74 | } |
| 75 | |
| 76 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) |
| 77 | and abort "Failed to build lib: $alg\n"; |
| 78 | system( "cd tests && make" ) and abort "Failed to build tests: $alg\n"; |
| 79 | system( "make test" ) and abort "Failed test suite: $alg\n"; |
| 80 | } |
| 81 | |
| 82 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 83 | system( "make clean" ) and die; |
| 84 | exit 0; |