Skip to content

Commit

Permalink
Test linking pthread_trace as a library too
Browse files Browse the repository at this point in the history
  • Loading branch information
dsharlet committed Nov 20, 2024
1 parent 847a415 commit f112b81
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ cc_test(
# The best we have for now is just running one of the benchmarks that use pthreads with tracing,
# and verifying it doesn't crash and we see expected pthread_trace output.
sh_test(
name = "trace_thread_benchmark",
srcs = ["trace_test.sh"],
name = "ld_preload_test_thread_benchmark",
srcs = ["ld_preload_test.sh"],
data = [
":thread_benchmark",
"//:pthread_trace.so",
Expand All @@ -41,6 +41,28 @@ cc_test(
size = "small",
)

cc_test(
name = "traced_thread_benchmark",
srcs = ["thread_benchmark.cc"],
deps = [
"//:pthread_trace",
"@google_benchmark//:benchmark_main",
],
args = ["--benchmark_min_time=1x"],
size = "small",
)

sh_test(
name = "linked_test_thread_benchmark",
srcs = ["linked_test.sh"],
data = [":traced_thread_benchmark"],
args = [
"$(location :traced_thread_benchmark)",
"--benchmark_min_time=1x",
],
size = "small",
)

cc_test(
name = "proto_benchmark",
srcs = ["proto_benchmark.cc"],
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions test/linked_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

target="$1"

shift

fail() { rc=$?; (( $# )) && printf '%s\n' "$*" >&2; exit $(( rc == 0 ? 1 : rc )); }

trace=$(mktemp)

exec 5>&1
output=$(PTHREAD_TRACE_BUFFER_SIZE_KB=1 PTHREAD_TRACE_PATH=$trace "$target" "$@" 2>&1 | tee >(cat - >&5))

echo "$output" | grep "pthread_trace: Recorded.*KB trace" > /dev/null || fail "Did not find pthread_trace report in output"

0 comments on commit f112b81

Please sign in to comment.