asmdata.t 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env perl -w
  2. # blead cannot run -T
  3. BEGIN {
  4. if ($ENV{PERL_CORE}){
  5. chdir('t') if -d 't';
  6. @INC = ('.', '../lib');
  7. }
  8. require Config;
  9. if ($ENV{PERL_CORE} and ($Config::Config{'extensions'} !~ /\bB\b/) ){
  10. print "1..0 # Skip -- Perl configured without B module\n";
  11. exit 0;
  12. }
  13. }
  14. use Test::More;
  15. if (!-d '.git' or $ENV{NO_AUTHOR}) {
  16. plan tests => ($] < 5.009) ? 15 : 16;
  17. }
  18. use B ();
  19. if ($] < 5.009) {
  20. use_ok('B::Asmdata', qw(%insn_data @insn_name @optype @specialsv_name));
  21. } else {
  22. use_ok('B', qw(@optype @specialsv_name));
  23. use_ok('B::Asmdata', qw(%insn_data @insn_name));
  24. }
  25. # see bytecode.pl (alias_to or argtype) and ByteLoader/bytecode.h
  26. my @valid_type = qw(comment_t none svindex pvindex opindex U32 U16 U8 I32 IV long NV
  27. PADOFFSET pvcontents strconst op_tr_array pmflags PV IV64);
  28. my %valid_type = map {$_ => 1} @valid_type;
  29. # check we got something.
  30. isnt( keys %insn_data, 0, '%insn_data exported and populated' );
  31. isnt( @insn_name, 0, ' @insn_name' );
  32. isnt( @optype, 0, ' @optype' );
  33. isnt( @specialsv_name, 0, ' @specialsv_name' );
  34. # pick an op that's not likely to go away in the future
  35. my @data = values %insn_data;
  36. is( (grep { ref eq 'ARRAY' } @data), @data, '%insn_data contains arrays' );
  37. # sort out unsupport ones, with no PUT method
  38. # @data = grep {$_[1]} @data;
  39. # pick one at random to test with.
  40. my (@opnames, $random);
  41. unless (!-d '.git' or $ENV{NO_AUTHOR}) {
  42. @opnames = sort keys %insn_data;
  43. $random = "";
  44. } else {
  45. @opnames = ( (keys %insn_data)[rand @data] );
  46. $random = "random";
  47. }
  48. for my $opname (@opnames) {
  49. my $data = $insn_data{$opname};
  50. my $opidx = $data->[0];
  51. like( $data->[0], qr/^\d+$/, " op number for $random $opname:$opidx" );
  52. if ($data->[1]) {
  53. is( ref $data->[1], 'CODE', " PUT code ref for $opname" );
  54. my $putname = B::svref_2object($data->[1])->GV->NAME;
  55. $putname =~ s/^PUT_//;
  56. ok( $valid_type{$putname}, " valid PUT name $putname for $opname" );
  57. } else {
  58. ok(1, " empty PUT for $opname" );
  59. ok(1, " skip valid PUT name check" );
  60. }
  61. ok( !ref $data->[2], " GET method for $opname" );
  62. my $getname = $data->[2];
  63. my $ok;
  64. if ($getname =~ /^GET_(.*)$/) {
  65. $ok = $valid_type{$1};
  66. }
  67. ok( $ok, " GET method $getname looks good" );
  68. is( $insn_name[$data->[0]], $opname, '@insn_name maps correctly' );
  69. }
  70. # I'm going to assume that op types will all be named /OP$/.
  71. # Just 5.22 added a UNOP_AUX
  72. if ($] >= 5.021007) {
  73. is( grep(/OP$/, @optype), scalar(@optype) - 1, '@optype is almost all /OP$/' );
  74. } else {
  75. is( grep(/OP$/, @optype), @optype, '@optype is all /OP$/' );
  76. }
  77. # comment in bytecode.pl says "Nullsv *must come first so that the
  78. # condition ($$sv == 0) can continue to be used to test (sv == Nullsv)."
  79. is( $specialsv_name[0], 'Nullsv', 'Nullsv come first in @special_sv_name' );
  80. # other than that, we can't really say much more about @specialsv_name
  81. # than it has to contain strings (on the off chance &PL_sv_undef gets
  82. # flubbed)
  83. is( grep(!ref, @specialsv_name), @specialsv_name, ' contains all strings' );
  84. unless (!-d '.git' or $ENV{NO_AUTHOR}) {
  85. done_testing;
  86. }