progs/gallium: add unit test for u_half
authorLuca Barbieri <luca@luca-barbieri.com>
Fri, 2 Apr 2010 02:35:20 +0000 (04:35 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Fri, 2 Apr 2010 04:16:30 +0000 (06:16 +0200)
progs/gallium/unit/Makefile [new file with mode: 0644]
progs/gallium/unit/SConscript
progs/gallium/unit/u_half_test.c [new file with mode: 0644]

diff --git a/progs/gallium/unit/Makefile b/progs/gallium/unit/Makefile
new file mode 100644 (file)
index 0000000..f3dbd76
--- /dev/null
@@ -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 $@
index a8c39c152b341905f1d883325ec3af8d8dcb814b..0db3bb687c6988bd2eb41e144cab79aceaaba59a 100644 (file)
@@ -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 (file)
index 0000000..0486f73
--- /dev/null
@@ -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;
+}