Commit graph android_packages_modules_Co.../staticlibs/testutils/devicetests
Message SHA1
Merge "Add config for client-side traffic stats rate-limit cache." into main
Junyu Lai   authored and   Gerrit Code Review   commited 2024-10-31 07:22:36 +00:00
30ff675df5
Add config for client-side traffic stats rate-limit cache.
This is a no-op change since the config is not used yet, and
the feature flag will be gradually rolled out instead of enabled
by default.
However, this change is necessary for follow-up changes to enable
toggling the feature and configuring its behavior through device
configuration flags.

This change includes:

 1. Disable the service-side cache flag if the client-side flag
    is enabled.
 2. Since the apps don't have enough permission to check the
    feature flag from DeviceConfig. Provides a binder interface
    for returning per-UID config,
    which only returns cache enabled if the SDK level is V+
    or the app's target SDK is V+.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.TrafficStatsTest \
      FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest \
      CtsNetTestCases:android.net.cts.NetworkStatsBinderTest \
      FrameworksNetIntegrationTests:com.android.server.net.integrationtests.NetworkStatsIntegrationTest
Bug: 343260158
Change-Id: Id9761e4aea65fabe6466c875b787e178317a1da2

Junyu Lai   commited 2024-10-30 23:02:59 +08:00
b9071f8512
Add log when resetting DeviceConfig
The log should help investigate flakes, by knowing at which point
DeviceConfig is being reset and to which value.

Test: atest
Change-Id: Ia7392ad57d3df17b0d5194158b402f52bc90f7e3

Remi NGUYEN VAN   commited 2024-10-25 09:20:12 +09:00
001be79f0f
Merge "Add report header to failure diagnostics" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-18 04:46:04 +00:00
40b2466b1d
Add report header to failure diagnostics
Add a one line header of JSON info about the failure in failure
diagnostics reports.

This can then be automatically collected to calculate statistics about
particular failures, for example how often they happen when wifi is not
connected, not validated etc.

Test: atest
Change-Id: Ic4c99c53fc2686aaf2f1651522aa2f0d82d0cb86

Remi NGUYEN VAN   commited 2024-10-18 09:41:33 +09:00
e980872140
Merge "Do not run diagnostics on assumption failures" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-16 07:16:44 +00:00
8eff4fd04b
Do not run diagnostics on assumption failures
Assumption failures are not actual failures, do not run connectivity
diagnostics for these.

Test: atest
Change-Id: I1d78eb6f12412e13cf4c29718ff8869ed089f491

Remi NGUYEN VAN   commited 2024-10-16 15:26:47 +09:00
3feb788aa5
Merge "Add options to disable diagnostics collector" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-16 06:02:22 +00:00
5024551d11
Add options to disable diagnostics collector
Disable by default on local builds (which generally have "eng.username"
as their INCREMENTAL version), and add an option to allow disabling
manually on other builds as well.

Test: atest

Change-Id: I2d406a55ba0e3d57ed30e740b6c011124905b8d7

Remi NGUYEN VAN   commited 2024-10-16 13:27:14 +09:00
2665f0a4d5
Merge "Add connectivity diagnostics on test failure" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-10-16 04:11:58 +00:00
c0ebf16036
Add connectivity diagnostics on test failure
When CtsNetTestCases tests fail, or when a tryTest statement fails,
collect connectivity diagnostics and output them as a test artifact.

tryTest must be followed by cleanup blocks, which often change the
configuration, so having diagnostics when the tryTest fails in addition
to after the test failure is useful.

The collected diagnostics will be available as individual test
artifacts. They should make it easier to investigate test failures, and
could be collected across test runs in an automated way.

Output files are currently limited at 20 per run, to avoid collecting
too much data in case everything is failing in the run.

Test: atest
Change-Id: Iaa48e519028dc61c03d387beeade7d41fca2ef48

Remi NGUYEN VAN   commited 2024-10-16 10:05:35 +09:00
43730b3f0f
Rename TapPacketReader to PollPacketReader for broader applicability
* Renamed TapPacketReader to PollPacketReader to better reflect its
  functionality beyond TAP interface interaction.
* The class includes general logic for polling and sending packets to
  file descriptors, making it suitable for wider use cases.

Test: TH
Change-Id: Icdf9a9d7ef6f49b589ed9cdbd05159ab95e7e5d9

Yuyang Huang   commited 2024-10-15 13:42:05 +09:00
eb3c631b89
Merge changes from topics "ddr-tests-in-networkstack", "move-fakedns" into main
* changes:
  Move to one unified implementation of FakeDns.
  Add test utils for SVCB packet generation.

Lorenzo Colitti   authored and   Gerrit Code Review   commited 2024-09-19 06:19:31 +00:00
3627907075
Move to one unified implementation of FakeDns.
Take the functionality from the (better) FakeDns in NetworkStack,
move it to the FakeDns in staticlibs, and port it to kotlin.

