summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuchi Kandoi2018-01-31 15:47:17 -0600
committerRuchi Kandoi2018-02-02 18:53:00 -0600
commit912ce33eeba8ea761465d8b399e6829eb57066bd (patch)
tree7125c4c671f831dd9e0a264bf20efbf4370a11ce
parent2ea233becbb380539823437fac3f469b644c51e1 (diff)
downloadplatform-hardware-interfaces-912ce33eeba8ea761465d8b399e6829eb57066bd.tar.gz
platform-hardware-interfaces-912ce33eeba8ea761465d8b399e6829eb57066bd.tar.xz
platform-hardware-interfaces-912ce33eeba8ea761465d8b399e6829eb57066bd.zip
Add NFC 1.1 VTS Test
Test: Run VtsHalNfcV1_1TargetTest Bug: 72746517 Change-Id: I11db8782e89fe06a33d9d7b56d3270b0ad0341cd
-rw-r--r--nfc/1.1/vts/functional/Android.bp25
-rw-r--r--nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp220
2 files changed, 245 insertions, 0 deletions
diff --git a/nfc/1.1/vts/functional/Android.bp b/nfc/1.1/vts/functional/Android.bp
new file mode 100644
index 00000000..0ce531f6
--- /dev/null
+++ b/nfc/1.1/vts/functional/Android.bp
@@ -0,0 +1,25 @@
1//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17cc_test {
18 name: "VtsHalNfcV1_1TargetTest",
19 defaults: ["VtsHalTargetTestDefaults"],
20 srcs: ["VtsHalNfcV1_1TargetTest.cpp"],
21 static_libs: [
22 "android.hardware.nfc@1.0",
23 "android.hardware.nfc@1.1",
24 ],
25}
diff --git a/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp b/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp
new file mode 100644
index 00000000..a5b40d47
--- /dev/null
+++ b/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp
@@ -0,0 +1,220 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "nfc_hidl_hal_test"
18#include <android-base/logging.h>
19
20#include <android/hardware/nfc/1.0/types.h>
21#include <android/hardware/nfc/1.1/INfc.h>
22#include <android/hardware/nfc/1.1/INfcClientCallback.h>
23#include <android/hardware/nfc/1.1/types.h>
24#include <hardware/nfc.h>
25
26#include <VtsHalHidlTargetCallbackBase.h>
27#include <VtsHalHidlTargetTestBase.h>
28
29using ::android::hardware::nfc::V1_1::INfc;
30using ::android::hardware::nfc::V1_1::INfcClientCallback;
31using ::android::hardware::nfc::V1_1::NfcEvent;
32using ::android::hardware::nfc::V1_0::NfcStatus;
33using ::android::hardware::nfc::V1_0::NfcData;
34using ::android::hardware::Return;
35using ::android::hardware::Void;
36using ::android::hardware::hidl_vec;
37using ::android::sp;
38
39constexpr char kCallbackNameSendEvent[] = "sendEvent";
40constexpr char kCallbackNameSendData[] = "sendData";
41
42class NfcClientCallbackArgs {
43 public:
44 NfcEvent last_event_;
45 NfcStatus last_status_;
46 NfcData last_data_;
47};
48
49/* Callback class for data & Event. */
50class NfcClientCallback : public ::testing::VtsHalHidlTargetCallbackBase<NfcClientCallbackArgs>,
51 public INfcClientCallback {
52 public:
53 virtual ~NfcClientCallback() = default;
54
55 /* sendEvent callback function - Records the Event & Status
56 * and notifies the TEST
57 **/
58 Return<void> sendEvent_1_1(NfcEvent event, NfcStatus event_status) override {
59 NfcClientCallbackArgs args;
60 args.last_event_ = event;
61 args.last_status_ = event_status;
62 NotifyFromCallback(kCallbackNameSendEvent, args);
63 return Void();
64 };
65
66 /** NFC 1.1 HAL shouldn't send 1.0 callbacks */
67 Return<void> sendEvent(__attribute__((unused))::android::hardware::nfc::V1_0::NfcEvent event,
68 __attribute__((unused)) NfcStatus event_status) override {
69 return Void();
70 }
71
72 /* sendData callback function. Records the data and notifies the TEST*/
73 Return<void> sendData(const NfcData& data) override {
74 NfcClientCallbackArgs args;
75 args.last_data_ = data;
76 NotifyFromCallback(kCallbackNameSendData, args);
77 return Void();
78 };
79};
80
81// The main test class for NFC HIDL HAL.
82class NfcHidlTest : public ::testing::VtsHalHidlTargetTestBase {
83 public:
84 virtual void SetUp() override {
85 nfc_ = ::testing::VtsHalHidlTargetTestBase::getService<INfc>();
86 ASSERT_NE(nfc_, nullptr);
87
88 nfc_cb_ = new NfcClientCallback();
89 ASSERT_NE(nfc_cb_, nullptr);
90
91 EXPECT_EQ(NfcStatus::OK, nfc_->open_1_1(nfc_cb_));
92 // Wait for OPEN_CPLT event
93 auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
94 EXPECT_TRUE(res.no_timeout);
95 EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
96 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
97
98 /*
99 * Close the hal and then re-open to make sure we are in a predictable
100 * state for all the tests.
101 */
102 EXPECT_EQ(NfcStatus::OK, nfc_->close());
103 // Wait for CLOSE_CPLT event
104 res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
105 EXPECT_TRUE(res.no_timeout);
106 EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
107 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
108
109 EXPECT_EQ(NfcStatus::OK, nfc_->open_1_1(nfc_cb_));
110 // Wait for OPEN_CPLT event
111 res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
112 EXPECT_TRUE(res.no_timeout);
113 EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
114 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
115 }
116
117 virtual void TearDown() override {
118 EXPECT_EQ(NfcStatus::OK, nfc_->close());
119 // Wait for CLOSE_CPLT event
120 auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
121 EXPECT_TRUE(res.no_timeout);
122 EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
123 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
124 }
125
126 sp<INfc> nfc_;
127 sp<NfcClientCallback> nfc_cb_;
128};
129
130// A class for test environment setup (kept since this file is a template).
131class NfcHidlEnvironment : public ::testing::Environment {
132 public:
133 virtual void SetUp() {}
134 virtual void TearDown() {}
135
136 private:
137};
138
139/*
140 * factoryReset
141 * calls factoryReset()
142 * checks status
143 */
144TEST_F(NfcHidlTest, FactoryReset) {
145 nfc_->factoryReset();
146
147 EXPECT_EQ(NfcStatus::OK, nfc_->close());
148 // Wait for CLOSE_CPLT event
149 auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
150 EXPECT_TRUE(res.no_timeout);
151 EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
152 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
153
154 EXPECT_EQ(NfcStatus::OK, nfc_->open_1_1(nfc_cb_));
155 // Wait for OPEN_CPLT event
156 res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
157 EXPECT_TRUE(res.no_timeout);
158 EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
159 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
160}
161
162/*
163 * OpenAndClose:
164 * Makes an open call, waits for NfcEvent.OPEN_CPLT
165 * Immediately calls closeforPowerOffCase() and waits for NfcEvent.CLOSE_CPLT
166 */
167TEST_F(NfcHidlTest, OpenAndCloseForPowerOff) {
168 EXPECT_EQ(NfcStatus::OK, nfc_->closeForPowerOffCase());
169 // Wait for CLOSE_CPLT event
170 auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
171 EXPECT_TRUE(res.no_timeout);
172 EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
173 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
174
175 EXPECT_EQ(NfcStatus::OK, nfc_->open_1_1(nfc_cb_));
176 // Wait for OPEN_CPLT event
177 res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
178 EXPECT_TRUE(res.no_timeout);
179 EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
180 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
181}
182
183/*
184 * CloseForPowerOffCaseAfterClose:
185 * Calls closeForPowerOffCase()
186 * Calls close() - checks failed status
187 */
188TEST_F(NfcHidlTest, CloseForPowerCaseOffAfterClose) {
189 EXPECT_EQ(NfcStatus::OK, nfc_->closeForPowerOffCase());
190 // Wait for CLOSE_CPLT event
191 auto res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
192 EXPECT_TRUE(res.no_timeout);
193 EXPECT_EQ(NfcEvent::CLOSE_CPLT, res.args->last_event_);
194 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
195
196 EXPECT_EQ(NfcStatus::FAILED, nfc_->close());
197
198 EXPECT_EQ(NfcStatus::OK, nfc_->open_1_1(nfc_cb_));
199 // Wait for OPEN_CPLT event
200 res = nfc_cb_->WaitForCallback(kCallbackNameSendEvent);
201 EXPECT_TRUE(res.no_timeout);
202 EXPECT_EQ(NfcEvent::OPEN_CPLT, res.args->last_event_);
203 EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
204}
205
206int main(int argc, char** argv) {
207 ::testing::AddGlobalTestEnvironment(new NfcHidlEnvironment);
208 ::testing::InitGoogleTest(&argc, argv);
209
210 std::system("svc nfc disable"); /* Turn off NFC */
211 sleep(5);
212
213 int status = RUN_ALL_TESTS();
214 LOG(INFO) << "Test result = " << status;
215
216 std::system("svc nfc enable"); /* Turn on NFC */
217 sleep(5);
218
219 return status;
220}