diff options
author | Christof Schmitt <cs@samba.org> | 2019-03-28 10:46:43 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2019-04-06 06:08:42 +0000 |
commit | b7028c42462c34cf86cb949bfdb16ebc7ed0a6c6 (patch) | |
tree | bb84bd7e0afbbf898037351faea3aa8eab818ae7 /source3/torture | |
parent | 9ff5c0bab76c5d3d7bea1fcb79861d0c9a3b9839 (diff) | |
download | samba-b7028c42462c34cf86cb949bfdb16ebc7ed0a6c6.tar.gz |
torture: Add test for talloc size accounting in memcache
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13865
Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Apr 6 06:08:42 UTC 2019 on sn-devel-144
Diffstat (limited to 'source3/torture')
-rw-r--r-- | source3/torture/torture.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 219ac4a370c..782980dec3a 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -11155,13 +11155,14 @@ static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b) static bool run_local_memcache(int dummy) { struct memcache *cache; - DATA_BLOB k1, k2, k3; + DATA_BLOB k1, k2, k3, k4, k5; DATA_BLOB d1, d3; DATA_BLOB v1, v3; TALLOC_CTX *mem_ctx; char *ptr1 = NULL; char *ptr2 = NULL; + char *ptr3 = NULL; char *str1, *str2; size_t size1, size2; @@ -11187,6 +11188,8 @@ static bool run_local_memcache(int dummy) k1 = data_blob_const("d1", 2); k2 = data_blob_const("d2", 2); k3 = data_blob_const("d3", 2); + k4 = data_blob_const("d4", 2); + k5 = data_blob_const("d5", 2); memcache_add(cache, STAT_CACHE, k1, d1); @@ -11250,6 +11253,71 @@ static bool run_local_memcache(int dummy) return false; } + /* + * Test that talloc size also is accounted in memcache and + * causes purge of other object. + */ + + str1 = talloc_zero_size(mem_ctx, 100); + str2 = talloc_zero_size(mem_ctx, 100); + + memcache_add_talloc(cache, GETWD_CACHE, k4, &str1); + memcache_add_talloc(cache, GETWD_CACHE, k5, &str1); + + ptr3 = memcache_lookup_talloc(cache, GETWD_CACHE, k4); + if (ptr3 != NULL) { + printf("Did find k4, should have been purged\n"); + return false; + } + + /* + * Test that adding a duplicate non-talloced + * key/value on top of a talloced key/value takes account + * of the talloc_freed value size. + */ + TALLOC_FREE(cache); + TALLOC_FREE(mem_ctx); + + mem_ctx = talloc_init("key_replace"); + if (mem_ctx == NULL) { + return false; + } + + cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100); + if (cache == NULL) { + return false; + } + + /* + * Add a 100 byte talloced string. This will + * store a (4 or 8 byte) pointer and record the + * total talloced size. + */ + str1 = talloc_zero_size(mem_ctx, 100); + memcache_add_talloc(cache, GETWD_CACHE, k4, &str1); + /* + * Now overwrite with a small talloced + * value. This should fit in the existing size + * and the total talloced size should be removed + * from the cache size. + */ + str1 = talloc_zero_size(mem_ctx, 2); + memcache_add_talloc(cache, GETWD_CACHE, k4, &str1); + /* + * Now store a 20 byte string. If the + * total talloced size wasn't accounted for + * and removed in the overwrite, then this + * will evict k4. + */ + str2 = talloc_zero_size(mem_ctx, 20); + memcache_add_talloc(cache, GETWD_CACHE, k5, &str2); + + ptr3 = memcache_lookup_talloc(cache, GETWD_CACHE, k4); + if (ptr3 == NULL) { + printf("Did not find k4, should not have been purged\n"); + return false; + } + TALLOC_FREE(cache); TALLOC_FREE(mem_ctx); |