Commit graph android_packages_modules_Co.../staticlibs/testutils/devicetests
Message SHA1
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
Delete unused TestInterfaceStateListener
Test: TH
Flag: EXEMPT mainline
Change-Id: I6fb98e87ca1aa460aca6d08cbdd5ddcaaaee55de

Patrick Rohr   commited 2025-07-16 11:21:08 -07:00
3563cc1725
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
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
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
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
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
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
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
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
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
Add packet builder support for commonly used DCHPv6 options
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I38f3250279c85177fc4ce8f44a35ae3883e7a8ae

Patrick Rohr   commited 2025-05-05 11:10:06 -07:00
684c48afb0
Add Dhcp6Pkt PacketBuilder support
This adds support for building the Dhcp6Pkt header. Options are added
later.

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

Patrick Rohr   commited 2025-05-05 11:10:06 -07:00
3b88b3cec5
Make NdResponder thread-safe
Note that a new neighbor can still be added while processing a packet,
which may influence the result, though this shouldn't affect tests.

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

Patrick Rohr   commited 2025-05-05 11:10:06 -07:00
86b2aed4f4
Merge "Update outdated example code" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-05-01 00:59:52 -07:00
ffd713da3d
Update outdated example code
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I0a87d71f693edcf13ad85049bff24169ddbedb3e

Patrick Rohr   commited 2025-04-30 12:24:09 -07:00
09c0307b9a
Move failWithErrorReason to a common place
This is a shared public utility. Its main utility is for methods
that can fail, have an error message of their own, and also want
to take an error message from a caller and want to combine them.
Example use :
fun <T> assertEquals(expected: T, actual: T, msg: String? = null) {
  if (expected != null) {
    failWithErrorReason(msg, "Expected $expected, got $actual")
  }
}
...which allows someone to say
assertEquals(a, b, "Checking a vs b")

Test: TH
Flag: EXEMPT test-only change
Change-Id: Id3eaa8384b4177f38f13576d9b4d742c52027ae4

Chalard Jean   commited 2025-04-27 15:54:35 +09:00
c96d1ae0e6
Improve TestableNetworkOfferCallback
Update it to follow the latest conventions and add support for
eventuallyExpect.

Test: ConnectivityCoverageTest
Flag: EXEMPT test-only change
Change-Id: Iabc2fad051b874e3e18a0645361409f0427891fb

Chalard Jean   commited 2025-04-27 15:54:34 +09:00
5f3997b6af
Merge "File the per-app request for opted-in satellite-optimized apps" into main
Jean Chalard   authored and   Android (Google) Code Review   commited 2025-04-26 18:18:21 -07:00
31dce78e09
File the per-app request for opted-in satellite-optimized apps
Test: ConnectivityCoverageTest
Bug: 410731080
Flag: EXEMPT controlled in counter-part change ag/33220291
Change-Id: I0307f697a441c2810cafd4643d381e66a0ac9243

Chalard Jean   commited 2025-04-27 02:12:44 +09:00
76a60c1654
Merge "Refactor CarrierConfigRule carrier privilege" into main
Quang Luong   authored and   Android (Google) Code Review   commited 2025-04-24 23:33:19 -07:00
81a8ec0bcf
Refactor CarrierConfigRule carrier privilege
Addressing leftover comments in ag/33040619 regarding carrier privilege
acquisition in CarrierConfigRule with the following changes:
1) Refactored CarrierPrivilegeCallback to match records using a lambda.
2) Added various helper methods to handle calls with permissions.
3) Moved wait for carrier privlege to overrideConfigAndWait.
4) Fixed acquireCarrierPrivilege to append to current cert strings
   instead of overwriting them.
5) Fixed dropCarrierPrivilege to remove from current cert strings
   instead of cleaning up all configs.

Flag: EXEMPT test only change

Bug: 409710349
Test: atest TetheringManagerTest
Change-Id: I1165d95775e809f1aa8905af029fb13df0d3a1a8

Quang Anh Luong   commited 2025-04-25 12:50:32 +09:00
b4f1e46e6d
Merge "Move getTestableNetworks to a common location" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-04-21 00:36:58 -07:00
cb677726c6
Move getTestableNetworks to a common location
Use a common code path for getTestableNetworks, which obtains Wi-Fi and
cellular from network callbacks. This avoids mixing callbacks and
synchronous calls, as getTestableNetworks may be called after
ensureWifiConnected, which uses NetworkCallbacks.

Test: atest
Bug: 253698734
Flag: TEST_ONLY
Change-Id: I8bf946b5258270554286e52b8aa3189aa2ba52e1

Remi NGUYEN VAN   commited 2025-04-21 15:18:57 +09:00
46f86934e1
Remove @JvmSerializableLambda usage in CarrierConfigRule
@JvmSerializableLambda was used in NetworkAgentTest to get around the
link error caused by JUnit enumerating through lambda methods that
referenced classes that weren't available on older platform versions.

Since this code was ported from NetworkAgentTest to CarrierConfigRule
whose lambda methods are not enumerated by JUnit, this workaround isn't
necessary anymore.

Flag: EXEMPT test only change

Bug: 409710349
Test: atest TetheringManagerTest
Change-Id: Ib876e237b239661548ae3c1d23fcb52f389f6254

