Commit graph android_packages_modules_Co.../staticlibs/testutils/devicetests
Message SHA1
Merge "Request INTERNET capability in ensureWifiConnected" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-04-11 08:20:51 +00:00
cbcbec8bc1
Merge changes from topic "rate-limit-trafficstats" into main
* changes:
  Make cache duration and max entries configurable
  Create TestRule: SetFeatureFlagsRule
  Rate-limit on TrafficStats#get*[Bytes|Packets] API calls
  Clear TrafficStats cache before getting readings from TrafficStats

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-11 07:26:14 +00:00
47c819640d
Request INTERNET capability in ensureWifiConnected
The intention of ensureWifiConnected is to connect to a "standard"
wifi network that has internet capability.

Add the capability to avoid selecting alternate wifi networks.

Test: atest
Change-Id: I20caa34feebe9d5449f4fcd8ae00fd91dd17dc5d

Remi NGUYEN VAN   commited 2024-04-10 15:29:30 +09:00
689f1cbb6d
Migrate ConnectivityManagerTest to callback rule
ConnectivityManagerTest has existing logic that is functionally
identical to AutoReleaseNetworkCallbackRule. Migrate it to use the rule
instead.

This just migrates callbacks to their Rule equivalents, except for
waitForActiveNetworkMetered which relied on the NetworkStack
ConnectivityManager shim for registerSystemDefaultNetworkCallback on R
to use a fallback implementation. Use the same NetworkRequest as
ConnectivityManagerShim as a direct fallback in this case.

Test: atest
Change-Id: I06501a5b7c05071667344bedb08e9b824c03b27c

Remi NGUYEN VAN   commited 2024-04-10 15:27:08 +09:00
93b08e202e
Create TestRule: SetFeatureFlagsRule
This rule works by reading the annotation and dynamically
invoking a user-specified method before evaluation to handle the feature flag configuration.

Usage:
class MyTestClass {
  @get:Rule
  val setFeatureFlagsRule = SetFeatureFlagsRule(setFlagsMethod = (name, enabled) -> {
    // Custom handling code.
  })

  // ... test methods with @FeatureFlag annotations
  @FeatureFlag("FooBar1", true)
  @FeatureFlag("FooBar2", false)
  @Test
  fun testFooBar() {}
}

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: N/A
Change-Id: I439e8ee40b8e81b6eb3857925912a3b843e8dfa1

Junyu Lai   commited 2024-04-08 10:43:42 +08:00
5ed8003915
Replace connectToCell -> NetworkCallbackRule
Developers often forget to unregister requests in tests, and cleanup
code also makes tests more verbose.

Add a rule that unregisters callbacks automatically when after each test
method.

Replace current usage of connectToCell with this rule, as well as
network callback usage in CaptivePortalTest (which is one example that
did not unregister its callback).

Test: atest
Change-Id: Ie3b9c5cf529004b7b3af04bc13a7e69acfbbaa18

Remi NGUYEN VAN   commited 2024-04-02 11:18:20 +09:00
e629bb7c84
Use custom defined DNS/HTTP port
Refactor the test case to support listen custom DNS/HTTP port.
Avoid binding system restricted port (<1024).

Bug: 322113686
Test: atest NetworkStackIntegrationTests:android.net.NetworkStatsIntegrationTest
Change-Id: I5d3b966cdadc9321ca2ee0d04a5b8f71ee79bd8a

Jimi Chen   commited 2024-02-20 08:08:17 +00:00
45ac04442f
Merge "Add CtsConnectivityMultiDevicesTestCases for hotspot" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2024-01-31 14:29:18 +00:00
9c3c120c6c
clearInlineMocks from DevSdkIgnoreRunner after running test
Memory leak was observed and inline mock is one of the reasons.
This CL updates DevSdkIgnoreRunner to clear mock state if there is no
thread leak.

Test: TH
Bug: 321603955
Change-Id: I50fd03f14c6703bd38b5729f577d7ea516cd5b44

Motomu Utsumi   commited 2024-01-25 21:55:10 +09:00
05bf4f398f
Add CtsConnectivityMultiDevicesTestCases for hotspot
This test is conducting two physical devices: a device
acting as the hotspot and a separate client device. The test
assesses whether the client can connect to the hotspot and utilize
its internet connection.

