Commit graph android_packages_modules_Co.../staticlibs/testutils
Message SHA1
Revert "[ST03] Add test dns server for integration tests"
Revert "[ST03.1] Add DnsAnswerProviderTest"

Revert submission 1390056-st03

Reason for revert: test failed in presubmit, still under checking.
Reverted Changes:
Ia5039a47f:[ST03] Add test dns server for integration tests
I9157e030c:[ST03.1] Add DnsAnswerProviderTest

Change-Id: I1ff291ca62e2209343ed5c5e4aa3bf3e93229f47

Junyu Lai   authored and   Gerrit Code Review   commited 2022-11-15 05:55:27 +00:00
88c48e18e4
Merge "[ST03] Add test dns server for integration tests"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-11-14 14:01:12 +00:00
40b76e8bac
Merge "Move DeviceConfigRule to libs/net"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-11-14 09:34:58 +00:00
1a81ae4eb9
Merge "Add eventuallyExpect method that takes mark"
Junyu Lai   authored and   Gerrit Code Review   commited 2022-11-14 05:55:58 +00:00
c32afc4238
Merge "[CC08] Remove expectCallback*"
Jean Chalard   authored and   Gerrit Code Review   commited 2022-11-11 03:17:42 +00:00
664e53bd88
Move DeviceConfigRule to libs/net
The utility can be useful for tests in several repositories, not just
CTS.

Test: m
Change-Id: Id4c653793e58d91d604b388a06a7c137ed020110

Remi NGUYEN VAN   commited 2022-11-10 18:10:24 +09:00
7356d356fb
Add eventuallyExpect method that takes mark
Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest
Fix: 254188130
Change-Id: I98ea8aef5cb21ee92ce47d97d2f9c81448b1cd9e

Junyu Lai   commited 2022-11-10 14:35:29 +08:00
53a6b7053d
[ST03] Add test dns server for integration tests
Bug: 139774492
Test: atest DnsAnswerProviderTest TestDnsServerTest
Change-Id: Ia5039a47f4b818efb09aab8174beb9d921339c3d

Junyu Lai   commited 2022-11-02 11:18:48 +08:00
be99103196
Merge "Add debug log in ensureWifiConnected"
Chiachang Wang   authored and   Gerrit Code Review   commited 2022-10-31 01:38:57 +00:00
97d0f3a563
Add debug log in ensureWifiConnected
It's sometimes not clear that tests call ensureWifiConnected
but no wifi enabled. It's hard to clarify design with wifi
stack, so add the gotten wifi info in the log to help on
debugging.

Bug: 252869312
Test: atest CtsNetTestCases
Change-Id: I3bc74dd38dd5a36a93510fc5d70c0fa00b66e842

chiachangwang   commited 2022-10-28 01:13:40 +00:00
b5e9e3fc2b
Merge "Fix errorprone warnings that should be errors"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-10-26 21:09:23 +00:00
9c549c0d53
[CC08] Remove expectCallback*
These methods have been migrated to the shorter and better
provisioned expect<> family of methods.

Test: Builds
Change-Id: I60c77bfeabe373557d61f0f8d0295b385fe5271e

Chalard Jean   commited 2022-10-24 18:54:46 +09:00
0eac837b01
[CC07] Add build tests for expect* versions
Also address some comments left on a previous patchset.

Test: NetworkStaticLibTests
Change-Id: I3ea16bb54aec31ddb0368af980483109a1bdb49b

Chalard Jean   commited 2022-10-24 18:54:45 +09:00
6f8bcae7d0
Increase the timeout for eventuallyExpect
Sometimes the tests are run under high load, e.g. immediately
after boot while all apps that listen for the boot completed
broadcast run their listeners. Under these circumstances,
40ms of leeway is tight ; on recent Android devices HZ is
commonly 100 too, meaning a general time unit of 60 will give
a little bit of air.

The drawback in this is that the test is less stringent on
TrackRecord, which as a multi-thread primitive should have
really tight tests to make sure that a non-threading primitive
(e.g. a polling implementation) doesn't pass. This patch makes
the testing on that front a little bit less reliable.

Note that this patch won't actually fix all flakes in that it
isn't really possible to guarantee the device will have any
CPU time to run the test at all anyway, but this should make
most failures go away.

Also, the argument for the time unit is never used, and can
be removed ; at least, the possibility of the timeArg() func
not using the same value as the sleep directive is scary, so
that possibility should be removed. If the time unit argument
is ever needed it can be added back, but considering the arg
has been available for years and never used, it's unlikely.

