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 <kzak@redhat.com>
This commit is contained in:
parent
8399fe089b
commit
734678205a
|
@ -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 }
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue