Mesa (master): progs/gallium: add unit test for u_half

Luca Barbieri lb at kemper.freedesktop.org
Fri Apr 2 04:17:07 UTC 2010


Module: Mesa
Branch: master
Commit: 6259264c57537896d72158f811674a192c6a1596
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6259264c57537896d72158f811674a192c6a1596

Author: Luca Barbieri <luca at luca-barbieri.com>
Date:   Fri Apr  2 04:35:20 2010 +0200

progs/gallium: add unit test for u_half

---

 progs/gallium/unit/Makefile      |   44 ++++++++++++++++++++++++++++++++++++++
 progs/gallium/unit/SConscript    |    3 +-
 progs/gallium/unit/u_half_test.c |   31 ++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletions(-)

diff --git a/progs/gallium/unit/Makefile b/progs/gallium/unit/Makefile
new file mode 100644
index 0000000..f3dbd76
--- /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 a8c39c1..0db3bb6 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 0000000..0486f73
--- /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;
+}




More information about the mesa-commit mailing list