summaryrefslogtreecommitdiffstats
path: root/library/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 20:34:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 20:34:44 +0000
commite3be059d4da38aa36f1aee1d56f8ceb943d92f1c (patch)
tree26edef31e4e503dd1c92a112de174f366dd61802 /library/tests
parentInitial commit. (diff)
downloadprocps-upstream/2%4.0.4.tar.xz
procps-upstream/2%4.0.4.zip
Adding upstream version 2:4.0.4.upstream/2%4.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/tests')
-rw-r--r--library/tests/test_Itemtables.c91
-rw-r--r--library/tests/test_namespace.c76
-rw-r--r--library/tests/test_pids.c75
-rw-r--r--library/tests/test_sysinfo.c64
-rw-r--r--library/tests/test_uptime.c97
-rw-r--r--library/tests/test_version.c72
6 files changed, 475 insertions, 0 deletions
diff --git a/library/tests/test_Itemtables.c b/library/tests/test_Itemtables.c
new file mode 100644
index 0000000..4204700
--- /dev/null
+++ b/library/tests/test_Itemtables.c
@@ -0,0 +1,91 @@
+/*
+ * libprocps - Library to read proc filesystem
+ * Tests for Item_table/enumerator synchronization
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+
+#include "diskstats.h"
+#include "meminfo.h"
+#include "pids.h"
+#include "slabinfo.h"
+#include "stat.h"
+#include "vmstat.h"
+
+#include "tests.h"
+
+static int check_diskstats (void *data) {
+ struct diskstats_info *ctx = NULL;
+ testname = "Itemtable check, diskstats";
+ if (0 == procps_diskstats_new(&ctx))
+ procps_diskstats_unref(&ctx);
+ return 1;
+}
+
+static int check_meminfo (void *data) {
+ struct meminfo_info *ctx = NULL;
+ testname = "Itemtable check, meminfo";
+ if (0 == procps_meminfo_new(&ctx))
+ procps_meminfo_unref(&ctx);
+ return 1;
+}
+
+static int check_pids (void *data) {
+ struct pids_info *ctx = NULL;
+ testname = "Itemtable check, pids";
+ if (0 == procps_pids_new(&ctx, NULL, 0))
+ procps_pids_unref(&ctx);
+ return 1;
+}
+
+static int check_slabinfo (void *data) {
+ struct slabinfo_info *ctx = NULL;
+ testname = "Itemtable check, slabinfo";
+ if (0 == procps_slabinfo_new(&ctx))
+ procps_slabinfo_unref(&ctx);
+ return 1;
+}
+
+static int check_stat (void *data) {
+ struct stat_info *ctx = NULL;
+ testname = "Itemtable check, stat";
+ if (0 == procps_stat_new(&ctx))
+ procps_stat_unref(&ctx);
+ return 1;
+}
+
+static int check_vmstat (void *data) {
+ struct vmstat_info *ctx = NULL;
+ testname = "Itemtable check, vmstat";
+ if (0 == procps_vmstat_new(&ctx))
+ procps_vmstat_unref(&ctx);
+ return 1;
+}
+
+static TestFunction test_funcs[] = {
+ check_diskstats,
+ check_meminfo,
+ check_pids,
+ check_slabinfo,
+ check_stat,
+ check_vmstat,
+ NULL
+};
+
+int main (void) {
+ return run_tests(test_funcs, NULL);
+}
diff --git a/library/tests/test_namespace.c b/library/tests/test_namespace.c
new file mode 100644
index 0000000..2c55c4f
--- /dev/null
+++ b/library/tests/test_namespace.c
@@ -0,0 +1,76 @@
+/*
+ * libprocps - Library to read proc filesystem
+ * Tests for namespace library calls
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "misc.h"
+#include "tests.h"
+
+int check_name_minus(void *data)
+{
+ testname = "procps_ns_get_name() negative id";
+ return (procps_ns_get_name(-1) == NULL);
+}
+
+int check_name_over(void *data)
+{
+ testname = "procps_ns_get_name() id over limit";
+ return (procps_ns_get_name(999) == NULL);
+}
+
+int check_name_ipc(void *data)
+{
+ testname = "procps_ns_get_name() ipc";
+ return (strcmp(procps_ns_get_name(PROCPS_NS_IPC),"ipc")==0);
+}
+
+int check_id_null(void *data)
+{
+ testname = "procps_ns_get_id(NULL)";
+ return (procps_ns_get_id(NULL) < 0);
+}
+
+int check_id_unfound(void *data)
+{
+ testname = "procps_ns_get_id(unknown)";
+ return (procps_ns_get_id("foobar") < 0);
+}
+
+int check_id_mnt(void *data)
+{
+ testname = "procps_ns_get_id(mnt)";
+ return (procps_ns_get_id("mnt") == PROCPS_NS_MNT);
+}
+
+TestFunction test_funcs[] = {
+ check_name_minus,
+ check_name_over,
+ check_name_ipc,
+ check_id_null,
+ check_id_unfound,
+ check_id_mnt,
+ NULL
+};
+
+int main(int argc, char *argv[])
+{
+ return run_tests(test_funcs, NULL);
+}
+
diff --git a/library/tests/test_pids.c b/library/tests/test_pids.c
new file mode 100644
index 0000000..eda0b73
--- /dev/null
+++ b/library/tests/test_pids.c
@@ -0,0 +1,75 @@
+/*
+ * libprocps - Library to read proc filesystem
+ * Tests for pids library calls
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "pids.h"
+#include "tests.h"
+
+enum pids_item items[] = { PIDS_ID_PID, PIDS_ID_PID };
+enum pids_item items2[] = { PIDS_ID_PID, PIDS_VM_RSS };
+
+int check_pids_new_nullinfo(void *data)
+{
+ testname = "procps_pids_new() info=NULL returns -EINVAL";
+ return (procps_pids_new(NULL, items, 0) == -EINVAL);
+}
+
+int check_pids_new_toomany(void *data)
+{
+ struct pids_info *info;
+ testname = "procps_pids_new() too many items returns -EINVAL";
+ return (procps_pids_new(&info, items, 1) == -EINVAL);
+}
+
+int check_pids_new_and_unref(void *data)
+{
+ struct pids_info *info = NULL;
+ testname = "procps_pids new then unref";
+ return ( (procps_pids_new(&info, items, 2) == 0) &&
+ (procps_pids_unref(&info) == 0) &&
+ info == NULL);
+}
+
+int check_fatal_proc_unmounted(void *data)
+{
+ struct pids_info *info = NULL;
+ struct pids_stack *stack;
+ testname = "check_fatal_proc_unmounted";
+
+ return ( (procps_pids_new(&info, items2, 2) == 0) &&
+ ( (stack = fatal_proc_unmounted(info, 1)) != NULL) &&
+ ( PIDS_VAL(0, s_int, stack, info) > 0) &&
+ ( PIDS_VAL(1, ul_int, stack, info) > 0));
+}
+
+TestFunction test_funcs[] = {
+ check_pids_new_nullinfo,
+ // skipped, ask Jim check_pids_new_toomany,
+ check_pids_new_and_unref,
+ check_fatal_proc_unmounted,
+ NULL };
+
+int main(int argc, char *argv[])
+{
+ return run_tests(test_funcs, NULL);
+}
+
+
diff --git a/library/tests/test_sysinfo.c b/library/tests/test_sysinfo.c
new file mode 100644
index 0000000..8390ccd
--- /dev/null
+++ b/library/tests/test_sysinfo.c
@@ -0,0 +1,64 @@
+/*
+ * libprocps - Library to read proc filesystem
+ * Tests for sysinfo library calls
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "misc.h"
+#include "tests.h"
+
+int check_hertz(void *data)
+{
+ long hz;
+ testname = "procps_hertz_get()";
+
+ hz = procps_hertz_get();
+ return (hz > 0);
+}
+
+int check_loadavg(void *data)
+{
+ double a,b,c;
+ testname = "procps_loadavg()";
+
+ if (procps_loadavg(&a, &b, &c) == 0)
+ return 1;
+ return (a>0 && b>0 && c>0);
+}
+
+int check_loadavg_null(void *data)
+{
+ testname = "procps_loadavg() with NULLs";
+ if (procps_loadavg(NULL, NULL, NULL) == 0)
+ return 1;
+ return 0;
+}
+
+TestFunction test_funcs[] = {
+ check_hertz,
+ check_loadavg,
+ check_loadavg_null,
+ NULL,
+};
+
+int main(int argc, char *argv[])
+{
+ return run_tests(test_funcs, NULL);
+}
+
+
diff --git a/library/tests/test_uptime.c b/library/tests/test_uptime.c
new file mode 100644
index 0000000..35d3e2e
--- /dev/null
+++ b/library/tests/test_uptime.c
@@ -0,0 +1,97 @@
+/*
+ * libprocps - Library to read proc filesystem
+ * Tests for version library calls
+ *
+ * Copyright 2016 Craig Small <csmall@dropbear.xyz>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "misc.h"
+#include "tests.h"
+
+int check_uptime(void *data)
+{
+ testname = "procps_uptime()";
+ double up=0, idle=0;
+ int rc;
+ rc = procps_uptime(&up, &idle);
+ return (rc == 0 && up > 0 && idle > 0);
+}
+
+int check_uptime_nullup(void *data)
+{
+ double idle=0;
+ int rc;
+ testname = "procps_uptime() (up=NULL)";
+ rc = procps_uptime(NULL, &idle);
+ return (rc == 0 && idle > 0);
+}
+
+int check_uptime_nullidle(void *data)
+{
+ double up=0;
+ int rc;
+ testname = "procps_uptime() (idle=NULL)";
+ rc = procps_uptime(&up, NULL);
+ return (rc == 0 && up > 0);
+}
+
+int check_uptime_nullall(void *data)
+{
+ int rc;
+ testname = "procps_uptime() (up,idle=NULL)";
+ rc = procps_uptime(NULL, NULL);
+ return (rc == 0);
+}
+
+int check_uptime_sprint(void *data)
+{
+ char *str;
+ testname = "procps_uptime_sprint()";
+
+ str = procps_uptime_sprint();
+
+ return (str != NULL && str[0] != '\0');
+}
+
+int check_uptime_sprint_short(void *data)
+{
+ char *str;
+ testname = "procps_uptime_sprint_short()";
+
+ str = procps_uptime_sprint_short();
+
+ return (str != NULL && str[0] != '\0');
+}
+
+TestFunction test_funcs[] = {
+ check_uptime,
+ check_uptime_nullup,
+ check_uptime_nullidle,
+ check_uptime_nullall,
+ check_uptime_sprint,
+ check_uptime_sprint_short,
+ NULL,
+};
+
+int main(int argc, char *argv[])
+{
+ return run_tests(test_funcs, NULL);
+}
+
+
diff --git a/library/tests/test_version.c b/library/tests/test_version.c
new file mode 100644
index 0000000..f2f5e1f
--- /dev/null
+++ b/library/tests/test_version.c
@@ -0,0 +1,72 @@
+/*
+ * libprocps - Library to read proc filesystem
+ * Tests for version library calls
+ *
+ * Copyright 2016 Craig Small <csmall@dropbear.xyz>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "misc.h"
+#include "tests.h"
+
+int check_linux_version(void *data)
+{
+ testname = "procps_linux_version()";
+ return (procps_linux_version() > 0);
+}
+
+int check_conversion(void *data)
+{
+ testname = "LINUX_VERSION macro";
+ struct testvals {
+ int retval;
+ int major, minor, patch;
+ };
+
+ struct testvals *tv;
+ struct testvals tvs[] = {
+ { 132096, 2, 4, 0 },
+ { 132635, 2, 6, 27 },
+ { 199936, 3, 13, 0 },
+ { 263426, 4, 5, 2 },
+ { 0, 0, 0, 0}
+ };
+
+ for (tv=tvs; tv->major != 0; tv++)
+ {
+ if (LINUX_VERSION(tv->major, tv->minor, tv->patch) != tv->retval) {
+ fprintf(stderr, "Failed %d != %d\n", LINUX_VERSION(tv->major, tv->minor,
+ tv->patch), tv->retval);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+TestFunction test_funcs[] = {
+ check_conversion,
+ check_linux_version,
+ NULL
+};
+
+int main(int argc, char *argv[])
+{
+ return run_tests(test_funcs, NULL);
+}
+
+