curves.pl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env perl
  2. # curves.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 curves 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 curve
  54. # build the library and test suites with the curve disabled
  55. # execute the test suites
  56. #
  57. # And any test suite with the wrong dependencies will fail.
  58. #
  59. # Usage: tests/scripts/curves.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 $sed_cmd = 's/^#define \(MBEDTLS_ECP_DP.*_ENABLED\)/\1/p';
  69. my $config_h = 'include/mbedtls/config.h';
  70. my @curves = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
  71. system( "cp $config_h $config_h.bak" ) and die;
  72. sub abort {
  73. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  74. # use an exit code between 1 and 124 for git bisect (die returns 255)
  75. warn $_[0];
  76. exit 1;
  77. }
  78. for my $curve (@curves) {
  79. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  80. system( "make clean" ) and die;
  81. # depends on a specific curve. Also, ignore error if it wasn't enabled
  82. system( "scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED" );
  83. print "\n******************************************\n";
  84. print "* Testing without curve: $curve\n";
  85. print "******************************************\n";
  86. system( "scripts/config.pl unset $curve" )
  87. and abort "Failed to disable $curve\n";
  88. system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
  89. and abort "Failed to build lib: $curve\n";
  90. system( "cd tests && make" ) and abort "Failed to build tests: $curve\n";
  91. system( "make test" ) and abort "Failed test suite: $curve\n";
  92. }
  93. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  94. system( "make clean" ) and die;
  95. exit 0;