Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 <android-base/logging.h> |
| 18 | #include <android/binder_manager.h> |
| 19 | |
| 20 | #include "radio_config_utils.h" |
| 21 | |
| 22 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 23 | |
| 24 | void RadioConfigTest::SetUp() { |
| 25 | std::string serviceName = GetParam(); |
| 26 | |
| 27 | if (!isServiceValidForDeviceConfiguration(serviceName)) { |
| 28 | ALOGI("Skipped the test due to device configuration."); |
| 29 | GTEST_SKIP(); |
| 30 | } |
| 31 | |
| 32 | radio_config = IRadioConfig::fromBinder( |
| 33 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 34 | ASSERT_NE(nullptr, radio_config.get()); |
| 35 | |
| 36 | radioRsp_config = ndk::SharedRefBase::make<RadioConfigResponse>(*this); |
| 37 | ASSERT_NE(nullptr, radioRsp_config.get()); |
| 38 | |
| 39 | count_ = 0; |
| 40 | |
| 41 | radioInd_config = ndk::SharedRefBase::make<RadioConfigIndication>(*this); |
| 42 | ASSERT_NE(nullptr, radioInd_config.get()); |
| 43 | |
| 44 | radio_config->setResponseFunctions(radioRsp_config, radioInd_config); |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Test IRadioConfig.getHalDeviceCapabilities() for the response returned. |
| 49 | */ |
| 50 | TEST_P(RadioConfigTest, getHalDeviceCapabilities) { |
| 51 | serial = GetRandomSerialNumber(); |
| 52 | ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial); |
| 53 | ASSERT_OK(res); |
| 54 | ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n", |
| 55 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 56 | } |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame^] | 57 | |
| 58 | /* |
| 59 | * Test IRadioConfig.getSimSlotsStatus() for the response returned. |
| 60 | */ |
| 61 | TEST_P(RadioConfigTest, getSimSlotsStatus) { |
| 62 | serial = GetRandomSerialNumber(); |
| 63 | ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial); |
| 64 | ASSERT_OK(res); |
| 65 | ALOGI("getSimSlotsStatus, rspInfo.error = %s\n", |
| 66 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Test IRadioConfig.getPhoneCapability() for the response returned. |
| 71 | */ |
| 72 | TEST_P(RadioConfigTest, getPhoneCapability) { |
| 73 | serial = GetRandomSerialNumber(); |
| 74 | ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial); |
| 75 | ASSERT_OK(res); |
| 76 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 77 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 78 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 79 | ALOGI("getPhoneCapability, rspInfo.error = %s\n", |
| 80 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 81 | |
| 82 | ASSERT_TRUE(CheckAnyOfErrors( |
| 83 | radioRsp_config->rspInfo.error, |
| 84 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 85 | |
| 86 | if (radioRsp_config->rspInfo.error == RadioError ::NONE) { |
| 87 | // maxActiveData should be greater than or equal to maxActiveInternetData. |
| 88 | EXPECT_GE(radioRsp_config->phoneCap.maxActiveData, |
| 89 | radioRsp_config->phoneCap.maxActiveInternetData); |
| 90 | // maxActiveData and maxActiveInternetData should be 0 or positive numbers. |
| 91 | EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * Test IRadioConfig.setPreferredDataModem() for the response returned. |
| 97 | */ |
| 98 | TEST_P(RadioConfigTest, setPreferredDataModem) { |
| 99 | serial = GetRandomSerialNumber(); |
| 100 | ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial); |
| 101 | ASSERT_OK(res); |
| 102 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 103 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 104 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 105 | ALOGI("getPhoneCapability, rspInfo.error = %s\n", |
| 106 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 107 | |
| 108 | ASSERT_TRUE(CheckAnyOfErrors( |
| 109 | radioRsp_config->rspInfo.error, |
| 110 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 111 | |
| 112 | if (radioRsp_config->rspInfo.error != RadioError ::NONE) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) { |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | // We get phoneCapability. Send setPreferredDataModem command |
| 121 | serial = GetRandomSerialNumber(); |
| 122 | uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0]; |
| 123 | res = radio_config->setPreferredDataModem(serial, modemId); |
| 124 | |
| 125 | ASSERT_OK(res); |
| 126 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 127 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 128 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 129 | ALOGI("setPreferredDataModem, rspInfo.error = %s\n", |
| 130 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 131 | |
| 132 | ASSERT_TRUE(CheckAnyOfErrors( |
| 133 | radioRsp_config->rspInfo.error, |
| 134 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Test IRadioConfig.setPreferredDataModem() with invalid arguments. |
| 139 | */ |
| 140 | TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) { |
| 141 | serial = GetRandomSerialNumber(); |
| 142 | uint8_t modemId = -1; |
| 143 | ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId); |
| 144 | |
| 145 | ASSERT_OK(res); |
| 146 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 147 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 148 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 149 | ALOGI("setPreferredDataModem, rspInfo.error = %s\n", |
| 150 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 151 | |
| 152 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, |
| 153 | {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE, |
| 154 | RadioError::INTERNAL_ERR})); |
| 155 | } |