diff --git a/radio/1.0/vts/functional/Android.bp b/radio/1.0/vts/functional/Android.bp index 24e3926ca1..7808de16ba 100644 --- a/radio/1.0/vts/functional/Android.bp +++ b/radio/1.0/vts/functional/Android.bp @@ -44,3 +44,27 @@ cc_test { "-g", ], } + +cc_test { + name: "VtsHalSapV1_0TargetTest", + defaults: ["hidl_defaults"], + srcs: ["sap_callback.cpp", + "sap_hidl_hal_api.cpp", + "sap_hidl_hal_test.cpp", + "VtsHalSapV1_0TargetTest.cpp"], + shared_libs: [ + "libbase", + "liblog", + "libcutils", + "libhidlbase", + "libhidltransport", + "libnativehelper", + "libutils", + "android.hardware.radio@1.0", + ], + static_libs: ["VtsHalHidlTargetTestBase"], + cflags: [ + "-O0", + "-g", + ], +} diff --git a/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp b/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp new file mode 100644 index 0000000000..f90258802e --- /dev/null +++ b/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2017 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. + */ + +#include + +int main(int argc, char** argv) { + // Add Sim-access Profile Hidl Environment + ::testing::AddGlobalTestEnvironment(new SapHidlEnvironment); + ::testing::InitGoogleTest(&argc, argv); + + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + + return status; +} diff --git a/radio/1.0/vts/functional/sap_callback.cpp b/radio/1.0/vts/functional/sap_callback.cpp new file mode 100644 index 0000000000..563d0661f1 --- /dev/null +++ b/radio/1.0/vts/functional/sap_callback.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2017 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. + */ + +#include + +SapCallback::SapCallback(SapHidlTest& parent) : parent(parent) { +} + +Return SapCallback::connectResponse(int32_t token, SapConnectRsp /*sapConnectRsp*/, + int32_t /*maxMsgSize*/) { + sapResponseToken = token; + parent.notify(); + return Void(); +} + +Return SapCallback::disconnectResponse(int32_t token) { + sapResponseToken = token; + parent.notify(); + return Void(); +} + +Return SapCallback::disconnectIndication(int32_t /*token*/, + SapDisconnectType /*disconnectType*/) { + return Void(); +} + +Return SapCallback::apduResponse(int32_t token, SapResultCode resultCode, + const ::android::hardware::hidl_vec& /*apduRsp*/) { + sapResponseToken = token; + sapResultCode = resultCode; + parent.notify(); + return Void(); +} + +Return SapCallback::transferAtrResponse(int32_t token, SapResultCode resultCode, + const ::android::hardware::hidl_vec& /*atr*/) { + sapResponseToken = token; + sapResultCode = resultCode; + parent.notify(); + return Void(); +} + +Return SapCallback::powerResponse(int32_t token, SapResultCode resultCode) { + sapResponseToken = token; + sapResultCode = resultCode; + parent.notify(); + return Void(); +} + +Return SapCallback::resetSimResponse(int32_t token, SapResultCode resultCode) { + sapResponseToken = token; + sapResultCode = resultCode; + parent.notify(); + return Void(); +} + +Return SapCallback::statusIndication(int32_t /*token*/, SapStatus /*status*/) { + return Void(); +} + +Return SapCallback::transferCardReaderStatusResponse(int32_t token, + SapResultCode resultCode, int32_t /*cardReaderStatus*/) { + sapResponseToken = token; + sapResultCode = resultCode; + parent.notify(); + return Void(); +} + +Return SapCallback::errorResponse(int32_t /*token*/) { + return Void(); +} + +Return SapCallback::transferProtocolResponse(int32_t token, + SapResultCode resultCode) { + sapResponseToken = token; + sapResultCode = resultCode; + parent.notify(); + return Void(); +} diff --git a/radio/1.0/vts/functional/sap_hidl_hal_api.cpp b/radio/1.0/vts/functional/sap_hidl_hal_api.cpp new file mode 100644 index 0000000000..e806bd7536 --- /dev/null +++ b/radio/1.0/vts/functional/sap_hidl_hal_api.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2017 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. + */ + +#include + +/* + * Test ISap.connectReq() for the response returned. + */ +TEST_F(SapHidlTest, connectReq) { + int32_t token = 0; + int32_t maxMsgSize = 100; + + sap->connectReq(++token, maxMsgSize); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); +} + +/* + * Test IRadio.disconnectReq() for the response returned + */ +TEST_F(SapHidlTest, disconnectReq) { + int32_t token = 0; + + sap->disconnectReq(++token); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); +} + +/* + * Test IRadio.apduReq() for the response returned. + */ +TEST_F(SapHidlTest, apduReq) { + int32_t token = 0; + SapApduType sapApduType = SapApduType::APDU; + android::hardware::hidl_vec command = {}; + + sap->apduReq(++token, sapApduType, command); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); + + ASSERT_TRUE(SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode || + SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode || + SapResultCode::CARD_REMOVED == sapCb->sapResultCode); +} + +/* + * Test IRadio.transferAtrReq() for the response returned. + */ +TEST_F(SapHidlTest, transferAtrReq) { + int32_t token = 0; + + sap->transferAtrReq(++token); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); + + ASSERT_TRUE(SapResultCode::DATA_NOT_AVAILABLE == sapCb->sapResultCode || + SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode || + SapResultCode::CARD_REMOVED == sapCb->sapResultCode); +} + +/* + * Test IRadio.powerReq() for the response returned. + */ +TEST_F(SapHidlTest, powerReq) { + int32_t token = 0; + bool state = true; + + sap->powerReq(++token, state); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); + + ASSERT_TRUE(SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode || + SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode || + SapResultCode::CARD_REMOVED == sapCb->sapResultCode || + SapResultCode::CARD_ALREADY_POWERED_ON == sapCb->sapResultCode); +} + +/* + * Test IRadio.resetSimReq() for the response returned. + */ +TEST_F(SapHidlTest, resetSimReq) { + int32_t token = 0; + + sap->resetSimReq(++token); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); + + ASSERT_TRUE(SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode || + SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode || + SapResultCode::CARD_REMOVED == sapCb->sapResultCode); +} + +/* + * Test IRadio.transferCardReaderStatusReq() for the response returned. + */ +TEST_F(SapHidlTest, transferCardReaderStatusReq) { + int32_t token = 0; + + sap->transferCardReaderStatusReq(++token); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); + + EXPECT_EQ(SapResultCode::DATA_NOT_AVAILABLE, sapCb->sapResultCode); +} + +/* + * Test IRadio.setTransferProtocolReq() for the response returned. + */ +TEST_F(SapHidlTest, setTransferProtocolReq) { + int32_t token = 0; + SapTransferProtocol sapTransferProtocol = SapTransferProtocol::T0; + + sap->setTransferProtocolReq(++token, sapTransferProtocol); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(sapCb->sapResponseToken, token); + + EXPECT_EQ(SapResultCode::NOT_SUPPORTED, sapCb->sapResultCode); +} diff --git a/radio/1.0/vts/functional/sap_hidl_hal_test.cpp b/radio/1.0/vts/functional/sap_hidl_hal_test.cpp new file mode 100644 index 0000000000..a67c5b6bb1 --- /dev/null +++ b/radio/1.0/vts/functional/sap_hidl_hal_test.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017 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. + */ + +#include + +void SapHidlTest::SetUp() { + sap = ::testing::VtsHalHidlTargetTestBase::getService(hidl_string("sap_uim_socket1")); + ASSERT_NE(sap, nullptr); + + sapCb = new SapCallback(*this); + ASSERT_NE(sapCb, nullptr); + + count = 0; + + sap->setCallback(sapCb); +} + +void SapHidlTest::TearDown() { +} + +void SapHidlTest::notify() { + std::unique_lock lock(mtx); + count++; + cv.notify_one(); +} + +std::cv_status SapHidlTest::wait() { + std::unique_lock lock(mtx); + + std::cv_status status = std::cv_status::no_timeout; + auto now = std::chrono::system_clock::now(); + while (count == 0) { + status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD)); + if (status == std::cv_status::timeout) { + return status; + } + } + count--; + return status; +} + diff --git a/radio/1.0/vts/functional/sap_hidl_hal_utils.h b/radio/1.0/vts/functional/sap_hidl_hal_utils.h new file mode 100644 index 0000000000..e3efa50a2a --- /dev/null +++ b/radio/1.0/vts/functional/sap_hidl_hal_utils.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2017 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. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +using namespace ::android::hardware::radio::V1_0; + +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +#define TIMEOUT_PERIOD 40 + +class SapHidlTest; + +/* Callback class for sap response */ +class SapCallback : public ISapCallback { +private: + SapHidlTest& parent; + +public: + SapResultCode sapResultCode; + int32_t sapResponseToken; + + SapCallback(SapHidlTest& parent); + + virtual ~SapCallback() = default; + + Return connectResponse(int32_t token, SapConnectRsp sapConnectRsp, int32_t maxMsgSize); + + Return disconnectResponse(int32_t token); + + Return disconnectIndication(int32_t token, SapDisconnectType disconnectType); + + Return apduResponse(int32_t token, SapResultCode resultCode, + const ::android::hardware::hidl_vec& apduRsp); + + Return transferAtrResponse(int32_t token, SapResultCode resultCode, + const ::android::hardware::hidl_vec& atr); + + Return powerResponse(int32_t token, SapResultCode resultCode); + + Return resetSimResponse(int32_t token, SapResultCode resultCode); + + Return statusIndication(int32_t token, SapStatus status); + + Return transferCardReaderStatusResponse(int32_t token, SapResultCode resultCode, + int32_t cardReaderStatus); + + Return errorResponse(int32_t token); + + Return transferProtocolResponse(int32_t token, SapResultCode resultCode); +}; + +// The main test class for Sap HIDL. +class SapHidlTest : public ::testing::VtsHalHidlTargetTestBase { +private: + std::mutex mtx; + std::condition_variable cv; + int count; + +public: + virtual void SetUp() override; + + virtual void TearDown() override; + + /* Used as a mechanism to inform the test about data/event callback */ + void notify(); + + /* Test code calls this function to wait for response */ + std::cv_status wait(); + + /* Sap service */ + sp sap; + + /* Sap Callback object */ + sp sapCb; +}; + +// A class for test environment setup +class SapHidlEnvironment : public ::testing::Environment { +public: + virtual void SetUp() {} + virtual void TearDown() {} +};