Whamcloud - gitweb
4cb72e38fddedd579a25a7e6197e8636c293f3ec
[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         # consistent with install.sh in LSB Test Suite
55         local gid=$((GROUP_ID + 1))
56         local uid=$USER_ID
57         local user group
58         local home
59         local opts
60         local i
61
62         for group in ${USER_GROUPS//,/ } ${SUPP_GROUPS//,/ }; do
63                 if ! do_rpc_nodes $node add_group $gid $group; then
64                         delete_posix_users $node
65                         return 1
66                 fi
67                 gid=$((gid + 1))
68         done
69
70         for i in 0 1 2; do
71                 user=vsx$i
72                 group=vsxg$i
73
74                 if [[ "$user" = "vsx0" ]]; then
75                         home=$INSTALL_DIR/test_sets
76                         opts="-G $SUPP_GROUPS"
77                 else
78                         home=$INSTALL_DIR
79                         opts=""
80                 fi
81
82                 if ! do_rpc_nodes $node add_user $uid $user $group $home $opts
83                 then
84                         delete_posix_users $node
85                         return 2
86                 fi
87                 uid=$((uid + 1))
88         done
89
90         return 0
91 }
92
93 prep() {
94     if [[ ! -d $POSIX_SRC ]]; then
95         echo "Missing POSIX testsuite source"
96         return 1
97     fi
98     [[ -f $TEST_BIN ]] && rm -f $TEST_BIN
99     [[ -d $INSTALL_DIR ]] && rm -rf $INSTALL_DIR
100
101         if egrep -q "CentOS|Red Hat|Fedora" /etc/redhat-release; then
102                 local prefix=/usr/lib/$(uname -m)-redhat-linux5E
103                 if egrep -q "Fedora" /etc/issue; then
104                         prefix=/usr/arm-gp2x-linux
105                 fi
106                 if grep -q "el7" <<<$(uname -r); then
107                         # Fix LU-9102
108                         prefix=/usr/local/lib/x86_64-redhat-linux5E
109                 fi
110                 [[ -d /usr/include/bits ]] || mkdir -p /usr/include/bits
111                 [[ -d /usr/include/sys ]] || mkdir -p /usr/include/sys
112                 [[ -s /usr/include/stropts.h ]] ||
113                         ln -s $prefix/include/stropts.h \
114                         /usr/include/stropts.h
115                 [[ -s /usr/include/bits/stropts.h ]] ||
116                         ln -s $prefix/include/bits/stropts.h \
117                         /usr/include/bits/stropts.h
118                 [[ -s /usr/include/bits/xtitypes.h ]] ||
119                         ln -s $prefix/include/bits/xtitypes.h \
120                         /usr/include/bits/xtitypes.h
121                 [[ -s /usr/include/sys/stropts.h ]] ||
122                         ln -s $prefix/include/sys/stropts.h \
123                         /usr/include/sys/stropts.h
124         fi
125
126     pushd $POSIX_SRC > /dev/null
127
128     if [[ -f install.sh ]]; then
129         [[ ! -x install.sh ]] && chmod +x install.sh
130     else
131         popd > /dev/null
132         echo "install.sh does not exist in $POSIX_SRC."
133         return 1
134     fi
135
136     popd > /dev/null
137 }
138
139 install() {
140     pushd $POSIX_SRC > /dev/null
141
142     log "Installing POSIX test suite"
143     # Install the POSIX test suite source files
144     expect -f install-posix.exp $INSTALL_DIR $TESTEXEC_DIR
145
146     popd > /dev/null
147 }
148
149 build() {
150     pushd $POSIX_SRC > /dev/null
151
152     log "Building POSIX test suite"
153     # Build testsets
154     expect -f build-posix.exp $INSTALL_DIR $TESTEXEC_DIR $POSIX_SRC
155
156     popd > /dev/null
157 }
158
159 cleanup() {
160     if [[ -f $TEST_BIN ]]; then
161         rm -fr $TESTEXEC_DIR
162         echo "Install and build POSIX test suite successfully!"
163         return 0
164     else
165         echo "failed to build POSIX test suite."
166         return 1
167     fi
168 }
169
170 run_posix() {
171     local MNTPNT=$1
172     local COMPARE=${2}
173     local compare=""
174     local rc=0
175     local cmd
176
177     [[ "x$COMPARE" != "x" ]] && compare="--compare-result"
178     # command to run posix test suite
179     cmd="TMP=/tmp/vsx0 TMPDIR=/tmp/vsx0 $POSIX_RUN --mountpt=$MNTPNT \
180         --posix-src=$POSIX_SRC --install-dir=$INSTALL_DIR \
181         --results-dir=$RESULT_DIR $compare 2>&1"
182
183     # run posix test suite
184     echo $cmd
185     if ! eval $cmd; then
186         rc=${PIPESTATUS[0]}
187     fi
188
189     return $rc
190 }
191
192 setup_posix() {
193     log "Setting up POSIX test suite from $POSIX_SRC"
194     prep || return $?
195     install
196     build
197     cleanup
198 }