blob: 8119a46e69144b15ba8997d1f792b957dfb0acd1 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +01002
Simon Butcher3000f782016-03-04 23:26:57 +00003# curves.pl
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +01004#
Simon Butcher3000f782016-03-04 23:26:57 +00005# 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#
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020020# Usage: tests/scripts/curves.pl
Simon Butcher3000f782016-03-04 23:26:57 +000021#
22# This script should be executed from the root of the project directory.
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020023#
24# For best effect, run either with cmake disabled, or cmake enabled in a mode
25# that includes -Werror.
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010026
27use warnings;
28use strict;
29
30-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
31
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032my $sed_cmd = 's/^#define \(MBEDTLS_ECP_DP.*_ENABLED\)/\1/p';
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000033my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010034my @curves = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
35
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010036system( "cp $config_h $config_h.bak" ) and die;
37sub abort {
38 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020039 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020040 warn $_[0];
41 exit 1;
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010042}
43
44for my $curve (@curves) {
45 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020046 system( "make clean" ) and die;
47
Manuel Pégourié-Gonnard8a7a1892015-10-20 16:56:12 +020048 # depends on a specific curve. Also, ignore error if it wasn't enabled
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020049 system( "scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED" );
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010050
51 print "\n******************************************\n";
52 print "* Testing without curve: $curve\n";
53 print "******************************************\n";
Gilles Peskine9004a172019-09-16 15:20:36 +020054 $ENV{MBEDTLS_TEST_CONFIGURATION} = "-$curve";
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010055
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020056 system( "scripts/config.py unset $curve" )
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010057 and abort "Failed to disable $curve\n";
58
Simon Butcherf95c1762016-11-10 17:25:58 +000059 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
60 and abort "Failed to build lib: $curve\n";
Andrzej Kurek098b16c2019-04-17 09:01:31 -040061 system( "make" ) and abort "Failed to build tests: $curve\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010062 system( "make test" ) and abort "Failed test suite: $curve\n";
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010063
64}
65
66system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
67system( "make clean" ) and die;
68exit 0;