1 /*
2 * Copyright (C) 2017 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 #include <android-base/logging.h>
18 #include <sap_hidl_hal_utils.h>
19
20 /*
21 * Test ISap.connectReq() for the response returned.
22 */
TEST_P(SapHidlTest,connectReq)23 TEST_P(SapHidlTest, connectReq) {
24 LOG(DEBUG) << "connectReq";
25 token = GetRandomSerialNumber();
26 int32_t maxMsgSize = 100;
27
28 sap->connectReq(token, maxMsgSize);
29 EXPECT_EQ(std::cv_status::no_timeout, wait());
30 EXPECT_EQ(sapCb->sapResponseToken, token);
31
32 // Modem side need time for connect to finish. Adding a waiting time to prevent
33 // disconnect being requested right after connect request.
34 sleep(1);
35 LOG(DEBUG) << "connectReq finished";
36 }
37
38 /*
39 * Test IRadio.disconnectReq() for the response returned
40 */
TEST_P(SapHidlTest,disconnectReq)41 TEST_P(SapHidlTest, disconnectReq) {
42 LOG(DEBUG) << "disconnectReq";
43 token = GetRandomSerialNumber();
44
45 sap->disconnectReq(token);
46 EXPECT_EQ(std::cv_status::no_timeout, wait());
47 EXPECT_EQ(sapCb->sapResponseToken, token);
48 LOG(DEBUG) << "disconnectReq finished";
49 }
50
51 /*
52 * Test IRadio.apduReq() for the response returned.
53 */
TEST_P(SapHidlTest,apduReq)54 TEST_P(SapHidlTest, apduReq) {
55 LOG(DEBUG) << "apduReq";
56 token = GetRandomSerialNumber();
57 SapApduType sapApduType = SapApduType::APDU;
58 android::hardware::hidl_vec<uint8_t> command = {};
59
60 sap->apduReq(token, sapApduType, command);
61 EXPECT_EQ(std::cv_status::no_timeout, wait());
62 EXPECT_EQ(sapCb->sapResponseToken, token);
63
64 ASSERT_TRUE(
65 CheckAnyOfErrors(sapCb->sapResultCode,
66 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_ALREADY_POWERED_OFF,
67 SapResultCode::CARD_NOT_ACCESSSIBLE, SapResultCode::CARD_REMOVED}));
68 LOG(DEBUG) << "apduReq finished";
69 }
70
71 /*
72 * Test IRadio.transferAtrReq() for the response returned.
73 */
TEST_P(SapHidlTest,transferAtrReq)74 TEST_P(SapHidlTest, transferAtrReq) {
75 LOG(DEBUG) << "transferAtrReq";
76 token = GetRandomSerialNumber();
77
78 sap->transferAtrReq(token);
79 EXPECT_EQ(std::cv_status::no_timeout, wait());
80 EXPECT_EQ(sapCb->sapResponseToken, token);
81
82 ASSERT_TRUE(
83 CheckAnyOfErrors(sapCb->sapResultCode,
84 {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE,
85 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED}));
86 LOG(DEBUG) << "transferAtrReq finished";
87 }
88
89 /*
90 * Test IRadio.powerReq() for the response returned.
91 */
TEST_P(SapHidlTest,powerReq)92 TEST_P(SapHidlTest, powerReq) {
93 LOG(DEBUG) << "powerReq";
94 token = GetRandomSerialNumber();
95 bool state = true;
96
97 sap->powerReq(token, state);
98 EXPECT_EQ(std::cv_status::no_timeout, wait());
99 EXPECT_EQ(sapCb->sapResponseToken, token);
100
101 ASSERT_TRUE(CheckAnyOfErrors(
102 sapCb->sapResultCode, {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
103 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED,
104 SapResultCode::CARD_ALREADY_POWERED_ON}));
105 LOG(DEBUG) << "powerReq finished";
106 }
107
108 /*
109 * Test IRadio.resetSimReq() for the response returned.
110 */
TEST_P(SapHidlTest,resetSimReq)111 TEST_P(SapHidlTest, resetSimReq) {
112 LOG(DEBUG) << "resetSimReq";
113 token = GetRandomSerialNumber();
114
115 sap->resetSimReq(token);
116 EXPECT_EQ(std::cv_status::no_timeout, wait());
117 EXPECT_EQ(sapCb->sapResponseToken, token);
118
119 ASSERT_TRUE(
120 CheckAnyOfErrors(sapCb->sapResultCode,
121 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
122 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED}));
123 LOG(DEBUG) << "resetSimReq finished";
124 }
125
126 /*
127 * Test IRadio.transferCardReaderStatusReq() for the response returned.
128 */
TEST_P(SapHidlTest,transferCardReaderStatusReq)129 TEST_P(SapHidlTest, transferCardReaderStatusReq) {
130 LOG(DEBUG) << "transferCardReaderStatusReq";
131 token = GetRandomSerialNumber();
132
133 sap->transferCardReaderStatusReq(token);
134 EXPECT_EQ(std::cv_status::no_timeout, wait());
135 EXPECT_EQ(sapCb->sapResponseToken, token);
136
137 ASSERT_TRUE(CheckAnyOfErrors(
138 sapCb->sapResultCode, {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE}));
139 LOG(DEBUG) << "transferCardReaderStatusReq finished";
140 }
141
142 /*
143 * Test IRadio.setTransferProtocolReq() for the response returned.
144 */
TEST_P(SapHidlTest,setTransferProtocolReq)145 TEST_P(SapHidlTest, setTransferProtocolReq) {
146 LOG(DEBUG) << "setTransferProtocolReq";
147 token = GetRandomSerialNumber();
148 SapTransferProtocol sapTransferProtocol = SapTransferProtocol::T0;
149
150 sap->setTransferProtocolReq(token, sapTransferProtocol);
151 EXPECT_EQ(std::cv_status::no_timeout, wait());
152 EXPECT_EQ(sapCb->sapResponseToken, token);
153
154 EXPECT_EQ(SapResultCode::NOT_SUPPORTED, sapCb->sapResultCode);
155 LOG(DEBUG) << "setTransferProtocolReq finished";
156 }
157