1#!/usr/bin/env python3 2# 3# Copyright 2018 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import acts.test_utils.wifi.wifi_test_utils as wutils 18import acts.utils 19import time 20 21from acts import asserts 22from acts import utils 23 24from acts.test_decorators import test_tracker_info 25from acts.test_utils.wifi.p2p.WifiP2pBaseTest import WifiP2pBaseTest 26from acts.test_utils.wifi.p2p import wifi_p2p_test_utils as wp2putils 27from acts.test_utils.wifi.p2p import wifi_p2p_const as p2pconsts 28 29WPS_PBC = wp2putils.WifiP2PEnums.WpsInfo.WIFI_WPS_INFO_PBC 30WPS_DISPLAY = wp2putils.WifiP2PEnums.WpsInfo.WIFI_WPS_INFO_DISPLAY 31WPS_KEYPAD = wp2putils.WifiP2PEnums.WpsInfo.WIFI_WPS_INFO_KEYPAD 32 33 34class WifiP2pGroupTest(WifiP2pBaseTest): 35 """Tests for APIs in Android's WifiP2pManager class. 36 37 Test Bed Requirement: 38 * At least two Android devices 39 """ 40 def __init__(self, controllers): 41 WifiP2pBaseTest.__init__(self, controllers) 42 43 def setup_class(self): 44 super().setup_class() 45 if not "network_name" in self.user_params.keys(): 46 self.log.error("Missing mandatory user config \"network_name\"!") 47 self.network_name = self.user_params["network_name"] 48 if not "passphrase" in self.user_params.keys(): 49 self.log.error("Missing mandatory user config \"passphrase\"!") 50 self.passphrase = self.user_params["passphrase"] 51 if not "group_band" in self.user_params.keys(): 52 self.log.error("Missing mandatory user config \"group_band\"!") 53 self.group_band = self.user_params["group_band"] 54 55 def setup_test(self): 56 super().setup_test() 57 self.dut1.droid.wifiP2pRemoveGroup() 58 self.dut2.droid.wifiP2pRemoveGroup() 59 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 60 61 def teardown_test(self): 62 self.dut1.droid.wifiP2pRemoveGroup() 63 self.dut2.droid.wifiP2pRemoveGroup() 64 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 65 super().teardown_test() 66 67 def p2p_group_join(self, wps_type): 68 """ General flow for p2p group join 69 70 Steps: 71 1. GO creates a group. 72 2. GC joins the group. 73 3. connection check via ping from GC to GO 74 """ 75 go_dut = self.dut1 76 gc_dut = self.dut2 77 # Create a group 78 wp2putils.p2p_create_group(go_dut) 79 go_dut.ed.pop_event(p2pconsts.CONNECTED_EVENT, 80 p2pconsts.DEFAULT_TIMEOUT) 81 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 82 # Request the connection 83 wp2putils.p2p_connect(gc_dut, 84 go_dut, 85 False, 86 wps_type, 87 p2p_connect_type=p2pconsts.P2P_CONNECT_JOIN) 88 89 go_ip = wp2putils.p2p_go_ip(gc_dut) 90 wp2putils.p2p_connection_ping_test(gc_dut, go_ip) 91 # trigger disconnect 92 wp2putils.p2p_disconnect(go_dut) 93 wp2putils.check_disconnect(gc_dut) 94 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 95 96 """Test Cases""" 97 @test_tracker_info(uuid="c41f8293-5225-430d-917e-c294ddff7c2a") 98 def test_p2p_group_join_via_pbc(self): 99 """Verify the p2p creates a group and join this group via WPS PBC method. 100 """ 101 self.p2p_group_join(WPS_PBC) 102 103 @test_tracker_info(uuid="56eb339f-d7e4-44f0-9802-6094e9255957") 104 def test_p2p_group_join_via_display(self): 105 """Verify the p2p creates a group and join this group via WPS DISPLAY method. 106 """ 107 self.p2p_group_join(WPS_DISPLAY) 108 109 @test_tracker_info(uuid="27075cab-7859-49a7-afe9-b6cc6e8faddb") 110 def test_p2p_group_with_config(self): 111 """Verify the p2p creates a group and join an this group with config. 112 113 Steps: 114 1. GO creates a group with config. 115 2. GC joins the group with config. 116 3. connection check via ping from GC to GO 117 """ 118 go_dut = self.dut1 119 gc_dut = self.dut2 120 # Create a group 121 wp2putils.p2p_create_group_with_config(go_dut, self.network_name, 122 self.passphrase, 123 self.group_band) 124 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 125 # Request the connection. Since config is known, this is reconnection. 126 wp2putils.p2p_connect_with_config(gc_dut, go_dut, self.network_name, 127 self.passphrase, self.group_band) 128 129 go_ip = wp2putils.p2p_go_ip(gc_dut) 130 wp2putils.p2p_connection_ping_test(gc_dut, go_ip) 131 # trigger disconnect 132 wp2putils.p2p_disconnect(go_dut) 133 wp2putils.check_disconnect(gc_dut) 134 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 135