Commit graph android_packages_modules_Co.../staticlibs/testutils
Message SHA1
Ensure flag restoration logic is always executed in SetFeatureFlagsRule.
`base.evaluate()` can be interrupted by other rules in the chain, such
as DevSdkIgnoreRule, if an assumption fails. This prevents
SetFeatureFlagsRule from executing its flag value restoration logic,
leading to an inconsistent state. This change ensures the restoration
logic runs regardless of exceptions.

Flag: EXEMPT mainline
Bug: 440618747
Test: TH
Change-Id: Iba4483b45f11aeed8ae565f8080b2bebd299046c

Xiao Ma   commited 2025-08-27 16:55:12 +09:00
bda151cd67
Merge "Stabilize flaky tests by adding packet delay" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-08-06 18:26:21 -07:00
a9a7a7c0d2
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
Don't call ContentObserver#onChange(..., UserHandle) on S.
S does not have this method (and correspondingly does not have
registerContentObserverAsUser). Use the overload that
does not take a UserHandle.

Bug: 397521796
Flag: TEST_ONLY
Test: test-only change
Change-Id: Icc00abb64fdc47128b93636708990f8ab67057f2

Lorenzo Colitti   commited 2025-08-05 18:02:02 +09:00
7b693cae9f
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
Fix permissions in RestoreEthernetRule
The previous runAsShell calls adopted permissions spuriously. This
change fixes runAsShell to consistently adopt the correct permission
for the respective API call.

Also calls setEthernetEnabled() no matter what the current state is at
the end of the test (as there is no harm in doing so).

Test: TH
Flag: EXEMPT mainline
Change-Id: Ib11b889148213b160567cf0a3b9ea72b5b0c851e

Patrick Rohr   commited 2025-07-17 13:54:12 -07:00
ac29211362
Merge changes I6fb98e87,I3f61b474 into main
* changes:
  Delete unused TestInterfaceStateListener
  Reset EthernetManagerTest to reintroduce InterfaceStateListener

Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-07-17 09:33:42 -07:00
7134b8ca22
Delete unused TestInterfaceStateListener
Test: TH
Flag: EXEMPT mainline
Change-Id: I6fb98e87ca1aa460aca6d08cbdd5ddcaaaee55de

Patrick Rohr   commited 2025-07-16 11:21:08 -07:00
3563cc1725
Merge changes I332c8d43,I340bcb77 into main
* changes:
  Simplify APF IGMPv3 general query offload test
  refactor: Lazy load IP addresses for APF tests

Jimi Chen   authored and   Android (Google) Code Review   commited 2025-07-16 07:38:59 -07:00
5904ce1431
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
Merge "Refactor: Add RestoreEthernetRule for ethernet tests" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-07-10 03:58:40 -07:00
f693a0f9bf
Refactor: Add RestoreEthernetRule for ethernet tests
This is a no-op, test only refactoring.
Move ethernet state management logic from EthernetManagerTest into a
dedicated JUnit test rule, RestoreEthernetRule. This new rule is
responsible for saving the initial ethernet state, allowing tests to
enable or disable it, and restoring the original state upon test
completion.  This refactoring simplifies EthernetManagerTest and
promotes code reuse.

Flag: EXEMPT EXEMPT test only refacotring
Test: atest NetworkStaticLibTests:com.android.testutils.RestoreEthernetRuleTest \
      CtsNetTestCases:android.net.cts.EthernetManagerTest --update-device
Bug: 410731080
Change-Id: If3dd869d6af4e0c659386621fb5d92012aa574d1

Junyu Lai   commited 2025-07-10 15:25:15 +08:00
9f6a566d89
Merge changes I65fecdcd,I0acc9fcb into main
* changes:
  Add pre-test check for APF offload status
  Add util to get APF offload config

Jimi Chen   authored and   Android (Google) Code Review   commited 2025-07-08 20:24:46 -07:00
df4c09fe3a
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
Refactor: Introduce TestableCallback for EthernetStateListener
The monolithic EthernetStateListener has been refactored and split
into two specialized test classes:

- TestInterfaceStateListener: For interface state callbacks.
- TestEthernetStateListener: For ethernet state callbacks.

Both new classes now extend TestableCallback, providing a standardized
and more robust way to manage and verify listener interactions in
unit tests. This improves testability and clarity of test code.

This is a no-op, test-only change.

Flag: EXEMPT refactor
Test: atest CtsNetTestCases:android.net.cts.EthernetManagerTest
Bug: 410731080
Change-Id: I667e3607954dcb073b2732b16bedfbc71a70bb39

