From 487dd815bfe4a24908950552f35ef17d6653b2f8 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Mon, 2 Nov 2020 16:54:00 -0800 Subject: [PATCH] scripts: Add script to update codegen tests This script helps update codegen changes. Basically all it does is compile bpftrace against LLVM 8 and run bpftrace_test with the right invocation. --- docker/build.sh | 2 +- scripts/update_codegen_tests.sh | 30 ++++++++++++++++++++++++++++++ tests/README.md | 8 ++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100755 scripts/update_codegen_tests.sh diff --git a/docker/build.sh b/docker/build.sh index d3124c8ee249..c818a6f9cd33 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -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 diff --git a/scripts/update_codegen_tests.sh b/scripts/update_codegen_tests.sh new file mode 100755 index 000000000000..b0df577b5dd3 --- /dev/null +++ b/scripts/update_codegen_tests.sh @@ -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 "$@" diff --git a/tests/README.md b/tests/README.md index 4bbdd9e3533d..9b986b239afb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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