summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-03-04 08:24:17 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-03-04 08:24:17 +0000
commit9c06c7859dbc2e2ebbe888bc18d8c396a9397d69 (patch)
treebedad948d5263c0714cec3a1a3982ea3cf61f3df
parentbc50f54fa5a310c86c6f8495ff3989b247fdc518 (diff)
parent2113ad3e00992556dde023dc3d9e0b718a723f48 (diff)
downloadtests-9c06c7859dbc2e2ebbe888bc18d8c396a9397d69.tar.gz
Snap for 4632767 from 2113ad3e00992556dde023dc3d9e0b718a723f48 to pi-release
Change-Id: I72da158352fa5e3912a490bf8fa3feef853c3971
-rwxr-xr-xnet/test/bpf.py11
-rwxr-xr-xnet/test/bpf_test.py21
2 files changed, 28 insertions, 4 deletions
diff --git a/net/test/bpf.py b/net/test/bpf.py
index a96a95a..ff23d79 100755
--- a/net/test/bpf.py
+++ b/net/test/bpf.py
@@ -144,11 +144,14 @@ BPF_FUNC_map_delete_elem = 3
BPF_FUNC_get_socket_cookie = 46
BPF_FUNC_get_socket_uid = 47
+BPF_F_RDONLY = 1 << 3
+BPF_F_WRONLY = 1 << 4
+
# These object below belongs to the same kernel union and the types below
# (e.g., bpf_attr_create) aren't kernel struct names but just different
# variants of the union.
-BpfAttrCreate = cstruct.Struct("bpf_attr_create", "=IIII",
- "map_type key_size value_size max_entries")
+BpfAttrCreate = cstruct.Struct("bpf_attr_create", "=IIIII",
+ "map_type key_size value_size max_entries, map_flags")
BpfAttrOps = cstruct.Struct("bpf_attr_ops", "=QQQQ",
"map_fd key_ptr value_ptr flags")
BpfAttrProgLoad = cstruct.Struct(
@@ -168,8 +171,8 @@ def BpfSyscall(op, attr):
csocket.MaybeRaiseSocketError(ret)
return ret
-def CreateMap(map_type, key_size, value_size, max_entries):
- attr = BpfAttrCreate((map_type, key_size, value_size, max_entries))
+def CreateMap(map_type, key_size, value_size, max_entries, map_flags=0):
+ attr = BpfAttrCreate((map_type, key_size, value_size, max_entries, map_flags))
return BpfSyscall(BPF_MAP_CREATE, attr)
diff --git a/net/test/bpf_test.py b/net/test/bpf_test.py
index 7014da4..9da3907 100755
--- a/net/test/bpf_test.py
+++ b/net/test/bpf_test.py
@@ -194,6 +194,27 @@ class BpfTest(net_test.NetworkTest):
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 testRdOnlyMap(self):
+ self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
+ TOTAL_ENTRIES, map_flags=BPF_F_RDONLY)
+ value = 1024
+ key = 1
+ self.assertRaisesErrno(errno.EPERM, UpdateMap, self.map_fd, key, value)
+ self.assertRaisesErrno(errno.ENOENT, LookupMap, self.map_fd, key)
+
+ @unittest.skipUnless(HAVE_EBPF_ACCOUNTING,
+ "BPF helper function is not fully supported")
+ def testWrOnlyMap(self):
+ self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
+ TOTAL_ENTRIES, map_flags=BPF_F_WRONLY)
+ value = 1024
+ key = 1
+ UpdateMap(self.map_fd, key, value)
+ self.assertRaisesErrno(errno.EPERM, LookupMap, self.map_fd, key)
+
def testProgLoad(self):
# Move skb to BPF_REG_6 for further usage
instructions = [