Generating Patches
This guide demonstrates how to generate patches for mutants. The patches can be further applied on the original source code to generate mutated version of the codebase.
This guide is based on the CMake Integration.
Step 1. Check out the source code
Section titled “Step 1. Check out the source code”git clone https://github.com/fmtlib/fmt --depth 1cd fmtStep 2. Create config mull.yml
Section titled “Step 2. Create config mull.yml”mutators: - cxx_add_to_subexcludePaths: - .*gtest.* - .*gmock.*Step 3. Configure and build fmtlib
Section titled “Step 3. Configure and build fmtlib”mkdir build.direxport CXX=clang++-22cmake \ -DCMAKE_CXX_FLAGS="-O0 -fpass-plugin=/usr/lib/mull-ir-frontend-22 -g -grecord-command-line" \ -S $PWD -B build.dircmake --build build.dir/ -t scan-testStep 4. Run Mull against fmtlib tests
Section titled “Step 4. Run Mull against fmtlib tests”mull-runner-22 --reporters=Patches --report-name fmtlib --report-patch-base $PWD ./build.dir/bin/scan-testYou should see similar output:
[info] Using config /tmp/fmt/mull.yml[warning] Could not find dynamic library: libstdc++.so.6[warning] Could not find dynamic library: libm.so.6[warning] Could not find dynamic library: libgcc_s.so.1[warning] Could not find dynamic library: libc.so.6[info] Warm up run (threads: 1) [################################] 1/1. Finished in 4ms[info] Applying file path filter (threads: 8) [################################] 105/105. Finished in 2ms[info] Baseline run (threads: 1) [################################] 1/1. Finished in 2ms[info] Running mutants (threads: 8) [################################] 105/105. Finished in 48ms[info] Patchfiles can be found at './fmtlib-patches'[info] Surviving mutants: 99[info] Total execution time: 106msGenerated patches are located under fmtlib-patches:
> ls -l fmtlib-patches/ | headtotal 420-rw-r--r-- 1 mull mull 280 Apr 4 10:37 killed-include_fmt_format_h-cxx_add_to_sub-L2071-C29.patch-rw-r--r-- 1 mull mull 210 Apr 4 10:37 killed-include_fmt_format_h-cxx_add_to_sub-L488-C30.patch-rw-r--r-- 1 mull mull 218 Apr 4 10:37 killed-test_scan_h-cxx_add_to_sub-L23-C44.patch-rw-r--r-- 1 mull mull 220 Apr 4 10:37 killed-test_scan_h-cxx_add_to_sub-L404-C16.patch-rw-r--r-- 1 mull mull 238 Apr 4 10:37 killed-test_scan_h-cxx_add_to_sub-L418-C20.patch-rw-r--r-- 1 mull mull 220 Apr 4 10:37 killed-test_scan_h-cxx_add_to_sub-L435-C18.patch-rw-r--r-- 1 mull mull 294 Apr 4 10:37 survived-include_fmt_base_h-cxx_add_to_sub-L1277-C74.patch-rw-r--r-- 1 mull mull 228 Apr 4 10:37 survived-include_fmt_base_h-cxx_add_to_sub-L1290-C24.patch-rw-r--r-- 1 mull mull 216 Apr 4 10:37 survived-include_fmt_base_h-cxx_add_to_sub-L1299-C33.patchThe patches can be applied now:
> patch -p1 < fmtlib-patches/killed-include_fmt_format_h-cxx_add_to_sub-L488-C30.patchpatching file include/fmt/format.h> git diffdiff --git a/include/fmt/format.h b/include/fmt/format.hindex e46b613..a8a43bf 100644--- a/include/fmt/format.h+++ b/include/fmt/format.h@@ -485,7 +485,7 @@ template <typename T> FMT_CONSTEXPR20 inline auto reserve(basic_appender<T> it, size_t n) -> basic_appender<T> { buffer<T>& buf = get_container(it);- buf.try_reserve(buf.size() + n);+ buf.try_reserve(buf.size() - n); return it; }