Test: test-only change
Change-Id: I6d0b4a348ca86ab69785cdf722c259ef6a92ce4b

Lorenzo Colitti   commited 2024-09-19 12:51:28 +09:00
5355fce9b2
Remove assert for R+
Mainline only ships to R+ devices, so this assertion is guaranteed to be
true.

Change-Id: I1fbc0a50dc35a306d782a0219955c51954deeca7
Test: TH

Patrick Rohr   commited 2024-09-12 04:32:59 +00:00
d393a9d8d4
Add test utils for SVCB packet generation.
This is based on patchset 22 of aosp/2453209.

Bug: 240259333
Test: test-only code, will be covered by NetworkMonitorTest
Change-Id: Ibede3fb519e6f1d0c3d99886f553ee006ddfebc9

Lorenzo Colitti   commited 2024-09-10 14:47:57 +09:00
93f2efbe86
Throw IllegalStateException when inserting an existing item
This commit throws IllegalStateException instead of
IllegalArgumentException when inserting an existing item
to TestBpfMap to fit the current behavior in the
production code.

This is safe given that this is only for test and no one is
currently check the exception.

Test: atest TetheringTests:com.android.networkstack.tethering.BpfCoordinatorTest
Bug: 354619988
Change-Id: I1e5c6e99a0d95b44dd556de8805bb16c3d1a4f61

Junyu Lai   commited 2024-09-04 18:48:56 +08:00
c1856de66e
Merge "Skip running restore default network monitor on instant mode." into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-08-20 06:14:30 +00:00
63488f4798
Skip running restore default network monitor on instant mode.
Instant mode does not have access to WifiManager

Test: atest MultinetworkApiTest --instant
Bug: 356644514
Change-Id: I310cd8a614006c391407829ada587d892a0ac3b4

Motomu Utsumi   commited 2024-08-20 13:41:12 +09:00
d3d139a80d
Add testutil to mock android.app.usage.NetworkStats
It's not possible to directly create a mocked `NetworkStats`
instance because of limitations with `NetworkStats#getNextBucket`.
As a workaround for testing, create a mock by controlling the
return values from the mocked service that provides the
`NetworkStats` data.

Test: atest FrameworksServicesTests:com.android.server.stats.pull.netstats.NetworkStatsUtilsTest
Bug: 335680025
Change-Id: I4be8420de50040781557587fba4a50b9c0587f61

Junyu Lai   commited 2024-08-19 17:39:15 +08:00
c51f71fb41
Revert "Use addEntries when creating NetworkStats"
This reverts commit 668560d85a.

Reason for revert: Devices failing to boot, see b/359795863 

Change-Id: I13dc629e2eb626bff1aed6ff262699c3f577ab9c

Sam Dubey   authored and   Gerrit Code Review   commited 2024-08-14 10:00:32 +00:00
c006797ed4
Use addEntries when creating NetworkStats
In the current design, NetworkStats.addEntry is used within a
loop to create a NetworkStats instance from entries. This results
in a large memory footprint because the addEntry() method clones
the original NetworkStats instance each time it is called.

This change utilizes the newly created API to add a list of
entries at once. This approach only clones the instance once,
thereby reducing the required memory footprint.

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.NetworkStatsUtilsTest#testPublicStatsToAndroidNetStats
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.NetworkStatsUtilsTest
      (on S device)
Test: atest ConnectivityCoverageTests:com.android.testutils.NetworkStatsUtilsTest
      (on S device)
Bug: 335680025
Change-Id: I5c635613ed3ba34d840ee71b6bef21d10105df0d

Junyu Lai   commited 2024-08-13 17:46:20 +08:00
668560d85a
Make assertNetworkStatsEquals supports null iface name
This change enables comparison of android.net.NetworkStats
instances even when their interface name is null. This scenario
arises when deriving a android.net.NetworkStats instance
from an app.usage.NetworkStats, which lacks interface name
information. However, the original utility method relies on
NetworkStats.Entry#equals, which is incompatible with null
interface names on T- devices, because they do not run
mainlined NetworkStats.

This change refactor assertEntryEquals and makes
assertNetworkStatsEquals to use it to compare android.net.NetworkStats
instances.

Test: atest NetworkStaticLibTests
Test: atest ConnectivityCoverageTests:com.android.testutils.NetworkStatsUtilsTest
      (on S device)
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.NetworkStatsUtilsTest
      (on S device)
Bug: 335680025

Change-Id: I25a685e4c2d4cf70132b2c4374b2bb8129c844cb

Junyu Lai   commited 2024-08-13 17:02:33 +08:00
10fcc1761d
Merge changes I44e85c09,I01810b54,I1c169311,I15f2aeac,I048512a1 into main
* changes:
  Use AutoCloseTestInterfaceRule in NsdManagerDownstreamTetheringTest
  Add auto close rule for test interfaces
  Add finalizer to check whether destroy was called
  Wrap use of test interface in EthernetTestInterface
  Add a class to properly manage ethernet test interfaces

