Commit Graph

157 Commits

Author SHA1 Message Date
Junyu Lai
c034c7217e 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
2023-11-17 15:05:19 +08:00
Junyu Lai
17f589cf47 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
2023-11-15 14:03:45 +08:00
Chalard Jean
22350c93b4 Add LocalNetworkInfo and send callbacks when it changes
Test: CSLocalAgentTest
Change-Id: I8caca97b891081f9212a01d428a34ed1a08d5126
2023-11-07 17:29:38 +09:00
Junyu Lai
626045a601 [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
2023-10-23 20:11:02 +08:00
Chalard Jean
d6f4efb1a8 Add hidden constants for communicating about local network agents
Test: FrameworksNetTests
Change-Id: Ic490fee6ee70d74acff0a290199b2946817173d0
2023-10-12 13:30:49 +09:00
Chalard Jean
2aa4412503 Address comments on aosp/2765367
Test: comment-only change
Change-Id: I788f6e9f5fdd913d4c5077b6bb82c19664d3cd3f
2023-09-29 15:48:09 +09:00
Chalard Jean
a10ae005df Have DevSdkIgnoreRunner support @Parameterized parameters
Test: aosp/2405723 uses this, TH is happy with existing tests
Change-Id: If47d7e239d8483716fb78a97bbc2da4e24731209
2023-09-28 21:37:31 +09:00
Remi NGUYEN VAN
f1846ac13b 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
2023-09-19 17:26:20 +09:00
Motomu Utsumi
7bca2922b8 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
2023-08-23 13:01:29 +09:00
Colin Cross
1d1c0e7282 Merge "Fix kotlin nullable errors in net-test-utils and NetworkStaticLibTests" into main 2023-08-21 19:04:15 +00:00
Patrick Rohr
10fe61b520 Merge "Improve test logs using TrackRecord backtrace" into main 2023-08-18 22:32:51 +00:00
Patrick Rohr
5bf2947997 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
2023-08-18 09:35:13 -07:00
Remi NGUYEN VAN
a6e8a281a4 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
2023-08-10 16:24:48 +09:00
Colin Cross
d91c89ba51 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
2023-08-08 14:26:10 -07:00
Junyu Lai
14a8c7d913 Merge "Fix crash when socket read is interrupted" 2023-06-01 05:39:33 +00:00
Junyu Lai
ab3fee4246 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
2023-05-31 14:14:01 +08:00
Hansen Kurli
8b39bca655 Merge "Use ThrowingSupplier for visibleOnHandlerThread." 2023-05-24 02:39:07 +00:00
Hansen Kurli
0cd46d480d 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
2023-05-23 06:17:52 +00:00
Chalard Jean
677b663aaf 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
2023-05-22 17:55:11 +09:00
Treehugger Robot
f01d29eae6 Merge "Add packet filters for IPv6 UDP" 2023-05-08 08:45:34 +00:00
Igor Chernyshev
810be2b456 Add async BufferedFile and StreamingPacketFile impls
Bug: 245971639

Change-Id: Ief1719262c2cb68819f6feb955e97793f3638ec0
2023-04-17 21:26:58 +00:00
Treehugger Robot
68783d0260 Merge "Remove pollOrThrow" 2023-04-10 04:58:22 +00:00
Jean Chalard
10dd699d9f Merge "Add javadoc descriptions for family of methods" 2023-04-08 02:02:43 +00:00
Jean Chalard
32a735e8fa Merge "Remove eventuallyExpectOrNull" 2023-04-08 02:02:22 +00:00
Junyu Lai
63ff33b9e0 [ST07] Add more documentation for PacketReflector
Test: TH
Bug: 139774492
Change-Id: I778a8392a01806da313335b8103d27295b3e96e4
2023-03-28 10:37:26 +08:00
Junyu Lai
8fef4f726a [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
2023-03-27 18:45:46 +08:00
Junyu Lai
86c95b4925 [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
2023-03-27 18:25:29 +08:00
Junyu Lai
460c042999 Merge "Fix lint errors and adding nullability annotations in PacketReflector" 2023-03-20 05:49:19 +00:00
Junyu Lai
621c1b739d Merge "[ST04.1] Move PacketReflector to static library" 2023-03-16 13:23:14 +00:00
Junyu Lai
388204218b Fix lint errors and adding nullability annotations in PacketReflector
This is a no-op refactoring.

Test: TH
Bug: 139774492
Change-Id: Ibb6605a9f7add8319321e5b4960a0b9b637f1434
2023-03-15 13:53:36 +08:00
Junyu Lai
5622c37a85 [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
2023-03-15 13:35:00 +08:00
Chalard Jean
c2cf7eb82d 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
2023-03-07 21:48:24 +09:00
Chalard Jean
2725af813a Add javadoc descriptions for family of methods
Test: comment-only change
Bug: 157405399
Change-Id: I58ccb8b05a8ffb82d4575b727bb48dfb21b191fd
2023-03-07 21:48:24 +09:00
Chalard Jean
0784d5dbd1 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
2023-03-07 21:47:50 +09:00
Chalard Jean
febf4ab6fb 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
2023-03-07 21:47:11 +09:00
Chalard Jean
2695fdf6ce Bubble up exceptions in visibleOnHandlerThread
Test: NetworkStaticLibTests
Fixes: 269390906
Change-Id: I3c2d330dd719869562f437c1995e85abd32dbd68
2023-02-17 07:19:22 +00:00
Jean Chalard
35f954324f Merge "Remove expectLinkPropertiesThat" 2023-02-11 02:09:38 +00:00
Jean Chalard
c67deee923 Merge changes from topics "remove_expectblocked", "rename_reason"
* changes:
  Rename BlockedStatusInt.blocked to .reason
  Remove expectBlockedStatusCallback
2023-02-10 05:26:50 +00:00
Igor Chernyshev
f063240c56 Merge "Add OS access interfaces and test impl for wear tethering" 2023-02-09 21:17:54 +00:00
Chalard Jean
36e8ff3f87 Remove expectLinkPropertiesThat
expect() is simply better

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: If8da940e378722f4cde2a4e7ea3eaef3b1380f18
2023-02-09 16:19:09 +09:00
Chalard Jean
ab47793183 Rename BlockedStatusInt.blocked to .reason
It's a reason, so it's a lot clearer this way

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: Id71d710a33b4df3c211e40141adb2aa0a535f458
2023-02-09 16:19:09 +09:00
Chalard Jean
12038d2e28 Remove expectBlockedStatusCallback
expect() does a better job.

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: I2bc4dc0f175b8d46784dbdb3a4724dea41200dc7
2023-02-09 16:19:09 +09:00
Jean Chalard
cd18acab06 Merge "Remove expectCapabilitiesWith and without" 2023-02-09 02:20:20 +00:00
Yuyang Huang
165c6ffbd6 Merge "Add CtsNetTestCasesMaxTargetSdk33" 2023-02-07 10:44:15 +00:00
Chalard Jean
ab521cf49d Remove expectCapabilitiesWith and without
This is not clearer than using the base method.

Test: ConnectivityServiceTest NetworkStaticLibTests
Bug: 157405399
Change-Id: Iac9aeffb563d0a1cb6c1287b46b9bbfffc0c75ca
2023-02-06 13:49:52 +09:00
Chalard Jean
c0ba521f79 Replace expectCapabilitiesThat with expectCaps
Add all the necessary overloads too.

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: Idea768934182d4e2226c273fda0189942dcbf62e
2023-02-06 13:49:51 +09:00
Yuyang Huang
bdb79c510f Add CtsNetTestCasesMaxTargetSdk33
The annotation is used to verify behavior for apps with max target SDK
33.

Bug: 267102290
Test: atest CtsNetTestCasesMaxTargetSdk33
Change-Id: I71ba4433389ba07553ea3d6d34a2bf64fdc132ad
2023-02-02 13:22:12 +09:00
Remi NGUYEN VAN
bcdc972c86 Add packet filters for IPv6 UDP
This is useful to test mDNS.

Bug: 266151066
Test: atest NsdManagerTest (with related change)
Change-Id: I790da3f3be5277f2480600cfbbaeac86c306f77d
2023-01-23 18:20:44 +09:00
Igor Chernyshev
004c5b422b Add OS access interfaces and test impl for wear tethering
Bug: 245971639

Change-Id: I750c2e9bbe8c9a3992ae91d9fea4958bfce60828
2023-01-13 17:57:01 +00:00
Chalard Jean
5987fc4fbe Cleanup TestableNetworkCallback#assertNoCallback
Test: FrameworksNetTests
      CtsNetTestCases
      FrameworksNetIntegrationTests
      NetworkStackTests
      NetworkStaticLibTests
      TetheringTests
      MtsTetheringTestLatestSdk
      TetheringIntegrationTests
Bug: 157405399
Change-Id: I43eb47bbcf947899c18fcd9498c9064edceb0ecf
2023-01-06 16:50:08 +09:00