Commit 4baf150d by tqchen Committed by Tianqi Chen

Add unittest

parent cf0ef48b
export LDFLAGS= -pthread -lm
export CFLAGS= -std=c++11 -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops\
export LDFLAGS = -pthread -lm
export CFLAGS = -std=c++11 -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops\
-Iinclude -Idmlc-core/include -fPIC
# specify tensor path
.PHONY: clean all test lint doc
all: lib/libnngraph.so test
all: lib/libnngraph.so lib/libnngraph.a cli_test
SRC = $(wildcard src/*.cc src/*/*.cc example/*.cc)
ALL_OBJ = $(patsubst src/%.cc, build/%.o, $(SRC))
ALL_DEP = $(ALL_OBJ)
ALL_DEP = $(filter-out build/test_main.o, $(ALL_OBJ))
include tests/cpp/unittest.mk
test: $(TEST)
build/%.o: src/%.cc
@mkdir -p $(@D)
......@@ -21,7 +24,11 @@ lib/libnngraph.so: $(ALL_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
test: $(ALL_DEP)
lib/libnngraph.a: $(ALL_DEP)
@mkdir -p $(@D)
ar crv $@ $(filter %.o, $?)
cli_test: $(ALL_DEP) build/test_main.o
$(CXX) $(CFLAGS) -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
lint:
......@@ -31,7 +38,7 @@ doc:
doxygen docs/Doxyfile
clean:
$(RM) -rf build lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o test
$(RM) -rf build lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o cli_test
-include build/*.d
-include build/*/*.d
unittest
*.d
*_test
\ No newline at end of file
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <nngraph/op.h>
#include <utility>
NNGRAPH_REGISTER_OP(add)
.describe("add two data together")
.set_num_inputs(2)
.attr("inplace_pair", std::make_pair(0, 0));
NNGRAPH_REGISTER_OP(add)
.attr<std::string>("nick_name", "plus");
TEST(Op, GetAttr) {
using namespace nngraph;
auto add = Op::Get("add");
auto nick = Op::GetAttr<std::string>("nick_name");
CHECK_EQ(nick[add], "plus");
}
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <nngraph/tuple.h>
TEST(Tuple, Basic) {
using nngraph::Tuple;
using nngraph::TShape;
Tuple<int> x{1, 2, 3};
Tuple<int> y{1, 2, 3, 5, 6};
x = std::move(y);
CHECK_EQ(x.ndim(), 5);
Tuple<int> z{1, 2, 3, 5, 6};
std::ostringstream os;
os << z;
CHECK_EQ(os.str(), "(1,2,3,5,6)");
std::istringstream is(os.str());
is >> y;
CHECK_EQ(x, y);
Tuple<nngraph::index_t> ss{1, 2, 3};
TShape s = ss;
s = std::move(ss);
CHECK((s == TShape{1, 2, 3}));
}
GTEST_LIB=$(GTEST_PATH)/lib/
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
$(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
-include tests/cpp/*.d
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment