From c596c270fa8092dc4ca712edbff60a489a727f49 Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Thu, 24 Feb 2022 09:36:04 +0100 Subject: [PATCH 1/5] diff: fix leak due to not calling git_libgit2_shutdown --- src/core/runner.c | 1 + src/core/runner_coroutine.c | 1 + src/string/diff-stubs.c | 4 ++++ src/string/diff.c | 5 +++++ src/string/diff.h | 1 + 5 files changed, 12 insertions(+) diff --git a/src/core/runner.c b/src/core/runner.c index ffe072c5..16d720ca 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -242,6 +242,7 @@ CR_API void criterion_finalize(struct criterion_test_set *set) VALGRIND_ENABLE_ERROR_REPORTING; #endif + cri_diff_fini(); criterion_free_output(); } diff --git a/src/core/runner_coroutine.c b/src/core/runner_coroutine.c index b78150e5..533e233a 100644 --- a/src/core/runner_coroutine.c +++ b/src/core/runner_coroutine.c @@ -234,6 +234,7 @@ static int run_test_child(void) #endif cri_proto_close(g_client_socket); + cri_diff_fini(); #ifndef ENABLE_VALGRIND_ERRORS VALGRIND_ENABLE_ERROR_REPORTING; diff --git a/src/string/diff-stubs.c b/src/string/diff-stubs.c index 04b654b4..52fa5414 100644 --- a/src/string/diff-stubs.c +++ b/src/string/diff-stubs.c @@ -28,6 +28,10 @@ void cri_diff_init(void) { } +void cri_diff_fini(void) +{ +} + int cri_diff_buffer_to_buffer(const struct cri_diff_buffer *b1, const struct cri_diff_buffer *b2, struct cri_diff_buffer *out) { diff --git a/src/string/diff.c b/src/string/diff.c index a6c2ac79..bd7b1f6c 100644 --- a/src/string/diff.c +++ b/src/string/diff.c @@ -40,6 +40,11 @@ void cri_diff_init(void) git_libgit2_init(); } +void cri_diff_fini(void) +{ + git_libgit2_shutdown(); +} + static int process_line(const git_diff_delta *delta, const git_diff_hunk *hunk, const git_diff_line *line, void *data) { diff --git a/src/string/diff.h b/src/string/diff.h index c341d893..f229e8a0 100644 --- a/src/string/diff.h +++ b/src/string/diff.h @@ -34,6 +34,7 @@ struct cri_diff_buffer { }; void cri_diff_init(void); +void cri_diff_fini(void); int cri_diff_buffer_to_buffer(const struct cri_diff_buffer *b1, const struct cri_diff_buffer *b2, struct cri_diff_buffer *out); From c4d9a78d738f4ce82e8beee44196bb9dc5ae2ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Tue, 5 Apr 2022 13:30:41 +0200 Subject: [PATCH 2/5] readme: advertise official homebrew package for macOS --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c25e85c..f14b5727 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ the user would have with other frameworks: $ sudo apt-get install criterion-dev ``` * Arch Linux ([AUR](https://aur.archlinux.org/packages/criterion/)): `pacaur -S criterion` -* macOS: `brew install mranno/tap/criterion` +* macOS: `brew install criterion` ### Binary archives From 7e3c35e2230da1b2cd1a6bb48450f1561fa4c7c9 Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Wed, 13 Apr 2022 18:30:16 +0200 Subject: [PATCH 3/5] api: mark cr_tst and cr_sts sections as used This prevents LTO from removing the sections at link-time, which caused tests to not be detected and run. --- include/criterion/internal/test.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/criterion/internal/test.h b/include/criterion/internal/test.h index e299ca66..7cce462b 100644 --- a/include/criterion/internal/test.h +++ b/include/criterion/internal/test.h @@ -173,6 +173,7 @@ static const char *const cr_msg_test_fini_other_exception = "Caught some unexpec CR_IDENTIFIER_(Category, Name, jmp), \ &CR_IDENTIFIER_(Category, Name, extra) \ }; \ + CR_ATTRIBUTE(used) \ CR_SECTION_("cr_tst") \ struct criterion_test *CR_IDENTIFIER_(Category, Name, ptr) \ = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_; \ @@ -189,6 +190,7 @@ static const char *const cr_msg_test_fini_other_exception = "Caught some unexpec #Name, \ &CR_SUITE_IDENTIFIER_(Name, extra), \ }; \ + CR_ATTRIBUTE(used) \ CR_SECTION_("cr_sts") \ struct criterion_suite *CR_SUITE_IDENTIFIER_(Name, ptr) \ = &CR_SUITE_IDENTIFIER_(Name, meta) CR_SECTION_SUFFIX_ From cc567af6a53a55cbadc156701735dc4bb81bc0cd Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Tue, 5 Apr 2022 15:56:08 +0200 Subject: [PATCH 4/5] theories: reset ffi argument vector on each iteration --- src/core/theories.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/theories.c b/src/core/theories.c index c643eeda..de81cc37 100644 --- a/src/core/theories.c +++ b/src/core/theories.c @@ -237,6 +237,8 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (* int theory_aborted = 0; if (!cri_setjmp(theory_jmp)) { + ctx->nargs = 0; + for (size_t i = 0; i < datapoints; ++i) { bool is_float = contains_word(dps[i].name, "float", sizeof ("float")) || contains_word(dps[i].name, "double", sizeof ("double")); From e9ee02c24858eeea58be82107708e95ebde387e8 Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Wed, 13 Apr 2022 19:36:03 +0200 Subject: [PATCH 5/5] samples: fix theory sample to avoid UB INT_MIN / -1 is undefined behaviour, as its numerical result is INT_MAX+1 and is therefore not representable on an int. The instructions emited by optimizing compilers assume that this does not happen, which usually results in SIGFPE rather than an overflow. --- samples/theories.c | 2 ++ samples/theories.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/samples/theories.c b/samples/theories.c index 3094a74e..2649dcba 100644 --- a/samples/theories.c +++ b/samples/theories.c @@ -26,6 +26,7 @@ TheoryDataPoints(algebra, bad_divide_is_inverse_of_multiply) = { Theory((int a, int b), algebra, bad_divide_is_inverse_of_multiply) { cr_assume(b != 0); + cr_assume(a != INT_MIN || b != -1); cr_assert_eq(a, bad_div(bad_mul(a, b), b)); } @@ -48,6 +49,7 @@ TheoryDataPoints(algebra, good_divide_is_inverse_of_multiply) = { Theory((int a, int b), algebra, good_divide_is_inverse_of_multiply) { cr_assume(b != 0); + cr_assume(a != INT_MIN || b != -1); cr_assert_eq(a, good_div(good_mul(a, b), b)); } diff --git a/samples/theories.cc b/samples/theories.cc index a711aab3..dbd14356 100644 --- a/samples/theories.cc +++ b/samples/theories.cc @@ -30,6 +30,7 @@ TheoryDataPoints(algebra, bad_divide_is_inverse_of_multiply) = { Theory((int a, int b), algebra, bad_divide_is_inverse_of_multiply) { cr_assume(b != 0); + cr_assume(a != INT_MIN || b != -1); cr_assert_eq(a, bad_div(bad_mul(a, b), b)); } @@ -52,6 +53,7 @@ TheoryDataPoints(algebra, good_divide_is_inverse_of_multiply) = { Theory((int a, int b), algebra, good_divide_is_inverse_of_multiply) { cr_assume(b != 0); + cr_assume(a != INT_MIN || b != -1); cr_assert_eq(a, good_div(good_mul(a, b), b)); }