Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 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 |
| 6 | # |
| 7 | # Purpose |
| 8 | # |
| 9 | # To test the code dependencies on individual curves 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 curve |
| 15 | # build the library and test suites with the curve disabled |
| 16 | # execute the test suites |
| 17 | # |
| 18 | # And any test suite with the wrong dependencies will fail. |
| 19 | # |
| 20 | # Usage: curves.pl |
| 21 | # |
| 22 | # This script should be executed from the root of the project directory. |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 23 | |
| 24 | use warnings; |
| 25 | use strict; |
| 26 | |
| 27 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 28 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 29 | 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] | 30 | my $config_h = 'include/mbedtls/config.h'; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 31 | my @curves = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` ); |
| 32 | |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 33 | system( "cp $config_h $config_h.bak" ) and die; |
| 34 | sub abort { |
| 35 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 36 | die $_[0]; |
| 37 | } |
| 38 | |
| 39 | for my $curve (@curves) { |
| 40 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
Manuel Pégourié-Gonnard | 8a7a189 | 2015-10-20 16:56:12 +0200 | [diff] [blame] | 41 | # depends on a specific curve. Also, ignore error if it wasn't enabled |
| 42 | system( "scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED" ); |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 43 | system( "make clean" ) and die; |
| 44 | |
| 45 | print "\n******************************************\n"; |
| 46 | print "* Testing without curve: $curve\n"; |
| 47 | print "******************************************\n"; |
| 48 | |
| 49 | system( "scripts/config.pl unset $curve" ) |
| 50 | and abort "Failed to disable $curve\n"; |
| 51 | |
Simon Butcher | f95c176 | 2016-11-10 17:25:58 +0000 | [diff] [blame] | 52 | system( "CFLAGS='-Werror -Wall -Wextra' make lib" ) |
| 53 | and abort "Failed to build lib: $curve\n"; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 54 | system( "cd tests && make" ) and abort "Failed to build tests: $curve\n"; |
Manuel Pégourié-Gonnard | 1780f89 | 2015-07-08 22:08:02 +0100 | [diff] [blame] | 55 | system( "make test" ) and abort "Failed test suite: $curve\n"; |
Manuel Pégourié-Gonnard | 2727dc1 | 2014-11-19 20:02:46 +0100 | [diff] [blame] | 56 | |
| 57 | } |
| 58 | |
| 59 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 60 | system( "make clean" ) and die; |
| 61 | exit 0; |