#!/bin/bash
#generate html report from nightly.log output file
cd $ISSM_DIR/test/Verification/NightlyRun/
#process nightly.log
TODAY=` cat nightly.log | grep "today" | awk '{printf("%s %s",$2,$3);}'`
USER=` cat nightly.log | grep "user" | awk '{print $2}'`
HOST_NAME=` cat nightly.log | grep "host" | awk '{print $2}'`
OS=` cat nightly.log | grep "OS" | awk '{print $2}'`
RELEASE=` cat nightly.log | grep "release" | awk '{print $2}'`
EL_INSTALL=`cat nightly.log | grep "elapsed_install" | awk '{print $2}'`
EL_RUN=` cat nightly.log | grep "elapsed_run" | awk '{print $2}'`
EL_TOTAL=` cat nightly.log | grep "elapsed_total" | awk '{print $2}'`
#Process matlab_log.log
cat matlab_log.log | egrep 'ERROR|SUCCESS|FAILURE' > matlab.log
NUM_TOT=`wc -l matlab.log | awk '{print $1}'`
NUM_ERR=`cat matlab.log | grep 'ERROR' | grep -v "PETSC ERROR" | wc -l`
NUM_SUC=`cat matlab.log | grep 'SUCCESS' | wc -l`
NUM_FAI=`cat matlab.log | grep 'FAILURE' | wc -l`
#style
H1_STYLE='width="1000px" cellpadding="20"'
H1_FONT='style="color:#6495ed; font-family:Arial, Verdana, Tahoma; font-weight: bold; font-size:35px;" align="center"'
H2_STYLE='width="900px" cellpadding="20"'
H2_FONT='style="color:#6495ed; font-family:Arial, Verdana, Tahoma; font-size:28px; font-weight: bold;" align="left"'
TABLE_STYLE='width="800px" 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"'
MATLAB_STYLE='width="1000px" rules=none'
MATLAB_FONT='style="color:#404040; font-family:Arial, Verdana, Tahoma; font-size:14px; font-weight: normal;" align="left"'
BODY_STYLE='width="1000px"'
BODY_FONT="style=\"color:#404040; font-family:Arial, Verdana, Tahoma; font-size:14px;\""
FOOTER_STYLE='width="800px" cellpadding="10"'
FOOTER_FONT='style="color:#404040; font-family:Arial, Verdana, Tahoma; font-size:12px; font-weight: normal;" align="center"'
#style 2
BODY_FONTC=`echo $BODY_FONT | sed -e "s/style=\"/style=\"text-align:center; /g"`
BODY_FONTL=`echo $BODY_FONT | sed -e "s/style=\"/style=\"text-align:left; /g"`
#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 matlab.log | awk '{printf("%s",$1);}') -eq 0 ]
then
IS_RUN=0
else
IS_RUN=1
fi
#build report.html
#first: summary
cat << END > summary.html
host: $HOST_NAME |
date: $TODAY |
OS: $OS |
user: $USER |
status: STATUS |
release: $RELEASE |
number of success: $NUM_SUC/$NUM_TOT
| total elapsed time: $EL_TOTAL |
number of errors: $NUM_ERR/$NUM_TOT
| installation elapsed time: $EL_INSTALL |
number of failures: $NUM_FAI/$NUM_TOT
| execution elapsed time: $EL_RUN |
END
#update status
if [ $IS_RUN -eq 1 ]
then
cat summary.html | sed -e "s/STATUS/
all test desks have been run<\/span>/g" > summary2.html
mv summary2.html summary.html
else
if [ $IS_INSTALL -eq 1 ]
then
cat summary.html | sed -e "s/STATUS/installation successful but tests runs failed<\/span>/g" > summary2.html
mv summary2.html summary.html
else
cat summary.html | sed -e "s/STATUS/installation failed<\/span>/g" > summary2.html
mv summary2.html summary.html
fi
fi
#Matlab error report
if [ -e matlaberror.log ]
then
cat << END > matlaberror.html
END
else
mktemp matlaberror.html
fi
#report content
if [ $IS_RUN -eq 1 ];
then
cat << END > content.html
Result |
Tolerance |
Test name |
Analysis |
Subanalysis |
Qmu |
Control |
Control fit |
Parallel |
Field checked |
$(cat matlab.log | while read line
do
echo ""
#get status
STATUS=`echo $line | awk '{print $1}'`
#FAILURE
if [ "$STATUS" = "FAILURE" ]
then
FONTC=$(echo "$BODY_FONTC bgcolor=#ffff00");
FONTL=$(echo "$BODY_FONTL bgcolor=#ffff00");
echo $line | awk -v FONTC="$FONTC" -v FONTL="$FONTL" '
{ printf("%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n",FONTL,$1,FONTC,"N/A",FONTL,$3,FONTL,$5,FONTL,$7,FONTC,$9,FONTC,$11,FONTC,$13,FONTC,$15,FONTC,"N/A");}
';
else
#SUCCESS
if [ "$STATUS" = "SUCCESS" ]
then
color="bgcolor=#ddffdd";
#ERROR
else
color="bgcolor=#ffdddd";
fi
FONTC=$(echo "$BODY_FONTC $color")
FONTL=$(echo "$BODY_FONTL $color")
echo $line | awk -v FONTC="$FONTC" -v FONTL="$FONTL" '
{ printf("%s | \n%s%s%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n%s | \n",FONTL,$1,FONTL,$3,$4,$5,FONTL,$7,FONTL,$9,FONTL,$11,FONTC,$13,FONTC,$15,FONTC,$17,FONTC,$19,FONTL,$21);}
';
fi
echo "
"
done
)
END
else
mktemp content.html
fi
#last footer
cat << END > footer.html
END
#concatenate files
cat summary.html matlaberror.html content.html footer.html > report.html
rm summary.html content.html footer.html matlaberror.html matlab.log