Skip to content

Commit

Permalink
[python][test] change traced syscall from clone to execve
Browse files Browse the repository at this point in the history
Fixes iovisor#4203

The issue goes into more details as to why this change is needed. The TL;DR is
that the implementation of `os.popen` change somewhere between python 3.9 and
3.10 and depending on which version of python is used, either `fork/clone` is
called, or `vfork`.

In both cases, we are going to end up calling `execve`. This change switches
the syscall traced from `clone` to `execve`.

At the same time, it is now a constant that can be used across the tests.

Test plan:
Before https://gist.github.com/chantra/d37f3daa969bdbc07862dc11f8384a38
After https://gist.github.com/chantra/2860e9812f00eaa0758ccdb5d3192689
  • Loading branch information
chantra committed Aug 30, 2022
1 parent 552d64e commit 5360496
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/python/test_percpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from bcc import BPF
import multiprocessing

MONITORED_SYSCALL="execve"

class TestPercpu(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -38,7 +40,7 @@ def test_u64(self):
"""
bpf_code = BPF(text=test_prog1)
stats_map = bpf_code.get_table("stats")
event_name = bpf_code.get_syscall_fnname("clone")
event_name = bpf_code.get_syscall_fnname(MONITORED_SYSCALL)
bpf_code.attach_kprobe(event=event_name, fn_name="hello_world")
ini = stats_map.Leaf()
for i in range(0, multiprocessing.cpu_count()):
Expand Down Expand Up @@ -70,7 +72,7 @@ def test_u32(self):
"""
bpf_code = BPF(text=test_prog1)
stats_map = bpf_code.get_table("stats")
event_name = bpf_code.get_syscall_fnname("clone")
event_name = bpf_code.get_syscall_fnname(MONITORED_SYSCALL)
bpf_code.attach_kprobe(event=event_name, fn_name="hello_world")
ini = stats_map.Leaf()
for i in range(0, multiprocessing.cpu_count()):
Expand Down Expand Up @@ -108,7 +110,7 @@ def test_struct_custom_func(self):
bpf_code = BPF(text=test_prog2)
stats_map = bpf_code.get_table("stats",
reducer=lambda x,y: stats_map.sLeaf(x.c1+y.c1))
event_name = bpf_code.get_syscall_fnname("clone")
event_name = bpf_code.get_syscall_fnname(MONITORED_SYSCALL)
bpf_code.attach_kprobe(event=event_name, fn_name="hello_world")
ini = stats_map.Leaf()
for i in ini:
Expand Down

0 comments on commit 5360496

Please sign in to comment.