Patrick Rohr   authored and   Gerrit Code Review   commited 2024-07-31 20:36:45 +00:00
74e3f5aa48
Increase timeout to expect CapabilitiesChanged callback
DefaultNetworkRestoreMonitor sometimes fails since the CapabilitiesChanged callback is not called within the timeout.
This CL fixes the issue by increasing the timeout.

Bug: 356132243
Test: TH
Change-Id: Id36d9166538070933fd62a03c6dd18bc84053bd8

Motomu Utsumi   commited 2024-07-30 06:10:27 +00:00
2ac329900b
Add auto close rule for test interfaces
This rule proxies calls to TestNetworkManager, keeps track of all
interfaces created by it, and closes them after running the test.

Test: builds
Change-Id: I01810b54929fea6e9c929a49bbf5e5268c6793af

Patrick Rohr   commited 2024-07-22 15:29:24 -07:00
ebb20c841f
Increase timeout to wait the default network is restored
3 seconds were too short to wait the network validation.
This CL also updates error message to include more information that
helps investigation.

Test: TH
Bug: 354475907
Bug: 354475880
Bug: 354104252
Change-Id: I513a5bd8af44df47f18773f8fa49323986757e0d

Motomu Utsumi   commited 2024-07-22 09:45:07 +00:00
7269856960
Merge "Add default network monitor to DevSdkIgnoreRunner" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-07-17 02:47:06 +00:00
a9a27614cc
Add default network monitor to DevSdkIgnoreRunner
Some tests reconnect wifi and don't wait wifi is validated.
So default network is changed while later tests are running.
This CL adds RestoreDefaultNetwork annotation to monitor default network
changes and wait to default network is restored to previous state.
If the default network is not restored within timeout, test fails.

Bug: 328870515
Test: atest MultinetworkApiTest NetworkAgentTest
Change-Id: I01e858109ac274ff60769bd558b91654298290ff

Motomu Utsumi   commited 2024-07-16 20:16:04 +09:00
74db5855fb
Merge "Allow using a log tag in TestableNetworkCallback" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-07-04 05:36:56 +00:00
a1d8c55bbf
Allow using a log tag in TestableNetworkCallback
For tests that register multiple callbacks, like ConnectivityService
tests, this can make it easier to figure out which callback is getting
called in logs.

Test: atest CtsNetTestCases (tests using this callback)
Bug: 327038794
Bug: 279392981
Change-Id: Ifea5a8180f9667feaadf94c8b927469bafe29590

Remi NGUYEN VAN   commited 2024-07-04 14:35:31 +09:00
198230dc6a
Merge "Refactor thread leak monitoring" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-07-01 04:25:29 +00:00
584cadc1eb
Refactor thread leak monitoring
Preparation to add default network restore monitor(aosp/3037352)

Test: TH
Bug: 328870515
Change-Id: I0f9deede6075bccaa26ee7f286a42dd60413fac3

Motomu Utsumi   commited 2024-06-26 18:39:10 +09:00
8ab6a6b512
Move MdnsTestUtils to the net-tests-utils library
This is a no-op refactoring to move MdnsTestUtils to the
net-tests-utils library.

Bug: 343311941
Test: build pass
Change-Id: I009f421da47771cf4d4d3673db1a807e555ce86f

Paul Hu   commited 2024-06-20 09:59:34 +00:00
be4e552787
Merge "Improve error message of TestableNetworkCallback#expect" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2024-05-28 02:06:09 +00:00
167768264d
Improve error message of TestableNetworkCallback#expect
Currently, expect method only use the given error message
when predicate is not matched. In some cases, it could cause
some confusions where we might just want the tester to
ensure the data subscription is valid.

Make other fail cases use the error message if provided.
This would provide more clear error message for the callers
e.g. NetworkCallbackHelper#requestCell

Exmaple output:
java.lang.AssertionError: Cell network not available. Please
ensure the device has working mobile data. : Did not receive
Available after 30000ms.

Test: Manual
Bug: N/A
Change-Id: If00c84d622a69d9b7bab7b333da9d1449ba747c2

Junyu Lai   commited 2024-05-27 19:09:28 +08:00
80a3cd134a
Add support to restore original values
In current design, this class is risky because developers might
assume that it's safe to set real device flags with it. This is
unsafe because the class does not restore the previous value.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Fix: 339154394
Change-Id: I2a12e7892eaf66e7572928de39e00de3faf5fa60

Junyu Lai   commited 2024-05-21 02:16:21 +00:00
a8ba04b132
Fix linter error in TestableNetworkCallback
This is suggested by ktlint.py --format

Test: TH
Bug: NA
Change-Id: I1537cb183246783575f40eb55ad4cea0515eb48a

Junyu Lai   commited 2024-04-26 07:03:20 +00:00
0f579646cd
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