From 8efa1123601025c75e793eb710464a6eb10fd336 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Thu, 26 Sep 2024 17:05:15 -0700 Subject: [PATCH] Add ASAN/UBSAN recipe to just, make a CI that runs it + adding GDB (#1474) * Add ASAN/UBSAN recipe to just, make a CI that runs it * Add GDB options to justfile Module operandi I propose: we dont save the log for now, we dont run the leak sanitizer part, then we run this every time a new PR comes in, and if any of those introduce a problem, this test will fail. It will not show what the issue is (given the ASAN output saving problem), but it will show that there is an issue, so we can check out the branch locally and run this and we'll see the problem. --- .github/workflows/asan_ubsan_build.yml | 49 ++++++++++++++++++++++++++ justfile | 27 +++++++++++--- 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/asan_ubsan_build.yml diff --git a/.github/workflows/asan_ubsan_build.yml b/.github/workflows/asan_ubsan_build.yml new file mode 100644 index 000000000..f1206aea4 --- /dev/null +++ b/.github/workflows/asan_ubsan_build.yml @@ -0,0 +1,49 @@ + +name: Build with ASAN and UBSAN + +on: + workflow_dispatch: + pull_request: + branches: [trunk] + types: [opened, ready_for_review] + +env: + LDMX_DOCKER_TAG: ldmx/dev:latest + +jobs: + build-with-asan-ubsan: + runs-on: ubuntu-latest + steps: + - name: Checkout ldmx-sw + uses: actions/checkout@v4 + with: + submodules: 'recursive' + fetch-depth: 0 + + - name: Install just + uses: extractions/setup-just@v2 + with: + just-version: 1.26.0 + + - name: Compile and Install ldmx-sw + run: | + just install-denv init configure-asan-ubsan + just build + shell: bash + + - name: Run ecal_pn config + #continue-on-error: true + run: | + just setenv LDMX_NUM_EVENTS=15 + just setenv LDMX_RUN_NUMBER=7500 + #just setenv ASAN_OPTIONS=log_path=output.log + just setenv ASAN_OPTIONS=detect_leaks=0 + just fire ${GITHUB_WORKSPACE}/.github/validation_samples/ecal_pn/config.py + shell: bash + + # For the future, we could try to save the output of ASAN/UBSAN + # - name: Upload log artifact + # uses: actions/upload-artifact@v4 + # with: + # name: ASAN_UBSAN_output + # path: output.log* diff --git a/justfile b/justfile index e054c9562..305d4b760 100644 --- a/justfile +++ b/justfile @@ -59,16 +59,28 @@ install-denv: # configure how ldmx-sw will be built # added ADDITIONAL_WARNINGS and CLANG_TIDY to help improve code quality -configure *CONFIG: - denv cmake -B build -S . -DADDITIONAL_WARNINGS=ON -DENABLE_CLANG_TIDY=ON {{ CONFIG }} +# base configure command defining how cmake is called, private so only experts call it +[private] +configure-base *CONFIG: + denv cmake -B build -S . {{ CONFIG }} + +# default configure of build when developing +configure *CONFIG: (configure-base "-DADDITIONAL_WARNINGS=ON -DENABLE_CLANG_TIDY=ON" CONFIG) + +# configure minimal option for faster compilation +configure-quick: (configure-base) + +# configure with Address Sanitizer (ASAN) and UndefinedBehaviorSanitizer (UBSan) +configure-asan-ubsan: (configure-base "-DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON -DENABLE_SANITIZER_ADDRESS=ON") # This is the same as just configure but reports all (non-3rd-party) warnings as errors -configure-force-error *CONFIG: (configure "-DWARNINGS_AS_ERRORS=ON" CONFIG) +configure-force-error: (configure "-DWARNINGS_AS_ERRORS=ON") -# This is an alternative compiler (clang) together with enabling the LTO sanitizer -# This is very helpful but for now it optimizes away our module linking, use for testing only +# Use alternative compiler and enable LTO (test compiling only, won't run properly) configure-clang-lto: (configure "-DENABLE_LTO=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang") +# Keep debug symbols so running with gdb provides more helpful detail +configure-gdb: (configure-base "-DCMAKE_BUILD_TYPE=Debug") # compile and install ldmx-sw build ncpu=num_cpus(): denv cmake --build build --target install -- -j{{ ncpu }} @@ -82,6 +94,11 @@ test *ARGS: fire config_py *ARGS: denv fire {{ config_py }} {{ ARGS }} +# run gdb on a config file +[no-cd] +debug config_py *ARGS: + denv gdb fire {{ config_py }} {{ ARGS }} + # initialize a containerized development environment init: #!/usr/bin/env sh