Whamcloud - gitweb
51f50aaafb38938ddc42630696fccf5b134ccd05
[fs/lustre-release.git] / lustre / tests / posix / posix.cfg
1 #!/bin/bash
2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
3 #
4 # This file contains the global variables and common functions
5 # used in the posix test scripts.
6 set -e
7 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
8 . $LUSTRE/tests/test-framework.sh
9 #************************ Initialize Global Variables *************************#
10 export POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"}
11 export POSIX_RUN=${POSIX_RUN:-"$POSIX_SRC/run_posix_suite.pl"}
12 export TEST_BIN="$POSIX_SRC/TESTROOT-gcc$(gcc -v 2>&1 | tail -1 | cut -d' ' -f3)-$(uname -m).tgz"
13
14 # Root directory of the POSIX test suite installation.
15 export INSTALL_DIR=${INSTALL_DIR:-"$POSIX_SRC/tet"}
16
17 # Root directory from which the testsets will be executed.
18 export TESTEXEC_DIR=${TESTEXEC_DIR:-"$POSIX_SRC/TESTROOT"}
19
20 # Test results directory.
21 export RESULT_DIR=${RESULT_DIR:-"$INSTALL_DIR/test_sets/results"}
22
23 # Test groups for POSIX compliance test suite.
24 USER_GROUPS="vsxg0,vsxg1,vsxg2"
25 SUPP_GROUPS="supp1,supp2,supp3,supp4,supp5,supp6,supp7,supp8,supp9,supp10,supp11,supp12,supp13,supp14,supp15,supp16,supp17,supp18,supp19,supp20,supp21,supp22,supp23,supp24,supp25,supp26,supp27,supp28,supp29,supp30,supp31"
26
27 export GROUP_ID=${GROUP_ID:-"1000"}
28 export USER_ID=${USER_ID:-"1000"}
29
30 #***************************** Common Functions *******************************#
31 # Check and add a test group.
32 add_group() {
33     local node=${1:-$(hostname)}
34     local group_id=$2
35     local group_name=$3
36     local rc=0
37
38     if ! (do_nodes $node "
39         error() { set +x; echo Error: \\\$2: \\\$1; echo XXRETCODE:\\\$1; exit \\\$1; }
40         gid=\\\$(getent group $group_name | cut -d: -f3);
41         if [ \"x\\\$gid\" != \"x\" ]; then
42             [ \\\$gid -eq $group_id ] || \\
43                 error 1 \\\"inconsistent group ID: new: $group_id, old: \\\$gid\\\";
44         else
45             groupadd -g $group_id $group_name
46         fi;" 2>&1 | dshbak -c
47         exit ${PIPESTATUS[0]})
48     then
49         rc=${PIPESTATUS[0]}
50     fi
51
52     return $rc
53 }
54
55 # Check and add a test user.
56 add_user() {
57     local node=${1:-$(hostname)}
58     local user_id=$2
59     local user_name=$3
60     local group_name=$4
61     local home_dir
62     local rc=0
63
64     if [[ "$user_name" = "vsx0" ]]; then
65         home_dir=$INSTALL_DIR/test_sets
66     else
67         home_dir=$INSTALL_DIR
68     fi
69
70     if ! (do_nodes $node "
71         error() { set +x; echo Error: \\\$2: \\\$1; echo XXRETCODE:\\\$1; exit \\\$1; }
72         SUPP_GROUPS=$SUPP_GROUPS;
73         uid=\\\$(getent passwd $user_name | cut -d: -f3);
74         if [ \"x\\\$uid\" != \"x\" ]; then
75             if [ \\\$uid -eq $user_id ]; then
76                 dir=\\\$(getent passwd $user_name | cut -d: -f6)
77                 if [ \"x\\\$dir\" != \"x$home_dir\" ]; then
78                     mkdir -p $home_dir
79                     usermod -d $home_dir $user_name
80                 fi
81             else
82                 error 1 \\\"inconsistent user ID: new: $user_id, old: \\\$uid\\\"
83             fi
84         else
85             mkdir -p $home_dir
86             if [ \"x$user_name\" = \"xvsx0\" ]; then
87                 useradd -M -u $user_id -d $home_dir -g $group_name -G $SUPP_GROUPS $user_name
88             else
89                 useradd -M -u $user_id -d $home_dir -g $group_name $user_name
90             fi
91         fi" 2>&1 | dshbak -c
92         exit ${PIPESTATUS[0]})
93     then
94         rc=${PIPESTATUS[0]}
95     fi
96
97     return $rc
98 }
99
100 # Remove users and groups for running the POSIX test suite.
101 delete_posix_users() {
102     local node=${1:-$(hostname)}
103
104     do_nodes $node "
105         for i in 0 1 2; do
106             userdel vsx\\\$i;
107         done;
108         for group in ${SUPP_GROUPS//,/ } ${USER_GROUPS//,/ }; do
109             groupdel \\\$group;
110         done" 2>&1 | dshbak -c
111     return ${PIPESTATUS[0]}
112 }
113
114 # Setup users and groups for running the POSIX test suite.
115 setup_posix_users() {
116     local node=${1:-$(hostname)}
117     local gid=$((GROUP_ID + 1))
118     local uid=$USER_ID
119     local user group
120     local i
121
122     for group in ${USER_GROUPS//,/ } ${SUPP_GROUPS//,/ }; do
123         if ! add_group $node $gid $group; then
124             delete_posix_users $node
125             setup_posix_users $node
126         fi
127         gid=$(( gid + 1 ))
128     done
129
130     for i in 0 1 2; do
131         user=vsx$i
132         group=vsxg$i
133         if ! add_user $node $uid $user $group; then
134             delete_posix_users $node
135             setup_posix_users $node
136         fi
137         uid=$(( uid + 1 ))
138     done
139 }
140
141 prep() {
142     if [[ ! -d $POSIX_SRC ]]; then
143         echo "Missing POSIX testsuite source"
144         return 1
145     fi
146     [[ -f $TEST_BIN ]] && rm -f $TEST_BIN
147     [[ -d $INSTALL_DIR ]] && rm -rf $INSTALL_DIR
148
149     rpm -q byacc > /dev/null || yum -y install byacc
150     if grep -q " 6." /etc/issue; then
151         rpm -q compat-glibc-headers > /dev/null || \
152             yum install -y compat-glibc-headers
153
154         [[ -d /usr/include/bits ]] || mkdir -p /usr/include/bits
155         [[ -d /usr/include/sys ]] || mkdir -p /usr/include/sys
156         [[ -s /usr/include/stropts.h ]] || \
157             ln -s /usr/lib/x86_64-redhat-linux5E/include/stropts.h \
158             /usr/include/stropts.h
159         [[ -s /usr/include/bits/stropts.h ]] || \
160             ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/stropts.h \
161             /usr/include/bits/stropts.h
162         [[ -s /usr/include/bits/xtitypes.h ]] || \
163             ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/xtitypes.h \
164             /usr/include/bits/xtitypes.h
165         [[ -s /usr/include/sys/stropts.h ]] || \
166             ln -s /usr/lib/x86_64-redhat-linux5E/include/sys/stropts.h \
167             /usr/include/sys/stropts.h
168     fi
169
170     pushd $POSIX_SRC > /dev/null
171
172     if [[ -f install.sh ]]; then
173         [[ ! -x install.sh ]] && chmod +x install.sh
174     else
175         popd > /dev/null
176         echo "install.sh does not exist in $POSIX_SRC."
177         return 1
178     fi
179
180     popd > /dev/null
181 }
182
183 install() {
184     pushd $POSIX_SRC > /dev/null
185
186     log "Installing POSIX test suite"
187     # Install the POSIX test suite source files
188     expect -f install-posix.exp $INSTALL_DIR $TESTEXEC_DIR
189
190     popd > /dev/null
191 }
192
193 build() {
194     pushd $POSIX_SRC > /dev/null
195
196     log "Building POSIX test suite"
197     # Build testsets
198     expect -f build-posix.exp $INSTALL_DIR $TESTEXEC_DIR $POSIX_SRC
199
200     popd > /dev/null
201 }
202
203 cleanup() {
204     if [[ -f $TEST_BIN ]]; then
205         rm -fr $TESTEXEC_DIR
206         echo "Install and build POSIX test suite successfully!"
207         return 0
208     else
209         echo "failed to build POSIX test suite."
210         return 1
211     fi
212 }
213
214 run_posix() {
215     local MNTPNT=$1
216     local COMPARE=${2}
217     local compare=""
218     local rc=0
219     local cmd
220
221     [[ "x$COMPARE" != "x" ]] && compare="--compare-result"
222     # command to run posix test suite
223     cmd="TMP=/tmp/vsx0 TMPDIR=/tmp/vsx0 $POSIX_RUN --mountpt=$MNTPNT \
224         --posix-src=$POSIX_SRC --install-dir=$INSTALL_DIR \
225         --results-dir=$RESULT_DIR $compare 2>&1"
226
227     # run posix test suite
228     echo $cmd
229     if ! eval $cmd; then
230         rc=${PIPESTATUS[0]}
231     fi
232
233     return $rc
234 }
235
236 setup_posix() {
237     log "Setting up POSIX test suite from $POSIX_SRC"
238     prep || return $?
239     install
240     build
241     cleanup
242 }