Commit Graph

85 Commits

Author SHA1 Message Date
Chalard Jean
b7e2284acf [CC03] Replace expectCallback* with expect
"callback" is redundant – it's a TestCallback object and
it takes a type of callback anyway.

"assertNextIs" is shorter than expectCallback, and more
directly explicit than "expect", but it's also 3 words
and very different from previous usage.
Using expect() is a little bit less in-your-face obvious,
but it's simple, familiar, and short.

Test: CtsNetTestCases
      FrameworksNetIntegrationTests
      FrameworksNetTests
      NetworkStackTests
Bug: 157405399
Change-Id: I6c8c85a8be3895dd8f0ef681faa4a8b2b4f2f493
2022-10-18 20:18:46 +09:00
Chalard Jean
70c62e594a [CC01] Remove the confusing pollForNextCallback
In Java, "poll" methods return null when the collection is
empty. Respect this convention.

Bug: 157405399
Test: FrameworksNetTests
Change-Id: I3b17908f9ce1f60b18908605a645da3199c010b9
2022-10-17 14:51:53 +09:00
chiachangwang
8d65699533 Correct failed log in ensureWifiConnected()
The timeout is used in the test should be WIFI_CONNECT_TIMEOUT_MS
but log shows WIFI_CONNECT_INTERVAL_MS instead. The debug log is
confusing. Correct it to right variable.

Test: atest CtsNetTestCases
Change-Id: I4cedaa6e03aea6cc02a07bdbea2f0b1e7f5076e1
2022-10-12 14:14:49 +00:00
Paul Hu
561b97e711 Enlarge the TestableNetworkCallback default timeout
TestableNetworkCallback is using on both unit and cts tests with
same timeout 200ms. For unit tests, most of objects are mock, so
the callback should respond quickly and this interval is fine.
But for cts tests, they are running on the real system and the
callback time will depend on the system which may be over 200 ms
sometimes if the system is busy or has performance problems. So
enlarge the Network Callback default timeout to 500ms that can
reduce the test flake on cts tests. To ensure there is no impact
on no callback check, add the no callback timeout 200ms which is
the same timeout as before.

Bug: 245000567
Test: Run the FrameworksNetTests CtsNetTestCases and check
      no running time increase.
Change-Id: I31f8bc08f65a622f6ab9b6c7f0577f0b107440c1
2022-10-04 07:05:14 +00:00
Jean Chalard
a804f3fc1e Merge changes I506872f7,I0afb6513
* changes:
  Improve documentation for the concurrent interpreter
  Fix a flake due to uncertainties in time measurement
2022-09-01 03:01:40 +00:00
Chalard Jean
9df957f803 Improve documentation for the concurrent interpreter
Test: comment-only change
Change-Id: I506872f7ff83b8c99527ff593eecc8fdc6760b53
2022-08-30 18:32:54 +09:00
Chalard Jean
6f469c8e9d Fix a flake due to uncertainties in time measurement
The concurrent interpreter supports a `time` directive that
lets testers ensure some instruction has taken at least some
amount of time. This is useful when testing that some
callback didn't arrive before it was sent, for example.

Unfortunately, there is some unavoidable uncertainty in how
time is measured. Because the thread that measures time
needs a very small amount of time before it starts measuring
the time taken by its instruction, it is possible that the
time that is intended to be measured actually took X, but
because the measuring thread took Ɛ before it started
measuring time, the measured time is X - Ɛ, which may fail
the test because it didn't take enough time.

Because there is no way at all to know how much time passed
between the measuring thread being woken up and it measuring
start time, it's not possible to fix this as long as the
measure for the minimum time is taken after the wait. So
instead, take the measure before the wait.

It's always technically possible that there is a bug where
the code doesn't take enough time, but the test doesn't
catch it because the device happened to run slowly as it
ran the test (e.g. other stuff running at the same time),
and this patch makes it a little worse – there will be more
true negatives, but this is the only way to ensure no false
positives and it should still catch the "too fast" cases
most of the time.

