diff --git a/lib/import/import-gtest.mk b/lib/import/import-gtest.mk new file mode 100644 index 0000000..5aa2e59 --- /dev/null +++ b/lib/import/import-gtest.mk @@ -0,0 +1,8 @@ +GTEST_PORT_DIR := $(call select_from_ports,googletest) + +INC_DIR += $(GTEST_PORT_DIR)/include + +CC_OPT += -DGTEST_HAS_RTTI=0 +CC_OPT += -DGTEST_HAS_PTHREAD=0 +CC_OPT += -DGTEST_HAS_DEATH_TEST=0 +CC_OPT += -DGTEST_USE_OWN_FLAGFILE_FLAG_=0 diff --git a/lib/mk/gmock.mk b/lib/mk/gmock.mk new file mode 100644 index 0000000..e79c556 --- /dev/null +++ b/lib/mk/gmock.mk @@ -0,0 +1,19 @@ +GMOCK_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googlemock +GTEST_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googletest + +include $(REP_DIR)/lib/import/import-gtest.mk + +SHARED_LIB = yes + +SRC_CC = gmock-all.cc + +vpath %.cc $(GMOCK_DIR)/src + +INC_DIR += $(GMOCK_DIR) +INC_DIR += $(GMOCK_DIR)/include +INC_DIR += $(GMOCK_DIR)/include/internal + +INC_DIR += $(GTEST_DIR)/include +INC_DIR += $(GTEST_DIR)/include/internal + +LIBS += stdcxx diff --git a/lib/mk/gtest.mk b/lib/mk/gtest.mk new file mode 100644 index 0000000..164d3e7 --- /dev/null +++ b/lib/mk/gtest.mk @@ -0,0 +1,13 @@ +GTEST_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googletest + +include $(REP_DIR)/lib/import/import-gtest.mk + +SRC_CC = gtest-all.cc + +vpath %.cc $(GTEST_DIR)/src + +INC_DIR += $(GTEST_DIR) +INC_DIR += $(GTEST_DIR)/include +INC_DIR += $(GTEST_DIR)/include/internal + +LIBS += libc libm stdcxx diff --git a/ports/googletest.hash b/ports/googletest.hash new file mode 100644 index 0000000..44ec81a --- /dev/null +++ b/ports/googletest.hash @@ -0,0 +1 @@ +6dbd3bd4791b02ea55f2b4985b2d6df16cd8e853 diff --git a/ports/googletest.port b/ports/googletest.port new file mode 100644 index 0000000..f66f89e --- /dev/null +++ b/ports/googletest.port @@ -0,0 +1,18 @@ +LICENSE := BSD-3-Clause +VERSION := git +DOWNLOADS := googletest.git + +URL(googletest) := https://github.com/google/googletest.git +REV(googletest) := 10799abad25aa9ec7dcd08d9a46cad093f8bb074 +DIR(googletest) := src/lib/googletest + +DIRS += include/gtest +DIR_CONTENT(include/gtest) := src/lib/googletest/googletest/include/gtest/** + +DIRS += include/gmock +DIR_CONTENT(include/gmock) := src/lib/googletest/googlemock/include/gmock/** + +PATCHES += src/lib/googletest/gtest-port.h.patch + +# quick and dirty solution to enable colored console output +PATCHES += src/lib/googletest/gtest.patch diff --git a/run/gmock.run b/run/gmock.run new file mode 100644 index 0000000..e4238c3 --- /dev/null +++ b/run/gmock.run @@ -0,0 +1,83 @@ +# +# Build +# + +set build_components { + core init + drivers/timer + drivers/rtc + server/ram_fs + test/gmock +} + +build $build_components + +create_boot_directory + +# +# Generate config +# + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +# +# Boot image +# + +build_boot_image { + core init ld.lib.so + timer ram_fs + libc.lib.so libm.lib.so posix.lib.so stdcxx.lib.so + rtc_drv + gmock.lib.so + gmock +} + +append qemu_args " -nographic " + +run_genode_until {.*child "gmock" exited with exit value 0} 1000 diff --git a/run/gtest-samples.run b/run/gtest-samples.run new file mode 100644 index 0000000..e5ccccc --- /dev/null +++ b/run/gtest-samples.run @@ -0,0 +1,72 @@ +# +# Build +# + +set build_components { + core init + drivers/timer + drivers/rtc + test/gtest-samples +} + +build $build_components + +create_boot_directory + +# +# Generate config +# + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +# +# Boot image +# + +build_boot_image { + core init ld.lib.so + timer + libc.lib.so libm.lib.so posix.lib.so stdcxx.lib.so + rtc_drv + gtest-samples +} + +append qemu_args " -nographic " + +run_genode_until {.*child "gtest-samples" exited with exit value 0} 1000 diff --git a/run/gtest.run b/run/gtest.run new file mode 100644 index 0000000..29fc317 --- /dev/null +++ b/run/gtest.run @@ -0,0 +1,80 @@ +# +# Build +# + +set build_components { + core init + drivers/timer + drivers/rtc + server/ram_fs + test/gtest +} + +build $build_components + +create_boot_directory + +# +# Generate config +# + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +# +# Boot image +# + +build_boot_image { + core init ld.lib.so + timer ram_fs + libc.lib.so libm.lib.so posix.lib.so stdcxx.lib.so + rtc_drv + gtest +} + +append qemu_args " -nographic " + +run_genode_until {.*child "gtest" exited with exit value 0} 1000 diff --git a/src/lib/googletest/gtest-port.h.patch b/src/lib/googletest/gtest-port.h.patch new file mode 100644 index 0000000..af55af1 --- /dev/null +++ b/src/lib/googletest/gtest-port.h.patch @@ -0,0 +1,29 @@ +diff --git src/lib/googletest/googletest/include/gtest/internal/gtest-port.h src/lib/googletest/googletest/include/gtest/internal/gtest-port.h +index 0094ed5..41aa33e 100644 +--- src/lib/googletest/googletest/include/gtest/internal/gtest-port.h ++++ src/lib/googletest/googletest/include/gtest/internal/gtest-port.h +@@ -786,6 +786,7 @@ using ::std::tuple_size; + // Google Test does not support death tests for VC 7.1 and earlier as + // abort() in a VC 7.1 application compiled as GUI in debug config + // pops up a dialog window that cannot be suppressed programmatically. ++#ifndef GTEST_HAS_DEATH_TEST + #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ + (GTEST_OS_MAC && !GTEST_OS_IOS) || \ + (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ +@@ -793,6 +794,7 @@ using ::std::tuple_size; + GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD) + # define GTEST_HAS_DEATH_TEST 1 + #endif ++#endif + + // We don't support MSVC 7.1 with exceptions disabled now. Therefore + // all the compilers we care about are adequate for supporting +@@ -963,7 +963,7 @@ + + // _LIBCPP_VERSION is defined by the libc++ library from the LLVM project. + #if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) +-# define GTEST_HAS_CXXABI_H_ 1 ++# define GTEST_HAS_CXXABI_H_ 0 + #else + # define GTEST_HAS_CXXABI_H_ 0 + #endif diff --git a/src/lib/googletest/gtest.patch b/src/lib/googletest/gtest.patch new file mode 100644 index 0000000..67ec29e --- /dev/null +++ b/src/lib/googletest/gtest.patch @@ -0,0 +1,24 @@ ++++ src/lib/googletest/googletest/src/gtest.cc +@@ -2922,21 +2922,7 @@ bool ShouldUseColor(bool stdout_is_tty) { + // console there does support colors. + return stdout_is_tty; + #else +- // On non-Windows platforms, we rely on the TERM variable. +- const char* const term = posix::GetEnv("TERM"); +- const bool term_supports_color = +- String::CStringEquals(term, "xterm") || +- String::CStringEquals(term, "xterm-color") || +- String::CStringEquals(term, "xterm-256color") || +- String::CStringEquals(term, "screen") || +- String::CStringEquals(term, "screen-256color") || +- String::CStringEquals(term, "tmux") || +- String::CStringEquals(term, "tmux-256color") || +- String::CStringEquals(term, "rxvt-unicode") || +- String::CStringEquals(term, "rxvt-unicode-256color") || +- String::CStringEquals(term, "linux") || +- String::CStringEquals(term, "cygwin"); +- return stdout_is_tty && term_supports_color; ++ return stdout_is_tty; + #endif // GTEST_OS_WINDOWS + } + diff --git a/src/test/gmock/main.cc b/src/test/gmock/main.cc new file mode 100644 index 0000000..0449c3b --- /dev/null +++ b/src/test/gmock/main.cc @@ -0,0 +1,21 @@ +/* Genode includes */ +#include + +/* libc includes */ +#include /* 'exit' */ + +/* provided by the application */ +extern "C" int main(int argc, char const **argv); + +void Libc::Component::construct(Libc::Env &env) +{ + Libc::with_libc([&] { + int argc = 2; + char const *argv[] = { + "gmock", + "--gtest_filter=-*Death*:*.*WhenVerbosityIs*:ExpectCallTest.TakesDefaultAction*:AssertTest.FailsFatally*:LogTest.*:*.LogsAnything*:*MockTest.*:*IsMandatory:*.DoesNotWarnOnAdequateActionCount:*.WarnsOn*:*.Reports*:*FunctionCallMessageTest.*:GMockVerboseFlagTest.*", + 0 + }; + exit(main(argc, argv)); + }); +} diff --git a/src/test/gmock/target.mk b/src/test/gmock/target.mk new file mode 100644 index 0000000..0c78f40 --- /dev/null +++ b/src/test/gmock/target.mk @@ -0,0 +1,13 @@ +TARGET = gmock + +GMOCK_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googlemock +GTEST_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googletest + +SRC_CC = gmock_all_test.cc + +vpath gmock_all_test.cc $(GMOCK_DIR)/test + +INC_DIR += $(GMOCK_DIR) $(GTEST_DIR) +CC_OPT += -DGTEST_HAS_PTHREAD=0 + +LIBS = posix stdcxx gtest gmock diff --git a/src/test/gtest-samples/main.cc b/src/test/gtest-samples/main.cc new file mode 100644 index 0000000..6a70647 --- /dev/null +++ b/src/test/gtest-samples/main.cc @@ -0,0 +1,20 @@ +/* Genode includes */ +#include + +/* libc includes */ +#include /* 'exit' */ + +/* provided by the application */ +extern "C" int main(int argc, char const **argv); + +void Libc::Component::construct(Libc::Env &env) +{ + Libc::with_libc([&] { + int argc = 1; + char const *argv[] = { + "gtest-samples", + 0 + }; + exit(main(argc, argv)); + }); +} diff --git a/src/test/gtest-samples/target.mk b/src/test/gtest-samples/target.mk new file mode 100644 index 0000000..36beec7 --- /dev/null +++ b/src/test/gtest-samples/target.mk @@ -0,0 +1,13 @@ +TARGET = gtest-samples + +GTEST_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googletest + +SRC_CC = main.cc gtest_main.cc sample1.cc sample1_unittest.cc + +vpath gtest_main.cc $(GTEST_DIR)/src +vpath sample1.cc $(GTEST_DIR)/samples +vpath sample1_unittest.cc $(GTEST_DIR)/samples + +INC_DIR += $(GTEST_DIR)/samples + +LIBS = posix stdcxx gtest diff --git a/src/test/gtest/main.cc b/src/test/gtest/main.cc new file mode 100644 index 0000000..bc30681 --- /dev/null +++ b/src/test/gtest/main.cc @@ -0,0 +1,21 @@ +/* Genode includes */ +#include + +/* libc includes */ +#include /* 'exit' */ + +/* provided by the application */ +extern "C" int main(int argc, char const **argv); + +void Libc::Component::construct(Libc::Env &env) +{ + Libc::with_libc([&] { + int argc = 2; + char const *argv[] = { + "gtest", + "--gtest_filter=-OutputFile*:Directory*Test.*:*Death*:InitGoogleTestTest.*:CaptureTest.*:RETest*:Thread*:Mutex*:EXPECT_PRED1Test.Function*:ColoredOutputTest.UsesColorsWhenTermSupportsColors", + 0 + }; + exit(main(argc, argv)); + }); +} diff --git a/src/test/gtest/target.mk b/src/test/gtest/target.mk new file mode 100644 index 0000000..9599278 --- /dev/null +++ b/src/test/gtest/target.mk @@ -0,0 +1,12 @@ +TARGET = gtest + +GTEST_DIR := $(call select_from_ports,googletest)/src/lib/googletest/googletest + +SRC_CC = main.cc gtest_main.cc gtest_all_test.cc + +vpath gtest_main.cc $(GTEST_DIR)/src +vpath gtest_all_test.cc $(GTEST_DIR)/test + +INC_DIR += $(GTEST_DIR) + +LIBS = posix stdcxx gtest