Index: docs/manual/megatest_manual.html ================================================================== --- docs/manual/megatest_manual.html +++ docs/manual/megatest_manual.html @@ -3028,10 +3028,30 @@
Propagate environment to next step
$MT_MEGATEST -env2file .ezsteps/${stepname}
+
+

Automatic environment propagation with Ezsteps

+

Simply give your step name an extension of .sh or .csh. The environment variables will be propagated.

+
+ + + +
+Note +aliases and variables with strange whitespace or characters will not propagate correctly. Put in a ticket on the http://www.kiatoa.com/fossils/megatest site if you need support for a specific strange character combination.
+
+
+
Example of auto propagation
+
+
[ezsteps]
+step1.sh export SOMEVAR=$(ps -def | wc -l);ls /tmp
+# The next step will get the value of $SOMEVAR from step1.sh
+step2.sh echo $SOMEVAR
+
+

Scripts

Specifying scripts inline (best used for only simple scripts)
@@ -3499,10 +3519,10 @@

Index: docs/manual/reference.txt ================================================================== --- docs/manual/reference.txt +++ docs/manual/reference.txt @@ -742,10 +742,25 @@ .Propagate environment to next step ---------------------------- $MT_MEGATEST -env2file .ezsteps/${stepname} ---------------------------- + +Automatic environment propagation with Ezsteps +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Simply give your step name an extension of .sh or .csh. The environment variables will be propagated. + +NOTE: aliases and variables with strange whitespace or characters will not propagate correctly. Put in a ticket on the http://www.kiatoa.com/fossils/megatest site if you need support for a specific strange character combination. + +.Example of auto propagation +--------------------------- +[ezsteps] +step1.sh export SOMEVAR=$(ps -def | wc -l);ls /tmp +# The next step will get the value of $SOMEVAR from step1.sh +step2.sh echo $SOMEVAR +--------------------------- Scripts ~~~~~~~ .Specifying scripts inline (best used for only simple scripts) Index: env.scm ================================================================== --- env.scm +++ env.scm @@ -21,20 +21,22 @@ (declare (unit env)) (use sql-de-lite) ;; srfi-1 posix regex regex-case srfi-69 srfi-18 call-with-environment-variables) (define (env:open-db fname) - (let* ((db-exists (common:file-exists? fname)) + (let* ((db-exists (if (equal? fname ":memory:") + #f + (common:file-exists? fname))) (db (open-database fname))) (if (not db-exists) (begin - (exec (sql db "CREATE TABLE envvars ( - id INTEGER PRIMARY KEY, - context TEXT NOT NULL, - var TEXT NOT NULL, - val TEXT NOT NULL, - CONSTRAINT envvars_constraint UNIQUE (context,var))")))) + (exec (sql db "CREATE TABLE IF NOT EXISTS envvars ( + id INTEGER PRIMARY KEY, + context TEXT NOT NULL, + var TEXT NOT NULL, + val TEXT NOT NULL, + CONSTRAINT envvars_constraint UNIQUE (context,var))")))) (set-busy-handler! db (busy-timeout 10000)) db)) ;; save vars in given context, this is NOT incremental by default ;; @@ -77,10 +79,33 @@ val))))) (sql db "SELECT var,val FROM envvars WHERE context=?") context)) contexts) result)) + +;; envdelta: a-b (start=a, end=b, get the delta) +;; ofile: #f = write to stdout, else write to file with string name +;; +(define (env:envdelta db envdelta ofile) + (let ((match (string-split envdelta "-")));; (string-match "([a-z0-9_]+)=([a-z0-9_\\-,]+)" envdelta))) + (if (not (null? match)) + (let* ((parts match) ;; (string-split equn "-")) + (minuend (car parts)) + (subtraend (cadr parts)) + (added (env:get-added db minuend subtraend)) + (removed (env:get-removed db minuend subtraend)) + (changed (env:get-changed db minuend subtraend))) + ;; (pp (hash-table->alist added)) + ;; (pp (hash-table->alist removed)) + ;; (pp (hash-table->alist changed)) + (if (args:get-arg "-o") + (with-output-to-file + (args:get-arg "-o") + (lambda () + (env:print added removed changed))) + (env:print added removed changed))) + #f))) ;; get list of removed variables between two contexts ;; (define (env:get-removed db contexta contextb) (let ((result (make-hash-table))) Index: ezsteps.scm ================================================================== --- ezsteps.scm +++ ezsteps.scm @@ -33,17 +33,44 @@ (include "common_records.scm") (include "key_records.scm") (include "db_records.scm") (include "run_records.scm") +(define (ezsteps:step-name->mode stepname) + (match (string-search "\\.([^\\.]+)$" stepname) + ((_ ext) (string->symbol ext)) + (else #f))) -;;(rmt:get-test-info-by-id run-id test-id) -> testdat +(define (ezsteps:create-step-script envdbf stepname prevstepname mode cmd) + (let* ((shebang (case mode + ((sh) "/bin/sh") + ((csh) "/bin/csh") + (else "/bin/bash"))) + (sourcef (conc ".ezsteps/" prevstepname)) + (scriptn stepname)) ;; remember the name already has an extension .sh, .csh etc. + (with-output-to-file scriptn + (lambda () + ;; the shebang line + (print "#!" shebang "\n") + ;; first setup the source of the previous changes + (if (file-exists? sourcef) + (print "source " sourcef)) + ;; save the env at start + (print "megatest -envcap "stepname"_start "envdbf) + ;; run the command + (print cmd "\necode=$?") + ;; save the env at end + (print "megatest -envcap "stepname"_end "envdbf) + ;; write the delta + (print "megatest -envdelta "stepname"_start-"stepname"_end -dumpmode bash -o .ezsteps/"stepname" "envdbf) + (print "exit $ecode"))) + (system (conc "chmod a+x " scriptn)))) -;; TODO: deprecate me in favor of ezsteps.scm -;; -(define (launch:runstep ezstep run-id test-id exit-info m tal testconfig all-steps-dat) +;; +(define (launch:runstep ezstep run-id test-id exit-info m tal testconfig all-steps-dat prevstepname envdbf) (let* ((stepname (car ezstep)) ;; do stuff to run the step + (stepmode (ezsteps:step-name->mode stepname)) (stepinfo (cadr ezstep)) ;; (let ((info (cadr ezstep))) ;; (if (proc? info) "" info))) ;; (stepproc (let ((info (cadr ezstep))) ;; (if (proc? info) info #f))) @@ -80,13 +107,16 @@ ";;") (print tconfig-logpro))) (set! logpro-used #t))) ;; NB// can safely assume we are in test-area directory - (debug:print 4 *default-log-port* "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts + (debug:print 4 *default-log-port* "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo + " stepparts: " stepparts " stepparams: " stepparams " stepcmd: " stepcmd) - + + (if stepmode (ezsteps:create-step-script envdbf stepname prevstepname stepmode stepcmd)) + ;; ;; first source the previous environment ;; (let ((prev-env (conc ".ezsteps/" prevstep (if (string-search (regexp "csh") ;; (get-environment-variable "SHELL")) ".csh" ".sh")))) ;; (if (and prevstep (common:file-exists? prev-env)) ;; (set! script (conc script "source " prev-env)))) @@ -98,11 +128,14 @@ (rmt:teststep-set-status! run-id test-id stepname "start" "-" #f #f) ;; now launch the actual process (call-with-environment-variables (list (cons "PATH" (conc (get-environment-variable "PATH") ":."))) (lambda () ;; (process-run "/bin/bash" "-c" "exec ls -l /tmp/foobar > /tmp/delme-more.log 2>&1") - (let* ((cmd (conc stepcmd " > " stepname ".log 2>&1")) ;; >outfile 2>&1 + (let* ((cmd (conc (if stepmode + stepname + stepcmd) + " > " stepname ".log 2>&1")) ;; >outfile 2>&1 (pid #f)) (let ((proc (lambda () (set! pid (process-run "/bin/bash" (list "-c" cmd)))))) (if subrun (begin Index: launch.scm ================================================================== --- launch.scm +++ launch.scm @@ -168,11 +168,14 @@ (append (or ezstepslst '()) (list (list "subrun" (conc "{subrun=true} " mt-cmd))))))) ;; process the ezsteps (if ezsteps - (let* ((all-steps-dat (make-hash-table))) ;; keep all the info around as stepname ==> alist; where 'params is the params list (add other stuff as needed) + (let* ((envdbf (conc "/tmp/."(current-user-name)"-"(current-process-id)"-"run-id"-"test-id".db")) + (all-steps-dat (make-hash-table))) ;; keep all the info around as stepname ==> alist; + ;;; where 'params is the params list (add other + ;;; stuff as needed) (if (not (common: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-error 0 *default-log-port* "ezsteps defined but ezstepslst is zero length") (let loop ((ezstep (car ezstepslst)) @@ -179,11 +182,12 @@ (tal (cdr ezstepslst)) (prevstep #f)) (debug:print-info 0 *default-log-port* "Processing ezstep \"" (string-intersperse ezstep " ") "\"") ;; check exit-info (vector-ref exit-info 1) (if (launch:einf-exit-status exit-info) ;; (vector-ref exit-info 1) - (let* ((logpro-used (launch:runstep ezstep run-id test-id exit-info m tal testconfig all-steps-dat)) + (let* ((logpro-used (launch:runstep ezstep run-id test-id exit-info m + tal testconfig all-steps-dat prevstep envdbf)) (stepname (car ezstep)) (stepparms (hash-table-ref all-steps-dat stepname))) (setenv "MT_STEP_NAME" stepname) (pp (hash-table->alist all-steps-dat)) ;; if logpro-used read in the stepname.dat file Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -868,11 +868,14 @@ (let* ((db (env:open-db (if (null? remargs) "envdat.db" (car remargs))))) (env:save-env-vars db envcap) (env:close-database db) (set! *didsomething* #t)))) -;; delta "language" will eventually be res=a+b-c but for now it is just res=a-b +;; delta "language" will eventually be res=a+b-c but for now it is just res=a-b +;; +;; db file can be stuck on the end of the command line: +;; megatest -envdelta start-end -dumpmode bash -o .ezsteps/step5.sh /tmp/myfile.db ;; (let ((envdelta (args:get-arg "-envdelta"))) (if envdelta (let ((match (string-split envdelta "-")));; (string-match "([a-z0-9_]+)=([a-z0-9_\\-,]+)" envdelta))) (if (not (null? match))