From: Andreas Schneider Date: Wed, 3 Feb 2021 09:37:12 +0000 (+0100) Subject: lib:util: Add cache oversize test for memcache X-Git-Tag: samba-4.12.12~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65b3648c55332d6186c6a03c0ef56e683a7afa46;p=thirdparty%2Fsamba.git lib:util: Add cache oversize test for memcache BUG: https://bugzilla.samba.org/show_bug.cgi?id=14625 Signed-off-by: Andreas Schneider Reviewed-by: Ralph Boehme (cherry picked from commit 00543ab3b29e3fbfe8314e51919629803e14ede6) --- diff --git a/lib/util/tests/test_memcache.c b/lib/util/tests/test_memcache.c index 8ea5e5b042e..8a3997817c1 100644 --- a/lib/util/tests/test_memcache.c +++ b/lib/util/tests/test_memcache.c @@ -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 index 00000000000..0a74ace3003 --- /dev/null +++ b/selftest/knownfail.d/memcache @@ -0,0 +1 @@ +^samba.unittests.memcache.torture_memcache_add_oversize