Whamcloud - gitweb
LU-1192 tests: automate POSIX compliance testing
[fs/lustre-release.git] / lustre / tests / posix / posix.cfg
diff --git a/lustre/tests/posix/posix.cfg b/lustre/tests/posix/posix.cfg
new file mode 100644 (file)
index 0000000..51f50aa
--- /dev/null
@@ -0,0 +1,242 @@
+#!/bin/bash
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+#
+# This file contains the global variables and common functions
+# used in the posix test scripts.
+set -e
+LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
+. $LUSTRE/tests/test-framework.sh
+#************************ Initialize Global Variables *************************#
+export POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"}
+export POSIX_RUN=${POSIX_RUN:-"$POSIX_SRC/run_posix_suite.pl"}
+export TEST_BIN="$POSIX_SRC/TESTROOT-gcc$(gcc -v 2>&1 | tail -1 | cut -d' ' -f3)-$(uname -m).tgz"
+
+# Root directory of the POSIX test suite installation.
+export INSTALL_DIR=${INSTALL_DIR:-"$POSIX_SRC/tet"}
+
+# Root directory from which the testsets will be executed.
+export TESTEXEC_DIR=${TESTEXEC_DIR:-"$POSIX_SRC/TESTROOT"}
+
+# Test results directory.
+export RESULT_DIR=${RESULT_DIR:-"$INSTALL_DIR/test_sets/results"}
+
+# Test groups for POSIX compliance test suite.
+USER_GROUPS="vsxg0,vsxg1,vsxg2"
+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"
+
+export GROUP_ID=${GROUP_ID:-"1000"}
+export USER_ID=${USER_ID:-"1000"}
+
+#***************************** Common Functions *******************************#
+# Check and add a test group.
+add_group() {
+    local node=${1:-$(hostname)}
+    local group_id=$2
+    local group_name=$3
+    local rc=0
+
+    if ! (do_nodes $node "
+        error() { set +x; echo Error: \\\$2: \\\$1; echo XXRETCODE:\\\$1; exit \\\$1; }
+        gid=\\\$(getent group $group_name | cut -d: -f3);
+        if [ \"x\\\$gid\" != \"x\" ]; then
+            [ \\\$gid -eq $group_id ] || \\
+                error 1 \\\"inconsistent group ID: new: $group_id, old: \\\$gid\\\";
+        else
+            groupadd -g $group_id $group_name
+        fi;" 2>&1 | dshbak -c
+        exit ${PIPESTATUS[0]})
+    then
+        rc=${PIPESTATUS[0]}
+    fi
+
+    return $rc
+}
+
+# Check and add a test user.
+add_user() {
+    local node=${1:-$(hostname)}
+    local user_id=$2
+    local user_name=$3
+    local group_name=$4
+    local home_dir
+    local rc=0
+
+    if [[ "$user_name" = "vsx0" ]]; then
+        home_dir=$INSTALL_DIR/test_sets
+    else
+        home_dir=$INSTALL_DIR
+    fi
+
+    if ! (do_nodes $node "
+        error() { set +x; echo Error: \\\$2: \\\$1; echo XXRETCODE:\\\$1; exit \\\$1; }
+        SUPP_GROUPS=$SUPP_GROUPS;
+        uid=\\\$(getent passwd $user_name | cut -d: -f3);
+        if [ \"x\\\$uid\" != \"x\" ]; then
+            if [ \\\$uid -eq $user_id ]; then
+                dir=\\\$(getent passwd $user_name | cut -d: -f6)
+                if [ \"x\\\$dir\" != \"x$home_dir\" ]; then
+                    mkdir -p $home_dir
+                    usermod -d $home_dir $user_name
+                fi
+            else
+                error 1 \\\"inconsistent user ID: new: $user_id, old: \\\$uid\\\"
+            fi
+        else
+            mkdir -p $home_dir
+            if [ \"x$user_name\" = \"xvsx0\" ]; then
+                useradd -M -u $user_id -d $home_dir -g $group_name -G $SUPP_GROUPS $user_name
+            else
+                useradd -M -u $user_id -d $home_dir -g $group_name $user_name
+            fi
+        fi" 2>&1 | dshbak -c
+        exit ${PIPESTATUS[0]})
+    then
+        rc=${PIPESTATUS[0]}
+    fi
+
+    return $rc
+}
+
+# Remove users and groups for running the POSIX test suite.
+delete_posix_users() {
+    local node=${1:-$(hostname)}
+
+    do_nodes $node "
+        for i in 0 1 2; do
+            userdel vsx\\\$i;
+        done;
+        for group in ${SUPP_GROUPS//,/ } ${USER_GROUPS//,/ }; do
+            groupdel \\\$group;
+        done" 2>&1 | dshbak -c
+    return ${PIPESTATUS[0]}
+}
+
+# Setup users and groups for running the POSIX test suite.
+setup_posix_users() {
+    local node=${1:-$(hostname)}
+    local gid=$((GROUP_ID + 1))
+    local uid=$USER_ID
+    local user group
+    local i
+
+    for group in ${USER_GROUPS//,/ } ${SUPP_GROUPS//,/ }; do
+        if ! add_group $node $gid $group; then
+            delete_posix_users $node
+            setup_posix_users $node
+        fi
+        gid=$(( gid + 1 ))
+    done
+
+    for i in 0 1 2; do
+        user=vsx$i
+        group=vsxg$i
+        if ! add_user $node $uid $user $group; then
+            delete_posix_users $node
+            setup_posix_users $node
+        fi
+        uid=$(( uid + 1 ))
+    done
+}
+
+prep() {
+    if [[ ! -d $POSIX_SRC ]]; then
+        echo "Missing POSIX testsuite source"
+        return 1
+    fi
+    [[ -f $TEST_BIN ]] && rm -f $TEST_BIN
+    [[ -d $INSTALL_DIR ]] && rm -rf $INSTALL_DIR
+
+    rpm -q byacc > /dev/null || yum -y install byacc
+    if grep -q " 6." /etc/issue; then
+        rpm -q compat-glibc-headers > /dev/null || \
+            yum install -y compat-glibc-headers
+
+        [[ -d /usr/include/bits ]] || mkdir -p /usr/include/bits
+        [[ -d /usr/include/sys ]] || mkdir -p /usr/include/sys
+        [[ -s /usr/include/stropts.h ]] || \
+            ln -s /usr/lib/x86_64-redhat-linux5E/include/stropts.h \
+            /usr/include/stropts.h
+        [[ -s /usr/include/bits/stropts.h ]] || \
+            ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/stropts.h \
+            /usr/include/bits/stropts.h
+        [[ -s /usr/include/bits/xtitypes.h ]] || \
+            ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/xtitypes.h \
+            /usr/include/bits/xtitypes.h
+        [[ -s /usr/include/sys/stropts.h ]] || \
+            ln -s /usr/lib/x86_64-redhat-linux5E/include/sys/stropts.h \
+            /usr/include/sys/stropts.h
+    fi
+
+    pushd $POSIX_SRC > /dev/null
+
+    if [[ -f install.sh ]]; then
+        [[ ! -x install.sh ]] && chmod +x install.sh
+    else
+        popd > /dev/null
+        echo "install.sh does not exist in $POSIX_SRC."
+        return 1
+    fi
+
+    popd > /dev/null
+}
+
+install() {
+    pushd $POSIX_SRC > /dev/null
+
+    log "Installing POSIX test suite"
+    # Install the POSIX test suite source files
+    expect -f install-posix.exp $INSTALL_DIR $TESTEXEC_DIR
+
+    popd > /dev/null
+}
+
+build() {
+    pushd $POSIX_SRC > /dev/null
+
+    log "Building POSIX test suite"
+    # Build testsets
+    expect -f build-posix.exp $INSTALL_DIR $TESTEXEC_DIR $POSIX_SRC
+
+    popd > /dev/null
+}
+
+cleanup() {
+    if [[ -f $TEST_BIN ]]; then
+        rm -fr $TESTEXEC_DIR
+        echo "Install and build POSIX test suite successfully!"
+        return 0
+    else
+        echo "failed to build POSIX test suite."
+        return 1
+    fi
+}
+
+run_posix() {
+    local MNTPNT=$1
+    local COMPARE=${2}
+    local compare=""
+    local rc=0
+    local cmd
+
+    [[ "x$COMPARE" != "x" ]] && compare="--compare-result"
+    # command to run posix test suite
+    cmd="TMP=/tmp/vsx0 TMPDIR=/tmp/vsx0 $POSIX_RUN --mountpt=$MNTPNT \
+        --posix-src=$POSIX_SRC --install-dir=$INSTALL_DIR \
+        --results-dir=$RESULT_DIR $compare 2>&1"
+
+    # run posix test suite
+    echo $cmd
+    if ! eval $cmd; then
+        rc=${PIPESTATUS[0]}
+    fi
+
+    return $rc
+}
+
+setup_posix() {
+    log "Setting up POSIX test suite from $POSIX_SRC"
+    prep || return $?
+    install
+    build
+    cleanup
+}