From c86a8706943d27df0ed72ee9cb195d5b56df9d98 Mon Sep 17 00:00:00 2001
From: Yuxuan Shui <yshuiv7@gmail.com>
Date: Thu, 1 Aug 2024 13:59:22 +0100
Subject: [PATCH] ci: store coredumps and binaries when tests fail

It's not easy as it looks. I might need to write up on how this tool
works.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
---
 .circleci/config.yml | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 949ed97a..2b58d99e 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -50,17 +50,21 @@ jobs:
       - attach_workspace:
           at: /tmp/workspace
       - run:
-          name: unit test
-          command: ninja -vC build test
-      - run:
-          name: test config file parsing
-          command: xvfb-run -s "-screen 0 640x480x24" build/src/picom --config tests/configs/parsing_test.conf --no-vsync --diagnostics
-      - run:
-          name: test config file parsing in a different locale
-          command: LC_NUMERIC=de_DE.UTF-8 xvfb-run -s "-screen 0 640x480x24" build/src/picom --config tests/configs/parsing_test.conf --no-vsync --diagnostics
-      - run:
-          name: run testsuite
-          command: tests/run_tests.sh build/src/picom
+          name: Tests
+          command: |
+            ulimit -c unlimited
+
+            printf "\n::: Unit tests :::\n"
+            ninja -vC build test
+
+            printf "\n::: test config file parsing :::\n"
+            xvfb-run -a -s "-screen 0 640x480x24" build/src/picom --config tests/configs/parsing_test.conf --no-vsync --diagnostics
+
+            printf "\n::: test config file parsing in a different locale :::\n"
+            LC_NUMERIC=de_DE.UTF-8 xvfb-run -a -s "-screen 0 640x480x24" build/src/picom --config tests/configs/parsing_test.conf --no-vsync --diagnostics
+
+            printf "\n::: run testsuite :::\n"
+            tests/run_tests.sh build/src/picom
       - run:
           name: generate coverage reports
           command: cd build; find -name '*.gcno' -exec gcov -pb {} +
@@ -70,6 +74,18 @@ jobs:
       - run:
           name: upload coverage reports
           command: bash ./codecov.sh -X gcov
+      - run:
+          name: collect coredumps
+          when: on_fail
+          command: |
+            . $HOME/.cargo/env
+            mkdir /tmp/artifacts
+            for c in tests/core.*; do
+              coredump-copy $c /tmp/coredumps/`basename $c`
+            done
+            tar zcf /tmp/artifacts/coredumps.tar.xz /tmp/coredumps
+      - store_artifacts:
+          path: /tmp/artifacts
 
   minimal:
     executor: e