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 <VtsHalHidlTargetTestEnvBase.h> 29 30 // Used to stop the android wifi framework before every test. 31 void stopWifiFramework(); 32 void startWifiFramework(); 33 void stopSupplicant(); 34 // Used to configure the chip, driver and start wpa_supplicant before every 35 // test. 36 void startSupplicantAndWaitForHidlService(); 37 38 // Helper functions to obtain references to the various HIDL interface objects. 39 // Note: We only have a single instance of each of these objects currently. 40 // These helper functions should be modified to return vectors if we support 41 // multiple instances. 42 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 43 getSupplicant(); 44 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface> 45 getSupplicantStaIface(); 46 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork> 47 createSupplicantStaNetwork(); 48 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface> 49 getSupplicantP2pIface(); 50 51 bool turnOnExcessiveLogging(); 52 53 class WifiSupplicantHidlEnvironment 54 : public ::testing::VtsHalHidlTargetTestEnvBase { 55 protected: HidlSetUp()56 virtual void HidlSetUp() override { stopSupplicant(); } HidlTearDown()57 virtual void HidlTearDown() override { 58 startSupplicantAndWaitForHidlService(); 59 } 60 61 public: 62 // Whether P2P feature is supported on the device. 63 bool isP2pOn = true; 64 usage(char * me,char * arg)65 void usage(char* me, char* arg) { 66 fprintf(stderr, 67 "unrecognized option: %s\n\n" 68 "usage: %s <gtest options> <test options>\n\n" 69 "test options are:\n\n" 70 "-P, --p2p_on: Whether P2P feature is supported\n", 71 arg, me); 72 } 73 initFromOptions(int argc,char ** argv)74 int initFromOptions(int argc, char** argv) { 75 static struct option options[] = {{"p2p_off", no_argument, 0, 'P'}, 76 {0, 0, 0, 0}}; 77 78 int c; 79 while ((c = getopt_long(argc, argv, "P", options, NULL)) >= 0) { 80 switch (c) { 81 case 'P': 82 isP2pOn = false; 83 break; 84 default: 85 usage(argv[0], argv[optind]); 86 return 2; 87 } 88 } 89 90 if (optind < argc) { 91 usage(argv[0], argv[optind]); 92 return 2; 93 } 94 95 return 0; 96 } 97 }; 98 99 #endif /* SUPPLICANT_HIDL_TEST_UTILS_H */ 100