From 971b7dee311b62cb4fe4e6d77a005df0f4af66e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 17 Sep 2022 20:07:11 +0200 Subject: [PATCH] tests: skip test with broken fmemopen under sanitizers fmemopen(2) is broken with address and memory sanitizer, see https://github.com/google/sanitizers/issues/627 and https://github.com/google/sanitizers/issues/628. --- tests/empty_string.c | 17 ++++++++++++++--- tests/print_filter.c | 13 +++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/empty_string.c b/tests/empty_string.c index 530585b..94e0735 100644 --- a/tests/empty_string.c +++ b/tests/empty_string.c @@ -25,19 +25,30 @@ int main(void) fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0); f = fmemopen(buf, sizeof(buf), "w+"); fail_unless(f != NULL); - cfg_print(cfg, f); + fail_unless(cfg_print(cfg, f) == CFG_SUCCESS); cfg_free(cfg); +#if defined(__has_feature) +# if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer) + /* Skip check since fmemopen(2) is broken with sanitizers, see + * https://github.com/google/sanitizers/issues/627 + * https://github.com/google/sanitizers/issues/628 + */ +# else /* * try to reload the generated temporary config file to check * that the default is indeed overridden by an empty string */ cfg = cfg_init(opts, 0); - fseek(f, 0L, SEEK_SET); + fail_unless(cfg != NULL); + fail_unless(fseek(f, 0L, SEEK_SET) == 0); fail_unless(cfg_parse_fp(cfg, f) == CFG_SUCCESS); - fclose(f); fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0); cfg_free(cfg); +# endif +#endif + + fclose(f); return 0; } diff --git a/tests/print_filter.c b/tests/print_filter.c index ca78a1b..77c1a44 100644 --- a/tests/print_filter.c +++ b/tests/print_filter.c @@ -39,9 +39,16 @@ int main(void) cfg_set_print_filter_func(cfg, no_foo); f = fmemopen(buf, sizeof(buf), "w+"); fail_unless(f != NULL); - cfg_print(cfg, f); + fail_unless(cfg_print(cfg, f) == CFG_SUCCESS); fclose(f); +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + /* Skip check since fmemopen(2) is broken with sanitizers, see + * https://github.com/google/sanitizers/issues/627 + * https://github.com/google/sanitizers/issues/628 + */ +# else fprintf(stderr, "no_foo filter:\n%s", buf); fail_unless(strstr(buf, "foo-") == NULL); fail_unless(strstr(buf, "bar-") != NULL); @@ -49,13 +56,15 @@ int main(void) cfg_set_print_filter_func(cfg, no_bar); f = fmemopen(buf, sizeof(buf), "w+"); fail_unless(f != NULL); - cfg_print(cfg, f); + fail_unless(cfg_print(cfg, f) == CFG_SUCCESS); fclose(f); fprintf(stderr, "----\n"); fprintf(stderr, "no_bar filter:\n%s", buf); fail_unless(strstr(buf, "foo-") != NULL); fail_unless(strstr(buf, "bar-") == NULL); +# endif +#endif cfg_free(cfg);