Merge "Get Radio Hal Capabilities in VTS"

This commit is contained in:
Treehugger Robot 2021-03-09 17:58:46 +00:00 committed by Gerrit Code Review
commit 26629e8698
10 changed files with 134 additions and 105 deletions

View file

@ -19,6 +19,8 @@
#include <iostream> #include <iostream>
#include "VtsCoreUtil.h" #include "VtsCoreUtil.h"
#define WAIT_TIMEOUT_PERIOD 75
int GetRandomSerialNumber() { int GetRandomSerialNumber() {
return rand(); return rand();
} }
@ -99,4 +101,33 @@ bool isVoiceEmergencyOnly(RegState state) {
::android::hardware::radio::V1_0::RegState::NOT_REG_MT_SEARCHING_OP_EM == state || ::android::hardware::radio::V1_0::RegState::NOT_REG_MT_SEARCHING_OP_EM == state ||
::android::hardware::radio::V1_0::RegState::REG_DENIED_EM == state || ::android::hardware::radio::V1_0::RegState::REG_DENIED_EM == state ||
::android::hardware::radio::V1_0::RegState::UNKNOWN_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;
}

View file

@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#pragma once
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/hardware/radio/1.0/types.h> #include <android/hardware/radio/1.0/types.h>
@ -81,4 +83,24 @@ bool isVoiceEmergencyOnly(RegState state);
/* /*
* Check if voice status is in service. * Check if voice status is in service.
*/ */
bool isVoiceInService(RegState state); 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();
};

View file

