Commit Graph

1238 Commits

Author SHA1 Message Date
Remi NGUYEN VAN
6c67e2723d Merge "Add visibility rules for Connectivity project" 2020-12-24 01:46:30 +00:00
Xiao Ma
acc47e60da Add ETHER_BROADCAST and DEFAULT_LINK_MTU constants.
ETHER_BROADCAST is used to fill the destination mac address of ether
header, it was defined in the DhcpPacket.java, move it to a common
place for other usecases.

Also have a link mtu constant(default value is 1500 bytes), irrelevant
to specific link-layer type.

Bug: 175830307
Test: m
Change-Id: I422d284cd8fa943bd745ad29229a54515135a3c4
2020-12-23 08:01:45 +00:00
Chalard Jean
359a533e56 Merge "Make Readhead more usable in multithread." 2020-12-23 00:33:32 +00:00
Remi NGUYEN VAN
128c31f0b8 Add kotlin-reflect to net-tests-utils
This fixes failures in CtsNetTestCases, where
TestableNetworkCallback.TAG cannot be used because
it uses kotlin-reflect.

Change-Id: I7e76fe224b1098c967665275eac24fcac08fca23
Fixes: 176047509
Test: atest CtsNetTestCasesLatestSdk
2020-12-21 07:16:52 +00:00
Chalard Jean
460e78931a Make Readhead more usable in multithread.
There doesn't seem to be a way to get any code at all
to run in a generic way on the thread that will execute
a test in android JUnit. JUnit can do it, but the android
harness imposes a thread hop.

This is inconvenent with ReadHead, because ReadHead can't
be used in multithread for semantic reasons : it would
make no sense at all. ReadHead enforces this today in a
relatively strong fashion.

But technically, the only guarantee that is needed is that
poll() is executed only on one thread in slabs of time
defined between a read barrier and a write barrier, where
the write barrier of the previous slab happen-before the
read barrier of the next slab. This in generally speaking
a bit difficult to achieve, but the tests run satisfy this
condition by starting the thread after executing the
@Before methods and joining it before executing the @After
methods. So in fact, it's safe to use ReadHead during
the befores and afters, if a bit uncomfortable, as long
as only one thread uses it during the before, one thread
during the test, and one thread during the afters.

This patch relaxes the enforcement on ReadHead to accept
the usage above. If any slab of time contains usage of
poll() on multiple threads, this will instead crash with
ConcurrentModificationException in almost all cases. It's
no longer possible to detect every possible misuse of
poll() under these conditions, but with this code it's
going to be very unlikely at each test run that the code
is incorrect and still doesn't crash, so incorrect use
should still cause at least very severe flakiness.

The main drawback, aside from the very slight performance
penalty, is that some use can be accidentally correct and
this code will now accept it. So it's possible that code
that is only accidentally correct is accepted, and a
seemingly unrelated change later breaks that correctness,
causing seemingly unrelated tests to fail.

Still, this is going to be an improvement in usability
of ReadHead. We'll no longer need to have lazy creation
of it, and it will be possible to check remaining events
after a tests runs.

Test: FrameworksNetTests NetworkStackTests
Change-Id: If87eef1686b235e53cb444a32f9985b4c2a0a901
2020-12-21 15:47:09 +09:00
Chalard Jean
1aadbb0afd Merge "Move util classes to their destination package" 2020-12-21 05:35:09 +00:00
Xiao Ma
ce033d4824 Move Struct.java to com.android.net.module.util package.
Bug: 163492391
Test: atest NetworkStaticLibTests
Change-Id: If7d54f0356ce4d6426011914df0a2e85784daebd
2020-12-17 15:36:23 +00:00
Xiao Ma
127532321c Merge "Add new APIs writeToByteBuffer/writeToBytes for generic Struct class." 2020-12-17 02:11:50 +00:00
Chalard Jean
ceaf7d0edc Move util classes to their destination package
Test: FrameworksWifiTests FrameworksNetTests
Change-Id: I93e9cfd968e08f983e3fd9f7196c455c79a0f32d
Merged-In: Id19c650246a8f3d55d7b6a874840a6eebcd9eb17
2020-12-16 08:50:20 +09:00
Orion Hodson
72472e4202 Merge "Share JNI file descriptor helper code" 2020-12-15 06:25:37 +00:00
Lorenzo Colitti
a726723ffb Add logging to TestableNetworkCallback.
This is not super useful because it cannot identify different
NetworkCallback objects from each other, but I've found it to be
better than nothing.

Test: manual
Change-Id: Ib402161f361c0f9fb68701bf171cbc99f598dafd
2020-12-14 14:43:42 +09:00
Orion Hodson
4ec55ea007 Share JNI file descriptor helper code
Move JNI File descriptor code from NetworkStack into a common native
static library.

