From e82d261d10729b08ebe3e75fd6927d9993fc9182 Mon Sep 17 00:00:00 2001 From: John Koleszar Date: Wed, 16 May 2012 16:25:51 -0700 Subject: [PATCH] Build unit tests monolithically Rework unit tests to have a single executable rather than many, which should avoid pollution of the visual studio project namespace, improve build times, and make it easier to use the gtest test sharding system when we get these going on the continuous build cluster. Change-Id: If4c3e5d4b3515522869de6c89455c2a64697cca6 --- libs.mk | 28 ++-- test/test.mk | 2 + .../test_libvpx.cc | 21 +-- vp8/common/idctllm_test.cc | 120 ++++++++++++++++-- vp8/common/idctllm_test.h | 113 ----------------- vp8/encoder/boolcoder_test.cc | 6 - vp8/vp8_common.mk | 3 +- vp8/vp8cx.mk | 2 +- 8 files changed, 130 insertions(+), 165 deletions(-) create mode 100644 test/test.mk rename vp8/common/x86/idctllm_mmx_test.cc => test/test_libvpx.cc (50%) mode change 100755 => 100644 delete mode 100755 vp8/common/idctllm_test.h diff --git a/libs.mk b/libs.mk index f25664932..516e6d834 100644 --- a/libs.mk +++ b/libs.mk @@ -329,7 +329,6 @@ CLEAN-OBJS += $(BUILD_PFX)vpx_version.h # # Rule to generate runtime cpu detection files # -$(OBJS-yes:.o=.d): $(BUILD_PFX)vpx_rtcd.h $(BUILD_PFX)vpx_rtcd.h: $(SRC_PATH_BARE)/$(sort $(filter %rtcd_defs.sh,$(CODEC_SRCS))) @echo " [CREATE] $@" $(qexec)$(SRC_PATH_BARE)/build/make/rtcd.sh --arch=$(TGT_ISA) \ @@ -346,14 +345,15 @@ CODEC_DOC_SRCS += vpx/vpx_codec.h \ ## ## libvpx test directives ## - ifeq ($(CONFIG_UNIT_TESTS),yes) + +include $(SRC_PATH_BARE)/test/test.mk +LIBVPX_TEST_SRCS=$(addprefix test/,$(call enabled,LIBVPX_TEST_SRCS)) +LIBVPX_TEST_BINS=./test_libvpx + ifeq ($(CONFIG_EXTERNAL_BUILD),yes) ifeq ($(CONFIG_MSVS),yes) -LIBVPX_TEST_SRCS=$(filter %_test.cc,$(call enabled,CODEC_SRCS)) -LIBVPX_TEST_BINS=$(sort $(LIBVPX_TEST_SRCS:.cc.o=)) - gtest.vcproj: $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc @echo " [CREATE] $@" $(SRC_PATH_BARE)/build/make/gen_msvs_proj.sh \ @@ -403,17 +403,20 @@ OBJS-$(BUILD_LIBVPX) += $(GTEST_OBJS) LIBS-$(BUILD_LIBVPX) += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a $(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS) -LIBVPX_TEST_SRCS=$(filter %_test.cc,$(call enabled,CODEC_SRCS)) -LIBVPX_TEST_OBJS=$(call objs,$(LIBVPX_TEST_SRCS)) -$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src -$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src/include -LIBVPX_TEST_BINS=$(sort $(LIBVPX_TEST_OBJS:.cc.o=)) +LIBVPX_TEST_OBJS=$(sort $(call objs,$(LIBVPX_TEST_SRCS))) +$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src +$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src/include OBJS-$(BUILD_LIBVPX) += $(LIBVPX_TEST_OBJS) +# Install test sources only if codec source is included +INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\ + $(shell find $(SRC_PATH_BARE)/third_party/googletest -type f)) +INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBVPX_TEST_SRCS) + $(foreach bin,$(LIBVPX_TEST_BINS),\ $(if $(BUILD_LIBVPX),$(eval $(bin): libvpx.a libgtest.a ))\ $(if $(BUILD_LIBVPX),$(eval $(call linkerxx_template,$(bin),\ - $(bin).cc.o \ + $(LIBVPX_TEST_OBJS) \ -L. -lvpx -lgtest -lpthread -lm)\ )))\ $(if $(LIPO_LIBS),$(eval $(call lipo_bin_template,$(bin))))\ @@ -436,3 +439,6 @@ libs.doxy: $(CODEC_DOC_SRCS) @echo "PREDEFINED = VPX_CODEC_DISABLE_COMPAT" >> $@ @echo "INCLUDE_PATH += ." >> $@; @echo "ENABLED_SECTIONS += $(sort $(CODEC_DOC_SECTIONS))" >> $@ + +## Generate vpx_rtcd.h for all objects +$(OBJS-yes:.o=.d): $(BUILD_PFX)vpx_rtcd.h diff --git a/test/test.mk b/test/test.mk new file mode 100644 index 000000000..e486795e3 --- /dev/null +++ b/test/test.mk @@ -0,0 +1,2 @@ +LIBVPX_TEST_SRCS-yes += test.mk +LIBVPX_TEST_SRCS-yes += test_libvpx.cc diff --git a/vp8/common/x86/idctllm_mmx_test.cc b/test/test_libvpx.cc old mode 100755 new mode 100644 similarity index 50% rename from vp8/common/x86/idctllm_mmx_test.cc rename to test/test_libvpx.cc index 8c115335e..48bfc6c76 --- a/vp8/common/x86/idctllm_mmx_test.cc +++ b/test/test_libvpx.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. + * Copyright (c) 2012 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -7,24 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ - - - extern "C" { - void vp8_short_idct4x4llm_mmx(short *input, unsigned char *pred_ptr, - int pred_stride, unsigned char *dst_ptr, - int dst_stride); -} - -#include "vp8/common/idctllm_test.h" - -namespace -{ - -INSTANTIATE_TEST_CASE_P(MMX, IDCTTest, - ::testing::Values(vp8_short_idct4x4llm_mmx)); - -} // namespace - +#include "third_party/googletest/src/include/gtest/gtest.h" int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/vp8/common/idctllm_test.cc b/vp8/common/idctllm_test.cc index 0f6ebe7fe..dd42e2299 100755 --- a/vp8/common/idctllm_test.cc +++ b/vp8/common/idctllm_test.cc @@ -9,23 +9,117 @@ */ - extern "C" { - void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr, - int pred_stride, unsigned char *dst_ptr, - int dst_stride); +extern "C" { +#include "vpx_config.h" +#include "vpx_rtcd.h" +} +#include "third_party/googletest/src/include/gtest/gtest.h" + +typedef void (*idct_fn_t)(short *input, unsigned char *pred_ptr, + int pred_stride, unsigned char *dst_ptr, + int dst_stride); +namespace { +class IDCTTest : public ::testing::TestWithParam +{ + protected: + virtual void SetUp() + { + int i; + + UUT = GetParam(); + memset(input, 0, sizeof(input)); + /* Set up guard blocks */ + for(i=0; i<256; i++) + output[i] = ((i&0xF)<4&&(i<64))?0:-1; + } + + idct_fn_t UUT; + short input[16]; + unsigned char output[256]; + unsigned char predict[256]; +}; + +TEST_P(IDCTTest, TestGuardBlocks) +{ + int i; + + for(i=0; i<256; i++) + if((i&0xF) < 4 && i<64) + EXPECT_EQ(0, output[i]) << i; + else + EXPECT_EQ(255, output[i]); } -#include "vpx_config.h" -#include "idctllm_test.h" -namespace +TEST_P(IDCTTest, TestAllZeros) { + int i; + + UUT(input, output, 16, output, 16); + + for(i=0; i<256; i++) + if((i&0xF) < 4 && i<64) + EXPECT_EQ(0, output[i]) << "i==" << i; + else + EXPECT_EQ(255, output[i]) << "i==" << i; +} + +TEST_P(IDCTTest, TestAllOnes) +{ + int i; + + input[0] = 4; + UUT(input, output, 16, output, 16); + + for(i=0; i<256; i++) + if((i&0xF) < 4 && i<64) + EXPECT_EQ(1, output[i]) << "i==" << i; + else + EXPECT_EQ(255, output[i]) << "i==" << i; +} + +TEST_P(IDCTTest, TestAddOne) +{ + int i; + + for(i=0; i<256; i++) + predict[i] = i; + + input[0] = 4; + UUT(input, predict, 16, output, 16); + + for(i=0; i<256; i++) + if((i&0xF) < 4 && i<64) + EXPECT_EQ(i+1, output[i]) << "i==" << i; + else + EXPECT_EQ(255, output[i]) << "i==" << i; +} + +TEST_P(IDCTTest, TestWithData) +{ + int i; + + for(i=0; i<16; i++) + input[i] = i; + + UUT(input, output, 16, output, 16); + + for(i=0; i<256; i++) + if((i&0xF) > 3 || i>63) + EXPECT_EQ(255, output[i]) << "i==" << i; + else if(i == 0) + EXPECT_EQ(11, output[i]) << "i==" << i; + else if(i == 34) + EXPECT_EQ(1, output[i]) << "i==" << i; + else if(i == 2 || i == 17 || i == 32) + EXPECT_EQ(3, output[i]) << "i==" << i; + else + EXPECT_EQ(0, output[i]) << "i==" << i; +} INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c)); - -} // namespace - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +#if HAVE_MMX +INSTANTIATE_TEST_CASE_P(MMX, IDCTTest, + ::testing::Values(vp8_short_idct4x4llm_mmx)); +#endif } diff --git a/vp8/common/idctllm_test.h b/vp8/common/idctllm_test.h deleted file mode 100755 index a6a694b18..000000000 --- a/vp8/common/idctllm_test.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - - - #include "third_party/googletest/src/include/gtest/gtest.h" -typedef void (*idct_fn_t)(short *input, unsigned char *pred_ptr, - int pred_stride, unsigned char *dst_ptr, - int dst_stride); -namespace { -class IDCTTest : public ::testing::TestWithParam -{ - protected: - virtual void SetUp() - { - int i; - - UUT = GetParam(); - memset(input, 0, sizeof(input)); - /* Set up guard blocks */ - for(i=0; i<256; i++) - output[i] = ((i&0xF)<4&&(i<64))?0:-1; - } - - idct_fn_t UUT; - short input[16]; - unsigned char output[256]; - unsigned char predict[256]; -}; - -TEST_P(IDCTTest, TestGuardBlocks) -{ - int i; - - for(i=0; i<256; i++) - if((i&0xF) < 4 && i<64) - EXPECT_EQ(0, output[i]) << i; - else - EXPECT_EQ(255, output[i]); -} - -TEST_P(IDCTTest, TestAllZeros) -{ - int i; - - UUT(input, output, 16, output, 16); - - for(i=0; i<256; i++) - if((i&0xF) < 4 && i<64) - EXPECT_EQ(0, output[i]) << "i==" << i; - else - EXPECT_EQ(255, output[i]) << "i==" << i; -} - -TEST_P(IDCTTest, TestAllOnes) -{ - int i; - - input[0] = 4; - UUT(input, output, 16, output, 16); - - for(i=0; i<256; i++) - if((i&0xF) < 4 && i<64) - EXPECT_EQ(1, output[i]) << "i==" << i; - else - EXPECT_EQ(255, output[i]) << "i==" << i; -} - -TEST_P(IDCTTest, TestAddOne) -{ - int i; - - for(i=0; i<256; i++) - predict[i] = i; - - input[0] = 4; - UUT(input, predict, 16, output, 16); - - for(i=0; i<256; i++) - if((i&0xF) < 4 && i<64) - EXPECT_EQ(i+1, output[i]) << "i==" << i; - else - EXPECT_EQ(255, output[i]) << "i==" << i; -} - -TEST_P(IDCTTest, TestWithData) -{ - int i; - - for(i=0; i<16; i++) - input[i] = i; - - UUT(input, output, 16, output, 16); - - for(i=0; i<256; i++) - if((i&0xF) > 3 || i>63) - EXPECT_EQ(255, output[i]) << "i==" << i; - else if(i == 0) - EXPECT_EQ(11, output[i]) << "i==" << i; - else if(i == 34) - EXPECT_EQ(1, output[i]) << "i==" << i; - else if(i == 2 || i == 17 || i == 32) - EXPECT_EQ(3, output[i]) << "i==" << i; - else - EXPECT_EQ(0, output[i]) << "i==" << i; -} -} diff --git a/vp8/encoder/boolcoder_test.cc b/vp8/encoder/boolcoder_test.cc index 9d9462690..00c2b7593 100644 --- a/vp8/encoder/boolcoder_test.cc +++ b/vp8/encoder/boolcoder_test.cc @@ -121,9 +121,3 @@ TEST(VP8, TestBitIO) } } } - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/vp8/vp8_common.mk b/vp8/vp8_common.mk index 3a7b146fc..0afd85f7d 100644 --- a/vp8/vp8_common.mk +++ b/vp8/vp8_common.mk @@ -30,7 +30,7 @@ VP8_COMMON_SRCS-yes += common/findnearmv.c VP8_COMMON_SRCS-yes += common/generic/systemdependent.c VP8_COMMON_SRCS-yes += common/idct_blk.c VP8_COMMON_SRCS-yes += common/idctllm.c -VP8_COMMON_SRCS-yes += common/idctllm_test.cc +LIBVPX_TEST_SRCS-yes += ../vp8/common/idctllm_test.cc VP8_COMMON_SRCS-yes += common/alloccommon.h VP8_COMMON_SRCS-yes += common/blockd.h VP8_COMMON_SRCS-yes += common/common.h @@ -85,7 +85,6 @@ VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/postproc.c VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/dequantize_mmx.asm VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idct_blk_mmx.c VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idctllm_mmx.asm -VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idctllm_mmx_test.cc VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/iwalsh_mmx.asm VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/loopfilter_mmx.asm VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/recon_mmx.asm diff --git a/vp8/vp8cx.mk b/vp8/vp8cx.mk index 78674ca5f..9f50fadfc 100644 --- a/vp8/vp8cx.mk +++ b/vp8/vp8cx.mk @@ -88,7 +88,7 @@ VP8_CX_SRCS-yes += encoder/temporal_filter.c VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING) += encoder/mr_dissim.c VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING) += encoder/mr_dissim.h -VP8_CX_SRCS-$(CONFIG_UNIT_TESTS) += encoder/boolcoder_test.cc +LIBVPX_TEST_SRCS-yes += ../vp8/encoder/boolcoder_test.cc ifeq ($(CONFIG_REALTIME_ONLY),yes) VP8_CX_SRCS_REMOVE-yes += encoder/firstpass.c