summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChenbo Feng <fengc@google.com>2018-08-23 16:08:02 -0700
committerChenbo Feng <fengc@google.com>2018-08-27 12:13:08 -0700
commite59c063ef4331ca047d51a0df4aa4dd0ce49e09e (patch)
treecdd5bcbfd65d46b00844b2a841967fcd8c720255
parente57d074dc520ab1feabe5b202e6ef1c3f9f9844b (diff)
downloadtests-e59c063ef4331ca047d51a0df4aa4dd0ce49e09e.tar.gz
Always test UDP_DIAG for 4.9 kernel
The devices that ship with P and running 4.9 kernel need CONFIG_INET_UDP_DIAG to work properly. It cannot be added to android-base.config now but it is required for P. So we do not skip the test for that config anymore in this case. Bug: 112068616 Test: sock_diag_test pass on device Change-Id: I10b26a8e667de83cd156b4622eb7a4cd0b35bb2e
-rwxr-xr-xnet/test/sock_diag_test.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/net/test/sock_diag_test.py b/net/test/sock_diag_test.py
index e25035b..4b1d055 100755
--- a/net/test/sock_diag_test.py
+++ b/net/test/sock_diag_test.py
@@ -39,10 +39,24 @@ HAVE_SO_COOKIE_SUPPORT = net_test.LINUX_VERSION >= (4, 9, 0)
IPPROTO_SCTP = 132
def HaveUdpDiag():
- # There is no way to tell whether a dump succeeded: if the appropriate handler
- # wasn't found, __inet_diag_dump just returns an empty result instead of an
- # error. So, just check to see if a UDP dump returns no sockets when we know
- # it should return one.
+ """Checks if the current kernel has config CONFIG_INET_UDP_DIAG enabled.
+
+ This config is required for device running 4.9 kernel that ship with P, In
+ this case always assume the config is there and use the tests to check if the
+ config is enabled as required.
+
+ For all ther other kernel version, there is no way to tell whether a dump
+ succeeded: if the appropriate handler wasn't found, __inet_diag_dump just
+ returns an empty result instead of an error. So, just check to see if a UDP
+ dump returns no sockets when we know it should return one. If not, some tests
+ will be skipped.
+
+ Returns:
+ True if the kernel is 4.9 or above, or the CONFIG_INET_UDP_DIAG is enabled.
+ False otherwise.
+ """
+ if HAVE_SO_COOKIE_SUPPORT:
+ return True;
s = socket(AF_INET6, SOCK_DGRAM, 0)
s.bind(("::", 0))
s.connect((s.getsockname()))