From: Bruno Haible Date: Sun, 13 Aug 2023 22:49:25 +0000 (+0200) Subject: physmem: Add tests. X-Git-Tag: v1.0~910 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=edd9de933cd491685296d0bb87375670ae8a1302;p=gnulib.git physmem: Add tests. * tests/test-physmem.c: New file. * modules/physmem-tests: New file. --- diff --git a/ChangeLog b/ChangeLog index 35e95693d8..05d4466c77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-08-13 Bruno Haible + + physmem: Add tests. + * tests/test-physmem.c: New file. + * modules/physmem-tests: New file. + 2023-08-13 Bruno Haible 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 index 0000000000..c37c41cd7e --- /dev/null +++ b/modules/physmem-tests @@ -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 index 0000000000..232cc86d12 --- /dev/null +++ b/tests/test-physmem.c @@ -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 . */ + +/* Written by Bruno Haible , 2023. */ + +#include + +#include "physmem.h" + +#include + +#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; +}