1 /*
2 * Copyright (C) 2018 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 <radio_config_hidl_hal_utils.h>
18
19 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
20
21 /*
22 * Test IRadioConfig.getModemsConfig()
23 */
TEST_P(RadioConfigHidlTest,getModemsConfig)24 TEST_P(RadioConfigHidlTest, getModemsConfig) {
25 serial = GetRandomSerialNumber();
26 Return<void> res = radioConfig->getModemsConfig(serial);
27 ASSERT_OK(res);
28 EXPECT_EQ(std::cv_status::no_timeout, wait());
29 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
30 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
31 ALOGI("getModemsConfig, rspInfo.error = %s\n", toString(radioConfigRsp->rspInfo.error).c_str());
32
33 ASSERT_TRUE(CheckAnyOfErrors(radioConfigRsp->rspInfo.error,
34 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
35 }
36
37 /*
38 * Test IRadioConfig.setModemsConfig()
39 */
TEST_P(RadioConfigHidlTest,setModemsConfig_invalidArgument)40 TEST_P(RadioConfigHidlTest, setModemsConfig_invalidArgument) {
41 serial = GetRandomSerialNumber();
42 ModemsConfig* mConfig = new ModemsConfig();
43 Return<void> res = radioConfig->setModemsConfig(serial, *mConfig);
44 ASSERT_OK(res);
45 EXPECT_EQ(std::cv_status::no_timeout, wait());
46 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
47 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
48 ALOGI("setModemsConfig, rspInfo.error = %s\n", toString(radioConfigRsp->rspInfo.error).c_str());
49
50 ASSERT_TRUE(
51 CheckAnyOfErrors(radioConfigRsp->rspInfo.error,
52 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
53 }
54
55 /*
56 * Test IRadioConfig.setModemsConfig()
57 */
TEST_P(RadioConfigHidlTest,setModemsConfig_goodRequest)58 TEST_P(RadioConfigHidlTest, setModemsConfig_goodRequest) {
59 serial = GetRandomSerialNumber();
60 ModemsConfig* mConfig = new ModemsConfig();
61 if (isSsSsEnabled()) {
62 mConfig->numOfLiveModems = 1;
63 } else if (isDsDsEnabled()) {
64 mConfig->numOfLiveModems = 2;
65 } else if (isTsTsEnabled()) {
66 mConfig->numOfLiveModems = 3;
67 } else {
68 ALOGI("Skipping setModemsConfig_goodRequest, unsupported multisim number");
69 return;
70 }
71 Return<void> res = radioConfig->setModemsConfig(serial, *mConfig);
72 ASSERT_OK(res);
73 EXPECT_EQ(std::cv_status::no_timeout, wait());
74 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
75 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
76 ALOGI("setModemsConfig, rspInfo.error = %s\n", toString(radioConfigRsp->rspInfo.error).c_str());
77
78 ASSERT_TRUE(CheckAnyOfErrors(radioConfigRsp->rspInfo.error,
79 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
80 }
81
82 /*
83 * Test IRadioConfig.getPhoneCapability()
84 */
TEST_P(RadioConfigHidlTest,getPhoneCapability)85 TEST_P(RadioConfigHidlTest, getPhoneCapability) {
86 serial = GetRandomSerialNumber();
87 Return<void> res = radioConfig->getPhoneCapability(serial);
88 ASSERT_OK(res);
89 EXPECT_EQ(std::cv_status::no_timeout, wait());
90 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
91 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
92 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
93 toString(radioConfigRsp->rspInfo.error).c_str());
94
95 ASSERT_TRUE(CheckAnyOfErrors(
96 radioConfigRsp->rspInfo.error,
97 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
98
99 if (radioConfigRsp->rspInfo.error == RadioError ::NONE) {
100 // maxActiveData should be greater than or equal to maxActiveInternetData.
101 EXPECT_GE(radioConfigRsp->phoneCap.maxActiveData,
102 radioConfigRsp->phoneCap.maxActiveInternetData);
103 // maxActiveData and maxActiveInternetData should be 0 or positive numbers.
104 EXPECT_GE(radioConfigRsp->phoneCap.maxActiveInternetData, 0);
105 }
106 }
107
108 /*
109 * Test IRadioConfig.getPhoneCapability()
110 */
TEST_P(RadioConfigHidlTest,setPreferredDataModem)111 TEST_P(RadioConfigHidlTest, setPreferredDataModem) {
112 serial = GetRandomSerialNumber();
113 Return<void> res = radioConfig->getPhoneCapability(serial);
114 ASSERT_OK(res);
115 EXPECT_EQ(std::cv_status::no_timeout, wait());
116 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
117 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
118 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
119 toString(radioConfigRsp->rspInfo.error).c_str());
120
121 ASSERT_TRUE(CheckAnyOfErrors(
122 radioConfigRsp->rspInfo.error,
123 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
124
125 if (radioConfigRsp->rspInfo.error != RadioError ::NONE) {
126 return;
127 }
128
129 if (radioConfigRsp->phoneCap.logicalModemList.size() == 0) {
130 return;
131 }
132
133 // We get phoneCapability. send setPreferredDataModem command
134 serial = GetRandomSerialNumber();
135 uint8_t modemId = radioConfigRsp->phoneCap.logicalModemList[0].modemId;
136 res = radioConfig->setPreferredDataModem(serial, modemId);
137
138 ASSERT_OK(res);
139 EXPECT_EQ(std::cv_status::no_timeout, wait());
140 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
141 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
142 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
143 toString(radioConfigRsp->rspInfo.error).c_str());
144
145 ASSERT_TRUE(CheckAnyOfErrors(
146 radioConfigRsp->rspInfo.error,
147 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
148 }
149
150 /*
151 * Test IRadioConfig.getPhoneCapability()
152 */
TEST_P(RadioConfigHidlTest,setPreferredDataModem_invalidArgument)153 TEST_P(RadioConfigHidlTest, setPreferredDataModem_invalidArgument) {
154 serial = GetRandomSerialNumber();
155 uint8_t modemId = -1;
156 Return<void> res = radioConfig->setPreferredDataModem(serial, modemId);
157
158 ASSERT_OK(res);
159 EXPECT_EQ(std::cv_status::no_timeout, wait());
160 EXPECT_EQ(RadioResponseType::SOLICITED, radioConfigRsp->rspInfo.type);
161 EXPECT_EQ(serial, radioConfigRsp->rspInfo.serial);
162 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
163 toString(radioConfigRsp->rspInfo.error).c_str());
164
165 ASSERT_TRUE(CheckAnyOfErrors(radioConfigRsp->rspInfo.error,
166 {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE,
167 RadioError::INTERNAL_ERR}));
168 }
169