Commit Graph

280 Commits

Author SHA1 Message Date
Paul Hu
528e675fdd Add ByteUtils for byte utility functions
Bug: 254155029
Test: atest NetworkStaticLibTests
Change-Id: I996ead6f23698313828e844672de5917efdfce69
2022-10-25 05:40:00 +00:00
Chalard Jean
6f8bcae7d0 [CC07] Add build tests for expect* versions
Also address some comments left on a previous patchset.

Test: NetworkStaticLibTests
Change-Id: I3ea16bb54aec31ddb0368af980483109a1bdb49b
2022-10-24 18:54:45 +09:00
Chalard Jean
3ad176b03a [CC06] Move usage of expectCallback* to expect
See CC03 (aosp/2255619) for details

Test: NettworkStaticLibTests
Change-Id: Id15560f5744024ff2ac2acbaf4de83818ce6efc5
2022-10-21 11:53:13 +09:00
Chalard Jean
347dd8ded4 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
2022-10-20 16:42:16 +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
Jean Chalard
4152f83b27 Merge "Move bit utility methods to a new BitUtils class." 2022-10-14 04:55:25 +00:00
Chalard Jean
5c6f7809e2 Save one minute in executing NetworkStaticLibTests
The default timeout for expectEventually is 30 seconds, so this
test used to take one minute. With this change, it now only takes
50ms, with virtually no change in safety.

Test: NetworkStaticLibTests
Change-Id: Id8d6a738ea6a70f7d901a7659b2160c2f3d7d2c0
2022-10-13 16:41:29 +09:00
Chalard Jean
cd0fc3d71b Move TestableNetworkCallbackTest to f/l/n
This tests a utility in f/l/n, so it should live together with
it and not in the network stack tests

Test: NetworkStaticLibTests NetworkStackTests
Change-Id: I90d12933e3a82eba4b565022d3df1e7c1d503f56
2022-10-13 16:41:28 +09:00
Chalard Jean
2ecf120256 Move bit utility methods to a new BitUtils class.
In particular this moves NetworkCapabilies#
appendStringRepresentationOfBitMaskToStringBuilder to this
class. It also moves some other NetworkCapabilitiesUtils
methods that are better homed in this new class.

Test: new test in this patch
Change-Id: I16374d7ca1da92052bb814bde796602d62f5c42e
2022-10-12 20:31:20 +09:00
Junyu Lai
e766a09b79 Merge "[ST02] Add methods for synthesizing DNS packets" 2022-09-22 02:39:42 +00:00
Nucca Chen
48a33adc7b Merge changes from topic "test-tethering-icmp"
* changes:
  IpUtils: add ICMP checksum calculation function
  NetworkStackConstants: add ICMP checksum offset constant
2022-09-19 15:53:43 +00:00
Hungming Chen
0aa70a0973 IpUtils: add ICMP checksum calculation function
Bug: 237369591
Test: NetworkStaticLibTests
Change-Id: If45de190872cad588f9b9104828a0d8116fc158b
2022-09-19 15:34:33 +08:00
Junyu Lai
85e24e85b2 [ST02] Add methods for synthesizing DNS packets
This re-submit aosp/1387135 but define TYPE_CNAME locally to
prevent from using non-finalize API.

Bug: 139774492
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.DnsPacketUtilsTest

Change-Id: Ib2e98292be994ca09845c6857b8884f9bcdaba80
2022-09-16 15:40:01 +08:00
Maciej Żenczykowski
1bff3fb28f NetlinkSocketTest.java - replace U32 ifindex with S32
These are allocated in order by the kernel, if we go
over 2 billion, we've got other problems... besides
U32 to S32 conversion will work just fine anyway.

(apparently this field is never accessed, as the test only looks at family)

Bug: 245472520
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I879c1637a87587b7bc1c13013ea9c5e655c141eb
2022-09-16 06:37:44 +00:00
Motomu Utsumi
1eb3792251 Add BpfDump#dumpMapStatus
Test: atest NetworkStaticLibTests
Change-Id: I77d397b16380a397573cc528fe7f15f381cda21f
2022-09-12 19:08:31 +09:00
Motomu Utsumi
9f732331a4 Merge "Add idiag_sock_id to InetDiagMessage class" 2022-09-10 02:02:11 +00:00
Anton Hansson
2464a31bf8 Merge "Revert "[ST02] Add methods for synthesizing DNS packets"" 2022-09-09 07:58:06 +00:00
Remi NGUYEN VAN
f53c488b93 Revert "[ST02] Add methods for synthesizing DNS packets"
Revert "[ST02.1] Add TYPE_CNAME constant to DnsResolver"