This test verifies the basic functionality of the hotspot feature
by exercising the entire system without mocking any component.
This is crucial because various system components, like cellular,
Wi-Fi, routing rules, tethering, and hardware offload, can have
regressions or design changes that impact the basic functionality.

Test: m connectivity_multi_devices_snippet && \
      atest CtsConnectivityMultiDevicesTestCases
      (2 physical devices near each other are needed
      to perform this test)
Bug: N/A
Change-Id: Ib97495c48f313889cedae03d59762482da10cfd8

Junyu Lai   commited 2024-01-22 15:13:11 +08:00
36e7626406
Merge changes from topics "remove-napt", "support-multipleaddr" into main
* changes:
  Support multiple addresses in PacketBridge
  Remove NAPT from PacketForwarder

Junyu Lai   authored and   Gerrit Code Review   commited 2024-01-16 07:47:47 +00:00
24b54c2285
Fix replying to queries via unicast
Instead of (wrongly) looking at the DNS message flags for the Query
Unicast bit, look at the flag in the question record.

The previous bug means that all queries would be replied multicast
instead of sometimes unicast. The fix is flagged off as this is a
behavior change that may affect performance and latency.

Bug: 289482497
Test: atest
Change-Id: I08e30c4ffa747c9073d631e8addca1278ea40648

Remi NGUYEN VAN   commited 2024-01-15 20:26:28 +09:00
0ca094b577
Support multiple addresses in PacketBridge
Test: atest NetworkStackIntegrationTests:android.net.NetworkStatsIntegrationTest
Bug: N/A
Change-Id: Icaef559d54f8d7ce06fb9bf231330235ee01ab8f

Junyu Lai   commited 2024-01-15 17:54:26 +08:00
3cc222dd76
Remove NAPT from PacketForwarder
Consider below scenario:
  Internal address: 1.2.3.4
  External address: 5.6.7.8
  Remote address: 8.8.8.8
When a packet was sent from 1.2.3.4 to 8.8.8.8, the current design
translate it to a packet from 8.8.8.8 to 5.6.7.8 and foward it
to the external interface. However, when the response is received
from the external interface, there is a need to remember what is
the original address to forward to. Thus, an address translation
mechanism was introduced in current design.

This change simplify PacketForwarder by removing the address
translation.
Consider, if the 2 interfaces are using the same address.
  Internal address: 1.2.3.4
  External address: 1.2.3.4
  Remote address: 8.8.8.8
When a packet was sent from 1.2.3.4 to 8.8.8.8, simply swap
source and destination and and foward it to the external
interface. When there is a response from the external interface,
the same process can be done, this removes the need of address
translation.

Test: atest NetworkStackIntegrationTests:android.net.NetworkStatsIntegrationTest
Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideVpnTests
Bug: N/A

Change-Id: I86f2e774e9112905e5255b5a28c927562a42ab84

Junyu Lai   commited 2024-01-15 17:54:26 +08:00
74acb88d03
Make thread leak error message more readable
This change only outputs thread count differences instead of
listing all threads. Additionally, it ignores threads with 1
count, which effectively filter out threads created
by the test runner or other system components, such as
hwuiTask*, queued-work-looper, SurfaceSyncGroupTimer,
RenderThread, and Time-limited test.

Sample Output:
[1122/3060] android.net.connectivity.com.android.server.CSLocalAgentCreationTests#ThreadLeakMonitor: FAILED (1ms)

STACKTRACE:
java.lang.IllegalStateException: Unexpected thread changes: removed=[] added=[] updated=[TestAlarmManager=25,CSTestHandler=25]

Test: atest ConnectivityCoverageTests
      (with shouldThreadLeakFailTest set to true)
Bug: 310581973
Bug: 307693729
Change-Id: I085799ebbd69c29f833335684de208105302e012

Junyu Lai   commited 2023-11-17 15:05:19 +08:00
c034c7217e
Ensure no thread leak after NetworkStatsServiceTest
This change includes:
 1. A mechanism in DevSdkIngoreRunnrer to dump thread counts
    before/after tests, and compare thread counts to detect leaks.
 2. Add an annotation @MonitorThreadLeak for test classes to
    annotate the classes which should monitor thread leaks.
 3. Annotated NetworkStatsServiceTest to apply the enforcement.

Sample output:
[1/2] android.net.connectivity.com.android.server.net.NetworkStatsServiceTest#testDumpStatsMap: PASSED (1.187s)
[2/2] android.net.connectivity.com.android.server.net.NetworkStatsServiceTest#ThreadLeakMonitor: FAILED (7ms)

