lib:util: Add cache oversize test for memcache
authorAndreas Schneider <asn@samba.org>
Wed, 3 Feb 2021 09:37:12 +0000 (10:37 +0100)
committerKarolin Seeger <kseeger@samba.org>
Tue, 9 Feb 2021 12:27:16 +0000 (12:27 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14625

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 00543ab3b29e3fbfe8314e51919629803e14ede6)

lib/util/tests/test_memcache.c
selftest/knownfail.d/memcache [new file with mode: 0644]

index 8ea5e5b042eb158684cc4fa8be5fd1e638edf5ae..8a3997817c11281ce3f840121ed6bb5fd51ecec5 100644 (file)
@@ -98,6 +98,44 @@ static void torture_memcache_add_lookup_delete(void **state)
        path2 = memcache_lookup_talloc(cache, GETWD_CACHE, key2);
        assert_null(path2);
 
+       TALLOC_FREE(path1);
+       TALLOC_FREE(path2);
+       TALLOC_FREE(cache);
+}
+
+static void torture_memcache_add_oversize(void **state)
+{
+       TALLOC_CTX *mem_ctx = *state;
+       struct memcache *cache = NULL;
+       DATA_BLOB key1, key2;
+       char *path1 = NULL, *path2 = NULL;
+
+       cache = memcache_init(mem_ctx, 10);
+       assert_non_null(cache);
+
+       key1 = data_blob_const("key1", 4);
+       path1 = talloc_strdup(mem_ctx, "/tmp/one");
+       assert_non_null(path1);
+
+       key2 = data_blob_const("key2", 4);
+       path2 = talloc_strdup(mem_ctx, "/tmp/two");
+       assert_non_null(path1);
+
+       memcache_add_talloc(cache, GETWD_CACHE, key1, &path1);
+       assert_null(path1);
+
+       memcache_add_talloc(cache, GETWD_CACHE, key2, &path2);
+       assert_null(path2);
+
+       path1 = memcache_lookup_talloc(cache, GETWD_CACHE, key1);
+       assert_null(path1);
+
+       path2 = memcache_lookup_talloc(cache, GETWD_CACHE, key2);
+       assert_non_null(path2);
+       assert_string_equal(path2, "/tmp/two");
+
+       TALLOC_FREE(path1);
+       TALLOC_FREE(path2);
        TALLOC_FREE(cache);
 }
 
@@ -107,6 +145,7 @@ int main(int argc, char *argv[])
        const struct CMUnitTest tests[] = {
                cmocka_unit_test(torture_memcache_init),
                cmocka_unit_test(torture_memcache_add_lookup_delete),
+               cmocka_unit_test(torture_memcache_add_oversize),
        };
 
        if (argc == 2) {
diff --git a/selftest/knownfail.d/memcache b/selftest/knownfail.d/memcache
new file mode 100644 (file)
index 0000000..0a74ace
--- /dev/null
@@ -0,0 +1 @@
+^samba.unittests.memcache.torture_memcache_add_oversize