Home | History | Annotate | Download | only in integration
      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 #include <string>
     18 #include <vector>
     19 
     20 #include <gtest/gtest.h>
     21 #include <utils/StrongPointer.h>
     22 #include <wifi_system/interface_tool.h>
     23 
     24 #include "android/net/wifi/IClientInterface.h"
     25 #include "android/net/wifi/IWificond.h"
     26 #include "wificond/tests/integration/process_utils.h"
     27 
     28 using android::net::wifi::IClientInterface;
     29 using android::net::wifi::IWificond;
     30 using android::wifi_system::InterfaceTool;
     31 using android::wificond::tests::integration::ScopedDevModeWificond;
     32 using android::wificond::tests::integration::SupplicantIsDead;
     33 using android::wificond::tests::integration::SupplicantIsRunning;
     34 using android::wificond::tests::integration::WaitForTrue;
     35 using std::string;
     36 using std::vector;
     37 
     38 namespace android {
     39 namespace wificond {
     40 namespace {
     41 
     42 const char kInterfaceName[] = "wlan0";
     43 }  // namespace
     44 
     45 TEST(ClientInterfaceTest, CanCreateClientInterfaces) {
     46   ScopedDevModeWificond dev_mode;
     47   sp<IWificond> service = dev_mode.EnterDevModeOrDie();
     48 
     49   // We should be able to create an client interface.
     50   sp<IClientInterface> client_interface;
     51   EXPECT_TRUE(service->createClientInterface(
     52       kInterfaceName, &client_interface).isOk());
     53   EXPECT_NE(nullptr, client_interface.get());
     54 
     55   // The interface should start out down.
     56   string if_name;
     57   EXPECT_TRUE(client_interface->getInterfaceName(&if_name).isOk());
     58   EXPECT_TRUE(!if_name.empty());
     59   InterfaceTool if_tool;
     60   EXPECT_FALSE(if_tool.GetUpState(if_name.c_str()));
     61 
     62   // Mark the interface as up, just to test that we mark it down on tearDown.
     63   EXPECT_TRUE(if_tool.SetUpState(if_name.c_str(), true));
     64   EXPECT_TRUE(if_tool.GetUpState(if_name.c_str()));
     65 
     66   // We should not be able to create two client interfaces.
     67   sp<IClientInterface> client_interface2;
     68   EXPECT_TRUE(service->createClientInterface(
     69       kInterfaceName, &client_interface2).isOk());
     70   EXPECT_EQ(nullptr, client_interface2.get());
     71 
     72   // We can tear down the created interface.
     73   bool succes = false;
     74   EXPECT_TRUE(service->tearDownClientInterface(kInterfaceName, &succes).isOk());
     75   EXPECT_TRUE(succes);
     76   EXPECT_FALSE(if_tool.GetUpState(if_name.c_str()));
     77 
     78   // Teardown everything at the end of the test.
     79   EXPECT_TRUE(service->tearDownInterfaces().isOk());
     80 }
     81 
     82 TEST(ClientInterfaceTest, CanGetMacAddress) {
     83   ScopedDevModeWificond dev_mode;
     84   sp<IWificond> service = dev_mode.EnterDevModeOrDie();
     85   sp<IClientInterface> client_interface;
     86   EXPECT_TRUE(service->createClientInterface(
     87       kInterfaceName, &client_interface).isOk());
     88   ASSERT_NE(nullptr, client_interface.get());
     89   vector<uint8_t> mac_address;
     90   EXPECT_TRUE(client_interface->getMacAddress(&mac_address).isOk());
     91   EXPECT_TRUE(mac_address.size() == 6);
     92 }
     93 
     94 }  // namespace wificond
     95 }  // namespace android
     96