Added required structure to implement unit tests
authorrodrigosiqueira <rodrigosiqueiramelo@gmail.com>
Sun, 4 Dec 2016 13:28:25 +0000 (11:28 -0200)
committerrodrigosiqueira <rodrigosiqueiramelo@gmail.com>
Sun, 4 Dec 2016 13:34:27 +0000 (11:34 -0200)
Added modifications inside the main Makefile to refers the unit test Makefile.
Added separated Makefile only for compiling unit tests.
Added simple example of unit test.

Signed-off-by: Charles Oliveira <18oliveira.charles@gmail.com>
Signed-off-by: Pablo Alejandro <pabloabur@usp.br>
Signed-off-by: Rodrigo Siqueira <siqueira@ime.usp.br>
.gitignore
Makefile
tests/unit/Makefile [new file with mode: 0644]
tests/unit/kernel/logTest.cc [new file with mode: 0644]
tests/unit/kernel/rtlilTest.cc [new file with mode: 0644]

index 93e28cd6c63e8fd302a281c2ce129ff9e16c8a5e..cd624f23332fdb1257c21eaaf80af2ff0b9f0d0f 100644 (file)
@@ -1,6 +1,7 @@
 *.o
 *.d
 .*.swp
+*.gch
 /.cproject
 /.project
 /.settings
@@ -27,3 +28,5 @@
 /yosys-win32-vcxsrc-*
 /yosysjs-*
 /libyosys.so
+/tests/unit/bintest/
+/tests/unit/objtest/
index 9bf67d3494e8fd3e82b967fd86bc525cadf83671..340fe12296953a94a16a43d9325791193c2d0672 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,9 @@ TARGETS = yosys$(EXE) yosys-config
 PRETTY = 1
 SMALL = 0
 
+# Unit test
+UNITESTPATH := tests/unit
+
 all: top-all
 
 YOSYS_SRC := $(dir $(firstword $(MAKEFILE_LIST)))
@@ -447,6 +450,17 @@ vloghtb: $(TARGETS) $(EXTRA_TARGETS)
        @echo "  Passed \"make vloghtb\"."
        @echo ""
 
+# Unit test
+unit-test: libyosys.so
+       @$(MAKE) -C $(UNITESTPATH) CXX="$(CXX)" CPPFLAGS="$(CPPFLAGS)" \
+               CXXFLAGS="$(CXXFLAGS)" LDLIBS="$(LDLIBS)" ROOTPATH="$(CURDIR)"
+
+run-all-unitest:
+       @$(MAKE) -C $(UNITESTPATH) run-tests
+
+clean-unit-test:
+       @$(MAKE) -C $(UNITESTPATH) clean
+
 install: $(TARGETS) $(EXTRA_TARGETS)
        $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(BINDIR)
        $(INSTALL_SUDO) install $(TARGETS) $(DESTDIR)$(BINDIR)
diff --git a/tests/unit/Makefile b/tests/unit/Makefile
new file mode 100644 (file)
index 0000000..16f65ec
--- /dev/null
@@ -0,0 +1,28 @@
+GTESTFLAG := -lgtest -lgtest_main
+RPATH := -Wl,-rpath
+EXTRAFLAGS := -lyosys
+
+ALLTESTFILE := $(wildcard ./**/*Test.cc)
+OBJTEST := objtest
+BINTEST := bintest
+
+all: prepare $(ALLTESTFILE:%Test.cc=%Test.o)
+
+%Test.o: %Test.cc
+       $(CXX) -o $(OBJTEST)/$(notdir $@) -c -I$(ROOTPATH) $(CPPFLAGS) $(CXXFLAGS) $<
+       $(CXX) -L$(ROOTPATH) $(RPATH)=$(ROOTPATH) -o \
+               $(BINTEST)/$(basename $(notdir $@)) $(OBJTEST)/$(notdir $@) $(LDLIBS) \
+               $(GTESTFLAG) $(EXTRAFLAGS)
+       
+.PHONY: prepare run-tests clean
+
+run-tests:
+       $(CURDIR)/$(BINTEST)/*
+
+prepare:
+       mkdir -p $(OBJTEST)
+       mkdir -p $(BINTEST)
+
+clean:
+       rm -rf $(OBJTEST)
+       rm -rf $(BINTEST)
diff --git a/tests/unit/kernel/logTest.cc b/tests/unit/kernel/logTest.cc
new file mode 100644 (file)
index 0000000..62b4f3b
--- /dev/null
@@ -0,0 +1,14 @@
+#include <gtest/gtest.h>
+
+#include "kernel/yosys.h"
+#include "kernel/log.h"
+
+YOSYS_NAMESPACE_BEGIN
+
+TEST(KernelLogTest, logvValidValues)
+{
+       //TODO: Implement log test
+       EXPECT_EQ(7, 7);
+}
+
+YOSYS_NAMESPACE_END
diff --git a/tests/unit/kernel/rtlilTest.cc b/tests/unit/kernel/rtlilTest.cc
new file mode 100644 (file)
index 0000000..d9eeed5
--- /dev/null
@@ -0,0 +1,14 @@
+#include <gtest/gtest.h>
+
+#include "kernel/yosys.h"
+#include "kernel/rtlil.h"
+
+YOSYS_NAMESPACE_BEGIN
+
+TEST(KernelRtlilTest, getReferenceValid)
+{
+       //TODO: Implement rtlil test
+       EXPECT_EQ(33, 33);
+}
+
+YOSYS_NAMESPACE_END