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
b93f2c0e
Commit
b93f2c0e
authored
8 years ago
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cc: Add tests for the C API
parent
18ae111f
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
393 additions
and
0 deletions
+393
-0
tests/cc/CMakeLists.txt
tests/cc/CMakeLists.txt
+5
-0
tests/cc/sput.h
tests/cc/sput.h
+272
-0
tests/cc/test_c_api.c
tests/cc/test_c_api.c
+116
-0
No files found.
tests/cc/CMakeLists.txt
View file @
b93f2c0e
...
...
@@ -7,3 +7,8 @@ add_executable(test_static test_static.c)
target_link_libraries
(
test_static bcc-static
)
add_test
(
NAME c_test_static COMMAND
${
TEST_WRAPPER
}
c_test_static sudo
${
CMAKE_CURRENT_BINARY_DIR
}
/test_static
)
add_executable
(
test_c_api test_c_api.c
)
target_link_libraries
(
test_c_api bcc-shared dl
)
add_test
(
NAME test_c_api COMMAND
${
TEST_WRAPPER
}
c_test_api sudo
${
CMAKE_CURRENT_BINARY_DIR
}
/test_c_api
)
This diff is collapsed.
Click to expand it.
tests/cc/sput.h
0 → 100644
View file @
b93f2c0e
This diff is collapsed.
Click to expand it.
tests/cc/test_c_api.c
0 → 100644
View file @
b93f2c0e
#include <stdint.h>
#include <unistd.h>
#include <dlfcn.h>
#include "sput.h"
#include "bcc_elf.h"
#include "bcc_proc.h"
#include "bcc_syms.h"
static
void
test_procutils__which_so
(
void
)
{
const
char
*
libm
=
bcc_procutils_which_so
(
"m"
);
sput_fail_unless
(
libm
,
"find libm"
);
sput_fail_unless
(
libm
[
0
]
==
'/'
,
"resolve libm absolute path"
);
sput_fail_unless
(
strstr
(
libm
,
"libm.so"
),
"resolve libm so"
);
}
static
void
test_procutils__which
(
void
)
{
char
*
ld
=
bcc_procutils_which
(
"ld"
);
sput_fail_unless
(
ld
,
"find `ld` binary"
);
sput_fail_unless
(
ld
[
0
]
==
'/'
,
"find `ld` absolute path"
);
free
(
ld
);
}
static
void
_test_ksym
(
const
char
*
sym
,
uint64_t
addr
,
void
*
_
)
{
if
(
!
strcmp
(
sym
,
"startup_64"
))
{
sput_fail_unless
(
addr
==
0xffffffff81000000ull
,
"ksym `startup_64`"
);
}
else
if
(
!
strcmp
(
sym
,
"__per_cpu_start"
))
sput_fail_unless
(
addr
==
0x0
,
"ksym `__per_cpu_start`"
);
}
static
void
test_procutils__each_ksym
(
void
)
{
sput_fail_unless
(
geteuid
()
==
0
,
"ensure we are root"
);
bcc_procutils_each_ksym
(
_test_ksym
,
NULL
);
}
static
void
test_syms__resolve_symname
(
void
)
{
struct
bcc_symbol
sym
;
sput_fail_unless
(
bcc_resolve_symname
(
"c"
,
"malloc"
,
0x0
,
&
sym
)
==
0
,
"bcc_resolve_symname(c, malloc)"
);
sput_fail_unless
(
strstr
(
sym
.
module
,
"libc.so"
),
"resolve to module"
);
sput_fail_unless
(
sym
.
module
[
0
]
==
'/'
,
"resolve to abspath"
);
sput_fail_unless
(
sym
.
offset
!=
0
,
"resolve sym offset"
);
}
static
void
test_syms__resolver_pid
(
void
)
{
struct
bcc_symbol
sym
;
void
*
resolver
=
bcc_symcache_new
(
getpid
());
sput_fail_unless
(
resolver
,
"create a new resolver for PID"
);
sput_fail_unless
(
bcc_symcache_resolve
(
resolver
,
(
uint64_t
)
&
test_syms__resolver_pid
,
&
sym
)
==
0
,
"resolve the current function address"
);
char
*
this_exe
=
realpath
(
"/proc/self/exe"
,
NULL
);
sput_fail_unless
(
strcmp
(
this_exe
,
sym
.
module
)
==
0
,
"resolve a function to our own binary"
);
free
(
this_exe
);
sput_fail_unless
(
strcmp
(
"test_syms__resolver_pid"
,
sym
.
name
)
==
0
,
"resolve a function to its actual name"
);
void
*
libbcc
=
dlopen
(
"libbcc.so"
,
RTLD_LAZY
|
RTLD_NOLOAD
);
sput_fail_unless
(
libbcc
,
"dlopen(libbcc.so)"
);
void
*
libbcc_fptr
=
dlsym
(
libbcc
,
"bcc_resolve_symname"
);
sput_fail_unless
(
libbcc_fptr
,
"dlsym(bcc_resolve_symname)"
);
sput_fail_unless
(
bcc_symcache_resolve
(
resolver
,
(
uint64_t
)
libbcc_fptr
,
&
sym
)
==
0
,
"resolve a function in libbcc in our current process"
);
sput_fail_unless
(
strstr
(
sym
.
module
,
"libbcc.so"
),
"resolve a function to the loaded libbcc module"
);
sput_fail_unless
(
strcmp
(
"bcc_resolve_symname"
,
sym
.
name
)
==
0
,
"resolve a function in libbcc to its actual name"
);
void
*
libc_fptr
=
dlsym
(
NULL
,
"strtok"
);
sput_fail_unless
(
libc_fptr
,
"dlsym(strtok)"
);
sput_fail_unless
(
bcc_symcache_resolve
(
resolver
,
(
uint64_t
)
libc_fptr
,
&
sym
)
==
0
,
"resolve a function in libc in our current process"
);
sput_fail_unless
(
sym
.
module
&&
sym
.
module
[
0
]
==
'/'
&&
strstr
(
sym
.
module
,
"libc"
),
"resolve a function to linked libc module"
);
sput_fail_unless
(
strcmp
(
"strtok"
,
sym
.
name
)
==
0
,
"resolve a function in libc to its actual name"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
sput_start_testing
();
sput_enter_suite
(
"procutils: which_so"
);
sput_run_test
(
test_procutils__which_so
);
sput_enter_suite
(
"procutils: which"
);
sput_run_test
(
test_procutils__which
);
sput_enter_suite
(
"procutils: each_ksym"
);
sput_run_test
(
test_procutils__each_ksym
);
sput_enter_suite
(
"syms: resolve_symname"
);
sput_run_test
(
test_syms__resolve_symname
);
sput_enter_suite
(
"syms: resolver_pid"
);
sput_run_test
(
test_syms__resolver_pid
);
sput_finish_testing
();
return
sput_get_return_value
();
}
This diff is collapsed.
Click to expand it.
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