From: Karel Zak Date: Tue, 19 Jan 2021 15:25:33 +0000 (+0100) Subject: tests: improve u64 use in ipcs test X-Git-Tag: v2.37-rc1~173 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=734678205af89c2022fd1ad86fddd7c07d188f20;p=thirdparty%2Futil-linux.git tests: improve u64 use in ipcs test 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 --- diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c index ce7bc081a5..e13931d04b 100644 --- a/tests/helpers/test_sysinfo.c +++ b/tests/helpers/test_sysinfo.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include 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 } }; diff --git a/tests/ts/ipcs/functions.sh b/tests/ts/ipcs/functions.sh index b23e123d9c..e9b437ee4d 100644 --- a/tests/ts/ipcs/functions.sh +++ b/tests/ts/ipcs/functions.sh @@ -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