diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..423d8d6 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/tests/Makefile b/tests/Makefile index 4d27eef..b971d3c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 \ ) \ @@ -59,6 +59,7 @@ clean: .PHONY: list list: + $(call msg,TESTS,$@) $(Q)$(foreach test,$(TESTS), $(info $(test))) .PHONY: build diff --git a/tests/prepare-bt-script.awk b/tests/prepare-bt-script.awk index 55eaeb3..8be7af2 100644 --- a/tests/prepare-bt-script.awk +++ b/tests/prepare-bt-script.awk @@ -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); diff --git a/tests/run_test.sh b/tests/run_test.sh index ea4389a..68da7d9 100755 --- a/tests/run_test.sh +++ b/tests/run_test.sh @@ -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} @@ -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:" @@ -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:"