Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f7ed1d9 authored by Daniel Bright's avatar Daniel Bright
Browse files

Get Radio Hal Capabilities in VTS

* Created utility method in v1_6 HAL to access radio hal capabilities
* Created static library to support getting the capaiblities response
* Created RadioResponseWaiter to encapsulate the notify \ wait logic
  used when waiting for an asynchronous response from the HAL
* Usage: if (getRadioHalCapabilities().modemReducedFeatureSet1) { ... }

Bug: 181895757
Test: Accessed default hal capabilities
Change-Id: Ie0a727d4e9d268ad03cf3fa793aa456a95c89f5b
parent 688c8846
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <iostream>
#include "VtsCoreUtil.h"

#define WAIT_TIMEOUT_PERIOD 75

int GetRandomSerialNumber() {
    return rand();
}
@@ -100,3 +102,32 @@ bool isVoiceEmergencyOnly(RegState state) {
           ::android::hardware::radio::V1_0::RegState::REG_DENIED_EM == state ||
           ::android::hardware::radio::V1_0::RegState::UNKNOWN_EM == state;
}

/*
 * Notify that the response message is received.
 */
void RadioResponseWaiter::notify(int receivedSerial) {
    std::unique_lock<std::mutex> lock(mtx_);
    if (serial == receivedSerial) {
        count_++;
        cv_.notify_one();
    }
}

/*
 * Wait till the response message is notified or till WAIT_TIMEOUT_PERIOD.
 */
std::cv_status RadioResponseWaiter::wait() {
    std::unique_lock<std::mutex> lock(mtx_);

    std::cv_status status = std::cv_status::no_timeout;
    auto now = std::chrono::system_clock::now();
    while (count_ == 0) {
        status = cv_.wait_until(lock, now + std::chrono::seconds(WAIT_TIMEOUT_PERIOD));
        if (status == std::cv_status::timeout) {
            return status;
        }
    }
    count_--;
    return status;
}
+23 −1
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#pragma once

#include <android-base/logging.h>

#include <android/hardware/radio/1.0/types.h>
@@ -82,3 +84,23 @@ bool isVoiceEmergencyOnly(RegState state);
 * Check if voice status is in service.
 */
bool isVoiceInService(RegState state);

/**
 * Used when waiting for an asynchronous response from the HAL.
 */
class RadioResponseWaiter {
  protected:
    std::mutex mtx_;
    std::condition_variable cv_;
    int count_;

  public:
    /* Serial number for radio request */
    int serial;

    /* Used as a mechanism to inform the test about data/event callback */
    void notify(int receivedSerial);

