1 /* 2 * Copyright (C) 2016 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 #ifndef SUPPLICANT_HIDL_TEST_UTILS_H 18 #define SUPPLICANT_HIDL_TEST_UTILS_H 19 20 #include <android/hardware/wifi/supplicant/1.0/ISupplicant.h> 21 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h> 22 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h> 23 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h> 24 #include <android/hardware/wifi/supplicant/1.1/ISupplicant.h> 25 26 #include <getopt.h> 27 28 #include "wifi_hidl_test_utils.h" 29 30 // Used to stop the android wifi framework before every test. 31 void stopWifiFramework(); 32 void stopWifiFramework(const std::string& wifi_instance_name); 33 void startWifiFramework(); 34 void startWifiFramework(const std::string& wifi_instance_name); 35 36 void stopSupplicant(); 37 void stopSupplicant(const std::string& wifi_instance_name); 38 // Used to configure the chip, driver and start wpa_supplicant before every 39 // test. 40 void startSupplicantAndWaitForHidlService( 41 const std::string& wifi_instance_name, 42 const std::string& supplicant_instance_name); 43 44 // Helper functions to obtain references to the various HIDL interface objects. 45 // Note: We only have a single instance of each of these objects currently. 46 // These helper functions should be modified to return vectors if we support 47 // multiple instances. 48 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 49 getSupplicant(const std::string& supplicant_instance_name, bool isP2pOn); 50 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface> 51 getSupplicantStaIface( 52 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 53 supplicant); 54 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork> 55 createSupplicantStaNetwork( 56 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 57 supplicant); 58 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface> 59 getSupplicantP2pIface( 60 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 61 supplicant); 62 bool turnOnExcessiveLogging( 63 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 64 supplicant); 65 66 // TODO(b/143892896): Remove old APIs after all supplicant tests are updated. 67 void startSupplicantAndWaitForHidlService(); 68 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 69 getSupplicant(); 70 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface> 71 getSupplicantStaIface(); 72 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork> 73 createSupplicantStaNetwork(); 74 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface> 75 getSupplicantP2pIface(); 76 77 bool turnOnExcessiveLogging(); 78 79 class WifiSupplicantHidlEnvironment 80 : public ::testing::VtsHalHidlTargetTestEnvBase { 81 protected: HidlSetUp()82 virtual void HidlSetUp() override { stopSupplicant(); } HidlTearDown()83 virtual void HidlTearDown() override { 84 startSupplicantAndWaitForHidlService(); 85 } 86 87 public: 88 // Whether P2P feature is supported on the device. 89 bool isP2pOn = true; 90 usage(char * me,char * arg)91 void usage(char* me, char* arg) { 92 fprintf(stderr, 93 "unrecognized option: %s\n\n" 94 "usage: %s <gtest options> <test options>\n\n" 95 "test options are:\n\n" 96 "-P, --p2p_on: Whether P2P feature is supported\n", 97 arg, me); 98 } 99 initFromOptions(int argc,char ** argv)100 int initFromOptions(int argc, char** argv) { 101 static struct option options[] = {{"p2p_off", no_argument, 0, 'P'}, 102 {0, 0, 0, 0}}; 103 104 int c; 105 while ((c = getopt_long(argc, argv, "P", options, NULL)) >= 0) { 106 switch (c) { 107 case 'P': 108 isP2pOn = false; 109 break; 110 default: 111 usage(argv[0], argv[optind]); 112 return 2; 113 } 114 } 115 116 if (optind < argc) { 117 usage(argv[0], argv[optind]); 118 return 2; 119 } 120 121 return 0; 122 } 123 }; 124 125 #endif /* SUPPLICANT_HIDL_TEST_UTILS_H */ 126