Skip to content

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.

Terminal window
git clone https://github.com/fmtlib/fmt --depth 1
cd fmt
mull.yml
mutators:
- cxx_add_to_sub
excludePaths:
- .*gtest.*
- .*gmock.*
Terminal window
mkdir build.dir
export CXX=clang++-22
cmake \
-DCMAKE_CXX_FLAGS="-O0 -fpass-plugin=/usr/lib/mull-ir-frontend-22 -g -grecord-command-line" \
-S $PWD -B build.dir
cmake --build build.dir/ -t scan-test
Terminal window
mull-runner-22 --reporters=Patches --report-name fmtlib --report-patch-base $PWD ./build.dir/bin/scan-test

You 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: 106ms

Generated patches are located under fmtlib-patches:

Terminal window
> ls -l fmtlib-patches/ | head
total 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.patch

The patches can be applied now:

Terminal window
> patch -p1 < fmtlib-patches/killed-include_fmt_format_h-cxx_add_to_sub-L488-C30.patch
patching file include/fmt/format.h
> git diff
diff --git a/include/fmt/format.h b/include/fmt/format.h
index 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;
}