test-ref-configs.pl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env perl
  2. # test-ref-configs.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. # Purpose
  20. #
  21. # For each reference configuration file in the configs directory, build the
  22. # configuration, run the test suites and compat.sh
  23. #
  24. # Usage: tests/scripts/test-ref-configs.pl [config-name [...]]
  25. use warnings;
  26. use strict;
  27. my %configs = (
  28. 'config-ccm-psk-tls1_2.h' => {
  29. 'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
  30. },
  31. 'config-mini-tls1_1.h' => {
  32. 'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #'
  33. },
  34. 'config-no-entropy.h' => {
  35. },
  36. 'config-suite-b.h' => {
  37. 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
  38. },
  39. 'config-symmetric-only.h' => {
  40. },
  41. 'config-thread.h' => {
  42. 'opt' => '-f ECJPAKE.*nolog',
  43. },
  44. );
  45. # If no config-name is provided, use all known configs.
  46. # Otherwise, use the provided names only.
  47. if ($#ARGV >= 0) {
  48. my %configs_ori = ( %configs );
  49. %configs = ();
  50. foreach my $conf_name (@ARGV) {
  51. if( ! exists $configs_ori{$conf_name} ) {
  52. die "Unknown configuration: $conf_name\n";
  53. } else {
  54. $configs{$conf_name} = $configs_ori{$conf_name};
  55. }
  56. }
  57. }
  58. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  59. my $config_h = 'include/mbedtls/config.h';
  60. system( "cp $config_h $config_h.bak" ) and die;
  61. sub abort {
  62. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  63. # use an exit code between 1 and 124 for git bisect (die returns 255)
  64. warn $_[0];
  65. exit 1;
  66. }
  67. # Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
  68. # For test purposes, this doesn't have to be cryptographically random.
  69. if (!-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. while( my ($conf, $data) = each %configs ) {
  76. system( "cp $config_h.bak $config_h" ) and die;
  77. system( "make clean" ) and die;
  78. print "\n******************************************\n";
  79. print "* Testing configuration: $conf\n";
  80. print "******************************************\n";
  81. $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf;
  82. system( "cp configs/$conf $config_h" )
  83. and abort "Failed to activate $conf\n";
  84. system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf\n";
  85. system( "make test" ) and abort "Failed test suite: $conf\n";
  86. my $compat = $data->{'compat'};
  87. if( $compat )
  88. {
  89. print "\nrunning compat.sh $compat\n";
  90. system( "tests/compat.sh $compat" )
  91. and abort "Failed compat.sh: $conf\n";
  92. }
  93. else
  94. {
  95. print "\nskipping compat.sh\n";
  96. }
  97. my $opt = $data->{'opt'};
  98. if( $opt )
  99. {
  100. print "\nrunning ssl-opt.sh $opt\n";
  101. system( "tests/ssl-opt.sh $opt" )
  102. and abort "Failed ssl-opt.sh: $conf\n";
  103. }
  104. else
  105. {
  106. print "\nskipping ssl-opt.sh\n";
  107. }
  108. }
  109. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  110. system( "make clean" );
  111. exit 0;