• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env perl
2
3# test-ref-configs.pl
4#
5# Copyright The Mbed TLS Contributors
6# 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:
13#
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#
26# **********
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#
47# Purpose
48#
49# For each reference configuration file in the configs directory, build the
50# configuration, run the test suites and compat.sh
51#
52# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
53
54use warnings;
55use strict;
56
57my %configs = (
58    'config-ccm-psk-tls1_2.h' => {
59        'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
60    },
61    'config-mini-tls1_1.h' => {
62        'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
63    },
64    'config-no-entropy.h' => {
65    },
66    'config-suite-b.h' => {
67        'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
68    },
69    'config-thread.h' => {
70        'opt' => '-f ECJPAKE.*nolog',
71    },
72);
73
74# If no config-name is provided, use all known configs.
75# Otherwise, use the provided names only.
76if ($#ARGV >= 0) {
77    my %configs_ori = ( %configs );
78    %configs = ();
79
80    foreach my $conf_name (@ARGV) {
81        if( ! exists $configs_ori{$conf_name} ) {
82            die "Unknown configuration: $conf_name\n";
83        } else {
84            $configs{$conf_name} = $configs_ori{$conf_name};
85        }
86    }
87}
88
89-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
90
91my $config_h = 'include/mbedtls/config.h';
92
93system( "cp $config_h $config_h.bak" ) and die;
94sub abort {
95    system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
96    # use an exit code between 1 and 124 for git bisect (die returns 255)
97    warn $_[0];
98    exit 1;
99}
100
101while( my ($conf, $data) = each %configs ) {
102    system( "cp $config_h.bak $config_h" ) and die;
103    system( "make clean" ) and die;
104
105    print "\n******************************************\n";
106    print "* Testing configuration: $conf\n";
107    print "******************************************\n";
108
109    system( "cp configs/$conf $config_h" )
110        and abort "Failed to activate $conf\n";
111
112    system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
113    system( "make test" ) and abort "Failed test suite: $conf\n";
114
115    my $compat = $data->{'compat'};
116    if( $compat )
117    {
118        print "\nrunning compat.sh $compat\n";
119        system( "tests/compat.sh $compat" )
120            and abort "Failed compat.sh: $conf\n";
121    }
122    else
123    {
124        print "\nskipping compat.sh\n";
125    }
126
127    my $opt = $data->{'opt'};
128    if( $opt )
129    {
130        print "\nrunning ssl-opt.sh $opt\n";
131        system( "tests/ssl-opt.sh $opt" )
132            and abort "Failed ssl-opt.sh: $conf\n";
133    }
134    else
135    {
136        print "\nskipping ssl-opt.sh\n";
137    }
138}
139
140system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
141system( "make clean" );
142exit 0;
143