Commit graph android_packages_modules_Co.../staticlibs/testutils/host/python
Message SHA1
Stabilize flaky tests by adding packet delay
Introduce a 3-second delay in each packet send.
Before sending each packet, wait for 3 seconds to give the
firmware time to turn on the APF.
The firmware may have throughput calculation logic that
depends on a certain time window.

Flag: EXEMPT test only
Bug: 434614102
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Test: ./cts-tradefed run commandAndExit cts \
      -m CtsConnectivityMultiDevicesTestCases \
      -t ApfV6Test --shard-count 2
Change-Id: I0807562cd87cbfe90c90d48cf2d0e41673c153b0

Jimi Chen   commited 2025-08-06 13:11:46 +00:00
003403e237
Make APF packet count assertion more robust
Improve the APF test by changing the packet count assertion from
`== 1` to `> matched_pkt_count_before_test`.

This handles scenarios where the packet counter might already
have a non-zero value or increment due to other traffic, making
the test more reliable. The test now asserts that the specific
test packet caused the counter to increase.

Flag: EXEMPT test only
Bug: 419427388
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Change-Id: Id3c0de786e674214948e7030519fe25383c9958c

Jimi Chen   commited 2025-07-29 08:56:35 +00:00
c4fcf02870
Send multiple packets for stability
The test was observed to be flaky when sending a single packet.
Sending three packets increases the likelihood of the test's
assertion passing reliably, addressing potential timing issues
or packet loss.

Flag: EXEMPT test only
Bug: 419427388
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test --iteration 10
Change-Id: I42426d49a81871e6c8e275b1bd8cb0964290ce17

Jimi Chen   commited 2025-07-29 07:23:24 +00:00
ed5e3c185a
Fix lambda returning set instead of boolean
The `expect_with_retry` utility expects the lambda to return a
boolean value. However, the previous implementation wrapped the
comparison result `apf_utils.get_matched_packet_counts(...) == 1`
inside a set `{...}`.

This caused the lambda to return a set (e.g., `{True}` or `{False}`),
which is truthy if non-empty, but not the actual boolean result.
This commit removes the unnecessary set wrapper, ensuring the lambda
directly returns the boolean outcome of the packet count comparison

Flag: EXEMPT test only
Bug: 419427388
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Change-Id: Idd77d905e5be7933b3213df5cb772773286becfa

Jimi Chen   commited 2025-07-22 08:47:03 +00:00
7e922cf917
Increase retry interval for APF packet count assertion
Adds `retry_interval_sec` to the packet count assertion in `ApfTestBase`.
This addresses intermittent test flakiness by allowing more time for the
server device to capture offloaded packets.

Flag: EXEMPT test only
Bug: 419427388
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test --iteration 10
Change-Id: Ia0ac83a7054c6a606f300546306fef1b8fccd701

Jimi Chen   commited 2025-07-21 07:27:43 +00:00
ab0cdd8fce
refactor: Lazy load IP addresses for APF tests
Previously, IPv4 and IPv6 addresses were retrieved in `ApfTestBase.setup_class`,
which meant all APF tests assumed the presence of both.

This change refactors `ApfTestBase` to introduce dedicated methods:
- `get_and_expect_ipv4_addresses_exist()`
- `get_and_expect_ipv6_addresses_exist()`

These methods now handle the retrieval and assertion of IP addresses.
Individual test cases in `ApfV6Test` are updated to call these methods
only when the respective address type is required for the specific test
scenario.

This improves test robustness by ensuring tests only depend on the
necessary IP addresses, allowing for more precise test setup and failure
reporting. Additionally, the doze mode activation is reordered to occur
after initial network setup.

Flag: EXEMPT mainline
Bug: 419427388
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Change-Id: I340bcb77fe66cc9927dcd58e5899cdf9a4375daa

Jimi Chen   commited 2025-07-16 04:31:40 +00:00
419e088796
Add pre-test check for APF offload status
This commit introduces a verification step that runs before APF
offload tests.

It uses the `cmd network_stack apf <iface> config` shell command
to dump the list of enabled offloads. By checking this list first,
we can ensure that the specific offload under test is actually
enabled, avoiding misleading failures and improving test reliability.

Flag: EXEMPT mainline
Bug: 419427388
Test: ./cts-tradefed run commandAndExit cts -m CtsConnectivityMultiDevicesTestCases -t ApfV6Test --shard-count 2
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Change-Id: I65fecdcd4f2f9e9586da2684bf68cec215d0f359

