From: Peter Krempa Date: Thu, 2 Mar 2023 16:32:28 +0000 (+0100) Subject: util: virfilecache: Introduce virFileCacheClear for usage in tests X-Git-Tag: v9.2.0-rc1~181 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ac7e0a06f4b1dc4a6cdbb3611c5b9a6496454e2;p=thirdparty%2Flibvirt.git util: virfilecache: Introduce virFileCacheClear for usage in tests In tests we need to be able to populate the cache with a deterministic set of entries. This means we need to drop the contents of the cache between runs to prevent spillage between test cases. virFileCacheClear drops all entries from the hash table used for the cache. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8792bf7f54..d5b1b9cb72 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2354,6 +2354,7 @@ virFindFileInPath; # util/virfilecache.h +virFileCacheClear; virFileCacheGetPriv; virFileCacheInsertData; virFileCacheLookup; diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index bad37c9f00..b9e06545c0 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -407,3 +407,19 @@ virFileCacheInsertData(virFileCache *cache, return ret; } + + +/** + * virFileCacheClear: + * @cache: existing cache object + * + * Drops all entries from the cache. This is useful in tests to clean out + * previous usage. + */ +void +virFileCacheClear(virFileCache *cache) +{ + virObjectLock(cache); + virHashRemoveAll(cache->table); + virObjectUnlock(cache); +} diff --git a/src/util/virfilecache.h b/src/util/virfilecache.h index 81be8feef5..c3bc0f529c 100644 --- a/src/util/virfilecache.h +++ b/src/util/virfilecache.h @@ -135,3 +135,7 @@ int virFileCacheInsertData(virFileCache *cache, const char *name, void *data); + +/* for testing usage */ +void +virFileCacheClear(virFileCache *cache);