Skip to content

Commit a07786b

Browse files
author
yennj12
committed
add
1 parent 96abe87 commit a07786b

File tree

4 files changed

+374
-3
lines changed

4 files changed

+374
-3
lines changed

mobly/README.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
```bash
66
# mac
77

8-
pip install mobly
8+
pip install mobly aware
99
```
1010

1111
```bash
@@ -25,12 +25,26 @@ pip install mobly
2525
```bash
2626

2727
#-----------------------
28-
# Exp 1
28+
# TEST 1
2929
#-----------------------
3030

3131
python3 hello_world_test.py -c sample_config.yml
32+
33+
34+
python3 test_1.py -c sample_config.yml
35+
36+
37+
38+
#-----------------------
39+
# TEST 2
40+
#-----------------------
41+
42+
cd android_integ_test
43+
44+
atest CtsWifiAwareTestCases
3245
```
3346

3447

3548
## Ref
36-
- https://github.com/google/mobly/blob/master/docs/tutorial.md
49+
- https://github.com/google/mobly/blob/master/docs/tutorial.md
50+
- https://source.android.com/docs/core/tests/tradefed/testing/through-suite/multi-devices-suites?hl=zh-tw

mobly/android_integ_test/Android.bp

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (C) 2023 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package {
16+
default_team: "trendy_team_fwk_wifi_hal",
17+
default_applicable_licenses: ["Andsroid-Apache-2.0"],
18+
}
19+
20+
python_test_host {
21+
name: "WifiAwareAttachTestCases",
22+
main: "wifi_aware_attached_test.py",
23+
srcs: ["wifi_aware_attached_test.py"],
24+
device_common_data: [":wifi_aware_snippet_new"],
25+
libs: [
26+
"aware_lib_utils",
27+
"mobly",
28+
"wifi_aware_constants",
29+
],
30+
test_suites: [
31+
"general-tests",
32+
],
33+
test_options: {
34+
unit_test: false,
35+
tags: ["mobly"],
36+
},
37+
}
38+
39+
python_test_host {
40+
name: "WifiAwareDiscoveryCases",
41+
main: "wifi_aware_discovery_test.py",
42+
srcs: ["wifi_aware_discovery_test.py"],
43+
device_common_data: [":wifi_aware_snippet_new"],
44+
libs: [
45+
"aware_lib_utils",
46+
"mobly",
47+
"wifi_aware_constants",
48+
],
49+
test_suites: [
50+
"general-tests",
51+
],
52+
test_options: {
53+
unit_test: false,
54+
tags: ["mobly"],
55+
},
56+
}
57+
58+
python_test_host {
59+
name: "WifiAwareMessageCases",
60+
main: "wifi_aware_message_test.py",
61+
srcs: ["wifi_aware_message_test.py"],
62+
device_common_data: [":wifi_aware_snippet_new"],
63+
libs: [
64+
"aware_lib_utils",
65+
"mobly",
66+
"wifi_aware_constants",
67+
],
68+
test_suites: [
69+
"general-tests",
70+
],
71+
test_options: {
72+
unit_test: false,
73+
tags: ["mobly"],
74+
},
75+
}
76+
77+
python_test_host {
78+
name: "WifiAwareMatchFilterCases",
79+
main: "wifi_aware_matchfilter_test.py",
80+
srcs: ["wifi_aware_matchfilter_test.py"],
81+
device_common_data: [":wifi_aware_snippet_new"],
82+
libs: [
83+
"aware_lib_utils",
84+
"mobly",
85+
"wifi_aware_constants",
86+
],
87+
test_suites: [
88+
"general-tests",
89+
],
90+
test_options: {
91+
unit_test: false,
92+
tags: ["mobly"],
93+
},
94+
}
95+
96+
python_test_host {
97+
name: "WifiAwareDatapathTestCases",
98+
main: "wifi_aware_datapath_test.py",
99+
srcs: ["wifi_aware_datapath_test.py"],
100+
device_common_data: [":wifi_aware_snippet_new"],
101+
libs: [
102+
"aware_lib_utils",
103+
"mobly",
104+
"wifi_aware_constants",
105+
],
106+
test_suites: [
107+
"general-tests",
108+
],
109+
test_options: {
110+
unit_test: false,
111+
tags: ["mobly"],
112+
},
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# Copyright (C) 2024 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# https://source.android.com/docs/core/tests/tradefed/testing/through-suite/multi-devices-suites?hl=zh-tw
16+
17+
# Lint as: python3
18+
"""ACTS Wi-Fi Aware Attached test reimplemented in Mobly."""
19+
import sys
20+
21+
from aware import aware_lib_utils as autils
22+
from aware import constants
23+
from mobly import asserts
24+
from mobly import base_test
25+
from mobly import records
26+
from mobly import test_runner
27+
from mobly import utils
28+
from mobly.controllers import android_device
29+
30+
31+
RUNTIME_PERMISSIONS = (
32+
'android.permission.ACCESS_FINE_LOCATION',
33+
'android.permission.ACCESS_COARSE_LOCATION',
34+
'android.permission.NEARBY_WIFI_DEVICES',
35+
)
36+
PACKAGE_NAME = constants.WIFI_AWARE_SNIPPET_PACKAGE_NAME
37+
38+
39+
class WifiAwareAttachTest(base_test.BaseTestClass):
40+
"""Wi-Fi Aware Attach test class."""
41+
42+
ads: list[android_device.AndroidDevice]
43+
44+
def setup_class(self):
45+
# Register two Android devices.
46+
self.ads = self.register_controller(android_device, min_number=1)
47+
48+
def setup_device(device: android_device.AndroidDevice):
49+
device.load_snippet('wifi_aware_snippet', PACKAGE_NAME)
50+
for permission in RUNTIME_PERMISSIONS:
51+
device.adb.shell(['pm', 'grant', PACKAGE_NAME, permission])
52+
asserts.abort_all_if(
53+
not device.wifi_aware_snippet.wifiAwareIsAvailable(),
54+
f'{device} Wi-Fi Aware is not available.',
55+
)
56+
57+
# Set up devices in parallel.
58+
utils.concurrent_exec(
59+
setup_device,
60+
param_list=[[ad] for ad in self.ads],
61+
max_workers=1,
62+
raise_on_exception=True,
63+
)
64+
65+
def setup_test(self):
66+
for ad in self.ads:
67+
autils.control_wifi(ad, True)
68+
aware_avail = ad.wifi_aware_snippet.wifiAwareIsAvailable()
69+
if not aware_avail:
70+
ad.log.info('Aware not available. Waiting ...')
71+
state_handler = ad.wifi_aware_snippet.wifiAwareMonitorStateChange()
72+
state_handler.waitAndGet(constants.WifiAwareBroadcast.WIFI_AWARE_AVAILABLE)
73+
74+
def teardown_test(self):
75+
utils.concurrent_exec(
76+
self._teardown_test_on_device,
77+
param_list=[[ad] for ad in self.ads],
78+
max_workers=1,
79+
raise_on_exception=True,
80+
)
81+
utils.concurrent_exec(
82+
lambda d: d.services.create_output_excerpts_all(self.current_test_info),
83+
param_list=[[ad] for ad in self.ads],
84+
raise_on_exception=True,
85+
)
86+
87+
def _teardown_test_on_device(self, ad: android_device.AndroidDevice) -> None:
88+
ad.wifi_aware_snippet.wifiAwareCloseAllWifiAwareSession()
89+
ad.wifi_aware_snippet.wifiAwareMonitorStopStateChange()
90+
autils.set_airplane_mode(ad, False)
91+
autils.control_wifi(ad, True)
92+
93+
def on_fail(self, record: records.TestResult) -> None:
94+
android_device.take_bug_reports(
95+
self.ads, destination=self.current_test_info.output_path
96+
)
97+
98+
def test_attach(self) -> None:
99+
"""Basic attaching request.
100+
101+
Validates that attaching to the Wi-Fi Aware service works
102+
without IdentityChanged callback.
103+
"""
104+
dut = self.ads[0]
105+
handler = dut.wifi_aware_snippet.wifiAwareAttached(False)
106+
handler.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
107+
autils.callback_no_response(
108+
handler, constants.AttachCallBackMethodType.ID_CHANGED
109+
)
110+
111+
def test_attach_with_identity(self) -> None:
112+
"""Basic attaching request with extra callback.
113+
114+
Validates that attaching to the Wi-Fi Aware service works
115+
with IdentityChanged callback.
116+
"""
117+
dut = self.ads[0]
118+
handler = dut.wifi_aware_snippet.wifiAwareAttached(True)
119+
handler.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
120+
handler.waitAndGet(constants.AttachCallBackMethodType.ID_CHANGED)
121+
122+
def test_attach_multiple_sessions(self):
123+
"""Multiple attaching request.
124+
125+
Validates that attaching to the Wi-Fi Aware service works with
126+
multiple request at same time.
127+
"""
128+
dut = self.ads[0]
129+
handler_1 = dut.wifi_aware_snippet.wifiAwareAttached(False)
130+
handler_2 = dut.wifi_aware_snippet.wifiAwareAttached(True)
131+
handler_3 = dut.wifi_aware_snippet.wifiAwareAttached(False)
132+
handler_1.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
133+
autils.callback_no_response(
134+
handler_1, constants.AttachCallBackMethodType.ID_CHANGED, 10, True
135+
)
136+
handler_2.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
137+
handler_2.waitAndGet(constants.AttachCallBackMethodType.ID_CHANGED)
138+
handler_3.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
139+
autils.callback_no_response(
140+
handler_3, constants.AttachCallBackMethodType.ID_CHANGED, 10, True
141+
)
142+
143+
def test_attach_with_no_wifi(self):
144+
"""WiFi Aware attempt to attach with wifi off.
145+
146+
Validates that if trying to attach with Wi-Fi disabled will receive
147+
the expected failure callback. As a side-effect also validates that the
148+
broadcast for Aware unavailable is received.
149+
"""
150+
dut = self.ads[0]
151+
state_handler = dut.wifi_aware_snippet.wifiAwareMonitorStateChange()
152+
autils.control_wifi(dut, False)
153+
state_handler.waitAndGet(constants.WifiAwareBroadcast.WIFI_AWARE_NOT_AVAILABLE)
154+
attach_callback = dut.wifi_aware_snippet.wifiAwareAttached(True)
155+
attach_callback.waitAndGet(constants.AttachCallBackMethodType.ATTACH_FAILED)
156+
dut.wifi_aware_snippet.wifiAwareMonitorStopStateChange()
157+
158+
def test_attach_with_location_off(self):
159+
"""Function/Attach test cases/attempt to attach with location mode off.
160+
161+
Validates that if trying to attach with device location mode off will
162+
receive the expected failure callback. As a side-effect also validates
163+
that the broadcast for Aware unavailable is received.
164+
"""
165+
dut = self.ads[0]
166+
asserts.skip_if(
167+
autils.check_android_os_version(
168+
dut, constants.Operator.GREATER_EQUAL, constants.AndroidVersion.T
169+
),
170+
'From T build Aware will not be disabled due to location off',
171+
)
172+
state_handler = dut.wifi_aware_snippet.wifiAwareMonitorStateChange()
173+
dut.adb.shell('settings put secure location_mode 0')
174+
state_handler.waitAndGet(constants.WifiAwareBroadcast.WIFI_AWARE_NOT_AVAILABLE)
175+
attach_callback = dut.wifi_aware_snippet.wifiAwareAttached(True)
176+
attach_callback.waitAndGet(constants.AttachCallBackMethodType.ATTACH_FAILED)
177+
dut.adb.shell('settings put secure location_mode 3')
178+
state_handler.waitAndGet(constants.WifiAwareBroadcast.WIFI_AWARE_AVAILABLE)
179+
dut.wifi_aware_snippet.wifiAwareMonitorStopStateChange()
180+
181+
def test_attach_apm_toggle_attach_again(self):
182+
"""Function/Attach test cases/attempt to attach with airplane mode on.
183+
184+
Validates that enabling Airplane mode while Aware is on resets it
185+
correctly, and allows it to be re-enabled when Airplane mode is then
186+
disabled.
187+
"""
188+
dut = self.ads[0]
189+
asserts.skip_if(
190+
not dut.is_adb_root,
191+
'APM toggle needs Android device(s) with root permission',
192+
)
193+
state_handler = dut.wifi_aware_snippet.wifiAwareMonitorStateChange()
194+
attach_callback = dut.wifi_aware_snippet.wifiAwareAttached(True)
195+
attach_callback.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
196+
autils.set_airplane_mode(dut, True)
197+
if autils.check_android_os_version(
198+
dut, constants.Operator.GREATER_EQUAL, constants.AndroidVersion.T
199+
):
200+
if not autils._check_wifi_status(dut):
201+
return
202+
else:
203+
autils.control_wifi(dut, False)
204+
autils.callback_no_response(
205+
state_handler,
206+
constants.WifiAwareBroadcast.WIFI_AWARE_AVAILABLE,
207+
10,
208+
True,)
209+
state_handler.waitAndGet(constants.WifiAwareBroadcast.WIFI_AWARE_NOT_AVAILABLE)
210+
autils.set_airplane_mode(dut, False)
211+
state_handler.waitAndGet(constants.WifiAwareBroadcast.WIFI_AWARE_AVAILABLE)
212+
attach_callback = dut.wifi_aware_snippet.wifiAwareAttached(True)
213+
attach_callback.waitAndGet(constants.AttachCallBackMethodType.ATTACHED)
214+
dut.wifi_aware_snippet.wifiAwareMonitorStopStateChange()
215+
216+
217+
if __name__ == '__main__':
218+
# Take test args
219+
if '--' in sys.argv:
220+
index = sys.argv.index('--')
221+
sys.argv = sys.argv[:1] + sys.argv[index + 1 :]
222+
223+
test_runner.main()

0 commit comments

Comments
 (0)