fix some test cases failed (#3235)
authorxuchunmei000 <59222308+xuchunmei000@users.noreply.github.com>
Thu, 21 Jan 2021 15:22:23 +0000 (23:22 +0800)
committerGitHub <noreply@github.com>
Thu, 21 Jan 2021 15:22:23 +0000 (07:22 -0800)
* tests/test_uprobes.py: set larger sleep time to pass test on aarch64
* test/test_clang.py: attach to vfs_read after failed to attach __vfs_read
* tests/test_clang_complex.c: set BPF_TABLE array key type to int
  array_map_check_btf in kernel/bpf/arraymap.c check key type must be
  BTF_KIND_INT

Signed-off-by: Chunmei Xu <xuchunmei@linux.alibaba.com>
tests/python/test_clang.py
tests/python/test_clang_complex.c
tests/python/test_uprobes.py

index 1006bee4b917c3860920ca9a186301deb78dfd3a..b1fb7e96082145f60fa9715115084d811e82b1c8 100755 (executable)
@@ -852,7 +852,11 @@ int trace_read_entry(struct pt_regs *ctx, struct file *file) {
 }
         """
         b = BPF(text=text)
-        b.attach_kprobe(event="__vfs_read", fn_name="trace_read_entry")
+        try:
+            b.attach_kprobe(event="__vfs_read", fn_name="trace_read_entry")
+        except Exception:
+            print('Current kernel does not have __vfs_read, try vfs_read instead')
+            b.attach_kprobe(event="vfs_read", fn_name="trace_read_entry")
 
     def test_printk_f(self):
         text = """
index 8cb9d7c9210f417cf56fd09e5a9b85a5e659595f..b0397e8db1a7a3fbe2de84860b495dc321988c91 100644 (file)
@@ -13,14 +13,11 @@ struct FwdLeaf {
 BPF_HASH(fwd_map, struct FwdKey, struct FwdLeaf, 1);
 
 // array
-struct ConfigKey {
-  u32 index;
-};
 struct ConfigLeaf {
   u32 bpfdev_ip;
   u32 slave_ip;
 };
-BPF_TABLE("array", struct ConfigKey, struct ConfigLeaf, config_map, 1);
+BPF_TABLE("array", u32, struct ConfigLeaf, config_map, 1);
 
 // hash
 struct MacaddrKey {
@@ -49,7 +46,7 @@ int handle_packet(struct __sk_buff *skb) {
     // make sure configured
     u32 slave_ip;
 
-    struct ConfigKey cfg_key = {.index = 0};
+    u32 cfg_key = 0;
     struct ConfigLeaf *cfg_leaf = config_map.lookup(&cfg_key);
     if (cfg_leaf) {
       slave_ip = cfg_leaf->slave_ip;
@@ -132,7 +129,7 @@ int handle_packet(struct __sk_buff *skb) {
       u64 src_mac;
       u64 dst_mac;
 
-      struct ConfigKey cfg_key = {.index = 0};
+      u32 cfg_key = 0;
       struct ConfigLeaf *cfg_leaf = config_map.lookup(&cfg_key);
       if (cfg_leaf) {
         struct MacaddrKey mac_key = {.ip = cfg_leaf->bpfdev_ip};
index 62a370fa574598dc4f9e76828a99bf90dcbf511a..f7c78e7547f72e946a1a105797a67e4795569edc 100755 (executable)
@@ -119,7 +119,7 @@ int count(struct pt_regs *ctx) {
             shutil.copy(libz_path, b"/tmp")
 
             libz = ctypes.CDLL("/tmp/libz.so.1")
-            time.sleep(1)
+            time.sleep(3)
             libz.zlibVersion()
             time.sleep(5)
             os._exit(0)
@@ -130,7 +130,7 @@ int count(struct pt_regs *ctx) {
         b = bcc.BPF(text=text)
         b.attach_uprobe(name=libname, sym=symname, fn_name="count", pid=child_pid)
         b.attach_uretprobe(name=libname, sym=symname, fn_name="count", pid=child_pid)
-        time.sleep(1)
+        time.sleep(5)
         self.assertEqual(b["stats"][ctypes.c_int(0)].value, 2)
         b.detach_uretprobe(name=libname, sym=symname, pid=child_pid)
         b.detach_uprobe(name=libname, sym=symname, pid=child_pid)