From 244423c76b4afe649eec4194ced19a36c5c66472 Mon Sep 17 00:00:00 2001 From: Nathan Harold Date: Wed, 22 Dec 2021 13:27:36 -0800 Subject: [PATCH] VTS for UsageSetting Add tests to check that usage setting can be retrived and set as well as ensuring that invalid values cannot be set. Bug: 205595503 Test: make VtsHalRadioTargetTest Change-Id: I26a68d4b6be4810fab9302b58a3be7f65fc82c83 --- radio/aidl/vts/radio_network_response.cpp | 12 ++- radio/aidl/vts/radio_network_test.cpp | 112 +++++++++++++++++++++- radio/aidl/vts/radio_network_utils.h | 7 ++ 3 files changed, 126 insertions(+), 5 deletions(-) diff --git a/radio/aidl/vts/radio_network_response.cpp b/radio/aidl/vts/radio_network_response.cpp index 64f85c6bab..b242341960 100644 --- a/radio/aidl/vts/radio_network_response.cpp +++ b/radio/aidl/vts/radio_network_response.cpp @@ -96,8 +96,11 @@ ndk::ScopedAStatus RadioNetworkResponse::getSystemSelectionChannelsResponse( return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus RadioNetworkResponse::getUsageSettingResponse( - const RadioResponseInfo& /*info*/, const UsageSetting /*usageSetting*/) { +ndk::ScopedAStatus RadioNetworkResponse::getUsageSettingResponse(const RadioResponseInfo& info, + const UsageSetting usageSetting) { + rspInfo = info; + this->usageSetting = usageSetting; + parent_network.notify(info.serial); return ndk::ScopedAStatus::ok(); } @@ -195,8 +198,9 @@ ndk::ScopedAStatus RadioNetworkResponse::setSystemSelectionChannelsResponse( return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus RadioNetworkResponse::setUsageSettingResponse( - const RadioResponseInfo& /*info*/) { +ndk::ScopedAStatus RadioNetworkResponse::setUsageSettingResponse(const RadioResponseInfo& info) { + rspInfo = info; + parent_network.notify(info.serial); return ndk::ScopedAStatus::ok(); } diff --git a/radio/aidl/vts/radio_network_test.cpp b/radio/aidl/vts/radio_network_test.cpp index a8f87fc6ed..1cdbb6dca8 100644 --- a/radio/aidl/vts/radio_network_test.cpp +++ b/radio/aidl/vts/radio_network_test.cpp @@ -146,4 +146,114 @@ TEST_P(RadioNetworkTest, isNrDualConnectivityEnabled) { radioRsp_network->rspInfo.error, {RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR, RadioError::NONE})); } -} \ No newline at end of file +} + +void RadioNetworkTest::invokeAndExpectResponse( + std::function request, + std::vector errors_to_check) { + serial = GetRandomSerialNumber(); + + ndk::ScopedAStatus res = request(serial); + ASSERT_OK(res); + + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_network->rspInfo.type); + EXPECT_EQ(serial, radioRsp_network->rspInfo.serial); + ASSERT_TRUE(CheckAnyOfErrors(radioRsp_network->rspInfo.error, errors_to_check)); +} + +/* + * Test IRadioNetwork.getUsageSetting() + * + * Verify that the usage setting can be retrieved. + */ +TEST_P(RadioNetworkTest, getUsageSetting) { + invokeAndExpectResponse([&](int serial) { return radio_network->getUsageSetting(serial); }, + {RadioError::RADIO_NOT_AVAILABLE, RadioError::INVALID_STATE, + RadioError::SIM_ABSENT, RadioError::INTERNAL_ERR, RadioError::NONE}); + + ASSERT_TRUE(radioRsp_network->usageSetting == UsageSetting::VOICE_CENTRIC || + radioRsp_network->usageSetting == UsageSetting::DATA_CENTRIC); +} + +void RadioNetworkTest::testSetUsageSetting_InvalidValues(std::vector errors) { + invokeAndExpectResponse( + [&](int serial) { + return radio_network->setUsageSetting(serial, + UsageSetting(0) /*below valid range*/); + }, + errors); + invokeAndExpectResponse( + [&](int serial) { + return radio_network->setUsageSetting(serial, UsageSetting(-1) /*negative*/); + }, + errors); + invokeAndExpectResponse( + [&](int serial) { + return radio_network->setUsageSetting(serial, + UsageSetting(3) /*above valid range*/); + }, + errors); +} + +/* + * Test IRadioNetwork.setUsageSetting() and IRadioNetwork.getUsageSetting() + * + * Verify the following: + * -That the usage setting can be retrieved. + * -That the usage setting can be successfully set to allowed values. + * -That the usage setting cannot be set to invalid values. + */ +TEST_P(RadioNetworkTest, setUsageSetting) { + invokeAndExpectResponse([&](int serial) { return radio_network->getUsageSetting(serial); }, + {RadioError::RADIO_NOT_AVAILABLE, RadioError::INVALID_STATE, + RadioError::SIM_ABSENT, RadioError::INTERNAL_ERR, RadioError::NONE}); + + if (radioRsp_network->rspInfo.error != RadioError::NONE) { + // Test only for invalid values, with the only allowable response being the same error + // that was previously provided, or an error indicating invalid arguments. + testSetUsageSetting_InvalidValues( + {radioRsp_network->rspInfo.error, RadioError::INVALID_ARGUMENTS}); + // It is unsafe to proceed with setting valid values without knowing the starting value, but + // we expect errors anyway, so not necessary. + return; + } else { + // Because querying succeeded, the device is in a valid state to test for invalid values + // and the only thing that can change is that we expect to have an EINVAL return each time. + testSetUsageSetting_InvalidValues({RadioError::INVALID_ARGUMENTS}); + } + + // Store the original setting value to reset later. + const UsageSetting originalSetting = radioRsp_network->usageSetting; + + // Choose the "other" value that is not the current value for test. + const UsageSetting testSetting = radioRsp_network->usageSetting == UsageSetting::VOICE_CENTRIC + ? UsageSetting::DATA_CENTRIC + : UsageSetting::VOICE_CENTRIC; + + // Set an alternative setting; it may either succeed or be disallowed as out of range for + // the current device (if the device only supports its current mode). + invokeAndExpectResponse( + [&](int serial) { return radio_network->setUsageSetting(serial, testSetting); }, + {RadioError::INVALID_ARGUMENTS, RadioError::NONE}); + + // If there was no error, then we expect the test setting to be set, or if there is an error + // we expect the original setting to be maintained. + const UsageSetting expectedSetting = + radioRsp_network->rspInfo.error == RadioError::NONE ? testSetting : originalSetting; + invokeAndExpectResponse([&](int serial) { return radio_network->getUsageSetting(serial); }, + {RadioError::NONE}); + + const UsageSetting updatedSetting = radioRsp_network->usageSetting; + + // Re-set the original setting, which must always succeed. + invokeAndExpectResponse( + [&](int serial) { return radio_network->setUsageSetting(serial, originalSetting); }, + {RadioError::NONE}); + + // Check that indeed the updated setting was set. We do this after resetting to original + // conditions to avoid early-exiting the test and leaving the device in a modified state. + ASSERT_TRUE(expectedSetting == updatedSetting); + // Check that indeed the original setting was reset. + ASSERT_TRUE(originalSetting == radioRsp_network->usageSetting); +} diff --git a/radio/aidl/vts/radio_network_utils.h b/radio/aidl/vts/radio_network_utils.h index 26fce016b2..caa1ecc62a 100644 --- a/radio/aidl/vts/radio_network_utils.h +++ b/radio/aidl/vts/radio_network_utils.h @@ -43,6 +43,7 @@ class RadioNetworkResponse : public BnRadioNetworkResponse { RegStateResult regStateResp; CellIdentity barringCellIdentity; std::vector barringInfos; + UsageSetting usageSetting; virtual ndk::ScopedAStatus acknowledgeRequest(int32_t serial) override; @@ -211,4 +212,10 @@ class RadioNetworkTest : public ::testing::TestWithParam, public Ra std::shared_ptr radioRsp_network; /* radio network indication handle */ std::shared_ptr radioInd_network; + + void invokeAndExpectResponse(std::function request, + std::vector errors_to_check); + + // Helper function to reduce copy+paste + void testSetUsageSetting_InvalidValues(std::vector errors); };