diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a9ef435e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +PROJECT(sigar C) + +cmake_minimum_required(VERSION 2.6) + +INCLUDE(CheckIncludeFiles) +INCLUDE(CheckFunctionExists) +INCLUDE(CheckTypeSize) +INCLUDE(CTest) +INCLUDE(InstallRequiredSystemLibraries) + +ENABLE_TESTING() + +SET(CPACK_PACKAGE_VERSION_MAJOR "1") +SET(CPACK_PACKAGE_VERSION_MINOR "6") +SET(CPACK_PACKAGE_VERSION_PATCH "2") +SET(CPACK_PACKAGE_VENDOR "Hyperic") +## SET(CPACK_*) before the INCLUDE(CPack) +INCLUDE(CPack) + +IF(WIN32) + ## make sure we only use the smallest set of + ## headers on win32. Otherwise we get clashes + ## between winsock2.h and winsock.h + ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN) + + # force the correct version for the redist manifest + ADD_DEFINITIONS(-D_BIND_TO_CURRENT_MFC_VERSION=1 -D_BIND_TO_CURRENT_CRT_VERSION=1) + # turn off security warnings for system calls + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) +ENDIF(WIN32) + +ADD_SUBDIRECTORY(src build-src) +ADD_SUBDIRECTORY(tests build-tests) +ADD_SUBDIRECTORY(include build-include) + diff --git a/Makefile.am b/Makefile.am index 865e8f95..ed215524 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,5 @@ -SUBDIRS = src examples +SUBDIRS = include src examples tests +EXTRA_DIST=\ + CMakeLists.txt \ + winbuild.bat diff --git a/autogen.sh b/autogen.sh index a46b735d..e9688bf3 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,15 +1,96 @@ #!/bin/sh -set -x +# Run this to generate all the initial makefiles, etc. -touch INSTALL NEWS AUTHORS -libtoolize="libtoolize" -if which glibtoolize >/dev/null 2>&1 -then - libtoolize=glibtoolize +# LIBTOOLIZE=${LIBTOOLIZE:-libtoolize} +LIBTOOLIZE_FLAGS="--copy --force" +# ACLOCAL=${ACLOCAL:-aclocal} +# AUTOHEADER=${AUTOHEADER:-autoheader} +# AUTOMAKE=${AUTOMAKE:-automake} +AUTOMAKE_FLAGS="--add-missing --copy" +# AUTOCONF=${AUTOCONF:-autoconf} + +ARGV0=$0 +ARGS="$@" + + +run() { + echo "$ARGV0: running \`$@' $ARGS" + $@ $ARGS +} + +## jump out if one of the programs returns 'false' +set -e + +## on macosx glibtoolize, others have libtool +if test x$LIBTOOLIZE = x; then + if test \! "x`which glibtoolize 2> /dev/null | grep -v '^no'`" = x; then + LIBTOOLIZE=glibtoolize + elif test \! "x`which libtoolize-1.5 2> /dev/null | grep -v '^no'`" = x; then + LIBTOOLIZE=libtoolize-1.5 + elif test \! "x`which libtoolize 2> /dev/null | grep -v '^no'`" = x; then + LIBTOOLIZE=libtoolize + else + echo "libtoolize 1.5.x wasn't found, exiting"; exit 0 + fi fi -autoheader \ -&& aclocal \ -&& $libtoolize --copy --force \ -&& automake --add-missing --copy \ -&& autoconf +## suse has aclocal and aclocal-1.9 +if test x$ACLOCAL = x; then + if test \! "x`which aclocal-1.9 2> /dev/null | grep -v '^no'`" = x; then + ACLOCAL=aclocal-1.9 + elif test \! "x`which aclocal19 2> /dev/null | grep -v '^no'`" = x; then + ACLOCAL=aclocal19 + elif test \! "x`which aclocal 2> /dev/null | grep -v '^no'`" = x; then + ACLOCAL=aclocal + else + echo "automake 1.9.x (aclocal) wasn't found, exiting"; exit 0 + fi +fi + +if test x$AUTOMAKE = x; then + if test \! "x`which automake-1.9 2> /dev/null | grep -v '^no'`" = x; then + AUTOMAKE=automake-1.9 + elif test \! "x`which automake19 2> /dev/null | grep -v '^no'`" = x; then + AUTOMAKE=automake19 + elif test \! "x`which automake 2> /dev/null | grep -v '^no'`" = x; then + AUTOMAKE=automake + else + echo "automake 1.9.x wasn't found, exiting"; exit 0 + fi +fi + + +## macosx has autoconf-2.59 and autoconf-2.60 +if test x$AUTOCONF = x; then + if test \! "x`which autoconf-2.59 2> /dev/null | grep -v '^no'`" = x; then + AUTOCONF=autoconf-2.59 + elif test \! "x`which autoconf259 2> /dev/null | grep -v '^no'`" = x; then + AUTOCONF=autoconf259 + elif test \! "x`which autoconf 2> /dev/null | grep -v '^no'`" = x; then + AUTOCONF=autoconf + else + echo "autoconf 2.59+ wasn't found, exiting"; exit 0 + fi +fi + +if test x$AUTOHEADER = x; then + if test \! "x`which autoheader-2.59 2> /dev/null | grep -v '^no'`" = x; then + AUTOHEADER=autoheader-2.59 + elif test \! "x`which autoheader259 2> /dev/null | grep -v '^no'`" = x; then + AUTOHEADER=autoheader259 + elif test \! "x`which autoheader 2> /dev/null | grep -v '^no'`" = x; then + AUTOHEADER=autoheader + else + echo "autoconf 2.59+ (autoheader) wasn't found, exiting"; exit 0 + fi +fi + + +run $LIBTOOLIZE $LIBTOOLIZE_FLAGS +run $ACLOCAL $ACLOCAL_FLAGS +# we don't need autoheader as we don't have a config.h +# run $AUTOHEADER +run $AUTOMAKE $AUTOMAKE_FLAGS +run $AUTOCONF +test "$ARGS" = "" && echo "Now type './configure --enable-maintainer-mode ...' and 'make' to compile." + diff --git a/configure.ac b/configure.ac index 42613400..54ae61e8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,9 +1,21 @@ +dnl ... hmm ... we have to duplicate the data below again AC_INIT(libsigar, 1.6.2) AC_CONFIG_SRCDIR(src/sigar.c) -AC_CONFIG_HEADERS(src/config.h) -AM_INIT_AUTOMAKE +dnl AC_CONFIG_HEADERS(src/config.h) +AM_INIT_AUTOMAKE([foreign]) AC_CANONICAL_HOST +dnl for sigar_version_autoconf.c.in +VERSION_MAJOR=1 +VERSION_MINOR=6 +VERSION_MAINT=2 +VERSION_BUILD=0 + +AC_SUBST(VERSION_MAJOR) +AC_SUBST(VERSION_MINOR) +AC_SUBST(VERSION_MAINT) +AC_SUBST(VERSION_BUILD) + AC_PROG_CC AC_PROG_LN_S AC_PROG_INSTALL @@ -11,57 +23,109 @@ AC_PROG_MAKE_SET AC_PROG_LIBTOOL AC_MSG_CHECKING([for os type ($host_os)]) +FRAMEWORK= case $host_os in *aix*) SRC_OS="aix" + AC_DEFINE(SIGAR_TEST_OS_AIX, [1], [for the tests]) + LIBS="-lodm -lcfg -lperfstat -lpthreads" ;; *darwin*) SRC_OS="darwin" - ;; - *freebsd*) - SRC_OS="darwin" - LIBS="-lkvm" - ;; - *hpux*) - SRC_OS="hpux" - ;; - *linux*) - SRC_OS="linux" - ;; - *openbsd*) - SRC_OS="darwin" - LIBS="-lkvm" + AC_DEFINE(DARWIN,[],[running on MacOS X]) + AC_DEFINE(SIGAR_TEST_OS_DARWIN, [1], [for the tests]) + SIGAR_INCLUDES="-I /Developer/Headers/FlatCarbon/" + SIGAR_LIBS="-framework IOKit -framework CoreServices" ;; *netbsd*) SRC_OS="darwin" - LIBS="-lkvm" + AC_DEFINE(SIGAR_TEST_OS_DARWIN, [1], [for the tests]) + SIGAR_LIBS="-lkvm" + ;; + *openbsd*) + SRC_OS="darwin" + AC_DEFINE(SIGAR_TEST_OS_DARWIN, [1], [for the tests]) + SIGAR_LIBS="-lkvm" + ;; + *freebsd*) + SRC_OS="darwin" + AC_DEFINE(SIGAR_TEST_OS_DARWIN, [1], [for the tests]) + SIGAR_LIBS="-lkvm" + ;; + *hpux*) + AC_DEFINE(SIGAR_HPUX,[],[running on HPUX]) + SRC_OS="hpux" + AC_DEFINE(SIGAR_TEST_OS_HPUX, [1], [for the tests]) + SIGAR_LIBS="-lnm -lnsl" + ;; + *linux*) + SRC_OS="linux" + AC_DEFINE(SIGAR_TEST_OS_LINUX, [1], [for the tests]) ;; *solaris*) + AC_DEFINE(SOLARIS,[],[running on Solaris]) SRC_OS="solaris" - LIBS="-lkstat -lsocket" + AC_DEFINE(SIGAR_TEST_OS_SOLARIS, [1], [for the tests]) + SIGAR_LIBS="-lkstat -lsocket" ;; *) ac_system="unknown" esac -AC_MSG_RESULT([$ac_system]) AC_MSG_RESULT([$SRC_OS]) -INCLUDES="-I\$(top_builddir)/include -I\$(srcdir)/os/$SRC_OS" +AC_CHECK_HEADERS(libproc.h valgrind/valgrind.h) +if test $ac_cv_header_libproc_h = yes; then + AC_DEFINE(DARWIN_HAS_LIBPROC_H, [1], [sigar named them DARWIN_HAS_... instead of HAVE_]) +fi + +INCLUDES="-I\$(top_srcdir)/include -I\$(top_srcdir)/src/os/$SRC_OS $SIGAR_INCLUDES" AC_SUBST(SRC_OS) AC_SUBST(INCLUDES) -AC_SUBST(LIBS) +AC_SUBST(SIGAR_LIBS) + +AM_CONDITIONAL(OS_WIN32, test x$SRC_OS = xwin32) +AM_CONDITIONAL(OS_MACOSX, test x$SRC_OS = xdarwin) +AM_CONDITIONAL(OS_LINUX, test x$SRC_OS = xlinux) +AM_CONDITIONAL(OS_HPUX, test x$SRC_OS = xhpux) +AM_CONDITIONAL(OS_AIX, test x$SRC_OS = xaix) +AM_CONDITIONAL(OS_SOLARIS, test x$SRC_OS = xsolaris) + +AC_ARG_WITH(valgrind, [AC_HELP_STRING( + [--with-valgrind[=binary]], + [run the tests in valgrind to check for mem-leaks] + )], + [], + [with_valgrind=no]) +AS_IF([test "x$with_valgrind" != xno], + [AS_IF([test "x$with_valgrind" = xyes], + [AC_CHECK_PROG(VALGRIND, valgrind) + AS_IF([test "x$VALGRIND" = x], + [AC_MSG_ERROR("--with-valgrind ... but no valgrind found")]) + ], + [VALGRIND="$with_valgrind" + AC_SUBST(VALGRIND)]) + ]) +AM_CONDITIONAL(USE_VALGRIND, test "x$VALGRIND" != x) AC_CONFIG_FILES([ Makefile +include/Makefile src/Makefile src/os/Makefile src/os/aix/Makefile src/os/darwin/Makefile -src/os/linux/Makefile +src/os/freebsd/Makefile src/os/hpux/Makefile +src/os/linux/Makefile +src/os/netware/Makefile +src/os/osf1/Makefile src/os/solaris/Makefile +src/os/stub/Makefile +src/os/win32/Makefile examples/Makefile +src/sigar_version_autoconf.c +tests/Makefile ]) AC_OUTPUT diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 00000000..1a05c187 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,10 @@ +INSTALL(FILES sigar.h + sigar_fileinfo.h + sigar_format.h + sigar_getline.h + sigar_log.h + sigar_private.h + sigar_ptql.h + sigar_util.h + DESTINATION include/ + ) diff --git a/include/Makefile.am b/include/Makefile.am new file mode 100644 index 00000000..cc93781f --- /dev/null +++ b/include/Makefile.am @@ -0,0 +1,12 @@ +include_HEADERS = \ + sigar.h \ + sigar_fileinfo.h \ + sigar_format.h \ + sigar_getline.h \ + sigar_log.h \ + sigar_private.h \ + sigar_ptql.h \ + sigar_util.h + +EXTRA_DIST=\ + CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..d5303c80 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,92 @@ +## sigar has some base files + a set of platform specific files + +MESSAGE(STATUS "CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}") + +INCLUDE_DIRECTORIES(../include/) + +## linux +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + SET(SIGAR_SRC os/linux/linux_sigar.c) + + INCLUDE_DIRECTORIES(os/linux/) +ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + +## macosx, freebsd +IF(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)") + SET(SIGAR_SRC os/darwin/darwin_sigar.c) + + INCLUDE_DIRECTORIES(os/darwin/) + IF(CMAKE_SYSTEM_NAME MATCHES "(Darwin)") + INCLUDE_DIRECTORIES(/Developer/Headers/FlatCarbon/) + ADD_DEFINITIONS(-DDARWIN) + SET(SIGAR_LINK_FLAGS "-framework CoreServices -framework IOKit") + ELSE(CMAKE_SYSTEM_NAME MATCHES "(Darwin)") + ## freebsd needs libkvm + SET(SIGAR_LINK_FLAGS "-lkvm") + ENDIF(CMAKE_SYSTEM_NAME MATCHES "(Darwin)") +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)") + +## solaris +IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)" ) + SET(SIGAR_SRC + os/solaris/solaris_sigar.c + os/solaris/get_mib2.c + os/solaris/kstats.c + os/solaris/procfs.c + ) + + INCLUDE_DIRECTORIES(os/solaris/) + ADD_DEFINITIONS(-DSOLARIS) + SET(SIGAR_LINK_FLAGS -lkstat -ldl -lnsl -lsocket -lresolv) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)" ) + +## solaris +IF (CMAKE_SYSTEM_NAME MATCHES "(hpux)" ) + SET(SIGAR_SRC + os/hpux/hpux_sigar.c + os/hpux/dlpi.c + ) + + INCLUDE_DIRECTORIES(os/hpux/) + ADD_DEFINITIONS(-DSIGAR_HPUX) + SET(SIGAR_LINK_FLAGS -lnm) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(hpux)" ) + +## aix +IF (CMAKE_SYSTEM_NAME MATCHES "(AIX)" ) + SET(SIGAR_SRC os/aix/aix_sigar.c) + + INCLUDE_DIRECTORIES(os/aix/) + SET(SIGAR_LINK_FLAGS -lodm -lcfg) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(AIX)" ) + +IF(WIN32) + ADD_DEFINITIONS(-DSIGAR_SHARED) + SET(SIGAR_SRC os/win32/peb.c os/win32/win32_sigar.c) + INCLUDE_DIRECTORIES(os/win32) +ENDIF(WIN32) + +SET(SIGAR_SRC ${SIGAR_SRC} + sigar.c + sigar_cache.c + sigar_fileinfo.c + sigar_format.c + sigar_getline.c + sigar_ptql.c + sigar_signal.c + sigar_util.c +) + +ADD_LIBRARY(sigar SHARED ${SIGAR_SRC}) +IF(WIN32) + TARGET_LINK_LIBRARIES(sigar ws2_32 netapi32 version) +ENDIF(WIN32) +IF(SIGAR_LINK_FLAGS) + SET_TARGET_PROPERTIES(sigar PROPERTIES LINK_FLAGS "${SIGAR_LINK_FLAGS}") +ENDIF(SIGAR_LINK_FLAGS) + +INSTALL(TARGETS sigar + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + ) diff --git a/src/Makefile.am b/src/Makefile.am index fda8b9d2..b3443789 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,26 +2,15 @@ SUBDIRS = os INCLUDES = @INCLUDES@ -include_HEADERS = \ - $(top_builddir)/include/sigar.h \ - $(top_builddir)/include/sigar_log.h \ - $(top_builddir)/include/sigar_format.h \ - $(top_builddir)/include/sigar_fileinfo.h \ - $(top_builddir)/include/sigar_ptql.h - lib_LTLIBRARIES = libsigar.la -libsigar_la_LDFLAGS = +libsigar_la_LDFLAGS = $(SIGAR_LIBS) libsigar_la_LIBADD = $(top_builddir)/src/os/@SRC_OS@/libsigar_os.la -libsigar_la_CFLAGS = +libsigar_la_CFLAGS = -I$(top_srcdir)/include libsigar_la_SOURCES = \ - $(include_HEADERS) \ - $(top_builddir)/include/sigar_private.h \ - $(top_builddir)/include/sigar_util.h \ - $(top_builddir)/include/sigar_getline.h \ sigar.c \ sigar_cache.c \ sigar_fileinfo.c \ @@ -29,5 +18,10 @@ libsigar_la_SOURCES = \ sigar_getline.c \ sigar_ptql.c \ sigar_signal.c \ - sigar_util.c + sigar_util.c \ + sigar_version_autoconf.c + +EXTRA_DIST=\ + sigar_version.c.in \ + CMakeLists.txt diff --git a/src/os/Makefile.am b/src/os/Makefile.am index ded6dcbf..53363f29 100644 --- a/src/os/Makefile.am +++ b/src/os/Makefile.am @@ -1 +1,11 @@ -SUBDIRS = @SRC_OS@ +SUBDIRS = \ + aix \ + darwin \ + freebsd \ + hpux \ + linux \ + netware \ + osf1 \ + solaris \ + stub \ + win32 diff --git a/src/os/aix/Makefile.am b/src/os/aix/Makefile.am index cad5b699..54f498d9 100644 --- a/src/os/aix/Makefile.am +++ b/src/os/aix/Makefile.am @@ -1,7 +1,18 @@ INCLUDES = @INCLUDES@ +SIGAR_OS_SRCS = aix_sigar.c + +SIGAR_OS_HDRS = sigar_os.h + +if OS_AIX noinst_LTLIBRARIES = libsigar_os.la -libsigar_os_la_SOURCES = aix_sigar.c +libsigar_os_la_SOURCES = ${SIGAR_OS_SRCS} + +noinst_HEADERS = ${SIGAR_OS_HDRS} +else +EXTRA_DIST=\ + ${SIGAR_OS_SRCS} \ + ${SIGAR_OS_HDRS} +endif -noinst_HEADERS = sigar_os.h diff --git a/src/os/darwin/Makefile.am b/src/os/darwin/Makefile.am index 0d27888e..b946948e 100644 --- a/src/os/darwin/Makefile.am +++ b/src/os/darwin/Makefile.am @@ -1,7 +1,18 @@ INCLUDES = @INCLUDES@ +SIGAR_OS_SRCS=\ + darwin_sigar.c +SIGAR_OS_HDRS=\ + sigar_os.h + +if OS_MACOSX noinst_LTLIBRARIES = libsigar_os.la -libsigar_os_la_SOURCES = darwin_sigar.c +libsigar_os_la_SOURCES = ${SIGAR_OS_SRCS} -noinst_HEADERS = sigar_os.h +noinst_HEADERS = ${SIGAR_OS_HDRS} +else +EXTRA_DIST=\ + ${SIGAR_OS_SRCS} \ + ${SIGAR_OS_HDRS} +endif diff --git a/src/os/freebsd/Makefile.am b/src/os/freebsd/Makefile.am new file mode 100644 index 00000000..a346cf6c --- /dev/null +++ b/src/os/freebsd/Makefile.am @@ -0,0 +1,2 @@ +EXTRA_DIST=\ + README diff --git a/src/os/hpux/Makefile.am b/src/os/hpux/Makefile.am index a4502c28..123d4eef 100644 --- a/src/os/hpux/Makefile.am +++ b/src/os/hpux/Makefile.am @@ -1,7 +1,17 @@ INCLUDES = @INCLUDES@ +SIGAR_OS_SRCS = hpux_sigar.c dlpi.c + +SIGAR_OS_HDRS = sigar_os.h + +if OS_HPUX noinst_LTLIBRARIES = libsigar_os.la -libsigar_os_la_SOURCES = hpux_sigar.c dlpi.c +libsigar_os_la_SOURCES = ${SIGAR_OS_SRCS} -noinst_HEADERS = sigar_os.h +noinst_HEADERS = ${SIGAR_OS_HDRS} +else +EXTRA_DIST=\ + ${SIGAR_OS_SRCS} \ + ${SIGAR_OS_HDRS} +endif diff --git a/src/os/linux/Makefile.am b/src/os/linux/Makefile.am index abac4b62..15ade3ea 100644 --- a/src/os/linux/Makefile.am +++ b/src/os/linux/Makefile.am @@ -1,7 +1,18 @@ INCLUDES = @INCLUDES@ +SIGAR_OS_SRCS = linux_sigar.c + +SIGAR_OS_HDRS = sigar_os.h + +if OS_LINUX noinst_LTLIBRARIES = libsigar_os.la -libsigar_os_la_SOURCES = linux_sigar.c +libsigar_os_la_SOURCES = ${SIGAR_OS_SRCS} + +noinst_HEADERS = ${SIGAR_OS_HDRS} +else +EXTRA_DIST=\ + ${SIGAR_OS_SRCS} \ + ${SIGAR_OS_HDRS} +endif -noinst_HEADERS = sigar_os.h diff --git a/src/os/netware/Makefile.am b/src/os/netware/Makefile.am new file mode 100644 index 00000000..83ed1c4c --- /dev/null +++ b/src/os/netware/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST=\ + Makefile.nw \ + netware_sigar.c \ + sigar.def.in \ + sigar_os.h diff --git a/src/os/osf1/Makefile.am b/src/os/osf1/Makefile.am new file mode 100644 index 00000000..2f3133c9 --- /dev/null +++ b/src/os/osf1/Makefile.am @@ -0,0 +1,3 @@ +EXTRA_DIST=\ + osf1_sigar.c \ + sigar_os.h diff --git a/src/os/solaris/Makefile.am b/src/os/solaris/Makefile.am index 885ee1b2..8107af1e 100644 --- a/src/os/solaris/Makefile.am +++ b/src/os/solaris/Makefile.am @@ -1,7 +1,18 @@ INCLUDES = @INCLUDES@ +SIGAR_OS_SRCS = solaris_sigar.c get_mib2.c kstats.c procfs.c + +SIGAR_OS_HDRS = sigar_os.h get_mib2.h hmekstat.h + +if OS_SOLARIS noinst_LTLIBRARIES = libsigar_os.la -libsigar_os_la_SOURCES = solaris_sigar.c get_mib2.c kstats.c procfs.c +libsigar_os_la_SOURCES = ${SIGAR_OS_SRCS} + +noinst_HEADERS = ${SIGAR_OS_HDRS} +else +EXTRA_DIST=\ + ${SIGAR_OS_SRCS} \ + ${SIGAR_OS_HDRS} +endif -noinst_HEADERS = sigar_os.h diff --git a/src/os/stub/Makefile.am b/src/os/stub/Makefile.am new file mode 100644 index 00000000..3526f1a6 --- /dev/null +++ b/src/os/stub/Makefile.am @@ -0,0 +1,3 @@ +EXTRA_DIST=\ + sigar_os.h \ + stub_sigar.c diff --git a/src/os/win32/Makefile.am b/src/os/win32/Makefile.am new file mode 100644 index 00000000..fc0d0e1a --- /dev/null +++ b/src/os/win32/Makefile.am @@ -0,0 +1,8 @@ +EXTRA_DIST=\ + build-cpu.bat \ + counter_names.txt \ + peb.c \ + sigar.rc.in \ + sigar_os.h \ + sigar_pdh.h \ + win32_sigar.c diff --git a/src/sigar_version_autoconf.c.in b/src/sigar_version_autoconf.c.in new file mode 100644 index 00000000..3b1f36f6 --- /dev/null +++ b/src/sigar_version_autoconf.c.in @@ -0,0 +1,22 @@ +#include "sigar.h" + +static sigar_version_t sigar_version = { + __DATE__, + "@SCM_REVISION@", + "@PACKAGE_STRING@", + "@build@", + "@build_os@", + "@build_cpu@", + "SIGAR-@PACKAGE_VERSION@, " + "SCM revision @SCM_REVISION@, " + "built "__DATE__" as @build_cpu@", + @VERSION_MAJOR@, + @VERSION_MINOR@, + @VERSION_MAINT@, + @VERSION_BUILD@ +}; + +SIGAR_DECLARE(sigar_version_t *) sigar_version_get(void) +{ + return &sigar_version; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..7f0e2047 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,52 @@ +MACRO(SIGAR_TEST name) + ADD_EXECUTABLE(${name} ${name}.c) + TARGET_LINK_LIBRARIES(${name} sigar) + ADD_TEST(${name} ${name}) +ENDMACRO(SIGAR_TEST name) + +INCLUDE_DIRECTORIES(../include/) + +MESSAGE(STATUS "CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}") + +## linux +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + ADD_DEFINITIONS(-DSIGAR_TEST_OS_LINUX) +ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + +## macosx, freebsd +IF(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)") + ADD_DEFINITIONS(-DSIGAR_TEST_OS_DARWIN) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)") + +## solaris +IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)" ) + ADD_DEFINITIONS(-DSIGAR_TEST_OS_SOLARIS) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)" ) + +## solaris +IF (CMAKE_SYSTEM_NAME MATCHES "(hpux)" ) + ADD_DEFINITIONS(-DSIGAR_TEST_OS_HPUX) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(hpux)" ) + +## aix +IF (CMAKE_SYSTEM_NAME MATCHES "(AIX)" ) + ADD_DEFINITIONS(-DSIGAR_TEST_OS_AIX) +ENDIF(CMAKE_SYSTEM_NAME MATCHES "(AIX)" ) + +IF(WIN32) + ADD_DEFINITIONS(-DSIGAR_TEST_OS_WIN32) +ENDIF(WIN32) + +SIGAR_TEST(t_sigar_cpu) +SIGAR_TEST(t_sigar_fs) +SIGAR_TEST(t_sigar_loadavg) +SIGAR_TEST(t_sigar_mem) +SIGAR_TEST(t_sigar_netconn) +SIGAR_TEST(t_sigar_netif) +SIGAR_TEST(t_sigar_pid) +SIGAR_TEST(t_sigar_proc) +SIGAR_TEST(t_sigar_reslimit) +SIGAR_TEST(t_sigar_swap) +SIGAR_TEST(t_sigar_sysinfo) +SIGAR_TEST(t_sigar_uptime) +# SIGAR_TEST(t_sigar_version) diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 00000000..cbc707fd --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,69 @@ +TESTS = \ + t_sigar_cpu \ + t_sigar_proc \ + t_sigar_swap \ + t_sigar_mem \ + t_sigar_sysinfo \ + t_sigar_version \ + t_sigar_loadavg \ + t_sigar_uptime \ + t_sigar_reslimit \ + t_sigar_fs \ + t_sigar_netif \ + t_sigar_netconn \ + t_sigar_pid + +if USE_VALGRIND +TESTS_ENVIRONMENT = \ + VALGRIND=${VALGRIND} \ + ${srcdir}/valgrind-leak-check +endif + +check_PROGRAMS = \ + $(TESTS) + +t_sigar_mem_SOURCES = t_sigar_mem.c +t_sigar_mem_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_pid_SOURCES = t_sigar_pid.c +t_sigar_pid_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_swap_SOURCES = t_sigar_swap.c +t_sigar_swap_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_cpu_SOURCES = t_sigar_cpu.c +t_sigar_cpu_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_proc_SOURCES = t_sigar_proc.c +t_sigar_proc_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_sysinfo_SOURCES = t_sigar_sysinfo.c +t_sigar_sysinfo_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_uptime_SOURCES = t_sigar_uptime.c +t_sigar_uptime_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_loadavg_SOURCES = t_sigar_loadavg.c +t_sigar_loadavg_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_version_SOURCES = t_sigar_version.c +t_sigar_version_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_fs_SOURCES = t_sigar_fs.c +t_sigar_fs_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_reslimit_SOURCES = t_sigar_reslimit.c +t_sigar_reslimit_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_netif_SOURCES = t_sigar_netif.c +t_sigar_netif_LDADD = $(top_builddir)/src/libsigar.la + +t_sigar_netconn_SOURCES = t_sigar_netconn.c +t_sigar_netconn_LDADD = $(top_builddir)/src/libsigar.la + +noinst_HEADERS=\ + sigar_tests.h + +EXTRA_DIST=\ + valgrind-leak-check \ + CMakeLists.txt diff --git a/tests/sigar_tests.h b/tests/sigar_tests.h new file mode 100644 index 00000000..c0d4c856 --- /dev/null +++ b/tests/sigar_tests.h @@ -0,0 +1,50 @@ +#ifndef __SIGAR_TESTS_H__ +#define __SIGAR_TESTS_H__ + +#ifdef WIN32 +#define EOL "\r\n" +#else +#define EOL "\n" +#endif + +/** + * pick the right format for a unsigned 64bit int */ +#ifdef WIN32 +# define F_U64 "%I64u" +# define F_SIZE_T "%lu" +#else +# ifdef SIGAR_64BIT +# define F_U64 "%lu" +# define F_SIZE_T "%lu" +# else +# define F_U64 "%llu" +# define F_SIZE_T "%lu" +# endif +#endif + +#ifndef RLIM_INFINITY +# define RLIM_INFINITY -1 +#endif + +#define IS_IMPL_U64(x) \ + (x != (sigar_uint64_t)SIGAR_FIELD_NOTIMPL) +#define IS_IMPL_INT(x) \ + (x != (int)SIGAR_FIELD_NOTIMPL) +#define IS_RLIM_INF(x) \ + (x == (sigar_uint64_t)RLIM_INFINITY) + +#define F_IF_VALID_U64 \ + "%s" F_U64 + +#define TEST(name) \ + static int name(sigar_t *t) + +#define NETADDR_IF_IMPL(x, value) \ + if (x.family != SIGAR_AF_UNSPEC) { \ + value = calloc(1, SIGAR_INET6_ADDRSTRLEN + 1); \ + assert(SIGAR_OK == sigar_net_address_to_string(t, &x, value));\ + } + + + +#endif diff --git a/tests/t_sigar_cpu.c b/tests/t_sigar_cpu.c new file mode 100644 index 00000000..4e3317e3 --- /dev/null +++ b/tests/t_sigar_cpu.c @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_cpu_get) { + sigar_cpu_t cpu; + int ret; + + if (SIGAR_OK == (ret = sigar_cpu_get(t, &cpu))) { + assert(IS_IMPL_U64(cpu.user)); + assert(IS_IMPL_U64(cpu.sys)); +#if !(defined(SIGAR_TEST_OS_AIX)) + assert(IS_IMPL_U64(cpu.nice)); +#endif + assert(IS_IMPL_U64(cpu.idle)); + assert(IS_IMPL_U64(cpu.wait)); + assert(IS_IMPL_U64(cpu.total)); + } else { + switch (ret) { + /* track the expected error code */ + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + + return 0; +} + +TEST(test_sigar_cpu_list_get) { + sigar_cpu_list_t cpulist; + size_t i; + int ret; + + if (SIGAR_OK != (ret = sigar_cpu_list_get(t, &cpulist))) { + switch (ret) { + /* track the expected error code */ + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + + for (i = 0; i < cpulist.number; i++) { + sigar_cpu_t cpu = cpulist.data[i]; + + assert(IS_IMPL_U64(cpu.user)); + assert(IS_IMPL_U64(cpu.user)); + assert(IS_IMPL_U64(cpu.sys)); +#if !(defined(SIGAR_TEST_OS_AIX)) + assert(IS_IMPL_U64(cpu.nice)); +#endif + assert(IS_IMPL_U64(cpu.idle)); + assert(IS_IMPL_U64(cpu.wait)); + assert(IS_IMPL_U64(cpu.total)); + } + + sigar_cpu_list_destroy(t, &cpulist); + + return 0; +} + +TEST(test_sigar_cpu_info_get) { + sigar_cpu_info_list_t cpuinfo; + size_t i; + + assert(SIGAR_OK == sigar_cpu_info_list_get(t, &cpuinfo)); + + for (i = 0; i < cpuinfo.number; i++) { + sigar_cpu_info_t info = cpuinfo.data[i]; + + assert(info.vendor); + assert(info.model); +#if !(defined(SIGAR_TEST_OS_DARWIN)) + /* freebsd doesn't always expose it */ + assert(IS_IMPL_INT(info.mhz)); +#endif +#if !(defined(SIGAR_TEST_OS_DARWIN) || defined(SIGAR_TEST_OS_SOLARIS) || defined(SIGAR_TEST_OS_HPUX) || defined(_WIN32)) + /* freebsd, solaris, hpux nor win32 do expose it */ + assert(IS_IMPL_U64(info.cache_size)); +#endif + } + + sigar_cpu_info_list_destroy(t, &cpuinfo); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_cpu_get(t); + test_sigar_cpu_list_get(t); + test_sigar_cpu_info_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_fs.c b/tests/t_sigar_fs.c new file mode 100644 index 00000000..f298a086 --- /dev/null +++ b/tests/t_sigar_fs.c @@ -0,0 +1,163 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include +#if defined(_WIN32) +#include +#endif + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + + +TEST(test_sigar_file_system_list_get) { + sigar_file_system_list_t fslist; + size_t i; + + assert(SIGAR_OK == sigar_file_system_list_get(t, &fslist)); + assert(fslist.number > 0); + + for (i = 0; i < fslist.number; i++) { + sigar_file_system_t fs = fslist.data[i]; + sigar_file_system_usage_t fsusage; + sigar_disk_usage_t diskusage; + int ret; + + assert(fs.dir_name); + assert(fs.dev_name); + assert(fs.type_name); + assert(fs.sys_type_name); + assert(fs.type); + + if (SIGAR_OK != (ret = sigar_file_system_ping(t, &fs))) { + continue; + } + + if (SIGAR_OK == (ret = sigar_file_system_usage_get(t, fs.dir_name, &fsusage))) { + assert(IS_IMPL_U64(fsusage.total)); + assert(IS_IMPL_U64(fsusage.free)); + assert(IS_IMPL_U64(fsusage.used)); + assert(IS_IMPL_U64(fsusage.avail)); +#if !(defined(SIGAR_TEST_OS_SOLARIS) || defined(_WIN32)) + /* solaris 8 */ + assert(IS_IMPL_U64(fsusage.files)); +#endif + assert(fsusage.use_percent >= 0); + } else { + switch (ret) { + /* track the expected error code */ +#if defined(_WIN32) + case ERROR_NOT_READY: + break; +#endif + default: + fprintf(stderr, "sigar_file_system_usage_get(%s) ret = %d (%s)\n", + fs.dir_name, + ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + + if (SIGAR_OK == (ret = sigar_disk_usage_get(t, fs.dev_name, &diskusage))) { + assert(IS_IMPL_U64(diskusage.reads)); + assert(IS_IMPL_U64(diskusage.writes)); +#if !defined(SIGAR_TEST_OS_DARWIN) + /* freebsd */ + assert(IS_IMPL_U64(diskusage.read_bytes)); + assert(IS_IMPL_U64(diskusage.write_bytes)); + assert(IS_IMPL_U64(diskusage.rtime)); + assert(IS_IMPL_U64(diskusage.wtime)); +#endif +#if !(defined(SIGAR_TEST_OS_LINUX) || defined(SIGAR_TEST_OS_DARWIN) || defined(_WIN32)) + /* depending on the Linux version they might not be set */ + assert(IS_IMPL_U64(diskusage.qtime)); +#endif +#if !(defined(SIGAR_TEST_OS_LINUX) || defined(SIGAR_TEST_OS_DARWIN)) + assert(IS_IMPL_U64(diskusage.time)); +#endif +#if !defined(SIGAR_TEST_OS_DARWIN) + assert(IS_IMPL_U64(diskusage.snaptime)); +#endif +#if 0 + /* is -1 if undefined */ + assert(diskusage.service_time >= 0); + assert(diskusage.queue >= 0); +#endif + } else { + switch (ret) { + case ESRCH: /* macosx */ + case ENXIO: /* solaris */ + case ENOENT: /* aix */ + case SIGAR_ENOTIMPL: /* hpux */ + /* track the expected error code */ + fprintf(stderr, "sigar_disk_usage_get(%s) ret = %d (%s)\n", + fs.dev_name, + ret, sigar_strerror(t, ret)); + break; + default: + fprintf(stderr, "sigar_disk_usage_get(%s) ret = %d (%s)\n", + fs.dev_name, + ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + } + + sigar_file_system_list_destroy(t, &fslist); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_file_system_list_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_loadavg.c b/tests/t_sigar_loadavg.c new file mode 100644 index 00000000..c786a448 --- /dev/null +++ b/tests/t_sigar_loadavg.c @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_loadavg_get) { + sigar_loadavg_t loadavg; + int ret; + + if (SIGAR_OK == (ret = sigar_loadavg_get(t, &loadavg))) { + assert(loadavg.loadavg[0] >= 0); + assert(loadavg.loadavg[1] >= 0); + assert(loadavg.loadavg[2] >= 0); + } else { + switch (ret) { + /* track the expected error code */ + default: +#if !(defined(_WIN32)) + /* win32 has no loadavg */ + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); +#endif + break; + } + } + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_loadavg_get(t); + + sigar_close(t); + + return 0; +} diff --git a/tests/t_sigar_mem.c b/tests/t_sigar_mem.c new file mode 100644 index 00000000..1743a73a --- /dev/null +++ b/tests/t_sigar_mem.c @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + + +TEST(test_sigar_mem_get) { + sigar_mem_t mem; + int status; + + assert(SIGAR_OK == (status = sigar_mem_get(t, &mem))); + + assert(mem.ram > 0); + assert(mem.total > 0); + assert(mem.used > 0); + assert(mem.free > 0); + assert(mem.actual_free > 0); + assert(mem.actual_used > 0); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_mem_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_netconn.c b/tests/t_sigar_netconn.c new file mode 100644 index 00000000..784d49bd --- /dev/null +++ b/tests/t_sigar_netconn.c @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_net_connections_get) { + sigar_net_connection_list_t connlist; + size_t i; + int ret; + + if (SIGAR_OK == (ret = sigar_net_connection_list_get(t, &connlist, + SIGAR_NETCONN_SERVER | SIGAR_NETCONN_CLIENT | + SIGAR_NETCONN_TCP | SIGAR_NETCONN_UDP))) { + assert(connlist.number > 0); + + for (i = 0; i < connlist.number; i++) { + sigar_net_connection_t con = connlist.data[i]; + + assert(con.local_port < 65536); + assert(con.local_port < 65536); + assert(con.uid >= 0); + assert(con.inode >= 0); + assert(con.type >= 0); + assert(con.state >= 0); + assert(con.send_queue >= 0); + assert(con.receive_queue >= 0); + } + + assert(SIGAR_OK == sigar_net_connection_list_destroy(t, &connlist)); + } else { + switch (ret) { + case 40013: /* AIX: SIGAR_EPERM_KMEM */ + /* track the expected error code */ + break; + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_net_connections_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_netif.c b/tests/t_sigar_netif.c new file mode 100644 index 00000000..abf8d57d --- /dev/null +++ b/tests/t_sigar_netif.c @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_net_iflist_get) { + sigar_net_interface_list_t net_iflist; + size_t i; + int ret; + + assert(SIGAR_OK == sigar_net_interface_list_get(t, &net_iflist)); + assert(net_iflist.number > 0); + + for (i = 0; i < net_iflist.number; i++) { + char *ifname = net_iflist.data[i]; + sigar_net_interface_stat_t ifstat; + sigar_net_interface_config_t config; + + if (SIGAR_OK == (ret = sigar_net_interface_stat_get(t, ifname, &ifstat))) { +#if defined(SIGAR_TEST_OS_SOLARIS) + /* on solaris "lo" has no real stats, skip it */ + if (0 == strncmp(ifname, "lo", 2)) continue; +#endif + assert(IS_IMPL_U64(ifstat.rx_packets)); + assert(IS_IMPL_U64(ifstat.rx_bytes)); + assert(IS_IMPL_U64(ifstat.rx_errors)); +#if !(defined(SIGAR_TEST_OS_AIX)) + assert(IS_IMPL_U64(ifstat.rx_dropped)); +#endif +#if !(defined(SIGAR_TEST_OS_DARWIN) || defined(SIGAR_TEST_OS_AIX) || defined(SIGAR_TEST_OS_HPUX) || defined(_WIN32)) + assert(IS_IMPL_U64(ifstat.rx_overruns)); + assert(IS_IMPL_U64(ifstat.rx_frame)); +#endif + assert(IS_IMPL_U64(ifstat.tx_packets)); + assert(IS_IMPL_U64(ifstat.tx_bytes)); + assert(IS_IMPL_U64(ifstat.tx_errors)); +#if !(defined(SIGAR_TEST_OS_HPUX) || defined(_WIN32)) + assert(IS_IMPL_U64(ifstat.tx_collisions)); +#endif +#if !(defined(SIGAR_TEST_OS_DARWIN) || defined(SIGAR_TEST_OS_AIX)) + assert(IS_IMPL_U64(ifstat.tx_dropped)); +#endif +#if !(defined(SIGAR_TEST_OS_DARWIN) || defined(SIGAR_TEST_OS_AIX) || defined(SIGAR_TEST_OS_HPUX) || defined(_WIN32)) + assert(IS_IMPL_U64(ifstat.tx_overruns)); + assert(IS_IMPL_U64(ifstat.tx_carrier)); +#endif +#ifndef SIGAR_TEST_OS_LINUX + assert(IS_IMPL_U64(ifstat.speed)); +#endif + } else { + switch (ret) { + /* track the expected error code */ + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + + if (SIGAR_OK == (ret = sigar_net_interface_config_get(t, ifname, &config))) { + assert(config.name); + assert(config.type); + assert(config.description); + assert(IS_IMPL_U64(config.flags)); + assert(IS_IMPL_U64(config.mtu)); + assert(IS_IMPL_U64(config.metric)); + } else { + switch (ret) { + /* track the expected error code */ + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + } + + assert(SIGAR_OK == sigar_net_interface_list_destroy(t, &net_iflist)); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_net_iflist_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_pid.c b/tests/t_sigar_pid.c new file mode 100644 index 00000000..9b51772e --- /dev/null +++ b/tests/t_sigar_pid.c @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_pid_get) { + sigar_pid_t pid; + + pid = sigar_pid_get(t); + assert(pid > 0); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_pid_get(t); + + sigar_close(t); + + return 0; +} diff --git a/tests/t_sigar_proc.c b/tests/t_sigar_proc.c new file mode 100644 index 00000000..88a9ac73 --- /dev/null +++ b/tests/t_sigar_proc.c @@ -0,0 +1,199 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include +#if defined(_WIN32) +#include +#endif + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +#ifdef HAVE_VALGRIND_VALGRIND_H +#include +#else +#define RUNNING_ON_VALGRIND 0 +#endif + +TEST(test_sigar_proc_stat_get) { + sigar_proc_stat_t proc_stat; + + assert(SIGAR_OK == sigar_proc_stat_get(t, &proc_stat)); + assert(proc_stat.total > 0); + + return 0; +} + +TEST(test_sigar_proc_list_get) { + sigar_proc_list_t proclist; + size_t i; + + assert(SIGAR_OK == sigar_proc_list_get(t, &proclist)); + assert(proclist.number > 0); + + for (i = 0; i < proclist.number; i++) { + sigar_pid_t pid = proclist.data[i]; + sigar_proc_mem_t proc_mem; + sigar_proc_time_t proc_time; + sigar_proc_state_t proc_state; + int ret; + + if (SIGAR_OK == (ret = sigar_proc_mem_get(t, pid, &proc_mem))) { + assert(IS_IMPL_U64(proc_mem.size)); + assert(IS_IMPL_U64(proc_mem.resident)); +#if !(defined(SIGAR_TEST_OS_DARWIN) || defined(SIGAR_TEST_OS_SOLARIS) || defined(_WIN32)) + /* MacOS X, solaris nor win32 do provide them */ + assert(IS_IMPL_U64(proc_mem.share)); + assert(IS_IMPL_U64(proc_mem.minor_faults)); + assert(IS_IMPL_U64(proc_mem.major_faults)); +#endif +#if !(defined(SIGAR_TEST_OS_DARWIN)) + /* freebsd */ + assert(IS_IMPL_U64(proc_mem.page_faults)); +#endif + } else { + switch (ret) { + case ESRCH: + case EPERM: + /* track the expected error code */ + break; +#if (defined(SIGAR_TEST_OS_DARWIN)) + /* valgrind on macosx doesn't handle this syscall yet */ + case ENOSYS: + if (RUNNING_ON_VALGRIND) { + break; + } +#endif + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + + if (SIGAR_OK == (ret = sigar_proc_time_get(t, pid, &proc_time))) { + assert(IS_IMPL_U64(proc_time.start_time)); + assert(IS_IMPL_U64(proc_time.user)); + assert(IS_IMPL_U64(proc_time.sys)); + assert(IS_IMPL_U64(proc_time.total)); + +#if !(defined(SIGAR_TEST_OS_DARWIN)) + /* Freebsd */ + assert(proc_time.start_time > 0); +#endif + assert(proc_time.user >= 0); + assert(proc_time.sys >= 0); + assert(proc_time.total == proc_time.user + proc_time.sys); + } else { + switch (ret) { + case EPERM: + case ESRCH: +#if (defined(_WIN32)) + /* OpenProcess() may return ERROR_ACCESS_DENIED */ + case ERROR_ACCESS_DENIED: +#endif + /* track the expected error code */ + break; +#if (defined(SIGAR_TEST_OS_DARWIN)) + /* valgrind on macosx doesn't handle this syscall yet */ + case ENOSYS: + if (RUNNING_ON_VALGRIND) { + break; + } +#endif + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + if (SIGAR_OK == sigar_proc_state_get(t, pid, &proc_state)) { + assert(proc_state.name != NULL); +#if 0 + /* all values are fine */ + (proc_state.state); /* we should check if the state is one of the announced group */ + (proc_state.ppid); + (proc_state.tty); + (proc_state.priority); + (proc_state.nice); + (proc_state.processor); +#endif +#if !(defined(SIGAR_TEST_OS_DARWIN) || defined(SIGAR_TEST_OS_LINUX)) + /* MacOS X doesn't provide them, Linux-IA64 neither */ + assert(IS_IMPL_U64(proc_state.threads)); +#endif + } else { + switch (ret) { + /* track the expected error code */ +#if (defined(SIGAR_TEST_OS_DARWIN)) + /* valgrind on macosx doesn't handle this syscall yet */ + case ENOSYS: + if (RUNNING_ON_VALGRIND) { + break; + } +#endif + default: + fprintf(stderr, "ret = %d (%s)\n", ret, sigar_strerror(t, ret)); + assert(ret == SIGAR_OK); + break; + } + } + } + + sigar_proc_list_destroy(t, &proclist); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_proc_stat_get(t); + test_sigar_proc_list_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_reslimit.c b/tests/t_sigar_reslimit.c new file mode 100644 index 00000000..cef537ec --- /dev/null +++ b/tests/t_sigar_reslimit.c @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_resource_limit_get) { + sigar_resource_limit_t rlimit; + + assert(SIGAR_OK == sigar_resource_limit_get(t, &rlimit)); + /* we can't check if the limits are reasonable */ + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_resource_limit_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_swap.c b/tests/t_sigar_swap.c new file mode 100644 index 00000000..b5e8f56c --- /dev/null +++ b/tests/t_sigar_swap.c @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_swap_get) { + sigar_swap_t swap; + + assert(SIGAR_OK == sigar_swap_get(t, &swap)); + assert(swap.total == swap.used + swap.free); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_swap_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_sysinfo.c b/tests/t_sigar_sysinfo.c new file mode 100644 index 00000000..1b4f5067 --- /dev/null +++ b/tests/t_sigar_sysinfo.c @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_sys_info_get) { + sigar_sys_info_t sysinfo; + + assert(SIGAR_OK == sigar_sys_info_get(t, &sysinfo)); + assert(sysinfo.name); + assert(sysinfo.version); + assert(sysinfo.arch); + assert(sysinfo.machine); + assert(sysinfo.description); + assert(sysinfo.patch_level); + assert(sysinfo.vendor); + assert(sysinfo.vendor_version); + assert(sysinfo.vendor_name); + assert(sysinfo.vendor_code_name); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_sys_info_get(t); + + sigar_close(t); + + return err ? -1 : 0; +} diff --git a/tests/t_sigar_uptime.c b/tests/t_sigar_uptime.c new file mode 100644 index 00000000..5dd35607 --- /dev/null +++ b/tests/t_sigar_uptime.c @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_uptime_get) { + sigar_uptime_t uptime; + + assert(SIGAR_OK == sigar_uptime_get(t, &uptime)); + assert(uptime.uptime > 0); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_uptime_get(t); + + sigar_close(t); + + return 0; +} diff --git a/tests/t_sigar_version.c b/tests/t_sigar_version.c new file mode 100644 index 00000000..2b867f72 --- /dev/null +++ b/tests/t_sigar_version.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2009, Sun Microsystems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Sun Microsystems Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "sigar.h" +#include "sigar_private.h" +#include "sigar_format.h" +#include "sigar_tests.h" + +TEST(test_sigar_version_get) { + sigar_version_t *version; + + version = sigar_version_get(); + assert(version->major >= 0); + assert(version->minor >= 0); + assert(version->maint >= 0); + assert(version->build >= 0); + + return 0; +} + +int main() { + sigar_t *t; + int err = 0; + + assert(SIGAR_OK == sigar_open(&t)); + + test_sigar_version_get(t); + + sigar_close(t); + + return 0; +} diff --git a/tests/valgrind-leak-check b/tests/valgrind-leak-check new file mode 100644 index 00000000..24b707b1 --- /dev/null +++ b/tests/valgrind-leak-check @@ -0,0 +1,25 @@ +#!/bin/sh + +if test x$VALGRIND = x; then + echo "\$VALGRIND isn't set, can't check for mem-leaks" + exit 1 +fi + +tempfoo=`basename $0` +TEMPFILE=`mktemp -t ${tempfoo}` || exit 1 +function rm_tmpfile () { + cat $TEMPFILE + rm -f $TEMPFILE +} +trap rm_tmpfile ERR + +set -e +DYLD_LIBRARY_PATH=../src/.libs/ \ +$VALGRIND --auto-run-dsymutil=yes --log-file=$TEMPFILE .libs/$1 + +# make the test fail, if this line isn't found +grep "ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)" $TEMPFILE > /dev/null +grep "definitely lost: 0 bytes in 0 blocks." $TEMPFILE > /dev/null + +rm -f $TEMPFILE + diff --git a/winbuild.bat b/winbuild.bat new file mode 100644 index 00000000..c3fd7b74 --- /dev/null +++ b/winbuild.bat @@ -0,0 +1,53 @@ +@rem $%BEGINLICENSE%$ +@rem $%ENDLICENSE%$ +@echo "Run this from a shell started with the Visual Studio Build environment set!" + +@IF DEFINED GENERATOR (GOTO GENERAL_CONF) +@rem Sane default is VS2005, but maybe not what we really want... +@SET GENERATOR="Visual Studio 8 2005" +@GOTO GENERAL_CONF + +:GENERAL_CONF + +@echo Using %GENERATOR% + +@rem MSVC 8 2005 doesn't seem to have devenv.com +@SET VS_CMD="%VS90COMNTOOLS%\..\IDE\VCExpress.exe" + +@rem clear the cache if neccesary to let cmake recheck everything +@rem del CMakeCache.txt + +:CMAKE +@rem make sure that /D NDEBUG isn't set as it disables all the assert()ions in the testcase +cmake -G %GENERATOR% -DBUILD_NUMBER=%BUILD_NUMBER% -DCMAKE_INSTALL_PREFIX=%INST_PREFIX% -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING="/MD /Zi /O2 /Ob1" . + +@IF NOT %GENERATOR%=="NMake Makefiles" (GOTO VS08BUILD) +nmake +IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +cp build-src/sigar.dll build-tests/ +nmake test +IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +nmake install +IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% + +@GOTO CLEANUP + +:VS08BUILD +%VS_CMD% mysql-proxy.sln /Clean +%VS_CMD% mysql-proxy.sln /Build Release +%VS_CMD% mysql-proxy.sln /Build Release /project RUN_TESTS +%VS_CMD% mysql-proxy.sln /Build Release /project PACKAGE +%VS_CMD% mysql-proxy.sln /Build Release /project INSTALL + +@GOTO CLEANUP + +@rem if you use VS8 to build then VS80COMNTOOLS should be set +@rem "%VS80COMNTOOLS%\..\IDE\devenv.com" mysql-proxy.sln /Clean +@rem "%VS80COMNTOOLS%\..\IDE\devenv.com" mysql-proxy.sln /Build +@rem "%VS80COMNTOOLS%\..\IDE\devenv.com" mysql-proxy.sln /Build Debug /project RUN_TESTS +@rem "%VS80COMNTOOLS%\..\IDE\devenv.com" mysql-proxy.sln /Build Debug /project PACKAGE +@rem "%VS80COMNTOOLS%\..\IDE\devenv.com" mysql-proxy.sln /Build Debug /project INSTALL + +:CLEANUP + +:END