-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun-test.sh
executable file
·111 lines (91 loc) · 2.89 KB
/
run-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
#
# This script creates a temporary matlab script for a specific test and
# a specific FieldTrip revision, starts MATLAB and executes the temporary
# script.
#
# Use as either one of these
# run-test.sh <TESTSCRIPT> <FIELDTRIPDIR> <LOGDIR> <MATLABCMD>
# run-test.sh <TESTSCRIPT> <FIELDTRIPDIR> <LOGDIR>
# run-test.sh <TESTSCRIPT> <FIELDTRIPDIR>
# run-test.sh <TESTSCRIPT>
#
# This script is scheduled for execution on the torque cluster by schedule-batch.sh
#
# optenv does not load modules when executed as PBS job
source /opt/optenv.sh
module load openmeeg
module load cluster
module load fsl
set -u -e # exit on error or if variable is unset
umask 0022 # ensure that other team members can read the results
ulimit -c 0 # disable core dumps
DASHBOARDDIR=$(dirname $(readlink -f $0))
TESTSCRIPT=`readlink -f $1`
if [ "$#" -ge 2 ]; then
FIELDTRIPDIR=$2
else
FIELDTRIPDIR=$HOME/matlab/fieldtrip
fi
if [ "$#" -ge 3 ]; then
LOGDIR=$3
else
REVISION=$(cd $FIELDTRIPDIR && git rev-parse --short HEAD)
LOGDIR=$DASHBOARDDIR/logs/$REVISION
fi
if [ "$#" -ge 4 ]; then
MATLABCMD=$4
else
MATLABCMD="/opt/matlab/R2018b/bin/matlab -nodesktop -nosplash -nodisplay -singleCompThread"
fi
if [[ $MATLABCMD == *"matlab"* ]]; then
XUNIT=`readlink -f /home/common/matlab/xunit`
elif [[ $MATLABCMD == *"octave"* ]]; then
XUNIT=`readlink -f $HOME/matlab/xunit-octave`
else
>&2 echo Error: unknown MATLABCMD $MATLABCMD
fi
# the FieldTrip test script test to be executed is passed with the full path
TESTDIR=`dirname $TESTSCRIPT`
TESTNAME=`basename $TESTSCRIPT .m`
# Create temp file for job submission with so-called "here document":
mkdir -p $LOGDIR
MATLABSCRIPT=`mktemp $LOGDIR/test_XXXXXXXX.m`
cat > $MATLABSCRIPT <<EOF
%-------------------------------------------------------------------------------
% this MATLAB script will be automatically removed when execution has finished
try
restoredefaultpath
addpath $FIELDTRIPDIR
addpath $FIELDTRIPDIR/test % for dccnpath
global ft_default
ft_default = [];
ft_default.feedback = 'no';
ft_default.checkconfig = 'loose';
ft_default.trackusage = 'no';
% ft_default.trackconfig = 'no';
ft_defaults
stopwatch = tic;
cd $TESTDIR
$TESTNAME
disp(sprintf('$TESTNAME PASSED in %d seconds', round(toc(stopwatch))));
catch err
disp(err)
disp(sprintf('$TESTNAME FAILED in %d seconds', round(toc(stopwatch))));
end
exit
%-------------------------------------------------------------------------------
EOF
MDIR=`dirname ${MATLABSCRIPT}`
MFUN=${MATLABSCRIPT##*/} # remove dir
MFUN=${MFUN%.*} # remove extension
# $HOME/bin/shmwait 15 # start different instances 10 seconds apart
if [[ $MATLABCMD == *"matlab"* ]]; then
$MATLABCMD -r "cd $MDIR ; $MFUN"
elif [[ $MATLABCMD == *"octave"* ]]; then
$MATLABCMD ${MATLABSCRIPT}
else
>&2 echo Error: unknown MATLABCMD $MATLABCMD
fi
# remove the temp file, not the actual FieldTrip test script
rm $MATLABSCRIPT