Convert usb hal test to use VtsHalHidlTargetTestEnvBase
Bug: 64203181
Test: make vts
vts-tradefed run vts -m VtsHalUsbV1_0Target
vts-tradefed run vts -m VtsHalUsbV1_1Target
Change-Id: I49d8af2b53e484cc68fcb72f75f8bfafc6d02f59
diff --git a/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp b/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp
index e01b974..ee7ef1b 100644
--- a/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp
+++ b/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp
@@ -22,6 +22,7 @@
#include <android/hardware/usb/1.0/types.h>
#include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
#include <log/log.h>
#include <stdlib.h>
#include <chrono>
@@ -48,6 +49,18 @@
using ::android::hardware::Void;
using ::android::sp;
+// Test environment for Usb HIDL HAL.
+class UsbHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+ // get the test environment singleton
+ static UsbHidlEnvironment* Instance() {
+ static UsbHidlEnvironment* instance = new UsbHidlEnvironment;
+ return instance;
+ }
+
+ virtual void registerTestServices() override { registerTestService<IUsb>(); }
+};
+
// The main test class for the USB hidl HAL
class UsbHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public:
@@ -96,7 +109,8 @@
virtual void SetUp() override {
ALOGI("Setup");
- usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>();
+ usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>(
+ UsbHidlEnvironment::Instance()->getServiceName<IUsb>());
ASSERT_NE(usb, nullptr);
usb_cb_2 = new UsbCallback(*this, 2);
@@ -343,7 +357,9 @@
}
int main(int argc, char** argv) {
+ ::testing::AddGlobalTestEnvironment(UsbHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
+ UsbHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;