    /* Test code calls this function to wait for response */
    std::cv_status wait();
};
+7 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ cc_test {
    ],
    static_libs: [
        "RadioVtsTestUtilBase",
        "RadioConfigVtsTestResponse",
        "android.hardware.radio@1.6",
        "android.hardware.radio@1.5",
        "android.hardware.radio@1.4",
@@ -45,8 +46,13 @@ cc_test {
        "android.hardware.radio@1.0",
        "android.hardware.radio.config@1.0",
        "android.hardware.radio.config@1.1",
        "android.hardware.radio.config@1.2",
        "android.hardware.radio.config@1.3",
    ],
    header_libs: [
        "radio.util.header@1.0",
        "radio.config.util.header@1.3",
    ],
    header_libs: ["radio.util.header@1.0"],
    test_suites: [
        "general-tests",
        "vts",
+28 −29
Original line number Diff line number Diff line
@@ -45,35 +45,6 @@ void RadioHidlTest_v1_6::SetUp() {
    EXPECT_EQ(CardState::PRESENT, cardStatus.base.base.base.cardState);
}

/*
 * Notify that the response message is received.
 */
void RadioHidlTest_v1_6::notify(int receivedSerial) {
    std::unique_lock<std::mutex> lock(mtx_);
    if (serial == receivedSerial) {
        count_++;
        cv_.notify_one();
    }
}

/*
 * Wait till the response message is notified or till TIMEOUT_PERIOD.
 */
std::cv_status RadioHidlTest_v1_6::wait() {
    std::unique_lock<std::mutex> lock(mtx_);

    std::cv_status status = std::cv_status::no_timeout;
    auto now = std::chrono::system_clock::now();
    while (count_ == 0) {
        status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
        if (status == std::cv_status::timeout) {
            return status;
        }
    }
    count_--;
    return status;
}

void RadioHidlTest_v1_6::clearPotentialEstablishedCalls() {
    // Get the current call Id to hangup the established emergency call.
    serial = GetRandomSerialNumber();
@@ -108,3 +79,31 @@ void RadioHidlTest_v1_6::getDataCallList() {
    radio_v1_6->getDataCallList_1_6(serial);
    EXPECT_EQ(std::cv_status::no_timeout, wait());
}

/**
 * Specific features on the Radio Hal rely on Radio Hal Capabilities.  The VTS
 * tests related to that features must not run if the related capability is
 * disabled.
 * <p/>
 * Typical usage within VTS:
 * if (getRadioHalCapabilities().modemReducedFeatureSet) return;
 */
HalDeviceCapabilities RadioHidlTest_v1_6::getRadioHalCapabilities() {
    sp<::android::hardware::radio::config::V1_3::IRadioConfig> radioConfig_v1_3 =
            ::android::hardware::radio::config::V1_3::IRadioConfig::getService();
    if (radioConfig_v1_3.get() == nullptr) {
        // If v1_3 isn't present, the values are initialized to false
        HalDeviceCapabilities radioHalCapabilities;
        memset(&radioHalCapabilities, 0, sizeof(radioHalCapabilities));
        return radioHalCapabilities;
    } else {
        // Get radioHalDeviceCapabilities from the radio config
        sp<RadioConfigResponse> radioConfigRsp = new (std::nothrow) RadioConfigResponse(*this);
        radioConfig_v1_3->setResponseFunctions(radioConfigRsp, nullptr);
        serial = GetRandomSerialNumber();

        radioConfig_v1_3->getHalDeviceCapabilities(serial);
        EXPECT_EQ(std::cv_status::no_timeout, wait());
        return radioConfigRsp->halDeviceCapabilities;
    }
}
+9 −22
Original line number Diff line number Diff line
@@ -18,16 +18,12 @@

#include <android-base/logging.h>

#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <utils/Log.h>
#include "radio_config_hidl_hal_utils.h"

#include <chrono>
#include <condition_variable>
#include <mutex>

#include <android/hardware/radio/config/1.1/IRadioConfig.h>

#include <android/hardware/radio/1.6/IRadio.h>
#include <android/hardware/radio/1.6/IRadioIndication.h>
#include <android/hardware/radio/1.6/IRadioResponse.h>
@@ -42,14 +38,15 @@ using namespace ::android::hardware::radio::V1_3;
using namespace ::android::hardware::radio::V1_2;
using namespace ::android::hardware::radio::V1_1;
using namespace ::android::hardware::radio::V1_0;
using namespace ::android::hardware::radio::config::V1_3;

using ::android::sp;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::radio::config::V1_3::HalDeviceCapabilities;

#define TIMEOUT_PERIOD 75
#define MODEM_EMERGENCY_CALL_ESTABLISH_TIME 3
#define MODEM_EMERGENCY_CALL_DISCONNECT_TIME 3

@@ -61,7 +58,7 @@ extern ::android::hardware::radio::V1_5::CardStatus cardStatus;
/* Callback class for radio response v1_6 */
class RadioResponse_v1_6 : public ::android::hardware::radio::V1_6::IRadioResponse {
  protected:
    RadioHidlTest_v1_6& parent_v1_6;
    RadioResponseWaiter& parent_v1_6;

  public:
    hidl_vec<RadioBandMode> radioBandModes;
@@ -105,7 +102,7 @@ class RadioResponse_v1_6 : public ::android::hardware::radio::V1_6::IRadioRespon
    ::android::hardware::radio::V1_5::CellIdentity barringCellIdentity;
    ::android::hardware::hidl_vec<::android::hardware::radio::V1_5::BarringInfo> barringInfos;

    RadioResponse_v1_6(RadioHidlTest_v1_6& parent_v1_6);
    RadioResponse_v1_6(RadioResponseWaiter& parent_v1_6);
    virtual ~RadioResponse_v1_6() = default;

    Return<void> getIccCardStatusResponse(
@@ -1079,15 +1076,9 @@ class RadioIndication_v1_6 : public ::android::hardware::radio::V1_6::IRadioIndi
};

// The main test class for Radio HIDL.
class RadioHidlTest_v1_6 : public ::testing::TestWithParam<std::string> {
class RadioHidlTest_v1_6 : public ::testing::TestWithParam<std::string>,
                           public RadioResponseWaiter {
  protected:
    std::mutex mtx_;
    std::condition_variable cv_;
    int count_;

    /* Serial number for radio request */
    int serial;

    /* Clear Potential Established Calls */
    void clearPotentialEstablishedCalls();

@@ -1100,11 +1091,7 @@ class RadioHidlTest_v1_6 : public ::testing::TestWithParam<std::string> {
  public:
    virtual void SetUp() override;

    /* Used as a mechanism to inform the test about data/event callback */
    void notify(int receivedSerial);

    /* Test code calls this function to wait for response */
    std::cv_status wait();
    HalDeviceCapabilities getRadioHalCapabilities();

    /* radio service handle */
    sp<::android::hardware::radio::V1_6::IRadio> radio_v1_6;
Loading