commit 026ca5390c4ee5e3674e3c8fcb7e5b4a940e7725
Author: Tomas Korbar <tkorbar@redhat.com>
Date: Thu Jun 4 19:17:57 2020 +0200
Update test_stats_prefix_dump
- the test was failing on big endian architectures
diff --git a/testapp.c b/testapp.c
index b670708..5a758b4 100644
--- a/testapp.c
+++ b/testapp.c
@@ -322,38 +322,45 @@ static enum test_return test_stats_prefix_record_set(void) {
static enum test_return test_stats_prefix_dump(void) {
int hashval = hash("abc", 3) % PREFIX_HASH_SIZE;
char tmp[500];
- char *expected;
+ char *buf;
+ const char *expected;
int keynum;
int length;
stats_prefix_clear();
- assert(strcmp("END\r\n", stats_prefix_dump(&length)) == 0);
+ assert(strcmp("END\r\n", (buf = stats_prefix_dump(&length))) == 0);
assert(5 == length);
stats_prefix_record_set("abc:123", 7);
+ free(buf);
expected = "PREFIX abc get 0 hit 0 set 1 del 0\r\nEND\r\n";
- assert(strcmp(expected, stats_prefix_dump(&length)) == 0);
+ assert(strcmp(expected, (buf = stats_prefix_dump(&length))) == 0);
assert(strlen(expected) == length);
stats_prefix_record_get("abc:123", 7, false);
+ free(buf);
expected = "PREFIX abc get 1 hit 0 set 1 del 0\r\nEND\r\n";
- assert(strcmp(expected, stats_prefix_dump(&length)) == 0);
+ assert(strcmp(expected, (buf = stats_prefix_dump(&length))) == 0);
assert(strlen(expected) == length);
stats_prefix_record_get("abc:123", 7, true);
+ free(buf);
expected = "PREFIX abc get 2 hit 1 set 1 del 0\r\nEND\r\n";
- assert(strcmp(expected, stats_prefix_dump(&length)) == 0);
+ assert(strcmp(expected, (buf = stats_prefix_dump(&length))) == 0);
assert(strlen(expected) == length);
stats_prefix_record_delete("abc:123", 7);
+ free(buf);
expected = "PREFIX abc get 2 hit 1 set 1 del 1\r\nEND\r\n";
- assert(strcmp(expected, stats_prefix_dump(&length)) == 0);
+ assert(strcmp(expected, (buf = stats_prefix_dump(&length))) == 0);
assert(strlen(expected) == length);
- /* The order of results might change if we switch hash functions. */
stats_prefix_record_delete("def:123", 7);
- expected = "PREFIX abc get 2 hit 1 set 1 del 1\r\n"
- "PREFIX def get 0 hit 0 set 0 del 1\r\n"
- "END\r\n";
- assert(strcmp(expected, stats_prefix_dump(&length)) == 0);
- assert(strlen(expected) == length);
+ free(buf);
+ /* NOTE: Prefixes can be dumped in any order, so we verify that
+ each expected line is present in the string. */
+ buf = stats_prefix_dump(&length);
+ assert(strstr(buf, "PREFIX abc get 2 hit 1 set 1 del 1\r\n") != NULL);
+ assert(strstr(buf, "PREFIX def get 0 hit 0 set 0 del 1\r\n") != NULL);
+ assert(strstr(buf, "END\r\n") != NULL);
+ free(buf);
/* Find a key that hashes to the same bucket as "abc" */
bool found_match = false;
@@ -367,13 +374,16 @@ static enum test_return test_stats_prefix_dump(void) {
}
assert(found_match);
stats_prefix_record_set(tmp, strlen(tmp));
- snprintf(tmp, sizeof(tmp),
- "PREFIX %d get 0 hit 0 set 1 del 0\r\n"
- "PREFIX abc get 2 hit 1 set 1 del 1\r\n"
- "PREFIX def get 0 hit 0 set 0 del 1\r\n"
- "END\r\n", keynum);
- assert(strcmp(tmp, stats_prefix_dump(&length)) == 0);
- assert(strlen(tmp) == length);
+ buf = stats_prefix_dump(&length);
+ assert(strstr(buf, "PREFIX abc get 2 hit 1 set 1 del 1\r\n") != NULL);
+ assert(strstr(buf, "PREFIX def get 0 hit 0 set 0 del 1\r\n") != NULL);
+ assert(strstr(buf, "END\r\n") != NULL);
+ snprintf(tmp, sizeof(tmp), "PREFIX %d get 0 hit 0 set 1 del 0\r\n", keynum);
+ assert(strstr(buf, tmp) != NULL);
+ free(buf);
+
+ /* Marking the end of these tests */
+ stats_prefix_clear();
return TEST_PASS;
}