From 2dec5182c508bd3cc286b4649836ead51aec50ef Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:18:51 +0100 Subject: check_swap: refactor to improve readability --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 17272e45..42fc0292 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(monitoring-plugins,2.3git) AC_CONFIG_SRCDIR(NPTest.pm) AC_CONFIG_FILES([gl/Makefile]) AC_CONFIG_AUX_DIR(build-aux) -AM_INIT_AUTOMAKE([1.8.3]) +AM_INIT_AUTOMAKE([1.8.3 subdir-objects]) AM_SILENT_RULES([yes]) AM_MAINTAINER_MODE([enable]) AC_CONFIG_HEADERS([config.h]) -- cgit v1.2.3-74-g34f1 From 6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:28:35 +0100 Subject: Implement first unit test for check_swap --- .gitignore | 2 ++ configure.ac | 3 +++ plugins/Makefile.am | 19 ++++++++++++++++--- plugins/tests/test_check_swap.c | 21 +++++++++++++++++++++ plugins/tests/test_check_swap.t | 6 ++++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 plugins/tests/test_check_swap.c create mode 100644 plugins/tests/test_check_swap.t (limited to 'configure.ac') diff --git a/.gitignore b/.gitignore index 7e640a0e..bbd7d844 100644 --- a/.gitignore +++ b/.gitignore @@ -221,7 +221,9 @@ NP-VERSION-FILE /plugins/tests/Makefile.in /plugins/tests/test_utils /plugins/tests/test_disk +/plugins/tests/test_check_swap /plugins/tests/.deps +/plugins/tests/.dirstamp # /plugins/check_swap.d /plugins/check_swap.d/.deps diff --git a/configure.ac b/configure.ac index 42fc0292..190b43ad 100644 --- a/configure.ac +++ b/configure.ac @@ -185,6 +185,9 @@ fi if test "$enable_libtap" = "yes" ; then EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64" AC_SUBST(EXTRA_TEST) + + EXTRA_PLUGIN_TESTS="tests/test_check_swap" + AC_SUBST(EXTRA_PLUGIN_TESTS) fi dnl INI Parsing diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 1ca7cf3f..8ef2a246 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -38,19 +38,27 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop \ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ check_swap check_fping check_ldap check_game check_dig \ check_nagios check_by_ssh check_dns check_nt check_ide_smart \ - check_procs check_mysql_query check_apt check_dbi check_curl + check_procs check_mysql_query check_apt check_dbi check_curl \ + \ + tests/test_check_swap SUBDIRS = picohttpparser -EXTRA_DIST = t tests +np_test_scripts = tests/test_check_swap.t + +EXTRA_DIST = t tests $(np_test_scripts) PLUGINHDRS = common.h noinst_LIBRARIES = libnpcommon.a +noinst_PROGRAMS = @EXTRA_PLUGIN_TESTS@ +# These two lines support "make check", but we use "make test" +check_PROGRAMS = @EXTRA_PLUGIN_TESTS@ libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h + BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) NETLIBS = $(NETOBJS) $(SOCKETLIBS) @@ -58,7 +66,10 @@ SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) $(LIB_CRYPTO) TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) -TESTS = @PLUGIN_TEST@ +tap_ldflags = -L$(top_srcdir)/tap + +TESTS = @PLUGIN_TEST@ @EXTRA_PLUGIN_TESTS@ + test: perl -I $(top_builddir) -I $(top_srcdir) ../test.pl @@ -122,6 +133,8 @@ if !HAVE_UTMPX check_users_LDADD += popen.o endif +tests_test_check_swap_LDADD = $(BASEOBJS) check_swap.d/swap.o $(tap_ldflags) -ltap + ############################################################################## # secondary dependencies diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c new file mode 100644 index 00000000..42ac0086 --- /dev/null +++ b/plugins/tests/test_check_swap.c @@ -0,0 +1,21 @@ + +#include "../check_swap.d/check_swap.h" +#include "../../tap/tap.h" + +void print_usage() {}; +void print_help(swap_config config) { + (void) config; +}; + +const char *progname = "test_check_swap"; + +int main() { + + swap_config config = swap_config_init(); + + swap_result test_data = get_swap_data(config); + + plan_tests(1); + + ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data"); +} diff --git a/plugins/tests/test_check_swap.t b/plugins/tests/test_check_swap.t new file mode 100644 index 00000000..97c651a8 --- /dev/null +++ b/plugins/tests/test_check_swap.t @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use Test::More; +if (! -e "./test_check_swap") { + plan skip_all => "./test_swap not compiled - please enable libtap library to test"; +} +exec "./test_check_swap"; -- cgit v1.2.3-74-g34f1 From c9cfe677a7132c568ddec4cf6074fef85bdca1ea Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 12:40:33 +0100 Subject: Remove gettext stuff from main configure.ac --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 190b43ad..e4408a41 100644 --- a/configure.ac +++ b/configure.ac @@ -1853,8 +1853,8 @@ AC_SUBST(EXTRAS_ROOT) AC_SUBST(EXTRA_NETOBJS) AC_SUBST(DEPLIBS) -AM_GNU_GETTEXT([external], [need-ngettext]) -AM_GNU_GETTEXT_VERSION(0.15) +dnl AM_GNU_GETTEXT([external], [need-ngettext]) +dnl AM_GNU_GETTEXT_VERSION(0.15) dnl Check for Redhat spopen problem dnl Weird problem where ECHILD is returned from a wait call in error -- cgit v1.2.3-74-g34f1 From 28b4f8dde4318a474c4d7e2ed1d284a304c419d1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 31 Dec 2024 11:07:00 +0100 Subject: configure.ac: Bump Autoconf to version 2.71 Apply all changes suggested by the autoupdate(1) tool. --- configure.ac | 110 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 48 insertions(+), 62 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 0432336b..e3b66fef 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -AC_PREREQ(2.64) -AC_INIT(monitoring-plugins,2.4git) +AC_PREREQ([2.71]) +AC_INIT([monitoring-plugins],[2.4git]) AC_CONFIG_SRCDIR(NPTest.pm) AC_CONFIG_FILES([gl/Makefile]) AC_CONFIG_AUX_DIR(build-aux) @@ -43,14 +43,14 @@ AC_SUBST(INSTALL) AC_PROG_CC gl_EARLY AC_PROG_GCC_TRADITIONAL -AC_PROG_LIBTOOL +LT_INIT AM_PROG_CC_C_O AC_FUNC_ERROR_AT_LINE AC_SYS_LARGEFILE -ifdef([AC_FUNC_STRTOD],[AC_FUNC_STRTOD],[AM_FUNC_STRTOD]) +ifdef([AC_FUNC_STRTOD],[AC_FUNC_STRTOD],[AC_FUNC_STRTOD]) PLUGIN_TEST=`echo $srcdir/plugins/t/*.t|sed -e 's,\.*/plugins/,,g'` AC_SUBST(PLUGIN_TEST)dnl @@ -125,8 +125,7 @@ AC_SUBST(PERL, $with_perl) dnl openssl/gnutls AC_ARG_WITH(openssl, - AC_HELP_STRING([--with-openssl=DIR], - [path to openssl installation]),) + AS_HELP_STRING([--with-openssl=DIR],[path to openssl installation]),) AC_ARG_WITH(gnutls, ACX_HELP_STRING([--with-gnutls=PATH], @@ -167,8 +166,7 @@ AC_SUBST(MATHLIBS) dnl Check if we buils local libtap AC_ARG_ENABLE(libtap, - AC_HELP_STRING([--enable-libtap], - [Enable built-in libtap for unit-testing (default: autodetect system library).]), + AS_HELP_STRING([--enable-libtap],[Enable built-in libtap for unit-testing (default: autodetect system library).]), [enable_libtap=$enableval], [enable_libtap=no]) AM_CONDITIONAL([USE_LIBTAP_LOCAL],[test "$enable_libtap" = "yes"]) @@ -192,8 +190,7 @@ fi dnl INI Parsing AC_ARG_ENABLE(extra-opts, - AC_HELP_STRING([--enable-extra-opts], - [Enables parsing of plugins ini config files for extra options (default: no)]), + AS_HELP_STRING([--enable-extra-opts],[Enables parsing of plugins ini config files for extra options (default: no)]), [enable_extra_opts=$enableval], [enable_extra_opts=yes]) AM_CONDITIONAL([USE_PARSE_INI],[test "$enable_extra_opts" = "yes"]) @@ -467,20 +464,16 @@ AC_ARG_WITH([ipv6], dnl Check for AF_INET6 support - unistd.h required for Darwin if test "$with_ipv6" != "no"; then AC_CACHE_CHECK([for IPv6 support], np_cv_sys_ipv6, [ - AC_TRY_COMPILE( - [#ifdef HAVE_UNISTD_H + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef HAVE_UNISTD_H #include #endif #include - #include ], - [struct sockaddr_in6 sin6; + #include ]], [[struct sockaddr_in6 sin6; void *p; sin6.sin6_family = AF_INET6; sin6.sin6_port = 587; - p = &sin6.sin6_addr;], - [np_cv_sys_ipv6=yes], - [np_cv_sys_ipv6=no]) + p = &sin6.sin6_addr;]])],[np_cv_sys_ipv6=yes],[np_cv_sys_ipv6=no]) ]) if test "$np_cv_sys_ipv6" = "no" -a "$with_ipv6" != "check"; then AC_MSG_FAILURE([--with-ipv6 was given, but test for IPv6 support failed]) @@ -614,7 +607,20 @@ dnl dnl Checks for header files. dnl -AC_HEADER_TIME +m4_warn([obsolete], +[Update your code to rely only on HAVE_SYS_TIME_H, +then remove this warning and the obsolete code below it. +All current systems provide time.h; it need not be checked for. +Not all systems provide sys/time.h, but those that do, all allow +you to include it and time.h simultaneously.])dnl +AC_CHECK_HEADERS_ONCE([sys/time.h]) +# Obsolete code to be removed. +if test $ac_cv_header_sys_time_h = yes; then + AC_DEFINE([TIME_WITH_SYS_TIME],[1],[Define to 1 if you can safely include both + and . This macro is obsolete.]) +fi +# End of obsolete code. + AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(signal.h syslog.h uio.h errno.h sys/time.h sys/socket.h sys/un.h sys/poll.h) AC_CHECK_HEADERS(features.h stdarg.h sys/unistd.h ctype.h) @@ -626,36 +632,27 @@ AC_TYPE_PID_T AC_TYPE_SIZE_T AC_CACHE_CHECK([for va_copy],ac_cv_HAVE_VA_COPY,[ -AC_TRY_LINK([#include -va_list ap1,ap2;], [va_copy(ap1,ap2);], -ac_cv_HAVE_VA_COPY=yes, -ac_cv_HAVE_VA_COPY=no)]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include +va_list ap1,ap2;]], [[va_copy(ap1,ap2);]])],[ac_cv_HAVE_VA_COPY=yes],[ac_cv_HAVE_VA_COPY=no])]) if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available]) else AC_CACHE_CHECK([for __va_copy],ac_cv_HAVE___VA_COPY,[ - AC_TRY_LINK([#include - va_list ap1,ap2;], [__va_copy(ap1,ap2);], - ac_cv_HAVE___VA_COPY=yes, - ac_cv_HAVE___VA_COPY=no)]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include + va_list ap1,ap2;]], [[__va_copy(ap1,ap2);]])],[ac_cv_HAVE___VA_COPY=yes],[ac_cv_HAVE___VA_COPY=no])]) if test x"$ac_cv_HAVE___VA_COPY" = x"yes"; then AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available]) fi fi -AC_TRY_COMPILE([#include ], - [struct timeval *tv; - struct timezone *tz;], - AC_DEFINE(HAVE_STRUCT_TIMEVAL,1,[Define if we have a timeval structure]) - FOUND_STRUCT_TIMEVAL="yes") +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[struct timeval *tv; + struct timezone *tz;]])],[AC_DEFINE(HAVE_STRUCT_TIMEVAL,1,Define if we have a timeval structure) + FOUND_STRUCT_TIMEVAL="yes"],[]) if test x"$FOUND_STRUCT_TIMEVAL" = x"yes"; then - AC_TRY_COMPILE([#include ], - [struct timeval *tv; + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[struct timeval *tv; struct timezone *tz; - gettimeofday(tv, tz);], - AC_DEFINE(HAVE_GETTIMEOFDAY,1,[Define if gettimeofday is found]), - AC_DEFINE(NEED_GETTIMEOFDAY,1,[Define if gettimeofday is needed])) + gettimeofday(tv, tz);]])],[AC_DEFINE(HAVE_GETTIMEOFDAY,1,Define if gettimeofday is found)],[AC_DEFINE(NEED_GETTIMEOFDAY,1,Define if gettimeofday is needed)]) fi dnl Checks for library functions. @@ -663,14 +660,11 @@ AC_CHECK_FUNCS(memmove select socket strdup strstr strtol strtoul floor) AC_CHECK_FUNCS(poll) AC_MSG_CHECKING(return type of socket size) -AC_TRY_COMPILE([#include +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include #include - #include ], - [int a = send(1, (const void *) buffer, (size_t *) 0, (int *) 0);], - ac_cv_socket_size_type=["size_t"] - AC_MSG_RESULT(size_t), - ac_cv_socket_size_type=["int"] - AC_MSG_RESULT(int)) + #include ]], [[int a = send(1, (const void *) buffer, (size_t *) 0, (int *) 0);]])],[ac_cv_socket_size_type="size_t" + AC_MSG_RESULT(size_t)],[ac_cv_socket_size_type="int" + AC_MSG_RESULT(int)]) AC_DEFINE_UNQUOTED(SOCKET_SIZE_TYPE, $ac_cv_socket_size_type , [Define type of socket size]) @@ -1433,20 +1427,14 @@ if test -n "$ac_cv_nslookup_command"; then fi AC_MSG_CHECKING([for number of online cpus]) -AC_TRY_COMPILE([#include ], - [sysconf(_SC_NPROCESSORS_ONLN) > 0;], - AC_DEFINE(HAVE_SYSCONF__SC_NPROCESSORS_ONLN,1,[Define if sysconf returns number of online cpus]) - AC_MSG_RESULT([sysconf(_SC_NPROCESSORS_ONLN)]), - AC_MSG_RESULT([cannot calculate]) - ) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[sysconf(_SC_NPROCESSORS_ONLN) > 0;]])],[AC_DEFINE(HAVE_SYSCONF__SC_NPROCESSORS_ONLN,1,Define if sysconf returns number of online cpus) + AC_MSG_RESULT(sysconf(_SC_NPROCESSORS_ONLN))],[AC_MSG_RESULT(cannot calculate) + ]) AC_MSG_CHECKING([for number of available cpus]) -AC_TRY_COMPILE([#include ], - [sysconf(_SC_NPROCESSORS_CONF) > 0;], - AC_DEFINE(HAVE_SYSCONF__SC_NPROCESSORS_CONF,1,[Define if sysconf returns number of available cpus]) - AC_MSG_RESULT([sysconf(_SC_NPROCESSORS_CONF)]), - AC_MSG_RESULT([cannot calculate]) - ) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[sysconf(_SC_NPROCESSORS_CONF) > 0;]])],[AC_DEFINE(HAVE_SYSCONF__SC_NPROCESSORS_CONF,1,Define if sysconf returns number of available cpus) + AC_MSG_RESULT(sysconf(_SC_NPROCESSORS_CONF))],[AC_MSG_RESULT(cannot calculate) + ]) AC_PATH_PROG(PATH_TO_UPTIME,uptime) AC_ARG_WITH(uptime_command, @@ -1864,8 +1852,7 @@ dnl We patch plugins/popen.c dnl Need to add smp because uname different on those dnl Can force patch to be applied with --enable-redhat-pthread-workaround AC_ARG_ENABLE(redhat-pthread-workaround, - AC_HELP_STRING([--enable-redhat-pthread-workaround], - [force Redhat patch to be applied (default: test system)]), + AS_HELP_STRING([--enable-redhat-pthread-workaround],[force Redhat patch to be applied (default: test system)]), [ac_cv_enable_redhat_pthread_workaround=$enableval], [ac_cv_enable_redhat_pthread_workaround=test]) if test "$ac_cv_enable_redhat_pthread_workaround" = "test" ; then @@ -1886,8 +1873,7 @@ fi dnl Perl modules AC_ARG_ENABLE(perl-modules, - AC_HELP_STRING([--enable-perl-modules], - [Enables installation of Monitoring::Plugin and its dependencies (default: no)]), + AS_HELP_STRING([--enable-perl-modules],[Enables installation of Monitoring::Plugin and its dependencies (default: no)]), [enable_perl_modules=$enableval], [enable_perl_modules=no]) if test "$enable_perl_modules" = "yes" ; then @@ -1914,8 +1900,7 @@ if test "$ac_cv_uname_s" = 'SunOS' -a \( "x$ac_cv_prog_ac_ct_AR" = "x" -o "$ac_c AC_MSG_ERROR(No ar found for Solaris - is /usr/ccs/bin in PATH?) fi -AC_OUTPUT( - Makefile +AC_CONFIG_FILES([Makefile tap/Makefile lib/Makefile plugins/Makefile @@ -1927,7 +1912,8 @@ AC_OUTPUT( perlmods/Makefile test.pl pkg/solaris/pkginfo -) +]) +AC_OUTPUT dnl the ones below that are commented out need to be cleaned up -- cgit v1.2.3-74-g34f1 From b709a4d858537060a96f2b6986d15d3abcb9529a Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 31 Dec 2024 11:13:01 +0100 Subject: Don't check for TIME_WITH_SYS_TIME Follow the suggestion made by the autoupdate(1) tool: | All current systems provide time.h; it need not be checked for. Not | all systems provide sys/time.h, but those that do, all allow you to | include it and time.h simultaneously. Therefore, include sys/time.h if available, and include time.h unconditionally. --- configure.ac | 15 +-------------- plugins/common.h | 10 ++-------- 2 files changed, 3 insertions(+), 22 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index e3b66fef..79b44c7b 100644 --- a/configure.ac +++ b/configure.ac @@ -607,23 +607,10 @@ dnl dnl Checks for header files. dnl -m4_warn([obsolete], -[Update your code to rely only on HAVE_SYS_TIME_H, -then remove this warning and the obsolete code below it. -All current systems provide time.h; it need not be checked for. -Not all systems provide sys/time.h, but those that do, all allow -you to include it and time.h simultaneously.])dnl -AC_CHECK_HEADERS_ONCE([sys/time.h]) -# Obsolete code to be removed. -if test $ac_cv_header_sys_time_h = yes; then - AC_DEFINE([TIME_WITH_SYS_TIME],[1],[Define to 1 if you can safely include both - and . This macro is obsolete.]) -fi -# End of obsolete code. - AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(signal.h syslog.h uio.h errno.h sys/time.h sys/socket.h sys/un.h sys/poll.h) AC_CHECK_HEADERS(features.h stdarg.h sys/unistd.h ctype.h) +AC_CHECK_HEADERS_ONCE([sys/time.h]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff --git a/plugins/common.h b/plugins/common.h index 833479ce..b7a7d59b 100644 --- a/plugins/common.h +++ b/plugins/common.h @@ -90,16 +90,10 @@ # define GET_NUMBER_OF_CPUS() -1 #endif -#ifdef TIME_WITH_SYS_TIME +#ifdef HAVE_SYS_TIME_H # include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif #endif +#include #ifdef HAVE_SYS_TYPES_H #include -- cgit v1.2.3-74-g34f1 From 29396a397e18f368fc9ecad4a8e831dd6d75d46e Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 31 Dec 2024 12:38:40 +0100 Subject: configure.ac: Lower required Autoconf version Revert the bump to requiring Autoconf 2.71, as some of our CI images don't offer that version yet. Keep the remaining changes though, as they should be compatible with Autoconf 2.64. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 79b44c7b..ef3d26e2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_PREREQ([2.71]) +AC_PREREQ([2.64]) AC_INIT([monitoring-plugins],[2.4git]) AC_CONFIG_SRCDIR(NPTest.pm) AC_CONFIG_FILES([gl/Makefile]) -- cgit v1.2.3-74-g34f1