Enable swarming's shard config for GPU tests on Skylab

This CL extracts swarming sharding for GPU tests on Skylab,
thus test owners could reuse the existing test config.

As a result, sharding will be enabled on
ChromeOS FYI Release Skylab (jacuzzi).

BUG=1492552
TEST=generate_buildbot_json_unittest.py

Change-Id: Ice022846c0073f64d07f6976cf47e4030abd5c40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4942806
Reviewed-by: Brian Sheedy <[email protected]>
Commit-Queue: Xinan Lin <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1212448}
diff --git a/testing/buildbot/generate_buildbot_json.py b/testing/buildbot/generate_buildbot_json.py
index 16052ba..6b553334 100755
--- a/testing/buildbot/generate_buildbot_json.py
+++ b/testing/buildbot/generate_buildbot_json.py
@@ -46,10 +46,15 @@
 
 
 class GPUTelemetryTestGenerator(BaseGenerator):
-  def __init__(self, bb_gen, is_android_webview=False, is_cast_streaming=False):
+  def __init__(self,
+               bb_gen,
+               is_android_webview=False,
+               is_cast_streaming=False,
+               is_skylab=False):
     super(GPUTelemetryTestGenerator, self).__init__(bb_gen)
     self._is_android_webview = is_android_webview
     self._is_cast_streaming = is_cast_streaming
+    self._is_skylab = is_skylab
 
   def generate(self, waterfall, tester_name, tester_config, input_tests):
     isolated_scripts = []
@@ -60,11 +65,9 @@
         test_config = [test_config]
 
       for config in test_config:
-        test = self.bb_gen.generate_gpu_telemetry_test(waterfall, tester_name,
-                                                       tester_config, test_name,
-                                                       config,
-                                                       self._is_android_webview,
-                                                       self._is_cast_streaming)
+        test = self.bb_gen.generate_gpu_telemetry_test(
+            waterfall, tester_name, tester_config, test_name, config,
+            self._is_android_webview, self._is_cast_streaming, self._is_skylab)
         if test:
           isolated_scripts.append(test)
 
@@ -72,6 +75,10 @@
 
 
 class SkylabGPUTelemetryTestGenerator(GPUTelemetryTestGenerator):
+  def __init__(self, bb_gen):
+    super(SkylabGPUTelemetryTestGenerator, self).__init__(bb_gen,
+                                                          is_skylab=True)
+
   def generate(self, *args, **kwargs):
     # This should be identical to a regular GPU Telemetry test, but with any
     # swarming arguments removed.
@@ -878,7 +885,7 @@
 
   def generate_gpu_telemetry_test(self, waterfall, tester_name, tester_config,
                                   test_name, test_config, is_android_webview,
-                                  is_cast_streaming):
+                                  is_cast_streaming, is_skylab):
     # These are all just specializations of isolated script tests with
     # a bunch of boilerplate command line arguments added.
 
@@ -939,6 +946,11 @@
     # reproduce GC-related bugs in the V8 bindings.
     extra_browser_args.append('--js-flags=--expose-gc')
 
+    # Skylab supports sharding, so reuse swarming's shard config.
+    if is_skylab and 'shards' not in result and test_config.get(
+        'swarming', {}).get('shards'):
+      result['shards'] = test_config['swarming']['shards']
+
     args = [
         test_to_run,
         '--show-stdout',