blob: b27d64c4b337fb2afd22cf052b500926e46cc334 [file] [log] [blame]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +02001#!/usr/bin/perl
2
3# test standard configurations:
4# - build
5# - run test suite
6# - run compat.sh
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +02007#
8# Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +02009
10use warnings;
11use strict;
12
13my %configs = (
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020014 'config-mini-tls1_1.h' => {
15 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
16 },
17 'config-suite-b.h' => {
18 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
19 },
20 'config-picocoin.h' => {
21 },
22 'config-ccm-psk-tls1_2.h' => {
23 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
24 },
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020025 'config-thread.h' => {
26 'opt' => '-f ECJPAKE.*nolog',
27 },
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020028);
29
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020030# If no config-name is provided, use all known configs.
31# Otherwise, use the provided names only.
Paul Bakker30a30622013-12-19 17:09:49 +010032if ($#ARGV >= 0) {
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020033 my %configs_ori = ( %configs );
34 %configs = ();
Paul Bakker30a30622013-12-19 17:09:49 +010035
Manuel Pégourié-Gonnard827b6ce2014-04-30 12:05:29 +020036 foreach my $conf_name (@ARGV) {
37 if( ! exists $configs_ori{$conf_name} ) {
38 die "Unknown configuration: $conf_name\n";
39 } else {
40 $configs{$conf_name} = $configs_ori{$conf_name};
41 }
Paul Bakker30a30622013-12-19 17:09:49 +010042 }
Paul Bakker30a30622013-12-19 17:09:49 +010043}
44
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020045-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
46
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000047my $config_h = 'include/mbedtls/config.h';
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020048
49system( "cp $config_h $config_h.bak" ) and die;
50sub abort {
51 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
52 die $_[0];
53}
54
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020055while( my ($conf, $data) = each %configs ) {
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020056 system( "cp $config_h.bak $config_h" ) and die;
57 system( "make clean" ) and die;
58
59 print "\n******************************************\n";
60 print "* Testing configuration: $conf\n";
61 print "******************************************\n";
62
Manuel Pégourié-Gonnard0bc1f232014-04-30 11:53:50 +020063 system( "cp configs/$conf $config_h" )
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020064 and abort "Failed to activate $conf\n";
65
66 system( "make" ) and abort "Failed to build: $conf\n";
Manuel Pégourié-Gonnard1780f892015-07-08 22:08:02 +010067 system( "make test" ) and abort "Failed test suite: $conf\n";
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020068
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020069 my $compat = $data->{'compat'};
70 if( $compat )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020071 {
Manuel Pégourié-Gonnardeb47b872015-10-20 14:07:03 +020072 print "\nrunning compat.sh $compat\n";
73 system( "tests/compat.sh $compat" )
Manuel Pégourié-Gonnard43b29862014-06-24 11:25:43 +020074 and abort "Failed compat.sh: $conf\n";
75 }
76 else
77 {
78 print "\nskipping compat.sh\n";
79 }
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +020080
81 my $opt = $data->{'opt'};
82 if( $opt )
83 {
84 print "\nrunning ssl-opt.sh $opt\n";
85 system( "tests/ssl-opt.sh $opt" )
86 and abort "Failed ssl-opt.sh: $conf\n";
87 }
88 else
89 {
90 print "\nskipping ssl-opt.sh\n";
91 }
Manuel Pégourié-Gonnard64985402013-09-20 16:22:42 +020092}
93
94system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
95system( "make clean" );
96exit 0;