Merge "Automatic mk -> bp."
[android/platform-hardware-interfaces.git] / radio / 1.2 / vts / functional / radio_hidl_hal_api.cpp
1 /*
2  * Copyright (C) 2017 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  */
17 #include <radio_hidl_hal_utils_v1_2.h>
18 #include <vector>
20 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
22 /*
23  * Test IRadio.startNetworkScan() for the response returned.
24  */
25 TEST_F(RadioHidlTest_v1_2, startNetworkScan) {
26     const int serial = GetRandomSerialNumber();
28     RadioAccessSpecifier specifier = {
29         .radioAccessNetwork = RadioAccessNetworks::GERAN,
30         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
31         .channels = {1,2}};
33     V1_2::NetworkScanRequest request = {
34         .type = ScanType::ONE_SHOT,
35         .interval = 60,
36         .specifiers = {specifier}};
38     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
39     ASSERT_OK(res);
40     EXPECT_EQ(std::cv_status::no_timeout, wait());
41     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
42     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
44     ALOGI("startNetworkScan, rspInfo.error = %s\n", toString(radioRsp_v1_2->rspInfo.error).c_str());
45     if (cardStatus.cardState == CardState::ABSENT) {
46         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
47                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED ||
48                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED);
49     } else if (cardStatus.cardState == CardState::PRESENT) {
50         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::NONE ||
51                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED ||
52                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED);
53     }
54 }
56 /*
57  * Test IRadio.startNetworkScan() with invalid specifier.
58  */
59 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidArgument) {
60     const int serial = GetRandomSerialNumber();
62     V1_2::NetworkScanRequest request = {
63         .type = ScanType::ONE_SHOT,
64         .interval = 60};
66     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
67     ASSERT_OK(res);
68     EXPECT_EQ(std::cv_status::no_timeout, wait());
69     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
70     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
72     ALOGI("startNetworkScan_InvalidArgument, rspInfo.error = %s\n",
73           toString(radioRsp_v1_2->rspInfo.error).c_str());
74     if (cardStatus.cardState == CardState::ABSENT) {
75         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
76                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
77                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
78     } else if (cardStatus.cardState == CardState::PRESENT) {
79         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
80                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
81     }
82 }
84 /*
85  * Test IRadio.startNetworkScan() with invalid interval (lower boundary).
86  */
87 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidInterval1) {
88     const int serial = GetRandomSerialNumber();
90     RadioAccessSpecifier specifier = {
91         .radioAccessNetwork = RadioAccessNetworks::GERAN,
92         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
93         .channels = {1,2}};
95     V1_2::NetworkScanRequest request = {
96         .type = ScanType::ONE_SHOT,
97         .interval = 4,
98         .specifiers = {specifier},
99         .maxSearchTime = 60,
100         .incrementalResults = false,
101         .incrementalResultsPeriodicity = 1};
103     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
104     ASSERT_OK(res);
105     EXPECT_EQ(std::cv_status::no_timeout, wait());
106     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
107     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
109     ALOGI("startNetworkScan_InvalidInterval1, rspInfo.error = %s\n",
110           toString(radioRsp_v1_2->rspInfo.error).c_str());
111     if (cardStatus.cardState == CardState::ABSENT) {
112         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
113                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
114                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
115                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
116     } else if (cardStatus.cardState == CardState::PRESENT) {
117         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
118                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
119                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
120     }
123 /*
124  * Test IRadio.startNetworkScan() with invalid interval (upper boundary).
125  */
126 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidInterval2) {
127     const int serial = GetRandomSerialNumber();
129     RadioAccessSpecifier specifier = {
130         .radioAccessNetwork = RadioAccessNetworks::GERAN,
131         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
132         .channels = {1,2}};
134     V1_2::NetworkScanRequest request = {
135         .type = ScanType::ONE_SHOT,
136         .interval = 301,
137         .specifiers = {specifier},
138         .maxSearchTime = 60,
139         .incrementalResults = false,
140         .incrementalResultsPeriodicity = 1};
142     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
143     ASSERT_OK(res);
144     EXPECT_EQ(std::cv_status::no_timeout, wait());
145     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
146     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
148     ALOGI("startNetworkScan_InvalidInterval2, rspInfo.error = %s\n",
149           toString(radioRsp_v1_2->rspInfo.error).c_str());
150     if (cardStatus.cardState == CardState::ABSENT) {
151         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
152                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
153                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
154                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
155     } else if (cardStatus.cardState == CardState::PRESENT) {
156         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
157                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
158                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
159     }
162 /*
163  * Test IRadio.startNetworkScan() with invalid max search time (lower boundary).
164  */
165 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidMaxSearchTime1) {
166     const int serial = GetRandomSerialNumber();
168     RadioAccessSpecifier specifier = {
169         .radioAccessNetwork = RadioAccessNetworks::GERAN,
170         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
171         .channels = {1,2}};
173     V1_2::NetworkScanRequest request = {
174         .type = ScanType::ONE_SHOT,
175         .interval = 60,
176         .specifiers = {specifier},
177         .maxSearchTime = 59,
178         .incrementalResults = false,
179         .incrementalResultsPeriodicity = 1};
181     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
182     ASSERT_OK(res);
183     EXPECT_EQ(std::cv_status::no_timeout, wait());
184     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
185     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
187     ALOGI("startNetworkScan_InvalidMaxSearchTime1, rspInfo.error = %s\n",
188           toString(radioRsp_v1_2->rspInfo.error).c_str());
189     if (cardStatus.cardState == CardState::ABSENT) {
190         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
191                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
192                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
193                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
194     } else if (cardStatus.cardState == CardState::PRESENT) {
195         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
196                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
197                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
198     }
201 /*
202  * Test IRadio.startNetworkScan() with invalid max search time (upper boundary).
203  */
204 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidMaxSearchTime2) {
205     const int serial = GetRandomSerialNumber();
207     RadioAccessSpecifier specifier = {
208         .radioAccessNetwork = RadioAccessNetworks::GERAN,
209         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
210         .channels = {1,2}};
212     V1_2::NetworkScanRequest request = {
213         .type = ScanType::ONE_SHOT,
214         .interval = 60,
215         .specifiers = {specifier},
216         .maxSearchTime = 3601,
217         .incrementalResults = false,
218         .incrementalResultsPeriodicity = 1};
220     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
221     ASSERT_OK(res);
222     EXPECT_EQ(std::cv_status::no_timeout, wait());
223     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
224     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
226     ALOGI("startNetworkScan_InvalidMaxSearchTime2, rspInfo.error = %s\n",
227           toString(radioRsp_v1_2->rspInfo.error).c_str());
228     if (cardStatus.cardState == CardState::ABSENT) {
229         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
230                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
231                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
232                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
233     } else if (cardStatus.cardState == CardState::PRESENT) {
234         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
235                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
236                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
237     }
240 /*
241  * Test IRadio.startNetworkScan() with invalid periodicity (lower boundary).
242  */
243 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidPeriodicity1) {
244     const int serial = GetRandomSerialNumber();
246     RadioAccessSpecifier specifier = {
247         .radioAccessNetwork = RadioAccessNetworks::GERAN,
248         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
249         .channels = {1,2}};
251     V1_2::NetworkScanRequest request = {
252         .type = ScanType::ONE_SHOT,
253         .interval = 60,
254         .specifiers = {specifier},
255         .maxSearchTime = 600,
256         .incrementalResults = false,
257         .incrementalResultsPeriodicity = 0};
259     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
260     ASSERT_OK(res);
261     EXPECT_EQ(std::cv_status::no_timeout, wait());
262     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
263     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
265     ALOGI("startNetworkScan_InvalidPeriodicity1, rspInfo.error = %s\n",
266           toString(radioRsp_v1_2->rspInfo.error).c_str());
267     if (cardStatus.cardState == CardState::ABSENT) {
268         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
269                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
270                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
271                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
272     } else if (cardStatus.cardState == CardState::PRESENT) {
273         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
274                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
275                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
276     }
279 /*
280  * Test IRadio.startNetworkScan() with invalid periodicity (upper boundary).
281  */
282 TEST_F(RadioHidlTest_v1_2, startNetworkScan_InvalidPeriodicity2) {
283     const int serial = GetRandomSerialNumber();
285     RadioAccessSpecifier specifier = {
286         .radioAccessNetwork = RadioAccessNetworks::GERAN,
287         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
288         .channels = {1,2}};
290     V1_2::NetworkScanRequest request = {
291         .type = ScanType::ONE_SHOT,
292         .interval = 60,
293         .specifiers = {specifier},
294         .maxSearchTime = 600,
295         .incrementalResults = false,
296         .incrementalResultsPeriodicity = 11};
298     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
299     ASSERT_OK(res);
300     EXPECT_EQ(std::cv_status::no_timeout, wait());
301     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
302     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
304     ALOGI("startNetworkScan_InvalidPeriodicity2, rspInfo.error = %s\n",
305           toString(radioRsp_v1_2->rspInfo.error).c_str());
306     if (cardStatus.cardState == CardState::ABSENT) {
307         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
308                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
309                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
310                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
311     } else if (cardStatus.cardState == CardState::PRESENT) {
312         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
313                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
314                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
315     }
318 /*
319  * Test IRadio.startNetworkScan() with valid periodicity
320  */
321 TEST_F(RadioHidlTest_v1_2, startNetworkScan_GoodRequest1) {
322     const int serial = GetRandomSerialNumber();
324     RadioAccessSpecifier specifier = {
325         .radioAccessNetwork = RadioAccessNetworks::GERAN,
326         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
327         .channels = {1,2}};
329     V1_2::NetworkScanRequest request = {
330         .type = ScanType::ONE_SHOT,
331         .interval = 60,
332         .specifiers = {specifier},
333         .maxSearchTime = 600,
334         .incrementalResults = false,
335         .incrementalResultsPeriodicity = 10};
337     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
338     ASSERT_OK(res);
339     EXPECT_EQ(std::cv_status::no_timeout, wait());
340     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
341     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
343     ALOGI("startNetworkScan_InvalidArgument, rspInfo.error = %s\n",
344           toString(radioRsp_v1_2->rspInfo.error).c_str());
345     if (cardStatus.cardState == CardState::ABSENT) {
346         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::NONE ||
347                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
348                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
349                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
350     } else if (cardStatus.cardState == CardState::PRESENT) {
351         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::NONE ||
352                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
353                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
354     }
357 /*
358  * Test IRadio.startNetworkScan() with valid periodicity and plmns
359  */
360 TEST_F(RadioHidlTest_v1_2, startNetworkScan_GoodRequest2) {
361     const int serial = GetRandomSerialNumber();
363     RadioAccessSpecifier specifier = {
364         .radioAccessNetwork = RadioAccessNetworks::GERAN,
365         .geranBands = {GeranBands::BAND_450, GeranBands::BAND_480},
366         .channels = {1,2}};
368     V1_2::NetworkScanRequest request = {
369         .type = ScanType::ONE_SHOT,
370         .interval = 60,
371         .specifiers = {specifier},
372         .maxSearchTime = 600,
373         .incrementalResults = false,
374         .incrementalResultsPeriodicity = 10,
375         .mccMncs = {"310410"}};
377     Return<void> res = radio_v1_2->startNetworkScan_1_2(serial, request);
378     ASSERT_OK(res);
379     EXPECT_EQ(std::cv_status::no_timeout, wait());
380     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
381     EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
383     ALOGI("startNetworkScan_InvalidArgument, rspInfo.error = %s\n",
384           toString(radioRsp_v1_2->rspInfo.error).c_str());
385     if (cardStatus.cardState == CardState::ABSENT) {
386         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::NONE ||
387                     radioRsp_v1_2->rspInfo.error == RadioError::SIM_ABSENT ||
388                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
389                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
390     } else if (cardStatus.cardState == CardState::PRESENT) {
391         ASSERT_TRUE(radioRsp_v1_2->rspInfo.error == RadioError::NONE ||
392                     radioRsp_v1_2->rspInfo.error == RadioError::OPERATION_NOT_ALLOWED ||
393                     radioRsp_v1_2->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
394     }