blob: 28f13787d6da6e4a969fc868b85c5b31f75a54ca [file] [log] [blame]
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +02001#!/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
27use warnings;
28use strict;
29
30-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
31
32my $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
37my $ssl_sed = 's/^#define \(MBEDTLS_SSL.*\)/\1/p';
38my $kex_sed = 's/^#define \(MBEDTLS_KEY_EXCHANGE.*\)/\1/p';
39my @ssl = split( /\s+/, `sed -n -e '$ssl_sed' -e '$kex_sed' $config_h` );
40
41my %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
50system( "cp $config_h $config_h.bak" ) and die;
51sub abort {
52 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020053 warn $_[0];
54 exit 1;
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020055}
56
57while( my ($alg, $extras) = each %algs ) {
58 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
59 system( "make clean" ) and die;
60
61 print "\n******************************************\n";
62 print "* Testing without alg: $alg\n";
63 print "******************************************\n";
64
65 system( "scripts/config.pl unset $alg" )
66 and abort "Failed to disable $alg\n";
67 for my $opt (@$extras) {
68 system( "scripts/config.pl unset $opt" )
69 and abort "Failed to disable $opt\n";
70 }
71
72 for my $opt (@ssl) {
73 system( "scripts/config.pl unset $opt" )
74 and abort "Failed to disable $opt\n";
75 }
76
77 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
78 and abort "Failed to build lib: $alg\n";
79 system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
80 system( "make test" ) and abort "Failed test suite: $alg\n";
81}
82
83system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
84system( "make clean" ) and die;
85exit 0;