Skip to content

Commit

Permalink
Add travis test scripts (apache#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored and sergei-mironov committed Aug 8, 2018
1 parent 170cbb8 commit 25b3c30
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nnvm/include/nnvm/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Graph {
* \tparam T the type of the attribute.
*/
template<typename T>
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.
Expand Down Expand Up @@ -209,7 +209,7 @@ inline void DFSVisit(const std::vector<NodeEntry>& heads, FVisit fvisit);

// inline function implementations
template<typename T>
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";
Expand Down
6 changes: 6 additions & 0 deletions nnvm/tests/cpp/op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
6 changes: 6 additions & 0 deletions nnvm/tests/cpp/tuple_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 2 additions & 2 deletions nnvm/tests/cpp/unittest.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion nnvm/tests/python/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
54 changes: 54 additions & 0 deletions nnvm/tests/travis/run_test.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions nnvm/tests/travis/setup.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions nnvm/tests/travis/travis_after_failure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash

0 comments on commit 25b3c30

Please sign in to comment.