Skip to content

Commit 7ae17f3

Browse files
committed
Add a dlopen test for toggle traces
1 parent 635451f commit 7ae17f3

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

integration_tests/setup_suite.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
setup_suite() {
44
export MPIRUN=${MPIRUN:-mpirun}
55

6+
# Set the path to find iprof, babeltrace_thapi, etc.
67
export PATH=$(pkg-config --variable=bindir thapi):${PATH}
8+
# We need this for the toggle_api/toggle_dlopen test.
9+
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pkg-config --variable=libdir thapi)
710

811
missing_tools=()
912

integration_tests/toggle.bats

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ get_unique_jobid() {
1010
}
1111

1212
@test "toggle_api" {
13-
rm -rf toggle_traces 2>/dev/null
14-
1513
cc ${THAPI_INCFLAGS} ./integration_tests/toggle.c -o toggle ${THAPI_LDFLAGS}
1614

15+
rm -rf toggle_traces 2>/dev/null
1716
iprof --trace-output toggle_traces --no-analysis -- ./toggle
1817
dir=$(ls -d -1 ./toggle_traces/*/)
1918

@@ -33,6 +32,21 @@ get_unique_jobid() {
3332
auto_stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:auto_stop | wc -l)
3433
[ "$auto_stop_count" -eq 1 ]
3534

35+
cc ./integration_tests/toggle_dlopen.c -o toggle_dlopen -ldl
36+
37+
rm -rf toggle_traces 2>/dev/null
38+
iprof --trace-output toggle_traces --no-analysis -- ./toggle_dlopen
39+
dir=$(ls -d -1 ./toggle_traces/*/)
40+
41+
# Check expected trace counts.
42+
start_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:start | wc -l)
43+
[ "$start_count" -eq 2 ]
44+
45+
stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:stop | wc -l)
46+
[ "$stop_count" -eq 2 ]
47+
48+
auto_stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:auto_stop | wc -l)
49+
[ "$auto_stop_count" -eq 2 ]
3650
}
3751

3852
toggle_count_base() {

integration_tests/toggle.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <thapi.h>
22

3-
int main(int argc, char *argv[]) {
3+
int main(void) {
44
thapi_start();
55
thapi_stop();
6+
return 0;
67
}

integration_tests/toggle_dlopen.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <dlfcn.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#define check_error(ptr_) \
6+
{ \
7+
void *ptr = (void *)ptr_; \
8+
if (!ptr) { \
9+
printf("%s:%d -- %s\n", __FILE__, __LINE__, dlerror()); \
10+
return 1; \
11+
} \
12+
}
13+
14+
int main(void) {
15+
dlerror();
16+
17+
for (int i = 0; i < 2; i++) {
18+
void *thapi = dlopen("libThapi.so", RTLD_NOW | RTLD_LOCAL);
19+
check_error(thapi);
20+
21+
void (*start)(void) = (void (*)(void))dlsym(thapi, "thapi_start");
22+
check_error(start);
23+
24+
void (*stop)(void) = (void (*)(void))dlsym(thapi, "thapi_stop");
25+
check_error(stop);
26+
27+
(*start)(), (*stop)();
28+
29+
dlclose(thapi);
30+
}
31+
32+
return 0;
33+
}
34+
35+
#undef check_error

0 commit comments

Comments
 (0)