Now, each thread has its own "blocked" time. It would be
possible to store that time in a local and pass it down to
all instructions, but that would require all instructions
to take the blocked time as an argument, while only the
`time` instruction can have any meaningful use of it.
Therefore, store it in a thread local instead of adding an
argument to all instructions for all interpreters.

Test: atest --iterations 100 'TestableNetworkCallbackTest#testPollForNextCallback'
      ...although I can't get it to fail locally, so the
      proof will be in a dying out of the flakes.
      Also checked that increasing the minimum time on an
      existing test does fail as expected
Bug: 185735163
Change-Id: I0afb651337a8b10a864cc5bc793d65d2ce56ab20
2022-08-30 18:32:52 +09:00
Motomu Utsumi
3d835e9a8e TestBpfMap implements IBpfMap instead of extends BpfMap
Bug: 217624062
Test: m, atest BpfCoordinatorTest BpfNetMapsTest
Change-Id: I41153a569d79031f0841432c6e83bef2170a33e4
2022-08-25 11:01:25 +09:00
Chalard Jean
a19f85124e Add Function3
...and rename ExceptionUtils to FunctionalUtils as the old name
would no longer be appropriate.

Test: FrameworksNetTests
Change-Id: I2affd69fb84d7f250b4a45497eec6c052bf6ec50
2022-08-16 18:53:17 +09:00
Lorenzo Colitti
0b3378b7d4 Randomize the prefix used by RouterAdvertisementResponder.
Currently RouterAdvertisementResponder always uses a prefix of
2001:db8::/64, even if there are multiple instances on different
interfaces. Randomize the prefix instead.

Test: TH
Bug: 240323229
Change-Id: I585ca804845f4278187602a6c9816470dcea04f8
2022-08-03 17:24:11 +09:00
Remi NGUYEN VAN
1ea7347343 Merge "Add CtsNetTestCasesMaxTargetSdk30" 2022-07-29 08:09:54 +00:00
Patrick Rohr
4a76563701 RaResponder: log instead of throw exception
Throwing an exception in RaResponder crashes the test process (as it
runs in a secondary thread). This is not very useful as that will fail
the execution of all the other tests.
Adding a log statement instead of throwing an exception makes more sense
as the tests will most likely fail anyways.

Test: atest EthernetManagerTest
Change-Id: I9c5f5dc417dad7df1c7f729caa4e0259ed71591f
2022-07-28 15:50:50 -07:00
Patrick Rohr
a5500c6d05 PacketResponder: stop should wait for thread to join
stop() calls interrupt which does not terminate the thread instantly.
Therefore, it should wait for the thread to join, as otherwise the
caller has no way of knowing when it is safe to close the underlying fd.

This led to frequent test process crashes during EthernetManagerTest
runs.

Test: atest EthernetManagerTest
Change-Id: I28f0d46c4f0295acffa5ec9f04964cd73d3de928
2022-07-28 15:50:50 -07:00
Patrick Rohr
3015965660 Merge "RaResponder: add slla option to RA" 2022-07-25 23:07:01 +00:00
Patrick Rohr
56cb967f25 Merge "RaResponder: add support for NS/NA for tests" 2022-07-22 19:08:57 +00:00
Treehugger Robot
763aef5266 Merge "Use UnboundedSdkLevel for DevSdkIgnoreRule" 2022-07-22 11:01:02 +00:00
Patrick Rohr
53165692ca RaResponder: add slla option to RA
Test: test only change
Change-Id: I75beb79cd95489c8a93bd930eb54fc0cb8168cdf
2022-07-21 12:21:46 -07:00
Patrick Rohr
406063f0e2 RaResponder: add support for NS/NA for tests
Add support to respond to neighbor solicitations in addition to router
solicitations. This is useful for tests that need to send IPv6 traffic
through a tap interface. I have previously experimented with the target
link-layer address option in the RA, but it did not seem to prevent a
subsequent NS.

As a TODO, this class should be renamed to NdResponder (and possibly
rewritten in Kotlin).

