Move preload test to libhidl_test.

Since hidl_test is completely static now, moving
the DISABLED preload test so that we can actually
test the API here.

Test: libhidl_test
Change-Id: I1e34ddc959d761130cf5b2c0a30fa2e1ec675d99
diff --git a/test_main.cpp b/test_main.cpp
index 2811612..0de46ec 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -17,12 +17,15 @@
 #define LOG_TAG "LibHidlTest"
 
 #include <android-base/logging.h>
-#include <condition_variable>
+#include <android/hardware/tests/inheritance/1.0/IParent.h>
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 #include <hidl/HidlSupport.h>
+#include <hidl/ServiceManagement.h>
 #include <hidl/Status.h>
 #include <hidl/TaskRunner.h>
+#include <condition_variable>
+#include <fstream>
 #include <vector>
 
 #define EXPECT_ARRAYEQ(__a1__, __a2__, __size__) EXPECT_TRUE(isArrayEqual(__a1__, __a2__, __size__))
@@ -46,6 +49,17 @@
     return true;
 }
 
+bool isLibraryOpen(const std::string& lib) {
+    std::ifstream ifs("/proc/self/maps");
+    for (std::string line; std::getline(ifs, line);) {
+        if (line.size() >= lib.size() && line.substr(line.size() - lib.size()) == lib) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 class LibHidlTest : public ::testing::Test {
 public:
     virtual void SetUp() override {
@@ -441,7 +455,17 @@
 
     EXPECT_THAT(toString(Status::fromExceptionCode(Status::EX_NULL_POINTER)),
             HasSubstr("EX_NULL_POINTER"));
+}
 
+TEST_F(LibHidlTest, PreloadTest) {
+    using ::android::hardware::preloadPassthroughService;
+    using ::android::hardware::tests::inheritance::V1_0::IParent;
+
+    static const std::string kLib = "android.hardware.tests.inheritance@1.0-impl.so";
+
+    EXPECT_FALSE(isLibraryOpen(kLib));
+    preloadPassthroughService<IParent>();
+    EXPECT_TRUE(isLibraryOpen(kLib));
 }
 
 int main(int argc, char **argv) {