Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9040400 authored by Ricky Niu's avatar Ricky Niu Committed by Chien Kun Niu
Browse files

Implement VTS for resetUsbPort and notifyResetUsbPort



Because resetUSBPort API will disconnect the device,
disabled the test for temporary.

Write another VTS on the host side.
Create the b/216387845 to trace.

Bug: 197300598
Test: atest VtsAidlUsbTargetTest

Signed-off-by: default avatarRicky Niu <rickyniu@google.com>
Change-Id: I17d66c2e9ec55b4ebd9edbb153b7f6bd7166d847
parent 45131a73
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
@@ -150,6 +150,17 @@ class UsbAidlTest : public testing::TestWithParam<std::string> {
      parent_.notify();
      return ScopedAStatus::ok();
    }

    // Callback method for the status of resetUsbPortStatus operation
    ScopedAStatus notifyResetUsbPortStatus(const string& /*portName*/, Status /*retval*/,
                                        int64_t transactionId) override {
      ALOGI("enter notifyResetUsbPortStatus");
      parent_.last_transactionId = transactionId;
      parent_.usb_last_cookie = cookie;
      parent_.reset_usb_port_done = true;
      parent_.notify();
      return ScopedAStatus::ok();
    }
  };

  virtual void SetUp() override {
@@ -223,6 +234,9 @@ class UsbAidlTest : public testing::TestWithParam<std::string> {
  // Flag to indicate the invocation of notifyLimitPowerTransferStatus callback.
  bool limit_power_transfer_done;

  // Flag to indicate the invocation of notifyResetUsbPort callback.
  bool reset_usb_port_done;

  // Stores the cookie of the last invoked usb callback object.
  int usb_last_cookie;

@@ -509,6 +523,43 @@ TEST_P(UsbAidlTest, limitPowerTransfer) {
  ALOGI("UsbAidlTest limitPowerTransfer end");
}

/*
 * Test reset Usb data of the port.
 * Test case queries the usb ports present in device.
 * If there is at least one usb port, reset Usb data for the port.
 * The callback parameters are checked to see if transaction id
 * matches.
 */
TEST_P(UsbAidlTest, DISABLED_resetUsbPort) {
  ALOGI("UsbAidlTest resetUsbPort start");
  int64_t transactionId = rand() % 10000;
  const auto& ret = usb->queryPortStatus(transactionId);
  ASSERT_TRUE(ret.isOk());
  EXPECT_EQ(std::cv_status::no_timeout, wait());
  EXPECT_EQ(2, usb_last_cookie);
  EXPECT_EQ(transactionId, last_transactionId);

  if (!usb_last_port_status.portName.empty()) {
    ALOGI("portname:%s", usb_last_port_status.portName.c_str());
    reset_usb_port_done = false;
    transactionId = rand() % 10000;
    const auto& ret = usb->resetUsbPort(usb_last_port_status.portName, transactionId);
    ASSERT_TRUE(ret.isOk());
    ALOGI("UsbAidlTest resetUsbPort ret.isOk");

    std::cv_status waitStatus = wait();
    while (waitStatus == std::cv_status::no_timeout &&
           reset_usb_port_done == false)
      waitStatus = wait();

    ALOGI("UsbAidlTest resetUsbPort wait()");
    EXPECT_EQ(std::cv_status::no_timeout, waitStatus);
    EXPECT_EQ(2, usb_last_cookie);
    EXPECT_EQ(transactionId, last_transactionId);
  }
  ALOGI("UsbAidlTest resetUsbPort end");
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(UsbAidlTest);
INSTANTIATE_TEST_SUITE_P(
        PerInstance, UsbAidlTest,