Test: NetworkStaticLibTests
Fixes: 254188131
Change-Id: Ia7a4fe775942484dcd7dc223c7710e82a8329beb

Chalard Jean   commited 2022-10-20 16:42:16 +09:00
347dd8ded4
[CC04] Have TestNetworkTracker implement HasNetwork
This already has all necessary methods, it only needs to
declare it implements the interface.

Test: ConnectivityServiceTest
Change-Id: I8de643f2b8de9765c25c3efe934c94549f341a51

Chalard Jean   commited 2022-10-19 15:46:35 +09:00
f79ca2809a
[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

Chalard Jean   commited 2022-10-18 20:18:46 +09:00
b7e2284acf
[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

Chalard Jean   commited 2022-10-17 14:51:53 +09:00
70c62e594a
Fix errorprone warnings that should be errors
This commit is part of a large scale change to fix errorprone
errors that have been downgraded to warnings in the android
source tree, so that they can be promoted to errors again.
The full list of changes include the following, but not all
will be present in any one individual commit:

BadAnnotationImplementation
BadShiftAmount
BanJNDI
BoxedPrimitiveEquality
ComparableType
ComplexBooleanConstant
CollectionToArraySafeParameter
ConditionalExpressionNumericPromotion
DangerousLiteralNull
DoubleBraceInitialization
DurationFrom
DurationTemporalUnit
EmptyTopLevelDeclaration
EqualsNull
EqualsReference
FormatString
FromTemporalAccessor
GetClassOnAnnotation
GetClassOnClass
HashtableContains
IdentityBinaryExpression
IdentityHashMapBoxing
InstantTemporalUnit
InvalidTimeZoneID
InvalidZoneId
IsInstanceIncompatibleType
JUnitParameterMethodNotFound
LockOnBoxedPrimitive
MathRoundIntLong
MislabeledAndroidString
MisusedDayOfYear
MissingSuperCall
MisusedWeekYear
ModifyingCollectionWithItself
NoCanIgnoreReturnValueOnClasses
NonRuntimeAnnotation
NullableOnContainingClass
NullTernary
OverridesJavaxInjectableMethod
ParcelableCreator
PeriodFrom
PreconditionsInvalidPlaceholder
ProtoBuilderReturnValueIgnored
ProtoFieldNullComparison
RandomModInteger
RectIntersectReturnValueIgnored
ReturnValueIgnored
SelfAssignment
SelfComparison
SelfEquals
SizeGreaterThanOrEqualsZero
StringBuilderInitWithChar
TreeToString
TryFailThrowable
UnnecessaryCheckNotNull
UnusedCollectionModifiedInPlace
XorPower

See https://errorprone.info/bugpatterns for more
information on the checks.

Bug: 253827323
Test: m RUN_ERROR_PRONE=true javac-check
Change-Id: I772563b5e54b468a755520d2ed9b78bcb5fc3ad6

Cole Faust   commited 2022-10-15 21:33:31 -07:00
f4dd77109e
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

chiachangwang   authored and   Chiachang Wang   commited 2022-10-12 14:14:49 +00:00
8d65699533
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

Paul Hu   commited 2022-10-04 07:05:14 +00:00
561b97e711
include ats target
fixes: 244138449

include ats target

Change-Id: I462b13a5b1332c8afdf46761f1cbad545e7cf291

Nandu Suram   commited 2022-09-08 23:00:44 +00:00
8d88f8bb36
Merge changes I506872f7,I0afb6513
* changes:
  Improve documentation for the concurrent interpreter
  Fix a flake due to uncertainties in time measurement

Jean Chalard   authored and   Gerrit Code Review   commited 2022-09-01 03:01:40 +00:00
a804f3fc1e
Improve documentation for the concurrent interpreter
Test: comment-only change
Change-Id: I506872f7ff83b8c99527ff593eecc8fdc6760b53

Chalard Jean   commited 2022-08-30 18:32:54 +09:00
9df957f803
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

Chalard Jean   commited 2022-08-30 18:32:52 +09:00
6f469c8e9d
TestBpfMap implements IBpfMap instead of extends BpfMap
Bug: 217624062
Test: m, atest BpfCoordinatorTest BpfNetMapsTest
Change-Id: I41153a569d79031f0841432c6e83bef2170a33e4

Motomu Utsumi   commited 2022-08-25 11:01:25 +09:00
3d835e9a8e
Merge "Check that cell network is available before tests"
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2022-08-24 04:21:22 +00:00
f3a6a1bbdf
Check that cell network is available before tests
Instead of only checking that a sim card that supports data connectivity
is inserted, also check that there is an available cellular network.
This helps ensure that the device is setup with a working data plan and
APN configuration.

Bug: 242628522
Test: atest CtsNetTestCases
Change-Id: Id47d49de77da5d9f7a87ff34b954c61662965c9e

Remi NGUYEN VAN   commited 2022-08-22 11:15:49 +09:00
da0e172551
Add Function3
...and rename ExceptionUtils to FunctionalUtils as the old name
would no longer be appropriate.

Test: FrameworksNetTests
Change-Id: I2affd69fb84d7f250b4a45497eec6c052bf6ec50

Chalard Jean   commited 2022-08-16 18:53:17 +09:00
a19f85124e
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

Lorenzo Colitti   commited 2022-08-03 17:24:11 +09:00
0b3378b7d4
Merge "Add CtsNetTestCasesMaxTargetSdk30"
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2022-07-29 08:09:54 +00:00
1ea7347343
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

Patrick Rohr   commited 2022-07-28 15:50:50 -07:00
4a76563701
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

Patrick Rohr   commited 2022-07-28 15:50:50 -07:00
a5500c6d05
Merge "RaResponder: add slla option to RA"
Patrick Rohr   authored and   Gerrit Code Review   commited 2022-07-25 23:07:01 +00:00
3015965660
Merge "RaResponder: add support for NS/NA for tests"
Patrick Rohr   authored and   Gerrit Code Review   commited 2022-07-22 19:08:57 +00:00
56cb967f25
Merge "Use UnboundedSdkLevel for DevSdkIgnoreRule"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-07-22 11:01:02 +00:00
763aef5266
RaResponder: add slla option to RA
Test: test only change
Change-Id: I75beb79cd95489c8a93bd930eb54fc0cb8168cdf

Patrick Rohr   commited 2022-07-21 12:21:46 -07:00
53165692ca
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

Patrick Rohr   commited 2022-07-21 12:21:46 -07:00
406063f0e2
Merge "Refuse to adopt shell permissions if they were already adopted."
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-07-21 15:31:33 +00:00
44fd16d057
Add CtsNetTestCasesMaxTargetSdk30
The annotation is used to verify behavior for apps with max target SDK
30.

Bug: 235355681
Test: atest CtsNetTestCasesMaxTargetSdk30
Change-Id: Idb358ee1179bc3b6ef9ddbe7b567532822bdc64e

Remi NGUYEN VAN   commited 2022-07-20 15:02:00 +09:00
12ac792079
Merge "Add mockService method."
Chiachang Wang   authored and   Gerrit Code Review   commited 2022-06-30 01:34:54 +00:00
1e6a3a970e
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

Xiao Ma   commited 2022-06-22 20:10:13 +09:00
39c7bd7571
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

Remi NGUYEN VAN   commited 2022-06-22 19:13:56 +09:00
de5e402e48
Fix handling of Throwable in tryTest/catch
Throwable could be used as a type argument to catch(), but it would
possibly never be caught, because the method only catches Exception.

Notably, junit assertions fail with AssertionError, which is not a
subclass of Exception. Due to that, tests or utilities like
DeviceConfigRule that have failing assertions in catch() would not
run the subsequent cleanup steps.

Bug: 210377950
Test: atest CleanupTest
Change-Id: I54e2922cb466f077ba4d219f8c3c6f885316296c

Remi NGUYEN VAN   commited 2022-06-21 12:52:10 +09:00
a79814aade
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

Lorenzo Colitti   commited 2022-06-17 15:13:04 +09:00
05eb2d093c
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

chiachangwang   commited 2022-06-14 11:09:26 +00:00
8e74aa9aa4
Merge "Fix TestNetworkTracker on Q"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-06-13 06:20:34 +00:00
9e4b9188de
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

Lorenzo Colitti   commited 2022-06-10 23:58:49 +09:00
0d19b66c96
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

Remi NGUYEN VAN   commited 2022-06-06 18:17:43 +09:00
639aa94826
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

Remi NGUYEN VAN   commited 2022-06-02 07:15:12 +00:00
ed448e4640
Merge changes from topic "icmpv6-forwarding-test"
* changes:
  Add some ipv6 packet utils
  Support initTestNetwork with LinkProperties

Mark Chien   authored and   Gerrit Code Review   commited 2022-06-01 15:15:37 +00:00
9840a07a37