Test: test only change
Bug: 235559605
Change-Id: I33bac507082fa89d1a5ae02cbe671ce7f5f09b07
2022-07-21 12:21:46 -07:00
Treehugger Robot
44fd16d057 Merge "Refuse to adopt shell permissions if they were already adopted." 2022-07-21 15:31:33 +00:00
Remi NGUYEN VAN
12ac792079 Add CtsNetTestCasesMaxTargetSdk30
The annotation is used to verify behavior for apps with max target SDK
30.

Bug: 235355681
Test: atest CtsNetTestCasesMaxTargetSdk30
Change-Id: Idb358ee1179bc3b6ef9ddbe7b567532822bdc64e
2022-07-20 15:02:00 +09:00
Chiachang Wang
1e6a3a970e Merge "Add mockService method." 2022-06-30 01:34:54 +00:00
Xiao Ma
39c7bd7571 DeviceInfoUtils: add isKernelVersionAtLeast method.
Add a method to check if the current kernel version is at least from a
given version.

Bug: 236783925
Test: atest com.android.testutils.DeviceInfoUtilsTest --iterations
Change-Id: If0509b8ccad895c31d9447fee06789540002f666
2022-06-22 20:10:13 +09:00
Remi NGUYEN VAN
de5e402e48 Use UnboundedSdkLevel for DevSdkIgnoreRule
UnboundedSdkLevel provides a generic and supported way to check for
development SDK level, which makes it unnecessary to update
DevSdkIgnoreRule yearly.

Also this allows using UDC with DevSdkIgnoreRule / DevSdkIgnoreRunner.

Test: Tests using this rule
Change-Id: I151df06ce1498ecbf81c01de8884ebbac83cf7d7
2022-06-22 19:13:56 +09:00
Lorenzo Colitti
05eb2d093c Refuse to adopt shell permissions if they were already adopted.
This does not work because when the permissions are dropped, all
previously-adopted permissions will be dropped as well. Attempts
to do so will likely result in hard-to-understand test failures.

On S+, where we can detect this, fail with a clear error message.

Test: treehugger
Bug: 225092753
Change-Id: I1587ab77f885c595f0b9168c6739303c6227218e
2022-06-17 15:13:04 +09:00
chiachangwang
8e74aa9aa4 Add mockService method.
Add a mockService method to support the common usage that requires
mocking the system service from with a mock context.

Bug: 231373589
Test: atest FrameworksNetTests
Change-Id: Id17af4027a019834c1779be550f4329b1edd6809
2022-06-14 11:09:26 +00:00
Treehugger Robot
9e4b9188de Merge "Fix TestNetworkTracker on Q" 2022-06-13 06:20:34 +00:00
Lorenzo Colitti
0d19b66c96 Fix DevSdkIgnoreRule target SDK annotation processing.
The code added to DevSdkIgnoreRule to process the max target SDK
annotations in aosp/2110064 was incorrect. It is trying to match
the annotation name, but ::class.simpleName returns something
like Proxy$3, not the actual name of the annotation. Use
annotationClass.simpleName instead, which actually works.

This was not caught in aosp/2110064 because it contained an even
worse error which broke DevSdkIgnoreRule completely. That was
fixed in aosp/2114653.

Bug: 233553525
Test: LinkPropertiesTest#testExcludedRoutesDisabled passes on user build
Change-Id: If9220e5ef00fafea556604b251b2106d15d063f8
2022-06-10 23:58:49 +09:00
Remi NGUYEN VAN
639aa94826 Fix TestNetworkTracker on Q
setupTestNetwork only supports the LinkProperties argument starting from
R. Keep overloads that specify only LinkAddresses and mark the
LinkAddress initTestNetwork version as requiring R.

Bug: 234879676
Test: atest CaptivePortalLoginTests on a Q device
Change-Id: I66c0ad9663bffb0ec2659d67c2ca6f4d167e15a6
2022-06-06 18:17:43 +09:00
Remi NGUYEN VAN
ed448e4640 Run tests using DevSdkIgnoreRule
Tests using DevSdkIgnoreRule are currently not being run at all,
as the call to base.evaluate() was removed.

