diff options
| author | 2018-02-23 00:39:19 +0000 | |
|---|---|---|
| committer | 2018-02-23 00:39:19 +0000 | |
| commit | df2ad65036f66979005620683ce11958e415e378 (patch) | |
| tree | dfe030c8137e4831b19bac1873c331d8681d7ace | |
| parent | 68ffcec8e0342315f7b9693aa1fd7f16e48f5842 (diff) | |
| parent | 9b44532d648d88732c6f17820cf6418c025aecae (diff) | |
Merge "Create DvrApiTest to load libdvr.so at runtime and get Dvr API."
| -rw-r--r-- | libs/vr/libdvr/tests/dvr_api_test.h | 38 | ||||
| -rw-r--r-- | libs/vr/libdvr/tests/dvr_buffer_queue-test.cpp | 32 | ||||
| -rw-r--r-- | libs/vr/libdvr/tests/dvr_display-test.cpp | 32 |
3 files changed, 46 insertions, 56 deletions
diff --git a/libs/vr/libdvr/tests/dvr_api_test.h b/libs/vr/libdvr/tests/dvr_api_test.h new file mode 100644 index 0000000000..648af755d0 --- /dev/null +++ b/libs/vr/libdvr/tests/dvr_api_test.h @@ -0,0 +1,38 @@ +#include <dlfcn.h> +#include <dvr/dvr_api.h> + +#include <gtest/gtest.h> + +#define ASSERT_NOT_NULL(x) ASSERT_TRUE((x) != nullptr) + +/** DvrTestBase loads the libdvr.so at runtime and get the Dvr API version 1. */ +class DvrApiTest : public ::testing::Test { + protected: + void SetUp() override { + int flags = RTLD_NOW | RTLD_LOCAL; + + // Here we need to ensure that libdvr is loaded with RTLD_NODELETE flag set + // (so that calls to `dlclose` don't actually unload the library). This is a + // workaround for an Android NDK bug. See more detail: + // https://github.com/android-ndk/ndk/issues/360 + flags |= RTLD_NODELETE; + platform_handle_ = dlopen("libdvr.so", flags); + ASSERT_NOT_NULL(platform_handle_) << "Dvr shared library missing."; + + auto dvr_get_api = reinterpret_cast<decltype(&dvrGetApi)>( + dlsym(platform_handle_, "dvrGetApi")); + ASSERT_NOT_NULL(dvr_get_api) << "Platform library missing dvrGetApi."; + + ASSERT_EQ(dvr_get_api(&api_, sizeof(api_), /*version=*/1), 0) + << "Unable to find compatible Dvr API."; + } + + void TearDown() override { + if (platform_handle_ != nullptr) { + dlclose(platform_handle_); + } + } + + void* platform_handle_ = nullptr; + DvrApi_v1 api_; +}; diff --git a/libs/vr/libdvr/tests/dvr_buffer_queue-test.cpp b/libs/vr/libdvr/tests/dvr_buffer_queue-test.cpp index ea37935a9d..301458a546 100644 --- a/libs/vr/libdvr/tests/dvr_buffer_queue-test.cpp +++ b/libs/vr/libdvr/tests/dvr_buffer_queue-test.cpp @@ -1,6 +1,5 @@ #include <android/log.h> #include <android/native_window.h> -#include <dlfcn.h> #include <dvr/dvr_api.h> #include <dvr/dvr_buffer_queue.h> @@ -9,14 +8,14 @@ #include <array> #include <unordered_map> +#include "dvr_api_test.h" + #define LOG_TAG "dvr_buffer_queue-test" #ifndef ALOGD #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #endif -#define ASSERT_NOT_NULL(x) ASSERT_TRUE((x) != nullptr) - #ifndef ALOGD_IF #define ALOGD_IF(cond, ...) \ ((__predict_false(cond)) ? ((void)ALOGD(__VA_ARGS__)) : (void)0) @@ -31,7 +30,7 @@ static constexpr uint32_t kBufferFormat = AHARDWAREBUFFER_FORMAT_BLOB; static constexpr uint64_t kBufferUsage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN; static constexpr size_t kQueueCapacity = 3; -class DvrBufferQueueTest : public ::testing::Test { +class DvrBufferQueueTest : public DvrApiTest { public: static void BufferAvailableCallback(void* context) { DvrBufferQueueTest* thiz = static_cast<DvrBufferQueueTest*>(context); @@ -44,33 +43,12 @@ class DvrBufferQueueTest : public ::testing::Test { } protected: - void SetUp() override { - int flags = RTLD_NOW | RTLD_LOCAL; - - // Here we need to ensure that libdvr is loaded with RTLD_NODELETE flag set - // (so that calls to `dlclose` don't actually unload the library). This is a - // workaround for an Android NDK bug. See more detail: - // https://github.com/android-ndk/ndk/issues/360 - flags |= RTLD_NODELETE; - platform_handle_ = dlopen("libdvr.so", flags); - ASSERT_NOT_NULL(platform_handle_) << "Dvr shared library missing."; - - auto dvr_get_api = reinterpret_cast<decltype(&dvrGetApi)>( - dlsym(platform_handle_, "dvrGetApi")); - ASSERT_NOT_NULL(dvr_get_api) << "Platform library missing dvrGetApi."; - - ASSERT_EQ(dvr_get_api(&api_, sizeof(api_), /*version=*/1), 0) - << "Unable to find compatible Dvr API."; - } - void TearDown() override { if (write_queue_ != nullptr) { api_.WriteBufferQueueDestroy(write_queue_); write_queue_ = nullptr; } - if (platform_handle_ != nullptr) { - dlclose(platform_handle_); - } + DvrApiTest::TearDown(); } void HandleBufferAvailable() { @@ -87,8 +65,6 @@ class DvrBufferQueueTest : public ::testing::Test { DvrWriteBufferQueue* write_queue_{nullptr}; int buffer_available_count_{0}; int buffer_removed_count_{0}; - void* platform_handle_{nullptr}; - DvrApi_v1 api_{}; }; TEST_F(DvrBufferQueueTest, WriteQueueCreateDestroy) { diff --git a/libs/vr/libdvr/tests/dvr_display-test.cpp b/libs/vr/libdvr/tests/dvr_display-test.cpp index c07b062c70..11655735d9 100644 --- a/libs/vr/libdvr/tests/dvr_display-test.cpp +++ b/libs/vr/libdvr/tests/dvr_display-test.cpp @@ -1,53 +1,29 @@ #include <android/hardware_buffer.h> #include <android/log.h> -#include <dlfcn.h> #include <dvr/dvr_api.h> #include <dvr/dvr_display_types.h> #include <dvr/dvr_surface.h> #include <gtest/gtest.h> +#include "dvr_api_test.h" + #define LOG_TAG "dvr_display-test" #ifndef ALOGD #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #endif -#define ASSERT_NOT_NULL(x) ASSERT_TRUE((x) != nullptr) - -class DvrDisplayTest : public ::testing::Test { +class DvrDisplayTest : public DvrApiTest { protected: - void SetUp() override { - int flags = RTLD_NOW | RTLD_LOCAL; - - // Here we need to ensure that libdvr is loaded with RTLD_NODELETE flag set - // (so that calls to `dlclose` don't actually unload the library). This is a - // workaround for an Android NDK bug. See more detail: - // https://github.com/android-ndk/ndk/issues/360 - flags |= RTLD_NODELETE; - platform_handle_ = dlopen("libdvr.so", flags); - ASSERT_NOT_NULL(platform_handle_) << "Dvr shared library missing."; - - auto dvr_get_api = reinterpret_cast<decltype(&dvrGetApi)>( - dlsym(platform_handle_, "dvrGetApi")); - ASSERT_NOT_NULL(dvr_get_api) << "Platform library missing dvrGetApi."; - - ASSERT_EQ(dvr_get_api(&api_, sizeof(api_), /*version=*/1), 0) - << "Unable to find compatible Dvr API."; - } - void TearDown() override { if (write_queue_ != nullptr) { api_.WriteBufferQueueDestroy(write_queue_); write_queue_ = nullptr; } - if (platform_handle_ != nullptr) { - dlclose(platform_handle_); - } + DvrApiTest::TearDown(); } - void* platform_handle_ = nullptr; - DvrApi_v1 api_; DvrWriteBufferQueue* write_queue_ = nullptr; }; |