Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 2 | # Copyright 2020 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import unittest |
| 7 | |
| 8 | import buildbot_json_magic_substitutions as magic_substitutions |
| 9 | |
| 10 | |
Ben Pastene | 2ea8ba5 | 2020-10-16 21:43:25 | [diff] [blame] | 11 | def CreateConfigWithPool(pool, device_type=None): |
| 12 | dims = { |
Brian Sheedy | 9517d1c | 2022-04-08 01:17:01 | [diff] [blame] | 13 | 'name': 'test_name', |
| 14 | 'swarming': { |
| 15 | 'dimension_sets': [ |
| 16 | { |
| 17 | 'pool': pool, |
| 18 | }, |
| 19 | ], |
| 20 | }, |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 21 | } |
Ben Pastene | 2ea8ba5 | 2020-10-16 21:43:25 | [diff] [blame] | 22 | if device_type: |
| 23 | dims['swarming']['dimension_sets'][0]['device_type'] = device_type |
| 24 | return dims |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 25 | |
| 26 | |
| 27 | class ChromeOSTelemetryRemoteTest(unittest.TestCase): |
| 28 | |
| 29 | def testVirtualMachineSubstitutions(self): |
| 30 | test_config = CreateConfigWithPool('chromium.tests.cros.vm') |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 31 | self.assertEqual( |
| 32 | magic_substitutions.ChromeOSTelemetryRemote(test_config, None), [ |
| 33 | '--remote=127.0.0.1', |
| 34 | '--remote-ssh-port=9222', |
| 35 | ]) |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 36 | |
| 37 | def testPhysicalHardwareSubstitutions(self): |
Ben Pastene | 2ea8ba5 | 2020-10-16 21:43:25 | [diff] [blame] | 38 | test_config = CreateConfigWithPool('chromium.tests', device_type='eve') |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 39 | self.assertEqual( |
| 40 | magic_substitutions.ChromeOSTelemetryRemote(test_config, None), |
| 41 | ['--remote=variable_chromeos_device_hostname']) |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 42 | |
| 43 | def testNoPool(self): |
| 44 | test_config = CreateConfigWithPool(None) |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 45 | with self.assertRaisesRegex(RuntimeError, 'No pool *'): |
| 46 | magic_substitutions.ChromeOSTelemetryRemote(test_config, None) |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 47 | |
| 48 | def testUnknownPool(self): |
| 49 | test_config = CreateConfigWithPool('totally-legit-pool') |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 50 | with self.assertRaisesRegex(RuntimeError, 'Unknown CrOS pool *'): |
| 51 | magic_substitutions.ChromeOSTelemetryRemote(test_config, None) |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 52 | |
| 53 | |
Brian Sheedy | 9517d1c | 2022-04-08 01:17:01 | [diff] [blame] | 54 | class ChromeOSGtestFilterFileTest(unittest.TestCase): |
| 55 | def testVirtualMachineFile(self): |
| 56 | test_config = CreateConfigWithPool('chromium.tests.cros.vm') |
| 57 | self.assertEqual( |
| 58 | magic_substitutions.ChromeOSGtestFilterFile(test_config, None), [ |
| 59 | '--test-launcher-filter-file=../../testing/buildbot/filters/' |
| 60 | 'chromeos.amd64-generic.test_name.filter', |
| 61 | ]) |
| 62 | |
| 63 | def testPhysicalHardwareFile(self): |
| 64 | test_config = CreateConfigWithPool('chromium.tests', device_type='eve') |
| 65 | self.assertEqual( |
| 66 | magic_substitutions.ChromeOSGtestFilterFile(test_config, None), [ |
| 67 | '--test-launcher-filter-file=../../testing/buildbot/filters/' |
| 68 | 'chromeos.eve.test_name.filter', |
| 69 | ]) |
| 70 | |
| 71 | def testNoPool(self): |
| 72 | test_config = CreateConfigWithPool(None) |
| 73 | with self.assertRaisesRegex(RuntimeError, 'No pool *'): |
| 74 | magic_substitutions.ChromeOSTelemetryRemote(test_config, None) |
| 75 | |
| 76 | def testUnknownPool(self): |
| 77 | test_config = CreateConfigWithPool('totally-legit-pool') |
| 78 | with self.assertRaisesRegex(RuntimeError, 'Unknown CrOS pool *'): |
| 79 | magic_substitutions.ChromeOSTelemetryRemote(test_config, None) |
| 80 | |
| 81 | |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 82 | def CreateConfigWithGpus(gpus): |
| 83 | dimension_sets = [] |
| 84 | for g in gpus: |
| 85 | dimension_sets.append({'gpu': g}) |
| 86 | return { |
| 87 | 'swarming': { |
| 88 | 'dimension_sets': dimension_sets, |
| 89 | }, |
| 90 | } |
| 91 | |
| 92 | |
| 93 | class GPUExpectedDeviceId(unittest.TestCase): |
| 94 | def assertDeviceIdCorrectness(self, retval, device_ids): |
| 95 | self.assertEqual(len(retval), 2 * len(device_ids)) |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 96 | for i in range(0, len(retval), 2): |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 97 | self.assertEqual(retval[i], '--expected-device-id') |
| 98 | for d in device_ids: |
| 99 | self.assertIn(d, retval) |
| 100 | |
| 101 | def testSingleGpuSingleDimension(self): |
| 102 | test_config = CreateConfigWithGpus(['vendor:device1-driver']) |
| 103 | self.assertDeviceIdCorrectness( |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 104 | magic_substitutions.GPUExpectedDeviceId(test_config, None), ['device1']) |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 105 | |
| 106 | def testSingleGpuDoubleDimension(self): |
| 107 | test_config = CreateConfigWithGpus( |
| 108 | ['vendor:device1-driver', 'vendor:device2-driver']) |
| 109 | self.assertDeviceIdCorrectness( |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 110 | magic_substitutions.GPUExpectedDeviceId(test_config, None), |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 111 | ['device1', 'device2']) |
| 112 | |
| 113 | def testDoubleGpuSingleDimension(self): |
| 114 | test_config = CreateConfigWithGpus( |
| 115 | ['vendor:device1-driver|vendor:device2-driver']) |
| 116 | self.assertDeviceIdCorrectness( |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 117 | magic_substitutions.GPUExpectedDeviceId(test_config, None), |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 118 | ['device1', 'device2']) |
| 119 | |
| 120 | def testDoubleGpuDoubleDimension(self): |
| 121 | test_config = CreateConfigWithGpus([ |
| 122 | 'vendor:device1-driver|vendor:device2-driver', |
| 123 | 'vendor:device1-driver|vendor:device3-driver' |
| 124 | ]) |
| 125 | self.assertDeviceIdCorrectness( |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 126 | magic_substitutions.GPUExpectedDeviceId(test_config, None), |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 127 | ['device1', 'device2', 'device3']) |
| 128 | |
| 129 | def testNoGpu(self): |
| 130 | self.assertDeviceIdCorrectness( |
| 131 | magic_substitutions.GPUExpectedDeviceId( |
| 132 | {'swarming': { |
| 133 | 'dimension_sets': [{}] |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 134 | }}, None), ['0']) |
Brian Sheedy | b18cb76 | 2020-06-30 00:09:29 | [diff] [blame] | 135 | |
| 136 | def testNoDimensions(self): |
| 137 | with self.assertRaises(AssertionError): |
Brian Sheedy | 5f173bb | 2021-11-24 00:45:54 | [diff] [blame] | 138 | magic_substitutions.GPUExpectedDeviceId({}, None) |
| 139 | |
| 140 | |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 141 | class GPUParallelJobs(unittest.TestCase): |
| 142 | def testNoOsType(self): |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 143 | test_config = CreateConfigWithGpus(['vendor:device1-driver']) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 144 | with self.assertRaises(AssertionError): |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 145 | magic_substitutions.GPUParallelJobs(test_config, None, {}) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 146 | |
| 147 | def testParallelJobs(self): |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 148 | test_config = CreateConfigWithGpus(['vendor:device1-driver']) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 149 | for os_type in ['lacros', 'linux', 'mac', 'win']: |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 150 | retval = magic_substitutions.GPUParallelJobs(test_config, None, |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 151 | {'os_type': os_type}) |
| 152 | self.assertEqual(retval, ['--jobs=4']) |
| 153 | |
| 154 | def testSerialJobs(self): |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 155 | test_config = CreateConfigWithGpus(['vendor:device1-driver']) |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 156 | for os_type in ['android', 'chromeos', 'fuchsia']: |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 157 | retval = magic_substitutions.GPUParallelJobs(test_config, None, |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 158 | {'os_type': os_type}) |
| 159 | self.assertEqual(retval, ['--jobs=1']) |
| 160 | |
Austin Eng | 479701f | 2022-08-19 13:32:50 | [diff] [blame^] | 161 | def testWebGPUCTSWindowsIntelSerialJobs(self): |
| 162 | intel_config = CreateConfigWithGpus(['8086:device1-driver']) |
| 163 | nvidia_config = CreateConfigWithGpus(['10de:device1-driver']) |
| 164 | |
| 165 | for gpu_config in [intel_config, nvidia_config]: |
| 166 | for name, telemetry_test_name in [('webgpu_cts', None), |
| 167 | (None, 'webgpu_cts')]: |
| 168 | is_intel = intel_config == gpu_config |
| 169 | c = gpu_config.copy() |
| 170 | if name: |
| 171 | c['name'] = name |
| 172 | if telemetry_test_name: |
| 173 | c['telemetry_test_name'] = telemetry_test_name |
| 174 | for os_type in ['lacros', 'linux', 'mac', 'win']: |
| 175 | retval = magic_substitutions.GPUParallelJobs(c, None, |
| 176 | {'os_type': os_type}) |
| 177 | if is_intel and os_type == 'win': |
| 178 | self.assertEqual(retval, ['--jobs=1']) |
| 179 | else: |
| 180 | self.assertEqual(retval, ['--jobs=4']) |
| 181 | |
Brian Sheedy | 910cda8 | 2022-07-19 11:58:34 | [diff] [blame] | 182 | |
Brian Sheedy | a31578e | 2020-05-18 20:24:36 | [diff] [blame] | 183 | if __name__ == '__main__': |
| 184 | unittest.main() |