test-ref-configs.pl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env perl
  2. # test-ref-configs.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. #
  7. # This file is provided under the Apache License 2.0, or the
  8. # GNU General Public License v2.0 or later.
  9. #
  10. # **********
  11. # Apache License 2.0:
  12. #
  13. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  14. # not use this file except in compliance with the License.
  15. # You may obtain a copy of the License at
  16. #
  17. # http://www.apache.org/licenses/LICENSE-2.0
  18. #
  19. # Unless required by applicable law or agreed to in writing, software
  20. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. # See the License for the specific language governing permissions and
  23. # limitations under the License.
  24. #
  25. # **********
  26. #
  27. # **********
  28. # GNU General Public License v2.0 or later:
  29. #
  30. # This program is free software; you can redistribute it and/or modify
  31. # it under the terms of the GNU General Public License as published by
  32. # the Free Software Foundation; either version 2 of the License, or
  33. # (at your option) any later version.
  34. #
  35. # This program is distributed in the hope that it will be useful,
  36. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. # GNU General Public License for more details.
  39. #
  40. # You should have received a copy of the GNU General Public License along
  41. # with this program; if not, write to the Free Software Foundation, Inc.,
  42. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  43. #
  44. # **********
  45. #
  46. # Purpose
  47. #
  48. # For each reference configuration file in the configs directory, build the
  49. # configuration, run the test suites and compat.sh
  50. #
  51. # Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
  52. use warnings;
  53. use strict;
  54. my %configs = (
  55. 'config-ccm-psk-tls1_2.h' => {
  56. 'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
  57. },
  58. 'config-mini-tls1_1.h' => {
  59. 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'',
  60. },
  61. 'config-no-entropy.h' => {
  62. },
  63. 'config-suite-b.h' => {
  64. 'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
  65. },
  66. 'config-thread.h' => {
  67. 'opt' => '-f ECJPAKE.*nolog',
  68. },
  69. );
  70. # If no config-name is provided, use all known configs.
  71. # Otherwise, use the provided names only.
  72. if ($#ARGV >= 0) {
  73. my %configs_ori = ( %configs );
  74. %configs = ();
  75. foreach my $conf_name (@ARGV) {
  76. if( ! exists $configs_ori{$conf_name} ) {
  77. die "Unknown configuration: $conf_name\n";
  78. } else {
  79. $configs{$conf_name} = $configs_ori{$conf_name};
  80. }
  81. }
  82. }
  83. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  84. my $config_h = 'include/mbedtls/config.h';
  85. system( "cp $config_h $config_h.bak" ) and die;
  86. sub abort {
  87. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  88. # use an exit code between 1 and 124 for git bisect (die returns 255)
  89. warn $_[0];
  90. exit 1;
  91. }
  92. while( my ($conf, $data) = each %configs ) {
  93. system( "cp $config_h.bak $config_h" ) and die;
  94. system( "make clean" ) and die;
  95. print "\n******************************************\n";
  96. print "* Testing configuration: $conf\n";
  97. print "******************************************\n";
  98. system( "cp configs/$conf $config_h" )
  99. and abort "Failed to activate $conf\n";
  100. system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
  101. system( "make test" ) and abort "Failed test suite: $conf\n";
  102. my $compat = $data->{'compat'};
  103. if( $compat )
  104. {
  105. print "\nrunning compat.sh $compat\n";
  106. system( "tests/compat.sh $compat" )
  107. and abort "Failed compat.sh: $conf\n";
  108. }
  109. else
  110. {
  111. print "\nskipping compat.sh\n";
  112. }
  113. my $opt = $data->{'opt'};
  114. if( $opt )
  115. {
  116. print "\nrunning ssl-opt.sh $opt\n";
  117. system( "tests/ssl-opt.sh $opt" )
  118. and abort "Failed ssl-opt.sh: $conf\n";
  119. }
  120. else
  121. {
  122. print "\nskipping ssl-opt.sh\n";
  123. }
  124. }
  125. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  126. system( "make clean" );
  127. exit 0;