Junyu Lai   commited 2025-07-06 23:39:42 -07:00
4c7ba24f57
Refactor: Move EthernetStateListener to a standalone file
This is a no-op, test-only change.
Move EthernetStateListener from EthernetManagerTest.kt to a new
standalone file in testutils.
This refactoring makes the listener reusable across other tests and
decouples it from its dependency on EthernetTestInterface.

Flag: EXEMPT refactor
Test: atest CtsNetTestCases:android.net.cts.EthernetManagerTest
Bug: 410731080
Change-Id: Iacd9236f758011da0714884040aebe3e42ef1646

Junyu Lai   authored and   Chalard Jean   commited 2025-07-04 13:03:55 +09:00
bb75ed8900
Merge "Add a ContentResolverWithFakeSettingsProvider class to testutils." into main
Lorenzo Colitti   authored and   Android (Google) Code Review   commited 2025-07-01 04:13:49 -07:00
7e5665ae44
Support AutoReleaseBluetoothRule
This change introduces a utility class to disable
Bluetooth before testing, in case it was previously connected
as the default network.

Flag: EXEMPT test only
Test: atest NetworkStaticLibTests:com.android.testutils.AutoReleaseBluetoothRuleTest \
      --update-device
Bug: 410731080
Change-Id: I95afc6174698bf73b21d95a85c02e107ee0d59f7

Junyu Lai   commited 2025-07-01 17:52:22 +08:00
c5c80cc9ab
Add a ContentResolverWithFakeSettingsProvider class to testutils.
This makes it a bit easier to use FakeSettingsProvider and
get settings change notifications. It's still difficult because
the ContentResolver#registerContentObserver methods are final and
cannot be subclassed, but at least it removes the need for some
boilerplate code.

Bug: 397521796
Flag: TEST_ONLY
Test: tests updated in next CL
Change-Id: I43b45eca964b103ad65d0db82682aa8644fcacaf

Lorenzo Colitti   commited 2025-06-28 11:06:53 +09:00
86625b4734
Fix typo
Still not sure whether the log message is 100% correct. Technically, it
means no callback was received between now and the last successful poll
operation that incremented the track record position.

Test: TH
Flag: EXEMPT trivial
Change-Id: I57e9600321cb4a79d035d64d488af09b17a50706

Patrick Rohr   commited 2025-06-24 08:33:51 -07:00
a36b89c5b0
Migrate CSAgentWrapper to TestableCallback.
This makes it much more powerful as well as consistent with
other use cases of this paradigm.

Test: TH
Flag: EXEMPT test-only
Change-Id: I4f5b86bfdd16d8bfe21b79235444817a13bc3c49

Chalard Jean   authored and   Jean Chalard   commited 2025-06-20 01:08:25 -07:00
6fe5d13b3a
Don't blame a non-existent test for not restoring default networking
RestoreDefaultNetwork is a virtual test, causing a lot of confusion among
testers who can't reproduce or run this test.
Instead, blame the test that actually failed to restore the default network.

Before :
```
[1/2] android.net.cts.MultinetworkApiTest#testFoo: PASSED (253ms)
[2/2] android.net.cts.MultinetworkApiTest#RestoreDefaultNetwork: FAILED (54ms)

STACKTRACE:
java.lang.IllegalStateException: testFoo does not restore the default network. Default network has caps null ; expected a network with transports = WIFI
        at com.android.testutils.DefaultNetworkRestoreMonitor$listener$1.testFinished(DefaultNetworkRestoreMonitor.kt:64)
```

After :
```
[1/2] android.net.cts.MultinetworkApiTest#testFoo: PASSED (353ms)
[2/2] android.net.cts.MultinetworkApiTest#testFoo: FAILED (54ms)

STACKTRACE:
java.lang.IllegalStateException: testFoo does not restore the default network. Default network has caps null ; expected a network with transports = WIFI
        at com.android.testutils.DefaultNetworkRestoreMonitor$listener$1.testFinished(DefaultNetworkRestoreMonitor.kt:64)
```

Test: this
Flag: EXEMPT test-only
Bug: 413188127
Change-Id: Ia17bc9ddeedbd9303e5788ef79fb190e6e9dca1e

Chalard Jean   commited 2025-06-20 15:12:31 +09:00
00275e3f44
Have TestableNetworkAgent implement Expectable
This will make these agents testing a lot easier.

Also fix a small bug where waiting for callbacks that
are not expected would take a lot longer than it should.

Also trivial improvements to logging that I needed to stabilize
this.

Test: TH
Flag: EXEMPT test-only
Change-Id: I654d63eb226990ad1c5087cade7cf0a82d8526a1

