source: issm/trunk-jpl/scripts/jenkins.sh@ 16597

Last change on this file since 16597 was 16597, checked in by Eric.Larour, 11 years ago

CHG: duplicate logs

  • Property svn:executable set to *
File size: 7.5 KB
Line 
1#!/bin/bash
2#This bash script calls the nightlyrun.m matlab file to run our nightly test decks.
3#It then processes the results and sends an email to the Ice developpers.
4
5#some functions
6function timer() #{{{
7{
8 if [[ $# -eq 0 ]]; then
9 echo $(date '+%s')
10 else
11 local stime=$1
12 etime=$(date '+%s')
13
14 if [[ -z "$stime" ]]; then stime=$etime; fi
15
16 dt=$((etime - stime))
17 ds=$((dt % 60))
18 dm=$(((dt / 60) % 60))
19 dh=$((dt / 3600))
20 printf '%d:%02d:%02d' $dh $dm $ds
21 fi
22} #}}}
23function todaydate() #{{{
24{
25 suffix=`date | awk '{printf("%s-%s-%s %s",$2,$3,$6,$4);}'`
26 echo $suffix;
27} #}}}
28function host_name() #{{{
29{
30 #return host name depending on the OS
31 if [ "$1" = "win7" ]
32 then
33 HOST_NAME=`hostname | sed 's/-//g'`;
34 else
35 HOST_NAME=`hostname -s | sed 's/-//g'`;
36 fi
37 echo $HOST_NAME;
38} #}}}
39function pause() #{{{
40{
41pid=`ps aux -W | grep $1 | awk '{printf("%s\n",$1);}'`
42
43while [ -n "$pid" ]
44do
45 pid=`ps aux -W | grep $1 | awk '{printf("%s\n",$1);}'`
46done
47}
48#}}}
49
50#Get configuration
51#Source config file{{{
52if [ $# -ne 1 ];
53then
54 #no config file specified: exit
55 echo "no config file specified. Exiting..." >&2 # Error message to stderr.
56 exit 1
57fi
58if [ ! -f "$1" ]
59then
60 echo "File $1 not found!" >&2 # Error message to stderr.
61 exit 1
62fi
63source $1;
64#}}}
65#Export ISSM_* variables{{{
66export ISSM_DIR
67export ISSM_ARCH
68#}}}
69#Initialize variables {{{
70TODAY=$(todaydate);
71HOST_NAME=$(host_name $OS);
72OS=$(uname -s)
73START_TIME=$(timer);
74ISSM_RELEASE=$(basename $(echo $REPOSITORY));
75USER=$(whoami);
76INIT_PATH=$(pwd);
77#}}}
78
79#Installation ISSM
80#create matlab's installation sript {{{
81cat << END > $ISSM_DIR/externalpackages/matlab/install.sh
82#!/bin/bash
83rm -rf install
84ln -s $MATLAB_PATH install
85END
86#}}}
87#install/copy/none external packages (ISSM_EXTERNALPACKAGES){{{
88if [ "$ISSM_EXTERNALPACKAGES" == "install" ]
89then
90
91 cd $ISSM_DIR/externalpackages
92
93 #number of packages:
94 NUMPACKAGES=$(($(echo $EXTERNALPACKAGES | wc -w )/2))
95
96 for ((i=1;i<=$NUMPACKAGES;i++))
97 do
98 NUM1=$((2*$i-1))
99 NUM2=$((2*$i))
100 PACKAGENAME=$(echo $EXTERNALPACKAGES | cut -d " " -f $NUM1-$NUM1)
101 PACKAGEINST=$(echo $EXTERNALPACKAGES | cut -d " " -f $NUM2-$NUM2)
102
103 cd $PACKAGENAME
104 echo "======================================================";
105 echo " Installing $PACKAGENAME ";
106 echo "======================================================";
107 ./$PACKAGEINST | compil.log
108 if [ $? -ne 0 ]; then
109 echo "======================================================";
110 echo " ERROR: installation of $PACKAGENAME failed ";
111 echo "======================================================";
112 fi
113 source $ISSM_DIR/etc/environment.sh
114 cd ..
115 done
116
117elif [ "$ISSM_EXTERNALPACKAGES" == "copy" ]
118then
119 cd $ISSM_DIR
120 rm -rf externalpackages
121 cp -Rf $EXTERNALPACKAGESDIR ./
122elif [ "$ISSM_EXTERNALPACKAGES" == "link" ]
123then
124 cd $ISSM_DIR
125 rm -rf externalpackages
126 ln -s $EXTERNALPACKAGESDIR .
127elif [ "$ISSM_EXTERNALPACKAGES" == "none" ]
128then
129 echo "Skipping external packages installation"
130else
131 echo "ISSM_EXTERNALPACKAGES supported values are: install, copy and none. Exiting..." >&2 # Error message to stderr.
132 exit 1
133fi
134source $ISSM_DIR/etc/environment.sh
135#}}}
136#ISSM compilation yes/no (ISSM_COMPILATION) {{{
137if [ "$ISSM_COMPILATION" == "yes" ]
138then
139 cd $ISSM_DIR
140 make uninstall
141 make clean
142 make distclean
143 ./scripts/automakererun.sh
144 cat > configure.sh << EOF
145./configure $ISSM_CONFIG
146EOF
147 chmod 700 configure.sh
148 ./configure.sh
149
150 #4: compile and install ISSM
151 if [ $NUMCPUS_INSTALL -gt 1 ]
152 then
153 echo "Making with " $NUMCPUS_INSTALL " cpus"
154 make -j $NUMCPUS_INSTALL install
155 else
156 make install
157 fi
158elif [ "$ISSM_COMPILATION" == "no" ]
159then
160 echo "Skipping ISSM compilation"
161else
162 echo "ISSM_COMPILATION supported values are: yes and no. Exiting..." >&2 # Error message to stderr.
163 exit 1
164fi
165#}}}
166
167#Prepare info.log
168#{{{
169rm -rf $ISSM_DIR/nightlylog
170mkdir $ISSM_DIR/nightlylog
171INSTALL_TIME=$(timer)
172ELAPSED=$(timer $START_TIME)
173VERSION=$(svnversion $ISSM_DIR)
174cat << END > $ISSM_DIR/nightlylog/info.log
175name: $(echo $NAME)
176today: $(echo $TODAY)
177user: $(echo $USER)
178host: $(echo $HOST_NAME)
179OS: $(echo $OS)
180release: $(echo $ISSM_RELEASE)
181init_path: $(echo $INIT_PATH)
182is_matlab: $(echo $MATLAB_TEST)
183is_python: $(echo $PYTHON_TEST)
184elapsed_install: $(echo $ELAPSED)
185version: $(echo $VERSION)
186END
187#}}}
188
189#matlab tests
190if [ $MATLAB_TEST -eq 1 ]; then
191#Launch all tests on different cpus {{{
192MATLAB_START_TIME=$(timer);
193for (( i=1;i<=$NUMCPUS_RUN;i++ ))
194do
195 #Launch matlab and the nightly run script
196 cat > $ISSM_DIR/nightlylog/matlab_run$i.m << EOF
197 warning off %necessary to avoid a info.log of several Go for parallel runs
198 try,
199 $(if [ "$MATLAB_NROPTIONS" = "" ]
200 then
201 echo "runme('output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
202 else
203 echo "runme($MATLAB_NROPTIONS,'output','nightly','rank',$i,'numprocs',$NUMCPUS_RUN);"
204 fi
205 )
206 catch me,
207 %An error occured, get report and exit
208 message=getReport(me)
209 directory=strsplit(pwd,'/');
210 fid=fopen([issmdir '/nightlylog/matlaberror.log'], 'at');
211 fprintf(fid,'\nMatlab error occured in: %s\n\n',directory{end});
212 fprintf(fid,'%s',message);
213 fclose(fid);
214 end
215 disp('MATLABEXITEDCORRECTLY');
216 exit
217EOF
218 cd $ISSM_DIR/test/NightlyRun
219 matlab -nojvm -nosplash -r "addpath $ISSM_DIR/src/m/dev; devpath; addpath $ISSM_DIR/nightlylog/; matlab_run$i" -logfile $ISSM_DIR/nightlylog/matlab_log$i.log &
220done
221
222#wait until matlab closes
223if [ "$OS" = "win7" ]; then
224 pause MATLAB
225else
226 wait
227fi
228
229#concatenate reports
230cd $ISSM_DIR/nightlylog/
231rm matlab_log.log
232for (( i=1;i<=$NUMCPUS_RUN;i++ ))
233do
234 cat matlab_log$i.log >> matlab_log.log
235done
236#}}}
237#Complete info.log {{{
238if [ $(cat matlab_log.log | grep "MATLABEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]
239then
240 MATLABCRASH=0
241else
242 MATLABCRASH=1
243fi
244ELAPSED=$(timer $MATLAB_START_TIME)
245cat << END >> $ISSM_DIR/nightlylog/info.log
246elapsed_matlab: $(echo $ELAPSED)
247matlab_crash: $(echo $MATLABCRASH)
248END
249#}}}
250fi
251
252#python tests
253if [ $PYTHON_TEST -eq 1 ]; then
254#Launch all tests on different cpus {{{
255PYTHON_START_TIME=$(timer);
256export PYTHONSTARTUP=$ISSM_DIR/src/m/dev/devpath.py
257for (( i=1;i<=$NUMCPUS_RUN;i++ ))
258do
259 cd $ISSM_DIR/test/NightlyRun
260 ./runme.py --output=nightly --rank=$i --numprocs=$NUMCPUS_RUN $PYTHON_NROPTIONS 2>&1 > $ISSM_DIR/nightlylog/python_log$i.log &
261done
262
263#wait until python closes
264if [ "$OS" = "win7" ]; then
265 pause MATLAB
266else
267 wait
268fi
269
270#concatenate reports
271cd $ISSM_DIR/nightlylog/
272rm python_log.log
273for (( i=1;i<=$NUMCPUS_RUN;i++ ))
274do
275 cat python_log$i.log >> python_log.log
276done
277#}}}
278#Complete info.log {{{
279if [ $(cat python_log.log | grep "PYTHONEXITEDCORRECTLY" | wc -l) -eq $NUMCPUS_RUN ]
280then
281 PYTHONCRASH=0
282else
283 PYTHONCRASH=1
284fi
285ELAPSED=$(timer $PYTHON_START_TIME)
286cat << END >> $ISSM_DIR/nightlylog/info.log
287elapsed_python: $(echo $ELAPSED)
288python_crash: $(echo $PYTHONCRASH)
289END
290#}}}
291fi
292
293#complete info.log
294#{{{
295ELAPSED=$(timer $START_TIME)
296cat << END >> $ISSM_DIR/nightlylog/info.log
297elapsed_total: $(echo $ELAPSED)
298END
299#}}}
300
301#Send Report
302#Build html report {{{
303cd $ISSM_DIR/nightlylog/
304sh ../scripts/report.sh
305echo "html report located in $ISSM_DIR/nightlylog/report.html"
306#}}}
307#send mail if requested (SKIPMAIL) {{{
308if [ "$SKIPMAIL" != "yes" ]
309then
310 echo "sending report..."
311 for i in `echo $MAILINGLIST`; do
312
313cat - $ISSM_DIR/nightlylog/report.html <<HERE | /usr/lib/sendmail -oi -t
314From: "ISSM Nightly run" <$EMAIL_ADRESS>
315To: $i
316Subject: ISSM nightly runs report: $NAME
317Mime-Version: 1.0
318Content-Type: text/html
319HERE
320 done
321fi
322#}}}
323
324#remove lock file
325#{{{
326cd $ISSM_DIR/../
327rm NIGHTLYLOCK
328#}}}
Note: See TracBrowser for help on using the repository browser.