graphics: make mapper VTS utils more reusable
Better include path (#include <mapper-vts/2.0/MapperVts.h>), better
library naming, and move GraphicsMapperHidlEnvironment to where
tests are defined.
Test: VTS
Change-Id: I9fbf6515993ac11852b11ca6b8194a58afe5579a
diff --git a/graphics/mapper/2.0/utils/vts/Android.bp b/graphics/mapper/2.0/utils/vts/Android.bp
index 8bca152..1aa3185 100644
--- a/graphics/mapper/2.0/utils/vts/Android.bp
+++ b/graphics/mapper/2.0/utils/vts/Android.bp
@@ -15,9 +15,9 @@
//
cc_library_static {
- name: "libVtsHalGraphicsMapperTestUtils",
+ name: "android.hardware.graphics.mapper@2.0-vts",
defaults: ["hidl_defaults"],
- srcs: ["VtsHalGraphicsMapperTestUtils.cpp"],
+ srcs: ["MapperVts.cpp"],
cflags: [
"-O0",
"-g",
@@ -34,5 +34,5 @@
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.mapper@2.0",
],
- export_include_dirs: ["."],
+ export_include_dirs: ["include"],
}
diff --git a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.cpp b/graphics/mapper/2.0/utils/vts/MapperVts.cpp
similarity index 95%
rename from graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.cpp
rename to graphics/mapper/2.0/utils/vts/MapperVts.cpp
index e3229ca..d08ac56 100644
--- a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.cpp
+++ b/graphics/mapper/2.0/utils/vts/MapperVts.cpp
@@ -14,28 +14,26 @@
* limitations under the License.
*/
-#include <VtsHalHidlTargetTestBase.h>
+#include <mapper-vts/2.0/MapperVts.h>
-#include "VtsHalGraphicsMapperTestUtils.h"
+#include <VtsHalHidlTargetTestBase.h>
namespace android {
namespace hardware {
namespace graphics {
namespace mapper {
namespace V2_0 {
-namespace tests {
+namespace vts {
-Gralloc::Gralloc() {
- init();
+Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
+ init(allocatorServiceName, mapperServiceName);
}
-void Gralloc::init() {
- mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(
- GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>());
+void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
+ mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName);
ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
- mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(
- GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>());
+ mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(mapperServiceName);
ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
}
@@ -240,7 +238,7 @@
return releaseFence;
}
-} // namespace tests
+} // namespace vts
} // namespace V2_0
} // namespace mapper
} // namespace graphics
diff --git a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.h b/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h
similarity index 80%
rename from graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.h
rename to graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h
index 1f7d88a..6c2c9a6 100644
--- a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.h
+++ b/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#ifndef VTS_HAL_GRAPHICS_MAPPER_UTILS
-#define VTS_HAL_GRAPHICS_MAPPER_UTILS
+#pragma once
+#include <string>
#include <unordered_set>
+#include <vector>
-#include <VtsHalHidlTargetTestEnvBase.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <utils/StrongPointer.h>
@@ -29,14 +29,15 @@
namespace graphics {
namespace mapper {
namespace V2_0 {
-namespace tests {
+namespace vts {
using android::hardware::graphics::allocator::V2_0::IAllocator;
// A wrapper to IAllocator and IMapper.
class Gralloc {
public:
- Gralloc();
+ Gralloc(const std::string& allocatorServiceName = "default",
+ const std::string& mapperServiceName = "default");
~Gralloc();
// IAllocator methods
@@ -73,7 +74,7 @@
int unlock(const native_handle_t* bufferHandle);
private:
- void init();
+ void init(const std::string& allocatorServiceName, const std::string& mapperServiceName);
const native_handle_t* cloneBuffer(const hidl_handle& rawHandle);
sp<IAllocator> mAllocator;
@@ -85,26 +86,9 @@
std::unordered_set<const native_handle_t*> mImportedBuffers;
};
-// Test environment for graphics.mapper.
-class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- // get the test environment singleton
- static GraphicsMapperHidlEnvironment* Instance() {
- static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment;
- return instance;
- }
-
- virtual void registerTestServices() override {
- registerTestService<IAllocator>();
- registerTestService<IMapper>();
- }
-};
-
-} // namespace tests
+} // namespace vts
} // namespace V2_0
} // namespace mapper
} // namespace graphics
} // namespace hardware
} // namespace android
-
-#endif // VTS_HAL_GRAPHICS_MAPPER_UTILS