Merge "Make sure VTS retry the unaltered fingeprint"
diff --git a/harnesses/tradefed/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelper.java b/harnesses/tradefed/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelper.java
index c573b1c..ff18af7 100644
--- a/harnesses/tradefed/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelper.java
+++ b/harnesses/tradefed/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelper.java
@@ -62,8 +62,10 @@
         String currentVendorFingerprint = device.getProperty("ro.vendor.build.fingerprint");
         if (!oldVendorFingerprint.equals(currentVendorFingerprint)) {
             throw new IllegalArgumentException(
-                    String.format("Device vendor fingerprint must match %s to retry session %d",
-                            oldVendorFingerprint, mSessionId));
+                    String.format("Device vendor fingerprint must match %s to retry session %d. "
+                                    + "Found %s instead on %s",
+                            oldVendorFingerprint, mSessionId, currentVendorFingerprint,
+                            device.getSerialNumber()));
         }
     }
 }
diff --git a/harnesses/tradefed/tests/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelperTest.java b/harnesses/tradefed/tests/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelperTest.java
index 940b330..c891c1e 100644
--- a/harnesses/tradefed/tests/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelperTest.java
+++ b/harnesses/tradefed/tests/src/com/android/compatibility/common/tradefed/util/VtsRetryFilterHelperTest.java
@@ -80,6 +80,7 @@
         ITestDevice mockDevice = EasyMock.createMock(ITestDevice.class);
         EasyMock.expect(mockDevice.getProperty(VENDOR_FINGERPRINT_PROPERTY))
                 .andReturn(vendorFingerprint);
+        EasyMock.expect(mockDevice.getSerialNumber()).andStubReturn("serial");
         EasyMock.replay(mockDevice);
         return mockDevice;
     }
diff --git a/runners/host/base_test.py b/runners/host/base_test.py
index 0ff7fa4..17b1562 100644
--- a/runners/host/base_test.py
+++ b/runners/host/base_test.py
@@ -56,7 +56,7 @@
 STR_TEST = "test"
 STR_GENERATE = "generate"
 TIMEOUT_SECS_LOG_UPLOADING = 60
-TIMEOUT_SECS_TEARDOWN_CLASS = 30
+TIMEOUT_SECS_TEARDOWN_CLASS = 120
 _REPORT_MESSAGE_FILE_NAME = "report_proto.msg"
 _BUG_REPORT_FILE_PREFIX = "bugreport_"
 _BUG_REPORT_FILE_EXTENSION = ".zip"
diff --git a/testcases/host/fastboot/VtsFastbootVerification.py b/testcases/host/fastboot/VtsFastbootVerification.py
index 8f680fe..db60ffc 100644
--- a/testcases/host/fastboot/VtsFastbootVerification.py
+++ b/testcases/host/fastboot/VtsFastbootVerification.py
@@ -30,34 +30,59 @@
     """Verifies userspace fastboot implementation."""
 
     def setUpClass(self):
-        """Initializes the DUT and places devices into fastboot mode."""
+        """Initializes the DUT and places devices into fastboot mode.
+
+        Attributes:
+            gtest_bin_path: Path to the fuzzy_fastboot gtest binary
+        """
         self.dut = self.android_devices[0]
         self.shell = self.dut.shell
+        self.gtest_bin_path = os.path.join("host", "nativetest64", "fuzzy_fastboot",
+                                           "fuzzy_fastboot")
         if self.dut.getProp(PROPERTY_LOGICAL_PARTITIONS) != "true":
             self.skipAllTests("Device does not support userspace fastboot")
         else:
             self.dut.cleanUp()
-            self.shell.Execute("reboot fastboot")
+            self.dut.adb.reboot_fastboot()
+            # The below command blocks until the device enters fastbootd mode to
+            # ensure that the device is in fastbootd mode when setUpClass exits.
+            # If this is not done, VTS self-diagnosis tries to recover the
+            # device.
+            self.dut.fastboot.getvar("is-userspace")
 
