diff options
-rw-r--r-- | Makefile.am | 12 | ||||
-rw-r--r-- | configure.ac | 66 | ||||
-rw-r--r-- | test/Makefile.am.include | 25 | ||||
-rw-r--r-- | test/physical.cpp | 37 |
4 files changed, 138 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index 3c42e07..5683086 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,3 +9,15 @@ phosphor_ledcontroller_LDFLAGS = $(SDBUSPLUS_LIBS) \ $(PHOSPHOR_DBUS_INTERFACES_LIBS) phosphor_ledcontroller_CFLAGS = $(SDBUSPLUS_CFLAGS) \ $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) + +@CODE_COVERAGE_RULES@ + +check_PROGRAMS = +XFAIL_TESTS = + +include test/Makefile.am.include + +TESTS = $(check_PROGRAMS) + +clean-local: code-coverage-clean +dist-clean-local: code-coverage-dist-clean diff --git a/configure.ac b/configure.ac index 58e557a..7060472 100644 --- a/configure.ac +++ b/configure.ac @@ -26,8 +26,70 @@ PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, [AC_MSG_ERROR([Could not find sdbus PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],, [AC_MSG_ERROR([Could not find phosphor-dbus-interfaces...openbmc/phosphor-dbus-interfaces package required])]) # Check/set gtest specific functions. -AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=0"]) -AC_SUBST(GTEST_CPPFLAGS) +AS_IF([test "x$enable_tests" != "xno"], [ + PKG_CHECK_MODULES([GTEST], [gtest], [], [true]) + PKG_CHECK_MODULES([GMOCK], [gmock], [], [true]) + AX_PTHREAD + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS]) + AC_LANG_PUSH([C++]) + AC_CHECK_HEADERS([gtest/gtest.h], [ + AS_IF([test "x$GTEST_CFLAGS" = "x"], [ + AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [ + AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS]) + ], [ + AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS]) + AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS]) + ]) + ]) + ], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h]) + ]) + ]) + AC_LANG_POP([C++]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS]) + AC_LANG_PUSH([C++]) + AC_CHECK_HEADERS([gmock/gmock.h], [], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h]) + ]) + ]) + AC_LANG_POP([C++]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS]) + AC_CHECK_LIB([gtest], [main], [ + AS_IF([test "x$GTEST_LIBS" = "x"], [ + AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS]) + ]) + ], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but couldn't find gtest libs]) + ]) + ]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS]) + AC_CHECK_LIB([gmock], [main], [ + AS_IF([test "x$GMOCK_LIBS" = "x"], [ + AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS]) + ]) + ], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but couldn't find gmock libs]) + ]) + ]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) +]) + +AX_CODE_COVERAGE AC_ARG_VAR(BUSNAME, [The Dbus busname to own]) AS_IF([test "x$BUSNAME" == "x"], [BUSNAME="xyz.openbmc_project.LED.Controller"]) diff --git a/test/Makefile.am.include b/test/Makefile.am.include new file mode 100644 index 0000000..dd41dd8 --- /dev/null +++ b/test/Makefile.am.include @@ -0,0 +1,25 @@ +AM_CPPFLAGS = \ + $(PTHREAD_CPPFLAGS) \ + $(SDBUSPLUS_CPPFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CPPFLAGS) \ + $(CODE_COVERAGE_CPPFLAGS) +AM_CFLAGS = \ + $(PTHREAD_CFLAGS) \ + $(SDBUSPLUS_CFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \ + $(CODE_COVERAGE_CFLAGS) +AM_CXXFLAGS = \ + $(PTHREAD_CXXFLAGS) \ + $(SDBUSPLUS_CXXFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CXXFLAGS) \ + $(CODE_COVERAGE_CXXFLAGS) +AM_LDFLAGS = \ + $(SDBUSPLUS_LIBS) \ + $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ + $(CODE_COVERAGE_LIBS) \ + -lgtest -lgtest_main -lgmock $(PTHREAD_CFLAGS) $(OESDK_TESTCASE_FLAGS) + +test_physical_SOURCES = %reldir%/physical.cpp +test_physical_LDADD = physical.o + +check_PROGRAMS += %reldir%/physical diff --git a/test/physical.cpp b/test/physical.cpp new file mode 100644 index 0000000..9ab4a30 --- /dev/null +++ b/test/physical.cpp @@ -0,0 +1,37 @@ +#include "physical.hpp" + +#include <sdbusplus/bus.hpp> + +#include <gtest/gtest.h> + +constexpr auto LED_OBJ = "/foo/bar/led"; +constexpr auto LED_SYSFS = "/sys/class/leds/test"; + +using Action = sdbusplus::xyz::openbmc_project::Led::server::Physical::Action; + +TEST(Physical, ctor) +{ + sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); + phosphor::led::Physical led(bus, LED_OBJ, LED_SYSFS); +} + +TEST(Physical, off) +{ + sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); + phosphor::led::Physical led(bus, LED_OBJ, LED_SYSFS); + led.state(Action::Off); +} + +TEST(Physical, on) +{ + sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); + phosphor::led::Physical led(bus, LED_OBJ, LED_SYSFS); + led.state(Action::On); +} + +TEST(Physical, blink) +{ + sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); + phosphor::led::Physical led(bus, LED_OBJ, LED_SYSFS); + led.state(Action::Blink); +} |