Skip to content

Commit ac06b53

Browse files
committed
ci: minimal testing workflow
Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
1 parent e09e184 commit ac06b53

File tree

5 files changed

+59
-39
lines changed

5 files changed

+59
-39
lines changed

.github/scripts/setup.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Assume sudo in this script
6+
7+
# Install dependencies
8+
apt update && apt install -y make file gawk libfuse2t64
9+
10+
# Download bpftrace release
11+
BIN_DIR=/usr/local/bin
12+
mkdir -p $BIN_DIR
13+
curl -L -o bpftrace https://github.com/bpftrace/bpftrace/releases/download/v0.21.2/bpftrace
14+
chmod +x bpftrace
15+
mv bpftrace $BIN_DIR
16+
bpftrace --version
17+
18+
# mount tracefs to avoid warnings from bpftrace
19+
grep -q tracefs /proc/mounts || mount -t tracefs tracefs /sys/kernel/tracing

.github/workflows/test.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: USDT CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install prerequisites
18+
run: sudo .github/scripts/setup.sh
19+
20+
- name: Build (static)
21+
run: make SHARED=0 -C tests -j$(nproc) build
22+
23+
- name: Build (shared)
24+
run: make SHARED=1 -C tests -j$(nproc) build
25+
26+
- name: Test (static)
27+
run: make V=1 SHARED=0 -C tests test
28+
29+
- name: Test (shared)
30+
run: make V=1 SHARED=1 -C tests test
31+

tests/Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ endif
3838
NONTESTS = tester common
3939

4040
TESTS := $(filter-out $(NONTESTS), \
41-
$(shell ls *.{c,cpp} 2>/dev/null | grep -v '^lib' | \
42-
${AWK} '{split($$0, p, /[^A-Za-z_]+/); print p[1]}' | \
41+
$(shell ls *.c *.cpp 2>/dev/null | grep -v '^lib' | \
42+
${AWK} '{split($$0, p, /[^A-Za-z_]+/); print p[1]}' | \
4343
sort | uniq \
4444
) \
4545
)
4646
LIBS := $(filter-out $(NONTESTS), \
47-
$(shell ls lib*.{c,cpp} 2>/dev/null | \
47+
$(shell ls lib*.c lib*.cpp 2>/dev/null | \
4848
${AWK} '{split($$0, p, /[^A-Za-z_]+/); print substr(p[1], 4)}' | \
4949
sort | uniq \
5050
) \
@@ -63,6 +63,7 @@ clean:
6363

6464
.PHONY: list
6565
list:
66+
$(call msg,TESTS,$@)
6667
$(Q)$(foreach test,$(TESTS), $(info $(test)))
6768

6869
.PHONY: build

tests/prepare-bt-script.awk

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# Emit corresponding bpftrace probe spec:
4141
# U:./test:group:name { printf("%s: some %s fmt %d spec %d\n", probe, str(arg0), (int)arg1, arg2 - 10); }
42-
printf("U:%s:%s:%s { printf(\"%s%s:%s: %s\\n\"%s); }\n",
42+
printf("usdt:%s:%s:%s { printf(\"%s%s:%s: %s\\n\"%s); }\n",
4343
path, group, name,
4444
probe[1] == "lib" ? "lib:" : "", group, name,
4545
fmt, args == "" ? "" : ", " args);

tests/run_test.sh

+4-35
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ if [ "${V:-0}" -eq 1 ]; then
77
set -x
88
fi
99

10-
TIMEOUT=10
11-
1210
awk=${AWK:-awk}
1311
readelf=${READELF:-readelf}
1412
bpftrace=${BPFTRACE:-bpftrace}
@@ -64,41 +62,12 @@ fi
6462
$TEST_BIN -B > $TEST_BTOUT_SPEC
6563

6664
if [ -s "$TEST_BTSCRIPT" ]; then
67-
# start attaching bpftrace
68-
setsid sudo $bpftrace -B none "$TEST_BTSCRIPT" >"$TEST_BTOUT_RAW" 2>&1 &
69-
bt_pid=$!
70-
bt_pgid="$(ps -opgid= "$bt_pid" | tr -d ' ')"
71-
72-
# wait for bpftrace to finish attachment
73-
bt_start=$(date +%s)
74-
while true; do
75-
bt_elapsed=$(( $(date +%s) - bt_start ))
76-
if grep -q "STARTED!" "$TEST_BTOUT_RAW"; then
77-
break
78-
elif [ "$bt_elapsed" -ge "$TIMEOUT" ]; then
79-
sudo kill -KILL -$bt_pgid 2>/dev/null
80-
echo "BPFTRACE STARTUP TIMEOUT!"
81-
echo "BPFTRACE SCRIPT:"
82-
cat "$TEST_BTSCRIPT"
83-
echo "BPFTRACE OUTPUT:"
84-
cat "$TEST_BTOUT_RAW"
85-
exit 1
86-
elif ! kill -s 0 "$bt_pid"; then
87-
echo "BPFTRACE STARTUP FAILURE!"
88-
echo "BPFTRACE SCRIPT:"
89-
cat "$TEST_BTSCRIPT"
90-
echo "BPFTRACE OUTPUT:"
91-
cat "$TEST_BTOUT_RAW"
92-
exit 1
93-
else
94-
sleep 0.2
95-
fi
96-
done
9765

98-
# get test output while bpftrace is attached
99-
$TEST_BIN &>"$TEST_OUT"
66+
# export LD_LIBRARY_PATH=$OUTPUT/shared
67+
sudo $bpftrace -B none -o $TEST_BTOUT_RAW -c $TEST_BIN $TEST_BTSCRIPT > $TEST_OUT
10068

101-
sudo kill -INT -$bt_pgid 2>/dev/null
69+
# it appears bpftrace might print some empty lines when running this way, clean them up
70+
gawk -i inplace 'NF' $TEST_OUT
10271

10372
$awk '/STARTED!/ {flag=1; next} /DONE!/ {flag=0} flag' $TEST_BTOUT_RAW > $TEST_BTOUT
10473
if ! $awk -f check-match.awk $TEST_BTOUT_SPEC $TEST_BTOUT; then

0 commit comments

Comments
 (0)