Add VintfObjectRecoveryTest.

This tests compatibility check in recovery and primarily
make sure mounting works correctly. It does not, however,
check selinux permissions of the 'recovery' binary.
Test: run it

Change-Id: Iffdebb09c7920f103f9c8a84e9cdff0a5434d880
diff --git a/test/Android.bp b/test/Android.bp
index 2246c12..9682be0 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -82,3 +82,31 @@
         },
     }
 }
+
+// run this with: ./vintf_object_recovery_test.sh
+cc_test {
+    name: "vintf_object_recovery_test",
+    defaults: ["libvintf-defaults"],
+
+    static_libs: [
+        "libvintf_recovery",
+        "libvintf",
+        "libhidl-gen-utils",
+        "libfs_mgr",
+        "libgtest",
+        "libbase",
+        "liblog",
+        "libselinux",
+        "libtinyxml2",
+        "libz",
+    ],
+
+    cflags: [
+        "-O0",
+        "-g",
+    ],
+
+    srcs: [
+        "VintfObjectRecoveryTest.cpp",
+    ],
+}
diff --git a/test/VintfObjectRecoveryTest.cpp b/test/VintfObjectRecoveryTest.cpp
new file mode 100644
index 0000000..d7a4367
--- /dev/null
+++ b/test/VintfObjectRecoveryTest.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <android-base/logging.h>
+#include <vintf/VintfObjectRecovery.h>
+
+namespace android {
+namespace vintf {
+
+struct VintfObjectRecoveryTest : public ::testing::Test {};
+
+TEST_F(VintfObjectRecoveryTest, LoadAllVintf) {
+    std::string error;
+    ASSERT_EQ(COMPATIBLE, VintfObjectRecovery::CheckCompatibility({}, &error)) << error;
+
+    ASSERT_EQ(COMPATIBLE, VintfObjectRecovery::CheckCompatibility({}, &error))
+        << "Second CheckCompatibility call should still be successful because all "
+        << "partitions should already be mounted, but error: " << error;
+}
+
+}  // namespace vintf
+}  // namespace android
+
+int main(int argc, char** argv) {
+    // There is no logcat in recovery.
+    android::base::SetLogger(android::base::StderrLogger);
+
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}
diff --git a/test/vintf_object_recovery_test.sh b/test/vintf_object_recovery_test.sh
new file mode 100755
index 0000000..7918c5f
--- /dev/null
+++ b/test/vintf_object_recovery_test.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -ex
+
+if [[ "$@" != *"--no-reboot"* ]]; then
+    adb reboot recovery
+    echo "Waiting for device to boot into recovery..."
+    adb wait-for-recovery
+fi
+adb root
+adb wait-for-recovery
+
+# There is no /data in recovery unless mounted.
+# Push test to /system directory in the recovery ramdisk
+adb push ${ANDROID_PRODUCT_OUT}/data/nativetest64/vintf_object_recovery_test/vintf_object_recovery_test \
+       /system/bin/vintf_object_recovery_test
+
+adb shell /system/bin/vintf_object_recovery_test