From 1a55fff64be23cad1e305fa5a58e077228251783 Mon Sep 17 00:00:00 2001 From: Tim Lin Date: Thu, 7 Apr 2022 01:25:37 +0800 Subject: [PATCH 1/2] set SIM slots mapping based on current mapping If we set the SIM slots mapping arbitrarily on single SIM enabled device, the SIM state could become absent and cause other TCs fail. Bug: 227693614 Test: run vts -m VtsHalRadioTargetTest Change-Id: I2c8d3a162e1dca5a0bd6cfe93a1cc269f4c25188 Merged-In: I2c8d3a162e1dca5a0bd6cfe93a1cc269f4c25188 --- radio/aidl/vts/radio_config_test.cpp | 77 +++++++++++++++++++--------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/radio/aidl/vts/radio_config_test.cpp b/radio/aidl/vts/radio_config_test.cpp index 5e1c811d91..2309f9ef7e 100644 --- a/radio/aidl/vts/radio_config_test.cpp +++ b/radio/aidl/vts/radio_config_test.cpp @@ -166,31 +166,60 @@ TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) { * Test IRadioConfig.setSimSlotsMapping() for the response returned. */ TEST_P(RadioConfigTest, setSimSlotsMapping) { - serial = GetRandomSerialNumber(); - SlotPortMapping slotPortMapping; - slotPortMapping.physicalSlotId = 0; - slotPortMapping.portId = 0; - std::vector slotPortMappingList = {slotPortMapping}; - if (isDsDsEnabled()) { - slotPortMapping.physicalSlotId = 1; - slotPortMappingList.push_back(slotPortMapping); - } else if (isTsTsEnabled()) { - slotPortMapping.physicalSlotId = 1; - slotPortMappingList.push_back(slotPortMapping); - slotPortMapping.physicalSlotId = 2; - slotPortMappingList.push_back(slotPortMapping); - } - ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList); - ASSERT_OK(res); - EXPECT_EQ(std::cv_status::no_timeout, wait()); - EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); - EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); - ALOGI("setSimSlotsMapping, rspInfo.error = %s\n", - toString(radioRsp_config->rspInfo.error).c_str()); - ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE})); + // get slot status and set SIM slots mapping based on the result. + updateSimSlotStatus(); + if (radioRsp_config->rspInfo.error == RadioError::NONE) { + SlotPortMapping slotPortMapping; + // put invalid value at first and adjust by slotStatusResponse. + slotPortMapping.physicalSlotId = -1; + slotPortMapping.portId = -1; + std::vector slotPortMappingList = {slotPortMapping}; + if (isDsDsEnabled()) { + slotPortMappingList.push_back(slotPortMapping); + } else if (isTsTsEnabled()) { + slotPortMappingList.push_back(slotPortMapping); + slotPortMappingList.push_back(slotPortMapping); + } + for (size_t i = 0; i < radioRsp_config->simSlotStatus.size(); i++) { + ASSERT_TRUE(radioRsp_config->simSlotStatus[i].portInfo.size() > 0); + for (size_t j = 0; j < radioRsp_config->simSlotStatus[i].portInfo.size(); j++) { + if (radioRsp_config->simSlotStatus[i].portInfo[j].portActive) { + int32_t logicalSlotId = + radioRsp_config->simSlotStatus[i].portInfo[j].logicalSlotId; + // logicalSlotId should be 0 or positive numbers if the port + // is active. + EXPECT_GE(logicalSlotId, 0); + // logicalSlotId should be less than the maximum number of + // supported SIM slots. + EXPECT_LT(logicalSlotId, slotPortMappingList.size()); + if (logicalSlotId >= 0 && logicalSlotId < slotPortMappingList.size()) { + slotPortMappingList[logicalSlotId].physicalSlotId = i; + slotPortMappingList[logicalSlotId].portId = j; + } + } + } + } - // Give some time for modem to fully switch SIM configuration - sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS); + // set SIM slots mapping + for (size_t i = 0; i < slotPortMappingList.size(); i++) { + // physicalSlotId and portId should be 0 or positive numbers for the + // input of setSimSlotsMapping. + EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0); + EXPECT_GE(slotPortMappingList[i].portId, 0); + } + serial = GetRandomSerialNumber(); + ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList); + ASSERT_OK(res); + EXPECT_EQ(std::cv_status::no_timeout, wait()); + EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); + EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); + ALOGI("setSimSlotsMapping, rspInfo.error = %s\n", + toString(radioRsp_config->rspInfo.error).c_str()); + ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE})); + + // Give some time for modem to fully switch SIM configuration + sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS); + } } /* From 148303775a3e5248ce1e5a62e5edf4e14298ab49 Mon Sep 17 00:00:00 2001 From: Tim Lin Date: Fri, 8 Apr 2022 22:54:48 +0800 Subject: [PATCH 2/2] wait for response before running next TC All TCs store RadioResponseInfo in a shared variable and read it to verify the result. So there is race condition problem if we don't wait for responses. Bug: 228593077 Test: run vts -m VtsHalRadioTargetTest Change-Id: I45e60f324926588c55abd0a719fd55352767a3eb Merged-In: I45e60f324926588c55abd0a719fd55352767a3eb --- radio/aidl/vts/radio_config_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/radio/aidl/vts/radio_config_test.cpp b/radio/aidl/vts/radio_config_test.cpp index 2309f9ef7e..81d87d23c4 100644 --- a/radio/aidl/vts/radio_config_test.cpp +++ b/radio/aidl/vts/radio_config_test.cpp @@ -59,6 +59,7 @@ TEST_P(RadioConfigTest, getHalDeviceCapabilities) { serial = GetRandomSerialNumber(); ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial); ASSERT_OK(res); + EXPECT_EQ(std::cv_status::no_timeout, wait()); ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n", toString(radioRsp_config->rspInfo.error).c_str()); } @@ -70,6 +71,7 @@ TEST_P(RadioConfigTest, getSimSlotsStatus) { serial = GetRandomSerialNumber(); ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial); ASSERT_OK(res); + EXPECT_EQ(std::cv_status::no_timeout, wait()); ALOGI("getSimSlotsStatus, rspInfo.error = %s\n", toString(radioRsp_config->rspInfo.error).c_str()); }