Bug: 233553525
Bug: 234680138
Change-Id: Ice2d1c85f5b886b1fcd5214046ae554d6c66134b
Test: atest
2022-06-02 07:15:12 +00:00
Mark Chien
9840a07a37 Merge changes from topic "icmpv6-forwarding-test"
* changes:
  Add some ipv6 packet utils
  Support initTestNetwork with LinkProperties
2022-06-01 15:15:37 +00:00
markchien
d59b7e067a Support initTestNetwork with LinkProperties
This is the follow CL to fix the comment from
https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/1810276/3/common/testutils/devicetests/com/android/testutils/TestNetworkTracker.kt#45

TestNetworkService only default configure interface name, link addresses,
and routing. To support specify some configuration (e.g. dns server) which
TestNetworkService doesn't default configuration, extend iniTestNetwork
pass LinkProperties.

Bug: 183166581
Test: atest EthernetTetheringTest
      atest ConnectivityManagerTest
      atest TetheringModuleTest
      atest CaptivePortalLoginActivityTest
Change-Id: I560d95516159fa05007057614ac47591fbb3a08c
2022-06-01 03:38:21 +00:00
Lorenzo Colitti
db5d69ec49 Add an annotation to skip tests if the APK has target SDK > 31.
This skips a test if the APK it's running in targets an SDK
above 31. This allows us to add such tests to CtsNetTestCases,
which is currently targeting SDK 33.

By using the annotation as an include-annotation filter in
AndroidTestTemplate.xml, this makes it very easy to create a
clone of CtsNetTestCases that targets SDK 31 and which only runs
tests annotated with this annotation. Thus, CtsNetTestCases and
CtsNetTestCasesLatestSdk will run all tests that pass if target
SDK is 33, and CtsNetTestCasesMaxTargetSdk31 will only run the
tests that requires target SDK 31. See other CL in topic.

Bug: 233553525
Test: atest CtsNetTestCasesMaxTargetSdk31:android.net.LinkPropertiesTest
Test: atest CtsNetTestCasesLatestSdk:android.net.LinkPropertiesTest
Change-Id: Ib5df3bbc659d6a737a846fdf57cddee002e4e9ae
2022-05-30 15:20:26 +09:00
Hungming Chen
085b7f442a DeviceInfoUtils: add class and helper for three-part version number
Add a class Version and string helper for handling a three-part
kernel version number.

Test: atest com.android.testutils.DeviceInfoUtilsTest
Bug: 232332847
Change-Id: I0f229e935bd8332ef2ef93fc910a576df9c054ae
2022-05-27 22:12:40 +08:00
Hungming Chen
c56679d1b5 Migrate compareMajorMinorVersion from ConnectivityManagerTest
Move compareMajorMinorVersion() and getVersionFromString()
from ConnectivityManagerTest.java.

Test: atest DeviceInfoUtilsTest
Change-Id: Ib8245890856a3e4518e48e0afeada746a24e8b22
2022-04-29 13:52:57 +08:00
Patrick Rohr
86dd5872be Create RouterAdvertisementResponder
This is useful for tests that need a provisioned tap interface.

Test: TH
Change-Id: I9a2eb3d8697bbcbfdb65563da609534b929a0715
2022-04-08 13:52:15 +02:00
Frank
4e70104466 [DU04-3]Appropriate changes to the NetworkPolicyManager API
Divide the NetworkPolicyManager API
notifyStatsProviderWarningOrLimitReached into the following two APIs:
1. notifyStatsProviderWarningReached()
2. notifyStatsProviderLimitReached()

Bug: 216474563
Test: atest NetworkStatsServiceTest NetworkPolicyManagerTest
            NetworkPolicyManagerServiceTest OffloadControllerTest