-    def testFastbootdImplementation(self):
-        """Runs fuzzy_fastboot to verify fastboot implementation."""
-        fastboot_gtest_bin_path = os.path.join(
-            "host", "nativetest64", "fuzzy_fastboot", "fuzzy_fastboot")
-        fastboot_gtest_cmd = [
-            "%s" % fastboot_gtest_bin_path, "--gtest_filter=Conformance*"
+    def testFastbootdSlotOperations(self):
+        """Runs fuzzy_fastboot gtest to verify slot operations in fastbootd implementation."""
+        # Test slot operations and getvar partition-type
+        fastboot_gtest_cmd_slot_operations = [
+            "%s" % self.gtest_bin_path, "--gtest_filter=Conformance.Slots:Conformance.SetActive"
         ]
-        #TODO(b/117181762): Add a serial number argument to fuzzy_fastboot.
-        retcode = subprocess.call(fastboot_gtest_cmd)
-        asserts.assertTrue(retcode == 0, "Fastboot implementation has errors")
+        # TODO(b/117181762): Add a serial number argument to fuzzy_fastboot.
+        retcode = subprocess.call(fastboot_gtest_cmd_slot_operations)
+        asserts.assertTrue(retcode == 0, "Incorrect slot operations")
+
+    def testLogicalPartitionCommands(self):
+        """Runs fuzzy_fastboot to verify getvar commands related to logical partitions."""
+        fastboot_gtest_cmd_logical_partition_compliance = [
+            "%s" % self.gtest_bin_path,
+            "--gtest_filter=LogicalPartitionCompliance.GetVarIsLogical:LogicalPartitionCompliance.SuperPartition"
+        ]
+        retcode = subprocess.call(fastboot_gtest_cmd_logical_partition_compliance)
+        asserts.assertTrue(retcode == 0, "Error in logical partition operations")
+
+    def testFastbootReboot(self):
+        """Runs fuzzy_fastboot to verify the commands to reboot into fastbootd and bootloader."""
+        fastboot_gtest_cmd_reboot_test = [
+            "%s" % self.gtest_bin_path,
+            "--gtest_filter=LogicalPartitionCompliance.FastbootRebootTest"
+        ]
+        retcode = subprocess.call(fastboot_gtest_cmd_reboot_test)
+        asserts.assertTrue(retcode == 0, "Error in fastbootd reboot test")
 
     def tearDownClass(self):
         """Reboot to Android."""
-        if self.isSkipAllTests():
-            return
         if self.dut.isBootloaderMode:
             self.dut.reboot()
             self.dut.waitForBootCompletion()
 
-
 if __name__ == "__main__":
     test_runner.main()
diff --git a/testcases/host/verify_boot_header/VtsFirmwareBootHeaderVerification.py b/testcases/host/verify_boot_header/VtsFirmwareBootHeaderVerification.py
index e7204b7..d823cca 100644
--- a/testcases/host/verify_boot_header/VtsFirmwareBootHeaderVerification.py
+++ b/testcases/host/verify_boot_header/VtsFirmwareBootHeaderVerification.py
@@ -47,6 +47,7 @@
         self.shell = self.dut.shell
         self.adb = self.dut.adb
         self.temp_dir = tempfile.mkdtemp()
+        self.launch_api_level = self.dut.getLaunchApiLevel()
         logging.info("Create %s", self.temp_dir)
         self.slot_suffix = self.dut.getProp(PROPERTY_SLOT_SUFFIX)
         if self.slot_suffix is None:
@@ -76,9 +77,14 @@
                 image_file.read(8)  # read boot magic
                 host_image_header_version = unpack("10I",
                                                    image_file.read(10 * 4))[8]
-                asserts.assertEqual(
-                    host_image_header_version, 1,
-                    "Device does not have boot image of version 1")
+                if (self.launch_api_level > api.PLATFORM_API_LEVEL_P):
+                    asserts.assertTrue(
+                        host_image_header_version >= 2,
+                        "Device must atleast have a boot image of version 2")
+                else:
+                    asserts.assertTrue(
+                        host_image_header_version >= 1,
+                        "Device must atleast have a boot image of version 1")
                 image_file.seek(BOOT_HEADER_DTBO_SIZE_OFFSET)
                 recovery_dtbo_size = unpack("I", image_file.read(4))[0]
                 image_file.read(8)  # ignore recovery dtbo load address
@@ -88,6 +94,10 @@
                         "recovery partition for non-A/B devices must contain the recovery DTBO"
                     )
                 boot_header_size = unpack("I", image_file.read(4))[0]
