diff options
author | Thomas Balling Sørensen <[email protected]> | 2010-07-14 00:34:56 +0200 |
---|---|---|
committer | Thomas Balling Sørensen <tball@tball-laptop.(none)> | 2010-07-14 00:36:17 +0200 |
commit | 3299997bcc5a672617095adb560b3834dced39a6 (patch) | |
tree | 70f63a9f2049636fa3b249ce522c779173e66a13 /src/gallium/tests/unit | |
parent | 15bc635499589dc3490e5bdc198dfd376ce6fb1f (diff) |
vdpau changes
Diffstat (limited to 'src/gallium/tests/unit')
-rw-r--r-- | src/gallium/tests/unit/Makefile | 47 | ||||
-rw-r--r-- | src/gallium/tests/unit/SConscript | 25 | ||||
-rw-r--r-- | src/gallium/tests/unit/pipe_barrier_test.c | 86 | ||||
-rw-r--r-- | src/gallium/tests/unit/u_cache_test.c | 121 | ||||
-rw-r--r-- | src/gallium/tests/unit/u_format_test.c | 708 | ||||
-rw-r--r-- | src/gallium/tests/unit/u_half_test.c | 32 |
6 files changed, 0 insertions, 1019 deletions
diff --git a/src/gallium/tests/unit/Makefile b/src/gallium/tests/unit/Makefile deleted file mode 100644 index f65958dadd5..00000000000 --- a/src/gallium/tests/unit/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# progs/gallium/simple/Makefile - -TOP = ../../../.. -include $(TOP)/configs/current - -INCLUDES = \ - -I. \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/winsys \ - $(PROG_INCLUDES) - -LINKS = \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/winsys/sw/null/libws_null.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) \ - $(PROG_LINKS) - -SOURCES = \ - pipe_barrier_test.c \ - u_cache_test.c \ - u_half_test.c \ - u_format_test.c - - -OBJECTS = $(SOURCES:.c=.o) - -PROGS = $(OBJECTS:.o=) - -##### TARGETS ##### - -default: $(PROGS) - -clean: - -rm -f $(PROGS) - -rm -f *.o - -rm -f result.bmp - -##### RULES ##### - -$(OBJECTS): %.o: %.c - $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ - -$(PROGS): %: %.o - $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@ diff --git a/src/gallium/tests/unit/SConscript b/src/gallium/tests/unit/SConscript deleted file mode 100644 index 8a9f3504c75..00000000000 --- a/src/gallium/tests/unit/SConscript +++ /dev/null @@ -1,25 +0,0 @@ -Import('*') - -env = env.Clone() - -env.Prepend(LIBS = [gallium]) - -progs = [ - 'pipe_barrier_test', - 'u_cache_test', - 'u_format_test', - 'u_half_test' -] - -for prog in progs: - prog = env.Program( - target = prog, - source = prog + '.c', - ) - - env.InstallProgram(prog) - - # http://www.scons.org/wiki/UnitTests - test_alias = env.Alias('unit', [prog], prog[0].abspath) - AlwaysBuild(test_alias) - diff --git a/src/gallium/tests/unit/pipe_barrier_test.c b/src/gallium/tests/unit/pipe_barrier_test.c deleted file mode 100644 index f5d72b0abae..00000000000 --- a/src/gallium/tests/unit/pipe_barrier_test.c +++ /dev/null @@ -1,86 +0,0 @@ -/************************************************************************** - * - * Copyright 2009-2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -/* - * Test case for pipe_barrier. - * - * The test succeeds if no thread exits before all the other threads reach - * the barrier. - */ - - -#include <stdio.h> - -#include "os/os_thread.h" -#include "os/os_time.h" - - -#define NUM_THREADS 10 - -static pipe_thread threads[NUM_THREADS]; -static pipe_barrier barrier; -static int thread_ids[NUM_THREADS]; - - -static PIPE_THREAD_ROUTINE(thread_function, thread_data) -{ - int thread_id = *((int *) thread_data); - - printf("thread %d starting\n", thread_id); - os_time_sleep(thread_id * 1000 * 1000); - printf("thread %d before barrier\n", thread_id); - pipe_barrier_wait(&barrier); - printf("thread %d exiting\n", thread_id); - - return NULL; -} - - -int main() -{ - int i; - - printf("pipe_barrier_test starting\n"); - - pipe_barrier_init(&barrier, NUM_THREADS); - - for (i = 0; i < NUM_THREADS; i++) { - thread_ids[i] = i; - threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]); - } - - for (i = 0; i < NUM_THREADS; i++ ) { - pipe_thread_wait(threads[i]); - } - - pipe_barrier_destroy(&barrier); - - printf("pipe_barrier_test exiting\n"); - - return 0; -} diff --git a/src/gallium/tests/unit/u_cache_test.c b/src/gallium/tests/unit/u_cache_test.c deleted file mode 100644 index 0b62a765230..00000000000 --- a/src/gallium/tests/unit/u_cache_test.c +++ /dev/null @@ -1,121 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -/* - * Test case for u_cache. - */ - - -#include <assert.h> -#include <stdio.h> - -#include "util/u_cache.h" -#include "util/u_hash.h" - - -typedef uint32_t cache_test_key; -typedef uint32_t cache_test_value; - - -static uint32_t -cache_test_hash(const void *key) -{ - return util_hash_crc32(key, sizeof(cache_test_key)); -} - - -static void -cache_test_destroy(void *key, void *value) -{ - free(key); - free(value); -} - - -static int -cache_test_compare(const void *key1, const void *key2) { - return !(key1 == key2); -} - - -int main() { - unsigned cache_size; - unsigned cache_count; - - for (cache_size = 2; cache_size < (1 << 15); cache_size *= 2) { - for (cache_count = (cache_size << 5); cache_count < (cache_size << 10); cache_count *= 2) { - struct util_cache * cache; - cache_test_key *key; - cache_test_value *value_in; - cache_test_value *value_out; - int i; - - printf("Testing cache size of %d with %d values.\n", cache_size, cache_count); - - cache = util_cache_create(cache_test_hash, - cache_test_compare, - cache_test_destroy, - cache_size); - - /* - * Retrieve a value from an empty cache. - */ - key = malloc(sizeof(cache_test_key)); - *key = 0xdeadbeef; - value_out = (cache_test_value *) util_cache_get(cache, key); - assert(value_out == NULL); - free(key); - - - /* - * Repeatedly insert into and retrieve values from the cache. - */ - for (i = 0; i < cache_count; i++) { - key = malloc(sizeof(cache_test_key)); - value_in = malloc(sizeof(cache_test_value)); - - *key = rand(); - *value_in = rand(); - util_cache_set(cache, key, value_in); - - value_out = util_cache_get(cache, key); - assert(value_out != NULL); - assert(value_in == value_out); - assert(*value_in == *value_out); - } - - /* - * In debug builds, this will trigger a self-check by the cache of - * the distribution of hits in its internal cache entries. - */ - util_cache_destroy(cache); - } - } - - return 0; -} diff --git a/src/gallium/tests/unit/u_format_test.c b/src/gallium/tests/unit/u_format_test.c deleted file mode 100644 index cfde6af75e0..00000000000 --- a/src/gallium/tests/unit/u_format_test.c +++ /dev/null @@ -1,708 +0,0 @@ -/************************************************************************** - * - * Copyright 2009-2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include <stdlib.h> -#include <stdio.h> -#include <float.h> - -#include "util/u_half.h" -#include "util/u_format.h" -#include "util/u_format_tests.h" -#include "util/u_format_s3tc.h" - - -static boolean -compare_float(float x, float y) -{ - float error = y - x; - - if (error < 0.0f) - error = -error; - - if (error > FLT_EPSILON) { - return FALSE; - } - - return TRUE; -} - - -static void -print_packed(const struct util_format_description *format_desc, - const char *prefix, - const uint8_t *packed, - const char *suffix) -{ - unsigned i; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.bits/8; ++i) { - printf("%s%02x", sep, packed[i]); - sep = " "; - } - printf("%s", suffix); -} - - -static void -print_unpacked_rgba_doubl(const struct util_format_description *format_desc, - const char *prefix, - const double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], - const char *suffix) -{ - unsigned i, j; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); - sep = ", "; - } - sep = ",\n"; - } - printf("%s", suffix); -} - - -static void -print_unpacked_rgba_float(const struct util_format_description *format_desc, - const char *prefix, - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], - const char *suffix) -{ - unsigned i, j; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); - sep = ", "; - } - sep = ",\n"; - } - printf("%s", suffix); -} - - -static void -print_unpacked_rgba_8unorm(const struct util_format_description *format_desc, - const char *prefix, - uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], - const char *suffix) -{ - unsigned i, j; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); - sep = ", "; - } - } - printf("%s", suffix); -} - - -static void -print_unpacked_z_float(const struct util_format_description *format_desc, - const char *prefix, - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH], - const char *suffix) -{ - unsigned i, j; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - printf("%s%f", sep, unpacked[i][j]); - sep = ", "; - } - sep = ",\n"; - } - printf("%s", suffix); -} - - -static void -print_unpacked_z_32unorm(const struct util_format_description *format_desc, - const char *prefix, - uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH], - const char *suffix) -{ - unsigned i, j; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - printf("%s0x%08x", sep, unpacked[i][j]); - sep = ", "; - } - } - printf("%s", suffix); -} - - -static void -print_unpacked_s_8uscaled(const struct util_format_description *format_desc, - const char *prefix, - uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH], - const char *suffix) -{ - unsigned i, j; - const char *sep = ""; - - printf("%s", prefix); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - printf("%s0x%02x", sep, unpacked[i][j]); - sep = ", "; - } - } - printf("%s", suffix); -} - - -static boolean -test_format_fetch_rgba_float(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; - unsigned i, j, k; - boolean success; - - success = TRUE; - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - format_desc->fetch_rgba_float(unpacked[i][j], test->packed, j, i); - for (k = 0; k < 4; ++k) { - if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) { - success = FALSE; - } - } - } - } - - if (!success) { - print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n"); - print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n"); - } - - return success; -} - - -static boolean -test_format_unpack_rgba_float(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; - unsigned i, j, k; - boolean success; - - format_desc->unpack_rgba_float(&unpacked[0][0][0], sizeof unpacked[0], - test->packed, 0, - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - for (k = 0; k < 4; ++k) { - if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) { - success = FALSE; - } - } - } - } - - if (!success) { - print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n"); - print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n"); - } - - return success; -} - - -static boolean -test_format_pack_rgba_float(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; - uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; - unsigned i, j, k; - boolean success; - - if (test->format == PIPE_FORMAT_DXT1_RGBA) { - /* - * Skip S3TC as packed representation is not canonical. - * - * TODO: Do a round trip conversion. - */ - return TRUE; - } - - memset(packed, 0, sizeof packed); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - for (k = 0; k < 4; ++k) { - unpacked[i][j][k] = (float) test->unpacked[i][j][k]; - } - } - } - - format_desc->pack_rgba_float(packed, 0, - &unpacked[0][0][0], sizeof unpacked[0], - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.bits/8; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - print_packed(format_desc, "FAILED: ", packed, " obtained\n"); - print_packed(format_desc, " ", test->packed, " expected\n"); - } - - return success; -} - - -static boolean -convert_float_to_8unorm(uint8_t *dst, const double *src) -{ - unsigned i; - boolean accurate = TRUE; - - for (i = 0; i < UTIL_FORMAT_MAX_UNPACKED_HEIGHT*UTIL_FORMAT_MAX_UNPACKED_WIDTH*4; ++i) { - if (src[i] < 0.0) { - accurate = FALSE; - dst[i] = 0; - } - else if (src[i] > 1.0) { - accurate = FALSE; - dst[i] = 255; - } - else { - dst[i] = src[i] * 255.0; - } - } - - return accurate; -} - - -static boolean -test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; - uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; - unsigned i, j, k; - boolean success; - - format_desc->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0], - test->packed, 0, - format_desc->block.width, format_desc->block.height); - - convert_float_to_8unorm(&expected[0][0][0], &test->unpacked[0][0][0]); - - success = TRUE; - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - for (k = 0; k < 4; ++k) { - if (expected[i][j][k] != unpacked[i][j][k]) { - success = FALSE; - } - } - } - } - - if (!success) { - print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n"); - print_unpacked_rgba_8unorm(format_desc, " ", expected, " expected\n"); - } - - return success; -} - - -static boolean -test_format_pack_rgba_8unorm(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; - uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; - unsigned i; - boolean success; - - if (test->format == PIPE_FORMAT_DXT1_RGBA) { - /* - * Skip S3TC as packed representation is not canonical. - * - * TODO: Do a round trip conversion. - */ - return TRUE; - } - - if (!convert_float_to_8unorm(&unpacked[0][0][0], &test->unpacked[0][0][0])) { - /* - * Skip test cases which cannot be represented by four unorm bytes. - */ - return TRUE; - } - - memset(packed, 0, sizeof packed); - - format_desc->pack_rgba_8unorm(packed, 0, - &unpacked[0][0][0], sizeof unpacked[0], - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.bits/8; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - print_packed(format_desc, "FAILED: ", packed, " obtained\n"); - print_packed(format_desc, " ", test->packed, " expected\n"); - } - - return success; -} - - -static boolean -test_format_unpack_z_float(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; - unsigned i, j; - boolean success; - - format_desc->unpack_z_float(&unpacked[0][0], sizeof unpacked[0], - test->packed, 0, - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - if (!compare_float(test->unpacked[i][j][0], unpacked[i][j])) { - success = FALSE; - } - } - } - - if (!success) { - print_unpacked_z_float(format_desc, "FAILED: ", unpacked, " obtained\n"); - print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n"); - } - - return success; -} - - -static boolean -test_format_pack_z_float(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH]; - uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; - unsigned i, j; - boolean success; - - memset(packed, 0, sizeof packed); - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - unpacked[i][j] = (float) test->unpacked[i][j][0]; - if (test->unpacked[i][j][1]) { - return TRUE; - } - } - } - - format_desc->pack_z_float(packed, 0, - &unpacked[0][0], sizeof unpacked[0], - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.bits/8; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - print_packed(format_desc, "FAILED: ", packed, " obtained\n"); - print_packed(format_desc, " ", test->packed, " expected\n"); - } - - return success; -} - - -static boolean -test_format_unpack_z_32unorm(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; - uint32_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; - unsigned i, j; - boolean success; - - format_desc->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0], - test->packed, 0, - format_desc->block.width, format_desc->block.height); - - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - expected[i][j] = test->unpacked[i][j][0] * 0xffffffff; - } - } - - success = TRUE; - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - if (expected[i][j] != unpacked[i][j]) { - success = FALSE; - } - } - } - - if (!success) { - print_unpacked_z_32unorm(format_desc, "FAILED: ", unpacked, " obtained\n"); - print_unpacked_z_32unorm(format_desc, " ", expected, " expected\n"); - } - - return success; -} - - -static boolean -test_format_pack_z_32unorm(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH]; - uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; - unsigned i, j; - boolean success; - - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - unpacked[i][j] = test->unpacked[i][j][0] * 0xffffffff; - if (test->unpacked[i][j][1]) { - return TRUE; - } - } - } - - memset(packed, 0, sizeof packed); - - format_desc->pack_z_32unorm(packed, 0, - &unpacked[0][0], sizeof unpacked[0], - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.bits/8; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - print_packed(format_desc, "FAILED: ", packed, " obtained\n"); - print_packed(format_desc, " ", test->packed, " expected\n"); - } - - return success; -} - - -static boolean -test_format_unpack_s_8uscaled(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; - uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; - unsigned i, j; - boolean success; - - format_desc->unpack_s_8uscaled(&unpacked[0][0], sizeof unpacked[0], - test->packed, 0, - format_desc->block.width, format_desc->block.height); - - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - expected[i][j] = test->unpacked[i][j][1]; - } - } - - success = TRUE; - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - if (expected[i][j] != unpacked[i][j]) { - success = FALSE; - } - } - } - - if (!success) { - print_unpacked_s_8uscaled(format_desc, "FAILED: ", unpacked, " obtained\n"); - print_unpacked_s_8uscaled(format_desc, " ", expected, " expected\n"); - } - - return success; -} - - -static boolean -test_format_pack_s_8uscaled(const struct util_format_description *format_desc, - const struct util_format_test_case *test) -{ - uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH]; - uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; - unsigned i, j; - boolean success; - - for (i = 0; i < format_desc->block.height; ++i) { - for (j = 0; j < format_desc->block.width; ++j) { - unpacked[i][j] = test->unpacked[i][j][1]; - if (test->unpacked[i][j][0]) { - return TRUE; - } - } - } - - memset(packed, 0, sizeof packed); - - format_desc->pack_s_8uscaled(packed, 0, - &unpacked[0][0], sizeof unpacked[0], - format_desc->block.width, format_desc->block.height); - - success = TRUE; - for (i = 0; i < format_desc->block.bits/8; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - print_packed(format_desc, "FAILED: ", packed, " obtained\n"); - print_packed(format_desc, " ", test->packed, " expected\n"); - } - - return success; -} - - -typedef boolean -(*test_func_t)(const struct util_format_description *format_desc, - const struct util_format_test_case *test); - - -static boolean -test_one_func(const struct util_format_description *format_desc, - test_func_t func, - const char *suffix) -{ - unsigned i; - bool success = TRUE; - - printf("Testing util_format_%s_%s ...\n", - format_desc->short_name, suffix); - - for (i = 0; i < util_format_nr_test_cases; ++i) { - const struct util_format_test_case *test = &util_format_test_cases[i]; - - if (test->format == format_desc->format) { - if (!func(format_desc, &util_format_test_cases[i])) { - success = FALSE; - } - } - } - - return success; -} - - -static boolean -test_all(void) -{ - enum pipe_format format; - bool success = TRUE; - - for (format = 1; format < PIPE_FORMAT_COUNT; ++format) { - const struct util_format_description *format_desc; - - format_desc = util_format_description(format); - if (!format_desc) { - continue; - } - - if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC && - !util_format_s3tc_enabled) { - continue; - } - -# define TEST_ONE_FUNC(name) \ - if (format_desc->name) { \ - if (!test_one_func(format_desc, &test_format_##name, #name)) { \ - success = FALSE; \ - } \ - } - - TEST_ONE_FUNC(fetch_rgba_float); - TEST_ONE_FUNC(pack_rgba_float); - TEST_ONE_FUNC(unpack_rgba_float); - TEST_ONE_FUNC(pack_rgba_8unorm); - TEST_ONE_FUNC(unpack_rgba_8unorm); - - TEST_ONE_FUNC(unpack_z_32unorm); - TEST_ONE_FUNC(pack_z_32unorm); - TEST_ONE_FUNC(unpack_z_float); - TEST_ONE_FUNC(pack_z_float); - TEST_ONE_FUNC(unpack_s_8uscaled); - TEST_ONE_FUNC(pack_s_8uscaled); - -# undef TEST_ONE_FUNC - } - - return success; -} - - -int main(int argc, char **argv) -{ - boolean success; - - util_format_s3tc_init(); - - success = test_all(); - - return success ? 0 : 1; -} diff --git a/src/gallium/tests/unit/u_half_test.c b/src/gallium/tests/unit/u_half_test.c deleted file mode 100644 index 00bda7f50a6..00000000000 --- a/src/gallium/tests/unit/u_half_test.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <float.h> - -#include "util/u_math.h" -#include "util/u_half.h" - -int -main(int argc, char **argv) -{ - unsigned i; - unsigned roundtrip_fails = 0; - for(i = 0; i < 1 << 16; ++i) - { - uint16_t h = (uint16_t) i; - union fi f; - uint16_t rh; - f.ui = util_half_to_floatui(h); - rh = util_floatui_to_half(f.ui); - if(h != rh) - { - printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh); - ++roundtrip_fails; - } - } - - if(roundtrip_fails) - printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails); - else - printf("Success!\n"); - return 0; -} |