From 0081384727e40502653b3f669607d7629ede39be Mon Sep 17 00:00:00 2001 From: Ari Lemmetti Date: Fri, 17 Apr 2015 18:08:58 +0300 Subject: [PATCH 1/2] Clean Makefile a bit. Add debug build option. --- src/Makefile | 98 ++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/src/Makefile b/src/Makefile index b79451b7..15e1994d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -66,6 +66,8 @@ WARNINGS = -Wall -Wtype-limits -Wvla INCLUDEDIRS = -I. -I./strategies -I./extras -I.. +STRATEGIES = generic sse2 sse41 avx2 x86_asm altivec + #Detect if cc is gcc for the link time optimization flag GCCVERSION = $(shell $(CC) --version | grep GCC) ifneq (, $(GCCVERSION)) @@ -75,8 +77,7 @@ endif CFLAGS += -std=gnu99 $(INCLUDEDIRS) $(WARNINGS) LDFLAGS += -lm -pthread LD = gcc -OBJS = interface_main.o \ - encmain.o \ +OBJS = \ bitstream.o \ cabac.o \ checkpoint.o \ @@ -117,19 +118,21 @@ OBJS = interface_main.o \ strategies/generic/dct-generic.o \ strategies/avx2/dct-avx2.o \ strategies/generic/ipol-generic.o \ - strategies/avx2/ipol-avx2.o \ - -TEST_OBJS = $(filter-out encmain.o interface_main.o, $(OBJS)) \ - ../tests/dct_tests.o \ - ../tests/intra_sad_tests.o \ - ../tests/sad_tests.o \ - ../tests/satd_tests.o \ - ../tests/speed_tests.o \ - ../tests/tests_main.o \ - ../tests/test_strategies.o \ + strategies/avx2/ipol-avx2.o +MAIN_OBJS := encmain.o interface_main.o +TESTDIR := ../tests +TEST_OBJS := \ + $(TESTDIR)/dct_tests.o \ + $(TESTDIR)/intra_sad_tests.o \ + $(TESTDIR)/sad_tests.o \ + $(TESTDIR)/satd_tests.o \ + $(TESTDIR)/speed_tests.o \ + $(TESTDIR)/tests_main.o \ + $(TESTDIR)/test_strategies.o + ASMFLAGS += $(INCLUDEDIRS) ASMOBJS = @@ -145,28 +148,25 @@ endif PROG = ./kvazaar -PROGS = $(PROG) - +DEBUG = ./kvazaar_debug TESTS = ./kvazaar_tests -DEPS = $(OBJS:.o=.d) +PROGS = $(PROG) $(DEBUG) $(TESTS) + +RELEASE_OBJS = $(MAIN_OBJS) $(OBJS) $(ASMOBJS) +DEBUG_OBJS = $(RELEASE_OBJS:.o=_debug.o) +TESTS_OBJS = $(TEST_OBJS) $(OBJS) $(ASMOBJS) + + +DEPS = $(RELEASE_OBJS:.o=.d) $(DEBUG_OBJS:.o=.d) $(TESTS_OBJS:.o=.d) GREATEST = ../greatest/greatest.h -all: $(PROGS) -.PHONY: all clean build_tests tests +all: $(PROG) +.PHONY: all clean build_tests tests debug -build_tests: $(GREATEST) $(TESTS) - -tests: build_tests - $(TESTS) - -$(GREATEST): - git submodule init - git submodule update # Compile files in strategy directories with appropriate flags. -EXTRA_FLAGS = ifeq ($(ARCH), ppc64) strategies/altivec/%.o: EXTRA_FLAGS += -maltivec -fno-lto else @@ -184,32 +184,40 @@ ifndef KVZ_DISABLE_ASM strategies/x86_asm/%.o: EXTRA_FLAGS += -DKVZ_COMPILE_ASM endif +debug: LDFLAGS := $(filter-out -O3 -O2 -flto, $(LDFLAGS)) +debug: CFLAGS := $(filter-out -O3 -O2 -flto, $(CFLAGS)) +debug: $(DEBUG) -$(PROG): $(OBJS) $(ASMOBJS) +tests: build_tests + $(TESTS) + +build_tests: CFLAGS := $(filter-out -Werror, $(CFLAGS)) +build_tests: init_submodules $(TESTS) + +REMOVE_FILES = $(RELEASE_OBJS) $(DEBUG_OBJS) $(TESTS_OBJS) $(DEPS) $(PROGS) + +$(PROG): $(RELEASE_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +$(DEBUG): $(DEBUG_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +$(TESTS): $(TESTS_OBJS) $(LD) $^ $(LDFLAGS) -o $@ -$(TESTS): $(TEST_OBJS) $(ASMOBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -%.o: %.asm Makefile +%.o %_debug.o: %.asm Makefile $(AS) $(ASMFLAGS) -o $@ $< + +%.o %_debug.o: %.c Makefile + $(CC) $(CFLAGS) $(EXTRA_FLAGS) -MMD -MP -c $< -o $@ -%.d: %.asm Makefile - $(AS) $(ASMFLAGS) -M -o $@ > $< - -%.o: %.c Makefile - $(CC) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@ - -%.d: %.c Makefile - $(CC) $(CFLAGS) -MF"$@" -MM -MP -MT"$@" -MT"$(<:.c=.o)" "$<" - -../tests/%.c: ../tests/%.h Makefile - touch $@ - +init_submodules: + git submodule init + git submodule update clean: - rm -f $(OBJS) $(PROGS) $(TESTS) $(ASMOBJS) $(TEST_OBJS) $(DEPS) + rm -f $(REMOVE_FILES) ifneq ($(MAKECMDGOALS),clean) - -include $(DEPS) +-include $(DEPS) endif From 26daf514cac2144c86b837b73b3e6abfdcd69572 Mon Sep 17 00:00:00 2001 From: Ari Lemmetti Date: Thu, 23 Apr 2015 07:40:48 +0300 Subject: [PATCH 2/2] Test for memory leaks with valgrind in Travis. --- .travis.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b56d60a4..87e4e74c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,20 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y yasm - sudo apt-get install -qq gcc-4.8 + - sudo apt-get install -qq valgrind + - sudo apt-get install -qq p7zip-full + - wget http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-32bit-static.tar.xz + - 7z x ffmpeg-release-32bit-static.tar.xz + - 7z x ffmpeg-release-32bit-static.tar + - chmod +x ./ffmpeg-2.6.2-32bit-static/ffmpeg script: - cd src - export KVZ_DISABLE_AVX2=1 - - make && make tests - - if [ "$CC" = "gcc" ]; then make clean && unset KVZ_DISABLE_AVX2 && export CC=gcc-4.8 && make && make tests; fi - \ No newline at end of file + - make && make debug && make tests + - ../ffmpeg-2.6.2-32bit-static/ffmpeg -f lavfi -i mandelbrot=s=320x240 -vframes 25 -r 5 -pix_fmt yuv420p test.yuv + - if [ "$CC" = "gcc" ]; then valgrind --leak-check=full --error-exitcode=1 ./kvazaar_debug -i test.yuv --input-res=320x240 -n 16 -o test1.bin; fi + - if [ "$CC" = "gcc" ]; then valgrind --leak-check=full --error-exitcode=1 ./kvazaar_debug -i test.yuv --input-res=320x240 -n 16 -o test2.bin --threads 4 --wpp --owf 3 --cpuid=0; fi + - if [ "$CC" = "gcc" ]; then valgrind --leak-check=full --error-exitcode=1 ./kvazaar_debug -i test.yuv --input-res=320x240 -n 16 -o test3.bin --threads 4 --wpp --owf 3; fi + - if [ "$CC" = "gcc" ]; then make clean && unset KVZ_DISABLE_AVX2 && export CC=gcc-4.8 && make && make debug && make tests; fi +