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 33class WifiP2pManagerTest(WifiP2pBaseTest): 34 """Tests for APIs in Android's WifiP2pManager class. 35 36 Test Bed Requirement: 37 * At least two Android devices 38 * 3 Android devices for WifiP2pMultiPeersTest.py 39 """ 40 41 def __init__(self, controllers): 42 WifiP2pBaseTest.__init__(self, controllers) 43 44 """Test Cases""" 45 @test_tracker_info(uuid="28ddb16c-2ce4-44da-92f9-701d0dacc321") 46 def test_p2p_discovery(self): 47 """Verify the p2p discovery functionality 48 Steps: 49 1. Discover the target device 50 2. Check the target device in peer list 51 """ 52 self.log.info("Device discovery") 53 wp2putils.find_p2p_device(self.dut1, self.dut2) 54 wp2putils.find_p2p_device(self.dut2, self.dut1) 55 56 @test_tracker_info(uuid="0016e6db-9b46-44fb-a53e-10a81eee955e") 57 def test_p2p_connect_via_pbc_and_ping_and_reconnect(self): 58 """Verify the p2p connect via pbc functionality 59 60 Steps: 61 1. Request the connection which include discover the target device 62 2. check which dut is GO and which dut is GC 63 3. connection check via ping from GC to GO 64 4. disconnect 65 5. Trigger connect again from GO for reconnect test. 66 6. GO trigger disconnect 67 7. Trigger connect again from GC for reconnect test. 68 8. GC trigger disconnect 69 """ 70 # Request the connection 71 wp2putils.p2p_connect(self.dut1, self.dut2, False, WPS_PBC) 72 73 if wp2putils.is_go(self.dut1): 74 go_dut = self.dut1 75 gc_dut = self.dut2 76 elif wp2putils.is_go(self.dut2): 77 go_dut = self.dut2 78 gc_dut = self.dut1 79 80 wp2putils.p2p_connection_ping_test(gc_dut, p2pconsts.GO_IP_ADDRESS) 81 # trigger disconnect 82 wp2putils.p2p_disconnect(self.dut1) 83 wp2putils.check_disconnect(self.dut2) 84 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 85 86 self.log.info("Reconnect test, triggered by GO") 87 # trigger reconnect from GO 88 go_dut.ed.clear_all_events() 89 gc_dut.ed.clear_all_events() 90 wp2putils.p2p_connect(go_dut, gc_dut, True, WPS_PBC) 91 wp2putils.p2p_disconnect(go_dut) 92 wp2putils.check_disconnect(gc_dut) 93 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 94 95 # trigger reconnect from GC 96 self.log.info("Reconnect test, triggered by GC") 97 go_dut.ed.clear_all_events() 98 gc_dut.ed.clear_all_events() 99 wp2putils.p2p_connect(gc_dut, go_dut, True, WPS_PBC) 100 wp2putils.p2p_disconnect(gc_dut) 101 wp2putils.check_disconnect(go_dut) 102 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 103 104 @test_tracker_info(uuid="12bbe73a-5a6c-4307-9797-c77c7efdc4b5") 105 def test_p2p_connect_via_display_and_ping_and_reconnect(self): 106 """Verify the p2p connect via display functionality 107 108 Steps: 109 1. Request the connection which include discover the target device 110 2. check which dut is GO and which dut is GC 111 3. connection check via ping from GC to GO 112 4. disconnect 113 5. Trigger connect again from GO for reconnect test. 114 6. GO trigger disconnect 115 7. Trigger connect again from GC for reconnect test. 116 8. GC trigger disconnect 117 """ 118 # Request the connection 119 wp2putils.p2p_connect(self.dut1, self.dut2, False, WPS_DISPLAY) 120 121 if wp2putils.is_go(self.dut1): 122 go_dut = self.dut1 123 gc_dut = self.dut2 124 elif wp2putils.is_go(self.dut2): 125 go_dut = self.dut2 126 gc_dut = self.dut1 127 128 wp2putils.p2p_connection_ping_test(gc_dut, p2pconsts.GO_IP_ADDRESS) 129 # trigger disconnect 130 wp2putils.p2p_disconnect(self.dut1) 131 wp2putils.check_disconnect(self.dut2) 132 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 133 134 self.log.info("Reconnect test, triggered by GO") 135 # trigger reconnect from GO 136 go_dut.ed.clear_all_events() 137 gc_dut.ed.clear_all_events() 138 wp2putils.p2p_connect(go_dut, gc_dut, True, WPS_DISPLAY) 139 wp2putils.p2p_disconnect(go_dut) 140 wp2putils.check_disconnect(gc_dut) 141 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 142 143 # trigger reconnect from GC 144 self.log.info("Reconnect test, triggered by GC") 145 go_dut.ed.clear_all_events() 146 gc_dut.ed.clear_all_events() 147 wp2putils.p2p_connect(gc_dut, go_dut, True, WPS_DISPLAY) 148 wp2putils.p2p_disconnect(gc_dut) 149 wp2putils.check_disconnect(go_dut) 150 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 151 152 @test_tracker_info(uuid="efe88f57-5a08-4195-9592-2f6945a9d18a") 153 def test_p2p_connect_via_keypad_and_ping_and_reconnect(self): 154 """Verify the p2p connect via keypad functionality 155 156 Steps: 157 1. Request the connection which include discover the target device 158 2. check which dut is GO and which dut is GC 159 3. connection check via ping from GC to GO 160 4. disconnect 161 5. Trigger connect again from GO for reconnect test. 162 6. GO trigger disconnect 163 7. Trigger connect again from GC for reconnect test. 164 8. GC trigger disconnect 165 """ 166 # Request the connection 167 wp2putils.p2p_connect(self.dut1, self.dut2, False, WPS_KEYPAD) 168 169 if wp2putils.is_go(self.dut1): 170 go_dut = self.dut1 171 gc_dut = self.dut2 172 elif wp2putils.is_go(self.dut2): 173 go_dut = self.dut2 174 gc_dut = self.dut1 175 176 wp2putils.p2p_connection_ping_test(gc_dut, p2pconsts.GO_IP_ADDRESS) 177 178 # trigger disconnect 179 wp2putils.p2p_disconnect(self.dut1) 180 wp2putils.check_disconnect(self.dut2) 181 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 182 183 self.log.info("Reconnect test, triggered by GO") 184 # trigger reconnect from GO 185 go_dut.ed.clear_all_events() 186 gc_dut.ed.clear_all_events() 187 wp2putils.p2p_connect(go_dut, gc_dut, True, WPS_KEYPAD) 188 wp2putils.p2p_disconnect(go_dut) 189 wp2putils.check_disconnect(gc_dut) 190 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 191 192 # trigger reconnect from GC 193 self.log.info("Reconnect test, triggered by GC") 194 go_dut.ed.clear_all_events() 195 gc_dut.ed.clear_all_events() 196 wp2putils.p2p_connect(gc_dut, go_dut, True, WPS_KEYPAD) 197 wp2putils.p2p_disconnect(gc_dut) 198 wp2putils.check_disconnect(go_dut) 199 time.sleep(p2pconsts.DEFAULT_FUNCTION_SWITCH_TIME) 200