Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -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 <aidl/android/hardware/radio/config/IRadioConfig.h> |
| 18 | #include <android-base/logging.h> |
| 19 | #include <android/binder_manager.h> |
| 20 | |
| 21 | #include "radio_modem_utils.h" |
| 22 | |
| 23 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 24 | |
| 25 | void RadioModemTest::SetUp() { |
| 26 | std::string serviceName = GetParam(); |
| 27 | |
| 28 | if (!isServiceValidForDeviceConfiguration(serviceName)) { |
| 29 | ALOGI("Skipped the test due to device configuration."); |
| 30 | GTEST_SKIP(); |
| 31 | } |
| 32 | |
| 33 | radio_modem = IRadioModem::fromBinder( |
| 34 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 35 | ASSERT_NE(nullptr, radio_modem.get()); |
| 36 | |
| 37 | radioRsp_modem = ndk::SharedRefBase::make<RadioModemResponse>(*this); |
| 38 | ASSERT_NE(nullptr, radioRsp_modem.get()); |
| 39 | |
| 40 | count_ = 0; |
| 41 | |
| 42 | radioInd_modem = ndk::SharedRefBase::make<RadioModemIndication>(*this); |
| 43 | ASSERT_NE(nullptr, radioInd_modem.get()); |
| 44 | |
| 45 | radio_modem->setResponseFunctions(radioRsp_modem, radioInd_modem); |
| 46 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 47 | // Assert IRadioSim exists and SIM is present before testing |
| 48 | radio_sim = sim::IRadioSim::fromBinder(ndk::SpAIBinder( |
| 49 | AServiceManager_waitForService("android.hardware.radio.sim.IRadioSim/slot1"))); |
| 50 | ASSERT_NE(nullptr, radio_sim.get()); |
| 51 | updateSimCardStatus(); |
| 52 | EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState); |
| 53 | |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 54 | // Assert IRadioConfig exists before testing |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 55 | radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder( |
| 56 | AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default"))); |
| 57 | ASSERT_NE(nullptr, radio_config.get()); |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Test IRadioModem.setRadioPower() for the response returned. |
| 62 | */ |
| 63 | TEST_P(RadioModemTest, setRadioPower_emergencyCall_cancelled) { |
| 64 | // Set radio power to off. |
| 65 | serial = GetRandomSerialNumber(); |
| 66 | radio_modem->setRadioPower(serial, false, false, false); |
| 67 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 68 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 69 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 70 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 71 | |
| 72 | // Set radio power to on with forEmergencyCall being true. This should put modem to only scan |
| 73 | // emergency call bands. |
| 74 | serial = GetRandomSerialNumber(); |
| 75 | radio_modem->setRadioPower(serial, true, true, true); |
| 76 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 77 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 78 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 79 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 80 | |
| 81 | // Set radio power to on with forEmergencyCall being false. This should put modem in regular |
| 82 | // operation modem. |
| 83 | serial = GetRandomSerialNumber(); |
| 84 | radio_modem->setRadioPower(serial, true, false, false); |
| 85 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 86 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 87 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 88 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 89 | } |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame^] | 90 | |
| 91 | /* |
| 92 | * Test IRadioModem.enableModem() for the response returned. |
| 93 | */ |
| 94 | TEST_P(RadioModemTest, enableModem) { |
| 95 | serial = GetRandomSerialNumber(); |
| 96 | |
| 97 | if (isSsSsEnabled()) { |
| 98 | ALOGI("enableModem, no need to test in single SIM mode"); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | bool responseToggle = radioRsp_modem->enableModemResponseToggle; |
| 103 | ndk::ScopedAStatus res = radio_modem->enableModem(serial, true); |
| 104 | ASSERT_OK(res); |
| 105 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 106 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 107 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 108 | ALOGI("getModemStackStatus, rspInfo.error = %s\n", |
| 109 | toString(radioRsp_modem->rspInfo.error).c_str()); |
| 110 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 111 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, |
| 112 | RadioError::MODEM_ERR, RadioError::INVALID_STATE})); |
| 113 | |
| 114 | // checking if getModemStackStatus returns true, as modem was enabled above |
| 115 | if (RadioError::NONE == radioRsp_modem->rspInfo.error) { |
| 116 | // wait until modem enabling is finished |
| 117 | while (responseToggle == radioRsp_modem->enableModemResponseToggle) { |
| 118 | sleep(1); |
| 119 | } |
| 120 | ndk::ScopedAStatus resEnabled = radio_modem->getModemStackStatus(serial); |
| 121 | ASSERT_OK(resEnabled); |
| 122 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 123 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 124 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 125 | ALOGI("getModemStackStatus, rspInfo.error = %s\n", |
| 126 | toString(radioRsp_modem->rspInfo.error).c_str()); |
| 127 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 128 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, |
| 129 | RadioError::MODEM_ERR, RadioError::INVALID_STATE})); |
| 130 | // verify that enableModem did set isEnabled correctly |
| 131 | EXPECT_EQ(true, radioRsp_modem->isModemEnabled); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Test IRadioModem.getModemStackStatus() for the response returned. |
| 137 | */ |
| 138 | TEST_P(RadioModemTest, getModemStackStatus) { |
| 139 | serial = GetRandomSerialNumber(); |
| 140 | |
| 141 | ndk::ScopedAStatus res = radio_modem->getModemStackStatus(serial); |
| 142 | ASSERT_OK(res); |
| 143 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 144 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 145 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 146 | ALOGI("getModemStackStatus, rspInfo.error = %s\n", |
| 147 | toString(radioRsp_modem->rspInfo.error).c_str()); |
| 148 | ASSERT_TRUE(CheckAnyOfErrors( |
| 149 | radioRsp_modem->rspInfo.error, |
| 150 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR})); |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Test IRadioModem.getBasebandVersion() for the response returned. |
| 155 | */ |
| 156 | TEST_P(RadioModemTest, getBasebandVersion) { |
| 157 | LOG(DEBUG) << "getBasebandVersion"; |
| 158 | serial = GetRandomSerialNumber(); |
| 159 | |
| 160 | radio_modem->getBasebandVersion(serial); |
| 161 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 162 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 163 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 164 | |
| 165 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 166 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 167 | } |
| 168 | LOG(DEBUG) << "getBasebandVersion finished"; |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Test IRadioModem.getDeviceIdentity() for the response returned. |
| 173 | */ |
| 174 | TEST_P(RadioModemTest, getDeviceIdentity) { |
| 175 | LOG(DEBUG) << "getDeviceIdentity"; |
| 176 | serial = GetRandomSerialNumber(); |
| 177 | |
| 178 | radio_modem->getDeviceIdentity(serial); |
| 179 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 180 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 181 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 182 | |
| 183 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 184 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 185 | {RadioError::NONE, RadioError::EMPTY_RECORD})); |
| 186 | } |
| 187 | LOG(DEBUG) << "getDeviceIdentity finished"; |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Test IRadioModem.nvReadItem() for the response returned. |
| 192 | */ |
| 193 | TEST_P(RadioModemTest, nvReadItem) { |
| 194 | LOG(DEBUG) << "nvReadItem"; |
| 195 | serial = GetRandomSerialNumber(); |
| 196 | |
| 197 | radio_modem->nvReadItem(serial, NvItem::LTE_BAND_ENABLE_25); |
| 198 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 199 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 200 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 201 | |
| 202 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 203 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE}, |
| 204 | CHECK_GENERAL_ERROR)); |
| 205 | } |
| 206 | LOG(DEBUG) << "nvReadItem finished"; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Test IRadioModem.nvWriteItem() for the response returned. |
| 211 | */ |
| 212 | TEST_P(RadioModemTest, nvWriteItem) { |
| 213 | LOG(DEBUG) << "nvWriteItem"; |
| 214 | serial = GetRandomSerialNumber(); |
| 215 | NvWriteItem item; |
| 216 | memset(&item, 0, sizeof(item)); |
| 217 | item.value = std::string(); |
| 218 | |
| 219 | radio_modem->nvWriteItem(serial, item); |
| 220 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 221 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 222 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 223 | |
| 224 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 225 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE}, |
| 226 | CHECK_GENERAL_ERROR)); |
| 227 | } |
| 228 | LOG(DEBUG) << "nvWriteItem finished"; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Test IRadioModem.nvWriteCdmaPrl() for the response returned. |
| 233 | */ |
| 234 | TEST_P(RadioModemTest, nvWriteCdmaPrl) { |
| 235 | LOG(DEBUG) << "nvWriteCdmaPrl"; |
| 236 | serial = GetRandomSerialNumber(); |
| 237 | std::vector<uint8_t> prl = {1, 2, 3, 4, 5}; |
| 238 | |
| 239 | radio_modem->nvWriteCdmaPrl(serial, std::vector<uint8_t>(prl)); |
| 240 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 241 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 242 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 243 | |
| 244 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 245 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE}, |
| 246 | CHECK_GENERAL_ERROR)); |
| 247 | } |
| 248 | LOG(DEBUG) << "nvWriteCdmaPrl finished"; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Test IRadioModem.nvResetConfig() for the response returned. |
| 253 | */ |
| 254 | TEST_P(RadioModemTest, nvResetConfig) { |
| 255 | LOG(DEBUG) << "nvResetConfig"; |
| 256 | serial = GetRandomSerialNumber(); |
| 257 | |
| 258 | radio_modem->nvResetConfig(serial, ResetNvType::FACTORY_RESET); |
| 259 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 260 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 261 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 262 | |
| 263 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 264 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 265 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED})); |
| 266 | } |
| 267 | LOG(DEBUG) << "nvResetConfig finished"; |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Test IRadioModem.getHardwareConfig() for the response returned. |
| 272 | */ |
| 273 | TEST_P(RadioModemTest, getHardwareConfig) { |
| 274 | LOG(DEBUG) << "getHardwareConfig"; |
| 275 | serial = GetRandomSerialNumber(); |
| 276 | |
| 277 | radio_modem->getHardwareConfig(serial); |
| 278 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 279 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 280 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 281 | |
| 282 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 283 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE}, |
| 284 | CHECK_GENERAL_ERROR)); |
| 285 | } |
| 286 | LOG(DEBUG) << "getHardwareConfig finished"; |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * The following test is disabled due to b/64734869 |
| 291 | * |
| 292 | * Test IRadioModem.requestShutdown() for the response returned. |
| 293 | */ |
| 294 | TEST_P(RadioModemTest, DISABLED_requestShutdown) { |
| 295 | serial = GetRandomSerialNumber(); |
| 296 | |
| 297 | radio_modem->requestShutdown(serial); |
| 298 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 299 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 300 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 301 | |
| 302 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 303 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE}, |
| 304 | CHECK_GENERAL_ERROR)); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Test IRadioModem.getRadioCapability() for the response returned. |
| 310 | */ |
| 311 | TEST_P(RadioModemTest, getRadioCapability) { |
| 312 | LOG(DEBUG) << "getRadioCapability"; |
| 313 | serial = GetRandomSerialNumber(); |
| 314 | |
| 315 | radio_modem->getRadioCapability(serial); |
| 316 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 317 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 318 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 319 | |
| 320 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 321 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 322 | } |
| 323 | LOG(DEBUG) << "getRadioCapability finished"; |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * Test IRadioModem.setRadioCapability() for the response returned. |
| 328 | */ |
| 329 | TEST_P(RadioModemTest, setRadioCapability) { |
| 330 | LOG(DEBUG) << "setRadioCapability"; |
| 331 | serial = GetRandomSerialNumber(); |
| 332 | RadioCapability rc; |
| 333 | memset(&rc, 0, sizeof(rc)); |
| 334 | rc.logicalModemUuid = std::string(); |
| 335 | |
| 336 | radio_modem->setRadioCapability(serial, rc); |
| 337 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 338 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 339 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 340 | |
| 341 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 342 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 343 | {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE}, |
| 344 | CHECK_GENERAL_ERROR)); |
| 345 | } |
| 346 | LOG(DEBUG) << "setRadioCapability finished"; |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * Test IRadioModem.getModemActivityInfo() for the response returned. |
| 351 | */ |
| 352 | TEST_P(RadioModemTest, getModemActivityInfo) { |
| 353 | LOG(DEBUG) << "getModemActivityInfo"; |
| 354 | serial = GetRandomSerialNumber(); |
| 355 | |
| 356 | radio_modem->getModemActivityInfo(serial); |
| 357 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 358 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 359 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 360 | |
| 361 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 362 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 363 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED})); |
| 364 | } |
| 365 | LOG(DEBUG) << "getModemActivityInfo finished"; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Test IRadioModem.sendDeviceState() for the response returned. |
| 370 | */ |
| 371 | TEST_P(RadioModemTest, sendDeviceState) { |
| 372 | LOG(DEBUG) << "sendDeviceState"; |
| 373 | serial = GetRandomSerialNumber(); |
| 374 | |
| 375 | radio_modem->sendDeviceState(serial, DeviceStateType::POWER_SAVE_MODE, true); |
| 376 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 377 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 378 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 379 | |
| 380 | std::cout << static_cast<int>(radioRsp_modem->rspInfo.error) << std::endl; |
| 381 | |
| 382 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 383 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, |
| 384 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED})); |
| 385 | } |
| 386 | LOG(DEBUG) << "sendDeviceState finished"; |
| 387 | } |