Whamcloud - gitweb
63d386825eea73aa517ca2c1be38b17ed4c60c5d
[fs/lustre-release.git] / lustre / tests / functions.sh
1 #!/bin/bash
2
3 # Simple function used by run_*.sh scripts
4
5 assert_env() {
6     local failed=""
7     for name in $@; do
8         if [ -z "${!name}" ]; then
9             echo "$0: $name must be set"
10             failed=1
11         fi
12     done
13     [ $failed ] && exit 1 || true
14 }
15
16 echoerr () { echo "$@" 1>&2 ; }
17
18 signaled() {
19     echoerr "$(date +'%F %H:%M:%S'): client load was signaled to terminate"
20
21     local PGID=$(ps -eo "%c %p %r" | awk "/ $PPID / {print \$3}")
22     kill -TERM -$PGID
23     sleep 5
24     kill -KILL -$PGID
25 }
26
27 mpi_run () {
28     local mpirun="$MPIRUN $MPIRUN_OPTIONS"
29     local command="$mpirun $@"
30     local mpilog=$TMP/mpi.log
31     local rc
32     $LFS df -i
33
34     if [ -n "$MPI_USER" -a "$MPI_USER" != root -a -n "$mpirun" ]; then
35         echo "+ chmod 0777 $MOUNT"
36         chmod 0777 $MOUNT
37         command="su $MPI_USER sh -c \"$command \""
38     fi
39
40     ls -ald $MOUNT
41     echo "+ $command"
42     eval $command 2>&1 | tee $mpilog || true
43
44     rc=${PIPESTATUS[0]}
45     if [ $rc -eq 0 ] && grep -q "p4_error:" $mpilog ; then
46        rc=1
47     fi
48     $LFS df -i
49     return $rc
50 }
51
52 nids_list () {
53    local list
54    for i in ${1//,/ }; do
55        list="$list $i@$NETTYPE"
56    done
57    echo $list
58 }
59
60 # FIXME: all setup/cleanup can be done without rpc.sh
61 lst_end_session () {
62     local verbose=false
63     [ x$1 = x--verbose ] && verbose=true
64
65     export LST_SESSION=`$LST show_session 2>/dev/null | awk -F " " '{print $5}'`
66     [ "$LST_SESSION" == "" ] && return
67
68     if $verbose; then 
69         $LST show_error c s
70     fi
71     $LST stop b
72     $LST end_session
73 }
74
75 lst_session_cleanup_all () {
76     local list=$(comma_list $(nodes_list))
77     do_rpc_nodes $list lst_end_session
78 }
79
80 lst_cleanup () {
81     lsmod | grep -q lnet_selftest && rmmod lnet_selftest > /dev/null 2>&1 || true
82 }
83
84 lst_cleanup_all () {
85    local list=$(comma_list $(nodes_list))
86
87    # lst end_session needs to be executed only locally
88    # i.e. on node where lst new_session was called
89    lst_end_session --verbose 
90    do_rpc_nodes $list lst_cleanup
91 }
92
93 lst_setup () {
94     load_module lnet_selftest
95 }
96
97 lst_setup_all () {
98     local list=$(comma_list $(nodes_list))
99     do_rpc_nodes $list lst_setup 
100 }
101