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