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 <radio_hidl_hal_utils.h>
18
SetUp()19 void RadioHidlTest::SetUp() {
20 radio =
21 ::testing::VtsHalHidlTargetTestBase::getService<IRadio>(hidl_string(RADIO_SERVICE_NAME));
22 ASSERT_NE(radio, nullptr);
23
24 radioRsp = new RadioResponse(*this);
25 ASSERT_NE(radioRsp, nullptr);
26
27 count = 0;
28
29 radioInd = NULL;
30 radio->setResponseFunctions(radioRsp, radioInd);
31
32 int serial = GetRandomSerialNumber();
33 radio->getIccCardStatus(serial);
34 EXPECT_EQ(std::cv_status::no_timeout, wait());
35 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
36 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
37 EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
38 }
39
TearDown()40 void RadioHidlTest::TearDown() {}
41
notify()42 void RadioHidlTest::notify() {
43 std::unique_lock<std::mutex> lock(mtx);
44 count++;
45 cv.notify_one();
46 }
47
wait()48 std::cv_status RadioHidlTest::wait() {
49 std::unique_lock<std::mutex> lock(mtx);
50
51 std::cv_status status = std::cv_status::no_timeout;
52 auto now = std::chrono::system_clock::now();
53 while (count == 0) {
54 status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
55 if (status == std::cv_status::timeout) {
56 return status;
57 }
58 }
59 count--;
60 return status;
61 }
62
CheckGeneralError()63 bool RadioHidlTest::CheckGeneralError() {
64 return (radioRsp->rspInfo.error == RadioError::RADIO_NOT_AVAILABLE ||
65 radioRsp->rspInfo.error == RadioError::NO_MEMORY ||
66 radioRsp->rspInfo.error == RadioError::INTERNAL_ERR ||
67 radioRsp->rspInfo.error == RadioError::SYSTEM_ERR ||
68 radioRsp->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED ||
69 radioRsp->rspInfo.error == RadioError::CANCELLED);
70 }
71
CheckOEMError()72 bool RadioHidlTest::CheckOEMError() {
73 return (radioRsp->rspInfo.error >= RadioError::OEM_ERROR_1 &&
74 radioRsp->rspInfo.error <= RadioError::OEM_ERROR_25);
75 }
76