ref: e82d261d10729b08ebe3e75fd6927d9993fc9182
parent: 8631c1b8a21f2bc0c5a814d125a2e2eea2d2bf86
author: John Koleszar <jkoleszar@google.com>
date: Wed May 16 12:25:51 EDT 2012
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
--- a/libs.mk
+++ b/libs.mk
@@ -329,7 +329,6 @@
#
# 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 @@
##
## 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 @@
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 @@
@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
--- /dev/null
+++ b/test/test.mk
@@ -1,0 +1,2 @@
+LIBVPX_TEST_SRCS-yes += test.mk
+LIBVPX_TEST_SRCS-yes += test_libvpx.cc
--- /dev/null
+++ b/test/test_libvpx.cc
@@ -1,0 +1,14 @@
+/*
+ * 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
+ * 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"
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- 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"
-#include "vpx_config.h"
-#include "idctllm_test.h"
-namespace
+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<idct_fn_t>
{
+ protected:
+ virtual void SetUp()
+ {
+ int i;
-INSTANTIATE_TEST_CASE_P(C, IDCTTest,
- ::testing::Values(vp8_short_idct4x4llm_c));
+ 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;
+ }
-} // namespace
+ idct_fn_t UUT;
+ short input[16];
+ unsigned char output[256];
+ unsigned char predict[256];
+};
-int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+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;
+}
+
+INSTANTIATE_TEST_CASE_P(C, IDCTTest,
+ ::testing::Values(vp8_short_idct4x4llm_c));
+#if HAVE_MMX
+INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
+ ::testing::Values(vp8_short_idct4x4llm_mmx));
+#endif
}
--- a/vp8/common/idctllm_test.h
+++ /dev/null
@@ -1,113 +1,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<idct_fn_t>
-{
- 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;
-}
-}
--- a/vp8/common/x86/idctllm_mmx_test.cc
+++ /dev/null
@@ -1,31 +1,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.
- */
-
-
- 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
-
-int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
--- a/vp8/encoder/boolcoder_test.cc
+++ b/vp8/encoder/boolcoder_test.cc
@@ -121,9 +121,3 @@
}
}
}
-
-int main(int argc, char **argv)
-{
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
--- a/vp8/vp8_common.mk
+++ b/vp8/vp8_common.mk
@@ -30,7 +30,7 @@
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-$(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
--- a/vp8/vp8cx.mk
+++ b/vp8/vp8cx.mk
@@ -88,7 +88,7 @@
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
--
⑨