Chalard Jean   commited 2025-06-16 17:28:57 +09:00
7bff7b2455
Make a base class for testable callbacks
Have TestableNetworkCallback adopt it, as a first client. It's also by
far the most complex.

Test: TH
Flag: EXEMPT test-only
Change-Id: Ie58d051b4478c901b7f0f54e89a67d22f1ee2ce2

Chalard Jean   commited 2025-06-10 17:22:01 +09:00
2db96977db
Merge "Revert "Make a base class for testable callbacks"" into main
Priyanka Advani (xWF)   authored and   Android (Google) Code Review   commited 2025-06-05 13:02:09 -07:00
130e55e17e
Revert "Make a base class for testable callbacks"
This reverts commit a77d5ac126.

Reason for revert: Droidmonitor created revert due to b/422782308. Will be verifying through ABTD before submission.

Fix: 422782308
Change-Id: I00825e0f17a9a9e0d152ac8ebe767da3f267fbb1

Priyanka Advani (xWF)   authored and   Android (Google) Code Review   commited 2025-06-05 11:35:49 -07:00
827aa58224
Merge "Make a base class for testable callbacks" into main
Jean Chalard   authored and   Android (Google) Code Review   commited 2025-06-05 05:12:50 -07:00
595ab39d06
Make a base class for testable callbacks
Have TestableNetworkCallback adopt it, as a first client. It's also by
far the most complex.

Test: TH
Flag: EXEMPT test-only
Change-Id: Ifd636a09d0695f04b17330c4987f2b7b742508fa

Chalard Jean   commited 2025-06-05 16:13:34 +09:00
a77d5ac126
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
Address warnings in TestableNetworkCallback
Test: TH
Flag: EXEMPT test-only
Change-Id: Ifcbbc6e5443f619279744be993cce10f4ecd22a5

Chalard Jean   commited 2025-05-19 16:35:55 +09:00
63947668a2
Fix a bug in poll(from)
Test: new test in this patch
Flag: EXEMPT test-only
Change-Id: I00d367ce9db47e3fd30d27816b68280ab418f988

Chalard Jean   commited 2025-05-19 16:35:54 +09:00
f0252b1cf4
Remove RecorderCallback.
This class doesn't actually serve a purpose, it only makes
TestableNetworkCallbck more complex.

Test: CtsNetTestCases ConnectivityCoverageTests
Flag: EXEMPT test-only
Change-Id: I39a598b82a3215384bdfe04980f4b280ab2c2716

Chalard Jean   commited 2025-05-19 16:35:53 +09:00
f2994122c1
Remove deprecated SC_V2 constant
Test: TH
Flag: EXEMPT test-only
Change-Id: I3444fad305f49294ed8c3a850b631f385678c117

Chalard Jean   commited 2025-05-15 09:03:59 +09:00
9373e3442e
Merge "Cleanup and improve logging for DefaultNetworkRestoreMonitor" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-09 02:24:31 -07:00
bb2c4e66ef
Cleanup and improve logging for DefaultNetworkRestoreMonitor
Bug: 413188127
Flag: EXEMPT test-only
Test: CtsNetTestCases
Change-Id: I16938de33e1beee1a38c76eeae2fcf52d8f79870

Chalard Jean   commited 2025-05-09 16:43:56 +09:00
e73d3b934c
Clean up an old flag for removed downstream branches
Test: TH
Flag: EXEMPT test-only
Change-Id: I4a860c7c42afdfb5249b787daee80395096f5c84

Chalard Jean   commited 2025-05-09 14:59:29 +09:00
893f84f96e
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
Add packet builder support for rapid commit option
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I4fde592fca440d08f5d07f090d3c9ad45c2c10a1

Patrick Rohr   commited 2025-05-05 11:10:06 -07:00
bde43b8a72
Add IA_PD Option support to packet builder
The IA_PD Option is modeled as a separate "packet", because it can
contain various options itself. It turns out that with the current
packet builder architecture, building nested packets (of which DHCPv6 is
an extreme example) is actually quite difficult. We would encounter
similar problems if we ever were to try and build netlink packets.

One thing that could be done is to add another overload for
PacketBuilder#div that takes another PacketBuilder object, allowing an
syntax such as:

dhcp6_header / dhcp6_rt_sol_max / (dhcp6_ia_pd / dhcp6_ia_prefix)

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I35694627285759dd17d8a8bf5994aaa96e6b391d

Patrick Rohr   commited 2025-05-05 11:10:06 -07:00
424655f497
Add payload support for Dhcp6Pkt
IA_PD options will be modeled as separate packets

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I2841b1d2283fa50bdc664ab865e64f92aba3ce0c

Patrick Rohr   commited 2025-05-05 11:10:06 -07:00
ea3f8b0fb1