Upload Tizen:Base source
[framework/base/util-linux-ng.git] / tests / ts / ipcs / functions.sh
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2007 Karel Zak <kzak@redhat.com>
5 #
6 # This file is part of util-linux-ng.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18
19 PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize)
20
21 # kernel files
22 IPCS_PROCFILES=(
23         /proc/sys/kernel/shmmni
24         /proc/sys/kernel/shmall
25         /proc/sys/kernel/shmmax
26 )
27
28 # raw data converted to ipcs-like format
29 #       shmmni = same
30 #       shmall = from pages to KBytes
31 #       shmmax = from bytes to KBytes
32 #
33 IPCS_KERNEL_CMD=(
34         "cat /proc/sys/kernel/shmmni"
35         "echo \$(cat /proc/sys/kernel/shmall) / 1024 \* $PAGE_SIZE | bc -l | sed 's/\..*//'"
36         "echo \$(cat /proc/sys/kernel/shmmax) / 1024 | bc -l | sed 's/\..*//'"
37 )
38
39 # data from the ipcs command
40 IPCS_CMD=(
41         "$TS_CMD_IPCS -m -l | awk '/max number of segments/ { print \$6 }'"
42         "$TS_CMD_IPCS -m -l | awk '/max total shared memory/ { print \$7 }'"
43         "$TS_CMD_IPCS -m -l | awk '/max seg size/ { print \$6 }'"
44 )
45
46
47 # The linux kernel accepts ULONG_MAX, but this value is same like ULLONG_MAX on
48 # 64-bit archs. So the ipcs command has to always overflow on 64-bit archs when
49 # shmall (=num of pages!) is same or almost same like ULONG_MAX. This is reason
50 # why we for the test uses 32-bit limits on all archs.
51 #
52 # (Don't worry that 64-bit ULONG_MAX makes ipcs useless ...
53 #  ... it's a problem for admins who want to use 75557863725TB of RAM for shm)
54 #
55 IPCS_LIMITS=(
56         $($TS_HELPER_SYSINFO INT_MAX)
57         $($TS_HELPER_SYSINFO ULONG_MAX32)
58         $($TS_HELPER_SYSINFO ULONG_MAX32)
59 )
60
61 # list of indexes = 0..(sizeof Array - 1)
62 IPCS_IDX=$(seq 0 $(( ${#IPCS_PROCFILES[*]} - 1 )))
63
64 # checker
65 function ipcs_limits_check {
66         for i in $IPCS_IDX; do
67                 echo -n ${IPCS_PROCFILES[$i]}
68
69                 a=$(eval ${IPCS_KERNEL_CMD[$i]})
70                 b=$(eval ${IPCS_CMD[$i]})
71
72                 #echo -n " RAW: "
73                 #cat ${IPCS_PROCFILES[$i]}
74                 #echo "CMD: ${ICPS_KERNEL_CMD[$i]}"
75
76                 if [ x"$a" == x"$b" ]; then
77                         echo " OK"
78                 else
79                         echo " kernel=$a, ipcs=$b"
80                 fi
81         done
82 }
83