提交 0057c802 编写于 作者: T tianbingsz 提交者: GitHub

Merge pull request #1058 from tianbingsz/test_util

add paddle_test_util static lib to simplify unit test.
...@@ -156,6 +156,7 @@ function(link_paddle_test TARGET_NAME) ...@@ -156,6 +156,7 @@ function(link_paddle_test TARGET_NAME)
link_paddle_exe(${TARGET_NAME}) link_paddle_exe(${TARGET_NAME})
target_link_libraries(${TARGET_NAME} target_link_libraries(${TARGET_NAME}
paddle_test_main paddle_test_main
paddle_test_util
${GTEST_LIBRARIES}) ${GTEST_LIBRARIES})
endfunction() endfunction()
......
...@@ -17,9 +17,7 @@ if(WITH_TESTING) ...@@ -17,9 +17,7 @@ if(WITH_TESTING)
# file(GLOB test_files . *OpTest.cpp) # file(GLOB test_files . *OpTest.cpp)
# add_executable(${test_bin} EXCLUDE_FROM_ALL ${test_files}) # add_executable(${test_bin} EXCLUDE_FROM_ALL ${test_files})
add_simple_unittest(CrossMapNormalOpTest) add_simple_unittest(CrossMapNormalOpTest)
add_unittest(ContextProjectionOpTest add_simple_unittest(ContextProjectionOpTest)
ContextProjectionOpTest.cpp
../gserver/tests/TestUtil.cpp)
endif() endif()
endif() endif()
......
...@@ -14,8 +14,8 @@ limitations under the License. */ ...@@ -14,8 +14,8 @@ limitations under the License. */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "FunctionTest.h" #include "FunctionTest.h"
#include "paddle/gserver/tests/TestUtil.h"
#include "paddle/math/Matrix.h" #include "paddle/math/Matrix.h"
#include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
################### test_ProtoDataProvider ############ ################### test_ProtoDataProvider ############
add_unittest_without_exec(test_ProtoDataProvider add_unittest_without_exec(test_ProtoDataProvider
test_ProtoDataProvider.cpp test_ProtoDataProvider.cpp)
TestUtil.cpp)
# test_ProtoDataProvider will mkdir as same name, # test_ProtoDataProvider will mkdir as same name,
# so if WORKING_DIRECTORY is default directory, then # so if WORKING_DIRECTORY is default directory, then
...@@ -15,53 +14,46 @@ add_test(NAME test_ProtoDataProvider ...@@ -15,53 +14,46 @@ add_test(NAME test_ProtoDataProvider
################# test_LayerGrad ####################### ################# test_LayerGrad #######################
add_unittest_without_exec(test_LayerGrad add_unittest_without_exec(test_LayerGrad
test_LayerGrad.cpp test_LayerGrad.cpp
LayerGradUtil.cpp LayerGradUtil.cpp)
TestUtil.cpp)
add_test(NAME test_LayerGrad add_test(NAME test_LayerGrad
COMMAND test_LayerGrad) COMMAND test_LayerGrad)
add_unittest_without_exec(test_ActivationGrad add_unittest_without_exec(test_ActivationGrad
test_ActivationGrad.cpp test_ActivationGrad.cpp
LayerGradUtil.cpp LayerGradUtil.cpp)
TestUtil.cpp)
add_test(NAME test_ActivationGrad add_test(NAME test_ActivationGrad
COMMAND test_ActivationGrad) COMMAND test_ActivationGrad)
################# test_ConvTrans ####################### ################# test_ConvTrans #######################
add_unittest_without_exec(test_ConvTrans add_unittest_without_exec(test_ConvTrans
test_ConvTrans.cpp test_ConvTrans.cpp
LayerGradUtil.cpp LayerGradUtil.cpp)
TestUtil.cpp)
add_test(NAME test_ConvTrans add_test(NAME test_ConvTrans
COMMAND test_ConvTrans) COMMAND test_ConvTrans)
################# test_PriorBox ####################### ################# test_PriorBox #######################
add_unittest_without_exec(test_PriorBox add_unittest_without_exec(test_PriorBox
test_PriorBox.cpp test_PriorBox.cpp
LayerGradUtil.cpp LayerGradUtil.cpp)
TestUtil.cpp)
add_test(NAME test_PriorBox add_test(NAME test_PriorBox
COMMAND test_PriorBox) COMMAND test_PriorBox)
################# test_ConvUnify ####################### ################# test_ConvUnify #######################
add_unittest_without_exec(test_ConvUnify add_unittest_without_exec(test_ConvUnify
test_ConvUnify.cpp test_ConvUnify.cpp
LayerGradUtil.cpp LayerGradUtil.cpp)
TestUtil.cpp)
add_test(NAME test_ConvUnify add_test(NAME test_ConvUnify
COMMAND test_ConvUnify) COMMAND test_ConvUnify)
################# test_BatchNorm ####################### ################# test_BatchNorm #######################
add_unittest_without_exec(test_BatchNorm add_unittest_without_exec(test_BatchNorm
test_BatchNorm.cpp test_BatchNorm.cpp
LayerGradUtil.cpp LayerGradUtil.cpp)
TestUtil.cpp)
add_test(NAME test_BatchNorm add_test(NAME test_BatchNorm
COMMAND test_BatchNorm) COMMAND test_BatchNorm)
################## test_Evaluator ####################### ################## test_Evaluator #######################
add_unittest(test_Evaluator add_unittest(test_Evaluator
test_Evaluator.cpp test_Evaluator.cpp)
TestUtil.cpp)
################ test_LinearChainCRF #################### ################ test_LinearChainCRF ####################
add_simple_unittest(test_LinearChainCRF) add_simple_unittest(test_LinearChainCRF)
...@@ -72,8 +64,7 @@ add_simple_unittest(test_MultinomialSampler) ...@@ -72,8 +64,7 @@ add_simple_unittest(test_MultinomialSampler)
############## test_PyDataProvider ######################## ############## test_PyDataProvider ########################
if(WITH_PYTHON) if(WITH_PYTHON)
add_unittest_without_exec(test_PyDataProvider add_unittest_without_exec(test_PyDataProvider
test_PyDataProvider.cpp test_PyDataProvider.cpp)
TestUtil.cpp)
add_test(NAME test_PyDataProvider add_test(NAME test_PyDataProvider
COMMAND .set_python_path.sh -d ./gserver/tests:${PROJ_ROOT}/python/ ${CMAKE_CURRENT_BINARY_DIR}/test_PyDataProvider COMMAND .set_python_path.sh -d ./gserver/tests:${PROJ_ROOT}/python/ ${CMAKE_CURRENT_BINARY_DIR}/test_PyDataProvider
...@@ -81,15 +72,12 @@ if(WITH_PYTHON) ...@@ -81,15 +72,12 @@ if(WITH_PYTHON)
endif() endif()
############### test_RecurrentLayer ####################### ############### test_RecurrentLayer #######################
add_unittest(test_RecurrentLayer add_simple_unittest(test_RecurrentLayer)
test_RecurrentLayer.cpp
TestUtil.cpp)
############### test_WarpCTCLayer ####################### ############### test_WarpCTCLayer #######################
if(NOT WITH_DOUBLE) if(NOT WITH_DOUBLE)
add_unittest_without_exec(test_WarpCTCLayer add_unittest_without_exec(test_WarpCTCLayer
test_WarpCTCLayer.cpp test_WarpCTCLayer.cpp)
TestUtil.cpp)
add_test(NAME test_WarpCTCLayer add_test(NAME test_WarpCTCLayer
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_WarpCTCLayer --warpctc_dir=${PROJ_ROOT}/warp-ctc/build COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_WarpCTCLayer --warpctc_dir=${PROJ_ROOT}/warp-ctc/build
...@@ -108,8 +96,7 @@ add_test(NAME test_RecurrentGradientMachine ...@@ -108,8 +96,7 @@ add_test(NAME test_RecurrentGradientMachine
WORKING_DIRECTORY ${PROJ_ROOT}/paddle) WORKING_DIRECTORY ${PROJ_ROOT}/paddle)
add_unittest_without_exec(test_NetworkCompare add_unittest_without_exec(test_NetworkCompare
test_NetworkCompare.cpp test_NetworkCompare.cpp)
TestUtil.cpp)
if(WITH_GPU) if(WITH_GPU)
add_test(NAME test_NetworkCompare add_test(NAME test_NetworkCompare
COMMAND .set_python_path.sh -d ${PROJ_ROOT}/python ${CMAKE_CURRENT_BINARY_DIR}/test_NetworkCompare --use_gpu=true COMMAND .set_python_path.sh -d ${PROJ_ROOT}/python ${CMAKE_CURRENT_BINARY_DIR}/test_NetworkCompare --use_gpu=true
......
...@@ -17,7 +17,7 @@ limitations under the License. */ ...@@ -17,7 +17,7 @@ limitations under the License. */
#include "paddle/gserver/layers/DataLayer.h" #include "paddle/gserver/layers/DataLayer.h"
#include "paddle/trainer/Trainer.h" #include "paddle/trainer/Trainer.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace std; // NOLINT using namespace std; // NOLINT
namespace paddle { namespace paddle {
......
...@@ -20,7 +20,7 @@ limitations under the License. */ ...@@ -20,7 +20,7 @@ limitations under the License. */
#include "paddle/trainer/Trainer.h" #include "paddle/trainer/Trainer.h"
#include "LayerGradUtil.h" #include "LayerGradUtil.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -22,7 +22,7 @@ limitations under the License. */ ...@@ -22,7 +22,7 @@ limitations under the License. */
#include "paddle/utils/GlobalConstants.h" #include "paddle/utils/GlobalConstants.h"
#include "LayerGradUtil.h" #include "LayerGradUtil.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -23,7 +23,7 @@ limitations under the License. */ ...@@ -23,7 +23,7 @@ limitations under the License. */
#include "paddle/utils/GlobalConstants.h" #include "paddle/utils/GlobalConstants.h"
#include "LayerGradUtil.h" #include "LayerGradUtil.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -23,7 +23,7 @@ limitations under the License. */ ...@@ -23,7 +23,7 @@ limitations under the License. */
#include "paddle/utils/GlobalConstants.h" #include "paddle/utils/GlobalConstants.h"
#include "LayerGradUtil.h" #include "LayerGradUtil.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -15,7 +15,7 @@ limitations under the License. */ ...@@ -15,7 +15,7 @@ limitations under the License. */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <vector> #include <vector>
#include "ModelConfig.pb.h" #include "ModelConfig.pb.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
#include "paddle/trainer/Trainer.h" #include "paddle/trainer/Trainer.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
......
...@@ -21,7 +21,7 @@ limitations under the License. */ ...@@ -21,7 +21,7 @@ limitations under the License. */
#include "paddle/trainer/Trainer.h" #include "paddle/trainer/Trainer.h"
#include "LayerGradUtil.h" #include "LayerGradUtil.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -18,7 +18,7 @@ limitations under the License. */ ...@@ -18,7 +18,7 @@ limitations under the License. */
#include <algorithm> #include <algorithm>
#include <cstdlib> #include <cstdlib>
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
#include "paddle/trainer/Trainer.h" #include "paddle/trainer/Trainer.h"
#include "paddle/utils/Stat.h" #include "paddle/utils/Stat.h"
......
...@@ -17,7 +17,7 @@ limitations under the License. */ ...@@ -17,7 +17,7 @@ limitations under the License. */
#include <vector> #include <vector>
#include "LayerGradUtil.h" #include "LayerGradUtil.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -20,7 +20,7 @@ limitations under the License. */ ...@@ -20,7 +20,7 @@ limitations under the License. */
#include "paddle/gserver/dataproviders/ProtoDataProvider.h" #include "paddle/gserver/dataproviders/ProtoDataProvider.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -20,7 +20,7 @@ limitations under the License. */ ...@@ -20,7 +20,7 @@ limitations under the License. */
#include "paddle/gserver/dataproviders/PyDataProvider.h" #include "paddle/gserver/dataproviders/PyDataProvider.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace std; // NOLINT using namespace std; // NOLINT
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
......
...@@ -19,7 +19,7 @@ limitations under the License. */ ...@@ -19,7 +19,7 @@ limitations under the License. */
#include "paddle/gserver/layers/DataLayer.h" #include "paddle/gserver/layers/DataLayer.h"
#include "paddle/gserver/layers/Layer.h" #include "paddle/gserver/layers/Layer.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -20,7 +20,7 @@ limitations under the License. */ ...@@ -20,7 +20,7 @@ limitations under the License. */
#include "paddle/gserver/layers/Layer.h" #include "paddle/gserver/layers/Layer.h"
#include "paddle/gserver/layers/WarpCTCLayer.h" #include "paddle/gserver/layers/WarpCTCLayer.h"
#include "TestUtil.h" #include "paddle/testing/TestUtil.h"
using namespace paddle; // NOLINT using namespace paddle; // NOLINT
using namespace std; // NOLINT using namespace std; // NOLINT
......
...@@ -7,8 +7,7 @@ add_simple_unittest(test_SparseMatrix) ...@@ -7,8 +7,7 @@ add_simple_unittest(test_SparseMatrix)
# TODO(yuyang18): Refactor TestUtil.cpp. Remove this cross module reference. # TODO(yuyang18): Refactor TestUtil.cpp. Remove this cross module reference.
add_unittest(test_matrixCompare add_unittest(test_matrixCompare
test_matrixCompare.cpp test_matrixCompare.cpp)
../../gserver/tests/TestUtil.cpp)
add_simple_unittest(test_sparseMatrixCompare) add_simple_unittest(test_sparseMatrixCompare)
add_simple_unittest(test_perturbation) add_simple_unittest(test_perturbation)
......
...@@ -15,9 +15,9 @@ limitations under the License. */ ...@@ -15,9 +15,9 @@ limitations under the License. */
#ifndef PADDLE_ONLY_CPU #ifndef PADDLE_ONLY_CPU
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "paddle/gserver/tests/TestUtil.h"
#include "paddle/math/Matrix.h" #include "paddle/math/Matrix.h"
#include "paddle/math/SparseMatrix.h" #include "paddle/math/SparseMatrix.h"
#include "paddle/testing/TestUtil.h"
#include "paddle/utils/Stat.h" #include "paddle/utils/Stat.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
......
...@@ -18,9 +18,9 @@ limitations under the License. */ ...@@ -18,9 +18,9 @@ limitations under the License. */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "TensorCheck.h" #include "TensorCheck.h"
#include "paddle/gserver/tests/TestUtil.h"
#include "paddle/math/Matrix.h" #include "paddle/math/Matrix.h"
#include "paddle/math/SparseMatrix.h" #include "paddle/math/SparseMatrix.h"
#include "paddle/testing/TestUtil.h"
#include "paddle/utils/Stat.h" #include "paddle/utils/Stat.h"
#include "paddle/utils/Util.h" #include "paddle/utils/Util.h"
......
...@@ -3,4 +3,6 @@ ...@@ -3,4 +3,6 @@
if(WITH_TESTING) if(WITH_TESTING)
add_library(paddle_test_main STATIC TestMain.cpp) add_library(paddle_test_main STATIC TestMain.cpp)
add_dependencies(paddle_test_main gen_proto_cpp) add_dependencies(paddle_test_main gen_proto_cpp)
add_library(paddle_test_util STATIC TestUtil.cpp)
add_dependencies(paddle_test_util gen_proto_cpp)
endif() endif()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册