export AUTOTEST_RESULT_DIR="$AUTOTEST_PATH/result/$AUTOTEST_PROFILE"
export AUTOTEST_CURRENT_RESULT_DIR="$AUTOTEST_RESULT_DIR/current"
export AUTOTEST_PROPER_RESULT_DIR="$AUTOTEST_RESULT_DIR/proper"
+export AUTOTEST_DIFF_RESULT_DIR="$AUTOTEST_RESULT_DIR/diff"
AUTOTEST_TARGET_PATH="/home/owner/autotest.sh"
+AUTOTEST_RESULT_FILE="$AUTOTEST_DIFF_RESULT_DIR/result.html"
LOG_TAG_LEN=`echo $LOG_TAG | wc -c`
CMD_TAG_LEN=`echo $CMD_TAG | wc -c`
rm $AUTOTEST_CURRENT_RESULT_DIR/$WORKSPACE_LINK_NAME
}
+function check_prerequsites() {
+ IMAGEMAGICK_INSTALL_FILE="imagemagick"
+ IMAGEMAGICK_TOOL="compare.im6"
+ HAS_IMAGEMAGICK_TOOL=`which $IMAGEMAGICK_TOOL`
+ if [ -z $HAS_IMAGEMAGICK_TOOL ]; then
+ echo "This script needs $IMAGEMAGICK_INSTALL_FILE file, but was unable to find it. Please refer to the below command."
+ echo "\"sudo apt-get install $IMAGEMAGICK_INSTALL_FILE\""
+ cleanup
+ exit;
+ fi
+}
+
+function get_comparing_result() {
+ rm -rf $AUTOTEST_DIFF_RESULT_DIR
+ mkdir -p $AUTOTEST_DIFF_RESULT_DIR
+
+ while read -d '' -r; do
+ current_file+=("$REPLY")
+ done < <(find $AUTOTEST_CURRENT_RESULT_DIR -type f -print0)
+
+ if find "$AUTOTEST_PROPER_RESULT_DIR" -maxdepth 0 -empty | read; then
+ echo "$AUTOTEST_PROPER_RESULT_DIR is empty."
+ cleanup
+ exit;
+ fi
+
+ for i in ${!current_file[@]}; do
+ proper_file="${current_file[$i]//current/proper}"
+ new_file="${current_file[$i]//current/diff}"
+ if [[ -f $proper_file ]]; then
+ if [[ ! -d `dirname "$new_file"` ]]; then
+ mkdir -p `dirname "$new_file"`
+ fi
+ filename=$(basename "${current_file[$i]}")
+ extension="${filename##*.}"
+ if [[ "$extension" == "png" ]]; then
+ imagemagick_output=`compare.im6 -verbose -metric PSNR ${current_file[$i]} $proper_file $new_file 2>&1`
+ if [[ ! "$imagemagick_output" =~ "all: inf" ]]; then
+ diff_file+=(${current_file[$i]})
+ fi
+ else
+ if [[ ! "$(cat ${current_file[$i]})" =~ "$(cat $proper_file)" ]]; then
+ diff_file+=(${current_file[$i]})
+ fi
+ fi
+ else
+ echo "No such file = $proper_file"
+ fi
+ done
+
+ echo "<html><head></head><style>.container{display: -webkit-flex;}.item{flex:1 1 0;padding:10px;float:center;margin:10px auto;}</style>" > $AUTOTEST_RESULT_FILE
+ echo "<body><div class=\"container\">" >> $AUTOTEST_RESULT_FILE
+ for ((i=1; i<=3; i++)); do
+ echo "<div class=\"item item-$i\"><div style=\"text-align: center;\">" >> $AUTOTEST_RESULT_FILE
+ if [[ $i == "1" ]]; then
+ echo "<h1>Current Image</h1>" >> $AUTOTEST_RESULT_FILE
+ elif [[ $i == "2" ]]; then
+ echo "<h1>Proper Image</h1>" >> $AUTOTEST_RESULT_FILE
+ elif [[ $i == "3" ]]; then
+ echo "<h1>Comparing Result</h1>" >> $AUTOTEST_RESULT_FILE
+ fi
+ for j in ${!diff_file[@]}; do
+ filename=$(basename "${diff_file[$j]}")
+ extension="${filename##*.}"
+ if [[ $i == "1" ]]; then
+ if [[ "$extension" == "png" ]]; then
+ echo "<br><img style=\"width: 100%;\" src=\"${diff_file[$j]}\"><br>$(basename ${diff_file[$j]})" >> $AUTOTEST_RESULT_FILE
+ else
+ echo "<br>$(basename ${diff_file[$j]})<br>$(cat ${diff_file[$j]})" >> $AUTOTEST_RESULT_FILE
+ fi
+ elif [[ $i == "2" ]]; then
+ if [[ "$extension" == "png" ]]; then
+ echo "<br><img style=\"width: 100%;\" src=\"${diff_file[$j]//current/proper}\"><br>$(basename ${diff_file[$j]})" >> $AUTOTEST_RESULT_FILE
+ else
+ echo "<br>$(basename ${diff_file[$j]})<br>$(cat ${diff_file[$j]//current/proper})" >> $AUTOTEST_RESULT_FILE
+ fi
+ elif [[ $i == "3" ]]; then
+ if [[ "$extension" == "png" ]]; then
+ echo "<br><img style=\"width: 100%;\" src=\"${diff_file[$j]//current/diff}\"><br>$(basename ${diff_file[$j]})" >> $AUTOTEST_RESULT_FILE
+ else
+ echo "<br><br>" >> $AUTOTEST_RESULT_FILE
+ fi
+ fi
+ echo "<br><br><br>" >> $AUTOTEST_RESULT_FILE
+ done
+ echo "</div></div>" >> $AUTOTEST_RESULT_FILE
+ done
+ echo "</div></body></html>" >> $AUTOTEST_RESULT_FILE
+
+ XDG_TOOL="xdg-open"
+ HAS_XDG_TOOL=`which $XDG_TOOL`
+ if [ -z $HAS_XDG_TOOL ]; then
+ echo "Please check the $AUTOTEST_RESULT_FILE for the result."
+ else
+ xdg-open "$AUTOTEST_RESULT_FILE"
+ fi
+}
+
prepare
while read -r line
fi
done < <(sdb $AUTOTEST_SDB_MODE shell "$AUTOTEST_TARGET_PATH" 2>&1)
+check_prerequsites
+
+get_comparing_result
+
cleanup