sysd_monitor: Parse json file(s)
Parse the json file(s) into a c++ data object that can be used in later
commits to easily check for monitored targets and log appropriate
errors.
Accept a command line parameter to input file and call parsing function
Tested:
- Verified 100% code coverage of new parser cpp
Change-Id: I0bacd80b7f5330eb9cb03d8e3717742ab107bf94
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/configure.ac b/configure.ac
index 07ef420..e6ec283 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
AC_INIT([phosphor-state-manager], [1.0], [https://github.com/openbmc/phosphor-state-manager/issues])
AC_LANG([C++])
AC_CONFIG_HEADERS([config.h])
-AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign])
AM_SILENT_RULES([yes])
# Checks for programs
@@ -23,6 +23,8 @@
[],
[AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
)
+AC_CHECK_HEADER(nlohmann/json.hpp, ,
+ [AC_MSG_ERROR([Could not find nlohmann/json.hpp... nlohmann/json package required])])
# Checks for typedefs, structures, and compiler characteristics.
AX_CXX_COMPILE_STDCXX_17([noext])
@@ -90,5 +92,88 @@
AS_IF([test "x$CLASS_VERSION" == "x"], [CLASS_VERSION=1])
AC_DEFINE_UNQUOTED([CLASS_VERSION], [$CLASS_VERSION], [Class version to register with Cereal])
+# Make it possible for users to choose if they want test support
+# explicitly or not at all
+AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
+ [Build test cases]))
+
+ # Check/set gtest specific functions
+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_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])
+ ])
+ ])
+ AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
+
+ AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
+ AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
+ 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])
+ ])
+ ])
+ 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])
+])
+
+# Check for valgrind
+AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
+m4_foreach([vgtool], [valgrind_tool_list],
+ [AX_VALGRIND_DFLT(vgtool, [off])])
+AX_VALGRIND_DFLT([memcheck], [on])
+AX_VALGRIND_CHECK
+AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
+m4_foreach([vgtool], [valgrind_tool_list],
+ [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
+
+# Code coverage
+AX_CODE_COVERAGE
+
+m4_ifdef([_AX_CODE_COVERAGE_RULES],
+ [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
+ [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
+AX_ADD_AM_MACRO_STATIC([])
+
AC_CONFIG_FILES([Makefile])
AC_OUTPUT