@ -36,6 +36,7 @@ cc_test {
], ],
static_libs: [ static_libs: [
"RadioVtsTestUtilBase", "RadioVtsTestUtilBase",
"RadioConfigVtsTestResponse",
"android.hardware.radio@1.6", "android.hardware.radio@1.6",
"android.hardware.radio@1.5", "android.hardware.radio@1.5",
"android.hardware.radio@1.4", "android.hardware.radio@1.4",
@ -45,8 +46,13 @@ cc_test {
"android.hardware.radio@1.0", "android.hardware.radio@1.0",
"android.hardware.radio.config@1.0", "android.hardware.radio.config@1.0",
"android.hardware.radio.config@1.1", "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: [ test_suites: [
"general-tests", "general-tests",
"vts", "vts",

View file

@ -45,35 +45,6 @@ void RadioHidlTest_v1_6::SetUp() {
EXPECT_EQ(CardState::PRESENT, cardStatus.base.base.base.cardState); 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() { void RadioHidlTest_v1_6::clearPotentialEstablishedCalls() {
// Get the current call Id to hangup the established emergency call. // Get the current call Id to hangup the established emergency call.
serial = GetRandomSerialNumber(); serial = GetRandomSerialNumber();
@ -108,3 +79,31 @@ void RadioHidlTest_v1_6::getDataCallList() {
radio_v1_6->getDataCallList_1_6(serial); radio_v1_6->getDataCallList_1_6(serial);
EXPECT_EQ(std::cv_status::no_timeout, wait()); 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;
}
}

View file

@ -18,16 +18,12 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <gtest/gtest.h> #include "radio_config_hidl_hal_utils.h"
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <utils/Log.h>
#include <chrono> #include <chrono>
#include <condition_variable> #include <condition_variable>
#include <mutex> #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/IRadio.h>
#include <android/hardware/radio/1.6/IRadioIndication.h> #include <android/hardware/radio/1.6/IRadioIndication.h>
#include <android/hardware/radio/1.6/IRadioResponse.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_2;
using namespace ::android::hardware::radio::V1_1; using namespace ::android::hardware::radio::V1_1;
using namespace ::android::hardware::radio::V1_0; using namespace ::android::hardware::radio::V1_0;
using namespace ::android::hardware::radio::config::V1_3;
using ::android::sp; using ::android::sp;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; 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_ESTABLISH_TIME 3
#define MODEM_EMERGENCY_CALL_DISCONNECT_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 */ /* Callback class for radio response v1_6 */
class RadioResponse_v1_6 : public ::android::hardware::radio::V1_6::IRadioResponse { class RadioResponse_v1_6 : public ::android::hardware::radio::V1_6::IRadioResponse {
protected: protected:
RadioHidlTest_v1_6& parent_v1_6; RadioResponseWaiter& parent_v1_6;
public: public:
hidl_vec<RadioBandMode> radioBandModes; 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::radio::V1_5::CellIdentity barringCellIdentity;
::android::hardware::hidl_vec<::android::hardware::radio::V1_5::BarringInfo> barringInfos; ::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; virtual ~RadioResponse_v1_6() = default;
Return<void> getIccCardStatusResponse( 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. // 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: protected:
std::mutex mtx_;
std::condition_variable cv_;
int count_;
/* Serial number for radio request */
int serial;
/* Clear Potential Established Calls */ /* Clear Potential Established Calls */
void clearPotentialEstablishedCalls(); void clearPotentialEstablishedCalls();
@ -1100,11 +1091,7 @@ class RadioHidlTest_v1_6 : public ::testing::TestWithParam<std::string> {
public: public:
virtual void SetUp() override; virtual void SetUp() override;
/* Used as a mechanism to inform the test about data/event callback */ HalDeviceCapabilities getRadioHalCapabilities();
void notify(int receivedSerial);
/* Test code calls this function to wait for response */
std::cv_status wait();
/* radio service handle */ /* radio service handle */
sp<::android::hardware::radio::V1_6::IRadio> radio_v1_6; sp<::android::hardware::radio::V1_6::IRadio> radio_v1_6;

View file

@ -18,7 +18,7 @@
::android::hardware::radio::V1_5::CardStatus cardStatus; ::android::hardware::radio::V1_5::CardStatus cardStatus;
RadioResponse_v1_6::RadioResponse_v1_6(RadioHidlTest_v1_6& parent) : parent_v1_6(parent) {} RadioResponse_v1_6::RadioResponse_v1_6(RadioResponseWaiter& parent) : parent_v1_6(parent) {}
/* 1.0 Apis */ /* 1.0 Apis */
Return<void> RadioResponse_v1_6::getIccCardStatusResponse( Return<void> RadioResponse_v1_6::getIccCardStatusResponse(

View file

@ -46,3 +46,26 @@ cc_test {
"vts", "vts",
], ],
} }
cc_library_static {
name: "RadioConfigVtsTestResponse",
defaults: ["VtsHalTargetTestDefaults"],
srcs : [
"radio_config_response.cpp",
"radio_config_hidl_hal_test.cpp",
],
header_libs: ["radio.util.header@1.0"],
static_libs: ["RadioVtsTestUtilBase"],
shared_libs: [
"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",
],
}
cc_library_headers {
name: "radio.config.util.header@1.3",
export_include_dirs: ["."],
}

View file

@ -31,32 +31,3 @@ void RadioConfigHidlTest::SetUp() {
radioConfig->setResponseFunctions(radioConfigRsp, nullptr); radioConfig->setResponseFunctions(radioConfigRsp, nullptr);
} }
/*
* Notify that the response message is received.
*/
void RadioConfigHidlTest::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 RadioConfigHidlTest::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;
}

View file

@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#pragma once
#include <android-base/logging.h> #include <android-base/logging.h>
#include <chrono> #include <chrono>
@ -49,7 +51,6 @@ using ::android::hardware::radio::config::V1_3::HalDeviceCapabilities;
using ::android::hardware::radio::config::V1_3::IRadioConfig; using ::android::hardware::radio::config::V1_3::IRadioConfig;
using ::android::hardware::radio::V1_0::RadioResponseInfo; using ::android::hardware::radio::V1_0::RadioResponseInfo;
#define TIMEOUT_PERIOD 75
#define RADIO_SERVICE_NAME "slot1" #define RADIO_SERVICE_NAME "slot1"
class RadioConfigHidlTest; class RadioConfigHidlTest;
@ -57,13 +58,14 @@ class RadioConfigHidlTest;
/* Callback class for radio config response */ /* Callback class for radio config response */
class RadioConfigResponse : public IRadioConfigResponse { class RadioConfigResponse : public IRadioConfigResponse {
protected: protected:
RadioConfigHidlTest& parent; RadioResponseWaiter& parent;
public: public:
RadioResponseInfo rspInfo; RadioResponseInfo rspInfo;
PhoneCapability phoneCap; PhoneCapability phoneCap;
HalDeviceCapabilities halDeviceCapabilities;
RadioConfigResponse(RadioConfigHidlTest& parent); RadioConfigResponse(RadioResponseWaiter& parent);
virtual ~RadioConfigResponse() = default; virtual ~RadioConfigResponse() = default;
Return<void> getSimSlotsStatusResponse( Return<void> getSimSlotsStatusResponse(
@ -107,26 +109,13 @@ class RadioConfigIndication : public IRadioConfigIndication {
}; };
// The main test class for Radio config HIDL. // The main test class for Radio config HIDL.
class RadioConfigHidlTest : public ::testing::TestWithParam<std::string> { class RadioConfigHidlTest : public ::testing::TestWithParam<std::string>,
protected: public RadioResponseWaiter {
std::mutex mtx_;
std::condition_variable cv_;
int count_;
public: public:
virtual void SetUp() override; 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();
void updateSimCardStatus(); void updateSimCardStatus();
/* Serial number for radio request */
int serial;
/* radio config service handle */ /* radio config service handle */
sp<IRadioConfig> radioConfig; sp<IRadioConfig> radioConfig;

View file

@ -18,7 +18,7 @@
// SimSlotStatus slotStatus; // SimSlotStatus slotStatus;
RadioConfigResponse::RadioConfigResponse(RadioConfigHidlTest& parent) : parent(parent) {} RadioConfigResponse::RadioConfigResponse(RadioResponseWaiter& parent) : parent(parent) {}
Return<void> RadioConfigResponse::getSimSlotsStatusResponse( Return<void> RadioConfigResponse::getSimSlotsStatusResponse(
const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */, const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */,
@ -65,6 +65,7 @@ Return<void> RadioConfigResponse::setModemsConfigResponse(
Return<void> RadioConfigResponse::getHalDeviceCapabilitiesResponse( Return<void> RadioConfigResponse::getHalDeviceCapabilitiesResponse(
const ::android::hardware::radio::V1_6::RadioResponseInfo& /* info */, const ::android::hardware::radio::V1_6::RadioResponseInfo& /* info */,
const ::android::hardware::radio::config::V1_3::HalDeviceCapabilities& /* capabilities */) { const ::android::hardware::radio::config::V1_3::HalDeviceCapabilities& capabilities) {
halDeviceCapabilities = capabilities;
return Void(); return Void();
} }