From: Luca Barbieri Date: Fri, 2 Apr 2010 02:35:20 +0000 (+0200) Subject: progs/gallium: add unit test for u_half X-Git-Tag: 062012170305~13638 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6259264c57537896d72158f811674a192c6a1596;p=profile%2Fivi%2Fmesa.git progs/gallium: add unit test for u_half --- 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 +#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; +}