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

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

CHG new nightly system using jenkins, testing

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