summaryrefslogtreecommitdiff
path: root/lib/mesa/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mesa/src/util')
-rw-r--r--lib/mesa/src/util/bitscan.h43
-rw-r--r--lib/mesa/src/util/bitset_test.cpp129
-rw-r--r--lib/mesa/src/util/blob_test.c328
-rw-r--r--lib/mesa/src/util/crc32.c134
-rw-r--r--lib/mesa/src/util/crc32.h4
-rw-r--r--lib/mesa/src/util/disk_cache.c16
-rw-r--r--lib/mesa/src/util/hash_table.c11
-rw-r--r--lib/mesa/src/util/hash_table.h3
-rw-r--r--lib/mesa/src/util/list.h12
-rw-r--r--lib/mesa/src/util/macros.h14
-rw-r--r--lib/mesa/src/util/mesa-sha1.c34
-rw-r--r--lib/mesa/src/util/mesa-sha1.h10
-rw-r--r--lib/mesa/src/util/mesa-sha1_test.c65
-rw-r--r--lib/mesa/src/util/meson.build181
-rw-r--r--lib/mesa/src/util/process_test.c97
-rw-r--r--lib/mesa/src/util/rb_tree_test.c229
-rw-r--r--lib/mesa/src/util/register_allocate_test.cpp211
-rw-r--r--lib/mesa/src/util/roundeven_test.c140
-rw-r--r--lib/mesa/src/util/set.c2
-rw-r--r--lib/mesa/src/util/sha1/README2
-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/fast_idiv_by_const/fast_idiv_by_const_test.cpp472
-rw-r--r--lib/mesa/src/util/tests/fast_idiv_by_const/meson.build30
-rw-r--r--lib/mesa/src/util/tests/fast_urem_by_const/fast_urem_by_const_test.cpp99
-rw-r--r--lib/mesa/src/util/tests/fast_urem_by_const/meson.build31
-rw-r--r--lib/mesa/src/util/tests/set/meson.build30
-rw-r--r--lib/mesa/src/util/tests/set/set_test.cpp115
-rw-r--r--lib/mesa/src/util/tests/sparse_array/meson.build31
-rw-r--r--lib/mesa/src/util/tests/sparse_array/multi_threaded.c84
-rw-r--r--lib/mesa/src/util/tests/string_buffer/meson.build30
-rw-r--r--lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp122
-rw-r--r--lib/mesa/src/util/tests/timespec/meson.build30
-rw-r--r--lib/mesa/src/util/tests/timespec/timespec_test.cpp292
-rw-r--r--lib/mesa/src/util/tests/vector/meson.build30
-rw-r--r--lib/mesa/src/util/tests/vector/vector_test.cpp101
-rw-r--r--lib/mesa/src/util/u_atomic.h8
-rw-r--r--lib/mesa/src/util/u_atomic_test.c162
-rw-r--r--lib/mesa/src/util/u_cpu_detect.c8
-rw-r--r--lib/mesa/src/util/u_debug_stack.c7
-rw-r--r--lib/mesa/src/util/u_debug_stack_test.cpp115
-rw-r--r--lib/mesa/src/util/u_dynarray.h10
-rw-r--r--lib/mesa/src/util/u_endian.h10
-rw-r--r--lib/mesa/src/util/u_printf.cpp54
-rw-r--r--lib/mesa/src/util/u_qsort_test.cpp53
-rw-r--r--lib/mesa/src/util/u_queue.c5
-rw-r--r--lib/mesa/src/util/u_thread.h29
-rw-r--r--lib/mesa/src/util/u_vector.h12
-rw-r--r--lib/mesa/src/util/xmlconfig.c44
-rw-r--r--lib/mesa/src/util/xmlconfig.h8
50 files changed, 357 insertions, 3903 deletions
diff --git a/lib/mesa/src/util/bitscan.h b/lib/mesa/src/util/bitscan.h
index 105b7ba31..726d2d2c3 100644
--- a/lib/mesa/src/util/bitscan.h
+++ b/lib/mesa/src/util/bitscan.h
@@ -349,8 +349,49 @@ util_bitcount64(uint64_t n)
#endif
}
+/**
+ * Widens the given bit mask by a multiplier, meaning that it will
+ * replicate each bit by that amount.
+ *
+ * For example:
+ * 0b101 widened by 2 will become: 0b110011
+ *
+ * This is typically used in shader I/O to transform a 64-bit
+ * writemask to a 32-bit writemask.
+ */
+static inline uint32_t
+util_widen_mask(uint32_t mask, unsigned multiplier)
+{
+ uint32_t new_mask = 0;
+ u_foreach_bit(i, mask)
+ new_mask |= ((1u << multiplier) - 1u) << (i * multiplier);
+ return new_mask;
+}
+
#ifdef __cplusplus
}
-#endif
+
+/* util_bitcount has large measurable overhead (~2%), so it's recommended to
+ * use the POPCNT instruction via inline assembly if the CPU supports it.
+ */
+enum util_popcnt {
+ POPCNT_NO,
+ POPCNT_YES,
+};
+
+/* Convenient function to select popcnt through a C++ template argument.
+ * This should be used as part of larger functions that are optimized
+ * as a whole.
+ */
+template<util_popcnt POPCNT> inline unsigned
+util_bitcount_fast(unsigned n)
+{
+ if (POPCNT == POPCNT_YES)
+ return util_popcnt_inline_asm(n);
+ else
+ return util_bitcount(n);
+}
+
+#endif /* __cplusplus */
#endif /* BITSCAN_H */
diff --git a/lib/mesa/src/util/bitset_test.cpp b/lib/mesa/src/util/bitset_test.cpp
deleted file mode 100644
index c848e2a79..000000000
--- a/lib/mesa/src/util/bitset_test.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright © 2019 Red Hat
- *
- * 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 "util/bitset.h"
-
-TEST(bitset, sizes)
-{
- EXPECT_EQ(sizeof(BITSET_WORD), 4);
-
- BITSET_DECLARE(mask32, 32);
- BITSET_DECLARE(mask64, 64);
- BITSET_DECLARE(mask128, 128);
-
- EXPECT_EQ(sizeof(mask32), 4);
- EXPECT_EQ(sizeof(mask64), 8);
- EXPECT_EQ(sizeof(mask128), 16);
-}
-
-TEST(bitset, testsetclear)
-{
- BITSET_DECLARE(mask128, 128);
- BITSET_ZERO(mask128);
-
- for (int i = 0; i < 128; i++) {
- EXPECT_EQ(BITSET_TEST(mask128, i), false);
- BITSET_SET(mask128, i);
- EXPECT_EQ(BITSET_TEST(mask128, i), true);
- BITSET_CLEAR(mask128, i);
- EXPECT_EQ(BITSET_TEST(mask128, i), false);
- }
-}
-
-TEST(bitset, testsetones)
-{
- BITSET_DECLARE(mask128, 128);
- BITSET_ONES(mask128);
-
- EXPECT_EQ(BITSET_FFS(mask128), 1);
-
- for (int i = 0; i < 128; i++) {
- EXPECT_EQ(BITSET_TEST(mask128, i), true);
- BITSET_CLEAR(mask128, i);
- EXPECT_EQ(BITSET_TEST(mask128, i), false);
- BITSET_SET(mask128, i);
- EXPECT_EQ(BITSET_TEST(mask128, i), true);
- }
-}
-
-TEST(bitset, testbasicrange)
-{
- BITSET_DECLARE(mask128, 128);
- BITSET_ZERO(mask128);
-
- const int max_set = 15;
- BITSET_SET_RANGE(mask128, 0, max_set);
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, 0, max_set), true);
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, max_set + 1, max_set + 15), false);
- for (int i = 0; i < 128; i++) {
- if (i <= max_set)
- EXPECT_EQ(BITSET_TEST(mask128, i), true);
- else
- EXPECT_EQ(BITSET_TEST(mask128, i), false);
- }
- BITSET_CLEAR_RANGE(mask128, 0, max_set);
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, 0, max_set), false);
- for (int i = 0; i < 128; i++) {
- EXPECT_EQ(BITSET_TEST(mask128, i), false);
- }
-}
-
-TEST(bitset, testbitsetffs)
-{
- BITSET_DECLARE(mask128, 128);
- BITSET_ZERO(mask128);
-
- EXPECT_EQ(BITSET_FFS(mask128), 0);
-
- BITSET_SET(mask128, 14);
- EXPECT_EQ(BITSET_FFS(mask128), 15);
-
- BITSET_SET(mask128, 28);
- EXPECT_EQ(BITSET_FFS(mask128), 15);
-
- BITSET_CLEAR(mask128, 14);
- EXPECT_EQ(BITSET_FFS(mask128), 29);
-
- BITSET_SET_RANGE(mask128, 14, 18);
- EXPECT_EQ(BITSET_FFS(mask128), 15);
-}
-
-TEST(bitset, testrangebits)
-{
- BITSET_DECLARE(mask128, 128);
- BITSET_ZERO(mask128);
-
- BITSET_SET_RANGE(mask128, 0, 31);
- BITSET_SET_RANGE(mask128, 32, 63);
- BITSET_SET_RANGE(mask128, 64, 95);
- BITSET_SET_RANGE(mask128, 96, 127);
-
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, 0, 31), true);
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, 32, 63), true);
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, 64, 95), true);
- EXPECT_EQ(BITSET_TEST_RANGE(mask128, 96, 127), true);
- for (int i = 0; i < 128; i++) {
- EXPECT_EQ(BITSET_TEST(mask128, i), true);
- }
-}
diff --git a/lib/mesa/src/util/blob_test.c b/lib/mesa/src/util/blob_test.c
deleted file mode 100644
index 21b8b1efd..000000000
--- a/lib/mesa/src/util/blob_test.c
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Copyright © 2014 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 blob.c */
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#ifdef _MSC_VER
-#include <BaseTsd.h>
-typedef SSIZE_T ssize_t;
-#endif
-
-#include "util/ralloc.h"
-#include "blob.h"
-
-#define bytes_test_str "bytes_test"
-#define reserve_test_str "reserve_test"
-
-/* This placeholder must be the same length as the next overwrite_test_str */
-#define placeholder_str "XXXXXXXXXXXXXX"
-#define overwrite_test_str "overwrite_test"
-#define uint32_test 0x12345678
-#define uint32_placeholder 0xDEADBEEF
-#define uint32_overwrite 0xA1B2C3D4
-#define uint64_test 0x1234567890ABCDEF
-#define string_test_str "string_test"
-
-bool error = false;
-
-static void
-expect_equal(uint64_t expected, uint64_t actual, 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_unequal(uint64_t expected, uint64_t actual, const char *test)
-{
- if (actual == expected) {
- fprintf(stderr,
- "Error: Test '%s' failed: Result=%" PRIu64 ", "
- "but expected something different.\n",
- test, actual);
- error = true;
- }
-}
-
-static void
-expect_equal_str(const char *expected, const char *actual, const char *test)
-{
- if (strcmp(expected, actual)) {
- fprintf (stderr, "Error: Test '%s' failed:\n\t"
- "Expected=\"%s\", Actual=\"%s\"\n",
- test, expected, actual);
- error = true;
- }
-}
-
-static void
-expect_equal_bytes(uint8_t *expected, const uint8_t *actual,
- size_t num_bytes, const char *test)
-{
- size_t i;
-
- if (memcmp(expected, actual, num_bytes)) {
- fprintf (stderr, "Error: Test '%s' failed:\n\t", test);
-
- fprintf (stderr, "Expected=[");
- for (i = 0; i < num_bytes; i++) {
- if (i != 0)
- fprintf(stderr, ", ");
- fprintf(stderr, "0x%02x", expected[i]);
- }
- fprintf (stderr, "]");
-
- fprintf (stderr, "Actual=[");
- for (i = 0; i < num_bytes; i++) {
- if (i != 0)
- fprintf(stderr, ", ");
- fprintf(stderr, "0x%02x", actual[i]);
- }
- fprintf (stderr, "]\n");
-
- error = true;
- }
-}
-
-/* Test at least one call of each blob_write_foo and blob_read_foo function,
- * verifying that we read out everything we wrote, that every bytes is
- * consumed, and that the overrun bit is not set.
- */
-static void
-test_write_and_read_functions (void)
-{
- struct blob blob;
- struct blob_reader reader;
- ssize_t reserved;
- size_t str_offset, uint_offset;
- uint8_t reserve_buf[sizeof(reserve_test_str)];
-
- blob_init(&blob);
-
- /*** Test blob by writing one of every possible kind of value. */
-
- blob_write_bytes(&blob, bytes_test_str, sizeof(bytes_test_str));
-
- reserved = blob_reserve_bytes(&blob, sizeof(reserve_test_str));
- blob_overwrite_bytes(&blob, reserved, reserve_test_str, sizeof(reserve_test_str));
-
- /* Write a placeholder, (to be replaced later via overwrite_bytes) */
- str_offset = blob.size;
- blob_write_bytes(&blob, placeholder_str, sizeof(placeholder_str));
-
- blob_write_uint32(&blob, uint32_test);
-
- /* Write a placeholder, (to be replaced later via overwrite_uint32) */
- uint_offset = blob.size;
- blob_write_uint32(&blob, uint32_placeholder);
-
- blob_write_uint64(&blob, uint64_test);
-
- blob_write_intptr(&blob, (intptr_t) &blob);
-
- blob_write_string(&blob, string_test_str);
-
- /* Finally, overwrite our placeholders. */
- blob_overwrite_bytes(&blob, str_offset, overwrite_test_str,
- sizeof(overwrite_test_str));
- blob_overwrite_uint32(&blob, uint_offset, uint32_overwrite);
-
- /*** Now read each value and verify. */
- blob_reader_init(&reader, blob.data, blob.size);
-
- expect_equal_str(bytes_test_str,
- blob_read_bytes(&reader, sizeof(bytes_test_str)),
- "blob_write/read_bytes");
-
- blob_copy_bytes(&reader, reserve_buf, sizeof(reserve_buf));
- expect_equal_str(reserve_test_str, (char *) reserve_buf,
- "blob_reserve_bytes/blob_copy_bytes");
-
- expect_equal_str(overwrite_test_str,
- blob_read_bytes(&reader, sizeof(overwrite_test_str)),
- "blob_overwrite_bytes");
-
- expect_equal(uint32_test, blob_read_uint32(&reader),
- "blob_write/read_uint32");
- expect_equal(uint32_overwrite, blob_read_uint32(&reader),
- "blob_overwrite_uint32");
- expect_equal(uint64_test, blob_read_uint64(&reader),
- "blob_write/read_uint64");
- expect_equal((intptr_t) &blob, blob_read_intptr(&reader),
- "blob_write/read_intptr");
- expect_equal_str(string_test_str, blob_read_string(&reader),
- "blob_write/read_string");
-
- expect_equal(reader.end - reader.data, reader.current - reader.data,
- "read_consumes_all_bytes");
- expect_equal(false, reader.overrun, "read_does_not_overrun");
-
- blob_finish(&blob);
-}
-
-/* Test that data values are written and read with proper alignment. */
-static void
-test_alignment(void)
-{
- struct blob blob;
- struct blob_reader reader;
- uint8_t bytes[] = "ABCDEFGHIJKLMNOP";
- size_t delta, last, num_bytes;
-
- blob_init(&blob);
-
- /* First, write an intptr value to the blob and capture that size. This is
- * the expected offset between any pair of intptr values (if written with
- * alignment).
- */
- blob_write_intptr(&blob, (intptr_t) &blob);
-
- delta = blob.size;
- last = blob.size;
-
- /* Then loop doing the following:
- *
- * 1. Write an unaligned number of bytes
- * 2. Verify that write results in an unaligned size
- * 3. Write an intptr_t value
- * 2. Verify that that write results in an aligned size
- */
- for (num_bytes = 1; num_bytes < sizeof(intptr_t); num_bytes++) {
- blob_write_bytes(&blob, bytes, num_bytes);
-
- expect_unequal(delta, blob.size - last, "unaligned write of bytes");
-
- blob_write_intptr(&blob, (intptr_t) &blob);
-
- expect_equal(2 * delta, blob.size - last, "aligned write of intptr");
-
- last = blob.size;
- }
-
- /* Finally, test that reading also does proper alignment. Since we know
- * that values were written with all the right alignment, all we have to do
- * here is verify that correct values are read.
- */
- blob_reader_init(&reader, blob.data, blob.size);
-
- expect_equal((intptr_t) &blob, blob_read_intptr(&reader),
- "read of initial, aligned intptr_t");
-
- for (num_bytes = 1; num_bytes < sizeof(intptr_t); num_bytes++) {
- expect_equal_bytes(bytes, blob_read_bytes(&reader, num_bytes),
- num_bytes, "unaligned read of bytes");
- expect_equal((intptr_t) &blob, blob_read_intptr(&reader),
- "aligned read of intptr_t");
- }
-
- blob_finish(&blob);
-}
-
-/* Test that we detect overrun. */
-static void
-test_overrun(void)
-{
- struct blob blob;
- struct blob_reader reader;
- uint32_t value = 0xdeadbeef;
-
- blob_init(&blob);
-
- blob_write_uint32(&blob, value);
-
- blob_reader_init(&reader, blob.data, blob.size);
-
- expect_equal(value, blob_read_uint32(&reader), "read before overrun");
- expect_equal(false, reader.overrun, "overrun flag not set");
- expect_equal(0, blob_read_uint32(&reader), "read at overrun");
- expect_equal(true, reader.overrun, "overrun flag set");
-
- blob_finish(&blob);
-}
-
-/* Test that we can read and write some large objects, (exercising the code in
- * the blob_write functions to realloc blob->data.
- */
-static void
-test_big_objects(void)
-{
- void *ctx = ralloc_context(NULL);
- struct blob blob;
- struct blob_reader reader;
- int size = 1000;
- int count = 1000;
- size_t i;
- char *buf;
-
- blob_init(&blob);
-
- /* Initialize our buffer. */
- buf = ralloc_size(ctx, size);
- for (i = 0; i < size; i++) {
- buf[i] = i % 256;
- }
-
- /* Write it many times. */
- for (i = 0; i < count; i++) {
- blob_write_bytes(&blob, buf, size);
- }
-
- blob_reader_init(&reader, blob.data, blob.size);
-
- /* Read and verify it many times. */
- for (i = 0; i < count; i++) {
- expect_equal_bytes((uint8_t *) buf, blob_read_bytes(&reader, size), size,
- "read of large objects");
- }
-
- expect_equal(reader.end - reader.data, reader.current - reader.data,
- "number of bytes read reading large objects");
-
- expect_equal(false, reader.overrun,
- "overrun flag not set reading large objects");
-
- blob_finish(&blob);
- ralloc_free(ctx);
-}
-
-int
-main (void)
-{
- test_write_and_read_functions ();
- test_alignment ();
- test_overrun ();
- test_big_objects ();
-
- return error ? 1 : 0;
-}
diff --git a/lib/mesa/src/util/crc32.c b/lib/mesa/src/util/crc32.c
index 425046ab5..ec5ad2cc9 100644
--- a/lib/mesa/src/util/crc32.c
+++ b/lib/mesa/src/util/crc32.c
@@ -28,7 +28,7 @@
/**
* @file
* CRC32 implementation.
- *
+ *
* @author Jose Fonseca
*/
@@ -39,71 +39,71 @@
#include "crc32.h"
-static const uint32_t
+static const uint32_t
util_crc32_table[256] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
- 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
- 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
- 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
- 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
- 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
- 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
- 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
- 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
- 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
- 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
- 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
- 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
- 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
- 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
- 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
- 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
- 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
+ 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
+ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
+ 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
+ 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
+ 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
+ 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
+ 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
+ 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
+ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
+ 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
+ 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
+ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
+ 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
+ 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
+ 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
+ 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
+ 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
+ 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
+ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
+ 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
+ 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
@@ -116,7 +116,7 @@ util_hash_crc32(const void *data, size_t size)
{
const uint8_t *p = data;
uint32_t crc = 0xffffffff;
-
+
#ifdef HAVE_ZLIB
/* Prefer zlib's implementation for better performance.
* zlib's uInt is always "unsigned int" while size_t can be 64bit.
@@ -129,6 +129,6 @@ util_hash_crc32(const void *data, size_t size)
while (size--)
crc = util_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
-
+
return crc;
}
diff --git a/lib/mesa/src/util/crc32.h b/lib/mesa/src/util/crc32.h
index b6a21f417..3ddfc16f4 100644
--- a/lib/mesa/src/util/crc32.h
+++ b/lib/mesa/src/util/crc32.h
@@ -28,7 +28,7 @@
/**
* @file
* CRC32 function.
- *
+ *
* @author Jose Fonseca <jfonseca@vmware.com>
*/
@@ -43,7 +43,7 @@
extern "C" {
#endif
-
+
uint32_t
util_hash_crc32(const void *data, size_t size);
diff --git a/lib/mesa/src/util/disk_cache.c b/lib/mesa/src/util/disk_cache.c
index d9769cda0..c4486d75b 100644
--- a/lib/mesa/src/util/disk_cache.c
+++ b/lib/mesa/src/util/disk_cache.c
@@ -126,11 +126,19 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
max_size = 0;
- max_size_str = getenv("MESA_GLSL_CACHE_MAX_SIZE");
-
- #ifdef MESA_GLSL_CACHE_MAX_SIZE
+ max_size_str = getenv("MESA_SHADER_CACHE_MAX_SIZE");
+
+ if (!max_size_str) {
+ max_size_str = getenv("MESA_GLSL_CACHE_MAX_SIZE");
+ if (max_size_str)
+ fprintf(stderr,
+ "*** MESA_GLSL_CACHE_MAX_SIZE is deprecated; "
+ "use MESA_SHADER_CACHE_MAX_SIZE instead ***\n");
+ }
+
+ #ifdef MESA_SHADER_CACHE_MAX_SIZE
if( !max_size_str ) {
- max_size_str = MESA_GLSL_CACHE_MAX_SIZE;
+ max_size_str = MESA_SHADER_CACHE_MAX_SIZE;
}
#endif
diff --git a/lib/mesa/src/util/hash_table.c b/lib/mesa/src/util/hash_table.c
index 9be605d43..b0e7506ab 100644
--- a/lib/mesa/src/util/hash_table.c
+++ b/lib/mesa/src/util/hash_table.c
@@ -659,13 +659,18 @@ _mesa_hash_u32(const void *key)
uint32_t
_mesa_hash_string(const void *_key)
{
+ return _mesa_hash_string_with_length(_key, strlen((const char *)_key));
+}
+
+uint32_t
+_mesa_hash_string_with_length(const void *_key, unsigned length)
+{
uint32_t hash = 0;
const char *key = _key;
- size_t len = strlen(key);
#if defined(_WIN64) || defined(__x86_64__)
- hash = (uint32_t)XXH64(key, len, hash);
+ hash = (uint32_t)XXH64(key, length, hash);
#else
- hash = XXH32(key, len, hash);
+ hash = XXH32(key, length, hash);
#endif
return hash;
}
diff --git a/lib/mesa/src/util/hash_table.h b/lib/mesa/src/util/hash_table.h
index 8079d102d..c8a96b79e 100644
--- a/lib/mesa/src/util/hash_table.h
+++ b/lib/mesa/src/util/hash_table.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright © 2009,2012 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -119,6 +119,7 @@ uint32_t _mesa_hash_int(const void *key);
uint32_t _mesa_hash_uint(const void *key);
uint32_t _mesa_hash_u32(const void *key);
uint32_t _mesa_hash_string(const void *key);
+uint32_t _mesa_hash_string_with_length(const void *_key, unsigned length);
uint32_t _mesa_hash_pointer(const void *pointer);
bool _mesa_key_int_equal(const void *a, const void *b);
diff --git a/lib/mesa/src/util/list.h b/lib/mesa/src/util/list.h
index 0e71a66a7..383073b12 100644
--- a/lib/mesa/src/util/list.h
+++ b/lib/mesa/src/util/list.h
@@ -61,6 +61,12 @@ static inline void list_inithead(struct list_head *item)
item->next = item;
}
+/**
+ * Prepend an item to a list
+ *
+ * @param item The element to add to the list
+ * @param list The list to prepend to
+ */
static inline void list_add(struct list_head *item, struct list_head *list)
{
item->prev = list;
@@ -69,6 +75,12 @@ static inline void list_add(struct list_head *item, struct list_head *list)
list->next = item;
}
+/**
+ * Append an item to a list
+ *
+ * @param item The element to add to the list
+ * @param list The list to append to
+ */
static inline void list_addtail(struct list_head *item, struct list_head *list)
{
item->next = list;
diff --git a/lib/mesa/src/util/macros.h b/lib/mesa/src/util/macros.h
index 35ffa80de..7c6df7e58 100644
--- a/lib/mesa/src/util/macros.h
+++ b/lib/mesa/src/util/macros.h
@@ -425,20 +425,6 @@ u_uintN_max(unsigned bit_size)
return UINT64_MAX >> (64 - bit_size);
}
-/* TODO: In future we should try to move this to u_debug.h once header
- * dependencies are reorganised to allow this.
- */
-enum pipe_debug_type
-{
- PIPE_DEBUG_TYPE_OUT_OF_MEMORY = 1,
- PIPE_DEBUG_TYPE_ERROR,
- PIPE_DEBUG_TYPE_SHADER_INFO,
- PIPE_DEBUG_TYPE_PERF_INFO,
- PIPE_DEBUG_TYPE_INFO,
- PIPE_DEBUG_TYPE_FALLBACK,
- PIPE_DEBUG_TYPE_CONFORMANCE,
-};
-
#if !defined(alignof) && !defined(__cplusplus)
#if __STDC_VERSION__ >= 201112L
#define alignof(t) _Alignof(t)
diff --git a/lib/mesa/src/util/mesa-sha1.c b/lib/mesa/src/util/mesa-sha1.c
index 410e82c71..701ba8a28 100644
--- a/lib/mesa/src/util/mesa-sha1.c
+++ b/lib/mesa/src/util/mesa-sha1.c
@@ -26,6 +26,7 @@
#include "sha1/sha1.h"
#include "mesa-sha1.h"
+#include <string.h>
void
_mesa_sha1_compute(const void *data, size_t size, unsigned char result[20])
@@ -64,3 +65,36 @@ _mesa_sha1_hex_to_sha1(unsigned char *buf, const char *hex)
buf[i] = strtol(tmp, NULL, 16);
}
}
+
+static void
+sha1_to_uint32(const uint8_t sha1[SHA1_DIGEST_LENGTH],
+ uint32_t out[SHA1_DIGEST_LENGTH32])
+{
+ memset(out, 0, SHA1_DIGEST_LENGTH);
+
+ for (unsigned i = 0; i < SHA1_DIGEST_LENGTH; i++)
+ out[i / 4] |= (uint32_t)sha1[i] << ((i % 4) * 8);
+}
+
+void
+_mesa_sha1_print(FILE *f, const uint8_t sha1[SHA1_DIGEST_LENGTH])
+{
+ uint32_t u32[SHA1_DIGEST_LENGTH];
+ sha1_to_uint32(sha1, u32);
+
+ for (unsigned i = 0; i < SHA1_DIGEST_LENGTH32; i++) {
+ fprintf(f, "0x%08x", u32[i]);
+ if (i < SHA1_DIGEST_LENGTH32 - 1)
+ fprintf(f, ", ");
+ }
+}
+
+bool
+_mesa_printed_sha1_equal(const uint8_t sha1[SHA1_DIGEST_LENGTH],
+ const uint32_t printed_sha1[SHA1_DIGEST_LENGTH32])
+{
+ uint32_t u32[SHA1_DIGEST_LENGTH32];
+ sha1_to_uint32(sha1, u32);
+
+ return memcmp(u32, printed_sha1, sizeof(u32)) == 0;
+}
diff --git a/lib/mesa/src/util/mesa-sha1.h b/lib/mesa/src/util/mesa-sha1.h
index 9842bbb1e..9d174fd9b 100644
--- a/lib/mesa/src/util/mesa-sha1.h
+++ b/lib/mesa/src/util/mesa-sha1.h
@@ -24,6 +24,8 @@
#define MESA_SHA1_H
#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
#include "c99_compat.h"
#include "sha1/sha1.h"
@@ -32,6 +34,7 @@ extern "C" {
#endif
#define mesa_sha1 _SHA1_CTX
+#define SHA1_DIGEST_LENGTH32 (SHA1_DIGEST_LENGTH / 4)
static inline void
_mesa_sha1_init(struct mesa_sha1 *ctx)
@@ -60,6 +63,13 @@ _mesa_sha1_hex_to_sha1(unsigned char *buf, const char *hex);
void
_mesa_sha1_compute(const void *data, size_t size, unsigned char result[20]);
+void
+_mesa_sha1_print(FILE *f, const uint8_t sha1[SHA1_DIGEST_LENGTH]);
+
+bool
+_mesa_printed_sha1_equal(const uint8_t sha1[SHA1_DIGEST_LENGTH],
+ const uint32_t printed_sha1[SHA1_DIGEST_LENGTH32]);
+
#ifdef __cplusplus
} /* extern C */
#endif
diff --git a/lib/mesa/src/util/mesa-sha1_test.c b/lib/mesa/src/util/mesa-sha1_test.c
deleted file mode 100644
index 9b3b477c7..000000000
--- a/lib/mesa/src/util/mesa-sha1_test.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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 (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 <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include "macros.h"
-#include "mesa-sha1.h"
-
-#define SHA1_LENGTH 40
-
-int main(int argc, char *argv[])
-{
- static const struct {
- const char *string;
- const char *sha1;
- } test_data[] = {
- {"Mesa Rocks! 273", "7fb99737373d65a73f049cdabc01e73aa6bc60f3"},
- {"Mesa Rocks! 300", "b2180263e37d3bed6a4be0afe41b1a82ebbcf4c3"},
- {"Mesa Rocks! 583", "7fb9734108a62503e8a149c1051facd7fb112d05"},
- };
-
- bool failed = false;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(test_data); i++) {
- unsigned char sha1[20];
- _mesa_sha1_compute(test_data[i].string, strlen(test_data[i].string),
- sha1);
-
- char buf[41];
- _mesa_sha1_format(buf, sha1);
-
- if (memcmp(test_data[i].sha1, buf, SHA1_LENGTH) != 0) {
- printf("For string \"%s\", length %zu:\n"
- "\tExpected: %s\n\t Got: %s\n",
- test_data[i].string, strlen(test_data[i].string),
- test_data[i].sha1, buf);
- failed = true;
- }
- }
-
- return failed;
-}
diff --git a/lib/mesa/src/util/meson.build b/lib/mesa/src/util/meson.build
index b61723da3..2a1028f0d 100644
--- a/lib/mesa/src/util/meson.build
+++ b/lib/mesa/src/util/meson.build
@@ -78,6 +78,7 @@ files_mesa_util = files(
'os_misc.h',
'os_socket.c',
'os_socket.h',
+ 'ptralloc.h',
'perf/u_trace.h',
'perf/u_trace.c',
'perf/u_trace_priv.h',
@@ -143,12 +144,17 @@ files_mesa_util = files(
'u_debug_memory.c',
'u_cpu_detect.c',
'u_cpu_detect.h',
- 'u_printf.cpp',
+ 'u_printf.c',
'u_printf.h',
- 'u_printf_length.c',
+ 'vl_vlc.h',
+ 'vl_rbsp.h',
'vma.c',
'vma.h',
'xxhash.h',
+ 'indices/u_indices.h',
+ 'indices/u_indices_priv.h',
+ 'indices/u_primconvert.c',
+ 'indices/u_primconvert.h',
)
files_drirc = files('00-mesa-defaults.conf')
@@ -226,9 +232,25 @@ endif
u_trace_py = files('perf/u_trace.py')
+u_indices_gen_c = custom_target(
+ 'u_indices_gen.c',
+ input : 'indices/u_indices_gen.py',
+ output : 'u_indices_gen.c',
+ command : [prog_python, '@INPUT@'],
+ capture : true,
+)
+
+u_unfilled_gen_c = custom_target(
+ 'u_unfilled_gen.c',
+ input : 'indices/u_unfilled_gen.py',
+ output : 'u_unfilled_gen.c',
+ command : [prog_python, '@INPUT@'],
+ capture : true,
+)
+
_libmesa_util = static_library(
'mesa_util',
- [files_mesa_util, files_debug_stack, format_srgb],
+ [files_mesa_util, files_debug_stack, format_srgb, u_indices_gen_c, u_unfilled_gen_c],
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
dependencies : deps_for_libmesa_util,
link_with: libmesa_format,
@@ -290,90 +312,72 @@ if with_tests
env: ['HOME=' + join_paths(meson.current_source_dir(),
'tests', 'drirc_home'),
'DRIRC_CONFIGDIR=' + join_paths(meson.current_source_dir(),
- 'tests', 'drirc_configdir')]
- )
+ 'tests', 'drirc_configdir')],
+ protocol : gtest_test_protocol,
+ )
endif
- test(
- 'u_atomic',
- executable(
- 'u_atomic_test',
- files('u_atomic_test.c'),
- include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
- dependencies : idep_mesautil,
- c_args : [c_msvc_compat_args],
- ),
- suite : ['util'],
+ files_util_tests = files(
+ 'tests/bitset_test.cpp',
+ 'tests/blob_test.cpp',
+ 'tests/dag_test.cpp',
+ 'tests/fast_idiv_by_const_test.cpp',
+ 'tests/fast_urem_by_const_test.cpp',
+ 'tests/int_min_max.cpp',
+ 'tests/rb_tree_test.cpp',
+ 'tests/register_allocate_test.cpp',
+ 'tests/roundeven_test.cpp',
+ 'tests/set_test.cpp',
+ 'tests/sparse_array_test.cpp',
+ 'tests/u_atomic_test.cpp',
+ 'tests/u_debug_stack_test.cpp',
+ 'tests/u_printf_test.cpp',
+ 'tests/u_qsort_test.cpp',
+ 'tests/vector_test.cpp',
)
- test(
- 'blob',
- executable(
- 'blob_test',
- files('blob_test.c'),
- include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
- dependencies : idep_mesautil,
- c_args : [c_msvc_compat_args],
- ),
- suite : ['util'],
- )
-
- test(
- 'rb_tree',
- executable(
- 'rb_tree_test',
- files('rb_tree_test.c'),
- include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
- dependencies : idep_mesautil,
- c_args : [c_msvc_compat_args],
- ),
- suite : ['util'],
- )
+ if not (host_machine.system() == 'windows' and cc.get_id() == 'gcc')
+ # FIXME: These tests fail with mingw, but not with msvc.
+ files_util_tests += files(
+ 'tests/string_buffer_test.cpp',
+ )
+ endif
- test(
- 'roundeven',
- executable(
- 'roundeven_test',
- files('roundeven_test.c'),
- include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
- c_args : [c_msvc_compat_args],
- dependencies : [dep_m],
- ),
- suite : ['util'],
- should_fail : meson.get_cross_property('xfail', '').contains('roundeven'),
- )
+ if cc.has_header('sys/time.h') # MinGW has this, but Vanilla windows doesn't
+ files_util_tests += files(
+ 'tests/timespec_test.cpp'
+ )
+ endif
# FIXME: this test crashes on windows
if host_machine.system() != 'windows'
- test(
- 'mesa-sha1',
- executable(
- 'mesa-sha1_test',
- files('mesa-sha1_test.c'),
- include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
- link_with : _libmesa_util,
- c_args : [c_msvc_compat_args],
- ),
- suite : ['util'],
+ files_util_tests += files(
+ 'tests/mesa-sha1_test.cpp',
)
endif
- foreach t: ['bitset', 'register_allocate', 'u_debug_stack', 'u_qsort']
- test(
- t,
- executable(
- t + '_test',
- files(t + '_test.cpp'),
- include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
- dependencies : [idep_mesautil, idep_gtest],
- ),
- suite : ['util'],
+ if with_shader_cache
+ files_util_tests += files(
+ 'tests/cache_test.cpp',
)
- endforeach
+ endif
+
+ test(
+ 'util_tests',
+ executable(
+ 'util_tests',
+ files_util_tests,
+ include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
+ dependencies : [idep_mesautil, idep_gtest],
+ ),
+ suite : ['util'],
+ protocol : gtest_test_protocol,
+ timeout : 180,
+ )
process_test_exe = executable(
'process_test',
- files('process_test.c'),
+ files('tests/process_test.c'),
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
dependencies : idep_mesautil,
c_args : [c_msvc_compat_args],
@@ -397,40 +401,7 @@ if with_tests
env: ['BUILD_FULL_PATH='+process_test_exe_full_path]
)
- test('int_min_max',
- executable('int_min_max_test',
- files('tests/int_min_max.cpp'),
- include_directories : [inc_include, inc_src],
- dependencies : [idep_mesautil, idep_gtest],
- ),
- suite : ['util'],
- )
-
- test(
- 'dag',
- executable(
- 'dag_test',
- 'tests/dag_test.cpp',
- dependencies : [idep_mesautil, idep_gtest],
- include_directories : [inc_include, inc_src],
- ),
- suite : ['util'],
- )
-
- subdir('tests/cache')
- subdir('tests/fast_idiv_by_const')
- subdir('tests/fast_urem_by_const')
subdir('tests/hash_table')
- if not (host_machine.system() == 'windows' and cc.get_id() == 'gcc')
- # FIXME: These tests fail with mingw, but not with msvc.
- subdir('tests/string_buffer')
- endif
- if cc.has_header('sys/time.h') # MinGW has this, but Vanilla windows doesn't
- subdir('tests/timespec')
- endif
subdir('tests/vma')
- subdir('tests/set')
- subdir('tests/sparse_array')
subdir('tests/format')
- subdir('tests/vector')
endif
diff --git a/lib/mesa/src/util/process_test.c b/lib/mesa/src/util/process_test.c
deleted file mode 100644
index fdd6ee6ba..000000000
--- a/lib/mesa/src/util/process_test.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright © 2020 Advanced Micro Devices, Inc.
- *
- * 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 u_process.c */
-
-#include "util/detect_os.h"
-#include "util/u_process.h"
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <limits.h>
-#include <stdlib.h>
-
-#if DETECT_OS_WINDOWS && !defined(PATH_MAX)
-#include <windows.h>
-#define PATH_MAX MAX_PATH
-#endif
-
-bool error = false;
-
-static void
-expect_equal_str(const char *expected, const char *actual, const char *test)
-{
- if (strcmp(expected, actual)) {
- fprintf (stderr, "Error: Test '%s' failed:\n\t"
- "Expected=\"%s\", Actual=\"%s\"\n",
- test, expected, actual);
- error = true;
- }
-}
-
-static void
-test_util_get_process_name (void)
-{
-#if DETECT_OS_WINDOWS
- const char *expected = "process_test.exe";
-#else
- const char *expected = "process_test";
-#endif
-
- const char *name = util_get_process_name();
- expect_equal_str(expected, name, "util_get_process_name");
-}
-
-/* This test gets the real path from Meson (BUILD_FULL_PATH env var),
- * and compares it to the output of util_get_process_exec_path.
- */
-static void
-test_util_get_process_exec_path (void)
-{
- char path[PATH_MAX];
- if (util_get_process_exec_path(path, PATH_MAX) == 0) {
- error = true;
- return;
- }
- char* build_path = getenv("BUILD_FULL_PATH");
- if (!build_path) {
- fprintf(stderr, "BUILD_FULL_PATH environment variable should be set\n");
- error = true;
- return;
- }
-#ifdef __CYGWIN__
- int i = strlen(build_path) - 4;
- if ((i > 0) && (strcmp(&build_path[i], ".exe") == 0))
- build_path[i] = 0;
-#endif
- expect_equal_str(build_path, path, "util_get_process_name");
-}
-
-int
-main (void)
-{
- test_util_get_process_name();
- test_util_get_process_exec_path();
-
- return error ? 1 : 0;
-}
diff --git a/lib/mesa/src/util/rb_tree_test.c b/lib/mesa/src/util/rb_tree_test.c
deleted file mode 100644
index 7551add95..000000000
--- a/lib/mesa/src/util/rb_tree_test.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright © 2017 Jason Ekstrand
- *
- * 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.
- */
-
-#undef NDEBUG
-
-#include "rb_tree.h"
-
-#include <assert.h>
-#include <limits.h>
-
-/* A list of 100 random numbers from 1 to 100. The number 30 is explicitly
- * missing from this list.
- */
-int test_numbers[] = {
- 26, 12, 35, 15, 48, 11, 39, 23, 40, 18,
- 39, 15, 40, 11, 42, 2, 5, 2, 28, 8,
- 10, 22, 23, 38, 47, 12, 31, 22, 26, 39,
- 9, 42, 32, 18, 36, 8, 32, 29, 9, 3,
- 32, 49, 23, 11, 43, 41, 22, 42, 6, 35,
- 38, 48, 5, 35, 39, 44, 22, 16, 16, 32,
- 31, 50, 48, 5, 50, 8, 2, 32, 27, 34,
- 42, 48, 22, 47, 10, 48, 39, 36, 28, 40,
- 32, 33, 21, 17, 14, 38, 27, 6, 25, 18,
- 32, 38, 19, 22, 20, 47, 50, 41, 29, 50,
-};
-
-#define NON_EXISTANT_NUMBER 30
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
-
-struct rb_test_node {
- int key;
- struct rb_node node;
-};
-
-static int
-rb_test_node_cmp_void(const struct rb_node *n, const void *v)
-{
- struct rb_test_node *tn = rb_node_data(struct rb_test_node, n, node);
- return *(int *)v - tn->key;
-}
-
-static int
-rb_test_node_cmp(const struct rb_node *a, const struct rb_node *b)
-{
- struct rb_test_node *ta = rb_node_data(struct rb_test_node, a, node);
- struct rb_test_node *tb = rb_node_data(struct rb_test_node, b, node);
-
- return tb->key - ta->key;
-}
-
-static void
-validate_tree_order(struct rb_tree *tree, unsigned expected_count)
-{
- struct rb_test_node *prev = NULL;
- int max_val = -1;
- unsigned count = 0;
- rb_tree_foreach(struct rb_test_node, n, tree, node) {
- /* Everything should be in increasing order */
- assert(n->key >= max_val);
- if (n->key > max_val) {
- max_val = n->key;
- } else {
- /* Things should be stable, i.e., given equal keys, they should
- * show up in the list in order of insertion. We insert them
- * in the order they are in in the array.
- */
- assert(prev == NULL || prev < n);
- }
-
- prev = n;
- count++;
- }
- assert(count == expected_count);
-
- prev = NULL;
- max_val = -1;
- count = 0;
- rb_tree_foreach_safe(struct rb_test_node, n, tree, node) {
- /* Everything should be in increasing order */
- assert(n->key >= max_val);
- if (n->key > max_val) {
- max_val = n->key;
- } else {
- /* Things should be stable, i.e., given equal keys, they should
- * show up in the list in order of insertion. We insert them
- * in the order they are in in the array.
- */
- assert(prev == NULL || prev < n);
- }
-
- prev = n;
- count++;
- }
- assert(count == expected_count);
-
- prev = NULL;
- int min_val = INT_MAX;
- count = 0;
- rb_tree_foreach_rev(struct rb_test_node, n, tree, node) {
- /* Everything should be in increasing order */
- assert(n->key <= min_val);
- if (n->key < min_val) {
- min_val = n->key;
- } else {
- /* Things should be stable, i.e., given equal keys, they should
- * show up in the list in order of insertion. We insert them
- * in the order they are in in the array.
- */
- assert(prev == NULL || prev > n);
- }
-
- prev = n;
- count++;
- }
- assert(count == expected_count);
-
- prev = NULL;
- min_val = INT_MAX;
- count = 0;
- rb_tree_foreach_rev_safe(struct rb_test_node, n, tree, node) {
- /* Everything should be in increasing order */
- assert(n->key <= min_val);
- if (n->key < min_val) {
- min_val = n->key;
- } else {
- /* Things should be stable, i.e., given equal keys, they should
- * show up in the list in order of insertion. We insert them
- * in the order they are in in the array.
- */
- assert(prev == NULL || prev > n);
- }
-
- prev = n;
- count++;
- }
- assert(count == expected_count);
-}
-
-static void
-validate_search(struct rb_tree *tree, int first_number,
- int last_number)
-{
- struct rb_node *n;
- struct rb_test_node *tn;
-
- /* Search for all of the values */
- for (int i = first_number; i <= last_number; i++) {
- n = rb_tree_search(tree, &test_numbers[i], rb_test_node_cmp_void);
- tn = rb_node_data(struct rb_test_node, n, node);
- assert(tn->key == test_numbers[i]);
-
- n = rb_tree_search_sloppy(tree, &test_numbers[i],
- rb_test_node_cmp_void);
- tn = rb_node_data(struct rb_test_node, n, node);
- assert(tn->key == test_numbers[i]);
- }
-
- int missing_key = NON_EXISTANT_NUMBER;
- n = rb_tree_search(tree, &missing_key, rb_test_node_cmp_void);
- assert(n == NULL);
-
- n = rb_tree_search_sloppy(tree, &missing_key, rb_test_node_cmp_void);
- if (rb_tree_is_empty(tree)) {
- assert(n == NULL);
- } else {
- assert(n != NULL);
- tn = rb_node_data(struct rb_test_node, n, node);
- assert(tn->key != missing_key);
- if (tn->key < missing_key) {
- struct rb_node *next = rb_node_next(n);
- if (next != NULL) {
- struct rb_test_node *tnext =
- rb_node_data(struct rb_test_node, next, node);
- assert(missing_key < tnext->key);
- }
- } else {
- struct rb_node *prev = rb_node_prev(n);
- if (prev != NULL) {
- struct rb_test_node *tprev =
- rb_node_data(struct rb_test_node, prev, node);
- assert(missing_key > tprev->key);
- }
- }
- }
-}
-
-int
-main()
-{
- struct rb_test_node nodes[ARRAY_SIZE(test_numbers)];
- struct rb_tree tree;
-
- rb_tree_init(&tree);
-
- for (unsigned i = 0; i < ARRAY_SIZE(test_numbers); i++) {
- nodes[i].key = test_numbers[i];
- rb_tree_insert(&tree, &nodes[i].node, rb_test_node_cmp);
- rb_tree_validate(&tree);
- validate_tree_order(&tree, i + 1);
- validate_search(&tree, 0, i);
- }
-
- for (unsigned i = 0; i < ARRAY_SIZE(test_numbers); i++) {
- rb_tree_remove(&tree, &nodes[i].node);
- rb_tree_validate(&tree);
- validate_tree_order(&tree, ARRAY_SIZE(test_numbers) - i - 1);
- validate_search(&tree, i + 1, ARRAY_SIZE(test_numbers) - 1);
- }
-}
diff --git a/lib/mesa/src/util/register_allocate_test.cpp b/lib/mesa/src/util/register_allocate_test.cpp
deleted file mode 100644
index 9a0cb3a12..000000000
--- a/lib/mesa/src/util/register_allocate_test.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright © 2021 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 "ralloc.h"
-#include "register_allocate.h"
-#include "register_allocate_internal.h"
-
-class ra_test : public ::testing::Test {
-public:
- void *mem_ctx;
-
-protected:
- ra_test();
- ~ra_test();
-};
-
-ra_test::ra_test()
-{
- mem_ctx = ralloc_context(NULL);
-}
-
-ra_test::~ra_test()
-{
- ralloc_free(mem_ctx);
-}
-
-void
-thumb_checks(struct ra_regs *regs, unsigned reg32_base, unsigned reg64_base)
-{
- struct ra_class *reg32low = ra_get_class_from_index(regs, 0);
- struct ra_class *reg64low = ra_get_class_from_index(regs, 1);
- struct ra_class *reg96 = ra_get_class_from_index(regs, 2);
-
- /* Table 4.1 */
- ASSERT_EQ(reg32low->p, 8);
- ASSERT_EQ(reg32low->q[reg32low->index], 1);
- ASSERT_EQ(reg32low->q[reg64low->index], 2);
- ASSERT_EQ(reg32low->q[reg96->index], 3);
- ASSERT_EQ(reg64low->p, 8);
- ASSERT_EQ(reg64low->q[reg32low->index], 2);
- ASSERT_EQ(reg64low->q[reg64low->index], 3);
- ASSERT_EQ(reg64low->q[reg96->index], 4);
- ASSERT_EQ(reg96->p, 2);
- ASSERT_EQ(reg96->q[reg96->index], 2);
- ASSERT_EQ(reg96->q[reg64low->index], 2);
- ASSERT_EQ(reg96->q[reg96->index], 2);
-
- /* These individual regs should conflict with themselves, but nothing else from their class */
- for (int i = 0; i < 7; i++) {
- ASSERT_FALSE(ra_class_allocations_conflict(reg32low, reg32_base + i, reg32low, reg32_base + i + 1));
- ASSERT_TRUE(ra_class_allocations_conflict(reg32low, reg32_base + i, reg32low, reg32_base + i));
- }
-
- /* Check that reg64low conflicts with the pairs of reg32low but not neighbors */
- ASSERT_TRUE(ra_class_allocations_conflict(reg64low, reg64_base + 0, reg32low, reg32_base + 0));
- ASSERT_TRUE(ra_class_allocations_conflict(reg64low, reg64_base + 0, reg32low, reg32_base + 1));
- ASSERT_FALSE(ra_class_allocations_conflict(reg64low, reg64_base + 0, reg32low, reg32_base + 2));
-
- ASSERT_FALSE(ra_class_allocations_conflict(reg64low, reg64_base + 1, reg32low, reg32_base + 0));
- ASSERT_TRUE(ra_class_allocations_conflict(reg64low, reg64_base + 1, reg32low, reg32_base + 1));
- ASSERT_TRUE(ra_class_allocations_conflict(reg64low, reg64_base + 1, reg32low, reg32_base + 2));
- ASSERT_FALSE(ra_class_allocations_conflict(reg64low, reg64_base + 1, reg32low, reg32_base + 3));
-}
-
-TEST_F(ra_test, thumb)
-{
- struct ra_regs *regs = ra_alloc_reg_set(mem_ctx, 100, true);
-
- /* r0..15 are the real HW registers. */
- int next_vreg = 16;
-
- /* reg32low is any of the low 8 registers. */
- unsigned int reg32_base = next_vreg;
- struct ra_class *reg32low = ra_alloc_reg_class(regs);
- for (int i = 0; i < 8; i++) {
- int vreg = next_vreg++;
- ra_class_add_reg(reg32low, vreg);
- ra_add_transitive_reg_conflict(regs, i, vreg);
- }
-
- /* reg64low is pairs of the low 8 registers (with wraparound!) */
- unsigned int reg64_base = next_vreg;
- struct ra_class *reg64low = ra_alloc_reg_class(regs);
- for (int i = 0; i < 8; i++) {
- int vreg = next_vreg++;
- ra_class_add_reg(reg64low, vreg);
- ra_add_transitive_reg_conflict(regs, i, vreg);
- ra_add_transitive_reg_conflict(regs, (i + 1) % 8, vreg);
- }
-
- /* reg96 is one of either r[0..2] or r[1..3] */
- struct ra_class *reg96 = ra_alloc_reg_class(regs);
- for (int i = 0; i < 2; i++) {
- int vreg = next_vreg++;
- ra_class_add_reg(reg96, vreg);
- for (int j = 0; j < 3; j++)
- ra_add_transitive_reg_conflict(regs, i + j, vreg);
- }
-
- ra_set_finalize(regs, NULL);
-
- thumb_checks(regs, reg32_base, reg64_base);
-}
-
-TEST_F(ra_test, thumb_contigregs)
-{
- struct ra_regs *regs = ra_alloc_reg_set(mem_ctx, 16, true);
-
- /* reg32low is any of the low 8 registers. */
- struct ra_class *reg32low = ra_alloc_contig_reg_class(regs, 1);
- for (int i = 0; i < 8; i++)
- ra_class_add_reg(reg32low, i);
-
- /* reg64low is pairs of the low 8 registers (we're ignoring the wraparound thing here) */
- struct ra_class *reg64low = ra_alloc_contig_reg_class(regs, 2);
- for (int i = 0; i < 8; i++)
- ra_class_add_reg(reg64low, i);
-
- /* reg96 is one of either r[0..2] or r[1..3] */
- struct ra_class *reg96 = ra_alloc_contig_reg_class(regs, 3);
- for (int i = 0; i < 2; i++)
- ra_class_add_reg(reg96, i);
-
- ra_set_finalize(regs, NULL);
-
- thumb_checks(regs, 0, 0);
-}
-
-TEST_F(ra_test, nonintersect_contigregs)
-{
- struct ra_regs *regs = ra_alloc_reg_set(mem_ctx, 16, true);
-
- struct ra_class *low = ra_alloc_contig_reg_class(regs, 1);
- for (int i = 0; i < 8; i++)
- ra_class_add_reg(low, i);
-
- struct ra_class *high = ra_alloc_contig_reg_class(regs, 1);
- for (int i = 8; i < 16; i++)
- ra_class_add_reg(high, i);
-
- ra_set_finalize(regs, NULL);
-
- ASSERT_EQ(low->q[low->index], 1);
- ASSERT_EQ(low->q[high->index], 0);
- ASSERT_EQ(high->q[low->index], 0);
- ASSERT_EQ(high->q[high->index], 1);
-}
-
-TEST_F(ra_test, aligned_contigregs)
-{
- int base_regs = 32;
- struct ra_regs *regs = ra_alloc_reg_set(mem_ctx, base_regs, true);
-
- struct ra_class *c1 = ra_alloc_contig_reg_class(regs, 1);
- for (int i = 0; i < base_regs; i++)
- ra_class_add_reg(c1, i);
-
- struct ra_class *c2 = ra_alloc_contig_reg_class(regs, 2);
- for (int i = 8; i < base_regs; i += 2)
- ra_class_add_reg(c2, i);
-
- struct ra_class *c4 = ra_alloc_contig_reg_class(regs, 4);
- for (int i = 8; i < base_regs; i += 4)
- ra_class_add_reg(c4, i);
-
- ra_set_finalize(regs, NULL);
-
- ASSERT_EQ(c1->q[c1->index], 1);
- ASSERT_EQ(c1->q[c2->index], 2);
- ASSERT_EQ(c1->q[c4->index], 4);
- ASSERT_EQ(c2->q[c1->index], 1);
- ASSERT_EQ(c2->q[c2->index], 1);
- ASSERT_EQ(c2->q[c4->index], 2);
- ASSERT_EQ(c4->q[c1->index], 1);
- ASSERT_EQ(c4->q[c2->index], 1);
- ASSERT_EQ(c4->q[c4->index], 1);
-
- /* Check conflicts for a c4 allocation at i against other classes. */
- for (int i = 0; i < base_regs / 4; i += 4) {
- for (int j = 0; j < base_regs; j++) {
- ASSERT_EQ(ra_class_allocations_conflict(c4, i, c1, j),
- j >= i && j < i + 4);
- }
-
- for (int j = 0; j < base_regs; j += 2) {
- ASSERT_EQ(ra_class_allocations_conflict(c4, i, c2, j),
- j >= i && j < i + 4);
- }
- }
-}
diff --git a/lib/mesa/src/util/roundeven_test.c b/lib/mesa/src/util/roundeven_test.c
deleted file mode 100644
index 7526db1f3..000000000
--- a/lib/mesa/src/util/roundeven_test.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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.
- */
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <math.h>
-
-#include "macros.h"
-#include "rounding.h"
-
-int main(int argc, char *argv[])
-{
- const struct {
- float input, expected;
- } float_data[] = {
- { 0.0, 0.0 },
- { nextafterf(0.5, 0.0), 0.0 },
- { 0.5, 0.0 },
- { nextafterf(0.5, 1.0), 1.0 },
- { 1.0, 1.0 },
- { nextafterf(1.5, 1.0), 1.0 },
- { 1.5, 2.0 },
- { nextafterf(1.5, 2.0), 2.0 },
- { 2.0, 2.0 },
- { nextafterf(2.5, 2.0), 2.0 },
- { 2.5, 2.0 },
- { nextafterf(2.5, 3.0), 3.0 },
- };
-
- const struct {
- double input, expected;
- } double_data[] = {
- { 0.0, 0.0 },
- { nextafter(0.5, 0.0), 0.0 },
- { 0.5, 0.0 },
- { nextafter(0.5, 1.0), 1.0 },
- { 1.0, 1.0 },
- { nextafter(1.5, 1.0), 1.0 },
- { 1.5, 2.0 },
- { nextafter(1.5, 2.0), 2.0 },
- { 2.0, 2.0 },
- { nextafter(2.5, 2.0), 2.0 },
- { 2.5, 2.0 },
- { nextafter(2.5, 3.0), 3.0 },
- };
-
- bool failed = false;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(float_data); i++) {
- float output = _mesa_roundevenf(float_data[i].input);
- if (memcmp(&float_data[i].expected, &output, sizeof(float))) {
- fprintf(stderr, "%d float: expected %f (%a) from "
- "_mesa_roundevenf(%f (%a)) but got %f (%a)\n",
- i,
- float_data[i].expected,
- float_data[i].expected,
- float_data[i].input,
- float_data[i].input,
- output,
- output);
- failed = true;
- }
- }
-
- /* Test negated values */
- for (i = 0; i < ARRAY_SIZE(float_data); i++) {
- float output = _mesa_roundevenf(-float_data[i].input);
- float negated_expected = -float_data[i].expected;
- if (memcmp(&negated_expected, &output, sizeof(float))) {
- fprintf(stderr, "%d float: expected %f (%a) from "
- "_mesa_roundevenf(%f (%a)) but got %f (%a)\n",
- i,
- negated_expected,
- negated_expected,
- -float_data[i].input,
- -float_data[i].input,
- output,
- output);
- failed = true;
- }
- }
-
- for (i = 0; i < ARRAY_SIZE(double_data); i++) {
- double output = _mesa_roundeven(double_data[i].input);
- if (memcmp(&double_data[i].expected, &output, sizeof(double))) {
- fprintf(stderr, "%d double: expected %f (%a) from "
- "_mesa_roundeven(%f (%a)) but got %f (%a)\n",
- i,
- double_data[i].expected,
- double_data[i].expected,
- double_data[i].input,
- double_data[i].input,
- output,
- output);
- failed = true;
- }
- }
-
- /* Test negated values */
- for (i = 0; i < ARRAY_SIZE(double_data); i++) {
- double output = _mesa_roundeven(-double_data[i].input);
- double negated_expected = -double_data[i].expected;
- if (memcmp(&negated_expected, &output, sizeof(double))) {
- fprintf(stderr, "%d double: expected %f (%a) from "
- "_mesa_roundeven(%f (%a)) but got %f (%a)\n",
- i,
- negated_expected,
- negated_expected,
- -double_data[i].input,
- -double_data[i].input,
- output,
- output);
- failed = true;
- }
- }
-
- return failed;
-}
diff --git a/lib/mesa/src/util/set.c b/lib/mesa/src/util/set.c
index 37bd689e8..2a3c16658 100644
--- a/lib/mesa/src/util/set.c
+++ b/lib/mesa/src/util/set.c
@@ -531,7 +531,7 @@ _mesa_set_search_or_add_pre_hashed(struct set *set, uint32_t hash,
{
assert(set->key_hash_function == NULL ||
hash == set->key_hash_function(key));
- return set_search_or_add(set, hash, key, NULL);
+ return set_search_or_add(set, hash, key, found);
}
/**
diff --git a/lib/mesa/src/util/sha1/README b/lib/mesa/src/util/sha1/README
index f30acf984..445d23716 100644
--- a/lib/mesa/src/util/sha1/README
+++ b/lib/mesa/src/util/sha1/README
@@ -25,7 +25,7 @@ http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/include/sha1.h?rev=HEAD
Notes:
- The files should not have any local changes. If there are any they should be
clearly documented below and one should aim to upstream them where possible.
-
+
- Files will be periodically syncronised with the respective upstream sources.
Updates will be made regularly, but since the code is _not_ aimed as a
cryptography solution any issues found should not be considered security ones.
diff --git a/lib/mesa/src/util/tests/cache/cache_test.c b/lib/mesa/src/util/tests/cache/cache_test.c
deleted file mode 100644
index ec1587daa..000000000
--- a/lib/mesa/src/util/tests/cache/cache_test.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 3a8fd213e..000000000
--- a/lib/mesa/src/util/tests/cache/meson.build
+++ /dev/null
@@ -1,34 +0,0 @@
-# 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/fast_idiv_by_const/fast_idiv_by_const_test.cpp b/lib/mesa/src/util/tests/fast_idiv_by_const/fast_idiv_by_const_test.cpp
deleted file mode 100644
index 3983a39ed..000000000
--- a/lib/mesa/src/util/tests/fast_idiv_by_const/fast_idiv_by_const_test.cpp
+++ /dev/null
@@ -1,472 +0,0 @@
-/*
- * Copyright © 2018 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.
- */
-
-#include <gtest/gtest.h>
-#include "util/bigmath.h"
-#include "util/fast_idiv_by_const.h"
-#include "util/u_math.h"
-
-#define RAND_TEST_ITERATIONS 100000
-
-#define MAX_UINT(bits) \
- (((bits) == 64) ? UINT64_MAX : ((1ull << (bits)) - 1))
-
-static inline uint64_t
-utrunc(uint64_t x, unsigned num_bits)
-{
- if (num_bits == 64)
- return x;
-
- return (x << (64 - num_bits)) >> (64 - num_bits);
-}
-
-static inline int64_t
-strunc(int64_t x, unsigned num_bits)
-{
- if (num_bits == 64)
- return x;
-
- return (x << (64 - num_bits)) >> (64 - num_bits);
-}
-
-static inline bool
-uint_is_in_range(uint64_t x, unsigned num_bits)
-{
- if (num_bits == 64)
- return true;
-
- return x < (1ull << num_bits);
-}
-
-static inline bool
-sint_is_in_range(int64_t x, unsigned num_bits)
-{
- if (num_bits == 64)
- return true;
-
- return x >= -(1ll << (num_bits - 1)) &&
- x < (1ll << (num_bits - 1));
-}
-
-static inline uint64_t
-uadd_sat(uint64_t a, uint64_t b, unsigned num_bits)
-{
- assert(uint_is_in_range(a, num_bits));
- assert(uint_is_in_range(b, num_bits));
-
- uint64_t sum = a + b;
- if (num_bits == 64) {
- /* Standard overflow check */
- return sum < a ? UINT64_MAX : sum;
- } else {
- /* Check if sum is more than num_bits */
- return (sum >> num_bits) ? MAX_UINT(num_bits) : sum;
- }
-}
-
-static inline uint64_t
-umul_add_high(uint64_t a, uint64_t b, uint64_t c, unsigned num_bits)
-{
- assert(uint_is_in_range(a, num_bits));
- assert(uint_is_in_range(b, num_bits));
- assert(uint_is_in_range(c, num_bits));
-
- if (num_bits == 64) {
- uint32_t a32[2] = { (uint32_t)a, (uint32_t)(a >> 32) };
- uint32_t b32[2] = { (uint32_t)b, (uint32_t)(b >> 32) };
- uint32_t c32[2] = { (uint32_t)c, (uint32_t)(c >> 32) };
-
- uint32_t ab32[4];
- ubm_mul_u32arr(ab32, a32, b32);
-
- uint32_t abc32[4];
- ubm_add_u32arr(abc32, ab32, c32);
-
- return abc32[2] | ((uint64_t)abc32[3] << 32);
- } else {
- assert(num_bits <= 32);
- return utrunc(((a * b) + c) >> num_bits, num_bits);
- }
-}
-
-static inline int64_t
-smul_high(int64_t a, int64_t b, unsigned num_bits)
-{
- assert(sint_is_in_range(a, num_bits));
- assert(sint_is_in_range(b, num_bits));
-
- if (num_bits == 64) {
- uint32_t a32[4] = {
- (uint32_t)a,
- (uint32_t)(a >> 32),
- (uint32_t)(a >> 63), /* sign extend */
- (uint32_t)(a >> 63), /* sign extend */
- };
- uint32_t b32[4] = {
- (uint32_t)b,
- (uint32_t)(b >> 32),
- (uint32_t)(b >> 63), /* sign extend */
- (uint32_t)(b >> 63), /* sign extend */
- };
-
- uint32_t ab32[4];
- ubm_mul_u32arr(ab32, a32, b32);
-
- return ab32[2] | ((uint64_t)ab32[3] << 32);
- } else {
- assert(num_bits <= 32);
- return strunc((a * b) >> num_bits, num_bits);
- }
-}
-
-static inline uint64_t
-fast_udiv_add_sat(uint64_t n, struct util_fast_udiv_info m, unsigned num_bits)
-{
- assert(uint_is_in_range(n, num_bits));
- assert(uint_is_in_range(m.multiplier, num_bits));
-
- n = n >> m.pre_shift;
- n = uadd_sat(n, m.increment, num_bits);
- n = umul_add_high(n, m.multiplier, 0, num_bits);
- n = n >> m.post_shift;
-
- return n;
-}
-
-static inline uint64_t
-fast_udiv_mul_add(uint64_t n, struct util_fast_udiv_info m, unsigned num_bits)
-{
- assert(uint_is_in_range(n, num_bits));
- assert(uint_is_in_range(m.multiplier, num_bits));
-
- n = n >> m.pre_shift;
- n = umul_add_high(n, m.multiplier,
- m.increment ? m.multiplier : 0,
- num_bits);
- n = n >> m.post_shift;
-
- return n;
-}
-
-static inline uint64_t
-fast_sdiv(int64_t n, int64_t d, struct util_fast_sdiv_info m, unsigned num_bits)
-{
- assert(sint_is_in_range(n, num_bits));
- assert(sint_is_in_range(d, num_bits));
- assert(sint_is_in_range(m.multiplier, num_bits));
-
- int64_t res;
- res = smul_high(n, m.multiplier, num_bits);
- if (d > 0 && m.multiplier < 0)
- res = strunc(res + n, num_bits);
- if (d < 0 && m.multiplier > 0)
- res = strunc(res - n, num_bits);
- res = res >> m.shift;
- res = res - (res >> (num_bits - 1));
-
- return res;
-}
-
-static uint64_t
-rand_uint(unsigned bits, unsigned min)
-{
- assert(bits >= 4);
-
- /* Make sure we get some small and large numbers and powers of two every
- * once in a while
- */
- int k = rand() % 64;
- if (k == 17) {
- return min + (rand() % 16);
- } else if (k == 42) {
- return MAX_UINT(bits) - (rand() % 16);
- } else if (k == 9) {
- uint64_t r;
- do {
- r = 1ull << (rand() % bits);
- } while (r < min);
- return r;
- }
-
- if (min == 0) {
- assert(bits <= 64);
- uint64_t r = 0;
- for (unsigned i = 0; i < 8; i++)
- r |= ((uint64_t)rand() & 0xf) << i * 8;
- return r >> (63 - (rand() % bits));
- } else {
- uint64_t r;
- do {
- r = rand_uint(bits, 0);
- } while (r < min);
- return r;
- }
-}
-
-static int64_t
-rand_sint(unsigned bits, unsigned min_abs)
-{
- /* Make sure we hit MIN_INT every once in a while */
- if (rand() % 64 == 37)
- return -(1 << (bits - 1));
-
- int64_t s = rand_uint(bits - 1, min_abs);
- return rand() & 1 ? s : -s;
-}
-
-static uint64_t
-udiv(uint64_t a, uint64_t b, unsigned bit_size)
-{
- switch (bit_size) {
- case 64: return (uint64_t)a / (uint64_t)b;
- case 32: return (uint32_t)a / (uint32_t)b;
- case 16: return (uint16_t)a / (uint16_t)b;
- case 8: return (uint8_t)a / (uint8_t)b;
- default:
- assert(!"Invalid bit size");
- return 0;
- }
-}
-
-static int64_t
-sdiv(int64_t a, int64_t b, unsigned bit_size)
-{
- switch (bit_size) {
- case 64: return (int64_t)a / (int64_t)b;
- case 32: return (int32_t)a / (int32_t)b;
- case 16: return (int16_t)a / (int16_t)b;
- case 8: return (int8_t)a / (int8_t)b;
- default:
- assert(!"Invalid bit size");
- return 0;
- }
-}
-
-static void
-random_udiv_add_sat_test(unsigned bits, bool bounded)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- uint64_t n = rand_uint(bits, 0);
- uint64_t d = rand_uint(bits, 2);
- assert(uint_is_in_range(n, bits));
- assert(uint_is_in_range(d, bits) && d >= 2);
-
- unsigned n_bits = bounded ? util_logbase2_64(MAX2(n, 1)) + 1 : bits;
-
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, n_bits, bits);
- EXPECT_EQ(fast_udiv_add_sat(n, m, bits), udiv(n, d, bits));
- }
-}
-
-static void
-random_udiv_mul_add_test(unsigned bits, bool bounded)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- uint64_t n = rand_uint(bits, 0);
- uint64_t d = rand_uint(bits, 1);
- assert(uint_is_in_range(n, bits));
- assert(uint_is_in_range(d, bits) && d >= 1);
-
- unsigned n_bits = bounded ? util_logbase2_64(MAX2(n, 1)) + 1: bits;
-
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, n_bits, bits);
- EXPECT_EQ(fast_udiv_mul_add(n, m, bits), udiv(n, d, bits));
- }
-}
-
-static void
-random_sdiv_test(unsigned bits)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- int64_t n = rand_sint(bits, 0);
- int64_t d;
- do {
- d = rand_sint(bits, 2);
- } while (util_is_power_of_two_or_zero64(llabs(d)));
-
- assert(sint_is_in_range(n, bits));
- assert(sint_is_in_range(d, bits) && llabs(d) >= 2);
-
- struct util_fast_sdiv_info m =
- util_compute_fast_sdiv_info(d, bits);
- EXPECT_EQ(fast_sdiv(n, d, m, bits), sdiv(n, d, bits));
- }
-}
-
-TEST(fast_idiv_by_const, uint8_add_sat)
-{
- /* 8-bit is small enough we can brute-force the entire space */
- for (unsigned d = 2; d < 256; d++) {
- for (unsigned n_bits = 1; n_bits <= 8; n_bits++) {
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, n_bits, 8);
-
- for (unsigned n = 0; n < (1u << n_bits); n++)
- EXPECT_EQ(fast_udiv_add_sat(n, m, 8), udiv(n, d, 8));
- }
- }
-}
-
-TEST(fast_idiv_by_const, uint8_mul_add)
-{
- /* 8-bit is small enough we can brute-force the entire space */
- for (unsigned d = 2; d < 256; d++) {
- for (unsigned n_bits = 1; n_bits <= 8; n_bits++) {
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, n_bits, 8);
-
- for (unsigned n = 0; n < (1u << n_bits); n++)
- EXPECT_EQ(fast_udiv_mul_add(n, m, 8), udiv(n, d, 8));
- }
- }
-}
-
-TEST(fast_idiv_by_const, int8)
-{
- /* 8-bit is small enough we can brute-force the entire space */
- for (int n = -128; n < 128; n++) {
- for (int d = -128; d < 128; d++) {
- if (util_is_power_of_two_or_zero(abs(d)))
- continue;
-
- struct util_fast_sdiv_info m =
- util_compute_fast_sdiv_info(d, 8);
- EXPECT_EQ(fast_sdiv(n, d, m, 8), sdiv(n, d, 8));
- }
- }
-}
-
-TEST(fast_idiv_by_const, uint16_add_sat_bounded)
-{
- random_udiv_add_sat_test(16, true);
-}
-
-TEST(fast_idiv_by_const, uint16_add_sat_full)
-{
- random_udiv_add_sat_test(16, false);
-}
-
-TEST(fast_idiv_by_const, uint16_mul_add_bounded)
-{
- random_udiv_mul_add_test(16, true);
-}
-
-TEST(fast_idiv_by_const, uint16_mul_add_full)
-{
- random_udiv_mul_add_test(16, false);
-}
-
-TEST(fast_idiv_by_const, int16)
-{
- random_sdiv_test(16);
-}
-
-TEST(fast_idiv_by_const, uint32_add_sat_bounded)
-{
- random_udiv_add_sat_test(32, true);
-}
-
-TEST(fast_idiv_by_const, uint32_add_sat_full)
-{
- random_udiv_add_sat_test(32, false);
-}
-
-TEST(fast_idiv_by_const, uint32_mul_add_bounded)
-{
- random_udiv_mul_add_test(32, true);
-}
-
-TEST(fast_idiv_by_const, uint32_mul_add_full)
-{
- random_udiv_mul_add_test(32, false);
-}
-
-TEST(fast_idiv_by_const, int32)
-{
- random_sdiv_test(32);
-}
-
-TEST(fast_idiv_by_const, util_fast_udiv32)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- uint32_t n = rand_uint(32, 0);
- uint32_t d = rand_uint(32, 1);
-
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, 32, 32);
- EXPECT_EQ(util_fast_udiv32(n, m), n / d);
- }
-}
-
-TEST(fast_idiv_by_const, util_fast_udiv32_nuw)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- uint32_t n = rand_uint(32, 0);
- if (n == UINT32_MAX)
- continue;
- uint32_t d = rand_uint(32, 1);
-
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, 32, 32);
- EXPECT_EQ(util_fast_udiv32_nuw(n, m), n / d);
- }
-}
-
-TEST(fast_idiv_by_const, util_fast_udiv32_u31_d_not_one)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- uint32_t n = rand_uint(31, 0);
- uint32_t d = rand_uint(31, 2);
-
- struct util_fast_udiv_info m =
- util_compute_fast_udiv_info(d, 31, 32);
- EXPECT_EQ(util_fast_udiv32_u31_d_not_one(n, m), n / d);
- }
-}
-
-TEST(fast_idiv_by_const, uint64_add_sat_bounded)
-{
- random_udiv_add_sat_test(64, true);
-}
-
-TEST(fast_idiv_by_const, uint64_add_sat_full)
-{
- random_udiv_add_sat_test(64, false);
-}
-
-TEST(fast_idiv_by_const, uint64_mul_add_bounded)
-{
- random_udiv_mul_add_test(64, true);
-}
-
-TEST(fast_idiv_by_const, uint64_mul_add_full)
-{
- random_udiv_mul_add_test(64, false);
-}
-
-TEST(fast_idiv_by_const, int64)
-{
- random_sdiv_test(64);
-}
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
deleted file mode 100644
index 8c3b79493..000000000
--- a/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright © 2018 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.
-
-test(
- 'fast_idiv_by_const',
- executable(
- 'fast_idiv_by_const_test',
- 'fast_idiv_by_const_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest],
- include_directories : inc_common,
- link_with : [libmesa_util],
- )
-)
diff --git a/lib/mesa/src/util/tests/fast_urem_by_const/fast_urem_by_const_test.cpp b/lib/mesa/src/util/tests/fast_urem_by_const/fast_urem_by_const_test.cpp
deleted file mode 100644
index 752cd8cd3..000000000
--- a/lib/mesa/src/util/tests/fast_urem_by_const/fast_urem_by_const_test.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright © 2018 Intel Corporation
- * Copyright © 2019 Valve 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.
- */
-
-#undef NDEBUG
-
-#include <gtest/gtest.h>
-#include "util/fast_urem_by_const.h"
-
-#define RAND_TEST_ITERATIONS 100000
-
-static uint32_t
-rand_uint(unsigned min)
-{
- /* Make sure we get some small and large numbers and powers of two every
- * once in a while
- */
- int k = rand() % 64;
- if (k == 17) {
- return min + (rand() % 16);
- } else if (k == 42) {
- return UINT32_MAX - (rand() % 16);
- } else if (k == 9) {
- uint32_t r;
- do {
- r = 1ull << (rand() % 32);
- } while (r < min);
- return r;
- }
-
- if (min == 0) {
- uint32_t r = 0;
- for (unsigned i = 0; i < 4; i++)
- r |= ((uint32_t)rand() & 0xf) << i * 8;
- return r >> (31 - (rand() % 32));
- } else {
- uint64_t r;
- do {
- r = rand_uint(0);
- } while (r < min);
- return r;
- }
-}
-
-static void
-test_case(uint32_t n, uint32_t d)
-{
- assert(d >= 1);
- uint64_t magic = REMAINDER_MAGIC(d);
- /* Note: there's already an assert inside util_fast_urem32(), so the
- * EXPECT_EQ is only here to make sure the test fails with a wrong result
- * even if asserts are disabled. Ideally we could disable the assert just
- * for the test to get a better error message, but that doesn't seem too
- * easy.
- */
- EXPECT_EQ(util_fast_urem32(n, d, magic), n % d);
-}
-
-TEST(fast_urem_by_const, random)
-{
- for (unsigned i = 0; i < RAND_TEST_ITERATIONS; i++) {
- uint64_t n = rand_uint(0);
- uint64_t d = rand_uint(1);
- test_case(n, d);
- }
-}
-
-TEST(fast_urem_by_const, special_cases)
-{
- test_case(0, 1);
- test_case(0, UINT32_MAX);
- test_case(UINT32_MAX, 1);
- test_case(1, UINT32_MAX);
- test_case(UINT32_MAX, UINT32_MAX);
- test_case(UINT32_MAX, UINT32_MAX - 1);
- test_case(UINT32_MAX - 1, UINT32_MAX - 1);
- test_case(UINT32_MAX - 2, UINT32_MAX - 1);
-}
-
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
deleted file mode 100644
index a16407d5e..000000000
--- a/lib/mesa/src/util/tests/fast_urem_by_const/meson.build
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright © 2018 Intel Corporation
-# Copyright © 2010 Valve 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.
-
-test(
- 'fast_urem_by_const',
- executable(
- 'fast_urem_by_const_test',
- 'fast_urem_by_const_test.cpp',
- dependencies : [idep_gtest, idep_mesautil],
- include_directories : inc_common,
- ),
- suite : ['util'],
-)
diff --git a/lib/mesa/src/util/tests/set/meson.build b/lib/mesa/src/util/tests/set/meson.build
deleted file mode 100644
index add3fc560..000000000
--- a/lib/mesa/src/util/tests/set/meson.build
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright © 2018 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.
-
-test(
- 'set',
- executable(
- 'set_test',
- 'set_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest],
- include_directories : inc_common,
- link_with : [libmesa_util],
- )
-)
diff --git a/lib/mesa/src/util/tests/set/set_test.cpp b/lib/mesa/src/util/tests/set/set_test.cpp
deleted file mode 100644
index a1eef0b3d..000000000
--- a/lib/mesa/src/util/tests/set/set_test.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright © 2018 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.
- */
-
-#include <gtest/gtest.h>
-#include "util/hash_table.h"
-#include "util/set.h"
-
-TEST(set, basic)
-{
- struct set *s = _mesa_set_create(NULL, _mesa_hash_pointer,
- _mesa_key_pointer_equal);
- struct set_entry *entry;
-
- const void *a = (const void *)10;
- const void *b = (const void *)20;
-
- _mesa_set_add(s, a);
- _mesa_set_add(s, b);
- EXPECT_EQ(s->entries, 2);
-
- _mesa_set_add(s, a);
- EXPECT_EQ(s->entries, 2);
-
- entry = _mesa_set_search(s, a);
- EXPECT_TRUE(entry);
- EXPECT_EQ(entry->key, a);
-
- _mesa_set_remove(s, entry);
- EXPECT_EQ(s->entries, 1);
-
- entry = _mesa_set_search(s, a);
- EXPECT_FALSE(entry);
-
- _mesa_set_destroy(s, NULL);
-}
-
-TEST(set, clone)
-{
- struct set *s = _mesa_set_create(NULL, _mesa_hash_pointer,
- _mesa_key_pointer_equal);
- struct set_entry *entry;
-
- const void *a = (const void *)10;
- const void *b = (const void *)20;
- const void *c = (const void *)30;
-
- _mesa_set_add(s, a);
- _mesa_set_add(s, b);
- _mesa_set_add(s, c);
-
- entry = _mesa_set_search(s, c);
- EXPECT_TRUE(entry);
- EXPECT_EQ(entry->key, c);
-
- _mesa_set_remove(s, entry);
- EXPECT_EQ(s->entries, 2);
-
- struct set *clone = _mesa_set_clone(s, NULL);
- EXPECT_EQ(clone->entries, 2);
-
- EXPECT_TRUE(_mesa_set_search(clone, a));
- EXPECT_TRUE(_mesa_set_search(clone, b));
- EXPECT_FALSE(_mesa_set_search(clone, c));
-
- _mesa_set_destroy(s, NULL);
- _mesa_set_destroy(clone, NULL);
-}
-
-TEST(set, remove_key)
-{
- struct set *s = _mesa_set_create(NULL, _mesa_hash_pointer,
- _mesa_key_pointer_equal);
-
- const void *a = (const void *)10;
- const void *b = (const void *)20;
- const void *c = (const void *)30;
-
- _mesa_set_add(s, a);
- _mesa_set_add(s, b);
- EXPECT_EQ(s->entries, 2);
-
- /* Remove existing key. */
- _mesa_set_remove_key(s, a);
- EXPECT_EQ(s->entries, 1);
- EXPECT_FALSE(_mesa_set_search(s, a));
- EXPECT_TRUE(_mesa_set_search(s, b));
-
- /* Remove non-existing key. */
- _mesa_set_remove_key(s, c);
- EXPECT_EQ(s->entries, 1);
- EXPECT_FALSE(_mesa_set_search(s, a));
- EXPECT_TRUE(_mesa_set_search(s, b));
-
- _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
deleted file mode 100644
index 9afb49301..000000000
--- a/lib/mesa/src/util/tests/sparse_array/meson.build
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright © 2019 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.
-
-test(
- 'sparse_array_multi_threaded',
- executable(
- 'multi_threaded',
- 'multi_threaded.c',
- dependencies : [idep_mesautil],
- 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
deleted file mode 100644
index b084ac994..000000000
--- a/lib/mesa/src/util/tests/sparse_array/multi_threaded.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright © 2019 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.
- */
-
-#undef NDEBUG
-
-#include "util/sparse_array.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include "c11/threads.h"
-
-#define NUM_THREADS 16
-#define NUM_RUNS 16
-#define NUM_SETS_PER_THREAD (1 << 10)
-#define MAX_ARR_SIZE (1 << 20)
-
-static int
-test_thread(void *_state)
-{
- struct util_sparse_array *arr = _state;
- for (unsigned i = 0; i < NUM_SETS_PER_THREAD; i++) {
- uint32_t idx = rand() % MAX_ARR_SIZE;
- uint32_t *elem = util_sparse_array_get(arr, idx);
- *elem = idx;
- }
-
- return 0;
-}
-
-static void
-run_test(unsigned run_idx)
-{
- size_t node_size = 4 << (run_idx / 2);
-
- struct util_sparse_array arr;
- util_sparse_array_init(&arr, sizeof(uint32_t), node_size);
-
- thrd_t threads[NUM_THREADS];
- for (unsigned i = 0; i < NUM_THREADS; i++) {
- int ret = thrd_create(&threads[i], test_thread, &arr);
- assert(ret == thrd_success);
- }
-
- for (unsigned i = 0; i < NUM_THREADS; i++) {
- int ret = thrd_join(threads[i], NULL);
- assert(ret == thrd_success);
- }
-
- util_sparse_array_validate(&arr);
-
- for (unsigned i = 0; i < MAX_ARR_SIZE; i++) {
- uint32_t *elem = util_sparse_array_get(&arr, i);
- assert(*elem == 0 || *elem == i);
- }
-
- util_sparse_array_finish(&arr);
-}
-
-int
-main(int argc, char **argv)
-{
- for (unsigned i = 0; i < NUM_RUNS; i++)
- run_test(i);
-}
diff --git a/lib/mesa/src/util/tests/string_buffer/meson.build b/lib/mesa/src/util/tests/string_buffer/meson.build
deleted file mode 100644
index 9f42e3550..000000000
--- a/lib/mesa/src/util/tests/string_buffer/meson.build
+++ /dev/null
@@ -1,30 +0,0 @@
-# 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.
-
-test(
- 'string_buffer',
- executable(
- 'string_buffer_test',
- 'string_buffer_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest],
- include_directories : inc_common,
- link_with : [libmesa_util],
- )
-)
diff --git a/lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp b/lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp
deleted file mode 100644
index 545f607fa..000000000
--- a/lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright © 2017 Thomas Helland
- *
- * 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 <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <gtest/gtest.h>
-#include "util/string_buffer.h"
-
-/**
- * \file string_buffer_test.cpp
- *
- * Test the string buffer implementation
- */
-
-#define INITIAL_BUF_SIZE 6
-class string_buffer : public ::testing::Test {
-public:
-
- struct _mesa_string_buffer *buf;
- const char *str1;
- const char *str2;
- const char *str3;
- char str4[80];
- char str5[40];
-
- virtual void SetUp();
- virtual void TearDown();
-};
-
-void
-string_buffer::SetUp()
-{
- str1 = "test1";
- str2 = "test2";
- str3 = "test1test2";
- buf = _mesa_string_buffer_create(NULL, INITIAL_BUF_SIZE);
-}
-
-void
-string_buffer::TearDown()
-{
- /* Finally, clean up after us */
- _mesa_string_buffer_destroy(buf);
-}
-
-static uint32_t
-space_left_in_buffer(_mesa_string_buffer *buf)
-{
- return buf->capacity - buf->length - 1;
-}
-
-TEST_F(string_buffer, string_buffer_tests)
-{
- /* The string terminator needs one byte, so there should one "missing" */
- EXPECT_TRUE(space_left_in_buffer(buf) == INITIAL_BUF_SIZE - 1);
-
- /* Start by appending str1 */
- EXPECT_TRUE(_mesa_string_buffer_append(buf, str1));
- EXPECT_TRUE(space_left_in_buffer(buf) ==
- INITIAL_BUF_SIZE - strlen(str1) - 1);
- EXPECT_TRUE(strcmp(buf->buf, str1) == 0);
-
- /* Add more, so that the string is resized */
- EXPECT_TRUE(_mesa_string_buffer_append(buf, str2));
-
- /* The string should now be equal to str3 */
- EXPECT_TRUE(strcmp(buf->buf, str3) == 0);
-
- /* Check that the length of the string is reset when clearing */
- _mesa_string_buffer_clear(buf);
- EXPECT_TRUE(buf->length == 0);
- EXPECT_TRUE(strlen(buf->buf) == 0);
-
- /* Test a string with some formatting */
- sprintf(str4, "Testing formatting %d, %f", 100, 1.0);
- EXPECT_TRUE(_mesa_string_buffer_printf(buf, "Testing formatting %d, %f", 100, 1.0));
- EXPECT_TRUE(strcmp(buf->buf, str4) == 0);
-
- /* Compile a string with some other formatting */
- sprintf(str5, "Testing formatting %d, %x", 100, 0xDEADBEAF);
-
- /* Concatenate str5 to str4 */
- strcat(str4, str5);
-
- /* Now use the formatted append function again */
- EXPECT_TRUE(_mesa_string_buffer_printf(buf, "Testing formatting %d, %x", 100, 0xDEADBEAF));
-
- /* The string buffer should now be equal to str4 */
- EXPECT_TRUE(strcmp(buf->buf, str4) == 0);
-
- _mesa_string_buffer_clear(buf);
-
- /* Test appending by one char at a time */
- EXPECT_TRUE(_mesa_string_buffer_append_char(buf, 'a'));
- EXPECT_TRUE(buf->length == 1);
- EXPECT_TRUE(strcmp(buf->buf, "a") == 0);
- EXPECT_TRUE(_mesa_string_buffer_append_char(buf, 'a'));
- EXPECT_TRUE(strcmp(buf->buf, "aa") == 0);
-}
diff --git a/lib/mesa/src/util/tests/timespec/meson.build b/lib/mesa/src/util/tests/timespec/meson.build
deleted file mode 100644
index c685db5fd..000000000
--- a/lib/mesa/src/util/tests/timespec/meson.build
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright © 2019 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.
-
-test(
- 'timespec',
- executable(
- 'timespec_test',
- 'timespec_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest, idep_mesautil],
- include_directories : inc_common,
- ),
- suite : ['util'],
-)
diff --git a/lib/mesa/src/util/tests/timespec/timespec_test.cpp b/lib/mesa/src/util/tests/timespec/timespec_test.cpp
deleted file mode 100644
index 5005506f9..000000000
--- a/lib/mesa/src/util/tests/timespec/timespec_test.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright © 2016 Collabora, Ltd.
- *
- * 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 "util/timespec.h"
-
-TEST(timespec_test, timespec_add)
-{
- struct timespec a, b, r;
-
- a.tv_sec = 1;
- a.tv_nsec = NSEC_PER_SEC - 1;
- b.tv_sec = 1;
- b.tv_nsec = 2;
- timespec_add(&r, &a, &b);
- EXPECT_EQ(r.tv_sec, 3);
- EXPECT_EQ(r.tv_nsec, 1);
-}
-
-TEST(timespec_test, timespec_sub)
-{
- struct timespec a, b, r;
-
- a.tv_sec = 1;
- a.tv_nsec = 1;
- b.tv_sec = 0;
- b.tv_nsec = 2;
- timespec_sub(&r, &a, &b);
- EXPECT_EQ(r.tv_sec, 0);
- EXPECT_EQ(r.tv_nsec, NSEC_PER_SEC - 1);
-}
-
-TEST(timespec_test, timespec_to_nsec)
-{
- struct timespec a;
-
- a.tv_sec = 4;
- a.tv_nsec = 4;
- EXPECT_EQ(timespec_to_nsec(&a), (NSEC_PER_SEC * 4ULL) + 4);
-}
-
-TEST(timespec_test, timespec_to_usec)
-{
- struct timespec a;
-
- a.tv_sec = 4;
- a.tv_nsec = 4000;
- EXPECT_EQ(timespec_to_usec(&a), (4000000ULL) + 4);
-}
-
-TEST(timespec_test, timespec_to_msec)
-{
- struct timespec a;
-
- a.tv_sec = 4;
- a.tv_nsec = 4000000;
- EXPECT_EQ(timespec_to_msec(&a), (4000ULL) + 4);
-}
-
-TEST(timespec_test, timespec_to_proto)
-{
- struct timespec a;
- uint32_t tv_sec_hi;
- uint32_t tv_sec_lo;
- uint32_t tv_nsec;
-
- a.tv_sec = 0;
- a.tv_nsec = 0;
- timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
- EXPECT_EQ(0, tv_sec_hi);
- EXPECT_EQ(0, tv_sec_lo);
- EXPECT_EQ(0, tv_nsec);
-
- a.tv_sec = 1234;
- a.tv_nsec = NSEC_PER_SEC - 1;
- timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
- EXPECT_EQ(0, tv_sec_hi);
- EXPECT_EQ(1234, tv_sec_lo);
- EXPECT_EQ(NSEC_PER_SEC - 1, tv_nsec);
-
- a.tv_sec = (time_t)0x7000123470005678LL;
- a.tv_nsec = 1;
- timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
- EXPECT_EQ((uint64_t)a.tv_sec >> 32, tv_sec_hi);
- EXPECT_EQ(0x70005678, tv_sec_lo);
- EXPECT_EQ(1, tv_nsec);
-}
-
-TEST(timespec_test, millihz_to_nsec)
-{
- EXPECT_EQ(millihz_to_nsec(60000), 16666666);
-}
-
-TEST(timespec_test, timespec_add_nsec)
-{
- struct timespec a, r;
-
- a.tv_sec = 0;
- a.tv_nsec = NSEC_PER_SEC - 1;
- timespec_add_nsec(&r, &a, 1);
- EXPECT_EQ(1, r.tv_sec);
- EXPECT_EQ(0, r.tv_nsec);
-
- timespec_add_nsec(&r, &a, 2);
- EXPECT_EQ(1, r.tv_sec);
- EXPECT_EQ(1, r.tv_nsec);
-
- timespec_add_nsec(&r, &a, (NSEC_PER_SEC * 2ULL));
- EXPECT_EQ(2, r.tv_sec);
- EXPECT_EQ(NSEC_PER_SEC - 1, r.tv_nsec);
-
- timespec_add_nsec(&r, &a, (NSEC_PER_SEC * 2ULL) + 2);
- EXPECT_EQ(r.tv_sec, 3);
- EXPECT_EQ(r.tv_nsec, 1);
-
- r.tv_sec = 4;
- r.tv_nsec = 0;
- timespec_add_nsec(&r, &r, NSEC_PER_SEC + 10ULL);
- EXPECT_EQ(5, r.tv_sec);
- EXPECT_EQ(10, r.tv_nsec);
-
- timespec_add_nsec(&r, &r, (NSEC_PER_SEC * 3ULL) - 9ULL);
- EXPECT_EQ(8, r.tv_sec);
- EXPECT_EQ(1, r.tv_nsec);
-
- timespec_add_nsec(&r, &r, (NSEC_PER_SEC * 7ULL) + (NSEC_PER_SEC - 1ULL));
- EXPECT_EQ(16, r.tv_sec);
- EXPECT_EQ(0, r.tv_nsec);
-}
-
-TEST(timespec_test, timespec_add_msec)
-{
- struct timespec a, r;
-
- a.tv_sec = 1000;
- a.tv_nsec = 1;
- timespec_add_msec(&r, &a, 2002);
- EXPECT_EQ(1002, r.tv_sec);
- EXPECT_EQ(2000001, r.tv_nsec);
-}
-
-TEST(timespec_test, timespec_sub_to_nsec)
-{
- struct timespec a, b;
-
- a.tv_sec = 1000;
- a.tv_nsec = 1;
- b.tv_sec = 1;
- b.tv_nsec = 2;
- EXPECT_EQ((999LL * NSEC_PER_SEC) - 1, timespec_sub_to_nsec(&a, &b));
-}
-
-TEST(timespec_test, timespec_sub_to_msec)
-{
- struct timespec a, b;
-
- a.tv_sec = 1000;
- a.tv_nsec = 2000000L;
- b.tv_sec = 2;
- b.tv_nsec = 1000000L;
- EXPECT_EQ((998 * 1000) + 1, timespec_sub_to_msec(&a, &b));
-}
-
-TEST(timespec_test, timespec_from_nsec)
-{
- struct timespec a;
-
- timespec_from_nsec(&a, 0);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_nsec(&a, NSEC_PER_SEC - 1);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(NSEC_PER_SEC - 1, a.tv_nsec);
-
- timespec_from_nsec(&a, NSEC_PER_SEC);
- EXPECT_EQ(1, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_nsec(&a, (5LL * NSEC_PER_SEC) + 1);
- EXPECT_EQ(5, a.tv_sec);
- EXPECT_EQ(1, a.tv_nsec);
-
- timespec_from_nsec(&a, UINT64_MAX);
- EXPECT_EQ(a.tv_nsec, UINT64_MAX % NSEC_PER_SEC);
- EXPECT_EQ(a.tv_sec, (time_t)(UINT64_MAX / NSEC_PER_SEC));
-}
-
-TEST(timespec_test, timespec_from_usec)
-{
- struct timespec a;
-
- timespec_from_usec(&a, 0);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_usec(&a, 999999);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(999999 * 1000, a.tv_nsec);
-
- timespec_from_usec(&a, 1000000);
- EXPECT_EQ(1, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_usec(&a, 5000001);
- EXPECT_EQ(5, a.tv_sec);
- EXPECT_EQ(1000, a.tv_nsec);
-}
-
-TEST(timespec_test, timespec_from_msec)
-{
- struct timespec a;
-
- timespec_from_msec(&a, 0);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_msec(&a, 999);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(999 * 1000000, a.tv_nsec);
-
- timespec_from_msec(&a, 1000);
- EXPECT_EQ(1, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_msec(&a, 5001);
- EXPECT_EQ(5, a.tv_sec);
- EXPECT_EQ(1000000, a.tv_nsec);
-}
-
-TEST(timespec_test, timespec_from_proto)
-{
- struct timespec a;
-
- timespec_from_proto(&a, 0, 0, 0);
- EXPECT_EQ(0, a.tv_sec);
- EXPECT_EQ(0, a.tv_nsec);
-
- timespec_from_proto(&a, 0, 1234, 9999);
- EXPECT_EQ(1234, a.tv_sec);
- EXPECT_EQ(9999, a.tv_nsec);
-
- timespec_from_proto(&a, 0x1234, 0x5678, 1);
- EXPECT_EQ((time_t)0x0000123400005678LL, a.tv_sec);
- EXPECT_EQ(1, a.tv_nsec);
-}
-
-TEST(timespec_test, timespec_is_zero)
-{
- struct timespec zero = { 0 };
- struct timespec non_zero_sec = { .tv_sec = 1, .tv_nsec = 0 };
- struct timespec non_zero_nsec = { .tv_sec = 0, .tv_nsec = 1 };
-
- EXPECT_TRUE(timespec_is_zero(&zero));
- EXPECT_FALSE(timespec_is_zero(&non_zero_nsec));
- EXPECT_FALSE(timespec_is_zero(&non_zero_sec));
-}
-
-TEST(timespec_test, timespec_eq)
-{
- struct timespec a = { .tv_sec = 2, .tv_nsec = 1 };
- struct timespec b = { .tv_sec = -1, .tv_nsec = 2 };
-
- EXPECT_TRUE(timespec_eq(&a, &a));
- EXPECT_TRUE(timespec_eq(&b, &b));
-
- EXPECT_FALSE(timespec_eq(&a, &b));
- EXPECT_FALSE(timespec_eq(&b, &a));
-}
diff --git a/lib/mesa/src/util/tests/vector/meson.build b/lib/mesa/src/util/tests/vector/meson.build
deleted file mode 100644
index 40ad93995..000000000
--- a/lib/mesa/src/util/tests/vector/meson.build
+++ /dev/null
@@ -1,30 +0,0 @@
-# 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 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.
-
-test(
- 'vector',
- executable(
- 'vector_test',
- 'vector_test.cpp',
- dependencies : [idep_gtest, idep_mesautil],
- 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/vector_test.cpp b/lib/mesa/src/util/tests/vector/vector_test.cpp
deleted file mode 100644
index aa7ca2bbf..000000000
--- a/lib/mesa/src/util/tests/vector/vector_test.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright © 2019 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 "util/u_vector.h"
-#include "gtest/gtest.h"
-
-static void test(uint32_t size_in_elements, uint32_t elements_to_walk, uint32_t start)
-{
- struct u_vector vector;
- uint32_t add_counter = 0;
- uint32_t remove_counter = 0;
-
- ASSERT_TRUE(u_vector_init(&vector, sizeof(uint64_t), sizeof(uint64_t) * size_in_elements));
-
- // Override the head and tail so we can quickly test rollover
- vector.head = vector.tail = start;
-
- EXPECT_EQ(sizeof(uint64_t) * size_in_elements, vector.size);
- EXPECT_EQ(0, u_vector_length(&vector));
-
- for (uint32_t i = 0; i < size_in_elements; i++) {
- *(uint64_t*)u_vector_add(&vector) = add_counter++;
-
- int length = u_vector_length(&vector);
- EXPECT_EQ(i + 1, length);
-
- // Check the entries
- uint32_t count = 0;
- void* element;
- u_vector_foreach(element, &vector)
- {
- EXPECT_EQ(count, *(uint64_t*)element) << "i: " << i << " count: " << count;
- count++;
- }
- EXPECT_EQ(count, length);
- }
-
- // Remove + add
- for (uint32_t i = 0; i < elements_to_walk; i++) {
- u_vector_remove(&vector);
- remove_counter++;
- *(uint64_t*)u_vector_add(&vector) = add_counter++;
- }
-
- EXPECT_EQ(sizeof(uint64_t) * size_in_elements, vector.size);
-
- // Grow the vector now
- *(uint64_t*)u_vector_add(&vector) = add_counter++;
- EXPECT_EQ(size_in_elements + 1, u_vector_length(&vector));
-
- EXPECT_EQ(sizeof(uint64_t) * size_in_elements * 2, vector.size);
-
- {
- uint32_t count = remove_counter;
- void* element;
- u_vector_foreach(element, &vector)
- {
- EXPECT_EQ(count++, *(uint64_t*)element) << "count: " << count;
- }
- }
-
- u_vector_finish(&vector);
-}
-
-TEST(Vector, Grow0) { test(4, 0, 0); }
-
-TEST(Vector, Grow1) { test(4, 1, 0); }
-
-TEST(Vector, Grow2) { test(4, 2, 0); }
-
-TEST(Vector, Grow3) { test(4, 3, 0); }
-
-TEST(Vector, Grow4) { test(4, 4, 0); }
-
-TEST(Vector, Grow5) { test(4, 5, 0); }
-
-TEST(Vector, Rollover)
-{
- uint32_t start = (1ull << 32) - 4 * sizeof(uint64_t);
- test(8, 4, start);
-}
diff --git a/lib/mesa/src/util/u_atomic.h b/lib/mesa/src/util/u_atomic.h
index 0bd6a4aaa..c94a9a459 100644
--- a/lib/mesa/src/util/u_atomic.h
+++ b/lib/mesa/src/util/u_atomic.h
@@ -82,7 +82,7 @@
/* Unlocked version for single threaded environments, such as some
* windows kernel modules.
*/
-#if defined(PIPE_ATOMIC_OS_UNLOCKED)
+#if defined(PIPE_ATOMIC_OS_UNLOCKED)
#define PIPE_ATOMIC "Unlocked"
@@ -153,10 +153,8 @@
((void) p_atomic_add_return((_v), (_i)))
#define p_atomic_add_return(_v, _i) (\
- sizeof *(_v) == sizeof(char) ? _InterlockedExchangeAdd8 ((char *) (_v), (_i)) : \
- sizeof *(_v) == sizeof(short) ? _InterlockedExchangeAdd16((short *) (_v), (_i)) : \
- sizeof *(_v) == sizeof(long) ? _InterlockedExchangeAdd ((long *) (_v), (_i)) : \
- sizeof *(_v) == sizeof(__int64) ? InterlockedExchangeAdd64((__int64 *)(_v), (_i)) : \
+ sizeof *(_v) == sizeof(long) ? InterlockedAdd ((long *) (_v), (_i)) : \
+ sizeof *(_v) == sizeof(__int64) ? InterlockedAdd64((__int64 *)(_v), (_i)) : \
(assert(!"should not get here"), 0))
#define p_atomic_cmpxchg(_v, _old, _new) (\
diff --git a/lib/mesa/src/util/u_atomic_test.c b/lib/mesa/src/util/u_atomic_test.c
deleted file mode 100644
index 7844f6162..000000000
--- a/lib/mesa/src/util/u_atomic_test.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2014 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-
-/* Force assertions, even on debug builds. */
-#undef NDEBUG
-
-
-#include <stdint.h>
-#include <inttypes.h>
-#include <assert.h>
-
-#include "u_atomic.h"
-
-#ifdef _MSC_VER
-#pragma warning( disable : 28112 ) /* Accessing a local variable via an Interlocked function */
-#pragma warning( disable : 28113 ) /* A variable which is accessed via an Interlocked function must always be accessed via an Interlocked function */
-#endif
-
-
-/* Test only assignment-like operations, which are supported on all types */
-#define test_atomic_assign(type, ones) \
- static void test_atomic_assign_##type (void) { \
- type v, r; \
- \
- p_atomic_set(&v, ones); \
- assert(v == ones && "p_atomic_set"); \
- \
- r = p_atomic_read(&v); \
- assert(r == ones && "p_atomic_read"); \
- \
- v = ones; \
- r = p_atomic_cmpxchg(&v, 0, 1); \
- assert(v == ones && "p_atomic_cmpxchg"); \
- assert(r == ones && "p_atomic_cmpxchg"); \
- r = p_atomic_cmpxchg(&v, ones, 0); \
- assert(v == 0 && "p_atomic_cmpxchg"); \
- assert(r == ones && "p_atomic_cmpxchg"); \
- \
- (void) r; \
- }
-
-
-/* Test arithmetic operations that are supported on 8 bits integer types */
-#define test_atomic_8bits(type, ones) \
- test_atomic_assign(type, ones) \
- \
- static void test_atomic_8bits_##type (void) { \
- type v, r; \
- \
- test_atomic_assign_##type(); \
- \
- v = 23; \
- p_atomic_add(&v, 42); \
- r = p_atomic_read(&v); \
- assert(r == 65 && "p_atomic_add"); \
- \
- (void) r; \
- }
-
-
-/* Test all operations */
-#define test_atomic(type, ones) \
- test_atomic_8bits(type, ones) \
- \
- static void test_atomic_##type (void) { \
- type v, r; \
- bool b; \
- \
- test_atomic_8bits_##type(); \
- \
- v = 2; \
- b = p_atomic_dec_zero(&v); \
- assert(v == 1 && "p_atomic_dec_zero"); \
- assert(b == false && "p_atomic_dec_zero"); \
- b = p_atomic_dec_zero(&v); \
- assert(v == 0 && "p_atomic_dec_zero"); \
- assert(b == true && "p_atomic_dec_zero"); \
- b = p_atomic_dec_zero(&v); \
- assert(v == ones && "p_atomic_dec_zero"); \
- assert(b == false && "p_atomic_dec_zero"); \
- \
- v = ones; \
- p_atomic_inc(&v); \
- assert(v == 0 && "p_atomic_inc"); \
- \
- v = ones; \
- r = p_atomic_inc_return(&v); \
- assert(v == 0 && "p_atomic_inc_return"); \
- assert(r == v && "p_atomic_inc_return"); \
- \
- v = 0; \
- p_atomic_dec(&v); \
- assert(v == ones && "p_atomic_dec"); \
- \
- v = 0; \
- r = p_atomic_dec_return(&v); \
- assert(v == ones && "p_atomic_dec_return"); \
- assert(r == v && "p_atomic_dec_return"); \
- \
- (void) r; \
- (void) b; \
- }
-
-
-test_atomic(int, -1)
-test_atomic(unsigned, ~0U)
-
-test_atomic(int16_t, INT16_C(-1))
-test_atomic(uint16_t, UINT16_C(0xffff))
-test_atomic(int32_t, INT32_C(-1))
-test_atomic(uint32_t, UINT32_C(0xffffffff))
-test_atomic(int64_t, INT64_C(-1))
-test_atomic(uint64_t, UINT64_C(0xffffffffffffffff))
-
-test_atomic_8bits(int8_t, INT8_C(-1))
-test_atomic_8bits(uint8_t, UINT8_C(0xff))
-test_atomic_assign(bool, true)
-
-int
-main()
-{
- test_atomic_int();
- test_atomic_unsigned();
-
- test_atomic_int16_t();
- test_atomic_uint16_t();
- test_atomic_int32_t();
- test_atomic_uint32_t();
- test_atomic_int64_t();
- test_atomic_uint64_t();
-
- test_atomic_8bits_int8_t();
- test_atomic_8bits_uint8_t();
- test_atomic_assign_bool();
-
- return 0;
-}
diff --git a/lib/mesa/src/util/u_cpu_detect.c b/lib/mesa/src/util/u_cpu_detect.c
index 0d5f52e68..c63c9d32d 100644
--- a/lib/mesa/src/util/u_cpu_detect.c
+++ b/lib/mesa/src/util/u_cpu_detect.c
@@ -1,5 +1,5 @@
/**************************************************************************
- *
+ *
* Copyright 2008 Dennis Smit
* All Rights Reserved.
*
@@ -21,7 +21,7 @@
* 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.
- *
+ *
**************************************************************************/
/**
@@ -818,6 +818,10 @@ util_cpu_detect_once(void)
check_os_mips64_support();
#endif /* PIPE_ARCH_MIPS64 */
+#if defined(PIPE_ARCH_S390)
+ util_cpu_caps.family = CPU_S390X;
+#endif
+
get_cpu_topology();
if (debug_get_option_dump_cpu()) {
diff --git a/lib/mesa/src/util/u_debug_stack.c b/lib/mesa/src/util/u_debug_stack.c
index 86bfb2fb6..87f981f98 100644
--- a/lib/mesa/src/util/u_debug_stack.c
+++ b/lib/mesa/src/util/u_debug_stack.c
@@ -1,5 +1,5 @@
/**************************************************************************
- *
+ *
* Copyright 2009 VMware, Inc.
* All Rights Reserved.
*
@@ -75,7 +75,7 @@ symbol_name_cached(unw_cursor_t *cursor, unw_proc_info_t *pip)
procname[1] = 0;
}
- if (asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "") == -1)
+ if (asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "") == -1)
name = "??";
entry = _mesa_hash_table_insert(symbols_hash, addr, (void*)name);
}
@@ -256,10 +256,11 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
const void **frame_pointer = ((const void **)__builtin_frame_address(1));
#pragma GCC diagnostic pop
#elif defined(PIPE_CC_MSVC)
+ const void **frame_pointer;
__asm {
mov frame_pointer, ebp
}
- const void **frame_pointer = (const void **)frame_pointer[0];
+ frame_pointer = (const void **)frame_pointer[0];
#else
const void **frame_pointer = NULL;
#endif
diff --git a/lib/mesa/src/util/u_debug_stack_test.cpp b/lib/mesa/src/util/u_debug_stack_test.cpp
deleted file mode 100644
index b9a563488..000000000
--- a/lib/mesa/src/util/u_debug_stack_test.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright © 2020 Google, Inc.
- *
- * 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 <stdio.h>
-#include <gtest/gtest.h>
-
-#include "util/macros.h"
-#include "util/u_debug_stack.h"
-
-static void ATTRIBUTE_NOINLINE
-func_a(void)
-{
- struct debug_stack_frame backtrace[16];
-
- fprintf(stderr, "--- backtrace from func_a:\n");
- debug_backtrace_capture(backtrace, 0, 16);
- debug_backtrace_dump(backtrace, 16);
-}
-
-static void ATTRIBUTE_NOINLINE
-func_b(void)
-{
- struct debug_stack_frame backtrace[16];
-
- func_a();
-
- fprintf(stderr, "--- backtrace from func_b:\n");
- debug_backtrace_capture(backtrace, 0, 16);
- debug_backtrace_dump(backtrace, 16);
-}
-
-static void ATTRIBUTE_NOINLINE
-func_c(struct debug_stack_frame *frames)
-{
- debug_backtrace_capture(frames, 0, 16);
-}
-
-TEST(u_debug_stack_test, basics)
-{
- struct debug_stack_frame backtrace[16];
- struct debug_stack_frame stored_backtrace[16];
-
- func_c(stored_backtrace);
-
- fprintf(stderr, "--- backtrace from main to stderr:\n");
- debug_backtrace_capture(backtrace, 0, 16);
- debug_backtrace_print(stderr, backtrace, 16);
-
- fprintf(stderr, "--- backtrace from main again to debug_printf:\n");
- debug_backtrace_capture(backtrace, 0, 16);
- debug_backtrace_dump(backtrace, 16);
-
- func_a();
-
- func_b();
-
- fprintf(stderr, "--- stored backtrace from start of main:\n");
- debug_backtrace_dump(stored_backtrace, 16);
-}
-
-#if _POSIX_C_SOURCE >= 200809L
-
-TEST(u_debug_stack_test, capture_not_overwritten)
-{
- struct debug_stack_frame backtrace1[16], backtrace2[16];
-
- FILE *fp;
- char *bt1, *bt2;
- size_t size;
-
- /* Old android implementation uses one global capture per thread. Test that
- * we can store multiple captures and that they decode to different
- * backtraces.
- */
-
- func_c(backtrace1);
- debug_backtrace_capture(backtrace2, 0, 16);
-
- fp = open_memstream(&bt1, &size);
- debug_backtrace_print(fp, backtrace1, 16);
- fclose(fp);
-
- fp = open_memstream(&bt2, &size);
- debug_backtrace_print(fp, backtrace2, 16);
- fclose(fp);
-
- if (size > 0) {
- EXPECT_STRNE(bt1, bt2);
- }
-
- free(bt1);
- free(bt2);
-}
-
-#endif
diff --git a/lib/mesa/src/util/u_dynarray.h b/lib/mesa/src/util/u_dynarray.h
index 000feaa83..6f91b8208 100644
--- a/lib/mesa/src/util/u_dynarray.h
+++ b/lib/mesa/src/util/u_dynarray.h
@@ -91,7 +91,7 @@ util_dynarray_ensure_cap(struct util_dynarray *buf, unsigned newcap)
data = realloc(buf->data, capacity);
}
if (!data)
- return 0;
+ return NULL;
buf->data = data;
buf->capacity = capacity;
@@ -105,12 +105,12 @@ MUST_CHECK static inline void *
util_dynarray_resize_bytes(struct util_dynarray *buf, unsigned nelts, size_t eltsize)
{
if (unlikely(nelts > UINT_MAX / eltsize))
- return 0;
+ return NULL;
unsigned newsize = nelts * eltsize;
void *p = util_dynarray_ensure_cap(buf, newsize);
if (!p)
- return 0;
+ return NULL;
buf->size = newsize;
@@ -133,12 +133,12 @@ util_dynarray_grow_bytes(struct util_dynarray *buf, unsigned ngrow, size_t eltsi
if (unlikely(ngrow > (UINT_MAX / eltsize) ||
growbytes > UINT_MAX - buf->size))
- return 0;
+ return NULL;
unsigned newsize = buf->size + growbytes;
void *p = util_dynarray_ensure_cap(buf, newsize);
if (!p)
- return 0;
+ return NULL;
buf->size = newsize;
diff --git a/lib/mesa/src/util/u_endian.h b/lib/mesa/src/util/u_endian.h
index d9ead69a4..661628e18 100644
--- a/lib/mesa/src/util/u_endian.h
+++ b/lib/mesa/src/util/u_endian.h
@@ -1,8 +1,8 @@
/**************************************************************************
- *
+ *
* Copyright 2007-2008 VMware, Inc.
* All Rights Reserved.
- *
+ *
* 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
@@ -10,11 +10,11 @@
* distribute, sub license, 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 NON-INFRINGEMENT.
@@ -22,7 +22,7 @@
* 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.
- *
+ *
**************************************************************************/
#ifndef U_ENDIAN_H
#define U_ENDIAN_H
diff --git a/lib/mesa/src/util/u_printf.cpp b/lib/mesa/src/util/u_printf.cpp
deleted file mode 100644
index 3bd406a4e..000000000
--- a/lib/mesa/src/util/u_printf.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// Copyright 2020 Serge Martin
-//
-// 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.
-//
-// Extract from Serge's printf clover code by airlied.
-
-#include <stdarg.h>
-#include "u_printf.h"
-
-size_t util_printf_next_spec_pos(const std::string &s, size_t pos)
-{
- size_t next_tok, spec_pos;
- do {
- pos = s.find_first_of('%', pos);
-
- if (pos == std::string::npos)
- return -1;
-
- if (s[pos + 1] == '%') {
- pos += 2;
- continue;
- }
-
- next_tok = s.find_first_of('%', pos + 1);
- spec_pos = s.find_first_of("cdieEfFgGaAosuxXp", pos + 1);
- if (spec_pos != std::string::npos)
- if (spec_pos < next_tok)
- return spec_pos;
-
- pos++;
- } while (1);
-}
-
-size_t util_printf_next_spec_pos(const char *str, size_t pos)
-{
- return util_printf_next_spec_pos(std::string(str), pos);
-}
diff --git a/lib/mesa/src/util/u_qsort_test.cpp b/lib/mesa/src/util/u_qsort_test.cpp
deleted file mode 100644
index a0964e452..000000000
--- a/lib/mesa/src/util/u_qsort_test.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright © 2021 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.
- */
-
-#include <gtest/gtest.h>
-
-#include "util/u_qsort.h"
-
-constexpr int CONTEXT_CHECK = 12345;
-
-static int
-cmp_func(const void *a, const void *b, void *ctx)
-{
- int check = *reinterpret_cast<const int*>(ctx);
- EXPECT_EQ(check, CONTEXT_CHECK);
-
- int elem1 = *reinterpret_cast<const int*>(a);
- int elem2 = *reinterpret_cast<const int*>(b);
- return elem1 - elem2;
-}
-
-TEST(u_qsort_test, qsort_test)
-{
- int data[] = { 3, 6, 4, 9, 10, 2, 5, 7, 8, 1 };
- int ctx = CONTEXT_CHECK;
-
- util_qsort_r(data, GTEST_ARRAY_SIZE_(data),
- sizeof(data[0]), cmp_func,
- reinterpret_cast<void *>(&ctx));
-
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(data); ++i) {
- EXPECT_EQ(data[i], i + 1);
- }
-}
diff --git a/lib/mesa/src/util/u_queue.c b/lib/mesa/src/util/u_queue.c
index f0eb78955..d35b8f2f2 100644
--- a/lib/mesa/src/util/u_queue.c
+++ b/lib/mesa/src/util/u_queue.c
@@ -527,7 +527,8 @@ static void
util_queue_finish_execute(void *data, void *gdata, int num_thread)
{
util_barrier *barrier = data;
- util_barrier_wait(barrier);
+ if (util_barrier_wait(barrier))
+ util_barrier_destroy(barrier);
}
void
@@ -705,8 +706,6 @@ util_queue_finish(struct util_queue *queue)
}
simple_mtx_unlock(&queue->finish_lock);
- util_barrier_destroy(&barrier);
-
free(fences);
}
diff --git a/lib/mesa/src/util/u_thread.h b/lib/mesa/src/util/u_thread.h
index 013e8be6a..d06ff6bed 100644
--- a/lib/mesa/src/util/u_thread.h
+++ b/lib/mesa/src/util/u_thread.h
@@ -1,9 +1,9 @@
/**************************************************************************
- *
+ *
* Copyright 1999-2006 Brian Paul
* Copyright 2008 VMware, Inc.
* All Rights Reserved.
- *
+ *
* 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
@@ -75,19 +75,15 @@
* still want to use normal TLS (which involves a function call, but not the
* expensive pthread_getspecific() or its equivalent).
*/
+#ifdef USE_ELF_TLS
#ifdef _MSC_VER
#define __THREAD_INITIAL_EXEC __declspec(thread)
-#elif defined(ANDROID)
-/* Android 29 gained ELF TLS support, but it doesn't support initial-exec and
- * it will throw:
- *
- * dlopen failed: TLS symbol "(null)" in dlopened
- * "/vendor/lib64/egl/libEGL_mesa.so" referenced from
- * "/vendor/lib64/egl/libEGL_mesa.so" using IE access model.
- */
-#define __THREAD_INITIAL_EXEC __thread
-#else
+#elif defined(__GLIBC__)
#define __THREAD_INITIAL_EXEC __thread __attribute__((tls_model("initial-exec")))
+#define REALLY_INITIAL_EXEC
+#else
+#define __THREAD_INITIAL_EXEC __thread
+#endif
#endif
static inline int
@@ -250,6 +246,7 @@ util_thread_get_time_nano(thrd_t thread)
clock_gettime(cid, &ts);
return (int64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
#else
+ (void)thread;
return 0;
#endif
}
@@ -296,9 +293,9 @@ static inline void util_barrier_destroy(util_barrier *barrier)
pthread_barrier_destroy(barrier);
}
-static inline void util_barrier_wait(util_barrier *barrier)
+static inline bool util_barrier_wait(util_barrier *barrier)
{
- pthread_barrier_wait(barrier);
+ return pthread_barrier_wait(barrier) == PTHREAD_BARRIER_SERIAL_THREAD;
}
@@ -328,7 +325,7 @@ static inline void util_barrier_destroy(util_barrier *barrier)
cnd_destroy(&barrier->condvar);
}
-static inline void util_barrier_wait(util_barrier *barrier)
+static inline bool util_barrier_wait(util_barrier *barrier)
{
mtx_lock(&barrier->mutex);
@@ -348,6 +345,8 @@ static inline void util_barrier_wait(util_barrier *barrier)
}
mtx_unlock(&barrier->mutex);
+
+ return true;
}
#endif
diff --git a/lib/mesa/src/util/u_vector.h b/lib/mesa/src/util/u_vector.h
index 1283e78b7..5a1a08934 100644
--- a/lib/mesa/src/util/u_vector.h
+++ b/lib/mesa/src/util/u_vector.h
@@ -21,7 +21,7 @@
* IN THE SOFTWARE.
*/
-/*
+/*
* u_vector is a vector based queue for storing arbitrary
* sized arrays of objects without using a linked list.
*/
@@ -98,10 +98,18 @@ u_vector_finish(struct u_vector *queue)
free(queue->data);
}
+#ifdef __cplusplus
+#define u_vector_element_cast(elem) (decltype(elem))
+#else
+#define u_vector_element_cast(elem) (void *)
+#endif
+
#define u_vector_foreach(elem, queue) \
STATIC_ASSERT(__builtin_types_compatible_p(__typeof__(queue), struct u_vector *)); \
for (uint32_t __u_vector_offset = (queue)->tail; \
- elem = (void *)((char *)(queue)->data + (__u_vector_offset & ((queue)->size - 1))), __u_vector_offset != (queue)->head; \
+ elem = u_vector_element_cast(elem)((char *)(queue)->data + \
+ (__u_vector_offset & ((queue)->size - 1))), \
+ __u_vector_offset != (queue)->head; \
__u_vector_offset += (queue)->element_size)
#ifdef __cplusplus
diff --git a/lib/mesa/src/util/xmlconfig.c b/lib/mesa/src/util/xmlconfig.c
index dde6e5fa0..a824f2f1a 100644
--- a/lib/mesa/src/util/xmlconfig.c
+++ b/lib/mesa/src/util/xmlconfig.c
@@ -15,11 +15,11 @@
* 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
- * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS 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
+ * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS 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.
- *
+ *
*/
/**
* \file xmlconfig.c
@@ -272,7 +272,7 @@ findOption(const driOptionCache *cache, const char *name)
/* this is just the starting point of the linear search for the option */
for (i = 0; i < size; ++i, hash = (hash+1) & mask) {
/* if we hit an empty entry then the option is not defined (yet) */
- if (cache->info[hash].name == 0)
+ if (cache->info[hash].name == NULL)
break;
else if (!strcmp(name, cache->info[hash].name))
break;
@@ -320,7 +320,7 @@ driParseOptionInfo(driOptionCache *info,
/* Make the hash table big enough to fit more than the maximum number of
* config options we've ever seen in a driver.
*/
- info->tableSize = 6;
+ info->tableSize = 7;
info->info = calloc((size_t)1 << info->tableSize, sizeof(driOptionInfo));
info->values = calloc((size_t)1 << info->tableSize, sizeof(driOptionValue));
if (info->info == NULL || info->values == NULL) {
@@ -681,6 +681,7 @@ parseAppAttr(struct OptConfData *data, const char **attr)
uint32_t i;
const char *exec = NULL;
const char *sha1 = NULL;
+ const char *exec_regexp = NULL;
const char *application_name_match = NULL;
const char *application_versions = NULL;
driOptionInfo version_range = {
@@ -690,6 +691,7 @@ parseAppAttr(struct OptConfData *data, const char **attr)
for (i = 0; attr[i]; i += 2) {
if (!strcmp(attr[i], "name")) /* not needed here */;
else if (!strcmp(attr[i], "executable")) exec = attr[i+1];
+ else if (!strcmp(attr[i], "executable_regexp")) exec_regexp = attr[i+1];
else if (!strcmp(attr[i], "sha1")) sha1 = attr[i+1];
else if (!strcmp(attr[i], "application_name_match"))
application_name_match = attr[i+1];
@@ -699,6 +701,15 @@ parseAppAttr(struct OptConfData *data, const char **attr)
}
if (exec && strcmp(exec, data->execName)) {
data->ignoringApp = data->inApp;
+ } else if (exec_regexp) {
+ regex_t re;
+
+ if (regcomp(&re, exec_regexp, REG_EXTENDED|REG_NOSUB) == 0) {
+ if (regexec(&re, data->execName, 0, NULL, 0) == REG_NOMATCH)
+ data->ignoringApp = data->inApp;
+ regfree(&re);
+ } else
+ XML_WARNING("Invalid executable_regexp=\"%s\".", exec_regexp);
} else if (sha1) {
/* SHA1_DIGEST_STRING_LENGTH includes terminating null byte */
if (strlen(sha1) != (SHA1_DIGEST_STRING_LENGTH - 1)) {
@@ -998,7 +1009,10 @@ scandir_filter(const struct dirent *ent)
(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)))
return 0;
#else
- if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
+ /* Allow through unknown file types for filesystems that don't support d_type
+ * The full filepath isn't available here to stat the file
+ */
+ if (ent->d_type != DT_REG && ent->d_type != DT_LNK && ent->d_type != DT_UNKNOWN)
return 0;
#endif
@@ -1022,10 +1036,26 @@ parseConfigDir(struct OptConfData *data, const char *dirname)
for (i = 0; i < count; i++) {
char filename[PATH_MAX];
+#ifdef DT_REG
+ unsigned char d_type = entries[i]->d_type;
+#endif
snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
free(entries[i]);
+#ifdef DT_REG
+ /* In the case of unknown d_type, ensure it is a regular file
+ * This can be accomplished with stat on the full filepath
+ */
+ if (d_type == DT_UNKNOWN) {
+ struct stat st;
+ if (stat(filename, &st) != 0 ||
+ !S_ISREG(st.st_mode)) {
+ continue;
+ }
+ }
+#endif
+
parseOneConfigFile(data, filename);
}
diff --git a/lib/mesa/src/util/xmlconfig.h b/lib/mesa/src/util/xmlconfig.h
index 8e6327951..82554b7ce 100644
--- a/lib/mesa/src/util/xmlconfig.h
+++ b/lib/mesa/src/util/xmlconfig.h
@@ -15,11 +15,11 @@
* 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
- * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS 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
+ * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS 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.
- *
+ *
*/
/**
* \file xmlconfig.h