]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: improve u64 use in ipcs test
authorKarel Zak <kzak@redhat.com>
Tue, 19 Jan 2021 15:25:33 +0000 (16:25 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 19 Jan 2021 15:25:33 +0000 (16:25 +0100)
UINT64_MAX is 18446744073709551615, but 2^64 is 18446744073709551616.
We also need to use kbytes in all calculation in the test than bytes
as ipcs by default do not use bytes anymore.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/helpers/test_sysinfo.c
tests/ts/ipcs/functions.sh

index ce7bc081a51d0b3e68aece05b62936a7b1495269..e13931d04b1b2ead228a4a32a6e3fe649e33076c 100644 (file)
@@ -19,6 +19,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <limits.h>
+#include <stdint.h>
+#include <inttypes.h>
 
 typedef struct {
        const char      *name;
@@ -72,6 +74,12 @@ static int hlp_ulong_max(void)
        return 0;
 }
 
+static int hlp_u64_max(void)
+{
+       printf("%" PRIu64 "\n", UINT64_MAX);
+       return 0;
+}
+
 static int hlp_ulong_max32(void)
 {
 #if __WORDSIZE == 64
@@ -91,6 +99,7 @@ static mntHlpfnc hlps[] =
        { "LONG_MAX",   hlp_long_max    },
        { "ULONG_MAX",  hlp_ulong_max   },
        { "ULONG_MAX32",hlp_ulong_max32 },
+       { "UINT64_MAX", hlp_u64_max     },
        { "byte-order", hlp_endianness  },
        { NULL, NULL }
 };
index b23e123d9c45fd089d5c01ee92bc5aa3962be7e3..e9b437ee4d1de397c0de02203a89a25276f5ef9d 100644 (file)
@@ -63,6 +63,8 @@ IPCS_LIMITS=(
 # list of indexes = 0..(sizeof Array - 1)
 IPCS_IDX=$(seq 0 $(( ${#IPCS_PROCFILES[*]} - 1 )))
 
+UINT64_MAX=$($TS_HELPER_SYSINFO UINT64_MAX)
+
 # checker
 function ipcs_limits_check {
        for i in $IPCS_IDX; do
@@ -72,16 +74,17 @@ function ipcs_limits_check {
                a=$(eval ${IPCS_KERNEL_CMD[$i]})
                b=$(eval ${IPCS_CMD[$i]})
 
+               # follow the way how ipcs handles u64 overflow
+               max_kbytes=$(bc <<< "$UINT64_MAX - ($UINT64_MAX % ($PAGE_SIZE / 1024))")
+
                #echo
-               #echo "KERNEL-CMD: ${IPCS_KERNEL_CMD[$i]}"
-               #echo "KERNEL-RAW: $(cat ${IPCS_PROCFILES[$i]})"
-               #echo "IPCS-CMD:   ${IPCS_CMD[$i]}"
+               #echo "kernel kbytes: $a"
+               #echo "lsipc kbytes:  $b"
+               #echo "max kbytes:    $max_kbytes"
                #echo
 
-               # overflow is handled differently because we don't have large
-               # int math, see https://github.com/karelzak/util-linux/issues/51
-               if [ $(bc <<<"$a >= 2^64/1024") -eq 1 ]; then
-                       a=$(bc <<<"(2^64 - $PAGE_SIZE)/1024")
+               if [ $(bc <<<"$a > $max_kbytes") -eq 1 ]; then
+                       a=$max_kbytes
                fi
 
                if [ x"$a" == x"$b" ]; then