blob: 956f9575db2888649244e937f5977ac421eebe28 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +02002
Simon Butcherf95c1762016-11-10 17:25:58 +00003# test-ref-configs.pl
4#
5# This file is part of mbed TLS (https://tls.mbed.org)
6#
7# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
8#
9# Purpose
10#
11# For each reference configuration file in the configs directory, build the
Gilles Peskine7dc97042020-02-26 19:48:43 +010012# configuration, run the test suites and compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020013#
14# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020015
16use warnings;
17use strict;
18
19my %configs = (
Gilles Peskine12230eb2020-02-26 19:02:33 +010020 'config-default.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010021 'opt' => '-f Default',
22 'compat' => '-m tls1_2 -V NO',
Gilles Peskine12230eb2020-02-26 19:02:33 +010023 },
24 'config-mini-tls1_1.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010025 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
Gilles Peskinefec30642019-10-10 20:30:54 +020026 },
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020027 'config-suite-b.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010028 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020029 },
Gilles Peskine12230eb2020-02-26 19:02:33 +010030 'config-symmetric-only.h' => {
31 },
32 'config-ccm-psk-tls1_2.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010033 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
Gilles Peskine12230eb2020-02-26 19:02:33 +010034 },
35 'config-thread.h' => {
Gilles Peskine7dc97042020-02-26 19:48:43 +010036 'opt' => '-f ECJPAKE.*nolog',
Gilles Peskine12230eb2020-02-26 19:02:33 +010037 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020038);
39
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020040# If no config-name is provided, use all known configs.
41# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010042if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020043 my %configs_ori = ( %configs );
44 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010045
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020046 foreach my $conf_name (@ARGV) {
47 if( ! exists $configs_ori{$conf_name} ) {
48 die "Unknown configuration: $conf_name\n";
49 } else {
50 $configs{$conf_name} = $configs_ori{$conf_name};
51 }
Paul Bakker30a30622013-12-19 17:09:49 +010052 }
Paul Bakker30a30622013-12-19 17:09:49 +010053}
54
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020055-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
56
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020058
59system( "cp $config_h $config_h.bak" ) and die;
60sub abort {
61 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020062 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020063 warn $_[0];
64 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020065}
66
Gilles Peskine581bfcf2019-10-11 17:19:45 +020067# Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
68# For test purposes, this doesn't have to be cryptographically random.
69if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
70 local *SEEDFILE;
71 open SEEDFILE, ">tests/seedfile" or die;
72 print SEEDFILE "*" x 64 or die;
73 close SEEDFILE or die;
74}
75
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020076while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020077 system( "cp $config_h.bak $config_h" ) and die;
78 system( "make clean" ) and die;
79
80 print "\n******************************************\n";
81 print "* Testing configuration: $conf\n";
82 print "******************************************\n";
Gilles Peskinea9478ba2019-09-18 18:45:35 +020083 $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020084
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +020085 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020086 and abort "Failed to activate $conf\n";
87
Simon Butcherf95c1762016-11-10 17:25:58 +000088 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010089 system( "make test" ) and abort "Failed test suite: $conf\n";
Gilles Peskine7dc97042020-02-26 19:48:43 +010090
91 my $compat = $data->{'compat'};
92 if( $compat )
93 {
94 print "\nrunning compat.sh $compat\n";
95 system( "tests/compat.sh $compat" )
96 and abort "Failed compat.sh: $conf\n";
97 }
98 else
99 {
100 print "\nskipping compat.sh\n";
101 }
102
103 my $opt = $data->{'opt'};
104 if( $opt )
105 {
106 print "\nrunning ssl-opt.sh $opt\n";
107 system( "tests/ssl-opt.sh $opt" )
108 and abort "Failed ssl-opt.sh: $conf\n";
109 }
110 else
111 {
112 print "\nskipping ssl-opt.sh\n";
113 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +0200114}
115
116system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
117system( "make clean" );
118exit 0;