Dpkg_Arch.t 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/perl
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. use strict;
  16. use warnings;
  17. use Test::More tests => 16334;
  18. use_ok('Dpkg::Arch', qw(debarch_to_debtuple debarch_to_multiarch
  19. debarch_eq debarch_is debarch_is_wildcard
  20. debarch_is_illegal
  21. debarch_to_cpuattrs
  22. debarch_list_parse
  23. debtuple_to_debarch gnutriplet_to_debarch
  24. get_host_gnu_type
  25. get_valid_arches));
  26. sub get_valid_wildcards
  27. {
  28. my %wildcards;
  29. my @wildcards_base = qw(
  30. any
  31. any-any
  32. any-any-any
  33. any-any-any-any
  34. );
  35. foreach my $archname (get_valid_arches()) {
  36. my @tuple = debarch_to_debtuple($archname);
  37. my @wildcards_arch = (
  38. # Two element tuples.
  39. "$tuple[2]-any",
  40. "any-$tuple[3]",
  41. # Three element tuples.
  42. "$tuple[1]-$tuple[2]-any",
  43. "$tuple[1]-any-$tuple[3]",
  44. "$tuple[1]-any-any",
  45. "any-$tuple[2]-$tuple[3]",
  46. "any-$tuple[2]-any",
  47. "any-any-$tuple[3]",
  48. # Four element tuples.
  49. "$tuple[0]-$tuple[1]-$tuple[2]-any",
  50. "$tuple[0]-$tuple[1]-any-$tuple[3]",
  51. "$tuple[0]-$tuple[1]-any-any",
  52. "$tuple[0]-any-$tuple[2]-$tuple[3]",
  53. "$tuple[0]-any-$tuple[2]-any",
  54. "$tuple[0]-any-any-$tuple[3]",
  55. "$tuple[0]-any-any-any",
  56. "any-$tuple[1]-$tuple[2]-$tuple[3]",
  57. "any-$tuple[1]-$tuple[2]-any",
  58. "any-$tuple[1]-any-$tuple[3]",
  59. "any-$tuple[1]-any-any",
  60. "any-any-$tuple[2]-$tuple[3]",
  61. "any-any-$tuple[2]-any",
  62. "any-any-any-$tuple[3]",
  63. );
  64. foreach my $wildcard ((@wildcards_base, @wildcards_arch)) {
  65. push @{$wildcards{$wildcard}}, $archname;
  66. }
  67. }
  68. return \%wildcards;
  69. }
  70. my @tuple_new;
  71. my @tuple_ref;
  72. @tuple_new = debarch_to_debtuple('unknown');
  73. is_deeply(\@tuple_new, [], 'unknown tuple');
  74. @tuple_ref = qw(base gnu linux amd64);
  75. @tuple_new = debarch_to_debtuple('amd64');
  76. is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
  77. @tuple_ref = qw(base gnu linux amd64);
  78. @tuple_new = debarch_to_debtuple('amd64');
  79. is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
  80. @tuple_new = debarch_to_debtuple('linux-amd64');
  81. is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
  82. is(debarch_to_multiarch('i386'), 'i386-linux-gnu',
  83. 'normalized i386 multiarch triplet');
  84. is(debarch_to_multiarch('amd64'), 'x86_64-linux-gnu',
  85. 'normalized amd64 multiarch triplet');
  86. ok(!debarch_eq('amd64', 'i386'), 'no match, simple arch');
  87. ok(!debarch_eq('', 'amd64'), 'no match, empty first arch');
  88. ok(!debarch_eq('amd64', ''), 'no match, empty second arch');
  89. ok(!debarch_eq('amd64', 'unknown'), 'no match, with first unknown arch');
  90. ok(!debarch_eq('unknown', 'i386'), 'no match, second unknown arch');
  91. ok(debarch_eq('unknown', 'unknown'), 'match equal unknown arch');
  92. ok(debarch_eq('amd64', 'amd64'), 'match equal known arch');
  93. ok(debarch_eq('amd64', 'linux-amd64'), 'match implicit linux arch');
  94. ok(!debarch_is('unknown', 'linux-any'), 'no match unknown on wildcard cpu');
  95. ok(!debarch_is('unknown', 'any-amd64'), 'no match unknown on wildcard os');
  96. ok(!debarch_is('amd64', 'unknown'), 'no match amd64 on unknown wildcard');
  97. ok(!debarch_is('amd64', 'unknown-any'), 'no match amd64 on unknown wildcard');
  98. ok(!debarch_is('amd64', 'any-unknown'), 'no match amd64 on unknown wildcard');
  99. ok(debarch_is('unknown', 'any'), 'match unknown on global wildcard');
  100. ok(debarch_is('linux-amd64', 'linux-any'), 'match implicit linux-amd64 on wildcard cpu');
  101. ok(debarch_is('linux-amd64', 'any-amd64'), 'match implicit linux-amd64 on wildcard os');
  102. my $wildcards = get_valid_wildcards();
  103. foreach my $wildcard (sort keys %{$wildcards}) {
  104. ok(debarch_is_wildcard($wildcard), "$wildcard is a wildcard");
  105. foreach my $arch (sort @{$wildcards->{$wildcard}}) {
  106. ok(debarch_is($arch, $wildcard), "wildcard $wildcard matches $arch");
  107. }
  108. }
  109. ok(!debarch_is_wildcard('unknown'), 'unknown is not a wildcard');
  110. ok(!debarch_is_wildcard('all'), 'all is not a wildcard');
  111. ok(!debarch_is_wildcard('amd64'), '<arch> is not a wildcard');
  112. ok(!debarch_is_illegal('0'), '');
  113. ok(!debarch_is_illegal('a'), '');
  114. ok(!debarch_is_illegal('amd64'), '');
  115. ok(!debarch_is_illegal('!arm64'), '');
  116. ok(!debarch_is_illegal('kfreebsd-any'), '');
  117. ok(debarch_is_illegal('!amd64!arm'), '');
  118. ok(debarch_is_illegal('arch%name'), '');
  119. ok(debarch_is_illegal('-any'), '');
  120. ok(debarch_is_illegal('!'), '');
  121. my @arch_new;
  122. my @arch_ref;
  123. @arch_ref = qw(amd64 !arm64 linux-i386 !kfreebsd-any);
  124. @arch_new = debarch_list_parse('amd64 !arm64 linux-i386 !kfreebsd-any');
  125. is_deeply(\@arch_new, \@arch_ref, 'parse valid arch list');
  126. eval { @arch_new = debarch_list_parse('!amd64!arm64') };
  127. ok($@, 'parse concatenated arches failed');
  128. is(debarch_to_cpuattrs(undef), undef, 'undef cpu attrs');
  129. is_deeply([ debarch_to_cpuattrs('amd64') ], [ qw(64 little) ], 'amd64 cpu attrs');
  130. is(debtuple_to_debarch(undef, undef, undef, undef), undef, 'undef debtuple');
  131. is(debtuple_to_debarch('base', 'gnu', 'linux', 'amd64'), 'amd64', 'known debtuple');
  132. is(debtuple_to_debarch('unknown', 'unknown', 'unknown', 'unknown'), undef, 'unknown debtuple');
  133. is(gnutriplet_to_debarch(undef), undef, 'undef gnutriplet');
  134. is(gnutriplet_to_debarch('unknown-unknown-unknown'), undef, 'unknown gnutriplet');
  135. is(gnutriplet_to_debarch('x86_64-linux-gnu'), 'amd64', 'known gnutriplet');
  136. is(scalar get_valid_arches(), 523, 'expected amount of known architectures');
  137. {
  138. local $ENV{CC} = 'false';
  139. is(get_host_gnu_type(), '', 'CC does not support -dumpmachine');
  140. $ENV{CC} = 'echo CC';
  141. is(get_host_gnu_type(), 'CC -dumpmachine',
  142. 'CC does not report expected synthetic result for -dumpmachine');
  143. }
  144. 1;