Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -9,11 +9,11 @@ GUISRCF = dashboard.scm dashboard-tests.scm OFILES = $(SRCFILES:%.scm=%.o) GOFILES = $(GUISRCF:%.scm=%.o) -HELPERS=$(addprefix $(PREFIX)/bin/,mt_laststep mt_runstep) +HELPERS=$(addprefix $(PREFIX)/bin/,mt_laststep mt_runstep mt_ezstep) all : megatest dboard megatest: $(OFILES) megatest.o csc $(OFILES) megatest.o -o megatest @@ -30,12 +30,11 @@ %.o : %.scm csc -c $< $(PREFIX)/bin/megatest : megatest - @echo Installing to PREFIX=$(PREFIX), use ^C to cancel and change - sleep 2 + @echo Installing to PREFIX=$(PREFIX) cp megatest $(PREFIX)/bin/megatest $(HELPERS) : utils/mt_* cp $< $@ chmod a+x $@ Index: configf.scm ================================================================== --- configf.scm +++ configf.scm @@ -35,11 +35,11 @@ (define (config:assoc-safe-add alist key val) (let ((newalist (filter (lambda (x)(not (equal? key (car x)))) alist))) (append newalist (list (list key val))))) -;; read a config file, returns two level hierarchial hash-table, +;; read a config file, returns hash table of alists ;; adds to ht if given (must be #f otherwise) (define (read-config path ht allow-system) (if (not (file-exists? path)) (if (not ht)(make-hash-table) ht) (let ((inp (open-input-file path)) Index: launch.scm ================================================================== --- launch.scm +++ launch.scm @@ -11,11 +11,11 @@ ;;====================================================================== ;; launch a task - this runs on the originating host, tests themselves ;; ;;====================================================================== -(use regex regex-case base64 sqlite3) +(use regex regex-case base64 sqlite3 srfi-18) (import (prefix base64 base64:)) (import (prefix sqlite3 sqlite3:)) (declare (unit launch)) (declare (uses common)) @@ -23,27 +23,39 @@ (declare (uses db)) (include "common_records.scm") (include "key_records.scm") (include "db_records.scm") + +;;====================================================================== +;; ezsteps +;;====================================================================== + +;; ezsteps were going to be coded as +;; stepname[,predstep1,predstep2 ...] [{VAR1=first,second,third}] command to execute +;; BUT +;; now are +;; stepname {VAR=first,second,third ...} command ... + (define (launch:execute encoded-cmd) (let* ((cmdinfo (read (open-input-string (base64:base64-decode encoded-cmd))))) (setenv "MT_CMDINFO" encoded-cmd) (if (list? cmdinfo) ;; ((testpath /tmp/mrwellan/jazzmind/src/example_run/tests/sqlitespeed) (test-name sqlitespeed) (runscript runscript.rb) (db-host localhost) (run-id 1)) (let* ((testpath (assoc/default 'testpath cmdinfo)) (work-area (assoc/default 'work-area cmdinfo)) (test-name (assoc/default 'test-name cmdinfo)) (runscript (assoc/default 'runscript cmdinfo)) + (ezsteps (assoc/default 'ezsteps cmdinfo)) (db-host (assoc/default 'db-host cmdinfo)) (run-id (assoc/default 'run-id cmdinfo)) (itemdat (assoc/default 'itemdat cmdinfo)) (env-ovrd (assoc/default 'env-ovrd cmdinfo)) (runname (assoc/default 'runname cmdinfo)) (megatest (assoc/default 'megatest cmdinfo)) (mt-bindir-path (assoc/default 'mt-bindir-path cmdinfo)) - (fullrunscript (conc testpath "/" runscript)) + (fullrunscript (if runscript (conc testpath "/" runscript) #f)) (db #f)) (debug:print 2 "Exectuing " test-name " on " (get-host-name)) (change-directory testpath) (setenv "MT_TEST_RUN_DIR" work-area) (setenv "MT_TEST_NAME" test-name) @@ -67,11 +79,11 @@ (save-environment-as-files "megatest") (test-set-meta-info db run-id test-name itemdat) (test-set-status! db run-id test-name "REMOTEHOSTSTART" "n/a" itemdat (args:get-arg "-m") #f) (if (args:get-arg "-xterm") (set! fullrunscript "xterm") - (if (not (file-execute-access? fullrunscript)) + (if (and fullrunscript (not (file-execute-access? fullrunscript))) (system (conc "chmod ug+x " fullrunscript)))) ;; We are about to actually kick off the test ;; so this is a good place to remove the records for ;; any previous runs ;; (db:test-remove-steps db run-id testname itemdat) @@ -81,30 +93,83 @@ ;; contention or stuck access on nfs. (sqlite3:finalize! db) (let* ((m (make-mutex)) (kill-job? #f) - (exit-info (make-vector 3)) + (exit-info (vector #t #t #t)) (job-thread #f) (runit (lambda () ;; (let-values ;; (((pid exit-status exit-code) ;; (run-n-wait fullrunscript))) - (let ((pid (process-run fullrunscript))) - (let loop ((i 0)) - (let-values - (((pid-val exit-status exit-code) (process-wait pid #t))) - (mutex-lock! m) - (vector-set! exit-info 0 pid) - (vector-set! exit-info 1 exit-status) - (vector-set! exit-info 2 exit-code) - (mutex-unlock! m) - (if (eq? pid-val 0) - (begin - (thread-sleep! 2) - (loop (+ i 1))) - )))))) + + ;; if there is a runscript do it first + (if fullrunscript + (let ((pid (process-run fullrunscript))) + (let loop ((i 0)) + (let-values + (((pid-val exit-status exit-code) (process-wait pid #t))) + (mutex-lock! m) + (vector-set! exit-info 0 pid) + (vector-set! exit-info 1 exit-status) + (vector-set! exit-info 2 exit-code) + (mutex-unlock! m) + (if (eq? pid-val 0) + (begin + (thread-sleep! 2) + (loop (+ i 1))) + ))))) + ;; then, if runscript ran ok (or did not get called) + ;; do all the ezsteps (if any) + (if ezsteps + (let* ((testconfig (read-config (conc work-area "/testconfig") #f #t)) ;; FIXME??? is allow-system ok here? + (ezstepslst (hash-table-ref/default testconfig "ezsteps" '()))) + (if (not (file-exists? ".ezsteps"))(create-directory ".ezsteps")) + ;; if ezsteps was defined then we are sure to have at least one step but check anyway + (if (not (> (length ezstepslst) 0)) + (debug:print 0 "ERROR: ezsteps defined but ezstepslst is zero length") + (let loop ((ezstep (car ezstepslst)) + (tal (cdr ezstepslst)) + (prevstep #f)) + ;; check exit-info (vector-ref exit-info 1) + (if (vector-ref exit-info 1) + (let* ((stepname (car ezstep)) ;; do stuff to run the step + (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 "#!/bin/bash\n")) ;; yep, we depend on bin/bash FIXME!!! + ;; NB// can safely assume we are in test-area directory + (debug:print 4 "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts + " stepparms: " stepparms " stepcmd: " stepcmd) + + ;; first source the previous environment + (if (and prevstep (file-exists? prevstep)) + (set! script (conc script "source .ezsteps/" prevstep ".sh"))) + + ;; call the command using mt_ezstep + (set! script (conc script "mt_ezstep " stepname " " stepcmd "\n")) + + (debug:print 4 "script: " script) + + ;; now launch + (let ((pid (process-run script))) + (let processloop ((i 0)) + (let-values (((pid-val exit-status exit-code)(process-wait pid #t))) + (mutex-lock! m) + (vector-set! exit-info 0 pid) + (vector-set! exit-info 1 exit-status) + (vector-set! exit-info 2 exit-code) + (mutex-unlock! m) + (if (eq? pid-val 0) + (begin + (thread-sleep! 2) + (processloop (+ i 1)))) + ))) + (if (not (null? tal)) + (loop (car tal) (cdr tal) stepname))) + (debug:print 4 "WARNING: a prior step failed, stopping at " ezstep)))))))) (monitorjob (lambda () (let* ((start-seconds (current-seconds)) (calc-minutes (lambda () (inexact->exact (round @@ -269,16 +334,17 @@ (define (launch-test db run-id test-conf keyvallst test-name test-path itemdat) (change-directory *toppath*) (let ((useshell (config-lookup *configdat* "jobtools" "useshell")) (launcher (config-lookup *configdat* "jobtools" "launcher")) (runscript (config-lookup test-conf "setup" "runscript")) + (ezsteps (> (length (hash-table-ref/default test-conf "ezsteps" '())) 0)) ;; don't send all the steps, could be big (diskspace (config-lookup test-conf "requirements" "diskspace")) (memory (config-lookup test-conf "requirements" "memory")) (hosts (config-lookup *configdat* "jobtools" "workhosts")) (remote-megatest (config-lookup *configdat* "setup" "executable")) (local-megatest (car (argv))) - ;; (item-path (item-list->path itemdat)) test-path is the full path including the item-path + (test-sig (conc "=" test-name ":" (item-list->path itemdat) "=")) ;; test-path is the full path including the item-path (work-area #f) (toptest-work-area #f) ;; for iterated tests the top test contains data relevant for all (diskpath #f) (cmdparms #f) (fullcmd #f) ;; (define a (with-output-to-string (lambda ()(write x)))) @@ -303,23 +369,25 @@ (list 'test-name test-name) (list 'runscript runscript) (list 'run-id run-id ) (list 'itemdat itemdat ) (list 'megatest remote-megatest) + (list 'ezsteps ezsteps) (list 'env-ovrd (hash-table-ref/default *configdat* "env-override" '())) (list 'runname (args:get-arg ":runname")) (list 'mt-bindir-path mt-bindir-path))))))) ;; (string-intersperse keyvallst " ")))) ;; clean out step records from previous run if they exist (db:delete-test-step-records db run-id test-name itemdat) (change-directory work-area) ;; so that log files from the launch process don't clutter the test dir (cond ((and launcher hosts) ;; must be using ssh hostname - (set! fullcmd (append launcher (car hosts)(list remote-megatest "-execute" cmdparms)))) + (set! fullcmd (append launcher (car hosts)(list remote-megatest test-sig "-execute" cmdparms)))) (launcher - (set! fullcmd (append launcher (list remote-megatest "-execute" cmdparms)))) + (set! fullcmd (append launcher (list remote-megatest test-sig "-execute" cmdparms)))) (else - (set! fullcmd (list remote-megatest "-execute" cmdparms)))) + (if (not useshell)(debug:print 0 "WARNING: internal launching will not work well without \"useshell yes\" in your [jobtools] section")) + (set! fullcmd (list remote-megatest test-sig "-execute" cmdparms (if useshell "&" ""))))) (if (args:get-arg "-xterm")(set! fullcmd (append fullcmd (list "-xterm")))) (debug:print 1 "Launching megatest for test " test-name " in " work-area" ...") (test-set-status! db run-id test-name "LAUNCHED" "n/a" itemdat #f #f) ;; (if launch-results launch-results "FAILED")) ;; set ;; set pre-launch-env-vars before launching, keep the vars in prevvals and put the envionment back when done Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -89,10 +89,11 @@ -rollup : fill run (set by :runname) with latest test(s) from prior runs with same keys -rename-run : rename run (set by :runname) to , requires keys -update-meta : update the tests metadata for all tests -extract-ods : extract an open document spreadsheet from the database + -env2file fname : write the environment to fname.csh and fname.sh Helpers -runstep stepname ... : take remaining params as comand and execute as stepname log will be in stepname.log. Best to put command in quotes -logpro file : with -exec apply logpro file to stepname.log, creates @@ -137,10 +138,11 @@ ":expected" ":tol" ":units" ;; misc "-extract-ods" + "-env2file" "-debug" ;; for *verbosity* > 2 ) (list "-h" "-force" "-xterm" @@ -177,10 +179,19 @@ (set! *verbosity* (cond ((args:get-arg "-debug")(string->number (args:get-arg "-debug"))) ((args:get-arg "-v") 2) ((args:get-arg "-q") 0) (else 1))) + +;;====================================================================== +;; Misc general calls +;;====================================================================== + +(if (args:get-arg "-env2file") + (begin + (save-environment-as-files (args:get-arg "-env2file")) + (set! *didsomething* #t))) ;;====================================================================== ;; Remove old run(s) ;;====================================================================== ADDED tests/tests/eztest_pass/testconfig Index: tests/tests/eztest_pass/testconfig ================================================================== --- /dev/null +++ tests/tests/eztest_pass/testconfig @@ -0,0 +1,12 @@ +[setup] + +[ezsteps] +lstmp ls /tmp + +[test_meta] +author matt +owner bob +description This test runs a single ezstep which is expected to pass, no logpro file. + +tags first,single +reviewed 09/10/2011, by Matt ADDED utils/mt_ezstep Index: utils/mt_ezstep ================================================================== --- /dev/null +++ utils/mt_ezstep @@ -0,0 +1,42 @@ +#!/bin/bash -x + +if [ "$MT_CMDINFO" == "" ];then + echo "ERROR: $0 should be run within a megatest test environment" + exit +fi + +# Purpose: This is for the [ezsteps] secton in your testconfig file. +# DO NOT USE IN YOUR SCRIPTS! +# +# Call like this: +# mt_ezstep stepname command .... +# +stepname=$1;shift +command=$* + +# if a logpro file exists then use it otherwise just run the command, nb// was using 2>&1 +if [ -e ${stepname}.logpro ];then + $command 2>&1| logpro ${stepname}.logpro ${stepname}.html &> ${stepname}.log + 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=0 +else + exitstatus=1 +fi +$MT_MEGATEST -env2file .ezsteps/${stepname} +exit $exitstatus Index: utils/mt_laststep ================================================================== --- utils/mt_laststep +++ utils/mt_laststep @@ -51,20 +51,26 @@ # 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