Revert submission 1387135-st02

Reason for revert: Usage of TYPE_CNAME in a library shared among
modules does not interact well with current module release process

Reverted Changes:
Ib5616c65c:[ST02.2] Use the getters of DnsHeader
I5e58f99b0:[ST02.1] Add TYPE_CNAME constant to DnsResolver
I0c1547cbc:[ST02] Add methods for synthesizing DNS packets

Change-Id: I9f8de47c9ba9fb4db7cf3695966f222f68a9a290
2022-09-08 11:01:05 +00:00
Junyu Lai
5e53d5390c Merge "[ST02] Add methods for synthesizing DNS packets" 2022-09-07 02:25:41 +00:00
Chalard Jean
e301436409 Introduce getResIntegerConfig
This is a symmetric to getResBooleanConfig for integers.

Test: new test in this patch
Change-Id: I36cb910acb59c3211ba2c77dd3784fefa93545d9
2022-09-06 11:23:25 +09:00
Motomu Utsumi
ea0fcc94ec Add idiag_sock_id to InetDiagMessage class
Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I9dc5b1d5b2d3da9ab21ce92b3f88d3f9d4d842f1
2022-09-05 21:59:25 +09:00
junyulai
96c4750d59 [ST02] Add methods for synthesizing DNS packets
Bug: 139774492
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.DnsPacketUtilsTest
Change-Id: I0c1547cbc1e7295e9a3dcb0f553065356b05bd7c
2022-09-05 10:16:24 +08:00
Jean Chalard
df8292c805 Merge "Add CollectionUtils.contains with predicate" 2022-09-03 03:27:03 +00:00
Chalard Jean
debdc78518 Add CollectionUtils.contains with predicate
Test: included in this patch
Change-Id: Id10c8878a8e7fe59fa2d7858212e4c01d4de1ca4
2022-08-31 15:55:20 +09:00
Motomu Utsumi
3becbd22dc Add BpfDump#dumpMap
Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I7b0a949e667da4120cc20d8587019bfb0f922584
2022-08-25 18:34:22 +09:00
Motomu Utsumi
fdfaa30146 Merge "Support StructInetDiagSockId parse" 2022-08-24 11:45:53 +00:00
Jean Chalard
8f31efb89c Merge "Add findFirst and findLast to CollectionsUtils" 2022-08-24 09:51:36 +00:00
Motomu Utsumi
56fa997164 Merge "Add test for StructInetDiagSockId" 2022-08-24 09:39:04 +00:00
Motomu Utsumi
dfe4251427 Merge "Add fromBase64EncodedString to BpfDump" 2022-08-24 03:16:53 +00:00
Treehugger Robot
eecde2bc87 Merge "Add getter to PerUidCounter" 2022-08-23 18:25:03 +00:00
Motomu Utsumi
556667ef02 Support StructInetDiagSockId parse
Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: If42436459874d4c61037a98db18c43b40eb81066
2022-08-23 12:42:12 +09:00
Motomu Utsumi
fbc3280c79 Add test for StructInetDiagSockId
Upcoming CL will modify StructInetDiagSockId.
So, as a preparation, this CL adds test for existing behavior of
StructInetDiagSockId.

Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I6ef475bec050ba2689a8df6182be36a6fccd9bfb
2022-08-23 11:56:11 +09:00
Cole Faust
0d8bd9005d Add CollectionUtils.indexOfSubArray()
This is useful as an array version of Collections.indexOfSubList().

Bug: 242630963
Test: atest NetworkStaticLibTests
Change-Id: I36724791ceece1348826a51cb2a975e169dfecc6
2022-08-22 09:17:29 +09:00
Motomu Utsumi
4dcf00e78c Add fromBase64EncodedString to BpfDump
EthernetTetheringTest has parseMapKeyValue that decodes the string
encoded by BpfDump#toBase64EncodedString
Upcoming CL also wants to decode the encoded string.
So this CL renames parseMapKeyValue to fromBase64EncodedString and moves
to BpfDump with refactoring

Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I6ec302aaaa3e8779119cf153567cb032828f5daf
2022-08-18 12:38:24 +09:00
Junyu Lai
c0a6d524eb Add getter to PerUidCounter
This is needed by ConnectivityServiceTest, refer to the
counter part CL in the module git.

This CL also fix guarded by annotation and remove the
increment/decrement method with count methods, which
is not very useful.

