summaryrefslogtreecommitdiff
path: root/lib/mesa/src/util/tests
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2021-07-22 10:17:30 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2021-07-22 10:17:30 +0000
commitca11beabae33eb59fb981b8adf50b1d47a2a98f0 (patch)
tree3e4691a396e6e54cd54224a190663d5cf976625b /lib/mesa/src/util/tests
parent27c8a50e8bbde7d28b1fc46d715a4c469e24f2c4 (diff)
Import Mesa 21.1.5
Diffstat (limited to 'lib/mesa/src/util/tests')
-rw-r--r--lib/mesa/src/util/tests/cache/cache_test.c539
-rw-r--r--lib/mesa/src/util/tests/cache/meson.build34
-rw-r--r--lib/mesa/src/util/tests/drirc_configdir/00-test.conf51
-rw-r--r--lib/mesa/src/util/tests/drirc_configdir/01-unused34
-rw-r--r--lib/mesa/src/util/tests/drirc_home/.drirc32
-rw-r--r--lib/mesa/src/util/tests/fast_idiv_by_const/meson.build3
-rw-r--r--lib/mesa/src/util/tests/fast_urem_by_const/meson.build2
-rw-r--r--lib/mesa/src/util/tests/format/meson.build2
-rw-r--r--lib/mesa/src/util/tests/format/u_format_test.c127
-rw-r--r--lib/mesa/src/util/tests/hash_table/clear.c16
-rw-r--r--lib/mesa/src/util/tests/hash_table/collision.c13
-rw-r--r--lib/mesa/src/util/tests/hash_table/random_entry.c2
-rw-r--r--lib/mesa/src/util/tests/set/meson.build2
-rw-r--r--lib/mesa/src/util/tests/set/set_test.cpp29
-rw-r--r--lib/mesa/src/util/tests/sparse_array/meson.build3
-rw-r--r--lib/mesa/src/util/tests/sparse_array/multi_threaded.c2
-rw-r--r--lib/mesa/src/util/tests/string_buffer/meson.build2
-rw-r--r--lib/mesa/src/util/tests/timespec/meson.build2
-rw-r--r--lib/mesa/src/util/tests/vector/meson.build2
-rw-r--r--lib/mesa/src/util/tests/vma/vma_random_test.cpp5
-rw-r--r--lib/mesa/src/util/tests/xmlconfig.cpp255
21 files changed, 1098 insertions, 59 deletions
diff --git a/lib/mesa/src/util/tests/cache/cache_test.c b/lib/mesa/src/util/tests/cache/cache_test.c
new file mode 100644
index 000000000..ec1587daa
--- /dev/null
+++ b/lib/mesa/src/util/tests/cache/cache_test.c
@@ -0,0 +1,539 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/* A collection of unit tests for cache.c */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <ftw.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "util/mesa-sha1.h"
+#include "util/disk_cache.h"
+
+bool error = false;
+
+#ifdef ENABLE_SHADER_CACHE
+
+static void
+expect_true(bool result, const char *test)
+{
+ if (!result) {
+ fprintf(stderr, "Error: Test '%s' failed: Expected=true"
+ ", Actual=false\n", test);
+ error = true;
+ }
+}
+static void
+expect_false(bool result, const char *test)
+{
+ if (result) {
+ fprintf(stderr, "Error: Test '%s' failed: Expected=false"
+ ", Actual=true\n", test);
+ error = true;
+ }
+}
+
+static void
+expect_equal(uint64_t actual, uint64_t expected, const char *test)
+{
+ if (actual != expected) {
+ fprintf(stderr, "Error: Test '%s' failed: Expected=%" PRIu64
+ ", Actual=%" PRIu64 "\n",
+ test, expected, actual);
+ error = true;
+ }
+}
+
+static void
+expect_null(void *ptr, const char *test)
+{
+ if (ptr != NULL) {
+ fprintf(stderr, "Error: Test '%s' failed: Result=%p, but expected NULL.\n",
+ test, ptr);
+ error = true;
+ }
+}
+
+static void
+expect_non_null(void *ptr, const char *test)
+{
+ if (ptr == NULL) {
+ fprintf(stderr, "Error: Test '%s' failed: Result=NULL, but expected something else.\n",
+ test);
+ error = true;
+ }
+}
+
+static void
+expect_equal_str(const char *actual, const char *expected, const char *test)
+{
+ if (strcmp(actual, expected)) {
+ fprintf(stderr, "Error: Test '%s' failed:\n\t"
+ "Expected=\"%s\", Actual=\"%s\"\n",
+ test, expected, actual);
+ error = true;
+ }
+}
+
+/* Callback for nftw used in rmrf_local below.
+ */
+static int
+remove_entry(const char *path,
+ const struct stat *sb,
+ int typeflag,
+ struct FTW *ftwbuf)
+{
+ int err = remove(path);
+
+ if (err)
+ fprintf(stderr, "Error removing %s: %s\n", path, strerror(errno));
+
+ return err;
+}
+
+/* Recursively remove a directory.
+ *
+ * This is equivalent to "rm -rf <dir>" with one bit of protection
+ * that the directory name must begin with "." to ensure we don't
+ * wander around deleting more than intended.
+ *
+ * Returns 0 on success, -1 on any error.
+ */
+static int
+rmrf_local(const char *path)
+{
+ if (path == NULL || *path == '\0' || *path != '.')
+ return -1;
+
+ return nftw(path, remove_entry, 64, FTW_DEPTH | FTW_PHYS);
+}
+
+static void
+check_directories_created(const char *cache_dir)
+{
+ bool sub_dirs_created = false;
+
+ char buf[PATH_MAX];
+ if (getcwd(buf, PATH_MAX)) {
+ char *full_path = NULL;
+ if (asprintf(&full_path, "%s%s", buf, ++cache_dir) != -1 ) {
+ struct stat sb;
+ if (stat(full_path, &sb) != -1 && S_ISDIR(sb.st_mode))
+ sub_dirs_created = true;
+
+ free(full_path);
+ }
+ }
+
+ expect_true(sub_dirs_created, "create sub dirs");
+}
+
+static bool
+does_cache_contain(struct disk_cache *cache, const cache_key key)
+{
+ void *result;
+
+ result = disk_cache_get(cache, key, NULL);
+
+ if (result) {
+ free(result);
+ return true;
+ }
+
+ return false;
+}
+
+static bool
+cache_exists(struct disk_cache *cache)
+{
+ uint8_t key[20];
+ char data[] = "some test data";
+
+ if (!cache)
+ return NULL;
+
+ disk_cache_compute_key(cache, data, sizeof(data), key);
+ disk_cache_put(cache, key, data, sizeof(data), NULL);
+ disk_cache_wait_for_idle(cache);
+ void *result = disk_cache_get(cache, key, NULL);
+
+ free(result);
+ return result != NULL;
+}
+
+#define CACHE_TEST_TMP "./cache-test-tmp"
+
+static void
+test_disk_cache_create(void)
+{
+ struct disk_cache *cache;
+ int err;
+
+ /* Before doing anything else, ensure that with
+ * MESA_GLSL_CACHE_DISABLE set to true, that disk_cache_create returns NULL.
+ */
+ setenv("MESA_GLSL_CACHE_DISABLE", "true", 1);
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set");
+
+ unsetenv("MESA_GLSL_CACHE_DISABLE");
+
+#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
+ /* With SHADER_CACHE_DISABLE_BY_DEFAULT, ensure that with
+ * MESA_GLSL_CACHE_DISABLE set to nothing, disk_cache_create returns NULL.
+ */
+ unsetenv("MESA_GLSL_CACHE_DISABLE");
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE unset "
+ " and SHADER_CACHE_DISABLE_BY_DEFAULT build option");
+
+ /* For remaining tests, ensure that the cache is enabled. */
+ setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
+#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
+
+ /* For the first real disk_cache_create() clear these environment
+ * variables to test creation of cache in home directory.
+ */
+ unsetenv("MESA_GLSL_CACHE_DIR");
+ unsetenv("XDG_CACHE_HOME");
+
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_non_null(cache, "disk_cache_create with no environment variables");
+
+ disk_cache_destroy(cache);
+
+#ifdef ANDROID
+ /* Android doesn't try writing to disk (just calls the cache callbacks), so
+ * the directory tests below don't apply.
+ */
+ exit(error ? 1 : 0);
+#endif
+
+ /* Test with XDG_CACHE_HOME set */
+ setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_false(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME set "
+ "with a non-existing parent directory");
+
+ err = mkdir(CACHE_TEST_TMP, 0755);
+ if (err != 0) {
+ fprintf(stderr, "Error creating %s: %s\n", CACHE_TEST_TMP, strerror(errno));
+ error = true;
+ return;
+ }
+ disk_cache_destroy(cache);
+
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_true(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME "
+ "set");
+
+ check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/"
+ CACHE_DIR_NAME);
+
+ disk_cache_destroy(cache);
+
+ /* Test with MESA_GLSL_CACHE_DIR set */
+ err = rmrf_local(CACHE_TEST_TMP);
+ expect_equal(err, 0, "Removing " CACHE_TEST_TMP);
+
+ setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_false(cache_exists(cache), "disk_cache_create with MESA_GLSL_CACHE_DIR"
+ " set with a non-existing parent directory");
+
+ err = mkdir(CACHE_TEST_TMP, 0755);
+ if (err != 0) {
+ fprintf(stderr, "Error creating %s: %s\n", CACHE_TEST_TMP, strerror(errno));
+ error = true;
+ return;
+ }
+ disk_cache_destroy(cache);
+
+ cache = disk_cache_create("test", "make_check", 0);
+ expect_true(cache_exists(cache), "disk_cache_create with "
+ "MESA_GLSL_CACHE_DIR set");
+
+ check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/"
+ CACHE_DIR_NAME);
+
+ disk_cache_destroy(cache);
+}
+
+static void
+test_put_and_get(void)
+{
+ struct disk_cache *cache;
+ char blob[] = "This is a blob of thirty-seven bytes";
+ uint8_t blob_key[20];
+ char string[] = "While this string has thirty-four";
+ uint8_t string_key[20];
+ char *result;
+ size_t size;
+ uint8_t *one_KB, *one_MB;
+ uint8_t one_KB_key[20], one_MB_key[20];
+ int count;
+
+#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
+ setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
+#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
+
+ cache = disk_cache_create("test", "make_check", 0);
+
+ disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
+
+ /* Ensure that disk_cache_get returns nothing before anything is added. */
+ result = disk_cache_get(cache, blob_key, &size);
+ expect_null(result, "disk_cache_get with non-existent item (pointer)");
+ expect_equal(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 = disk_cache_get(cache, blob_key, &size);
+ expect_equal_str(blob, result, "disk_cache_get of existing item (pointer)");
+ expect_equal(size, sizeof(blob), "disk_cache_get of existing item (size)");
+
+ free(result);
+
+ /* Test put and get of a second item. */
+ disk_cache_compute_key(cache, string, sizeof(string), string_key);
+ disk_cache_put(cache, string_key, string, sizeof(string), NULL);
+
+ /* disk_cache_put() hands things off to a thread so wait for it. */
+ disk_cache_wait_for_idle(cache);
+
+ result = disk_cache_get(cache, string_key, &size);
+ expect_equal_str(result, string, "2nd disk_cache_get of existing item (pointer)");
+ expect_equal(size, sizeof(string), "2nd disk_cache_get of existing item (size)");
+
+ free(result);
+
+ /* Set the cache size to 1KB and add a 1KB item to force an eviction. */
+ disk_cache_destroy(cache);
+
+ setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
+ cache = disk_cache_create("test", "make_check", 0);
+
+ one_KB = calloc(1, 1024);
+
+ /* Obviously the SHA-1 hash of 1024 zero bytes isn't particularly
+ * interesting. But we do have want to take some special care with
+ * the hash we use here. The issue is that in this artificial case,
+ * (with only three files in the cache), the probability is good
+ * that each of the three files will end up in their own
+ * directory. Then, if the directory containing the .tmp file for
+ * the new item being added for disk_cache_put() is the chosen victim
+ * directory for eviction, then no suitable file will be found and
+ * nothing will be evicted.
+ *
+ * That's actually expected given how the eviction code is
+ * implemented, (which expects to only evict once things are more
+ * interestingly full than that).
+ *
+ * For this test, we force this signature to land in the same
+ * directory as the original blob first written to the cache.
+ */
+ disk_cache_compute_key(cache, one_KB, 1024, one_KB_key);
+ one_KB_key[0] = blob_key[0];
+
+ disk_cache_put(cache, one_KB_key, one_KB, 1024, NULL);
+
+ free(one_KB);
+
+ /* disk_cache_put() hands things off to a thread so wait for it. */
+ disk_cache_wait_for_idle(cache);
+
+ result = disk_cache_get(cache, one_KB_key, &size);
+ expect_non_null(result, "3rd disk_cache_get of existing item (pointer)");
+ expect_equal(size, 1024, "3rd disk_cache_get of existing item (size)");
+
+ free(result);
+
+ /* Ensure eviction happened by checking that both of the previous
+ * cache itesm were evicted.
+ */
+ bool contains_1KB_file = false;
+ count = 0;
+ if (does_cache_contain(cache, blob_key))
+ count++;
+
+ if (does_cache_contain(cache, string_key))
+ count++;
+
+ if (does_cache_contain(cache, one_KB_key)) {
+ count++;
+ contains_1KB_file = true;
+ }
+
+ expect_true(contains_1KB_file,
+ "disk_cache_put eviction last file == MAX_SIZE (1KB)");
+ expect_equal(count, 1, "disk_cache_put eviction with MAX_SIZE=1K");
+
+ /* Now increase the size to 1M, add back both items, and ensure all
+ * three that have been added are available via disk_cache_get.
+ */
+ disk_cache_destroy(cache);
+
+ setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
+ cache = disk_cache_create("test", "make_check", 0);
+
+ disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
+ disk_cache_put(cache, string_key, string, sizeof(string), NULL);
+
+ /* disk_cache_put() hands things off to a thread so wait for it. */
+ disk_cache_wait_for_idle(cache);
+
+ count = 0;
+ if (does_cache_contain(cache, blob_key))
+ count++;
+
+ if (does_cache_contain(cache, string_key))
+ count++;
+
+ if (does_cache_contain(cache, one_KB_key))
+ count++;
+
+ expect_equal(count, 3, "no eviction before overflow with MAX_SIZE=1M");
+
+ /* Finally, check eviction again after adding an object of size 1M. */
+ one_MB = calloc(1024, 1024);
+
+ disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key);
+ one_MB_key[0] = blob_key[0];
+
+ disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024, NULL);
+
+ free(one_MB);
+
+ /* disk_cache_put() hands things off to a thread so wait for it. */
+ disk_cache_wait_for_idle(cache);
+
+ bool contains_1MB_file = false;
+ count = 0;
+ if (does_cache_contain(cache, blob_key))
+ count++;
+
+ if (does_cache_contain(cache, string_key))
+ count++;
+
+ if (does_cache_contain(cache, one_KB_key))
+ count++;
+
+ if (does_cache_contain(cache, one_MB_key)) {
+ count++;
+ contains_1MB_file = true;
+ }
+
+ expect_true(contains_1MB_file,
+ "disk_cache_put eviction last file == MAX_SIZE (1MB)");
+ expect_equal(count, 1, "eviction after overflow with MAX_SIZE=1M");
+
+ disk_cache_destroy(cache);
+}
+
+static void
+test_put_key_and_get_key(void)
+{
+ struct disk_cache *cache;
+ bool result;
+
+ uint8_t key_a[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+ uint8_t key_b[20] = { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 33, 32, 33, 34, 35, 36, 37, 38, 39};
+ uint8_t key_a_collide[20] =
+ { 0, 1, 42, 43, 44, 45, 46, 47, 48, 49,
+ 50, 55, 52, 53, 54, 55, 56, 57, 58, 59};
+
+#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
+ setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
+#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
+
+ cache = disk_cache_create("test", "make_check", 0);
+
+ /* First test that disk_cache_has_key returns false before disk_cache_put_key */
+ result = disk_cache_has_key(cache, key_a);
+ expect_equal(result, 0, "disk_cache_has_key before key added");
+
+ /* Then a couple of tests of disk_cache_put_key followed by disk_cache_has_key */
+ disk_cache_put_key(cache, key_a);
+ result = disk_cache_has_key(cache, key_a);
+ expect_equal(result, 1, "disk_cache_has_key after key added");
+
+ disk_cache_put_key(cache, key_b);
+ result = disk_cache_has_key(cache, key_b);
+ expect_equal(result, 1, "2nd disk_cache_has_key after key added");
+
+ /* Test that a key with the same two bytes as an existing key
+ * forces an eviction.
+ */
+ disk_cache_put_key(cache, key_a_collide);
+ result = disk_cache_has_key(cache, key_a_collide);
+ expect_equal(result, 1, "put_key of a colliding key lands in the cache");
+
+ result = disk_cache_has_key(cache, key_a);
+ expect_equal(result, 0, "put_key of a colliding key evicts from the cache");
+
+ /* And finally test that we can re-add the original key to re-evict
+ * the colliding key.
+ */
+ disk_cache_put_key(cache, key_a);
+ result = disk_cache_has_key(cache, key_a);
+ expect_equal(result, 1, "put_key of original key lands again");
+
+ result = disk_cache_has_key(cache, key_a_collide);
+ expect_equal(result, 0, "put_key of orginal key evicts the colliding key");
+
+ disk_cache_destroy(cache);
+}
+#endif /* ENABLE_SHADER_CACHE */
+
+int
+main(void)
+{
+#ifdef ENABLE_SHADER_CACHE
+ int err;
+
+ test_disk_cache_create();
+
+ test_put_and_get();
+
+ test_put_key_and_get_key();
+
+ err = rmrf_local(CACHE_TEST_TMP);
+ expect_equal(err, 0, "Removing " CACHE_TEST_TMP " again");
+#endif /* ENABLE_SHADER_CACHE */
+
+ return error ? 1 : 0;
+}
diff --git a/lib/mesa/src/util/tests/cache/meson.build b/lib/mesa/src/util/tests/cache/meson.build
new file mode 100644
index 000000000..3a8fd213e
--- /dev/null
+++ b/lib/mesa/src/util/tests/cache/meson.build
@@ -0,0 +1,34 @@
+# Copyright © 2017 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+if with_shader_cache
+ test(
+ 'cache',
+ executable(
+ 'cache_test',
+ 'cache_test.c',
+ c_args : [c_msvc_compat_args, no_override_init_args],
+ gnu_symbol_visibility : 'hidden',
+ include_directories : [inc_include, inc_src],
+ dependencies : [dep_clock, dep_thread, idep_gtest, idep_mesautil],
+ ),
+ suite : ['util'],
+ )
+endif
diff --git a/lib/mesa/src/util/tests/drirc_configdir/00-test.conf b/lib/mesa/src/util/tests/drirc_configdir/00-test.conf
new file mode 100644
index 000000000..fcc720877
--- /dev/null
+++ b/lib/mesa/src/util/tests/drirc_configdir/00-test.conf
@@ -0,0 +1,51 @@
+<?xml version="1.0" standalone="yes"?>
+<!DOCTYPE driconf [
+ <!ELEMENT driconf (device+)>
+ <!ELEMENT device (application | engine)+>
+ <!ATTLIST device driver CDATA #IMPLIED>
+ <!ELEMENT application (option+)>
+ <!ATTLIST application name CDATA #REQUIRED
+ executable CDATA #IMPLIED
+ sha1 CDATA #IMPLIED
+ application_name_match CDATA #IMPLIED
+ application_versions CDATA #IMPLIED>
+ <!ELEMENT engine (option+)>
+
+ <!-- engine_name_match: A regexp matching the engine name -->
+ <!-- engine_versions: A version in range format
+ (version 1 to 4 : "1:4") -->
+
+ <!ATTLIST engine engine_name_match CDATA #REQUIRED
+ engine_versions CDATA #REQUIRED>
+
+ <!ELEMENT option EMPTY>
+ <!ATTLIST option name CDATA #REQUIRED
+ value CDATA #REQUIRED>
+]>
+
+<driconf>
+ <device>
+ <application name="Application 1" executable="app1">
+ <option name="mesa_drirc_option" value="1" />
+ </application>
+
+ <application name="Application 2" executable="app2">
+ <option name="mesa_drirc_option" value="2" />
+ </application>
+
+ <application name="Application 2" application_name_match="Versioned App.*" application_versions="0:1">
+ <option name="mesa_drirc_option" value="3" />
+ </application>
+
+ <application name="Application 2" application_name_match="Versioned App.*" application_versions="2:3">
+ <option name="mesa_drirc_option" value="4" />
+ </application>
+
+ <engine engine_name_match="Versioned Engine.*" engine_versions="0:1">
+ <option name="mesa_drirc_option" value="5" />
+ </engine>
+ <engine engine_name_match="Versioned Engine.*" engine_versions="2:3">
+ <option name="mesa_drirc_option" value="6" />
+ </engine>
+ </device>
+</driconf>
diff --git a/lib/mesa/src/util/tests/drirc_configdir/01-unused b/lib/mesa/src/util/tests/drirc_configdir/01-unused
new file mode 100644
index 000000000..dfdc4eb75
--- /dev/null
+++ b/lib/mesa/src/util/tests/drirc_configdir/01-unused
@@ -0,0 +1,34 @@
+<?xml version="1.0" standalone="yes"?>
+<!DOCTYPE driconf [
+ <!ELEMENT driconf (device+)>
+ <!ELEMENT device (application | engine)+>
+ <!ATTLIST device driver CDATA #IMPLIED>
+ <!ELEMENT application (option+)>
+ <!ATTLIST application name CDATA #REQUIRED
+ executable CDATA #IMPLIED
+ sha1 CDATA #IMPLIED
+ application_name_match CDATA #IMPLIED
+ application_versions CDATA #IMPLIED>
+ <!ELEMENT engine (option+)>
+
+ <!-- engine_name_match: A regexp matching the engine name -->
+ <!-- engine_versions: A version in range format
+ (version 1 to 4 : "1:4") -->
+
+ <!ATTLIST engine engine_name_match CDATA #REQUIRED
+ engine_versions CDATA #REQUIRED>
+
+ <!ELEMENT option EMPTY>
+ <!ATTLIST option name CDATA #REQUIRED
+ value CDATA #REQUIRED>
+]>
+
+<!-- since this file lacks its extension, it shouldn't be parsed. -->
+
+<driconf>
+ <device>
+ <application name="Application 1" executable="app1">
+ <option name="mesa_drirc_option" value="100" />
+ </application>
+ </device>
+</driconf>
diff --git a/lib/mesa/src/util/tests/drirc_home/.drirc b/lib/mesa/src/util/tests/drirc_home/.drirc
new file mode 100644
index 000000000..695fe0e57
--- /dev/null
+++ b/lib/mesa/src/util/tests/drirc_home/.drirc
@@ -0,0 +1,32 @@
+<?xml version="1.0" standalone="yes"?>
+<!DOCTYPE driconf [
+ <!ELEMENT driconf (device+)>
+ <!ELEMENT device (application | engine)+>
+ <!ATTLIST device driver CDATA #IMPLIED>
+ <!ELEMENT application (option+)>
+ <!ATTLIST application name CDATA #REQUIRED
+ executable CDATA #IMPLIED
+ sha1 CDATA #IMPLIED
+ application_name_match CDATA #IMPLIED
+ application_versions CDATA #IMPLIED>
+ <!ELEMENT engine (option+)>
+
+ <!-- engine_name_match: A regexp matching the engine name -->
+ <!-- engine_versions: A version in range format
+ (version 1 to 4 : "1:4") -->
+
+ <!ATTLIST engine engine_name_match CDATA #REQUIRED
+ engine_versions CDATA #REQUIRED>
+
+ <!ELEMENT option EMPTY>
+ <!ATTLIST option name CDATA #REQUIRED
+ value CDATA #REQUIRED>
+]>
+
+<driconf>
+ <device>
+ <application name="Application 3" executable="app3">
+ <option name="mesa_drirc_option" value="10" />
+ </application>
+ </device>
+</driconf>
diff --git a/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build b/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
index 2a341d181..9c8c03d97 100644
--- a/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
+++ b/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
@@ -24,7 +24,8 @@ test(
'fast_idiv_by_const_test',
'fast_idiv_by_const_test.cpp',
dependencies : [idep_gtest, idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
+ timeout: 60,
)
diff --git a/lib/mesa/src/util/tests/fast_urem_by_const/meson.build b/lib/mesa/src/util/tests/fast_urem_by_const/meson.build
index a16407d5e..079309745 100644
--- a/lib/mesa/src/util/tests/fast_urem_by_const/meson.build
+++ b/lib/mesa/src/util/tests/fast_urem_by_const/meson.build
@@ -25,7 +25,7 @@ test(
'fast_urem_by_const_test',
'fast_urem_by_const_test.cpp',
dependencies : [idep_gtest, idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/format/meson.build b/lib/mesa/src/util/tests/format/meson.build
index 6f4b91cf8..761ce49ab 100644
--- a/lib/mesa/src/util/tests/format/meson.build
+++ b/lib/mesa/src/util/tests/format/meson.build
@@ -3,7 +3,7 @@ foreach t : ['srgb', 'u_format_test', 'u_format_compatible_test']
executable(
t,
'@0@.c'.format(t),
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
dependencies : idep_mesautil,
),
suite : 'format',
diff --git a/lib/mesa/src/util/tests/format/u_format_test.c b/lib/mesa/src/util/tests/format/u_format_test.c
index 69e3b5aeb..e6473c2bf 100644
--- a/lib/mesa/src/util/tests/format/u_format_test.c
+++ b/lib/mesa/src/util/tests/format/u_format_test.c
@@ -30,7 +30,8 @@
#include <stdio.h>
#include <float.h>
-#include "util/u_half.h"
+#include "util/half_float.h"
+#include "util/u_math.h"
#include "util/format/u_format.h"
#include "util/format/u_format_tests.h"
#include "util/format/u_format_s3tc.h"
@@ -201,9 +202,11 @@ print_unpacked_s_8uint(const struct util_format_description *format_desc,
static boolean
-test_format_fetch_rgba_float(const struct util_format_description *format_desc,
+test_format_fetch_rgba(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ util_format_fetch_rgba_func_ptr fetch_rgba =
+ util_format_fetch_rgba_func(format_desc->format);
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
@@ -211,7 +214,7 @@ test_format_fetch_rgba_float(const struct util_format_description *format_desc,
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
- format_desc->fetch_rgba_float(unpacked[i][j], test->packed, j, i);
+ fetch_rgba(unpacked[i][j], test->packed, j, i);
for (k = 0; k < 4; ++k) {
if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
success = FALSE;
@@ -235,16 +238,18 @@ test_format_fetch_rgba_float(const struct util_format_description *format_desc,
static boolean
-test_format_unpack_rgba_float(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
+test_format_unpack_rgba(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
+ const struct util_format_unpack_description *unpack =
+ util_format_unpack_description(format_desc->format);
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
- format_desc->unpack_rgba_float(&unpacked[0][0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
+ unpack->unpack_rgba(&unpacked[0][0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
@@ -275,6 +280,8 @@ static boolean
test_format_pack_rgba_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_pack_description *pack =
+ util_format_pack_description(format_desc->format);
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j, k;
@@ -298,7 +305,7 @@ test_format_pack_rgba_float(const struct util_format_description *format_desc,
}
}
- format_desc->pack_rgba_float(packed, 0,
+ pack->pack_rgba_float(packed, 0,
&unpacked[0][0][0], sizeof unpacked[0],
format_desc->block.width, format_desc->block.height);
@@ -354,12 +361,17 @@ static boolean
test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_unpack_description *unpack =
+ util_format_unpack_description(format_desc->format);
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
- format_desc->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0],
+ if (util_format_is_pure_integer(format_desc->format))
+ return FALSE;
+
+ unpack->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0],
test->packed, 0,
format_desc->block.width, format_desc->block.height);
@@ -393,6 +405,8 @@ static boolean
test_format_pack_rgba_8unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_pack_description *pack =
+ util_format_pack_description(format_desc->format);
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i;
@@ -416,9 +430,9 @@ test_format_pack_rgba_8unorm(const struct util_format_description *format_desc,
memset(packed, 0, sizeof packed);
- format_desc->pack_rgba_8unorm(packed, 0,
- &unpacked[0][0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
+ pack->pack_rgba_8unorm(packed, 0,
+ &unpacked[0][0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
@@ -455,13 +469,15 @@ static boolean
test_format_unpack_z_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_unpack_description *unpack =
+ util_format_unpack_description(format_desc->format);
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
unsigned i, j;
boolean success;
- format_desc->unpack_z_float(&unpacked[0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
+ unpack->unpack_z_float(&unpacked[0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
@@ -485,6 +501,8 @@ static boolean
test_format_pack_z_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_pack_description *pack =
+ util_format_pack_description(format_desc->format);
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j;
@@ -500,9 +518,9 @@ test_format_pack_z_float(const struct util_format_description *format_desc,
}
}
- format_desc->pack_z_float(packed, 0,
- &unpacked[0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
+ pack->pack_z_float(packed, 0,
+ &unpacked[0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
@@ -522,14 +540,16 @@ static boolean
test_format_unpack_z_32unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_unpack_description *unpack =
+ util_format_unpack_description(format_desc->format);
uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
uint32_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
unsigned i, j;
boolean success;
- format_desc->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
+ unpack->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
@@ -559,6 +579,8 @@ static boolean
test_format_pack_z_32unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_pack_description *pack =
+ util_format_pack_description(format_desc->format);
uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j;
@@ -575,9 +597,9 @@ test_format_pack_z_32unorm(const struct util_format_description *format_desc,
memset(packed, 0, sizeof packed);
- format_desc->pack_z_32unorm(packed, 0,
- &unpacked[0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
+ pack->pack_z_32unorm(packed, 0,
+ &unpacked[0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
@@ -597,14 +619,16 @@ static boolean
test_format_unpack_s_8uint(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_unpack_description *unpack =
+ util_format_unpack_description(format_desc->format);
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
unsigned i, j;
boolean success;
- format_desc->unpack_s_8uint(&unpacked[0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
+ unpack->unpack_s_8uint(&unpacked[0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
@@ -634,6 +658,8 @@ static boolean
test_format_pack_s_8uint(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
+ const struct util_format_pack_description *pack =
+ util_format_pack_description(format_desc->format);
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j;
@@ -650,9 +676,9 @@ test_format_pack_s_8uint(const struct util_format_description *format_desc,
memset(packed, 0, sizeof packed);
- format_desc->pack_s_8uint(packed, 0,
- &unpacked[0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
+ pack->pack_s_8uint(packed, 0,
+ &unpacked[0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
@@ -774,8 +800,15 @@ test_all(void)
assert(format_desc->block.height <= UTIL_FORMAT_MAX_UNPACKED_HEIGHT);
assert(format_desc->block.width <= UTIL_FORMAT_MAX_UNPACKED_WIDTH);
-# define TEST_ONE_FUNC(name) \
- if (format_desc->name) { \
+# define TEST_ONE_PACK_FUNC(name) \
+ if (util_format_pack_description(format)->name) { \
+ if (!test_one_func(format_desc, &test_format_##name, #name)) { \
+ success = FALSE; \
+ } \
+ }
+
+# define TEST_ONE_UNPACK_FUNC(name) \
+ if (util_format_unpack_description(format)->name) { \
if (!test_one_func(format_desc, &test_format_##name, #name)) { \
success = FALSE; \
} \
@@ -786,18 +819,22 @@ test_all(void)
success = FALSE; \
} \
- TEST_ONE_FUNC(fetch_rgba_float);
- TEST_ONE_FUNC(pack_rgba_float);
- TEST_ONE_FUNC(unpack_rgba_float);
- TEST_ONE_FUNC(pack_rgba_8unorm);
- TEST_ONE_FUNC(unpack_rgba_8unorm);
+ if (util_format_fetch_rgba_func(format)) {
+ if (!test_one_func(format_desc, test_format_fetch_rgba, "fetch_rgba"))
+ success = FALSE;
+ }
+
+ TEST_ONE_PACK_FUNC(pack_rgba_float);
+ TEST_ONE_UNPACK_FUNC(unpack_rgba);
+ TEST_ONE_PACK_FUNC(pack_rgba_8unorm);
+ TEST_ONE_UNPACK_FUNC(unpack_rgba_8unorm);
- TEST_ONE_FUNC(unpack_z_32unorm);
- TEST_ONE_FUNC(pack_z_32unorm);
- TEST_ONE_FUNC(unpack_z_float);
- TEST_ONE_FUNC(pack_z_float);
- TEST_ONE_FUNC(unpack_s_8uint);
- TEST_ONE_FUNC(pack_s_8uint);
+ TEST_ONE_UNPACK_FUNC(unpack_z_32unorm);
+ TEST_ONE_PACK_FUNC(pack_z_32unorm);
+ TEST_ONE_UNPACK_FUNC(unpack_z_float);
+ TEST_ONE_PACK_FUNC(pack_z_float);
+ TEST_ONE_UNPACK_FUNC(unpack_s_8uint);
+ TEST_ONE_PACK_FUNC(pack_s_8uint);
TEST_FORMAT_METADATA(norm_flags);
@@ -813,6 +850,8 @@ int main(int argc, char **argv)
{
boolean success;
+ util_cpu_detect();
+
success = test_all();
return success ? 0 : 1;
diff --git a/lib/mesa/src/util/tests/hash_table/clear.c b/lib/mesa/src/util/tests/hash_table/clear.c
index e61f60ece..eaa316ff0 100644
--- a/lib/mesa/src/util/tests/hash_table/clear.c
+++ b/lib/mesa/src/util/tests/hash_table/clear.c
@@ -86,6 +86,22 @@ int main()
hash_table_foreach(ht, entry) {
assert(key_id(entry->key) < SIZE);
}
+ _mesa_hash_table_clear(ht, NULL);
+ assert(!ht->entries);
+ assert(!ht->deleted_entries);
+ hash_table_foreach(ht, entry) {
+ assert(0);
+ }
+
+ for (i = 0; i < SIZE; ++i) {
+ flags[i] = false;
+ _mesa_hash_table_insert(ht, make_key(i), &flags[i]);
+ }
+ hash_table_foreach_remove(ht, entry) {
+ assert(key_id(entry->key) < SIZE);
+ }
+ assert(!ht->entries);
+ assert(!ht->deleted_entries);
_mesa_hash_table_destroy(ht, NULL);
diff --git a/lib/mesa/src/util/tests/hash_table/collision.c b/lib/mesa/src/util/tests/hash_table/collision.c
index c7f8569c2..40143e81a 100644
--- a/lib/mesa/src/util/tests/hash_table/collision.c
+++ b/lib/mesa/src/util/tests/hash_table/collision.c
@@ -32,13 +32,18 @@
#include <assert.h>
#include "hash_table.h"
+static void entry_free(struct hash_entry *entry)
+{
+ free((void *)entry->key);
+}
+
int
main(int argc, char **argv)
{
struct hash_table *ht;
- const char *str1 = "test1";
- const char *str2 = "test2";
- const char *str3 = "test3";
+ const char *str1 = strdup("test1");
+ const char *str2 = strdup("test2");
+ const char *str3 = strdup("test3");
struct hash_entry *entry1, *entry2;
uint32_t bad_hash = 5;
int i;
@@ -91,7 +96,7 @@ main(int argc, char **argv)
entry2 = _mesa_hash_table_search_pre_hashed(ht, bad_hash, str2);
assert(entry2->key == str2);
- _mesa_hash_table_destroy(ht, NULL);
+ _mesa_hash_table_destroy(ht, entry_free);
return 0;
}
diff --git a/lib/mesa/src/util/tests/hash_table/random_entry.c b/lib/mesa/src/util/tests/hash_table/random_entry.c
index 4902a999d..75c4ef652 100644
--- a/lib/mesa/src/util/tests/hash_table/random_entry.c
+++ b/lib/mesa/src/util/tests/hash_table/random_entry.c
@@ -58,7 +58,7 @@ main(int argc, char **argv)
struct hash_table *ht;
struct hash_entry *entry;
uint32_t keys[SIZE];
- uint32_t i, random_value;
+ uint32_t i, random_value = 0;
(void) argc;
(void) argv;
diff --git a/lib/mesa/src/util/tests/set/meson.build b/lib/mesa/src/util/tests/set/meson.build
index 9d0d311ba..e9b00629b 100644
--- a/lib/mesa/src/util/tests/set/meson.build
+++ b/lib/mesa/src/util/tests/set/meson.build
@@ -24,7 +24,7 @@ test(
'set_test',
'set_test.cpp',
dependencies : [dep_thread, dep_dl, idep_gtest, idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/set/set_test.cpp b/lib/mesa/src/util/tests/set/set_test.cpp
index 0b4355af1..67e3085ee 100644
--- a/lib/mesa/src/util/tests/set/set_test.cpp
+++ b/lib/mesa/src/util/tests/set/set_test.cpp
@@ -51,6 +51,27 @@ TEST(set, basic)
entry = _mesa_set_search(s, a);
EXPECT_FALSE(entry);
+ _mesa_set_clear(s, NULL);
+ EXPECT_EQ(s->entries, 0);
+ EXPECT_EQ(s->deleted_entries, 0);
+ set_foreach(s, he) {
+ GTEST_FAIL();
+ }
+
+ _mesa_set_add(s, a);
+ _mesa_set_add(s, b);
+ EXPECT_EQ(s->entries, 2);
+ unsigned count = s->entries;
+ set_foreach_remove(s, he) {
+ EXPECT_TRUE(he->key == a || he->key == b);
+ EXPECT_EQ(s->entries, count--);
+ EXPECT_EQ(s->deleted_entries, 0);
+ }
+ EXPECT_EQ(s->entries, 0);
+ set_foreach(s, he) {
+ GTEST_FAIL();
+ }
+
_mesa_set_destroy(s, NULL);
}
@@ -136,12 +157,16 @@ TEST(set, search_or_add)
_mesa_set_add(s, &b);
EXPECT_EQ(s->entries, 2);
- struct set_entry *entry = _mesa_set_search_or_add(s, &c);
+ bool found = false;
+ struct set_entry *entry = _mesa_set_search_or_add(s, &c, &found);
EXPECT_EQ(entry->key, (void *)&b);
+ EXPECT_EQ(found, true);
EXPECT_EQ(s->entries, 2);
- struct set_entry *entry3 = _mesa_set_search_or_add(s, &d);
+ found = false;
+ struct set_entry *entry3 = _mesa_set_search_or_add(s, &d, &found);
EXPECT_EQ(entry3->key, &d);
+ EXPECT_EQ(found, false);
EXPECT_EQ(s->entries, 3);
_mesa_set_destroy(s, NULL);
diff --git a/lib/mesa/src/util/tests/sparse_array/meson.build b/lib/mesa/src/util/tests/sparse_array/meson.build
index 036591e3b..9afb49301 100644
--- a/lib/mesa/src/util/tests/sparse_array/meson.build
+++ b/lib/mesa/src/util/tests/sparse_array/meson.build
@@ -24,7 +24,8 @@ test(
'multi_threaded',
'multi_threaded.c',
dependencies : [idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
+ timeout: 60,
)
diff --git a/lib/mesa/src/util/tests/sparse_array/multi_threaded.c b/lib/mesa/src/util/tests/sparse_array/multi_threaded.c
index b7b4e73a1..b084ac994 100644
--- a/lib/mesa/src/util/tests/sparse_array/multi_threaded.c
+++ b/lib/mesa/src/util/tests/sparse_array/multi_threaded.c
@@ -72,6 +72,8 @@ run_test(unsigned run_idx)
uint32_t *elem = util_sparse_array_get(&arr, i);
assert(*elem == 0 || *elem == i);
}
+
+ util_sparse_array_finish(&arr);
}
int
diff --git a/lib/mesa/src/util/tests/string_buffer/meson.build b/lib/mesa/src/util/tests/string_buffer/meson.build
index b3eb2714a..acb6abca4 100644
--- a/lib/mesa/src/util/tests/string_buffer/meson.build
+++ b/lib/mesa/src/util/tests/string_buffer/meson.build
@@ -25,7 +25,7 @@ test(
'string_buffer_test.cpp',
cpp_args : [cpp_msvc_compat_args],
dependencies : [idep_gtest, idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/timespec/meson.build b/lib/mesa/src/util/tests/timespec/meson.build
index c685db5fd..2fc737a7d 100644
--- a/lib/mesa/src/util/tests/timespec/meson.build
+++ b/lib/mesa/src/util/tests/timespec/meson.build
@@ -24,7 +24,7 @@ test(
'timespec_test',
'timespec_test.cpp',
dependencies : [dep_thread, dep_dl, idep_gtest, idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/vector/meson.build b/lib/mesa/src/util/tests/vector/meson.build
index d05abc633..40ad93995 100644
--- a/lib/mesa/src/util/tests/vector/meson.build
+++ b/lib/mesa/src/util/tests/vector/meson.build
@@ -24,7 +24,7 @@ test(
'vector_test',
'vector_test.cpp',
dependencies : [idep_gtest, idep_mesautil],
- include_directories : inc_common,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/vma/vma_random_test.cpp b/lib/mesa/src/util/tests/vma/vma_random_test.cpp
index 9246176cb..44f25e47b 100644
--- a/lib/mesa/src/util/tests/vma/vma_random_test.cpp
+++ b/lib/mesa/src/util/tests/vma/vma_random_test.cpp
@@ -78,6 +78,11 @@ struct random_test {
util_vma_heap_init(&heap, MEM_START_PAGE * MEM_PAGE_SIZE, MEM_SIZE);
}
+ ~random_test()
+ {
+ util_vma_heap_finish(&heap);
+ }
+
void test(unsigned long count)
{
std::uniform_int_distribution<> one_to_thousand(1, 1000);
diff --git a/lib/mesa/src/util/tests/xmlconfig.cpp b/lib/mesa/src/util/tests/xmlconfig.cpp
new file mode 100644
index 000000000..b59c8497d
--- /dev/null
+++ b/lib/mesa/src/util/tests/xmlconfig.cpp
@@ -0,0 +1,255 @@
+/*
+ * Copyright © 2020 Google LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <gtest/gtest.h>
+#include <driconf.h>
+#include <xmlconfig.h>
+
+class xmlconfig_test : public ::testing::Test {
+protected:
+ xmlconfig_test();
+ ~xmlconfig_test();
+
+ driOptionCache drirc_init(const char *driver, const char *drm,
+ const char *exec_name,
+ const char *app, int appver,
+ const char *engine, int enginever);
+
+ driOptionCache options;
+};
+
+xmlconfig_test::xmlconfig_test()
+{
+ options = {};
+}
+
+xmlconfig_test::~xmlconfig_test()
+{
+ driDestroyOptionInfo(&options);
+}
+
+/* wraps a DRI_CONF_OPT_* in the required xml bits */
+#define DRI_CONF_TEST_OPT(x) x
+
+TEST_F(xmlconfig_test, bools)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_GLSL_ZERO_INIT(false)
+ DRI_CONF_ALWAYS_HAVE_DEPTH_BUFFER(true)
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ EXPECT_EQ(driQueryOptionb(&options, "glsl_zero_init"), false);
+ EXPECT_EQ(driQueryOptionb(&options, "always_have_depth_buffer"), true);
+}
+
+TEST_F(xmlconfig_test, ints)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_OPT_I(opt, 2, 0, 999, "option")
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ EXPECT_EQ(driQueryOptioni(&options, "opt"), 2);
+}
+
+TEST_F(xmlconfig_test, floats)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_OPT_F(opt, 2.0, 1.0, 2.0, "option")
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ EXPECT_EQ(driQueryOptionf(&options, "opt"), 2.0);
+}
+
+TEST_F(xmlconfig_test, enums)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1)
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ EXPECT_EQ(driQueryOptioni(&options, "vblank_mode"), DRI_CONF_VBLANK_DEF_INTERVAL_1);
+}
+
+TEST_F(xmlconfig_test, string)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_OPT_S(opt, value, "option")
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ EXPECT_STREQ(driQueryOptionstr(&options, "opt"), "value");
+}
+
+TEST_F(xmlconfig_test, check_option)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_GLSL_ZERO_INIT(true)
+ DRI_CONF_ALWAYS_HAVE_DEPTH_BUFFER(true)
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ EXPECT_EQ(driCheckOption(&options, "glsl_zero_init", DRI_BOOL), true);
+
+ EXPECT_EQ(driCheckOption(&options, "glsl_zero_init", DRI_ENUM), false);
+ EXPECT_EQ(driCheckOption(&options, "glsl_zero_init", DRI_INT), false);
+ EXPECT_EQ(driCheckOption(&options, "glsl_zero_init", DRI_FLOAT), false);
+ EXPECT_EQ(driCheckOption(&options, "glsl_zero_init", DRI_STRING), false);
+
+ EXPECT_EQ(driCheckOption(&options, "not_present", DRI_BOOL), false);
+}
+
+TEST_F(xmlconfig_test, copy_cache)
+{
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_OPT_B(mesa_b_option, true, "description")
+ DRI_CONF_OPT_S(mesa_s_option, value, "description")
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ driOptionCache cache;
+
+ /* This tries to parse user config files. We've called our option
+ * "mesa_test_option" so the test shouldn't end up with something from the
+ * user's homedir/environment that would override us.
+ */
+ driParseConfigFiles(&cache, &options,
+ 0, "driver", "drm",
+ NULL, 0,
+ NULL, 0);
+
+ /* Can we inspect the cache? */
+ EXPECT_EQ(driCheckOption(&cache, "mesa_b_option", DRI_BOOL), true);
+ EXPECT_EQ(driCheckOption(&cache, "mesa_s_option", DRI_STRING), true);
+ EXPECT_EQ(driCheckOption(&cache, "mesa_test_unknown_option", DRI_BOOL), false);
+
+ /* Did the value get copied? */
+ EXPECT_EQ(driQueryOptionb(&cache, "mesa_b_option"), true);
+ EXPECT_STREQ(driQueryOptionstr(&cache, "mesa_s_option"), "value");
+
+ driDestroyOptionCache(&cache);
+}
+
+driOptionCache
+xmlconfig_test::drirc_init(const char *driver, const char *drm,
+ const char *exec_name,
+ const char *app, int appver,
+ const char *engine, int enginever)
+{
+ /* Make the parser look in the directory of config files for the test,
+ * passed in by meson.build.
+ */
+ driInjectDataDir(getenv("DRIRC_CONFIGDIR"));
+
+ driInjectExecName(exec_name);
+
+ driOptionDescription driconf[] = {
+ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_OPT_I(mesa_drirc_option, 0, 0, 200, "description")
+ };
+ driParseOptionInfo(&options, driconf, ARRAY_SIZE(driconf));
+
+ driOptionCache cache;
+
+ /* This should parse the "user" drirc files under ./tests/drirc_test/,
+ * based on the setting of $HOME by meson.build.
+ */
+ driParseConfigFiles(&cache, &options,
+ 0, driver, drm,
+ app, appver,
+ engine, enginever);
+
+ return cache;
+}
+
+TEST_F(xmlconfig_test, drirc_app)
+{
+ driOptionCache cache = drirc_init("driver", "drm",
+ "app1",
+ NULL, 0,
+ NULL, 0);
+#if WITH_XMLCONFIG
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 1);
+#else
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 0);
+#endif
+ driDestroyOptionCache(&cache);
+}
+
+TEST_F(xmlconfig_test, drirc_user_app)
+{
+ driOptionCache cache = drirc_init("driver", "drm",
+ "app3",
+ NULL, 0,
+ NULL, 0);
+#if WITH_XMLCONFIG
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 10);
+#else
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 0);
+#endif
+ driDestroyOptionCache(&cache);
+}
+
+TEST_F(xmlconfig_test, drirc_env_override)
+{
+ setenv("mesa_drirc_option", "7", 1);
+ driOptionCache cache = drirc_init("driver", "drm",
+ "app1",
+ NULL, 0,
+ NULL, 0);
+ /* env var takes precedence over config files */
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 7);
+ unsetenv("mesa_drirc_option");
+ driDestroyOptionCache(&cache);
+}
+
+#if WITH_XMLCONFIG
+TEST_F(xmlconfig_test, drirc_app_versioned)
+{
+ driOptionCache cache = drirc_init("driver", "drm",
+ NULL,
+ "Versioned App Name", 1,
+ NULL, 0);
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 3);
+ driDestroyOptionCache(&cache);
+}
+
+TEST_F(xmlconfig_test, drirc_engine_versioned)
+{
+ driOptionCache cache = drirc_init("driver", "drm",
+ NULL,
+ "unknownapp", 0,
+ "Versioned Engine Name", 1);
+ EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 5);
+ driDestroyOptionCache(&cache);
+}
+#endif