From 15df27e428e83018850bea9f8b20cc0840a8d509 Mon Sep 17 00:00:00 2001 From: Jordan Liu Date: Wed, 29 May 2019 11:06:16 -0700 Subject: [PATCH] Add radio config 1.2 VTS tests Bug: 122730535 Test: run vts -m VtsHalRadioConfigV1_2Target Change-Id: Ib4fc17ea9f76caaf0cb0d4a2914595b7cfb7b041 --- radio/config/1.2/vts/functional/Android.bp | 35 +++++ .../VtsHalRadioConfigV1_2TargetTest.cpp | 26 ++++ .../functional/radio_config_hidl_hal_api.cpp | 30 ++++ .../functional/radio_config_hidl_hal_test.cpp | 66 +++++++++ .../functional/radio_config_hidl_hal_utils.h | 140 ++++++++++++++++++ .../functional/radio_config_indication.cpp | 25 ++++ .../vts/functional/radio_config_response.cpp | 66 +++++++++ 7 files changed, 388 insertions(+) create mode 100644 radio/config/1.2/vts/functional/Android.bp create mode 100644 radio/config/1.2/vts/functional/VtsHalRadioConfigV1_2TargetTest.cpp create mode 100644 radio/config/1.2/vts/functional/radio_config_hidl_hal_api.cpp create mode 100644 radio/config/1.2/vts/functional/radio_config_hidl_hal_test.cpp create mode 100644 radio/config/1.2/vts/functional/radio_config_hidl_hal_utils.h create mode 100644 radio/config/1.2/vts/functional/radio_config_indication.cpp create mode 100644 radio/config/1.2/vts/functional/radio_config_response.cpp diff --git a/radio/config/1.2/vts/functional/Android.bp b/radio/config/1.2/vts/functional/Android.bp new file mode 100644 index 0000000000..0cafc24160 --- /dev/null +++ b/radio/config/1.2/vts/functional/Android.bp @@ -0,0 +1,35 @@ +// +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +cc_test { + name: "VtsHalRadioConfigV1_2TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: [ + "radio_config_hidl_hal_api.cpp", + "radio_config_hidl_hal_test.cpp", + "radio_config_response.cpp", + "radio_config_indication.cpp", + "VtsHalRadioConfigV1_2TargetTest.cpp", + ], + static_libs: [ + "RadioVtsTestUtilBase", + "android.hardware.radio.config@1.0", + "android.hardware.radio.config@1.1", + "android.hardware.radio.config@1.2", + ], + header_libs: ["radio.util.header@1.0"], + test_suites: ["general-tests"], +} diff --git a/radio/config/1.2/vts/functional/VtsHalRadioConfigV1_2TargetTest.cpp b/radio/config/1.2/vts/functional/VtsHalRadioConfigV1_2TargetTest.cpp new file mode 100644 index 0000000000..ec6544e659 --- /dev/null +++ b/radio/config/1.2/vts/functional/VtsHalRadioConfigV1_2TargetTest.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +int main(int argc, char** argv) { + ::testing::AddGlobalTestEnvironment(RadioConfigHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + RadioConfigHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; +} diff --git a/radio/config/1.2/vts/functional/radio_config_hidl_hal_api.cpp b/radio/config/1.2/vts/functional/radio_config_hidl_hal_api.cpp new file mode 100644 index 0000000000..a3729aca2f --- /dev/null +++ b/radio/config/1.2/vts/functional/radio_config_hidl_hal_api.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) + +/* + * Test IRadioConfig.getSimSlotsStatus() + */ +TEST_F(RadioConfigHidlTest, getSimSlotsStatus) { + const int serial = GetRandomSerialNumber(); + Return res = radioConfig->getSimSlotsStatus(serial); + ASSERT_OK(res); + ALOGI("getIccSlotsStatus, rspInfo.error = %s\n", + toString(radioConfigRsp->rspInfo.error).c_str()); +} diff --git a/radio/config/1.2/vts/functional/radio_config_hidl_hal_test.cpp b/radio/config/1.2/vts/functional/radio_config_hidl_hal_test.cpp new file mode 100644 index 0000000000..cd7a1726aa --- /dev/null +++ b/radio/config/1.2/vts/functional/radio_config_hidl_hal_test.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +void RadioConfigHidlTest::SetUp() { + radioConfig = ::testing::VtsHalHidlTargetTestBase::getService( + RadioConfigHidlEnvironment::Instance()->getServiceName( + hidl_string(RADIO_SERVICE_NAME))); + if (radioConfig == NULL) { + sleep(60); + radioConfig = ::testing::VtsHalHidlTargetTestBase::getService( + RadioConfigHidlEnvironment::Instance()->getServiceName( + hidl_string(RADIO_SERVICE_NAME))); + } + ASSERT_NE(nullptr, radioConfig.get()); + + radioConfigRsp = new (std::nothrow) RadioConfigResponse(*this); + ASSERT_NE(nullptr, radioConfigRsp.get()); + + count_ = 0; + + radioConfig->setResponseFunctions(radioConfigRsp, nullptr); +} + +/* + * Notify that the response message is received. + */ +void RadioConfigHidlTest::notify(int receivedSerial) { + std::unique_lock 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 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; +} diff --git a/radio/config/1.2/vts/functional/radio_config_hidl_hal_utils.h b/radio/config/1.2/vts/functional/radio_config_hidl_hal_utils.h new file mode 100644 index 0000000000..a876766b48 --- /dev/null +++ b/radio/config/1.2/vts/functional/radio_config_hidl_hal_utils.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "vts_test_util.h" + +using namespace ::android::hardware::radio::config::V1_2; + +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_1::IRadioConfig; +using ::android::hardware::radio::config::V1_1::ModemsConfig; +using ::android::hardware::radio::config::V1_1::PhoneCapability; +using ::android::hardware::radio::config::V1_2::SimSlotStatus; +using ::android::hardware::radio::V1_0::RadioResponseInfo; +using ::android::hardware::radio::V1_0::RadioResponseType; + +#define TIMEOUT_PERIOD 75 +#define RADIO_SERVICE_NAME "slot1" + +class RadioConfigHidlTest; + +/* Callback class for radio config response */ +class RadioConfigResponse : public IRadioConfigResponse { + protected: + RadioConfigHidlTest& parent; + + public: + RadioResponseInfo rspInfo; + PhoneCapability phoneCap; + + RadioConfigResponse(RadioConfigHidlTest& parent); + virtual ~RadioConfigResponse() = default; + + Return getSimSlotsStatusResponse( + const RadioResponseInfo& info, + const ::android::hardware::hidl_vec< + ::android::hardware::radio::config::V1_0::SimSlotStatus>& slotStatus); + + Return getSimSlotsStatusResponse_1_2( + const RadioResponseInfo& info, + const ::android::hardware::hidl_vec& slotStatus); + + Return setSimSlotsMappingResponse(const RadioResponseInfo& info); + + Return getPhoneCapabilityResponse(const RadioResponseInfo& info, + const PhoneCapability& phoneCapability); + + Return setPreferredDataModemResponse(const RadioResponseInfo& info); + + Return getModemsConfigResponse(const RadioResponseInfo& info, + const ModemsConfig& mConfig); + + Return setModemsConfigResponse(const RadioResponseInfo& info); +}; + +/* Callback class for radio config indication */ +class RadioConfigIndication : public IRadioConfigIndication { + protected: + RadioConfigHidlTest& parent; + + public: + RadioConfigIndication(RadioConfigHidlTest& parent); + virtual ~RadioConfigIndication() = default; + + Return simSlotsStatusChanged_1_2( + ::android::hardware::radio::V1_0::RadioIndicationType type, + const ::android::hardware::hidl_vec& slotStatus); +}; + +// Test environment for Radio HIDL HAL. +class RadioConfigHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static RadioConfigHidlEnvironment* Instance() { + static RadioConfigHidlEnvironment* instance = new RadioConfigHidlEnvironment; + return instance; + } + virtual void registerTestServices() override { registerTestService(); } + + private: + RadioConfigHidlEnvironment() {} +}; + +// The main test class for Radio config HIDL. +class RadioConfigHidlTest : public ::testing::VtsHalHidlTargetTestBase { + protected: + std::mutex mtx_; + std::condition_variable cv_; + int count_; + + 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(); + + void updateSimCardStatus(); + + /* Serial number for radio request */ + int serial; + + /* radio config service handle */ + sp radioConfig; + + /* radio config response handle */ + sp radioConfigRsp; +}; diff --git a/radio/config/1.2/vts/functional/radio_config_indication.cpp b/radio/config/1.2/vts/functional/radio_config_indication.cpp new file mode 100644 index 0000000000..0bacacb363 --- /dev/null +++ b/radio/config/1.2/vts/functional/radio_config_indication.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +RadioConfigIndication::RadioConfigIndication(RadioConfigHidlTest& parent) : parent(parent) {} + +Return RadioConfigIndication::simSlotsStatusChanged_1_2( + ::android::hardware::radio::V1_0::RadioIndicationType /*type*/, + const ::android::hardware::hidl_vec& /*slotStatus*/) { + return Void(); +} diff --git a/radio/config/1.2/vts/functional/radio_config_response.cpp b/radio/config/1.2/vts/functional/radio_config_response.cpp new file mode 100644 index 0000000000..ec0f88662a --- /dev/null +++ b/radio/config/1.2/vts/functional/radio_config_response.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +using ::android::hardware::radio::V1_0::RadioResponseInfo; + +// SimSlotStatus slotStatus; + +RadioConfigResponse::RadioConfigResponse(RadioConfigHidlTest& parent) : parent(parent) {} + +Return RadioConfigResponse::getSimSlotsStatusResponse( + const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */, + const ::android::hardware::hidl_vec< + ::android::hardware::radio::config::V1_0::SimSlotStatus>& /* slotStatus */) { + return Void(); +} + +Return RadioConfigResponse::getSimSlotsStatusResponse_1_2( + const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */, + const ::android::hardware::hidl_vec& /* slotStatus */) { + return Void(); +} + +Return RadioConfigResponse::setSimSlotsMappingResponse( + const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */) { + return Void(); +} + +Return RadioConfigResponse::getPhoneCapabilityResponse( + const ::android::hardware::radio::V1_0::RadioResponseInfo& info, + const PhoneCapability& phoneCapability) { + rspInfo = info; + phoneCap = phoneCapability; + parent.notify(info.serial); + return Void(); +} + +Return RadioConfigResponse::setPreferredDataModemResponse( + const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */) { + return Void(); +} + +Return RadioConfigResponse::getModemsConfigResponse( + const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */, + const ModemsConfig& /* mConfig */) { + return Void(); +} + +Return RadioConfigResponse::setModemsConfigResponse( + const ::android::hardware::radio::V1_0::RadioResponseInfo& /* info */) { + return Void(); +}