Test: TH
Bug: 235771502
Change-Id: Iaab681bf456e14afb4c6ddf700eb3308abead35f
2022-08-17 14:17:42 +08:00
Chalard Jean
cc5f01c610 Add findFirst and findLast to CollectionsUtils
Test: new tests in this patch
Change-Id: Ie13ee7f50832ffec1febe4f4596d0b26e4c4a2f6
2022-08-17 01:44:13 +00:00
Paul Hu
3b5af9962d Add more tests to cover SharedLog methods
Add tests for SharedLog methods that do not have test coverage.
- SharedLog#reverseDump(java.io.PrintWriter)
- SharedLog#e(java.lang.Exception)
- SharedLog#getTag()
- SharedLog#i(java.lang.String)
- SharedLog#logf(java.lang.String, java.lang.Object[])
- SharedLog$LocalLog#reverseDump(java.io.PrintWriter)

Bug: 236768003
Test: atest NetworkStaticLibTests
Change-Id: I465b8e2d528fe70cddc49257d14fecad948fc50f
2022-07-14 06:17:59 +00:00
Hungming Chen
b3e71a2959 Add BpfDump.toBase64EncodedString to dump raw map
Move base64 related bpf map function and constant from BpfCoordinator.
This is preparation for testing BPF map in ClatCoordinator.

Test: atest NetworkStaticLibTests
Change-Id: I3a23393abe5b108cdb8d621e99b74fd20847474e
2022-07-06 04:34:34 +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
a79814aade 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
2022-06-21 12:52:10 +09:00
Treehugger Robot
46cfe8b811 Merge "Ipv6UtilsTest: testBuildEchoReplyPacket" 2022-06-02 19:48:21 +00:00
Hungming Chen
39e1e8844c Ipv6UtilsTest: testBuildEchoReplyPacket
Bug: 183166581
Test: atest NetworkStaticLibTests
Change-Id: I2cd3a4142f3457cdf99547500ab2b93f8f96c314
2022-06-01 06:24:16 +00:00
Treehugger Robot
81c9d79102 Merge "DeviceInfoUtils: add class and helper for three-part version number" 2022-05-27 19:03:58 +00: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
690d1e15f5 PacketBuilder: correct IPv6 header payload length
Ipv6 payload length doesn't include header length.

rfc8200 section 3
https://tools.ietf.org/html/rfc8200
Payload Length      16-bit unsigned integer. Length of the IPv6
                    payload, i.e., the rest of the packet
                    following this IPv6 header, in octets.

Bug: 215655463
Test: atest NetworkStaticLibTests
Change-Id: Ifdc871125b0fe2eb3a8909b8b0723a62dbe44bcf
2022-05-27 10:48:52 +00:00
Treehugger Robot
ec25765f96 Merge changes I62771a8f,I5edf0ffb
* changes:
  PacketBuilderTest: add IPv6 TCP test
  PacketBuilder: add IPv6 support
2022-05-27 09:59:17 +00:00
Lorenzo Colitti
b02211a312 When parsing a netlink message, always advance to the end.
NetlinkEvent#parse relies on message-specific classes to parse
the payload of the message. If these classes do not consume the
entire message, parse does not advance to the end of the
message. This means that any code that loops over a ByteBuffer
parsing messages one at a time (e.g., NetlinkMonitor) will think
that there is still a message left to parse, and will attempt
to parse the remainder of the message as a new netlink message.
This is obviously incorrect for any buffer that contains more
than one netlink message.

Bug: 163492391
Test: existing unit tests
Change-Id: Ifdb9748068857f75ca00c58f0c40f19809aae5c9
2022-05-26 17:37:04 +09:00
Xiao Ma
6b6fc1b38d Add test to verify parsing multiple netlink messages in one buffer.
Currently the netlink parsing code doesn't advance to the end of message
if it doesn't consume the entire message, that results in the remaining
attributes will be considered as a new netlink message, parsing the
attributes will fail and return null. Have a testcase to verify this case.

Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I2719cd917f9932d5e77002e615845076784139a2
2022-05-26 15:57:06 +09:00
Hungming Chen
3288afaede PacketBuilderTest: add IPv6 TCP test
Bug: 215655463
Test: atest NetworkStaticLibTests
Change-Id: I62771a8f2549c7785919504f4816a28f30551953
2022-05-17 22:35:11 +08:00
Hungming Chen
8ffa79ce34 PacketBuilder: add IPv6 support
Support IPv6 packet builder and verify with UDP packet unit test.

Bug: 215655463
Test: atest NetworkStaticLibTests

Change-Id: I5edf0ffbc9b37ecf0e0a6da0dc7d04716fc4c38c
2022-05-17 22:35:01 +08:00