Jimi Chen   commited 2025-07-08 04:11:22 +00:00
af1e460e26
Add util to get APF offload config
Adds a new helper function `get_apf_config_from_cmd` to retrieve the
list of enabled APF offloads for a given network interface.

Flag: EXEMPT mainline
Bug: 419427388
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I0acc9fcbf2e8bc6f4d8f309c2ec64c003c325c42

Jimi Chen   commited 2025-07-08 04:10:41 +00:00
7c190ecb78
Force device unroot in the multi-device setup
In mobly, it will root the device if the device is rootable.
If there is some operation needs root permission,
the test result will be inconsistent between user and userdebug build.

Flag: EXEMPT mainline
Bug: 419423721
Test: atest CtsConnectivityMultiDevicesTestCases
Change-Id: Ib962b565aeaf8f0e1737b700a16420277e088e6b

Jimi Chen   commited 2025-06-04 14:27:06 +00:00
cfc8a85432
Format multidevice tests with pyformat
Use the following commands to apply pyformat
pyformat -i -r --force_quote_type single staticlibs/
pyformat -i -r --force_quote_type single tests/

Flag: EXEMPT mainline
Bug: 419423721
Test: TH
Change-Id: I0d3914ec652664ed4ec5d44afc25d97ff8bb4626

Jimi Chen   commited 2025-06-04 14:27:06 +00:00
ead97d1ef3
Skip APF multidevice CTS if device support automotive feature
Flag: EXEMPT mainline
Bug: 407637806
Test: TH
Change-Id: I1dff6c2507455451951314ba0298cecb62d4bb17

Jimi Chen   commited 2025-06-02 05:10:24 +00:00
80a2a14a91
Refactor: apply pyformat for coding style consistency
add pyformat for presubmit hook

Flag: EXEMPT mainline
Bug: 419423721
Test: atest CtsConnectivityMultiDevicesTestCases
Change-Id: I9abc5cee454e8c8e21ce7e3c134145857680251f

Jimi Chen   commited 2025-05-28 12:44:57 +00:00
dcbe9b403d
Replace get_apf_counter from apf shell command instead of dumpsys
Flag: EXEMPT mainline
Bug: 419423721
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I6f5f93acb13503ce23066b1541c0843f6d7951d2

Jimi Chen   commited 2025-05-28 04:55:33 +00:00
5e69785de3
Merge "Fix for timing issue for handling user interaction addExternalApprover" into main
Paul Hu   authored and   Android (Google) Code Review   commited 2025-05-07 02:48:27 -07:00
8014cfea1e
Fix for timing issue for handling user interaction addExternalApprover
If client knows network name and passphrase, it can connect to the
server (Group owner) without user interaction. In this case, it needs
to use interface address of group owner, not device address

Bug: 408245757
Test: atest CtsConnectivityMultiDevicesTestCases
Flag: EXEMPT bug fix
Change-Id: I47bc8609e63564f4226a4ef71ea9e382f5f919fe
Signed-off-by: Rohit Kothari <r.kothari@samsung.corp-partner.google.com>

Rohit Kothari   authored and   Paul Hu   commited 2025-05-07 02:47:38 -07:00
50b479097d
Network name for Wi-Fi Direct group should have prefix DIRECT-xy.
Network name for Wi-Fi Direct group must starts with the prefix DIRECT-xy.
But CTS sometimes makes name with non-character in the position of “xy”.
To prevent issue, network name needs to be generated with the prefix DIRECT-xy.

Bug: 408245757
Test: atest CtsConnectivityMultiDevicesTestCases
Flag: EXEMPT bug fix
Change-Id: Ida07616b920b32dadd76f732ff2d87cc6ecc960d
Signed-off-by: Rohit Kothari <r.kothari@samsung.corp-partner.google.com>

Rohit Kothari   authored and   Paul Hu   commited 2025-05-07 00:34:24 -07:00
756adee79c
Remove non-functional IGMPv3 test and flaky APF checks
This commit removes the test_igmpv3_general_query_offload() test
logic. This test fails on user builds because they run on non-rootable
devices, preventing the necessary test operations.

Additionally, the APF counter check logic is removed as it was causing
test flakiness and instability.

Bug: 406570694
Test: TH
Flag: EXEMPT test only change
Change-Id: I9f2f32c49737721e537d578d6df41d4062d0684f