STACKTRACE:
java.lang.IllegalStateException: Expected threads: {binder:26055_3=1, Instr: androidx.test.runner.AndroidJUnitRunner=1, main=1, InstrumentationConnectionThread=1, binder:26055_2=1, binder:26055_1=1} but got: {binder:26055_3=1, NetworkStatsObservers=1, Instr: androidx.test.runner.AndroidJUnitRunner=1, main=1, InstrumentationConnectionThread=1, binder:26055_2=1, binder:26055_1=1}

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest \
      --rerun-until-failure 100
Bug: 308544001
Bug: 307693729
Change-Id: Ia0bccb82c5985df608b8402009b32626b6b17c5a

Junyu Lai   commited 2023-11-15 14:03:45 +08:00
17f589cf47
Add LocalNetworkInfo and send callbacks when it changes
Test: CSLocalAgentTest
Change-Id: I8caca97b891081f9212a01d428a34ed1a08d5126

Chalard Jean   commited 2023-11-07 17:29:38 +09:00
22350c93b4
[BR01.1] Support BpfNetMapsReader
A helper class to *read* java BpfMaps. This is designed to
provide direct bpf access in the caller process through
ConnectivityManager APIs.

The change also removes any statical link to
net-utils-device-common-struct from service-connectivity.
This is because net-utils-device-common-struct is already
included in framework-connectivity. Including it again in
service-connectivity would create a r8 build fail by circular
dependency.

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.StructTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Bug: 297836825
Change-Id: I7a6d2eb816d0dc7343167bddd672806b199f44fe

Junyu Lai   commited 2023-10-23 20:11:02 +08:00
626045a601
Add hidden constants for communicating about local network agents
Test: FrameworksNetTests
Change-Id: Ic490fee6ee70d74acff0a290199b2946817173d0

Chalard Jean   commited 2023-10-12 13:30:49 +09:00
d6f4efb1a8
Address comments on aosp/2765367
Test: comment-only change
Change-Id: I788f6e9f5fdd913d4c5077b6bb82c19664d3cd3f

Chalard Jean   commited 2023-09-29 15:48:09 +09:00
2aa4412503
Have DevSdkIgnoreRunner support @Parameterized parameters
Test: aosp/2405723 uses this, TH is happy with existing tests
Change-Id: If47d7e239d8483716fb78a97bbc2da4e24731209

Chalard Jean   commited 2023-09-28 21:37:31 +09:00
a10ae005df
Check that wifi, cell validates before tests
Tests are sometimes run on hardware devices with wrongly configured wifi
or cell data. Ensure that this is reported as an infra error, and not a
test error, so the root cause is easier to identify.

Bug: 264170054
Test: atest
Change-Id: I4f964fbd4ee497e8ac92f7729375b75b6c4594a3

Remi NGUYEN VAN   commited 2023-09-19 17:26:20 +09:00
f1846ac13b
Add class to help Kotlin to pass nullable to java @NonNull for testing
Follow up CL for aosp/2700076

Bug: 296972712
Test: build with aosp/2688146
Change-Id: Ib582ef41f34baf0bb896e32d681843358f928c87

Motomu Utsumi   commited 2023-08-23 13:01:29 +09:00
7bca2922b8
Merge "Fix kotlin nullable errors in net-test-utils and NetworkStaticLibTests" into main
Colin Cross   authored and   Gerrit Code Review   commited 2023-08-21 19:04:15 +00:00
1d1c0e7282
Merge "Improve test logs using TrackRecord backtrace" into main
Patrick Rohr   authored and   Gerrit Code Review   commited 2023-08-18 22:32:51 +00:00
10fe61b520
Improve test logs using TrackRecord backtrace
eventuallyExpect methods should print the received callbacks since
poll() was called for better debugging.

Test: atest EthernetManagerTest
Change-Id: Ia08abf2436b050a7e319b9f70694ce3d132b4fc3

Patrick Rohr   commited 2023-08-18 09:35:13 -07:00
5bf2947997
Fix DevSdkIgnoreRule for Q-
UnboundedSdkLevel stopped working on Q as it now depends on Set.of,
which is an R+ API. Arguably this should be fixed as its minSdk is still
29, but long-term UnboundedSdkLevel may drop Q support as modules now
only need to support R+.

