From d02de75487b092144d581f1582c548a2235e746a Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 12 Mar 2023 20:29:58 +0100 Subject: [PATCH] Add control that all initialized testobj are properly cleared at the end of the test suite --- tests/test-malgo.c | 1 + tests/test-marray.c | 1 + tests/test-mbptree.c | 1 + tests/test-mbuffer.c | 1 + tests/test-mcore.c | 1 + tests/test-mdeque.c | 1 + tests/test-mdict.c | 1 + tests/test-mlist.c | 2 +- tests/test-mprioqueue.c | 1 + tests/test-mrbtree.c | 1 + tests/test-mshared.c | 1 + tests/test-msnapshot.c | 2 +- tests/test-mtree.c | 11 ++++++----- tests/test-mtuple.c | 1 + tests/test-mvariant.c | 2 +- tests/test-obj.h | 14 ++++++++++++++ 16 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tests/test-malgo.c b/tests/test-malgo.c index 333d8be6..517a961c 100644 --- a/tests/test-malgo.c +++ b/tests/test-malgo.c @@ -724,5 +724,6 @@ int main(void) test_insert(); test_string_utf8(); test_fo(); + testobj_final_check(); exit(0); } diff --git a/tests/test-marray.c b/tests/test-marray.c index 848729ea..866e0f67 100644 --- a/tests/test-marray.c +++ b/tests/test-marray.c @@ -535,5 +535,6 @@ int main(void) test_str(); test_double(); test_cplusplus(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mbptree.c b/tests/test-mbptree.c index cdb90790..7acfe0ab 100644 --- a/tests/test-mbptree.c +++ b/tests/test-mbptree.c @@ -705,5 +705,6 @@ int main(void) test_multiset(); test_double(); test_emplace(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mbuffer.c b/tests/test-mbuffer.c index 47d1c9c9..c41f8922 100644 --- a/tests/test-mbuffer.c +++ b/tests/test-mbuffer.c @@ -661,5 +661,6 @@ int main(void) test_double1(); test_double2(); test_double3(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mcore.c b/tests/test-mcore.c index c9a71ef3..ada38d91 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -947,5 +947,6 @@ int main(void) test_M_CSTR(); test_properties(); test_generic_api(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mdeque.c b/tests/test-mdeque.c index 756efa86..d240fafb 100644 --- a/tests/test-mdeque.c +++ b/tests/test-mdeque.c @@ -548,5 +548,6 @@ int main(void) test_backward(); test_double(); test_remove(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mdict.c b/tests/test-mdict.c index 79159fd4..2bb3d5e1 100644 --- a/tests/test-mdict.c +++ b/tests/test-mdict.c @@ -590,5 +590,6 @@ int main(void) test_it_oa(); test_oa_str1(); test_oa_str2(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 3af0d9ab..7f1bfd29 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -751,6 +751,6 @@ int main(void) test_out_default_oplist(); test_double(); test_let_string(); + testobj_final_check(); exit(0); } - diff --git a/tests/test-mprioqueue.c b/tests/test-mprioqueue.c index 15ed3a69..0e9c797a 100644 --- a/tests/test-mprioqueue.c +++ b/tests/test-mprioqueue.c @@ -382,5 +382,6 @@ int main(void) test_double(); test_it(); test_io(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mrbtree.c b/tests/test-mrbtree.c index c00caf9e..162705ad 100644 --- a/tests/test-mrbtree.c +++ b/tests/test-mrbtree.c @@ -532,5 +532,6 @@ int main(void) test_double(); test_from(); test_z(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mshared.c b/tests/test-mshared.c index b20253d0..3093e8eb 100644 --- a/tests/test-mshared.c +++ b/tests/test-mshared.c @@ -229,5 +229,6 @@ int main(void) test_double(); test_double2(); test_double_res(); + testobj_final_check(); exit(0); } diff --git a/tests/test-msnapshot.c b/tests/test-msnapshot.c index 63374501..e0c6fb45 100644 --- a/tests/test-msnapshot.c +++ b/tests/test-msnapshot.c @@ -407,6 +407,6 @@ int main(void) test_double(); test_doubleSPMC(); test_doubleMPMC(); + testobj_final_check(); exit(0); } - diff --git a/tests/test-mtree.c b/tests/test-mtree.c index 06f54d27..4af48f3b 100644 --- a/tests/test-mtree.c +++ b/tests/test-mtree.c @@ -527,9 +527,10 @@ static void test_emplace(void) int main(void) { - test_basic(); - test_gen(); - test_io(); - test_emplace(); - return 0; + test_basic(); + test_gen(); + test_io(); + test_emplace(); + testobj_final_check(); + return 0; } diff --git a/tests/test-mtuple.c b/tests/test-mtuple.c index 6b0ad959..0da8451d 100644 --- a/tests/test-mtuple.c +++ b/tests/test-mtuple.c @@ -288,5 +288,6 @@ int main(void) check_reset(); check_chaining_tuple(); test_double(); + testobj_final_check(); exit(0); } diff --git a/tests/test-mvariant.c b/tests/test-mvariant.c index 067d473f..8b0c233b 100644 --- a/tests/test-mvariant.c +++ b/tests/test-mvariant.c @@ -297,6 +297,6 @@ int main(void) test_triple(); test_io(); test_double(); + testobj_final_check(); exit(0); } - diff --git a/tests/test-obj.h b/tests/test-obj.h index 220d9d91..4872e846 100644 --- a/tests/test-obj.h +++ b/tests/test-obj.h @@ -39,6 +39,14 @@ typedef struct testobj_s { unsigned int *ptr; } testobj_t[1]; +int testobj_init_counter = 0; + +static inline void testobj_final_check(void) +{ + // All created testobj shall have been cleared at the end. + assert(testobj_init_counter == 0); +} + static inline void testobj_init(testobj_t z) { z->n = 1; @@ -46,6 +54,7 @@ static inline void testobj_init(testobj_t z) z->ptr = (unsigned int*) calloc(1, sizeof(unsigned int)); assert(z->ptr != NULL); z->allocated = true; + testobj_init_counter++; } static inline void testobj_clear(testobj_t z) @@ -55,6 +64,8 @@ static inline void testobj_clear(testobj_t z) free(z->ptr); z->ptr = NULL; z->allocated = false; + testobj_init_counter--; + assert(testobj_init_counter >= 0); } static inline void testobj_init_set(testobj_t d, const testobj_t s) @@ -65,6 +76,7 @@ static inline void testobj_init_set(testobj_t d, const testobj_t s) assert(d->ptr != NULL); memcpy(d->ptr, s->ptr, sizeof(unsigned int) * s->n); d->allocated = true; + testobj_init_counter++; } static inline void testobj_set(testobj_t d, const testobj_t s) @@ -178,6 +190,7 @@ static inline void testobj_str(string_t str, const testobj_t z, bool append) PARSE_STR(testobj_parse_str), \ GET_STR(testobj_str), \ EQUAL(testobj_equal_p), \ + INIT_WITH(testobj_init_set_ui), \ EMPLACE_TYPE( LIST( (_ui, testobj_init_set_ui, unsigned int), (_str, testobj_init_set_str, const char *), ( /*empty*/, testobj_init_set, testobj_t) ) ) \ ) @@ -193,6 +206,7 @@ static inline void testobj_str(string_t str, const testobj_t z, bool append) GET_STR(testobj_str), \ EQUAL(testobj_equal_p), \ CMP(testobj_cmp), \ + INIT_WITH(testobj_init_set_ui), \ EMPLACE_TYPE( LIST( (_ui, testobj_init_set_ui, unsigned int), (_str, testobj_init_set_str, const char *), ( /*empty*/, testobj_init_set, testobj_t) ) ) \ )