depends-hashes.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env perl
  2. # depends-hashes.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. # To test the code dependencies on individual hashes in each test suite. This
  49. # is a verification step to ensure we don't ship test suites that do not work
  50. # for some build options.
  51. #
  52. # The process is:
  53. # for each possible hash
  54. # build the library and test suites with the hash disabled
  55. # execute the test suites
  56. #
  57. # And any test suite with the wrong dependencies will fail.
  58. #
  59. # Usage: tests/scripts/depends-hashes.pl
  60. #
  61. # This script should be executed from the root of the project directory.
  62. #
  63. # For best effect, run either with cmake disabled, or cmake enabled in a mode
  64. # that includes -Werror.
  65. use warnings;
  66. use strict;
  67. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  68. my $config_h = 'include/mbedtls/config.h';
  69. # as many SSL options depend on specific hashes,
  70. # and SSL is not in the test suites anyways,
  71. # disable it to avoid dependcies issues
  72. my $ssl_sed_cmd = 's/^#define \(MBEDTLS_SSL.*\)/\1/p';
  73. my @ssl = split( /\s+/, `sed -n -e '$ssl_sed_cmd' $config_h` );
  74. # for md we want to catch MD5_C but not MD_C, hence the extra dot
  75. my $mdx_sed_cmd = 's/^#define \(MBEDTLS_MD..*_C\)/\1/p';
  76. my $sha_sed_cmd = 's/^#define \(MBEDTLS_SHA.*_C\)/\1/p';
  77. my @hashes = split( /\s+/,
  78. `sed -n -e '$mdx_sed_cmd' -e '$sha_sed_cmd' $config_h` );
  79. system( "cp $config_h $config_h.bak" ) and die;
  80. sub abort {
  81. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  82. # use an exit code between 1 and 124 for git bisect (die returns 255)
  83. warn $_[0];
  84. exit 1;
  85. }
  86. for my $hash (@hashes) {
  87. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  88. system( "make clean" ) and die;
  89. print "\n******************************************\n";
  90. print "* Testing without hash: $hash\n";
  91. print "******************************************\n";
  92. system( "scripts/config.pl unset $hash" )
  93. and abort "Failed to disable $hash\n";
  94. for my $opt (@ssl) {
  95. system( "scripts/config.pl unset $opt" )
  96. and abort "Failed to disable $opt\n";
  97. }
  98. system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
  99. and abort "Failed to build lib: $hash\n";
  100. system( "cd tests && make" ) and abort "Failed to build tests: $hash\n";
  101. system( "make test" ) and abort "Failed test suite: $hash\n";
  102. }
  103. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  104. system( "make clean" ) and die;
  105. exit 0;