diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2022-09-02 05:47:02 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2022-09-02 05:47:02 +0000 |
commit | 0dbbf1e0708df85a357d70e2708c0a11aeb5480e (patch) | |
tree | 6656ff8eb8b15a2fc1c02888973caf618388cfd0 /lib/mesa/src/util/tests | |
parent | 5f66494d31f735486b8222ecfa0a0c9046e92543 (diff) |
Merge Mesa 22.1.7
Diffstat (limited to 'lib/mesa/src/util/tests')
16 files changed, 0 insertions, 2070 deletions
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); -} |