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

Commit a04877f2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Convert VtsHalNfcV1_*TargetTest to be parameterized test"

parents 6ba951f6 e64262f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,5 +21,5 @@ cc_test {
    static_libs: [
        "android.hardware.nfc@1.0",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}
+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<configuration description="Runs VtsHalNfcV1_0TargetTest.">
    <option name="test-suite-tag" value="apct" />
    <option name="test-suite-tag" value="apct-native" />

    <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer">
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
        <option name="cleanup" value="true" />
        <option name="push" value="VtsHalNfcV1_0TargetTest->/data/local/tmp/VtsHalNfcV1_0TargetTest" />
    </target_preparer>

    <test class="com.android.tradefed.testtype.GTest" >
        <option name="native-test-device-path" value="/data/local/tmp" />
        <option name="module-name" value="VtsHalNfcV1_0TargetTest" />
        <option name="native-test-timeout" value="180000"/>
    </test>
</configuration>
+25 −36
Original line number Diff line number Diff line
@@ -20,11 +20,12 @@
#include <android/hardware/nfc/1.0/INfc.h>
#include <android/hardware/nfc/1.0/INfcClientCallback.h>
#include <android/hardware/nfc/1.0/types.h>
#include <gtest/gtest.h>
#include <hardware/nfc.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>

using ::android::hardware::nfc::V1_0::INfc;
using ::android::hardware::nfc::V1_0::INfcClientCallback;
@@ -94,26 +95,11 @@ class NfcClientCallback
    };
};

// Test environment for Nfc HIDL HAL.
class NfcHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
 public:
  // get the test environment singleton
  static NfcHidlEnvironment* Instance() {
    static NfcHidlEnvironment* instance = new NfcHidlEnvironment;
    return instance;
  }

  virtual void registerTestServices() override { registerTestService<INfc>(); }
 private:
  NfcHidlEnvironment() {}
};