Avoid using UnboundedSdkLevel on Q- in DevSdkIgnoreRule: this avoids the
above problem, and also makes it compatible with even older builds,
which may happen in GTS.

Bug: 292868272
Test: all tests using this rule
Change-Id: I5e1559d841398a6c6763283f32c9f766a3661e21

Remi NGUYEN VAN   commited 2023-08-10 16:24:48 +09:00
a6e8a281a4
Fix kotlin nullable errors in net-test-utils and NetworkStaticLibTests
Fix kotlin nullable errors that were exposed by setting the retention
of android.annotation.NonNull and android.annotation.Nullable to
class retention.

Bug: 294110802
Test: builds
Change-Id: I2a2c91188b64619fca190a9bd7812d32f9610abd

Colin Cross   commited 2023-08-08 14:26:10 -07:00
d91c89ba51
Merge "Fix crash when socket read is interrupted"
Junyu Lai   authored and   Gerrit Code Review   commited 2023-06-01 05:39:33 +00:00
14a8c7d913
Fix crash when socket read is interrupted
The exception is thrown in some normal cases e.g. interrupt()
called when Os.read is blocked and waiting for the input.
Ignore such events.

Test: 1. atest NetworkStackCoverageMtsConfigTests on S device
      2. atest com.android.cts.net.HostsideVpnTests
      3. atest NetworkStatsIntegrationTest
Bug: 259632210
Change-Id: Ibff41312d9c7431c2b19f780844ab3a81b48f9e8

Junyu Lai   commited 2023-05-31 14:14:01 +08:00
ab3fee4246
Merge "Use ThrowingSupplier for visibleOnHandlerThread."
Hansen Kurli   authored and   Gerrit Code Review   commited 2023-05-24 02:39:07 +00:00
8b39bca655
Use ThrowingSupplier for visibleOnHandlerThread.
In order to return values from functions that are run on the handler
thread, use a ThrowingSupplier instead of a ThrowingRunnable.
Also maintain the case with ThrowingRunnable by overloading.

Test: NetworkStaticLibTests
Change-Id: Ic1b86f9f764997ce5d6848f04185194a961d1106

Hansen Kurli   commited 2023-05-23 06:17:52 +00:00
0cd46d480d
Correctly test for an object being of the correct type
This `as? T` instruction warns that this is an unchecked cast.
It's unchecked in the literal sense : the compiler actually
doesn't check that the var is of that type. Accordingly, this
will only fail if `it` is null, which never happens.

Concretely what that means is that Java code calling this
method like

  expect(AVAILABLE, network)

...will actually pass for *any* callback matching the network,
because the class is not checked.

Thankfully this code is recent and there doesn't seem to be a
lot of tests that got accepted by this bug when they should
have been rejected.

Test: ConnectivityServiceTest, TH
      new test in this patch that fails before but succeeds after
Change-Id: I2e48dae28ff92045f002cfb2798d383c9c19d5ed

Chalard Jean   commited 2023-05-22 17:55:11 +09:00
677b663aaf
Merge "Add packet filters for IPv6 UDP"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-05-08 08:45:34 +00:00
f01d29eae6
Add async BufferedFile and StreamingPacketFile impls
Bug: 245971639

Change-Id: Ief1719262c2cb68819f6feb955e97793f3638ec0

Igor Chernyshev   commited 2023-04-17 21:26:58 +00:00
810be2b456
Merge "Remove pollOrThrow"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-04-10 04:58:22 +00:00
68783d0260
Merge "Add javadoc descriptions for family of methods"
Jean Chalard   authored and   Gerrit Code Review   commited 2023-04-08 02:02:43 +00:00
10dd699d9f
Merge "Remove eventuallyExpectOrNull"
Jean Chalard   authored and   Gerrit Code Review   commited 2023-04-08 02:02:22 +00:00
32a735e8fa
[ST07] Add more documentation for PacketReflector
Test: TH
Bug: 139774492
Change-Id: I778a8392a01806da313335b8103d27295b3e96e4

Junyu Lai   commited 2023-03-28 10:37:26 +08:00
63ff33b9e0
[ST06.2] Read http body for PUT or POST http request
Currently, the test http server will respond whenever
http request is read, no matter how much data was declared
in the Content-Length header. For tests that uses POST
request to test uplink traffic this is not good enough.

