• 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 <sap_hidl_hal_utils.h>
18 
isServiceValidForDeviceConfiguration(hidl_string & serviceName)19 bool isServiceValidForDeviceConfiguration(hidl_string& serviceName) {
20     if (isSsSsEnabled()) {
21         // Device is configured as SSSS.
22         if (serviceName != SAP_SERVICE_SLOT1_NAME) {
23             LOG(DEBUG) << "Not valid for SSSS device.";
24             return false;
25         }
26     } else if (isDsDsEnabled()) {
27         // Device is configured as DSDS.
28         if (serviceName != SAP_SERVICE_SLOT1_NAME && serviceName != SAP_SERVICE_SLOT2_NAME) {
29             LOG(DEBUG) << "Not valid for DSDS device.";
30             return false;
31         }
32     } else if (isTsTsEnabled()) {
33         // Device is configured as TSTS.
34         if (serviceName != SAP_SERVICE_SLOT1_NAME && serviceName != SAP_SERVICE_SLOT2_NAME &&
35             serviceName != SAP_SERVICE_SLOT3_NAME) {
36             LOG(DEBUG) << "Not valid for TSTS device.";
37             return false;
38         }
39     }
40     return true;
41 }
42 
SetUp()43 void SapHidlTest::SetUp() {
44     hidl_string serviceName = GetParam();
45     if (!isServiceValidForDeviceConfiguration(serviceName)) {
46         LOG(DEBUG) << "Skipped the test due to device configuration.";
47         GTEST_SKIP();
48     }
49     sap = ISap::getService(serviceName);
50     ASSERT_NE(sap, nullptr);
51 
52     sapCb = new SapCallback(*this);
53     ASSERT_NE(sapCb, nullptr);
54 
55     count = 0;
56 
57     sap->setCallback(sapCb);
58 }
59 
TearDown()60 void SapHidlTest::TearDown() {}
61 
notify(int receivedToken)62 void SapHidlTest::notify(int receivedToken) {
63     std::unique_lock<std::mutex> lock(mtx);
64     count++;
65     if (token == receivedToken) {
66         cv.notify_one();
67     }
68 }
69 
wait()70 std::cv_status SapHidlTest::wait() {
71     std::unique_lock<std::mutex> lock(mtx);
72 
73     std::cv_status status = std::cv_status::no_timeout;
74     auto now = std::chrono::system_clock::now();
75     while (count == 0) {
76         status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
77         if (status == std::cv_status::timeout) {
78             return status;
79         }
80     }
81     count--;
82     return status;
83 }
84