Merge "avb: move error module to libavb" into main
diff --git a/compos/tests/java/android/compos/test/ComposTestCase.java b/compos/tests/java/android/compos/test/ComposTestCase.java
index 4851321..bd011fa 100644
--- a/compos/tests/java/android/compos/test/ComposTestCase.java
+++ b/compos/tests/java/android/compos/test/ComposTestCase.java
@@ -116,13 +116,13 @@
 
     @Test
     public void testOdrefreshSpeed() throws Exception {
-        getDevice().setProperty(SYSTEM_SERVER_COMPILER_FILTER_PROP_NAME, "speed");
+        setPropertyOrThrow(getDevice(), SYSTEM_SERVER_COMPILER_FILTER_PROP_NAME, "speed");
         testOdrefresh();
     }
 
     @Test
     public void testOdrefreshSpeedProfile() throws Exception {
-        getDevice().setProperty(SYSTEM_SERVER_COMPILER_FILTER_PROP_NAME, "speed-profile");
+        setPropertyOrThrow(getDevice(), SYSTEM_SERVER_COMPILER_FILTER_PROP_NAME, "speed-profile");
         testOdrefresh();
     }
 
diff --git a/microdroid_manager/src/main.rs b/microdroid_manager/src/main.rs
index a48d540..5a5b34a 100644
--- a/microdroid_manager/src/main.rs
+++ b/microdroid_manager/src/main.rs
@@ -341,7 +341,9 @@
     let mut file = match File::open(path) {
         Ok(dp) => dp,
         Err(e) => {
-            info!("{e:?}. Assumes <0>");
+            info!(
+                "Assumes that debug policy is disabled because failed to read debug policy ({e:?})"
+            );
             return Ok(Some(false));
         }
     };
diff --git a/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java b/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java
index 98327a9..937fbee 100644
--- a/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java
+++ b/tests/hostside/helper/java/com/android/microdroid/test/host/MicrodroidHostTestCaseBase.java
@@ -112,6 +112,13 @@
         LogArchiver.archiveLogThenDelete(logs, device, remotePath, localName);
     }
 
