From 7eff0db95914ffd272e9378f60671fa32a2f6342 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sun, 12 May 2019 18:30:17 -0400 Subject: [PATCH] regressions/ck_hs: fix invalid memory management for next_spmc tests. These tests check for sane behavior in the presence of new maps being created for the hash set. They require the presence of SMR. For the life time of the growth_spmc tests, disable deallocation. --- regressions/ck_hs/validate/serial.c | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/regressions/ck_hs/validate/serial.c b/regressions/ck_hs/validate/serial.c index 21cb13a..d1ae749 100644 --- a/regressions/ck_hs/validate/serial.c +++ b/regressions/ck_hs/validate/serial.c @@ -57,6 +57,22 @@ static struct ck_malloc my_allocator = { .free = hs_free }; +static void +stub_free(void *p, size_t b, bool r) +{ + + (void)b; + (void)r; + + fprintf(stderr, "Ignoring reclamation of %p\n", p); + return; +} + +static struct ck_malloc stub_allocator = { + .malloc = hs_malloc, + .free = stub_free +}; + const char *test[] = { "Samy", "Al", "Bahra", "dances", "in", "the", "wind.", "Once", "upon", "a", "time", "his", "gypsy", "ate", "one", "itsy", "bitsy", "spider.", "What", "goes", "up", "must", @@ -183,12 +199,13 @@ run_test(unsigned int is, unsigned int ad) } /* Test iteration */ - if (j == 0) { // avoid the blob stuff as it's not in the test array + if (j == 0) { + /* Avoid the blob stuff as it's not in the test array. */ ck_hs_iterator_init(&it); void *k = NULL; int matches = 0; int entries = 0; - while(ck_hs_next(&hs[j], &it, &k)) { + while (ck_hs_next(&hs[j], &it, &k) == true) { entries++; for (i = 0; i < sizeof(test) / sizeof(*test); i++) { int x = strcmp(test[i], (char *)k); @@ -203,12 +220,17 @@ run_test(unsigned int is, unsigned int ad) ck_error("Iteration must match all elements, has: %d, matched: %d [%d]", entries, matches, is); } - /* Now test iteration in the face of grows (spmc)*/ + /* + * Now test iteration in the face of grows (spmc). + * In order to test usage after reclamation, we + * stub the allocator. + */ ck_hs_iterator_init(&it); k = NULL; matches = 0; entries = 0; - while(ck_hs_next_spmc(&hs[j], &it, &k)) { + hs[j].m = &stub_allocator; + while (ck_hs_next_spmc(&hs[j], &it, &k) == true) { entries++; for (i = 0; i < sizeof(test) / sizeof(*test); i++) { int x = strcmp(test[i], (char *)k); @@ -221,6 +243,7 @@ run_test(unsigned int is, unsigned int ad) ck_hs_grow(&hs[j], 128); } } + hs[j].m = &my_allocator; if (entries != matches) { ck_error("After growth, iteration must match all elements, has: %d, matched: %d [%d]", entries, matches, is);