Megatest

mt_laststep at [55d3f1d05d]
Login

File utils/mt_laststep artifact fae58533b9 part of check-in 55d3f1d05d


#!/bin/bash

#  Copyright 2006-2017, Matthew Welland.
# 
# This file is part of Megatest.
# 
#     Megatest is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
# 
#     Megatest is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.

if [ $MT_CMDINFO == "" ];then
  echo "ERROR: $0 should be run within a megatest test environment"
  exit
fi

# Purpose: run a step, record start and end with exit codes, if sucessful
# update test status with PASS, else update with FAIL
#
# Call like this:
# mt_laststep stepname command ....
# 
# This expects that you have a logpro file named stepname.logpro and must be run
# inside a test environment (click on xterm button on a test control panel
# then source megatest.csh (if you are using tcsh) or megatest.sh (if you are using
# bash, sh or zsh)
# 
# Example: copy files
# mt_runstep copy_files cp $frompath $topath
#
# Use a copy_files.logpro file like this:
# (expect:error in "LogFileBody" = 0 "Any err/error/warn/warning" #/(err|warn)/)
# 
stepname=$1;shifttepname"

echo "stepname=$s
# Theoretically could call megatest directly like the following line but
# we'll do each individual step so folks can see what is going on.
#
# $MT_MEGATEST -runstep $stepname -logpro ${stepname}.logpro "$*" || exit $?

# First, register the start of this step
$MT_MEGATEST -step $stepname :state start :status n/a 

# Second, run the command (the remaining stuff on the command line after the stepname)
# We could put the results in a log file for processing but we are relying on logpro...
# $* 2>&1 ${stepname}.log

# So lets use a pipe to logpro, put the output from logpro into stepname_logpro.log
$* 2>&1| logpro ${stepname}.logpro ${stepname}.html 2>&1 ${stepname}_logpro.log 

allstatus=(${PIPESTATUS[0]} ${PIPESTATUS[1]})
runstatus=${allstatus[0]}
logprostatus=${allstatus[1]}

echo runstatus: $runstatus logprostatus: $logprostatus

# Record the step completion and exit status
$MT_MEGATEST -step $stepname :state end :status $runstatus

# If the test exits with non-zero, we will record FAIL even if logpro
# says it is a PASS

if [ $runstatus -ne 0 ]; then
    finalstatus=FAIL
    exitstatus=$runstatus
elif [ $logprostatus -eq 0 ]; then
    finalstatus=PASS
    exitstatus=$logprostatus
elif [ $logprostatus -eq 2 ]; then
    finalstatus=WARN
    exitstatus=0
else 
    finalstatus=FAIL
    exitstatus=1
fi

# test ${logprostatus} -eq 0 && finalstatus="PASS"
# test ${logprostatus} -eq 1 && finalstatus="FAIL"
# test ${logprostatus} -eq 2 && finalstatus="WARN"
# test ${logprostatus} -gt 2 && finalstatus="FAIL"

# Set the final test status
$MT_MEGATEST -test-status :state COMPLETED :status $finalstatus

exit $exitstatus