Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
72d7aa3c
Commit
72d7aa3c
authored
Mar 30, 2016
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test.lua: Port the `test_uprobes` suite
parent
b2a64a7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
tests/lua/test_uprobes.lua
tests/lua/test_uprobes.lua
+71
-0
No files found.
tests/lua/test_uprobes.lua
0 → 100644
View file @
72d7aa3c
require
(
"test_helper"
)
local
ffi
=
require
(
"ffi"
)
ffi
.
cdef
[[
int getpid(void);
void malloc_stats(void);
]]
TestUprobes
=
{}
function
TestUprobes
:
test_simple_library
()
local
text
=
[[
#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, stats, 1);
static void incr(int idx) {
u64 *ptr = stats.lookup(&idx);
if (ptr)
++(*ptr);
}
int count(struct pt_regs *ctx) {
u32 pid = bpf_get_current_pid_tgid();
if (pid == PID)
incr(0);
return 0;
}]]
local
pid
=
tonumber
(
ffi
.
C
.
getpid
())
local
text
=
text
:
gsub
(
"PID"
,
tostring
(
pid
))
local
b
=
BPF
:
new
{
text
=
text
}
b
:
attach_uprobe
{
name
=
"c"
,
sym
=
"malloc_stats"
,
fn_name
=
"count"
}
b
:
attach_uprobe
{
name
=
"c"
,
sym
=
"malloc_stats"
,
fn_name
=
"count"
,
retprobe
=
true
}
assert_equals
(
BPF
.
num_open_uprobes
(),
2
)
ffi
.
C
.
malloc_stats
()
local
stats
=
b
:
get_table
(
"stats"
)
assert_equals
(
tonumber
(
stats
:
get
(
0
)),
2
)
end
function
TestUprobes
:
test_simple_binary
()
local
text
=
[[
#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, stats, 1);
static void incr(int idx) {
u64 *ptr = stats.lookup(&idx);
if (ptr)
++(*ptr);
}
int count(struct pt_regs *ctx) {
u32 pid = bpf_get_current_pid_tgid();
incr(0);
return 0;
}]]
local
b
=
BPF
:
new
{
text
=
text
}
b
:
attach_uprobe
{
name
=
"/usr/bin/python"
,
sym
=
"main"
,
fn_name
=
"count"
}
b
:
attach_uprobe
{
name
=
"/usr/bin/python"
,
sym
=
"main"
,
fn_name
=
"count"
,
retprobe
=
true
}
os
.
spawn
(
"/usr/bin/python -V"
)
local
stats
=
b
:
get_table
(
"stats"
)
assert_true
(
tonumber
(
stats
:
get
(
0
))
>=
2
)
end
function
TestUprobes
:
teardown
()
BPF
.
cleanup_probes
()
end
os.exit
(
LuaUnit
.
run
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment