Whamcloud - gitweb
LU-1661 tests: improve setup_posix_users()
[fs/lustre-release.git] / lustre / tests / posix / posix.cfg
1 #!/bin/bash
2 #
3 # This file contains the global variables and common functions
4 # used in the posix test scripts.
5 set -e
6
7 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/../..; echo $PWD)}
8 . $LUSTRE/tests/test-framework.sh
9
10 #************************ Initialize Global Variables *************************#
11 export POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"}
12 export POSIX_RUN=${POSIX_RUN:-"$POSIX_SRC/run_posix_suite.pl"}
13 export TEST_BIN="$POSIX_SRC/TESTROOT-gcc$(gcc -v 2>&1 | tail -1 |
14                  cut -d' ' -f3)-$(uname -m).tgz"
15
16 # Root directory of the POSIX test suite installation.
17 export INSTALL_DIR=${INSTALL_DIR:-"$POSIX_SRC/tet"}
18
19 # Root directory from which the testsets will be executed.
20 export TESTEXEC_DIR=${TESTEXEC_DIR:-"$POSIX_SRC/TESTROOT"}
21
22 # Test results directory.
23 export RESULT_DIR=${RESULT_DIR:-"$INSTALL_DIR/test_sets/results"}
24
25 # Test groups for POSIX compliance test suite.
26 USER_GROUPS="vsxg0,vsxg1,vsxg2"
27
28 for i in $(seq 31); do
29         SUPP_GROUPS="$SUPP_GROUPS,supp$i"
30 done
31 SUPP_GROUPS=${SUPP_GROUPS#,}
32
33 export GROUP_ID=${GROUP_ID:-"2000000000"}
34 export USER_ID=${USER_ID:-"2000000000"}
35
36 #***************************** Common Functions *******************************#
37 # Remove users and groups for running the POSIX test suite.
38 delete_posix_users() {
39     local node=${1:-$(hostname)}
40
41     do_nodes $node "
42         for i in 0 1 2; do
43             userdel vsx\\\$i;
44         done;
45         for group in ${SUPP_GROUPS//,/ } ${USER_GROUPS//,/ }; do
46             groupdel \\\$group;
47         done" 2>&1 | dshbak -c
48     return ${PIPESTATUS[0]}
49 }
50
51 # Setup users and groups for running the POSIX test suite.
52 setup_posix_users() {
53         local node=${1:-$HOSTNAME}
54         local gid=$GROUP_ID
55         local uid=$USER_ID
56         local user group
57         local home
58         local opts
59         local i
60
61         for group in ${USER_GROUPS//,/ } ${SUPP_GROUPS//,/ }; do
62                 if ! do_rpc_nodes $node add_group $gid $group; then
63                         delete_posix_users $node
64                         return 1
65                 fi
66                 gid=$((gid + 1))
67         done
68
69         for i in 0 1 2; do
70                 user=vsx$i
71                 group=vsxg$i
72
73                 if [[ "$user" = "vsx0" ]]; then
74                         home=$INSTALL_DIR/test_sets
75                         opts="-G $SUPP_GROUPS"
76                 else
77                         home=$INSTALL_DIR
78                         opts=""
79                 fi
80
81                 if ! do_rpc_nodes $node add_user $uid $user $group $home $opts
82                 then
83                         delete_posix_users $node
84                         return 2
85                 fi
86                 uid=$((uid + 1))
87         done
88
89         return 0
90 }
91
92 prep() {
93     if [[ ! -d $POSIX_SRC ]]; then
94         echo "Missing POSIX testsuite source"
95         return 1
96     fi
97     [[ -f $TEST_BIN ]] && rm -f $TEST_BIN
98     [[ -d $INSTALL_DIR ]] && rm -rf $INSTALL_DIR
99
100     rpm -q byacc > /dev/null || yum -y install byacc
101     if grep -q " 6." /etc/issue; then
102         rpm -q compat-glibc-headers > /dev/null || \
103             yum install -y compat-glibc-headers
104
105         [[ -d /usr/include/bits ]] || mkdir -p /usr/include/bits
106         [[ -d /usr/include/sys ]] || mkdir -p /usr/include/sys
107         [[ -s /usr/include/stropts.h ]] || \
108             ln -s /usr/lib/x86_64-redhat-linux5E/include/stropts.h \
109             /usr/include/stropts.h
110         [[ -s /usr/include/bits/stropts.h ]] || \
111             ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/stropts.h \
112             /usr/include/bits/stropts.h
113         [[ -s /usr/include/bits/xtitypes.h ]] || \
114             ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/xtitypes.h \
115             /usr/include/bits/xtitypes.h
116         [[ -s /usr/include/sys/stropts.h ]] || \
117             ln -s /usr/lib/x86_64-redhat-linux5E/include/sys/stropts.h \
118             /usr/include/sys/stropts.h
119     fi
120
121     pushd $POSIX_SRC > /dev/null
122
123     if [[ -f install.sh ]]; then
124         [[ ! -x install.sh ]] && chmod +x install.sh
125     else
126         popd > /dev/null
127         echo "install.sh does not exist in $POSIX_SRC."
128         return 1
129     fi
130
131     popd > /dev/null
132 }
133
134 install() {
135     pushd $POSIX_SRC > /dev/null
136
137     log "Installing POSIX test suite"
138     # Install the POSIX test suite source files
139     expect -f install-posix.exp $INSTALL_DIR $TESTEXEC_DIR
140
141     popd > /dev/null
142 }
143
144 build() {
145     pushd $POSIX_SRC > /dev/null
146
147     log "Building POSIX test suite"
148     # Build testsets
149     expect -f build-posix.exp $INSTALL_DIR $TESTEXEC_DIR $POSIX_SRC
150
151     popd > /dev/null
152 }
153
154 cleanup() {
155     if [[ -f $TEST_BIN ]]; then
156         rm -fr $TESTEXEC_DIR
157         echo "Install and build POSIX test suite successfully!"
158         return 0
159     else
160         echo "failed to build POSIX test suite."
161         return 1
162     fi
163 }
164
165 run_posix() {
166     local MNTPNT=$1
167     local COMPARE=${2}
168     local compare=""
169     local rc=0
170     local cmd
171
172     [[ "x$COMPARE" != "x" ]] && compare="--compare-result"
173     # command to run posix test suite
174     cmd="TMP=/tmp/vsx0 TMPDIR=/tmp/vsx0 $POSIX_RUN --mountpt=$MNTPNT \
175         --posix-src=$POSIX_SRC --install-dir=$INSTALL_DIR \
176         --results-dir=$RESULT_DIR $compare 2>&1"
177
178     # run posix test suite
179     echo $cmd
180     if ! eval $cmd; then
181         rc=${PIPESTATUS[0]}
182     fi
183
184     return $rc
185 }
186
187 setup_posix() {
188     log "Setting up POSIX test suite from $POSIX_SRC"
189     prep || return $?
190     install
191     build
192     cleanup
193 }