diff options
author | Andreas Schneider <asn@samba.org> | 2021-02-03 10:37:12 +0100 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2021-02-08 10:46:08 +0000 |
commit | a3fa41c742900d7a91adc2e80a388e86e5b05f17 (patch) | |
tree | a7b854ddc750efd7f4f6c17faa3899558017135c | |
parent | 32d62beae343a58e8ddc1bccff8dbf9bfe8f869e (diff) | |
download | samba-a3fa41c742900d7a91adc2e80a388e86e5b05f17.tar.gz |
lib:util: Add cache oversize test for memcache
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)
-rw-r--r-- | lib/util/tests/test_memcache.c | 39 | ||||
-rw-r--r-- | selftest/knownfail.d/memcache | 1 |
2 files changed, 40 insertions, 0 deletions
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 |