From 067b37d6e254513e4fe18c1413769aca0e3565d6 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 19 Nov 2021 11:24:44 -0800 Subject: [PATCH 01/18] Check delta valgrind between builds. 1. Suppress false positives / noise 2. Remove memory address 3. Remove noise at beginning of each line 4. Display only what is added to the child valgrind report --- .github/workflows/valgrind.yml | 81 +++++++++++++++++++++++++++++++ scripts/delta_valgrind.sh | 26 ++++++++++ scripts/valgrind_suppression.supp | 28 +++++++++++ 3 files changed, 135 insertions(+) create mode 100755 .github/workflows/valgrind.yml create mode 100755 scripts/delta_valgrind.sh create mode 100755 scripts/valgrind_suppression.supp diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml new file mode 100755 index 00000000..9b4cb279 --- /dev/null +++ b/.github/workflows/valgrind.yml @@ -0,0 +1,81 @@ +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause + +# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions + +name: delta coverage checks + +permissions: + # Grant read permissions to repository in case it is not a forked public + # repository, but a private repository that was created manually. + contents: read + + # Grant read permissions to private container images. + packages: read + +on: + pull_request: + paths: + - '**' + - '!**.md' + - '!**/.clang-format' + - '!**/COPYING' + - '!**/LICENSE' + - '!.github/**' + - '.github/workflows/valgrind.yml' + - '!.gitignore' + - '!cmake/manifests/**' + - 'cmake/manifests/linux/**' + - '!container/**' + - '!docs/**' + - '!scripts/**' + +jobs: + build: + runs-on: ubuntu-20.04 + + container: + image: ghcr.io/intel/fpga-runtime-for-opencl/ubuntu-20.04-dev:main + + env: + TMP_DIR: /home/build/ + + steps: + - name: change ownership of workspace to current user + run: sudo chown -R build:build . + + - name: checkout main branch + uses: actions/checkout@v2 + with: + ref: ${{ github.base_ref }} + + - name: create build directories + run: mkdir "$TMP_DIR/child_build" "$TMP_DIR/parent_build" + + - name: create parent build files + run: cd "$TMP_DIR/parent_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug + + - name: build parent runtime + run: cd "$TMP_DIR/parent_build" && ninja -v -k0 + + - name: parent runtime valgrind scan + run: cd "$TMP_DIR/parent_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$GITHUB_WORKSPACE/scripts/valgrind_suppression.supp" -T memcheck + + - name: checkout current branch + uses: actions/checkout@v2 + + - name: create child build files + run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug + + - name: build child runtime + run: cd "$TMP_DIR/child_build" && ninja -v -k0 + + - name: child runtime valgrind scan + run: cd "$TMP_DIR/child_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$GITHUB_WORKSPACE/scripts/valgrind_suppression.supp" -T memcheck + + - name: valgrind incremental + run: ./delta_valgrind.sh "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" + + - name: revert ownership of workspace to root + run: sudo chown -R root:root . + if: always() \ No newline at end of file diff --git a/scripts/delta_valgrind.sh b/scripts/delta_valgrind.sh new file mode 100755 index 00000000..6919d125 --- /dev/null +++ b/scripts/delta_valgrind.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause + +# Install Intel FPGA SDK for OpenCL Pro Edition +# https://fpgasoftware.intel.com/ + +set -eu -o pipefail + +parent_valgrind_report="$1" +child_valgrind_report="$1" + +# remove ==29048== patern from beginning +sed -i -E "s/==.*== //" ${parent_valgrind_report} +sed -i -E "s/==.*== //" ${child_valgrind_report} +# remove memory address +sed -i -E "s/0x.*: //" ${parent_valgrind_report} +sed -i -E "s/0x.*: //" ${child_valgrind_report} +# remove file header +sed -i -e '1,/Parent PID/ d' ${parent_valgrind_report} +sed -i -e '1,/Parent PID/ d' ${child_valgrind_report} +# remove file ending +sed -i -e '/LEAK SUMMARY/Q' ${parent_valgrind_report} +sed -i -e '/LEAK SUMMARY/Q' ${child_valgrind_report} +# check what is added to second file +comm -13 ${parent_valgrind_report} ${child_valgrind_report} diff --git a/scripts/valgrind_suppression.supp b/scripts/valgrind_suppression.supp new file mode 100755 index 00000000..c8234f2e --- /dev/null +++ b/scripts/valgrind_suppression.supp @@ -0,0 +1,28 @@ +{ + getenv-Cond + Memcheck:Cond + ... + fun:getenv + ... +} +{ + getenv-Addr2 + Memcheck:Addr2 + ... + fun:getenv + ... +} +{ + setenv + Memcheck:Cond + ... + fun:setenv + ... +} +{ + unsetenv + Memcheck:Cond + ... + fun:unsetenv + ... +} From 4aa654241b4a49692f9bf00d798fe7522f4a50dd Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 19 Nov 2021 12:04:17 -0800 Subject: [PATCH 02/18] remove source file line number from report for better comparison --- .github/workflows/valgrind.yml | 8 +++++++- scripts/delta_valgrind.sh | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 9b4cb279..3ff43615 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -3,7 +3,7 @@ # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions -name: delta coverage checks +name: valgrind incremental checks permissions: # Grant read permissions to repository in case it is not a forked public @@ -73,6 +73,12 @@ jobs: - name: child runtime valgrind scan run: cd "$TMP_DIR/child_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$GITHUB_WORKSPACE/scripts/valgrind_suppression.supp" -T memcheck + - name: upload valgrind report as manifest + uses: actions/upload-artifact@v2 + with: + name: valgrind-${{ github.run_id }} + path: "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" + - name: valgrind incremental run: ./delta_valgrind.sh "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" diff --git a/scripts/delta_valgrind.sh b/scripts/delta_valgrind.sh index 6919d125..27fece8c 100755 --- a/scripts/delta_valgrind.sh +++ b/scripts/delta_valgrind.sh @@ -19,6 +19,9 @@ sed -i -E "s/0x.*: //" ${child_valgrind_report} # remove file header sed -i -e '1,/Parent PID/ d' ${parent_valgrind_report} sed -i -e '1,/Parent PID/ d' ${child_valgrind_report} +# remove source code line number +sed -i -E "s/\(([^)]*)\)[^(]*$//" ${parent_valgrind_report} +sed -i -E "s/\(([^)]*)\)[^(]*$//" ${child_valgrind_report} # remove file ending sed -i -e '/LEAK SUMMARY/Q' ${parent_valgrind_report} sed -i -e '/LEAK SUMMARY/Q' ${child_valgrind_report} From 98f189e47e715179a9da649af06eac0ccca123db Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 19 Nov 2021 12:29:40 -0800 Subject: [PATCH 03/18] apt install valgrind package --- .github/workflows/valgrind.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 3ff43615..4ae9b766 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -43,7 +43,10 @@ jobs: steps: - name: change ownership of workspace to current user run: sudo chown -R build:build . - + + - name: install valgrind + run: sudo apt-get install -y valgrind + - name: checkout main branch uses: actions/checkout@v2 with: From 1d50c396d86b6fc32ab57b7c805f05f82d26643f Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 19 Nov 2021 13:03:06 -0800 Subject: [PATCH 04/18] copy suppression file from current branch to main branch prior to merge, need to remove after merge --- .github/workflows/valgrind.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 4ae9b766..2f67dcaf 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -47,10 +47,21 @@ jobs: - name: install valgrind run: sudo apt-get install -y valgrind + - name: checkout current branch + uses: actions/checkout@v2 + + # Remove after merged into main + - name: copy suppression file to tmp + run: cp scripts/valgrind_suppression.supp $TMP_DIR/valgrind_suppression.supp + - name: checkout main branch uses: actions/checkout@v2 with: ref: ${{ github.base_ref }} + + # Remove after merged into main + - name: copy suppression file to scripts + run: cp $TMP_DIR/valgrind_suppression.supp scripts/valgrind_suppression.supp - name: create build directories run: mkdir "$TMP_DIR/child_build" "$TMP_DIR/parent_build" From b948b717da5c652713614541138010a584958aed Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 09:15:18 -0800 Subject: [PATCH 05/18] execute script in correct path --- .github/workflows/valgrind.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 2f67dcaf..a55e9178 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -94,7 +94,7 @@ jobs: path: "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" - name: valgrind incremental - run: ./delta_valgrind.sh "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" + run: ./scripts/delta_valgrind.sh "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" - name: revert ownership of workspace to root run: sudo chown -R root:root . From 66f914eaea1e93c269652011f296ebf769834559 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 09:31:08 -0800 Subject: [PATCH 06/18] list files --- .github/workflows/valgrind.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index a55e9178..bfd5db9b 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -87,6 +87,9 @@ jobs: - name: child runtime valgrind scan run: cd "$TMP_DIR/child_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$GITHUB_WORKSPACE/scripts/valgrind_suppression.supp" -T memcheck + - name: list files + run: ls "$TMP_DIR/child_build/Testing/Temporary" + - name: upload valgrind report as manifest uses: actions/upload-artifact@v2 with: From 9483ba09d0e65e26a6d28daa1b090f891c34332c Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 09:54:45 -0800 Subject: [PATCH 07/18] add intentional leak --- .github/workflows/valgrind.yml | 2 +- scripts/delta_valgrind.sh | 8 +++++++- src/acl_context.cpp | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index bfd5db9b..45da9485 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -94,7 +94,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: valgrind-${{ github.run_id }} - path: "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" + path: /home/build/child_build/Testing/Temporary/MemoryChecker.6.log - name: valgrind incremental run: ./scripts/delta_valgrind.sh "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" diff --git a/scripts/delta_valgrind.sh b/scripts/delta_valgrind.sh index 27fece8c..f13155a9 100755 --- a/scripts/delta_valgrind.sh +++ b/scripts/delta_valgrind.sh @@ -8,22 +8,28 @@ set -eu -o pipefail parent_valgrind_report="$1" -child_valgrind_report="$1" +child_valgrind_report="$2" # remove ==29048== patern from beginning +echo 'Removing line prefix' sed -i -E "s/==.*== //" ${parent_valgrind_report} sed -i -E "s/==.*== //" ${child_valgrind_report} # remove memory address +echo 'Removing memory address' sed -i -E "s/0x.*: //" ${parent_valgrind_report} sed -i -E "s/0x.*: //" ${child_valgrind_report} # remove file header +echo 'Removing file header' sed -i -e '1,/Parent PID/ d' ${parent_valgrind_report} sed -i -e '1,/Parent PID/ d' ${child_valgrind_report} # remove source code line number +echo 'Removing source code line number' sed -i -E "s/\(([^)]*)\)[^(]*$//" ${parent_valgrind_report} sed -i -E "s/\(([^)]*)\)[^(]*$//" ${child_valgrind_report} # remove file ending +echo 'Removing file ending' sed -i -e '/LEAK SUMMARY/Q' ${parent_valgrind_report} sed -i -e '/LEAK SUMMARY/Q' ${child_valgrind_report} # check what is added to second file +echo 'Delta check' comm -13 ${parent_valgrind_report} ${child_valgrind_report} diff --git a/src/acl_context.cpp b/src/acl_context.cpp index a753065f..ec2a18af 100644 --- a/src/acl_context.cpp +++ b/src/acl_context.cpp @@ -289,7 +289,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseContextIntelFPGA(cl_context context) { // release them until our own reference count is 0. if (acl_ref_count(context) > context->num_automatic_references) { - acl_release(context); + // acl_release(context); } else { // num_automatic_references is the ref count the context had when it was // given to the user. So, if we have a ref count equal to that, the user @@ -302,7 +302,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseContextIntelFPGA(cl_context context) { // they're gonna call clReleaseContext themselves. This stops us from // recursively trying to delete them again. if (context->is_being_freed) { - acl_release(context); + // acl_release(context); UNLOCK_RETURN(CL_SUCCESS); } context->is_being_freed = 1; From 1fdca17c3ee0f9cbb7a1c07def4af1edca3bd0bf Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 10:05:40 -0800 Subject: [PATCH 08/18] add intentional leak --- src/acl_context.cpp | 4 ++-- src/acl_mem.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/acl_context.cpp b/src/acl_context.cpp index ec2a18af..a753065f 100644 --- a/src/acl_context.cpp +++ b/src/acl_context.cpp @@ -289,7 +289,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseContextIntelFPGA(cl_context context) { // release them until our own reference count is 0. if (acl_ref_count(context) > context->num_automatic_references) { - // acl_release(context); + acl_release(context); } else { // num_automatic_references is the ref count the context had when it was // given to the user. So, if we have a ref count equal to that, the user @@ -302,7 +302,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseContextIntelFPGA(cl_context context) { // they're gonna call clReleaseContext themselves. This stops us from // recursively trying to delete them again. if (context->is_being_freed) { - // acl_release(context); + acl_release(context); UNLOCK_RETURN(CL_SUCCESS); } context->is_being_freed = 1; diff --git a/src/acl_mem.cpp b/src/acl_mem.cpp index a4213ef9..914c2845 100644 --- a/src/acl_mem.cpp +++ b/src/acl_mem.cpp @@ -228,7 +228,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseMemObjectIntelFPGA(cl_mem mem) { } } acl_mutex_destroy(&(mem->host_pipe_info->m_lock)); - acl_delete(mem->host_pipe_info); + // acl_delete(mem->host_pipe_info); context->pipe_vec.erase(std::remove(context->pipe_vec.begin(), context->pipe_vec.end(), mem)); } From 59b8e7cea81ae5e3923dcee4bfbd973c247fdeb8 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 11:16:23 -0800 Subject: [PATCH 09/18] suppress all parent valgrind logs --- .github/workflows/valgrind.yml | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 45da9485..d71f5caa 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -50,18 +50,10 @@ jobs: - name: checkout current branch uses: actions/checkout@v2 - # Remove after merged into main - - name: copy suppression file to tmp - run: cp scripts/valgrind_suppression.supp $TMP_DIR/valgrind_suppression.supp - - name: checkout main branch uses: actions/checkout@v2 with: ref: ${{ github.base_ref }} - - # Remove after merged into main - - name: copy suppression file to scripts - run: cp $TMP_DIR/valgrind_suppression.supp scripts/valgrind_suppression.supp - name: create build directories run: mkdir "$TMP_DIR/child_build" "$TMP_DIR/parent_build" @@ -73,11 +65,14 @@ jobs: run: cd "$TMP_DIR/parent_build" && ninja -v -k0 - name: parent runtime valgrind scan - run: cd "$TMP_DIR/parent_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$GITHUB_WORKSPACE/scripts/valgrind_suppression.supp" -T memcheck + run: cd "$TMP_DIR/parent_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all" -T memcheck - name: checkout current branch uses: actions/checkout@v2 + - name: get parent valgrind suppression file + run: cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" + - name: create child build files run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug @@ -85,10 +80,7 @@ jobs: run: cd "$TMP_DIR/child_build" && ninja -v -k0 - name: child runtime valgrind scan - run: cd "$TMP_DIR/child_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$GITHUB_WORKSPACE/scripts/valgrind_suppression.supp" -T memcheck - - - name: list files - run: ls "$TMP_DIR/child_build/Testing/Temporary" + run: cd "$TMP_DIR/child_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$TMP_DIR/valgrind_suppression.supp" -T memcheck - name: upload valgrind report as manifest uses: actions/upload-artifact@v2 @@ -97,7 +89,13 @@ jobs: path: /home/build/child_build/Testing/Temporary/MemoryChecker.6.log - name: valgrind incremental - run: ./scripts/delta_valgrind.sh "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" + run: | + if [ -s "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" ]; then + # The valgrind log after suppressing all parent log is not empty + cat "$TMP_DIR/child_build/Testing/Temporary/MemoryChecker.6.log" + exit 1 + fi + - name: revert ownership of workspace to root run: sudo chown -R root:root . From 3ebb20009c194a9251a1330f057a7089915aba5f Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 11:18:26 -0800 Subject: [PATCH 10/18] remove intentional mem leak --- src/acl_mem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acl_mem.cpp b/src/acl_mem.cpp index 914c2845..a4213ef9 100644 --- a/src/acl_mem.cpp +++ b/src/acl_mem.cpp @@ -228,7 +228,7 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseMemObjectIntelFPGA(cl_mem mem) { } } acl_mutex_destroy(&(mem->host_pipe_info->m_lock)); - // acl_delete(mem->host_pipe_info); + acl_delete(mem->host_pipe_info); context->pipe_vec.erase(std::remove(context->pipe_vec.begin(), context->pipe_vec.end(), mem)); } From 1856bcaf0c28f1d992c88b90c9501989186d22d3 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 11:32:39 -0800 Subject: [PATCH 11/18] add suppression generation script --- scripts/parse_valgrind_suppressions.sh | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 scripts/parse_valgrind_suppressions.sh diff --git a/scripts/parse_valgrind_suppressions.sh b/scripts/parse_valgrind_suppressions.sh new file mode 100755 index 00000000..72552b5c --- /dev/null +++ b/scripts/parse_valgrind_suppressions.sh @@ -0,0 +1,57 @@ +#! /usr/bin/awk -f +# A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal +# The desired bits are between ^{ and ^} (including the braces themselves). +# The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own +# If the latter, either tell valgrind about it each time with --suppressions=, or add that line to ~/.valgrindrc + +# NB This script uses the |& operator, which I believe is gawk-specific. In case of failure, check that you're using gawk rather than some other awk + +# The script looks for suppressions. When it finds one it stores it temporarily in an array, +# and also feeds it line by line to the external app 'md5sum' which generates a unique checksum for it. +# The checksum is used as an index in a different array. If an item with that index already exists the suppression must be a duplicate and is discarded. + +BEGIN { suppression=0; md5sum = "md5sum" } + # If the line begins with '{', it's the start of a supression; so set the var and initialise things + /^{/ { + suppression=1; i=0; next + } + # If the line begins with '}' its the end of a suppression + /^}/ { + if (suppression) + { suppression=0; + close(md5sum, "to") # We've finished sending data to md5sum, so close that part of the pipe + ProcessInput() # Do the slightly-complicated stuff in functions + delete supparray # We don't want subsequent suppressions to append to it! + } + } + # Otherwise, it's a normal line. If we're inside a supression, store it, and pipe it to md5sum. Otherwise it's cruft, so ignore it + { if (suppression) + { + supparray[++i] = $0 + print |& md5sum + } + } + + + function ProcessInput() + { + # Pipe the result from md5sum, then close it + md5sum |& getline result + close(md5sum) + # gawk can't cope with enormous ints like $result would be, so stringify it first by prefixing a definite string + resultstring = "prefix"result + + if (! (resultstring in chksum_array) ) + { chksum_array[resultstring] = 0; # This checksum hasn't been seen before, so add it to the array + OutputSuppression() # and output the contents of the suppression + } + } + + function OutputSuppression() + { + # A suppression is surrounded by '{' and '}'. Its data was stored line by line in the array + print "{" + for (n=1; n <= i; ++n) + { print supparray[n] } + print "}" + } \ No newline at end of file From b62acdaefa3d30c2bb938fa8a2ca497ae5c91ae1 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 11:54:59 -0800 Subject: [PATCH 12/18] use gawk instead --- .github/workflows/valgrind.yml | 3 ++- scripts/parse_valgrind_suppressions.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index d71f5caa..89e8b866 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -71,7 +71,8 @@ jobs: uses: actions/checkout@v2 - name: get parent valgrind suppression file - run: cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" + run: | + cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" - name: create child build files run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug diff --git a/scripts/parse_valgrind_suppressions.sh b/scripts/parse_valgrind_suppressions.sh index 72552b5c..6364ff36 100755 --- a/scripts/parse_valgrind_suppressions.sh +++ b/scripts/parse_valgrind_suppressions.sh @@ -1,4 +1,4 @@ -#! /usr/bin/awk -f +#! /usr/bin/gawk -f # A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal # The desired bits are between ^{ and ^} (including the braces themselves). # The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own From 74ff435287faf0db292fd7e86299588277df8257 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 12:08:50 -0800 Subject: [PATCH 13/18] explicit gawk invocation --- .github/workflows/valgrind.yml | 2 +- scripts/parse_valgrind_suppressions.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 89e8b866..621be926 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -72,7 +72,7 @@ jobs: - name: get parent valgrind suppression file run: | - cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" + cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | gawk ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" - name: create child build files run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug diff --git a/scripts/parse_valgrind_suppressions.sh b/scripts/parse_valgrind_suppressions.sh index 6364ff36..72552b5c 100755 --- a/scripts/parse_valgrind_suppressions.sh +++ b/scripts/parse_valgrind_suppressions.sh @@ -1,4 +1,4 @@ -#! /usr/bin/gawk -f +#! /usr/bin/awk -f # A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal # The desired bits are between ^{ and ^} (including the braces themselves). # The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own From 253c258daa38e0442772f9188dacbda7af2db28c Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 12:42:45 -0800 Subject: [PATCH 14/18] install gawk --- .github/workflows/valgrind.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 621be926..298dcb63 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -45,7 +45,7 @@ jobs: run: sudo chown -R build:build . - name: install valgrind - run: sudo apt-get install -y valgrind + run: sudo apt-get install -y valgrind gawk - name: checkout current branch uses: actions/checkout@v2 From f3a0634908b02b18c94b5840305990a623f265b9 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 26 Nov 2021 12:52:38 -0800 Subject: [PATCH 15/18] use shebang for gawk --- .github/workflows/valgrind.yml | 2 +- scripts/parse_valgrind_suppressions.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 298dcb63..57975d93 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -72,7 +72,7 @@ jobs: - name: get parent valgrind suppression file run: | - cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | gawk ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" + cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" - name: create child build files run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug diff --git a/scripts/parse_valgrind_suppressions.sh b/scripts/parse_valgrind_suppressions.sh index 72552b5c..6364ff36 100755 --- a/scripts/parse_valgrind_suppressions.sh +++ b/scripts/parse_valgrind_suppressions.sh @@ -1,4 +1,4 @@ -#! /usr/bin/awk -f +#! /usr/bin/gawk -f # A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal # The desired bits are between ^{ and ^} (including the braces themselves). # The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own From 56f8558a371349a9094e3b3fb0d07944810ad9a7 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Mon, 29 Nov 2021 11:06:28 -0800 Subject: [PATCH 16/18] cat valgrind suppression file --- .github/workflows/valgrind.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 57975d93..77248f27 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -73,6 +73,10 @@ jobs: - name: get parent valgrind suppression file run: | cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" + + - name: cat valgrind suppresion file + run: | + cat "$TMP_DIR/valgrind_suppression.supp" - name: create child build files run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug From c6af5aea6d2a32d12d41aac1827f22031ed81332 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Thu, 2 Dec 2021 13:09:33 -0800 Subject: [PATCH 17/18] append necessary suppression to processed suppression --- .github/workflows/valgrind.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 77248f27..6480aa71 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -50,6 +50,9 @@ jobs: - name: checkout current branch uses: actions/checkout@v2 + - name: copy necessary suppression files + run: cp ./scripts/valgrind_suppression.supp "$TMP_DIR/valgrind_suppression_base.supp" + - name: checkout main branch uses: actions/checkout@v2 with: @@ -73,6 +76,7 @@ jobs: - name: get parent valgrind suppression file run: | cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" + cat "$TMP_DIR/valgrind_suppression_base.supp" >> "$TMP_DIR/valgrind_suppression.supp" - name: cat valgrind suppresion file run: | From fa4bf4bd9a2ab5cfd933d499728aaae8b9c5744c Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Thu, 9 Dec 2021 13:55:07 -0800 Subject: [PATCH 18/18] upload suppression and generalize getenv suppression --- .github/workflows/valgrind.yml | 16 ++++++++++++---- scripts/valgrind_suppression.supp | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 6480aa71..7e786b8c 100755 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -78,9 +78,11 @@ jobs: cat "$TMP_DIR/parent_build/Testing/Temporary/MemoryChecker.6.log" | ./scripts/parse_valgrind_suppressions.sh > "$TMP_DIR/valgrind_suppression.supp" cat "$TMP_DIR/valgrind_suppression_base.supp" >> "$TMP_DIR/valgrind_suppression.supp" - - name: cat valgrind suppresion file - run: | - cat "$TMP_DIR/valgrind_suppression.supp" + - name: upload valgrind report as manifest + uses: actions/upload-artifact@v2 + with: + name: suppression-${{ github.run_id }} + path: /home/build/valgrind_suppression.supp - name: create child build files run: cd "$TMP_DIR/child_build" && cmake -G Ninja "$GITHUB_WORKSPACE" -DCMAKE_BUILD_TYPE=Debug @@ -91,7 +93,13 @@ jobs: - name: child runtime valgrind scan run: cd "$TMP_DIR/child_build" && ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --show-reachable=yes --error-limit=no" --overwrite MemoryCheckSuppressionFile="$TMP_DIR/valgrind_suppression.supp" -T memcheck - - name: upload valgrind report as manifest + - name: upload parent valgrind report as manifest + uses: actions/upload-artifact@v2 + with: + name: parent-valgrind-${{ github.run_id }} + path: /home/build/parent_build/Testing/Temporary/MemoryChecker.6.log + + - name: upload child valgrind report as manifest uses: actions/upload-artifact@v2 with: name: valgrind-${{ github.run_id }} diff --git a/scripts/valgrind_suppression.supp b/scripts/valgrind_suppression.supp index c8234f2e..06d0d1f8 100755 --- a/scripts/valgrind_suppression.supp +++ b/scripts/valgrind_suppression.supp @@ -5,6 +5,13 @@ fun:getenv ... } +{ + getenv-Addr1 + Memcheck:Addr1 + ... + fun:getenv + ... +} { getenv-Addr2 Memcheck:Addr2 @@ -12,6 +19,27 @@ fun:getenv ... } +{ + getenv-Addr4 + Memcheck:Addr4 + ... + fun:getenv + ... +} +{ + getenv-Addr8 + Memcheck:Addr8 + ... + fun:getenv + ... +} +{ + getenv-Addr16 + Memcheck:Addr16 + ... + fun:getenv + ... +} { setenv Memcheck:Cond