Yuyang Huang   commited 2025-04-22 18:02:55 +09:00
3781d05054
Improve stability of APFv{4,6} multi-device tests
This commit enhances the stability of the APFv{4,6} multi-device tests by addressing several sources of flakiness and improving the test setup and validation.

Specifically, this commit:

* Increased sleep time in the test setup. This ensures APF is activated before each test, preventing unexpected behavior.
* Added sleep time in `ApfV4Test` to ensure APF remains enabled and is not disabled due to high throughput scenarios.
* Changed the validation order to first check received packets and then APF counters. This helps to more easily identify the root cause of test failures.
* Changed the Ethernet destination address from multicast to unicast in `ApfV6Test` to prevent packets from being filtered due to DTIM skip.
* Removed the `test_broadcast_arp_request_offload()` test, which was flaky due to DTIM skip and is adequately covered by the `test_unicast_arp_request_offload()` test.

Bug: 406570694
Flag: TEST_ONLY
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV4Test
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Test: run cts -m CtsConnectivityMultiDevicesTestCases --skip-preconditions -t ApfV4Test --shard-count 2
Test: run cts -m CtsConnectivityMultiDevicesTestCases --skip-preconditions -t ApfV6Test --shard-count 2
Change-Id: I053509459078d0bd94e16a6bf7349b948f930e6c

Jimi Chen   authored and   Yuyang Huang   commited 2025-04-02 04:31:01 -07:00
744a17443a
Merge "Use scapy to generate ARP packet in multi-device test" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2025-03-20 16:58:58 -07:00
4703e17d98
Merge "Revert "Skip multi-device tests instead of abort if device is non-B+ devices"" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-03-20 06:11:49 -07:00
23cfd04e9b
Use scapy to generate ARP packet in multi-device test
Test: m connectivity_multi_devices_snippet && atest CtsConnectivityMultiDevicesTestCases
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I30adfe7ca2fef83ed4ef2ea3e5bc2291b9016530

Jimi Chen   commited 2025-03-20 12:25:57 +00:00
f0343a65d1
Revert "Skip multi-device tests instead of abort if device is non-B+ devices"
This reverts commit 372a15220a.

Reason for revert: this is Android B+ CTS and shouldn't be run with previous release, this can help to catch human error.

Change-Id: I867c63511d4f640e07b8317506291de284efcef3

Jimi Chen   commited 2025-03-20 04:33:43 -07:00
a27bbe9eea
Delay test for APF activation after screen-off
CTS tests screen-on device in the beginning, but APF is not activated after screen-off in the test setup.
This change adds 3 secs delay to ensure APF activation before test execution.

Bug: 402667362
Test: ./cts-tradefed run cts-on-gsi -m CtsConnectivityMultiDevicesTestCases -t ApfV4Test --shard-count 2
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV4Test
Change-Id: I067ce792b5f89e2f0051933982ebc734607fbf98

Jimi Chen   commited 2025-03-20 00:41:07 -07:00
d9b49c6938
Skip multi-device tests instead of abort if device is non-B+ devices
Test: TH
Change-Id: Ib27dea9197d5230313944777abb958f68425b213

Jimi Chen   commited 2025-03-19 14:38:06 +00:00
372a15220a
Add apf_ram_at_least decorator to restrict multi-device tests to the given minimum apf ram size capable device.
Test: TH
Change-Id: I1042fd0662695e9bc71833eb24311f4436b2676c

Jimi Chen   commited 2025-03-19 14:35:15 +00:00
8f712c6ed9
Add get exclude all host IPv6 multicast addresses function to apf_utils
Test: atest NetworkStaticLibHostPythonTests
Change-Id: Ib05eaf6ac94e9511a43b4b494eb5935746f50aa7

Jimi Chen   commited 2025-03-19 13:41:41 +00:00
ceefdceafd
Use non-tentative IPv6 addresses in multi-device test
This update ensures multi-device offload tests retrieve only non-tentative IPv6 addresses,
preventing test caused by tentative addresses undergoing duplicate address detection.

Test: atest NetworkStaticLibHostPythonTests
Change-Id: Id2f61a34eda01a6e8e0457647229fe438a85c232

Jimi Chen   commited 2025-03-17 06:31:46 +00:00
2bfe2654d1
Merge "Add at_least_B() decorator to restrict multi-device tests to Android B+ capable device." into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-03-13 12:01:33 -07:00
d5dd81741c
Add at_least_B() decorator to restrict multi-device tests to Android B+ capable device.
Test: TH
Change-Id: Id5fde8c59560bb84bed062331121c3524f362c7b