Bug: 158749603
Test: atest NetworkStaticLibTests / treehugger
Change-Id: I3d14587ee8e8590b727736d7d2e29cba687e5514
2020-12-11 23:15:44 +00:00
Xiao Ma
f4cb6d6789 Add new APIs writeToByteBuffer/writeToBytes for generic Struct class.
Split the original U64/UBE64 into two groups: U63/UBE63 which could be
represented by long primitive directly and U64/UBE64 which should be
represented by BigInteger class.

Also fix the endianness-related issue to support both of big-endian or
little-endian input ByteBuffer, and writeToBytes API outputs the bytes
array in appropriate order then.

Bug: 163492391
Test: atest android.net.util.StructTest --rerun-until-failure
Change-Id: Ie9c07fac6dcfceb8efdf1d6b56ce6ff1e845f477
2020-12-07 17:35:03 +09:00
Remi NGUYEN VAN
1ba696dbf7 Add NetworkStackConstants to framework/
The constants are also useful for bootclasspath code, for example in
Ikev2VpnProfile.

Bug: 174436414
Test: atest FrameworksNetTests NetworkStackTests NetworkStaticLibTests
Change-Id: I34458fe6568a73533f956f86ed7bb50d45aa7d7e
2020-11-30 17:19:18 +09:00
Remi NGUYEN VAN
38afb0cd07 Add visibility rules for Connectivity project
The packages/modules/Connectivity project contains module code that can
depend on net-utils-device-common or net-utils-framework-common.

Bug: 171540887
Test: m
Change-Id: Ie754e3f55d78aabff4cef2da3a2a94a1204bd5e5
2020-11-27 13:59:48 +09:00
Xiao Ma
fb21a2d0c3 Merge "Introduce cache schema for generic Struct class." 2020-11-25 00:47:18 +00:00
Xiao Ma
a76690a3b7 Introduce cache schema for generic Struct class.
Bug: 163492391
Test: atest android.net.util.StructTest --rerun-until-failure
Change-Id: Idffad7d3b907d8853ed7d296808a2e0e2736cbbe
2020-11-24 18:03:07 +09:00
David Su
6ca84ae4c5 Merge "Create net-utils-services-common-srcs" 2020-11-12 02:53:27 +00:00
David Su
2dbab6439b Create net-utils-services-common-srcs
...in order to allow "services.net-module-wifi" to
use it.

Bug: 171330443
Test: compiles
Change-Id: I67300429e1a95344c2287ec0358c94c651d2f9f9
2020-11-04 16:59:08 +00:00
Baligh Uddin
e685c813d5 Adjust visibility to avoid build breaks.
per b/167962976#comment10,  following project directories are being
moved under platform/packages/modules/Connectivity/...

cts/test/net --> packages/modules/Connectivity/tests/cts/net
cts/tests/tests/tethering -> packages/modules/Connectivity/tests/cts/tethering
cts/hostsidetests/net -> packages/modules/Connectivity/tests/cts/hostside

BUG: 167962976
Test: TH & Local Build
Exempt-From-Owner-Approval: PS.1 +2d by Lorenzo.  fixing tab (+2 not sticky)
Change-Id: I4e13620ea16b74712a917737607bc3ed38c11cd9
2020-10-31 12:54:44 +00:00
Baligh Uddin
ae4770df38 Add visibility rules for packages/modules/Connectivity/Tethering
BUG: 167962976
Test: TH
Change-Id: I4f9c63d27fe7f10534e89f3d132f26b2f45e7b07
2020-10-29 03:57:51 +00:00
Mark Chien
dea71cd586 Merge "Move jarjar rules from NetworkStaticTestsLib to NetworkStaticTests" 2020-10-26 12:22:32 +00:00
markchien
c064abd0db Move jarjar rules from NetworkStaticTestsLib to NetworkStaticTests
jarjar should be applied on the final artifact (android_test,
android_app, java_library that goes into an apex), not on any
intermediate (android_library etc).

Bug: 171670016
Test: atest NetworkStaticTests
      atest TetheringCoverageTests
      atest NetworkCoverageTests
Change-Id: I86a15133112c555e08275efbde99e68315aa6bc2
2020-10-26 09:52:13 +00:00
Chalard Jean
c746481d10 Add basic tests for CompareResult
...as suggested in aosp/1448415

