aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Zonenberg <azonenberg@drawersteak.com>2016-12-12 17:05:06 +0800
committerAndrew Zonenberg <azonenberg@drawersteak.com>2016-12-12 17:05:06 +0800
commit01d8278e539933124de1336aa8ab70f49c6ac216 (patch)
tree835ec76259d82c74e975f52749e6360889e042af
parentc3c2983d12ce3b1ed6d7e025eb6b5141f3ed9b40 (diff)
parenta61c88f12215eb8bfa1db62aec7c2c95bb3cc702 (diff)
downloadyosys-01d8278e539933124de1336aa8ab70f49c6ac216.tar.gz
yosys-01d8278e539933124de1336aa8ab70f49c6ac216.tar.bz2
yosys-01d8278e539933124de1336aa8ab70f49c6ac216.zip
Merge https://github.com/cliffordwolf/yosys
-rw-r--r--.gitignore3
-rw-r--r--CodingReadme69
-rw-r--r--Makefile11
-rw-r--r--backends/aiger/aiger.cc7
-rw-r--r--tests/unit/Makefile35
-rw-r--r--tests/unit/kernel/logTest.cc14
-rw-r--r--tests/unit/kernel/rtlilTest.cc14
7 files changed, 153 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 93e28cd6c..cd624f233 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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/
diff --git a/CodingReadme b/CodingReadme
index cbe1fb8be..9e85add28 100644
--- a/CodingReadme
+++ b/CodingReadme
@@ -411,3 +411,72 @@ Updating the website:
git commit -am update
make push
+How to add unit test
+====================
+
+Unit test brings some advantages, briefly, we can list some of them (reference
+[1](https://en.wikipedia.org/wiki/Unit_testing)):
+
+* Tests reduce bugs in new features;
+* Tests reduce bugs in existing features;
+* Tests are good documentation;
+* Tests reduce the cost of change;
+* Tests allow refactoring;
+
+With those advantages in mind, it was required to choose a framework which fits
+well with C/C++ code. Hence, it was chosen (google test)
+[https://github.com/google/googletest], because it is largely used and it is
+relatively easy learn.
+
+Install and configure google test (manually)
+--------------------------------------------
+
+In this section, you will see a brief description of how to install google
+test. However, it is strongly recommended that you take a look to the official
+repository (https://github.com/google/googletest) and refers to that if you
+have any problem to install it. Follow the steps below:
+
+* Install: cmake and pthread
+* Clone google test project from: https://github.com/google/googletest and
+ enter in the project directory
+* Inside project directory, type:
+
+```
+cmake -DBUILD_SHARED_LIBS=ON .
+make
+```
+
+* After compilation, copy all "*.so" inside directory "googlemock" and
+ "googlemock/gtest" to "/usr/lib/"
+* Done! Now you can compile your tests.
+
+If you have any problem, go to the official repository to find help.
+
+Ps.: Some distros already have googletest packed. If your distro supports it,
+you can use it instead of compile.
+
+Create new unit test
+--------------------
+
+If you want to add new unit tests for Yosys, just follow the steps below:
+
+* Go to directory "yosys/test/unit/"
+* In this directory you can find something similar Yosys's directory structure.
+ To create your unit test file you have to follow this pattern:
+ fileNameToImplementUnitTest + Test.cc. E.g.: if you want to implement the
+ unit test for kernel/celledges.cc, you will need to create a file like this:
+ tests/unit/kernel/celledgesTest.cc;
+* Implement your unit test
+
+Run unit test
+-------------
+
+To compile and run all unit tests, just go to yosys root directory and type:
+```
+make unit-test
+```
+
+If you want to remove all unit test files, type:
+```
+make clean-unit-test
+```
diff --git a/Makefile b/Makefile
index 9bf67d349..cf40309ce 100644
--- 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,14 @@ 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)"
+
+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/backends/aiger/aiger.cc b/backends/aiger/aiger.cc
index aefe5cf43..ab1fba6f1 100644
--- a/backends/aiger/aiger.cc
+++ b/backends/aiger/aiger.cc
@@ -163,6 +163,13 @@ struct AigerWriter
continue;
}
+ if (cell->type == "$anyconst")
+ {
+ for (auto bit : sigmap(cell->getPort("\\Y")))
+ ff_map[bit] = bit;
+ continue;
+ }
+
log_error("Unsupported cell type: %s (%s)\n", log_id(cell->type), log_id(cell));
}
diff --git a/tests/unit/Makefile b/tests/unit/Makefile
new file mode 100644
index 000000000..9f1e5c99e
--- /dev/null
+++ b/tests/unit/Makefile
@@ -0,0 +1,35 @@
+GTESTFLAG := -lgtest -lgtest_main
+RPATH := -Wl,-rpath
+EXTRAFLAGS := -lyosys -pthreads
+
+OBJTEST := objtest
+BINTEST := bintest
+
+ALLTESTFILE := $(shell find -name '*Test.cc' -printf '%P ')
+TESTDIRS := $(sort $(dir $(ALLTESTFILE)))
+TESTS := $(addprefix $(BINTEST)/, $(basename $(ALLTESTFILE:%Test.cc=%Test.o)))
+
+# Prevent make from removing our .o files
+.SECONDARY:
+
+all: prepare $(TESTS) run-tests
+
+$(BINTEST)/%: $(OBJTEST)/%.o
+ $(CXX) -L$(ROOTPATH) $(RPATH)=$(ROOTPATH) -o $@ $^ $(LDLIBS) \
+ $(GTESTFLAG) $(EXTRAFLAGS)
+
+$(OBJTEST)/%.o: $(basename $(subst $(OBJTEST),.,%)).cc
+ $(CXX) -o $@ -c -I$(ROOTPATH) $(CPPFLAGS) $(CXXFLAGS) $^
+
+.PHONY: prepare run-tests clean
+
+run-tests: $(TESTS)
+ $(subst Test ,Test; ,$^)
+
+prepare:
+ mkdir -p $(addprefix $(BINTEST)/,$(TESTDIRS))
+ mkdir -p $(addprefix $(OBJTEST)/,$(TESTDIRS))
+
+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
index 000000000..62b4f3b98
--- /dev/null
+++ b/tests/unit/kernel/logTest.cc
@@ -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
index 000000000..d9eeed555
--- /dev/null
+++ b/tests/unit/kernel/rtlilTest.cc
@@ -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