From 6259264c57537896d72158f811674a192c6a1596 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Fri, 2 Apr 2010 04:35:20 +0200 Subject: [PATCH] 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 deletion(-) create mode 100644 progs/gallium/unit/Makefile create mode 100644 progs/gallium/unit/u_half_test.c 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 +#include +#include + +#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; +} -- 2.30.2