NAME uprobes - list probes by file
RUN {{BPFTRACE}} -l 'uprobe:./testprogs/uprobe_test:*'
EXPECT uprobe:./testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5

NAME uprobes - list probes by file with wildcarded filter
RUN {{BPFTRACE}} -l 'uprobe:./testprogs/uprobe_test:uprobeFunc*'
EXPECT uprobe:./testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5

NAME uprobes - list probes with wildcarded file matching multiple files
RUN {{BPFTRACE}} -l 'uprobe:./testprogs/uprobe*:*'
EXPECT uprobe:./testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5

NAME uprobes - list probes by file with wildcarded file and filter
RUN {{BPFTRACE}} -l 'uprobe:./testprogs/uprobe_test*:uprobeFunc*'
EXPECT uprobe:./testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5

NAME uprobes - list probes by file with specific filter
RUN {{BPFTRACE}} -l 'uprobe:./testprogs/uprobe_test:uprobeFunction1'
EXPECT uprobe:./testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5

NAME uprobes - list probes by file with wildcarded probe type
RUN {{BPFTRACE}} -l '*:./testprogs/uprobe_test:*' | grep -e '^uprobe:'
EXPECT uprobe:./testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5

NAME uprobes - list probes by pid
RUN {{BPFTRACE}} -l -p {{BEFORE_PID}} | grep -e '^uprobe'
EXPECT_REGEX uprobe:.*/testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5
BEFORE ./testprogs/uprobe_test

NAME uprobes - list probes by pid; uprobes only
RUN {{BPFTRACE}} -l 'uprobe:*' -p {{BEFORE_PID}}
EXPECT_REGEX uprobe:.*/testprogs/uprobe_test:uprobeFunction1
TIMEOUT 5
BEFORE ./testprogs/uprobe_test

NAME uprobes - list probes by pid in separate mount namespace
RUN {{BPFTRACE}} -l -p {{BEFORE_PID}} | grep -e '^uprobe'
EXPECT_REGEX uprobe:.*/bpftrace-unshare-mountns-test/uprobe_test:uprobeFunction1
TIMEOUT 5
BEFORE ./testprogs/mountns_wrapper uprobe_test

NAME uprobes - attach to probe for executable in separate mount namespace
RUN {{BPFTRACE}} -e 'uprobe:/tmp/bpftrace-unshare-mountns-test/uprobe_test:uprobeFunction1 { printf("here\n" ); exit(); }' -p {{BEFORE_PID}}
EXPECT Attaching 1 probe...
TIMEOUT 5
BEFORE ./testprogs/mountns_wrapper uprobe_test

# Note that we don't expect the exact uprobeFunction1 name because CI runs in a docker
# container and symbols don't currently get resolved correctly in this scenario
# as the event received by bpftrace contains the pid of the process in the root
# pid namespace, not that of the docker container's namespace.
NAME uprobes - attach to probe for executable in a pivot_root'd mount namespace
RUN {{BPFTRACE}} -e 'uprobe:/proc/{{BEFORE_PID}}/root/uprobe_test:uprobeFunction1 { printf("func %s\n", func); exit(); }'
EXPECT_REGEX ^func (0x[0-9a-f]+|function1)$
TIMEOUT 5
BEFORE ./testprogs/mountns_pivot_wrapper uprobe_test

NAME uprobes - attach to probe by pid with only wildcard
RUN {{BPFTRACE}} -e 'uprobe:*:uprobeFunction1 { printf("here\n" ); exit(); }' -p {{BEFORE_PID}}
EXPECT Attaching 1 probe...
TIMEOUT 5
BEFORE ./testprogs/uprobe_test

NAME uprobes - attach to multiple probes by pid with only wildcard
RUN {{BPFTRACE}} -e 'uprobe:*:uprobeFunc* { printf("here\n" ); exit(); }' -p {{BEFORE_PID}}
EXPECT here
TIMEOUT 5
BEFORE ./testprogs/uprobe_test

NAME uprobes - list probes in non-executable library
RUN {{BPFTRACE}} -l 'uprobe:./testlibs/libsimple.so:fun'
EXPECT uprobe:./testlibs/libsimple.so:fun
TIMEOUT 5

NAME uprobes - probe function in non-executable library
PROG uprobe:./testlibs/libsimple.so:fun {}
EXPECT Attaching 1 probe...
TIMEOUT 5

NAME uprobes - attach to single process with pid arg
RUN {{BPFTRACE}} runtime/scripts/uprobe_pid_check.bt -p {{BEFORE_PID}} {{BEFORE_PID}}
EXPECT hello
TIMEOUT 5
BEFORE ./testprogs/uprobe_fork_loop
