blob: 90353d3f72a94a9aca7f91b55826e2ef5c8b29ce [file] [log] [blame]
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +01001#!/usr/bin/perl
2
Manuel Pégourié-Gonnard364ece32017-06-06 11:51:34 +02003# curves.pl
4#
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.
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010019#
20# Usage: tests/scripts/curves.pl
Manuel Pégourié-Gonnard364ece32017-06-06 11:51:34 +020021#
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.
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";
39 die $_[0];
40}
41
42for my $curve (@curves) {
43 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
44 system( "make clean" ) and die;
45
46 print "\n******************************************\n";
47 print "* Testing without curve: $curve\n";
48 print "******************************************\n";
49
50 system( "scripts/config.pl unset $curve" )
51 and abort "Failed to disable $curve\n";
52
Manuel Pégourié-Gonnard4b56e752015-10-22 16:11:39 +020053 system( "make lib" ) and abort "Failed to build lib: $curve\n";
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010054 system( "cd tests && make" ) and abort "Failed to build tests: $curve\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010055 system( "make test" ) and abort "Failed test suite: $curve\n";
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010056
57}
58
59system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
60system( "make clean" ) and die;
61exit 0;