From 6fcbbaafc4bae79d4e674a2cf7f1d87d5a471603 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:28:35 +0100 Subject: Implement first unit test for check_swap --- plugins/tests/test_check_swap.c | 21 +++++++++++++++++++++ plugins/tests/test_check_swap.t | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 plugins/tests/test_check_swap.c create mode 100644 plugins/tests/test_check_swap.t (limited to 'plugins/tests') diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c new file mode 100644 index 00000000..42ac0086 --- /dev/null +++ b/plugins/tests/test_check_swap.c @@ -0,0 +1,21 @@ + +#include "../check_swap.d/check_swap.h" +#include "../../tap/tap.h" + +void print_usage() {}; +void print_help(swap_config config) { + (void) config; +}; + +const char *progname = "test_check_swap"; + +int main() { + + swap_config config = swap_config_init(); + + swap_result test_data = get_swap_data(config); + + plan_tests(1); + + ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data"); +} diff --git a/plugins/tests/test_check_swap.t b/plugins/tests/test_check_swap.t new file mode 100644 index 00000000..97c651a8 --- /dev/null +++ b/plugins/tests/test_check_swap.t @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use Test::More; +if (! -e "./test_check_swap") { + plan skip_all => "./test_swap not compiled - please enable libtap library to test"; +} +exec "./test_check_swap"; -- cgit v1.2.3-74-g34f1 From 08c3f0f7379eabe51cd965d0dc35626d8939ae27 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:06:11 +0100 Subject: Add test proc/meminfo file and corresponding test --- plugins/tests/test_check_swap.c | 7 ++++-- plugins/tests/var/proc_meminfo | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 plugins/tests/var/proc_meminfo (limited to 'plugins/tests') diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c index 42ac0086..86ab188f 100644 --- a/plugins/tests/test_check_swap.c +++ b/plugins/tests/test_check_swap.c @@ -13,9 +13,12 @@ int main() { swap_config config = swap_config_init(); - swap_result test_data = get_swap_data(config); + swap_result test_data = getSwapFromProcMeminfo(config, "./var/proc_meminfo"); - plan_tests(1); + plan_tests(4); ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data"); + ok(test_data.metrics.total == 34233905152, "Is the total Swap correct"); + ok(test_data.metrics.free == 34231021568, "Is the free Swap correct"); + ok(test_data.metrics.used == 0, "Is the used Swap correct"); } diff --git a/plugins/tests/var/proc_meminfo b/plugins/tests/var/proc_meminfo new file mode 100644 index 00000000..8c94c4e5 --- /dev/null +++ b/plugins/tests/var/proc_meminfo @@ -0,0 +1,55 @@ +MemTotal: 32767776 kB +MemFree: 1693508 kB +MemAvailable: 23807480 kB +Buffers: 438456 kB +Cached: 19124976 kB +SwapCached: 136 kB +Active: 7860680 kB +Inactive: 18886776 kB +Active(anon): 6108756 kB +Inactive(anon): 1364500 kB +Active(file): 1751924 kB +Inactive(file): 17522276 kB +Unevictable: 8548 kB +Mlocked: 8548 kB +SwapTotal: 33431548 kB +SwapFree: 33428732 kB +Zswap: 0 kB +Zswapped: 0 kB +Dirty: 784 kB +Writeback: 0 kB +AnonPages: 7139968 kB +Mapped: 1094916 kB +Shmem: 284160 kB +KReclaimable: 3303788 kB +Slab: 3801908 kB +SReclaimable: 3303788 kB +SUnreclaim: 498120 kB +KernelStack: 32992 kB +PageTables: 68160 kB +SecPageTables: 0 kB +NFS_Unstable: 0 kB +Bounce: 0 kB +WritebackTmp: 0 kB +CommitLimit: 49815436 kB +Committed_AS: 16888536 kB +VmallocTotal: 34359738367 kB +VmallocUsed: 91200 kB +VmallocChunk: 0 kB +Percpu: 41472 kB +HardwareCorrupted: 0 kB +AnonHugePages: 1708032 kB +ShmemHugePages: 0 kB +ShmemPmdMapped: 0 kB +FileHugePages: 0 kB +FilePmdMapped: 0 kB +Unaccepted: 0 kB +HugePages_Total: 0 +HugePages_Free: 0 +HugePages_Rsvd: 0 +HugePages_Surp: 0 +Hugepagesize: 2048 kB +Hugetlb: 0 kB +DirectMap4k: 860468 kB +DirectMap2M: 20023296 kB +DirectMap1G: 12582912 kB -- cgit v1.2.3-74-g34f1 From 735b04eff721a28e791714c0da4c8ac5726bfbcf Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:37:26 +0100 Subject: Fix tests --- plugins/tests/test_check_swap.c | 3 +-- plugins/tests/test_check_swap.t | 2 +- plugins/tests/var/proc_meminfo | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) mode change 100644 => 100755 plugins/tests/test_check_swap.t (limited to 'plugins/tests') diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c index 86ab188f..319cadbf 100644 --- a/plugins/tests/test_check_swap.c +++ b/plugins/tests/test_check_swap.c @@ -10,7 +10,6 @@ void print_help(swap_config config) { const char *progname = "test_check_swap"; int main() { - swap_config config = swap_config_init(); swap_result test_data = getSwapFromProcMeminfo(config, "./var/proc_meminfo"); @@ -19,6 +18,6 @@ int main() { ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data"); ok(test_data.metrics.total == 34233905152, "Is the total Swap correct"); - ok(test_data.metrics.free == 34231021568, "Is the free Swap correct"); + ok(test_data.metrics.free == 34233905152, "Is the free Swap correct"); ok(test_data.metrics.used == 0, "Is the used Swap correct"); } diff --git a/plugins/tests/test_check_swap.t b/plugins/tests/test_check_swap.t old mode 100644 new mode 100755 index 97c651a8..826fae01 --- a/plugins/tests/test_check_swap.t +++ b/plugins/tests/test_check_swap.t @@ -1,6 +1,6 @@ #!/usr/bin/perl use Test::More; if (! -e "./test_check_swap") { - plan skip_all => "./test_swap not compiled - please enable libtap library to test"; + plan skip_all => "./test_check_swap not compiled - please enable libtap library to test"; } exec "./test_check_swap"; diff --git a/plugins/tests/var/proc_meminfo b/plugins/tests/var/proc_meminfo index 8c94c4e5..6c5a618d 100644 --- a/plugins/tests/var/proc_meminfo +++ b/plugins/tests/var/proc_meminfo @@ -3,7 +3,7 @@ MemFree: 1693508 kB MemAvailable: 23807480 kB Buffers: 438456 kB Cached: 19124976 kB -SwapCached: 136 kB +SwapCached: 0 kB Active: 7860680 kB Inactive: 18886776 kB Active(anon): 6108756 kB @@ -13,7 +13,7 @@ Inactive(file): 17522276 kB Unevictable: 8548 kB Mlocked: 8548 kB SwapTotal: 33431548 kB -SwapFree: 33428732 kB +SwapFree: 33431548 kB Zswap: 0 kB Zswapped: 0 kB Dirty: 784 kB -- cgit v1.2.3-74-g34f1 From 801d0faf457799e9772b5b97e821968f522778be Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 10 Nov 2024 01:28:52 +0100 Subject: test_check_swap: improvements and updates to unit test code --- plugins/tests/test_check_swap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c index 319cadbf..d657c13a 100644 --- a/plugins/tests/test_check_swap.c +++ b/plugins/tests/test_check_swap.c @@ -2,17 +2,15 @@ #include "../check_swap.d/check_swap.h" #include "../../tap/tap.h" -void print_usage() {}; +void print_usage(void) {} void print_help(swap_config config) { (void) config; -}; +} const char *progname = "test_check_swap"; -int main() { - swap_config config = swap_config_init(); - - swap_result test_data = getSwapFromProcMeminfo(config, "./var/proc_meminfo"); +int main(void) { + swap_result test_data = getSwapFromProcMeminfo("./var/proc_meminfo"); plan_tests(4); -- cgit v1.2.3-74-g34f1 From ecbd9e9cb3bb4a1c497a19a29950583202ae4303 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 10 Nov 2024 01:30:40 +0100 Subject: test_check_swap: declare verbose in tests for now --- plugins/tests/test_check_swap.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins/tests') diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c index d657c13a..b85fb4ad 100644 --- a/plugins/tests/test_check_swap.c +++ b/plugins/tests/test_check_swap.c @@ -2,6 +2,8 @@ #include "../check_swap.d/check_swap.h" #include "../../tap/tap.h" +int verbose = 0; + void print_usage(void) {} void print_help(swap_config config) { (void) config; -- cgit v1.2.3-74-g34f1