curves.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/perl
  2. # curves.pl
  3. #
  4. # Copyright (c) 2014-2016, ARM Limited, All Rights Reserved
  5. #
  6. # Purpose
  7. #
  8. # To test the code dependencies on individual curves in each test suite. This
  9. # is a verification step to ensure we don't ship test suites that do not work
  10. # for some build options.
  11. #
  12. # The process is:
  13. # for each possible curve
  14. # build the library and test suites with the curve disabled
  15. # execute the test suites
  16. #
  17. # And any test suite with the wrong dependencies will fail.
  18. #
  19. # Usage: curves.pl
  20. #
  21. # This script should be executed from the root of the project directory.
  22. use warnings;
  23. use strict;
  24. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  25. my $sed_cmd = 's/^#define \(MBEDTLS_ECP_DP.*_ENABLED\)/\1/p';
  26. my $config_h = 'include/mbedtls/config.h';
  27. my @curves = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
  28. system( "cp $config_h $config_h.bak" ) and die;
  29. sub abort {
  30. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  31. die $_[0];
  32. }
  33. for my $curve (@curves) {
  34. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  35. # depends on a specific curve. Also, ignore error if it wasn't enabled
  36. system( "scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED" );
  37. system( "make clean" ) and die;
  38. print "\n******************************************\n";
  39. print "* Testing without curve: $curve\n";
  40. print "******************************************\n";
  41. system( "scripts/config.pl unset $curve" )
  42. and abort "Failed to disable $curve\n";
  43. system( "make lib" ) and abort "Failed to build lib: $curve\n";
  44. system( "cd tests && make" ) and abort "Failed to build tests: $curve\n";
  45. system( "make test" ) and abort "Failed test suite: $curve\n";
  46. }
  47. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  48. system( "make clean" ) and die;
  49. exit 0;