Test: this
Change-Id: I8469ba6cbcbd9c1b414cfde6cda27505c210526c
2020-10-19 16:17:50 +09:00
Treehugger Robot
e27ae93f77 Merge "Let frameworks/base/tests access the static lib" 2020-10-15 12:27:15 +00:00
Chalard Jean
a9f49910fe Let frameworks/base/tests access the static lib
Test: CtsNetTestCases FrameworksNetTests
Change-Id: I51520b179fe2946f03311eccac97bf4bd4019aea
2020-10-15 18:06:30 +09:00
Treehugger Robot
bfd404c903 Merge "Improve code style in Struct.java and add tests for Type.U64 represented by long primitive." 2020-10-13 07:02:18 +00:00
Xiao Ma
ea53144db0 Improve code style in Struct.java and add tests for Type.U64 represented
by long primitive.

Bug: 163492391
Test: atest android.net.util.StructTest --rerun-until-failure
Change-Id: I0120d7ab063d9d170e8b6e6a6077f8f86db93d67
2020-10-13 06:59:51 +00:00
Remi NGUYEN VAN
867c472714 Merge "Add an icmpv6Checksum utility to IpUtils" 2020-10-13 06:14:38 +00:00
Remi NGUYEN VAN
9f0bde57d2 Merge "Move NetworkStackConstants to frameworks/libs/net" 2020-10-12 02:00:55 +00:00
Xiao Ma
1f2650f6d6 Merge "Define a generic class to parse structured message." 2020-10-09 13:20:31 +00:00
Xiao Ma
6f95cefd38 Define a generic class to parse structured message.
Bug: 163492391
Test: atest android.net.util.StructTest --rerun-until-failure
Change-Id: I1848984d80998d87acccc52287a351d27708dedc
2020-10-09 18:25:34 +09:00
Remi NGUYEN VAN
e1979e7624 Move NetworkStackConstants to frameworks/libs/net
The class only contains constants that should be shareable between
different modules and tests.

This rolls forward the previous change that broke
FrameworksTelephonyTests, because adding net-utils-framework-common to
net-utils-device-common caused the tests to contain a jarjared version
of net-utils-framework-common inherited from telephony code, and a
non-jarjared version inherited from net-utils-device-common. This
resulted in duplicate classes after applying jarjar to the test, which
is not supported (the build system can deduplicate if two libs include
the same class, but jarjar fails if a class after rename conflicts with
an existing class).

This new change removes the dependency on net-utils-framework-common
from net-utils-device-common.

Bug: 168868607
Test: m

Change-Id: I34bad7ec79ef0fd03e5e40b643f0d85d686c53ec
2020-10-09 16:57:24 +09:00
Remi NGUYEN VAN
b2cce59454 Revert "Move NetworkStackConstants to frameworks/libs/net"
Revert "Use new test utilities from frameworks/libs/net"

Revert submission 1440811-iputils_constants_move

Reason for revert: Likely broke build in b/170438226
Reverted Changes:
Ic382d24e7:Move NetworkStackConstants to frameworks/libs/net
I0d938e296:Use new test utilities from frameworks/libs/net

Change-Id: I5e41daa85af39cfab4261ddf790c2008b2630c15
2020-10-09 01:38:44 +00:00
Remi NGUYEN VAN
b60e8e2836 Add an icmpv6Checksum utility to IpUtils
The utility is similar to the existing udpChecksum and tcpChecksum
methods, but for ICMPv6 messages.

Bug: 168868607
Test: m, followup tests using this utility
Change-Id: I41f478af89260a0225f597e672bd798932f1b5eb
2020-10-05 11:25:18 +09:00
Remi NGUYEN VAN
8f415d0066 Move NetworkStackConstants to frameworks/libs/net
The class only contains constants that should be shareable between
different modules and tests.

Bug: 168868607
Test: m
Change-Id: Ic382d24e73697d85d29fa226692bd0d64ffa0f1f
2020-10-05 11:25:18 +09:00
Remi NGUYEN VAN
ff57cec7d1 Move IpUtils to frameworks/libs/net
The utility classes are useful for mainline modules and their tests, for
example IpClientIntegrationTest.

Bug: 168868607
Test: m && atest NetworkStackCoverageTests
Change-Id: Ie3eea7731fa45cd58cd4acf8249da68ff3eb6a70
2020-10-05 11:25:18 +09:00
Remi NGUYEN VAN
9355bc90aa Merge "Add autoStart parameter to TapPacketReader rule" 2020-10-05 02:05:48 +00:00
Remi NGUYEN VAN
539aece60f Add autoStart parameter to TapPacketReader rule
Setting autoStart to false allows tests to manually start the
TapPacketReader rule, either via method call (allowing callers to
specify their own Handler) or an annotation.

