This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=b8fe840fd697cebee6c42ddb14ace8b0969b8520

commit b8fe840fd697cebee6c42ddb14ace8b0969b8520
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Nov 19 03:12:18 2022 +0100

    test: Add unit tests for meminfo module
---
 lib/dpkg/Makefile.am                               |  9 +++
 lib/dpkg/t/.gitignore                              |  1 +
 .../empty => lib/dpkg/t/data/meminfo-no-data       |  0
 lib/dpkg/t/data/meminfo-no-info                    | 52 +++++++++++++
 lib/dpkg/t/data/meminfo-no-unit                    | 53 +++++++++++++
 lib/dpkg/t/data/meminfo-ok                         | 53 +++++++++++++
 lib/dpkg/t/t-meminfo.c                             | 88 ++++++++++++++++++++++
 7 files changed, 256 insertions(+)

diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index e28cd4562..d001878f8 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -20,6 +20,7 @@ LDADD = \
 
 EXTRA_DIST = \
        $(test_scripts) \
+       $(test_data) \
        libdpkg.map \
        libdpkg.pc.in \
        # EOL
@@ -196,6 +197,7 @@ test_programs = \
        t/t-string \
        t/t-file \
        t/t-buffer \
+       t/t-meminfo \
        t/t-path \
        t/t-progname \
        t/t-subproc \
@@ -225,6 +227,13 @@ test_scripts = \
        t/t-trigdeferred.t \
        # EOL
 
+test_data = \
+       t/data/meminfo-no-data \
+       t/data/meminfo-no-info \
+       t/data/meminfo-no-unit \
+       t/data/meminfo-ok \
+       # EOL
+
 BENCHMARK_LDADD_FLAGS = \
        -lrt \
        $(LDADD) \
diff --git a/lib/dpkg/t/.gitignore b/lib/dpkg/t/.gitignore
index c2fc4a9d0..9f3082e9b 100644
--- a/lib/dpkg/t/.gitignore
+++ b/lib/dpkg/t/.gitignore
@@ -19,6 +19,7 @@ t-fsys-dir
 t-fsys-hash
 t-headers-cpp
 t-macros
+t-meminfo
 t-mod-db
 t-namevalue
 t-pager
