summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-05-20 07:25:50 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-05-20 07:25:50 +0000
commit20522bdde70b29f96291d5d1b9cd343cf1d20f80 (patch)
tree0c3b90e114e2af9715be969bb3252a7f99811c2b
parent6394bb4a94596201d144bdf04757736329da1e23 (diff)
parent60317ba07e58a16ffe300b963a0b6fcbb8e17c07 (diff)
downloadtests-security-pi-release.tar.gz
Snap for 4793185 from 60317ba07e58a16ffe300b963a0b6fcbb8e17c07 to pi-releaseandroid-wear-9.0.0_r9android-wear-9.0.0_r8android-wear-9.0.0_r7android-wear-9.0.0_r6android-wear-9.0.0_r5android-wear-9.0.0_r4android-wear-9.0.0_r34android-wear-9.0.0_r33android-wear-9.0.0_r32android-wear-9.0.0_r31android-wear-9.0.0_r30android-wear-9.0.0_r3android-wear-9.0.0_r29android-wear-9.0.0_r28android-wear-9.0.0_r27android-wear-9.0.0_r26android-wear-9.0.0_r25android-wear-9.0.0_r24android-wear-9.0.0_r23android-wear-9.0.0_r22android-wear-9.0.0_r21android-wear-9.0.0_r20android-wear-9.0.0_r2android-wear-9.0.0_r19android-wear-9.0.0_r18android-wear-9.0.0_r17android-wear-9.0.0_r16android-wear-9.0.0_r15android-wear-9.0.0_r14android-wear-9.0.0_r13android-wear-9.0.0_r12android-wear-9.0.0_r11android-wear-9.0.0_r10android-wear-9.0.0_r1android-security-9.0.0_r76android-security-9.0.0_r75android-security-9.0.0_r74android-security-9.0.0_r73android-security-9.0.0_r72android-security-9.0.0_r71android-security-9.0.0_r70android-security-9.0.0_r69android-security-9.0.0_r68android-security-9.0.0_r67android-security-9.0.0_r66android-security-9.0.0_r65android-security-9.0.0_r64android-security-9.0.0_r63android-security-9.0.0_r62android-cts-9.0_r9android-cts-9.0_r8android-cts-9.0_r7android-cts-9.0_r6android-cts-9.0_r5android-cts-9.0_r4android-cts-9.0_r3android-cts-9.0_r20android-cts-9.0_r2android-cts-9.0_r19android-cts-9.0_r18android-cts-9.0_r17android-cts-9.0_r16android-cts-9.0_r15android-cts-9.0_r14android-cts-9.0_r13android-cts-9.0_r12android-cts-9.0_r11android-cts-9.0_r10android-cts-9.0_r1android-9.0.0_r9android-9.0.0_r8android-9.0.0_r7android-9.0.0_r61android-9.0.0_r60android-9.0.0_r6android-9.0.0_r59android-9.0.0_r58android-9.0.0_r57android-9.0.0_r56android-9.0.0_r55android-9.0.0_r54android-9.0.0_r53android-9.0.0_r52android-9.0.0_r51android-9.0.0_r50android-9.0.0_r5android-9.0.0_r49android-9.0.0_r48android-9.0.0_r3android-9.0.0_r2android-9.0.0_r18android-9.0.0_r17android-9.0.0_r10android-9.0.0_r1security-pi-releasepie-security-releasepie-s2-releasepie-release-2pie-releasepie-r2-s2-releasepie-r2-s1-releasepie-r2-releasepie-cts-release
Change-Id: Ibbd3d7792162bcdbaaffc889159d5718c945d901
-rwxr-xr-xnet/test/bpf.py11
-rwxr-xr-xnet/test/bpf_test.py49
2 files changed, 39 insertions, 21 deletions
diff --git a/net/test/bpf.py b/net/test/bpf.py
index ff23d79..c9ad264 100755
--- a/net/test/bpf.py
+++ b/net/test/bpf.py
@@ -195,13 +195,20 @@ def LookupMap(map_fd, key):
def GetNextKey(map_fd, key):
- c_key = ctypes.c_uint32(key)
+ if key is not None:
+ c_key = ctypes.c_uint32(key)
+ c_next_key = ctypes.c_uint32(0)
+ key_ptr = ctypes.addressof(c_key)
+ else:
+ key_ptr = 0;
c_next_key = ctypes.c_uint32(0)
attr = BpfAttrOps(
- (map_fd, ctypes.addressof(c_key), ctypes.addressof(c_next_key), 0))
+ (map_fd, key_ptr, ctypes.addressof(c_next_key), 0))
BpfSyscall(BPF_MAP_GET_NEXT_KEY, attr)
return c_next_key
+def GetFirstKey(map_fd):
+ return GetNextKey(map_fd, None)
def DeleteMap(map_fd, key):
c_key = ctypes.c_uint32(key)
diff --git a/net/test/bpf_test.py b/net/test/bpf_test.py
index 9da3907..e7a4edb 100755
--- a/net/test/bpf_test.py
+++ b/net/test/bpf_test.py
@@ -29,7 +29,6 @@ import net_test
import sock_diag
libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True)
-HAVE_EBPF_SUPPORT = net_test.LINUX_VERSION >= (4, 9, 0)
HAVE_EBPF_ACCOUNTING = net_test.LINUX_VERSION >= (4, 9, 0)
KEY_SIZE = 8
VALUE_SIZE = 4
@@ -146,8 +145,8 @@ INS_BPF_PARAM_STORE = [
BpfStxMem(BPF_DW, BPF_REG_10, BPF_REG_0, key_offset),
]
-@unittest.skipUnless(HAVE_EBPF_SUPPORT,
- "eBPF function not fully supported")
+@unittest.skipUnless(HAVE_EBPF_ACCOUNTING,
+ "BPF helper function is not fully supported")
class BpfTest(net_test.NetworkTest):
def setUp(self):
@@ -172,31 +171,43 @@ class BpfTest(net_test.NetworkTest):
DeleteMap(self.map_fd, key)
self.assertRaisesErrno(errno.ENOENT, LookupMap, self.map_fd, key)
- def testIterateMap(self):
- self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
- TOTAL_ENTRIES)
- value = 1024
- for key in xrange(1, TOTAL_ENTRIES):
- UpdateMap(self.map_fd, key, value)
- for key in xrange(1, TOTAL_ENTRIES):
- self.assertEquals(value, LookupMap(self.map_fd, key).value)
- self.assertRaisesErrno(errno.ENOENT, LookupMap, self.map_fd, 101)
- key = 0
+ def CheckAllMapEntry(self, nonexistent_key, totalEntries, value):
count = 0
- while 1:
- if count == TOTAL_ENTRIES - 1:
+ key = nonexistent_key
+ while True:
+ if count == totalEntries:
self.assertRaisesErrno(errno.ENOENT, GetNextKey, self.map_fd, key)
break
else:
result = GetNextKey(self.map_fd, key)
key = result.value
- self.assertGreater(key, 0)
+ self.assertGreaterEqual(key, 0)
self.assertEquals(value, LookupMap(self.map_fd, key).value)
count += 1
- # TODO: move this check to the begining of the class insdead.
- @unittest.skipUnless(HAVE_EBPF_ACCOUNTING,
- "BPF helper function is not fully supported")
+ def testIterateMap(self):
+ self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
+ TOTAL_ENTRIES)
+ value = 1024
+ for key in xrange(0, TOTAL_ENTRIES):
+ UpdateMap(self.map_fd, key, value)
+ for key in xrange(0, TOTAL_ENTRIES):
+ self.assertEquals(value, LookupMap(self.map_fd, key).value)
+ self.assertRaisesErrno(errno.ENOENT, LookupMap, self.map_fd, 101)
+ nonexistent_key = -1
+ self.CheckAllMapEntry(nonexistent_key, TOTAL_ENTRIES, value)
+
+ def testFindFirstMapKey(self):
+ self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
+ TOTAL_ENTRIES)
+ value = 1024
+ for key in xrange(0, TOTAL_ENTRIES):
+ UpdateMap(self.map_fd, key, value)
+ firstKey = GetFirstKey(self.map_fd)
+ key = firstKey.value
+ self.CheckAllMapEntry(key, TOTAL_ENTRIES - 1, value)
+
+
def testRdOnlyMap(self):
self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
TOTAL_ENTRIES, map_flags=BPF_F_RDONLY)