summaryrefslogtreecommitdiffstats
path: root/tests/ts/ipcs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ts/ipcs')
-rw-r--r--tests/ts/ipcs/functions.sh114
-rwxr-xr-xtests/ts/ipcs/headers60
-rwxr-xr-xtests/ts/ipcs/limits54
-rwxr-xr-xtests/ts/ipcs/limits237
-rwxr-xr-xtests/ts/ipcs/mk-rm-msg44
-rwxr-xr-xtests/ts/ipcs/mk-rm-sem44
-rwxr-xr-xtests/ts/ipcs/mk-rm-shm44
7 files changed, 397 insertions, 0 deletions
diff --git a/tests/ts/ipcs/functions.sh b/tests/ts/ipcs/functions.sh
new file mode 100644
index 0000000..e9b437e
--- /dev/null
+++ b/tests/ts/ipcs/functions.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux.
+#
+# 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 2 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.
+#
+
+test -f /proc/sys/kernel/shmall || ts_skip "no /proc"
+
+PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize)
+
+# kernel files
+IPCS_PROCFILES=(
+ /proc/sys/kernel/shmmni
+ /proc/sys/kernel/shmall
+ /proc/sys/kernel/shmmax
+)
+
+# raw data converted to ipcs-like format
+# shmmni = same
+# shmall = from pages to KBytes
+# shmmax = from bytes to KBytes
+#
+IPCS_KERNEL_CMD=(
+ "cat /proc/sys/kernel/shmmni"
+ "echo \$(cat /proc/sys/kernel/shmall) / 1024 \* $PAGE_SIZE | bc -l | sed 's/\..*//'"
+ "echo \$(cat /proc/sys/kernel/shmmax) / 1024 | bc -l | sed 's/\..*//'"
+)
+
+# data from the ipcs command
+IPCS_CMD=(
+ "$TS_CMD_IPCS -m -l | awk '/max number of segments/ { print \$6 }'"
+ "$TS_CMD_IPCS -m -l | awk '/max total shared memory/ { print \$7 }'"
+ "$TS_CMD_IPCS -m -l | awk '/max seg size/ { print \$6 }'"
+)
+
+
+# The linux kernel accepts ULONG_MAX, but this value is same like ULLONG_MAX on
+# 64-bit archs. So the ipcs command has to always overflow on 64-bit archs when
+# shmall (=num of pages!) is same or almost same like ULONG_MAX. This is reason
+# why we for the test uses 32-bit limits on all archs.
+#
+# (Don't worry that 64-bit ULONG_MAX makes ipcs useless ...
+# ... it's a problem for admins who want to use 75557863725TB of RAM for shm)
+#
+IPCS_LIMITS=(
+ 32768
+ $($TS_HELPER_SYSINFO ULONG_MAX32)
+ $($TS_HELPER_SYSINFO ULONG_MAX32)
+)
+
+# 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
+
+ echo -n ${IPCS_PROCFILES[$i]}
+
+ 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 kbytes: $a"
+ #echo "lsipc kbytes: $b"
+ #echo "max kbytes: $max_kbytes"
+ #echo
+
+ if [ $(bc <<<"$a > $max_kbytes") -eq 1 ]; then
+ a=$max_kbytes
+ fi
+
+ if [ x"$a" == x"$b" ]; then
+ echo " OK"
+ else
+ echo " kernel=$a, ipcs=$b"
+ fi
+ done
+}
+
+# Read 'ipcmk' output, such as 'Shared memory id: 22839299' and
+# write the message to two files: (1) something what one can
+# compare as test output, and (2) id which ipcrm later will use
+# for deletion.
+ipcmk_output_handler() {
+ awk -v text=$1 -v num=$2 '
+ function isnum(x) {
+ return(x == x + 0)
+ }
+ {
+ if (isnum($NF)) {
+ print $NF >> num
+ $NF="<was_number>"
+ }
+ print $0 >> text
+ }'
+}
diff --git a/tests/ts/ipcs/headers b/tests/ts/ipcs/headers
new file mode 100755
index 0000000..1ee13a9
--- /dev/null
+++ b/tests/ts/ipcs/headers
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux.
+#
+# 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 2 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.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="headers"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_IPCS"
+
+ts_init_subtest "shm-headers"
+$TS_CMD_IPCS -m -t | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -m -p | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -m -c | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -m -l | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -m -u | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_init_subtest "mesg-headers"
+$TS_CMD_IPCS -q -t | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -q -p | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -q -c | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -q -l | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -q -u | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_init_subtest "sem-headers"
+$TS_CMD_IPCS -s -t | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -s -p | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -s -c | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -s -l | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -s -u | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_init_subtest "all-headers"
+$TS_CMD_IPCS -a | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+$TS_CMD_IPCS -a -t | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -a -p | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -a -c | grep -A1 "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -a -l | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+$TS_CMD_IPCS -a -u | grep "^---" >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_finalize
diff --git a/tests/ts/ipcs/limits b/tests/ts/ipcs/limits
new file mode 100755
index 0000000..671f23c
--- /dev/null
+++ b/tests/ts/ipcs/limits
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux.
+#
+# 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 2 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.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="limits overflow"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_IPCS"
+ts_check_test_command "$TS_HELPER_SYSINFO"
+
+ts_skip_nonroot
+ts_check_prog "bc"
+
+. $TS_SELF/functions.sh
+
+ts_lock "ipcslimits"
+
+ts_log "load original values"
+for i in $IPCS_IDX; do
+ SHM_ORG[$i]=$(cat ${IPCS_PROCFILES[$i]})
+done >> $TS_OUTPUT
+
+ts_log "maximize kernel setting"
+for i in $IPCS_IDX; do
+ echo ${IPCS_LIMITS[$i]} >> ${IPCS_PROCFILES[$i]}
+done >> $TS_OUTPUT
+
+ts_log "check for difference between kernel and IPC"
+ipcs_limits_check >> $TS_OUTPUT
+
+ts_log "write original values to kernel"
+for i in $IPCS_IDX; do
+ echo ${SHM_ORG[$i]} >> ${IPCS_PROCFILES[$i]}
+done >> $TS_OUTPUT
+
+ts_finalize
+
diff --git a/tests/ts/ipcs/limits2 b/tests/ts/ipcs/limits2
new file mode 100755
index 0000000..77ad70f
--- /dev/null
+++ b/tests/ts/ipcs/limits2
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux.
+#
+# 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 2 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.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="basic limits"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_IPCS"
+ts_check_test_command "$TS_HELPER_SYSINFO"
+ts_check_prog "bc"
+
+. $TS_SELF/functions.sh
+
+ts_lock "ipcslimits"
+
+ts_log "check for difference between kernel and IPC"
+ipcs_limits_check >> $TS_OUTPUT
+
+ts_finalize
+
diff --git a/tests/ts/ipcs/mk-rm-msg b/tests/ts/ipcs/mk-rm-msg
new file mode 100755
index 0000000..a9e2ca9
--- /dev/null
+++ b/tests/ts/ipcs/mk-rm-msg
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# 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 2 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.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="mk-rm-msg"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_IPCS"
+ts_check_test_command "$TS_CMD_IPCMK"
+ts_check_test_command "$TS_CMD_IPCRM"
+ts_check_test_command "$TS_HELPER_SYSINFO"
+
+. $TS_SELF/functions.sh
+
+rm -f $TS_OUTDIR/id-msg
+$TS_CMD_IPCMK -Q 2>>$TS_OUTPUT | ipcmk_output_handler $TS_OUTPUT $TS_OUTDIR/id-msg
+$TS_CMD_IPCS -q -i "$(cat $TS_OUTDIR/id-msg)" |\
+ grep -c "^Message Queue msqid=$(cat $TS_OUTDIR/id-msg)$" >>$TS_OUTPUT
+$TS_CMD_IPCRM -q $(cat $TS_OUTDIR/id-msg) >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $TS_OUTDIR/id-msg
+$TS_CMD_IPCMK -Q 2>>$TS_OUTPUT | ipcmk_output_handler $TS_OUTPUT $TS_OUTDIR/id-msg
+$TS_CMD_IPCRM -Q "$(
+ $TS_CMD_IPCS -q |
+ awk -v id=$(cat $TS_OUTDIR/id-msg) '{if ($2 == id){print $1}}' |
+ uniq
+)" >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $TS_OUTDIR/id-msg
+
+ts_finalize
diff --git a/tests/ts/ipcs/mk-rm-sem b/tests/ts/ipcs/mk-rm-sem
new file mode 100755
index 0000000..ec59c08
--- /dev/null
+++ b/tests/ts/ipcs/mk-rm-sem
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# 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 2 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.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="mk-rm-sem"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_IPCS"
+ts_check_test_command "$TS_CMD_IPCMK"
+ts_check_test_command "$TS_CMD_IPCRM"
+ts_check_test_command "$TS_HELPER_SYSINFO"
+
+. $TS_SELF/functions.sh
+
+rm -f $TS_OUTDIR/id-sem
+$TS_CMD_IPCMK -S 1 2>>$TS_OUTPUT | ipcmk_output_handler $TS_OUTPUT $TS_OUTDIR/id-sem
+$TS_CMD_IPCS -s -i "$(cat $TS_OUTDIR/id-sem)" | grep "^nsems" >>$TS_OUTPUT
+$TS_CMD_IPCRM -s $(cat $TS_OUTDIR/id-sem) >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $TS_OUTDIR/id-sem
+$TS_CMD_IPCMK -S 2 2>>$TS_OUTPUT | ipcmk_output_handler $TS_OUTPUT $TS_OUTDIR/id-sem
+$TS_CMD_IPCS -s -i "$(cat $TS_OUTDIR/id-sem)" | grep "^nsems" >>$TS_OUTPUT
+$TS_CMD_IPCRM -S "$(
+ $TS_CMD_IPCS -s |
+ awk -v id=$(cat $TS_OUTDIR/id-sem) '{if ($2 == id){print $1}}' |
+ uniq
+)" >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $TS_OUTDIR/id-sem
+
+ts_finalize
diff --git a/tests/ts/ipcs/mk-rm-shm b/tests/ts/ipcs/mk-rm-shm
new file mode 100755
index 0000000..eb85ad6
--- /dev/null
+++ b/tests/ts/ipcs/mk-rm-shm
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# 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 2 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.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="mk-rm-shm"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_IPCS"
+ts_check_test_command "$TS_CMD_IPCMK"
+ts_check_test_command "$TS_CMD_IPCRM"
+ts_check_test_command "$TS_HELPER_SYSINFO"
+
+. $TS_SELF/functions.sh
+
+rm -f $TS_OUTDIR/id-shm
+$TS_CMD_IPCMK -M 1 2>>$TS_OUTPUT | ipcmk_output_handler $TS_OUTPUT $TS_OUTDIR/id-shm
+$TS_CMD_IPCS -m -i "$(cat $TS_OUTDIR/id-shm)" | sed -n '/^bytes/s/\t.*//p' >>$TS_OUTPUT
+$TS_CMD_IPCRM -m $(cat $TS_OUTDIR/id-shm) >> $TS_OUTPUT 2>> $TS_ERRLOG
+rm -f $TS_OUTDIR/id-shm
+
+$TS_CMD_IPCMK -M 12 2>>$TS_OUTPUT | ipcmk_output_handler $TS_OUTPUT $TS_OUTDIR/id-shm
+$TS_CMD_IPCS -m -i "$(cat $TS_OUTDIR/id-shm)" | sed -n '/^bytes/s/\t.*//p' >>$TS_OUTPUT
+$TS_CMD_IPCRM -M "$(
+ $TS_CMD_IPCS -m |
+ awk -v id=$(cat $TS_OUTDIR/id-shm) '{if ($2 == id){print $1}}' |
+ uniq
+)" >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $TS_OUTDIR/id-shm
+
+ts_finalize