test_platforminfo.py (9170B)
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 # Macos 15 has specific hacks 71 test_settings["platform"]["os"]["name"] = "macosx" 72 test_settings["platform"]["os"]["version"] = "1500" 73 platform_info = PlatformInfo(test_settings) 74 assert platform_info.os_version == "15.30" 75 76 # Android os version gets converted to sdk version 77 test_settings["platform"]["os"]["name"] = "android" 78 test_settings["platform"]["os"]["version"] = "14.0" 79 platform_info = PlatformInfo(test_settings) 80 assert platform_info.os_version == "14" 81 82 # Windows version stays as is 83 test_settings["platform"]["os"]["name"] = "windows" 84 test_settings["platform"]["os"]["version"] = "11" 85 platform_info = PlatformInfo(test_settings) 86 assert platform_info.os_version == "11" 87 88 # Can add build number if needed for windows 89 test_settings["platform"]["os"]["name"] = "windows" 90 test_settings["platform"]["os"]["version"] = "11" 91 test_settings["platform"]["os"]["build"] = "2009" 92 platform_info = PlatformInfo(test_settings) 93 assert platform_info.os_version == "11.2009" 94 95 test_settings["platform"]["os"]["name"] = "windows" 96 test_settings["platform"]["os"]["version"] = "11" 97 test_settings["platform"]["os"]["build"] = "24h2" 98 platform_info = PlatformInfo(test_settings) 99 assert platform_info.os_version == "11.26100" 100 101 102 def test_os_arch(): 103 test_settings = deepcopy(BASE_TEST_SETTINGS) 104 105 # detects 32bits arch as x86 106 test_settings["platform"]["arch"] = "x86" 107 platform_info = PlatformInfo(test_settings) 108 assert platform_info.arch == "x86" 109 test_settings["platform"]["arch"] = "anything32" 110 platform_info = PlatformInfo(test_settings) 111 assert platform_info.arch == "x86" 112 113 # detects specific architectures 114 test_settings["platform"]["arch"] = "aarch64" 115 platform_info = PlatformInfo(test_settings) 116 assert platform_info.arch == "aarch64" 117 test_settings["platform"]["arch"] = "ppc" 118 platform_info = PlatformInfo(test_settings) 119 assert platform_info.arch == "ppc" 120 test_settings["platform"]["arch"] = "arm7" 121 platform_info = PlatformInfo(test_settings) 122 assert platform_info.arch == "arm7" 123 124 # converts other arch as x86_64 125 test_settings["platform"]["arch"] = "x86_64" 126 platform_info = PlatformInfo(test_settings) 127 assert platform_info.arch == "x86_64" 128 test_settings["platform"]["arch"] = "anything" 129 platform_info = PlatformInfo(test_settings) 130 assert platform_info.arch == "x86_64" 131 132 133 def test_os_bits(): 134 test_settings = deepcopy(BASE_TEST_SETTINGS) 135 136 # detects 32bits 137 test_settings["platform"]["arch"] = "x86" 138 platform_info = PlatformInfo(test_settings) 139 assert platform_info.bits == "32" 140 test_settings["platform"]["arch"] = "anything32" 141 platform_info = PlatformInfo(test_settings) 142 assert platform_info.bits == "32" 143 144 # other architectures are assumed 64 bits 145 test_settings["platform"]["arch"] = "aarch64" 146 platform_info = PlatformInfo(test_settings) 147 assert platform_info.bits == "64" 148 test_settings["platform"]["arch"] = "x86_64" 149 platform_info = PlatformInfo(test_settings) 150 assert platform_info.bits == "64" 151 test_settings["platform"]["arch"] = "anything" 152 platform_info = PlatformInfo(test_settings) 153 assert platform_info.bits == "64" 154 155 156 def test_build_type(): 157 test_settings = deepcopy(BASE_TEST_SETTINGS) 158 159 # detects opt and debug build types 160 test_settings["build"] = {"type": "debug"} 161 platform_info = PlatformInfo(test_settings) 162 assert platform_info.build_type == "debug" 163 assert platform_info.debug 164 test_settings["build"] = {"type": "opt"} 165 platform_info = PlatformInfo(test_settings) 166 assert platform_info.build_type == "opt" 167 assert platform_info.opt 168 169 # detects more complex build types 170 test_settings["build"] = {"type": "opt", "asan": True} 171 platform_info = PlatformInfo(test_settings) 172 assert platform_info.build_type == "asan" 173 assert platform_info.opt 174 175 # ignore shippable, devedition and mingwclang 176 test_settings["build"] = {"type": "opt", "shippable": True} 177 platform_info = PlatformInfo(test_settings) 178 assert platform_info.build_type == "opt" 179 assert platform_info.opt 180 181 test_settings["build"] = {"type": "opt", "devedition": True} 182 platform_info = PlatformInfo(test_settings) 183 assert platform_info.build_type == "opt" 184 assert platform_info.opt 185 186 test_settings["build"] = {"type": "opt", "mingwclang": True} 187 platform_info = PlatformInfo(test_settings) 188 assert platform_info.build_type == "opt" 189 assert platform_info.opt 190 191 # ignore ccov only on mac 192 test_settings["platform"]["os"]["name"] = "macosx" 193 test_settings["platform"]["os"]["version"] = "1407" 194 test_settings["build"] = {"type": "opt", "ccov": True} 195 platform_info = PlatformInfo(test_settings) 196 assert platform_info.build_type == "opt" 197 assert platform_info.opt 198 test_settings["platform"]["os"]["name"] = "linux" 199 test_settings["platform"]["os"]["version"] = "2204" 200 test_settings["build"] = {"type": "opt", "ccov": True} 201 platform_info = PlatformInfo(test_settings) 202 assert platform_info.build_type == "ccov" 203 assert platform_info.opt 204 205 # ignore lite on android 206 test_settings["platform"]["os"]["name"] = "android" 207 test_settings["platform"]["os"]["version"] = "13.0" 208 test_settings["build"] = {"type": "opt", "lite": True} 209 platform_info = PlatformInfo(test_settings) 210 assert platform_info.build_type == "opt" 211 assert platform_info.opt 212 213 214 def test_runtimes(): 215 test_settings = deepcopy(BASE_TEST_SETTINGS) 216 217 # replace empty array by no_variant 218 test_settings["runtime"] = {} 219 platform_info = PlatformInfo(test_settings) 220 assert platform_info.test_variant == "no_variant" 221 222 # ignore invalid runtimes 223 test_settings["runtime"] = {"anything": True} 224 platform_info = PlatformInfo(test_settings) 225 assert platform_info.test_variant == "no_variant" 226 227 # detect valid runtimes 228 test_settings["runtime"] = {"xorigin": True} 229 platform_info = PlatformInfo(test_settings) 230 assert platform_info.test_variant == "xorigin" 231 232 # converts variants using mowinfo 233 test_settings["runtime"] = {"1proc": True} 234 platform_info = PlatformInfo(test_settings) 235 assert platform_info.test_variant == "!e10s" 236 237 # specific logic for no-fission 238 test_settings["runtime"] = {"no-fission": True} 239 platform_info = PlatformInfo(test_settings) 240 assert platform_info.test_variant == "!fission" 241 242 # combines multiple runtimes 243 test_settings["runtime"] = {"xorigin": True, "1proc": True} 244 platform_info = PlatformInfo(test_settings) 245 assert platform_info.test_variant == "!e10s+xorigin" 246 247 # combines multiple runtimes 2 248 test_settings["runtime"] = {"no-fission": True} 249 platform_info = PlatformInfo(test_settings) 250 assert platform_info.test_variant == "!fission" 251 252 253 if __name__ == "__main__": 254 main()