1 /*
2  * Copyright (C) 2019 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_hidl_hal_utils_v1_3.h>
18 #include <vector>
19 #include "VtsCoreUtil.h"
20 
21 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
22 
23 /*
24  * Test IRadio.enableMddem() for the response returned.
25  */
TEST_P(RadioHidlTest_v1_3,enableModem)26 TEST_P(RadioHidlTest_v1_3, enableModem) {
27     serial = GetRandomSerialNumber();
28 
29     bool isMultiSimEnabled =
30             testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config",
31                                                    "dsds") ||
32             testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "tsts");
33     if (!isMultiSimEnabled) {
34         ALOGI("enableModem, no need to test in single SIM mode");
35         return;
36     }
37 
38     bool responseToggle = radioRsp_v1_3->enableModemResponseToggle;
39     Return<void> res = radio_v1_3->enableModem(serial, true);
40     ASSERT_OK(res);
41     EXPECT_EQ(std::cv_status::no_timeout, wait());
42     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_3->rspInfo.type);
43     EXPECT_EQ(serial, radioRsp_v1_3->rspInfo.serial);
44     ALOGI("getModemStackStatus, rspInfo.error = %s\n",
45           toString(radioRsp_v1_3->rspInfo.error).c_str());
46     ASSERT_TRUE(CheckAnyOfErrors(radioRsp_v1_3->rspInfo.error,
47                                  {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
48                                   RadioError::MODEM_ERR, RadioError::INVALID_STATE}));
49 
50     // checking if getModemStackStatus returns true, as modem was enabled above
51     if (RadioError::NONE == radioRsp_v1_3->rspInfo.error) {
52         // wait until modem enabling is finished
53         while (responseToggle == radioRsp_v1_3->enableModemResponseToggle) {
54             sleep(1);
55         }
56         Return<void> resEnabled = radio_v1_3->getModemStackStatus(serial);
57         ASSERT_OK(resEnabled);
58         EXPECT_EQ(std::cv_status::no_timeout, wait());
59         EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_3->rspInfo.type);
60         EXPECT_EQ(serial, radioRsp_v1_3->rspInfo.serial);
61         ALOGI("getModemStackStatus, rspInfo.error = %s\n",
62               toString(radioRsp_v1_3->rspInfo.error).c_str());
63         ASSERT_TRUE(CheckAnyOfErrors(radioRsp_v1_3->rspInfo.error,
64                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
65                                       RadioError::MODEM_ERR, RadioError::INVALID_STATE}));
66         // verify that enableModem did set isEnabled correctly
67         EXPECT_EQ(true, radioRsp_v1_3->isModemEnabled);
68     }
69 }
70 
71 /*
72  * Test IRadio.getModemStackStatus() for the response returned.
73  */
TEST_P(RadioHidlTest_v1_3,getModemStackStatus)74 TEST_P(RadioHidlTest_v1_3, getModemStackStatus) {
75     serial = GetRandomSerialNumber();
76 
77     Return<void> res = radio_v1_3->getModemStackStatus(serial);
78     ASSERT_OK(res);
79     EXPECT_EQ(std::cv_status::no_timeout, wait());
80     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_3->rspInfo.type);
81     EXPECT_EQ(serial, radioRsp_v1_3->rspInfo.serial);
82     ALOGI("getModemStackStatus, rspInfo.error = %s\n",
83           toString(radioRsp_v1_3->rspInfo.error).c_str());
84     ASSERT_TRUE(CheckAnyOfErrors(
85             radioRsp_v1_3->rspInfo.error,
86             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR}));
87 }
88