02-test_ordinals.t 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use strict;
  9. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  10. setup("test_ordinals");
  11. plan tests => 2;
  12. ok(testordinals(srctop_file("util", "libcrypto.num")), "Test libcrypto.num");
  13. ok(testordinals(srctop_file("util", "libssl.num")), "Test libssl.num");
  14. sub testordinals
  15. {
  16. my $filename = shift;
  17. my $cnt = 0;
  18. my $ret = 1;
  19. my $qualifier = "";
  20. my $newqual;
  21. my $lastfunc = "";
  22. open(my $fh, '<', $filename);
  23. while (my $line = <$fh>) {
  24. my @tokens = split(/(?:\s+|\s*:\s*)/, $line);
  25. #Check the line looks sane
  26. if ($#tokens < 5 || $#tokens > 6) {
  27. print STDERR "Invalid line:\n$line\n";
  28. $ret = 0;
  29. last;
  30. }
  31. if ($tokens[3] eq "NOEXIST") {
  32. #Ignore this line
  33. next;
  34. }
  35. #Some ordinals can be repeated, e.g. if one is VMS and another is !VMS
  36. $newqual = $tokens[4];
  37. $newqual =~ s/!//g;
  38. my $number = $tokens[1];
  39. $number = $cnt + 1 if $number eq '?';
  40. $number = $cnt if $number eq '?+';
  41. if ($cnt > $number
  42. || ($cnt == $number && ($qualifier ne $newqual
  43. || $qualifier eq ""))) {
  44. print STDERR "Invalid ordinal detected: ".$tokens[1]."\n";
  45. $ret = 0;
  46. last;
  47. }
  48. $cnt = $tokens[1];
  49. $qualifier = $newqual;
  50. $lastfunc = $tokens[0];
  51. }
  52. close($fh);
  53. return $ret;
  54. }