From ca99c108afd17c95bd7d7547b2b5ca9b74ca78db Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Wed, 31 Aug 2016 16:20:24 -0700 Subject: [PATCH] Add travis test scripts (#35) --- nnvm/include/nnvm/graph.h | 4 +- nnvm/tests/cpp/op_test.cc | 6 +++ nnvm/tests/cpp/tuple_test.cc | 6 +++ nnvm/tests/cpp/unittest.mk | 4 +- nnvm/tests/python/test_gradient.py | 2 +- nnvm/tests/travis/run_test.sh | 54 +++++++++++++++++++++++ nnvm/tests/travis/setup.sh | 19 ++++++++ nnvm/tests/travis/travis_after_failure.sh | 1 + 8 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 nnvm/tests/travis/run_test.sh create mode 100644 nnvm/tests/travis/setup.sh create mode 100644 nnvm/tests/travis/travis_after_failure.sh diff --git a/nnvm/include/nnvm/graph.h b/nnvm/include/nnvm/graph.h index 5147b22e4aec..9c08467218e9 100644 --- a/nnvm/include/nnvm/graph.h +++ b/nnvm/include/nnvm/graph.h @@ -46,7 +46,7 @@ class Graph { * \tparam T the type of the attribute. */ template - inline const T& GetAttr(const std::string& attr_name); + inline const T& GetAttr(const std::string& attr_name) const; /*! * \brief Get a move copy of the attribute, implement copy on write semantics. * The content is moved if the reference counter of shared_ptr is 1. @@ -209,7 +209,7 @@ inline void DFSVisit(const std::vector& heads, FVisit fvisit); // inline function implementations template -inline const T& Graph::GetAttr(const std::string& attr_name) { +inline const T& Graph::GetAttr(const std::string& attr_name) const { auto it = attrs.find(attr_name); CHECK(it != attrs.end()) << "Cannot find attribute " << attr_name << " in the graph"; diff --git a/nnvm/tests/cpp/op_test.cc b/nnvm/tests/cpp/op_test.cc index 816305c609ca..164cc469ad34 100644 --- a/nnvm/tests/cpp/op_test.cc +++ b/nnvm/tests/cpp/op_test.cc @@ -19,3 +19,9 @@ TEST(Op, GetAttr) { CHECK_EQ(nick[add], "plus"); } + +int main(int argc, char ** argv) { + testing::InitGoogleTest(&argc, argv); + testing::FLAGS_gtest_death_test_style = "threadsafe"; + return RUN_ALL_TESTS(); +} diff --git a/nnvm/tests/cpp/tuple_test.cc b/nnvm/tests/cpp/tuple_test.cc index 496e62ebe9a5..85cbc08f1f6f 100644 --- a/nnvm/tests/cpp/tuple_test.cc +++ b/nnvm/tests/cpp/tuple_test.cc @@ -22,3 +22,9 @@ TEST(Tuple, Basic) { s = std::move(ss); CHECK((s == TShape{1, 2, 3})); } + +int main(int argc, char ** argv) { + testing::InitGoogleTest(&argc, argv); + testing::FLAGS_gtest_death_test_style = "threadsafe"; + return RUN_ALL_TESTS(); +} diff --git a/nnvm/tests/cpp/unittest.mk b/nnvm/tests/cpp/unittest.mk index ade9f93947bd..1328eb7a314a 100644 --- a/nnvm/tests/cpp/unittest.mk +++ b/nnvm/tests/cpp/unittest.mk @@ -4,9 +4,9 @@ GTEST_INC=$(GTEST_PATH)/include/ TEST_SRC = $(wildcard tests/cpp/*_test.cc) TEST = $(patsubst tests/cpp/%_test.cc, tests/cpp/%_test, $(TEST_SRC)) -tests/cpp/%_test: tests/cpp/%_test.cc lib/libnngraph.a +tests/cpp/%_test: tests/cpp/%_test.cc lib/libnnvm.a $(CXX) -std=c++11 $(CFLAGS) -MM -MT tests/cpp/$* $< >tests/cpp/$*.d $(CXX) -std=c++11 $(CFLAGS) -I$(GTEST_INC) -o $@ $(filter %.cc %.a, $^) \ - -L$(GTEST_LIB) $(LDFLAGS) -lgtest -lgtest_main + -L$(GTEST_LIB) $(LDFLAGS) -lgtest -include tests/cpp/*.d diff --git a/nnvm/tests/python/test_gradient.py b/nnvm/tests/python/test_gradient.py index 5acdb1207f20..00fc5c75e620 100644 --- a/nnvm/tests/python/test_gradient.py +++ b/nnvm/tests/python/test_gradient.py @@ -18,7 +18,7 @@ def test_graph_gradient(): print("Original graph") print(y.debug_str()) print("Gradient graph") - print grad_graph.symbol.debug_str() + print(grad_graph.symbol.debug_str()) if __name__ == "__main__": test_graph_gradient() diff --git a/nnvm/tests/travis/run_test.sh b/nnvm/tests/travis/run_test.sh new file mode 100644 index 000000000000..2c4fe4a2f036 --- /dev/null +++ b/nnvm/tests/travis/run_test.sh @@ -0,0 +1,54 @@ +#!/bin/bash + + +if [ ${TASK} == "lint" ]; then + make lint || exit -1 + echo "Check documentations of c++ code..." + make doc 2>log.txt + (cat log.txt| grep -v ENABLE_PREPROCESSING |grep -v "unsupported tag") > logclean.txt + echo "---------Error Log----------" + cat logclean.txt + echo "----------------------------" + (cat logclean.txt|grep warning) && exit -1 + (cat logclean.txt|grep error) && exit -1 + exit 0 +fi + + +if [ ! ${TRAVIS_OS_NAME} == "osx" ]; then + # use g++-4.8 for linux + if [ ${CXX} == "g++" ]; then + export CXX=g++-4.8 + fi +fi + +if [ ${TASK} == "cpp_test" ]; then + make -f dmlc-core/scripts/packages.mk gtest + echo "GTEST_PATH="${CACHE_PREFIX} >> config.mk + make test || exit -1 + for test in tests/cpp/*_test; do + ./$test || exit -1 + done + exit 0 +fi + +# run two test one for cython, one for ctypes +if [ ${TASK} == "python_test" ]; then + make clean + make -j all || exit -1 + if [ ${TRAVIS_OS_NAME} == "osx" ]; then + python -m nose tests/python/ || exit -1 + python3 -m nose tests/python/ || exit -1 + else + nosetests tests/python/ || exit -1 + nosetests3 tests/python/ || exit -1 + fi + + python -m nose tests/python/ || exit -1 + python3 -m nose tests/python/ || exit -1 + make cython || exit -1 + make cython3 || exit -1 + python -m nose tests/python/ || exit -1 + python3 -m nose tests/python/ || exit -1 + exit 0 +fi diff --git a/nnvm/tests/travis/setup.sh b/nnvm/tests/travis/setup.sh new file mode 100644 index 000000000000..2621a7f03f25 --- /dev/null +++ b/nnvm/tests/travis/setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + + +if [ ${TRAVIS_OS_NAME} == "osx" ]; then + brew update + brew install python3 + if [ ${TASK} == "python_test" ]; then + python -m pip install nose numpy cython --user `whoami` + python3 -m pip install nose numpy cython --user `whoami` + fi +fi + +if [ ${TASK} == "lint" ]; then + pip install cpplint 'pylint==1.4.4' 'astroid==1.3.6' --user `whoami` +fi + +if [ ! -d dmlc-core ]; then + git clone https://github.com/dmlc/dmlc-core +fi diff --git a/nnvm/tests/travis/travis_after_failure.sh b/nnvm/tests/travis/travis_after_failure.sh new file mode 100644 index 000000000000..a9bf588e2f88 --- /dev/null +++ b/nnvm/tests/travis/travis_after_failure.sh @@ -0,0 +1 @@ +#!/bin/bash