added unit-tests
unit-tests for the majority of sigar functions including valgrind-leak-check
This commit is contained in:
parent
c007175b21
commit
f88489dc73
|
@ -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)
|
|
@ -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
|
|
@ -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
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <WinError.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <WinError.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "sigar.h"
|
||||||
|
#include "sigar_private.h"
|
||||||
|
#include "sigar_format.h"
|
||||||
|
#include "sigar_tests.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_VALGRIND_VALGRIND_H
|
||||||
|
#include <valgrind/valgrind.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue