Merging upstream version 0.7.1 (Closes: #991419).

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 07:39:31 +01:00
parent 05c588e9d7
commit 9e09e0ef69
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
99 changed files with 6727 additions and 943 deletions

View file

@ -5,9 +5,9 @@
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyrighs
* 1. Redistributions of source code must retain the above copyrights
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyrighs
* 2. Redistributions in binary form must reproduce the above copyrights
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
@ -57,12 +57,28 @@ 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",
"come", "down.", "What", "is", "down", "stays",
"down.", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q" };
"upon", "a", "time", "his", "gypsy", "ate", "one", "itsy",
"bitsy", "spider.", "What", "goes", "up", "must",
"come", "down.", "What", "is", "down", "stays",
"down.", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q" };
const char *negative = "negative";
@ -136,13 +152,21 @@ run_test(unsigned int is, unsigned int ad)
size_t i, j;
const char *blob = "#blobs";
unsigned long h;
ck_hs_iterator_t it;
if (ck_hs_init(&hs[0], CK_HS_MODE_SPMC | CK_HS_MODE_OBJECT | ad, hs_hash, hs_compare, &my_allocator, is, 6602834) == false)
ck_error("ck_hs_init\n");
for (j = 0; j < size; j++) {
for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
h = test[i][0];
unsigned long h_1;
h = CK_HS_HASH(&hs[j], hs_hash, test[i]);
h_1 = ck_hs_hash(&hs[j], test[i]);
if (h != h_1)
ck_error("h != h_1 (%lu != %lu)\n", h, h_1);
if (ck_hs_get(&hs[j], h, test[i]) != NULL) {
continue;
}
@ -181,6 +205,58 @@ 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. */
ck_hs_iterator_init(&it);
void *k = NULL;
int matches = 0;
int entries = 0;
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);
if (x == 0) {
matches++;
break;
}
}
}
if (entries != matches) {
ck_error("Iteration must match all elements, has: %d, matched: %d [%d]", entries, matches, is);
}
/*
* 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;
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);
if (x == 0) {
matches++;
break;
}
}
if (entries == 20) {
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);
}
}
/* Test grow semantics. */
ck_hs_grow(&hs[j], 128);
for (i = 0; i < sizeof(test) / sizeof(*test); i++) {