Debian Codegraph @

testing/mozbase/mozinfo/tests/test_platforminfo.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 from copy import deepcopy
6
7 from mozinfo.platforminfo import PlatformInfo
8 from mozunit import main
9
10 BASE_TEST_SETTINGS = {
11 "platform": {
12 "os": {
13 "name": "linux",
14 "version": "2204",
15 "build": None,
16 },
17 "arch": "x86",
18 },
19 "build": {"type": "debug"},
20 "runtime": {},
21 }
22
23
24 def test_os():
25 test_settings = deepcopy(BASE_TEST_SETTINGS)
26
27 # Android an linux names do not change
28 test_settings["platform"]["os"]["name"] = "linux"
29 test_settings["platform"]["os"]["version"] = "22.04"
30 platform_info = PlatformInfo(test_settings)
31 assert platform_info.os == "linux"
32
33 test_settings["platform"]["os"]["name"] = "android"
34 test_settings["platform"]["os"]["version"] = "13.0"
35 platform_info = PlatformInfo(test_settings)
36 assert platform_info.os == "android"
37
38 # Macosx and Windows names are shortened
39 test_settings["platform"]["os"]["name"] = "macosx"
40 test_settings["platform"]["os"]["version"] = "1407"
41 platform_info = PlatformInfo(test_settings)
42 assert platform_info.os == "mac"
43
44 test_settings["platform"]["os"]["name"] = "windows"
45 test_settings["platform"]["os"]["version"] = "11"
46 platform_info = PlatformInfo(test_settings)
47 assert platform_info.os == "win"
48
49
50 def test_os_version():
51 test_settings = deepcopy(BASE_TEST_SETTINGS)
52
53 # linux and macosx version get expanded
54 test_settings["platform"]["os"]["name"] = "linux"
55 test_settings["platform"]["os"]["version"] = "2204"
56 platform_info = PlatformInfo(test_settings)
57 assert platform_info.os_version == "22.04"
58
59 test_settings["platform"]["os"]["name"] = "macosx"
60 test_settings["platform"]["os"]["version"] = "1470"
61 platform_info = PlatformInfo(test_settings)
62 assert platform_info.os_version == "14.70"
63
64 # Macos 11 has specific hacks
65 test_settings["platform"]["os"]["name"] = "macosx"
66 test_settings["platform"]["os"]["version"] = "1100"
67 platform_info = PlatformInfo(test_settings)
68 assert platform_info.os_version == "11.20"
69
70 # Android os version gets converted to sdk version
71 test_settings["platform"]["os"]["name"] = "android"
72 test_settings["platform"]["os"]["version"] = "14.0"
73 platform_info = PlatformInfo(test_settings)
74 assert platform_info.os_version == "34"
75
76 # Windows version stays as is
77 test_settings["platform"]["os"]["name"] = "windows"
78 test_settings["platform"]["os"]["version"] = "11"
79 platform_info = PlatformInfo(test_settings)
80 assert platform_info.os_version == "11"
81
82 # Can add build number if needed for windows
83 test_settings["platform"]["os"]["name"] = "windows"
84 test_settings["platform"]["os"]["version"] = "11"
85 test_settings["platform"]["os"]["build"] = "2009"
86 platform_info = PlatformInfo(test_settings)
87 assert platform_info.os_version == "11.2009"
88
89 test_settings["platform"]["os"]["name"] = "windows"
90 test_settings["platform"]["os"]["version"] = "11"
91 test_settings["platform"]["os"]["build"] = "24h2"
92 platform_info = PlatformInfo(test_settings)
93 assert platform_info.os_version == "11.26100"
94
95
96 def test_os_arch():
97 test_settings = deepcopy(BASE_TEST_SETTINGS)
98
99 # detects 32bits arch as x86
100 test_settings["platform"]["arch"] = "x86"
101 platform_info = PlatformInfo(test_settings)
102 assert platform_info.arch == "x86"
103 test_settings["platform"]["arch"] = "anything32"
104 platform_info = PlatformInfo(test_settings)
105 assert platform_info.arch == "x86"
106
107 # detects specific architectures
108 test_settings["platform"]["arch"] = "aarch64"
109 platform_info = PlatformInfo(test_settings)
110 assert platform_info.arch == "aarch64"
111 test_settings["platform"]["arch"] = "ppc"
112 platform_info = PlatformInfo(test_settings)
113 assert platform_info.arch == "ppc"
114 test_settings["platform"]["arch"] = "arm7"
115 platform_info = PlatformInfo(test_settings)
116 assert platform_info.arch == "arm7"
117
118 # converts other arch as x86_64
119 test_settings["platform"]["arch"] = "x86_64"
120 platform_info = PlatformInfo(test_settings)
121 assert platform_info.arch == "x86_64"
122 test_settings["platform"]["arch"] = "anything"
123 platform_info = PlatformInfo(test_settings)
124 assert platform_info.arch == "x86_64"
125
126
127 def test_os_bits():
128 test_settings = deepcopy(BASE_TEST_SETTINGS)
129
130 # detects 32bits
131 test_settings["platform"]["arch"] = "x86"
132 platform_info = PlatformInfo(test_settings)
133 assert platform_info.bits == "32"
134 test_settings["platform"]["arch"] = "anything32"
135 platform_info = PlatformInfo(test_settings)
136 assert platform_info.bits == "32"
137
138 # other architectures are assumed 64 bits
139 test_settings["platform"]["arch"] = "aarch64"
140 platform_info = PlatformInfo(test_settings)
141 assert platform_info.bits == "64"
142 test_settings["platform"]["arch"] = "x86_64"
143 platform_info = PlatformInfo(test_settings)
144 assert platform_info.bits == "64"
145 test_settings["platform"]["arch"] = "anything"
146 platform_info = PlatformInfo(test_settings)
147 assert platform_info.bits == "64"
148
149
150 def test_build_type():
151 test_settings = deepcopy(BASE_TEST_SETTINGS)
152
153 # detects opt and debug build types
154 test_settings["build"] = {"type": "debug"}
155 platform_info = PlatformInfo(test_settings)
156 assert platform_info.build_type == "debug"
157 assert platform_info.debug
158 test_settings["build"] = {"type": "opt"}
159 platform_info = PlatformInfo(test_settings)
160 assert platform_info.build_type == "opt"
161 assert platform_info.opt
162
163 # detects more complex build types
164 test_settings["build"] = {"type": "opt", "asan": True}
165 platform_info = PlatformInfo(test_settings)
166 assert platform_info.build_type == "asan"
167 assert platform_info.opt
168
169 # ignore shippable, devedition and mingwclang
170 test_settings["build"] = {"type": "opt", "shippable": True}
171 platform_info = PlatformInfo(test_settings)
172 assert platform_info.build_type == "opt"
173 assert platform_info.opt
174
175 test_settings["build"] = {"type": "opt", "devedition": True}
176 platform_info = PlatformInfo(test_settings)
177 assert platform_info.build_type == "opt"
178 assert platform_info.opt
179
180 test_settings["build"] = {"type": "opt", "mingwclang": True}
181 platform_info = PlatformInfo(test_settings)
182 assert platform_info.build_type == "opt"
183 assert platform_info.opt
184
185 # ignore ccov only on mac
186 test_settings["platform"]["os"]["name"] = "macosx"
187 test_settings["platform"]["os"]["version"] = "1407"
188 test_settings["build"] = {"type": "opt", "ccov": True}
189 platform_info = PlatformInfo(test_settings)
190 assert platform_info.build_type == "opt"
191 assert platform_info.opt
192 test_settings["platform"]["os"]["name"] = "linux"
193 test_settings["platform"]["os"]["version"] = "2204"
194 test_settings["build"] = {"type": "opt", "ccov": True}
195 platform_info = PlatformInfo(test_settings)
196 assert platform_info.build_type == "ccov"
197 assert platform_info.opt
198
199 # ignore lite on android
200 test_settings["platform"]["os"]["name"] = "android"
201 test_settings["platform"]["os"]["version"] = "13.0"
202 test_settings["build"] = {"type": "opt", "lite": True}
203 platform_info = PlatformInfo(test_settings)
204 assert platform_info.build_type == "opt"
205 assert platform_info.opt
206
207
208 def test_runtimes():
209 test_settings = deepcopy(BASE_TEST_SETTINGS)
210
211 # replace empty array by no_variant
212 test_settings["runtime"] = {}
213 platform_info = PlatformInfo(test_settings)
214 assert platform_info.test_variant == "no_variant"
215
216 # ignore invalid runtimes
217 test_settings["runtime"] = {"anything": True}
218 platform_info = PlatformInfo(test_settings)
219 assert platform_info.test_variant == "no_variant"
220
221 # detect valid runtimes
222 test_settings["runtime"] = {"xorigin": True}
223 platform_info = PlatformInfo(test_settings)
224 assert platform_info.test_variant == "xorigin"
225
226 # converts variants using mowinfo
227 test_settings["runtime"] = {"1proc": True}
228 platform_info = PlatformInfo(test_settings)
229 assert platform_info.test_variant == "!e10s"
230
231 # specific logic for no-fission
232 test_settings["runtime"] = {"no-fission": True}
233 platform_info = PlatformInfo(test_settings)
234 assert platform_info.test_variant == "!fission"
235
236 # combines multiple runtimes
237 test_settings["runtime"] = {"xorigin": True, "1proc": True}
238 platform_info = PlatformInfo(test_settings)
239 assert platform_info.test_variant == "xorigin+!e10s"
240
241
242 if __name__ == "__main__":
243 main()