Skip to content

Commit

Permalink
scripts: Add script to update codegen tests
Browse files Browse the repository at this point in the history
This script helps update codegen changes. Basically all it does is
compile bpftrace against LLVM 8 and run bpftrace_test with the right
invocation.
  • Loading branch information
danobi authored and fbs committed Nov 4, 2020
1 parent 551fb81 commit 487dd81
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ shift 2
[[ $EMBED_LLVM == "ON" ]] && with_timeout make embedded_llvm "$@"
[[ $EMBED_CLANG == "ON" ]] && with_timeout make embedded_clang "$@"
[[ $DEPS_ONLY == "ON" ]] && exit 0
make "$@"
make "$@" -j $(nproc)

if [ $RUN_TESTS = 1 ]; then
if [ "$RUN_ALL_TESTS" = "1" ]; then
Expand Down
30 changes: 30 additions & 0 deletions scripts/update_codegen_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Updates codegen tests' expected LLVM IR
#

set -eu

# Change dir to project root
cd "$(dirname "${BASH_SOURCE[0]}")"
cd ..

# Build docker image
pushd docker
docker build \
--network host \
--build-arg LLVM_VERSION=8 \
-t bpftrace-builder-bionic \
-f Dockerfile.bionic \
.
popd

# Update IR
docker run \
--network host \
--rm \
-it \
-v $(pwd):$(pwd) \
-e BPFTRACE_UPDATE_TESTS=1 \
-e TEST_ARGS="--gtest_filter=codegen.*" \
bpftrace-builder-bionic "$(pwd)/build-codegen-update" Debug "$@"
8 changes: 6 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ automatically, else it will fall back to rewriting.

#### Updating

If the test is run with `BPFTRACE_UPDATE_TESTS=1` the `test` helper will update
the IR instead of running the tests.
Run `./scripts/update_codegen_tests.sh` after making codegen changes up update
the expected LLVM IR.

Alternatively (if you need more control over which tests are updated), if the
test is run with `BPFTRACE_UPDATE_TESTS=1` the `test` helper will update the IR
instead of running the tests.

## Runtime tests

Expand Down

0 comments on commit 487dd81

Please sign in to comment.