+    public static void setPropertyOrThrow(ITestDevice device, String propertyName, String value)
+            throws DeviceNotAvailableException {
+        if (!device.setProperty(propertyName, value)) {
+            throw new RuntimeException("Failed to set sysprop " + propertyName + " to " + value);
+        }
+    }
+
     // Run an arbitrary command in the host side and returns the result.
     // Note failure is not an error.
     public static String tryRunOnHost(String... cmd) {
diff --git a/tests/hostside/java/com/android/microdroid/test/DebugPolicyHostTests.java b/tests/hostside/java/com/android/microdroid/test/DebugPolicyHostTests.java
index 9cf28c7..ffeae09 100644
--- a/tests/hostside/java/com/android/microdroid/test/DebugPolicyHostTests.java
+++ b/tests/hostside/java/com/android/microdroid/test/DebugPolicyHostTests.java
@@ -130,8 +130,8 @@
         // or tryLaunchProtectedNonDebuggableVm().
         mCustomPvmfwBinFileOnHost =
                 FileUtil.createTempFile(CUSTOM_PVMFW_FILE_PREFIX, CUSTOM_PVMFW_FILE_SUFFIX);
-        mAndroidDevice.setProperty(CUSTOM_PVMFW_IMG_PATH_PROP, CUSTOM_PVMFW_IMG_PATH);
-        mAndroidDevice.setProperty(CUSTOM_DEBUG_POLICY_PATH_PROP, CUSTOM_DEBUG_POLICY_PATH);
+        setPropertyOrThrow(mAndroidDevice, CUSTOM_PVMFW_IMG_PATH_PROP, CUSTOM_PVMFW_IMG_PATH);
+        setPropertyOrThrow(mAndroidDevice, CUSTOM_DEBUG_POLICY_PATH_PROP, CUSTOM_DEBUG_POLICY_PATH);
 
         // Prepare for launching microdroid
         mAndroidDevice.installPackage(findTestFile(PACKAGE_FILE_NAME), /* reinstall */ false);
@@ -151,8 +151,8 @@
         mAndroidDevice.uninstallPackage(PACKAGE_NAME);
 
         // Cleanup for custom debug policies
-        mAndroidDevice.setProperty(CUSTOM_DEBUG_POLICY_PATH_PROP, "");
-        mAndroidDevice.setProperty(CUSTOM_PVMFW_IMG_PATH_PROP, "");
+        setPropertyOrThrow(mAndroidDevice, CUSTOM_DEBUG_POLICY_PATH_PROP, "");
+        setPropertyOrThrow(mAndroidDevice, CUSTOM_PVMFW_IMG_PATH_PROP, "");
         FileUtil.deleteFile(mCustomPvmfwBinFileOnHost);
 
         cleanUpVirtualizationTestSetup(mAndroidDevice);
diff --git a/tests/hostside/java/com/android/microdroid/test/PvmfwImgTest.java b/tests/hostside/java/com/android/microdroid/test/PvmfwImgTest.java
index 320b722..fa5ef1e 100644
--- a/tests/hostside/java/com/android/microdroid/test/PvmfwImgTest.java
+++ b/tests/hostside/java/com/android/microdroid/test/PvmfwImgTest.java
@@ -42,6 +42,8 @@
 import org.junit.runner.RunWith;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
 
 /** Tests pvmfw.img and pvmfw */
@@ -93,7 +95,7 @@
         // when launching with launchProtectedVmAndWaitForBootCompleted().
         mCustomPvmfwBinFileOnHost =
                 FileUtil.createTempFile(CUSTOM_PVMFW_FILE_PREFIX, CUSTOM_PVMFW_FILE_SUFFIX);
-        mAndroidDevice.setProperty(CUSTOM_PVMFW_IMG_PATH_PROP, CUSTOM_PVMFW_IMG_PATH);
+        setPropertyOrThrow(mAndroidDevice, CUSTOM_PVMFW_IMG_PATH_PROP, CUSTOM_PVMFW_IMG_PATH);
 
         // Prepare for launching microdroid
         mAndroidDevice.installPackage(findTestFile(PACKAGE_FILE_NAME), /* reinstall */ false);
@@ -113,7 +115,7 @@
         mAndroidDevice.uninstallPackage(PACKAGE_NAME);
 
         // Cleanup for custom pvmfw.img
-        mAndroidDevice.setProperty(CUSTOM_PVMFW_IMG_PATH_PROP, "");
+        setPropertyOrThrow(mAndroidDevice, CUSTOM_PVMFW_IMG_PATH_PROP, "");
         FileUtil.deleteFile(mCustomPvmfwBinFileOnHost);
 
         cleanUpVirtualizationTestSetup(mAndroidDevice);
@@ -141,15 +143,34 @@
 
     @Test
     public void testInvalidConfigVersion_doesNotBoot() throws Exception {
-        // Disclaimer: Update versions when it becomes valid
-        Pvmfw pvmfw =
-                new Pvmfw.Builder(mPvmfwBinFileOnHost, mBccFileOnHost).setVersion(2, 0).build();
-        pvmfw.serialize(mCustomPvmfwBinFileOnHost);
+        // Disclaimer: Update versions when they become valid
+        List<int[]> invalid_versions =
+                Arrays.asList(
+                        new int[] {0, 0},
+                        new int[] {0, 1},
+                        new int[] {0, 0xFFFF},
+                        new int[] {2, 0},
+                        new int[] {2, 1},
+                        new int[] {2, 0xFFFF},
+                        new int[] {0xFFFF, 0},
+                        new int[] {0xFFFF, 1},
+                        new int[] {0xFFFF, 0xFFFF});
 
-        assertThrows(
-                "pvmfw shouldn't boot with invalid version",
-                DeviceRuntimeException.class,
-                () -> launchProtectedVmAndWaitForBootCompleted(BOOT_FAILURE_WAIT_TIME_MS));
+        Pvmfw.Builder builder = new Pvmfw.Builder(mPvmfwBinFileOnHost, mBccFileOnHost);
+
+        for (int[] pair : invalid_versions) {
+            int major = pair[0];
+            int minor = pair[1];
+            String version = "v" + major + "." + minor;
+
+            Pvmfw pvmfw = builder.setVersion(major, minor).build();
+            pvmfw.serialize(mCustomPvmfwBinFileOnHost);
+
+            assertThrows(
+                    "pvmfw shouldn't boot with invalid version " + version,
+                    DeviceRuntimeException.class,
+                    () -> launchProtectedVmAndWaitForBootCompleted(BOOT_FAILURE_WAIT_TIME_MS));
+        }
     }
 
     private ITestDevice launchProtectedVmAndWaitForBootCompleted(long adbTimeoutMs)