mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-02 05:10:17 +01:00
util/cache_test: Add test for get/put() with disabled cache
The disk_cache_create() now always returns valid cache even when disk cache is disabled. In a case of disabled cache, the disk cache is NO-OP. Test whether get/put() work as expected for the disabled cache. Reviewed-by: Rob Clark <robdclark@chromium.org> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24985>
This commit is contained in:
parent
4547671fc3
commit
0ed4c86873
1 changed files with 60 additions and 0 deletions
|
|
@ -1278,3 +1278,63 @@ TEST_F(Cache, DatabaseMultipartEviction)
|
|||
EXPECT_EQ(err, 0) << "Removing " CACHE_TEST_TMP " again";
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
test_put_and_get_disabled(const char *driver_id)
|
||||
{
|
||||
struct disk_cache *cache;
|
||||
char blob[] = "This is a blob of thirty-seven bytes";
|
||||
uint8_t blob_key[20];
|
||||
char *result;
|
||||
size_t size;
|
||||
|
||||
cache = disk_cache_create("test", driver_id, 0);
|
||||
|
||||
disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
|
||||
|
||||
/* Ensure that disk_cache_get returns nothing before anything is added. */
|
||||
result = (char *) disk_cache_get(cache, blob_key, &size);
|
||||
EXPECT_EQ(result, nullptr) << "disk_cache_get with non-existent item (pointer)";
|
||||
EXPECT_EQ(size, 0) << "disk_cache_get with non-existent item (size)";
|
||||
|
||||
/* Simple test of put and get. */
|
||||
disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
|
||||
|
||||
/* disk_cache_put() hands things off to a thread so wait for it. */
|
||||
disk_cache_wait_for_idle(cache);
|
||||
|
||||
result = (char *) disk_cache_get(cache, blob_key, &size);
|
||||
EXPECT_STREQ(result, nullptr) << "disk_cache_get of existing item (pointer)";
|
||||
EXPECT_EQ(size, 0) << "disk_cache_get of existing item (size)";
|
||||
|
||||
disk_cache_destroy(cache);
|
||||
}
|
||||
|
||||
TEST_F(Cache, Disabled)
|
||||
{
|
||||
const char *driver_id = "make_check";
|
||||
|
||||
#ifndef ENABLE_SHADER_CACHE
|
||||
GTEST_SKIP() << "ENABLE_SHADER_CACHE not defined.";
|
||||
#else
|
||||
setenv("MESA_DISK_CACHE_SINGLE_FILE", "true", 1);
|
||||
|
||||
#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
|
||||
setenv("MESA_SHADER_CACHE_DISABLE", "false", 1);
|
||||
#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
|
||||
|
||||
test_disk_cache_create(mem_ctx, CACHE_DIR_NAME_SF, driver_id);
|
||||
|
||||
test_put_and_get(false, driver_id);
|
||||
|
||||
setenv("MESA_SHADER_CACHE_DISABLE", "true", 1);
|
||||
|
||||
test_put_and_get_disabled(driver_id);
|
||||
|
||||
setenv("MESA_SHADER_CACHE_DISABLE", "false", 1);
|
||||
setenv("MESA_DISK_CACHE_SINGLE_FILE", "false", 1);
|
||||
|
||||
int err = rmrf_local(CACHE_TEST_TMP);
|
||||
EXPECT_EQ(err, 0) << "Removing " CACHE_TEST_TMP " again";
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue