Merge "[vts-core] add VtsHalUsbV1_1TargetTest to vts-core"

am: 6c9fea5040

Change-Id: Icd2feaaa864437baf661ca351757bed8edfe8177
This commit is contained in:
nelsonli 2019-12-11 19:06:21 -08:00 committed by android-build-merger
commit 8aa2fcf9b4
2 changed files with 12 additions and 29 deletions

View file

@ -22,6 +22,6 @@ cc_test {
"android.hardware.usb@1.0",
"android.hardware.usb@1.1",
],
test_suites: ["general-tests"],
test_suites: ["general-tests", "vts-core"],
}

View file

@ -23,8 +23,9 @@
#include <android/hardware/usb/1.1/types.h>
#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <log/log.h>
#include <stdlib.h>
#include <chrono>
@ -114,25 +115,12 @@ class UsbCallback : public ::testing::VtsHalHidlTargetCallbackBase<UsbClientCall
};
};
// 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 {
class UsbHidlTest : public ::testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
ALOGI(__FUNCTION__);
usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>(
UsbHidlEnvironment::Instance()->getServiceName<IUsb>());
usb = IUsb::getService(GetParam());
ASSERT_NE(usb, nullptr);
usb_cb_2 = new UsbCallback(2);
@ -158,7 +146,7 @@ class UsbHidlTest : public ::testing::VtsHalHidlTargetTestBase {
* Callback oject is created and registered.
* Check to see if the hidl transaction succeeded.
*/
TEST_F(UsbHidlTest, setCallback) {
TEST_P(UsbHidlTest, setCallback) {
usb_cb_1 = new UsbCallback(1);
ASSERT_NE(usb_cb_1, nullptr);
Return<void> ret = usb->setCallback(usb_cb_1);
@ -171,7 +159,7 @@ TEST_F(UsbHidlTest, setCallback) {
* HAL service should call notifyPortStatusChange_1_1
* instead of notifyPortStatusChange of V1_0 interface
*/
TEST_F(UsbHidlTest, queryPortStatus) {
TEST_P(UsbHidlTest, queryPortStatus) {
Return<void> ret = usb->queryPortStatus();
ASSERT_TRUE(ret.isOk());
auto res = usb_cb_2->WaitForCallback(kCallbackNameNotifyPortStatusChange_1_1);
@ -181,12 +169,7 @@ TEST_F(UsbHidlTest, queryPortStatus) {
EXPECT_EQ(PortMode::NONE, res.args->usb_last_port_status.status.supportedModes);
EXPECT_EQ(Status::SUCCESS, res.args->usb_last_status);
}
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;
}
INSTANTIATE_TEST_SUITE_P(
PerInstance, UsbHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IUsb::descriptor)),
android::hardware::PrintInstanceNameToString);