blob: 234c3e3f8768cbfc834c92c4f13809f6ea1d3466 [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#
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +02009# To test the code dependencies on individual PK algs (those that can be used
10# from the PK layer, so currently signature and encryption but not key
11# exchange) in each test suite. This is a verification step to ensure we don't
12# ship test suites that do not work for some build options.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020013#
14# The process is:
15# for each possible PK alg
16# build the library and test suites with that alg disabled
17# execute the test suites
18#
19# And any test suite with the wrong dependencies will fail.
20#
21# Usage: tests/scripts/depends-pkalgs.pl
22#
23# This script should be executed from the root of the project directory.
24#
25# For best effect, run either with cmake disabled, or cmake enabled in a mode
26# that includes -Werror.
27
28use warnings;
29use strict;
30
31-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
32
33my $config_h = 'include/mbedtls/config.h';
34
35# as many SSL options depend on specific algs
36# and SSL is not in the test suites anyways,
37# disable it to avoid dependcies issues
38my $ssl_sed = 's/^#define \(MBEDTLS_SSL.*\)/\1/p';
39my $kex_sed = 's/^#define \(MBEDTLS_KEY_EXCHANGE.*\)/\1/p';
40my @ssl = split( /\s+/, `sed -n -e '$ssl_sed' -e '$kex_sed' $config_h` );
41
Manuel Pégourié-Gonnard562df402017-08-08 18:09:14 +020042# Some algorithms can't be disabled on their own as others depend on them, so
43# we list those reverse-dependencies here to keep check_config.h happy.
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020044my %algs = (
45 'MBEDTLS_ECDSA_C' => [],
46 'MBEDTLS_ECP_C' => ['MBEDTLS_ECDSA_C', 'MBEDTLS_ECDH_C'],
47 'MBEDTLS_X509_RSASSA_PSS_SUPPORT' => [],
48 'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
49 'MBEDTLS_PKCS1_V15' => [],
50 'MBEDTLS_RSA_C' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
51);
52
53system( "cp $config_h $config_h.bak" ) and die;
54sub abort {
55 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020056 warn $_[0];
57 exit 1;
Manuel Pégourié-Gonnard902bb6a2017-06-06 12:42:41 +020058}
59
60while( my ($alg, $extras) = each %algs ) {
61 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
62 system( "make clean" ) and die;
63
64 print "\n******************************************\n";
65 print "* Testing without alg: $alg\n";
66 print "******************************************\n";
67
68 system( "scripts/config.pl unset $alg" )
69 and abort "Failed to disable $alg\n";
70 for my $opt (@$extras) {
71 system( "scripts/config.pl unset $opt" )
72 and abort "Failed to disable $opt\n";
73 }
74
75 for my $opt (@ssl) {
76 system( "scripts/config.pl unset $opt" )
77 and abort "Failed to disable $opt\n";
78 }
79
80 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
81 and abort "Failed to build lib: $alg\n";
82 system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
83 system( "make test" ) and abort "Failed test suite: $alg\n";
84}
85
86system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
87system( "make clean" ) and die;
88exit 0;