From: Minh Diep Date: Mon, 5 Mar 2012 23:09:55 +0000 (-0800) Subject: LU-1192 tests: automate POSIX compliance testing X-Git-Tag: 2.2.52~45 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3fe74297d3dd063d23f26ae9850bdf8f0892fae8;hp=fd1a5c19ea412f3b9637be4fdbe8d30eeec1858c LU-1192 tests: automate POSIX compliance testing a. assuming that the POSIX source already installed on the system b. setup loop back ext4 filesystem c. install, build and run POSIX binaries on ext4 d. run POSIX again lustre f. compare results from ext4 and lustre Signed-off-by: Minh Diep Change-Id: I104a43549a2dedf272b52c4c9ce3ab0d50a223eb Reviewed-on: http://review.whamcloud.com/2256 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Yu Jian Reviewed-by: Wei Liu Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index e1ad6b3..f2c14db 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -28,6 +28,7 @@ noinst_SCRIPTS += lnet-selftest.sh obdfilter-survey.sh mmp.sh mmp_mark.sh noinst_SCRIPTS += sgpdd-survey.sh maloo_upload.sh auster setup-nfs.sh noinst_SCRIPTS += mds-survey.sh parallel-scale-nfs.sh noinst_SCRIPTS += parallel-scale-nfsv3.sh parallel-scale-nfsv4.sh +noinst_SCRIPTS += posix.sh nobase_noinst_SCRIPTS = cfg/local.sh nobase_noinst_SCRIPTS += test-groups/regression test-groups/regression-mpi nobase_noinst_SCRIPTS += acl/make-tree acl/run cfg/ncli.sh @@ -35,6 +36,7 @@ nobase_noinst_SCRIPTS += racer/dir_create.sh racer/file_create.sh racer/file_lis nobase_noinst_SCRIPTS += racer/file_rm.sh racer/racer.sh racer/file_concat.sh racer/file_exec.sh nobase_noinst_SCRIPTS += racer/file_link.sh racer/file_rename.sh racer/file_symlink.sh nobase_noinst_SCRIPTS += rmtacl/make-tree rmtacl/run +nobase_noinst_SCRIPTS += posix/posix.cfg nobase_noinst_DATA = acl/cp.test acl/getfacl-noacl.test acl/inheritance.test nobase_noinst_DATA += acl/misc.test acl/permissions.test acl/setfacl.test nobase_noinst_DATA += rmtacl/misc.test rmtacl/permissions.test diff --git a/lustre/tests/posix.sh b/lustre/tests/posix.sh new file mode 100755 index 0000000..3d75e5e --- /dev/null +++ b/lustre/tests/posix.sh @@ -0,0 +1,118 @@ +#!/bin/bash +#set -vx +set -e + +LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)} +. $LUSTRE/tests/test-framework.sh +init_test_env $@ +. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh} +init_logging + +build_test_filter +check_and_setup_lustre + +POSIX_DIR=${POSIX_DIR:-"$LUSTRE/tests/posix"} +POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"} + +cleanup_loop_dev() { + local mnt=$1 + local dev=$2 + local file=$3 + + # if we only have 1 arg, we will search for dev + if [[ $# = 1 ]]; then + dev=$(losetup -a | grep "$mnt" | cut -d: -f1) + [[ -n $dev ]] && losetup -d $dev + else # we need all args + [[ -z $mnt ]] || [[ -z $dev ]] || [[ -z $file ]] && + error "Can't cleanup loop device" + umount -f $mnt + losetup -d $dev && rm -rf $mnt + rm -f $file + fi +} + +setup_loop_dev() { + local mnt=$1 + local dev=$2 + local file=$3 + local rc=0 + + echo "Make a loop file system with $file on $dev" + dd if=/dev/zero of=$file bs=1024k count=500 > /dev/null + if ! losetup $dev $file; then + rc=$? + echo "can't set up $dev for $file" + return $rc + fi + if ! mkfs.ext4 $dev; then + rc=$? + echo "mkfs.ext4 on $dev failed" + return $rc + fi + mkdir -p ${mnt} + if ! mount -t ext4 $dev $mnt; then + rc=$? + echo "mount ext4 failed" + return $rc + fi + echo + return $rc +} + +test_1() { + local allnodes="$(comma_list $(nodes_list))" + local tfile="$TMP/ext4-file" + local mntpnt=$POSIX_SRC/ext4 + local loopbase + local loopdev + local rc=0 + + # We start at loop1 because posix build uses loop0 + [ -b /dev/loop/1 ] && loopbase=/dev/loop/ + [ -b /dev/loop1 ] && loopbase=/dev/loop + [ -z "$loopbase" ] && error "/dev/loop/1 and /dev/loop1 gone?" + + for i in `seq 1 7`; do + losetup $loopbase$i > /dev/null 2>&1 && continue || true + loopdev=$loopbase$i + break + done + + [ -z "$loopdev" ] && error "Can not find loop device" + + if ! setup_loop_dev $mntpnt $loopdev $tfile; then + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" + error "Setup loop device failed" + fi + + # copy the source over to ext mount point + if ! cp -af ${POSIX_SRC}/*.* $mntpnt; then + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" + error "Copy POSIX test suite failed" + fi + export POSIX_SRC=$mntpnt + . $POSIX_DIR/posix.cfg + + setup_posix_users $allnodes + if ! setup_posix; then + delete_posix_users $allnodes + cleanup_loop_dev "$POSIX_SRC" + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" + error "Setup POSIX test suite failed" + fi + + log "Run POSIX test against lustre filesystem" + run_posix $MOUNT compare || \ + error_noexit "Run POSIX testsuite on $MOUNT failed" + + [[ -d "$MOUNT/TESTROOT" ]] && rm -fr $MOUNT/TESTROOT + delete_posix_users $allnodes + cleanup_loop_dev "$POSIX_SRC" + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" +} +run_test 1 "build, install, run posix on ext4 and lustre, then compare" + +complete $(basename $0) $SECONDS +check_and_cleanup_lustre +exit_status diff --git a/lustre/tests/posix/posix.cfg b/lustre/tests/posix/posix.cfg new file mode 100644 index 0000000..51f50aa --- /dev/null +++ b/lustre/tests/posix/posix.cfg @@ -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 +}