From 61f6f2991b9a69bad68bbb594cc62faad77620e9 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 30 Jun 2026 16:56:16 -0400 Subject: [PATCH] Add single instance of a valgrind test to verify memory handling in CMock. --- .github/workflows/main.yml | 48 ++++++++++++++++++++++++++++++++++++++ test/gcc_64_valgrind.yml | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/gcc_64_valgrind.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8b66a49..e543d7e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,3 +67,51 @@ jobs: NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} run: | cd test && rake ci + + # Job: Valgrind memory-leak check (Linux/gcc_64 only, latest Ruby) + valgrind: + name: "Valgrind Memory Check" + runs-on: ubuntu-latest + steps: + - name: Install Dependencies + run: | + sudo apt-get update -qq + sudo apt-get install --assume-yes --quiet gcc-multilib valgrind + + - name: Checkout Latest Repo + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + + - name: Install Ruby Dependencies + run: | + gem install bundler + bundle install + + # Build and run C unit tests, then re-run the executable under valgrind. + # test:system clobbers the build directory, so check TestCMockC before that happens. + - name: Build and Run C Unit Tests + run: cd test && rake config[gcc_64_valgrind] test:c + + - name: Valgrind Check - C Unit Tests + run: | + valgrind --leak-check=full --track-origins=yes --error-exitcode=1 \ + test/system/build/TestCMockC.exe + + # Build and run system tests, then re-run each executable under valgrind. + - name: Build and Run System Tests + run: cd test && rake config[gcc_64_valgrind] test:system + + - name: Valgrind Check - System Tests + run: | + failed=0 + for exe in test/system/build/test_*.exe; do + echo "Checking: $exe" + valgrind --leak-check=full --track-origins=yes --error-exitcode=1 "$exe" || failed=1 + done + exit $failed diff --git a/test/gcc_64_valgrind.yml b/test/gcc_64_valgrind.yml new file mode 100644 index 0000000..a3af73b --- /dev/null +++ b/test/gcc_64_valgrind.yml @@ -0,0 +1,48 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +# gcc_64 with debug symbols enabled for meaningful valgrind output. +# Used by the CI valgrind job to check for memory leaks and errors. + +--- +:tools: + :test_compiler: + :name: compiler + :executable: gcc + :arguments: + - "-c" + - "-m64" + - "-g" + - "-Wall" + - "-Wno-address" + - "-std=c99" + - "-pedantic" + - '-I"${5}"' + - "-D${6}" + - "${1}" + - "-o ${2}" + :test_linker: + :name: linker + :executable: gcc + :arguments: + - "${1}" + - "-lm" + - "-m64" + - "-o ${2}" +:extension: + :object: ".o" + :executable: ".exe" +:defines: + :test: + - UNITY_EXCLUDE_STDINT_H + - UNITY_EXCLUDE_LIMITS_H + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_TEST_CASES + - UNITY_SUPPORT_64 + - UNITY_INT_WIDTH=32 + - UNITY_LONG_WIDTH=64 + - UNITY_POINTER_WIDTH=64