Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: minimal CI testing setup #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: USDT CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install prerequisites
run: |
curl -L -o bpftrace https://github.com/bpftrace/bpftrace/releases/download/v0.21.2/bpftrace
chmod +x bpftrace
./bpftrace --version

- name: Build (static)
run: make SHARED=0 -C tests -j$(nproc) build

- name: Build (shared)
run: make SHARED=1 -C tests -j$(nproc) build

- name: Test (shared)
run: make V=1 BPFTRACE=$(realpath bpftrace) BPFTRACE_TIMEOUT=300 SHARED=1 -C tests test

- name: Test (static)
run: make V=1 BPFTRACE=$(realpath bpftrace) BPFTRACE_TIMEOUT=300 SHARED=0 -C tests test
7 changes: 4 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ endif
NONTESTS = tester common

TESTS := $(filter-out $(NONTESTS), \
$(shell ls *.{c,cpp} 2>/dev/null | grep -v '^lib' | \
${AWK} '{split($$0, p, /[^A-Za-z_]+/); print p[1]}' | \
$(shell ls *.c *.cpp 2>/dev/null | grep -v '^lib' | \
${AWK} '{split($$0, p, /[^A-Za-z_]+/); print p[1]}' | \
sort | uniq \
) \
)
LIBS := $(filter-out $(NONTESTS), \
$(shell ls lib*.{c,cpp} 2>/dev/null | \
$(shell ls lib*.c lib*.cpp 2>/dev/null | \
${AWK} '{split($$0, p, /[^A-Za-z_]+/); print substr(p[1], 4)}' | \
sort | uniq \
) \
Expand All @@ -59,6 +59,7 @@ clean:

.PHONY: list
list:
$(call msg,TESTS,$@)
$(Q)$(foreach test,$(TESTS), $(info $(test)))

.PHONY: build
Expand Down
2 changes: 1 addition & 1 deletion tests/prepare-bt-script.awk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# Emit corresponding bpftrace probe spec:
# U:./test:group:name { printf("%s: some %s fmt %d spec %d\n", probe, str(arg0), (int)arg1, arg2 - 10); }
printf("U:%s:%s:%s { printf(\"%s%s:%s: %s\\n\"%s); }\n",
printf("usdt:%s:%s:%s { printf(\"%s%s:%s: %s\\n\"%s); }\n",
path, group, name,
probe[1] == "lib" ? "lib:" : "", group, name,
fmt, args == "" ? "" : ", " args);
Expand Down
23 changes: 19 additions & 4 deletions tests/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ if [ "${V:-0}" -eq 1 ]; then
set -x
fi

TIMEOUT=10

bpftrace_timeout=${BPFTRACE_TIMEOUT:-30}
awk=${AWK:-awk}
readelf=${READELF:-readelf}
bpftrace=${BPFTRACE:-bpftrace}
Expand Down Expand Up @@ -75,7 +74,7 @@ if [ -s "$TEST_BTSCRIPT" ]; then
bt_elapsed=$(( $(date +%s) - bt_start ))
if grep -q "STARTED!" "$TEST_BTOUT_RAW"; then
break
elif [ "$bt_elapsed" -ge "$TIMEOUT" ]; then
elif [ "$bt_elapsed" -ge "$bpftrace_timeout" ]; then
sudo kill -KILL -$bt_pgid 2>/dev/null
echo "BPFTRACE STARTUP TIMEOUT!"
echo "BPFTRACE SCRIPT:"
Expand All @@ -92,14 +91,30 @@ if [ -s "$TEST_BTSCRIPT" ]; then
exit 1
else
sleep 0.2
break;
fi
echo "ITER"
done

echo "DONE 1"

# get test output while bpftrace is attached
$TEST_BIN &>"$TEST_OUT"
file $TEST_BIN
echo OUTPUT START
$TEST_BIN
echo OUTPUT END
timeout 10s $TEST_BIN 2>&1 | tee "$TEST_OUT"

echo "DONE 2"

echo "BTOUT RAW START"
cat "$TEST_BTOUT_RAW"
echo "BTOUT RAW END"

sudo kill -INT -$bt_pgid 2>/dev/null

echo "DONE 3"

$awk '/STARTED!/ {flag=1; next} /DONE!/ {flag=0} flag' $TEST_BTOUT_RAW > $TEST_BTOUT
if ! $awk -f check-match.awk $TEST_BTOUT_SPEC $TEST_BTOUT; then
echo "BPFTRACE OUTPUT MISMTACH:"
Expand Down
Loading