Change-Id: I9d399ea32b656727bf155283265693d3f0d4b9cf
2022-03-16 12:27:08 +08:00
Treehugger Robot
798eebdade Merge "Add support for unknown Network to expectCallback" 2022-02-28 21:57:29 +00:00
Maciej Żenczykowski
0a7883f994 Merge "Change TestBpfMap to use ConcurrentHashMap" 2022-02-19 20:20:24 +00:00
Lorenzo Colitti
0a0877006d Merge "Allow of expectAvailableCallbacks when validation state is unknown." 2022-02-18 17:04:27 +00:00
Patrick Rohr
aeff1238bb Change TestBpfMap to use ConcurrentHashMap
IBpfMap#forEach allows concurrent map access (deleting from the map
while iterating), so we should allow this in TestBpfMap as well.

Test: builds
Change-Id: I89dc7e4daf1d0cfc1aac57cad4ea7f1e50f5f20c
2022-02-18 11:59:43 +01:00
Lorenzo Colitti
5fec18b980 Allow of expectAvailableCallbacks when validation state is unknown.
Currently, expectAvailableCallbacks requires that the caller know
in advance what the validation state is. This CL allows the
caller to pass in validated = null to indicate that it does not
matter whether the network is validated or not.

Test: modified CTS test in other CL in topic
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest
Change-Id: Ie54806a4a1d907de630819e11f9e34602cc55ef4
2022-02-17 17:45:05 +09:00
Remi NGUYEN VAN
48ce320ad3 Merge "Remove dependency on compatibility-device-util-axt" 2022-02-17 06:14:47 +00:00
Remi NGUYEN VAN
675cdf6d99 Remove dependency on compatibility-device-util-axt
The library pulls a lot of dependencies, which end up in code coverage
reports, because code coverage looks at code inside the test package
unless excluded.

Just use the existing TestPermissionUtil in the same library instead,
avoiding the need to exclude many test utilities and making the test
smaller.

Test: atest android.net.cts.ConnectivityManagerTest#testDump
Change-Id: I3ba2121ef034872acf077578644ac9e8aa92c7ef
2022-02-16 18:52:32 +09:00
Tyler Wear
8e377130c9 Add ThrowingBiConsumer to IBpfMap
Converting BiConsumer to ThrowingBiconsumer allows an
exception to correctly be thrown from the BiConsumer action
in forEach() from BpfMap.

Change-Id: I34363c5aa8b07c4cbd703e899381a95062d2b75b
2022-02-15 15:35:54 -08:00
Chalard Jean
1a21b9a9db Add support for unknown Network to expectCallback
This patch allows not passing a network to expectCallback
to allow receiving a callback when the network isn't known.
This is supported in other expect* methods but somehow was
missed in this one.

Test: Ikev2VpnRunnerTest, which uses this ability
Change-Id: Ifd20dd8789ff8b277bac3a73ddd23e2fe9febbca
2022-02-09 03:22:43 +09:00
Lorenzo Colitti
167102daab Turn TestBpfMap into a common utility class.
- Move it to frameworks/libs/net/common/testutils.
- Inherit from BpfMap, so the class can be used anywhere that
  uses a real BpfMap. For example, BpfCoordinatorTest uses
  BpfMap, not IBpfMap.

Test: atest BpfCoordinatorTest
Change-Id: I7ee65e47fa46ac6aafc831f5b1823b44267ba2a6
2022-02-02 00:25:40 +00:00
Lorenzo Colitti
e6cb32b01b Merge "Add Override for onDscpPolicyStatusUpdated" 2022-01-27 23:25:54 +00:00
Lorenzo Colitti
375241c99b Add a DumpTestUtils class to do service dumps in tests.
This allows tests to run dumpsys without worrying too much about
the nitty-gritty of finding the service, piping the output back,
etc.

Test: simple test added in other CL in topic
Change-Id: I0628c55ad199e4c888e4947e11bdb0a3b8150767
2022-01-25 17:35:18 +09:00
Tyler Wear
580cabf981 Add Override for onDscpPolicyStatusUpdated
Add override to allow for DscpPolicyTest to use updated
NetworkAgent callbacks.

Bug: 202871011
Change-Id: I2082f6553e56ff941a309e031184d6e0dfb88514
2022-01-21 11:32:35 -08:00
Maciej Żenczykowski
11e656cbf8 Merge "Add DSCP Status Callback to TestableNetworkAgent" 2022-01-21 19:03:11 +00:00