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 */
16 #define LOG_TAG "RadioTest"
17
18 #include <vts_test_util.h>
19 #include <iostream>
20
GetRandomSerialNumber()21 int GetRandomSerialNumber() {
22 return rand();
23 }
24
CheckAnyOfErrors(RadioError err,std::vector<RadioError> errors,CheckFlag flag)25 ::testing::AssertionResult CheckAnyOfErrors(RadioError err, std::vector<RadioError> errors,
26 CheckFlag flag) {
27 const static vector<RadioError> generalErrors = {
28 RadioError::RADIO_NOT_AVAILABLE, RadioError::NO_MEMORY,
29 RadioError::INTERNAL_ERR, RadioError::SYSTEM_ERR,
30 RadioError::REQUEST_NOT_SUPPORTED, RadioError::CANCELLED};
31 if (flag == CHECK_GENERAL_ERROR || flag == CHECK_OEM_AND_GENERAL_ERROR) {
32 for (size_t i = 0; i < generalErrors.size(); i++) {
33 if (err == generalErrors[i]) {
34 return testing::AssertionSuccess();
35 }
36 }
37 }
38 if (flag == CHECK_OEM_ERROR || flag == CHECK_OEM_AND_GENERAL_ERROR) {
39 if (err >= RadioError::OEM_ERROR_1 && err <= RadioError::OEM_ERROR_25) {
40 return testing::AssertionSuccess();
41 }
42 }
43 for (size_t i = 0; i < errors.size(); i++) {
44 if (err == errors[i]) {
45 return testing::AssertionSuccess();
46 }
47 }
48 return testing::AssertionFailure() << "RadioError:" + toString(err) + " is returned";
49 }
50
CheckAnyOfErrors(SapResultCode err,std::vector<SapResultCode> errors)51 ::testing::AssertionResult CheckAnyOfErrors(SapResultCode err, std::vector<SapResultCode> errors) {
52 for (size_t i = 0; i < errors.size(); i++) {
53 if (err == errors[i]) {
54 return testing::AssertionSuccess();
55 }
56 }
57 return testing::AssertionFailure() << "SapError:" + toString(err) + " is returned";
58 }
59
60 // Runs "pm list features" and attempts to find the specified feature in its output.
deviceSupportsFeature(const char * feature)61 bool deviceSupportsFeature(const char* feature) {
62 bool hasFeature = false;
63 FILE* p = popen("/system/bin/pm list features", "re");
64 if (p) {
65 char* line = NULL;
66 size_t len = 0;
67 while (getline(&line, &len, p) > 0) {
68 if (strstr(line, feature)) {
69 hasFeature = true;
70 break;
71 }
72 }
73 pclose(p);
74 } else {
75 __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, "popen failed: %d", errno);
76 _exit(EXIT_FAILURE);
77 }
78 __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Feature %s: %ssupported", feature,
79 hasFeature ? "" : "not ");
80 return hasFeature;
81 }