blob: 3bf7ae34faa94af9ed7ca80803c7056531009d39 [file] [log] [blame]
fbrosson06202062018-04-04 22:29:58 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard4b56e752015-10-22 16:11:39 +02002
Manuel Pégourié-Gonnard364ece32017-06-06 11:51:34 +02003# key-exchanges.pl
4#
5# Copyright (c) 2015-2017, ARM Limited, All Rights Reserved
6#
7# Purpose
8#
9# To test the code dependencies on individual key exchanges in the SSL module.
10# is a verification step to ensure we don't ship SSL code that do not work
11# for some build options.
12#
13# The process is:
14# for each possible key exchange
15# build the library with all but that key exchange disabled
Manuel Pégourié-Gonnard4b56e752015-10-22 16:11:39 +020016#
17# Usage: tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard364ece32017-06-06 11:51:34 +020018#
19# This script should be executed from the root of the project directory.
20#
21# For best effect, run either with cmake disabled, or cmake enabled in a mode
22# that includes -Werror.
Manuel Pégourié-Gonnard4b56e752015-10-22 16:11:39 +020023
24use warnings;
25use strict;
26
27-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
28
29my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p';
30my $config_h = 'include/mbedtls/config.h';
31my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
32
33system( "cp $config_h $config_h.bak" ) and die;
34sub abort {
35 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard52de8e02017-10-26 09:47:36 +020036 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnard0eb63152017-07-12 12:15:24 +020037 warn $_[0];
38 exit 1;
Manuel Pégourié-Gonnard4b56e752015-10-22 16:11:39 +020039}
40
41for my $kex (@kexes) {
42 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
43 system( "make clean" ) and die;
44
45 print "\n******************************************\n";
46 print "* Testing with key exchange: $kex\n";
47 print "******************************************\n";
48
49 # full config with all key exchanges disabled except one
50 system( "scripts/config.pl full" ) and abort "Failed config full\n";
51 for my $k (@kexes) {
52 next if $k eq $kex;
53 system( "scripts/config.pl unset $k" )
54 and abort "Failed to disable $k\n";
55 }
56
Manuel Pégourié-Gonnardfe3affd2015-10-23 08:53:34 +020057 system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n";
Manuel Pégourié-Gonnard4b56e752015-10-22 16:11:39 +020058}
59
60system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
61system( "make clean" ) and die;
62exit 0;