diff --git a/scripts/t/Dpkg_Checksums/empty b/lib/dpkg/t/data/meminfo-no-data
similarity index 100%
copy from scripts/t/Dpkg_Checksums/empty
copy to lib/dpkg/t/data/meminfo-no-data
diff --git a/lib/dpkg/t/data/meminfo-no-info b/lib/dpkg/t/data/meminfo-no-info
new file mode 100644
index 000000000..009c91bbc
--- /dev/null
+++ b/lib/dpkg/t/data/meminfo-no-info
@@ -0,0 +1,52 @@
+MemTotal:        3951508 kB
+MemFree:          130976 kB
+Buffers:            2448 kB
+Cached:          3694676 kB
+SwapCached:        12936 kB
+Active:          3111920 kB
+Inactive:         610376 kB
+Active(anon):    3102668 kB
+Inactive(anon):   606952 kB
+Active(file):       9252 kB
+Inactive(file):     3424 kB
+Unevictable:           0 kB
+Mlocked:               0 kB
+SwapTotal:       4194300 kB
+SwapFree:        3777400 kB
+Zswap:                 0 kB
+Zswapped:              0 kB
+Dirty:                 0 kB
+Writeback:             0 kB
+AnonPages:         12960 kB
+Mapped:             6700 kB
+Shmem:           3684416 kB
+KReclaimable:      27616 kB
+Slab:              54652 kB
+SReclaimable:      27616 kB
+SUnreclaim:        27036 kB
+KernelStack:        2496 kB
+PageTables:         1516 kB
+NFS_Unstable:          0 kB
+Bounce:                0 kB
+WritebackTmp:          0 kB
+CommitLimit:     6170052 kB
+Committed_AS:    4212940 kB
+VmallocTotal:   34359738367 kB
+VmallocUsed:       16116 kB
+VmallocChunk:          0 kB
+Percpu:             2288 kB
+HardwareCorrupted:     0 kB
+AnonHugePages:         0 kB
+ShmemHugePages:        0 kB
+ShmemPmdMapped:        0 kB
+FileHugePages:         0 kB
+FilePmdMapped:         0 kB
+HugePages_Total:       0
+HugePages_Free:        0
+HugePages_Rsvd:        0
+HugePages_Surp:        0
+Hugepagesize:       2048 kB
+Hugetlb:               0 kB
+DirectMap4k:      110452 kB
+DirectMap2M:     5132288 kB
+DirectMap1G:     5242880 kB
diff --git a/lib/dpkg/t/data/meminfo-no-unit b/lib/dpkg/t/data/meminfo-no-unit
new file mode 100644
index 000000000..4db2d9ca0
--- /dev/null
+++ b/lib/dpkg/t/data/meminfo-no-unit
@@ -0,0 +1,53 @@
+MemTotal:        3951508
+MemFree:          130976
+MemAvailable:      10584
+Buffers:            2448
+Cached:          3694676
+SwapCached:        12936
+Active:          3111920
+Inactive:         610376
+Active(anon):    3102668
+Inactive(anon):   606952
+Active(file):       9252
+Inactive(file):     3424
+Unevictable:           0
+Mlocked:               0
+SwapTotal:       4194300
+SwapFree:        3777400
+Zswap:                 0
+Zswapped:              0
+Dirty:                 0
+Writeback:             0
+AnonPages:         12960
+Mapped:             6700
+Shmem:           3684416
+KReclaimable:      27616
+Slab:              54652
+SReclaimable:      27616
+SUnreclaim:        27036
+KernelStack:        2496
+PageTables:         1516
+NFS_Unstable:          0
+Bounce:                0
+WritebackTmp:          0
+CommitLimit:     6170052
+Committed_AS:    4212940
+VmallocTotal:   34359738367
+VmallocUsed:       16116
+VmallocChunk:          0
+Percpu:             2288
+HardwareCorrupted:     0
+AnonHugePages:         0
+ShmemHugePages:        0
+ShmemPmdMapped:        0
+FileHugePages:         0
+FilePmdMapped:         0
+HugePages_Total:       0
+HugePages_Free:        0
+HugePages_Rsvd:        0
+HugePages_Surp:        0
+Hugepagesize:       2048
+Hugetlb:               0
+DirectMap4k:      110452
+DirectMap2M:     5132288
+DirectMap1G:     5242880
diff --git a/lib/dpkg/t/data/meminfo-ok b/lib/dpkg/t/data/meminfo-ok
new file mode 100644
index 000000000..d4fdf0b33
--- /dev/null
+++ b/lib/dpkg/t/data/meminfo-ok
@@ -0,0 +1,53 @@
+MemTotal:        3951508 kB
+MemFree:          130976 kB
+MemAvailable:      10584 kB
+Buffers:            2448 kB
+Cached:          3694676 kB
+SwapCached:        12936 kB
+Active:          3111920 kB
+Inactive:         610376 kB
+Active(anon):    3102668 kB
+Inactive(anon):   606952 kB
+Active(file):       9252 kB
+Inactive(file):     3424 kB
+Unevictable:           0 kB
+Mlocked:               0 kB
+SwapTotal:       4194300 kB
+SwapFree:        3777400 kB
+Zswap:                 0 kB
+Zswapped:              0 kB
+Dirty:                 0 kB
+Writeback:             0 kB
+AnonPages:         12960 kB
+Mapped:             6700 kB
+Shmem:           3684416 kB
+KReclaimable:      27616 kB
+Slab:              54652 kB
+SReclaimable:      27616 kB
+SUnreclaim:        27036 kB
+KernelStack:        2496 kB
+PageTables:         1516 kB
+NFS_Unstable:          0 kB
+Bounce:                0 kB
+WritebackTmp:          0 kB
+CommitLimit:     6170052 kB
+Committed_AS:    4212940 kB
+VmallocTotal:   34359738367 kB
+VmallocUsed:       16116 kB
+VmallocChunk:          0 kB
+Percpu:             2288 kB
+HardwareCorrupted:     0 kB
+AnonHugePages:         0 kB
+ShmemHugePages:        0 kB
+ShmemPmdMapped:        0 kB
+FileHugePages:         0 kB
+FilePmdMapped:         0 kB
+HugePages_Total:       0
+HugePages_Free:        0
+HugePages_Rsvd:        0
+HugePages_Surp:        0
+Hugepagesize:       2048 kB
+Hugetlb:               0 kB
+DirectMap4k:      110452 kB
+DirectMap2M:     5132288 kB
+DirectMap1G:     5242880 kB
diff --git a/lib/dpkg/t/t-meminfo.c b/lib/dpkg/t/t-meminfo.c
new file mode 100644
index 000000000..fd158f7a0
--- /dev/null
+++ b/lib/dpkg/t/t-meminfo.c
@@ -0,0 +1,88 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * t-meminfo.c - test memory information handling code
+ *
+ * Copyright © 2022 Guillem Jover <[email protected]>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <dpkg/test.h>
+#include <dpkg/meminfo.h>
+
+static char *
+test_data_file(const char *filename)
+{
+       char *pathname;
+       int rc;
+
+       rc = asprintf(&pathname, "%s/t/data/%s", test_get_srcdir(), filename);
+       if (rc < 0)
+               test_bail("cannot allocate data filename");
+
+       return pathname;
+}
+
+static void
+test_meminfo(void)
+{
+       char *pathname;
+       uint64_t mem;
+       int rc;
+
+       mem = 0;
+       pathname = test_data_file("meminfo-no-file");
+       rc = meminfo_get_available_from_file(pathname, &mem);
+       test_pass(rc == MEMINFO_NO_FILE);
+       test_pass(mem == 0);
+       free(pathname);
+
+       mem = 0;
+       pathname = test_data_file("meminfo-no-data");
+       rc = meminfo_get_available_from_file(pathname, &mem);
+       test_pass(rc == MEMINFO_NO_DATA);
+       test_pass(mem == 0);
+       free(pathname);
+
+       mem = 0;
+       pathname = test_data_file("meminfo-no-unit");
+       rc = meminfo_get_available_from_file(pathname, &mem);
+       test_pass(rc == MEMINFO_NO_UNIT);
+       test_pass(mem == 0);
+       free(pathname);
+
+       mem = 0;
+       pathname = test_data_file("meminfo-no-info");
+       rc = meminfo_get_available_from_file(pathname, &mem);
+       test_pass(rc == MEMINFO_NO_INFO);
+       test_pass(mem == 0);
+       free(pathname);
+
+       mem = 0;
+       pathname = test_data_file("meminfo-ok");
+       rc = meminfo_get_available_from_file(pathname, &mem);
+       test_pass(rc == MEMINFO_OK);
+       test_pass(mem == 10838016UL);
+       free(pathname);
+}
+
+TEST_ENTRY(test)
+{
+       test_plan(10);
+
+       test_meminfo();
+}

-- 
Dpkg.Org's dpkg

Reply via email to