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.
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.
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/>.
19 use Test::More tests => 16830;
21 use_ok('Dpkg::Arch', qw(debarch_to_debtuple debarch_to_multiarch
22 debarch_eq debarch_is debarch_is_wildcard
26 debtuple_to_debarch gnutriplet_to_debarch
30 sub get_valid_wildcards
33 my @wildcards_base = qw(
40 foreach my $archname (get_valid_arches()) {
41 my @tuple = debarch_to_debtuple($archname);
43 my @wildcards_arch = (
48 # Three element tuples.
49 "$tuple[1]-$tuple[2]-any",
50 "$tuple[1]-any-$tuple[3]",
52 "any-$tuple[2]-$tuple[3]",
56 # Four element tuples.
57 "$tuple[0]-$tuple[1]-$tuple[2]-any",
58 "$tuple[0]-$tuple[1]-any-$tuple[3]",
59 "$tuple[0]-$tuple[1]-any-any",
60 "$tuple[0]-any-$tuple[2]-$tuple[3]",
61 "$tuple[0]-any-$tuple[2]-any",
62 "$tuple[0]-any-any-$tuple[3]",
63 "$tuple[0]-any-any-any",
64 "any-$tuple[1]-$tuple[2]-$tuple[3]",
65 "any-$tuple[1]-$tuple[2]-any",
66 "any-$tuple[1]-any-$tuple[3]",
67 "any-$tuple[1]-any-any",
68 "any-any-$tuple[2]-$tuple[3]",
69 "any-any-$tuple[2]-any",
70 "any-any-any-$tuple[3]",
73 foreach my $wildcard ((@wildcards_base, @wildcards_arch)) {
74 push @{$wildcards{$wildcard}}, $archname;
84 @tuple_new = debarch_to_debtuple('unknown');
85 is_deeply(\@tuple_new, [], 'unknown tuple');
87 @tuple_ref = qw(base gnu linux amd64);
88 @tuple_new = debarch_to_debtuple('amd64');
89 is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
91 @tuple_ref = qw(base gnu linux amd64);
92 @tuple_new = debarch_to_debtuple('amd64');
93 is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
94 @tuple_new = debarch_to_debtuple('linux-amd64');
95 is_deeply(\@tuple_new, \@tuple_ref, 'valid tuple');
97 is(debarch_to_multiarch('i386'), 'i386-linux-gnu',
98 'normalized i386 multiarch triplet');
99 is(debarch_to_multiarch('amd64'), 'x86_64-linux-gnu',
100 'normalized amd64 multiarch triplet');
102 ok(!debarch_eq('amd64', 'i386'), 'no match, simple arch');
103 ok(!debarch_eq('', 'amd64'), 'no match, empty first arch');
104 ok(!debarch_eq('amd64', ''), 'no match, empty second arch');
105 ok(!debarch_eq('amd64', 'unknown'), 'no match, with first unknown arch');
106 ok(!debarch_eq('unknown', 'i386'), 'no match, second unknown arch');
107 ok(debarch_eq('unknown', 'unknown'), 'match equal unknown arch');
108 ok(debarch_eq('amd64', 'amd64'), 'match equal known arch');
109 ok(debarch_eq('amd64', 'linux-amd64'), 'match implicit linux arch');
111 ok(!debarch_is('unknown', 'linux-any'), 'no match unknown on wildcard cpu');
112 ok(!debarch_is('unknown', 'any-amd64'), 'no match unknown on wildcard os');
113 ok(!debarch_is('amd64', 'unknown'), 'no match amd64 on unknown wildcard');
114 ok(!debarch_is('amd64', 'unknown-any'), 'no match amd64 on unknown wildcard');
115 ok(!debarch_is('amd64', 'any-unknown'), 'no match amd64 on unknown wildcard');
116 ok(debarch_is('unknown', 'any'), 'match unknown on global wildcard');
117 ok(debarch_is('linux-amd64', 'linux-any'), 'match implicit linux-amd64 on wildcard cpu');
118 ok(debarch_is('linux-amd64', 'any-amd64'), 'match implicit linux-amd64 on wildcard os');
120 my $wildcards = get_valid_wildcards();
122 foreach my $wildcard (sort keys %{$wildcards}) {
123 ok(debarch_is_wildcard($wildcard), "$wildcard is a wildcard");
125 foreach my $arch (sort @{$wildcards->{$wildcard}}) {
126 ok(debarch_is($arch, $wildcard), "wildcard $wildcard matches $arch");
130 ok(!debarch_is_wildcard('unknown'), 'unknown is not a wildcard');
131 ok(!debarch_is_wildcard('all'), 'all is not a wildcard');
132 ok(!debarch_is_wildcard('amd64'), '<arch> is not a wildcard');
134 ok(!debarch_is_illegal('0'), '');
135 ok(!debarch_is_illegal('a'), '');
136 ok(!debarch_is_illegal('amd64'), '');
137 ok(!debarch_is_illegal('!arm64'), '');
138 ok(!debarch_is_illegal('kfreebsd-any'), '');
139 ok(debarch_is_illegal('!amd64!arm'), '');
140 ok(debarch_is_illegal('arch%name'), '');
141 ok(debarch_is_illegal('-any'), '');
142 ok(debarch_is_illegal('!'), '');
147 @arch_ref = qw(amd64 !arm64 linux-i386 !kfreebsd-any);
148 @arch_new = debarch_list_parse('amd64 !arm64 linux-i386 !kfreebsd-any');
149 is_deeply(\@arch_new, \@arch_ref, 'parse valid arch list');
151 eval { @arch_new = debarch_list_parse('!amd64!arm64') };
152 ok($@, 'parse concatenated arches failed');
154 is(debarch_to_cpuattrs(undef), undef, 'undef cpu attrs');
155 is_deeply([ debarch_to_cpuattrs('amd64') ], [ qw(64 little) ], 'amd64 cpu attrs');
157 is(debtuple_to_debarch(undef, undef, undef, undef), undef, 'undef debtuple');
158 is(debtuple_to_debarch('base', 'gnu', 'linux', 'amd64'), 'amd64', 'known debtuple');
159 is(debtuple_to_debarch('unknown', 'unknown', 'unknown', 'unknown'), undef, 'unknown debtuple');
161 is(gnutriplet_to_debarch(undef), undef, 'undef gnutriplet');
162 is(gnutriplet_to_debarch('unknown-unknown-unknown'), undef, 'unknown gnutriplet');
163 is(gnutriplet_to_debarch('x86_64-linux-gnu'), 'amd64', 'known gnutriplet');
165 is(scalar get_valid_arches(), 539, 'expected amount of known architectures');
168 local $ENV{CC} = 'false';
169 is(get_host_gnu_type(), '', 'CC does not support -dumpmachine');
171 $ENV{CC} = 'echo CC';
172 is(get_host_gnu_type(), 'CC -dumpmachine',
173 'CC does not report expected synthetic result for -dumpmachine');