summaryrefslogtreecommitdiff
path: root/lib/mesa/src/util/tests
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2020-01-22 02:13:18 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2020-01-22 02:13:18 +0000
commitfdcc03929065b5bf5dd93553db219ea3e05c8c34 (patch)
treeca90dc8d9e89febdcd4160956c1b8ec098a4efc9 /lib/mesa/src/util/tests
parent3c9de4a7e13712b5696750bbd59a18c848742022 (diff)
Import Mesa 19.2.8
Diffstat (limited to 'lib/mesa/src/util/tests')
-rw-r--r--lib/mesa/src/util/tests/fast_idiv_by_const/fast_idiv_by_const_test.cpp2
-rw-r--r--lib/mesa/src/util/tests/fast_idiv_by_const/meson.build3
-rw-r--r--lib/mesa/src/util/tests/fast_urem_by_const/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/hash_table/clear.c15
-rw-r--r--lib/mesa/src/util/tests/hash_table/collision.c2
-rw-r--r--lib/mesa/src/util/tests/hash_table/delete_and_lookup.c2
-rw-r--r--lib/mesa/src/util/tests/hash_table/delete_management.c15
-rw-r--r--lib/mesa/src/util/tests/hash_table/destroy_callback.c2
-rw-r--r--lib/mesa/src/util/tests/hash_table/insert_and_lookup.c2
-rw-r--r--lib/mesa/src/util/tests/hash_table/insert_many.c13
-rw-r--r--lib/mesa/src/util/tests/hash_table/meson.build4
-rw-r--r--lib/mesa/src/util/tests/hash_table/random_entry.c9
-rw-r--r--lib/mesa/src/util/tests/hash_table/remove_key.c2
-rw-r--r--lib/mesa/src/util/tests/hash_table/remove_null.c2
-rw-r--r--lib/mesa/src/util/tests/hash_table/replacement.c2
-rw-r--r--lib/mesa/src/util/tests/set/meson.build3
-rw-r--r--lib/mesa/src/util/tests/set/set_test.cpp33
-rw-r--r--lib/mesa/src/util/tests/string_buffer/meson.build3
-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/vma/meson.build2
-rw-r--r--lib/mesa/src/util/tests/vma/vma_random_test.cpp8
23 files changed, 547 insertions, 29 deletions
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
index 3983a39ed..b0b3669e7 100644
--- 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
@@ -21,6 +21,8 @@
* IN THE SOFTWARE.
*/
+#undef NDEBUG
+
#include <gtest/gtest.h>
#include "util/bigmath.h"
#include "util/fast_idiv_by_const.h"
diff --git a/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build b/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
index 90ac7d159..2a341d181 100644
--- a/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
+++ b/lib/mesa/src/util/tests/fast_idiv_by_const/meson.build
@@ -23,9 +23,8 @@ test(
executable(
'fast_idiv_by_const_test',
'fast_idiv_by_const_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest],
+ dependencies : [idep_gtest, idep_mesautil],
include_directories : inc_common,
- link_with : [libmesa_util],
),
suite : ['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
new file mode 100644
index 000000000..752cd8cd3
--- /dev/null
+++ b/lib/mesa/src/util/tests/fast_urem_by_const/fast_urem_by_const_test.cpp
@@ -0,0 +1,99 @@
+/*
+ * 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
new file mode 100644
index 000000000..a16407d5e
--- /dev/null
+++ b/lib/mesa/src/util/tests/fast_urem_by_const/meson.build
@@ -0,0 +1,31 @@
+# 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/hash_table/clear.c b/lib/mesa/src/util/tests/hash_table/clear.c
index 3d6bf80c0..e61f60ece 100644
--- a/lib/mesa/src/util/tests/hash_table/clear.c
+++ b/lib/mesa/src/util/tests/hash_table/clear.c
@@ -21,8 +21,12 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#undef NDEBUG
+
#include "hash_table.h"
+#define SIZE 1000
+
static void *make_key(uint32_t i)
{
return (void *)(uintptr_t)(1 + i);
@@ -53,13 +57,12 @@ static void delete_function(struct hash_entry *entry)
int main()
{
struct hash_table *ht;
- const uint32_t size = 1000;
- bool flags[size];
+ bool flags[SIZE];
uint32_t i;
ht = _mesa_hash_table_create(NULL, key_hash, key_equal);
- for (i = 0; i < size; ++i) {
+ for (i = 0; i < SIZE; ++i) {
flags[i] = false;
_mesa_hash_table_insert(ht, make_key(i), &flags[i]);
}
@@ -69,19 +72,19 @@ int main()
/* Check that delete_function was called and that repopulating the table
* works. */
- for (i = 0; i < size; ++i) {
+ for (i = 0; i < SIZE; ++i) {
assert(flags[i]);
flags[i] = false;
_mesa_hash_table_insert(ht, make_key(i), &flags[i]);
}
/* Check that exactly the right set of entries is in the table. */
- for (i = 0; i < size; ++i) {
+ for (i = 0; i < SIZE; ++i) {
assert(_mesa_hash_table_search(ht, make_key(i)));
}
hash_table_foreach(ht, entry) {
- assert(key_id(entry->key) < size);
+ assert(key_id(entry->key) < SIZE);
}
_mesa_hash_table_destroy(ht, NULL);
diff --git a/lib/mesa/src/util/tests/hash_table/collision.c b/lib/mesa/src/util/tests/hash_table/collision.c
index ba8913281..c7f8569c2 100644
--- a/lib/mesa/src/util/tests/hash_table/collision.c
+++ b/lib/mesa/src/util/tests/hash_table/collision.c
@@ -24,6 +24,8 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/hash_table/delete_and_lookup.c b/lib/mesa/src/util/tests/hash_table/delete_and_lookup.c
index 4f70509d0..6248dfd5b 100644
--- a/lib/mesa/src/util/tests/hash_table/delete_and_lookup.c
+++ b/lib/mesa/src/util/tests/hash_table/delete_and_lookup.c
@@ -24,6 +24,8 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/hash_table/delete_management.c b/lib/mesa/src/util/tests/hash_table/delete_management.c
index 127d81b3c..92e995ecd 100644
--- a/lib/mesa/src/util/tests/hash_table/delete_management.c
+++ b/lib/mesa/src/util/tests/hash_table/delete_management.c
@@ -24,12 +24,16 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "hash_table.h"
+#define SIZE 10000
+
static uint32_t
key_value(const void *key)
{
@@ -47,8 +51,7 @@ main(int argc, char **argv)
{
struct hash_table *ht;
struct hash_entry *entry;
- unsigned size = 10000;
- uint32_t keys[size];
+ uint32_t keys[SIZE];
uint32_t i;
(void) argc;
@@ -56,7 +59,7 @@ main(int argc, char **argv)
ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);
- for (i = 0; i < size; i++) {
+ for (i = 0; i < SIZE; i++) {
keys[i] = i;
_mesa_hash_table_insert(ht, keys + i, NULL);
@@ -69,7 +72,7 @@ main(int argc, char **argv)
}
/* Make sure that all our entries were present at the end. */
- for (i = size - 100; i < size; i++) {
+ for (i = SIZE - 100; i < SIZE; i++) {
entry = _mesa_hash_table_search(ht, keys + i);
assert(entry);
assert(key_value(entry->key) == i);
@@ -79,8 +82,8 @@ main(int argc, char **argv)
for (entry = _mesa_hash_table_next_entry(ht, NULL);
entry != NULL;
entry = _mesa_hash_table_next_entry(ht, entry)) {
- assert(key_value(entry->key) >= size - 100 &&
- key_value(entry->key) < size);
+ assert(key_value(entry->key) >= SIZE - 100 &&
+ key_value(entry->key) < SIZE);
}
assert(ht->entries == 100);
diff --git a/lib/mesa/src/util/tests/hash_table/destroy_callback.c b/lib/mesa/src/util/tests/hash_table/destroy_callback.c
index 1c18ca3e3..3a050ff2a 100644
--- a/lib/mesa/src/util/tests/hash_table/destroy_callback.c
+++ b/lib/mesa/src/util/tests/hash_table/destroy_callback.c
@@ -24,6 +24,8 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/hash_table/insert_and_lookup.c b/lib/mesa/src/util/tests/hash_table/insert_and_lookup.c
index 98e719ff5..1fd735368 100644
--- a/lib/mesa/src/util/tests/hash_table/insert_and_lookup.c
+++ b/lib/mesa/src/util/tests/hash_table/insert_and_lookup.c
@@ -24,6 +24,8 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/hash_table/insert_many.c b/lib/mesa/src/util/tests/hash_table/insert_many.c
index b07e40842..c146b039c 100644
--- a/lib/mesa/src/util/tests/hash_table/insert_many.c
+++ b/lib/mesa/src/util/tests/hash_table/insert_many.c
@@ -24,12 +24,16 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "hash_table.h"
+#define SIZE 10000
+
static uint32_t
key_value(const void *key)
{
@@ -47,8 +51,7 @@ main(int argc, char **argv)
{
struct hash_table *ht;
struct hash_entry *entry;
- unsigned size = 10000;
- uint32_t keys[size];
+ uint32_t keys[SIZE];
uint32_t i;
(void) argc;
@@ -56,18 +59,18 @@ main(int argc, char **argv)
ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);
- for (i = 0; i < size; i++) {
+ for (i = 0; i < SIZE; i++) {
keys[i] = i;
_mesa_hash_table_insert(ht, keys + i, NULL);
}
- for (i = 0; i < size; i++) {
+ for (i = 0; i < SIZE; i++) {
entry = _mesa_hash_table_search(ht, keys + i);
assert(entry);
assert(key_value(entry->key) == i);
}
- assert(ht->entries == size);
+ assert(ht->entries == SIZE);
_mesa_hash_table_destroy(ht, NULL);
diff --git a/lib/mesa/src/util/tests/hash_table/meson.build b/lib/mesa/src/util/tests/hash_table/meson.build
index d4de448ae..237d5a04a 100644
--- a/lib/mesa/src/util/tests/hash_table/meson.build
+++ b/lib/mesa/src/util/tests/hash_table/meson.build
@@ -27,9 +27,9 @@ foreach t : ['clear', 'collision', 'delete_and_lookup', 'delete_management',
executable(
'@0@_test'.format(t),
files('@0@.c'.format(t)),
- dependencies : [dep_thread, dep_dl],
+ c_args : [c_msvc_compat_args],
+ dependencies : idep_mesautil,
include_directories : [inc_include, inc_util],
- link_with : libmesa_util,
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/hash_table/random_entry.c b/lib/mesa/src/util/tests/hash_table/random_entry.c
index d1bc44aeb..4902a999d 100644
--- a/lib/mesa/src/util/tests/hash_table/random_entry.c
+++ b/lib/mesa/src/util/tests/hash_table/random_entry.c
@@ -24,12 +24,16 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "hash_table.h"
+#define SIZE 10000
+
static uint32_t
key_value(const void *key)
{
@@ -53,8 +57,7 @@ main(int argc, char **argv)
{
struct hash_table *ht;
struct hash_entry *entry;
- unsigned size = 10000;
- uint32_t keys[size];
+ uint32_t keys[SIZE];
uint32_t i, random_value;
(void) argc;
@@ -62,7 +65,7 @@ main(int argc, char **argv)
ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);
- for (i = 0; i < size; i++) {
+ for (i = 0; i < SIZE; i++) {
keys[i] = i;
_mesa_hash_table_insert(ht, keys + i, NULL);
diff --git a/lib/mesa/src/util/tests/hash_table/remove_key.c b/lib/mesa/src/util/tests/hash_table/remove_key.c
index 906de6799..6df6d7d03 100644
--- a/lib/mesa/src/util/tests/hash_table/remove_key.c
+++ b/lib/mesa/src/util/tests/hash_table/remove_key.c
@@ -21,6 +21,8 @@
* IN THE SOFTWARE.
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/hash_table/remove_null.c b/lib/mesa/src/util/tests/hash_table/remove_null.c
index 7042f5e93..f0f527453 100644
--- a/lib/mesa/src/util/tests/hash_table/remove_null.c
+++ b/lib/mesa/src/util/tests/hash_table/remove_null.c
@@ -24,6 +24,8 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/hash_table/replacement.c b/lib/mesa/src/util/tests/hash_table/replacement.c
index 58c22aeb8..e74e63453 100644
--- a/lib/mesa/src/util/tests/hash_table/replacement.c
+++ b/lib/mesa/src/util/tests/hash_table/replacement.c
@@ -24,6 +24,8 @@
* Eric Anholt <eric@anholt.net>
*/
+#undef NDEBUG
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/mesa/src/util/tests/set/meson.build b/lib/mesa/src/util/tests/set/meson.build
index 5ab180c11..9d0d311ba 100644
--- a/lib/mesa/src/util/tests/set/meson.build
+++ b/lib/mesa/src/util/tests/set/meson.build
@@ -23,9 +23,8 @@ test(
executable(
'set_test',
'set_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest],
+ dependencies : [dep_thread, dep_dl, idep_gtest, idep_mesautil],
include_directories : inc_common,
- link_with : [libmesa_util],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/set/set_test.cpp b/lib/mesa/src/util/tests/set/set_test.cpp
index a1eef0b3d..0b4355af1 100644
--- a/lib/mesa/src/util/tests/set/set_test.cpp
+++ b/lib/mesa/src/util/tests/set/set_test.cpp
@@ -113,3 +113,36 @@ TEST(set, remove_key)
_mesa_set_destroy(s, NULL);
}
+
+static uint32_t hash_int(const void *p)
+{
+ int i = *(const int *)p;
+ return i;
+}
+
+static bool cmp_int(const void *p1, const void *p2)
+{
+ int i1 = *(const int *)p1, i2 = *(const int *)p2;
+ return i1 == i2;
+}
+
+TEST(set, search_or_add)
+{
+ struct set *s = _mesa_set_create(NULL, hash_int, cmp_int);
+
+ int a = 10, b = 20, c = 20, d = 30;
+
+ _mesa_set_add(s, &a);
+ _mesa_set_add(s, &b);
+ EXPECT_EQ(s->entries, 2);
+
+ struct set_entry *entry = _mesa_set_search_or_add(s, &c);
+ EXPECT_EQ(entry->key, (void *)&b);
+ EXPECT_EQ(s->entries, 2);
+
+ struct set_entry *entry3 = _mesa_set_search_or_add(s, &d);
+ EXPECT_EQ(entry3->key, &d);
+ EXPECT_EQ(s->entries, 3);
+
+ _mesa_set_destroy(s, NULL);
+}
diff --git a/lib/mesa/src/util/tests/string_buffer/meson.build b/lib/mesa/src/util/tests/string_buffer/meson.build
index f4e1a8e24..cb767bb31 100644
--- a/lib/mesa/src/util/tests/string_buffer/meson.build
+++ b/lib/mesa/src/util/tests/string_buffer/meson.build
@@ -23,9 +23,8 @@ test(
executable(
'string_buffer_test',
'string_buffer_test.cpp',
- dependencies : [dep_thread, dep_dl, idep_gtest],
+ dependencies : [idep_gtest, idep_mesautil],
include_directories : inc_common,
- link_with : [libmesa_util],
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/timespec/meson.build b/lib/mesa/src/util/tests/timespec/meson.build
new file mode 100644
index 000000000..c685db5fd
--- /dev/null
+++ b/lib/mesa/src/util/tests/timespec/meson.build
@@ -0,0 +1,30 @@
+# 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
new file mode 100644
index 000000000..5005506f9
--- /dev/null
+++ b/lib/mesa/src/util/tests/timespec/timespec_test.cpp
@@ -0,0 +1,292 @@
+/*
+ * 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/vma/meson.build b/lib/mesa/src/util/tests/vma/meson.build
index 22137eb67..1239c7b04 100644
--- a/lib/mesa/src/util/tests/vma/meson.build
+++ b/lib/mesa/src/util/tests/vma/meson.build
@@ -24,7 +24,7 @@ test(
'vma_random_test',
'vma_random_test.cpp',
include_directories : [inc_include, inc_util],
- link_with : [libmesa_util],
+ dependencies : idep_mesautil,
),
suite : ['util'],
)
diff --git a/lib/mesa/src/util/tests/vma/vma_random_test.cpp b/lib/mesa/src/util/tests/vma/vma_random_test.cpp
index 1f194fcdf..9246176cb 100644
--- a/lib/mesa/src/util/tests/vma/vma_random_test.cpp
+++ b/lib/mesa/src/util/tests/vma/vma_random_test.cpp
@@ -34,7 +34,15 @@
#include <set>
#include <vector>
+#ifndef _WIN32
#include <err.h>
+#else
+#define errx(code, msg, ...) \
+ do { \
+ fprintf(stderr, msg, __VA_ARGS__); \
+ exit(code); \
+ } while (0);
+#endif
#include "vma.h"