From a303f242e656812a1882c56d88c551fad07bf565 Mon Sep 17 00:00:00 2001 From: "Lukas Steiner (2)" Date: Thu, 25 Jul 2019 11:49:18 +0200 Subject: [PATCH] Included googletest and subproject for unit tests. --- .gitmodules | 3 ++ DRAMSys/DRAMSys.pro | 2 + DRAMSys/unitTests/Testfile.h | 7 +++ DRAMSys/unitTests/googleTest.pri | 23 ++++++++++ DRAMSys/unitTests/googletest | 1 + DRAMSys/unitTests/main.cpp | 9 ++++ DRAMSys/unitTests/unitTests.pro | 77 ++++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+) create mode 100644 DRAMSys/unitTests/Testfile.h create mode 100644 DRAMSys/unitTests/googleTest.pri create mode 160000 DRAMSys/unitTests/googletest create mode 100644 DRAMSys/unitTests/main.cpp create mode 100644 DRAMSys/unitTests/unitTests.pro diff --git a/.gitmodules b/.gitmodules index 82647b71..458b70e3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ path = DRAMSys/library/src/common/third_party/DRAMPower url = https://github.com/tukl-msd/DRAMPower.git branch = master +[submodule "DRAMSys/unitTests/googletest"] + path = DRAMSys/unitTests/googletest + url = https://github.com/google/googletest.git diff --git a/DRAMSys/DRAMSys.pro b/DRAMSys/DRAMSys.pro index 83be2a95..d4a5e29e 100644 --- a/DRAMSys/DRAMSys.pro +++ b/DRAMSys/DRAMSys.pro @@ -25,10 +25,12 @@ isEmpty(systemc_home) { message(SystemC home is $${systemc_home}) SUBDIRS += library +SUBDIRS += unitTests SUBDIRS += simulator SUBDIRS += traceAnalyzer library.subdir = library +unitTests.subdir = unitTests simulator.subdir = simulator traceAnalyzer.subdir = traceAnalyzer diff --git a/DRAMSys/unitTests/Testfile.h b/DRAMSys/unitTests/Testfile.h new file mode 100644 index 00000000..50726e5c --- /dev/null +++ b/DRAMSys/unitTests/Testfile.h @@ -0,0 +1,7 @@ +#include +#include "../library/src/controller/Command.h" + +TEST(testsuite, test) +{ + EXPECT_EQ(commandToString(Command::Activate), "ACT"); +} diff --git a/DRAMSys/unitTests/googleTest.pri b/DRAMSys/unitTests/googleTest.pri new file mode 100644 index 00000000..122881e3 --- /dev/null +++ b/DRAMSys/unitTests/googleTest.pri @@ -0,0 +1,23 @@ +GOOGLETEST_DIR = googletest + +!isEmpty(GOOGLETEST_DIR): { + GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest + GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock +} + +requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR)) + +!exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.") + +DEFINES += \ + GTEST_LANG_CXX11 + +INCLUDEPATH *= \ + $$GTEST_SRCDIR \ + $$GTEST_SRCDIR/include \ + $$GMOCK_SRCDIR \ + $$GMOCK_SRCDIR/include + +SOURCES += \ + $$GTEST_SRCDIR/src/gtest-all.cc \ + $$GMOCK_SRCDIR/src/gmock-all.cc diff --git a/DRAMSys/unitTests/googletest b/DRAMSys/unitTests/googletest new file mode 160000 index 00000000..b77e5c76 --- /dev/null +++ b/DRAMSys/unitTests/googletest @@ -0,0 +1 @@ +Subproject commit b77e5c76252bac322bb82c5b444f050bd0d92451 diff --git a/DRAMSys/unitTests/main.cpp b/DRAMSys/unitTests/main.cpp new file mode 100644 index 00000000..e76b5f95 --- /dev/null +++ b/DRAMSys/unitTests/main.cpp @@ -0,0 +1,9 @@ +#include +#include +#include "Testfile.h" + +int sc_main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/DRAMSys/unitTests/unitTests.pro b/DRAMSys/unitTests/unitTests.pro new file mode 100644 index 00000000..375411e7 --- /dev/null +++ b/DRAMSys/unitTests/unitTests.pro @@ -0,0 +1,77 @@ +TARGET = unitTestsDRAMSys + +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + +systemc_home = $$(SYSTEMC_HOME) +isEmpty(systemc_home) { + systemc_home = /opt/systemc +} +message(SystemC home is $${systemc_home}) + +systemc_target_arch = $$(SYSTEMC_TARGET_ARCH) +isEmpty(systemc_target_arch) { + systemc_target_arch = linux64 +} + +message(SystemC target architecture is $${systemc_target_arch}) + +dramsys_disable_coverage_check = $$(DRAMSYS_DISABLE_COVERAGE_CHECK) +isEmpty(dramsys_disable_coverage_check) { + coverage_check = true + message(Coverage check ENABLED) +} else { + coverage_check = false + message(Coverage check DISABLED) +} + +unix:!macx { + message(Building on a GNU/Linux) + QMAKE_RPATHDIR += $${systemc_home}/lib-$${systemc_target_arch} + message(Linker options QMAKE_RPATHDIR is $${QMAKE_RPATHDIR}) +} + +DEFINES += TIXML_USE_STL +DEFINES += SC_INCLUDE_DYNAMIC_PROCESSES + +unix:!macx { + QMAKE_CXXFLAGS += -std=c++11 -O0 -g + $$eval(coverage_check) { + QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage -fPIC -O0 + QMAKE_LFLAGS += -lgcov --coverage + } +} + +macx: { + CONFIG += c++11 + QMAKE_CXXFLAGS += -std=c++0x -stdlib=libc++ -O0 -g + $$eval(coverage_check) { + QMAKE_CXXFLAGS += --coverage + QMAKE_LFLAGS += --coverage + } +} + +QMAKE_CXXFLAGS += -pthread + +INCLUDEPATH += ../library/src/simulation/ +INCLUDEPATH += $${systemc_home}/include + +LIBS += -L$${systemc_home}/lib-$${systemc_target_arch} -lsystemc -lpthread + +SOURCEHOME = ../library/src/ + +SOURCES += \ + main.cpp \ + $${SOURCEHOME}/controller/Command.cpp + + +HEADERS += \ + Testfile.h \ + $${SOURCEHOME}/controller/Command.h + +DISTFILES += ../DRAMSys.astylerc + +include(googleTest.pri) +DISTFILES += googleTest.pri