Invoke parseBody to read data from input stream to make
sure the http body is read.

Test: atest android.net.NetworkStatsIntegrationTest \
      --rerun-until-failure 100
Bug: 139774492
Change-Id: I1b71f3e55747d104e4a8796611517d93f178321f

Junyu Lai   commited 2023-03-27 18:45:46 +08:00
8fef4f726a
[ST05.3] Support PacketBridge
For testing purposes, a TestNetworkInterface provides a
FileDescriptor which allows content injection on the test
network. However, this could be hard to use because the
callers need to compose IP packets in order to inject
content to the test network.

In order to remove the need of composing the IP packets,
this class forwards IP packets between two
TestNetworkInterface instances. Thus, the TCP/IP headers
could be parsed/composed automatically by the protocol stack of
this additional TestNetworkInterface, while the payload is
supplied by the servers run on the interface.

Test: 1. atest android.net.NetworkStatsIntegrationTest
      2. atest com.android.cts.net.HostsideVpnTests
Bug: 139774492
Change-Id: I8fe5a434d6d727a81d106a967dcdca157424e12e

Junyu Lai   commited 2023-03-27 18:25:29 +08:00
86c95b4925
Merge "Fix lint errors and adding nullability annotations in PacketReflector"
Junyu Lai   authored and   Gerrit Code Review   commited 2023-03-20 05:49:19 +00:00
460c042999
Merge "[ST04.1] Move PacketReflector to static library"
Junyu Lai   authored and   Gerrit Code Review   commited 2023-03-16 13:23:14 +00:00
621c1b739d
Fix lint errors and adding nullability annotations in PacketReflector
This is a no-op refactoring.

Test: TH
Bug: 139774492
Change-Id: Ibb6605a9f7add8319321e5b4960a0b9b637f1434

Junyu Lai   commited 2023-03-15 13:53:36 +08:00
388204218b
[ST04.1] Move PacketReflector to static library
This is also needed by integration test in NetworkStack module
in follow-up CLs. Move to a common place first.
This is a no-op refactoring.

Test: atest com.android.cts.net.HostsideVpnTests
Bug: 139774492
Change-Id: Ifc7ed4c93edfb0f6f8eb47231f6df40332d2c10c

Junyu Lai   commited 2023-03-15 13:35:00 +08:00
5622c37a85
Remove pollOrThrow
This method is better removed, because it doesn't follow the
naming conventions we want to keep in this file. It also isn't
useful :
• There is only one use of it outside tests, and it's in the
  same file. It's trivial to inline it.
• The method has a unit test, which becomes useless once the
  method is inlined.
• There is a corresponding command in the interpreter, but it's
  only used by the unit test and therefore can be removed once
  the unit test is removed.

Test: TH
Bug: 157405399
Change-Id: Ib5b1369ac28e4577adc98204e42ff2f27729e64c

Chalard Jean   commited 2023-03-07 21:48:24 +09:00
c2cf7eb82d
Add javadoc descriptions for family of methods
Test: comment-only change
Bug: 157405399
Change-Id: I58ccb8b05a8ffb82d4575b727bb48dfb21b191fd

Chalard Jean   commited 2023-03-07 21:48:24 +09:00
2725af813a
Remove eventuallyExpectOrNull
This is no longer used and is advantageously replaced
by a call to poll(), which has the same semantics.

Test: TH
Bug: 157405399
Change-Id: I3182fd3e3ac749e11a8f962ef1acfdca5d031b05

Chalard Jean   commited 2023-03-07 21:47:50 +09:00
0784d5dbd1
Remove eventuallyExpectOrNull usages from AOSP
This is not useful because it has the exact same semantics
as poll() : it returns the first event that matches the
predicate within the timeout, or null if none.

Unfortunately the method can't be removed until all
uses in internal master are removed, so the actual
removal will have to wait for the next patch.

Test: TH
Bug: 157405399
Change-Id: I471c44568e359f8686dcb21ae04c76ca8095f02f

Chalard Jean   commited 2023-03-07 21:47:11 +09:00
febf4ab6fb
Bubble up exceptions in visibleOnHandlerThread
Test: NetworkStaticLibTests
Fixes: 269390906
Change-Id: I3c2d330dd719869562f437c1995e85abd32dbd68

Chalard Jean   authored and   Jean Chalard   commited 2023-02-17 07:19:22 +00:00
2695fdf6ce