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 <radio_hidl_hal_utils_v1_0.h>
19
SetUp()20 void RadioHidlTest::SetUp() {
21 radio = IRadio::getService(GetParam());
22 if (radio == NULL) {
23 LOG(DEBUG) << "Radio is NULL, waiting 1 minute to retry";
24 sleep(60);
25 radio = IRadio::getService(GetParam());
26 }
27 ASSERT_NE(nullptr, radio.get());
28
29 radioRsp = new (std::nothrow) RadioResponse(*this);
30 ASSERT_NE(nullptr, radioRsp.get());
31
32 count = 0;
33
34 radioInd = new (std::nothrow) RadioIndication(*this);
35 ASSERT_NE(nullptr, radioInd.get());
36
37 radio->setResponseFunctions(radioRsp, radioInd);
38
39 updateSimCardStatus();
40 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
41 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
42 EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
43
44 /* Enforce Vts Testing with Sim Status Present only. */
45 EXPECT_EQ(CardState::PRESENT, cardStatus.cardState);
46 }
47
notify(int receivedSerial)48 void RadioHidlTest::notify(int receivedSerial) {
49 std::unique_lock<std::mutex> lock(mtx);
50 if (serial == receivedSerial) {
51 count++;
52 cv.notify_one();
53 }
54 }
55
wait(int sec)56 std::cv_status RadioHidlTest::wait(int sec) {
57 std::unique_lock<std::mutex> lock(mtx);
58
59 std::cv_status status = std::cv_status::no_timeout;
60 auto now = std::chrono::system_clock::now();
61 while (count == 0) {
62 status = cv.wait_until(lock, now + std::chrono::seconds(sec));
63 if (status == std::cv_status::timeout) {
64 return status;
65 }
66 }
67 count--;
68 return status;
69 }
70
updateSimCardStatus()71 void RadioHidlTest::updateSimCardStatus() {
72 serial = GetRandomSerialNumber();
73 radio->getIccCardStatus(serial);
74 EXPECT_EQ(std::cv_status::no_timeout, wait());
75 }
76