infra bot: Add Memcheck bot (valgrind)
authorJunsuChoi <jsuya.choi@samsung.com>
Fri, 12 Nov 2021 06:03:52 +0000 (15:03 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Wed, 17 Nov 2021 04:16:32 +0000 (13:16 +0900)
If the unit test is successful, valgrind memory check is executed based on the test.
If a leak occurs in the test result, the bot notifies the PR as a comment.
This notify may not be directly related to the created current PR.

(Asan is on hold because it is not well tested in the github action CI environment.)

.github/workflows/actions.yml
.github/workflows/memcheck_valgrind.sh [new file with mode: 0755]

index 69c5bee3999571e49c9f9c9204dcdbb4c51598ac..d09b12fb29bd2511f429288832ef76b7d659e684 100644 (file)
@@ -62,7 +62,9 @@ jobs:
     - name: Install Packages
       run: |
         sudo apt-get update
-        sudo apt-get install ninja-build gcc-multilib g++-multilib libgtest-dev meson cmake cmake-data
+        sudo apt-get install ninja-build gcc-multilib g++-multilib libgtest-dev meson cmake cmake-data libasan5 valgrind
+        sudo apt-get install curl jq
+        sudo apt-get install software-properties-common
 
     - name: Install TurboJPEG library
       run: sudo apt-get install libturbojpeg0-dev libjpeg8-dev
@@ -85,3 +87,12 @@ jobs:
       with:
         name: UnitTestReport
         path: build/meson-logs/testlog.txt
+
+    - name: Run memcheck Script(valgrind)
+      run: |
+        export PATH=$PATH:~/.local/bin/
+        chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh"
+        "${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh"
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
diff --git a/.github/workflows/memcheck_valgrind.sh b/.github/workflows/memcheck_valgrind.sh
new file mode 100755 (executable)
index 0000000..3dd59c8
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+echo "Run Valgrind"
+echo "valgrind --leak-check=yes ./tvgUnitTests"
+cd ./build/test
+
+valgrind --leak-check=yes ./tvgUnitTests > memcheck_valgrind.txt 2>&1
+
+
+PAYLOAD_MEMCHECK=`cat memcheck_valgrind.txt`
+COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
+
+echo $COMMENTS_URL
+echo "MEMCHECK errors:"
+echo $PAYLOAD_MEMCHECK
+
+if [[ $PAYLOAD_MEMCHECK == *"definitely lost:"* || $PAYLOAD_MEMCHECK == *"Invalid read "* || $PAYLOAD_MEMCHECK == *"Invalid write "* ]]; then
+  OUTPUT+=$'\n**MEMCHECK(VALGRIND) RESULT**:\n'
+  OUTPUT+=$'\n`valgrind --leak-check=yes ./tvgUnitTests`\n'
+  OUTPUT+=$'\n```\n'
+  OUTPUT+="$PAYLOAD_MEMCHECK"
+  OUTPUT+=$'\n```\n' 
+fi
+
+PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body')
+
+curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL"