blob: 0673430f8d483d698651221eea9f2dc4e1bc733f [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#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +02006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
Bence Szépkúti51b41d52020-05-26 01:54:15 +020013#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
Bence Szépkútif744bd72020-06-05 13:02:18 +020026# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
Simon Butcher3000f782016-03-04 23:26:57 +000047# Purpose
48#
49# To test the code dependencies on individual curves in each test suite. This
50# is a verification step to ensure we don't ship test suites that do not work
51# for some build options.
52#
53# The process is:
54# for each possible curve
55# build the library and test suites with the curve disabled
56# execute the test suites
57#
58# And any test suite with the wrong dependencies will fail.
59#
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020060# Usage: tests/scripts/curves.pl
Simon Butcher3000f782016-03-04 23:26:57 +000061#
62# This script should be executed from the root of the project directory.
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020063#
64# For best effect, run either with cmake disabled, or cmake enabled in a mode
65# that includes -Werror.
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010066
67use warnings;
68use strict;
69
70-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072my $sed_cmd = 's/^#define \(MBEDTLS_ECP_DP.*_ENABLED\)/\1/p';
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010074my @curves = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
75
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010076system( "cp $config_h $config_h.bak" ) and die;
77sub abort {
78 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020079 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020080 warn $_[0];
81 exit 1;
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010082}
83
84for my $curve (@curves) {
85 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020086 system( "make clean" ) and die;
87
Manuel Pégourié-Gonnard8a7a1892015-10-20 16:56:12 +020088 # depends on a specific curve. Also, ignore error if it wasn't enabled
89 system( "scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED" );
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +010090
91 print "\n******************************************\n";
92 print "* Testing without curve: $curve\n";
93 print "******************************************\n";
94
95 system( "scripts/config.pl unset $curve" )
96 and abort "Failed to disable $curve\n";
97
Simon Butcherf95c1762016-11-10 17:25:58 +000098 system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
99 and abort "Failed to build lib: $curve\n";
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +0100100 system( "cd tests && make" ) and abort "Failed to build tests: $curve\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +0100101 system( "make test" ) and abort "Failed test suite: $curve\n";
Manuel Pégourié-Gonnard2727dc12014-11-19 20:02:46 +0100102
103}
104
105system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
106system( "make clean" ) and die;
107exit 0;