Jimi Chen   commited 2025-03-13 14:05:09 +00:00
476552a7ae
Use 'ip link' to prevent permission errors in non-root environments
The 'ip link show' requires root permissions, causing errors.
This change replaces 'ip link show' with 'ip link'.

Bug: 401123634
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I82b219ae9179f23e3233f797aeb4aa3740e6d3ec

Jimi Chen   commited 2025-03-07 00:25:34 +00:00
c471fc945c
Do not expect validated when connect to Wi-Fi for upstream type None
Currently, upstream network validation is always required, even
for type None. This is unnecessary for APF and mDNS tests, as
they can be executed on local networks. Additionally, some
devices lack the ability to perform network validation when the
hotspot is enabled due to hardware limitations. Therefore, remove
the validation check for upstream type None.

Test: m connectivity_multi_devices_snippet && \
      atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Bug: 335368434
Bug: 396551848
Change-Id: If2a96cf9d62e37fc27be6193f9ce9b9cfc8613df

Junyu Lai   authored and   Paul Hu   commited 2025-02-17 21:22:19 -08:00
d16aa5538e
Reconnect to wifi if supported
Some tests may disable wifi when testing, for example,
tests which setup cellular default network.
Reconnect to wifi to prevent from flaky.

Test: m connectivity_multi_devices_snippet && \
      atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Bug: N/A
Change-Id: Ic0e27efc0e82698618c651c0a78b000c0ffe2131

Junyu Lai   commited 2024-12-05 08:12:25 +00:00
ad713e007a
Refactor is_packet_capture_supported() by expect_throws()
Test: atest NetworkStaticLibHostPythonTests
Change-Id: Ibbc249e3d6ef182207ba3fe37c47bab7e099f2b0

Jimi Chen   commited 2024-10-22 03:07:27 +00:00
13a9f53d98
Add expect_throws() to assert_utils.py to check expected exception
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I2e181f5b6f41e6de228d516dff970d47cfa3eaf6

Jimi Chen   commited 2024-10-22 03:06:47 +00:00
a0c0168ae6
Retrieve IPv4 and IPv6 addresses for client and server device in test setup
Test: m connectivity_multi_devices_snippet && atest CtsConnectivityMultiDevicesTestCases
Change-Id: Icba82832fa1840ea1a3299f61027666d4dd90d46

Jimi Chen   commited 2024-10-07 13:34:02 +00:00
4c3a13c048
Add send and check reply packet function for multi-devices tests
The `send_packet_and_expect_reply_received` start capurting packets,
and then send out request packets, then get expected packets counts to validate.
In the end, stop capturing for the specified interface.

Test: m connectivity_multi_devices_snippet && atest CtsConnectivityMultiDevicesTestCases
Change-Id: I275534a45ce0ed363fa8ab9d12272d25845aa598

Jimi Chen   commited 2024-10-07 13:34:01 +00:00
d07d47b1d3
Add packet capture and match network_stack adb command to to apf_utils
It wraps the following 3 commands for multi-devices tests
- cmd network_stack capture start <interface>
- cmd network_stack capture stop <interface>
- cmd network_stack capture matched-packet-counts <interface> <pkt-in-hex>

Add a helper function `is_packet_capture_supported` as APFv6 precondition check.
Test: atest NetworkStaticLibHostPythonTests

Change-Id: I526c678c6e753cee3969b04a56ab33e5e3d1600d

Jimi Chen   commited 2024-10-07 13:33:57 +00:00
1644f95852
Support get multiple ipv4/ipv6 addresses in apf_utils
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I806696437acf905c049762d59a46c866ff0584ef

Jimi Chen   commited 2024-09-27 06:55:54 +00:00
738bf999d5
Merge "Revert "Use unicast instead of broadcast as ethernet destination in test_apf_drop_ethercat"" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-09-26 18:12:15 +00:00
b437e753f7
Revert "Use unicast instead of broadcast as ethernet destination in test_apf_drop_ethercat"
This reverts commit 46102348e0.

Reason for revert: mistakenly submitted.

