Dpkg_Arch.t 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 => 64;
  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. my @tuple_new;
  27. my @tuple_ref;
  28. @tuple_new = debarch_to_debtuple('unknown');
  29. is_deeply(\@tuple_new, [], 'unknown tuple');
  30. @tuple_ref = qw(base gnu linux amd64);
  31. @tuple_new = debarch_to_debtuple('amd64');
  32. is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
  33. @tuple_ref = qw(base gnu linux amd64);
  34. @tuple_new = debarch_to_debtuple('amd64');
  35. is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
  36. @tuple_new = debarch_to_debtuple('linux-amd64');
  37. is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
  38. is(debarch_to_multiarch('i386'), 'i386-linux-gnu',
  39. 'normalized i386 multiarch triplet');
  40. is(debarch_to_multiarch('amd64'), 'x86_64-linux-gnu',
  41. 'normalized amd64 multiarch triplet');
  42. ok(!debarch_eq('amd64', 'i386'), 'no match, simple arch');
  43. ok(!debarch_eq('', 'amd64'), 'no match, empty first arch');
  44. ok(!debarch_eq('amd64', ''), 'no match, empty second arch');
  45. ok(!debarch_eq('amd64', 'unknown'), 'no match, with first unknown arch');
  46. ok(!debarch_eq('unknown', 'i386'), 'no match, second unknown arch');
  47. ok(debarch_eq('unknown', 'unknown'), 'match equal unknown arch');
  48. ok(debarch_eq('amd64', 'amd64'), 'match equal known arch');
  49. ok(debarch_eq('amd64', 'linux-amd64'), 'match implicit linux arch');
  50. ok(!debarch_is('unknown', 'linux-any'), 'no match unknown on wildcard cpu');
  51. ok(!debarch_is('unknown', 'any-amd64'), 'no match unknown on wildcard os');
  52. ok(!debarch_is('amd64', 'unknown'), 'no match amd64 on unknown wildcard');
  53. ok(!debarch_is('amd64', 'unknown-any'), 'no match amd64 on unknown wildcard');
  54. ok(!debarch_is('amd64', 'any-unknown'), 'no match amd64 on unknown wildcard');
  55. ok(debarch_is('unknown', 'any'), 'match unknown on global wildcard');
  56. ok(debarch_is('amd64', 'linux-any'), 'match amd64 on wildcard cpu');
  57. ok(debarch_is('amd64', 'any-amd64'), 'match amd64 on wildcard os');
  58. ok(debarch_is('x32', 'any-amd64'), 'match x32 on amd64 wildcard os');
  59. ok(debarch_is('i386', 'any-i386'), 'match i386 on i386 wildcard os');
  60. ok(debarch_is('arm', 'any-arm'), 'match arm on arm wildcard os');
  61. ok(debarch_is('armel', 'any-arm'), 'match armel on arm wildcard os');
  62. ok(debarch_is('armhf', 'any-arm'), 'match armhf on arm wildcard os');
  63. ok(debarch_is('amd64', 'gnu-any-any'), 'match amd64 on abi wildcard');
  64. ok(debarch_is('linux-amd64', 'gnu-any-any'),
  65. 'match linux-amd64 on abi wildcard');
  66. ok(debarch_is('kfreebsd-amd64', 'gnu-any-any'),
  67. 'match kfreebsd-amd64 on abi wildcard');
  68. ok(!debarch_is_wildcard('unknown'), 'unknown is not a wildcard');
  69. ok(!debarch_is_wildcard('all'), 'all is not a wildcard');
  70. ok(!debarch_is_wildcard('amd64'), '<arch> is not a wildcard');
  71. ok(debarch_is_wildcard('any'), '<any> is a global wildcard');
  72. ok(debarch_is_wildcard('any-any'), '<any>-<any> is a wildcard');
  73. ok(debarch_is_wildcard('any-any-any'), '<any>-<any>-<any> is a wildcard');
  74. ok(debarch_is_wildcard('linux-any'), '<os>-any is a wildcard');
  75. ok(debarch_is_wildcard('any-amd64'), 'any-<cpu> is a wildcard');
  76. ok(debarch_is_wildcard('gnu-any-any'), '<abi>-any-any is a wildcard');
  77. ok(debarch_is_wildcard('any-linux-any'), 'any-<os>-any is a wildcard');
  78. ok(debarch_is_wildcard('any-any-amd64'), 'any-any-<cpu> is a wildcard');
  79. ok(!debarch_is_illegal('0'), '');
  80. ok(!debarch_is_illegal('a'), '');
  81. ok(!debarch_is_illegal('amd64'), '');
  82. ok(!debarch_is_illegal('!arm64'), '');
  83. ok(!debarch_is_illegal('kfreebsd-any'), '');
  84. ok(debarch_is_illegal('!amd64!arm'), '');
  85. ok(debarch_is_illegal('arch%name'), '');
  86. ok(debarch_is_illegal('-any'), '');
  87. ok(debarch_is_illegal('!'), '');
  88. my @arch_new;
  89. my @arch_ref;
  90. @arch_ref = qw(amd64 !arm64 linux-i386 !kfreebsd-any);
  91. @arch_new = debarch_list_parse('amd64 !arm64 linux-i386 !kfreebsd-any');
  92. is_deeply(\@arch_new, \@arch_ref, 'parse valid arch list');
  93. eval { @arch_new = debarch_list_parse('!amd64!arm64') };
  94. ok($@, 'parse concatenated arches failed');
  95. is(debarch_to_cpuattrs(undef), undef, 'undef cpu attrs');
  96. is_deeply([ debarch_to_cpuattrs('amd64') ], [ qw(64 little) ], 'amd64 cpu attrs');
  97. is(debtuple_to_debarch(undef, undef, undef, undef), undef, 'undef debtuple');
  98. is(debtuple_to_debarch('base', 'gnu', 'linux', 'amd64'), 'amd64', 'known debtuple');
  99. is(debtuple_to_debarch('unknown', 'unknown', 'unknown', 'unknown'), undef, 'unknown debtuple');
  100. is(gnutriplet_to_debarch(undef), undef, 'undef gnutriplet');
  101. is(gnutriplet_to_debarch('unknown-unknown-unknown'), undef, 'unknown gnutriplet');
  102. is(gnutriplet_to_debarch('x86_64-linux-gnu'), 'amd64', 'known gnutriplet');
  103. is(scalar get_valid_arches(), 523, 'expected amount of known architectures');
  104. {
  105. local $ENV{CC} = 'false';
  106. is(get_host_gnu_type(), '', 'CC does not support -dumpmachine');
  107. $ENV{CC} = 'echo CC';
  108. is(get_host_gnu_type(), 'CC -dumpmachine',
  109. 'CC does not report expected synthetic result for -dumpmachine');
  110. }
  111. 1;