Fix naming issue for matrix compound test suites that have the 'test' key

If the 'test' key is in the definition for a basic test suite, then
that value overrides the mixed compound test suites name.
The name for the suite should be the test suites name plus the
identifier field set in a variants list entry.

Bug: 1041619
Bug: 1109967
Change-Id: I8a44b23d2511d2a5e85c0d06e3047c1d50abf011
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2318305
Commit-Queue: Rakib Hasan <[email protected]>
Reviewed-by: Garrett Beaty <[email protected]>
Cr-Commit-Position: refs/heads/master@{#792036}
diff --git a/testing/buildbot/generate_buildbot_json_unittest.py b/testing/buildbot/generate_buildbot_json_unittest.py
index 27757f9..54c2fc9 100755
--- a/testing/buildbot/generate_buildbot_json_unittest.py
+++ b/testing/buildbot/generate_buildbot_json_unittest.py
@@ -5383,6 +5383,27 @@
 }
 """
 
+MATRIX_COMPOUND_TEST_WITH_TEST_KEY = """\
+{
+  'basic_suites': {
+    'foo_tests': {
+      'swarming_test': {
+          'test': 'foo_test_apk'
+      },
+    }
+  },
+  'matrix_compound_suites': {
+    'matrix_tests': {
+      'foo_tests': {
+        'variants': [
+          'a_variant',
+        ],
+      },
+    },
+  },
+}
+"""
+
 MATRIX_COMPOUND_MIXED_VARIANTS_REF = """\
 {
   'basic_suites': {
@@ -5458,6 +5479,34 @@
 }
 """
 
+MATRIX_COMPOUND_TEST_SUITE_WITH_TEST_KEY_DICT = """\
+{
+  "AAAAA1 AUTOGENERATED FILE DO NOT EDIT": {},
+  "AAAAA2 See generate_buildbot_json.py to make changes": {},
+  "Fake Tester": {
+    "gtest_tests": [
+      {
+        "args": [
+          "--platform",
+          "device",
+          "--version",
+          "1"
+        ],
+        "merge": {
+          "args": [],
+          "script": "//testing/merge_scripts/standard_gtest_merge.py"
+        },
+        "name": "swarming_test_a_variant",
+        "swarming": {
+          "can_use_on_swarming_builders": true
+        },
+        "test": "foo_test_apk"
+      }
+    ]
+  }
+}
+"""
+
 MATRIX_TARGET_DICT_MERGE_OUTPUT_ARGS = """\
 {
   "AAAAA1 AUTOGENERATED FILE DO NOT EDIT": {},
@@ -5807,6 +5856,22 @@
     fbb.check_output_file_consistency(verbose=True)
     self.assertFalse(fbb.printed_lines)
 
+  def test_variant_test_suite_with_test_key(self):
+    """
+    Test targets in matrix compound test suites with variants
+    """
+    fbb = FakeBBGen(self.args,
+                    MATRIX_GTEST_SUITE_WATERFALL,
+                    MATRIX_COMPOUND_TEST_WITH_TEST_KEY,
+                    LUCI_MILO_CFG,
+                    variants=VARIANTS_FILE)
+    self.create_testing_buildbot_json_file(
+        'chromium.test.json', MATRIX_COMPOUND_TEST_SUITE_WITH_TEST_KEY_DICT)
+    self.create_testing_buildbot_json_file(
+        'chromium.ci.json', MATRIX_COMPOUND_TEST_SUITE_WITH_TEST_KEY_DICT)
+    fbb.check_output_file_consistency(verbose=True)
+    self.assertFalse(fbb.printed_lines)
+
   def test_variants_pyl_ref(self):
     """Test targets with variants string ref"""
     fbb = FakeBBGen(self.args,