OSDN Git Service

2a67954ff692279965cfd150666b76a7fb45879f
[android-x86/hardware-interfaces.git] / radio / 1.0 / vts / functional / radio_hidl_hal_test.cpp
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
19 void RadioHidlTest::SetUp() {
20     radio = IRadio::getService(hidl_string("rild"));
21     ASSERT_NE(radio, nullptr);
22
23     radioRsp = new RadioResponse(*this);
24     ASSERT_NE(radioRsp, nullptr);
25
26     count = 0;
27
28     radioInd = NULL;
29     radio->setResponseFunctions(radioRsp, radioInd);
30 }
31
32 void RadioHidlTest::TearDown() {
33 }
34
35 void RadioHidlTest::notify() {
36     std::unique_lock<std::mutex> lock(mtx);
37     count++;
38     cv.notify_one();
39 }
40
41 std::cv_status RadioHidlTest::wait() {
42     std::unique_lock<std::mutex> lock(mtx);
43
44     std::cv_status status = std::cv_status::no_timeout;
45     auto now = std::chrono::system_clock::now();
46     while (count == 0) {
47         status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
48         if (status == std::cv_status::timeout) {
49             return status;
50         }
51     }
52     count--;
53     return status;
54 }
55