blob: fe6d154f95e6e4becf9c3a1dc3ef71e167a72386 [file] [log] [blame]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +02001#!/usr/bin/perl
2
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
12# 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 = (
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020020 'config-mini-tls1_1.h' => {
21 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
22 },
23 'config-suite-b.h' => {
24 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
25 },
26 'config-picocoin.h' => {
27 },
28 'config-ccm-psk-tls1_2.h' => {
29 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
30 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020031 'config-thread.h' => {
32 'opt' => '-f ECJPAKE.*nolog',
33 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020034);
35
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020036# If no config-name is provided, use all known configs.
37# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010038if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020039 my %configs_ori = ( %configs );
40 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010041
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020042 foreach my $conf_name (@ARGV) {
43 if( ! exists $configs_ori{$conf_name} ) {
44 die "Unknown configuration: $conf_name\n";
45 } else {
46 $configs{$conf_name} = $configs_ori{$conf_name};
47 }
Paul Bakker30a30622013-12-19 17:09:49 +010048 }
Paul Bakker30a30622013-12-19 17:09:49 +010049}
50
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020051-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
52
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020054
55system( "cp $config_h $config_h.bak" ) and die;
56sub abort {
57 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020058 warn $_[0];
59 exit 1;
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020060}
61
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020062while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020063 system( "cp $config_h.bak $config_h" ) and die;
64 system( "make clean" ) and die;
65
66 print "\n******************************************\n";
67 print "* Testing configuration: $conf\n";
68 print "******************************************\n";
69
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +020070 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020071 and abort "Failed to activate $conf\n";
72
Simon Butcherf95c1762016-11-10 17:25:58 +000073 system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010074 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020075
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020076 my $compat = $data->{'compat'};
77 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020078 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020079 print "\nrunning compat.sh $compat\n";
80 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020081 and abort "Failed compat.sh: $conf\n";
82 }
83 else
84 {
85 print "\nskipping compat.sh\n";
86 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020087
88 my $opt = $data->{'opt'};
89 if( $opt )
90 {
91 print "\nrunning ssl-opt.sh $opt\n";
92 system( "tests/ssl-opt.sh $opt" )
93 and abort "Failed ssl-opt.sh: $conf\n";
94 }
95 else
96 {
97 print "\nskipping ssl-opt.sh\n";
98 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020099}
100
101system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
102system( "make clean" );
103exit 0;