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(CheckAnyOfErrors(
65 sapCb->sapResultCode,
66 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_ALREADY_POWERED_OFF,
67 SapResultCode::CARD_NOT_ACCESSSIBLE, SapResultCode::CARD_REMOVED,
68 SapResultCode::SUCCESS}));
69 LOG(DEBUG) << "apduReq finished";
70 }
71
72 /*
73 * Test IRadio.transferAtrReq() for the response returned.
74 */
TEST_P(SapHidlTest,transferAtrReq)75 TEST_P(SapHidlTest, transferAtrReq) {
76 LOG(DEBUG) << "transferAtrReq";
77 token = GetRandomSerialNumber();
78
79 sap->transferAtrReq(token);
80 EXPECT_EQ(std::cv_status::no_timeout, wait());
81 EXPECT_EQ(sapCb->sapResponseToken, token);
82
83 ASSERT_TRUE(CheckAnyOfErrors(sapCb->sapResultCode,
84 {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE,
85 SapResultCode::CARD_ALREADY_POWERED_OFF,
86 SapResultCode::CARD_REMOVED, SapResultCode::SUCCESS}));
87 LOG(DEBUG) << "transferAtrReq finished";
88 }
89
90 /*
91 * Test IRadio.powerReq() for the response returned.
92 */
TEST_P(SapHidlTest,powerReq)93 TEST_P(SapHidlTest, powerReq) {
94 LOG(DEBUG) << "powerReq";
95 token = GetRandomSerialNumber();
96 bool state = true;
97
98 sap->powerReq(token, state);
99 EXPECT_EQ(std::cv_status::no_timeout, wait());
100 EXPECT_EQ(sapCb->sapResponseToken, token);
101
102 ASSERT_TRUE(
103 CheckAnyOfErrors(sapCb->sapResultCode,
104 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
105 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED,
106 SapResultCode::CARD_ALREADY_POWERED_ON, SapResultCode::SUCCESS}));
107 LOG(DEBUG) << "powerReq finished";
108 }
109
110 /*
111 * Test IRadio.resetSimReq() for the response returned.
112 */
TEST_P(SapHidlTest,resetSimReq)113 TEST_P(SapHidlTest, resetSimReq) {
114 LOG(DEBUG) << "resetSimReq";
115 token = GetRandomSerialNumber();
116
117 sap->resetSimReq(token);
118 EXPECT_EQ(std::cv_status::no_timeout, wait());
119 EXPECT_EQ(sapCb->sapResponseToken, token);
120
121 ASSERT_TRUE(
122 CheckAnyOfErrors(sapCb->sapResultCode,
123 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
124 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED,
125 SapResultCode::SUCCESS}));
126 LOG(DEBUG) << "resetSimReq finished";
127 }
128
129 /*
130 * Test IRadio.transferCardReaderStatusReq() for the response returned.
131 */
TEST_P(SapHidlTest,transferCardReaderStatusReq)132 TEST_P(SapHidlTest, transferCardReaderStatusReq) {
133 LOG(DEBUG) << "transferCardReaderStatusReq";
134 token = GetRandomSerialNumber();
135
136 sap->transferCardReaderStatusReq(token);
137 EXPECT_EQ(std::cv_status::no_timeout, wait());
138 EXPECT_EQ(sapCb->sapResponseToken, token);
139
140 ASSERT_TRUE(CheckAnyOfErrors(sapCb->sapResultCode,
141 {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE,
142 SapResultCode::SUCCESS}));
143 LOG(DEBUG) << "transferCardReaderStatusReq finished";
144 }
145
146 /*
147 * Test IRadio.setTransferProtocolReq() for the response returned.
148 */
TEST_P(SapHidlTest,setTransferProtocolReq)149 TEST_P(SapHidlTest, setTransferProtocolReq) {
150 LOG(DEBUG) << "setTransferProtocolReq";
151 token = GetRandomSerialNumber();
152 SapTransferProtocol sapTransferProtocol = SapTransferProtocol::T0;
153
154 sap->setTransferProtocolReq(token, sapTransferProtocol);
155 EXPECT_EQ(std::cv_status::no_timeout, wait());
156 EXPECT_EQ(sapCb->sapResponseToken, token);
157
158 ASSERT_TRUE(CheckAnyOfErrors(sapCb->sapResultCode,
159 {SapResultCode::NOT_SUPPORTED, SapResultCode::SUCCESS}));
160 LOG(DEBUG) << "setTransferProtocolReq finished";
161 }
162