Change-Id: I6072a9828a8cc0633ca35ea2ecf7707f2b3573a1

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-09-26 18:11:41 +00:00
c3eccf9ef4
Merge "Use unicast instead of broadcast as ethernet destination in test_apf_drop_ethercat" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-09-25 21:02:35 +00:00
aabad69006
Use unicast instead of broadcast as ethernet destination in test_apf_drop_ethercat
To prevent packet dropped earlier by multicast filtering,
use unicast ethernet destination instead

Bug: 360730207
Test: m connectivity_multi_devices_snippet && atest CtsConnectivityMultiDevicesTestCases:ApfV4Test
Change-Id: I4816b71f68f349abf1423c7013bb058ccc233d61

Jimi Chen   authored and   Maciej Żenczykowski   commited 2024-09-25 19:42:01 +00:00
46102348e0
Add get ipv4/ipv6 address function to apf_utils
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I535bdca481f600b95603206bf368a106cbb45b42

Jimi Chen   commited 2024-09-20 05:45:19 +00:00
b756497e05
Add packet_utils for multi-devices tests
Test: atest NetworkStaticLibHostPythonTests
Change-Id: I211d071232d1730c043eef29e1bf2bce27a6e2a6

Jimi Chen   commited 2024-09-20 05:41:20 +00:00
0e1c1cc92d
Check APF version, VSR API level, and Android version
This commit introduces checks for APF version, VSR API level,
and Android version to decide whether an APFv4 test should be
run, skipped, or fail:
* If Android version is less than V, skip the test
* If VSR API level is greater than or equal to 14 and APF
  version is less than 4, fail the test
* Otherwise, if APF version is less than 4, skip the test

Test: m connectivity_multi_devices_snippet && \
      atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Fix: 352132428
Change-Id: I023164fb59ad40f489abea2e0c45761efc39699b

Junyu Lai   commited 2024-09-10 18:06:28 +08:00
73711f7b41
Setup Wi-Fi P2P connection
Add functionalities to setup Wi-Fi P2P connection for subsequent
Wi-Fi P2P mDns tests

Bug: 343311941
Test: atest CtsConnectivityMultiDevicesTestCases
Change-Id: I060509deb32c078829c1108f9ae2a29561e00d53

Paul Hu   commited 2024-08-13 07:20:21 +00:00
3e24dec82a
Refactor Drop EtherCat packet test
This is a no-op refactoring, which is preparation for follow-up
changes to add more apf tests.

This includes:
1. Add a method to send packet and expect counter increases.
2. Inline the packet construction code in the test method.

Test: atest NetworkStaticLibHostPythonTests
Test: m connectivity_multi_devices_snippet && \
      atest CtsConnectivityMultiDevicesTestCases
Bug: 350880989
Change-Id: Iadcfd97740033306af1b6a474004cbf0699ddd1b

Junyu Lai   commited 2024-08-01 03:32:19 +00:00
6f6b1a4684
Refactor ApfV4Test
This is a no-op refactoring, which is preparation for follow-up
changes to add more apf test classes.

This includes:
1. Move initialization code to a base class, which setup a hotspot
   and a client connects to it, and enable doze mode to
   activate the apf.
2. Check whether send raw packet is supported before testing.

Test: m connectivity_multi_devices_snippet && \
  atest CtsConnectivityMultiDevicesTestCases
Test: atest NetworkStaticLibHostPythonTests
Bug: 350880989
Change-Id: I6376935883653182728e473e2f5533407d993d7b

Junyu Lai   commited 2024-08-01 03:32:19 +00:00
cf655869ba
Move apf test to a standalone file
This is a no-op refactoring, which is preparation for follow-up
changes to add more apfv4 tests.

This includes:
  1. Add a entry point for multi-device tests to collect
     test cases from different files.
  2. Move multi-device initialization code to a base class.
  3. Make different test classes inherit the base class.

Test: m connectivity_multi_devices_snippet && \
      atest CtsConnectivityMultiDevicesTestCases
Bug: 350880989
Change-Id: I294c85d8e09633bbf02ba1543b9f2ea3e988e20d

Junyu Lai   commited 2024-08-01 03:32:19 +00:00
32a2d151cc
Add wifip2p_utils and Wifip2pMultiDevicesSnippet
Add wifip2p_utils and Wifip2pMultiDevicesSnippet for subsequent
Wi-Fi P2P mDns tests

Bug: 343311941
Test: atest CtsConnectivityMultiDevicesTestCases
Change-Id: Icfdea97595292e024269e789673e3b1e23aa37ee

Paul Hu   commited 2024-07-16 08:51:41 +00:00
f5020471fe