+                if (host_image_header_version > 1):
+                    dtb_size = unpack("I", image_file.read(4))[0]
+                    asserts.assertNotEqual(dtb_size, 0, "Boot/recovery image must contain DTB")
+                    image_file.read(8)  # ignore DTB physical load address
                 expected_header_size = image_file.tell()
                 asserts.assertEqual(
                     boot_header_size, expected_header_size,
diff --git a/tools/build/tasks/list/vts_test_bin_package_list.mk b/tools/build/tasks/list/vts_test_bin_package_list.mk
index c31748d..ef2af39 100644
--- a/tools/build/tasks/list/vts_test_bin_package_list.mk
+++ b/tools/build/tasks/list/vts_test_bin_package_list.mk
@@ -59,6 +59,7 @@
 vts_test_bin_packages += \
     dt_early_mount_test \
     kernel_net_tests \
+    vts_kernel_loopconfig_test \
     vts_kernel_tun_test \
     vts_kernel_toolchain \
     vts_meminfo_test \
@@ -93,3 +94,12 @@
 # libpower tests
 vts_test_bin_packages += \
     libpower_test
+
+# libprocessgroup JSON schema tests
+vts_test_bin_packages += \
+    vts_processgroup_validate_test \
+
+# configfile as API tests
+vts_test_bin_packages += \
+    vts_compatibilityMatrix_validate_test \
+    vts_halManifest_validate_test \
diff --git a/tools/build/tasks/list/vts_test_host_bin_package_list.mk b/tools/build/tasks/list/vts_test_host_bin_package_list.mk
index b586208..016eaa1 100644
--- a/tools/build/tasks/list/vts_test_host_bin_package_list.mk
+++ b/tools/build/tasks/list/vts_test_host_bin_package_list.mk
@@ -8,3 +8,4 @@
 vts_test_host_bin_packages += \
     mkdtboimg.py \
     fuzzy_fastboot \
+    fastboot \
diff --git a/tools/build/tasks/vts_package.mk b/tools/build/tasks/vts_package.mk
index 42cfb70..80d33ef 100644
--- a/tools/build/tasks/vts_package.mk
+++ b/tools/build/tasks/vts_package.mk
@@ -187,6 +187,10 @@
 VTF_TOOLS_OUT := $(VTF_OUT_ROOT)/android-vts/tools
 VTF_EXTRA_SCRIPTS :=
 
+xsd_config_files := \
+  system/libvintf/xsd/compatibilityMatrix/compatibility_matrix.xsd:$(VTS_TESTCASES_OUT)/DATA/etc/compatibility_matrix.xsd \
+  system/libvintf/xsd/halManifest/hal_manifest.xsd:$(VTS_TESTCASES_OUT)/DATA/etc/hal_manifest.xsd
+
 include $(LOCAL_PATH)/framework/vtf_package.mk
 
 # finally back to the rules for VTS (Vendor Test Suite) packages
@@ -204,6 +208,7 @@
   $(call copy-many-files,$(kernel_rootdir_test_rc_copy_pairs)) \
   $(call copy-many-files,$(acts_testcases_copy_pairs)) \
   $(call copy-many-files,$(system_property_compatibility_test_res_copy_pairs)) \
+  $(call copy-many-files,$(xsd_config_files)) \
   $(VTS_TESTCASES_OUT)/vts/testcases/vndk/golden/platform_vndk_version.txt \
   $(vts_hidl_hals_dump) \
 
diff --git a/utils/python/controllers/android_device.py b/utils/python/controllers/android_device.py
index 1d72f6d..a856c6a 100644
--- a/utils/python/controllers/android_device.py
+++ b/utils/python/controllers/android_device.py
@@ -1185,6 +1185,9 @@
             if self.serial in list_adb_devices():
                 self.log.error(
                     "Device is in adb devices, but is not responding!")
+            elif self.isBootloaderMode:
+                self.log.info("Device is in bootloader/fastbootd mode")
+                return True
             else:
                 self.log.error("Device is not in adb devices!")
             self.fatal_error = True