Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -238,11 +238,11 @@ (define (common:logpro-exit-code->status-sym exit-code) (or (alist-ref exit-code *common:logpro-exit-code->status-sym-alist*) 'fail)) (define (common:worse-status-sym ss1 ss2) - (let loop ((status-syms-remaining '(abort fail check warn waived pass))) + (let loop ((status-syms-remaining '(abort fail check skip warn waived pass))) (cond ((null? status-syms-remaining) 'fail) ((eq? (car status-syms-remaining) ss1) ss1) Index: ezsteps.scm ================================================================== --- ezsteps.scm +++ ezsteps.scm @@ -55,12 +55,12 @@ (test-name (db:test-get-testname testdat)) (kill-job #f)) ;; for future use (on re-factoring with launch.scm code ;; keep trying till NFS deigns to populate test run dir on this host (let loop ((count 5)) - (if (common:file-exists? test-run-dir) - (push-directory test-run-dir) + (if (not (common:file-exists? test-run-dir)) + ;;(push-directory test-run-dir) (if (> count 0) (begin (debug:print 0 *default-log-port* "WARNING: ezsteps attempting to run but test run directory " test-run-dir " is not there. Waiting and trying again " count " more times") (sleep 3) (loop (- count 1)))))) @@ -73,99 +73,87 @@ (message-window "ERROR: You can only re-run steps defined via ezsteps") (begin (let loop ((ezstep (car ezstepslst)) (tal (cdr ezstepslst)) (status-sym-so-far 'pass) - (prevstep "-") ;;(runflag #f) (saw-start-step-name #f)) ;; flag used to skip steps when not starting at the beginning - (if (vector-ref exit-info 1) (let* ((stepname (car ezstep)) ;; do stuff to run the step - (logpro-used (common:file-exists? (conc stepname ".logpro"))) + (logpro-used (common:file-exists? (conc test-run-dir "/" stepname ".logpro"))) (stepinfo (cadr ezstep)) (stepparts (string-match (regexp "^(\\{([^\\}]*)\\}\\s*|)(.*)$") stepinfo)) (stepparms (list-ref stepparts 2)) ;; for future use, {VAR=1,2,3}, run step for each (stepcmd (list-ref stepparts 3)) - (script (conc "mt_ezstep " stepname " " prevstep " " stepcmd)) ;; call the command using mt_ezstep + (script (conc "mt_ezstep '"test-run-dir"' '"stepname"' '"stepcmd"'")) ;; call the command using mt_ezstep (saw-start-step-name-next (or saw-start-step-name (equal? stepname start-step-name))) (proceed-with-this-step (or (not start-step-name) (equal? stepname start-step-name) (and saw-start-step-name (not run-one)) saw-start-step-name-next (and start-step-name (equal? stepname start-step-name))))) - (cond ((and (not proceed-with-this-step) (null? tal)) 'done) ((not proceed-with-this-step) (loop (car tal) (cdr tal) status-sym-so-far - stepname - ;; #f - saw-start-step-name-next))) - - (debug:print 4 *default-log-port* "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts - " stepparms: " stepparms " stepcmd: " stepcmd) - (debug:print 4 *default-log-port* "script: " script) - (rmt:teststep-set-status! run-id test-id stepname "start" "-" #f #f) - - ;; now launch the script - (let ((pid (process-run script))) - (let processloop ((i 0)) - (let-values (((pid-val exit-status exit-code)(process-wait pid #t))) - (mutex-lock! run-mutex) - (vector-set! exit-info 0 pid) - (vector-set! exit-info 1 exit-status) - (vector-set! exit-info 2 exit-code) - (mutex-unlock! run-mutex) - (if (eq? pid-val 0) - (begin - (thread-sleep! 1) - (processloop (+ i 1)))) - )) - (let ((exinfo (vector-ref exit-info 2)) - (logfna (if logpro-used (conc stepname ".html") ""))) - (rmt:teststep-set-status! run-id test-id stepname "end" exinfo #f logfna)) - - (if logpro-used - (rmt:test-set-log! run-id test-id (conc stepname ".html"))) - - ;; set the test final status - (let* ((this-step-status (cond - (logpro-used - (common:logpro-exit-code->status-sym (vector-ref exit-info 2))) - ((eq? (vector-ref exit-info 2) 0) - 'pass) - (else - 'fail))) - (overall-status-sym (common:worse-status-sym this-step-status status-sym-so-far)) - (overall-status-string (status-sym->string overall-status-sym))) - (debug:print 4 *default-log-port* "Exit value received: " (vector-ref exit-info 2) " logpro-used: " logpro-used - " this-step-status: " this-step-status " overall-status: " overall-status-sym) - ;;" next-status: " next-status " rollup-status: " rollup-status) - (set! rollup-status-string overall-status-string) - (set! rollup-status-sym overall-status-sym) - (tests:test-set-status! run-id test-id "RUNNING" overall-status-string #f #f))) - - (if (and - (not run-one) - (common:steps-can-proceed-given-status-sym rollup-status-sym) - (not (null? tal))) - (loop (car tal) - (cdr tal) - rollup-status-sym - stepname - ;; #f - saw-start-step-name-next))) - - ;; (if (and (steprun-good? logpro-used (vector-ref exit-info 2)) - ;; (not (null? tal))) - ;; (if (not run-one) ;; if we got here we completed the step, if run-one is true, stop - ;; (loop (car tal) (cdr tal) stepname runflag)))) + saw-start-step-name-next)) + (else + (debug:print 4 *default-log-port* "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts + " stepparms: " stepparms " stepcmd: " stepcmd) + (debug:print 4 *default-log-port* "script: " script) + (rmt:teststep-set-status! run-id test-id stepname "start" "-" #f #f) + + ;; now launch the script + (let ((pid (process-run script))) + (let processloop ((i 0)) + (let-values (((pid-val exit-status exit-code)(process-wait pid #t))) + (mutex-lock! run-mutex) + (vector-set! exit-info 0 pid) + (vector-set! exit-info 1 exit-status) + (vector-set! exit-info 2 exit-code) + (mutex-unlock! run-mutex) + (if (eq? pid-val 0) + (begin + (thread-sleep! 1) + (processloop (+ i 1)))) + )) + (let ((exinfo (vector-ref exit-info 2)) + (logfna (if logpro-used (conc stepname ".html") ""))) + (rmt:teststep-set-status! run-id test-id stepname "end" exinfo #f logfna)) + + (if logpro-used + (rmt:test-set-log! run-id test-id (conc stepname ".html"))) + + ;; set the test final status + (let* ((this-step-status (cond + (logpro-used + (common:logpro-exit-code->status-sym (vector-ref exit-info 2))) + ((eq? (vector-ref exit-info 2) 0) + 'pass) + (else + 'fail))) + (overall-status-sym (common:worse-status-sym this-step-status status-sym-so-far)) + (overall-status-string (status-sym->string overall-status-sym))) + (debug:print 4 *default-log-port* "Exit value received: " (vector-ref exit-info 2) " logpro-used: " logpro-used + " this-step-status: " this-step-status " overall-status: " overall-status-sym) + ;;" next-status: " next-status " rollup-status: " rollup-status) + (set! rollup-status-string overall-status-string) + (set! rollup-status-sym overall-status-sym) + (tests:test-set-status! run-id test-id "RUNNING" overall-status-string #f #f))) + + (if (and + (not run-one) + (common:steps-can-proceed-given-status-sym rollup-status-sym) + (not (null? tal))) + (loop (car tal) + (cdr tal) + rollup-status-sym + saw-start-step-name-next))))) (debug:print 4 *default-log-port* "WARNING: a prior step failed, stopping at " ezstep))) ;; Once done with step/steps update the test record ;; (let* ((item-path (db:test-get-item-path testdat)) ;; (item-list->path itemdat)) @@ -175,22 +163,10 @@ (let ((new-state (if kill-job "KILLED" "COMPLETED") ;; (if (eq? (vector-ref exit-info 2) 0) ;; exited with "good" status ;; "COMPLETED" ;; (db:test-get-state testinfo))) ;; else preseve the state as set within the test ) (new-status rollup-status-string) - - ;; (new-status (cond ;; bjbarcla -- what is this AUTO business?? - ;; ((not (vector-ref exit-info 1)) "FAIL") ;; job failed to run - ;; ((eq? rollup-status 0) - ;; ;; if the current status is AUTO the defer to the calculated value (i.e. leave this AUTO) - ;; (if (equal? (db:test-get-status testinfo) "AUTO") "AUTO" "PASS")) - ;; ((eq? rollup-status 1) "FAIL") - ;; ((eq? rollup-status 2) - ;; ;; if the current status is AUTO the defer to the calculated value but qualify (i.e. make this AUTO-WARN) - ;; (if (equal? (db:test-get-status testinfo) "AUTO") "AUTO-WARN" "WARN")) - ;; (else "FAIL"))) - ) ;; (db:test-get-status testinfo))) (debug:print-info 2 *default-log-port* "Test NOT logged as COMPLETED, (state=" (db:test-get-state testinfo) "), updating result, rollup-status is " rollup-status) (tests:test-set-status! run-id test-id new-state new-status @@ -200,11 +176,11 @@ (rmt:set-state-status-and-roll-up-items run-id test-name item-path new-state new-status #f)))) ;; for automated creation of the rollup html file this is a good place... (if (not (equal? item-path "")) (tests:summarize-items run-id test-id test-name #f)) ;; don't force - just update if no ))) - (pop-directory) + ;;(pop-directory) rollup-status-string)) (define (ezsteps:spawn-run-from testdat start-step-name run-one) (thread-start! (make-thread Index: utils/mt_ezstep ================================================================== --- utils/mt_ezstep +++ utils/mt_ezstep @@ -15,21 +15,12 @@ # 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 . -usage="mt_ezstep stepname prevstepname command [args ...]" - -if [[ "$MT_CMDINFO" == "" ]];then - if [[ -e megatest.sh ]];then - source megatest.sh - else - echo "ERROR: $0 should be run within a megatest test environment" - echo "Usage: $usage" - exit - fi -fi +usage="mt_ezstep stepname command [args ...]" + # Purpose: This is for the [ezsteps] secton in your testconfig file. # DO NOT USE IN YOUR SCRIPTS! # # Call like this: @@ -41,16 +32,15 @@ fi # Since the user may not have . on the path and since we are likely to want to # run test scripts in the current directory add the current dir to the path export PATH=$PATH:$PWD - +testrundir=$1; shift stepname=$1;shift -prevstepname=$1;shift + command=$* - allstatus=99 runstatus=99 logpropstatus=99 # prev_env=".ezsteps/${prevstepname}.sh" @@ -58,39 +48,36 @@ # if [[ -e "${prev_env}" ]];then # source $prev_env # fi # source the environment from the previous step if it exists +cd $testrundir +#if [[ "$MT_CMDINFO" == "" ]];then + if [[ -e megatest.sh ]];then + source megatest.sh + else + echo "ERROR: $0 should be run within a megatest test environment" + echo "Usage: $usage" + exit + fi +#fi + + # if a logpro file exists then use it otherwise just run the command, nb// was using 2>&1 if [[ -e ${stepname}.logpro ]];then - # could do: - $command 2>&1| tee ${stepname}.log | logpro ${stepname}.logpro ${stepname}.html &> /dev/null - logprostatus=$? - # $command 2>&1| logpro ${stepname}.logpro ${stepname}.html &> ${stepname}.log - # allstatus=(${PIPESTATUS[0]} ${PIPESTATUS[1]}) - allstatus=(${PIPESTATUS[0]} ${PIPESTATUS[1]}) - runstatus=${allstatus[0]} - # logprostatus=${allstatus[1]} -else - $command &> ${stepname}.log - runstatus=$? - logprostatus=$runstatus -fi - -# If the test exits with non-zero, we will record FAIL even if logpro -# says it is a PASS - -if [[ $runstatus -ne 0 ]]; then - exitstatus=$runstatus -elif [[ $logprostatus -eq 0 ]]; then - exitstatus=$logprostatus -elif [[ $logprostatus -eq 2 ]]; then - exitstatus=2 -elif [[ $logprostatus -eq 1 ]]; then - exitstatus=1 -else - exitstatus=0 -fi - -# $MT_MEGATEST -env2file .ezsteps/${stepname} + eval $command 2>&1 ${stepname}.log + runstatus=$? + logpro ${stepname}.logpro ${stepname}.html &> /dev/null < ${stepname}.log + logprostatus=$? + + if [[ $runstatus == 0 ]]; then + exitstatus=$logprostatus + else + exitstatus=$runstatus + fi +else + eval $command &> ${stepname}.log + exitstatus=$? +fi + exit $exitstatus