Bug: 168868607
Test: atest NetworkStackIntegrationTests using autoStart = false
Change-Id: Ic295d659250795c45181dc3c0ac0aaacba854f0b
2020-10-02 15:14:21 +09:00
Chalard Jean
7dc437d751 Merge "Add visibility of this lib to wifi tests" 2020-10-01 07:06:09 +00:00
Chalard Jean
1978919885 Add visibility of this lib to wifi tests
Test: this builds, and subsequent patches using this work
Change-Id: I8d59b39e6554eccd22695dda47c41b1f2f661495
2020-10-01 12:46:37 +09:00
Remi NGUYEN VAN
b904113030 Add TapPacketReaderRule
This test rule allows tests to easily create a tap interface, a
TapPacketReader on it, and tear them down after the test.

Bug: 168868607
Test: atest NetworkStackIntegrationTests
Change-Id: Ibc167f5c9a8a1b295e8f6c8384a55a1e3410fcdc
2020-09-30 17:59:41 +09:00
Remi NGUYEN VAN
3b1e9265eb Add TapPacketReader#startAsyncForTest, poll
Add a startAsyncForTest method to attempt to start the TapPacketReader
on its handler thread. The method will not report failures to start
(especially failures to create the socket), so it is only added in
TapPacketReader for test code, and not FdEventsReader which would be in
production code.

Rename popPacket to poll, keeping the old version as deprecated
for compatibility. "pop" normally refers to removing a packet from the
top of a LIFO stack, so it is not appropriate naming here.

Test: m
Bug: 168868607
Change-Id: I19184aaca018165856d1d5e5d24b976ae75d1664
2020-09-25 12:28:43 +09:00
Remi NGUYEN VAN
a60293a5e9 Add test utilities for shell permission identity
Add utilities allowing to run lambdas with shell permissions, in kotlin
and java tests.

Bug: 168868607
Test: m
Change-Id: Iaab38d498338b9e95d263789119cd0813983087d
2020-09-25 11:42:38 +09:00
Chiachang Wang
dea21b79a3 Add eventuallyExpect overload
eventuallyExpect is inline function with reified type which
is not accessible from java. Add an open overloaded method to
support the usage.

Bug: 162323152
Test: atest CtsNetTestCasesLatestSdk:ConnectivityManagerTest
Test: atest TestableNetworkCallbackTest
Change-Id: Ifd2256e08d7e5d092d57594350ac8ed1c1727afb
2020-09-02 17:46:28 +08:00
Chalard Jean
d59af18458 Remove backward compatibility flag
Kotlin updates to 1.4 and fixes an issue where @JvmOverload methods
were not final.
See https://kotlinlang.org/docs/reference/compatibility-guide-14.html#generated-overloads-for-jvmoverloads-on-open-methods-should-be-final

Remove the backward compatibility flag by special-casing the method
that needs to be overridden at this time, which gets rid of the
local concern.

Bug: 166499531
Test: Builds, atest ConnectivityServiceTest
Change-Id: Ia13c67876f99dafd77d890e82d62453713b7b5fe
2020-08-28 16:56:55 +09:00
Aurimas Liutikas
33ed824e80 Add workaround for Kotlin 1.4 upgrade
This library is not yet compatible with Kotlin 1.4 new @JvmOverloads
behavior. This change forces this library to the legacy behavior.

See https://kotlinlang.org/docs/reference/compatibility-guide-14.html#generated-overloads-for-jvmoverloads-on-open-methods-should-be-final

Bug: 166499531
Test: make
Change-Id: I9d675c7bd7a8ff223332dfbdf519c476f4c59c8a
2020-08-27 17:02:11 +00:00
Remi NGUYEN VAN
edb36498eb Merge changes from topic "metrics_cts_tests"
* changes:
  Add utilities to test tap interface networks
  Add PacketFilter utilities for DNS testing
2020-08-24 07:13:40 +00:00
Remi NGUYEN VAN
7995b438eb Add utilities to test tap interface networks
Add an ArpResponder based on a generic PacketResponder class, and a
TestHttpServer based on NanoHttpd.

Test: tests based on these utilities
Bug: 160617623
Bug: 160656765
Change-Id: I50b872a8b23e8df997e8f62f0adc7c0256c4d74d
2020-08-14 12:54:41 +09:00
Remi NGUYEN VAN
2f2a3b467c Add PacketFilter utilities for DNS testing
Add packet filters that are useful for filtering / testing DNS queries
and ARP requests.

This change is a prerequisite for tests verifying DNS and validation
metrics.

Test: tests using these utilities
Bug: 160617623
Bug: 160656765
Change-Id: I4216f4ec60d1a427f60fad6eb8017e36b082665f
2020-08-06 15:24:47 +09:00