Blame SOURCES/memcached-test-cache-dump.patch

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