Home | History | Annotate | Download | only in functional
      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 
     19 void SapHidlTest::SetUp() {
     20     sap = ::testing::VtsHalHidlTargetTestBase::getService<ISap>(hidl_string(SAP_SERVICE_NAME));
     21     ASSERT_NE(sap, nullptr);
     22 
     23     sapCb = new SapCallback(*this);
     24     ASSERT_NE(sapCb, nullptr);
     25 
     26     count = 0;
     27 
     28     sap->setCallback(sapCb);
     29 }
     30 
     31 void SapHidlTest::TearDown() {}
     32 
     33 void SapHidlTest::notify() {
     34     std::unique_lock<std::mutex> lock(mtx);
     35     count++;
     36     cv.notify_one();
     37     }
     38 
     39     std::cv_status SapHidlTest::wait() {
     40         std::unique_lock<std::mutex> lock(mtx);
     41 
     42         std::cv_status status = std::cv_status::no_timeout;
     43         auto now = std::chrono::system_clock::now();
     44         while (count == 0) {
     45             status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
     46             if (status == std::cv_status::timeout) {
     47                 return status;
     48             }
     49         }
     50         count--;
     51         return status;
     52     }