#!/bin/bash
#generate html report from nightly.log output file
#Process log
cat nightly.log | grep 'package: macayeal' | grep -v "not supported yet" > macayeal.log
cat nightly.log | grep 'package: ice' | grep -v "not supported yet" > ice.log
cat nightly.log | grep 'package: cielo_serial' | grep -v "not supported yet" > cielo_serial.log
cat nightly.log | grep 'package: cielo_parallel'| grep -v "not supported yet" > cielo_parallel.log
cat nightly.log | grep 'NIGHTLYRUNTERMINATEDCORRECTLY' > check.log
cat nightly.log | grep 'ERROR' | grep -v "PETSC ERROR" > errors.log
cat nightly.log | grep 'SUCCESS' > success.log
cat errors.log success.log > tests.log
#create some variables
if [ $(ls -1 $ISSM_DIR/bin | wc -l) -le 20 ];
then
IS_INSTALL=0
else
IS_INSTALL=1
fi
if [ $(wc -l nightly.log | awk '{printf("%s",$1);}') -eq 0 ]
then
IS_RUN=0
else
IS_RUN=1
fi
if [ $(wc -l check.log | awk '{printf("%s",$1);}') -eq 0 ]
then
IS_END=0
else
IS_END=1
fi
#style
H1_STYLE='width="800px" cellpadding="20"'
H1_FONT='style="color:#6495ed; font-family:Arial, Verdana, Tahoma; font-weight: bold; font-size:35px;" align="center"'
H2_STYLE='width="840px" cellpadding="20"'
H2_FONT='style="color:#6495ed; font-family:Arial, Verdana, Tahoma; font-size:28px; font-weight: bold;" align="left"'
TABLE_STYLE='width="820px" rules=none bgcolor="#ffffdd" border=1 bordercolor="#000000" cellpadding="3"'
TABLE_FONT='style="color:#404040; font-family:Arial, Verdana, Tahoma; font-size:14; font-weight: normal;" align="left"'
BODY_STYLE='width="820px"'
BODY_FONT="style=\"color:#404040; font-family:Arial, Verdana, Tahoma; font-size:14px;\""
NOTEST_STYLE='width="650px"'
NOTEST_FONT='style="color:#FF0000; font-family:Arial, Verdana, Tahoma; font-size:14px;" align="left"'
FOOTER_STYLE='width="800px" cellpadding="10"'
FOOTER_FONT='style="color:#404040; font-family:Arial, Verdana, Tahoma; font-size:12px; font-weight: normal;" align="center"'
#build report.html
#first: summary
cat << END > summary.html
host: $HOST_NAME |
date: $TODAY |
OS: $OS |
total elapsed time: $ELAPSED_TOTAL |
release: $ISSM_RELEASE |
installation elapsed time: $ELAPSED_INSTAL |
$(#print status
if [ $(echo $IS_INSTALL) = 0 ];
then
#installation failed, end of report
echo "status: installation failed | "
echo "execution elapsed time: $ELAPSED_RUN | "
echo "
"
echo "
"
rm check.log errors.log success.log tests.log
else
#installation successful. Did we go to the end?
if [ $(echo $IS_RUN) -eq 0 ];
then
#run failed, end of report
echo "
status: installation successful but tests runs failed | "
echo "
execution elapsed time: $ELAPSED_RUN | "
echo ""
echo ""
rm check.log errors.log success.log tests.log
else
if [ $(echo $IS_END) -eq 0 ];
then
echo "
status: stopped before the end | "
else
echo "
status: all test desks have been run | "
fi
echo "
execution elapsed time: $ELAPSED_RUN | "
echo ""
echo "
"
echo "number of errors: $(wc -l errors.log | awk '{printf("%s",$1);}')/$(wc -l tests.log | awk '{printf("%s",$1);}'; rm errors.log) | "
echo " | "
echo "
"
echo "
"
echo "number of success: $(wc -l success.log | awk '{printf("%s",$1);}')/$(wc -l tests.log | awk '{printf("%s",$1);}'; rm success.log tests.log) | "
echo " | "
echo "
"
echo ""
#draw a line and clean up
echo "
"
rm check.log
fi
fi)
END
#report content
if [ $(echo $IS_INSTALL) = 1 ];
then
cat << END > content.html
$(for package in "macayeal" "ice" "cielo_serial" "cielo_parallel"; do
#enter title
if [ $package == "macayeal" ];
then
echo "
"
fi
if [ $package == "ice" ];
then
echo "
"
fi
if [ $package == "cielo_serial" ];
then
echo "
"
fi
if [ $package == "cielo_parallel" ];
then
echo "
"
fi
#check that at least one Test exists
if [ `wc -l $package.log | awk '{printf("%s",$1);}'` = "0" ]; then
#No Test: use a table to fix entourage bug.
echo "
"
else
echo "
"
echo " Result | Tolerance | Test | Solution | Field |
"
# go through the lines of $package.log
COUNTER=0
MAX=`wc -l $package.log | awk '{printf("%s",$1);}'`
while [ $COUNTER -lt $MAX ]; do
let COUNTER=COUNTER+1
echo ""
#see wether it is success or error (get color: red or green)
if [ "`cat $package.log | awk '{ printf "line%so %s\n", NR, $0 }' | awk '/line'$COUNTER'o/ {printf("%s\n",$2);}';`" == "SUCCESS" ];
then
color="bgcolor=#ddffdd";
else
color="bgcolor=#ffdddd";
fi
FONT=$(echo "$BODY_FONT $color")
#build html corresponding line
cat $package.log | awk '{ printf "line%so %s\n", NR, $0 }' | awk -v FONT="$FONT" '
/line'$COUNTER'o/ { printf("%s | %s%s%s | %s | %s | %s | ",FONT,$2,FONT,$4,$5,$6,FONT,$8,FONT,$10,FONT,$14);}
';
echo "
"
done
echo "
"
fi
#remove log file
rm $package.log
done)
END
else
for package in "macayeal" "ice" "cielo_serial" "cielo_parallel"; do
rm $package.log
done
fi
#last footer
cat << END > footer.html
END
#concatenate files
if [ $IS_INSTALL -eq 1 ];
then
if [ $IS_END -eq 1 ];
then
cat summary.html content.html footer.html > report.html
rm summary.html content.html footer.html
else
cat summary.html footer.html > report.html
rm summary.html footer.html
fi
else
cat summary.html footer.html > report.html
rm summary.html footer.html
fi