From 88af3af3c9361a5265192e83f386e8c65068e6ea Mon Sep 17 00:00:00 2001 From: Whisperity Date: Sun, 28 Nov 2021 15:59:18 +0100 Subject: [PATCH] nit: Make the CTU test have a valid finding with defualt configuration --- .github/workflows/test.yml | 3 +++ README.md | 13 +++++++------ action.yml | 3 +++ src/execute-analysis.sh | 3 +-- src/parse-results.sh | 8 ++++++-- test/ctu/lib.cpp | 5 +++-- test/ctu/main.cpp | 5 +++-- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 11f5139..06f393e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -82,9 +82,12 @@ jobs: - uses: actions/checkout@v2 - run: test/fix_compile_json_paths.sh - uses: ./ + id: codechecker with: logfile: 'test/ctu/compile_commands.json' ctu: true + - name: "Reject test if previous step did not produce CTU finding" + run: cat ${{ steps.codechecker.outputs.result-log }} | grep "Dereference of null pointer" fail-on-error: name: "Parse: Fail the build on error" diff --git a/README.md b/README.md index 2717a27..628b86d 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,10 @@ runs: The action exposes the following outputs which may be used in a workflow's steps succeeding the analysis. -| Variable | Value | Description | -|-------------------|-------------------------------------------|-------------------------------------------------------------------------------| -| `analyze-output` | Auto-generated, or `analyze-output` input | The directory where the **raw** analysis output files are available. | -| `logfile` | Auto-generated, or `logfile` input | The JSON Compilation Database of the analysis that was executed. | -| `result-html-dir` | Auto-generated. | The directory where the **user-friendly HTML** bug reports were generated to. | -| `warnings` | `true` or `false` | Whether the static analysers reported any findings. | +| Variable | Value | Description | +|-------------------|-------------------------------------------|-----------------------------------------------------------------------------------| +| `analyze-output` | Auto-generated, or `analyze-output` input | The directory where the **raw** analysis output files are available. | +| `logfile` | Auto-generated, or `logfile` input | The JSON Compilation Database of the analysis that was executed. | +| `result-html-dir` | Auto-generated. | The directory where the **user-friendly HTML** bug reports were generated to. | +| `result-log` | Auto-generated. | `CodeChecker parse`'s output log file which contains the findings dumped into it. | +| `warnings` | `true` or `false` | Whether the static analysers reported any findings. | diff --git a/action.yml b/action.yml index 3711ae6..bc3838b 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,9 @@ outputs: warnings: description: 'Whether the static analyser(s) reported any findings.' value: ${{ steps.parse.outputs.HAS_FINDINGS }} + result-log: + description: 'The file where the output of CodeChecker parse is written to verbatim.' + value: ${{ steps.parse.outputs.OUTPUT_LOG }} result-html-dir: description: 'The output directory where the user-friendly HTML reports were stored to.' value: ${{ steps.parse.outputs.HTML_DIR }} diff --git a/src/execute-analysis.sh b/src/execute-analysis.sh index bbd02aa..e48a7dc 100755 --- a/src/execute-analysis.sh +++ b/src/execute-analysis.sh @@ -19,9 +19,8 @@ if [[ ! -z "$IN_CONFIGFILE" ]]; then echo "Using configuration file \"$IN_CONFIGFILE\"!" fi -CTU_FLAG=$([[ "$IN_CTU" == "true" ]] && echo "--ctu --ctu-ast-mode load-from-pch" || echo "") if [[ "$IN_CTU" == "true" ]]; then - CTU_FLAG="--ctu --ctu-ast-mode load-from-pch" + CTU_FLAGS="--ctu --ctu-ast-mode load-from-pch" echo "::notice title=Cross Translation Unit analyis::CTU has been enabled, the analysis might take a long time!" fi diff --git a/src/parse-results.sh b/src/parse-results.sh index c5338ee..940354c 100755 --- a/src/parse-results.sh +++ b/src/parse-results.sh @@ -15,9 +15,10 @@ OUTPUT_DIR="$IN_OUTPUT_DIR" if [[ -z "$OUTPUT_DIR" ]]; then OUTPUT_DIR=~/"$ACTION_NAME"_Results-HTML fi - mkdir -pv "$(dirname $"OUTPUT_DIR")" +OUTPUT_LOG="$(dirname "$IN_OUTPUT_DIR")"/"$(basename "$IN_OUTPUT_DIR")_Parse.log" + if [[ ! -z "$IN_CONFIGFILE" ]]; then CONFIG_FLAG_1="--config" CONFIG_FLAG_2=$IN_CONFIGFILE @@ -34,8 +35,11 @@ echo "::set-output name=HTML_DIR::$OUTPUT_DIR" "$CODECHECKER_PATH"/CodeChecker parse \ "$RAW_RESULT_DIR" \ - --trim-path-prefix "$PROJECT_PATH" + --trim-path-prefix "$PROJECT_PATH" \ + > "$OUTPUT_LOG" EXIT_CODE=$? +echo "::set-output name=OUTPUT_LOG::$OUTPUT_LOG" + if [[ "$EXIT_CODE" == "2" ]]; then echo "::set-output name=HAS_FINDINGS::true" diff --git a/test/ctu/lib.cpp b/test/ctu/lib.cpp index 0dea71a..9b2f28f 100644 --- a/test/ctu/lib.cpp +++ b/test/ctu/lib.cpp @@ -1,3 +1,4 @@ -int zero() { - return 0; +int broken(int* iptr) { + *iptr = 42; + return *iptr; } diff --git a/test/ctu/main.cpp b/test/ctu/main.cpp index 442d4db..a1eaf57 100644 --- a/test/ctu/main.cpp +++ b/test/ctu/main.cpp @@ -1,5 +1,6 @@ -int zero(); +int broken(int* iptr); int main(int argc, char** argv) { - return argc / zero(); + int* ptr = nullptr; + return broken(ptr); }