Quang Anh Luong   commited 2025-04-17 17:10:44 +09:00
5db5a47144
Merge "Fix carrier privilege race condition" into main
Quang Luong   authored and   Android (Google) Code Review   commited 2025-04-16 15:19:02 -07:00
fae887a44b
Fix carrier privilege race condition
CarrierConfigRule cleanup does not wait for carrier privilege value
to change before continuing to the next test, which may cause test
failures if the value isn't fully reset on time.

Make sure the value has time to properly be reset by waiting for
onCarrierPrivilegesChanged before proceeding.

Flag: EXEMPT test only change.

Bug: 409710349
Test: atest TetheringManagerTest#testCarrierPrivilegedIsTetheringSupported TetheringManagerTest#testCarrierPrivilegedStopTetheringWifiWithConfigSucceeds

Change-Id: If67884514a2c1678834ab9ff67947e75e37db0a7

Quang Anh Luong   commited 2025-04-16 15:02:54 +09:00
9bd526d7d4
Add SLLAO support to RaPkt
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I1c0050ca1b634dfa7b2ac5de551a2470e06a9791

Patrick Rohr   commited 2025-04-14 15:47:41 -07:00
ea0364b5d4
Use HexDump instead of Kotlin Experimental API
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I5d0e4989194eecc90e00b1903f8458d9df098ff4

Patrick Rohr   commited 2025-04-14 15:47:41 -07:00
db7d961fb3
Rename lifetime params for brevity
Line breaks make tests harder to read, so this change should help
fitting everything on a single line.

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

Patrick Rohr   commited 2025-04-14 15:47:41 -07:00
c43cc96360
Align UdpPkt with scapy
Renames srcPort to sport and dstPort to dport and generates a random
port number in the range of [1, 65536) if no argument is passed.

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

Patrick Rohr   commited 2025-04-14 15:47:41 -07:00
ea520794cc
Expose backtrace() in PollPacketReader
Figuring out what packets were received is useful for debugging.

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

Patrick Rohr   commited 2025-04-11 15:59:37 -07:00
f39b748cbf
Add support for setting hop limit
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I7ee5b0f31b4db633451a0ddee5d92e45e5947f84

Patrick Rohr   commited 2025-04-11 15:11:33 -07:00
1586ffbeb1
Merge "Print module version in CtsNetTestCases conndiag" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-04-10 02:09:09 -07:00
e2209bf89b
Print module version in CtsNetTestCases conndiag
Bundle the version of the tethering APEX in the build branch into
CtsNetTestCases as a resource, and include it in the failure header on
test failure.

This should make it easy to identify what version of the module matches
the built test when investigating test failures.

Test: atest
Flag: TEST_ONLY
Change-Id: I15a53b3d7649ebde9706b10ee504d08aa78ee7de

Remi NGUYEN VAN   commited 2025-04-10 16:41:29 +09:00
6ee6075685
Merge "Only set the carrier service package on supported devices" into main
Jean Chalard   authored and   Android (Google) Code Review   commited 2025-04-09 15:57:02 -07:00
86fb573931
Only set the carrier service package on supported devices
Not all U devices support this. It's only supported by U QPR1+.

Bug: 404415649
Test: NetworkAgentTest
Flag: EXEMPT bugfix
Change-Id: I66d30b5f0be5628561bfeb1f90f5318954544e31

Chalard Jean   authored and   Jean Chalard   commited 2025-04-08 00:51:44 -07:00
d3db165d9e
IpUtils.checksum() does not require ByteBuffer position reset
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Ib38c54419675bc41337f24932f0aa1cd7b9eeb4f

Patrick Rohr   commited 2025-04-07 20:10:18 -07:00
9381c493d9
Move UDP header assembly to build()
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I5e070a57bfa40f95b72549cb02662f6557f78d45

Patrick Rohr   commited 2025-04-07 20:10:18 -07:00
c1cf40d38e
Add packet builder support for UDP packets
UDP packets can be built as:

val p = ether / ipv6 / udp / data
val p2 = ether / ipv4 / udp / data
val p3 = ether / ipv4 / udp / ipv4 / udp / data

This also gets rid of Icmp6Pkt in favor of a function call that
calculates the checksum over an L4 packet.

This does add a bit of duplication: the build() function for RA and NA
packets is identical, and UdpPkt#build() is not far off. However, subtle
differences in L4 packet format (namely the checksum and length
positions) make generalizing this code difficult. This is possible by
passing the checksum position, proto byte, and adding an abstract
function that fills in the L4 length field before performing checksum
calculation. However, this complexity is likely not worth it. If the
repetition becomes obvious once more protocols (such as ICMPv4/6 echo,
etc.) are added, this decision will be revisited.

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

Patrick Rohr   authored and   Maciej Żenczykowski   commited 2025-04-07 14:22:43 -07:00
328cfb5051
Add packet builder support for IPv4 packet
Options and fragments aren't currently supported.

Test: decoded test packet on packetor.com
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Ia3a094cb1d2b093cae2f372cc84a72ad7e107105

Patrick Rohr   commited 2025-04-07 10:28:35 -07:00
313c1057f6