summaryrefslogtreecommitdiffstats
path: root/progs
diff options
context:
space:
mode:
authorLuca Barbieri <[email protected]>2010-04-02 04:35:20 +0200
committerLuca Barbieri <[email protected]>2010-04-02 06:16:30 +0200
commit6259264c57537896d72158f811674a192c6a1596 (patch)
treef1f6c51591f4d1f2f2042301231c7e17d3280286 /progs
parentc476305cdeb1ca9d755983e2058cb44f5b9109f0 (diff)
progs/gallium: add unit test for u_half
Diffstat (limited to 'progs')
-rw-r--r--progs/gallium/unit/Makefile44
-rw-r--r--progs/gallium/unit/SConscript3
-rw-r--r--progs/gallium/unit/u_half_test.c31
3 files changed, 77 insertions, 1 deletions
diff --git a/progs/gallium/unit/Makefile b/progs/gallium/unit/Makefile
new file mode 100644
index 00000000000..f3dbd7695c6
--- /dev/null
+++ b/progs/gallium/unit/Makefile
@@ -0,0 +1,44 @@
+# 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 = \
+ u_format_test.c \
+ u_half_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/progs/gallium/unit/SConscript b/progs/gallium/unit/SConscript
index a8c39c152b3..0db3bb687c6 100644
--- a/progs/gallium/unit/SConscript
+++ b/progs/gallium/unit/SConscript
@@ -5,7 +5,8 @@ env = env.Clone()
env.Prepend(LIBS = [gallium])
progs = [
- 'u_format_test'
+ 'u_format_test',
+ 'u_half_test'
]
for prog in progs:
diff --git a/progs/gallium/unit/u_half_test.c b/progs/gallium/unit/u_half_test.c
new file mode 100644
index 00000000000..0486f731acd
--- /dev/null
+++ b/progs/gallium/unit/u_half_test.c
@@ -0,0 +1,31 @@
+#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)
+ {
+ half h = (half) i;
+ union fi f;
+ f.ui = util_half_to_floatui(h);
+ half 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;
+}