github-action/ubuntu: handle coredump from unit test
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 28 Feb 2024 06:32:10 +0000 (15:32 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Thu, 4 Jul 2024 01:21:58 +0000 (10:21 +0900)
If unit test generates core dump,
show the backtrace in the build log and
upload the coredump file.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
.github/workflows/ubuntu_clean_meson_build.yml

index 3127d70..3628796 100644 (file)
@@ -27,7 +27,7 @@ jobs:
     - name: install requirements
       if: env.rebuild == '1'
       run: |
-        sudo apt-get update && sudo apt-get install -y libglib2.0-dev libjson-glib-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev googletest
+        sudo apt-get update && sudo apt-get install -y libglib2.0-dev libjson-glib-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev googletest gdb
         sudo apt-get install -y liborc-0.4-dev flex bison libopencv-dev pkg-config python3-dev python3-numpy python3
         sudo add-apt-repository -y ppa:nnstreamer/ppa && sudo apt-get update && sudo apt-get install -y ssat libpaho-mqtt-dev
         sudo apt-get install -y valgrind gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-base libgtest-dev libpng-dev libc6-dbg binutils-x86-64-linux-gnu-dbg valgrind-dbg
@@ -37,9 +37,30 @@ jobs:
       run: |
         meson setup build/
         meson compile -C build/
+
+        sudo mkdir -m 777 /cores
+        sudo bash -c 'echo "/cores/coredump" > /proc/sys/kernel/core_pattern'
+
+        ulimit -c unlimited
+
         meson test -C build/ -v
       env:
         CC: gcc
+    - name: Upload core if something went wrong
+      uses: actions/upload-artifact@v3
+      if: ${{ failure() }}
+      with:
+        name: cores
+        path: /cores
+    - name: Try to show a stack trace if something went wrong
+      if: ${{ failure() }}
+      run: |
+        if [[ -f /cores/coredump ]]; then
+          ERROREXEC=`gdb -c /cores/coredump -batch -ex bt | grep "Core was generated by " | sed "s|Core was generated by \`||" | sed "s|'.||"`
+          echo "::group::There is a core dump file. The backtrace shows:"
+          gdb ${ERROREXEC} -c coredump -batch -ex bt
+          echo "::endgroup::"
+        fi
     - uses: actions/upload-artifact@v1
       if: failure()
       with: