Skip to content

Commit

Permalink
[ci/BuildAndTest]: try to simplify exit code capture logic
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Kemal Gilor <[email protected]>
  • Loading branch information
xmkg committed Feb 28, 2025
1 parent 3273a11 commit 4df339e
Showing 1 changed file with 12 additions and 54 deletions.
66 changes: 12 additions & 54 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,60 +175,34 @@ jobs:
# we need to override it at the runner level.
sudo bash -c 'echo "/coredump/%e.%p.%t" > /proc/sys/kernel/core_pattern'
# - name : Mock failure
# id: mock-fail
# if: ${{ matrix.build-type == 'Debug' }} || ${{ matrix.build-type == 'Coverage' }}
# run: |

# # Perform an intentional segfault
# set +e
# set -o xtrace
# # mkdir -p /root/parts/multipass/build/bin/
# instance_name=`/snap/bin/lxc --project snapcraft --format=csv --columns=n list | grep multipass`
# /snap/bin/lxc --project snapcraft start $instance_name
# /snap/bin/lxc --project snapcraft exec $instance_name -- bash -c "echo 'int main() { *(int *)0 = 0; }' | gcc -xc -o /root/parts/multipass/build/bin/multipass_tests - && ulimit -c unlimited && /root/parts/multipass/build/bin/multipass_tests"
# # Capture the exit code.
# exit_code="$?"
# # Save the exit code to a action-level variable so we can refer to it in other steps.
# echo "MULTIPASS_TESTS_EXIT_CODE=$exit_code" >> $GITHUB_ENV
# # Re-enable exit on failure
# set -e
# # We're now done with our intermediate "SIGSEGV" special case, finalize the step with
# # the test executable's original exit code.
# set +o xtrace
# exit $exit_code
- name : Mock failure
id: mock-fail
if: ${{ matrix.build-type == 'Debug' }} || ${{ matrix.build-type == 'Coverage' }}
run: |
trap 'echo "MULTIPASS_TESTS_EXIT_CODE=$?" >> $GITHUB_ENV' EXIT
# mkdir -p /root/parts/multipass/build/bin/
instance_name=`/snap/bin/lxc --project snapcraft --format=csv --columns=n list | grep multipass`
/snap/bin/lxc --project snapcraft start $instance_name
/snap/bin/lxc --project snapcraft exec $instance_name -- bash -c "echo 'int main() { *(int *)0 = 0; }' | gcc -xc -o /root/parts/multipass/build/bin/multipass_tests - && ulimit -c unlimited && /root/parts/multipass/build/bin/multipass_tests"
- name: Test
id: test
if: ${{ matrix.build-type == 'Debug' }}
timeout-minutes: 2
run: |
trap 'echo "MULTIPASS_TESTS_EXIT_CODE=$?" >> $GITHUB_ENV' EXIT
instance_name=`/snap/bin/lxc --project snapcraft --format=csv --columns=n list | grep multipass`
/snap/bin/lxc --project snapcraft start $instance_name
# Let's print the core pattern so we can check if it's successfully propagated to the container.
/snap/bin/lxc --project snapcraft exec $instance_name -- bash -c 'cat /proc/sys/kernel/core_pattern'
# We need to capture the exit code here for the coredump capture steps.
# The step `run` sets exit on failure as default, so disable it to allow the code
# to capture the exit code. We'll manually do an exit(exit_code) later on.
set +e
set -o xtrace
# Enable coredumps by setting the core dump size to "unlimited", and run the tests.
/snap/bin/lxc --project snapcraft exec $instance_name -- bash -c "\
ulimit -c unlimited && \
env CTEST_OUTPUT_ON_FAILURE=1 \
LD_LIBRARY_PATH=/root/stage/usr/lib/x86_64-linux-gnu/:/root/stage/lib/:/root/parts/multipass/build/lib/ \
/root/parts/multipass/build/bin/multipass_tests"
# Capture the exit code.
exit_code="$?"
# Save the exit code to a action-level variable so we can refer to it in other steps.
echo "MULTIPASS_TESTS_EXIT_CODE=$exit_code" >> $GITHUB_ENV
# Re-enable exit on failure
set -e
# We're now done with our intermediate "SIGSEGV" special case, finalize the step with
# the test executable's original exit code.
set +o xtrace
exit $exit_code
- name: Measure coverage
id: measure-coverage
Expand All @@ -238,6 +212,7 @@ jobs:
timeout-minutes: 5
run: |
trap 'echo "MULTIPASS_TESTS_EXIT_CODE=$?" >> $GITHUB_ENV' EXIT
instance_name=`/snap/bin/lxc --project snapcraft --format=csv --columns=n list | grep multipass`
/snap/bin/lxc --project snapcraft start $instance_name
Expand All @@ -257,28 +232,11 @@ jobs:
/snap/bin/lxc --project snapcraft exec $instance_name -- \
sh -c "sudo sed -i \"s/use JSON::PP/use JSON::XS/\" \`which geninfo\`"
# We need to capture the exit code here for the coredump capture steps.
# The step `run` sets exit on failure as default, so disable it to allow the code
# to capture the exit code. We'll manually do an exit(exit_code) later on.
set +e
set -o xtrace
/snap/bin/lxc --project snapcraft exec $instance_name -- bash -c "\
ulimit -c unlimited && \
env CTEST_OUTPUT_ON_FAILURE=1 \
cmake --build /root/parts/multipass/build --target covreport"
# Capture the exit code.
exit_code="$?"
# Save the exit code to a action-level variable so we can refer to it in other steps.
echo "MULTIPASS_TESTS_EXIT_CODE=$exit_code" >> $GITHUB_ENV
# Re-enable exit on failure
set -e
# Directly exit without running the codecov if an error occurs
if [ $exit_code -ne 0 ] ; then
exit $exit_code
fi
bash <(curl -s https://codecov.io/bash) -Z -s ${{ steps.coverage-setup.outputs.build }}
exit $exit_code
- name: Pull coredump and executable from LXC container
if: ${{ failure() && env.MULTIPASS_TESTS_EXIT_CODE == '139'}}
Expand Down

0 comments on commit 4df339e

Please sign in to comment.