// The main test class for NFC HIDL HAL.
class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class NfcHidlTest : public ::testing::TestWithParam<std::string> {
 public:
  virtual void SetUp() override {
    nfc_ = ::testing::VtsHalHidlTargetTestBase::getService<INfc>(
        NfcHidlEnvironment::Instance()->getServiceName<INfc>());
    nfc_ = INfc::getService(GetParam());
    ASSERT_NE(nfc_, nullptr);

    nfc_cb_ = new NfcClientCallback();
@@ -186,7 +172,7 @@ class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 * Since open and close calls are a part of SetUp() and TearDown(),
 * the function definition is intentionally kept empty
 */
TEST_F(NfcHidlTest, OpenAndClose) {}
TEST_P(NfcHidlTest, OpenAndClose) {}

/*
 * WriteCoreReset:
@@ -194,7 +180,7 @@ TEST_F(NfcHidlTest, OpenAndClose) {}
 * Waits for CORE_RESET_RSP
 * Checks the status, version number and configuration status
 */
TEST_F(NfcHidlTest, WriteCoreReset) {
TEST_P(NfcHidlTest, WriteCoreReset) {
  std::vector<uint8_t> cmd = CORE_RESET_CMD;
  NfcData data = cmd;
  EXPECT_EQ(data.size(), nfc_->write(data));
@@ -229,7 +215,7 @@ TEST_F(NfcHidlTest, WriteCoreReset) {
 * Waits for CORE_RESET_RSP
 * Checks the status, version number and configuration status
 */
TEST_F(NfcHidlTest, WriteCoreResetConfigReset) {
TEST_P(NfcHidlTest, WriteCoreResetConfigReset) {
  std::vector<uint8_t> cmd = CORE_RESET_CMD_CONFIG_RESET;
  NfcData data = cmd;
  EXPECT_EQ(data.size(), nfc_->write(data));
@@ -264,7 +250,7 @@ TEST_F(NfcHidlTest, WriteCoreResetConfigReset) {
 * Waits for response
 * Checks SYNTAX_ERROR status
 */
TEST_F(NfcHidlTest, WriteInvalidCommand) {
TEST_P(NfcHidlTest, WriteInvalidCommand) {
  // Send an Error Command
  std::vector<uint8_t> cmd = INVALID_COMMAND;
  NfcData data = cmd;
@@ -285,7 +271,7 @@ TEST_F(NfcHidlTest, WriteInvalidCommand) {
 * Send CORE_CONN_CREATE_CMD for loop-back mode
 * Check the response
 */
TEST_F(NfcHidlTest, WriteInvalidAndThenValidCommand) {
TEST_P(NfcHidlTest, WriteInvalidAndThenValidCommand) {
    std::vector<uint8_t> cmd = CORE_RESET_CMD;
    NfcData data = cmd;
    EXPECT_EQ(data.size(), nfc_->write(data));
@@ -349,7 +335,7 @@ TEST_F(NfcHidlTest, WriteInvalidAndThenValidCommand) {
 * Checks the data received
 * Repeat to send total of 1Mb data
 */
TEST_F(NfcHidlTest, Bandwidth) {
TEST_P(NfcHidlTest, Bandwidth) {
    std::vector<uint8_t> cmd = CORE_RESET_CMD;
    NfcData data = cmd;
    EXPECT_EQ(data.size(), nfc_->write(data));
@@ -437,7 +423,7 @@ TEST_F(NfcHidlTest, Bandwidth) {
 * Waits for NfcEvent.OPEN_CPLT
 * Checks status
 */
TEST_F(NfcHidlTest, PowerCycle) {
TEST_P(NfcHidlTest, PowerCycle) {
  EXPECT_EQ(NfcStatus::OK, nfc_->powerCycle());
  // Wait for NfcEvent.OPEN_CPLT
  auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -451,7 +437,7 @@ TEST_F(NfcHidlTest, PowerCycle) {
 * Calls powerCycle() after close()
 * Checks status
 */
TEST_F(NfcHidlTest, PowerCycleAfterClose) {
TEST_P(NfcHidlTest, PowerCycleAfterClose) {
  EXPECT_EQ(NfcStatus::OK, nfc_->close());
  // Wait for CLOSE_CPLT event
  auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -474,7 +460,7 @@ TEST_F(NfcHidlTest, PowerCycleAfterClose) {
 * Calls coreInitialized() with different data
 * Waits for NfcEvent.POST_INIT_CPLT
 */
TEST_F(NfcHidlTest, CoreInitialized) {
TEST_P(NfcHidlTest, CoreInitialized) {
  NfcData data;
  data.resize(1);
  // These parameters might lead to device specific proprietary behavior
@@ -501,7 +487,7 @@ TEST_F(NfcHidlTest, CoreInitialized) {
 * Calls controlGranted()
 * Checks the return value
 */
TEST_F(NfcHidlTest, ControlGranted) {
TEST_P(NfcHidlTest, ControlGranted) {
  EXPECT_EQ(NfcStatus::OK, nfc_->controlGranted());
}

@@ -510,7 +496,7 @@ TEST_F(NfcHidlTest, ControlGranted) {
 * Call controlGranted() after close
 * Checks the return value
 */
TEST_F(NfcHidlTest, ControlGrantedAfterClose) {
TEST_P(NfcHidlTest, ControlGrantedAfterClose) {
  EXPECT_EQ(NfcStatus::OK, nfc_->close());
  // Wait for CLOSE_CPLT event
  auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -532,7 +518,7 @@ TEST_F(NfcHidlTest, ControlGrantedAfterClose) {
 * Calls prediscover()
 * Checks the return value
 */
TEST_F(NfcHidlTest, PreDiscover) {
TEST_P(NfcHidlTest, PreDiscover) {
  EXPECT_EQ(NfcStatus::OK, nfc_->prediscover());
}

@@ -541,7 +527,7 @@ TEST_F(NfcHidlTest, PreDiscover) {
 * Call prediscover() after close
 * Checks the return value
 */
TEST_F(NfcHidlTest, PreDiscoverAfterClose) {
TEST_P(NfcHidlTest, PreDiscoverAfterClose) {
  EXPECT_EQ(NfcStatus::OK, nfc_->close());
  // Wait for CLOSE_CPLT event
  auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -564,7 +550,7 @@ TEST_F(NfcHidlTest, PreDiscoverAfterClose) {
 * Calls close() multiple times
 * Checks status
 */
TEST_F(NfcHidlTest, CloseAfterClose) {
TEST_P(NfcHidlTest, CloseAfterClose) {
  EXPECT_EQ(NfcStatus::OK, nfc_->close());
  // Wait for CLOSE_CPLT event
  auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -587,15 +573,18 @@ TEST_F(NfcHidlTest, CloseAfterClose) {
 * Calls open() multiple times
 * Checks status
 */
TEST_F(NfcHidlTest, OpenAfterOpen) {
TEST_P(NfcHidlTest, OpenAfterOpen) {
  EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
  EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
}

INSTANTIATE_TEST_SUITE_P(
        PerInstance, NfcHidlTest,
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(INfc::descriptor)),
        android::hardware::PrintInstanceNameToString);

int main(int argc, char** argv) {
  ::testing::AddGlobalTestEnvironment(NfcHidlEnvironment::Instance());
  ::testing::InitGoogleTest(&argc, argv);
  NfcHidlEnvironment::Instance()->init(&argc, argv);

  std::system("svc nfc disable"); /* Turn off NFC */
  sleep(5);
+1 −1
Original line number Diff line number Diff line
@@ -22,5 +22,5 @@ cc_test {
        "android.hardware.nfc@1.0",
        "android.hardware.nfc@1.1",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}
+14 −24
Original line number Diff line number Diff line
@@ -21,11 +21,12 @@
#include <android/hardware/nfc/1.1/INfc.h>
#include <android/hardware/nfc/1.1/INfcClientCallback.h>
#include <android/hardware/nfc/1.1/types.h>
#include <gtest/gtest.h>
#include <hardware/nfc.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>

using ::android::hardware::nfc::V1_1::INfc;
using ::android::hardware::nfc::V1_1::INfcClientCallback;
@@ -83,25 +84,11 @@ class NfcClientCallback : public ::testing::VtsHalHidlTargetCallbackBase<NfcClie
    };
};

// Test environment for Nfc HIDL HAL.
class NfcHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
   public:
    // get the test environment singleton
    static NfcHidlEnvironment* Instance() {
        static NfcHidlEnvironment* instance = new NfcHidlEnvironment;
        return instance;
    }

    virtual void registerTestServices() override { registerTestService<INfc>(); }
   private:
    NfcHidlEnvironment() {}
};

// The main test class for NFC HIDL HAL.
class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class NfcHidlTest : public ::testing::TestWithParam<std::string> {
   public:
    virtual void SetUp() override {
        nfc_ = ::testing::VtsHalHidlTargetTestBase::getService<INfc>();
        nfc_ = INfc::getService(GetParam());
        ASSERT_NE(nfc_, nullptr);

        nfc_cb_ = new NfcClientCallback();
@@ -151,7 +138,7 @@ class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 * calls factoryReset()
 * checks status
 */
TEST_F(NfcHidlTest, FactoryReset) {
TEST_P(NfcHidlTest, FactoryReset) {
    nfc_->factoryReset();

    EXPECT_EQ(NfcStatus::OK, nfc_->close());
@@ -174,7 +161,7 @@ TEST_F(NfcHidlTest, FactoryReset) {
 * Makes an open call, waits for NfcEvent.OPEN_CPLT
 * Immediately calls closeforPowerOffCase() and waits for NfcEvent.CLOSE_CPLT
 */
TEST_F(NfcHidlTest, OpenAndCloseForPowerOff) {
TEST_P(NfcHidlTest, OpenAndCloseForPowerOff) {
    EXPECT_EQ(NfcStatus::OK, nfc_->closeForPowerOffCase());
    // Wait for CLOSE_CPLT event
    auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -195,7 +182,7 @@ TEST_F(NfcHidlTest, OpenAndCloseForPowerOff) {
 * Calls closeForPowerOffCase()
 * Calls close() - checks failed status
 */
TEST_F(NfcHidlTest, CloseForPowerCaseOffAfterClose) {
TEST_P(NfcHidlTest, CloseForPowerCaseOffAfterClose) {
    EXPECT_EQ(NfcStatus::OK, nfc_->closeForPowerOffCase());
    // Wait for CLOSE_CPLT event
    auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
@@ -218,16 +205,19 @@ TEST_F(NfcHidlTest, CloseForPowerCaseOffAfterClose) {
 * Calls getConfig()
 * checks if fields in NfcConfig are populated correctly
 */
TEST_F(NfcHidlTest, GetConfig) {
TEST_P(NfcHidlTest, GetConfig) {
    nfc_->getConfig([](NfcConfig config) {
        EXPECT_GE(config.maxIsoDepTransceiveLength, MIN_ISO_DEP_TRANSCEIVE_LENGTH);
    });
}

INSTANTIATE_TEST_SUITE_P(
        PerInstance, NfcHidlTest,
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(INfc::descriptor)),
        android::hardware::PrintInstanceNameToString);

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(NfcHidlEnvironment::Instance());
    ::testing::InitGoogleTest(&argc, argv);
    NfcHidlEnvironment::Instance()->init(&argc, argv);

    std::system("svc nfc disable"); /* Turn off NFC */
    sleep(5);
Loading