test-ref-configs.pl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. 'test_again_with_use_psa' => 1
  31. },
  32. 'config-ccm-psk-dtls1_2.h' => {
  33. 'compat' => '-m dtls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
  34. 'opt' => ' ',
  35. 'opt_needs_debug' => 1,
  36. 'test_again_with_use_psa' => 1
  37. },
  38. 'config-no-entropy.h' => {
  39. },
  40. 'config-suite-b.h' => {
  41. 'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
  42. 'test_again_with_use_psa' => 1,
  43. 'opt' => ' ',
  44. 'opt_needs_debug' => 1,
  45. },
  46. 'config-symmetric-only.h' => {
  47. 'test_again_with_use_psa' => 0, # Uses PSA by default, no need to test it twice
  48. },
  49. 'config-thread.h' => {
  50. 'opt' => '-f ECJPAKE.*nolog',
  51. 'test_again_with_use_psa' => 1,
  52. },
  53. );
  54. # If no config-name is provided, use all known configs.
  55. # Otherwise, use the provided names only.
  56. my @configs_to_test = sort keys %configs;
  57. if ($#ARGV >= 0) {
  58. foreach my $conf_name ( @ARGV ) {
  59. if( ! exists $configs{$conf_name} ) {
  60. die "Unknown configuration: $conf_name\n";
  61. }
  62. }
  63. @configs_to_test = @ARGV;
  64. }
  65. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  66. my $config_h = 'include/mbedtls/mbedtls_config.h';
  67. system( "cp $config_h $config_h.bak" ) and die;
  68. sub abort {
  69. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  70. # use an exit code between 1 and 124 for git bisect (die returns 255)
  71. warn $_[0];
  72. exit 1;
  73. }
  74. # Create a seedfile for configurations that enable MBEDTLS_ENTROPY_NV_SEED.
  75. # For test purposes, this doesn't have to be cryptographically random.
  76. if (!-e "tests/seedfile" || -s "tests/seedfile" < 64) {
  77. local *SEEDFILE;
  78. open SEEDFILE, ">tests/seedfile" or die;
  79. print SEEDFILE "*" x 64 or die;
  80. close SEEDFILE or die;
  81. }
  82. sub perform_test {
  83. my $conf_file = $_[0];
  84. my $data = $_[1];
  85. my $test_with_psa = $_[2];
  86. my $conf_name = $conf_file;
  87. if ( $test_with_psa )
  88. {
  89. $conf_name .= "+PSA";
  90. }
  91. system( "cp $config_h.bak $config_h" ) and die;
  92. system( "make clean" ) and die;
  93. print "\n******************************************\n";
  94. print "* Testing configuration: $conf_name\n";
  95. print "******************************************\n";
  96. $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
  97. system( "cp configs/$conf_file $config_h" )
  98. and abort "Failed to activate $conf_file\n";
  99. if ( $test_with_psa )
  100. {
  101. system( "scripts/config.py set MBEDTLS_PSA_CRYPTO_C" );
  102. system( "scripts/config.py set MBEDTLS_USE_PSA_CRYPTO" );
  103. }
  104. system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
  105. system( "make test" ) and abort "Failed test suite: $conf_name\n";
  106. my $compat = $data->{'compat'};
  107. if( $compat )
  108. {
  109. print "\nrunning compat.sh $compat ($conf_name)\n";
  110. system( "tests/compat.sh $compat" )
  111. and abort "Failed compat.sh: $conf_name\n";
  112. }
  113. else
  114. {
  115. print "\nskipping compat.sh ($conf_name)\n";
  116. }
  117. my $opt = $data->{'opt'};
  118. if( $opt )
  119. {
  120. if( $data->{'opt_needs_debug'} )
  121. {
  122. print "\nrebuilding with debug traces for ssl-opt ($conf_name)\n";
  123. $conf_name .= '+DEBUG';
  124. $ENV{MBEDTLS_TEST_CONFIGURATION} = $conf_name;
  125. system( "make clean" );
  126. system( "scripts/config.py set MBEDTLS_DEBUG_C" );
  127. system( "scripts/config.py set MBEDTLS_ERROR_C" );
  128. system( "CFLAGS='-Os -Werror -Wall -Wextra' make" ) and abort "Failed to build: $conf_name\n";
  129. }
  130. print "\nrunning ssl-opt.sh $opt ($conf_name)\n";
  131. system( "tests/ssl-opt.sh $opt" )
  132. and abort "Failed ssl-opt.sh: $conf_name\n";
  133. }
  134. else
  135. {
  136. print "\nskipping ssl-opt.sh ($conf_name)\n";
  137. }
  138. }
  139. foreach my $conf ( @configs_to_test ) {
  140. my $test_with_psa = $configs{$conf}{'test_again_with_use_psa'};
  141. if ( $test_with_psa )
  142. {
  143. perform_test( $conf, $configs{$conf}, $test_with_psa );
  144. }
  145. perform_test( $conf, $configs{$conf}, 0 );
  146. }
  147. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  148. system( "make clean" );
  149. exit 0;