• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_v1_0.h>
18 
SetUp()19 void RadioHidlTest::SetUp() {
20     radio =
21         ::testing::VtsHalHidlTargetTestBase::getService<IRadio>(hidl_string(RADIO_SERVICE_NAME));
22     ASSERT_NE(nullptr, radio.get());
23 
24     radioRsp = new (std::nothrow) RadioResponse(*this);
25     ASSERT_NE(nullptr, radioRsp.get());
26 
27     count = 0;
28 
29     radioInd = new (std::nothrow) RadioIndication(*this);
30     ASSERT_NE(nullptr, radioInd.get());
31 
32     radio->setResponseFunctions(radioRsp, radioInd);
33 
34     int serial = GetRandomSerialNumber();
35     radio->getIccCardStatus(serial);
36     EXPECT_EQ(std::cv_status::no_timeout, wait());
37     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
38     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
39     EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
40 
41     /* Vts Testing with Sim Absent only. This needs to be removed later in P when sim present
42      * scenarios will be tested. */
43     EXPECT_EQ(CardState::ABSENT, cardStatus.cardState);
44 }
45 
TearDown()46 void RadioHidlTest::TearDown() {}
47 
notify()48 void RadioHidlTest::notify() {
49     std::unique_lock<std::mutex> lock(mtx);
50     count++;
51     cv.notify_one();
52 }
53 
wait()54 std::cv_status RadioHidlTest::wait() {
55     std::unique_lock<std::mutex> lock(mtx);
56 
57     std::cv_status status = std::cv_status::no_timeout;
58     auto now = std::chrono::system_clock::now();
59     while (count == 0) {
60         status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
61         if (status == std::cv_status::timeout) {
62             return status;
63         }
64     }
65     count--;
66     return status;
67 }
68 
CheckGeneralError()69 bool RadioHidlTest::CheckGeneralError() {
70     return (radioRsp->rspInfo.error == RadioError::RADIO_NOT_AVAILABLE ||
71             radioRsp->rspInfo.error == RadioError::NO_MEMORY ||
72             radioRsp->rspInfo.error == RadioError::INTERNAL_ERR ||
73             radioRsp->rspInfo.error == RadioError::SYSTEM_ERR ||
74             radioRsp->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED ||
75             radioRsp->rspInfo.error == RadioError::CANCELLED);
76 }
77 
CheckOEMError()78 bool RadioHidlTest::CheckOEMError() {
79     return (radioRsp->rspInfo.error >= RadioError::OEM_ERROR_1 &&
80             radioRsp->rspInfo.error <= RadioError::OEM_ERROR_25);
81 }
82