1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-03-02 17:32:28 +01:00
parent 3c02b1e810
commit 6ac7e0a06f
3 changed files with 21 additions and 0 deletions

View File

@ -2354,6 +2354,7 @@ virFindFileInPath;
# util/virfilecache.h
virFileCacheClear;
virFileCacheGetPriv;
virFileCacheInsertData;
virFileCacheLookup;

View File

@ -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);
}

View File

@ -135,3 +135,7 @@ int
virFileCacheInsertData(virFileCache *cache,
const char *name,
void *data);
/* for testing usage */
void
virFileCacheClear(virFileCache *cache);