]> Savannah Git Hosting - gnulib.git/commitdiff
physmem: Add tests.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Aug 2023 22:49:25 +0000 (00:49 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Aug 2023 22:49:25 +0000 (00:49 +0200)
* tests/test-physmem.c: New file.
* modules/physmem-tests: New file.

ChangeLog
modules/physmem-tests [new file with mode: 0644]
tests/test-physmem.c [new file with mode: 0644]

index 35e95693d8c06d2e884837eadca000209fa318ae..05d4466c776ff8ec759df3977d7505f75a3780da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-08-13  Bruno Haible  <bruno@clisp.org>
+
+       physmem: Add tests.
+       * tests/test-physmem.c: New file.
+       * modules/physmem-tests: New file.
+
 2023-08-13  Bruno Haible  <bruno@clisp.org>
 
        readutmp, boot-time: Fix warning on glibc 2.30..2.31 on Linux.
diff --git a/modules/physmem-tests b/modules/physmem-tests
new file mode 100644 (file)
index 0000000..c37c41c
--- /dev/null
@@ -0,0 +1,11 @@
+Files:
+tests/test-physmem.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-physmem
+check_PROGRAMS += test-physmem
diff --git a/tests/test-physmem.c b/tests/test-physmem.c
new file mode 100644 (file)
index 0000000..232cc86
--- /dev/null
@@ -0,0 +1,38 @@
+/* Test of getting the amount of total/available physical memory.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file 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 3 of the License,
+   or (at your option) any later version.
+
+   This file 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/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2023.  */
+
+#include <config.h>
+
+#include "physmem.h"
+
+#include <stdio.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  printf ("Total memory:     %12.f B = %6.f MiB\n",
+          physmem_total (), physmem_total () / (1024.0 * 1024.0));
+  printf ("Available memory: %12.f B = %6.f MiB\n",
+          physmem_available (), physmem_available () / (1024.0 * 1024.0));
+  ASSERT (physmem_total () >= physmem_available ());
+  ASSERT (physmem_available () >= 4 * 1024 * 1024);
+
+  return 0;
+}