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 <VtsCoreUtil.h> 21 #include <android-base/logging.h> 22 #include <android/hardware/wifi/supplicant/1.0/ISupplicant.h> 23 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h> 24 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h> 25 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h> 26 #include <android/hardware/wifi/supplicant/1.1/ISupplicant.h> 27 28 #include <getopt.h> 29 30 #include "wifi_hidl_test_utils.h" 31 32 // Used to stop the android wifi framework before every test. 33 void stopWifiFramework(const std::string& wifi_instance_name); 34 void startWifiFramework(const std::string& wifi_instance_name); 35 36 void stopSupplicant(const std::string& wifi_instance_name); 37 // Used to configure the chip, driver and start wpa_supplicant before every 38 // test. 39 void startSupplicantAndWaitForHidlService( 40 const std::string& wifi_instance_name, 41 const std::string& supplicant_instance_name); 42 43 // Helper functions to obtain references to the various HIDL interface objects. 44 // Note: We only have a single instance of each of these objects currently. 45 // These helper functions should be modified to return vectors if we support 46 // multiple instances. 47 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 48 getSupplicant(const std::string& supplicant_instance_name, bool isP2pOn); 49 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface> 50 getSupplicantStaIface( 51 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 52 supplicant); 53 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork> 54 createSupplicantStaNetwork( 55 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 56 supplicant); 57 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface> 58 getSupplicantP2pIface( 59 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 60 supplicant); 61 bool turnOnExcessiveLogging( 62 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 63 supplicant); 64 65 bool turnOnExcessiveLogging(); 66 67 bool waitForFrameworkReady(); 68 69 class SupplicantHidlTestBase 70 : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { 71 public: SetUp()72 virtual void SetUp() override { 73 // should always be v1.0 wifi 74 wifi_v1_0_instance_name_ = std::get<0>(GetParam()); 75 supplicant_instance_name_ = std::get<1>(GetParam()); 76 std::system("/system/bin/start"); 77 ASSERT_TRUE(waitForFrameworkReady()); 78 79 isP2pOn_ = 80 testing::deviceSupportsFeature("android.hardware.wifi.direct"); 81 // Stop Framework 82 std::system("/system/bin/stop"); 83 stopSupplicant(wifi_v1_0_instance_name_); 84 startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_, 85 supplicant_instance_name_); 86 LOG(INFO) << "SupplicantHidlTestBase isP2pOn_: " << isP2pOn_; 87 } 88 TearDown()89 virtual void TearDown() override { 90 stopSupplicant(wifi_v1_0_instance_name_); 91 // Start Framework 92 std::system("/system/bin/start"); 93 } 94 95 protected: 96 bool isP2pOn_ = false; 97 std::string wifi_v1_0_instance_name_; 98 std::string supplicant_instance_name_; 99 }; 100 101 class SupplicantHidlTestBaseV1_0 : public SupplicantHidlTestBase { 102 public: SetUp()103 virtual void SetUp() override { 104 SupplicantHidlTestBase::SetUp(); 105 supplicant_ = getSupplicant(supplicant_instance_name_, isP2pOn_); 106 ASSERT_NE(supplicant_.get(), nullptr); 107 EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); 108 } 109 110 protected: 111 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 112 supplicant_; 113 }; 114 #endif /* SUPPLICANT_HIDL_TEST_UTILS_H */ 115