1 | #!/bin/bash
|
---|
2 | #This bash script calls the dailyrun.m matlab file to run our daily test decks.
|
---|
3 | #It then processes the results and sends an email to the Ice developpers.
|
---|
4 |
|
---|
5 | #Hard coded options
|
---|
6 | NUMCPUS_RUN=7
|
---|
7 | NROPTIONS=""
|
---|
8 |
|
---|
9 | #some functions
|
---|
10 | function timer() #{{{1
|
---|
11 | {
|
---|
12 | if [[ $# -eq 0 ]]; then
|
---|
13 | echo $(date '+%s')
|
---|
14 | else
|
---|
15 | local stime=$1
|
---|
16 | etime=$(date '+%s')
|
---|
17 |
|
---|
18 | if [[ -z "$stime" ]]; then stime=$etime; fi
|
---|
19 |
|
---|
20 | dt=$((etime - stime))
|
---|
21 | ds=$((dt % 60))
|
---|
22 | dm=$(((dt / 60) % 60))
|
---|
23 | dh=$((dt / 3600))
|
---|
24 | printf '%d:%02d:%02d' $dh $dm $ds
|
---|
25 | fi
|
---|
26 | } #}}}
|
---|
27 | function todaydate() #{{{1
|
---|
28 | {
|
---|
29 | suffix=`date | awk '{printf("%s-%s-%s %s",$2,$3,$6,$4);}'`
|
---|
30 | echo $suffix;
|
---|
31 | } #}}}
|
---|
32 | function host_name() #{{{1
|
---|
33 | {
|
---|
34 | #return host name depending on the OS
|
---|
35 | if [ "$1" = "winxp32" ]
|
---|
36 | then
|
---|
37 | HOST_NAME=`hostname`;
|
---|
38 | else
|
---|
39 | HOST_NAME=`hostname -s`;
|
---|
40 | fi
|
---|
41 | echo $HOST_NAME;
|
---|
42 | } #}}}
|
---|
43 |
|
---|
44 | #Get configuration
|
---|
45 | #Initialize variables {{{1
|
---|
46 | TODAY=$(todaydate);
|
---|
47 | HOST_NAME=$(host_name $OS);
|
---|
48 | START_TIME=$(timer);
|
---|
49 | ISSM_RELEASE="N/A"
|
---|
50 | USER=$(whoami);
|
---|
51 | INIT_PATH=$(pwd);
|
---|
52 | #}}}
|
---|
53 |
|
---|
54 | #Prepare run
|
---|
55 | #Windows hack for startup.m {{{1
|
---|
56 | #windows environments: ISSM_DIR_WIN variable not correctly picked up when using
|
---|
57 | #the cron job. just get startup to take the ISSM_DIR variable as the pwd:
|
---|
58 | if [ "$OS" = "winxp32" ]
|
---|
59 | then
|
---|
60 | cat startup.m | sed 's/clear status/clear status; ISSM_DIR=pwd;/g' > startup.m.bak
|
---|
61 | mv startup.m.bak startup.m
|
---|
62 | fi
|
---|
63 | #}}}
|
---|
64 | #create softlink to startup {{{1
|
---|
65 | cd $ISSM_DIR/test/NightlyRun/
|
---|
66 | ln -s $ISSM_DIR/startup.m .
|
---|
67 | #}}}
|
---|
68 | #Create dailylog directory and info.log {{{1
|
---|
69 | #put installation elapsed time in info.log
|
---|
70 | INSTALL_TIME=$(timer)
|
---|
71 | ELAPSED_INSTALL=$(timer $START_TIME)
|
---|
72 | rm -rf $ISSM_DIR/dailylog
|
---|
73 | mkdir $ISSM_DIR/dailylog
|
---|
74 | cat << END > $ISSM_DIR/dailylog/info.log
|
---|
75 | today: $(echo $TODAY)
|
---|
76 | user: $(echo $USER)
|
---|
77 | host: $(echo $HOST_NAME)
|
---|
78 | OS: N/A
|
---|
79 | release: N/A
|
---|
80 | init_path: $(echo $INIT_PATH)
|
---|
81 | elapsed_install: $(echo $ELAPSED_INSTALL)
|
---|
82 | END
|
---|
83 | #}}}
|
---|
84 | #check NUMCPUS_RUN options {{{1
|
---|
85 | if [ "$NUMCPUS_RUN" = "" ]
|
---|
86 | then
|
---|
87 | echo "NUMCPUS_RUN option not found, defaulting to NUMCPUS_RUN = 1"
|
---|
88 | NUMCPUS_RUN=1
|
---|
89 | fi
|
---|
90 | #}}}
|
---|
91 |
|
---|
92 | #Run tests
|
---|
93 | #Launch all tests on different cpus {{{1
|
---|
94 | for (( i=1;i<=$NUMCPUS_RUN;i++ ))
|
---|
95 | do
|
---|
96 | #Launch matlab and the daily run script
|
---|
97 | cat > $ISSM_DIR/dailylog/matlab_run$i.m << EOF
|
---|
98 | warning off %necessary to avoid a info.log of several Go for parallel runs
|
---|
99 | try,
|
---|
100 | cd $ISSM_DIR/test/NightlyRun
|
---|
101 | startup;
|
---|
102 | $(if [ "$NROPTIONS" = "" ]
|
---|
103 | then
|
---|
104 | echo "runme('output','daily','rank',$i,'numprocs',$NUMCPUS_RUN);"
|
---|
105 | else
|
---|
106 | echo "runme($NROPTIONS,'output','daily','rank',$i,'numprocs',$NUMCPUS_RUN);"
|
---|
107 | fi
|
---|
108 | )
|
---|
109 | catch me,
|
---|
110 | %An error occured, get report and exit
|
---|
111 | directory=strsplit(pwd,'/');
|
---|
112 | message=getReport(me)
|
---|
113 | fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
|
---|
114 | fprintf(fid,'\nMatlab error occured in: %s\n\n',directory{end});
|
---|
115 | fprintf(fid,'%s',message);
|
---|
116 | fclose(fid);
|
---|
117 | end
|
---|
118 | disp('MATLABEXITEDCORRECTLY');
|
---|
119 | exit
|
---|
120 | EOF
|
---|
121 |
|
---|
122 | #Start run from dailylog directory
|
---|
123 | cd $ISSM_DIR/dailylog/
|
---|
124 |
|
---|
125 | #Start test
|
---|
126 | MATLAB_VERSION="7.6" #7.2,7.4,7.6 and 7.8
|
---|
127 | /usr/local/pkgs/matlab-$MATLAB_VERSION/bin/matlab -nojvm -nosplash -r matlab_run$i -logfile matlab_log$i.log &
|
---|
128 | done
|
---|
129 |
|
---|
130 | #wait until matlab closes
|
---|
131 | wait
|
---|
132 | #}}}
|
---|
133 | #concatenate all reports {{{1
|
---|
134 | cd $ISSM_DIR/dailylog/
|
---|
135 | mv matlab_log1.log matlab_log.log
|
---|
136 | for (( i=2;i<=$NUMCPUS_RUN;i++ ))
|
---|
137 | do
|
---|
138 | cat matlab_log.log matlab_log$i.log > matlab_log.log.bak
|
---|
139 | mv matlab_log.log.bak matlab_log.log
|
---|
140 | done
|
---|
141 | #}}}
|
---|
142 | #Complete info.log {{{1
|
---|
143 | if [ $(cat matlab_log.log | grep "MATLABEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]
|
---|
144 | then
|
---|
145 | MATLABCRASH=0
|
---|
146 | else
|
---|
147 | MATLABCRASH=1
|
---|
148 | fi
|
---|
149 | ELAPSED_RUN=$(timer $INSTALL_TIME)
|
---|
150 | ELAPSED_TOTAL=$(timer $START_TIME)
|
---|
151 | cat << END >> $ISSM_DIR/dailylog/info.log
|
---|
152 | elapsed_run: $(echo $ELAPSED_RUN)
|
---|
153 | elapsed_total: $(echo $ELAPSED_TOTAL)
|
---|
154 | matlab_crash: $(echo $MATLABCRASH)
|
---|
155 | END
|
---|
156 | #}}}
|
---|
157 |
|
---|
158 | #Send Report
|
---|
159 | #Build html report {{{1
|
---|
160 | cd $ISSM_DIR/dailylog/
|
---|
161 | sh ../scripts/report.sh
|
---|
162 | ln -s $ISSM_DIR/dailylog/report.html $INIT_PATH
|
---|
163 | echo "html report located in $ISSM_DIR/dailylog/report.html and $INIT_PATH/report.html"
|
---|
164 | #}}}
|
---|