"))
+ running-color)
+
+ ((member (conc status) '("0" 0))
+ white)
+ (else test-status-color)))
+ ; (else failcolor)))
+ (mtrx-rc (conc rownum ":" colnum)))
+ ;;(print "BB> status=>"status"< bgcolor="bgcolor)
+ (iup:attribute-set! steps-matrix mtrx-rc (if val (conc val) ""))
+ (if (< colnum 5)
+ (iup:attribute-set! steps-matrix (conc "BGCOLOR" mtrx-rc) bgcolor))
+ (if (< colnum max-col)
+ (loop hed tal rownum (+ colnum 1))
+ (if (not (null? tal))
+ (loop (car tal) (cdr tal) (+ rownum 1) 1))))))
+ (if (> max-row 0)
+ (begin
+ ;; we are going to speculatively clear rows until we find a row that is already cleared
+ (let loop ((rownum (+ max-row 1))
+ (colnum 0)
+ (deleted #f))
+ ;; (debug:print-info 0 *default-log-port* "cleaning " rownum ":" colnum)
+ (let* ((next-row (if (eq? colnum max-col) (+ rownum 1) rownum))
+ (next-col (if (eq? colnum max-col) 1 (+ colnum 1)))
+ (mtrx-rc (conc rownum ":" colnum))
+ (curr-val (iup:attribute steps-matrix mtrx-rc)))
+ ;; (debug:print-info 0 *default-log-port* "cleaning " rownum ":" colnum " currval= " curr-val)
+ (if (and (string? curr-val)
+ (not (equal? curr-val "")))
+ (begin
+ (iup:attribute-set! steps-matrix mtrx-rc "")
+ (loop next-row next-col #t))
+ (if (eq? colnum max-col) ;; not done, didn't get a full blank row
+ (if deleted (loop next-row next-col #f)) ;; exit on this not met
+ (loop next-row next-col deleted)))))
+ (iup:attribute-set! steps-matrix "REDRAW" "ALL")))))
+
+;;======================================================================
+;; U T I L I T I E S
+;;======================================================================
+
+(define (dcommon:run-html-viewer lfilename)
+ (let ((htmlviewercmd (configf:lookup *configdat* "setup" "htmlviewercmd")))
+ (if htmlviewercmd
+ (system (conc "(" htmlviewercmd " " lfilename " ) &"))
+ (iup:send-url lfilename))))
+
+(define (dashboard:monitor-changed? commondat tabdat)
+ (let* ((run-update-time (current-seconds))
+ (monitor-db-path (dboard:tabdat-monitor-db-path tabdat))
+ (monitor-modtime (if (and monitor-db-path (common:file-exists? monitor-db-path))
+ (file-modification-time monitor-db-path)
+ -1)))
+ (if (and (eq? (dboard:commondat-curr-tab-num commondat) 0)
+ (or (> monitor-modtime *last-monitor-update-time*)
+ (> (- run-update-time *last-monitor-update-time*) 5))) ;; update every 1/2 minute just in case
+ (begin
+ (set! *last-monitor-update-time* run-update-time) ;; monitor-modtime)
+ #t)
+ #f)))
+
+;; DOES NOT WORK RELIABLY WITH /tmp WAL mode files. Timestamps only change when the db
+;; is closed (I think). If db dir starts with /tmp always return true
+;;
+(define (dashboard:database-changed? commondat tabdat #!key (context-key 'default))
+ (let* ((run-update-time (current-seconds))
+ (dbdir (dboard:tabdat-dbdir tabdat))
+ (modtime (dashboard:get-youngest-run-db-mod-time dbdir))
+ (recalc (dashboard:recalc modtime
+ (dboard:commondat-please-update commondat)
+ (dboard:get-last-db-update tabdat context-key))))
+ ;; (dboard:tabdat-last-db-update tabdat))))
+ (if recalc
+ (dboard:set-last-db-update! tabdat context-key run-update-time))
+ (dboard:commondat-please-update-set! commondat #f)
+ recalc))
+
+(define (dashboard:get-youngest-run-db-mod-time dbdir)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 2 *default-log-port* "WARNING: error in accessing databases in get-youngest-run-db-mod-time: " ((condition-property-accessor 'exn 'message) exn)
+ " db-dir="dbdir ", exn=" exn)
+ (current-seconds)) ;; something went wrong - just print an error and return current-seconds
+ (common:max (map (lambda (filen)
+ (file-modification-time filen))
+ (glob (conc dbdir "/*.db*"))))))
+
+(define (dboard:get-last-db-update tabdat context)
+ (hash-table-ref/default (dboard:tabdat-last-db-update tabdat) context 0))
+
+(define (dboard:set-last-db-update! tabdat context newtime)
+ (hash-table-set! (dboard:tabdat-last-db-update tabdat) context newtime))
+
+;; point inside line
+;;
+(define-inline (dashboard:px-between px lx1 lx2)
+ (and (< lx1 px)(> lx2 px)))
+
+(define (dashboard:recalc modtime please-update-buttons last-db-update-time)
+ (or please-update-buttons
+ (and ;; (> (current-milliseconds)(+ *last-recalc-ended-time* 150)) ;; can't use this - it needs to be tab specific
+ (> modtime (- last-db-update-time 3)) ;; add three seconds of margin
+ (> (current-seconds)(+ last-db-update-time 1)))))
+
ADDED attic_modular/dcommonmod.import.scm
Index: attic_modular/dcommonmod.import.scm
==================================================================
--- /dev/null
+++ attic_modular/dcommonmod.import.scm
@@ -0,0 +1,635 @@
+;;;; dcommonmod.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ (prefix iup iup:)
+ canvas-draw
+ (prefix sqlite3 sqlite3:)
+ posix
+ typed-records
+ srfi-18
+ srfi-69
+ matchable
+ sparse-vectors
+ srfi-1
+ regex
+ srfi-13
+ canvas-draw-iup
+ commonmod
+ debugprint
+ configfmod
+ postgresql))
+(##sys#register-compiled-module
+ 'dcommonmod
+ (list)
+ '((alist->dboard:rundat . dcommonmod#alist->dboard:rundat)
+ (dboard:rundat->alist . dcommonmod#dboard:rundat->alist)
+ (update-dboard:rundat . dcommonmod#update-dboard:rundat)
+ (set-dboard:rundat! . dcommonmod#set-dboard:rundat!)
+ (make-dboard:rundat . dcommonmod#make-dboard:rundat)
+ (dboard:rundat-db-path . dcommonmod#dboard:rundat-db-path)
+ (dboard:rundat-db-path-set! . dcommonmod#dboard:rundat-db-path-set!)
+ (dboard:rundat-run-data-offset . dcommonmod#dboard:rundat-run-data-offset)
+ (dboard:rundat-run-data-offset-set!
+ .
+ dcommonmod#dboard:rundat-run-data-offset-set!)
+ (dboard:rundat-data-changed . dcommonmod#dboard:rundat-data-changed)
+ (dboard:rundat-data-changed-set!
+ .
+ dcommonmod#dboard:rundat-data-changed-set!)
+ (dboard:rundat-last-db-time . dcommonmod#dboard:rundat-last-db-time)
+ (dboard:rundat-last-db-time-set!
+ .
+ dcommonmod#dboard:rundat-last-db-time-set!)
+ (dboard:rundat-last-update . dcommonmod#dboard:rundat-last-update)
+ (dboard:rundat-last-update-set!
+ .
+ dcommonmod#dboard:rundat-last-update-set!)
+ (dboard:rundat-tests-by-name . dcommonmod#dboard:rundat-tests-by-name)
+ (dboard:rundat-tests-by-name-set!
+ .
+ dcommonmod#dboard:rundat-tests-by-name-set!)
+ (dboard:rundat-key-vals . dcommonmod#dboard:rundat-key-vals)
+ (dboard:rundat-key-vals-set! . dcommonmod#dboard:rundat-key-vals-set!)
+ (dboard:rundat-tests . dcommonmod#dboard:rundat-tests)
+ (dboard:rundat-tests-set! . dcommonmod#dboard:rundat-tests-set!)
+ (dboard:rundat-hierdat . dcommonmod#dboard:rundat-hierdat)
+ (dboard:rundat-hierdat-set! . dcommonmod#dboard:rundat-hierdat-set!)
+ (dboard:rundat-rowsused . dcommonmod#dboard:rundat-rowsused)
+ (dboard:rundat-rowsused-set! . dcommonmod#dboard:rundat-rowsused-set!)
+ (dboard:rundat-tests-notdrawn . dcommonmod#dboard:rundat-tests-notdrawn)
+ (dboard:rundat-tests-notdrawn-set!
+ .
+ dcommonmod#dboard:rundat-tests-notdrawn-set!)
+ (dboard:rundat-tests-drawn . dcommonmod#dboard:rundat-tests-drawn)
+ (dboard:rundat-tests-drawn-set!
+ .
+ dcommonmod#dboard:rundat-tests-drawn-set!)
+ (dboard:rundat-run . dcommonmod#dboard:rundat-run)
+ (dboard:rundat-run-set! . dcommonmod#dboard:rundat-run-set!)
+ (dboard:rundat? . dcommonmod#dboard:rundat?)
+ (make-dboard:rundat . dcommonmod#make-dboard:rundat)
+ (alist->dboard:runsdat . dcommonmod#alist->dboard:runsdat)
+ (dboard:runsdat->alist . dcommonmod#dboard:runsdat->alist)
+ (update-dboard:runsdat . dcommonmod#update-dboard:runsdat)
+ (set-dboard:runsdat! . dcommonmod#set-dboard:runsdat!)
+ (make-dboard:runsdat . dcommonmod#make-dboard:runsdat)
+ (dboard:runsdat-matrix-dat . dcommonmod#dboard:runsdat-matrix-dat)
+ (dboard:runsdat-matrix-dat-set!
+ .
+ dcommonmod#dboard:runsdat-matrix-dat-set!)
+ (dboard:runsdat-tests-index . dcommonmod#dboard:runsdat-tests-index)
+ (dboard:runsdat-tests-index-set!
+ .
+ dcommonmod#dboard:runsdat-tests-index-set!)
+ (dboard:runsdat-runs-index . dcommonmod#dboard:runsdat-runs-index)
+ (dboard:runsdat-runs-index-set!
+ .
+ dcommonmod#dboard:runsdat-runs-index-set!)
+ (dboard:runsdat? . dcommonmod#dboard:runsdat?)
+ (make-dboard:runsdat . dcommonmod#make-dboard:runsdat)
+ (alist->dboard:graph-dat . dcommonmod#alist->dboard:graph-dat)
+ (dboard:graph-dat->alist . dcommonmod#dboard:graph-dat->alist)
+ (update-dboard:graph-dat . dcommonmod#update-dboard:graph-dat)
+ (set-dboard:graph-dat! . dcommonmod#set-dboard:graph-dat!)
+ (make-dboard:graph-dat . dcommonmod#make-dboard:graph-dat)
+ (dboard:graph-dat-cell . dcommonmod#dboard:graph-dat-cell)
+ (dboard:graph-dat-cell-set! . dcommonmod#dboard:graph-dat-cell-set!)
+ (dboard:graph-dat-flag . dcommonmod#dboard:graph-dat-flag)
+ (dboard:graph-dat-flag-set! . dcommonmod#dboard:graph-dat-flag-set!)
+ (dboard:graph-dat-color . dcommonmod#dboard:graph-dat-color)
+ (dboard:graph-dat-color-set! . dcommonmod#dboard:graph-dat-color-set!)
+ (dboard:graph-dat-id . dcommonmod#dboard:graph-dat-id)
+ (dboard:graph-dat-id-set! . dcommonmod#dboard:graph-dat-id-set!)
+ (dboard:graph-dat? . dcommonmod#dboard:graph-dat?)
+ (make-dboard:graph-dat . dcommonmod#make-dboard:graph-dat)
+ (alist->dboard:tabdat . dcommonmod#alist->dboard:tabdat)
+ (dboard:tabdat->alist . dcommonmod#dboard:tabdat->alist)
+ (update-dboard:tabdat . dcommonmod#update-dboard:tabdat)
+ (set-dboard:tabdat! . dcommonmod#set-dboard:tabdat!)
+ (make-dboard:tabdat . dcommonmod#make-dboard:tabdat)
+ (dboard:tabdat-runs-summary-dest-runname-label
+ .
+ dcommonmod#dboard:tabdat-runs-summary-dest-runname-label)
+ (dboard:tabdat-runs-summary-dest-runname-label-set!
+ .
+ dcommonmod#dboard:tabdat-runs-summary-dest-runname-label-set!)
+ (dboard:tabdat-runs-summary-source-runname-label
+ .
+ dcommonmod#dboard:tabdat-runs-summary-source-runname-label)
+ (dboard:tabdat-runs-summary-source-runname-label-set!
+ .
+ dcommonmod#dboard:tabdat-runs-summary-source-runname-label-set!)
+ (dboard:tabdat-runs-summary-mode-change-callbacks
+ .
+ dcommonmod#dboard:tabdat-runs-summary-mode-change-callbacks)
+ (dboard:tabdat-runs-summary-mode-change-callbacks-set!
+ .
+ dcommonmod#dboard:tabdat-runs-summary-mode-change-callbacks-set!)
+ (dboard:tabdat-runs-summary-mode
+ .
+ dcommonmod#dboard:tabdat-runs-summary-mode)
+ (dboard:tabdat-runs-summary-mode-set!
+ .
+ dcommonmod#dboard:tabdat-runs-summary-mode-set!)
+ (dboard:tabdat-runs-summary-mode-buttons
+ .
+ dcommonmod#dboard:tabdat-runs-summary-mode-buttons)
+ (dboard:tabdat-runs-summary-mode-buttons-set!
+ .
+ dcommonmod#dboard:tabdat-runs-summary-mode-buttons-set!)
+ (dboard:tabdat-runs-summary-modes
+ .
+ dcommonmod#dboard:tabdat-runs-summary-modes)
+ (dboard:tabdat-runs-summary-modes-set!
+ .
+ dcommonmod#dboard:tabdat-runs-summary-modes-set!)
+ (dboard:tabdat-yadj . dcommonmod#dboard:tabdat-yadj)
+ (dboard:tabdat-yadj-set! . dcommonmod#dboard:tabdat-yadj-set!)
+ (dboard:tabdat-xadj . dcommonmod#dboard:tabdat-xadj)
+ (dboard:tabdat-xadj-set! . dcommonmod#dboard:tabdat-xadj-set!)
+ (dboard:tabdat-view-changed . dcommonmod#dboard:tabdat-view-changed)
+ (dboard:tabdat-view-changed-set!
+ .
+ dcommonmod#dboard:tabdat-view-changed-set!)
+ (dboard:tabdat-runs-tree-ht . dcommonmod#dboard:tabdat-runs-tree-ht)
+ (dboard:tabdat-runs-tree-ht-set!
+ .
+ dcommonmod#dboard:tabdat-runs-tree-ht-set!)
+ (dboard:tabdat-runs-tree . dcommonmod#dboard:tabdat-runs-tree)
+ (dboard:tabdat-runs-tree-set! . dcommonmod#dboard:tabdat-runs-tree-set!)
+ (dboard:tabdat-path-run-ids . dcommonmod#dboard:tabdat-path-run-ids)
+ (dboard:tabdat-path-run-ids-set!
+ .
+ dcommonmod#dboard:tabdat-path-run-ids-set!)
+ (dboard:tabdat-num-tests . dcommonmod#dboard:tabdat-num-tests)
+ (dboard:tabdat-num-tests-set! . dcommonmod#dboard:tabdat-num-tests-set!)
+ (dboard:tabdat-monitor-db-path . dcommonmod#dboard:tabdat-monitor-db-path)
+ (dboard:tabdat-monitor-db-path-set!
+ .
+ dcommonmod#dboard:tabdat-monitor-db-path-set!)
+ (dboard:tabdat-last-db-update . dcommonmod#dboard:tabdat-last-db-update)
+ (dboard:tabdat-last-db-update-set!
+ .
+ dcommonmod#dboard:tabdat-last-db-update-set!)
+ (dboard:tabdat-dbkeys . dcommonmod#dboard:tabdat-dbkeys)
+ (dboard:tabdat-dbkeys-set! . dcommonmod#dboard:tabdat-dbkeys-set!)
+ (dboard:tabdat-dbfpath . dcommonmod#dboard:tabdat-dbfpath)
+ (dboard:tabdat-dbfpath-set! . dcommonmod#dboard:tabdat-dbfpath-set!)
+ (dboard:tabdat-dbdir . dcommonmod#dboard:tabdat-dbdir)
+ (dboard:tabdat-dbdir-set! . dcommonmod#dboard:tabdat-dbdir-set!)
+ (dboard:tabdat-access-mode . dcommonmod#dboard:tabdat-access-mode)
+ (dboard:tabdat-access-mode-set!
+ .
+ dcommonmod#dboard:tabdat-access-mode-set!)
+ (dboard:tabdat-test-patts . dcommonmod#dboard:tabdat-test-patts)
+ (dboard:tabdat-test-patts-set! . dcommonmod#dboard:tabdat-test-patts-set!)
+ (dboard:tabdat-target . dcommonmod#dboard:tabdat-target)
+ (dboard:tabdat-target-set! . dcommonmod#dboard:tabdat-target-set!)
+ (dboard:tabdat-status-ignore-hash
+ .
+ dcommonmod#dboard:tabdat-status-ignore-hash)
+ (dboard:tabdat-status-ignore-hash-set!
+ .
+ dcommonmod#dboard:tabdat-status-ignore-hash-set!)
+ (dboard:tabdat-state-ignore-hash
+ .
+ dcommonmod#dboard:tabdat-state-ignore-hash)
+ (dboard:tabdat-state-ignore-hash-set!
+ .
+ dcommonmod#dboard:tabdat-state-ignore-hash-set!)
+ (dboard:tabdat-searchpatts . dcommonmod#dboard:tabdat-searchpatts)
+ (dboard:tabdat-searchpatts-set!
+ .
+ dcommonmod#dboard:tabdat-searchpatts-set!)
+ (dboard:tabdat-hide-not-hide-button
+ .
+ dcommonmod#dboard:tabdat-hide-not-hide-button)
+ (dboard:tabdat-hide-not-hide-button-set!
+ .
+ dcommonmod#dboard:tabdat-hide-not-hide-button-set!)
+ (dboard:tabdat-hide-not-hide . dcommonmod#dboard:tabdat-hide-not-hide)
+ (dboard:tabdat-hide-not-hide-set!
+ .
+ dcommonmod#dboard:tabdat-hide-not-hide-set!)
+ (dboard:tabdat-hide-empty-runs . dcommonmod#dboard:tabdat-hide-empty-runs)
+ (dboard:tabdat-hide-empty-runs-set!
+ .
+ dcommonmod#dboard:tabdat-hide-empty-runs-set!)
+ (dboard:tabdat-last-filter-str . dcommonmod#dboard:tabdat-last-filter-str)
+ (dboard:tabdat-last-filter-str-set!
+ .
+ dcommonmod#dboard:tabdat-last-filter-str-set!)
+ (dboard:tabdat-filters-changed . dcommonmod#dboard:tabdat-filters-changed)
+ (dboard:tabdat-filters-changed-set!
+ .
+ dcommonmod#dboard:tabdat-filters-changed-set!)
+ (dboard:tabdat-key-lbs . dcommonmod#dboard:tabdat-key-lbs)
+ (dboard:tabdat-key-lbs-set! . dcommonmod#dboard:tabdat-key-lbs-set!)
+ (dboard:tabdat-key-listboxes . dcommonmod#dboard:tabdat-key-listboxes)
+ (dboard:tabdat-key-listboxes-set!
+ .
+ dcommonmod#dboard:tabdat-key-listboxes-set!)
+ (dboard:tabdat-test-patterns-textbox
+ .
+ dcommonmod#dboard:tabdat-test-patterns-textbox)
+ (dboard:tabdat-test-patterns-textbox-set!
+ .
+ dcommonmod#dboard:tabdat-test-patterns-textbox-set!)
+ (dboard:tabdat-command-tb . dcommonmod#dboard:tabdat-command-tb)
+ (dboard:tabdat-command-tb-set! . dcommonmod#dboard:tabdat-command-tb-set!)
+ (dboard:tabdat-command . dcommonmod#dboard:tabdat-command)
+ (dboard:tabdat-command-set! . dcommonmod#dboard:tabdat-command-set!)
+ (dboard:tabdat-graph-matrix-col
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-col)
+ (dboard:tabdat-graph-matrix-col-set!
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-col-set!)
+ (dboard:tabdat-graph-matrix-row
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-row)
+ (dboard:tabdat-graph-matrix-row-set!
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-row-set!)
+ (dboard:tabdat-graph-cell-table
+ .
+ dcommonmod#dboard:tabdat-graph-cell-table)
+ (dboard:tabdat-graph-cell-table-set!
+ .
+ dcommonmod#dboard:tabdat-graph-cell-table-set!)
+ (dboard:tabdat-graph-matrix-table
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-table)
+ (dboard:tabdat-graph-matrix-table-set!
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-table-set!)
+ (dboard:tabdat-graph-matrix . dcommonmod#dboard:tabdat-graph-matrix)
+ (dboard:tabdat-graph-matrix-set!
+ .
+ dcommonmod#dboard:tabdat-graph-matrix-set!)
+ (dboard:tabdat-compact-layout . dcommonmod#dboard:tabdat-compact-layout)
+ (dboard:tabdat-compact-layout-set!
+ .
+ dcommonmod#dboard:tabdat-compact-layout-set!)
+ (dboard:tabdat-layout-update-ok
+ .
+ dcommonmod#dboard:tabdat-layout-update-ok)
+ (dboard:tabdat-layout-update-ok-set!
+ .
+ dcommonmod#dboard:tabdat-layout-update-ok-set!)
+ (dboard:tabdat-originy . dcommonmod#dboard:tabdat-originy)
+ (dboard:tabdat-originy-set! . dcommonmod#dboard:tabdat-originy-set!)
+ (dboard:tabdat-originx . dcommonmod#dboard:tabdat-originx)
+ (dboard:tabdat-originx-set! . dcommonmod#dboard:tabdat-originx-set!)
+ (dboard:tabdat-running-layout . dcommonmod#dboard:tabdat-running-layout)
+ (dboard:tabdat-running-layout-set!
+ .
+ dcommonmod#dboard:tabdat-running-layout-set!)
+ (dboard:tabdat-max-row . dcommonmod#dboard:tabdat-max-row)
+ (dboard:tabdat-max-row-set! . dcommonmod#dboard:tabdat-max-row-set!)
+ (dboard:tabdat-run-start-row . dcommonmod#dboard:tabdat-run-start-row)
+ (dboard:tabdat-run-start-row-set!
+ .
+ dcommonmod#dboard:tabdat-run-start-row-set!)
+ (dboard:tabdat-drawing . dcommonmod#dboard:tabdat-drawing)
+ (dboard:tabdat-drawing-set! . dcommonmod#dboard:tabdat-drawing-set!)
+ (dboard:tabdat-cnv-obj . dcommonmod#dboard:tabdat-cnv-obj)
+ (dboard:tabdat-cnv-obj-set! . dcommonmod#dboard:tabdat-cnv-obj-set!)
+ (dboard:tabdat-cnv . dcommonmod#dboard:tabdat-cnv)
+ (dboard:tabdat-cnv-set! . dcommonmod#dboard:tabdat-cnv-set!)
+ (dboard:tabdat-all-test-names . dcommonmod#dboard:tabdat-all-test-names)
+ (dboard:tabdat-all-test-names-set!
+ .
+ dcommonmod#dboard:tabdat-all-test-names-set!)
+ (dboard:tabdat-runs-cell-width . dcommonmod#dboard:tabdat-runs-cell-width)
+ (dboard:tabdat-runs-cell-width-set!
+ .
+ dcommonmod#dboard:tabdat-runs-cell-width-set!)
+ (dboard:tabdat-runs-btn-fontsz . dcommonmod#dboard:tabdat-runs-btn-fontsz)
+ (dboard:tabdat-runs-btn-fontsz-set!
+ .
+ dcommonmod#dboard:tabdat-runs-btn-fontsz-set!)
+ (dboard:tabdat-runs-btn-height . dcommonmod#dboard:tabdat-runs-btn-height)
+ (dboard:tabdat-runs-btn-height-set!
+ .
+ dcommonmod#dboard:tabdat-runs-btn-height-set!)
+ (dboard:tabdat-start-test-offset
+ .
+ dcommonmod#dboard:tabdat-start-test-offset)
+ (dboard:tabdat-start-test-offset-set!
+ .
+ dcommonmod#dboard:tabdat-start-test-offset-set!)
+ (dboard:tabdat-start-run-offset
+ .
+ dcommonmod#dboard:tabdat-start-run-offset)
+ (dboard:tabdat-start-run-offset-set!
+ .
+ dcommonmod#dboard:tabdat-start-run-offset-set!)
+ (dboard:tabdat-runs-matrix . dcommonmod#dboard:tabdat-runs-matrix)
+ (dboard:tabdat-runs-matrix-set!
+ .
+ dcommonmod#dboard:tabdat-runs-matrix-set!)
+ (dboard:tabdat-run-keys . dcommonmod#dboard:tabdat-run-keys)
+ (dboard:tabdat-run-keys-set! . dcommonmod#dboard:tabdat-run-keys-set!)
+ (dboard:tabdat-item-test-names . dcommonmod#dboard:tabdat-item-test-names)
+ (dboard:tabdat-item-test-names-set!
+ .
+ dcommonmod#dboard:tabdat-item-test-names-set!)
+ (dboard:tabdat-buttondat . dcommonmod#dboard:tabdat-buttondat)
+ (dboard:tabdat-buttondat-set! . dcommonmod#dboard:tabdat-buttondat-set!)
+ (dboard:tabdat-run-db-paths . dcommonmod#dboard:tabdat-run-db-paths)
+ (dboard:tabdat-run-db-paths-set!
+ .
+ dcommonmod#dboard:tabdat-run-db-paths-set!)
+ (dboard:tabdat-last-test-dat . dcommonmod#dboard:tabdat-last-test-dat)
+ (dboard:tabdat-last-test-dat-set!
+ .
+ dcommonmod#dboard:tabdat-last-test-dat-set!)
+ (dboard:tabdat-run-update-times
+ .
+ dcommonmod#dboard:tabdat-run-update-times)
+ (dboard:tabdat-run-update-times-set!
+ .
+ dcommonmod#dboard:tabdat-run-update-times-set!)
+ (dboard:tabdat-runs-mutex . dcommonmod#dboard:tabdat-runs-mutex)
+ (dboard:tabdat-runs-mutex-set! . dcommonmod#dboard:tabdat-runs-mutex-set!)
+ (dboard:tabdat-last-runs-update
+ .
+ dcommonmod#dboard:tabdat-last-runs-update)
+ (dboard:tabdat-last-runs-update-set!
+ .
+ dcommonmod#dboard:tabdat-last-runs-update-set!)
+ (dboard:tabdat-last-data-update
+ .
+ dcommonmod#dboard:tabdat-last-data-update)
+ (dboard:tabdat-last-data-update-set!
+ .
+ dcommonmod#dboard:tabdat-last-data-update-set!)
+ (dboard:tabdat-tot-runs . dcommonmod#dboard:tabdat-tot-runs)
+ (dboard:tabdat-tot-runs-set! . dcommonmod#dboard:tabdat-tot-runs-set!)
+ (dboard:tabdat-numruns . dcommonmod#dboard:tabdat-numruns)
+ (dboard:tabdat-numruns-set! . dcommonmod#dboard:tabdat-numruns-set!)
+ (dboard:tabdat-keys . dcommonmod#dboard:tabdat-keys)
+ (dboard:tabdat-keys-set! . dcommonmod#dboard:tabdat-keys-set!)
+ (dboard:tabdat-header . dcommonmod#dboard:tabdat-header)
+ (dboard:tabdat-header-set! . dcommonmod#dboard:tabdat-header-set!)
+ (dboard:tabdat-not-done-runs . dcommonmod#dboard:tabdat-not-done-runs)
+ (dboard:tabdat-not-done-runs-set!
+ .
+ dcommonmod#dboard:tabdat-not-done-runs-set!)
+ (dboard:tabdat-done-runs . dcommonmod#dboard:tabdat-done-runs)
+ (dboard:tabdat-done-runs-set! . dcommonmod#dboard:tabdat-done-runs-set!)
+ (dboard:tabdat-allruns-by-id . dcommonmod#dboard:tabdat-allruns-by-id)
+ (dboard:tabdat-allruns-by-id-set!
+ .
+ dcommonmod#dboard:tabdat-allruns-by-id-set!)
+ (dboard:tabdat-allruns . dcommonmod#dboard:tabdat-allruns)
+ (dboard:tabdat-allruns-set! . dcommonmod#dboard:tabdat-allruns-set!)
+ (dboard:tabdat-tests-tree . dcommonmod#dboard:tabdat-tests-tree)
+ (dboard:tabdat-tests-tree-set! . dcommonmod#dboard:tabdat-tests-tree-set!)
+ (dboard:tabdat-ro . dcommonmod#dboard:tabdat-ro)
+ (dboard:tabdat-ro-set! . dcommonmod#dboard:tabdat-ro-set!)
+ (dboard:tabdat-curr-test-ids . dcommonmod#dboard:tabdat-curr-test-ids)
+ (dboard:tabdat-curr-test-ids-set!
+ .
+ dcommonmod#dboard:tabdat-curr-test-ids-set!)
+ (dboard:tabdat-prev-run-id . dcommonmod#dboard:tabdat-prev-run-id)
+ (dboard:tabdat-prev-run-id-set!
+ .
+ dcommonmod#dboard:tabdat-prev-run-id-set!)
+ (dboard:tabdat-curr-run-id . dcommonmod#dboard:tabdat-curr-run-id)
+ (dboard:tabdat-curr-run-id-set!
+ .
+ dcommonmod#dboard:tabdat-curr-run-id-set!)
+ (dboard:tabdat-statuses . dcommonmod#dboard:tabdat-statuses)
+ (dboard:tabdat-statuses-set! . dcommonmod#dboard:tabdat-statuses-set!)
+ (dboard:tabdat-states . dcommonmod#dboard:tabdat-states)
+ (dboard:tabdat-states-set! . dcommonmod#dboard:tabdat-states-set!)
+ (dboard:tabdat-run-name . dcommonmod#dboard:tabdat-run-name)
+ (dboard:tabdat-run-name-set! . dcommonmod#dboard:tabdat-run-name-set!)
+ (dboard:tabdat? . dcommonmod#dboard:tabdat?)
+ (make-dboard:tabdat . dcommonmod#make-dboard:tabdat)
+ (dboard:commondat-make . dcommonmod#dboard:commondat-make)
+ (alist->dboard:commondat . dcommonmod#alist->dboard:commondat)
+ (dboard:commondat->alist . dcommonmod#dboard:commondat->alist)
+ (update-dboard:commondat . dcommonmod#update-dboard:commondat)
+ (set-dboard:commondat! . dcommonmod#set-dboard:commondat!)
+ (make-dboard:commondat . dcommonmod#make-dboard:commondat)
+ (dboard:commondat-curr-tab-num . dcommonmod#dboard:commondat-curr-tab-num)
+ (dboard:commondat-curr-tab-num-set!
+ .
+ dcommonmod#dboard:commondat-curr-tab-num-set!)
+ (dboard:commondat-hide-not-hide-tabs
+ .
+ dcommonmod#dboard:commondat-hide-not-hide-tabs)
+ (dboard:commondat-hide-not-hide-tabs-set!
+ .
+ dcommonmod#dboard:commondat-hide-not-hide-tabs-set!)
+ (dboard:commondat-uidat . dcommonmod#dboard:commondat-uidat)
+ (dboard:commondat-uidat-set! . dcommonmod#dboard:commondat-uidat-set!)
+ (dboard:commondat-updating . dcommonmod#dboard:commondat-updating)
+ (dboard:commondat-updating-set!
+ .
+ dcommonmod#dboard:commondat-updating-set!)
+ (dboard:commondat-updaters . dcommonmod#dboard:commondat-updaters)
+ (dboard:commondat-updaters-set!
+ .
+ dcommonmod#dboard:commondat-updaters-set!)
+ (dboard:commondat-update-mutex . dcommonmod#dboard:commondat-update-mutex)
+ (dboard:commondat-update-mutex-set!
+ .
+ dcommonmod#dboard:commondat-update-mutex-set!)
+ (dboard:commondat-tabdats . dcommonmod#dboard:commondat-tabdats)
+ (dboard:commondat-tabdats-set! . dcommonmod#dboard:commondat-tabdats-set!)
+ (dboard:commondat-please-update
+ .
+ dcommonmod#dboard:commondat-please-update)
+ (dboard:commondat-please-update-set!
+ .
+ dcommonmod#dboard:commondat-please-update-set!)
+ (dboard:commondat? . dcommonmod#dboard:commondat?)
+ (make-dboard:commondat . dcommonmod#make-dboard:commondat)
+ (alist->dboard:testdat . dcommonmod#alist->dboard:testdat)
+ (dboard:testdat->alist . dcommonmod#dboard:testdat->alist)
+ (update-dboard:testdat . dcommonmod#update-dboard:testdat)
+ (set-dboard:testdat! . dcommonmod#set-dboard:testdat!)
+ (make-dboard:testdat . dcommonmod#make-dboard:testdat)
+ (dboard:testdat-status . dcommonmod#dboard:testdat-status)
+ (dboard:testdat-status-set! . dcommonmod#dboard:testdat-status-set!)
+ (dboard:testdat-state . dcommonmod#dboard:testdat-state)
+ (dboard:testdat-state-set! . dcommonmod#dboard:testdat-state-set!)
+ (dboard:testdat-id . dcommonmod#dboard:testdat-id)
+ (dboard:testdat-id-set! . dcommonmod#dboard:testdat-id-set!)
+ (dboard:testdat? . dcommonmod#dboard:testdat?)
+ (make-dboard:testdat . dcommonmod#make-dboard:testdat)
+ (dboard:rundat-make-init . dcommonmod#dboard:rundat-make-init)
+ (alist->dboard:testrec . dcommonmod#alist->dboard:testrec)
+ (dboard:testrec->alist . dcommonmod#dboard:testrec->alist)
+ (update-dboard:testrec . dcommonmod#update-dboard:testrec)
+ (set-dboard:testrec! . dcommonmod#set-dboard:testrec!)
+ (make-dboard:testrec . dcommonmod#make-dboard:testrec)
+ (dboard:testrec-duration . dcommonmod#dboard:testrec-duration)
+ (dboard:testrec-duration-set! . dcommonmod#dboard:testrec-duration-set!)
+ (dboard:testrec-start-time . dcommonmod#dboard:testrec-start-time)
+ (dboard:testrec-start-time-set!
+ .
+ dcommonmod#dboard:testrec-start-time-set!)
+ (dboard:testrec-status . dcommonmod#dboard:testrec-status)
+ (dboard:testrec-status-set! . dcommonmod#dboard:testrec-status-set!)
+ (dboard:testrec-state . dcommonmod#dboard:testrec-state)
+ (dboard:testrec-state-set! . dcommonmod#dboard:testrec-state-set!)
+ (dboard:testrec-testname . dcommonmod#dboard:testrec-testname)
+ (dboard:testrec-testname-set! . dcommonmod#dboard:testrec-testname-set!)
+ (dboard:testrec-runid . dcommonmod#dboard:testrec-runid)
+ (dboard:testrec-runid-set! . dcommonmod#dboard:testrec-runid-set!)
+ (dboard:testrec-id . dcommonmod#dboard:testrec-id)
+ (dboard:testrec-id-set! . dcommonmod#dboard:testrec-id-set!)
+ (dboard:testrec? . dcommonmod#dboard:testrec?)
+ (make-dboard:testrec . dcommonmod#make-dboard:testrec)
+ (alist->dboard:runrec . dcommonmod#alist->dboard:runrec)
+ (dboard:runrec->alist . dcommonmod#dboard:runrec->alist)
+ (update-dboard:runrec . dcommonmod#update-dboard:runrec)
+ (set-dboard:runrec! . dcommonmod#set-dboard:runrec!)
+ (make-dboard:runrec . dcommonmod#make-dboard:runrec)
+ (dboard:runrec-tdef . dcommonmod#dboard:runrec-tdef)
+ (dboard:runrec-tdef-set! . dcommonmod#dboard:runrec-tdef-set!)
+ (dboard:runrec-target . dcommonmod#dboard:runrec-target)
+ (dboard:runrec-target-set! . dcommonmod#dboard:runrec-target-set!)
+ (dboard:runrec-id . dcommonmod#dboard:runrec-id)
+ (dboard:runrec-id-set! . dcommonmod#dboard:runrec-id-set!)
+ (dboard:runrec? . dcommonmod#dboard:runrec?)
+ (make-dboard:runrec . dcommonmod#make-dboard:runrec)
+ (dboard:rdat-push-run-id . dcommonmod#dboard:rdat-push-run-id)
+ (alist->dboard:rdat . dcommonmod#alist->dboard:rdat)
+ (dboard:rdat->alist . dcommonmod#dboard:rdat->alist)
+ (update-dboard:rdat . dcommonmod#update-dboard:rdat)
+ (set-dboard:rdat! . dcommonmod#set-dboard:rdat!)
+ (make-dboard:rdat . dcommonmod#make-dboard:rdat)
+ (dboard:rdat-items-mtx . dcommonmod#dboard:rdat-items-mtx)
+ (dboard:rdat-items-mtx-set! . dcommonmod#dboard:rdat-items-mtx-set!)
+ (dboard:rdat-runs-mtx . dcommonmod#dboard:rdat-runs-mtx)
+ (dboard:rdat-runs-mtx-set! . dcommonmod#dboard:rdat-runs-mtx-set!)
+ (dboard:rdat-runs-tree . dcommonmod#dboard:rdat-runs-tree)
+ (dboard:rdat-runs-tree-set! . dcommonmod#dboard:rdat-runs-tree-set!)
+ (dboard:rdat-view-changed . dcommonmod#dboard:rdat-view-changed)
+ (dboard:rdat-view-changed-set! . dcommonmod#dboard:rdat-view-changed-set!)
+ (dboard:rdat-prev-run-ids . dcommonmod#dboard:rdat-prev-run-ids)
+ (dboard:rdat-prev-run-ids-set! . dcommonmod#dboard:rdat-prev-run-ids-set!)
+ (dboard:rdat-tests . dcommonmod#dboard:rdat-tests)
+ (dboard:rdat-tests-set! . dcommonmod#dboard:rdat-tests-set!)
+ (dboard:rdat-cols . dcommonmod#dboard:rdat-cols)
+ (dboard:rdat-cols-set! . dcommonmod#dboard:rdat-cols-set!)
+ (dboard:rdat-last-updates . dcommonmod#dboard:rdat-last-updates)
+ (dboard:rdat-last-updates-set! . dcommonmod#dboard:rdat-last-updates-set!)
+ (dboard:rdat-test-status-sql-filt
+ .
+ dcommonmod#dboard:rdat-test-status-sql-filt)
+ (dboard:rdat-test-status-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-test-status-sql-filt-set!)
+ (dboard:rdat-test-state-sql-filt
+ .
+ dcommonmod#dboard:rdat-test-state-sql-filt)
+ (dboard:rdat-test-state-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-test-state-sql-filt-set!)
+ (dboard:rdat-itempath-sql-filt . dcommonmod#dboard:rdat-itempath-sql-filt)
+ (dboard:rdat-itempath-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-itempath-sql-filt-set!)
+ (dboard:rdat-testname-sql-filt . dcommonmod#dboard:rdat-testname-sql-filt)
+ (dboard:rdat-testname-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-testname-sql-filt-set!)
+ (dboard:rdat-run-status-sql-filt
+ .
+ dcommonmod#dboard:rdat-run-status-sql-filt)
+ (dboard:rdat-run-status-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-run-status-sql-filt-set!)
+ (dboard:rdat-run-state-sql-filt
+ .
+ dcommonmod#dboard:rdat-run-state-sql-filt)
+ (dboard:rdat-run-state-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-run-state-sql-filt-set!)
+ (dboard:rdat-runname-sql-filt . dcommonmod#dboard:rdat-runname-sql-filt)
+ (dboard:rdat-runname-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-runname-sql-filt-set!)
+ (dboard:rdat-targ-sql-filt . dcommonmod#dboard:rdat-targ-sql-filt)
+ (dboard:rdat-targ-sql-filt-set!
+ .
+ dcommonmod#dboard:rdat-targ-sql-filt-set!)
+ (dboard:rdat-tests . dcommonmod#dboard:rdat-tests)
+ (dboard:rdat-tests-set! . dcommonmod#dboard:rdat-tests-set!)
+ (dboard:rdat-targ-runid . dcommonmod#dboard:rdat-targ-runid)
+ (dboard:rdat-targ-runid-set! . dcommonmod#dboard:rdat-targ-runid-set!)
+ (dboard:rdat-rownames . dcommonmod#dboard:rdat-rownames)
+ (dboard:rdat-rownames-set! . dcommonmod#dboard:rdat-rownames-set!)
+ (dboard:rdat-runsbynum . dcommonmod#dboard:rdat-runsbynum)
+ (dboard:rdat-runsbynum-set! . dcommonmod#dboard:rdat-runsbynum-set!)
+ (dboard:rdat-run-tests . dcommonmod#dboard:rdat-run-tests)
+ (dboard:rdat-run-tests-set! . dcommonmod#dboard:rdat-run-tests-set!)
+ (dboard:rdat-runs . dcommonmod#dboard:rdat-runs)
+ (dboard:rdat-runs-set! . dcommonmod#dboard:rdat-runs-set!)
+ (dboard:rdat-numrows . dcommonmod#dboard:rdat-numrows)
+ (dboard:rdat-numrows-set! . dcommonmod#dboard:rdat-numrows-set!)
+ (dboard:rdat-numcols . dcommonmod#dboard:rdat-numcols)
+ (dboard:rdat-numcols-set! . dcommonmod#dboard:rdat-numcols-set!)
+ (dboard:rdat-toprow . dcommonmod#dboard:rdat-toprow)
+ (dboard:rdat-toprow-set! . dcommonmod#dboard:rdat-toprow-set!)
+ (dboard:rdat-leftcol . dcommonmod#dboard:rdat-leftcol)
+ (dboard:rdat-leftcol-set! . dcommonmod#dboard:rdat-leftcol-set!)
+ (dboard:rdat-runnum . dcommonmod#dboard:rdat-runnum)
+ (dboard:rdat-runnum-set! . dcommonmod#dboard:rdat-runnum-set!)
+ (dboard:rdat? . dcommonmod#dboard:rdat?)
+ (make-dboard:rdat . dcommonmod#make-dboard:rdat)
+ (new-tree-path->run-id . dcommonmod#new-tree-path->run-id)
+ (tree-path->run-id . dcommonmod#tree-path->run-id)
+ (tree:delete-node . dcommonmod#tree:delete-node)
+ (tree:node->path . dcommonmod#tree:node->path)
+ (tree:add-node . dcommonmod#tree:add-node)
+ (tree:find-node . dcommonmod#tree:find-node)
+ (*available-db* . commonmod#*available-db*))
+ (list (cons 'debug:catch-and-dump
+ (syntax-rules
+ ()
+ ((debug:catch-and-dump proc procname)
+ (begin
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain (current-error-port))
+ (with-output-to-port
+ (current-error-port)
+ (lambda ()
+ (print ((condition-property-accessor 'exn 'message) exn))
+ (print "Callback error in " procname)
+ (print "Full condition info:\n"
+ (condition->list exn)))))
+ (proc))))))
+ (cons 'common:handle-exceptions
+ (syntax-rules () ((_ exn errstmt body ...) (begin body ...))))
+ (cons 'common:debug-handle-exceptions
+ (syntax-rules
+ ()
+ ((_ debug exn errstmt body ...)
+ (if debug
+ (begin body ...)
+ (handle-exceptions exn errstmt body ...)))))
+ (cons 'define-simple-syntax
+ (syntax-rules
+ ()
+ ((_ (name arg ...) body ...)
+ (define-syntax
+ name
+ (syntax-rules () ((name arg ...) (begin body ...))))))))
+ (list))
+
+;; END OF FILE
ADDED attic_modular/dcommonmod.scm
Index: attic_modular/dcommonmod.scm
==================================================================
--- /dev/null
+++ attic_modular/dcommonmod.scm
@@ -0,0 +1,453 @@
+;;======================================================================
+;; Copyright 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 .
+
+;;======================================================================
+
+(declare (unit dcommonmod))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses configfmod))
+
+(module dcommonmod
+ *
+
+(import scheme chicken data-structures extras ports)
+(use
+ (prefix iup iup:)
+ canvas-draw
+ (prefix sqlite3 sqlite3:)
+ posix
+ typed-records
+ srfi-18
+ srfi-69
+ matchable
+ sparse-vectors
+ srfi-1
+ regex
+ srfi-13
+ )
+(import canvas-draw-iup)
+
+(import commonmod)
+(import debugprint)
+(import configfmod)
+
+(include "common_records.scm")
+
+;;======================================================================
+;; T R E E S T U F F
+;;======================================================================
+
+;; path is a list of nodes, each the child of the previous
+;; this routine returns the id so another node can be added
+;; either as a leaf or as a branch
+;;
+;; BUG: This needs a stop sensor for when a branch is exhausted
+;;
+(define (tree:find-node obj path)
+ ;; start at the base of the tree
+ (if (null? path)
+ #f ;; or 0 ????
+ (let loop ((hed (car path))
+ (tal (cdr path))
+ (depth 0)
+ (nodenum 0))
+ ;; nodes in iup tree are 100% sequential so iterate over nodenum
+ (if (iup:attribute obj (conc "DEPTH" nodenum)) ;; end when no more nodes
+ (let ((node-depth (string->number (iup:attribute obj (conc "DEPTH" nodenum))))
+ (node-title (iup:attribute obj (conc "TITLE" nodenum))))
+ (if (and (equal? depth node-depth)
+ (equal? hed node-title)) ;; yep, this is the one!
+ (if (null? tal) ;; end of the line
+ nodenum
+ (loop (car tal)(cdr tal)(+ depth 1)(+ 1 nodenum)))
+ ;; this is the case where we found part of the hierarchy but not
+ ;; all of it, i.e. the node-depth went from deep to less deep
+ (if (> depth node-depth) ;; (+ 1 node-depth))
+ #f
+ (loop hed tal depth (+ nodenum 1)))))
+ #f))))
+
+;; top is the top node name zeroeth node VALUE=0
+(define (tree:add-node obj top nodelst #!key (userdata #f))
+ (let ((curr-top (iup:attribute obj "TITLE0")))
+ (if (or (not (string? curr-top))
+ (string-null? curr-top)
+ (string-match "^\\s*$" curr-top))
+ (iup:attribute-set! obj "ADDBRANCH0" top))
+
+
+
+ (cond
+ ((not (equal? top (iup:attribute obj "TITLE0")))
+ (print "ERROR: top name " top " doesn't match " (iup:attribute obj "TITLE0")))
+ ((null? nodelst))
+ (else
+ (let loop ((hed (car nodelst))
+ (tal (cdr nodelst))
+ (depth 1)
+ (pathl (list top)))
+ ;; Because the tree dialog changes node numbers when
+ ;; nodes are added or removed we must look up nodes
+ ;; each and every time. 0 is the top node so default
+ ;; to that.
+ (let* ((newpath (append pathl (list hed)))
+ (parentnode (tree:find-node obj pathl))
+ (nodenum (tree:find-node obj newpath)))
+ ;; Add the branch under lastnode if not found
+ (if (not nodenum)
+ (begin
+ (iup:attribute-set! obj (conc "ADDBRANCH" parentnode) hed)
+ ;; ERROR? ADDING DATA TO PARENT, DONT WE WANT IT ON CREATED NODE?
+ (if userdata
+ (iup:attribute-set! obj (conc "USERDATA" parentnode) userdata))
+ (if (null? tal)
+ #t
+ ;; reset to top
+ (loop (car nodelst)(cdr nodelst) 1 (list top))))
+ (if (null? tal) ;; if null here then this path has already been added
+ #t
+ (loop (car tal)(cdr tal)(+ depth 1) newpath)))))))))
+
+(define (tree:node->path obj nodenum)
+ (let loop ((currnode 0)
+ (path '()))
+ (let* ((node-depth (string->number (iup:attribute obj (conc "DEPTH" currnode))))
+ (node-title (iup:attribute obj (conc "TITLE" currnode)))
+ (trimpath (if (and (not (null? path))
+ (> (length path) node-depth))
+ (take path node-depth)
+ path))
+ (newpath (append trimpath (list node-title))))
+ (if (>= currnode nodenum)
+ newpath
+ (loop (+ currnode 1)
+ newpath)))))
+
+(define (tree:delete-node obj top node-path) ;; node-path is a list of strings
+ (let ((id (tree:find-node obj (cons top node-path))))
+ (print "Found node to remove " id " for path " top " " node-path)
+ (iup:attribute-set! obj (conc "DELNODE" id) "SELECTED")))
+
+#|
+
+ (let* ((tb (iup:treebox
+ #:value 0
+ #:name "Runs"
+ #:expand "YES"
+ #:addexpanded "NO"
+ #:selection-cb
+ (lambda (obj id state)
+ ;; (print "obj: " obj ", id: " id ", state: " state)
+ (let* ((run-path (tree:node->path obj id))
+ (run-id (tree-path->run-id (cdr run-path))))
+ (if run-id
+ (begin
+ (dboard:data-curr-run-id-set! data run-id)
+ (dashboard:update-run-summary-tab)))
+ ;; (print "path: " (tree:node->path obj id) " run-id: " run-id)
+ ))))
+|#
+
+(define (tree-path->run-id tabdat path)
+ (if (not (null? path))
+ (hash-table-ref/default (dboard:tabdat-path-run-ids tabdat) path #f)
+ #f))
+
+(define (new-tree-path->run-id rdat path)
+ (if (not (null? path))
+ (hash-table-ref/default(dboard:rdat-targ-runid rdat) path #f)
+ ;;
+ #f))
+
+
+;;======================================================================
+;; COMMONDAT
+;;======================================================================
+
+;; for the new runs view lets build up a few new record types and then consolidate later
+;;
+;; this is a two level deep pipeline for the incoming data:
+;; sql query data ==> filters ==> data for display
+;;
+(defstruct dboard:rdat
+ ;; view related items
+ (runnum 0) ;; which column we are processing, index into runsbynum, we sweep across all these runs then start over
+ (leftcol 0) ;; number of the leftmost visible column
+ (toprow 0) ;; topmost visible row
+ (numcols 24) ;; number of columns visible
+ (numrows 20) ;; number of rows visible
+
+ ;; efactored <=== merge detritus
+ (runs (make-sparse-vector #f)) ;; id => runrec
+ (run-tests (make-sparse-vector '())) ;; id => list of tests
+ (runsbynum (make-vector 100 #f)) ;; vector num => runrec
+ (rownames (make-hash-table)) ;; testname => rownum
+ (targ-runid (make-hash-table)) ;; area/target/runname => run-id ;; not sure this will be needed
+ (tests (make-hash-table)) ;; test[/itempath] => list of test rec
+
+ ;; run sql filters
+ (targ-sql-filt "%")
+ (runname-sql-filt "%")
+ (run-state-sql-filt "%")
+ (run-status-sql-filt "%")
+
+ ;; test sql filter
+ (testname-sql-filt "%")
+ (itempath-sql-filt "%")
+ (test-state-sql-filt "%")
+ (test-status-sql-filt "%")
+
+ ;; other sql related fields
+ (last-updates (make-sparse-vector 0)) ;; run-id -> timestamp of the last update from sql db, set to zero on any field changes
+
+ ;; filtered data
+ (cols (make-sparse-vector)) ;; columnnum => run-id
+ (tests (make-hash-table)) ;; test[/itempath] => (vector columnnum => test rec)
+
+ ;; various
+ (prev-run-ids '()) ;; push previously looked at runs on this
+ (view-changed #f)
+
+ ;; widgets
+ (runs-tree #f) ;;
+ (runs-mtx #f) ;; runs displayed here
+ (items-mtx #f) ;; items displayed here
+ ;; info widgets here
+ )
+
+(define (dboard:rdat-push-run-id rdat run-id)
+ (dboard:rdat-prev-run-ids-set! rdat (cons run-id (dboard:rdat-prev-run-ids rdat))))
+
+(defstruct dboard:runrec
+ id
+ target ;; a/b/c...
+ tdef ;; for future use
+ )
+
+(defstruct dboard:testrec
+ id
+ runid
+ testname ;; test[/itempath]
+ state
+ status
+ start-time
+ duration
+ )
+
+
+(define (dboard:rundat-make-init #!key (run #f)(key-vals #f)(tests #f));; -100 is before time began
+ (make-dboard:rundat
+ run: run
+ tests: (or tests (make-hash-table))
+ key-vals: key-vals
+ ))
+
+(defstruct dboard:testdat
+ id ;; testid
+ state ;; test state
+ status ;; test status
+ )
+
+
+
+
+
+;; data common to all tabs goes here
+;;
+(defstruct dboard:commondat
+ ((curr-tab-num 0) : number)
+ please-update
+ tabdats
+ update-mutex
+ updaters
+ updating
+ uidat ;; needs to move to tabdat at some time
+ hide-not-hide-tabs
+ )
+
+(define (dboard:commondat-make)
+ (make-dboard:commondat
+ curr-tab-num: 0
+ tabdats: (make-hash-table)
+ please-update: #t
+ update-mutex: (make-mutex)
+ updaters: (make-hash-table)
+ updating: #f
+ hide-not-hide-tabs: #f
+ ))
+
+;;======================================================================
+;; TABDAT
+;;======================================================================
+
+;; data for each specific tab goes here
+;;
+(defstruct dboard:tabdat
+ ;; runs
+ ((allruns '()) : list) ;; list of dboard:rundat records
+ ((allruns-by-id (make-hash-table)) : hash-table) ;; hash of run-id -> dboard:rundat records
+ ((done-runs '()) : list) ;; list of runs already drawn
+ ((not-done-runs '()) : list) ;; list of runs not yet drawn
+ (header #f) ;; header for decoding the run records
+ (keys #f) ;; keys for this run (i.e. target components)
+ ((numruns 8) : number)
+ ((tot-runs 0) : number)
+ ((last-data-update 0) : number) ;; last time the data in allruns was updated
+ ((last-runs-update 0) : number) ;; last time we pulled the runs info to update the tree
+ (runs-mutex (make-mutex)) ;; use to prevent parallel access to draw objects
+ ((run-update-times (make-hash-table)) : hash-table) ;; update times indexed by run-id
+ ((last-test-dat (make-hash-table)) : hash-table) ;; cache last tests dat by run-id
+ ((run-db-paths (make-hash-table)) : hash-table) ;; cache the paths to the run db files
+
+ ;; Runs view
+ ((buttondat (make-hash-table)) : hash-table) ;;
+ ((item-test-names '()) : list) ;; list of itemized tests
+ ((run-keys (make-hash-table)) : hash-table)
+ (runs-matrix #f) ;; used in newdashboard
+ ((start-run-offset 0) : number) ;; left-right slider value
+ ((start-test-offset 0) : number) ;; up-down slider value
+ ((runs-btn-height "x16") : string) ;; (or (configf:lookup *configdat* "dashboard" "btn-height") "x16")) : string) ;; was 12
+ ((runs-btn-fontsz "10") : string) ;; (or (configf:lookup *configdat* "dashboard" "btn-fontsz") "10")) : string) ;; was 8
+ ((runs-cell-width "50") : string) ;; (or (configf:lookup *configdat* "dashboard" "cell-width") "50")) : string) ;; was 50
+ ((all-test-names '()) : list)
+
+ ;; Canvas and drawing data
+ (cnv #f)
+ (cnv-obj #f)
+ (drawing #f)
+ ((run-start-row 0) : number)
+ ((max-row 0) : number)
+ ((running-layout #f) : boolean)
+ (originx #f)
+ (originy #f)
+ ((layout-update-ok #t) : boolean)
+ ((compact-layout #t) : boolean)
+
+ ;; Run times layout
+ ;; (graph-button-box #f) ;; RA => Think it is not referenced anywhere
+ (graph-matrix #f)
+ ((graph-matrix-table (make-hash-table)) : hash-table) ;; graph-dats referenced thru graph name info
+ ((graph-cell-table (make-hash-table)) : hash-table) ;; graph-dats referenced thru matrix cell info
+ ((graph-matrix-row 1) : number)
+ ((graph-matrix-col 1) : number)
+
+ ;; Controls used to launch runs etc.
+ ((command "") : string) ;; for run control this is the command being built up
+ (command-tb #f) ;; widget for the type of command; run, remove-runs etc.
+ (test-patterns-textbox #f) ;; text box widget for editing a list of test patterns
+ (key-listboxes #f)
+ (key-lbs #f)
+ run-name ;; from run name setting widget
+ states ;; states for -state s1,s2 ...
+ statuses ;; statuses for -status s1,s2 ...
+
+ ;; Selector variables
+ curr-run-id ;; current row to display in Run summary view
+ prev-run-id ;; previous runid selected before current runid was selected (used in xor-two-runs runs summary mode
+ curr-test-ids ;; used only in dcommon:run-update which is used in newdashboard
+ ((filters-changed #t) : boolean) ;; to indicate that the user changed filters for this tab
+ ((last-filter-str "") : string) ;; conc the target runname and testpatt for a signature of changed filters
+ ((hide-empty-runs #f) : boolean)
+ ((hide-not-hide #t) : boolean) ;; toggle for hide/not hide empty runs
+ (hide-not-hide-button #f)
+ ((searchpatts (make-hash-table)) : hash-table) ;;
+ ((state-ignore-hash (make-hash-table)) : hash-table) ;; hash of STATE => #t/#f for display control
+ ((status-ignore-hash (make-hash-table)) : hash-table) ;; hash of STATUS => #t/#f
+ (target #f)
+ (test-patts #f)
+
+ ;; db info to file the .db files for the area
+ (access-mode #f)
+ (dbdir #f)
+ (dbfpath #f)
+ (dbkeys #f)
+ ((last-db-update (make-hash-table)) : hash-table) ;; last db file timestamp
+ (monitor-db-path #f) ;; where to find monitor.db
+ ro ;; is the database read-only?
+
+ ;; tests data
+ ((num-tests 10) : number) ;; total number of tests to show (used in the old runs display)
+
+ ;; runs tree
+ ((path-run-ids (make-hash-table)) : hash-table) ;; path (target / runname) => id
+ (runs-tree #f)
+ ((runs-tree-ht (make-hash-table)) : hash-table) ;; track which targets added to tree (merge functionality with path-run-ids?)
+
+ ;; tab data
+ ((view-changed #t) : boolean)
+ ((xadj 0) : number) ;; x slider number (if using canvas)
+ ((yadj 0) : number) ;; y slider number (if using canvas)
+ ;; runs-summary tab state
+ ((runs-summary-modes '((one-run . "Show One Run") (xor-two-runs . "XOR Two Runs") (xor-two-runs-hide-clean . "XOR; Hide Clean")) ) : list)
+ ((runs-summary-mode-buttons '()) : list)
+ ((runs-summary-mode 'one-run) : symbol)
+ ((runs-summary-mode-change-callbacks '()) : list)
+ (runs-summary-source-runname-label #f)
+ (runs-summary-dest-runname-label #f)
+ ;; runs summary view
+
+ tests-tree ;; used in newdashboard
+ )
+
+;;======================================================================
+;; GRAPHDAT
+;;======================================================================
+
+;; RADT => Matrix defstruct addition
+(defstruct dboard:graph-dat
+ ((id #f) : string)
+ ((color #f) : vector)
+ ((flag #t) : boolean)
+ ((cell #f) : number)
+ )
+
+;;======================================================================
+;; RUNSDAT
+;;======================================================================
+
+;; data for runs, tests etc. was used in run summary?
+;;
+(defstruct dboard:runsdat
+ ;; new system
+ runs-index ;; target/runname => colnum
+ tests-index ;; testname/itempath => rownum
+ matrix-dat ;; vector of vectors rows/cols
+ )
+
+;; used to keep the rundata from rmt:get-tests-for-run
+;; in sync.
+;;
+(defstruct dboard:rundat
+ run
+ tests-drawn ;; list of id's already drawn on screen
+ tests-notdrawn ;; list of id's NOT already drawn
+ rowsused ;; hash of lists covering what areas used - replace with quadtree
+ hierdat ;; put hierarchial sorted list here
+ tests ;; hash of id => testdat
+ ((tests-by-name (make-hash-table)) : hash-table) ;; hash of testfullname => testdat
+ key-vals
+ ((last-update 0) : number) ;; last query to db got records from before last-update
+ ((last-db-time 0) : number) ;; last timestamp on megatest.db
+ ((data-changed #f) : boolean)
+ ((run-data-offset 0) : number) ;; get only 100 items per call, set back to zero when received less than 100 items
+ (db-path #f))
+
+;;======================================================================the end
+
+)
ADDED attic_modular/debugprint.import.scm
Index: attic_modular/debugprint.import.scm
==================================================================
--- /dev/null
+++ attic_modular/debugprint.import.scm
@@ -0,0 +1,25 @@
+;;;; debugprint.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ margsmod
+ data-structures
+ extras
+ files
+ ports
+ srfi-1))
+(##sys#register-compiled-module
+ 'debugprint
+ (list)
+ '((debug:print-info . debugprint#debug:print-info)
+ (debug:print-error . debugprint#debug:print-error)
+ (debug:print . debugprint#debug:print)
+ (debug:debug-mode . debugprint#debug:debug-mode)
+ (debug:calc-verbosity . debugprint#debug:calc-verbosity)
+ (*default-log-port* . debugprint#*default-log-port*)
+ (verbosity . debugprint#verbosity))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/debugprint.scm
Index: attic_modular/debugprint.scm
==================================================================
--- /dev/null
+++ attic_modular/debugprint.scm
@@ -0,0 +1,128 @@
+(declare (unit debugprint))
+(declare (uses margsmod))
+
+(module debugprint
+ *
+
+;;(import scheme chicken data-structures extras files ports)
+(import scheme chicken)
+(import margsmod)
+
+(use data-structures extras files ports)
+(use
+;; (prefix base64 base64:)
+;; (prefix sqlite3 sqlite3:)
+;; (srfi 18)
+;; (prefix dbi dbi:)
+;; directory-utils
+;; format
+;; matchable
+;; md5
+;; message-digest
+;; pkts
+;; posix
+;; regex
+;; regex-case
+;; sparse-vectors
+ srfi-1
+;; srfi-13
+;; srfi-69
+;; stack
+;; stml2
+;; typed-records
+;; z3
+ )
+
+;;======================================================================
+;; debug stuff
+;;======================================================================
+
+(define verbosity (make-parameter '()))
+(define *default-log-port* (current-error-port))
+
+;;======================================================================
+;; (define (debug:print . params) #f)
+;; (define (debug:print-info . params) #f)
+;;
+;; (define (set-functions dbgp dbgpinfo)
+;; (set! debug:print dbgp)
+;; (set! debug:print-info dbgpinfo))
+
+;;======================================================================
+;; this was cached based on results from profiling but it turned out the profiling
+;; somehow went wrong - perhaps too many processes writing to it. Leaving the caching
+;; in for now but can probably take it out later.
+;;
+(define (debug:calc-verbosity vstr arg) ;; arg is 'v (verbose) or 'q (quiet)
+ (let* ((res (cond
+ ((number? vstr) vstr)
+ ((not (string? vstr)) 1)
+ ;; ((string-match "^\\s*$" vstr) 1)
+ (vstr (let ((debugvals (filter number? (map string->number (string-split vstr ",")))))
+ (cond
+ ((> (length debugvals) 1) debugvals)
+ ((> (length debugvals) 0)(car debugvals))
+ (else 1))))
+ ((eq? arg 'v) 2) ;; verbose
+ ((eq? arg 'q) 0) ;; quiet
+ (else 1))))
+ (verbosity res)
+ res))
+
+;;======================================================================
+;; check verbosity, #t is ok
+#;(define (debug-check-verbosity verbosity vstr)
+ (if (not (or (number? verbosity)
+ (list? verbosity)))
+ (begin
+ (print "ERROR: Invalid debug value \"" vstr "\"")
+ #f)
+ #t))
+
+(define (debug:debug-mode n)
+ (let* ((vb (verbosity)))
+ (cond
+ ((and (number? vb) ;; number number
+ (number? n))
+ (<= n vb))
+ ((and (list? vb) ;; list number
+ (number? n))
+ (member n vb))
+ ((and (list? vb) ;; list list
+ (list? n))
+ (not (null? (lset-intersection! eq? vb n))))
+ ((and (number? vb)
+ (list? n))
+ (member vb n)))))
+
+(define (debug:print n e . params)
+ (if (debug:debug-mode n)
+ (with-output-to-port (or e (current-error-port))
+ (lambda ()
+ ;; (if *logging*
+ ;; (db:log-event (apply conc params))
+ (apply print params)
+ )))) ;; )
+
+(define (debug:print-error n e . params)
+ ;; normal print
+ (if (debug:debug-mode n)
+ (with-output-to-port (if (port? e) e (current-error-port))
+ (lambda ()
+ (apply print "ERROR: " params)
+ )))
+ ;; pass important messages to stderr
+ (if (and (eq? n 0)(not (eq? e (current-error-port))))
+ (with-output-to-port (current-error-port)
+ (lambda ()
+ (apply print "ERROR: " params)
+ ))))
+
+(define (debug:print-info n e . params)
+ (if (debug:debug-mode n)
+ (with-output-to-port (if (port? e) e (current-error-port))
+ (lambda ()
+ (apply print "INFO: (" n ") " params) ;; res)
+ ))))
+
+)
ADDED attic_modular/diff-report.scm
Index: attic_modular/diff-report.scm
==================================================================
--- /dev/null
+++ attic_modular/diff-report.scm
@@ -0,0 +1,430 @@
+;; 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 .
+;;
+
+(declare (unit diff-report))
+(declare (uses common))
+(declare (uses rmt))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(include "common_records.scm")
+(use matchable)
+(use fmt)
+(use ducttape-lib)
+(define css "")
+
+(define (diff:tests-mindat->hash tests-mindat)
+ (let* ((res (make-hash-table)))
+ (for-each
+ (lambda (item)
+ (let* ((test-name+item-path (cons (list-ref item 0) (list-ref item 1)))
+ (value (list-ref item 2)))
+ (hash-table-set! res test-name+item-path value)))
+ tests-mindat)
+ res))
+
+;; return 1 if status1 is better
+;; return 0 if status1 and 2 are equally good
+;; return -1 if status2 is better
+(define (diff:status-compare3 status1 status2)
+ (let*
+ ((status-goodness-ranking (list "PASS" "WARN" "WAIVED" "SKIP" "FAIL" "ABORT" #f))
+ (mem1 (member status1 status-goodness-ranking))
+ (mem2 (member status2 status-goodness-ranking))
+ )
+ (cond
+ ((and (not mem1) (not mem2)) 0)
+ ((not mem1) -1)
+ ((not mem2) 1)
+ ((= (length mem1) (length mem2)) 0)
+ ((> (length mem1) (length mem2)) 1)
+ (else -1))))
+
+
+(define (diff:xor-tests-mindat src-tests-mindat dest-tests-mindat #!key (hide-clean #f) (consistent-fail-not-clean #f))
+ (let* ((src-hash (diff:tests-mindat->hash src-tests-mindat))
+ (dest-hash (diff:tests-mindat->hash dest-tests-mindat))
+ (all-keys
+ (reverse (sort
+ (delete-duplicates
+ (append (hash-table-keys src-hash) (hash-table-keys dest-hash)))
+
+ (lambda (a b)
+ (cond
+ ((< 0 (string-compare3 (car a) (car b))) #t)
+ ((> 0 (string-compare3 (car a) (car b))) #f)
+ ((< 0 (string-compare3 (cdr a) (cdr b))) #t)
+ (else #f)))
+
+ ))))
+ (let ((res
+ (map ;; TODO: rename xor to delta globally in dcommon and dashboard
+ (lambda (key)
+ (let* ((test-name (car key))
+ (item-path (cdr key))
+
+ (dest-value (hash-table-ref/default dest-hash key (list 0 "NULL" "NULL"))) ;; (list test-id state status)
+ (dest-test-id (list-ref dest-value 0))
+ (dest-state (list-ref dest-value 1))
+ (dest-status (list-ref dest-value 2))
+
+ (src-value (hash-table-ref/default src-hash key (list 0 "NULL" "NULL"))) ;; (list test-id state status)
+ (src-test-id (list-ref src-value 0))
+ (src-state (list-ref src-value 1))
+ (src-status (list-ref src-value 2))
+
+ (incomplete-statuses '("DELETED" "INCOMPLETE" "STUCK/DEAD" "N/A")) ;; if any of these statuses apply, treat test as incomplete
+
+ (dest-complete
+ (and dest-value dest-state dest-status
+ (equal? dest-state "COMPLETED")
+ (not (member dest-status incomplete-statuses))))
+ (src-complete
+ (and src-value src-state src-status
+ (equal? src-state "COMPLETED")
+ (not (member src-status incomplete-statuses))))
+ (status-compare-result (diff:status-compare3 src-status dest-status))
+ (xor-new-item
+ (cond
+ ;; complete, for this case means: state=compelte AND status not in ( deleted uncomplete stuck/dead n/a )
+ ;; neither complete -> bad
+
+ ;; src !complete, dest complete -> better
+ ((and (not dest-complete) (not src-complete))
+ (list dest-test-id "BOTH-BAD" "BOTH-INCOMPLETE") src-value dest-value)
+ ((not dest-complete)
+ (list src-test-id "NOT-IN-DEST" "DEST-INCOMPLETE") src-value dest-value)
+ ((not src-complete)
+ (list dest-test-id "NOT-IN-SRC" "SRC-INCOMPLETE") src-value dest-value)
+ ((and
+ (equal? src-state dest-state)
+ (equal? src-status dest-status))
+ (if (and consistent-fail-not-clean (not (member dest-status '("PASS" "SKIP" "WAIVED" "WARN"))))
+ (list dest-test-id (conc "BOTH-BAD") (conc "CLEAN-" dest-status) src-value dest-value)
+ (list dest-test-id (conc "CLEAN") (conc "CLEAN-" dest-status) src-value dest-value)))
+ ;; better or worse: pass > warn > waived > skip > fail > abort
+ ;; pass > warn > waived > skip > fail > abort
+
+ ((= 1 status-compare-result) ;; src is better, dest is worse
+ (list dest-test-id "WORSE" (conc src-status "->" dest-status) src-value dest-value))
+ (else
+ (list dest-test-id "BETTER" (conc src-status "->" dest-status) src-value dest-value)))))
+ (list test-name item-path xor-new-item)))
+ all-keys)))
+
+ (if hide-clean
+ (filter
+ (lambda (item)
+ (not
+ (equal?
+ "CLEAN"
+ (list-ref (list-ref item 2) 1))))
+ res)
+ res))))
+
+(define (diff:run-name->run-id run-name)
+ (if (number? run-name)
+ run-name
+ (let* ((qry-res (rmt:get-runs run-name 1 0 '())))
+ (if (eq? 2 (vector-length qry-res))
+ (vector-ref (car (vector-ref qry-res 1)) 1)
+ #f))))
+
+(define (diff:target+run-name->run-id target run-name)
+ (let* ((keys (rmt:get-keys))
+ (target-parts (if target (string-split target "/") (map (lambda (x) "%") keys))))
+ (if (not (eq? (length keys) (length keys)))
+ (begin
+ (print "Error: Target ("target") item count does not match fields count target tokens="target-parts" fields="keys)
+ #f)
+ (let* ((target-map (zip keys target-parts))
+ (qry-res (rmt:get-runs run-name 1 0 target-map)))
+
+ (if (eq? 2 (vector-length qry-res))
+ (let ((first-ent (vector-ref qry-res 1)))
+ (if (> (length first-ent) 0)
+ (vector-ref (car first-ent) 1)
+ #f))
+ #f)))))
+
+(define (diff:run-id->tests-mindat run-id #!key (testpatt "%/%"))
+ (let* ((states '())
+ (statuses '())
+ (offset #f)
+ (limit #f)
+ (not-in #t)
+ (sort-by #f)
+ (sort-order #f)
+ (qryvals "id,testname,item_path,state,status")
+ (qryvals "id,testname,item_path,state,status")
+ (last-update 0)
+ (mode #f)
+ )
+ (map
+ ;; (lambda (row)
+ ;; (match row
+ ;; ((#(id test-name item-path state status)
+ ;; (list test-name item-path (list id state status))))
+ ;; (else #f)))
+ (lambda (row)
+ (let* ((id (vector-ref row 0))
+ (test-name (vector-ref row 1))
+ (item-path (vector-ref row 2))
+ (state (vector-ref row 3))
+ (status (vector-ref row 4)))
+ (list test-name item-path (list id state status))))
+
+ (rmt:get-tests-for-run run-id
+ testpatt states statuses
+ offset limit
+ not-in sort-by sort-order
+ qryvals
+ last-update
+ mode))))
+
+
+(define (diff:diff-runs src-run-id dest-run-id)
+ (let* ((src-tests-mindat (diff:run-id->tests-mindat src-run-id))
+ (dest-tests-mindat (diff:run-id->tests-mindat dest-run-id)))
+ (diff:xor-tests-mindat src-tests-mindat dest-tests-mindat consistent-fail-not-clean: #t)))
+
+
+(define (diff:rundiff-find-by-state run-diff state)
+ (filter
+ (lambda (x)
+ (equal? (list-ref (caddr x) 1) state))
+ run-diff))
+
+(define (diff:rundiff-clean-breakdown run-diff)
+ (map
+ (lambda (run-diff-item)
+ (match run-diff-item
+ ((test-name item-path (junk-id diff-state diff-status (src-test-id src-state src-status) (dest-test-id dest-state dest-status)))
+ (list test-name item-path "CLEAN" src-status))
+ (else "")))
+ (diff:rundiff-find-by-state run-diff "CLEAN")))
+
+(define (diff:summarize-run-diff run-diff)
+
+ (let* ((diff-states (list "CLEAN" "BETTER" "WORSE" "BOTH-BAD" "NOT-IN-DEST" "NOT-IN-SRC" )))
+ (map
+ (lambda (state)
+ (list state
+ (length (diff:rundiff-find-by-state run-diff state))))
+ diff-states)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Presentation code below, business logic above ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define (diff:stml->string in-stml)
+ (with-output-to-string
+ (lambda ()
+ (s:output-new
+ (current-output-port)
+ in-stml))))
+
+(define (diff:state-status->bgcolor state status)
+ (match (list state status)
+ (("CLEAN" _) "#88ff88")
+ (("BETTER" _) "#33ff33")
+ (("WORSE" _) "#ff3333")
+ (("BOTH-BAD" _) "#ff3333")
+ ((_ "WARN") "#ffff88")
+ ((_ "FAIL") "#ff8888")
+ ((_ "ABORT") "#ff0000")
+ ((_ "PASS") "#88ff88")
+ ((_ "SKIP") "#ffff00")
+ (else "#ffffff")))
+
+(define (diff:test-state-status->diff-report-cell state status)
+ (s:td 'bgcolor (diff:state-status->bgcolor state status) status))
+
+(define (diff:diff-state-status->diff-report-cell state status)
+ (s:td state 'bgcolor (diff:state-status->bgcolor state status)))
+
+
+(define (diff:megatest-html-logo)
+
+ "
+___ ___ _ _
+| \\/ | ___ __ _ __ _| |_ ___ ___| |_
+| |\\/| |/ _ \\/ _` |/ _` | __/ _ \\/ __| __|
+| | | | __/ (_| | (_| | || __/\\__ \\ |_
+|_| |_|\\___|\\__, |\\__,_|\\__\\___||___/\\__|
+ |___/
+
")
+
+(define (diff:megatest-html-diff-logo)
+ "
+___ ___ _ _
+| \\/ | ___ __ _ __ _| |_ ___ ___| |_ | _ \\(_)/ _|/ _|
+| |\\/| |/ _ \\/ _` |/ _` | __/ _ \\/ __| __| | | | | | |_| |_
+| | | | __/ (_| | (_| | || __/\\__ \\ |_ | |_| | | _| _|
+|_| |_|\\___|\\__, |\\__,_|\\__\\___||___/\\__| |____/|_|_| |_|
+ |___/
+
")
+
+
+(define (diff:run-id->target+run-name+starttime run-id)
+ (let* ((target (rmt:get-target run-id))
+ (runinfo (rmt:get-run-info run-id)) ; vector of header (list) and result (vector)
+ (info-hash (alist->hash-table
+ (map (lambda (x) (cons (car x) (cadr x))) ; make it a useful hash
+ (zip (vector-ref runinfo 0) (vector->list (vector-ref runinfo 1))))))
+ (run-name (hash-table-ref/default info-hash "runname" "N/A"))
+ (start-time (hash-table-ref/default info-hash "event_time" 0)))
+ (list target run-name start-time)))
+
+(define (diff:deliver-diff-report src-run-id dest-run-id
+ #!key
+ (html-output-file #f)
+ (email-subject-prefix "[MEGATEST DIFF]")
+ (email-recipients-list '()) )
+ (let* ((src-info (diff:run-id->target+run-name+starttime src-run-id))
+ (src-target (car src-info))
+ (src-run-name (cadr src-info))
+ (src-start (conc (seconds->string (caddr src-info)) " " (local-timezone-abbreviation)))
+ (dest-info (diff:run-id->target+run-name+starttime dest-run-id))
+ (dest-target (car dest-info))
+ (dest-run-name (cadr dest-info))
+ (dest-start (conc (seconds->string (caddr dest-info)) " " (local-timezone-abbreviation)))
+
+
+ (run-diff (diff:diff-runs src-run-id dest-run-id ))
+ (test-count (length run-diff))
+ (summary-table
+ (apply s:table 'cellspacing "0" 'border "1"
+ (s:tr
+ (s:th "Diff type")
+ (s:th "% share")
+ (s:th "Count"))
+
+ (map
+ (lambda (state-count)
+ (s:tr
+ (diff:diff-state-status->diff-report-cell (car state-count) #f)
+ (s:td 'align "right" (fmt #f
+ (decimal-align 3
+ (fix 2
+ (num/fit 6
+ (* 100 (/ (cadr state-count) test-count)))))))
+ (s:td 'align "right" (cadr state-count))))
+ (diff:summarize-run-diff run-diff))))
+ (meta-table
+ (s:table 'cellspacing "0" 'border "1"
+
+ (s:tr
+ (s:td 'colspan "2"
+ (s:table 'cellspacing "0" 'border "1"
+ (s:tr
+ (s:th 'align "LEFT" "") (s:th "SOURCE RUN") (s:th "DESTINATION RUN"))
+ (s:tr
+ (s:th 'align "LEFT" "Started") (s:td src-start) (s:td dest-start))
+ (s:tr
+ (s:th 'align "LEFT" "TARGET") (s:td src-target) (s:td dest-target))
+ (s:tr
+ (s:th 'align "LEFT" "RUN NAME") (s:td src-run-name) (s:td dest-run-name)))))))
+
+ (main-table
+ (apply s:table 'cellspacing "0" 'border "1"
+ (s:tr
+ (s:th "Test name")
+ (s:th "Item Path")
+ (s:th (conc "SOURCE"))
+ (s:th (conc "DEST"))
+ (s:th "Diff"))
+ (map
+ (lambda (run-diff-item)
+ (match run-diff-item
+ ((test-name item-path (junk-id diff-state diff-status (src-test-id src-state src-status) (dest-test-id dest-state dest-status)))
+ (s:tr
+ (s:td test-name)
+ (s:td item-path)
+ (diff:test-state-status->diff-report-cell src-state src-status)
+ (diff:test-state-status->diff-report-cell dest-state dest-status)
+ (diff:diff-state-status->diff-report-cell diff-state diff-status)))
+ (else "")))
+ (filter (lambda (run-diff-item)
+ (match run-diff-item
+ ((test-name item-path (junk-id diff-state diff-status (src-test-id src-state src-status) (dest-test-id dest-state dest-status)))
+ (not (equal? diff-state "CLEAN")))
+ (else #f)))
+ run-diff))))
+ (email-subject (conc email-subject-prefix " " src-target "/" src-run-name" vs. "dest-target"/"dest-run-name))
+ (html-body (diff:stml->string (s:body
+ (diff:megatest-html-diff-logo)
+ (s:h2 "Summary")
+ (s:table 'border "0"
+ (s:tr
+ (s:td "Diff calculated at")
+ (s:td (conc (seconds->string) " " (local-timezone-abbreviation))))
+ (s:tr
+ (s:td "MT_RUN_AREA_HOME" ) (s:td *toppath*))
+ (s:tr 'valign "TOP"
+ (s:td summary-table)
+ (s:td meta-table)))
+ (s:h2 "Diffs + consistently failing tests")
+ main-table)))
+
+ )
+ (if html-output-file
+ (with-output-to-file html-output-file (lambda () (print html-body))))
+ (when (and email-recipients-list (> (length email-recipients-list) 0))
+ (sendmail (string-join email-recipients-list ",") email-subject html-body use_html: #t))
+ html-body))
+
+
+
+
+
+;; (let* ((src-run-name "all57")
+;; (dest-run-name "all60")
+;; (src-run-id (diff:run-name->run-id src-run-name))
+;; (dest-run-id (diff:run-name->run-id dest-run-name))
+;; (to-list (list "bjbarcla")))
+;; (diff:deliver-diff-report src-run-id dest-run-id email-recipients-list: to-list html-output-file: "/tmp/bjbarcla/zippy.html")
+;; )
+
+(define (do-diff-report src-target src-runname dest-target dest-runname html-file to-list-raw)
+ (let* (;;(src-target "nope%")
+ ;;(src-runname "all57")
+ ;;(dest-target "%")
+ ;;(dest-runname "all60")
+ (src-run-id (diff:target+run-name->run-id src-target src-runname))
+ (dest-run-id (diff:target+run-name->run-id dest-target dest-runname))
+ ;(html-file "/tmp/bjbarcla/zippy.html")
+ (to-list (if (string? to-list-raw) (string-split to-list-raw ",:") #f))
+ )
+
+ (cond
+ ((not src-run-id)
+ (print "No match for source target/runname="src-target"/"src-runname)
+ (print "Cannot proceed.")
+ #f)
+ ((not dest-run-id)
+ (print "No match for source target/runname="dest-target"/"dest-runname)
+ (print "Cannot proceed.")
+ #f)
+ (else
+ (diff:deliver-diff-report src-run-id dest-run-id email-recipients-list: to-list html-output-file: html-file)))))
+
+
ADDED attic_modular/ducttape-lib.scm
Index: attic_modular/ducttape-lib.scm
==================================================================
--- /dev/null
+++ attic_modular/ducttape-lib.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit ducttape-lib))
+
+(include "ducttape/ducttape-lib.scm")
ADDED attic_modular/env.scm
Index: attic_modular/env.scm
==================================================================
--- /dev/null
+++ attic_modular/env.scm
@@ -0,0 +1,260 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+
+;;======================================================================
+
+(declare (unit env))
+
+(declare (uses margsmod))
+(import margsmod)
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(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))
+ (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))"))))
+ (set-busy-handler! db (busy-timeout 10000))
+ db))
+
+;; save vars in given context, this is NOT incremental by default
+;;
+(define (env:save-env-vars db context #!key (incremental #f)(vardat #f))
+ (with-transaction
+ db
+ (lambda ()
+ ;; first clear out any vars for this context
+ (if (not incremental)(exec (sql db "DELETE FROM envvars WHERE context=?") context))
+ (for-each
+ (lambda (varval)
+ (let ((var (car varval))
+ (val (cdr varval)))
+ (if incremental (exec (sql db "DELETE FROM envvars WHERE context=? AND var=?") context var))
+ (exec (sql db "INSERT INTO envvars (context,var,val) VALUES (?,?,?)") context var val)))
+ (if vardat
+ (hash-table->alist vardat)
+ (get-environment-variables))))))
+
+;; merge contexts in the order given
+;; - each context is applied in the given order
+;; - variables in the paths list are split on the separator and the components
+;; merged using simple delta addition
+;; returns a hash of the merged vars
+;;
+(define (env:merge-contexts db basecontext contexts paths)
+ (let ((result (make-hash-table)))
+ (for-each
+ (lambda (context)
+ (query
+ (for-each-row
+ (lambda (row)
+ (let ((var (car row))
+ (val (cadr row)))
+ (hash-table-set! result var
+ (if (and (hash-table-ref/default result var #f)
+ (assoc var paths)) ;; this var is a path and there is a previous path
+ (let ((sep (cadr (assoc var paths))))
+ (env:merge-path-envvar sep (hash-table-ref result var) val))
+ val)))))
+ (sql db "SELECT var,val FROM envvars WHERE context=?")
+ context))
+ contexts)
+ result))
+
+;; get list of removed variables between two contexts
+;;
+(define (env:get-removed db contexta contextb)
+ (let ((result (make-hash-table)))
+ (query
+ (for-each-row
+ (lambda (row)
+ (let ((var (car row))
+ (val (cadr row)))
+ (hash-table-set! result var val))))
+ (sql db "SELECT var,val FROM envvars WHERE context=? AND var NOT IN (SELECT var FROM envvars WHERE context=?)")
+ contexta contextb)
+ result))
+
+;; get list of variables added to contextb from contexta
+;;
+(define (env:get-added db contexta contextb)
+ (let ((result (make-hash-table)))
+ (query
+ (for-each-row
+ (lambda (row)
+ (let ((var (car row))
+ (val (cadr row)))
+ (hash-table-set! result var val))))
+ (sql db "SELECT var,val FROM envvars WHERE context=? AND var NOT IN (SELECT var FROM envvars WHERE context=?)")
+ contextb contexta)
+ result))
+
+;; get list of variables in both contexta and contexb that have been changed
+;;
+(define (env:get-changed db contexta contextb)
+ (let ((result (make-hash-table)))
+ (query
+ (for-each-row
+ (lambda (row)
+ (let ((var (car row))
+ (val (cadr row)))
+ (hash-table-set! result var val))))
+ (sql db "SELECT var,val FROM envvars AS a WHERE context=? AND val != (SELECT val FROM envvars WHERE var=a.var AND context=?)")
+ contextb contexta)
+ result))
+
+;;
+(define (env:blind-merge l1 l2)
+ (if (null? l1) l2
+ (if (null? l2) l1
+ (cons (car l1) (cons (car l2) (env:blind-merge (cdr l1) (cdr l2)))))))
+
+;; given a before and an after envvar calculate a new merged path
+;;
+(define (env:merge-path-envvar separator patha pathb)
+ (let* ((patha-parts (string-split patha separator))
+ (pathb-parts (string-split pathb separator))
+ (common-parts (lset-intersection equal? patha-parts pathb-parts))
+ (final (delete-duplicates ;; env:blind-merge
+ (append pathb-parts common-parts patha-parts))))
+;; (print "BEFORE: " (string-intersperse patha-parts "\n "))
+;; (print "AFTER: " (string-intersperse pathb-parts "\n "))
+;; (print "COMMON: " (string-intersperse common-parts "\n "))
+ (string-intersperse final separator)))
+
+(define (env:process-path-envvar varname separator patha pathb)
+ (let ((newpath (env:merge-path-envvar separator patha pathb)))
+ (setenv varname newpath)))
+
+(define (env:have-context db context)
+ (> (query fetch-value (sql db "SELECT count(id) FROM envvars WHERE context=?") context)
+ 0))
+
+;; this is so the calling block does not need to import sql-de-lite
+(define (env:close-database db)
+ (close-database db))
+
+(define (env:lazy-hash-table->alist indat)
+ (if (hash-table? indat)
+ (let ((dat (hash-table->alist indat)))
+ (if (null? dat)
+ #f
+ dat))
+ #f))
+
+(define (env:inc-path path)
+ (print "PATH "
+ (conc "#{scheme (env:min-path \"" path "\" \"#{getenv PATH}\")}")))
+;; (conc
+;; "#{scheme (string-intersperse "
+;; "(delete-duplicates "
+;; "(append (string-split \"" path "\" \":\") "
+;; "(string-split \"#{getenv PATH}\" \":\")))"
+;; " \":\")}")))
+
+(define (env:min-path path1 path2)
+ (string-intersperse
+ (delete-duplicates
+ (append
+ (string-split path1 ":")
+ (string-split path2 ":")))
+ ":"))
+
+;; inc path will set a PATH that is incrementally modified when read - config mode only
+;;
+(define (env:print added removed changed #!key (inc-path #t))
+ (let ((a (env:lazy-hash-table->alist added))
+ (r (env:lazy-hash-table->alist removed))
+ (c (env:lazy-hash-table->alist changed)))
+ (case (if (args:get-arg "-dumpmode")
+ (string->symbol (args:get-arg "-dumpmode"))
+ 'bash)
+ ((bash)
+ (if a
+ (begin
+ (print "# Added vars")
+ (map (lambda (dat)(print "export " (car dat) "=" (cdr dat)))
+ (hash-table->alist added))))
+ (if r
+ (begin
+ (print "# Removed vars")
+ (map (lambda (dat)(print "unset " (car dat)))
+ (hash-table->alist removed))))
+ (if c
+ (begin
+ (print "# Changed vars")
+ (map (lambda (dat)(print "export " (car dat) "=" (cdr dat)))
+ (hash-table->alist changed)))))
+ ((csh)
+ (if a
+ (begin
+ (print "# Added vars")
+ (map (lambda (dat)(print "setenv " (car dat) " " (cdr dat)))
+ (hash-table->alist added))))
+ (if r
+ (begin
+ (print "# Removed vars")
+ (map (lambda (dat)(print "unsetenv " (car dat)))
+ (hash-table->alist removed))))
+ (if c
+ (begin
+ (print "# Changed vars")
+ (map (lambda (dat)(print "setenv " (car dat) " " (cdr dat)))
+ (hash-table->alist changed)))))
+ ((config ini)
+ (if a
+ (begin
+ (print "# Added vars")
+ (map (lambda (dat)
+ (let ((var (car dat))
+ (val (cdr dat)))
+ (if (and inc-path
+ (equal? var "PATH"))
+ (env:inc-path val)
+ (print var " " val))))
+ (hash-table->alist added))))
+ (if r
+ (begin
+ (print "# Removed vars")
+ (map (lambda (dat)(print "#{scheme (unsetenv \"" (car dat) "\")}"))
+ (hash-table->alist removed))))
+ (if c
+ (begin
+ (print "# Changed vars")
+ (map (lambda (dat)
+ (let ((var (car dat))
+ (val (cdr dat)))
+ (if (and inc-path
+ (equal? var "PATH"))
+ (env:inc-path val)
+ (print var " " val))))
+ (hash-table->alist changed)))))
+ (else
+ (debug:print-error 0 *default-log-port* "No dumpmode specified, use -dumpmode [bash|csh|config]")))))
ADDED attic_modular/ezsteps.scm
Index: attic_modular/ezsteps.scm
==================================================================
--- /dev/null
+++ attic_modular/ezsteps.scm
@@ -0,0 +1,474 @@
+
+;; Copyright 2006-2012, 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 .
+;;
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+(use srfi-1 posix regex srfi-69 directory-utils call-with-environment-variables posix-extras
+ z3 csv typed-records pathname-expand matchable)
+
+(declare (unit ezsteps))
+(declare (uses db))
+(declare (uses common))
+(declare (uses items))
+(declare (uses runconfig))
+
+(declare (uses margsmod))
+(import margsmod)
+
+;; (declare (uses sdb))
+;; (declare (uses filedb))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses dbmod))
+(import dbmod)
+
+(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)))
+
+(define (ezsteps:create-step-script envdbf stepname prevstepname mode cmd shellexe)
+ (let* (#;(shebang (case mode
+ ((sh) "/bin/sh")
+ ((csh) "/bin/csh")
+ (else "/bin/bash")))
+ (sourcef (conc ".ezsteps/vars_" prevstepname "." mode))
+ (scriptn (conc "ez_" stepname))) ;; remember the name already has an extension .sh, .csh etc.
+ (with-output-to-file scriptn
+ (lambda ()
+ ;; the shebang line
+ (print "#!" shellexe)
+ ;; save the env at start
+ (print "megatest -envcap "stepname"_start "envdbf)
+ ;; source vars from previous steps
+ (if (file-exists? sourcef)
+ (print "source " sourcef))
+ ;; run the command
+ (print cmd)
+ (if (eq? mode 'csh)
+ (print "set ecode=$?")
+ (print "ecode=$?"))
+ ;; 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/vars_"stepname".sh "envdbf)
+ (print "megatest -envdelta "stepname"_start-"stepname"_end -dumpmode csh -o .ezsteps/vars_"stepname".csh "envdbf)
+ (print "exit $ecode")))
+ (system (conc "chmod a+x " scriptn))))
+
+(define (ezsteps:get-ezpropvars res) ;; testconfig)
+ ;; (let* ((res (configf:lookup testconfig "setup" "ezpropvars")))
+ (if (string? res)
+ (let* ((dat (string-split res)))
+ (match dat
+ ((s shellexe)
+ (let ((shl (string->symbol s)))
+ `(,shl . ,shellexe)))
+ ((s)
+ (let* ((shl (string->symbol s))
+ (shellexe (if (eq? shl 'csh) "/bin/csh" "/bin/bash")))
+ `(,shl . ,shellexe)))
+ (else #f)))
+ #f))
+
+;; NOTE: returns logpro-used?
+;;
+(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-n (ezsteps:step-name->mode stepname))
+ (stepinfo (cadr ezstep))
+ (shellmode (ezsteps:get-ezpropvars (configf:lookup testconfig "setup" "ezpropvars"))) ;; returns '(csh|sh . "/path/to/shell")
+ (stepmode (if stepmode-n ;; the .sh or .csh always wins
+ stepmode-n
+ (if shellmode
+ (car shellmode)
+ #f)))
+ (shellexe (if stepmode-n
+ (case stepmode
+ ((csh) "/bin/csh")
+ (else "/bin/bash"))
+ (if shellmode
+ (cdr shellmode)
+ "/bin/bash")))
+ ;; (let ((info (cadr ezstep)))
+ ;; (if (proc? info) "" info)))
+ ;; (stepproc (let ((info (cadr ezstep)))
+ ;; (if (proc? info) info #f)))
+ (stepparts (string-match (regexp "^(\\{([^\\}\\{]*)\\}\\s*|)(.*)$") stepinfo))
+ (stepparams (if (and (list? stepparts)
+ (> (length stepparts) 1))
+ (list-ref stepparts 2)
+ #f)) ;; for future use, {VAR=1,2,3}, run step for each
+ (paramparts (if (string? stepparams)
+ (map (lambda (x)(string-split x "=")) (string-split-fields "[^;]*=[^;]*" stepparams))
+ '()))
+ (subrun (alist-ref "subrun" paramparts equal?))
+ (stepcmd (if (and (list? stepparts)
+ (> (length stepparts) 2))
+ (list-ref stepparts 3)
+ (conc "# error, no command for step "stepname)))
+ (script "") ; "#!/bin/bash\n") ;; yep, we depend on bin/bash FIXME!!!\
+ (logpro-file (conc stepname ".logpro"))
+ (html-file (conc stepname ".html"))
+ (dat-file (conc stepname ".dat"))
+ (tconfig-logpro (configf:lookup testconfig "logpro" stepname))
+ (logpro-used (common:file-exists? logpro-file)))
+ (setenv "MT_STEP_NAME" stepname)
+ (hash-table-set! all-steps-dat stepname `((params . ,paramparts)))
+ (debug:print 0 *default-log-port* "stepparts: " stepparts ", stepparams: " stepparams
+ ", paramparts: " paramparts ", subrun: " subrun ", stepcmd: " stepcmd)
+
+ (if (and tconfig-logpro
+ (not logpro-used)) ;; no logpro file found but have a defn in the testconfig
+ (begin
+ (with-output-to-file logpro-file
+ (lambda ()
+ (print ";; logpro file extracted from testconfig\n"
+ ";;")
+ (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
+ " stepparams: " stepparams " stepcmd: " stepcmd)
+ (if stepmode (ezsteps:create-step-script envdbf stepname prevstepname stepmode stepcmd shellexe))
+
+ ;; ;; 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))))
+
+ ;; call the command using mt_ezstep
+ ;; (set! script (conc "mt_ezstep " stepname " " (if prevstep prevstep "x") " " stepcmd))
+
+ (debug:print 4 *default-log-port* "script: " script)
+ (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 (if stepmode
+ (conc "ez_" 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
+ (debug:print-info 0 *default-log-port* "Running without MT_.* environment variables.")
+ (common:propogate-mt-vars-to-subrun proc '("MT_TARGET" "MT_LINKTREE" "MT_RUNNAME")))
+ (proc)))
+
+ (with-output-to-file "Makefile.ezsteps"
+ (lambda ()
+ (print stepname ".log :")
+ (print "\t" cmd)
+ (if (common:file-exists? (conc stepname ".logpro"))
+ (print "\tlogpro " stepname ".logpro " stepname ".html < " stepname ".log"))
+ (print)
+ (print stepname " : " stepname ".log")
+ (print))
+ #:append)
+
+ (rmt:test-set-top-process-pid run-id test-id pid)
+ (let processloop ((i 0))
+ (let-values (((pid-val exit-status exit-code)(process-wait pid #t)))
+ (mutex-lock! m)
+ (launch:einf-pid-set! exit-info pid) ;; (vector-set! exit-info 0 pid)
+ (launch:einf-exit-status-set! exit-info exit-status) ;; (vector-set! exit-info 1 exit-status)
+ (launch:einf-exit-code-set! exit-info exit-code) ;; (vector-set! exit-info 2 exit-code)
+ (mutex-unlock! m)
+ (if (eq? pid-val 0)
+ (begin
+ (thread-sleep! 2)
+ (processloop (+ i 1))))
+ )))))
+ (debug:print-info 0 *default-log-port* "step " stepname " completed with exit code " (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
+ ;; now run logpro if needed
+ (if logpro-used
+ (let* ((logpro-exe (or (getenv "LOGPRO_EXE") "logpro"))
+ (pid (process-run (conc "/bin/sh -c '"logpro-exe" "logpro-file " " (conc stepname ".html") " < " stepname ".log > /dev/null'"))))
+ (let processloop ((i 0))
+ (let-values (((pid-val exit-status exit-code)(process-wait pid #t)))
+ (mutex-lock! m)
+ ;; (make-launch:einf pid: pid exit-status: exit-status exit-code: exit-code)
+ (launch:einf-pid-set! exit-info pid) ;; (vector-set! exit-info 0 pid)
+ (launch:einf-exit-status-set! exit-info exit-status) ;; (vector-set! exit-info 1 exit-status)
+ (launch:einf-exit-code-set! exit-info exit-code) ;; (vector-set! exit-info 2 exit-code)
+ (mutex-unlock! m)
+ (if (eq? pid-val 0)
+ (begin
+ (thread-sleep! 2)
+ (processloop (+ i 1)))))
+ (debug:print-info 0 *default-log-port* "logpro for step " stepname " exited with code " (launch:einf-exit-code exit-info))))) ;; (vector-ref exit-info 2)))))
+
+ (let ((exinfo (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
+ (logfna (if logpro-used (conc stepname ".html") ""))
+ (comment #f))
+ (if logpro-used
+ (let ((datfile (conc stepname ".dat")))
+ ;; load the .dat file into the test_data table if it exists
+ (if (common:file-exists? datfile)
+ (set! comment (launch:load-logpro-dat run-id test-id stepname)))
+ (rmt:test-set-log! run-id test-id (conc stepname ".html"))))
+ (rmt:teststep-set-status! run-id test-id stepname "end" exinfo comment logfna))
+ ;; set the test final status
+ (let* ((process-exit-status (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
+ (this-step-status (cond
+ ((and (eq? process-exit-status 2) logpro-used) 'warn) ;; logpro 2 = warnings
+ ((and (eq? process-exit-status 3) logpro-used) 'check) ;; logpro 3 = check
+ ((and (eq? process-exit-status 4) logpro-used) 'waived) ;; logpro 4 = waived
+ ((and (eq? process-exit-status 5) logpro-used) 'abort) ;; logpro 5 = abort
+ ((and (eq? process-exit-status 6) logpro-used) 'skip) ;; logpro 6 = skip
+ ((eq? process-exit-status 0) 'pass) ;; logpro 0 = pass
+ (else 'fail)))
+ (overall-status (cond
+ ((eq? (launch:einf-rollup-status exit-info) 2) 'warn) ;; rollup-status (vector-ref exit-info 3)
+ ((eq? (launch:einf-rollup-status exit-info) 0) 'pass) ;; (vector-ref exit-info 3)
+ (else 'fail)))
+ (next-status (cond
+ ((eq? overall-status 'pass) this-step-status)
+ ((eq? overall-status 'warn)
+ (if (eq? this-step-status 'fail) 'fail 'warn))
+ ((eq? overall-status 'abort) 'abort)
+ (else 'fail)))
+ (next-state ;; "RUNNING") ;; WHY WAS THIS CHANGED TO NOT USE (null? tal) ??
+ (cond
+ ((null? tal) ;; more to run?
+ "COMPLETED")
+ (else "RUNNING"))))
+ (debug:print 4 *default-log-port* "Exit value received: " (launch:einf-exit-code exit-info) " logpro-used: " logpro-used
+ " this-step-status: " this-step-status " overall-status: " overall-status
+ " next-status: " next-status " rollup-status: " (launch:einf-rollup-status exit-info)) ;; (vector-ref exit-info 3))
+ (case next-status
+ ((warn)
+ (launch:einf-rollup-status-set! exit-info 2) ;; (vector-set! exit-info 3 2) ;; rollup-status
+ ;; NB// test-set-status! does rdb calls under the hood
+ (tests:test-set-status! run-id test-id next-state "WARN"
+ (if (eq? this-step-status 'warn) "Logpro warning found" #f)
+ #f))
+ ((check)
+ (launch:einf-rollup-status-set! exit-info 3) ;; (vector-set! exit-info 3 3) ;; rollup-status
+ ;; NB// test-set-status! does rdb calls under the hood
+ (tests:test-set-status! run-id test-id next-state "CHECK"
+ (if (eq? this-step-status 'check) "Logpro check found" #f)
+ #f))
+ ((waived)
+ (launch:einf-rollup-status-set! exit-info 4) ;; (vector-set! exit-info 3 3) ;; rollup-status
+ ;; NB// test-set-status! does rdb calls under the hood
+ (tests:test-set-status! run-id test-id next-state "WAIVED"
+ (if (eq? this-step-status 'check) "Logpro waived found" #f)
+ #f))
+ ((abort)
+ (launch:einf-rollup-status-set! exit-info 5) ;; (vector-set! exit-info 3 4) ;; rollup-status
+ ;; NB// test-set-status! does rdb calls under the hood
+ (tests:test-set-status! run-id test-id next-state "ABORT"
+ (if (eq? this-step-status 'abort) "Logpro abort found" #f)
+ #f))
+ ((skip)
+ (launch:einf-rollup-status-set! exit-info 6) ;; (vector-set! exit-info 3 4) ;; rollup-status
+ ;; NB// test-set-status! does rdb calls under the hood
+ (tests:test-set-status! run-id test-id next-state "SKIP"
+ (if (eq? this-step-status 'skip) "Logpro skip found" #f)
+ #f))
+ ((pass)
+ (tests:test-set-status! run-id test-id next-state "PASS" #f #f))
+ (else ;; 'fail
+ (launch:einf-rollup-status-set! exit-info 1) ;; (vector-set! exit-info 3 1) ;; force fail, this used to be next-state but that doesn't make sense. should always be "COMPLETED"
+ (tests:test-set-status! run-id test-id "COMPLETED" "FAIL" (conc "Failed at step " stepname) #f)
+ )))
+ logpro-used))
+
+(define (ezsteps:run-from testdat start-step-name run-one)
+ ;;# TODO - recapture item variables, debug repeated step eval; regen logpro from test
+ (let* ((do-update-test-state-status #f)
+ (test-run-dir ;; (filedb:get-path *fdb*
+ (db:test-get-rundir testdat)) ;; )
+ (testconfig (read-config (conc test-run-dir "/testconfig") #f #t environ-patt: "pre-launch-env-vars"))
+ (ezstepslst (hash-table-ref/default testconfig "ezsteps" '()))
+ (run-mutex (make-mutex))
+ (rollup-status 0)
+ (rollup-status-string #f)
+ (rollup-status-sym #f)
+ (exit-info (vector #t #t #t))
+ (test-id (db:test-get-id testdat))
+ (run-id (db:test-get-run_id testdat))
+ (test-name (db:test-get-testname testdat))
+ (orig-test-state (db:test-get-state testdat))
+ (orig-test-status (db:test-get-status testdat))
+ (kill-job #f) ;; for future use (on re-factoring with launch.scm code
+ (the-step-params '())) ;; not exactly "functional"
+
+ ;; keep trying till NFS deigns to populate test run dir on this host
+ (let loop ((count 5))
+ (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))))))
+
+ (debug:print-info 0 *default-log-port* "Running in directory " test-run-dir)
+ (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))
+ (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)
+ ;;(runflag #f)
+ (saw-start-step-name #f)) ;; flag used to skip steps when not starting at the beginning
+ (if (or (vector-ref exit-info 1)
+ (equal? (alist-ref 'keep-going prev-step-params) 'yes))
+ (let* ((prev-step-params the-step-params) ;; need to snag this now
+ (stepname (car ezstep)) ;; do stuff to run the step
+ (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 '"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))))
+ )
+ (debug:print 0 *default-log-port* "NOTE: stepparms=" stepparms)
+ (set! prev-step-params stepparms)
+ (set! do-update-test-state-status (and proceed-with-this-step (null? tal)))
+ ;;(BB> "stepname="stepname" proceed-with-this-step="proceed-with-this-step " do-update-test-state-status="do-update-test-state-status " orig-test-state="orig-test-state" orig-test-status="orig-test-status)
+ (cond
+ ((and (not proceed-with-this-step) (null? tal))
+ 'done)
+ ((not proceed-with-this-step)
+ (loop (car tal)
+ (cdr tal)
+ status-sym-so-far
+ 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))
+ (testinfo (rmt:get-testinfo-state-status run-id test-id))) ;; refresh the testdat, call it iteminfo in case need prev/curr
+ ;; Am I completed?
+ (if (equal? (db:test-get-state testinfo) "RUNNING") ;; (not (equal? (db:test-get-state testinfo) "COMPLETED"))
+ (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)
+ ) ;; (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
+ (if do-update-test-state-status new-state orig-test-state)
+ (if do-update-test-state-status new-status orig-test-status)
+ (args:get-arg "-m") #f)
+ ;; need to update the top test record if PASS or FAIL and this is a subtest
+ (if (and (not (equal? item-path "")) do-update-test-state-status)
+ (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)
+ rollup-status-string))
+
+(define (ezsteps:spawn-run-from testdat start-step-name run-one)
+ (thread-start!
+ (make-thread
+ (lambda ()
+ (ezsteps:run-from testdat start-step-name run-one))
+ (conc "ezstep run single step " start-step-name " run-one="run-one)))
+ )
+
ADDED attic_modular/fdb_records.scm
Index: attic_modular/fdb_records.scm
==================================================================
--- /dev/null
+++ attic_modular/fdb_records.scm
@@ -0,0 +1,36 @@
+;; 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 .
+
+;; Single record for managing a filedb
+;; make-vector-record "Filedb record" filedb fdb db dbpath pathcache idcache partcache
+;; Filedb record
+(define (make-filedb:fdb)(make-vector 5))
+(define-inline (filedb:fdb-get-db vec) (vector-ref vec 0))
+(define-inline (filedb:fdb-get-dbpath vec) (vector-ref vec 1))
+(define-inline (filedb:fdb-get-pathcache vec) (vector-ref vec 2))
+(define-inline (filedb:fdb-get-idcache vec) (vector-ref vec 3))
+(define-inline (filedb:fdb-get-partcache vec) (vector-ref vec 4))
+(define-inline (filedb:fdb-set-db! vec val)(vector-set! vec 0 val))
+(define-inline (filedb:fdb-set-dbpath! vec val)(vector-set! vec 1 val))
+(define-inline (filedb:fdb-set-pathcache! vec val)(vector-set! vec 2 val))
+(define-inline (filedb:fdb-set-idcache! vec val)(vector-set! vec 3 val))
+(define-inline (filedb:fdb-set-partcache! vec val)(vector-set! vec 4 val))
+
+;; children records, should have use something other than "child"
+(define-inline (filedb:child-get-id vec) (vector-ref vec 0))
+(define-inline (filedb:child-get-path vec) (vector-ref vec 1))
+(define-inline (filedb:child-get-parent_id vec)(vector-ref vec 2))
ADDED attic_modular/filedb.scm
Index: attic_modular/filedb.scm
==================================================================
--- /dev/null
+++ attic_modular/filedb.scm
@@ -0,0 +1,255 @@
+;; Copyright 2006-2011, 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 .
+;;
+
+;; (require-extension synch sqlite3 posix srfi-13 srfi-1 utils regex)
+(use sqlite3 srfi-1 posix regex srfi-69 srfi-13 posix-extras)
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit filedb))
+
+(include "fdb_records.scm")
+;; (include "settings.scm")
+
+(define (filedb:open-db dbpath)
+ (let* ((fdb (make-filedb:fdb))
+ (dbexists (common:file-exists? dbpath))
+ (db (sqlite3:open-database dbpath)))
+ (filedb:fdb-set-db! fdb db)
+ (filedb:fdb-set-dbpath! fdb dbpath)
+ (filedb:fdb-set-pathcache! fdb (make-hash-table))
+ (filedb:fdb-set-idcache! fdb (make-hash-table))
+ (filedb:fdb-set-partcache! fdb (make-hash-table))
+ (sqlite3:set-busy-handler! db (make-busy-timeout 136000))
+ (if (not dbexists)
+ (begin
+ (sqlite3:execute db "PRAGMA synchronous = OFF;")
+ (sqlite3:execute db "CREATE TABLE names (id INTEGER PRIMARY KEY,name TEST);") ;; for future use - change path in paths table to path_id
+ (sqlite3:execute db "CREATE INDEX name_index ON names (name);")
+ ;; NB// We store a useful subset of file attributes but do not attempt to store all
+ (sqlite3:execute db "CREATE TABLE paths (id INTEGER PRIMARY KEY,
+ path TEXT,
+ parent_id INTEGER,
+ mode INTEGER DEFAULT -1,
+ uid INTEGER DEFAULT -1,
+ gid INTEGER DEFAULT -1,
+ size INTEGER DEFAULT -1,
+ mtime INTEGER DEFAULT -1);")
+ (sqlite3:execute db "CREATE INDEX path_index ON paths (path,parent_id);")
+ (sqlite3:execute db "CREATE TABLE bases (id INTEGER PRIMARY KEY,base TEXT, updated TIMESTAMP);")))
+ ;; close the sqlite3 db and open it as needed
+ (filedb:finalize-db! fdb)
+ (filedb:fdb-set-db! fdb #f)
+ fdb))
+
+(define (filedb:reopen-db fdb)
+ (let ((db (sqlite3:open-database (filedb:fdb-get-dbpath fdb))))
+ (filedb:fdb-set-db! fdb db)
+ (sqlite3:set-busy-handler! db (make-busy-timeout 136000))))
+
+(define (filedb:finalize-db! fdb)
+ (sqlite3:finalize! (filedb:fdb-get-db fdb)))
+
+(define (filedb:get-current-time-string)
+ (string-chomp (time->string (seconds->local-time (current-seconds)))))
+
+(define (filedb:get-base-id db path)
+ (let ((stmt (sqlite3:prepare db "SELECT id FROM bases WHERE base=?;"))
+ (id-num #f))
+ (sqlite3:for-each-row
+ (lambda (num) (set! id-num num)) stmt path)
+ (sqlite3:finalize! stmt)
+ id-num))
+
+(define (filedb:get-path-id db path parent)
+ (let ((stmt (sqlite3:prepare db "SELECT id FROM paths WHERE path=? AND parent_id=?;"))
+ (id-num #f))
+ (sqlite3:for-each-row
+ (lambda (num) (set! id-num num)) stmt path parent)
+ (sqlite3:finalize! stmt)
+ id-num))
+
+(define (filedb:add-base db path)
+ (let ((existing (filedb:get-base-id db path)))
+ (if existing #f
+ (begin
+ (sqlite3:execute db "INSERT INTO bases (base,updated) VALUES (?,?);" path (filedb:get-current-time-string))))))
+
+;; index value field notes
+;; 0 inode number st_ino
+;; 1 mode st_mode bitfield combining file permissions and file type
+;; 2 number of hard links st_nlink
+;; 3 UID of owner st_uid as with file-owner
+;; 4 GID of owner st_gid
+;; 5 size st_size as with file-size
+;; 6 access time st_atime as with file-access-time
+;; 7 change time st_ctime as with file-change-time
+;; 8 modification time st_mtime as with file-modification-time
+;; 9 parent device ID st_dev ID of device on which this file resides
+;; 10 device ID st_rdev device ID for special files (i.e. the raw major/minor number)
+;; 11 block size st_blksize
+;; 12 number of blocks allocated st_blocks
+
+(define (filedb:add-path-stat db path parent statinfo)
+ (let ((stmt (sqlite3:prepare db "INSERT INTO paths (path,parent_id,mode,uid,gid,size,mtime) VALUES (?,?,?,?,?,?,?);")))
+ (sqlite3:execute stmt
+ path
+ parent
+ (vector-ref statinfo 1) ;; mode
+ (vector-ref statinfo 3) ;; uid
+ (vector-ref statinfo 4) ;; gid
+ (vector-ref statinfo 5) ;; size
+ (vector-ref statinfo 8) ;; mtime
+ )
+ (sqlite3:finalize! stmt))) ;; (filedb:get-current-time-string))))
+
+(define (filedb:add-path db path parent)
+ (let ((stmt (sqlite3:prepare db "INSERT INTO paths (path,parent_id) VALUES (?,?);")))
+ (sqlite3:execute stmt path parent)
+ (sqlite3:finalize! stmt)))
+
+(define (filedb:register-path fdb path #!key (save-stat #f))
+ (let* ((db (filedb:fdb-get-db fdb))
+ (pathcache (filedb:fdb-get-pathcache fdb))
+ (stat (if save-stat (file-stat path #t)))
+ (id (hash-table-ref/default pathcache path #f)))
+ (if (not db)(filedb:reopen-db fdb))
+ (if id id
+ (let ((plist (string-split path "/")))
+ (let loop ((head (car plist))
+ (tail (cdr plist))
+ (parent 0))
+ (let ((id (filedb:get-path-id db head parent))
+ (done (null? tail)))
+ (if id ;; we'll have a id if the path is already registered
+ (if done
+ (begin
+ (hash-table-set! pathcache path id)
+ id) ;; return the last path id for a result
+ (loop (car tail)(cdr tail) id))
+ (begin ;; add the path and then repeat the loop with the same data
+ (if save-stat
+ (filedb:add-path-stat db head parent stat)
+ (filedb:add-path db head parent))
+ (loop head tail parent)))))))))
+
+(define (filedb:update-recursively fdb path #!key (save-stat #f))
+ (let ((p (open-input-pipe (string-append "find -L " path)))) ;; (resolve-pathname path)))) ;; (string-append "find " path))))
+ (print "processed 0 files...")
+ (let loop ((l (read-line p))
+ (lc 0)) ;; line count
+ (if (eof-object? l)
+ (begin
+ (print " " lc " files")
+ (close-input-port p))
+ (begin
+ (filedb:register-path fdb l save-stat: save-stat) ;; (get-real-path l)) ;; don't like losing the original path info
+ (if (= (modulo lc 100) 0)
+ (print " " lc " files"))
+ (loop (read-line p)(+ lc 1)))))))
+
+(define (filedb:update fdb path #!key (save-stat #f))
+ ;; first get the realpath and add it to the bases table
+ (let ((real-path path) ;; (filedb:get-real-path path))
+ (db (filedb:fdb-get-db fdb)))
+ (filedb:add-base db real-path)
+ (filedb:update-recursively fdb path save-stat: save-stat)))
+
+;; not used and broken
+;;
+(define (filedb:get-real-path path)
+ (let* ((p (open-input-pipe (string-append real-path " " (regexp-escape path))))
+ (pth (read-line p)))
+ (if (eof-object? pth) path
+ (begin
+ (close-input-port p)
+ pth))))
+
+(define (filedb:drop-base fdb path)
+ (print "Sorry, I don't do anything yet"))
+
+(define (filedb:find-all fdb pattern action)
+ (let* ((db (filedb:fdb-get-db fdb))
+ (stmt (sqlite3:prepare db "SELECT id FROM paths WHERE path like ?;"))
+ (result '()))
+ (sqlite3:for-each-row
+ (lambda (num)
+ (action num)
+ (set! result (cons num result))) stmt pattern)
+ (sqlite3:finalize! stmt)
+ result))
+
+(define (filedb:get-path-record fdb id)
+ (let* ((db (filedb:fdb-get-db fdb))
+ (partcache (filedb:fdb-get-partcache fdb))
+ (dat (hash-table-ref/default partcache id #f)))
+ (if dat dat
+ (let ((stmt (sqlite3:prepare db "SELECT path,parent_id FROM paths WHERE id=?;"))
+ (result #f))
+ (sqlite3:for-each-row
+ (lambda (path parent_id)(set! result (list path parent_id))) stmt id)
+ (hash-table-set! partcache id result)
+ (sqlite3:finalize! stmt)
+ result))))
+
+(define (filedb:get-children fdb parent-id)
+ (let* ((db (filedb:fdb-get-db fdb))
+ (res '()))
+ (sqlite3:for-each-row
+ (lambda (id path parent-id)
+ (set! res (cons (vector id path parent-id) res)))
+ db "SELECT id,path,parent_id FROM paths WHERE parent_id=?;"
+ parent-id)
+ res))
+
+;; retrieve all that have children and those without
+;; children that match patt
+(define (filedb:get-children-patt fdb parent-id search-patt)
+ (let* ((db (filedb:fdb-get-db fdb))
+ (res '()))
+ ;; first get the children that have no children
+ (sqlite3:for-each-row
+ (lambda (id path parent-id)
+ (set! res (cons (vector id path parent-id) res)))
+ db "SELECT id,path,parent_id FROM paths WHERE parent_id=? AND
+ (id IN (SELECT parent_id FROM paths) OR path LIKE ?);"
+ parent-id search-patt)
+ res))
+
+(define (filedb:get-path fdb id)
+ (let* ((db (filedb:fdb-get-db fdb))
+ (idcache (filedb:fdb-get-idcache fdb))
+ (path (hash-table-ref/default idcache id #f)))
+ (if (not db)(filedb:reopen-db fdb))
+ (if path path
+ (let loop ((curr-id id)
+ (path ""))
+ (let ((path-record (filedb:get-path-record fdb curr-id)))
+ (if (not path-record) #f ;; this id has no path
+ (let* ((parent-id (list-ref path-record 1))
+ (pname (list-ref path-record 0))
+ (newpath (string-append "/" pname path)))
+ (if (= parent-id 0) ;; fields 0=path, 1=parent. root parent=0
+ (begin
+ (hash-table-set! idcache id newpath)
+ newpath)
+ (loop parent-id newpath)))))))))
+
+(define (filedb:search db pattern)
+ (let ((action (lambda (id)(print (filedb:get-path db id)))))
+ (filedb:find-all db pattern action)))
+
ADDED attic_modular/ftail.scm
Index: attic_modular/ftail.scm
==================================================================
--- /dev/null
+++ attic_modular/ftail.scm
@@ -0,0 +1,108 @@
+;;======================================================================
+;; Copyright 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 .
+
+;;======================================================================
+
+(declare (unit ftail))
+
+(module ftail
+ (
+ open-tail-db
+ tail-write
+ tail-get-fid
+ file-tail
+ )
+
+(import scheme chicken data-structures extras)
+(use (prefix sqlite3 sqlite3:) posix typed-records)
+
+(define (open-tail-db )
+ (let* ((basedir (create-directory (conc "/tmp/" (current-user-name))))
+ (dbpath (conc basedir "/megatest_logs.db"))
+ (dbexists (file-exists? dbpath))
+ (db (sqlite3:open-database dbpath))
+ (handler (sqlite3:make-busy-timeout 136000)))
+ (sqlite3:set-busy-handler! db handler)
+ (sqlite3:execute db "PRAGMA synchronous = 0;")
+ (if (not dbexists)
+ (begin
+ (sqlite3:execute db "CREATE TABLE IF NOT EXISTS log_files (id INTEGER PRIMARY KEY,filename TEXT,event_time TIMESTAMP DEFAULT (strftime('%s','now')));")
+ (sqlite3:execute db "CREATE TABLE IF NOT EXISTS log_data (id INTEGER PRIMARY KEY,fid INTEGER,line TEXT,event_time TIMESTAMP DEFAULT (strftime('%s','now')));")
+ ))
+ db))
+
+(define (tail-write db fid lines)
+ (sqlite3:with-transaction
+ db
+ (lambda ()
+ (for-each
+ (lambda (line)
+ (sqlite3:execute db "INSERT INTO log_data (fid,line) VALUES (?,?);" fid line))
+ lines))))
+
+(define (tail-get-fid db fname)
+ (let ((fid (handle-exceptions
+ exn
+ #f
+ (sqlite3:first-result db "SELECT id FROM log_files WHERE filename=?;" fname))))
+ (if fid
+ fid
+ (begin
+ (sqlite3:execute db "INSERT INTO log_files (filename) VALUES (?);" fname)
+ (tail-get-fid db fname)))))
+
+(define (file-tail fname #!key (db-in #f))
+ (let* ((inp (open-input-file fname))
+ (db (or db-in (open-tail-db)))
+ (fid (tail-get-fid db fname)))
+ (let loop ((inl (read-line inp))
+ (lines '())
+ (lastwr (current-seconds)))
+ (if (eof-object? inl)
+ (let ((timed-out (> (- (current-seconds) lastwr) 60)))
+ (if timed-out (tail-write db fid (reverse lines)))
+ (sleep 1)
+ (if timed-out
+ (loop (read-line inp) '() (current-seconds))
+ (loop (read-line inp) lines lastwr)))
+ (let* ((savelines (> (length lines) 19)))
+ ;; (print inl)
+ (if savelines (tail-write db fid (reverse lines)))
+ (loop (read-line inp)
+ (if savelines
+ '()
+ (cons inl lines))
+ (if savelines
+ (current-seconds)
+ lastwr)))))))
+
+;; offset -20 means get last 20 lines
+;;
+(define (tail-get-lines db fid offset count)
+ (if (> offset 0)
+ (sqlite3:map-row (lambda (id line)
+ (vector id line))
+ db
+ "SELECT id,line FROM log_data WHERE fid=? OFFSET ? LIMIT ?;" fid offset count)
+ (reverse ;; get N from the end
+ (sqlite3:map-row (lambda (id line)
+ (vector id line))
+ db
+ "SELECT id,line FROM log_data WHERE fid=? ORDER BY id DESC LIMIT ?;" fid (abs offset)))))
+
+)
ADDED attic_modular/gen-data-for-graph.scm
Index: attic_modular/gen-data-for-graph.scm
==================================================================
--- /dev/null
+++ attic_modular/gen-data-for-graph.scm
@@ -0,0 +1,72 @@
+;; 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 .
+;;
+(use foof-loop sql-de-lite posix)
+
+(define beginning-2016 1451636435.0)
+(define now (current-seconds))
+(define one-year-ago (- now (* 365 24 60 60)))
+
+(define db (open-database "example.db"))
+
+(exec (sql db "CREATE TABLE IF NOT EXISTS alldat (event_time,var,val)"))
+
+;; sin(time)
+(with-transaction
+ db
+ (lambda ()
+ (loop ((for m (up-from (/ one-year-ago 60) (to (/ now 60))))) ;; days of the year
+ (let ((thetime (* m 60))
+ (thehour (round (/ m 60))))
+ (let loop ((lastsec -1)
+ (sec (random 60))
+ (count 0))
+ (if (> sec lastsec)
+ (exec (sql db "INSERT INTO alldat (event_time,var,val) VALUES (?,?,?)")
+ (+ thetime sec) ;; (* sec 60))
+ "stuff"
+ (if (even? thehour)
+ (random 1000)
+ (random 6))))
+ (if (< count 20)
+ (loop (max sec lastsec)(random 60)(+ count 1))))))))
+
+(close-database db)
+
+
+;; (with-transaction
+;; db
+;; (lambda ()
+;; (loop ((for d (up-from 0 (to 365)))) ;; days of the year
+;; (print "Day: " d)
+;; (loop ((for h (up-from 1 (to 24))))
+;; (loop ((for m (up-from 1 (to 60))))
+;; (let ((thetime (+ beginning-2016 (* 365 24 60 60)(* h 60 60)(* m 60))))
+;; (let loop ((lastsec -1)
+;; (sec (random 60))
+;; (count 0))
+;; (if (> sec lastsec)
+;; (exec (sql db "INSERT INTO alldat (event_time,var,val) VALUES (?,?,?)")
+;; (+ thetime sec) ;; (* sec 60))
+;; "stuff"
+;; (if (even? h)
+;; (random 100)
+;; (random 6))))
+;; (if (< count 20)
+;; (loop (max sec lastsec)(random 60)(+ count 1))))))))))
+;;
+;; (close-database db)
ADDED attic_modular/genexample.scm
Index: attic_modular/genexample.scm
==================================================================
--- /dev/null
+++ attic_modular/genexample.scm
@@ -0,0 +1,526 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+
+;;======================================================================
+
+(declare (unit genexample))
+(use posix regex matchable)
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses margsmod))
+(import margsmod)
+
+(include "db_records.scm")
+
+(define genexample:example-logpro
+#< 0 "Put description here" #/put pattern here/)
+ ;;
+ ;; You may need ignores to suppress false error or warning hits from the later expects
+ ;; NOTE: Order is important here!
+ (expect:ignore in "LogFileBody" < 99 "Ignore the word error in comments" #/^\/\/.*error/)
+ (expect:warning in "LogFileBody" = 0 "Any warning" #/warn/)
+ (expect:error in "LogFileBody" = 0 "Any error" (list #/ERROR/ #/error/)) ;; but disallow any other errors
+EOF
+)
+
+(define genexample:example-script
+#<\" to create a test.
+
+Thank you for using Megatest.
+
+You can edit your config files and create tests in the " path " directory
+
+")))
+
+
+;;======================================================================
+;; create skeleton files for a test
+;;======================================================================
+
+(define (genexample:mk-megatest-test testname)
+ ;; Gather needed data
+ (let ((waiton #f)
+ (priority #f)
+ (description #f)
+ (steps '())
+ (scripts '())
+ (items '())
+ (rel-path #f))
+
+ (cond
+ ((common:file-exists? "megatest.config") (set! rel-path "./"))
+ ((common:file-exists? "../megatest.config") (set! rel-path "../"))
+ ((common:file-exists? "../../megatest.config") (set! rel-path "../../"))
+ ((common:file-exists? "../../../megatest.config")(set! rel-path "../../../"))) ;; good enough dang it.
+
+ ;; Don't gather data or continue if a) megatest.config can't be found or b) testconfig already exists
+ (if (not rel-path)
+ (begin
+ (print "ERROR: I could not find megatest.config, please run -create-test in the top dir of your megatest area")
+ (exit 1)))
+
+ (if (common:file-exists? (conc rel-path "tests/" testname "/testconfig"))
+ (begin
+ (print "WARNING: You already have a testconfig in " rel-path "tests/" testname ", do you want to clobber your files?")
+ (display "Enter y/n: ")
+ (if (not (equal? "y" (read-line)))
+ (begin
+ (print "INFO: user abort of creation of test " testname)
+ (exit 1)))))
+
+ (print "We are going to generate a skeleton set of files for your test " testname "\n"
+ " *** Note: do not worry too much about typos, you can edit the files created when you are done.")
+
+ (print "\n==================\nPlease describe this test. The description will be visible in various dialogs and reports")
+ (display "Enter one line description for this test: ")
+ (set! description (read-line))
+
+ (print "\n\n==================\nDoes this test, " testname ", require any other test be run prior to launch?")
+ (display (conc "Enter space delimited list of tests which " testname " must wait for (default is no waiton): "))
+ (set! waiton (read-line))
+
+ (print "\n\n==================\nDo you wish to prioritize the running of this test over other tests? If so")
+ (print "enter a number greater than zero here")
+ (display "Enter a priority of 0 (default) or higher: ")
+ (set! priority (read-line))
+
+ ;; Get the steps
+ (print "\n==================\nNow to enter the one or more steps that make up your test, note; you can add more later")
+ (print "Hint; use .sh extension on the script names and we'll create a placeholder script."
+
+ (let ((stepname #f)
+ (scriptname #f))
+ (let loop ((done #f))
+ (display "Enter the name for this step (blank to stop): ")
+ (set! stepname (read-line))
+ (if (not (equal? stepname ""))
+ (begin
+ (display "Enter the script or progam to run: ")
+ (set! scriptname (read-line))
+ (set! steps (append steps (list (list stepname scriptname))))))
+ (if (not (equal? stepname ""))
+ (begin
+ (print "Added step " stepname " to list of steps.\n")
+ (loop #f)))))
+
+ ;; Get the items
+ (print "\n\n==================\nNext we need to get the variables and values you wish to iterate this test over (blank for none)")
+ (let ((varname #f)
+ (values #f))
+ (let loop ((done #f))
+ (display "Enter the variable name: ")
+ (set! varname (read-line))
+ (if (not (equal? varname ""))
+ (begin
+ (display (conc "Enter the space separated list of values for " varname ": "))
+ (set! values (read-line))
+ (set! items (append items (list (conc varname " " values))))))
+ (if (not (equal? varname ""))
+ (loop #f))))
+
+ ;; Now create the test
+ (if (not rel-path)
+ (begin
+ (print "ERROR: You must run this command in a megatest area under where the megatest.config file exists.")
+ (exit 1))
+ (let ((testdir (conc rel-path "tests/" testname)))
+ (create-directory testdir #t)
+ (with-output-to-file (conc testdir "/testconfig")
+ (lambda ()
+ (print "# Add additional steps here. Format is \"stepname script\"\n[ezsteps]")
+ (map (lambda (stp)(print (string-intersperse stp " "))) steps)
+ (print "")
+ (print "# Test requirements are specified here\n[requirements]")
+ (print (if (string-null? waiton) "# " "") "waiton " waiton)
+ (print "priority " (if (string-null? priority) 0 priority) "\n")
+ (print "# Iteration for your test is controlled by the items section\n[items]")
+ (map print items)
+ (print "")
+ (print "# Alternatively you could use a [itemstable] section")
+ (print "# [itemstable]")
+ (print "# ITEMVAR1 a b c")
+ (print "# ITEMVAR2 d e f")
+ (print "#\n# would result in items: a/d b/e c/f\n#\n")
+ (print "# Logpro rules for each step can be captured here in the testconfig")
+ (print "# note: The ;; after the stepname and the leading whitespace are required")
+ (print "#\n[logpro]\n")
+ (for-each (lambda (step)
+ (let ((stepname (car step))
+ (scriptname (cadr step)))
+ (print stepname " ;; rules for checking output from running step " step " with command " scriptname)
+ (print genexample:example-logpro "\n")))
+ steps)
+ (print "# test_meta is a section for storing additional data on your test\n[test_meta]")
+ (print "author " (get-environment-variable "USER"))
+ (print "owner " (get-environment-variable "USER"))
+ (print "description " description)
+ (print "tags tagone,tagtwo")
+ (print "reviewed never")))
+ ;; Now create shell scripts (if extension is .sh) and logpro files
+ (for-each (lambda (stp)
+ (let ((stepname (car stp))
+ (script (cadr stp)))
+ (if (string-match ".*\\.sh$" script)
+ (begin
+ (with-output-to-file (conc testdir "/" script)
+ (lambda ()
+ (print genexample:example-script)))
+ (system (conc "chmod ug+r,a+x " (conc testdir "/" script)))))))
+ steps))))))
+
+;; easier to work backwards than change the upstream code
+;;
+(define (hrs-min-sec->seconds str)
+ (let* ((parts (string-split str))
+ (res 0))
+ (for-each
+ (lambda (part)
+ (set! res
+ (+ res
+ (match (string-match "(\\d+)([a-z])" part)
+ ((_ val units)(* (string->number val)(case (string->symbol units)
+ ((s) 1)
+ ((m) 60)
+ ((h) 3600))))
+ (else 0)))))
+ parts)
+ res))
+
+;; generate a skeleton Megatest area from a current area with runs
+;;
+;; specify target, runname etc to use specific runs for the template
+;;
+(define (genexample:extract-skeleton-area dest-path)
+ (let* ((target (args:get-arg "-target"))
+ (runname (args:get-arg "-runname"))
+ (obtuse (make-hash-table))
+ (obtusef (args:get-arg "-obfuscate"))
+ (letters (string-split-fields "\\S" "abcdefghijklmnopqrstuvwxyz"))
+ (maxletter (- (length letters) 1))
+ (lastlet 0)
+ (lastnum 1)
+ (obfuscate (lambda (instr)
+ (or (hash-table-ref/default obtuse instr #f)
+ (if obtusef
+ (let* ((letter (list-ref letters lastlet))
+ (val (conc letter lastnum)))
+ (if (>= lastlet maxletter)
+ (begin
+ (set! lastlet 0)
+ (set! lastnum (+ lastnum 1)))
+ (set! lastlet (+ lastlet 1)))
+ (hash-table-set! obtuse instr val)
+ val)
+ instr)))))
+ (if (not (and target runname))
+ (debug:print 0 *default-log-port* "WARNING: For best results please specifiy -target and -runname for a good run to use as a template."))
+ (if (not (and (file-exists? "megatest.config")
+ (file-exists? "megatest.db")))
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: this command must be run at the top level of a megatest area where runs have been completed")
+ (exit)))
+
+ ;; first create the dest path and needed subdirectories
+ (if (not (file-exists? dest-path))
+ (begin
+ (create-directory dest-path)
+ (create-directory (conc dest-path "/tests")))
+ (if (file-exists? (conc dest-path "/megatest.config"))
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: destination path already has megatest.config, stopping now.")
+ (exit))))
+
+ ;; dump the config files from this area to the dest area
+ (if (args:get-arg "-obfuscate")
+ (debug:print 0 *default-log-port* "WARNING: obfuscation is NOT done on megatest.config and runconfigs.config. Please edit those files to remove any sensitive information!"))
+ (system (conc "megatest -show-config > " dest-path "/megatest.config"))
+ (system (conc "megatest -show-runconfig > " dest-path "/runconfigs.config"))
+
+ ;; create stepsinfo and items refdbs, some stuff has to be done due to refdb not initing area
+ ;;
+ ;; sheet row col value
+ ;; stepsinfo testname itempath stepname steptime
+ ;; miscinfo "itemsinfo" testname itempath "x"
+ ;;
+ (for-each
+ (lambda (rdbname)
+ (if (not (file-exists? (conc dest-path "/" rdbname)))
+ (begin
+ (create-directory (conc dest-path "/" rdbname "/sxml") #t)
+ (with-output-to-file (conc dest-path "/" rdbname "/sheet-names.cfg")
+ (lambda ()(print))))))
+ '("stepsinfo" "miscinfo"))
+
+ (let* ((runs (rmt:simple-get-runs (or runname "%") #f #f (or target "%") #f))
+ (tests (make-hash-table)) ;; just tests
+ (fullt (make-hash-table)) ;; all test/items
+ (testreg (make-hash-table)) ;; for the testconfigs
+ (stepsrdb (conc dest-path "/stepsinfo"))
+ (miscrdb (conc dest-path "/miscinfo")))
+ (if (> (length runs) 1)
+ (debug:print-info 0 *default-log-port* "More than one run matches, first found data will be used."))
+ ;; get all testnames
+ (for-each
+ (lambda (run-id)
+ (let* ((tests-data (rmt:get-tests-for-run run-id "%" '() '() #f #f #f #f #f #f #f #f)))
+ (for-each
+ (lambda (testdat)
+ (let* ((test-id (db:test-get-id testdat))
+ (testname (db:test-get-testname testdat))
+ (item-path (db:test-get-item-path testdat))
+ (tlevel (db:test-get-is-toplevel testdat))
+ (tfullname (db:test-get-fullname testdat))
+ ;; now get steps info
+ (test-steps (tests:get-compressed-steps run-id test-id))
+ (testconfig (tests:get-testconfig testname item-path testreg #f)))
+
+
+ (if (not (hash-table-exists? fullt tfullname))
+ ;; do the work for this test if not previously done
+ (let* ((new-test-dir (conc dest-path "/tests/" (obfuscate testname)))
+ (tconfigf (conc new-test-dir "/testconfig")))
+ (print "Analyzing and extracting info for " tfullname " as " (obfuscate testname))
+ (print " toplevel: " (if tlevel "yes" "no"))
+ (hash-table-set! fullt tfullname #t) ;; track that this one has been seen
+ (if (not (directory-exists? new-test-dir))
+ (create-directory new-test-dir #t))
+
+ ;; create the testconfig IIF we are a toplevel or an item AND the testconfig has not been previously created
+ (if (and (or (not tlevel)
+ (not (equal? item-path "")))
+ (not (file-exists? tconfigf)))
+ (with-output-to-file tconfigf
+ (lambda ()
+ ;; first the ezsteps
+ (print "[ezsteps]")
+ (for-each
+ (lambda (teststep)
+ (let* ((step-name (vector-ref teststep 0)))
+ (print (obfuscate step-name)
+ " sleep $(refdb lookup #{getenv MT_RUN_AREA_HOME}/stepsinfo "
+ (obfuscate testname) " $MT_ITEMPATH "
+ (obfuscate step-name) ")")))
+ test-steps)
+
+ ;; now the requirements section
+ (if testconfig
+ (begin
+ (print "\n[requirements]")
+ (for-each
+ (lambda (entry)
+ (let* ((key (car entry))
+ (val (cadr entry)))
+ (case (string->symbol key)
+ ((waiton) (print "waiton " (obfuscate val)))
+ (else (print key " " val)))))
+ (configf:get-section testconfig "requirements")))
+ #;(print "WARNING: No testconfig data for " testname ", " item-path))
+
+ (print "\n[items]")
+ (print "THE_ITEM [system refdb getrow #{getenv MT_RUN_AREA_HOME}/miscinfo itemsinfo " (obfuscate testname)" | awk '{print $1}']")
+ )))
+
+ ;; fill the stepsrdb
+ (for-each
+ (lambda (teststep)
+ (let* ((step-name (vector-ref teststep 0))
+ (step-duration (hrs-min-sec->seconds (vector-ref teststep 4))))
+
+ (system (conc "refdb set " stepsrdb " " (obfuscate testname)
+ " '" (if (equal? item-path "")
+ "no-item-path"
+ (obfuscate item-path))
+ "' " (obfuscate step-name) " " step-duration))))
+ test-steps)
+
+ ;; miscinfo "itemsinfo" testname itempath "x"
+ (if (not (equal? item-path ""))
+ (system (conc "refdb set " miscrdb " itemsinfo " (obfuscate testname) " " (obfuscate item-path) " x")))
+
+ ))))
+ tests-data)))
+ (map (lambda (runrec)(simple-run-id runrec)) runs)))
+ ))
ADDED attic_modular/gutils.scm
Index: attic_modular/gutils.scm
==================================================================
--- /dev/null
+++ attic_modular/gutils.scm
@@ -0,0 +1,89 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+;;
+;;======================================================================
+
+(require-library iup)
+(import (prefix iup iup:))
+(use canvas-draw)
+
+(use srfi-1 regex regex-case srfi-69)
+(declare (unit gutils))
+
+;; NOTE: These functions will move to iuputils
+
+(define (gutils:colors-similar? color1 color2)
+ (let* ((c1 (map string->number (string-split color1)))
+ (c2 (map string->number (string-split color2)))
+ (delta (map (lambda (a b)(abs (- a b))) c1 c2)))
+ (null? (filter (lambda (x)(> x 3)) delta))))
+
+(define gutils:colors
+ '((PASS . "70 249 73")
+ (FAIL . "253 33 49")
+ (SKIP . "230 230 0")))
+
+(define (gutils:get-color-spec effective-state)
+ (or (alist-ref effective-state gutils:colors)
+ (alist-ref 'FAIL gutils:colors)))
+
+;; BBnote - state status dashboard button color / text defined here
+(define (gutils:get-color-for-state-status state status);; #!key (get-label #f))
+ ;; ((if get-label cadr car)
+ (case (string->symbol state)
+ ((COMPLETED) ;; ARCHIVED)
+ (case (string->symbol status)
+ ((PASS) (list "70 249 73" status))
+ ((PREQ_FAIL PREQ_DISCARDED) (list "255 127 127" status))
+ ((WARN WAIVED) (list "255 172 13" status))
+ ((SKIP) (list (gutils:get-color-spec 'SKIP) status))
+ ((ABORT) (list "198 36 166" status))
+ (else (list "253 33 49" status))))
+ ((ARCHIVED)
+ (case (string->symbol status)
+ ((PASS) (list "70 170 73" status))
+ ((WARN WAIVED) (list "200 130 13" status))
+ ((SKIP) (list (gutils:get-color-spec 'SKIP) status))
+ (else (list "180 33 49" status))))
+ ;; (if (equal? status "PASS")
+ ;; '("70 249 73" "PASS")
+ ;; (if (or (equal? status "WARN")
+ ;; (equal? status "WAIVED"))
+ ;; (list "255 172 13" status)
+ ;; (list "223 33 49" status)))) ;; greenish orangeish redish
+ ((LAUNCHED) (list "101 123 142" state))
+ ((CHECK) (list "255 100 50" state))
+ ((REMOTEHOSTSTART) (list "50 130 195" state))
+ ((RUNNING STARTED) (list "9 131 232" state))
+ ((KILLREQ) (list "39 82 206" state))
+ ((KILLED) (list "234 101 17" state))
+ ((NOT_STARTED) (case (string->symbol status)
+ ((CHECK STARTED)(list (gutils:get-color-spec 'SKIP) state))
+ (else (list "240 240 240" state))))
+ ;; for xor mode below
+ ;;
+ ((CLEAN)
+ (case (string->symbol status)
+ ((CLEAN-FAIL CLEAN-CHECK CLEAN-ABORT) (list "200 130 13" status)) ;; orange requested for these
+ (else (list "60 235 63" status))))
+ ((DIRTY-BETTER) (list "160 255 153" status))
+ ((DIRTY-WORSE) (list "165 42 42" status))
+ ((BOTH-BAD) (list "180 33 49" status))
+
+ (else (list "192 192 192" state))))
+
ADDED attic_modular/http-transport.scm
Index: attic_modular/http-transport.scm
==================================================================
--- /dev/null
+++ attic_modular/http-transport.scm
@@ -0,0 +1,93 @@
+;; Copyright 2006-2012, 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 .
+
+(require-extension (srfi 18) extras tcp s11n)
+
+
+(use
+ hostinfo
+ http-client
+ intarweb
+ md5
+ message-digest
+ posix
+ posix-extras
+ regex
+ regex-case
+ spiffy
+ spiffy-directory-listing
+ spiffy-request-vars
+ srfi-1
+ srfi-69
+ uri-common
+ )
+
+;; Configurations for server
+(tcp-buffer-size 2048)
+(max-connections 2048)
+
+(declare (unit http-transport))
+
+(declare (uses common))
+(declare (uses db))
+(declare (uses portlogger))
+(import portlogger)
+
+(declare (uses rmt))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses dbmod))
+(import dbmod)
+
+(declare (uses servermod))
+(import servermod)
+
+(declare (uses transport))
+(import transport)
+
+(declare (uses margsmod))
+(import margsmod)
+
+(include "common_records.scm")
+(include "db_records.scm")
+;; (include "js-path.scm")
+
+;; (require-library stml)
+
+;; (require-library stml)
+
+;; (define *server-loop-heart-beat* (current-seconds))
+
+;;======================================================================
+;; S E R V E R
+;; ======================================================================
+
+;;======================================================================
+;; S E R V E R U T I L I T I E S
+;;======================================================================
+
+;;======================================================================
+;; C L I E N T S
+;;======================================================================
+
ADDED attic_modular/index-tree.scm
Index: attic_modular/index-tree.scm
==================================================================
--- /dev/null
+++ attic_modular/index-tree.scm
@@ -0,0 +1,64 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+;;
+;;======================================================================
+
+;;======================================================================
+;; Tests
+;;======================================================================
+
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 dot-locking tcp directory-utils)
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit tests))
+(declare (uses lock-queue))
+(declare (uses db))
+(declare (uses common))
+(declare (uses items))
+(declare (uses runconfig))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "run_records.scm")
+(include "test_records.scm")
+
+;; Populate the links tree with index.html files
+;;
+;; - start from most recent tests and work towards oldest -OR-
+;; start from deepest hierarchy and work way up
+;; - look up tests in megatest.db
+;; - cross-reference the tests to stats.db
+;; - if newer than event_time in stats.db or not registered in stats.db regenerate
+;; - run du and store in stats.db
+;; - when all tests at that level done generate next level up index.html
+;;
+;; include in rollup html index.html:
+;; sum of du
+;; counts of PASS, FAIL, RUNNING, REMOTEHOSTSTART, LAUNCHED, CHECK etc.
+;; overall status
+;;
+;; include in test specific index.html:
+;; host, uname, cpu graph, disk avail graph, steps, data
+;; meta data, state, status, du
+;;
ADDED attic_modular/items.import.scm
Index: attic_modular/items.import.scm
==================================================================
--- /dev/null
+++ attic_modular/items.import.scm
@@ -0,0 +1,61 @@
+;;;; items.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ commonmod
+ debugprint
+ configfmod
+ srfi-69
+ srfi-1
+ postgresql))
+(##sys#register-compiled-module
+ 'items
+ (list)
+ '((items:get-items-from-config . items#items:get-items-from-config)
+ (items:read-items-file . items#items:read-items-file)
+ (items:first-row-intersperse . items#items:first-row-intersperse)
+ (items:check-valid-items . items#items:check-valid-items)
+ (item-table->item-list . items#item-table->item-list)
+ (item-assoc->item-list . items#item-assoc->item-list)
+ (process-itemlist . items#process-itemlist)
+ (*available-db* . commonmod#*available-db*))
+ (list (cons 'debug:catch-and-dump
+ (syntax-rules
+ ()
+ ((debug:catch-and-dump proc procname)
+ (begin
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain (current-error-port))
+ (with-output-to-port
+ (current-error-port)
+ (lambda ()
+ (print ((condition-property-accessor 'exn 'message) exn))
+ (print "Callback error in " procname)
+ (print "Full condition info:\n"
+ (condition->list exn)))))
+ (proc))))))
+ (cons 'common:handle-exceptions
+ (syntax-rules () ((_ exn errstmt body ...) (begin body ...))))
+ (cons 'common:debug-handle-exceptions
+ (syntax-rules
+ ()
+ ((_ debug exn errstmt body ...)
+ (if debug
+ (begin body ...)
+ (handle-exceptions exn errstmt body ...)))))
+ (cons 'define-simple-syntax
+ (syntax-rules
+ ()
+ ((_ (name arg ...) body ...)
+ (define-syntax
+ name
+ (syntax-rules () ((name arg ...) (begin body ...))))))))
+ (list))
+
+;; END OF FILE
ADDED attic_modular/items.scm
Index: attic_modular/items.scm
==================================================================
--- /dev/null
+++ attic_modular/items.scm
@@ -0,0 +1,225 @@
+
+;; Copyright 2006-2012, 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 .
+
+
+;; (define itemdat '((ripeness "green ripe overripe")
+;; (temperature "cool medium hot")
+;; (season "summer winter fall spring")))
+
+(declare (unit items))
+(declare (uses common))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses configfmod))
+
+(module items
+ *
+
+(import scheme chicken data-structures extras ports)
+(import commonmod)
+(import debugprint)
+(import configfmod)
+(import srfi-69
+ srfi-1
+ )
+
+(include "common_records.scm")
+
+;; Puts out all combinations
+(define (process-itemlist hierdepth curritemkey itemlist)
+ (let ((res '()))
+ (if (not hierdepth)
+ (set! hierdepth (length itemlist)))
+ (let loop ((hed (car itemlist))
+ (tal (cdr itemlist)))
+ (if (null? tal)
+ (for-each (lambda (item)
+ (if (> (length curritemkey) (- hierdepth 2))
+ (set! res (append res (list (append curritemkey (list (list (car hed) item))))))))
+ (cadr hed))
+ (begin
+ (for-each (lambda (item)
+ (set! res (append res (process-itemlist hierdepth (append curritemkey (list (list (car hed) item))) tal))))
+ (cadr hed))
+ (loop (car tal)(cdr tal)))))
+ res))
+
+;; (item-assoc->item-list '(("ANIMAL" "Elephant Lion")("SEASON" "Spring Fall")))
+;; => ((("ANIMAL" "Elephant") ("SEASON" "Spring"))
+;; (("ANIMAL" "Elephant") ("SEASON" "Fall"))
+;; (("ANIMAL" "Lion") ("SEASON" "Spring"))
+;; (("ANIMAL" "Lion") ("SEASON" "Fall")))
+(define (item-assoc->item-list itemsdat)
+ (if (and itemsdat (not (null? itemsdat)))
+ (let ((itemlst (filter (lambda (x)
+ (list? x))
+ (map (lambda (x)
+ (debug:print 6 *default-log-port* "item-assoc->item-list x: " x)
+ (if (< (length x) 2)
+ (begin
+ (debug:print-error 0 *default-log-port* "malformed items spec " (string-intersperse x " "))
+ (list (car x)'()))
+ (let* ((name (car x))
+ (items (cadr x))
+ (ilist (list name (if (string? items)
+ (string-split items)
+ '()))))
+ (if (null? ilist)
+ (debug:print-error 0 *default-log-port* "No items specified for " name))
+ ilist)))
+ itemsdat))))
+ (let ((debuglevel 5))
+ (debug:print 5 *default-log-port* "item-assoc->item-list: itemsdat => itemlst ")
+ (if (debug:debug-mode 5)
+ (begin
+ (pp itemsdat)
+ (print " => ")
+ (pp itemlst))))
+ (if (> (length itemlst) 0)
+ (process-itemlist #f '() itemlst)
+ '()))
+ '())) ;; return a list consisting on a single null list for non-item runs
+ ;; Nope, not now, return null as of 6/6/2011
+
+;; (item-table->item-list '(("ANIMAL" "Elephant Lion")("SEASON" "Spring Winter")))
+;; => ((("ANIMAL" "Elephant")("SEASON" "Spring"))
+;; (("ANIMAL" "Lion") ("SEASON" "Winter")))
+(define (item-table->item-list itemtable)
+ (let ((newlst (map (lambda (x)
+ (if (> (length x) 1)
+ (list (car x)
+ (string-split (cadr x)))
+ (list x '())))
+ itemtable))
+ (res '())) ;; a list of items
+ (let loop ((indx 0)
+ (item '()) ;; an item will be ((KEYNAME1 VAL1)(KEYNAME2 VAL2) ...)
+ (elflag #f))
+ (for-each (lambda (row)
+ (let ((rowname (car row))
+ (rowdat (cadr row)))
+ (set! item (append item
+ (list
+ (if (< indx (length rowdat))
+ (let ((new (list rowname (list-ref rowdat indx))))
+ ;; (debug:print 0 *default-log-port* "New: " new)
+ (set! elflag #t)
+ new
+ ) ;; i.e. had at least on legit value to use
+ (list rowname "-")))))))
+ newlst)
+ (if elflag
+ (begin
+ (set! res (append res (list item)))
+ (loop (+ indx 1)
+ '()
+ #f)))
+ res)))
+ ;; Nope, not now, return null as of 6/6/2011
+
+(define (items:check-valid-items class item)
+ (let ((valid-values (let ((s (configf:lookup *configdat* "validvalues" class)))
+ (if s (string-split s) #f))))
+ (if valid-values
+ (if (member item valid-values)
+ item #f)
+ item)))
+
+;; '(("k1" "k2" "k3")
+;; ("a" "b" "c")
+;; ("d" "e" "f"))
+;;
+;; => '((("k1" "a")("k2" "b")("k3" "c"))
+;; (("k1" "d")("k2" "e")("k3" "f")))
+;;
+(define (items:first-row-intersperse data)
+ (if (< (length data) 2)
+ '()
+ (let ((header (car data))
+ (rows (cdr data)))
+ (map (lambda (row)
+ (map list header row))
+ rows))))
+
+;; k1/k2/k3
+;; a/b/c
+;; d/e/f
+;; => '(("k1" "k2" "k3")
+;; ("a" "b" "c")
+;; ("d" "e" "f"))
+;;
+;; => '((("k1" "a")("k2" "b")("k3" "c"))
+;; (("k1" "d")("k2" "e")("k3" "f")))
+;;
+(define (items:read-items-file fname ftype) ;; 'sxml 'slash 'space
+ (if (and fname (file-exists? fname))
+ (items:first-row-intersperse (case ftype
+ ((slash space)
+ (let ((splitter (case ftype
+ ((slash) (lambda (x)(string-split x "/")))
+ (else string-split))))
+ (debug:print 0 *default-log-port* "Reading " fname " of type " ftype)
+ (with-input-from-file fname
+ (lambda ()
+ (let loop ((inl (read-line))
+ (res '()))
+ (if (eof-object? inl)
+ res
+ (loop (read-line)(cons (splitter inl) res))))))))
+ ((sxml)(with-input-from-file fname read))
+ (else (debug:print 0 *default-log-port* "items file type " ftype " not recognised"))))
+ (begin
+ (if fname (debug:print 0 *default-log-port* "no items file " fname " found"))
+ '())))
+
+(define (items:get-items-from-config tconfig)
+ (let* ((slashf (configf:lookup tconfig "itemopts" "slash")) ;; a/b/c\nd/e/f\n ...
+ (sxmlf (configf:lookup tconfig "itemopts" "sxml")) ;; '(("a" "b" "c")("d" "e" "f") ...)
+ (spacef (configf:lookup tconfig "itemopts" "space")) ;; a b c\nd e f\n ...
+ (have-items (hash-table-ref/default tconfig "items" #f))
+ (have-itable (hash-table-ref/default tconfig "itemstable" #f))
+ (items (hash-table-ref/default tconfig "items" '()))
+ (itemstable (hash-table-ref/default tconfig "itemstable" '())))
+ (debug:print 5 *default-log-port* "items: " items " itemstable: " itemstable)
+ (set! items (map (lambda (item)
+ (if (procedure? (cadr item))
+ (list (car item)((cadr item))) ;; evaluate the proc
+ item))
+ items))
+ (set! itemstable (map (lambda (item)
+ (if (procedure? (cadr item))
+ (list (car item)((cadr item))) ;; evaluate the proc
+ item))
+ itemstable))
+ (if (and have-items (null? items)) (debug:print 0 *default-log-port* "WARNING:[items] section in testconfig but no entries defined"))
+ (if (and have-itable (null? itemstable))(debug:print 0 *default-log-port* "WARNNG:[itemstable] section in testconfig but no entries defined"))
+ (if (or (not (null? items))
+ (not (null? itemstable))
+ slashf
+ sxmlf
+ spacef)
+ (append (item-assoc->item-list items)
+ (item-table->item-list itemstable)
+ (items:read-items-file slashf 'slash)
+ (items:read-items-file sxmlf 'sxml)
+ (items:read-items-file spacef 'space))
+ '(()))))
+
+)
+
+
ADDED attic_modular/js-path.scm
Index: attic_modular/js-path.scm
==================================================================
--- /dev/null
+++ attic_modular/js-path.scm
@@ -0,0 +1,18 @@
+;; 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 .
+;;
+(define *java-script-lib* (conc (common:get-install-area) "/share/js/jquery-3.1.0.slim.min.js"))
ADDED attic_modular/key_records.scm
Index: attic_modular/key_records.scm
==================================================================
--- /dev/null
+++ attic_modular/key_records.scm
@@ -0,0 +1,20 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+
+;;======================================================================
+
ADDED attic_modular/launch.scm
Index: attic_modular/launch.scm
==================================================================
--- /dev/null
+++ attic_modular/launch.scm
@@ -0,0 +1,1378 @@
+
+;; 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 .
+
+;;======================================================================
+;; launch a task - this runs on the originating host, tests themselves
+;;
+;;======================================================================
+
+(use regex regex-case base64 sqlite3 srfi-18 directory-utils posix-extras z3
+ call-with-environment-variables csv)
+(use typed-records pathname-expand matchable)
+
+(import (prefix base64 base64:))
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit launch))
+(declare (uses subrun))
+(declare (uses common))
+(declare (uses configf))
+(declare (uses db))
+(declare (uses ezsteps))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses dbmod))
+(import dbmod)
+
+(declare (uses margsmod))
+(import margsmod)
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "megatest-fossil-hash.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 ...
+;; where the {VAR=first,second,third ...} is optional.
+
+;; given an exit code and whether or not logpro was used calculate OK/BAD
+;; return #t if we are ok, #f otherwise
+(define (steprun-good? logpro exitcode stepparms)
+ (or (eq? exitcode 0)
+ (and logpro (eq? exitcode 2)) ;; shouldn't this be (member exitcode 2 ...) with the other ok codes?
+ (let* ((params (alist-ref 'params stepparms)) ;; get the params section
+ (keep-going (if params
+ (alist-ref "keep-going" params equal?)
+ #f)))
+ (debug:print 0 *default-log-port* "keep-going=" keep-going)
+ (and keep-going (equal? (car keep-going) "yes")))))
+
+;; if handed a string, process it, else look for MT_CMDINFO
+(define (launch:get-cmdinfo-assoc-list #!key (encoded-cmd #f))
+ (let ((enccmd (if encoded-cmd encoded-cmd (getenv "MT_CMDINFO"))))
+ (if enccmd
+ (common:read-encoded-string enccmd)
+ '())))
+
+;; 0 1 2 3
+(defstruct launch:einf (pid #t)(exit-status #t)(exit-code #t)(rollup-status 0))
+
+;; return (conc status ": " comment) from the final section so that
+;; the comment can be set in the step record in launch.scm
+;;
+(define (launch:load-logpro-dat run-id test-id stepname)
+ (let ((cname (conc stepname ".dat")))
+ (if (common:file-exists? cname)
+ (let* ((dat (read-config cname #f #f))
+ (csvr (db:logpro-dat->csv dat stepname))
+ (csvt (let-values (((fmt-cell fmt-record fmt-csv) (make-format ",")))
+ (fmt-csv (map list->csv-record csvr))))
+ (status (configf:lookup dat "final" "exit-status"))
+ (msg (configf:lookup dat "final" "message")))
+ (if csvt ;; this if blocked stack dump caused by .dat file from logpro being 0-byte. fixed by upgrading logpro
+ (rmt:csv->test-data run-id test-id csvt)
+ (debug:print 0 *default-log-port* "ERROR: no csvdat exists for run-id: " run-id " test-id: " test-id " stepname: " stepname ", check that logpro version is 1.15 or newer"))
+ ;; (debug:print-info 13 *default-log-port* "Error: run-id/test-id/stepname="run-id"/"test-id"/"stepname" => bad csvr="csvr)
+ ;; )
+ (cond
+ ((equal? status "PASS") "PASS") ;; skip the message part if status is pass
+ (status (conc (configf:lookup dat "final" "exit-status") ": " (if msg msg "no message")))
+ (else #f)))
+ #f)))
+
+(define (launch:manage-steps run-id test-id item-path fullrunscript ezsteps subrun test-name tconfigreg exit-info m)
+ ;; (let-values
+ ;; (((pid exit-status exit-code)
+ ;; (run-n-wait fullrunscript)))
+ ;; (tests:test-set-status! test-id "RUNNING" "n/a" #f #f)
+ ;; Since we should have a clean slate at this time there is no need to do
+ ;; any of the other stuff that tests:test-set-status! does. Let's just
+ ;; force RUNNING/n/a
+
+ ;; (thread-sleep! 0.3)
+ ;; (tests:test-force-state-status! run-id test-id "RUNNING" "n/a")
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path "RUNNING" #f #f)
+ ;; (thread-sleep! 0.3) ;; NFS slowness has caused grief here
+
+ ;; if there is a runscript do it first
+ (if fullrunscript
+ (let ((pid (process-run fullrunscript)))
+ (rmt:test-set-top-process-pid run-id test-id pid)
+ (let loop ((i 0))
+ (let-values
+ (((pid-val exit-status exit-code) (process-wait pid #t)))
+ (mutex-lock! m)
+ (launch:einf-pid-set! exit-info pid) ;; (vector-set! exit-info 0 pid)
+ (launch:einf-exit-status-set! exit-info exit-status) ;; (vector-set! exit-info 1 exit-status)
+ (launch:einf-exit-code-set! exit-info exit-code) ;; (vector-set! exit-info 2 exit-code)
+ (launch:einf-rollup-status-set! exit-info exit-code) ;; (vector-set! exit-info 3 exit-code) ;; rollup status
+ (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 (or ezsteps subrun)
+ (let* ((test-run-dir (tests:get-test-path-from-environment))
+ (testconfig ;; (read-config (conc work-area "/testconfig") #f #t environ-patt: "pre-launch-env-vars")) ;; FIXME??? is allow-system ok here?
+ ;; NOTE: it is tempting to turn off force-create of testconfig but dynamic
+ ;; ezstep names need a full re-eval here.
+ (tests:get-testconfig test-name item-path tconfigreg #t force-create: #t)) ;; 'return-procs)))
+ (ezstepslst (if (hash-table? testconfig)
+ (hash-table-ref/default testconfig "ezsteps" '())
+ #f)))
+ (if testconfig
+ (hash-table-set! *testconfigs* test-name testconfig) ;; cached for lazy reads later ...
+ (begin
+ (launch:setup)
+ (debug:print 0 *default-log-port* "WARNING: no testconfig found for " test-name " in search path:\n "
+ (string-intersperse (tests:get-tests-search-path *configdat*) "\n "))))
+ ;; after all that, still no testconfig? Time to abort
+ (if (not testconfig)
+ (begin
+ (debug:print-error 0 *default-log-port* "Failed to resolve megatest.config, runconfigs.config and testconfig issues. Giving up now")
+ (exit 1)))
+
+ ;; create a proc for the subrun if requested, save that proc in the ezsteps table as the last entry
+ ;; 1. get section [runarun]
+ ;; 2. unset MT_* vars
+ ;; 3. fix target
+ ;; 4. fix runname
+ ;; 5. fix testpatt or calculate it from contour
+ ;; 6. launch the run
+ ;; 7. roll up the run result and or roll up the logpro processed result
+ (when (configf:lookup testconfig "subrun" "runwait") ;; we use runwait as the flag that a subrun is requested
+ (subrun:initialize-toprun-test testconfig test-run-dir)
+ (let* ((mt-cmd (subrun:launch-cmd test-run-dir)))
+ (debug:print-info 0 *default-log-port* "Subrun command is \"" mt-cmd "\"")
+ (set! ezsteps #t) ;; set the needed flag
+ (set! ezstepslst
+ (append (or ezstepslst '())
+ (list (list "subrun" (conc "{subrun=true} " mt-cmd)))))))
+
+ ;; process the ezsteps
+ (if ezsteps
+ (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 ((all-step-names (map car ezstepslst)))
+ (setenv "MT_STEP_NAMES" (string-intersperse all-step-names " "))
+ (let loop ((ezstep (car ezstepslst))
+ (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 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
+ (if (and logpro-used (common:file-exists? (conc stepname ".dat")))
+ (launch:load-logpro-dat run-id test-id stepname))
+ (if (steprun-good? logpro-used (launch:einf-exit-code exit-info) stepparms)
+ (if (not (null? tal))
+ (loop (car tal) (cdr tal) stepname))
+ (debug:print 0 *default-log-port* "WARNING: step " (car ezstep) " failed. Stopping")))
+ (debug:print 0 *default-log-port* "WARNING: a prior step failed, stopping at " ezstep))
+ ))))))))
+
+(define (launch:monitor-job run-id test-id item-path fullrunscript ezsteps test-name tconfigreg exit-info m work-area runtlim misc-flags)
+ (let* ((update-period (string->number (or (configf:lookup *configdat* "setup" "test-stats-update-period") "30")))
+ (start-seconds (current-seconds))
+ (calc-minutes (lambda ()
+ (inexact->exact
+ (round
+ (-
+ (current-seconds)
+ start-seconds)))))
+ (kill-tries 0))
+ ;; (tests:set-full-meta-info #f test-id run-id (calc-minutes) work-area)
+ ;; (tests:set-full-meta-info test-id run-id (calc-minutes) work-area)
+ (tests:set-full-meta-info #f test-id run-id (calc-minutes) work-area 10)
+
+ (let loop ((minutes (calc-minutes))
+ (cpu-load (alist-ref 'adj-core-load (common:get-normalized-cpu-load #f)))
+ (disk-free (get-df (current-directory)))
+ (last-sync (current-seconds)))
+ ;; (common:telemetry-log "zombie" (conc "launch:monitor-job - top of loop encountered at "(current-seconds)" with last-sync="last-sync))
+ (let* ((over-time (> (current-seconds) (+ last-sync update-period)))
+ (new-cpu-load (let* ((load (alist-ref 'adj-core-load (common:get-normalized-cpu-load #f)))
+ (delta (abs (- load cpu-load))))
+ (if (> delta 0.1) ;; don't bother updating with small changes
+ load
+ #f)))
+ (new-disk-free (let* ((df (if over-time ;; only get df every 30 seconds
+ (get-df (current-directory))
+ disk-free))
+ (delta (abs (- df disk-free))))
+ (if (and (> df 0)
+ (> (/ delta df) 0.1)) ;; (> delta 200) ;; ignore changes under 200 Meg
+ df
+ #f)))
+ (do-sync (or new-cpu-load new-disk-free over-time))
+
+ (test-info (rmt:get-test-info-by-id run-id test-id))
+ (state (db:test-get-state test-info))
+ (status (db:test-get-status test-info))
+ (kill-reason "no kill reason specified")
+ (kill-job? #f))
+ ;; (common:telemetry-log "zombie" (conc "launch:monitor-job - decision time encountered at "(current-seconds)" with last-sync="last-sync" do-sync="do-sync" over-time="over-time" update-period="update-period))
+ (cond
+ ((test-get-kill-request run-id test-id)
+ (set! kill-reason "KILLING TEST since received kill request (KILLREQ)")
+ (set! kill-job? #t))
+ ((and runtlim (> (- (current-seconds) start-seconds) runtlim))
+ (set! kill-reason (conc "KILLING TEST DUE TO TIME LIMIT EXCEEDED! Runtime=" (- (current-seconds) start-seconds) " seconds, limit=" runtlim))
+ (set! kill-job? #t))
+ ((equal? status "DEAD")
+ (tests:update-central-meta-info run-id test-id new-cpu-load new-disk-free (calc-minutes) #f #f)
+ (rmt:set-state-status-and-roll-up-items run-id test-id 'foo "RUNNING" "n/a" "was marked dead; really still running.")
+ ;;(set! kill-reason "KILLING TEST because it was marked as DEAD by launch:handle-zombie-tests (might indicate really overloaded server or else overzealous setup.deadtime)") ;; MARK RUNNING
+ (set! kill-job? #f)))
+
+ (debug:print 4 *default-log-port* "cpu: " new-cpu-load " disk: " new-disk-free " last-sync: " last-sync " do-sync: " do-sync)
+ (launch:handle-zombie-tests run-id)
+ (when do-sync
+ ;;(with-output-to-file (conc (getenv "MT_TEST_RUN_DIR") "/last-loadinfo.log" #:append)
+ ;; (lambda () (pp (list (current-seconds) new-cpu-load new-disk-free (calc-minutes)))))
+ ;; (common:telemetry-log "zombie" (conc "launch:monitor-job - dosync started at "(current-seconds)))
+ (tests:update-central-meta-info run-id test-id new-cpu-load new-disk-free (calc-minutes) #f #f)
+ ;;(common:telemetry-log "zombie" (conc "launch:monitor-job - dosync finished at "(current-seconds)))
+ )
+
+ (if kill-job?
+ (begin
+ (debug:print-info 0 *default-log-port* "proceeding to kill test: "kill-reason)
+ (mutex-lock! m)
+ ;; NOTE: The pid can change as different steps are run. Do we need handshaking between this
+ ;; section and the runit section? Or add a loop that tries three times with a 1/4 second
+ ;; between tries?
+ (let* ((pid1 (launch:einf-pid exit-info)) ;; (vector-ref exit-info 0))
+ (pid2 (rmt:test-get-top-process-pid run-id test-id))
+ (pids (delete-duplicates (filter number? (list pid1 pid2)))))
+ (if (not (null? pids))
+ (begin
+ (for-each
+ (lambda (pid)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 0 *default-log-port* "Unable to kill process with pid " pid ", possibly already killed.")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn))
+ (debug:print 0 *default-log-port* "WARNING: Request received to kill job " pid) ;; " (attempt # " kill-tries ")")
+ (debug:print-info 0 *default-log-port* "Signal mask=" (signal-mask))
+ ;; (if (process:alive? pid)
+ ;; (begin
+ (map (lambda (pid-num)
+ (process-signal pid-num signal/term))
+ (process:get-sub-pids pid))
+ (thread-sleep! 5)
+ ;; (if (process:process-alive? pid)
+ (map (lambda (pid-num)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* " .... had trouble sending kill to " pid-num ", exn=" exn)
+ #f)
+ (process-signal pid-num signal/kill)))
+ (process:get-sub-pids pid))))
+ ;; (debug:print-info 0 *default-log-port* "not killing process " pid " as it is not alive"))))
+ pids)
+ ;; BB: question to Matt -- does the tests:test-state-status! encompass rollup to toplevel? If not, should it?
+ (tests:test-set-status! run-id test-id "KILLED" "KILLED" (conc (args:get-arg "-m")" "kill-reason) #f)) ;; BB ADDED kill-reason -- confirm OK with Matt
+ (begin
+ (debug:print-error 0 *default-log-port* "Nothing to kill, pid1=" pid1 ", pid2=" pid2)
+ (tests:test-set-status! run-id test-id "KILLED" "FAILED TO KILL" (conc (args:get-arg "-m")" "kill-reason) #f) ;; BB ADDED kill-reason -- confirm OK with Matt
+ )))
+ (mutex-unlock! m)
+ ;; no point in sticking around. Exit now. But run end of run before exiting?
+ (launch:end-of-run-check run-id)
+ (exit)))
+ (if (hash-table-ref/default misc-flags 'keep-going #f)
+ (begin
+ (thread-sleep! 3) ;; (+ 3 (random 6))) ;; add some jitter to the call home time to spread out the db accesses
+ (if (hash-table-ref/default misc-flags 'keep-going #f) ;; keep originals for cpu-load and disk-free unless they change more than the allowed delta
+ (loop (calc-minutes)
+ (or new-cpu-load cpu-load)
+ (or new-disk-free disk-free)
+ (if do-sync (current-seconds) last-sync)))))))
+ (tests:update-central-meta-info run-id test-id (get-cpu-load) (get-df (current-directory))(calc-minutes) #f #f))) ;; NOTE: Checking twice for keep-going is intentional
+
+
+(define (launch:execute encoded-cmd)
+ (let* ((cmdinfo (common:read-encoded-string encoded-cmd))
+ (tconfigreg #f))
+ (setenv "MT_CMDINFO" encoded-cmd)
+ ;;(bb-check-path msg: "launch:execute incoming")
+ (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)) ;; testpath is the test spec area
+ (top-path (assoc/default 'toppath cmdinfo))
+ (work-area (assoc/default 'work-area cmdinfo)) ;; work-area is the test run area
+ (test-name (assoc/default 'test-name cmdinfo))
+ (runscript (assoc/default 'runscript cmdinfo))
+ (ezsteps (assoc/default 'ezsteps cmdinfo))
+ (subrun (assoc/default 'subrun cmdinfo))
+ ;; (runremote (assoc/default 'runremote cmdinfo))
+ ;; (transport (assoc/default 'transport cmdinfo)) ;; not used
+ ;; (serverinf (assoc/default 'serverinf cmdinfo))
+ ;; (port (assoc/default 'port cmdinfo))
+ (serverurl (assoc/default 'serverurl cmdinfo))
+ (homehost (assoc/default 'homehost cmdinfo))
+ (run-id (assoc/default 'run-id cmdinfo))
+ (test-id (assoc/default 'test-id cmdinfo))
+ (target (assoc/default 'target cmdinfo))
+ (areaname (assoc/default 'areaname cmdinfo))
+ (itemdat (assoc/default 'itemdat cmdinfo))
+ (env-ovrd (assoc/default 'env-ovrd cmdinfo))
+ (set-vars (assoc/default 'set-vars cmdinfo)) ;; pre-overrides from -setvar
+ (runname (assoc/default 'runname cmdinfo))
+ (megatest (assoc/default 'megatest cmdinfo))
+ (runtlim (assoc/default 'runtlim cmdinfo))
+ (contour (assoc/default 'contour cmdinfo))
+ (item-path (item-list->path itemdat))
+ (mt-bindir-path (assoc/default 'mt-bindir-path cmdinfo))
+ (keys #f)
+ (keyvals #f)
+ (fullrunscript (if (not runscript)
+ #f
+ (if (substring-index "/" runscript)
+ runscript ;; use unadultered if contains slashes
+ (let ((fulln (conc work-area "/" runscript)))
+ (if (and (common:file-exists? fulln)
+ (file-execute-access? fulln))
+ fulln
+ runscript))))) ;; assume it is on the path
+ (check-work-area (lambda ()
+ ;; NFS might not have propagated the directory meta data to the run host - give it time if needed
+ (let loop ((count 0))
+ (if (or (common:directory-exists? work-area)
+ (> count 10))
+ (change-directory work-area)
+ (begin
+ (debug:print 0 *default-log-port* "INFO: Not starting job yet - directory " work-area " not found")
+ (thread-sleep! 10)
+ (loop (+ count 1)))))
+
+ (if (not (string=? (common:real-path work-area)(common:real-path (current-directory))))
+ (begin
+ (debug:print 0 *default-log-port*
+ "INFO: we are expecting to be in directory " work-area "\n"
+ " but we are actually in the directory " (current-directory) "\n"
+ " doing another change dir.")
+ (change-directory work-area)))
+
+ ;; spot check that the files in testpath are available. Too often NFS delays cause problems here.
+ (let ((files (glob (conc testpath "/*")))
+ (bad-files '()))
+ (for-each
+ (lambda (fullname)
+ (let* ((fname (pathname-strip-directory fullname))
+ (targn (conc work-area "/" fname)))
+ (if (not (file-exists? targn))
+ (set! bad-files (cons fname bad-files)))))
+ files)
+ (if (not (null? bad-files))
+ (begin
+ (debug:print 0 *default-log-port* "INFO: test data from " testpath " not copied properly or filesystem problems causing data to not be found. Re-running the copy command.")
+ (debug:print 0 *default-log-port* "INFO: missing files from " work-area ": " (string-intersperse bad-files ", "))
+ (launch:test-copy testpath work-area))))
+ ;; one more time, change to the work-area directory
+ (change-directory work-area)))
+ ) ;; let*
+
+ (if contour (setenv "MT_CONTOUR" contour))
+
+ ;; immediated set some key variables from CMDINFO data, yes, these will be set again below ...
+ ;;
+ (setenv "MT_TESTSUITENAME" areaname)
+ (setenv "MT_RUN_AREA_HOME" top-path)
+ (set! *toppath* top-path)
+ (change-directory *toppath*) ;; temporarily switch to the run area home
+ (setenv "MT_TEST_RUN_DIR" work-area)
+
+ (launch:setup) ;; should be properly in the run area home now
+
+ (if contour (setenv "MT_CONTOUR" contour))
+
+ ;; immediated set some key variables from CMDINFO data, yes, these will be set again below ...
+ ;;
+ (setenv "MT_TESTSUITENAME" areaname)
+ (setenv "MT_RUN_AREA_HOME" top-path)
+ (set! *toppath* top-path)
+ (change-directory *toppath*) ;; temporarily switch to the run area home
+ (setenv "MT_TEST_RUN_DIR" work-area)
+
+ (launch:setup) ;; should be properly in the run area home now
+
+ (set! tconfigreg (tests:get-all)) ;; mapping of testname => test source path
+ (let ((sighand (lambda (signum)
+ ;; (signal-mask! signum) ;; to mask or not? seems to cause issues in exiting
+ (if (eq? signum signal/stop)
+ (debug:print-error 0 *default-log-port* "attempt to STOP process. Exiting."))
+ (set! *time-to-exit* #t)
+ (print "Received signal " signum ", cleaning up before exit (set this test to COMPLETED/ABORT) . Please wait...")
+ (let ((th1 (make-thread (lambda ()
+ (print "set test to COMPLETED/ABORT begin.")
+ (rmt:test-set-state-status run-id test-id "COMPLETED" "ABORT" "received kill signal")
+ (print "set test to COMPLETED/ABORT complete.")
+ (print "Killed by signal " signum ". Exiting")
+ (exit 1))))
+ (th2 (make-thread (lambda ()
+ (thread-sleep! 20)
+ (debug:print 0 *default-log-port* "Done")
+ (exit 4)))))
+ (thread-start! th2)
+ (thread-start! th1)
+ (thread-join! th2)))))
+ (set-signal-handler! signal/int sighand)
+ (set-signal-handler! signal/term sighand)
+ ) ;; (set-signal-handler! signal/stop sighand)
+
+ ;; Do not run the test if it is REMOVING, RUNNING, KILLREQ or REMOTEHOSTSTART,
+ ;; Mark the test as REMOTEHOSTSTART *IMMEDIATELY*
+ ;;
+ (let* ((test-info (let loop ((tries 0))
+ (let ((tinfo (rmt:get-test-info-by-id run-id test-id)))
+ (if tinfo
+ tinfo
+ (if (> tries 5)
+ #f
+ (begin
+ (thread-sleep! (+ 1 (* tries 10)))
+ (loop (+ tries 1))))))))
+ (test-host (if test-info
+ (db:test-get-host test-info)
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: failed to find a record for test-id " test-id ", exiting.")
+ (exit))))
+ (test-pid (db:test-get-process_id test-info)))
+ (cond
+ ;; -mrw- I'm removing KILLREQ from this list so that a test in KILLREQ state is treated as a "do not run" flag.
+ ((member (db:test-get-state test-info) '("INCOMPLETE" "KILLED" "UNKNOWN" "STUCK")) ;; prior run of this test didn't complete, go ahead and try to rerun
+ (debug:print 0 *default-log-port* "INFO: test is INCOMPLETE or KILLED, treat this execute call as a rerun request")
+ ;; (tests:test-force-state-status! run-id test-id "REMOTEHOSTSTART" "n/a")
+
+ (rmt:general-call 'set-test-start-time #f test-id)
+ (rmt:test-set-state-status run-id test-id "REMOTEHOSTSTART" "n/a" #f)
+ ) ;; prime it for running
+ ((member (db:test-get-state test-info) '("RUNNING" "REMOTEHOSTSTART"))
+ (if (process:alive-on-host? test-host test-pid)
+ (debug:print-error 0 *default-log-port* "test state is " (db:test-get-state test-info) " and process " test-pid " is still running on host " test-host ", cannot proceed")
+ (exit)))
+ ((member (db:test-get-state test-info) '("COMPLETED")) ;; we do NOT want to re-run COMPLETED jobs. Mark as NOT_STARTED to run!
+ (debug:print-error 0 *default-log-port* "test state is " (db:test-get-state test-info) ", cannot proceed")
+ (exit))
+ ((not (member (db:test-get-state test-info) '("REMOVING" "REMOTEHOSTSTART" "RUNNING" "KILLREQ")))
+ ;; (tests:test-force-state-status! run-id test-id "REMOTEHOSTSTART" "n/a")
+ (rmt:general-call 'set-test-start-time #f test-id)
+ (rmt:test-set-state-status run-id test-id "REMOTEHOSTSTART" "n/a" #f))
+ (else ;; (member (db:test-get-state test-info) '("REMOVING" "REMOTEHOSTSTART" "RUNNING" "KILLREQ"))
+ (debug:print-error 0 *default-log-port* "test state is " (db:test-get-state test-info) ", cannot proceed")
+ (exit))))
+
+ ;; cleanup prior execution's steps
+ (rmt:delete-steps-for-test! run-id test-id)
+
+ (debug:print 2 *default-log-port* "Executing " test-name " (id: " test-id ") on " (get-host-name))
+ (set! keys (rmt:get-keys))
+ ;; (runs:set-megatest-env-vars run-id inkeys: keys inkeyvals: keyvals) ;; these may be needed by the launching process
+ ;; one of these is defunct/redundant ...
+ (if (not (launch:setup force-reread: #t))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ ;; (sqlite3:finalize! db)
+ ;; (sqlite3:finalize! tdb)
+ (exit 1)))
+ ;; validate that the test run area is available
+ (check-work-area)
+
+ ;; still need to go back to run area home for next couple steps
+ (change-directory *toppath*)
+
+ ;; NOTE: Current order is to process runconfigs *before* setting the MT_ vars. This
+ ;; seems non-ideal but could well break stuff
+ ;; BUG? BUG? BUG?
+
+ (let ((rconfig (full-runconfigs-read)) ;; (read-config (conc *toppath* "/runconfigs.config") #f #t sections: (list "default" target))))
+ (wconfig (read-config "waivers.config" #f #t sections: `( "default" ,target )))) ;; read the waivers config if it exists
+ ;; (setup-env-defaults (conc *toppath* "/runconfigs.config") run-id (make-hash-table) keyvals target)
+ ;; (set-run-config-vars run-id keyvals target) ;; (db:get-target db run-id))
+ ;; Now have runconfigs data loaded, set environment vars
+ (for-each
+ (lambda (section)
+ (for-each
+ (lambda (varval)
+ (let ((var (car varval))
+ (val (cadr varval)))
+ (if (and (string? var)(string? val))
+ (begin
+ (safe-setenv var (configf:eval-string-in-environment val))) ;; val)
+ (debug:print-error 0 *default-log-port* "bad variable spec, " var "=" val))))
+ (configf:get-section rconfig section)))
+ (list "default" target)))
+ ;;(bb-check-path msg: "launch:execute post block 1")
+
+ ;; NFS might not have propagated the directory meta data to the run host - give it time if needed
+ (let loop ((count 0))
+ (if (or (common:file-exists? work-area)
+ (> count 10))
+ (change-directory work-area)
+ (begin
+ (debug:print 0 *default-log-port* "INFO: Not starting job yet - directory " work-area " not found")
+ (thread-sleep! 10)
+ (loop (+ count 1)))))
+
+ ;; now we can switch to the work-area?
+ (change-directory work-area)
+ ;;(bb-check-path msg: "launch:execute post block 1.5")
+ ;; (change-directory work-area)
+ (set! keyvals (keys:target->keyval keys target))
+ ;; apply pre-overrides before other variables. The pre-override vars must not
+ ;; clobbers things from the official sources such as megatest.config and runconfigs.config
+ (if (string? set-vars)
+ (let ((varpairs (string-split set-vars ",")))
+ (debug:print 4 *default-log-port* "varpairs: " varpairs)
+ (map (lambda (varpair)
+ (let ((varval (string-split varpair "=")))
+ (if (eq? (length varval) 2)
+ (let ((var (car varval))
+ (val (cadr varval)))
+ (debug:print 1 *default-log-port* "Adding pre-var/val " var " = " val " to the environment")
+ (setenv var val)))))
+ varpairs)))
+ ;;(bb-check-path msg: "launch:execute post block 2")
+ (for-each
+ (lambda (varval)
+ (let ((var (car varval))
+ (val (cadr varval)))
+ (if val
+ (setenv var val)
+ (begin
+ (debug:print-error 0 *default-log-port* "required variable " var " does not have a valid value. Exiting")
+ (exit)))))
+ (list
+ (list "MT_TEST_RUN_DIR" work-area)
+ (list "MT_TEST_NAME" test-name)
+ (list "MT_ITEM_INFO" (conc itemdat))
+ (list "MT_ITEMPATH" item-path)
+ (list "MT_RUNNAME" runname)
+ (list "MT_MEGATEST" megatest)
+ (list "MT_TARGET" target)
+ (list "MT_LINKTREE" (common:get-linktree)) ;; (configf:lookup *configdat* "setup" "linktree"))
+ (list "MT_TESTSUITENAME" (common:get-testsuite-name))))
+ ;;(bb-check-path msg: "launch:execute post block 3")
+
+ (if mt-bindir-path (setenv "PATH" (conc (getenv "PATH") ":" mt-bindir-path)))
+ ;;(bb-check-path msg: "launch:execute post block 4")
+ ;; (change-directory top-path)
+ ;; Can setup as client for server mode now
+ ;; (client:setup)
+
+
+ ;; environment overrides are done *before* the remaining critical envars.
+ (alist->env-vars env-ovrd)
+ ;;(bb-check-path msg: "launch:execute post block 41")
+ (runs:set-megatest-env-vars run-id inkeys: keys inkeyvals: keyvals)
+ ;;(bb-check-path msg: "launch:execute post block 42")
+ (set-item-env-vars itemdat)
+ ;;(bb-check-path msg: "launch:execute post block 43")
+ (let ((blacklist (configf:lookup *configdat* "setup" "blacklistvars")))
+ (if blacklist
+ (let ((vars (string-split blacklist)))
+ (save-environment-as-files "megatest" ignorevars: vars)
+ (for-each (lambda (var)
+ (unsetenv var))
+ vars))
+ (save-environment-as-files "megatest")))
+ ;;(bb-check-path msg: "launch:execute post block 44")
+ ;; open-run-close not needed for test-set-meta-info
+ ;; (tests:set-full-meta-info #f test-id run-id 0 work-area)
+ ;; (tests:set-full-meta-info test-id run-id 0 work-area)
+ (tests:set-full-meta-info #f test-id run-id 0 work-area 10)
+
+ ;; (thread-sleep! 0.3) ;; NFS slowness has caused grief here
+
+ (if (args:get-arg "-xterm")
+ (set! fullrunscript "xterm")
+ (if (and fullrunscript
+ (common:file-exists? 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)
+ ;; now is also a good time to write the .testconfig file
+ (let* ((tconfig-fname (conc work-area "/.testconfig"))
+ (tconfig-tmpfile (conc tconfig-fname ".tmp"))
+ (tconfig (tests:get-testconfig test-name item-path tconfigreg #t force-create: #t)) ;; 'return-procs)))
+ (scripts (configf:get-section tconfig "scripts")))
+ ;; create .testconfig file
+ (configf:write-alist tconfig tconfig-tmpfile)
+ (file-move tconfig-tmpfile tconfig-fname #t)
+ (delete-file* ".final-status")
+
+ ;; extract scripts from testconfig and write them to files in test run dir
+ (for-each
+ (lambda (scriptdat)
+ (match scriptdat
+ ((name content)
+ (with-output-to-file name
+ (lambda ()
+ (print content)
+ (change-file-mode name (bitwise-ior perm/irwxg perm/irwxu)))))
+ (else
+ (debug:print-info 0 "Invalid script definiton found in [scripts] section of testconfig. \"" scriptdat "\""))))
+ scripts))
+ ;;
+ (let* ((m (make-mutex))
+ (kill-job? #f)
+ (exit-info (make-launch:einf pid: #t exit-status: #t exit-code: #t rollup-status: 0)) ;; pid exit-status exit-code (i.e. process was successfully run) rollup-status
+ (job-thread #f)
+ ;; (keep-going #t)
+ (misc-flags (let ((ht (make-hash-table)))
+ (hash-table-set! ht 'keep-going #t)
+ ht))
+ (runit (lambda ()
+ (launch:manage-steps run-id test-id item-path fullrunscript ezsteps subrun test-name tconfigreg exit-info m)))
+ (monitorjob (lambda ()
+ (launch:monitor-job run-id test-id item-path fullrunscript ezsteps test-name tconfigreg exit-info m work-area runtlim misc-flags)))
+ (th1 (make-thread monitorjob "monitor job"))
+ (th2 (make-thread runit "run job")))
+ (set! job-thread th2)
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th2)
+ (debug:print-info 0 *default-log-port* "Megatest exectute of test " test-name ", item path " item-path " complete. Notifying the db ...")
+ (hash-table-set! misc-flags 'keep-going #f)
+ (thread-join! th1)
+ (thread-sleep! 1) ;; givbe thread th1 a chance to be done TODO: Verify this is needed. At 0.1 I was getting fail to stop, increased to total of 1.1 sec.
+ (mutex-lock! m)
+ (let* ((item-path (item-list->path itemdat))
+ ;; only state and status needed - use lazy routine
+ (testinfo (rmt:get-testinfo-state-status run-id test-id)))
+ ;; Am I completed?
+ (if (member (db:test-get-state testinfo) '("REMOTEHOSTSTART" "RUNNING")) ;; NOTE: It should *not* be REMOTEHOSTSTART but for reasons I don't yet understand it sometimes gets stuck in that state ;; (not (equal? (db:test-get-state testinfo) "COMPLETED"))
+ (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 (cond
+ ((not (launch:einf-exit-status exit-info)) "FAIL") ;; job failed to run ... (vector-ref exit-info 1)
+ ((eq? (launch:einf-rollup-status exit-info) 0) ;; (vector-ref exit-info 3)
+ ;; if the current status is AUTO then defer to the calculated value (i.e. leave this AUTO)
+ (if (equal? (db:test-get-status testinfo) "AUTO") "AUTO" "PASS"))
+ ((eq? (launch:einf-rollup-status exit-info) 1) "FAIL") ;; (vector-ref exit-info 3)
+ ((eq? (launch:einf-rollup-status exit-info) 2) ;; (vector-ref exit-info 3)
+ ;; 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"))
+ ((eq? (launch:einf-rollup-status exit-info) 3) "CHECK")
+ ((eq? (launch:einf-rollup-status exit-info) 4) "WAIVED")
+ ((eq? (launch:einf-rollup-status exit-info) 5) "ABORT")
+ ((eq? (launch:einf-rollup-status exit-info) 6) "SKIP")
+ (else "FAIL")))) ;; (db:test-get-status testinfo)))
+ (debug:print-info 1 *default-log-port* "Test exited in state=" (db:test-get-state testinfo) ", setting state/status based on exit code of " (launch:einf-exit-status exit-info) " and rollup-status of " (launch:einf-rollup-status exit-info))
+
+ ;; Leave a .final-status file for each sub-test
+ (tests:save-final-status run-id test-id)
+
+ (tests:test-set-status! run-id
+ test-id
+ new-state
+ new-status
+ (args:get-arg "-m") #f)
+ ;; need to update the top test record if PASS or FAIL and this is a subtest
+ ;; NO NEED TO CALL set-state-status-and-roll-up-items HERE, THIS IS DONE IN set-state-status-and-roll-up-items called by tests:test-set-status!
+ ))
+ ;; 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))
+ (tests:summarize-test run-id test-id) ;; don't force - just update if no
+ ;; Leave a .final-status file for the top level test
+ (tests:save-final-status run-id test-id)
+ (rmt:update-run-stats run-id (rmt:get-raw-run-stats run-id)))
+ (mutex-unlock! m)
+ (launch:end-of-run-check run-id )
+ (debug:print 2 *default-log-port* "Output from running " fullrunscript ", pid " (launch:einf-pid exit-info) " in work area "
+ work-area ":\n====\n exit code " (launch:einf-exit-code exit-info) "\n" "====\n")
+ (if (not (launch:einf-exit-status exit-info))
+ (exit 4))))
+ )))
+
+;; Spec for End of test
+;; At end of each test call, after marking self as COMPLETED do run-state-status-rollup
+;; At transition to run COMPLETED/X do hooks
+;; Definition: test_dead if event_time + duration + 1 minute? < current_time AND
+;; we can prove the process is not alive (ssh host pstree -A pid)
+;; if dead safe to mark the test as killed in the db
+;; State/status table
+;; new
+;; 100% COMPLETED/ (PASS,FAIL,ABORT etc.) ==> COMPLETED / X where X is same as itemized rollup
+;; > 3 RUNNING with not test_dead do nothing (run should already be RUNNING/ na
+;; > 0 RUNNING and test_dead then send KILLREQ ==> COMPLETED
+;; 0 RUNNING ==> this is actually the first condition, should not get here
+
+(define (launch:end-of-run-check run-id )
+ (let* ((not-completed-cnt (rmt:get-not-completed-cnt run-id))
+ (running-cnt (rmt:get-count-tests-running-for-run-id run-id))
+ (all-test-launched (rmt:get-var (conc "lunch-complete-" run-id)))
+ (current-state (rmt:get-run-state run-id))
+ (current-status (rmt:get-run-status run-id)))
+ ;;get-vars run-id to query metadata table to check if all completed. if all-test-launched = yes then only not-completed-cnt = 0 means everyting is completed if no entry found in the table do nothing
+ (debug:print 0 *default-log-port* "Running test cnt :" running-cnt)
+ (rmt:set-state-status-and-roll-up-run run-id current-state current-status)
+ (runs:update-junit-test-reporter-xml run-id)
+ (cond
+ ((and all-test-launched (eq? not-completed-cnt 0) (equal? all-test-launched "yes" ))
+ (if (and (equal? (rmt:get-var (conc "end-of-run-" run-id)) "no") (common:simple-lock (conc "endOfRun" run-id)))
+ (begin
+ (debug:print 4 *default-log-port* "look for post hook. currseconds: " (current-seconds) " EOR " (rmt:get-var (conc "end-of-run-" run-id)))
+ (debug:print 0 *default-log-port* "End of Run Detected.")
+ (rmt:set-var (conc "end-of-run-" run-id) "yes")
+ ;(thread-sleep! 10)
+ (runs:run-post-hook run-id)
+ (debug:print 4 *default-log-port* "currseconds: " (current-seconds)" eor: " (rmt:get-var (conc "end-of-run-" run-id)))
+ (common:simple-unlock (conc "endOfRun" run-id)))
+ (debug:print 0 *default-log-port* "End of Run Detected but not running post hook. This should happen when eor is set to yes. This will happen only when 2 tests exit at smae time. eor= " (rmt:get-var (conc "end-of-run-" run-id)))))
+ ((> running-cnt 3)
+ (debug:print 0 *default-log-port* "There are " running-cnt " tests running." ))
+ ((> running-cnt 0)
+ (debug:print 0 *default-log-port* "running cnt > 0 but <= 3 kill-running-tests-if-dead" )
+ (let ((kill-cnt (launch:kill-tests-if-dead run-id)))
+ (if (and all-test-launched (equal? all-test-launched "yes") (eq? kill-cnt running-cnt))
+ (launch:end-of-run-check run-id)))) ;;todo
+ (else (debug:print 0 *default-log-port* "Should it get here?? May be everything is not launched yet. Running test cnt:" running-cnt " Not completed test cnt:" not-completed-cnt)
+ (let* ((not-completed-tests (rmt:get-tests-for-run run-id "%" `("NOT_STARTED" "RUNNING" "LAUNCHED" "REMOTEHOSTSTART") `() #f #f #f #f #f #f #f #f)))
+ (if (> (length not-completed-tests) 0)
+ (let loop ((running-test (car not-completed-tests))
+ (tal (cdr not-completed-tests)))
+ (let* ((test-name (vector-ref running-test 2))
+ (item-path (vector-ref running-test 11)))
+ (debug:print 0 *default-log-port* "test " test-name "/" item-path " not completed")
+ (if (not (null? tal))
+ (loop (car tal) (cdr tal)))))))))))
+
+(define (launch:kill-tests-if-dead run-id)
+ (let* ((running-tests (rmt:get-tests-for-run run-id "%" `("RUNNING" "LAUNCHED" "REMOTEHOSTSTART") `() #f #f #f #f #f #f #f #f)))
+ (let loop ((running-test (car running-tests))
+ (tal (cdr running-tests))
+ (kill-cnt 0))
+ (let* ((test-name (vector-ref running-test 2))
+ (item-path (vector-ref running-test 11))
+ (test-id (vector-ref running-test 0))
+ (host (vector-ref running-test 6))
+ (pid (rmt:test-get-top-process-pid run-id test-id))
+ (event-time (vector-ref running-test 5))
+ (duration (vector-ref running-test 12))
+ (flag 0)
+ (curr-time (current-seconds)))
+ (if (and (< (+ event-time duration 600) curr-time) (not (launch:is-test-alive host pid))) ;;test has not updated duration in last 10 min then likely its not running but confirm before marking it as killed
+ (begin
+ (debug:print 0 *default-log-port* "test " test-name "/" item-path " needs to be killed")
+ (set! flag 1)
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path "KILLREQ" "n/a" #f)))
+ (if (not (null? tal))
+ (loop (car tal) (cdr tal) (+ kill-cnt flag))
+ (+ kill-cnt flag))))))
+
+;; DO NOT USE - caching of configs is handled in launch:setup now.
+;;
+(define (launch:cache-config)
+ ;; if we have a linktree and -runtests and -target and the directory exists dump the config
+ ;; to megatest-(current-seconds).cfg and symlink it to megatest.cfg
+ (if (and *configdat*
+ (or (args:get-arg "-run")
+ (args:get-arg "-runtests")
+ (args:get-arg "-execute")))
+ (let* ((linktree (common:get-linktree)) ;; (get-environment-variable "MT_LINKTREE"))
+ (target (common:args-get-target exit-if-bad: #t))
+ (runname (or (args:get-arg "-runname")
+ (args:get-arg ":runname")
+ (getenv "MT_RUNNAME")))
+ (fulldir (conc linktree "/"
+ target "/"
+ runname)))
+ (if (and linktree (common:file-exists? linktree)) ;; can't proceed without linktree
+ (begin
+ (debug:print-info 0 *default-log-port* "Have -run with target=" target ", runname=" runname ", fulldir=" fulldir ", testpatt=" (or (args:get-arg "-testpatt") "%"))
+ (if (not (common:file-exists? fulldir))
+ (create-directory fulldir #t)) ;; need to protect with exception handler
+ (if (and target
+ runname
+ (common:file-exists? fulldir))
+ (let ((tmpfile (conc fulldir "/.megatest.cfg." (current-seconds)))
+ (targfile (conc fulldir "/.megatest.cfg-" megatest-version "-" megatest-fossil-hash))
+ (rconfig (conc fulldir "/.runconfig." megatest-version "-" megatest-fossil-hash)))
+ (if (common:file-exists? rconfig) ;; only cache megatest.config AFTER runconfigs has been cached
+ (begin
+ (debug:print-info 0 *default-log-port* "Caching megatest.config in " tmpfile)
+ (if (not (common:in-running-test?))
+ (configf:write-alist *configdat* tmpfile))
+ (system (conc "ln -sf " tmpfile " " targfile))))
+ )))
+ (debug:print-info 1 *default-log-port* "No linktree yet, no caching configs.")))))
+
+
+(define (get-best-disk confdat testconfig)
+ (let* ((disks (or (and testconfig (hash-table-ref/default testconfig "disks" #f))
+ (hash-table-ref/default confdat "disks" #f)))
+ (minspace (let ((m (configf:lookup confdat "setup" "minspace")))
+ (string->number (or m "10000")))))
+ (if disks
+ (let ((res (common:get-disk-with-most-free-space disks minspace))) ;; min size of 1000, seems tad dumb
+ (if res
+ (cdr res)
+ (begin ;; DEAD CODE PATH - REVISIT!
+;; (if (common:low-noise-print 20 "No valid disks or no disk with enough space")
+;; (debug:print-error 0 *default-log-port* "No valid disks found in megatest.config. Please add some to your [disks] section and ensure the directory exists and has enough space!\n You can change minspace in the [setup] section of megatest.config. Current setting is: " minspace))
+ ;;(exit 1)
+ (if (null? disks)
+ (cons 1 (conc *toppath* "/runs"))
+ (let ((paths (sort disks (lambda (x y) (> (string-length (cadr x)) (string-length (cadr y)))))))
+ (let loop ((head (car paths)) (tail (cdr paths)))
+ (let ((result (handle-exceptions exn
+ (begin
+ (debug:print 0 *default-log-port* "failed to create dir " (cadr head) ", exn=" exn)
+ #f)
+ (create-directory (cadr head) #t))))
+ (if result
+ result
+ (if (null? tail)
+ (cons 1 (conc *toppath* "/runs"))
+ (loop (car tail) (cdr tail)))))))))))
+ ;; no disks definition - use mtrah/runs, fall back to currdir/runs
+ (let* ((toppath (or *toppath*
+ (common:get-toppath *toppath*)
+ (begin
+ (debug:print-error 0 *default-log-port* "Creating runs dir in current directory, this is probably not what you wanted. Please check your setup.")
+ (current-directory))))
+ (runsdir (conc toppath "/runs")))
+ (if (not (file-exists? runsdir))(create-directory runsdir))
+ runsdir)
+ ))) ;; the code creates the necessary directories if it does not exist and returns the path.
+
+(define (launch:test-copy test-src-path test-path)
+ (let* ((ovrcmd (let ((cmd (configf:lookup *configdat* "setup" "testcopycmd")))
+ (if cmd
+ ;; substitute the TEST_SRC_PATH and TEST_TARG_PATH
+ (string-substitute "TEST_TARG_PATH" test-path
+ (string-substitute "TEST_SRC_PATH" test-src-path cmd #t) #t)
+ #f)))
+ (cmd (if ovrcmd
+ ovrcmd
+ (conc "rsync -av" (if (debug:debug-mode 1) "" "q") " " test-src-path "/ " test-path "/"
+ " >> " test-path "/mt_launch.log 2>> " test-path "/mt_launch.log")))
+ (status (system cmd)))
+ (if (not (eq? status 0))
+ (debug:print 2 *default-log-port* "ERROR: problem with running \"" cmd "\""))))
+
+
+;; Desired directory structure:
+;;
+;; - - -.
+;; |
+;; v
+;; - - -|-
+;;
+;; dir stored in test is:
+;;
+;; - - [ - ]
+;;
+;; All log file links should be stored relative to the top of link path
+;;
+;; - [ - ]
+;;
+(define (create-work-area run-id run-info keyvals test-id test-src-path disk-path testname itemdat #!key (remtries 2))
+ (let* ((item-path (if (string? itemdat) itemdat (item-list->path itemdat))) ;; if pass in string - just use it
+ (runname (if (string? run-info) ;; if we pass in a string as run-info use it as run-name.
+ run-info
+ (db:get-value-by-header (db:get-rows run-info)
+ (db:get-header run-info)
+ "runname")))
+ (contour #f) ;; NOT READY FOR THIS (args:get-arg "-contour"))
+ ;; convert back to db: from rdb: - this is always run at server end
+ (target (string-intersperse (map cadr keyvals) "/"))
+
+ (not-iterated (equal? "" item-path))
+
+ ;; all tests are found at /test-base or /test-base
+ (testtop-base (conc target "/" runname "/" testname))
+ (test-base (conc testtop-base (if not-iterated "" "/") item-path))
+
+ ;; nb// if itempath is not "" then it is prefixed with "/"
+ (toptest-path (conc disk-path (if contour (conc "/" contour) "") "/" testtop-base))
+ (test-path (conc disk-path (if contour (conc "/" contour) "") "/" test-base))
+
+ ;; ensure this exists first as links to subtests must be created there
+ (linktree (common:get-linktree))
+ ;; WAS: (let ((rd (configf:lookup *configdat* "setup" "linktree")))
+ ;; (if rd rd (conc *toppath* "/runs"))))
+ ;; which seems wrong ...
+
+ (lnkbase (conc linktree (if contour (conc "/" contour) "") "/" target "/" runname))
+ (lnkpath (conc lnkbase "/" testname))
+ (lnkpathf (conc lnkpath (if not-iterated "" "/") item-path))
+ (lnktarget (conc lnkpath "/" item-path)))
+
+ ;; Update the rundir path in the test record for all, rundir=physical, shortdir=logical
+ ;; rundir shortdir
+ (rmt:general-call 'test-set-rundir-shortdir run-id lnkpathf test-path testname item-path run-id)
+
+ (debug:print 2 *default-log-port* "INFO:\n lnkbase=" lnkbase "\n lnkpath=" lnkpath "\n toptest-path=" toptest-path "\n test-path=" test-path)
+ (if (not (common:file-exists? linktree))
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: linktree did not exist! Creating it now at " linktree)
+ (create-directory linktree #t))) ;; (system (conc "mkdir -p " linktree))))
+ ;; create the directory for the tests dir links, this is needed no matter what... try up to three times
+ (let loop ((done 3))
+ (let ((success (if (and (not (common:directory-exists? lnkbase))
+ (not (common:file-exists? lnkbase)))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* "Problem creating linktree base at " lnkbase ", exn=" exn)
+ (print-error-message exn (current-error-port))
+ #t)
+ (create-directory lnkbase #t)
+ #f))))
+ (if (and (not success)(> done 0))
+ (loop (- done 1)))))
+
+ ;; update the toptest record with its location rundir, cache the path
+ ;; This wass highly inefficient, one db write for every subtest, potentially
+ ;; thousands of unnecessary updates, cache the fact it was set and don't set it
+ ;; again.
+
+ ;; Now create the link from the test path to the link tree, however
+ ;; if the test is iterated it is necessary to create the parent path
+ ;; to the iteration. use pathname-directory to trim the path by one
+ ;; level
+ (if (not not-iterated) ;; i.e. iterated
+ (let ((iterated-parent (pathname-directory (conc lnkpath "/" item-path))))
+ (debug:print-info 2 *default-log-port* "Creating iterated parent " iterated-parent)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to create directory " iterated-parent ((condition-property-accessor 'exn 'message) exn)
+ ", continuing but link tree may be corrupted, exn=" exn)
+ #;(exit 1))
+ (create-directory iterated-parent #t))))
+
+ (if (symbolic-link? lnkpath)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to remove symlink " lnkpath ((condition-property-accessor 'exn 'message) exn)
+ ", continuing but link tree may be corrupted. exn=" exn)
+ #;(exit 1))
+ (delete-file lnkpath)))
+
+ (if (not (or (common:file-exists? lnkpath)
+ (symbolic-link? lnkpath)))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to create symlink " lnkpath ((condition-property-accessor 'exn 'message) exn)
+ ", continuing but link tree may be corrupted. exn=" exn)
+ #;(exit 1))
+ (create-symbolic-link toptest-path lnkpath)))
+
+ ;; NB - This was not working right - some top tests are not getting the path set!!!
+ ;;
+ ;; Do the setting of this record after the paths are created so that the shortdir can
+ ;; be set to the real directory location. This is safer for future clean up if the link
+ ;; tree is damaged or lost.
+ ;;
+ (if (not (hash-table-ref/default *toptest-paths* testname #f))
+ (let* ((testinfo (rmt:get-test-info-by-id run-id test-id)) ;; run-id testname item-path))
+ (curr-test-path (if testinfo ;; (filedb:get-path *fdb*
+ ;; (db:get-path dbstruct
+ ;; (rmt:sdb-qry 'getstr
+ (db:test-get-rundir testinfo) ;; ) ;; )
+ #f)))
+ (hash-table-set! *toptest-paths* testname curr-test-path)
+ ;; NB// Was this for the test or for the parent in an iterated test?
+ (rmt:general-call 'test-set-rundir-shortdir run-id lnkpath
+ (if (common:file-exists? lnkpath)
+ ;; (resolve-pathname lnkpath)
+ (common:nice-path lnkpath)
+ lnkpath)
+ testname "" run-id)
+ ;; (rmt:general-call 'test-set-rundir run-id lnkpath testname "") ;; toptest-path)
+ (if (or (not curr-test-path)
+ (not (directory-exists? toptest-path)))
+ (begin
+ (debug:print-info 2 *default-log-port* "Creating " toptest-path " and link " lnkpath)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "failed to create directory " toptest-path ", exn=" exn)
+ #f)
+ (create-directory toptest-path #t))
+ (hash-table-set! *toptest-paths* testname toptest-path)))))
+
+ ;; The toptest path has been created, the link to the test in the linktree has
+ ;; been created. Now, if this is an iterated test the real test dir must be created
+ (if (not not-iterated) ;; this is an iterated test
+ (begin ;; (let ((lnktarget (conc lnkpath "/" item-path)))
+ (debug:print 2 *default-log-port* "Setting up sub test run area")
+ (debug:print 2 *default-log-port* " - creating run area in " test-path)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to create directory " test-path ((condition-property-accessor 'exn 'message) exn)
+ ", exiting, exn=" exn)
+ (exit 1))
+ (create-directory test-path #t))
+ (debug:print 2 *default-log-port*
+ " - creating link from: " test-path "\n"
+ " to: " lnktarget)
+
+ ;; If there is already a symlink delete it and recreate it.
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to re-create link " lnktarget ((condition-property-accessor 'exn 'message) exn) ", exiting, exn=" exn)
+ (exit))
+ (if (symbolic-link? lnktarget) (delete-file lnktarget))
+ (if (not (common:file-exists? lnktarget)) (create-symbolic-link test-path lnktarget)))))
+
+ (if (not (directory? test-path))
+ (create-directory test-path #t)) ;; this is a hack, I don't know why out of the blue this path does not exist sometimes
+
+ (if (and test-src-path (directory? test-path))
+ (begin
+ (launch:test-copy test-src-path test-path)
+ (list lnkpathf lnkpath ))
+ (if (and test-src-path (> remtries 0))
+ (begin
+ (debug:print-error 0 *default-log-port* "Failed to create work area at " test-path " with link at " lnktarget ", remaining attempts " remtries)
+ ;;
+ (create-work-area run-id run-info keyvals test-id test-src-path disk-path testname itemdat remtries: (- remtries 1)))
+ (list #f #f)))))
+
+
+(define (launch:handle-zombie-tests run-id)
+ (let* ((key (conc "zombiescan-runid-"run-id))
+ (now (current-seconds))
+ (threshold (- (current-seconds) (* 2 (or (configf:lookup-number *configdat* "setup" "deadtime") 120))))
+ (val (rmt:get-var key))
+ (do-scan?
+ (cond
+ ((not val)
+ #t)
+ ((< val threshold)
+ #t)
+ (else #f))))
+ (when do-scan?
+ (debug:print 1 *default-log-port* "INFO: search and mark zombie tests")
+ (rmt:set-var key (current-seconds))
+ (rmt:find-and-mark-incomplete run-id #f))))
+
+
+
+
+
+;; 1. look though disks list for disk with most space
+;; 2. create run dir on disk, path name is meaningful
+;; 3. create link from run dir to megatest runs area
+;; 4. remotely run the test on allocated host
+;; - could be ssh to host from hosts table (update regularly with load)
+;; - could be netbatch
+;; (launch-test db (cadr status) test-conf))
+(define (launch-test test-id run-id run-info keyvals runname test-conf test-name test-path itemdat params)
+ (mutex-lock! *launch-setup-mutex*) ;; setting variables and processing the testconfig is NOT thread-safe, reuse the launch-setup mutex
+ (let* ( ;; (lock-key (conc "test-" test-id))
+ ;; (got-lock (let loop ((lock (rmt:no-sync-get-lock lock-key))
+ ;; (expire-time (+ (current-seconds) 15))) ;; give up on getting the lock and steal it after 15 seconds
+ ;; (if (car lock)
+ ;; #t
+ ;; (if (> (current-seconds) expire-time)
+ ;; (begin
+ ;; (debug:print-info 0 *default-log-port* "Timed out waiting for a lock to launch test " keyvals " " runname " " test-name " " test-path)
+ ;; (rmt:no-sync-del! lock-key) ;; destroy the lock
+ ;; (loop (rmt:no-sync-get-lock lock-key) expire-time)) ;;
+ ;; (begin
+ ;; (thread-sleep! 1)
+ ;; (loop (rmt:no-sync-get-lock lock-key) expire-time))))))
+ (item-path (item-list->path itemdat))
+ (contour #f)) ;; NOT READY FOR THIS (args:get-arg "-contour")))
+ (let loop ((delta (- (current-seconds) *last-launch*))
+ (launch-delay (configf:lookup-number *configdat* "setup" "launch-delay" default: 0)))
+ (if (> launch-delay delta)
+ (begin
+ (if (common:low-noise-print 1200 "test launch delay") ;; every two hours or so remind the user about launch delay.
+ (debug:print-info 0 *default-log-port* "NOTE: test launches are delayed by " launch-delay " seconds. See megatest.config launch-delay setting to adjust.")) ;; launch of " test-name " for " (- launch-delay delta) " seconds"))
+ (thread-sleep! (- launch-delay delta))
+ (loop (- (current-seconds) *last-launch*) launch-delay))))
+ (change-directory *toppath*)
+ (alist->env-vars ;; consolidate this code with the code in megatest.scm for "-execute", *maybe* - the longer they are set the longer each launch takes (must be non-overlapping with the vars)
+ (append
+ (list
+ (list "MT_RUN_AREA_HOME" *toppath*)
+ (list "MT_TEST_NAME" test-name)
+ (list "MT_RUNNAME" runname)
+ (list "MT_ITEMPATH" item-path)
+ (list "MT_CONTOUR" contour)
+ )
+ itemdat))
+ (let* ((tregistry (tests:get-all)) ;; third param (below) is system-allowed
+ ;; for tconfig, why do we allow fallback to test-conf?
+ (tconfig (or (tests:get-testconfig test-name item-path tregistry #t force-create: #t)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: falling back to pre-calculated testconfig. This is likely not desired.")
+ test-conf))) ;; force re-read now that all vars are set
+ (useshell (let ((ush (configf:lookup *configdat* "jobtools" "useshell")))
+ (if ush
+ (if (equal? ush "no") ;; must use "no" to NOT use shell
+ #f
+ ush)
+ #t))) ;; default is yes
+ (runscript (configf:lookup tconfig "setup" "runscript"))
+ (ezsteps (> (length (hash-table-ref/default tconfig "ezsteps" '())) 0)) ;; don't send all the steps, could be big, just send a flag
+ (subrun (> (length (hash-table-ref/default tconfig "subrun" '())) 0)) ;; send a flag to process a subrun
+ ;; (diskspace (configf:lookup tconfig "requirements" "diskspace"))
+ ;; (memory (configf:lookup tconfig "requirements" "memory"))
+ ;; (hosts (configf:lookup *configdat* "jobtools" "workhosts")) ;; I'm pretty sure this was never completed
+ (remote-megatest (configf:lookup *configdat* "setup" "executable"))
+ (run-time-limit (or (configf:lookup tconfig "requirements" "runtimelim")
+ (configf:lookup *configdat* "setup" "runtimelim")))
+ ;; FIXME SOMEDAY: not good how this is so obtuse, this hack is to
+ ;; allow running from dashboard. Extract the path
+ ;; from the called megatest and convert dashboard
+ ;; or dboard to megatest
+ (local-megatest (common:find-local-megatest))
+ #;(local-megatest (let* ((lm (car (argv)))
+ (dir (pathname-directory lm))
+ (exe (pathname-strip-directory lm)))
+ (conc (if dir (conc dir "/") "")
+ (case (string->symbol exe)
+ ((dboard) "../megatest")
+ ((mtest) "../megatest")
+ ((dashboard) "megatest")
+ (else exe)))))
+ (launcher (common:get-launcher *configdat* test-name item-path)) ;; (configf:lookup *configdat* "jobtools" "launcher"))
+ (test-sig (conc (common:get-testsuite-name) ":" test-name ":" item-path)) ;; (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))))
+ (mt-bindir-path #f)
+ (testinfo (rmt:get-test-info-by-id run-id test-id))
+ (mt_target (string-intersperse (map cadr keyvals) "/"))
+ (debug-param (append (if (args:get-arg "-debug") (list "-debug" (args:get-arg "-debug")) '())
+ (if (args:get-arg "-logging")(list "-logging") '())
+ (if (configf:lookup *configdat* "misc" "profilesw")
+ (list (configf:lookup *configdat* "misc" "profilesw"))
+ '()))))
+ ;; (if hosts (set! hosts (string-split hosts)))
+ ;; set the megatest to be called on the remote host
+ (if (not remote-megatest)(set! remote-megatest local-megatest)) ;; "megatest"))
+ (set! mt-bindir-path (pathname-directory remote-megatest))
+ (if launcher (set! launcher (string-split launcher)))
+ ;; set up the run work area for this test
+ (if (and (args:get-arg "-preclean") ;; user has requested to preclean for this run
+ (not (member (db:test-get-rundir testinfo)(list "n/a" "/tmp/badname")))) ;; n/a is a placeholder and thus not a read dir
+ (begin
+ (debug:print-info 0 *default-log-port* "attempting to preclean directory " (db:test-get-rundir testinfo) " for test " test-name "/" item-path)
+ (runs:remove-test-directory testinfo 'remove-data-only))) ;; remove data only, do not perturb the record
+
+ ;; prevent overlapping actions - set to LAUNCHED as early as possible
+ ;;
+ ;; the following call handles waiver propogation. cannot yet condense into roll-up-pass-fail
+ (tests:test-set-status! run-id test-id "LAUNCHED" "n/a" #f #f) ;; (if launch-results launch-results "FAILED"))
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path #f "LAUNCHED" #f)
+ ;; (pp (hash-table->alist tconfig))
+ (set! diskpath (get-best-disk *configdat* tconfig))
+ (if diskpath
+ (let ((dat (create-work-area run-id run-info keyvals test-id test-path diskpath test-name itemdat)))
+ (set! work-area (car dat))
+ (set! toptest-work-area (cadr dat))
+ (debug:print-info 2 *default-log-port* "Using work area " work-area))
+ (begin
+ (set! work-area (conc test-path "/tmp_run"))
+ (create-directory work-area #t)
+ (debug:print 0 *default-log-port* "WARNING: No disk work area specified - running in the test directory under tmp_run")))
+ (set! cmdparms (base64:base64-encode
+ (z3:encode-buffer
+ (with-output-to-string
+ (lambda () ;; (list 'hosts hosts)
+ (write (list (list 'testpath test-path)
+ ;; (list 'transport (conc *transport-type*))
+ ;; (list 'serverinf *server-info*)
+ (list 'homehost (let* ((hhdat (common:get-homehost)))
+ (if hhdat
+ (car hhdat)
+ #f)))
+ (list 'serverurl (if *runremote*
+ (remote-server-url *runremote*)
+ #f)) ;;
+ (list 'areaname (common:get-testsuite-name))
+ (list 'toppath *toppath*)
+ (list 'work-area work-area)
+ (list 'test-name test-name)
+ (list 'runscript runscript)
+ (list 'run-id run-id )
+ (list 'test-id test-id )
+ ;; (list 'item-path item-path )
+ (list 'itemdat itemdat )
+ (list 'megatest remote-megatest)
+ (list 'ezsteps ezsteps)
+ (list 'subrun subrun)
+ (list 'target mt_target)
+ (list 'contour contour)
+ (list 'runtlim (if run-time-limit (common:hms-string->seconds run-time-limit) #f))
+ (list 'env-ovrd (hash-table-ref/default *configdat* "env-override" '()))
+ (list 'set-vars (if params (hash-table-ref/default params "-setvars" #f)))
+ (list 'runname runname)
+ (list 'mt-bindir-path mt-bindir-path))))))))
+
+ ;; clean out step records from previous run if they exist
+ ;; (rmt:delete-test-step-records run-id test-id)
+ ;; if the dir does not exist we may have a itempath where individual variables are a path, launch anyway
+ (if (common:file-exists? work-area)
+ (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 "-m" test-sig "-execute" cmdparms) debug-param)))
+ ;; (set! fullcmd (append launcher (car hosts)(list remote-megatest test-sig "-execute" cmdparms))))
+ (launcher
+ (set! fullcmd (append launcher (list remote-megatest "-m" test-sig "-execute" cmdparms) debug-param)))
+ ;; (set! fullcmd (append launcher (list remote-megatest test-sig "-execute" cmdparms))))
+ (else
+ (if (not useshell)(debug:print 0 *default-log-port* "WARNING: internal launching will not work well without \"useshell yes\" in your [jobtools] section"))
+ (set! fullcmd (append (list remote-megatest "-m" test-sig "-execute" cmdparms) debug-param (list (if useshell "&" ""))))))
+ ;; (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 *default-log-port* "Launching " work-area)
+ ;; set pre-launch-env-vars before launching, keep the vars in prevvals and put the envionment back when done
+ (debug:print 4 *default-log-port* "fullcmd: " fullcmd)
+ (set! *last-launch* (current-seconds)) ;; all that junk above takes time, set this as late as possible.
+ (let* ((commonprevvals (alist->env-vars
+ (hash-table-ref/default *configdat* "env-override" '())))
+ (miscprevvals (alist->env-vars ;; consolidate this code with the code in megatest.scm for "-execute"
+ (append (list (list "MT_TEST_RUN_DIR" work-area)
+ (list "MT_TEST_NAME" test-name)
+ (list "MT_ITEM_INFO" (conc itemdat))
+ (list "MT_RUNNAME" runname)
+ (list "MT_TARGET" mt_target)
+ (list "MT_ITEMPATH" item-path)
+ )
+ itemdat)))
+ (testprevvals (alist->env-vars
+ (hash-table-ref/default tconfig "pre-launch-env-overrides" '())))
+ ;; Launchwait defaults to true, must override it to turn off wait
+ (launchwait (if (equal? (configf:lookup *configdat* "setup" "launchwait") "no") #f #t))
+ (launch-results-prev (apply (if launchwait ;; BB: TODO: refactor this to examine return code of launcher, if nonzero, set state to launch failed.
+ process:cmd-run-with-stderr-and-exitcode->list
+ process-run)
+ (if useshell
+ (let ((cmdstr (string-intersperse fullcmd " ")))
+ (if launchwait
+ cmdstr
+ (conc cmdstr " >> mt_launch.log 2>&1 &")))
+ (car fullcmd))
+ (if useshell
+ '()
+ (cdr fullcmd))))
+ (success (if launchwait (equal? 0 (cadr launch-results-prev)) #t))
+ (launch-results (if launchwait (car launch-results-prev) launch-results-prev)))
+ (if (not success)
+ (tests:test-set-status! run-id test-id "COMPLETED" "DEAD" "launcher failed; exited non-zero; check mt_launch.log" #f)) ;; (if launch-results launch-results "FAILED"))
+ (mutex-unlock! *launch-setup-mutex*) ;; yes, really should mutex all the way to here. Need to put this entire process into a fork.
+ ;; (rmt:no-sync-del! lock-key) ;; release the lock for starting this test
+ (if (not launchwait) ;; give the OS a little time to allow the process to start
+ (thread-sleep! 0.01))
+ (with-output-to-file "mt_launch.log"
+ (lambda ()
+ (print "LAUNCHCMD: " (string-intersperse fullcmd " "))
+ (if (list? launch-results)
+ (apply print launch-results)
+ (print "NOTE: launched \"" fullcmd "\"\n but did not wait for it to proceed. Add the following to megatest.config \n[setup]\nlaunchwait yes\n if you have problems with this"))
+ #:append))
+ (debug:print 2 *default-log-port* "Launching completed, updating db")
+ (debug:print 2 *default-log-port* "Launch results: " launch-results)
+ (if (not launch-results)
+ (begin
+ (print "ERROR: Failed to run " (string-intersperse fullcmd " ") ", exiting now")
+ ;; (sqlite3:finalize! db)
+ ;; good ole "exit" seems not to work
+ ;; (_exit 9)
+ ;; but this hack will work! Thanks go to Alan Post of the Chicken email list
+ ;; NB// Is this still needed? Should be safe to go back to "exit" now?
+ (process-signal (current-process-id) signal/kill)
+ ))
+ (alist->env-vars miscprevvals)
+ (alist->env-vars testprevvals)
+ (alist->env-vars commonprevvals)
+ launch-results))
+ (change-directory *toppath*)
+ (thread-sleep! (configf:lookup-number *configdat* "setup" "inter-test-delay" default: 0.0))))
+
+;; recover a test where the top controlling mtest may have died
+;;
+(define (launch:recover-test run-id test-id)
+ ;; this function is called on the test run host via ssh
+ ;;
+ ;; 1. look at the process from pid
+ ;; - is it owned by calling user
+ ;; - it it's run directory correct for the test
+ ;; - is there a controlling mtest (maybe stuck)
+ ;; 2. if recovery is needed watch pid
+ ;; - when it exits take the exit code and do the needful
+ ;;
+ (let* ((pid (rmt:test-get-top-process-pid run-id test-id))
+ (psres (with-input-from-pipe
+ (conc "ps -F -u " (current-user-name) " | grep -E '" pid " ' | grep -v 'grep -E " pid "'")
+ (lambda ()
+ (read-line))))
+ (rundir (if (string? psres) ;; real process owned by user
+ (read-symbolic-link (conc "/proc/" pid "/cwd"))
+ #f)))
+ ;; now wait on that process if all is correct
+ ;; periodically update the db with runtime
+ ;; when the process exits look at the db, if still RUNNING after 10 seconds set
+ ;; state/status appropriately
+ (process-wait pid)))
ADDED attic_modular/lock-queue.scm
Index: attic_modular/lock-queue.scm
==================================================================
--- /dev/null
+++ attic_modular/lock-queue.scm
@@ -0,0 +1,258 @@
+;; Copyright 2006-2013, 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 .
+;;
+
+(use (prefix sqlite3 sqlite3:) srfi-18)
+
+(declare (unit lock-queue))
+(declare (uses common))
+(declare (uses tasks))
+(import tasks)
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+;;======================================================================
+;; attempt to prevent overlapping updates of rollup files by queueing
+;; update requests in an sqlite db
+;;======================================================================
+
+;;======================================================================
+;; db record,
+;;======================================================================
+
+(define (make-lock-queue:db-dat)(make-vector 3))
+(define-inline (lock-queue:db-dat-get-db vec) (vector-ref vec 0))
+(define-inline (lock-queue:db-dat-get-path vec) (vector-ref vec 1))
+(define-inline (lock-queue:db-dat-set-db! vec val)(vector-set! vec 0 val))
+(define-inline (lock-queue:db-dat-set-path! vec val)(vector-set! vec 1 val))
+
+(define (lock-queue:delete-lock-db dbdat)
+ (let ((fname (lock-queue:db-dat-get-path dbdat)))
+ (system (conc "rm -f " fname "*"))))
+
+(define (lock-queue:open-db fname #!key (count 10))
+ (let* ((actualfname (conc fname ".lockdb"))
+ (dbexists (common:file-exists? actualfname))
+ (db (sqlite3:open-database actualfname))
+ (handler (make-busy-timeout 136000)))
+ (if dbexists
+ (vector db actualfname)
+ (begin
+ (handle-exceptions
+ exn
+ (begin
+ (thread-sleep! 10)
+ (if (> count 0)
+ (lock-queue:open-db fname count: (- count 1))
+ (vector db actualfname)))
+ (sqlite3:with-transaction
+ db
+ (lambda ()
+ (sqlite3:execute
+ db
+ "CREATE TABLE IF NOT EXISTS queue (
+ id INTEGER PRIMARY KEY,
+ test_id INTEGER,
+ start_time INTEGER,
+ state TEXT,
+ CONSTRAINT queue_constraint UNIQUE (test_id));")
+ (sqlite3:execute
+ db
+ "CREATE TABLE IF NOT EXISTS runlocks (
+ id INTEGER PRIMARY KEY,
+ test_id INTEGER,
+ run_lock TEXT,
+ CONSTRAINT runlock_constraint UNIQUE (run_lock));"))))))
+ (sqlite3:set-busy-handler! db handler)
+ (vector db actualfname)))
+
+(define (lock-queue:set-state dbdat test-id newstate #!key (remtries 10))
+ (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200)
+ (handle-exceptions
+ exn
+ (if (> remtries 0)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: exception on lock-queue:set-state. Trying again in 30 seconds.")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (thread-sleep! 30)
+ (lock-queue:set-state dbdat test-id newstate remtries: (- remtries 1)))
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to set lock state for test with id " test-id ", error: " ((condition-property-accessor 'exn 'message) exn) ", giving up.")
+ #f))
+ (sqlite3:execute (lock-queue:db-dat-get-db dbdat) "UPDATE queue SET state=? WHERE test_id=?;"
+ newstate
+ test-id)))
+
+(define (lock-queue:any-younger? dbdat mystart test-id #!key (remtries 10))
+ ;; no need to wait on journal on read only queries
+ ;; (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200)
+ (handle-exceptions
+ exn
+ (if (> remtries 0)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: exception on lock-queue:any-younger. Removing lockdb and trying again in 5 seconds.")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (thread-sleep! 5)
+ (lock-queue:delete-lock-db dbdat)
+ (lock-queue:any-younger? dbdat mystart test-id remtries: (- remtries 1)))
+ (begin
+ (debug:print-error 0 *default-log-port* " Failed to find younger locks for test with id " test-id ", error: " ((condition-property-accessor 'exn 'message) exn) ", giving up.")
+ #f))
+ (let ((res #f))
+ (sqlite3:for-each-row
+ (lambda (tid)
+ ;; Actually this should not be needed as mystart cannot be simultaneously less than and test-id same as
+ (if (not (equal? tid test-id))
+ (set! res tid)))
+ (lock-queue:db-dat-get-db dbdat)
+ "SELECT test_id FROM queue WHERE start_time > ?;" mystart)
+ res)))
+
+(define (lock-queue:get-lock dbdat test-id #!key (count 10)(waiting-msg #f))
+ (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 remove: #t waiting-msg: "lock-queue:get-lock, waiting on journal")
+ (let* ((res #f)
+ (db (lock-queue:db-dat-get-db dbdat))
+ (lckqry (sqlite3:prepare db "SELECT test_id,run_lock FROM runlocks WHERE run_lock='locked';"))
+ (mklckqry (sqlite3:prepare db "INSERT INTO runlocks (test_id,run_lock) VALUES (?,'locked');")))
+ (let ((result
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: failed to get queue lock. Removing lock db and returning fail") ;; Will try again in a few seconds")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (thread-sleep! 10)
+ ;; (if (> count 0)
+ ;; #f ;; (lock-queue:get-lock dbdat test-id count: (- count 1)) - give up on retries
+ ;; (begin ;; never recovered, remote the lock file and return #f, no lock obtained
+ (lock-queue:delete-lock-db dbdat)
+ #f)
+ (sqlite3:with-transaction
+ db
+ (lambda ()
+ (sqlite3:for-each-row (lambda (tid lockstate)
+ (set! res (list tid lockstate)))
+ lckqry)
+ (if res
+ (if (equal? (car res) test-id)
+ #t ;; already have the lock
+ #f)
+ (begin
+ (sqlite3:execute mklckqry test-id)
+ ;; if no error handled then return #t for got the lock
+ #t)))))))
+ (sqlite3:finalize! lckqry)
+ (sqlite3:finalize! mklckqry)
+ result)))
+
+(define (lock-queue:release-lock fname test-id #!key (count 10))
+ (let* ((dbdat (lock-queue:open-db fname)))
+ (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 "lock-queue:release-lock; waiting on journal")
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Failed to release queue lock. Will try again in few seconds")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (thread-sleep! (/ count 10))
+ (if (> count 0)
+ (begin
+ (sqlite3:finalize! (lock-queue:db-dat-get-db dbdat))
+ (lock-queue:release-lock fname test-id count: (- count 1)))
+ (let ((journal (conc fname "-journal")))
+ ;; If we've tried ten times and failed there is a serious problem
+ ;; try to remove the lock db and allow it to be recreated
+ (handle-exceptions
+ exn
+ #f
+ (if (common:file-exists? journal)(delete-file journal))
+ (if (common:file-exists? fname) (delete-file fname))
+ #f))))
+ (sqlite3:execute (lock-queue:db-dat-get-db dbdat) "DELETE FROM runlocks WHERE test_id=?;" test-id)
+ (sqlite3:finalize! (lock-queue:db-dat-get-db dbdat)))))
+
+(define (lock-queue:steal-lock dbdat test-id #!key (count 10))
+ (debug:print-info 0 *default-log-port* "Attempting to steal lock at " (lock-queue:db-dat-get-path dbdat))
+ (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 "lock-queue:steal-lock; waiting on journal")
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Failed to steal queue lock. Will try again in few seconds")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (thread-sleep! 10)
+ (if (> count 0)
+ (lock-queue:steal-lock dbdat test-id count: (- count 1))
+ #f))
+ (sqlite3:execute (lock-queue:db-dat-get-db dbdat) "DELETE FROM runlocks WHERE run_lock='locked';"))
+ (lock-queue:get-lock dbdat test-it))
+
+;; returns #f if ok to skip the task
+;; returns #t if ok to proceed with task
+;; otherwise waits
+;;
+(define (lock-queue:wait-turn fname test-id #!key (count 10)(waiting-msg #f))
+ (let* ((dbdat (lock-queue:open-db fname))
+ (mystart (current-seconds))
+ (db (lock-queue:db-dat-get-db dbdat)))
+ ;; (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 waiting-msg: "lock-queue:wait-turn; waiting on journal file")
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Failed to find out if it is ok to skip the wait queue. Will try again in few seconds")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (print-call-chain (current-error-port))
+ (thread-sleep! 10)
+ (if (> count 0)
+ (begin
+ (sqlite3:finalize! db)
+ (lock-queue:wait-turn fname test-id count: (- count 1)))
+ (begin
+ (debug:print 0 *default-log-port* "Giving up calls to lock-queue:wait-turn for test-id " test-id " at path " fname ", printing call chain")
+ (print-call-chain (current-error-port))
+ #f)))
+ ;; wait 10 seconds and then check to see if someone is already updating the html
+ (thread-sleep! 10)
+ (if (not (lock-queue:any-younger? dbdat mystart test-id)) ;; no processing in flight, must try to start processing
+ (begin
+ (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 waiting-msg: "lock-queue:wait-turn; waiting on journal file")
+ (sqlite3:execute
+ db
+ "INSERT OR REPLACE INTO queue (test_id,start_time,state) VALUES (?,?,'waiting');"
+ test-id mystart)
+ ;; (thread-sleep! 1) ;; give other tests a chance to register
+ (let ((result
+ (let loop ((younger-waiting (lock-queue:any-younger? dbdat mystart test-id)))
+ (if younger-waiting
+ (begin
+ ;; no need for us to wait. mark in the lock queue db as skipping
+ ;; no point in marking anything in the queue - simply never register this
+ ;; test as it is *covered* by a previously started update to the html file
+ ;; (lock-queue:set-state dbdat test-id "skipping")
+ #f) ;; let the calling process know that nothing needs to be done
+ (if (lock-queue:get-lock dbdat test-id)
+ #t
+ (if (> (- (current-seconds) mystart) 36000) ;; waited too long, steal the lock
+ (lock-queue:steal-lock dbdat test-id)
+ (begin
+ (thread-sleep! 1)
+ (loop (lock-queue:any-younger? dbdat mystart test-id)))))))))
+ (sqlite3:finalize! db)
+ result))))))
+
+
+;; (use trace)
+;; (trace lock-queue:get-lock lock-queue:release-lock lock-queue:wait-turn lock-queue:any-younger? lock-queue:set-state)
ADDED attic_modular/margsmod.import.scm
Index: attic_modular/margsmod.import.scm
==================================================================
--- /dev/null
+++ attic_modular/margsmod.import.scm
@@ -0,0 +1,20 @@
+;;;; margsmod.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import scheme chicken data-structures extras srfi-69 srfi-1))
+(##sys#register-compiled-module
+ 'margsmod
+ (list)
+ '((args:print-args . margsmod#args:print-args)
+ (args:get-args . margsmod#args:get-args)
+ (args:any-defined? . margsmod#args:any-defined?)
+ (args:usage . margsmod#args:usage)
+ (args:get-arg-from . margsmod#args:get-arg-from)
+ (args:any? . margsmod#args:any?)
+ (args:get-arg . margsmod#args:get-arg)
+ (args:arg-hash . margsmod#args:arg-hash)
+ (args:set-help . margsmod#args:set-help)
+ (args:help . margsmod#args:help))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/margsmod.scm
Index: attic_modular/margsmod.scm
==================================================================
--- /dev/null
+++ attic_modular/margsmod.scm
@@ -0,0 +1,99 @@
+;; Copyright 2007-2010, 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 .
+
+
+(declare (unit margsmod))
+
+(module margsmod
+ *
+
+(import scheme chicken data-structures extras)
+(import srfi-69 srfi-1)
+
+(define args:help #f)
+
+(define (args:set-help help)
+ (set! args:help help))
+
+(define args:arg-hash (make-hash-table))
+
+(define (args:get-arg arg . default)
+ (if (null? default)
+ (hash-table-ref/default args:arg-hash arg #f)
+ (hash-table-ref/default args:arg-hash arg (car default))))
+
+(define (args:any? . args)
+ (not (null? (filter (lambda (x) x)
+ (map args:get-arg args)))))
+
+(define (args:get-arg-from ht arg . default)
+ (if (null? default)
+ (hash-table-ref/default ht arg #f)
+ (hash-table-ref/default ht arg (car default))))
+
+(define (args:usage . args)
+ (if (> (length args) 0)
+ (apply print "ERROR: " args))
+ (if (string? args:help)
+ (print args:help)
+ (print "Usage: " (car (argv)) " ... "))
+ (exit 0))
+
+ ;; one-of args defined
+(define (args:any-defined? . param)
+ (let ((res #f))
+ (for-each
+ (lambda (arg)
+ (if (args:get-arg arg)(set! res #t)))
+ param)
+ res))
+
+;; args:
+(define (args:get-args args params switches arg-hash num-needed)
+ (let* ((numargs (length args))
+ (adj-num-needed (if num-needed (+ num-needed 2) #f)))
+ (if (< numargs (if adj-num-needed adj-num-needed 2))
+ (if (>= num-needed 1)
+ (args:usage "No arguments provided")
+ '())
+ (let loop ((arg (cadr args))
+ (tail (cddr args))
+ (remargs '()))
+ (cond
+ ((member arg params) ;; args with params
+ (if (< (length tail) 1)
+ (args:usage "param given without argument " arg)
+ (let ((val (car tail))
+ (newtail (cdr tail)))
+ (hash-table-set! arg-hash arg val)
+ (if (null? newtail) remargs
+ (loop (car newtail)(cdr newtail) remargs)))))
+ ((member arg switches) ;; args with no params (i.e. switches)
+ (hash-table-set! arg-hash arg #t)
+ (if (null? tail) remargs
+ (loop (car tail)(cdr tail) remargs)))
+ (else
+ (if (null? tail)(append remargs (list arg)) ;; return the non-used args
+ (loop (car tail)(cdr tail)(append remargs (list arg))))))))
+ ))
+
+(define (args:print-args remargs arg-hash)
+ (print "ARGS: " remargs)
+ (for-each (lambda (arg)
+ (print " " arg " " (hash-table-ref/default arg-hash arg #f)))
+ (hash-table-keys arg-hash)))
+)
ADDED attic_modular/megatest-fossil-hash.scm
Index: attic_modular/megatest-fossil-hash.scm
==================================================================
--- /dev/null
+++ attic_modular/megatest-fossil-hash.scm
@@ -0,0 +1,1 @@
+(define megatest-fossil-hash "ff6cbfba6c16713b75556397cc232f528599af19")
ADDED attic_modular/megatest-version.scm
Index: attic_modular/megatest-version.scm
==================================================================
--- /dev/null
+++ attic_modular/megatest-version.scm
@@ -0,0 +1,23 @@
+;; 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 .
+
+;; Always use two or four digit decimal
+;; 1.01, 1.02...1.10,1.11,1.1101 ... 1.99,2.00..
+
+;; (declare (unit megatest-version))
+
+(define megatest-version 1.6583)
ADDED attic_modular/megatest.scm
Index: attic_modular/megatest.scm
==================================================================
--- /dev/null
+++ attic_modular/megatest.scm
@@ -0,0 +1,2611 @@
+;; 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 .
+;;
+
+(use (prefix sqlite3 sqlite3:)
+ srfi-1 posix regex regex-case
+ srfi-69 (prefix base64 base64:) apropos json http-client
+ directory-utils typed-records http-client srfi-18 extras format
+ sparse-vectors)
+
+;; fake out readline usage of toplevel-command
+(define (toplevel-command . a) #f)
+(use readline)
+
+(declare (uses margsmod))
+(import margsmod)
+(declare (uses margsmod.import))
+
+(declare (uses debugprint))
+(import debugprint)
+(declare (uses debugprint.import))
+
+(declare (uses configfmod))
+(import configfmod)
+(declare (uses configfmod.import))
+
+(declare (uses commonmod))
+(import commonmod)
+(declare (uses commonmod.import))
+
+(declare (uses items))
+(import items)
+(declare (uses items.import))
+
+(declare (uses ods))
+(import ods)
+(declare (uses ods.import))
+
+(declare (uses dbmod))
+(import dbmod)
+(declare (uses dbmod.import))
+
+(declare (uses pgdb))
+(import pgdb)
+(declare (uses pgdb.import))
+
+(declare (uses tasks)) ;; only used for debugging.
+(import tasks)
+(declare (uses tasks.import))
+
+(declare (uses apimod))
+(import apimod)
+(declare (uses apimod.import))
+
+(declare (uses portlogger))
+(import portlogger)
+(declare (uses portlogger.import))
+
+(declare (uses tdb))
+(import tdb)
+(declare (uses tdb.import))
+
+(declare (uses rmtmod))
+(import rmtmod)
+(declare (uses rmtmod.import))
+
+(declare (uses client))
+(import client)
+(declare (uses client.import))
+
+(declare (uses ods))
+(import ods)
+(declare (uses ods.import))
+
+(declare (uses dbmod))
+(import dbmod)
+(declare (uses dbmod.import))
+
+(declare (uses servermod))
+(import servermod)
+(declare (uses servermod.import))
+
+
+;; (include "common.scm")
+(include "megatest-version.scm")
+
+(declare (uses common))
+;; (declare (uses megatest-version))
+
+(declare (uses runs))
+(declare (uses launch))
+(declare (uses server))
+
+(declare (uses tests))
+(declare (uses genexample))
+(declare (uses db))
+
+(declare (uses tdb))
+(declare (uses mt))
+
+(declare (uses env))
+(declare (uses diff-report))
+
+;; Needed for repl even if not used here in megatest.scm
+;; ORDER MATTERS!
+
+
+(define *db* #f) ;; this is only for the repl, do not use in general!!!!
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "run_records.scm")
+(include "megatest-fossil-hash.scm")
+
+(require-library mutils)
+
+(define *usage-log-file* #f) ;; put path to file for logging usage in this var in the ~/.megatestrc file
+(define *usage-use-seconds* #t) ;; for Epoc seconds in usage logging change this to #t in ~/.megatestrc file
+
+;; load the ~/.megatestrc file, put (use trace)(trace-call-sites #t)(trace function-you-want-to-trace) in this file
+;;
+(let ((debugcontrolf (conc (get-environment-variable "HOME") "/.megatestrc")))
+ (if (common:file-exists? debugcontrolf)
+ (load debugcontrolf)))
+
+;; usage logging, careful with this, it is not designed to deal with all real world challenges!
+;;
+(if (and *usage-log-file*
+ (file-write-access? *usage-log-file*))
+ (with-output-to-file
+ *usage-log-file*
+ (lambda ()
+ (print
+ (if *usage-use-seconds*
+ (current-seconds)
+ (time->string
+ (seconds->local-time (current-seconds))
+ "%Yww%V.%w %H:%M:%S"))
+ " "
+ (current-user-name) " "
+ (current-directory) " "
+ "\"" (string-intersperse (argv) " ") "\""))
+ #:append))
+
+;; Disabled help items
+;; -rollup : (currently disabled) fill run (set by :runname) with latest test(s)
+;; from prior runs with same keys
+;; -daemonize : fork into background and disconnect from stdin/out
+
+(define help (conc "
+Megatest, documentation at http://www.kiatoa.com/fossils/megatest
+ version " megatest-version "
+ license GPL, Copyright Matt Welland 2006-2017
+
+Usage: megatest [options]
+ -h : this help
+ -manual : show the Megatest user manual
+ -version : print megatest version (currently " megatest-version ")
+
+Launching and managing runs
+ -run : run all tests or as specified by -testpatt
+ -remove-runs : remove the data for a run, requires -runname and -testpatt
+ Optionally use :state and :status, use -keep-records to remove only
+ the run data. Use -kill-wait to override the 10 second
+ per test wait after kill delay (e.g. -kill-wait 0).
+ -kill-runs : kill existing run(s) (all incomplete tests killed)
+ -kill-rerun : kill an existing run (all incomplete tests killed and run is rerun)
+ -set-state-status X,Y : set state to X and status to Y, requires controls per -remove-runs
+ -rerun FAIL,WARN... : force re-run for tests with specificed status(s)
+ -rerun-clean : set all tests not COMPLETED+PASS,WARN,WAIVED to NOT_STARTED,n/a
+ and then run the specified testpatt with -preclean
+ -rerun-all : set all tests to NOT_STARTED,n/a and run with -preclean
+ -lock : lock run specified by target and runname
+ -unlock : unlock run specified by target and runname
+ -set-run-status status : sets status for run to status, requires -target and -runname
+ -get-run-status : gets status for run specified by target and runname
+ -run-wait : wait on run specified by target and runname
+ -preclean : remove the existing test directory before running the test
+ -clean-cache : remove the cached megatest.config and runconfigs.config files
+ -no-cache : do not use the cached config files.
+ -one-pass : launch as many tests as you can but do not wait for more to be ready
+ -remove-keep N : remove all but N most recent runs per target; use '-actions, -age, -precmd'
+ -age : 120d,3h,20m to apply only to runs older than the
+ specified age. NB// M=month, m=minute
+ -actions [,...] : actions to take; print,remove-runs,archive,kill-runs
+ -precmd : insert a wrapper command in front of the commands run
+
+Selectors (e.g. use for -runtests, -remove-runs, -set-state-status, -list-runs etc.)
+ -target key1/key2/... : run for key1, key2, etc.
+ -reqtarg key1/key2/... : run for key1, key2, etc. but key1/key2 must be in runconfigs
+ -testpatt patt1/patt2,patt3/... : % is wildcard
+ -runname : required, name for this particular test run
+ -state : Applies to runs, tests or steps depending on context
+ -status : Applies to runs, tests or steps depending on context
+ -modepatt key : load testpatt from in runconfigs instead of default TESTPATT if -testpatt and -tagexpr are not specified
+ -tagexpr tag1,tag2%,.. : select tests with tags matching expression
+
+
+Test helpers (for use inside tests)
+ -step stepname
+ -test-status : set the state and status of a test (use :state and :status)
+ -setlog logfname : set the path/filename to the final log relative to the test
+ directory. may be used with -test-status
+ -set-toplog logfname : set the overall log for a suite of sub-tests
+ -summarize-items : for an itemized test create a summary html
+ -m comment : insert a comment for this test
+
+Test data capture
+ -set-values : update or set values in the testdata table
+ :category : set the category field (optional)
+ :variable : set the variable name (optional)
+ :value : value measured (required)
+ :expected : value expected (required)
+ :tol : |value-expect| <= tol (required, can be <, >, >=, <= or number)
+ :units : name of the units for value, expected_value etc. (optional)
+ -load-test-data : read test specific data for storage in the test_data table
+ from standard in. Each line is comma delimited with four
+ fields category,variable,value,comment
+
+Queries
+ -list-runs patt : list runs matching pattern \"patt\", % is the wildcard
+ -show-keys : show the keys used in this megatest setup
+ -test-files targpatt : get the most recent test path/file matching targpatt e.g. %/% or '*.log'
+ returns list sorted by age ascending, see examples below
+ -test-paths : get the test paths matching target, runname, item and test
+ patterns.
+ -list-disks : list the disks available for storing runs
+ -list-targets : list the targets in runconfigs.config
+ -list-db-targets : list the target combinations used in the db
+ -show-config : dump the internal representation of the megatest.config file
+ -show-runconfig : dump the internal representation of the runconfigs.config file
+ -dumpmode MODE : dump in MODE format instead of sexpr, MODE=json,ini,sexp etc. (add -debug 0,9 to see which file contributes each line)
+ -show-cmdinfo : dump the command info for a test (run in test environment)
+ -section sectionName
+ -var varName : for config and runconfig lookup value for sectionName varName
+ -since N : get list of runs changed since time N (Unix seconds)
+ -fields fieldspec : fields to include in json dump; runs:id,runame+tests:testname+steps
+ -sort fieldname : in -list-runs sort tests by this field
+ -testdata-csv [categorypatt/]varpatt : dump testdata for given category
+
+Misc
+ -start-dir path : switch to this directory before running megatest
+ -contour cname : add a level of hierarcy to the linktree and run paths
+ -area-tag tagname : add a tag to an area while syncing to pgdb
+ -run-tag tagname : add a tag to a run while syncing to pgdb
+ -rebuild-db : bring the database schema up to date
+ -cleanup-db : remove any orphan records, vacuum the db
+ -import-megatest.db : push data from megatest.db to cache db files in /tmp/$USER
+ -sync-to-megatest.db : pull data from cache files in /tmp/$USER to megatest.db
+ -sync-to dest : sync to new postgresql central style database
+ -update-meta : update the tests metadata for all tests
+ -setvars VAR1=val1,VAR2=val2 : Add environment variables to a run NB// these are
+ overwritten by values set in config files.
+ -server -|hostname : start the server (reduces contention on megatest.db), use
+ - to automatically figure out hostname
+ -adjutant C,M : start the server/adjutant with allocated cores C and Mem M (Gig),
+ use 0,0 to auto use full machine
+ -transport http|rpc : use http or rpc for transport (default is http)
+ -log logfile : send stdout and stderr to logfile
+ -list-servers : list the servers
+ -kill-servers : kill all servers
+ -repl : start a repl (useful for extending megatest)
+ -load file.scm : load and run file.scm
+ -mark-incompletes : find and mark incomplete tests
+ -ping run-id|host:port : ping server, exit with 0 if found
+ -debug N|N,M,O... : enable debug 0-N or N and M and O ...
+ -debug-noprop N|M,M,O...: enable debug but do not propagate to subprocesses via MT_DEBUG
+ -config fname : override the megatest.config file with fname
+ -append-config fname : append fname to the megatest.config file
+
+Utilities
+ -env2file fname : write the environment to fname.csh and fname.sh
+ -envcap a : save current variables labeled as context 'a' in file envdat.db
+ -envdelta a-b : output enviroment delta from context a to context b to -o fname
+ set the output mode with -dumpmode csh, bash or ini
+ note: ini format will use calls to use curr and minimize path
+ -refdb2dat refdb : convert refdb to sexp or to format specified by s-dumpmode
+ formats: perl, ruby, sqlite3, csv (for csv the -o param
+ will substitute %s for the sheet name in generating
+ multiple sheets)
+ -o : output file for refdb2dat (defaults to stdout)
+ -archive cmd : archive runs specified by selectors to one of disks specified
+ in the [archive-disks] section.
+ cmd: keep-html, restore, save, save-remove, get, replicate-db (use
+ -dest to set destination), -include path1,path2... to get or save specific files
+ -generate-html : create a simple html dashboard for browsing your runs
+ -generate-html-structure : create a top level html veiw to list targets/runs and a Run view within each run directory.
+ -list-run-time : list time requered to complete runs. It supports following switches
+ -run-patt -target-patt -dumpmode
+ -list-test-time : list time requered to complete each test in a run. It following following arguments
+ -runname -target -dumpmode
+ -syscheck : do some very basic checks; write access and space in tmp, home, runs, links and
+ is $DISPLAY valid
+ -list-waivers : dump waivers for specified target, runname, testpatt to stdout
+
+Diff report
+ -diff-rep : generate diff report (must include -src-target, -src-runname, -target, -runname
+ and either -diff-email or -diff-html)
+ -src-target
+ -src-runname
+ -diff-email : comma separated list of email addresses to send diff report
+ -diff-html : path to html file to generate
+
+Spreadsheet generation
+ -extract-ods fname.ods : extract an open document spreadsheet from the database
+ -pathmod path : insert path, i.e. path/runame/itempath/logfile.html
+ will clear the field if no rundir/testname/itempath/logfile
+ if it contains forward slashes the path will be converted
+ to windows style
+Getting started
+ -create-megatest-area : create a skeleton megatest area. You will be prompted for paths
+ -create-test testname : create a skeleton megatest test. You will be prompted for info
+
+Examples
+
+# Get test path, use '.' to get a single path or a specific path/file pattern
+megatest -test-files 'logs/*.log' -target ubuntu/n%/no% -runname w49% -testpatt test_mt%
+
+Called as " (string-intersperse (argv) " ") "
+Version " megatest-version ", built from " megatest-fossil-hash ))
+
+;; -gui : start a gui interface
+;; -config fname : override the runconfigs file with fname
+
+;; process args
+(define remargs (args:get-args
+ (argv)
+ (list "-runtests" ;; run a specific test
+ "-config" ;; override the config file name
+ "-append-config"
+ "-execute" ;; run the command encoded in the base64 parameter
+ "-step"
+ "-target"
+ "-reqtarg"
+ ":runname"
+ "-runname"
+ ":state"
+ "-state"
+ ":status"
+ "-status"
+ "-list-runs"
+ "-testdata-csv"
+ "-testpatt"
+ "--modepatt"
+ "-modepatt"
+ "-tagexpr"
+ "-itempatt"
+ "-setlog"
+ "-set-toplog"
+ "-runstep"
+ "-logpro"
+ "-m"
+ "-rerun"
+
+ "-days"
+ "-rename-run"
+ "-to"
+ "-dest"
+ "-source"
+ "-time-stamp"
+ ;; values and messages
+ ":category"
+ ":variable"
+ ":value"
+ ":expected"
+ ":tol"
+ ":units"
+
+ ;; misc
+ "-start-dir"
+ "-run-patt"
+ "-target-patt"
+ "-contour"
+ "-area-tag"
+ "-area"
+ "-run-tag"
+ "-server"
+ "-adjutant"
+ "-transport"
+ "-port"
+ "-extract-ods"
+ "-pathmod"
+ "-env2file"
+ "-envcap"
+ "-envdelta"
+ "-setvars"
+ "-set-state-status"
+
+ ;; move runs stuff here
+ "-remove-keep"
+ "-set-run-status"
+ "-age"
+
+ ;; archive
+ "-archive"
+ "-actions"
+ "-precmd"
+ "-include"
+ "-exclude-rx"
+ "-exclude-rx-from"
+
+ "-debug" ;; for *verbosity* > 2
+ "-debug-noprop"
+ "-create-test"
+ "-override-timeout"
+ "-test-files" ;; -test-paths is for listing all
+ "-load" ;; load and exectute a scheme file
+ "-section"
+ "-var"
+ "-dumpmode"
+ "-run-id"
+ "-ping"
+ "-refdb2dat"
+ "-o"
+ "-log"
+ "-sync-log"
+ "-since"
+ "-fields"
+ "-recover-test" ;; run-id,test-id - used internally to recover a test stuck in RUNNING state
+ "-sort"
+ "-target-db"
+ "-source-db"
+ "-prefix-target"
+
+ "-src-target"
+ "-src-runname"
+ "-diff-email"
+ "-sync-to"
+ "-pgsync"
+ "-kill-wait" ;; wait this long before removing test (default is 10 sec)
+ "-diff-html"
+
+ ;; wizards, area capture, setup new ...
+ "-extract-skeleton"
+ )
+ (list "-h" "-help" "--help"
+ "-manual"
+ "-version"
+ "-force"
+ "-xterm"
+ "-showkeys"
+ "-show-keys"
+ "-test-status"
+ "-set-values"
+ "-load-test-data"
+ "-summarize-items"
+ "-gui"
+ "-daemonize"
+ "-preclean"
+ "-rerun-clean"
+ "-rerun-all"
+ "-clean-cache"
+ "-no-cache"
+ "-cache-db"
+ "-cp-eventtime-to-publishtime"
+ "-use-db-cache"
+ "-prepend-contour"
+
+
+ ;; misc
+ "-repl"
+ "-lock"
+ "-unlock"
+ "-list-servers"
+ "-kill-servers"
+ "-run-wait" ;; wait on a run to complete (i.e. no RUNNING)
+ "-one-pass" ;;
+ "-local" ;; run some commands using local db access
+ "-generate-html"
+ "-generate-html-structure"
+ "-list-run-time"
+ "-list-test-time"
+
+ ;; misc queries
+ "-list-disks"
+ "-list-targets"
+ "-list-db-targets"
+ "-show-runconfig"
+ "-show-config"
+ "-show-cmdinfo"
+ "-get-run-status"
+ "-list-waivers"
+
+ ;; queries
+ "-test-paths" ;; get path(s) to a test, ordered by youngest first
+
+ "-runall" ;; run all tests, respects -testpatt, defaults to %
+ "-run" ;; alias for -runall
+ "-remove-runs"
+ "-kill-runs"
+ "-kill-rerun"
+ "-keep-records" ;; use with -remove-runs to remove only the run data
+ "-rebuild-db"
+ "-cleanup-db"
+ "-rollup"
+ "-update-meta"
+ "-create-megatest-area"
+ "-mark-incompletes"
+
+ "-convert-to-norm"
+ "-convert-to-old"
+ "-import-megatest.db"
+ "-sync-to-megatest.db"
+ "-sync-brute-force"
+ ;; "-logging"
+ "-v" ;; verbose 2, more than normal (normal is 1)
+ "-q" ;; quiet 0, errors/warnings only
+
+ "-diff-rep"
+
+ "-syscheck"
+ "-obfuscate"
+ ;; junk placeholder
+ ;; "-:p"
+
+ )
+ args:arg-hash
+ 0))
+
+;; Add args that use remargs here
+;;
+(if (and (not (null? remargs))
+ (not (or
+ (args:get-arg "-runstep")
+ (args:get-arg "-envcap")
+ (args:get-arg "-envdelta")
+ )
+ ))
+ (debug:print-error 0 *default-log-port* "Unrecognised arguments: " (string-intersperse (if (list? remargs) remargs (argv)) " ")))
+
+;; before doing anything else change to the start-dir if provided
+;;
+(if (args:get-arg "-start-dir")
+ (if (common:file-exists? (args:get-arg "-start-dir"))
+ (let ((fullpath (common:real-path (args:get-arg "-start-dir"))))
+ (setenv "PWD" fullpath)
+ (change-directory fullpath))
+ (begin
+ (debug:print-error 0 *default-log-port* "non-existant start dir " (args:get-arg "-start-dir") " specified, exiting.")
+ (exit 1))))
+
+;; immediately set MT_TARGET if -reqtarg or -target are available
+;;
+(let ((targ (or (args:get-arg "-reqtarg")(args:get-arg "-target"))))
+ (if targ (setenv "MT_TARGET" targ)))
+
+;; The watchdog is to keep an eye on things like db sync etc.
+;;
+;; moved to commonmod
+
+;;(if (not (args:get-arg "-server"))
+;; (thread-start! *watchdog*)) ;; if starting a server; wait till we get to running state before kicking off watchdog
+(let* ((no-watchdog-args
+ '("-list-runs"
+ "-testdata-csv"
+ "-list-servers"
+ "-server"
+ "-adjutant"
+ "-list-disks"
+ "-list-targets"
+ "-show-runconfig"
+ ;;"-list-db-targets"
+ "-show-runconfig"
+ "-show-config"
+ "-show-cmdinfo"
+ "-cleanup-db"
+ ))
+ (no-watchdog-argvals (list '("-archive" . "replicate-db")))
+ (start-watchdog-specail-arg-val (let loop ((hed (car no-watchdog-argvals))
+ (tail (cdr no-watchdog-argvals)))
+ ;; (print "hed" hed " arg " (args:get-arg (car hed)) " val:" (cdr hed) " eql" (equal? (args:get-arg (car hed)) (cdr hed)))
+ (if (equal? (args:get-arg (car hed)) (cdr hed))
+ #f
+ (if (null? tail)
+ #t
+ (loop (car tail) (cdr tail))))))
+ (no-watchdog-args-vals (filter (lambda (x) x)
+ (map args:get-arg no-watchdog-args)))
+ (start-watchdog (and (null? no-watchdog-args-vals) start-watchdog-specail-arg-val)))
+ ;(print "no-watchdog-args="no-watchdog-args "no-watchdog-args-vals="no-watchdog-args-vals " start-watchdog-specail-arg-val:" start-watchdog-specail-arg-val " start-watchdog:" start-watchdog)
+ (if start-watchdog
+ (thread-start! *watchdog*)))
+
+
+;; bracket open-output-file with code to make leading directory if it does not exist and handle exceptions
+(define (open-logfile logpath-in)
+ (condition-case
+ (let* ((log-dir (or (pathname-directory logpath-in) "."))
+ (fname (pathname-strip-directory logpath-in))
+ (logpath (if (> (string-length fname) 250)
+ (let ((newlogf (conc log-dir "/" (common:get-signature fname) ".log")))
+ (debug:print 0 *default-log-port* "WARNING: log file " logpath-in " path too long, converted to " newlogf)
+ newlogf)
+ logpath-in)))
+ (if (not (directory-exists? log-dir))
+ (system (conc "mkdir -p " log-dir)))
+ (open-output-file logpath))
+ (exn ()
+ (debug:print-error 0 *default-log-port* "Could not open log file for write: "logpath)
+ (define *didsomething* #t)
+ (exit 1))))
+
+;; this segment will run launch:setup only if -log is not set. This is fairly safe as servers are not
+;; manually started and thus should never be started in a non-megatest area. Thus no need to handle situation
+;; where (launch:setup) returns #f?
+;;
+(if (or (args:get-arg "-log")(args:get-arg "-server")) ;; redirect the log always when a server
+ (handle-exceptions
+ exn
+ (begin
+ (print "ERROR: Failed to switch to log output. " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn)
+ )
+ (let* ((tl (or (args:get-arg "-log")(launch:setup))) ;; run launch:setup if -server, ensure we do NOT run launch:setup if -log specified
+ (logf (or (args:get-arg "-log") ;; use -log unless we are a server, then craft a logfile name
+ (conc tl "/logs/server-" (current-process-id) "-" (get-host-name) ".log")))
+ (oup (open-logfile logf)))
+ (if (not (args:get-arg "-log"))
+ (hash-table-set! args:arg-hash "-log" logf)) ;; fake out future queries of -log
+ (debug:print-info 0 *default-log-port* "Sending log output to " logf)
+ (set! *default-log-port* oup))))
+
+(if (or (args:get-arg "-h")
+ (args:get-arg "-help")
+ (args:get-arg "--help"))
+ (begin
+ (print help)
+ (exit)))
+
+(if (args:get-arg "-manual")
+ (let* ((htmlviewercmd (or (configf:lookup *configdat* "setup" "htmlviewercmd")
+ (common:which '("firefox" "arora"))))
+ (install-home (common:get-install-area))
+ (manual-html (conc install-home "/share/docs/megatest_manual.html")))
+ (if (and install-home
+ (common:file-exists? manual-html))
+ (system (conc "(" htmlviewercmd " " manual-html " ) &"))
+ (system (conc "(" htmlviewercmd " http://www.kiatoa.com/cgi-bin/fossils/megatest/doc/tip/docs/manual/megatest_manual.html ) &")))
+ (exit)))
+
+(if (args:get-arg "-version")
+ (begin
+ (print (common:version-signature)) ;; (print megatest-version)
+ (exit)))
+
+(define *didsomething* #f)
+
+;; Overall exit handling setup immediately
+;;
+(if (or (args:get-arg "-process-reap"))
+ ;; (args:get-arg "-runtests")
+ ;; (args:get-arg "-execute")
+ ;; (args:get-arg "-remove-runs")
+ ;; (args:get-arg "-runstep"))
+ (let ((original-exit (exit-handler)))
+ (exit-handler (lambda (#!optional (exit-code 0))
+ (printf "Preparing to exit with exit code ~A ...\n" exit-code)
+ (for-each
+
+ (lambda (pid)
+ (handle-exceptions
+ exn
+ (begin
+ (printf "process reap failed. exn=~A\n" exn)
+ #t)
+ (let-values (((pid-val exit-status exit-code) (process-wait pid #t)))
+ (if (or (eq? pid-val pid)
+ (eq? pid-val 0))
+ (begin
+ (printf "Sending signal/term to ~A\n" pid)
+ (process-signal pid signal/term))))))
+ (process:children #f))
+ (original-exit exit-code)))))
+
+;; for some switches always print the command to stderr
+;;
+(if (args:any? "-run" "-runall" "-remove-runs" "-set-state-status" "-kill-runs" "-kill-rerun")
+ (debug:print 0 *default-log-port* (string-intersperse (argv) " ")))
+
+;; some switches imply homehost. Exit here if not on homehost
+;;
+(let ((homehost-required (list "-cleanup-db" "-server")))
+ (if (apply args:any? homehost-required)
+ (if (not (common:on-homehost?))
+ (for-each
+ (lambda (switch)
+ (if (args:get-arg switch)
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: you must be on the homehost to run with " switch
+ ", you can move homehost by removing the .homehost file but this will disrupt any runs in progress.")
+ (exit 1))))
+ homehost-required))))
+
+;;======================================================================
+;; Misc setup stuff
+;;======================================================================
+
+(common:debug-setup)
+
+;; (if (args:get-arg "-logging")(set! *logging* #t))
+
+;;(if (debug:debug-mode 3) ;; we are obviously debugging
+;; (set! open-run-close open-run-close-no-exception-handling))
+
+(if (args:get-arg "-itempatt")
+ (let ((newval (conc (args:get-arg "-testpatt") "/" (args:get-arg "-itempatt"))))
+ (debug:print 0 *default-log-port* "WARNING: -itempatt has been deprecated, please use -testpatt testpatt/itempatt method, new testpatt is "newval)
+ (hash-table-set! args:arg-hash "-testpatt" newval)
+ (hash-table-delete! args:arg-hash "-itempatt")))
+
+(if (args:get-arg "-runtests")
+ (debug:print 0 *default-log-port* "WARNING: \"-runtests\" is deprecated. Use \"-run\" with \"-testpatt\" instead"))
+
+(on-exit std-exit-procedure)
+
+;;======================================================================
+;; Misc general calls
+;;======================================================================
+
+(if (and (args:get-arg "-cache-db")
+ (args:get-arg "-source-db"))
+ (let* ((temp-dir (or (args:get-arg "-target-db") (create-directory (conc "/tmp/" (getenv "USER") "/" (string-translate (current-directory) "/" "_")))))
+ (target-db (conc temp-dir "/cached.db"))
+ (source-db (args:get-arg "-source-db")))
+ (db:cache-for-read-only source-db target-db)
+ (set! *didsomething* #t)))
+
+;; handle a clean-cache request as early as possible
+;;
+(if (args:get-arg "-clean-cache")
+ (let ((toppath (launch:setup)))
+ (set! *didsomething* #t) ;; suppress the help output.
+ (runs:clean-cache (common:args-get-target)
+ (args:get-arg "-runname")
+ toppath)))
+
+(if (args:get-arg "-env2file")
+ (begin
+ (save-environment-as-files (args:get-arg "-env2file"))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-list-disks")
+ (let ((toppath (launch:setup)))
+ (print
+ (string-intersperse
+ (map (lambda (x)
+ (string-intersperse
+ x
+ " => "))
+ (common:get-disks *configdat*))
+ "\n"))
+ (set! *didsomething* #t)))
+
+;; csv processing record
+(define (make-refdb:csv)
+ (vector
+ (make-sparse-array)
+ (make-hash-table)
+ (make-hash-table)
+ 0
+ 0))
+(define-inline (refdb:csv-get-svec vec) (vector-ref vec 0))
+(define-inline (refdb:csv-get-rows vec) (vector-ref vec 1))
+(define-inline (refdb:csv-get-cols vec) (vector-ref vec 2))
+(define-inline (refdb:csv-get-maxrow vec) (vector-ref vec 3))
+(define-inline (refdb:csv-get-maxcol vec) (vector-ref vec 4))
+(define-inline (refdb:csv-set-svec! vec val)(vector-set! vec 0 val))
+(define-inline (refdb:csv-set-rows! vec val)(vector-set! vec 1 val))
+(define-inline (refdb:csv-set-cols! vec val)(vector-set! vec 2 val))
+(define-inline (refdb:csv-set-maxrow! vec val)(vector-set! vec 3 val))
+(define-inline (refdb:csv-set-maxcol! vec val)(vector-set! vec 4 val))
+
+(define (get-dat results sheetname)
+ (or (hash-table-ref/default results sheetname #f)
+ (let ((tmp-vec (make-refdb:csv)))
+ (hash-table-set! results sheetname tmp-vec)
+ tmp-vec)))
+
+(if (args:get-arg "-refdb2dat")
+ (let* ((input-db (args:get-arg "-refdb2dat"))
+ (out-file (args:get-arg "-o"))
+ (out-fmt (or (args:get-arg "-dumpmode") "scheme"))
+ (out-port (if (and out-file
+ (not (member out-fmt '("sqlite3" "csv"))))
+ (open-output-file out-file)
+ (current-output-port)))
+ (res-data (configf:read-refdb input-db))
+ (data (car res-data))
+ (msg (cadr res-data)))
+ (if (not data)
+ (debug:print 0 *default-log-port* "Bad input? data=" data) ;; some error occurred
+ (with-output-to-port out-port
+ (lambda ()
+ (case (string->symbol out-fmt)
+ ((scheme)(pp data))
+ ((perl)
+ ;; (print "%hash = (")
+ ;; key1 => 'value1',
+ ;; key2 => 'value2',
+ ;; key3 => 'value3',
+ ;; );
+ (configf:map-all-hier-alist
+ data
+ (lambda (sheetname sectionname varname val)
+ (print "$data{\"" sheetname "\"}{\"" sectionname "\"}{\"" varname "\"} = \"" val "\";"))))
+ ((python ruby)
+ (print "data={}")
+ (configf:map-all-hier-alist
+ data
+ (lambda (sheetname sectionname varname val)
+ (print "data[\"" sheetname "\"][\"" sectionname "\"][\"" varname "\"] = \"" val "\""))
+ initproc1:
+ (lambda (sheetname)
+ (print "data[\"" sheetname "\"] = {}"))
+ initproc2:
+ (lambda (sheetname sectionname)
+ (print "data[\"" sheetname "\"][\"" sectionname "\"] = {}"))))
+ ((csv)
+ (let* ((results (make-hash-table)) ;; (make-sparse-array)))
+ (row-cols (make-hash-table))) ;; hash of hashes where section => ht { row- => num or col- => num
+ ;; (print "data=")
+ ;; (pp data)
+ (configf:map-all-hier-alist
+ data
+ (lambda (sheetname sectionname varname val)
+ ;; (print "sheetname: " sheetname ", sectionname: " sectionname ", varname: " varname ", val: " val)
+ (let* ((dat (get-dat results sheetname))
+ (vec (refdb:csv-get-svec dat))
+ (rownames (refdb:csv-get-rows dat))
+ (colnames (refdb:csv-get-cols dat))
+ (currrown (hash-table-ref/default rownames varname #f))
+ (currcoln (hash-table-ref/default colnames sectionname #f))
+ (rown (or currrown
+ (let* ((lastn (refdb:csv-get-maxrow dat))
+ (newrown (+ lastn 1)))
+ (refdb:csv-set-maxrow! dat newrown)
+ newrown)))
+ (coln (or currcoln
+ (let* ((lastn (refdb:csv-get-maxcol dat))
+ (newcoln (+ lastn 1)))
+ (refdb:csv-set-maxcol! dat newcoln)
+ newcoln))))
+ (if (not (sparse-array-ref vec 0 coln)) ;; (eq? rown 0)
+ (begin
+ (sparse-array-set! vec 0 coln sectionname)
+ ;; (print "sparse-array-ref " 0 "," coln "=" (sparse-array-ref vec 0 coln))
+ ))
+ (if (not (sparse-array-ref vec rown 0)) ;; (eq? coln 0)
+ (begin
+ (sparse-array-set! vec rown 0 varname)
+ ;; (print "sparse-array-ref " rown "," 0 "=" (sparse-array-ref vec rown 0))
+ ))
+ (if (not currrown)(hash-table-set! rownames varname rown))
+ (if (not currcoln)(hash-table-set! colnames sectionname coln))
+ ;; (print "dat=" dat ", rown=" rown ", coln=" coln)
+ (sparse-array-set! vec rown coln val)
+ ;; (print "sparse-array-ref " rown "," coln "=" (sparse-array-ref vec rown coln))
+ )))
+ (for-each
+ (lambda (sheetname)
+ (let* ((sheetdat (get-dat results sheetname))
+ (svec (refdb:csv-get-svec sheetdat))
+ (maxrow (refdb:csv-get-maxrow sheetdat))
+ (maxcol (refdb:csv-get-maxcol sheetdat))
+ (fname (if out-file
+ (string-substitute "%s" sheetname out-file) ;; "/foo/bar/%s.csv")
+ (conc sheetname ".csv"))))
+ (with-output-to-file fname
+ (lambda ()
+ ;; (print "Sheetname: " sheetname)
+ (let loop ((row 0)
+ (col 0)
+ (curr-row '())
+ (result '()))
+ (let* ((val (sparse-array-ref svec row col))
+ (disp-val (if val
+ (conc "\"" val "\"")
+ "")))
+ (if (> col 0)(display ","))
+ (display disp-val)
+ (cond
+ ((> row maxrow)(display "\n") result)
+ ((>= col maxcol)
+ (display "\n")
+ (loop (+ row 1) 0 '() (append result (list curr-row))))
+ (else
+ (loop row (+ col 1) (append curr-row (list val)) result)))))))))
+ (hash-table-keys results))))
+ ((sqlite3)
+ (let* ((db-file (or out-file (pathname-file input-db)))
+ (db-exists (common:file-exists? db-file))
+ (db (sqlite3:open-database db-file)))
+ (if (not db-exists)(sqlite3:execute db "CREATE TABLE data (sheet,section,var,val);"))
+ (configf:map-all-hier-alist
+ data
+ (lambda (sheetname sectionname varname val)
+ (sqlite3:execute db
+ "INSERT OR REPLACE INTO data (sheet,section,var,val) VALUES (?,?,?,?);"
+ sheetname sectionname varname val)))
+ (sqlite3:finalize! db)))
+ (else
+ (pp data))))))
+ (if out-file (close-output-port out-port))
+ (exit) ;; yes, bending the rules here - need to exit since this is a utility
+ ))
+
+(if (args:get-arg "-ping")
+ (let* ((server-id (string->number (args:get-arg "-ping"))) ;; extract run-id (i.e. no ":"
+ (host:port (args:get-arg "-ping")))
+ (server:ping (or server-id host:port) #f do-exit: #t)))
+
+;;======================================================================
+;; Capture, save and manipulate environments
+;;======================================================================
+
+;; NOTE: Keep these above the section where the server or client code is setup
+
+(let ((envcap (args:get-arg "-envcap")))
+ (if envcap
+ (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
+;;
+(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))
+ (let* ((db (env:open-db (if (null? remargs) "envdat.db" (car remargs))))
+ ;; (resctx (cadr match))
+ ;; (equn (caddr match))
+ (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))
+ (env:close-database db)
+ (set! *didsomething* #t))
+ (debug:print-error 0 *default-log-port* "Parameter to -envdelta should be new=start-end")))))
+
+;;======================================================================
+;; Start the server - can be done in conjunction with -runall or -runtests (one day...)
+;; we start the server if not running else start the client thread
+;;======================================================================
+
+;; Server? Start up here.
+;;
+(if (args:get-arg "-server")
+ (let ((tl (launch:setup))
+ (transport-type (string->symbol (or (args:get-arg "-transport") "http"))))
+ (server:launch 0 transport-type)
+ (set! *didsomething* #t)))
+
+;; The adjutant is a bit different, it does NOT run (launch:setup) as it is not necessarily tied to
+;; a specific Megatest area. Detail are being hashed out and this may change.
+;;
+(if (args:get-arg "-adjutant")
+ (begin
+ (adjutant-run)
+ (set! *didsomething* #t)))
+
+(if (or (args:get-arg "-list-servers")
+ (args:get-arg "-kill-servers"))
+ (let ((tl (launch:setup)))
+ (if tl ;; all roads from here exit
+ (let* ((servers (server:get-list *toppath*))
+ (fmtstr "~8a~22a~20a~20a~8a\n"))
+ (format #t fmtstr "pid" "Interface:port" "age (hms)" "Last mod" "State")
+ (format #t fmtstr "===" "==============" "=========" "========" "=====")
+ (for-each ;; ( mod-time host port start-time pid )
+ (lambda (server)
+ (let* ((mtm (any->number (car server)))
+ (mod (if mtm (- (current-seconds) mtm) "unk"))
+ (age (- (current-seconds)(or (any->number (list-ref server 3)) (current-seconds))))
+ (url (conc (cadr server) ":" (caddr server)))
+ (pid (list-ref server 4))
+ (alv (if (number? mod)(< mod 10) #f)))
+ (format #t
+ fmtstr
+ pid
+ url
+ (seconds->hr-min-sec age)
+ (seconds->hr-min-sec mod)
+ (if alv "alive" "dead"))
+ (if (and alv
+ (args:get-arg "-kill-servers"))
+ (begin
+ (debug:print-info 0 *default-log-port* "Attempting to kill server with pid " pid)
+ (server:kill server)))))
+ (sort servers (lambda (a b)
+ (let ((ma (or (any->number (car a)) 9e9))
+ (mb (or (any->number (car b)) 9e9)))
+ (> ma mb)))))
+ ;; (debug:print-info 1 *default-log-port* "Done with listservers")
+ (set! *didsomething* #t)
+ (exit))
+ (exit))))
+ ;; must do, would have to add checks to many/all calls below
+
+;;======================================================================
+;; Weird special calls that need to run *after* the server has started?
+;;======================================================================
+
+(if (args:get-arg "-list-targets")
+ (if (launch:setup)
+ (let ((targets (common:get-runconfig-targets)))
+ ;; (debug:print 1 *default-log-port* "Found "(length targets) " targets")
+ (case (string->symbol (or (args:get-arg "-dumpmode") "alist"))
+ ((alist)
+ (for-each (lambda (x)
+ ;; (print "[" x "]"))
+ (print x))
+ targets))
+ ((json)
+ (json-write targets))
+ (else
+ (debug:print-error 0 *default-log-port* "dump output format " (args:get-arg "-dumpmode") " not supported for -list-targets")))
+ (set! *didsomething* #t))))
+
+;; cache the runconfigs in $MT_LINKTREE/$MT_TARGET/$MT_RUNNAME/.runconfig
+;;
+(define (full-runconfigs-read)
+;; in the envprocessing branch the below code replaces the further below code
+;; (if (eq? *configstatus* 'fulldata)
+;; *runconfigdat*
+;; (begin
+;; (launch:setup)
+;; *runconfigdat*)))
+
+ (let* ((rundir (if (and (getenv "MT_LINKTREE")(getenv "MT_TARGET")(getenv "MT_RUNNAME"))
+ (conc (getenv "MT_LINKTREE") "/" (getenv "MT_TARGET") "/" (getenv "MT_RUNNAME"))
+ #f))
+ (cfgf (if rundir (conc rundir "/.runconfig." megatest-version "-" megatest-fossil-hash) #f)))
+ (if (and cfgf
+ (common:file-exists? cfgf)
+ (file-write-access? cfgf)
+ (common:use-cache?))
+ (configf:read-alist cfgf)
+ (let* ((keys (rmt:get-keys))
+ (target (common:args-get-target))
+ (key-vals (if target (keys:target->keyval keys target) #f))
+ (sections (if target (list "default" target) #f))
+ (data (begin
+ (setenv "MT_RUN_AREA_HOME" *toppath*)
+ (if key-vals
+ (for-each (lambda (kt)
+ (setenv (car kt) (cadr kt)))
+ key-vals))
+ ;; (read-config (conc *toppath* "/runconfigs.config") #f #t sections: sections))))
+ (runconfig:read (conc *toppath* "/runconfigs.config") target #f))))
+ (if (and rundir ;; have all needed variabless
+ (directory-exists? rundir)
+ (file-write-access? rundir))
+ (begin
+ (if (not (common:in-running-test?))
+ (configf:write-alist data cfgf))
+ ;; force re-read of megatest.config - this resolves circular references between megatest.config
+ (launch:setup force-reread: #t)
+ ;; (launch:cache-config) ;; there are two independent config cache locations, turning this one off for now. MRW.
+ )) ;; we can safely cache megatest.config since we have a valid runconfig
+ data))))
+
+(if (args:get-arg "-show-runconfig")
+ (let ((tl (launch:setup)))
+ (push-directory *toppath*)
+ (let ((data (full-runconfigs-read)))
+ ;; keep this one local
+ (cond
+ ((and (args:get-arg "-section")
+ (args:get-arg "-var"))
+ (let ((val (or (configf:lookup data (args:get-arg "-section")(args:get-arg "-var"))
+ (configf:lookup data "default" (args:get-arg "-var")))))
+ (if val (print val))))
+ ((or (not (args:get-arg "-dumpmode"))
+ (string=? (args:get-arg "-dumpmode") "ini"))
+ (configf:config->ini data))
+ ((string=? (args:get-arg "-dumpmode") "sexp")
+ (pp (hash-table->alist data)))
+ ((string=? (args:get-arg "-dumpmode") "json")
+ (json-write data))
+ (else
+ (debug:print-error 0 *default-log-port* "-dumpmode of " (args:get-arg "-dumpmode") " not recognised")))
+ (set! *didsomething* #t))
+ (pop-directory)))
+
+(if (args:get-arg "-show-config")
+ (let ((tl (launch:setup))
+ (data *configdat*)) ;; (read-config "megatest.config" #f #t)))
+ (push-directory *toppath*)
+ ;; keep this one local
+ (cond
+ ((and (args:get-arg "-section")
+ (args:get-arg "-var"))
+ (let ((val (configf:lookup data (args:get-arg "-section")(args:get-arg "-var"))))
+ (if val (print val))))
+
+ ;; print just a section if only -section
+
+ ((equal? (args:get-arg "-dumpmode") "sexp")
+ (pp (hash-table->alist data)))
+ ((equal? (args:get-arg "-dumpmode") "json")
+ (json-write data))
+ ((or (not (args:get-arg "-dumpmode"))
+ (string=? (args:get-arg "-dumpmode") "ini"))
+ (configf:config->ini data))
+ (else
+ (debug:print-error 0 *default-log-port* "-dumpmode of " (args:get-arg "-dumpmode") " not recognised")))
+ (set! *didsomething* #t)
+ (pop-directory)
+ (set! *time-to-exit* #t)))
+
+(if (args:get-arg "-show-cmdinfo")
+ (if (or (args:get-arg ":value")(getenv "MT_CMDINFO"))
+ (let ((data (common:read-encoded-string (or (args:get-arg ":value")(getenv "MT_CMDINFO")))))
+ (if (equal? (args:get-arg "-dumpmode") "json")
+ (json-write data)
+ (pp data))
+ (set! *didsomething* #t))
+ (debug:print-info 0 *default-log-port* "environment variable MT_CMDINFO is not set")))
+
+;;======================================================================
+;; Remove old run(s)
+;;======================================================================
+
+;; since several actions can be specified on the command line the removal
+;; is done first
+(define (operate-on action #!key (mode #f)(target-in #f)(runname-in #f)(keys-in #f)(keyvals-in #f)) ;; #f is "use default"
+ (let* ((runrec (runs:runrec-make-record))
+ (target (or target-in (common:args-get-target))) ;; eventually get rid of the call to common:args-get-target
+ (runname (or runname-in
+ (args:get-arg "-runname"))) ;; eventually get rid of the get-arg calls
+ (testpatt (or (args:get-arg "-testpatt")
+ (and (eq? action 'archive) ;; if it is an archive command fallback to MT_TEST_NAME and MT_ITEMPATH
+ (common:get-full-test-name))
+ (and (eq? action 'kill-runs)
+ "%/%") ;; I'm just guessing that this is correct :(
+ (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")))
+ ))) ;;
+ (cond
+ ((not target)
+ (debug:print-error 0 *default-log-port* "Missing required parameter for "
+ action ", you must specify -target or -reqtarg")
+ (exit 1))
+ ((not runname)
+ (debug:print-error 0 *default-log-port* "Missing required parameter for "
+ action ", you must specify the run name pattern with -runname patt")
+ (exit 2))
+ ((not testpatt)
+ (debug:print-error 0 *default-log-port* "Missing required parameter for "
+ action ", you must specify the test pattern with -testpatt")
+ (exit 3))
+ (else
+ (if (not (car *configinfo*))
+ (begin
+ (debug:print-error 0 *default-log-port* "Attempted " action "on test(s) but run area config file not found")
+ (exit 1))
+ ;; put test parameters into convenient variables
+ (begin
+ ;; check for correct version, exit with message if not correct
+ (common:exit-on-version-changed)
+ (runs:operate-on action
+ target
+ runname
+ testpatt
+ state: (common:args-get-state)
+ status: (common:args-get-status)
+ new-state-status: (args:get-arg "-set-state-status")
+ mode: mode)))
+ (set! *didsomething* #t)))))
+
+(if (args:get-arg "-kill-runs")
+ (general-run-call
+ "-kill-runs"
+ "kill runs"
+ (lambda (target runname keys keyvals)
+ (operate-on 'kill-runs mode: #f)
+ )))
+
+(if (args:get-arg "-kill-rerun")
+ (let* ((target-patt (common:args-get-target))
+ (runname-patt (args:get-arg "-runname")))
+ (cond ((not target-patt)
+ (debug:print-error 0 *default-log-port* "Missing target, must specify target for -kill-rerun with -target ")
+ (exit 1))
+ ((not runname-patt)
+ (debug:print-error 0 *default-log-port* "Missing runname, must specify runname for -kill-rerun with -runname ")
+ (exit 1))
+ ((string-search "[ ,%]" target-patt)
+ (debug:print-error 0 *default-log-port* "Invalid target ["target-patt"], must specify exact target (no wildcards) for -kill-rerun with -target ")
+ (exit 1))
+ ((string-search "[ ,%]" runname-patt)
+ (debug:print-error 0 *default-log-port* "Invalid runname ["runname-patt"], must specify exact runname (no wildcards) for -kill-rerun with -runname ")
+ (exit 1))
+ (else
+ (general-run-call
+ "-kill-runs"
+ "kill runs"
+ (lambda (target runname keys keyvals)
+ (operate-on 'kill-runs mode: #f)
+ ))
+
+ (thread-sleep! 15))
+ ;; fall thru and let "-run" loop fire
+ )))
+
+
+(if (args:get-arg "-remove-runs")
+ (general-run-call
+ "-remove-runs"
+ "remove runs"
+ (lambda (target runname keys keyvals)
+ (operate-on 'remove-runs mode: (if (args:get-arg "-keep-records")
+ 'remove-data-only
+ 'remove-all)))))
+
+(if (args:get-arg "-remove-keep")
+ (general-run-call
+ "-remove-keep"
+ "remove keep"
+ (lambda (target runname keys keyvals)
+ (let ((actions (map string->symbol
+ (string-split
+ (or (args:get-arg "-actions")
+ "print")
+ ",")))) ;; default to printing the output
+ (runs:remove-all-but-last-n-runs-per-target target runname
+ (string->number (args:get-arg "-remove-keep"))
+ actions: actions)))))
+
+(if (args:get-arg "-set-state-status")
+ (general-run-call
+ "-set-state-status"
+ "set state and status"
+ (lambda (target runname keys keyvals)
+ (operate-on 'set-state-status))))
+
+(if (or (args:get-arg "-set-run-status")
+ (args:get-arg "-get-run-status"))
+ (general-run-call
+ "-set-run-status"
+ "set run status"
+ (lambda (target runname keys keyvals)
+ (let* ((runsdat (rmt:get-runs-by-patt keys runname
+ (common:args-get-target)
+ #f #f #f #f))
+ (header (vector-ref runsdat 0))
+ (rows (vector-ref runsdat 1)))
+ (if (null? rows)
+ (begin
+ (debug:print-info 0 *default-log-port* "No matching run found.")
+ (exit 1))
+ (let* ((row (car (vector-ref runsdat 1)))
+ (run-id (db:get-value-by-header row header "id")))
+ (if (args:get-arg "-set-run-status")
+ (rmt:set-run-status run-id (args:get-arg "-set-run-status") msg: (args:get-arg "-m"))
+ (print (rmt:get-run-status run-id))
+ )))))))
+
+;;======================================================================
+;; Query runs
+;;======================================================================
+
+;; -fields runs:id,target,runname,comment+tests:id,testname,item_path+steps
+;;
+;; csi> (extract-fields-constraints "runs:id,target,runname,comment+tests:id,testname,item_path+steps")
+;; => (("runs" "id" "target" "runname" "comment") ("tests" "id" "testname" "item_path") ("steps"))
+;;
+;; NOTE: remember that the cdr will be the list you expect (cdr ("runs" "id" "target" "runname" "comment")) => ("id" "target" "runname" "comment")
+;; and so alist-ref will yield what you expect
+;;
+(define (extract-fields-constraints fields-spec)
+ (map (lambda (table-spec) ;; runs:id,target,runname
+ (let ((dat (string-split table-spec ":"))) ;; ("runs" "id,target,runname")
+ (if (> (length dat) 1)
+ (cons (car dat)(string-split (cadr dat) ",")) ;; "id,target,runname"
+ dat)))
+ (string-split fields-spec "+")))
+
+(define (get-value-by-fieldname datavec test-field-index fieldname)
+ (let ((indx (hash-table-ref/default test-field-index fieldname #f)))
+ (if indx
+ (if (>= indx (vector-length datavec))
+ #f ;; index too high, should raise an error I suppose
+ (vector-ref datavec indx))
+ #f)))
+
+
+
+
+
+(when (args:get-arg "-testdata-csv")
+ (if (launch:setup)
+ (let* ((keys (rmt:get-keys)) ;; (db:get-keys dbstruct))
+ (runpatt (or (args:get-arg "-runname") "%"))
+ (testpatt (common:args-get-testpatt #f))
+ (datapatt (args:get-arg "-testdata-csv"))
+ (match-data (string-match "^([^/]+)/(.*)" (args:get-arg "-testdata-csv")))
+ (categorypatt (if match-data (list-ref match-data 1) "%"))
+ (setvarpatt (if match-data
+ (list-ref match-data 2)
+ (args:get-arg "-testdata-csv")))
+ (runsdat (rmt:get-runs-by-patt keys (or runpatt "%")
+ (common:args-get-target) #f #f '("id" "runname" "state" "status" "owner" "event_time" "comment") 0))
+ (header (db:get-header runsdat))
+ (access-mode (db:get-access-mode))
+ (testpatt (common:args-get-testpatt #f))
+ (fields-spec (if (args:get-arg "-fields")
+ (extract-fields-constraints (args:get-arg "-fields"))
+ (list (cons "runs" (append keys (list "id" "runname" "state" "status" "owner" "event_time" "comment" "fail_count" "pass_count")))
+ (cons "tests" db:test-record-fields) ;; "id" "testname" "test_path")
+ (list "steps" "id" "stepname"))))
+ (tests-spec (let ((t (alist-ref "tests" fields-spec equal?)))
+ (if (and t (null? t)) ;; all fields
+ db:test-record-fields
+ t)))
+ (adj-tests-spec (delete-duplicates (if tests-spec (cons "id" tests-spec) db:test-record-fields)))
+ (test-field-index (make-hash-table))
+ (runs (db:get-rows runsdat))
+ )
+ (if (and tests-spec (not (null? tests-spec))) ;; do some validation and processing of the test-spec
+ (let ((invalid-tests-spec (filter (lambda (x)(not (member x db:test-record-fields))) tests-spec)))
+ (if (null? invalid-tests-spec)
+ ;; generate the lookup map test-field-name => index-number
+ (let loop ((hed (car adj-tests-spec))
+ (tal (cdr adj-tests-spec))
+ (idx 0))
+ (hash-table-set! test-field-index hed idx)
+ (if (not (null? tal))(loop (car tal)(cdr tal)(+ idx 1))))
+ (begin
+ (debug:print-error 0 *default-log-port* "Invalid test fields specified: " (string-intersperse invalid-tests-spec ", "))
+ (exit)))))
+ (let* ((table-header (string-split "target,run,test,itempath,category,var,value,comment" ","))
+ (table-rows
+ (apply append (map
+ (lambda (run)
+ (let* ((target (string-intersperse (map (lambda (x)
+ (db:get-value-by-header run header x))
+ keys) "/"))
+ (statuses (string-split (or (args:get-arg "-status") "") ","))
+ (run-id (db:get-value-by-header run header "id"))
+ (runname (db:get-value-by-header run header "runname"))
+ (states (string-split (or (args:get-arg "-state") "") ","))
+ (tests (if tests-spec
+ (rmt:get-tests-for-run run-id testpatt states statuses #f #f #f 'testname 'asc ;; (db:get-tests-for-run dbstruct run-id testpatt '() '() #f #f #f 'testname 'asc
+ ;; use qryvals if test-spec provided
+ (if tests-spec
+ (string-intersperse adj-tests-spec ",")
+ ;; db:test-record-fields
+ #f)
+ #f
+ 'normal)
+ '())))
+ (apply append
+ (map
+ (lambda (test)
+ (let* (
+ (test-id (if (member "id" tests-spec)(get-value-by-fieldname test test-field-index "id" ) #f)) ;; (db:test-get-id test))
+ (testname (if (member "testname" tests-spec)(get-value-by-fieldname test test-field-index "testname" ) #f)) ;; (db:test-get-testname test))
+ (itempath (if (member "item_path" tests-spec)(get-value-by-fieldname test test-field-index "item_path" ) #f)) ;; (db:test-get-item-path test))
+ (fullname (conc testname
+ (if (equal? itempath "")
+ ""
+ (conc "/" itempath ))))
+ (testdat-raw (map vector->list (rmt:read-test-data-varpatt run-id test-id categorypatt setvarpatt)))
+ (testdat (filter
+ (lambda (x)
+ (not (equal? "logpro"
+ (list-ref x 10))))
+ testdat-raw)))
+ (map
+ (lambda (item)
+ (receive (id test_id category
+ variable value expected
+ tol units comment status type)
+ (apply values item)
+ (list target runname testname itempath category variable value comment)))
+ testdat)))
+ tests))))
+ runs))))
+ (print (string-join table-header ","))
+ (for-each (lambda(table-row)
+ (print (string-join (map ->string table-row) ",")))
+
+
+ table-rows))))
+ (set! *didsomething* #t)
+ (set! *time-to-exit* #t))
+
+
+
+;; NOTE: list-runs and list-db-targets operate on local db!!!
+;;
+;; IDEA: megatest list -runname blah% ...
+;;
+(if (or (args:get-arg "-list-runs")
+ (args:get-arg "-list-db-targets"))
+ (if (launch:setup)
+ (let* (;; (dbstruct (make-dbr:dbstruct path: *toppath* local: (args:get-arg "-local")))
+ (runpatt (args:get-arg "-list-runs"))
+ (access-mode (db:get-access-mode))
+ (testpatt (common:args-get-testpatt #f))
+ ;; (if (args:get-arg "-testpatt")
+ ;; (args:get-arg "-testpatt")
+ ;; "%"))
+ (keys (rmt:get-keys)) ;; (db:get-keys dbstruct))
+ ;; (runsdat (db:get-runs dbstruct runpatt #f #f '()))
+ ;; (runsdat (rmt:get-runs-by-patt keys (or runpatt "%") (common:args-get-target) ;; (db:get-runs-by-patt dbstruct keys (or runpatt "%") (common:args-get-target)
+ ;; #f #f '("id" "runname" "state" "status" "owner" "event_time" "comment") 0))
+ (runsdat (rmt:get-runs-by-patt keys (or runpatt "%")
+ (common:args-get-target) #f #f '("id" "runname" "state" "status" "owner" "event_time" "comment") 0))
+ (runstmp (db:get-rows runsdat))
+ (header (db:get-header runsdat))
+ ;; this is "-since" support. This looks at last mod times of .db files
+ ;; and collects those modified since the -since time.
+ (runs runstmp)
+ ;; (if (and (not (null? runstmp))
+ ;; (args:get-arg "-since"))
+ ;; (let ((changed-ids (db:get-changed-run-ids (string->number (args:get-arg "-since")))))
+ ;; (let loop ((hed (car runstmp))
+ ;; (tal (cdr runstmp))
+ ;; (res '()))
+ ;; (let ((new-res (if (member (db:get-value-by-header hed header "id") changed-ids)
+ ;; (cons hed res)
+ ;; res)))
+ ;; (if (null? tal)
+ ;; (reverse new-res)
+ ;; (loop (car tal)(cdr tal) new-res)))))
+ ;; runstmp))
+ (db-targets (args:get-arg "-list-db-targets"))
+ (seen (make-hash-table))
+ (dmode (let ((d (args:get-arg "-dumpmode"))) ;; json, sexpr
+ (if d (string->symbol d) #f)))
+ (data (make-hash-table))
+ (fields-spec (if (args:get-arg "-fields")
+ (extract-fields-constraints (args:get-arg "-fields"))
+ (list (cons "runs" (append keys (list "id" "runname" "state" "status" "owner" "event_time" "comment" "fail_count" "pass_count")))
+ (cons "tests" db:test-record-fields) ;; "id" "testname" "test_path")
+ (list "steps" "id" "stepname"))))
+ (runs-spec (let ((r (alist-ref "runs" fields-spec equal?))) ;; the check is now unnecessary
+ (if (and r (not (null? r))) r (list "id" ))))
+ (tests-spec (let ((t (alist-ref "tests" fields-spec equal?)))
+ (if (and t (null? t)) ;; all fields
+ db:test-record-fields
+ t)))
+ (adj-tests-spec (delete-duplicates (if tests-spec (cons "id" tests-spec) db:test-record-fields))) ;; '("id"))))
+ (steps-spec (alist-ref "steps" fields-spec equal?))
+ (test-field-index (make-hash-table)))
+ (if (and tests-spec (not (null? tests-spec))) ;; do some validation and processing of the test-spec
+ (let ((invalid-tests-spec (filter (lambda (x)(not (member x db:test-record-fields))) tests-spec)))
+ (if (null? invalid-tests-spec)
+ ;; generate the lookup map test-field-name => index-number
+ (let loop ((hed (car adj-tests-spec))
+ (tal (cdr adj-tests-spec))
+ (idx 0))
+ (hash-table-set! test-field-index hed idx)
+ (if (not (null? tal))(loop (car tal)(cdr tal)(+ idx 1))))
+ (begin
+ (debug:print-error 0 *default-log-port* "Invalid test fields specified: " (string-intersperse invalid-tests-spec ", "))
+ (exit)))))
+ ;; Each run
+ (for-each
+ (lambda (run)
+ (let ((targetstr (string-intersperse (map (lambda (x)
+ (db:get-value-by-header run header x))
+ keys) "/")))
+ (if db-targets
+ (if (not (hash-table-ref/default seen targetstr #f))
+ (begin
+ (hash-table-set! seen targetstr #t)
+ ;; (print "[" targetstr "]"))))
+ (if (not dmode)
+ (print targetstr)
+ (hash-table-set! data "targets" (cons targetstr (hash-table-ref/default data "targets" '())))
+ )))
+ (let* ((run-id (db:get-value-by-header run header "id"))
+ (runname (db:get-value-by-header run header "runname"))
+ (states (string-split (or (args:get-arg "-state") "") ","))
+ (statuses (string-split (or (args:get-arg "-status") "") ","))
+ (tests (if tests-spec
+ (rmt:get-tests-for-run run-id testpatt states statuses #f #f #f 'testname 'asc ;; (db:get-tests-for-run dbstruct run-id testpatt '() '() #f #f #f 'testname 'asc
+ ;; use qryvals if test-spec provided
+ (if tests-spec
+ (string-intersperse adj-tests-spec ",")
+ ;; db:test-record-fields
+ #f)
+ #f
+ 'normal)
+ '())))
+ (case dmode
+ ((json ods sexpr)
+ (if runs-spec
+ (for-each
+ (lambda (field-name)
+ (mutils:hierhash-set! data (conc (db:get-value-by-header run header field-name)) targetstr runname "meta" field-name))
+ runs-spec)))
+ ;; (mutils:hierhash-set! data (db:get-value-by-header run header "status") targetstr runname "meta" "status" )
+ ;; (mutils:hierhash-set! data (db:get-value-by-header run header "state") targetstr runname "meta" "state" )
+ ;; (mutils:hierhash-set! data (conc (db:get-value-by-header run header "id")) targetstr runname "meta" "id" )
+ ;; (mutils:hierhash-set! data (db:get-value-by-header run header "event_time") targetstr runname "meta" "event_time" )
+ ;; (mutils:hierhash-set! data (db:get-value-by-header run header "comment") targetstr runname "meta" "comment" )
+ ;; ;; add last entry twice - seems to be a bug in hierhash?
+ ;; (mutils:hierhash-set! data (db:get-value-by-header run header "comment") targetstr runname "meta" "comment" )
+ (else
+ (if (null? runs-spec)
+ (print "Run: " targetstr "/" runname
+ " status: " (db:get-value-by-header run header "state")
+ " run-id: " run-id ", number tests: " (length tests)
+ " event_time: " (db:get-value-by-header run header "event_time"))
+ (begin
+ (if (not (member "target" runs-spec))
+ ;; (display (conc "Target: " targetstr))
+ (display (conc "Run: " targetstr "/" runname " ")))
+ (for-each
+ (lambda (field-name)
+ (if (equal? field-name "target")
+ (display (conc "target: " targetstr " "))
+ (display (conc field-name ": " (db:get-value-by-header run header (conc field-name)) " "))))
+ runs-spec)
+ (newline)))))
+
+ (for-each
+ (lambda (test)
+ (common:debug-handle-exceptions #f
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* "Bad data in test record? " test)
+ (debug:print-error 5 *default-log-port* "exn=" (condition->list exn))
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (print-call-chain (current-error-port)))
+ (let* ((test-id (if (member "id" tests-spec)(get-value-by-fieldname test test-field-index "id" ) #f)) ;; (db:test-get-id test))
+ (testname (if (member "testname" tests-spec)(get-value-by-fieldname test test-field-index "testname" ) #f)) ;; (db:test-get-testname test))
+ (itempath (if (member "item_path" tests-spec)(get-value-by-fieldname test test-field-index "item_path" ) #f)) ;; (db:test-get-item-path test))
+ (comment (if (member "comment" tests-spec)(get-value-by-fieldname test test-field-index "comment" ) #f)) ;; (db:test-get-comment test))
+ (tstate (if (member "state" tests-spec)(get-value-by-fieldname test test-field-index "state" ) #f)) ;; (db:test-get-state test))
+ (tstatus (if (member "status" tests-spec)(get-value-by-fieldname test test-field-index "status" ) #f)) ;; (db:test-get-status test))
+ (event-time (if (member "event_time" tests-spec)(get-value-by-fieldname test test-field-index "event_time" ) #f)) ;; (db:test-get-event_time test))
+ (rundir (if (member "rundir" tests-spec)(get-value-by-fieldname test test-field-index "rundir" ) #f)) ;; (db:test-get-rundir test))
+ (final_logf (if (member "final_logf" tests-spec)(get-value-by-fieldname test test-field-index "final_logf" ) #f)) ;; (db:test-get-final_logf test))
+ (run_duration (if (member "run_duration" tests-spec)(get-value-by-fieldname test test-field-index "run_duration") #f)) ;; (db:test-get-run_duration test))
+ (fullname (conc testname
+ (if (equal? itempath "")
+ ""
+ (conc "(" itempath ")")))))
+ (case dmode
+ ((json ods sexpr)
+ (if tests-spec
+ (for-each
+ (lambda (field-name)
+ (mutils:hierhash-set! data (get-value-by-fieldname test test-field-index field-name) targetstr runname "data" (conc test-id) field-name))
+ tests-spec)))
+ ;; ;; (mutils:hierhash-set! data fullname targetstr runname "data" (conc test-id) "tname" )
+ ;; (mutils:hierhash-set! data testname targetstr runname "data" (conc test-id) "testname" )
+ ;; (mutils:hierhash-set! data itempath targetstr runname "data" (conc test-id) "itempath" )
+ ;; (mutils:hierhash-set! data comment targetstr runname "data" (conc test-id) "comment" )
+ ;; (mutils:hierhash-set! data tstate targetstr runname "data" (conc test-id) "state" )
+ ;; (mutils:hierhash-set! data tstatus targetstr runname "data" (conc test-id) "status" )
+ ;; (mutils:hierhash-set! data rundir targetstr runname "data" (conc test-id) "rundir" )
+ ;; (mutils:hierhash-set! data final_logf targetstr runname "data" (conc test-id) "final_logf")
+ ;; (mutils:hierhash-set! data run_duration targetstr runname "data" (conc test-id) "run_duration")
+ ;; (mutils:hierhash-set! data event-time targetstr runname "data" (conc test-id) "event_time")
+ ;; ;; add last entry twice - seems to be a bug in hierhash?
+ ;; (mutils:hierhash-set! data event-time targetstr runname "data" (conc test-id) "event_time")
+ ;; )
+ (else
+ (if (and tstate tstatus event-time)
+ (format #t
+ " Test: ~25a State: ~15a Status: ~15a Runtime: ~5@as Time: ~22a Host: ~10a\n"
+ (if fullname fullname "")
+ (if tstate tstate "")
+ (if tstatus tstatus "")
+ (get-value-by-fieldname test test-field-index "run_duration");;(if test (db:test-get-run_duration test) "")
+ (if event-time event-time "")
+ (get-value-by-fieldname test test-field-index "host")) ;;(if test (db:test-get-host test)) "")
+ (print " Test: " fullname
+ (if tstate (conc " State: " tstate) "")
+ (if tstatus (conc " Status: " tstatus) "")
+ (if (get-value-by-fieldname test test-field-index "run_duration")
+ (conc " Runtime: " (get-value-by-fieldname test test-field-index "run_duration"))
+ "")
+ (if event-time (conc " Time: " event-time) "")
+ (if (get-value-by-fieldname test test-field-index "host")
+ (conc " Host: " (get-value-by-fieldname test test-field-index "host"))
+ "")))
+ (if (not (or (equal? (get-value-by-fieldname test test-field-index "status") "PASS")
+ (equal? (get-value-by-fieldname test test-field-index "status") "WARN")
+ (equal? (get-value-by-fieldname test test-field-index "state") "NOT_STARTED")))
+ (begin
+ (print (if (get-value-by-fieldname test test-field-index "cpuload")
+ (conc " cpuload: " (get-value-by-fieldname test test-field-index "cpuload"))
+ "") ;; (db:test-get-cpuload test)
+ (if (get-value-by-fieldname test test-field-index "diskfree")
+ (conc "\n diskfree: " (get-value-by-fieldname test test-field-index "diskfree")) ;; (db:test-get-diskfree test)
+ "")
+ (if (get-value-by-fieldname test test-field-index "uname")
+ (conc "\n uname: " (get-value-by-fieldname test test-field-index "uname")) ;; (db:test-get-uname test)
+ "")
+ (if (get-value-by-fieldname test test-field-index "rundir")
+ (conc "\n rundir: " (get-value-by-fieldname test test-field-index "rundir")) ;; (db:test-get-rundir test)
+ "")
+;; "\n rundir: " (get-value-by-fieldname test test-field-index "") ;; (sdb:qry 'getstr ;; (filedb:get-path *fdb*
+;; (db:test-get-rundir test) ;; )
+ )
+ ;; Each test
+ ;; DO NOT remote run
+ (let ((steps (rmt:get-steps-for-test run-id (db:test-get-id test)))) ;; (db:get-steps-for-test dbstruct run-id (db:test-get-id test))))
+ (for-each
+ (lambda (step)
+ (format #t
+ " Step: ~20a State: ~10a Status: ~10a Time ~22a\n"
+ (tdb:step-get-stepname step)
+ (tdb:step-get-state step)
+ (tdb:step-get-status step)
+ (tdb:step-get-event_time step)))
+ steps)))))))))
+ (if (args:get-arg "-sort")
+ (sort tests
+ (lambda (a-test b-test)
+ (let* ((key (args:get-arg "-sort"))
+ (first (get-value-by-fieldname a-test test-field-index key))
+ (second (get-value-by-fieldname b-test test-field-index key)))
+ ((cond
+ ((and (number? first)(number? second)) <)
+ ((and (string? first)(string? second)) string<=?)
+ (else equal?))
+ first second))))
+ tests))))))
+ runs)
+ (case dmode
+ ((json) (json-write data))
+ ((sexpr) (pp (common:to-alist data))))
+ (let* ((metadat-fields (delete-duplicates
+ (append keys '( "runname" "time" "owner" "pass_count" "fail_count" "state" "status" "comment" "id"))))
+ (run-fields '(
+ "testname"
+ "item_path"
+ "state"
+ "status"
+ "comment"
+ "event_time"
+ "host"
+ "run_id"
+ "run_duration"
+ "attemptnum"
+ "id"
+ "archived"
+ "diskfree"
+ "cpuload"
+ "final_logf"
+ "shortdir"
+ "rundir"
+ "uname"
+ )
+ )
+ (newdat (common:to-alist data))
+ (allrundat (if (null? newdat)
+ '()
+ (car (map cdr newdat)))) ;; (car (map cdr (car (map cdr newdat)))))
+ (runs (append
+ (list "runs" ;; sheetname
+ metadat-fields)
+ (map (lambda (run)
+ ;; (print "run: " run)
+ (let* ((runname (car run))
+ (rundat (cdr run))
+ (metadat (let ((tmp (assoc "meta" rundat)))
+ (if tmp (cdr tmp) #f))))
+ ;; (print "runname: " runname "\n\nrundat: " )(pp rundat)(print "\n\nmetadat: ")(pp metadat)
+ (if metadat
+ (map (lambda (field)
+ (let ((tmp (assoc field metadat)))
+ (if tmp (cdr tmp) "")))
+ metadat-fields)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: meta data for run " runname " not found")
+ '()))))
+ allrundat)))
+ ;; '( ( "target" ( "runname" ( "data" ( "runid" ( "id . "37" ) ( ... ))))
+ (run-pages (map (lambda (targdat)
+ (let* ((target (car targdat))
+ (runsdat (cdr targdat)))
+ (if runsdat
+ (map (lambda (rundat)
+ (let* ((runname (car rundat))
+ (rundat (cdr rundat))
+ (testsdat (let ((tmp (assoc "data" rundat)))
+ (if tmp (cdr tmp) #f))))
+ (if testsdat
+ (let ((tests (map (lambda (test)
+ (let* ((test-id (car test))
+ (test-dat (cdr test)))
+ (map (lambda (field)
+ (let ((tmp (assoc field test-dat)))
+ (if tmp (cdr tmp) "")))
+ run-fields)))
+ testsdat)))
+ ;; (print "Target: " target "/" runname " tests:")
+ ;; (pp tests)
+ (cons (conc target "/" runname)
+ (cons (list (conc target "/" runname))
+ (cons '()
+ (cons run-fields tests)))))
+ (begin
+ (debug:print 4 *default-log-port* "WARNING: run " target "/" runname " appears to have no data")
+ ;; (pp rundat)
+ '()))))
+ runsdat)
+ '())))
+ newdat)) ;; we use newdat to get target
+ (sheets (filter (lambda (x)
+ (not (null? x)))
+ (cons runs (map car run-pages)))))
+ ;; (print "allrundat:")
+ ;; (pp allrundat)
+ ;; (print "runs:")
+ ;; (pp runs)
+ ;(print "sheets: ")
+ ;; (pp sheets)
+ (if (eq? dmode 'ods)
+ (let* ((tempdir (conc "/tmp/" (current-user-name) "/" (random 10000) "_" (current-process-id)))
+ (outputfile (or (args:get-arg "-o") "out.ods"))
+ (ouf (if (string-match (regexp "^[/~]+.*") outputfile) ;; full path?
+ outputfile
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: path given, " outputfile " is relative, prefixing with current directory")
+ (conc (current-directory) "/" outputfile)))))
+ (create-directory tempdir #t)
+ (ods:list->ods tempdir ouf sheets))))
+ ;; (system (conc "rm -rf " tempdir))
+ (set! *didsomething* #t)
+ (set! *time-to-exit* #t)
+ ) ;; end if true branch (end of a let)
+ ) ;; end if
+ ) ;; end if -list-runs
+
+;; list-waivers
+(if (and (args:get-arg "-list-waivers")
+ (launch:setup))
+ (let* ((runpatt (or (args:get-arg "-runname") "%"))
+ (testpatt (common:args-get-testpatt #f))
+ (keys (rmt:get-keys))
+ (runsdat (rmt:get-runs-by-patt
+ keys runpatt
+ (common:args-get-target) #f #f
+ '("id" "runname" "state" "status" "owner" "event_time" "comment") 0))
+ (runs (db:get-rows runsdat))
+ (header (db:get-header runsdat))
+ (results (make-hash-table)) ;; [target] ( (testname/itempath . "comment") ... )
+ (addtest (lambda (target testname itempath comment)
+ (hash-table-set! results target (cons (cons (conc testname "/" itempath) comment)
+ (hash-table-ref/default results target '())))))
+ (last-target #f))
+ (for-each
+ (lambda (run)
+ (let* ((run-id (db:get-value-by-header run header "id"))
+ (target (rmt:get-target run-id))
+ (runname (db:get-value-by-header run header "runname"))
+ (tests (rmt:get-tests-for-run
+ run-id testpatt '("COMPLETED") '("WAIVED") #f #f #f 'testname 'asc ;; use qryvals if test-spec provided
+ #f #f #f)))
+ (if (not (equal? target last-target))
+ (print "[" target "]"))
+ (set! last-target target)
+ (print "# " runname)
+ (for-each
+ (lambda (testdat)
+ (let* ((testfullname (conc (db:test-get-testname testdat)
+ (if (equal? "" (db:test-get-item-path testdat))
+ ""
+ (conc "/" (db:test-get-item-path testdat)))
+ )))
+ (print testfullname " " (db:test-get-comment testdat))))
+ tests)))
+ runs)
+ (set! *didsomething* #t)))
+
+;;======================================================================
+;; full run
+;;======================================================================
+
+(define (handle-run-requests target runname keys keyvals need-clean)
+ (if (or (args:get-arg "-kill-rerun") (args:get-arg "-rerun-clean")) ;; first set states/statuses correct
+ ;; For rerun-clean do we or do we not support the testpatt?
+ (let ((states (or (configf:lookup *configdat* "validvalues" "cleanrerun-states")
+ "KILLREQ,KILLED,UNKNOWN,INCOMPLETE,STUCK,NOT_STARTED"))
+ (statuses (or (configf:lookup *configdat* "validvalues" "cleanrerun-statuses")
+ "FAIL,INCOMPLETE,ABORT,CHECK,DEAD,PREQ_FAIL,PREQ_DISCARDED")))
+ (hash-table-set! args:arg-hash "-preclean" #t)
+ (runs:operate-on 'set-state-status
+ target
+ (common:args-get-runname) ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
+ ;; "%" ;; (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
+ (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
+ state: states
+ ;; status: statuses
+ new-state-status: "NOT_STARTED,n/a")
+ (runs:clean-cache target runname *toppath*)
+ (runs:operate-on 'set-state-status
+ target
+ (common:args-get-runname) ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
+ ;; "%" ;; (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
+ (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
+ ;; state: states
+ status: statuses
+ new-state-status: "NOT_STARTED,n/a")))
+ ;; RERUN ALL
+ (if (args:get-arg "-rerun-all") ;; first set states/statuses correct
+ (let* ((rconfig (full-runconfigs-read)))
+ (hash-table-set! args:arg-hash "-preclean" #t)
+ (runs:operate-on 'set-state-status
+ target
+ (common:args-get-runname) ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
+ (common:args-get-testpatt rconfig) ;; (args:get-arg "-testpatt")
+ state: #f
+ ;; status: statuses
+ new-state-status: "NOT_STARTED,n/a")
+ (runs:clean-cache target runname *toppath*)
+ (runs:operate-on 'set-state-status
+ target
+ (common:args-get-runname) ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
+ (common:args-get-testpatt rconfig) ;; (args:get-arg "-testpatt")
+ ;; state: states
+ status: #f
+ new-state-status: "NOT_STARTED,n/a")))
+ (let* ((config-reruns (let ((x (configf:lookup *configdat* "setup" "reruns")))
+ (if x (string->number x) #f)))
+ (rerun-cnt (if config-reruns
+ config-reruns
+ 1)))
+
+ (runs:run-tests target
+ runname
+ #f ;; (common:args-get-testpatt #f)
+ ;; (or (args:get-arg "-testpatt")
+ ;; "%")
+ user
+ args:arg-hash
+ run-count: rerun-cnt)))
+
+;; get lock in db for full run for this directory
+;; for all tests with deps
+;; walk tree of tests to find head tasks
+;; add head tasks to task queue
+;; add dependant tasks to task queue
+;; add remaining tasks to task queue
+;; for each task in task queue
+;; if have adequate resources
+;; launch task
+;; else
+;; put task in deferred queue
+;; if still ok to run tasks
+;; process deferred tasks per above steps
+
+;; run all tests are are Not COMPLETED and PASS or CHECK
+(if (or (args:get-arg "-runall")
+ (args:get-arg "-run")
+ (args:get-arg "-rerun-clean")
+ (args:get-arg "-rerun-all")
+ (args:get-arg "-runtests")
+ (args:get-arg "-kill-rerun"))
+ (let ((need-clean (or (args:get-arg "-rerun-clean")
+ (args:get-arg "-rerun-all")))
+ (orig-cmdline (string-intersperse (argv) " ")))
+ (general-run-call
+ "-runall"
+ "run all tests"
+ (lambda (target runname keys keyvals)
+ (if (or (string-search "%" target)
+ (string-search "%" runname)) ;; we are being asked to re-run multiple runs
+ (let* ((run-specs (rmt:simple-get-runs runname #f #f target #f))) ;; list of simple-run records
+ (debug:print-info 0 *default-log-port* "Pattern supplied for target or runname with "
+ (length run-specs) " matches round. Running each in turn.")
+ (if (null? run-specs)
+ (debug:print 0 *default-log-port* "WARNING: No runs match target " target " and runname " runname))
+ (for-each (lambda (spec)
+ (let* ((precmd (if (args:get-arg "-precmd")(conc (args:get-arg "-precmd") " ") ""))
+ (newcmdline (conc
+ precmd
+ (string-substitute
+ (conc "target " target)
+ (conc "target " (simple-run-target spec))
+ (string-substitute
+ (conc "runname " runname)
+ (conc "runname " (simple-run-runname spec))
+ orig-cmdline)))))
+ (debug:print 0 *default-log-port* "ORIG: " orig-cmdline)
+ (debug:print 0 *default-log-port* "NEW: " newcmdline)
+ (system newcmdline)))
+ run-specs))
+ (handle-run-requests target runname keys keyvals need-clean))))))
+
+;;======================================================================
+;; run one test
+;;======================================================================
+
+;; 1. find the config file
+;; 2. change to the test directory
+;; 3. update the db with "test started" status, set running host
+;; 4. process launch the test
+;; - monitor the process, update stats in the db every 2^n minutes
+;; 5. as the test proceeds internally it calls megatest as each step is
+;; started and completed
+;; - step started, timestamp
+;; - step completed, exit status, timestamp
+;; 6. test phone home
+;; - if test run time > allowed run time then kill job
+;; - if cannot access db > allowed disconnect time then kill job
+
+;; == duplicated == (if (or (args:get-arg "-run")(args:get-arg "-runtests"))
+;; == duplicated == (general-run-call
+;; == duplicated == "-runtests"
+;; == duplicated == "run a test"
+;; == duplicated == (lambda (target runname keys keyvals)
+;; == duplicated == ;;
+;; == duplicated == ;; May or may not implement it this way ...
+;; == duplicated == ;;
+;; == duplicated == ;; Insert this run into the tasks queue
+;; == duplicated == ;; (open-run-close tasks:add tasks:open-db
+;; == duplicated == ;; "runtests"
+;; == duplicated == ;; user
+;; == duplicated == ;; target
+;; == duplicated == ;; runname
+;; == duplicated == ;; (args:get-arg "-runtests")
+;; == duplicated == ;; #f))))
+;; == duplicated == (runs:run-tests target
+;; == duplicated == runname
+;; == duplicated == (common:args-get-testpatt #f) ;; (args:get-arg "-runtests")
+;; == duplicated == user
+;; == duplicated == args:arg-hash))))
+
+;;======================================================================
+;; Rollup into a run
+;;======================================================================
+
+(if (args:get-arg "-rollup")
+ (general-run-call
+ "-rollup"
+ "rollup tests"
+ (lambda (target runname keys keyvals)
+ (runs:rollup-run keys
+ keyvals
+ (or (args:get-arg "-runname")(args:get-arg ":runname") )
+ user))))
+
+;;======================================================================
+;; Lock or unlock a run
+;;======================================================================
+
+(if (or (args:get-arg "-lock")(args:get-arg "-unlock"))
+ (general-run-call
+ (if (args:get-arg "-lock") "-lock" "-unlock")
+ "lock/unlock tests"
+ (lambda (target runname keys keyvals)
+ (runs:handle-locking
+ target
+ keys
+ (or (args:get-arg "-runname")(args:get-arg ":runname") )
+ (args:get-arg "-lock")
+ (args:get-arg "-unlock")
+ user))))
+
+;;======================================================================
+;; Get paths to tests
+;;======================================================================
+;; Get test paths matching target, runname, and testpatt
+(if (or (args:get-arg "-test-files")(args:get-arg "-test-paths"))
+ ;; if we are in a test use the MT_CMDINFO data
+ (if (getenv "MT_CMDINFO")
+ (let* ((startingdir (current-directory))
+ (cmdinfo (common:read-encoded-string (getenv "MT_CMDINFO")))
+ (transport (assoc/default 'transport cmdinfo))
+ (testpath (assoc/default 'testpath cmdinfo))
+ (test-name (assoc/default 'test-name cmdinfo))
+ (runscript (assoc/default 'runscript cmdinfo))
+ (db-host (assoc/default 'db-host cmdinfo))
+ (run-id (assoc/default 'run-id cmdinfo))
+ (itemdat (assoc/default 'itemdat cmdinfo))
+ (state (args:get-arg ":state"))
+ (status (args:get-arg ":status"))
+ ;;(target (args:get-arg "-target"))
+ (target (common:args-get-target))
+ (toppath (assoc/default 'toppath cmdinfo)))
+ (change-directory toppath)
+ (if (not target)
+ (begin
+ (debug:print-error 0 *default-log-port* "-target is required.")
+ (exit 1)))
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, giving up on -test-paths or -test-files, exiting")
+ (exit 1)))
+ (let* ((keys (rmt:get-keys))
+ ;; db:test-get-paths must not be run remote
+ (paths (tests:test-get-paths-matching keys target (args:get-arg "-test-files"))))
+ (set! *didsomething* #t)
+ (for-each (lambda (path)
+ (if (common:file-exists? path)
+ (print path)))
+ paths)))
+ ;; else do a general-run-call
+ (general-run-call
+ "-test-files"
+ "Get paths to test"
+ (lambda (target runname keys keyvals)
+ (let* ((db #f)
+ ;; DO NOT run remote
+ (paths (tests:test-get-paths-matching keys target (args:get-arg "-test-files"))))
+ (for-each (lambda (path)
+ (print path))
+ paths))))))
+
+;;======================================================================
+;; Archive tests
+;;======================================================================
+;; Archive tests matching target, runname, and testpatt
+(if (equal? (args:get-arg "-archive") "replicate-db")
+ (begin
+ ;; check if source
+ ;; check if megatest.db exist
+ (launch:setup)
+ (if (not (args:get-arg "-source"))
+ (begin
+ (debug:print-info 1 *default-log-port* "Missing required argument -source ")
+ (exit 1)))
+ (if (common:file-exists? (conc *toppath* "/megatest.db"))
+ (begin
+ (debug:print-info 1 *default-log-port* "File " (conc *toppath* "/megatest.db") " already exists. Please remove it before trying to replicate db")
+ (exit 1)))
+ (if (and (common:get-db-tmp-area) (> (length (directory (common:get-db-tmp-area) #f)) 0))
+ (begin
+ (debug:print-info 1 *default-log-port* (common:get-db-tmp-area) " not empty. Please remove it before trying to replicate db")
+ (exit 1)))
+ ;; check if timestamp
+ (let* ((source (args:get-arg "-source"))
+ (src (if (not (equal? (substring source 0 1) "/"))
+ (conc (current-directory) "/" source)
+ source))
+ (ts (if (args:get-arg "-time-stamp") (args:get-arg "-time-stamp") "latest")))
+ (if (common:directory-exists? src)
+ (begin
+ (archive:restore-db src ts)
+ (set! *didsomething* #t))
+ (begin
+ (debug:print-error 1 *default-log-port* "Path " source " not found")
+ (exit 1))))))
+ ;; else do a general-run-call
+ (if (and (args:get-arg "-archive") (not (equal? (args:get-arg "-archive") "replicate-db")))
+ (begin
+ ;; for the archive get we need to preserve the starting dir as part of the target path
+ (if (and (args:get-arg "-dest")
+ (not (equal? (substring (args:get-arg "-dest") 0 1) "/")))
+ (let ((newpath (conc (current-directory) "/" (args:get-arg "-dest"))))
+ (debug:print-info 1 *default-log-port* "Preserving original path to destination, was " (args:get-arg "-dest") ", now " newpath)
+ (hash-table-set! args:arg-hash "-dest" newpath)))
+ (general-run-call
+ "-archive"
+ "Archive"
+ (lambda (target runname keys keyvals)
+ (operate-on 'archive target-in: target runname-in: runname )))))
+
+;;======================================================================
+;; Extract a spreadsheet from the runs database
+;;======================================================================
+
+(if (args:get-arg "-extract-ods")
+ (general-run-call
+ "-extract-ods"
+ "Make ods spreadsheet"
+ (lambda (target runname keys keyvals)
+ (let ((dbstruct (make-dbr:dbstruct path: *toppath* local: #t))
+ (outputfile (args:get-arg "-extract-ods"))
+ (runspatt (or (args:get-arg "-runname")(args:get-arg ":runname")))
+ (pathmod (args:get-arg "-pathmod")))
+ ;; (keyvalalist (keys->alist keys "%")))
+ (debug:print 2 *default-log-port* "Extract ods, outputfile: " outputfile " runspatt: " runspatt " keyvals: " keyvals)
+ (db:extract-ods-file dbstruct outputfile keyvals (if runspatt runspatt "%") pathmod)
+ (db:close-all dbstruct)
+ (set! *didsomething* #t)))))
+
+;;======================================================================
+;; execute the test
+;; - gets called on remote host
+;; - receives info from the -execute param
+;; - passes info to steps via MT_CMDINFO env var (future is to use a dot file)
+;; - gathers host info and
+;;======================================================================
+
+(if (args:get-arg "-execute")
+ (begin
+ (launch:execute (args:get-arg "-execute"))
+ (set! *didsomething* #t)))
+
+;;======================================================================
+;; recover from a test where the managing mtest was killed but the underlying
+;; process might still be salvageable
+;;======================================================================
+
+(if (args:get-arg "-recover-test")
+ (let* ((params (string-split (args:get-arg "-recover-test") ",")))
+ (if (> (length params) 1) ;; run-id and test-id
+ (let ((run-id (string->number (car params)))
+ (test-id (string->number (cadr params))))
+ (if (and run-id test-id)
+ (begin
+ (launch:recover-test run-id test-id)
+ (set! *didsomething* #t))
+ (begin
+ (debug:print-error 0 *default-log-port* "bad run-id or test-id, must be integers")
+ (exit 1)))))))
+
+;;======================================================================
+;; Test commands (i.e. for use inside tests)
+;;======================================================================
+
+(define (megatest:step step state status logfile msg)
+ (if (not (getenv "MT_CMDINFO"))
+ (begin
+ (debug:print-error 0 *default-log-port* "MT_CMDINFO env var not set, -step must be called *inside* a megatest invoked environment!")
+ (exit 5))
+ (let* ((cmdinfo (common:read-encoded-string (getenv "MT_CMDINFO")))
+ (transport (assoc/default 'transport cmdinfo))
+ (testpath (assoc/default 'testpath cmdinfo))
+ (test-name (assoc/default 'test-name cmdinfo))
+ (runscript (assoc/default 'runscript cmdinfo))
+ (db-host (assoc/default 'db-host cmdinfo))
+ (run-id (assoc/default 'run-id cmdinfo))
+ (test-id (assoc/default 'test-id cmdinfo))
+ (itemdat (assoc/default 'itemdat cmdinfo))
+ (work-area (assoc/default 'work-area cmdinfo))
+ (db #f))
+ (change-directory testpath)
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ (if (and state status)
+ (let ((comment (launch:load-logpro-dat run-id test-id step)))
+ ;; (rmt:test-set-log! run-id test-id (conc stepname ".html"))))
+ (rmt:teststep-set-status! run-id test-id step state status (or comment msg) logfile))
+ (begin
+ (debug:print-error 0 *default-log-port* "You must specify :state and :status with every call to -step")
+ (exit 6))))))
+
+(if (args:get-arg "-step")
+ (begin
+ (thread-sleep! 1.5)
+ (megatest:step
+ (args:get-arg "-step")
+ (or (args:get-arg "-state")(args:get-arg ":state"))
+ (or (args:get-arg "-status")(args:get-arg ":status"))
+ (args:get-arg "-setlog")
+ (args:get-arg "-m"))
+ ;; (if db (sqlite3:finalize! db))
+ (set! *didsomething* #t)
+ (thread-sleep! 1.5)))
+
+(if (or (args:get-arg "-setlog") ;; since setting up is so costly lets piggyback on -test-status
+ ;; (not (args:get-arg "-step"))) ;; -setlog may have been processed already in the "-step" previous
+ ;; NEW POLICY - -setlog sets test overall log on every call.
+ (args:get-arg "-set-toplog")
+ (args:get-arg "-test-status")
+ (args:get-arg "-set-values")
+ (args:get-arg "-load-test-data")
+ (args:get-arg "-runstep")
+ (args:get-arg "-summarize-items"))
+ (if (not (getenv "MT_CMDINFO"))
+ (begin
+ (debug:print-error 0 *default-log-port* "MT_CMDINFO env var not set, commands -test-status, -runstep and -setlog must be called *inside* a megatest environment!")
+ (exit 5))
+ (let* ((startingdir (current-directory))
+ (cmdinfo (common:read-encoded-string (getenv "MT_CMDINFO")))
+ (transport (assoc/default 'transport cmdinfo))
+ (testpath (assoc/default 'testpath cmdinfo))
+ (test-name (assoc/default 'test-name cmdinfo))
+ (runscript (assoc/default 'runscript cmdinfo))
+ (db-host (assoc/default 'db-host cmdinfo))
+ (run-id (assoc/default 'run-id cmdinfo))
+ (test-id (assoc/default 'test-id cmdinfo))
+ (itemdat (assoc/default 'itemdat cmdinfo))
+ (work-area (assoc/default 'work-area cmdinfo))
+ (db #f) ;; (open-db))
+ (state (args:get-arg ":state"))
+ (status (args:get-arg ":status"))
+ (stepname (args:get-arg "-step")))
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+
+ (if (args:get-arg "-runstep")(debug:print-info 1 *default-log-port* "Running -runstep, first change to directory " work-area))
+ (change-directory work-area)
+ ;; can setup as client for server mode now
+ ;; (client:setup)
+
+ (if (args:get-arg "-load-test-data")
+ ;; has sub commands that are rdb:
+ ;; DO NOT put this one into either rmt: or open-run-close
+ (tdb:load-test-data run-id test-id))
+ (if (args:get-arg "-setlog")
+ (let ((logfname (args:get-arg "-setlog")))
+ (rmt:test-set-log! run-id test-id logfname)))
+ (if (args:get-arg "-set-toplog")
+ ;; DO NOT run remote
+ (tests:test-set-toplog! run-id test-name (args:get-arg "-set-toplog")))
+ (if (args:get-arg "-summarize-items")
+ ;; DO NOT run remote
+ (tests:summarize-items run-id test-id test-name #t)) ;; do force here
+ (if (args:get-arg "-runstep")
+ (if (null? remargs)
+ (begin
+ (debug:print-error 0 *default-log-port* "nothing specified to run!")
+ (if db (sqlite3:finalize! db))
+ (exit 6))
+ (let* ((stepname (args:get-arg "-runstep"))
+ (logprofile (args:get-arg "-logpro"))
+ (logfile (conc stepname ".log"))
+ (cmd (if (null? remargs) #f (car remargs)))
+ (params (if cmd (cdr remargs) '()))
+ (exitstat #f)
+ (shell (let ((sh (get-environment-variable "SHELL") ))
+ (if sh
+ (last (string-split sh "/"))
+ "bash")))
+ (redir (case (string->symbol shell)
+ ((tcsh csh ksh) ">&")
+ ((zsh bash sh ash) "2>&1 >")
+ (else ">&")))
+ (fullcmd (conc "(" (string-intersperse
+ (cons cmd params) " ")
+ ") " redir " " logfile)))
+ ;; mark the start of the test
+ (rmt:teststep-set-status! run-id test-id stepname "start" "n/a" (args:get-arg "-m") logfile)
+ ;; run the test step
+ (debug:print-info 2 *default-log-port* "Running \"" fullcmd "\" in directory \"" startingdir)
+ (change-directory startingdir)
+ (set! exitstat (system fullcmd))
+ (set! *globalexitstatus* exitstat)
+ ;; (change-directory testpath)
+ ;; run logpro if applicable ;; (process-run "ls" (list "/foo" "2>&1" "blah.log"))
+ (if logprofile
+ (let* ((htmllogfile (conc stepname ".html"))
+ (oldexitstat exitstat)
+ (cmd (string-intersperse (list "logpro" logprofile htmllogfile "<" logfile ">" (conc stepname "_logpro.log")) " ")))
+ (debug:print-info 2 *default-log-port* "running \"" cmd "\"")
+ (change-directory startingdir)
+ (set! exitstat (system cmd))
+ (set! *globalexitstatus* exitstat) ;; no necessary
+ (change-directory testpath)
+ (rmt:test-set-log! run-id test-id htmllogfile)))
+ (let ((msg (args:get-arg "-m")))
+ (rmt:teststep-set-status! run-id test-id stepname "end" exitstat msg logfile))
+ )))
+ (if (or (args:get-arg "-test-status")
+ (args:get-arg "-set-values"))
+ (let ((newstatus (cond
+ ((number? status) (if (equal? status 0) "PASS" "FAIL"))
+ ((and (string? status)
+ (string->number status))(if (equal? (string->number status) 0) "PASS" "FAIL"))
+ (else status)))
+ ;; transfer relevant keys into a hash to be passed to test-set-status!
+ ;; could use an assoc list I guess.
+ (otherdata (let ((res (make-hash-table)))
+ (for-each (lambda (key)
+ (if (args:get-arg key)
+ (hash-table-set! res key (args:get-arg key))))
+ (list ":value" ":tol" ":expected" ":first_err" ":first_warn" ":units" ":category" ":variable"))
+ res)))
+ (if (and (args:get-arg "-test-status")
+ (or (not state)
+ (not status)))
+ (begin
+ (debug:print-error 0 *default-log-port* "You must specify :state and :status with every call to -test-status\n" help)
+ (if (sqlite3:database? db)(sqlite3:finalize! db))
+ (exit 6)))
+ (let* ((msg (args:get-arg "-m"))
+ (numoth (length (hash-table-keys otherdata))))
+ ;; Convert to rpc inside the tests:test-set-status! call, not here
+ (tests:test-set-status! run-id test-id state newstatus msg otherdata work-area: work-area))))
+ (if (sqlite3:database? db)(sqlite3:finalize! db))
+ (set! *didsomething* #t))))
+
+;;======================================================================
+;; Various helper commands can go below here
+;;======================================================================
+
+(if (or (args:get-arg "-showkeys")
+ (args:get-arg "-show-keys"))
+ (let ((db #f)
+ (keys #f))
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ (set! keys (rmt:get-keys)) ;; db))
+ (debug:print 1 *default-log-port* "Keys: " (string-intersperse keys ", "))
+ (if (sqlite3:database? db)(sqlite3:finalize! db))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-gui")
+ (begin
+ (debug:print 0 *default-log-port* "Look at the dashboard for now")
+ ;; (megatest-gui)
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-create-megatest-area")
+ (begin
+ (genexample:mk-megatest.config)
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-create-test")
+ (let ((testname (args:get-arg "-create-test")))
+ (genexample:mk-megatest-test testname)
+ (set! *didsomething* #t)))
+
+;;======================================================================
+;; Update the database schema, clean up the db
+;;======================================================================
+
+(if (args:get-arg "-rebuild-db")
+ (begin
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ ;; keep this one local
+ ;; (open-run-close patch-db #f)
+ (let ((dbstruct (db:setup #f areapath: *toppath*)))
+ (common:cleanup-db dbstruct full: #t))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-cleanup-db")
+ (begin
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ (let ((dbstruct (db:setup #f areapath: *toppath*)))
+ (common:cleanup-db dbstruct))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-mark-incompletes")
+ (begin
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ (open-run-close db:find-and-mark-incomplete #f)
+ (set! *didsomething* #t)))
+
+;;======================================================================
+;; Update the tests meta data from the testconfig files
+;;======================================================================
+
+(if (args:get-arg "-update-meta")
+ (begin
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ (runs:update-all-test_meta #f)
+ (set! *didsomething* #t)))
+
+;;======================================================================
+;; Start a repl
+;;======================================================================
+
+;; fakeout readline
+(include "readline-fix.scm")
+
+
+(when (args:get-arg "-diff-rep")
+ (when (and
+ (not (args:get-arg "-diff-html"))
+ (not (args:get-arg "-diff-email")))
+ (debug:print 0 *default-log-port* "Must specify -diff-html or -diff-email with -diff-rep")
+ (set! *didsomething* 1)
+ (exit 1))
+
+ (let* ((toppath (launch:setup)))
+ (do-diff-report
+ (args:get-arg "-src-target")
+ (args:get-arg "-src-runname")
+ (args:get-arg "-target")
+ (args:get-arg "-runname")
+ (args:get-arg "-diff-html")
+ (args:get-arg "-diff-email"))
+ (set! *didsomething* #t)
+ (exit 0)))
+
+(if (or (getenv "MT_RUNSCRIPT")
+ (args:get-arg "-repl")
+ (args:get-arg "-load"))
+ (let* ((toppath (launch:setup))
+ (dbstruct (if (and toppath
+ (common:on-homehost?))
+ (db:setup #t)
+ #f))) ;; make-dbr:dbstruct path: toppath local: (args:get-arg "-local")) #f)))
+ (if *toppath*
+ (cond
+ ((getenv "MT_RUNSCRIPT")
+ ;; How to run megatest scripts
+ ;;
+ ;; #!/bin/bash
+ ;;
+ ;; export MT_RUNSCRIPT=yes
+ ;; megatest << EOF
+ ;; (print "Hello world")
+ ;; (exit)
+ ;; EOF
+
+ (repl))
+ (else
+ (begin
+ (set! *db* dbstruct)
+ (import extras) ;; might not be needed
+ ;; (import csi)
+ (import readline)
+ (import apropos)
+ ;; (import (prefix sqlite3 sqlite3:)) ;; doesn't work ...
+
+ (if *use-new-readline*
+ (begin
+ (install-history-file (get-environment-variable "HOME") ".megatest_history") ;; [homedir] [filename] [nlines])
+ (current-input-port (make-readline-port "megatest> ")))
+ (begin
+ (gnu-history-install-file-manager
+ (string-append
+ (or (get-environment-variable "HOME") ".") "/.megatest_history"))
+ (current-input-port (make-gnu-readline-port "megatest> "))))
+ (if (args:get-arg "-repl")
+ (repl)
+ (load (args:get-arg "-load")))
+ ;; (db:close-all dbstruct) <= taken care of by on-exit call
+ )
+ (exit)))
+ (set! *didsomething* #t))))
+
+;;======================================================================
+;; Wait on a run to complete
+;;======================================================================
+
+(if (and (args:get-arg "-run-wait")
+ (not (or (args:get-arg "-run")
+ (args:get-arg "-runtests")))) ;; run-wait is built into runtests now
+ (begin
+ (if (not (launch:setup))
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+ (operate-on 'run-wait)
+ (set! *didsomething* #t)))
+
+;; ;; ;; redo me ;; Not converted to use dbstruct yet
+;; ;; ;; redo me ;;
+;; ;; ;; redo me (if (args:get-arg "-convert-to-norm")
+;; ;; ;; redo me (let* ((toppath (setup-for-run))
+;; ;; ;; redo me (dbstruct (if toppath (make-dbr:dbstruct path: toppath local: #t))))
+;; ;; ;; redo me (for-each
+;; ;; ;; redo me (lambda (field)
+;; ;; ;; redo me (let ((dat '()))
+;; ;; ;; redo me (debug:print-info 0 *default-log-port* "Getting data for field " field)
+;; ;; ;; redo me (sqlite3:for-each-row
+;; ;; ;; redo me (lambda (id val)
+;; ;; ;; redo me (set! dat (cons (list id val) dat)))
+;; ;; ;; redo me (db:get-db db run-id)
+;; ;; ;; redo me (conc "SELECT id," field " FROM tests;"))
+;; ;; ;; redo me (debug:print-info 0 *default-log-port* "found " (length dat) " items for field " field)
+;; ;; ;; redo me (let ((qry (sqlite3:prepare db (conc "UPDATE tests SET " field "=? WHERE id=?;"))))
+;; ;; ;; redo me (for-each
+;; ;; ;; redo me (lambda (item)
+;; ;; ;; redo me (let ((newval ;; (sdb:qry 'getid
+;; ;; ;; redo me (cadr item))) ;; )
+;; ;; ;; redo me (if (not (equal? newval (cadr item)))
+;; ;; ;; redo me (debug:print-info 0 *default-log-port* "Converting " (cadr item) " to " newval " for test #" (car item)))
+;; ;; ;; redo me (sqlite3:execute qry newval (car item))))
+;; ;; ;; redo me dat)
+;; ;; ;; redo me (sqlite3:finalize! qry))))
+;; ;; ;; redo me (db:close-all dbstruct)
+;; ;; ;; redo me (list "uname" "rundir" "final_logf" "comment"))
+;; ;; ;; redo me (set! *didsomething* #t)))
+
+(if (args:get-arg "-import-megatest.db")
+ (begin
+ (db:multi-db-sync
+ (db:setup #f)
+ 'killservers
+ 'dejunk
+ 'adj-testids
+ 'old2new
+ ;; 'new2old
+ )
+ (set! *didsomething* #t)))
+
+(when (args:get-arg "-sync-brute-force")
+ ((server:get-bruteforce-syncer (db:setup #t) persist-until-sync: #t))
+ (set! *didsomething* #t))
+
+(if (args:get-arg "-sync-to-megatest.db")
+ (let* ((dbstruct (db:setup #f))
+ (tmpdbpth (cdr (dbr:dbstruct-tmpdb dbstruct)))
+ (lockfile (conc tmpdbpth ".lock"))
+ (locked (common:simple-file-lock lockfile))
+ (res (if locked
+ (db:multi-db-sync
+ dbstruct
+ 'new2old)
+ #f)))
+ (if res
+ (begin
+ (common:simple-file-release-lock lockfile)
+ (print "Synced " res " records to megatest.db"))
+ (print "Skipping sync, there is a sync in progress."))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-sync-to")
+ (let ((toppath (launch:setup)))
+ (tasks:sync-to-postgres *configdat* (args:get-arg "-sync-to"))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-list-test-time")
+ (let* ((toppath (launch:setup)))
+ (task:get-test-times)
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-list-run-time")
+ (let* ((toppath (launch:setup)))
+ (task:get-run-times)
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-generate-html")
+ (let* ((toppath (launch:setup)))
+ (if (tests:create-html-tree #f)
+ (debug:print-info 0 *default-log-port* "HTML output created in " toppath "/lt/page0.html")
+ (debug:print 0 *default-log-port* "Failed to create HTML output in " toppath "/lt/runs-index.html"))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-generate-html-structure")
+ (let* ((toppath (launch:setup)))
+ ;(if (tests:create-html-tree #f)
+ (if (tests:create-html-summary #f)
+ (debug:print-info 0 *default-log-port* "HTML output created in " toppath "/lt/targets.html")
+ (debug:print 0 *default-log-port* "Failed to create HTML output in " toppath "/lt/runs-index.html"))
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-syscheck")
+ (begin
+ (mutils:syscheck common:raw-get-remote-host-load
+ server:get-best-guess-address
+ read-config)
+ (set! *didsomething* #t)))
+
+(if (args:get-arg "-extract-skeleton")
+ (let* ((toppath (launch:setup)))
+ (genexample:extract-skeleton-area (args:get-arg "-extract-skeleton"))
+ (set! *didsomething* #t)))
+
+;;======================================================================
+;; Exit and clean up
+;;======================================================================
+
+(if (not *didsomething*)
+ (debug:print 0 *default-log-port* help)
+ (set! *time-to-exit* #t)
+ )
+;;(debug:print-info 13 *default-log-port* "thread-join! watchdog")
+
+;; join the watchdog thread if it has been thread-start!ed (it may not have been started in the case of a server that never enters running state)
+;; (symbols returned by thread-state: created ready running blocked suspended sleeping terminated dead)
+;; TODO: for multiple areas, we will have multiple watchdogs; and multiple threads to manage
+(if (thread? *watchdog*)
+ (case (thread-state *watchdog*)
+ ((ready running blocked sleeping terminated dead)
+ (thread-join! *watchdog*))))
+
+(set! *time-to-exit* #t)
+
+(if (not (eq? *globalexitstatus* 0))
+ (if (or (args:get-arg "-run")(args:get-arg "-runtests")(args:get-arg "-runall"))
+ (begin
+ (debug:print 0 *default-log-port* "NOTE: Subprocesses with non-zero exit code detected: " *globalexitstatus*)
+ (exit 0))
+ (case *globalexitstatus*
+ ((0)(exit 0))
+ ((1)(exit 1))
+ ((2)(exit 2))
+ (else (exit 3)))))
ADDED attic_modular/mlaunch.scm
Index: attic_modular/mlaunch.scm
==================================================================
--- /dev/null
+++ attic_modular/mlaunch.scm
@@ -0,0 +1,33 @@
+;; Copyright 2006-2014, 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 .
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+;;======================================================================
+;; MLAUNCH
+;;
+;; take jobs from the given queue and keep launching them keeping
+;; the cpu load at the targeted level
+;;
+;;======================================================================
+
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 format)
+
+(declare (unit mlaunch))
+(declare (uses db))
+(declare (uses common))
+
ADDED attic_modular/mockup-cached-writes.scm
Index: attic_modular/mockup-cached-writes.scm
==================================================================
--- /dev/null
+++ attic_modular/mockup-cached-writes.scm
@@ -0,0 +1,48 @@
+;; 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 .
+;;
+
+
+(define (make-cached-writer the-db)
+ (let ((db the-db)
+ (queue '()))
+ (lambda (cacheable . qry-params) ;; fn qry
+ (if cacheable
+ (begin
+ (set! queue (cons qry-params queue))
+ (call/cc))
+ (begin
+ (print "Starting transaction")
+ (for-each
+ (lambda (queue-item)
+ (let ((fn (car queue-item))
+ (qry (cdr queue-item)))
+ (print "WRITE to " db ": " qry)
+ )
+ (reverse queue))
+ (print "End transaction")
+ (print "READ from " db ": " qry-params))))))
+
+(define *cw* (make-cached-writer "the db"))
+
+(define (dbcall cacheable query)
+ (*cw* cacheable query))
+
+(dbcall #t "insert abc")
+(dbcall #t "insert def")
+(dbcall #t "insert hij")
+(dbcall #f "select foo")
ADDED attic_modular/monitor.scm
Index: attic_modular/monitor.scm
==================================================================
--- /dev/null
+++ attic_modular/monitor.scm
@@ -0,0 +1,33 @@
+;; Copyright 2006-2012, 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 .
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 dot-locking)
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit runs))
+(declare (uses db))
+(declare (uses common))
+(declare (uses items))
+(declare (uses runconfig))
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "run_records.scm")
+
ADDED attic_modular/mt.scm
Index: attic_modular/mt.scm
==================================================================
--- /dev/null
+++ attic_modular/mt.scm
@@ -0,0 +1,193 @@
+;; Copyright 2006-2013, 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 .
+;;
+
+
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 dot-locking (srfi 18) posix-extras directory-utils call-with-environment-variables)
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit mt))
+(declare (uses db))
+(declare (uses common))
+;; (declare (uses items))
+;; (declare (uses runconfig))
+(declare (uses tests))
+;; (declare (uses server))
+;; (declare (uses runs))
+(declare (uses rmt))
+;; (declare (uses filedb))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses dbmod))
+(import dbmod)
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "run_records.scm")
+(include "test_records.scm")
+
+;; This is the Megatest API. All generally "useful" routines will be wrapped or extended
+;; here.
+
+;;======================================================================
+;; R U N S
+;;======================================================================
+
+;; runs:get-runs-by-patt
+;; get runs by list of criteria
+;; register a test run with the db
+;;
+;; Use: (db-get-value-by-header (db:get-header runinfo)(db:get-rows runinfo))
+;; to extract info from the structure returned
+;;
+(define (mt:get-runs-by-patt keys runnamepatt targpatt)
+ (let loop ((runsdat (rmt:get-runs-by-patt keys runnamepatt targpatt 0 500 #f 0))
+ (res '())
+ (offset 0)
+ (limit 500))
+ ;; (print "runsdat: " runsdat)
+ (let* ((header (vector-ref runsdat 0))
+ (runslst (vector-ref runsdat 1))
+ (full-list (append res runslst))
+ (have-more (eq? (length runslst) limit)))
+ ;; (debug:print 0 *default-log-port* "header: " header " runslst: " runslst " have-more: " have-more)
+ (if have-more
+ (let ((new-offset (+ offset limit))
+ (next-batch (rmt:get-runs-by-patt keys runnamepatt targpatt offset limit #f 0)))
+ (debug:print-info 4 *default-log-port* "More than " limit " runs, have " (length full-list) " runs so far.")
+ (debug:print-info 0 *default-log-port* "next-batch: " next-batch)
+ (loop next-batch
+ full-list
+ new-offset
+ limit))
+ (vector header full-list)))))
+
+;;======================================================================
+;; T E S T S
+;;======================================================================
+
+(define (mt:get-tests-for-run run-id testpatt states status #!key (not-in #t) (sort-by 'event_time) (sort-order "ASC") (qryvals #f)(last-update #f))
+ (let loop ((testsdat (rmt:get-tests-for-run run-id testpatt states status 0 500 not-in sort-by sort-order qryvals last-update 'normal))
+ (res '())
+ (offset 0)
+ (limit 500))
+ (let* ((full-list (append res testsdat))
+ (have-more (eq? (length testsdat) limit)))
+ (if have-more
+ (let ((new-offset (+ offset limit)))
+ (debug:print-info 4 *default-log-port* "More than " limit " tests, have " (length full-list) " tests so far.")
+ (loop (rmt:get-tests-for-run run-id testpatt states status new-offset limit not-in sort-by sort-order qryvals last-update 'normal)
+ full-list
+ new-offset
+ limit))
+ full-list))))
+
+(define (mt:lazy-get-prereqs-not-met run-id waitons ref-item-path #!key (mode '(normal))(itemmaps #f) )
+ (let* ((key (list run-id waitons ref-item-path mode))
+ (res (hash-table-ref/default *pre-reqs-met-cache* key #f))
+ (useres (let ((last-time (if (vector? res) (vector-ref res 0) #f)))
+ (if last-time
+ (< (current-seconds)(+ last-time 5))
+ #f))))
+ (if useres
+ (let ((result (vector-ref res 1)))
+ (debug:print 4 *default-log-port* "Using lazy value res: " result)
+ result)
+ (let ((newres (rmt:get-prereqs-not-met run-id waitons ref-item-path mode: mode itemmaps: itemmaps)))
+ (hash-table-set! *pre-reqs-met-cache* key (vector (current-seconds) newres))
+ newres))))
+
+(define (mt:get-run-stats dbstruct run-id)
+;; Get run stats from local access, move this ... but where?
+ (db:get-run-stats dbstruct run-id))
+
+(define (mt:discard-blocked-tests run-id failed-test tests test-records)
+ (if (null? tests)
+ tests
+ (begin
+ (debug:print-info 1 *default-log-port* "Discarding tests from " tests " that are waiting on " failed-test)
+ (let loop ((testn (car tests))
+ (remt (cdr tests))
+ (res '()))
+ (let* ((test-dat (hash-table-ref/default test-records testn (vector #f #f '())))
+ (waitons (vector-ref test-dat 2)))
+ ;; (print "mt:discard-blocked-tests run-id: " run-id " failed-test: " failed-test " testn: " testn " with waitons: " waitons)
+ (if (null? remt)
+ (let ((new-res (reverse res)))
+ ;; (print " new-res: " new-res)
+ new-res)
+ (loop (car remt)
+ (cdr remt)
+ (if (member failed-test waitons)
+ (begin
+ (debug:print 0 *default-log-port* "Discarding test " testn "(" test-dat ") due to " failed-test)
+ res)
+ (cons testn res)))))))))
+
+;;======================================================================
+;; S T A T E A N D S T A T U S F O R T E S T S
+;;======================================================================
+
+;; speed up for common cases with a little logic
+(define (mt:test-set-state-status-by-id run-id test-id newstate newstatus newcomment)
+ (if (not (and run-id test-id))
+ (begin
+ (debug:print-error 0 *default-log-port* "bad data handed to mt:test-set-state-status-by-id, run-id=" run-id ", test-id=" test-id ", newstate=" newstate)
+ (print-call-chain (current-error-port))
+ #f)
+ (begin
+ ;; cond
+ ;; ((and newstate newstatus newcomment)
+ ;; (rmt:general-call 'state-status-msg run-id newstate newstatus newcomment test-id))
+ ;; ((and newstate newstatus)
+ ;; (rmt:general-call 'state-status run-id newstate newstatus test-id))
+ ;; (else
+ ;; (if newstate (rmt:general-call 'set-test-state run-id newstate test-id))
+ ;; (if newstatus (rmt:general-call 'set-test-status run-id newstatus test-id))
+ ;; (if newcomment (rmt:general-call 'set-test-comment run-id newcomment test-id))))
+ (rmt:set-state-status-and-roll-up-items run-id test-id #f newstate newstatus newcomment)
+ ;; (mt:process-triggers run-id test-id newstate newstatus)
+ #t)))
+
+
+(define (mt:test-set-state-status-by-id-unless-completed run-id test-id newstate newstatus newcomment)
+ (let* ((test-vec (rmt:get-testinfo-state-status run-id test-id))
+ (state (vector-ref test-vec 3)))
+ (if (equal? state "COMPLETED")
+ #t
+ (rmt:set-state-status-and-roll-up-items run-id test-id #f newstate newstatus newcomment))))
+
+
+(define (mt:test-set-state-status-by-testname run-id test-name item-path new-state new-status new-comment)
+ ;(let ((test-id (rmt:get-test-id run-id test-name item-path)))
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path new-state new-status new-comment)
+ ;; (mt:process-triggers run-id test-id new-state new-status)
+ #t);)
+ ;;(mt:test-set-state-status-by-id run-id test-id new-state new-status new-comment)))
+
+(define (mt:test-set-state-status-by-testname-unless-completed run-id test-name item-path new-state new-status new-comment)
+ (let ((test-id (rmt:get-test-id run-id test-name item-path)))
+ (mt:test-set-state-status-by-id-unless-completed run-id test-id new-state new-status new-comment)))
+
ADDED attic_modular/mtargs.scm
Index: attic_modular/mtargs.scm
==================================================================
--- /dev/null
+++ attic_modular/mtargs.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit mtargs))
+
+(include "mtargs/mtargs.scm")
ADDED attic_modular/mtconfigf.scm
Index: attic_modular/mtconfigf.scm
==================================================================
--- /dev/null
+++ attic_modular/mtconfigf.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit mtconfigf))
+
+(include "mtconfigf/mtconfigf.scm")
ADDED attic_modular/mtexec.scm
Index: attic_modular/mtexec.scm
==================================================================
--- /dev/null
+++ attic_modular/mtexec.scm
@@ -0,0 +1,126 @@
+; 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 .
+;;
+
+;; (include "common.scm")
+;; (include "megatest-version.scm")
+
+;; fake out readline usage of toplevel-command
+(define (toplevel-command . a) #f)
+
+(use srfi-1 posix srfi-69 readline ;; regex regex-case srfi-69 apropos json http-client directory-utils rpc typed-records;; (srfi 18) extras)
+ srfi-19 srfi-18 extras format pkts regex regex-case
+ (prefix dbi dbi:)
+ )
+
+;; (declare (uses common))
+(declare (uses margsmod))
+(import margsmod)
+
+(declare (uses configf))
+;; (declare (uses rmt))
+
+(declare (uses configfmod))
+(import configfmod)
+
+;; (use ducttape-lib)
+(include "megatest-version.scm")
+(include "megatest-fossil-hash.scm")
+
+;; (require-library stml)
+
+(define help (conc "
+mtutil, part of the Megatest tool suite, documentation at http://www.kiatoa.com/fossils/megatest
+ version " megatest-version "
+ license GPL, Copyright Matt Welland 2006-2017
+
+Usage: mtutil action [options]
+ -h : this help
+ -manual : show the Megatest user manual
+ -version : print megatest version (currently " megatest-version ")
+
+Queries:
+ show [areas|contours... ] : show areas, contours or other section from megatest.config
+ gendot : generate a graphviz dot file from pkts.
+
+Contour actions:
+ process : runs import, rungen and dispatch
+
+Trigger propagation actions:
+ tsend a=b,c=d... : send trigger info to all recpients in the [listeners] section
+ tlisten -port N : listen for trigger info on port N
+
+Misc
+ -start-dir path : switch to this directory before running mtutil
+ -set-vars V1=1,V2=2 : Add environment variables to a run NB// these are
+ overwritten by values set in config files.
+ -log logfile : send stdout and stderr to logfile
+ -repl : start a repl (useful for extending megatest)
+ -load file.scm : load and run file.scm
+ -debug N|N,M,O... : enable debug messages 0-N or N and M and O ...
+ -list-pkt-keys : list all pkt keys
+
+Examples:
+
+# Start a megatest run in the area \"mytests\"
+mtutil run -area mytests -target v1.63/aa3e -mode-patt MYPATT -tag-expr quick
+
+# Start a contour
+mtutil run -contour quick -target v1.63/aa3e
+
+Called as " (string-intersperse (argv) " ") "
+Version " megatest-version ", built from " megatest-fossil-hash ))
+ ;; first token is our action, but only if no leading dash
+
+(define *action* (if (and (> (length (argv)) 1)
+ (not (string-match "^\\-.*" (cadr (argv)))))
+ (cadr (argv))
+ #f))
+
+(define *remargs*
+ (args:get-args
+ (if *action* (cdr (argv)) (argv))
+ '("-log")
+ '("-h")
+ args:arg-hash
+ 0))
+
+(if (args:get-arg "-h")
+ (begin
+ (print help)
+ (exit)))
+
+(if (or (args:get-arg "-repl")
+ (args:get-arg "-load"))
+ (begin
+ (import extras) ;; might not be needed
+ ;; (import csi)
+ (import readline)
+ (import apropos)
+ ;; (import (prefix sqlite3 sqlite3:)) ;; doesn't work ...
+
+ (install-history-file (get-environment-variable "HOME") ".mtutil_history") ;; [homedir] [filename] [nlines])
+ (current-input-port (make-readline-port "mtutil> "))
+ (if (args:get-arg "-repl")
+ (repl)
+ (load (args:get-arg "-load")))))
+
+#|
+(define mtconf (car (simple-setup #f)))
+(define dat (common:with-queue-db mtconf (lambda (conn)(get-pkts conn '()))))
+(pp (pkts#flatten-all dat '((cmd . ((parent . P)(url . M)))(runtype . ((parent . P)))) 'id 'group-id 'uuid 'parent 'pkt-type 'pkt 'processed))
+|#
ADDED attic_modular/mtut.scm
Index: attic_modular/mtut.scm
==================================================================
--- /dev/null
+++ attic_modular/mtut.scm
@@ -0,0 +1,1928 @@
+; 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 .
+;;
+
+;; (include "common.scm")
+(include "megatest-version.scm")
+
+;; fake out readline usage of toplevel-command
+(define (toplevel-command . a) #f)
+
+(use srfi-1 posix srfi-69 readline ;; regex regex-case srfi-69 apropos json http-client directory-utils rpc typed-records;; (srfi 18) extras)
+ srfi-19 srfi-18 extras format pkts regex regex-case
+ (prefix dbi dbi:)
+ (prefix sqlite3 sqlite3:)
+ nanomsg)
+
+(declare (uses common))
+(declare (uses margsmod))
+(import margsmod)
+
+(declare (uses configf))
+;; (declare (uses rmt))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(use ducttape-lib)
+
+(include "megatest-fossil-hash.scm")
+
+(require-library stml)
+
+;; stuff for the mapper and checker functions
+;;
+(define *target-mappers* (make-hash-table))
+(define *runname-mappers* (make-hash-table))
+(define *area-checkers* (make-hash-table))
+
+(define (mtut:stml->string in-stml)
+ (with-output-to-string
+ (lambda ()
+ (s:output-new
+ (current-output-port)
+ in-stml))))
+
+;; helpers for mappers/checkers
+(define (add-target-mapper name proc)
+ (hash-table-set! *target-mappers* name proc))
+(define (add-runname-mapper name proc)
+ (hash-table-set! *runname-mappers* name proc))
+(define (add-area-checker name proc)
+ (hash-table-set! *area-checkers* name proc))
+
+;; given a runkey, xlatr-key and other info return one of the following:
+;; list of targets, null list to skip processing
+;;
+(define (map-targets mtconf aval-alist runkey area contour #!key (xlatr-key-in #f))
+ (pp aval-alist)
+ (print "In Map-targets")
+ (let* ((xlatr-key (or xlatr-key-in
+ (conf-get/default mtconf aval-alist 'targtrans)))
+ (proc (hash-table-ref/default *target-mappers* xlatr-key #f)))
+ (if proc
+ (begin
+ (print "Using target mapper: " xlatr-key)
+ (handle-exceptions
+ exn
+ (begin
+ (print "FAILED TO RUN TARGET MAPPER FOR " area ", called " xlatr-key)
+ (print " function is: " (hash-table-ref/default *target-mappers* xlatr-key #f ) )
+ (print " message: " ((condition-property-accessor 'exn 'message) exn))
+ runkey)
+ (proc runkey area contour)))
+ (begin
+ (if xlatr-key
+ (print "ERROR: Failed to find named target translator " xlatr-key ", using original target."))
+ `(,runkey))))) ;; no proc then use runkey
+
+;; given mtconf and areaconf extract a translator/filter, first look at areaconf
+;; then if not found look at default
+;;
+(define (conf-get/default mtconf areaconf keyname #!key (default #f))
+ (let ((res (or (alist-ref keyname areaconf)
+ (configf:lookup mtconf "default" (conc keyname))
+ default)))
+ (if res
+ (string->symbol res)
+ res)))
+
+;; this needs some thought regarding security implications.
+;;
+;; i. Check that owner of the file and calling user are same?
+;; ii. Check that we are in a legal megatest area?
+;; iii. Have some form of authentication or record of the md5sum or similar of the file?
+;; iv. Use compiled version in preference to .scm version. Thus there is a manual "blessing"
+;; required to use .mtutil.scm.
+;;
+(if (common:file-exists? "megatest.config")
+ (if (common:file-exists? ".mtutil.so")
+ (load ".mtutil.so")
+ (if (common:file-exists? ".mtutil.scm")
+ (load ".mtutil.scm"))))
+
+;; main three types of run
+;; "-run" => initiate a run
+;; "-rerun-clean" => set failed, aborted, killed, etc. (not pass/fail) to NOT_STARTED and kick off run
+;; "-rerun-all" => set all tests NOT_STARTED and kick off run again
+
+;; deprecated/do not use
+;; "-runall" => synonym for run, do not use
+;; "-runtests" => synonym for run, do not use
+
+;; Disabled help items
+;; -rollup : (currently disabled) fill run (set by :runname) with latest test(s)
+;; from prior runs with same keys
+;; Contour actions
+;; import : import pkts
+;; dispatch : dispatch queued run jobs from imported pkts
+;; rungen : look at input sense list in [rungen] and generate run pkts
+
+(define help (conc "
+mtutil, part of the Megatest tool suite, documentation at http://www.kiatoa.com/fossils/megatest
+ version " megatest-version "
+ license GPL, Copyright Matt Welland 2006-2017
+
+Usage: mtutil action [options]
+ -h : this help
+ -manual : show the Megatest user manual
+ -version : print megatest version (currently " megatest-version ")
+
+Run management:
+ run : initiate or resume a run, already completed and in-progress
+ tests are not affected.
+ rerun-clean : clean and rerun all not completed pass/fail tests
+ rerun-all : clean and rerun entire run
+ kill-run : kill all tests in run
+ kill-rerun : kill all tests in run and restart non-completed tests
+ remove : remove runs
+ set-ss : set state/status
+ archive : compress and move test data to archive disk
+ kill : stop tests or entire runs
+ db : database utilities
+
+Queries:
+ show [areas|contours... ] : show areas, contours or other section from megatest.config
+ gendot : generate a graphviz dot file from pkts.
+
+Contour actions:
+ process : runs import, rungen and dispatch
+
+Trigger propagation actions:
+ tsend a=b,c=d... : send trigger info to all recpients in the [listeners] section
+ tlisten -port N : listen for trigger info on port N
+
+Selectors
+ -immediate : apply this action immediately, default is to queue up actions
+ -area areapatt1,area2... : apply this action only to the specified areas
+ -target key1/key2/... : run for key1, key2, etc.
+ -test-patt p1/p2,p3/... : % is wildcard
+ -run-name : required, name for this particular test run
+ -contour contourname : run all targets for contourname, requires -run-name, -target
+ -state-status c/p,c/f : Specify a list of state and status patterns
+ -tag-expr tag1,tag2%,.. : select tests with tags matching expression
+ -mode-patt key : load testpatt from in runconfigs instead of default TESTPATT
+ if -testpatt and -tagexpr are not specified
+ -new state/status : specify new state/status for set-ss
+
+Misc
+ -start-dir path : switch to this directory before running mtutil
+ -set-vars V1=1,V2=2 : Add environment variables to a run NB// these are
+ overwritten by values set in config files.
+ -log logfile : send stdout and stderr to logfile
+ -repl : start a repl (useful for extending megatest)
+ -load file.scm : load and run file.scm
+ -debug N|N,M,O... : enable debug messages 0-N or N and M and O ...
+ -list-pkt-keys : list all pkt keys
+
+Utility
+ db pgschema : emit postgresql schema; do \"mtutil db pgschema | psql -d mydb\"
+ gatherdb [propagate] : gather dbs from all areas into /tmp/$USER_megatest/alldbs,
+ optionally propagate the data to megatest2.0 format
+
+
+Examples:
+
+# Start a megatest run in the area \"mytests\"
+mtutil run -area mytests -target v1.63/aa3e -mode-patt MYPATT -tag-expr quick
+
+# Start a contour
+mtutil run -contour quick -target v1.63/aa3e
+
+Called as " (string-intersperse (argv) " ") "
+Version " megatest-version ", built from " megatest-fossil-hash ))
+
+;; args and pkt key specs
+;;
+(define *arg-keys*
+ ;; used keys
+ ;; a - action
+ '(
+ ("-area" . G) ;; maps to group
+ ("-contour" . c)
+ ("-append-config" . d)
+ ("-state" . e)
+ ("-item-patt" . i)
+ ("-sync-to" . k)
+ ("-new" . l) ;; l (see below) is new-ss
+ ("-run-name" . n)
+ ("-mode-patt" . o)
+ ("-test-patt" . p) ;; idea, enhance margs ("-test-patt" "-testpatt") => yields one value in "-test-patt"
+ ("-status" . s)
+ ("-target" . t)
+ ("-reqtarg" . R)
+
+ ("-tag-expr" . x)
+ ;; misc
+ ("-debug" . #f) ;; for *verbosity* > 2
+ ("-load" . #f) ;; load and exectute a scheme file
+ ("-log" . #f)
+ ("-override-user" . #f)
+ ("-msg" . M)
+ ("-start-dir" . S)
+ ("-set-vars" . v)
+ ("-config" . h)
+ ("-time-out" . u)
+ ("-archive" . b)
+ ))
+(define *switch-keys*
+ '(
+ ("-h" . #f)
+ ("-help" . #f)
+ ("--help" . #f)
+ ("-manual" . #f)
+ ("-version" . #f)
+ ;; misc
+ ("-repl" . #f)
+ ("-immediate" . I)
+ ("-preclean" . r)
+ ("-prepend-contour" . w)
+ ("-force" . F)
+ ("-list-pkt-keys" . #f)
+ ))
+
+;; alist to map actions to old megatest commands
+(define *action-keys*
+ '((run . "-run")
+ (rerun-clean . "-rerun-clean")
+ (rerun-all . "-rerun-all")
+ (kill-run . "-kill-runs")
+ (kill-rerun . "-kill-rerun")
+ (lock . "-lock")
+ (unlock . "-unlock")
+ (sync . "")
+ (archive . "")
+ (set-ss . "-set-state-status")
+ (remove . "-remove-runs")))
+
+;; manually keep this list updated from the keys to
+;; the case *action* near the end of this file.
+(define *other-actions*
+ '(run remove rerun set-ss archive kill list
+ dispatch import rungen process
+ show gendot db tsend tlisten))
+
+;; Card types:
+;;
+;; A action
+;; U username (Unix)
+;; D timestamp
+;; T card type
+
+;; a summary list of used card types for helping to not accidentally re-use them
+;;
+;; ADGIMSTUZabcdefghiklnoprstuvwx
+
+;; utilitarian alist for standard cards
+;;
+(define *additional-cards*
+ '(
+ ;; Standard Cards
+ (A . action )
+ (D . timestamp )
+ (T . cardtype )
+ (U . user ) ;; username
+ (Z . shar1sum )
+
+ ;; Extras
+ (a . runkey ) ;; needed for matching up pkts with target derived from runkey
+ ;; (l . new-ss ) ;; new state/status
+ (b . branch ) ;; repository branch or tag (fossil or git)
+ (f . url ) ;; repository URL (e.g. fossil or git)
+ (g . clone ) ;; existing clone area (cached in /tmp)
+ ))
+
+;; inlst is an alternative input
+;;
+(define (lookup-param-by-key key #!key (inlst #f))
+ (fold (lambda (a res)
+ (if (eq? (cdr a) key)
+ (car a)
+ res))
+ #f
+ (or inlst *arg-keys*)))
+
+(define (lookup-action-by-key key)
+ (alist-ref (string->symbol key) *action-keys*))
+
+(define (swizzle-alist lst)
+ (map (lambda (x)(cons (cdr x)(car x))) lst))
+
+;;======================================================================
+;; U T I L S
+;;======================================================================
+
+;; given a mtutil param, return the old megatest equivalent
+;;
+(define (megatest-param->mtutil-param param)
+ (let* ((mapping-alist (common:get-param-mapping flavor: 'switch-symbol)))
+ (alist-ref (string->symbol param) mapping-alist eq? param)
+ param))
+
+(define val->alist common:val->alist)
+
+(define (push-run-spec torun contour runkey spec)
+ (configf:section-var-set! torun contour runkey
+ (cons spec
+ (or (configf:lookup torun contour runkey)
+ '()))))
+
+(define (fossil:clone-or-sync url name dest-dir)
+ (let ((targ-file (conc dest-dir "/" name))) ;; do not force usage of .fossil extension
+ (handle-exceptions
+ exn
+ (print "ERROR: failed to create directory " dest-dir " message: " ((condition-property-accessor 'exn 'message) exn))
+ (create-directory dest-dir #t))
+ (handle-exceptions
+ exn
+ (print "ERROR: failed to clone or sync 1ossil " url " message: " ((condition-property-accessor 'exn 'message) exn))
+ (if (common:file-exists? targ-file)
+ (system (conc "fossil pull --once " url " -R " targ-file))
+ (system (conc "fossil clone " url " " targ-file))
+ ))))
+
+(define (fossil:last-change-node-and-time fossils-dir fossil-name branch)
+ (let* ((fossil-file (conc fossils-dir "/" fossil-name))
+ (timeline-port (if (file-read-access? fossil-file)
+ (handle-exceptions
+ exn
+ (begin
+ (print "ERROR: failed to get timeline from " fossil-file " message: " ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (open-input-pipe (conc "fossil timeline -t ci -W 0 -n 0 -R " fossil-file)))
+ #f))
+ (get-line (lambda ()
+ (handle-exceptions
+ exn
+ (begin
+ (print "ERROR: failed to read from file " fossil-file " message: " ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (read-line timeline-port))))
+ (date-rx (regexp "^=== (\\S+) ===$"))
+ (node-rx (regexp "^(\\S+) \\[(\\S+)\\].*\\(.*tags:\\s+([^\\)]+)\\)$")))
+ (let loop ((inl (get-line))
+ (date #f)
+ (node #f)
+ (time #f))
+ (cond
+ ((and date time node) ;; have all, return 'em
+ (close-input-port timeline-port)
+ (values (common:date-time->seconds (conc date " " time)) node))
+ ((and inl (not (eof-object? inl))) ;; have a line to process
+ (regex-case inl
+ (date-rx ( _ newdate ) (loop (get-line) newdate node time))
+ ;; 22:47:48 [a024d9e60f] Added *user-hash-data* - a global that can be used in -repl and #{scheme ...} calls by the end user (user: matt tags: v1.63)
+ (node-rx ( _ newtime newnode alltags )
+ (let ((tags (string-split-fields ",\\s*" alltags #:infix)))
+ (print "tags: " tags)
+ (if (member branch tags)
+ (loop (get-line) date newnode newtime)
+ (loop (get-line) date node time))))
+ (else ;; have some unrecognised junk? spit out error message
+ (print "ERROR: fossil timeline returned unrecognisable junk \"" inl "\"")
+ (loop (get-line) date node time))))
+ (else ;; no more datat and last node on branch not found
+ (close-input-port timeline-port)
+ (values (common:date-time->seconds (conc date " " time)) node))))))
+
+;;======================================================================
+;; GLOBALS
+;;======================================================================
+
+;; first token is our action, but only if no leading dash
+(define *action* (if (and (> (length (argv)) 1)
+ (not (string-match "^\\-.*" (cadr (argv)))))
+ (cadr (argv))
+ #f))
+
+;; process arguments, extract switches and parameters first
+(define remargs (args:get-args
+ (if *action* (cdr (argv)) (argv)) ;; args:get-args dumps first in argv list (the program name)
+ (map car *arg-keys*)
+ (map car *switch-keys*)
+ args:arg-hash
+ 0))
+
+;; handle requests for help
+;;
+(if (or (member *action* '("-h" "-help" "help" "--help"))
+ (args:any-defined? "-h" "-help" "--help"))
+ (begin
+ (print help)
+ (exit 1)))
+
+(define (print-pkt-keys inlst)
+ (for-each
+ (lambda (p)
+ (let ((sw (car p))
+ (c (cdr p)))
+ (print (or c "n/a") "\t" sw)))
+ inlst))
+
+(define (print-duplicate-keys . all)
+ (let ((card-hash (make-hash-table)))
+ (for-each
+ (lambda (lst)
+ (for-each
+ (lambda (card-spec)
+ (let ((k (cdr card-spec)))
+ ;; (print "card-spec: " card-spec ", k: " k)
+ (if k (hash-table-set! card-hash k (+ (hash-table-ref/default card-hash k 0) 1)))))
+ lst))
+ all)
+ (for-each
+ (lambda (k)
+ (if (> (hash-table-ref card-hash k) 1)
+ (print k "\t" (hash-table-ref card-hash k))))
+ (sort (hash-table-keys card-hash) (lambda (a b)(>= (hash-table-ref card-hash a)(hash-table-ref card-hash b)))))
+ ))
+
+(define (print-pkt-key-info)
+ (print "Argument keys")
+ (print-pkt-keys *arg-keys*)
+ (print "\nSwitch keys")
+ (print-pkt-keys *switch-keys*)
+ (print "\nAction keys")
+ (print-pkt-keys *action-keys*)
+ (print "\nAdditional cards")
+ (print-pkt-keys (swizzle-alist *additional-cards*))
+ (print "\nDuplicate keys")
+ (print-duplicate-keys *arg-keys* *switch-keys* *action-keys* (swizzle-alist *additional-cards*))
+ (print "\nEnd of report.")
+ )
+
+;; list packet keys
+;;
+(if (args:get-arg "-list-pkt-keys")
+ (begin (print-pkt-key-info)(exit 0)))
+
+;; (print "*action*: " *action*)
+
+;; (let-values (((uuid pkt)
+;; (command-line->pkt #f args:arg-hash)))
+;; (print pkt))
+
+;; Add args that use remargs here
+;;
+(if (and (not (null? remargs))
+ (not (or
+ (args:get-arg "-runstep")
+ (args:get-arg "-envcap")
+ (args:get-arg "-envdelta")
+ (member *action* '("db" "tsend" "tlisten")) ;; very loose checks on db and tsend/listen
+ (equal? *action* "show") ;; just keep going if list
+ )))
+ (debug:print-error 0 *default-log-port* "Unrecognised arguments: " (string-intersperse (if (list? remargs) remargs (argv)) " ")))
+
+(if (or (args:any? "-h" "help" "-help" "--help")
+ (member *action* '("-h" "-help" "--help" "help")))
+ (begin
+ (print help)
+ (exit 1)))
+
+;;======================================================================
+;; Nanomsg transport
+;;======================================================================
+
+(define-inline (encode data)
+ (with-output-to-string
+ (lambda ()
+ (write data))))
+
+(define-inline (decode data)
+ (with-input-from-string
+ data
+ (lambda ()
+ (read))))
+
+(define (is-port-in-use port-num)
+ (let* ((ret #f))
+ (let-values (((inp oup pid)
+ (process "netstat" (list "-tulpn" ))))
+ (let loop ((inl (read-line inp)))
+ (if (not (eof-object? inl))
+ (begin
+ (if (string-search (regexp (conc ":" port-num)) inl)
+ (begin
+ ;(print "Output: " inl)
+ (set! ret #t))
+ (loop (read-line inp)))))))
+ret))
+
+;;start a server, returns the connection
+;;
+(define (start-nn-server portnum )
+ (let ((rep (nn-socket 'rep)))
+ (handle-exceptions
+ exn
+ (let ((emsg ((condition-property-accessor 'exn 'message) exn)))
+ (print "ERROR: Failed to start server \"" emsg "\"")
+ (exit 1))
+
+ (nn-bind rep (conc "tcp://*:" portnum)))
+ rep))
+
+(define (can-user-kill-listner user-info attrib)
+ (let* ((contacts (alist-ref 'contact attrib))
+ (user-id (cadddr (cdr user-info)))
+ (ret #f)
+ (contact-list (string-split contacts ",")))
+ (for-each
+ (lambda (admin)
+ (if (string-contains user-id (car (string-split admin "@")))
+ (set! ret #t)))
+ contact-list)
+ ret))
+
+;; open connection to server, send message, close connection
+;;
+(define (open-send-close-nn host-port msg attrib #!key (timeout 3) ) ;; default timeout is 3 seconds
+ (let ((req (nn-socket 'req))
+ (uri (conc "tcp://" host-port))
+ (res #f)
+ (contacts (alist-ref 'contact attrib))
+ (mode (alist-ref 'mode attrib)))
+ (handle-exceptions
+ exn
+ (let ((emsg ((condition-property-accessor 'exn 'message) exn)))
+ ;; Send notification
+ (print "ERROR: Failed to connect / send to " uri " message was \"" emsg "\"" )
+ (if (equal? mode "production")
+ (begin
+ (print " Sending email to contacts : " contacts )
+ (let ((email-body (mtut:stml->string (s:body
+ (s:p (conc "We could not send messages to the server on " uri "." "Please check if the listner is running. It is possible that the host is overloaded due to which it may take too long to respond. \n Contact your system adminstrator if server load is high." (s:br)" Thank You ") )))))
+ (sendmail (string-join (string-split contacts ";" )) (conc "[Listner Error] Filed to connect to listner on " uri) email-body use_html: #t)))
+ (print " mode : " mode " Not sending any emails" ))
+ #f)
+ (nn-connect req uri)
+ (print "Connected to the server " )
+ (nn-send req msg)
+ (print "Request Sent")
+ (let* ((th1 (make-thread (lambda ()
+ (let ((resp (nn-recv req)))
+ (nn-close req)
+ (set! res (if (equal? resp "ok")
+ #t
+ #f))))
+ "recv thread"))
+ (th2 (make-thread (lambda ()
+ (thread-sleep! timeout)
+ (thread-terminate! th1))
+ "timer thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1)
+ res))))
+
+(define (open-send-receive-nn host-port msg attrib #!key (timeout 3) ) ;; default timeout is 3 seconds
+ (let ((req (nn-socket 'req))
+ (uri (conc "tcp://" host-port))
+ (res #f)
+ (contacts (alist-ref 'contact attrib))
+ (mode (alist-ref 'mode attrib)))
+ (handle-exceptions
+ exn
+ (let ((emsg ((condition-property-accessor 'exn 'message) exn)))
+ ;; Send notification
+ (print "ERROR: Failed to connect / send to " uri " message was \"" emsg "\"" )
+ (if (equal? mode "production")
+ (begin
+ (print " Sending email to contacts : " contacts )
+ (let ((email-body (mtut:stml->string (s:body
+ (s:p (conc "We could not send messages to the server on " uri "." "Please check if the listner is running. It is possible that the host is overloaded due to which it may take too long to respond. \n Contact your system adminstrator if server load is high." (s:br)" Thank You ") )))))
+ (sendmail (string-join (string-split contacts ";" )) (conc "[Listner Error] Filed to connect to listner on " uri) email-body use_html: #t)))
+ (print " mode : " mode " Not sending any emails" ))
+ #f)
+ (nn-connect req uri)
+ (print "Connected to the server " )
+ (nn-send req msg)
+ (print "Request Sent")
+ ;; receive code here
+ ;;(print (nn-recv req))
+ (let* ((th1 (make-thread (lambda ()
+ (let ((resp (nn-recv req)))
+ (nn-close req)
+ (print resp)
+ (set! res (if (equal? resp "ok")
+ #t
+ #f))))
+ "recv thread"))
+ (th2 (make-thread (lambda ()
+ (thread-sleep! timeout)
+ (thread-terminate! th1))
+ "timer thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1)
+ res))))
+
+;;======================================================================
+;; Runs
+;;======================================================================
+
+;; make a runname
+;;
+(define (make-runname pre post)
+ (time->string
+ (seconds->local-time (current-seconds)) "%Yw%V.%w-%H%M"))
+
+;; collect, translate, collate and assemble a pkt from the command-line
+;;
+;; sched => force the run start time to be recorded as sched Unix
+;; epoch. This aligns times properly for triggers in some cases.
+;;
+;; extra-dat format is ( 'x xval 'y yval .... )
+;;
+(define (command-line->pkt action args-alist sched-in #!key (extra-dat '())(area-path #f)(new-ss #f))
+ (let* ((sched (cond
+ ((vector? sched-in)(local-time->seconds sched-in)) ;; we recieved a time
+ ((number? sched-in) sched-in)
+ (else (current-seconds))))
+ (user (if (and args-alist (hash-table? args-alist))
+ (hash-table-ref/default args-alist "-override-user" (current-user-name))
+ (current-user-name)))
+
+ (args-data (if args-alist
+ (if (hash-table? args-alist) ;; seriously?
+ (hash-table->alist args-alist)
+ args-alist)
+ (hash-table->alist args:arg-hash))) ;; if no args-alist then we assume this is a call driven directly by commandline
+ (alldat (apply append
+ (list 'A action
+ 'U user
+ 'D sched)
+ (if area-path
+ (list 'S area-path) ;; the area-path is mapped to the start-dir
+ '())
+ (if (list? extra-dat)
+ extra-dat
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: command-line->pkt received bad extra-dat " extra-dat)
+ '()))
+ (map (lambda (x)
+ (let* ((param (car x))
+ (value (cdr x))
+ (pmeta (assoc param *arg-keys*)) ;; translate the card key to a megatest switch or parameter
+ (smeta (assoc param *switch-keys*)) ;; first lookup the key in arg-keys or switch-keys
+ (meta (if (or pmeta smeta)
+ (cdr (or pmeta smeta)) ;; found it?
+ #f)))
+ (if meta ;; construct the switch/param pair.
+ (list meta value)
+ '())))
+
+ (filter cdr args-data)))))
+ (print "Alldat: " alldat ) ;;Do not remove. This is uesed by other applications to calculate z card
+ ;(exit)
+ (add-z-card
+ (apply construct-sdat alldat))))
+
+(define (simple-setup start-dir-in)
+ (let* ((start-dir (or start-dir-in "."))
+ (mtconfig (or (args:get-arg "-config") "megatest.config"))
+ (mtconfdat (find-and-read-config ;; NB// sets MT_RUN_AREA_HOME as side effect
+ mtconfig
+ ;; environ-patt: "env-override"
+ given-toppath: start-dir
+ ;; pathenvvar: "MT_RUN_AREA_HOME"
+ ))
+ (mtconf (if mtconfdat (car mtconfdat) #f)))
+ ;; we set some dynamic data in a section called "scratchdata"
+ (if mtconf
+ (begin
+ (configf:section-var-set! mtconf "scratchdat" "toppath" start-dir)))
+ ;; (print "TOPPATH: " (configf:lookup mtconf "scratchdat" "toppath"))
+ mtconfdat))
+
+;;======================================================================
+;; Areas
+;;======================================================================
+
+;; look for areas=a1,a2,a3 OR areafn=somefuncname
+;;
+(define (val-alist->areas val-alist)
+ (let ((areas-string (alist-ref 'areas val-alist))
+ (areas-procname (alist-ref 'areafn val-alist)))
+ (if areas-procname ;; areas-procname take precedence
+ areas-procname
+ (string-split (or areas-string "") ","))))
+
+;; area - the current area under consideration
+;; areas - the list of allowed areas from the contour spec -OR-
+;; if it is a string then it is the function to use to
+;; lookup in *area-checkers*
+;;
+(define (area-allowed? area areas runkey contour mode-patt)
+ ;;(print "Areas: " areas)
+ (cond
+ ((not areas) #t) ;; no spec
+ ((string? areas) ;;
+ (let ((check-fn (hash-table-ref/default *area-checkers* (string->symbol areas) #f)))
+ (if check-fn
+ (check-fn area runkey contour mode-patt)
+ #f)))
+ ((list? areas)(member area areas))
+ (else #f))) ;; shouldn't get here
+
+(define (get-area-names mtconf)
+ (map car (configf:get-section mtconf "areas")))
+
+;;======================================================================
+;; Pkts for remote control
+;;======================================================================
+
+;; NEED TIMESTAMP ON PKTS for efficient loading of packets into db.
+
+
+;; make a run request pkt from basic data, this seriously needs to be refactored
+;; i. Take the code that builds the info to submit to create-run-pkt and have it
+;; generate the pkt keys directly.
+;; ii. Pass the pkt keys and values to this proc and go from there.
+;; iii. Maybe have an abstraction alist with meaningful names for the pkt keys
+;;
+;; Override the run start time record with sched. Usually #f is fine.
+;;
+(define (create-run-pkt mtconf action area runkey target runname mode-patt
+ tag-expr pktsdir reason contour sched dbdest append-conf
+ runtrans)
+ (let* ((good-val (lambda (inval)(and inval (string? inval)(not (string-null? inval)))))
+ (area-dat (common:val->alist (or (configf:lookup mtconf "areas" area) "")))
+ (area-path (alist-ref 'path area-dat))
+ ;; (area-xlatr (alist-ref 'targtrans area-dat))
+ ;; (xlatr-key (if area-xlatr (string->symbol area-xlatr) #f))
+ (new-runname (let* ((callname (if (string? runtrans)(string->symbol runtrans) #f))
+ (mapper (if callname (hash-table-ref/default *runname-mappers* callname #f) #f)))
+ ;; (print "callname=" callname " runtrans=" runtrans " mapper=" mapper)
+ (if (and callname
+ (not (equal? callname "auto"))
+ (not mapper))
+ (print "No mapper " callname " for area " area " using " callname " as the runname"))
+ (if mapper
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain)
+ (print "FAILED TO RUN RUNNAME MAPPER " callname " FOR AREA " area)
+ (print " message: " ((condition-property-accessor 'exn 'message) exn))
+ runname)
+ (print "(mapper " (string-intersperse (list runkey runname area area-path reason contour mode-patt) ", ") ")")
+ (mapper runkey runname area area-path reason contour mode-patt))
+ (case callname
+ ((auto #f) runname)
+ (else runtrans)))))
+ (new-target target) ;; I believe we will want target manipulation here .. (map-targets xlatr-key runkey area contour))
+ (actual-action (if action
+ (if (equal? action "sync-prepend")
+ "sync"
+ action)
+ "run"))) ;; this has gotten a bit ugly. Need a function to handle actions processing.
+ ;; some hacks to remove switches not needed in certain cases
+ (case (string->symbol (or action "run"))
+ ((sync sync-prepend)
+ (set! new-target #f)
+ (set! runame #f)))
+ ;; (print "area-path: " area-path " orig-target: " runkey " new-target: " new-target)
+ (let-values (((uuid pkt)
+ (command-line->pkt
+ actual-action
+ (append
+ `(("-start-dir" . ,area-path)
+ ;;("-msg" . ,reason)
+ ("-msg" . ,"Script-triggered")
+ ("-contour" . ,contour))
+ (if (good-val new-runname) `(("-run-name" . ,new-runname)) '())
+ (if (good-val new-target) `(("-target" . ,new-target)) '())
+ (if (good-val area) `(("-area" . ,area)) '())
+ (if (good-val mode-patt) `(("-mode-patt" . ,mode-patt)) '())
+ (if (good-val tag-expr) `(("-tag-expr" . ,tag-expr)) '())
+ (if (good-val dbdest) `(("-sync-to" . ,dbdest)) '())
+ (if (good-val append-conf) `(("-append-config" . ,append-conf)) '())
+ (if (equal? action "sync-prepend") '(("-prepend-contour" . " ")) '())
+ (if (not (or mode-patt tag-expr))
+ `(("-testpatt" . "%"))
+ '())
+ (if (or (not action)
+ (equal? action "run"))
+ `(("-preclean" . " ")
+ ("-rerun-all" . " ")) ;; if run we *always* want preclean set, use single space as placeholder
+ '())
+ )
+ sched
+ extra-dat: `(a ,runkey) ;; we need the run key for marking the run as launched
+ )))
+ (with-output-to-file
+ (conc pktsdir "/" uuid ".pkt")
+ (lambda ()
+ (print pkt))))))
+
+;; (use trace)(trace create-run-pkt)
+(define (contains list x) (cond ((null? list) #f) ((eq? (car list) x) #t) (else (contains (cdr list) x))))
+
+;; collect all needed data and create run pkts for contours with changed inputs
+;;
+(define (generate-run-pkts mtconf toppath)
+ (let ((std-runname (conc "sched" (time->string (seconds->local-time (current-seconds)) "%M%H%d")))
+ (packets-generated 0))
+ (common:with-queue-db
+ mtconf
+ (lambda (pktsdirs pktsdir pdb)
+ (let* ((rgconfdat (find-and-read-config (conc toppath "/runconfigs.config")))
+ (rgconf (car rgconfdat))
+ (all-areas (map car (configf:get-section mtconf "areas")))
+ (contours (configf:get-section mtconf "contours"))
+ (torun (make-hash-table)) ;; target => ( ... info ... )
+ (rgentargs (hash-table-keys rgconf))) ;; these are the targets registered for automatically triggering
+
+ ;;(print "rgentargs: " rgentargs)
+ (for-each
+ (lambda (runkey)
+ (let* ((keydats (configf:get-section rgconf runkey)))
+ (for-each
+ (lambda (sense) ;; these are the sense rules
+ (let* ((key (car sense))
+ (val (cadr sense))
+ (keyparts (string-split key ":")) ;; contour:ruletype:action:optional
+ (contour (car keyparts))
+ (len-key (length keyparts))
+ (ruletype (if (> len-key 1)(cadr keyparts) #f))
+ (action (if (> len-key 2)(caddr keyparts) #f))
+ (optional (if (> len-key 3)(cadddr keyparts) #f))
+ ;; (val-list (string-split-fields ";\\s*" val #:infix)) ;; (string-split val)) ;; runname-rule params
+ (val-alist (common:val->alist val))
+ (runname (make-runname "" ""))
+ (runtrans (alist-ref 'runtrans val-alist))
+
+ ;; these may or may not be defined and not all are used in each handler type in the case below
+ (run-name (alist-ref 'run-name val-alist))
+ (target (alist-ref 'target val-alist))
+ (crontab (alist-ref 'cron val-alist))
+ (areas (val-alist->areas val-alist)) ;; areas can be a single string (a reference to call an areas function), or a list of area names.
+ (dbdest (alist-ref 'dbdest val-alist))
+ (appendconf (alist-ref 'appendconf val-alist))
+ (file-globs (alist-ref 'glob val-alist))
+
+ (runstarts (find-pkts pdb '(runstart) `((c . ,contour)
+ (t . ,runkey))))
+ (rspkts (common:get-pkt-alists runstarts))
+ ;; starttimes is for run start times and is used to know when the last run was launched
+ (starttimes (common:get-pkt-times rspkts)) ;; sort by age (youngest first) and delete duplicates by target
+ (last-run (if (null? starttimes) ;; if '() then it has never been run, else get the max
+ 0
+ (apply max (map cdr starttimes))))
+ ;; synctimes is for figuring out the last time a sync was done
+ (syncstarts (find-pkts pdb '(syncstart) '())) ;; no qualifiers, a sync does all tarets etc.
+ (sspkts (common:get-pkt-alists syncstarts))
+ (synctimes (common:get-pkt-times sspkts))
+ (last-sync (if (null? synctimes) ;; if '() then it has never been run, else get the max
+ 0
+ (apply max (map cdr synctimes))))
+ )
+
+ (let ((delta (lambda (x)
+ (round (/ (- (current-seconds) x) 60)))))
+ (if (args:get-arg "-target")
+ (if (string= (args:get-arg "-target") runkey)
+ (begin (print "runkey: " runkey ", ruletype: " ruletype ", action: " action ", last-run: " last-run " time since; last-run: " (delta last-run) ", last-sync: " (delta last-sync))
+ (print "val-alist=" val-alist " runtrans=" runtrans))
+ (if #f (print "skipping: " runkey)))
+ (begin (print "runkey: " runkey ", ruletype: " ruletype ", action: " action ", last-run: " last-run " time since; last-run: " (delta last-run) ", last-sync: " (delta last-sync))
+ (print "val-alist=" val-alist " runtrans=" runtrans))
+ ))
+
+
+ ;; look in runstarts for matching runs by target and contour
+ ;; get the timestamp for when that run started and pass it
+ ;; to the rule logic here where "ruletype" will be applied
+ ;; if it comes back "changed" then proceed to register the runs
+
+ (case (string->symbol (or ruletype "no-such-rule"))
+
+ ((no-such-rule) (print "ERROR: no such rule for " sense))
+
+ ;; Handle crontab like rules
+ ;;
+ ((scheduled)
+ (if (not (alist-ref 'cron val-alist)) ;; gotta have cron spec
+ (print "ERROR: bad sense spec \"" (string-intersperse sense " ") "\" params: " val-alist)
+ (let* (
+ ;; (action (alist-ref 'action val-alist))
+ (cron-safe-string (string-translate (string-intersperse (string-split crontab) "-") "*" "X"))
+ (runname std-runname)) ;; (conc "sched" (time->string (seconds->local-time (current-seconds)) "%M%H%d")))))
+ ;; (print "last-run: " last-run " need-run: " need-run)
+ ;; (if need-run
+ (case (string->symbol action)
+ ((sync sync-prepend)
+ (if (common:extended-cron crontab #f last-sync)
+ (push-run-spec torun contour runkey
+ `((message . ,(conc ruletype ":sync-" cron-safe-string))
+ (action . ,action)
+ (dbdest . ,dbdest)
+ (append . ,appendconf)
+ (areas . ,areas)))))
+ ((run)
+ (if (common:extended-cron crontab #f last-run)
+ (push-run-spec torun contour runkey
+ `((message . ,(conc ruletype ":" cron-safe-string))
+ (runname . ,runname)
+ (runtrans . ,runtrans)
+ (action . ,action)
+ (areas . ,areas)
+ (target . ,target)))))
+ ((remove)
+ (push-run-spec torun contour runkey
+ `((message . ,(conc ruletype ":" cron-safe-string))
+ (runname . ,runname)
+ (runtrans . ,runtrans)
+ (action . ,action)
+ (areas . ,areas)
+ (target . ,target))))
+ (else
+ (print "ERROR: action \"" action "\" has no scheduled handler")
+ )))))
+
+
+ ;; script based sensors
+ ;;
+ ((script)
+ ;; syntax is a little different here. It is a list of commands to run, "scriptname = extra_parameters;scriptname = ..."
+ ;; where scriptname may be repeated multiple times. The script must return unix-epoch of last change, new-target-name and new-run-name
+ ;; the script is called like this: scriptname contour runkey std-runname action extra_param1 extra_param2 ...
+ (for-each
+ (lambda (cmd)
+ (print "cmd: " cmd)
+ (let* ((script (car cmd))
+ (params (cdr cmd))
+ (cmd (conc script " " contour " " runkey " " std-runname " " action " " params))
+ (res (handle-exceptions
+ exn
+ #f
+ (print "Running " cmd)
+ (with-input-from-pipe cmd read-lines))))
+ (if (and res (not (null? res)))
+ (let* ((parts (string-split (car res))) ;;
+ (rem-lines (cdr res))
+ (num-parts (length parts))
+ (last-change (string->number (if (> num-parts 0)(car parts) "abc"))) ;; force no run if not a number returned
+ (new-target (if (> num-parts 1)
+ (cadr parts)
+ runkey))
+ (new-runname (if (> num-parts 2)
+ (caddr parts)
+ std-runname))
+ (message (if (null? rem-lines)
+ cmd
+ (string-intersperse rem-lines "-")))
+ (need-run (> last-change last-run)))
+ (print "last-run: " last-run " need-run: " need-run)
+ (if need-run
+ (let* ((key-msg `((message . ,(conc ruletype ":" message))
+ (runname . ,new-runname)
+ (runtrans . ,runtrans)
+ (action . ,action)
+ (areas . ,areas)
+ ;;(target . ,(list new-target)) ;; overriding with result from runing the script
+ )))
+ (print "key-msg: " key-msg)
+ (push-run-spec torun contour
+ (if optional ;; we need to be able to differentiate same contour, different behavior.
+ (conc runkey ":" optional) ;; NOTE: NOT COMPLETELY IMPLEMENTED. DO NOT USE
+ runkey)
+ key-msg)))))))
+ val-alist)) ;; iterate over the param split by ;\s*
+
+ ;; script based sensors
+ ;;
+ ((area-script)
+ ;; syntax is a little different here. It is a list of commands to run, "scriptname = extra_parameters;scriptname = ..."
+ ;; where scriptname may be repeated multiple times. The script must return unix-epoch of last change, new-target-name and new-run-name
+ ;; the script is called like this: scriptname contour runkey std-runname action extra_param1 extra_param2 ...
+ (for-each
+ (lambda (cmd)
+ ;;(print "cmd: " cmd)
+ ;;(print "Areas: " all-areas)
+ (for-each
+ (lambda (area)
+ ;;(print "Area: " area)
+ ;;(print "Target: " runkey)
+ ;;(print "OR: " (or (string->number (if (configf:lookup mtconf "setup" "max_packets_per_run") (configf:lookup mtconf "setup" "max_packets_per_run") "10000" ))))
+ ;;(print "Packets generated: " packets-generated)
+ ;;(print "Comparison: " (< packets-generated 4))
+ ;;(print "Full Comparison: "
+ ;; (and (< packets-generated (or (string->number (if (configf:lookup mtconf "setup" "max_packets_per_run") (configf:lookup mtconf "setup" "max_packets_per_run") "10000" )) 10000))
+ ;; (if (args:get-arg "-target")
+ ;; (if (string= (args:get-arg "-target") runkey) (area-allowed? area "area-needs-to-be-run" runkey contour #f) #f)
+ ;; (area-allowed? area "area-needs-to-be-run" runkey contour #f))))
+ ;;(print "Area Allowed: " (area-allowed? area "area-needs-to-be-run" runkey contour #f))
+;Add code to check whether area is valid
+ (if
+ ;; This code checks whether the target has been passed in via argument, and only runs the specified target
+ (and (< packets-generated (or (string->number (if (configf:lookup mtconf "setup" "max_packets_per_run") (configf:lookup mtconf "setup" "max_packets_per_run") "10000" )) 10000))
+ (if (args:get-arg "-target")
+ (if (string= (args:get-arg "-target") runkey) (area-allowed? area "area-needs-to-be-run" runkey contour #f) #f)
+ (area-allowed? area "area-needs-to-be-run" runkey contour #f)))
+
+ (let* ((script (car cmd))
+ (params (cdr cmd))
+ (cmd (conc script " " contour " " area " " runkey " " std-runname " " action " " params))
+ (res (handle-exceptions
+ exn
+ #f
+ (print "Running " cmd)
+ (with-input-from-pipe cmd read-lines)))
+ (cval (or (configf:lookup mtconf "contours" contour) ""))
+ (cval-alist (common:val->alist cval)) ;; BEWARE ... NOT the same val-alist as above!
+ ;;(areas (val-alist->areas cval-alist))
+ (selector (alist-ref 'selector cval-alist))
+ (mode-tag (and selector (string-split-fields "/" selector #:infix)))
+ (mode-patt (and mode-tag (if (eq? (length mode-tag) 2)(cadr mode-tag) #f)))
+ (tag-expr (and mode-tag (if (null? mode-tag) #f (car mode-tag))))
+ )
+ (if (and res (not (null? res)))
+ (let* ((parts (string-split (car res))) ;;
+ (rem-lines (cdr res))
+ (num-parts (length parts))
+ (last-change (string->number (if (> num-parts 0)(car parts) "abc"))) ;; force no run if not a number returned
+ (new-target (if (> num-parts 1)
+ (cadr parts)
+ runkey))
+ (new-runname (if (> num-parts 2)
+ (caddr parts)
+ std-runname))
+ (area-pkts (find-pkts pdb '(runstart) `((c . ,contour)
+ (t . ,runkey)
+ (G . ,area ))))
+ (runstarts (filter (lambda (my-pkt)
+ ;;(print my-pkt)
+ (not (contains (map
+ (lambda (c)
+ ;;(print "C: " c "PKT: " my-pkt)
+ (let* ((ctype (car c))
+ (rx (cdr c))
+ ;;(foo2 (print "Ctype: " ctype " RX: " rx))
+ (pkt (alist-ref 'pkt my-pkt))
+ (apkt (pkt->alist pkt))
+ (cdat (alist-ref ctype apkt)))
+ (if rx
+ (if (string-match "t" (symbol->string ctype) )
+ (begin (if #f (print "RX: " rx " CDAT: " (string-join (take (string-split cdat "/") 3) "/"))) (if cdat (string-match rx (string-join (take (string-split cdat "/") 3) "/")) #f))
+ (begin (if #f (print "RX: " rx " CDAT: " cdat)) (if cdat (string-match rx cdat) #f))) #f)
+
+ ))
+ `((c . ,contour) (t . ,runkey) (G . ,area))) #f)))
+ area-pkts))
+
+ ;;(test (pp runstarts))
+ (rspkts (common:get-pkt-alists runstarts))
+ ;; starttimes is for run start times and is used to know when the last run was launched
+ (starttimes (common:get-pkt-times rspkts)) ;; sort by age (youngest first) and delete duplicates by target
+ (last-run (if (null? starttimes) ;; if '() then it has never been run, else get the max
+ 0
+ (apply max (map cdr starttimes))))
+
+ ;; (last-run 9) ;; I think we can do a more valid calculation for this based on the run started packets for this particular area and target
+ (reason "Area-script-triggered")
+ ;;(mode-patt #f)
+ ;;(tag-expr #f)
+ (sched #f)
+ (message (if (null? rem-lines)
+ cmd
+ (string-intersperse rem-lines "-")))
+ (need-run (> last-change last-run)))
+ (print "last-change: " last-change " last-run: " last-run " need-run: " need-run)
+ (if need-run
+ (let* ((key-msg `((message . ,(conc ruletype ":" message))
+ (runname . ,new-runname)
+ (runtrans . ,runtrans)
+ (action . ,action)
+ (areas . ,area)
+ ;;(target . ,(list new-target)) ;; overriding with result from runing the script
+ ))
+ (aval (or (configf:lookup mtconf "areas" area) ""))
+ (aval-alist (common:val->alist aval))
+
+ (targets (map-targets mtconf aval-alist runkey area contour)))
+ (pp targets)
+ (for-each (lambda (target)
+ (create-run-pkt mtconf action area runkey target new-runname mode-patt
+ tag-expr pktsdir reason contour sched dbdest append
+ runtrans)
+ (set! packets-generated (+ packets-generated 1))
+ ) targets)
+ ;; Add filter for targets
+
+ ;;(create-run-pkt mtconf action area runkey target runname
+ ;; pktsdir reason contour dbdest append
+ ;; runtrans)
+ (print "key-msg: " key-msg)
+ ;;(push-run-spec torun contour
+ ;; (if optional ;; we need to be able to differentiate same contour, different behavior.
+ ;; (conc runkey ":" optional) ;; NOTE: NOT COMPLETELY IMPLEMENTED. DO NOT USE
+ ;; runkey)
+ ;; key-msg)
+ )))))
+ (if (>= packets-generated (string->number (configf:lookup mtconf "setup" "max_packets_per_run"))) (print "Skipping area: " area " and target: " runkey " due to packets-generated: " packets-generated " higher than " (configf:lookup mtconf "setup" "max_packets_per_run"))))
+
+ ) (filter (lambda (x) (if (not (args:get-arg "-area")) #t (if (string= x (args:get-arg "-area")) #t #f))) all-areas))
+ ) val-alist)) ;; iterate over the param split by ;\s*
+
+ ;; fossil scm based triggers
+ ;;
+ ((fossil)
+ (for-each
+ (lambda (fspec)
+ (print "fspec: " fspec)
+ (let* ((url (symbol->string (car fspec))) ;; THIS COULD BE TROUBLE. Add option to reading line to return as string.
+ (branch (cdr fspec))
+ (url-is-file (string-match "^(/|file:).*$" url))
+ (fname (conc (common:get-signature url) ".fossil"))
+ (fdir (conc "/tmp/" (current-user-name) "/mtutil_cache")))
+ ;; (if (not url-is-file) ;; need to sync first --- for now, clone 'em all.
+ (fossil:clone-or-sync url fname fdir) ;; )
+ (let-values (((datetime node)
+ (fossil:last-change-node-and-time fdir fname branch)))
+ (if (null? starttimes)
+ (push-run-spec torun contour runkey
+ `((message . ,(conc "fossil:" branch "-neverrun"))
+ (runname . ,(conc runname "-" node))
+ (runtrans . ,runtrans)
+ (areas . ,areas)
+ ;; (target . ,runkey)
+ (action . ,action)
+ ))
+ (if (> datetime last-run) ;; change time is greater than last-run time
+ (push-run-spec torun contour runkey
+ `((message . ,(conc "fossil:" branch "-" node))
+ (runname . ,(conc runname "-" node))
+ (runtrans . ,runtrans)
+ (areas . ,areas)
+ ;; (target . ,runkey)
+ (action . ,action)
+ (branch . ,branch)
+ (url . ,url)
+ (clone . ,(conc fdir "/" fname))
+ ))))
+ (print "Got datetime=" datetime " node=" node))))
+ val-alist))
+
+ ;; sensor looking for one or more files newer than reference
+ ;;
+ ((file file-or) ;; one or more files must be newer than the reference
+ (let* ((youngestdat (common:get-youngest (common:bash-glob file-globs)))
+ (youngestmod (car youngestdat)))
+ ;; (print "youngestmod: " youngestmod " starttimes: " starttimes)
+ (if (null? starttimes) ;; this target has never been run
+ (push-run-spec torun contour runkey
+ `((message . "file:neverrun")
+ (action . ,action)
+ (runtrans . ,runtrans)
+ ;; (target . ,runkey)
+ (areas . ,areas)
+ (runname . ,runname)))
+ ;; (for-each
+ ;; (lambda (starttime) ;; look at the time the last run was kicked off for this contour
+ ;; (if (> youngestmod (cdr starttime))
+ ;; (begin
+ ;; (print "starttime younger than youngestmod: " starttime " Youngestmod: " youngestmod)
+ (if (> youngestmod last-run)
+ (push-run-spec torun contour runkey
+ `((message . ,(conc ruletype ":" (cadr youngestdat)))
+ (action . ,action)
+ ;; (target . ,runkey)
+ (runtrans . ,runtrans)
+ (areas . ,areas)
+ (runname . ,runname)
+ ))))))
+
+ ;; all globbed files must be newer than the reference
+ ;;
+ ((file-and) ;; all files must be newer than the reference
+ (let* ((youngestdat (common:get-youngest file-globs))
+ (youngestmod (car youngestdat))
+ (success #t)) ;; any cases of not true, set flag to #f for AND
+ ;; (print "youngestmod: " youngestmod " starttimes: " starttimes)
+ (if (null? starttimes) ;; this target has never been run
+ (push-run-spec torun contour runkey
+ `((message . "file:neverrun")
+ (runname . ,runname)
+ (runtrans . ,runtrans)
+ (areas . ,areas)
+ ;; (target . ,runkey)
+ (action . ,action)))
+ ;; NB// I think this is wrong. It should be looking at last-run only.
+ (if (> youngestmod last-run) ;; WAIT!! Shouldn't file-and be looking at the *oldest* file (thus all are younger than ...)
+
+ ;; (for-each
+ ;; (lambda (starttime) ;; look at the time the last run was kicked off for this contour
+ ;; (if (< youngestmod (cdr starttime))
+ ;; (set! success #f)))
+ ;; starttimes))
+ ;; (if success
+ ;; (begin
+ ;; (print "starttime younger than youngestmod: " starttime " Youngestmod: " youngestmod)
+ (push-run-spec torun contour runkey
+ `((message . ,(conc ruletype ":" (cadr youngestdat)))
+ (runname . ,runname)
+ (runtrans . ,runtrans)
+ ;; (target . ,runkey)
+ (areas . ,areas)
+ (action . ,action)
+ ))))))
+ (else (print "ERROR: unrecognised rule \"" ruletype)))))
+ keydats))) ;; sense rules
+ (hash-table-keys rgconf))
+
+ ;; now have to run populated
+ (for-each
+ (lambda (contour)
+ (let* ((cval (or (configf:lookup mtconf "contours" contour) ""))
+ (cval-alist (common:val->alist cval)) ;; BEWARE ... NOT the same val-alist as above!
+ (areas (val-alist->areas cval-alist))
+ (selector (alist-ref 'selector cval-alist))
+ (mode-tag (and selector (string-split-fields "/" selector #:infix)))
+ (mode-patt (and mode-tag (if (eq? (length mode-tag) 2)(cadr mode-tag) #f)))
+ (tag-expr (and mode-tag (if (null? mode-tag) #f (car mode-tag)))))
+ (print "contour: " contour " areas=" areas " cval=" cval)
+ (for-each
+ (lambda (runkeydatset)
+ ;; (print "runkeydatset: ")(pp runkeydatset)
+ (let ((runkey (car runkeydatset))
+ (runkeydats (cadr runkeydatset))
+ )
+ (for-each
+ (lambda (runkeydat)
+ (for-each
+ (lambda (area)
+ (if (area-allowed? area areas runkey contour mode-patt) ;; is this area to be handled (from areas=a,b,c OR using areafn=abcfn and *area-checks* ...)
+ (let* ((aval (or (configf:lookup mtconf "areas" area) ""))
+ (aval-alist (common:val->alist aval))
+ (runname (alist-ref 'runname runkeydat))
+ (runtrans (alist-ref 'runtrans runkeydat))
+
+ (reason (alist-ref 'message runkeydat))
+ (sched (alist-ref 'sched runkeydat))
+ (action (alist-ref 'action runkeydat))
+ (dbdest (alist-ref 'dbdest runkeydat))
+ (append (alist-ref 'append runkeydat))
+ (targets ;;(or (alist-ref 'target runkeydat)
+ (map-targets mtconf aval-alist runkey area contour))) ;; override with target if forced
+ ;;(targets (or (alist-ref 'target runkeydat)
+ ;; (map-targets mtconf aval-alist runkey area contour)))) ;; override with target if forced
+ ;; NEED TO EXPAND RUNKEY => ALL TARGETS MAPPED AND THEN FOREACH ....
+ ;;(print "Targets: " targets)
+ ;;(print "alist: " (alist-ref 'target runkeydat))
+ (for-each
+ (lambda (target)
+ (print "Creating pkt for runkey=" runkey " target=" target " contour=" contour " area=" area " action=" action " tag-expr=" tag-expr " mode-patt=" mode-patt)
+ (if (case (or (and action (string->symbol action)) 'noaction) ;; ensure we have the needed data to run this action
+ ((noaction) #f)
+ ((run) (and runname reason))
+ ((sync sync-prepend) (and reason dbdest))
+ (else #f))
+ ;; instead of unwrapping the runkeydat alist, pass it directly to create-run-pkt
+ (create-run-pkt mtconf action area runkey target runname mode-patt
+ tag-expr pktsdir reason contour sched dbdest append
+ runtrans)
+ (print "ERROR: Missing info to make a " action " call: runkey=" runkey " contour=" contour " area=" area " tag-expr=" tag-expr " mode-patt=" mode-patt " dbdest=" dbdest)
+ ))
+ targets))
+ (print "NOTE: skipping " runkeydat " for area \"" area "\", not in " areas)))
+ all-areas))
+ runkeydats)))
+ (let ((res (configf:get-section torun contour))) ;; each contour / target
+ ;; (print "res=" res)
+ res))))
+ (hash-table-keys torun)))))))
+
+(define (pkt->cmdline pkta)
+ (let* ((param-mapping-alist (common:get-param-mapping flavor: 'switch-symbol))
+ (action (or (lookup-action-by-key (alist-ref 'A pkta)) "noaction"))
+ (action-param (case (string->symbol action)
+ ((-set-state-status) (conc (alist-ref 'l pkta) " "))
+ (else ""))))
+ (fold (lambda (a res)
+ (let* ((key (car a)) ;; get the key name
+ (val (cdr a))
+ (par (or (lookup-param-by-key key) ;; need to check also if it is a switch
+ (lookup-param-by-key key inlst: *switch-keys*))))
+ (print "key: " key " val: " val " par: " par)
+ ;;(if (and par (not (string= (symbol->string key) "G")))
+ (if (and par)
+ (conc res " " (alist-ref (string->symbol par) param-mapping-alist eq? par) " " val)
+ (if (alist-ref key *additional-cards*) ;; these cards do not translate to parameters or switches
+ res
+ (begin
+ (print "ERROR: Unknown key in packet \"" key "\" with value \"" val "\"")
+ res)))))
+ (conc "megatest " (if (not (member action '("sync")))
+ (conc action " " action-param)
+ "") (if (member action '("-run" "-rerun-clean" "-rerun-all" "-kill-rerun"))
+ "-rerun DEAD,ABORT,KILLED"
+ ""))
+ pkta)))
+
+;; (use trace)(trace pkt->cmdline)
+
+(define (write-pkt pktsdir uuid pkt)
+ (if pktsdir
+ (with-output-to-file
+ (conc pktsdir "/" uuid ".pkt")
+ (lambda ()
+ (print pkt)))
+ (print "ERROR: cannot process commands without a pkts directory")))
+
+(define (check-if-modepatt-defined pkta notification-hook pktfile)
+ (let* ((start-dir (alist-ref 'S pkta))
+ (target (or (alist-ref 'R pkta) (alist-ref 't pkta)))
+ (patt (alist-ref 'o pkta))
+ (uuid (alist-ref 'Z pkta))
+ (cmd (conc "megatest -show-runconfig -target " target " -start-dir " start-dir))
+ (res (handle-exceptions
+ exn
+ #f
+ (print "Running " cmd)
+ (with-input-from-pipe cmd read-lines))))
+ (let loop ((hed (car res))
+ (tail (cdr res)))
+ (if (string-contains hed patt)
+ #t
+ (if (null? tail)
+ (begin
+ (if notification-hook
+ (let* ((notification-cmd (conc notification-hook " --pkt " pktfile " --msg INVALID_MODEPATT")))
+ (print "Running " notification-cmd)
+ (system notification-cmd)))
+ #f)
+ (loop (car tail) (cdr tail)))))))
+
+(define (check-if-target-defined pkta notification-hook pktfile)
+ (let* ((start-dir (alist-ref 'S pkta))
+ (target (alist-ref 'R pkta))
+ (uuid (alist-ref 'Z pkta))
+ (cmd (conc "megatest -list-targets -start-dir " start-dir))
+ (res (handle-exceptions
+ exn
+ #f
+ (print "Running " cmd)
+ (with-input-from-pipe cmd read-lines))))
+ (if (member target res)
+ #t
+ (begin
+ (if notification-hook
+ (let* ((notification-cmd (conc notification-hook " --pkt " pktfile " --msg INVALID_TARGET")))
+ (print "Running " notification-cmd)
+ (system notification-cmd)))
+ #f))))
+
+
+(define (validate-cmd cmd pkta notification-hook pktfile)
+ (let ((ret #t))
+ (if (string-contains cmd "-reqtarg")
+ (if (check-if-target-defined pkta notification-hook pktfile)
+ (begin
+ (print "Target is valid")
+ (if (string-contains cmd "-modepatt")
+ (if (check-if-modepatt-defined pkta notification-hook pktfile)
+ (print "Modepatt is valid")
+ (set! ret #f))))
+ (set! ret #f))
+ (if (string-contains cmd "-modepatt")
+ (if (check-if-modepatt-defined pkta notification-hook pktfile)
+ (print "Modepatt is valid")
+ (set! ret #f))))
+ ret))
+
+
+;; collect all needed data and create run pkts for contours with changed inputs
+;;
+(define (dispatch-commands mtconf toppath)
+ ;; we are expecting a directory "logs", check and create it, create the log in /tmp if not able to create logs dir
+ (let ((logdir
+ (if (if (not (directory? "logs"))
+ (handle-exceptions
+ exn
+ #f
+ (create-directory "logs")
+ #t)
+ #t)
+ "logs"
+ "/tmp"))
+ (cpuload (alist-ref 'adj-proc-load (common:get-normalized-cpu-load #f)))
+ (maxload (string->number (or (configf:lookup mtconf "setup" "maxload")
+ (configf:lookup mtconf "jobtools" "maxload") ;; respect value used by Megatest calls
+ "1.1")))
+ (notification-hook (if (configf:lookup mtconf "setup" "notification-hook")
+ (configf:lookup mtconf "setup" "notification-hook")
+ #f)))
+ (common:with-queue-db
+ mtconf
+ (lambda (pktsdirs pktsdir pdb)
+ (let* ((rgconfdat (find-and-read-config (conc toppath "/runconfigs.config")))
+ (rgconf (car rgconfdat))
+ (areas (configf:get-section mtconf "areas"))
+ (contours (configf:get-section mtconf "contours"))
+ (pkts (find-pkts pdb '(cmd) '()))
+ (torun (make-hash-table)) ;; target => ( ... info ... )
+ (rgentargs (hash-table-keys rgconf))) ;; these are the targets registered for automatically triggering
+ (sqlite3:set-busy-handler! (dbi:db-conn pdb) (sqlite3:make-busy-timeout 10000))
+ (for-each
+ (lambda (pktdat)
+ (let* ((pkta (alist-ref 'apkt pktdat))
+ (action (alist-ref 'A pkta))
+ (cmdline (pkt->cmdline pkta))
+ (uuid (alist-ref 'Z pkta))
+ (user (alist-ref 'U pkta))
+ (area (alist-ref 'G pkta))
+ (logf (conc logdir "/" uuid "-run.log"))
+ (pktfile (conc pktsdir "/" uuid ".pkt"))
+ (fullcmd (conc "NBFAKE_LOG=" logf " nbfake " cmdline)))
+ (if (check-access user mtconf action area)
+ (if (and (> cpuload maxload)
+ (member action '("run" "archive"))) ;; do not run archive or run if load is over the specified limit
+ (begin
+ (print "WARNING: cpuload too high, skipping processing of " uuid " due to " cpuload " > " maxload)
+ (if notification-hook
+ (let* ((notification-cmd (conc notification-hook " --pkt " pktfile " --msg HIGH_LOAD")))
+ (print "Running " notification-cmd)
+ (system notification-cmd))))
+ (begin
+ ;; if modepatt used chek if it is defined for the target. If -reqtarg check if target exist.
+ (if (validate-cmd fullcmd pkta notification-hook pktfile)
+ (begin
+ (print "RUNNING: " fullcmd)
+ (system fullcmd) ;; replace with process ...
+ (mark-processed pdb (list (alist-ref 'id pktdat)))
+ (let-values (((ack-uuid ack-pkt)
+ (add-z-card
+ (construct-sdat 'P uuid
+ 'T (case (string->symbol action)
+ ((run) "runstart")
+ ((sync) "syncstart") ;; example of translating run -> runstart
+ (else action))
+ 'G (alist-ref 'G pkta)
+ 'c (alist-ref 'c pkta) ;; THIS IS WRONG! SHOULD BE 'c
+ 't (alist-ref 't pkta)))))
+ (write-pkt pktsdir ack-uuid ack-pkt))
+ (if notification-hook
+ (let* ((notification-cmd (conc notification-hook " --pkt " pktfile " --msg RUN_LAUNCHED --contour " (caar contours) " --log_path " logf )))
+ (print "Running " notification-cmd)
+ (system notification-cmd))))
+ (begin
+ (mark-processed pdb (list (alist-ref 'id pktdat)))
+ (let-values (((ack-uuid ack-pkt)
+ (add-z-card
+ (construct-sdat 'P uuid
+ 'T "invalid-input"
+ 'c (alist-ref 'o pkta) ;; THIS IS WRONG! SHOULD BE 'c
+ 't (alist-ref 't pkta)))))
+ (write-pkt pktsdir ack-uuid ack-pkt))))))
+ (begin ;; access denied! Mark as such
+ (mark-processed pdb (list (alist-ref 'id pktdat)))
+ (let-values (((ack-uuid ack-pkt)
+ (add-z-card
+ (construct-sdat 'P uuid
+ 'T "access-denied"
+ 'c (alist-ref 'o pkta) ;; THIS IS WRONG! SHOULD BE 'c
+ 't (alist-ref 't pkta)))))
+ (write-pkt pktsdir ack-uuid ack-pkt))
+ (if notification-hook
+ (let* ((notification-cmd (conc notification-hook " --pkt " pktfile " --msg ACCESS_DENIED")))
+ (print "Running " notification-cmd)
+ (system notification-cmd)))))))
+ pkts))))))
+
+
+(define (check-access user mtconf action area)
+ ;; NOTE: Need control over defaults. E.g. default might be no access
+ (let* ((access-ctrl (hash-table-exists? mtconf "access")) ;; if there is an access section the default is to REQUIRE enablement/access
+ (access-list (map (lambda (x)
+ (string-split x ":"))
+ (string-split (or (configf:lookup mtconf "access" area) ;; userid:rightstype userid2:rightstype2 ...
+ (if access-ctrl
+ "*:none" ;; nobody has access by default
+ "*:all")))))
+ (access-types-dat (configf:get-section mtconf "accesstypes")))
+ (debug:print 2 *default-log-port* "Checking access in " access-list " with access-ctrl " access-ctrl " for area " area)
+ (if access-ctrl
+ (let* ((user-access (or (assoc user access-list)
+ (assoc "*" access-list)))
+ (access-type (if user-access
+ (cadr user-access)
+ #f))
+ (access-types (let ((res (alist-ref access-type access-types-dat equal?)))
+ (if res (car res) res)))
+ (allowed-actions (string-split (or access-types ""))))
+ (debug:print 2 *default-log-port* "Got " allowed-actions " for user " user " where access-types=" access-types " access-type=" access-type)
+ (cond
+ ((and access-types (member action allowed-actions))
+ ;; (print "Access granted for " user " for " action)
+ #t)
+ (else
+ ;; (print "Access denied for " user " for " action)
+ #f))))))
+
+(define (open-logfile logpath)
+ (condition-case
+ (let* ((log-dir (or (pathname-directory logpath) ".")))
+ (if (not (directory-exists? log-dir))
+ (system (conc "mkdir -p " log-dir)))
+ (open-output-file logpath))
+ (exn ()
+ (debug:print-error 0 *default-log-port* "Could not open log file for write: "logpath)
+ (define *didsomething* #t)
+ (exit 1))))
+
+
+(define (get-pkts-dir mtconf)
+ (let ((pktsdirs (configf:lookup mtconf "setup" "pktsdirs"))
+ (pktsdir (if pktsdirs (car (string-split pktsdirs " ")) #f)))
+ pktsdir))
+
+(let ((debugcontrolf (conc (get-environment-variable "HOME") "/.mtutilrc")))
+ (if (common:file-exists? debugcontrolf)
+ (load debugcontrolf)))
+
+(if (args:get-arg "-log") ;; redirect the log always when a server
+ (handle-exceptions
+ exn
+ (begin
+ (print "ERROR: Failed to switch to log output. " ((condition-property-accessor 'exn 'message) exn))
+ )
+ (let* ((tl (args:get-arg "-log")) ;; run launch:setup if -server, ensure we do NOT run launch:setup if -log specified
+ (logf (args:get-arg "-log")) ;; use -log unless we are a server, then craft a logfile name
+ (oup (open-logfile logf)))
+ ;(if (not (args:get-arg "-log"))
+ ; (hash-table-set! args:arg-hash "-log" logf)) ;; fake out future queries of -log
+ (print *default-log-port* "Sending log output to " logf)
+ (set! *default-log-port* oup)
+)))
+
+(if *action*
+ (case (string->symbol *action*)
+ ((run remove rerun rerun-clean rerun-all set-ss archive kill list kill-run kill-rerun lock unlock)
+
+ (let* ((mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (area (args:get-arg "-area")) ;; look up the area to dispatch to from [areas] section
+ (areasec (if area (configf:lookup mtconf "areas" area) #f))
+ (areadat (if areasec (common:val->alist areasec) #f))
+ (area-path (if areadat (alist-ref 'path areadat) #f))
+ (pktsdirs (configf:lookup mtconf "setup" "pktsdirs"))
+ (pktsdir (if pktsdirs (car (string-split pktsdirs " ")) #f))
+ (adjargs (hash-table-copy args:arg-hash))
+ (new-ss (args:get-arg "-new")))
+ ;; check a few things
+ (cond
+ ((and area (not area-path))
+ (print "ERROR: the specified area was not found in the [areas] table. Area name=" area)
+ (exit 1))
+ ((not area)
+ (print "ERROR: no area specified. Use -area ")
+ (exit 1))
+ (else
+ (let* ((usr-admin (check-access (current-user-name) mtconf "override" area))
+ (user (if (and usr-admin (args:get-arg "-override-user"))
+ (args:get-arg "-override-user")
+ (current-user-name))))
+ ; (print "user 123 " usr-admin )
+ ;(exit 1)
+ (if (and (not usr-admin) (args:get-arg "-override-user"))
+ (begin
+ (print user " does not have access to override user")
+ (exit 1)))
+ (if (check-access user mtconf *action* area);; check rights
+ (print "Access granted for " *action* " action by " user)
+ (begin
+ (print "Access denied for " *action* " action by " user)
+ (exit 1))))))
+
+ ;; (for-each
+ ;; (lambda (key)
+ ;; (if (not (member key *legal-params*))
+ ;; (hash-table-delete! adjargs key))) ;; we need to delete any params intended for mtutil
+ ;; (hash-table-keys adjargs))
+ (let-values (((uuid pkt)
+ (command-line->pkt *action* adjargs #f area-path: area-path new-ss: new-ss)))
+ (print "run log @ " (conc (current-directory) "/" uuid "-" *action* ".log"))
+ (write-pkt pktsdir uuid pkt))))
+ ((dispatch import rungen process)
+ (let* ((mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (toppath (configf:lookup mtconf "scratchdat" "toppath")))
+ (case (string->symbol *action*)
+ ((process) (begin
+ (common:load-pkts-to-db mtconf)
+ (generate-run-pkts mtconf toppath)
+ (common:load-pkts-to-db mtconf)
+ (dispatch-commands mtconf toppath)))
+ ((import) (common:load-pkts-to-db mtconf)) ;; import pkts
+ ((rungen) (generate-run-pkts mtconf toppath))
+ ((dispatch) (dispatch-commands mtconf toppath)))))
+ ;; misc
+ ((show)
+ (if (> (length remargs) 0)
+ (let* ((mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (sect-dat (configf:get-section mtconf (car remargs))))
+ (if sect-dat
+ (for-each
+ (lambda (entry)
+ (if (> (length entry) 1)
+ (print (car entry) " " (cadr entry))
+ (print (car entry))))
+ sect-dat)
+ (print "No section \"" (car remargs) "\" found")))
+ (print "ERROR: list requires section parameter; areas, setup or contours")))
+ ((gendot)
+ (let* ((mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat)))
+ (common:load-pkts-to-db mtconf use-lt: #t) ;; need to NOT do this by default ...
+ (common:with-queue-db
+ mtconf
+ (lambda (pktsdirs pktsdir conn)
+ ;; pktspec display-fields
+ (make-report "out.dot" conn
+ '((cmd . ((parent . P)
+ (user . M)
+ (target . t)))
+ (runstart . ((parent . P)
+ (target . t)))
+ (runtype . ((parent . P)))) ;; pktspec
+ '(P U t) ;;
+ ))))) ;; no ptypes listed (ptypes are strings of pkt types to read from db
+ ((db)
+ (if (null? remargs)
+ (print "ERROR: missing sub command for db command")
+ (let ((subcmd (car remargs)))
+ (case (string->symbol subcmd)
+ ((pgschema)
+ (let* ((install-home (common:get-install-area))
+ (schema-file (conc install-home "/share/db/mt-pg.sql")))
+ (if (common:file-exists? schema-file)
+ (system (conc "/bin/cat " schema-file)))))
+ ((sqlite3schema)
+ (let* ((install-home (common:get-install-area))
+ (schema-file (conc install-home "/share/db/mt-sqlite3.sql")))
+ (if (common:file-exists? schema-file)
+ (system (conc "/bin/cat " schema-file)))))
+ ((junk)
+ (rmt:get-keys))))))
+ ((tsend)
+ (if (null? remargs)
+ (print "ERROR: missing data to send to trigger listeners")
+ (let* ((msg (car remargs))
+ (mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (time-out (if (args:get-arg "-time-out")
+ (string->number (args:get-arg "-time-out"))
+ 5))
+ (listeners (configf:get-section mtconf "listeners"))
+ (user-info (user-information (current-user-id)))
+ (prev-seen (make-hash-table))) ;; catch duplicates
+ (if user-info
+ (begin
+ (for-each
+ (lambda (listener)
+ (let ((host-port (car listener))
+ (attrib (val->alist (cadr listener))))
+ (if (and (equal? msg "time-to-die") (not (can-user-kill-listner user-info attrib)))
+ (begin
+ (debug:print-error 0 *default-log-port* "User " (car user-info) " is not allowed to send message '" msg"'")
+ (exit 1)))
+ (print "sending " msg " to " host-port )
+ (open-send-close-nn host-port msg attrib timeout: time-out )))
+ listeners))
+ (begin
+ (debug:print-error 0 *default-log-port* "Could not Identify executing user. Will not send any message")
+ (exit 1))))))
+ ((tquery)
+ (if (null? remargs)
+ (print "ERROR: missing data to send to trigger listeners")
+ (let* ((msg (car remargs))
+ (mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (time-out (if (args:get-arg "-time-out")
+ (string->number (args:get-arg "-time-out"))
+ 5))
+ (listeners (configf:get-section mtconf "listeners"))
+ (user-info (user-information (current-user-id)))
+ (prev-seen (make-hash-table))) ;; catch duplicates
+ (if user-info
+ (begin
+ (for-each
+ (lambda (listener)
+ (let ((host-port (car listener))
+ (attrib (val->alist (cadr listener))))
+ (if (and (equal? msg "time-to-die") (not (can-user-kill-listner user-info attrib)))
+ (begin
+ (debug:print-error 0 *default-log-port* "User " (car user-info) " is not allowed to send message '" msg"'")
+ (exit 1)))
+ (print "sending " msg " to " host-port )
+ (open-send-receive-nn host-port msg attrib timeout: time-out )))
+ listeners))
+ (begin
+ (debug:print-error 0 *default-log-port* "Could not Identify executing user. Will not send any message")
+ (exit 1))))))
+
+ ((tquerylisten)
+ (if (null? remargs)
+ (print "ERROR: useage for tlisten is \"mtutil tlisten portnum\"")
+ (let ((portnum (string->number (car remargs))))
+
+ (if (not portnum)
+ (print "ERROR: the portnumber parameter must be a number, you gave: " (car remargs))
+ (begin
+ (if (not (is-port-in-use portnum))
+ (let* ((rep (start-nn-server portnum))
+ (mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (contact (configf:lookup mtconf "listener" "owner"))
+ (script (configf:lookup mtconf "listener" "script")))
+ (print "Listening on port " portnum " for messages.")
+ (set-signal-handler! signal/int (lambda (signum)
+ (set! *time-to-exit* #t)
+ (debug:print-error 0 *default-log-port* "Received signal " signum " sending email befor exiting !!")
+ (let ((email-body (mtut:stml->string (s:body
+ (s:p (conc "Received signal " signum ". Lister has been terminated on host " (get-environment-variable "HOST") ". "))))))
+ (sendmail contact "Listner has been terminated." email-body use_html: #t))
+ (exit)))
+ (set-signal-handler! signal/term (lambda (signum)
+ (set! *time-to-exit* #t)
+ (debug:print-error 0 *default-log-port* "Received signal " signum " sending email befor exiting !!")
+ (let ((email-body (mtut:stml->string (s:body
+ (s:p (conc "Received signal " signum ". Lister has been terminated on host " (get-environment-variable "HOST") ". "))))))
+ (sendmail contact "Listner has been terminated." email-body use_html: #t))
+ (exit)))
+
+ ;(set-signal-handler! signal/term special-signal-handler)
+
+ (let loop ((instr (nn-recv rep)))
+ ;;(nn-send rep "3.9")
+ (with-input-from-pipe (conc "/usr/bin/uptime | cut -d':' -f4 | awk '{print $1}' | cut -d',' -f1")
+ (lambda()
+ (let loop ((inl (read-line)))
+ (if (not (eof-object? inl))
+ (begin
+ ;;(print "fdk73: " inl ":")
+ ;;(set! current-list-ciaf (append! current-list-ciaf (list (string-substitute "\\s+$" "" inl))))
+ (nn-send rep inl)
+ (loop(read-line)))
+ ))
+
+ )
+ )
+ ;;(print (isys "/usr/bin/uptime" foreach-stdout-thunk: foreach-stdout))
+ (let ((ctime (date->string (current-date))))
+ (if (equal? instr "time-to-die")
+ (begin
+ (debug:print 0 *default-log-port* ctime " received '" instr "'. Time to sucide." )
+ (let ((pid (current-process-id)))
+ (debug:print 0 *default-log-port* "Killing current process (pid=" pid ")")
+ (system (conc "kill " pid))))
+ (begin
+ (debug:print 0 *default-log-port* ctime " received " instr )
+ ;(nn-send rep "ok")
+ (if (not (equal? instr "ping"))
+ (begin
+ (debug:print 0 *default-log-port* ctime " running \"" script " " instr "\"")
+ ;(system (conc script " '" instr "'"))
+ (process-run script (list instr ))
+ (debug:print 0 *default-log-port* ctime " done" ))
+ (begin
+ (if (not (equal? instr "load"))
+ (print "Checking load")
+
+ )
+ )
+
+ )
+
+ )))
+ (loop (nn-recv rep))))
+ (print "ERROR: Port " portnum " already in use. Try another port")))))))
+
+
+
+
+ ((tlisten)
+ (if (null? remargs)
+ (print "ERROR: useage for tlisten is \"mtutil tlisten portnum\"")
+ (let ((portnum (string->number (car remargs))))
+
+ (if (not portnum)
+ (print "ERROR: the portnumber parameter must be a number, you gave: " (car remargs))
+ (begin
+ (if (not (is-port-in-use portnum))
+ (let* ((rep (start-nn-server portnum))
+ (mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (contact (configf:lookup mtconf "listener" "owner"))
+ (script (configf:lookup mtconf "listener" "script")))
+ (print "Listening on port " portnum " for messages.")
+ (set-signal-handler! signal/int (lambda (signum)
+ (set! *time-to-exit* #t)
+ (debug:print-error 0 *default-log-port* "Received signal " signum " sending email befor exiting !!")
+ (let ((email-body (mtut:stml->string (s:body
+ (s:p (conc "Received signal " signum ". Lister has been terminated on host " (get-environment-variable "HOST") ". "))))))
+ (sendmail contact "Listner has been terminated." email-body use_html: #t))
+ (exit)))
+ (set-signal-handler! signal/term (lambda (signum)
+ (set! *time-to-exit* #t)
+ (debug:print-error 0 *default-log-port* "Received signal " signum " sending email befor exiting !!")
+ (let ((email-body (mtut:stml->string (s:body
+ (s:p (conc "Received signal " signum ". Lister has been terminated on host " (get-environment-variable "HOST") ". "))))))
+ (sendmail contact "Listner has been terminated." email-body use_html: #t))
+ (exit)))
+
+ ;(set-signal-handler! signal/term special-signal-handler)
+
+ (let loop ((instr (nn-recv rep)))
+ (nn-send rep "ok")
+ (let ((ctime (date->string (current-date))))
+ (if (equal? instr "time-to-die")
+ (begin
+ (debug:print 0 *default-log-port* ctime " received '" instr "'. Time to sucide." )
+ (let ((pid (current-process-id)))
+ (debug:print 0 *default-log-port* "Killing current process (pid=" pid ")")
+ (system (conc "kill " pid))))
+ (begin
+ (debug:print 0 *default-log-port* ctime " received " instr )
+ ;(nn-send rep "ok")
+ (if (not (equal? instr "ping"))
+ (begin
+ (debug:print 0 *default-log-port* ctime " running \"" script " " instr "\"")
+ (system (conc script " '" instr "' &"))
+ ;(process-run script (list instr ))
+ (debug:print 0 *default-log-port* ctime " done" ))
+ (begin
+ (if (not (equal? instr "load"))
+ (print "Checking load")
+
+ )
+ )
+
+ )
+
+ )))
+ (loop (nn-recv rep))))
+ (print "ERROR: Port " portnum " already in use. Try another port")))))))
+ ((gather) ;; gather all area db's into /tmp/$USER_megatest/alldbs
+ (let* ((mtconfdat (simple-setup (args:get-arg "-start-dir")))
+ (mtconf (car mtconfdat))
+ (areas (get-area-names mtconf)))
+ (print "areas: " areas)))
+
+ (else
+ (let ((all-actions (sort (map conc (delete-duplicates (append *other-actions* (map car *action-keys*)))) string<=?)))
+ (print "unrecognised action: \"" *action* "\", try one of; \"" (string-intersperse all-actions "\", \"") "\"")))
+
+ )) ;; the end
+
+
+;; If HTTP_HOST is defined then we must be in the cgi environment
+;; so run stml and exit
+;;
+(if (get-environment-variable "HTTP_HOST")
+ (begin
+ (stml:main #f)
+ (exit)))
+
+(if (or (args:get-arg "-repl")
+ (args:get-arg "-load"))
+ (begin
+ (import extras) ;; might not be needed
+ ;; (import csi)
+ (import readline)
+ (import apropos)
+ ;; (import (prefix sqlite3 sqlite3:)) ;; doesn't work ...
+
+ (install-history-file (get-environment-variable "HOME") ".mtutil_history") ;; [homedir] [filename] [nlines])
+ (current-input-port (make-readline-port "mtutil> "))
+ (if (args:get-arg "-repl")
+ (repl)
+ (load (args:get-arg "-load")))))
+
+#|
+(define mtconf (car (simple-setup #f)))
+(define dat (common:with-queue-db mtconf (lambda (conn)(get-pkts conn '()))))
+(pp (pkts#flatten-all dat '((cmd . ((parent . P)(url . M)))(runtype . ((parent . P)))) 'id 'group-id 'uuid 'parent 'pkt-type 'pkt 'processed))
+|#
ADDED attic_modular/mutils.scm
Index: attic_modular/mutils.scm
==================================================================
--- /dev/null
+++ attic_modular/mutils.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit mutils))
+
+(include "mutils/mutils.scm")
ADDED attic_modular/newdashboard.scm
Index: attic_modular/newdashboard.scm
==================================================================
--- /dev/null
+++ attic_modular/newdashboard.scm
@@ -0,0 +1,755 @@
+;;======================================================================
+;; Copyright 2006-2016, 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 .
+
+;;======================================================================
+
+(use format)
+
+(use (prefix iup iup:))
+
+(use canvas-draw)
+(import canvas-draw-iup)
+
+(use sql-de-lite srfi-1 posix regex regex-case srfi-69 typed-records sparse-vectors ;; defstruct
+ (prefix dbi dbi:))
+
+(declare (uses common))
+(declare (uses megatest-version))
+(declare (uses margsmod))
+(import margsmod)
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses dbmod))
+(import dbmod)
+
+;; (declare (uses launch))
+;; (declare (uses gutils))
+;; (declare (uses db))
+;; (declare (uses server))
+;; (declare (uses synchash))
+(declare (uses dcommon))
+;; (declare (uses tree))
+;;
+;; (include "common_records.scm")
+;; (include "db_records.scm")
+;; (include "key_records.scm")
+
+(declare (uses configfmod))
+(import configfmod)
+
+
+(define help (conc
+"Megatest Dashboard, documentation at http://www.kiatoa.com/fossils/megatest
+ version " megatest-version "
+ license GPL, Copyright (C) Matt Welland 2011
+
+Usage: dashboard [options]
+ -h : this help
+ -server host:port : connect to host:port instead of db access
+ -test testid : control test identified by testid
+ -guimonitor : control panel for runs
+
+Misc
+ -rows N : set number of rows
+"))
+
+;; process args
+(define remargs (args:get-args
+ (argv)
+ (list "-rows"
+ "-run"
+ "-test"
+ "-debug"
+ "-host"
+ )
+ (list "-h"
+ "-guimonitor"
+ "-main"
+ "-v"
+ "-q"
+ )
+ args:arg-hash
+ 0))
+
+(if (args:get-arg "-h")
+ (begin
+ (print help)
+ (exit)))
+
+;; ease debugging by loading ~/.dashboardrc
+(let ((debugcontrolf (conc (get-environment-variable "HOME") "/.dashboardrc")))
+ (if (common:file-exists? debugcontrolf)
+ (load debugcontrolf)))
+
+(debug:setup)
+
+(define *tim* (iup:timer))
+(define *ord* #f)
+
+(iup:attribute-set! *tim* "TIME" 300)
+(iup:attribute-set! *tim* "RUN" "YES")
+
+(define (message-window msg)
+ (iup:show
+ (iup:dialog
+ (iup:vbox
+ (iup:label msg #:margin "40x40")))))
+
+(define (iuplistbox-fill-list lb items . default)
+ (let ((i 1)
+ (selected-item (if (null? default) #f (car default))))
+ (iup:attribute-set! lb "VALUE" (if selected-item selected-item ""))
+ (for-each (lambda (item)
+ (iup:attribute-set! lb (number->string i) item)
+ (if selected-item
+ (if (equal? selected-item item)
+ (iup:attribute-set! lb "VALUE" item))) ;; (number->string i))))
+ (set! i (+ i 1)))
+ items)
+ i))
+
+(define (pad-list l n)(append l (make-list (- n (length l)))))
+
+
+(define (mkstr . x)
+ (string-intersperse (map conc x) ","))
+
+(define (update-search x val)
+ (hash-table-set! *searchpatts* x val))
+
+
+;; data for each specific tab goes here
+;;
+(defstruct dboard:tabdat
+ ;; runs
+ ((allruns '()) : list) ;; list of dboard:rundat records
+ ((allruns-by-id (make-hash-table)) : hash-table) ;; hash of run-id -> dboard:rundat records
+ ((done-runs '()) : list) ;; list of runs already drawn
+ ((not-done-runs '()) : list) ;; list of runs not yet drawn
+ (header #f) ;; header for decoding the run records
+ (keys #f) ;; keys for this run (i.e. target components)
+ ((numruns (string->number (or (args:get-arg "-cols") "10"))) : number) ;;
+ ((tot-runs 0) : number)
+ ((last-data-update 0) : number) ;; last time the data in allruns was updated
+ ((last-runs-update 0) : number) ;; last time we pulled the runs info to update the tree
+ (runs-mutex (make-mutex)) ;; use to prevent parallel access to draw objects
+ ((run-update-times (make-hash-table)) : hash-table) ;; update times indexed by run-id
+ ((last-test-dat (make-hash-table)) : hash-table) ;; cache last tests dat by run-id
+ ((run-db-paths (make-hash-table)) : hash-table) ;; cache the paths to the run db files
+
+ ;; Runs view
+ ((buttondat (make-hash-table)) : hash-table) ;;
+ ((item-test-names '()) : list) ;; list of itemized tests
+ ((run-keys (make-hash-table)) : hash-table)
+ (runs-matrix #f) ;; used in newdashboard
+ ((start-run-offset 0) : number) ;; left-right slider value
+ ((start-test-offset 0) : number) ;; up-down slider value
+ ((runs-btn-height (or (configf:lookup *configdat* "dashboard" "btn-height") "x16")) : string) ;; was 12
+ ((runs-btn-fontsz (or (configf:lookup *configdat* "dashboard" "btn-fontsz") "10")) : string) ;; was 8
+ ((runs-cell-width (or (configf:lookup *configdat* "dashboard" "cell-width") "60")) : string) ;; was 50
+ ((all-test-names '()) : list)
+
+ ;; Canvas and drawing data
+ (cnv #f)
+ (cnv-obj #f)
+ (drawing #f)
+ ((run-start-row 0) : number)
+ ((max-row 0) : number)
+ ((running-layout #f) : boolean)
+ (originx #f)
+ (originy #f)
+ ((layout-update-ok #t) : boolean)
+ ((compact-layout #t) : boolean)
+
+ ;; Run times layout
+ ;; (graph-button-box #f) ;; RA => Think it is not referenced anywhere
+ (graph-matrix #f)
+ ((graph-matrix-table (make-hash-table)) : hash-table) ;; graph-dats referenced thru graph name info
+ ((graph-cell-table (make-hash-table)) : hash-table) ;; graph-dats referenced thru matrix cell info
+ ((graph-matrix-row 1) : number)
+ ((graph-matrix-col 1) : number)
+
+ ;; Controls used to launch runs etc.
+ ((command "") : string) ;; for run control this is the command being built up
+ (command-tb #f) ;; widget for the type of command; run, remove-runs etc.
+ (test-patterns-textbox #f) ;; text box widget for editing a list of test patterns
+ (key-listboxes #f)
+ (key-lbs #f)
+ run-name ;; from run name setting widget
+ states ;; states for -state s1,s2 ...
+ statuses ;; statuses for -status s1,s2 ...
+
+ ;; Selector variables
+ curr-run-id ;; current row to display in Run summary view
+ prev-run-id ;; previous runid selected before current runid was selected (used in xor-two-runs runs summary mode
+ curr-test-ids ;; used only in dcommon:run-update which is used in newdashboard
+ ((filters-changed #t) : boolean) ;; to indicate that the user changed filters for this tab
+ ((last-filter-str "") : string) ;; conc the target runname and testpatt for a signature of changed filters
+ ((hide-empty-runs #f) : boolean)
+ ((hide-not-hide #t) : boolean) ;; toggle for hide/not hide empty runs
+ (hide-not-hide-button #f)
+ ((searchpatts (make-hash-table)) : hash-table) ;;
+ ((state-ignore-hash (make-hash-table)) : hash-table) ;; hash of STATE => #t/#f for display control
+ ((status-ignore-hash (make-hash-table)) : hash-table) ;; hash of STATUS => #t/#f
+ (target #f)
+ (test-patts #f)
+
+ ;; db info to file the .db files for the area
+ (access-mode (db:get-access-mode)) ;; use cached db or not
+ (dbdir #f)
+ (dbfpath #f)
+ (dbkeys #f)
+ ((last-db-update (make-hash-table)) : hash-table) ;; last db file timestamp
+ (monitor-db-path #f) ;; where to find monitor.db
+ ro ;; is the database read-only?
+
+ ;; tests data
+ ((num-tests 10) : number) ;; total number of tests to show (used in the old runs display)
+
+ ;; runs tree
+ ((path-run-ids (make-hash-table)) : hash-table) ;; path (target / runname) => id
+ (runs-tree #f)
+ ((runs-tree-ht (make-hash-table)) : hash-table) ;; track which targets added to tree (merge functionality with path-run-ids?)
+
+ ;; tab data
+ ((view-changed #t) : boolean)
+ ((xadj 0) : number) ;; x slider number (if using canvas)
+ ((yadj 0) : number) ;; y slider number (if using canvas)
+ ;; runs-summary tab state
+ ((runs-summary-modes '((one-run . "Show One Run") (xor-two-runs . "XOR Two Runs") (xor-two-runs-hide-clean . "XOR; Hide Clean")) ) : list)
+ ((runs-summary-mode-buttons '()) : list)
+ ((runs-summary-mode 'one-run) : symbol)
+ ((runs-summary-mode-change-callbacks '()) : list)
+ (runs-summary-source-runname-label #f)
+ (runs-summary-dest-runname-label #f)
+ ;; runs summary view
+
+ tests-tree ;; used in newdashboard
+ )
+
+
+
+;; mtest is actually the megatest.config file
+;;
+(define (mtest toppath window-id)
+ (let* ((curr-row-num 0)
+ ;; (rawconfig (read-config (conc toppath "/megatest.config") #f 'return-string))
+ (keys-matrix (iup:matrix)) ;; (dcommon:keys-matrix rawconfig))
+ (setup-matrix (iup:matrix)) ;; (dcommon:section-matrix rawconfig "setup" "Varname" "Value"))
+ (jobtools-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 5
+ #:numcol-visible 1
+ #:numlin-visible 3))
+ (validvals-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 2
+ #:numcol-visible 1
+ #:numlin-visible 2))
+ (envovrd-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 20
+ #:numcol-visible 1
+ #:numlin-visible 8))
+ (disks-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 20
+ #:numcol-visible 1
+ #:numlin-visible 8))
+ )
+ (iup:attribute-set! disks-matrix "0:0" "Disk Name")
+ (iup:attribute-set! disks-matrix "0:1" "Disk Path")
+ (iup:attribute-set! disks-matrix "WIDTH1" "120")
+ (iup:attribute-set! disks-matrix "WIDTH0" "100")
+ (iup:attribute-set! disks-matrix "ALIGNMENT1" "ALEFT")
+ (iup:attribute-set! disks-matrix "FIXTOTEXT" "C1")
+ (iup:attribute-set! disks-matrix "RESIZEMATRIX" "YES")
+
+ ;; fill in existing info
+ (for-each
+ (lambda (mat fname)
+ (set! curr-row-num 1)
+ (for-each
+ (lambda (var)
+ (iup:attribute-set! mat (conc curr-row-num ":0") var)
+ ;; (iup:attribute-set! mat (conc curr-row-num ":1") (config-lookup rawconfig fname var))
+ (set! curr-row-num (+ curr-row-num 1)))
+ '()));; (configf:section-vars rawconfig fname)))
+ (list setup-matrix jobtools-matrix validvals-matrix envovrd-matrix disks-matrix)
+ (list "setup" "jobtools" "validvalues" "env-override" "disks"))
+
+ (for-each
+ (lambda (mat)
+ (iup:attribute-set! mat "0:1" "Value")
+ (iup:attribute-set! mat "0:0" "Var")
+ (iup:attribute-set! mat "ALIGNMENT1" "ALEFT")
+ (iup:attribute-set! mat "FIXTOTEXT" "C1")
+ (iup:attribute-set! mat "RESIZEMATRIX" "YES")
+ (iup:attribute-set! mat "WIDTH1" "120")
+ (iup:attribute-set! mat "WIDTH0" "100")
+ )
+ (list setup-matrix jobtools-matrix validvals-matrix envovrd-matrix))
+
+ (iup:attribute-set! validvals-matrix "WIDTH1" "290")
+ (iup:attribute-set! envovrd-matrix "WIDTH1" "290")
+
+ (iup:vbox
+ (iup:hbox
+
+ (iup:vbox
+ (let ((tabs (iup:tabs
+ ;; The required tab
+ (iup:hbox
+ ;; The keys
+ (iup:frame
+ #:title "Keys (required)"
+ (iup:vbox
+ (iup:label (conc "Set the fields for organising your runs\n"
+ "here. Note: can only be changed before\n"
+ "running the first run when megatest.db\n"
+ "is created."))
+ keys-matrix))
+ (iup:vbox
+ ;; The setup section
+ (iup:frame
+ #:title "Setup"
+ (iup:vbox
+ (iup:label (conc "max_concurrent_jobs : limits total concurrent jobs (optional)\n"
+ "linktree : directory where linktree will be created."))
+ setup-matrix))
+ ;; The jobtools
+ (iup:frame
+ #:title "Jobtools"
+ (iup:vbox
+ (iup:label (conc "launcher : tool or script to run jobs (try nbfake)\n"
+ "useshell : use system to run your launcher\n"
+ "workhosts : spread jobs out on these hosts"))
+ jobtools-matrix))
+ ;; The disks
+ (iup:frame
+ #:title "Disks"
+ (iup:vbox
+ (iup:label (conc "Enter names and existing paths of locations to run tests"))
+ disks-matrix))))
+ ;; The optional tab
+ (iup:vbox
+ ;; The Environment Overrides
+ (iup:frame
+ #:title "Env override"
+ envovrd-matrix)
+ ;; The valid values
+ (iup:frame
+ #:title "Validvalues"
+ validvals-matrix)
+ ))))
+ (iup:attribute-set! tabs "TABTITLE0" "Required settings")
+ (iup:attribute-set! tabs "TABTITLE1" "Optional settings")
+ tabs))
+ ))))
+
+;; The runconfigs.config file
+;;
+(define (rconfig window-id)
+ (iup:vbox
+ (iup:frame #:title "Default")))
+
+;;======================================================================
+;; T E S T S
+;;======================================================================
+
+(define (tree-path->test-id path)
+ (if (not (null? path))
+ (hash-table-ref/default (dboard:data-path-test-ids *data*) path #f)
+ #f))
+
+(define (test-panel window-id)
+ (let* ((curr-row-num 0)
+ (viewlog (lambda (x)
+ (if (common:file-exists? logfile)
+ ;(system (conc "firefox " logfile "&"))
+ (iup:send-url logfile)
+ (message-window (conc "File " logfile " not found")))))
+ (xterm (lambda (x)
+ (if (directory-exists? rundir)
+ (let ((shell (if (get-environment-variable "SHELL")
+ (conc "-e " (get-environment-variable "SHELL"))
+ "")))
+ (system (conc "cd " rundir
+ ";xterm -T \"" (string-translate testfullname "()" " ") "\" " shell "&")))
+ (message-window (conc "Directory " rundir " not found")))))
+ (command-text-box (iup:textbox #:expand "HORIZONTAL" #:font "Courier New, -12"))
+ (command-launch-button (iup:button "Execute!"
+ ;; #:expand "HORIZONTAL"
+ #:size "50x"
+ #:action (lambda (x)
+ (let ((cmd (iup:attribute command-text-box "VALUE")))
+ (system (conc cmd " &"))))))
+ (run-test (lambda (x)
+ (iup:attribute-set!
+ command-text-box "VALUE"
+ (conc "xterm -geometry 180x20 -e \"megatest -target " keystring " :runname " runname
+ " -runtests " (conc testname "/" (if (equal? item-path "")
+ "%"
+ item-path))
+ ";echo Press any key to continue;bash -c 'read -n 1 -s'\""))))
+ (remove-test (lambda (x)
+ (iup:attribute-set!
+ command-text-box "VALUE"
+ (conc "xterm -geometry 180x20 -e \"megatest -remove-runs -target " keystring " :runname " runname
+ " -testpatt " (conc testname "/" (if (equal? item-path "")
+ "%"
+ item-path))
+ " -v;echo Press any key to continue;bash -c 'read -n 1 -s'\""))))
+ (run-info-matrix (iup:matrix
+ #:expand "YES"
+ ;; #:scrollbar "YES"
+ #:numcol 1
+ #:numlin 4
+ #:numcol-visible 1
+ #:numlin-visible 4
+ #:click-cb (lambda (obj lin col status)
+ (print "obj: " obj " lin: " lin " col: " col " status: " status))))
+ (test-info-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 7
+ #:numcol-visible 1
+ #:numlin-visible 7))
+ (test-run-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 5
+ #:numcol-visible 1
+ #:numlin-visible 5))
+ (meta-dat-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 1
+ #:numlin 5
+ #:numcol-visible 1
+ #:numlin-visible 5))
+ (steps-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 6
+ #:numlin 50
+ #:numcol-visible 6
+ #:numlin-visible 8))
+ (data-matrix (iup:matrix
+ #:expand "YES"
+ #:numcol 8
+ #:numlin 50
+ #:numcol-visible 8
+ #:numlin-visible 8))
+ (updater (lambda (testdat)
+ (test-update window-id testdat run-info-matrix test-info-matrix test-run-matrix meta-dat-matrix steps-matrix data-matrix))))
+
+ ;; Set the updater in updaters
+ ;; (hash-table-set! (dboard:data-updaters *data*) window-id updater)
+ ;;
+ (for-each
+ (lambda (mat)
+ ;; (iup:attribute-set! mat "0:1" "Value")
+ ;; (iup:attribute-set! mat "0:0" "Var")
+ (iup:attribute-set! mat "HEIGHT0" 0)
+ (iup:attribute-set! mat "ALIGNMENT1" "ALEFT")
+ ;; (iup:attribute-set! mat "FIXTOTEXT" "C1")
+ (iup:attribute-set! mat "RESIZEMATRIX" "YES"))
+ ;; (iup:attribute-set! mat "WIDTH1" "120")
+ ;; (iup:attribute-set! mat "WIDTH0" "100"))
+ (list run-info-matrix test-info-matrix test-run-matrix meta-dat-matrix))
+
+ ;; Steps matrix
+ (iup:attribute-set! steps-matrix "0:1" "Step Name")
+ (iup:attribute-set! steps-matrix "0:2" "Start")
+ (iup:attribute-set! steps-matrix "WIDTH2" "40")
+ (iup:attribute-set! steps-matrix "0:3" "End")
+ (iup:attribute-set! steps-matrix "WIDTH3" "40")
+ (iup:attribute-set! steps-matrix "0:4" "Status")
+ (iup:attribute-set! steps-matrix "WIDTH4" "40")
+ (iup:attribute-set! steps-matrix "0:5" "Duration")
+ (iup:attribute-set! steps-matrix "WIDTH5" "40")
+ (iup:attribute-set! steps-matrix "0:6" "Log File")
+ (iup:attribute-set! steps-matrix "ALIGNMENT1" "ALEFT")
+ ;; (iup:attribute-set! steps-matrix "FIXTOTEXT" "C1")
+ (iup:attribute-set! steps-matrix "RESIZEMATRIX" "YES")
+ ;; (iup:attribute-set! steps-matrix "WIDTH1" "120")
+ ;; (iup:attribute-set! steps-matrix "WIDTH0" "100")
+
+ ;; Data matrix
+ ;;
+ (let ((rownum 1))
+ (for-each
+ (lambda (x)
+ (iup:attribute-set! data-matrix (conc "0:" rownum) x)
+ (iup:attribute-set! data-matrix (conc "WIDTH" rownum) "50")
+ (set! rownum (+ rownum 1)))
+ (list "Category" "Variable" "Value" "Expected" "Tolerance" "Status" "Units" "Type" "Comment")))
+ (iup:attribute-set! data-matrix "REDRAW" "ALL")
+
+ (for-each
+ (lambda (data)
+ (let ((mat (car data))
+ (keys (cadr data))
+ (rownum 1))
+ (for-each
+ (lambda (key)
+ (iup:attribute-set! mat (conc rownum ":0") key)
+ (set! rownum (+ rownum 1)))
+ keys)
+ (iup:attribute-set! mat "REDRAW" "ALL")))
+ (list
+ (list run-info-matrix '("Run Id" "Target" "Runname" "Run Start Time" ))
+ (list test-info-matrix '("Test Id" "Testname" "Itempath" "State" "Status" "Test Start Time" "Comment"))
+ (list test-run-matrix '("Hostname" "Host info" "Disk Free" "CPU Load" "Run Duration"))
+ (list meta-dat-matrix '("Author" "Owner" "Last Reviewed" "Tags" "Description"))))
+
+ (iup:split
+ #:orientation "HORIZONTAL"
+ (iup:vbox
+ (iup:hbox
+ (iup:vbox
+ run-info-matrix
+ test-info-matrix)
+ ;; test-info-matrix)
+ (iup:vbox
+ test-run-matrix
+ meta-dat-matrix))
+ (iup:vbox
+ (iup:vbox
+ (iup:hbox
+ (iup:button "View Log" #:action viewlog #:size "60x" ) ;; #:size "30x"
+ (iup:button "Start Xterm" #:action xterm #:size "60x" )) ;; #:size "30x"
+ (iup:hbox
+ (iup:button "Run Test" #:action run-test #:size "60x" ) ;; #:size "30x"
+ (iup:button "Clean Test" #:action remove-test #:size "60x" ))) ;; #:size "30x"
+ (iup:hbox
+ ;; hiup:split ;; hbox
+ ;; #:orientation "HORIZONTAL"
+ ;; #:value 300
+ command-text-box
+ command-launch-button)))
+ (iup:vbox
+ (let ((tabs (iup:tabs
+ steps-matrix
+ data-matrix)))
+ (iup:attribute-set! tabs "TABTITLE0" "Test Steps")
+ (iup:attribute-set! tabs "TABTITLE1" "Test Data")
+ tabs)))))
+
+;; Test browser
+(define (tests window-id)
+ (iup:split
+ (let* ((tb (iup:treebox
+ #:selection-cb
+ (lambda (obj id state)
+ ;; (print "obj: " obj ", id: " id ", state: " state)
+ (let* ((run-path (tree:node->path obj id))
+ (test-id (tree-path->test-id (cdr run-path))))
+ ;; (if test-id
+ ;; (hash-table-set! (dboard:data-curr-test-ids *data*)
+ ;; window-id test-id))
+ (print "path: " (tree:node->path obj id) " test-id: " test-id))))))
+ (iup:attribute-set! tb "VALUE" "0")
+ (iup:attribute-set! tb "NAME" "Runs")
+ ;;(iup:attribute-set! tb "ADDEXPANDED" "NO")
+ ;; (dboard:data-tests-tree-set! *data* tb)
+ tb)
+ (test-panel window-id)))
+
+;; The function to update the fields in the test view panel
+(define (test-update window-id testdat run-info-matrix test-info-matrix test-run-matrix meta-dat-matrix steps-matrix data-matrix)
+ ;; get test-id
+ ;; then get test record
+ (if testdat
+ (let* ((test-id 0) ;; (hash-table-ref/default (dboard:data-curr-test-ids *data*) window-id #f))
+ (test-data (hash-table-ref/default testdat test-id #f))
+ (run-id (db:test-get-run_id test-data))
+ (targ/runname (hash-table-ref/default (dboard:data-run-keys *data*)
+ run-id
+ '()))
+ (target (if (null? targ/runname) "" (string-intersperse (reverse (cdr (reverse targ/runname))) "/")))
+ (runname (if (null? targ/runname) "" (car (cdr targ/runname))))
+ (steps-dat (tests:get-compressed-steps *dbstruct-local* run-id test-id)))
+
+ (if test-data
+ (begin
+ ;;
+ (for-each
+ (lambda (data)
+ (let ((mat (car data))
+ (vals (cadr data))
+ (rownum 1))
+ (for-each
+ (lambda (key)
+ (let ((cell (conc rownum ":1")))
+ (if (not (equal? (iup:attribute mat cell)(conc key)))
+ (begin
+ ;; (print "setting cell " cell " in matrix " mat " to value " key)
+ (iup:attribute-set! mat cell (conc key))
+ (iup:attribute-set! mat "REDRAW" cell)))
+ (set! rownum (+ rownum 1))))
+ vals)))
+ (list
+ (list run-info-matrix
+ (if test-id
+ (list (db:test-get-run_id test-data)
+ target
+ runname
+ "n/a")
+ (make-list 4 "")))
+ (list test-info-matrix
+ (if test-id
+ (list test-id
+ (db:test-get-testname test-data)
+ (db:test-get-item-path test-data)
+ (db:test-get-state test-data)
+ (db:test-get-status test-data)
+ (seconds->string (db:test-get-event_time test-data))
+ (db:test-get-comment test-data))
+ (make-list 7 "")))
+ (list test-run-matrix
+ (if test-id
+ (list (db:test-get-host test-data)
+ (db:test-get-uname test-data)
+ (db:test-get-diskfree test-data)
+ (db:test-get-cpuload test-data)
+ (seconds->hr-min-sec (db:test-get-run_duration test-data)))
+ (make-list 5 "")))
+ ))
+ (dcommon:populate-steps steps-dat steps-matrix))))))
+ ;;(list meta-dat-matrix
+ ;; (if test-id
+ ;; (list (
+
+
+;; db:test-get-id
+;; db:test-get-run_id
+;; db:test-get-testname
+;; db:test-get-state
+;; db:test-get-status
+;; db:test-get-event_time
+;; db:test-get-host
+;; db:test-get-cpuload
+;; db:test-get-diskfree
+;; db:test-get-uname
+;; db:test-get-rundir
+;; db:test-get-item-path
+;; db:test-get-run_duration
+;; db:test-get-final_logf
+;; db:test-get-comment
+;; db:test-get-fullname
+
+
+;;======================================================================
+;; R U N C O N T R O L
+;;======================================================================
+
+;; Overall runs browser
+;;
+(define (runs window-id)
+ (let* ((runs-matrix (iup:matrix
+ #:expand "YES"
+ ;; #:fittosize "YES"
+ #:scrollbar "YES"
+ #:numcol 100
+ #:numlin 100
+ #:numcol-visible 7
+ #:numlin-visible 7
+ #:click-cb (lambda (obj lin col status)
+ (print "obj: " obj " lin: " lin " col: " col " status: " status)))))
+
+ (iup:attribute-set! runs-matrix "RESIZEMATRIX" "YES")
+ (iup:attribute-set! runs-matrix "WIDTH0" "100")
+
+ ;; (dboard:data-runs-matrix-set! *data* runs-matrix)
+ (iup:hbox
+ (iup:frame
+ #:title "Runs browser"
+ (iup:vbox
+ runs-matrix)))))
+
+;; Browse and control a single run
+;;
+(define (runcontrol window-id)
+ (iup:hbox))
+
+;;======================================================================
+;; D A S H B O A R D
+;;======================================================================
+
+;; Main Panel
+(define (main-panel window-id)
+ (iup:dialog
+ #:title "Megatest Control Panel"
+ #:menu (dcommon:main-menu)
+ #:shrink "YES"
+ (let ((tabtop (iup:tabs
+ (runs window-id)
+ (tests window-id)
+ (runcontrol window-id)
+ (mtest *toppath* window-id)
+ (rconfig window-id)
+ )))
+ (iup:attribute-set! tabtop "TABTITLE0" "Runs")
+ (iup:attribute-set! tabtop "TABTITLE1" "Tests")
+ (iup:attribute-set! tabtop "TABTITLE2" "Run Control")
+ (iup:attribute-set! tabtop "TABTITLE3" "megatest.config")
+ (iup:attribute-set! tabtop "TABTITLE4" "runconfigs.config")
+ tabtop)))
+
+(define *current-window-id* 0)
+
+(define (newdashboard dbstruct)
+ (let* ((data (make-hash-table))
+ (keys '()) ;; (db:get-keys dbstruct))
+ (runname "%")
+ (testpatt "%")
+ (keypatts '()) ;; (map (lambda (k)(list k "%")) keys))
+ (states '())
+ (statuses '())
+ (nextmintime (current-milliseconds))
+ (my-window-id *current-window-id*))
+ (set! *current-window-id* (+ 1 *current-window-id*))
+ ;; (dboard:data-runs-set! *data* data) ;; make this data available to the rest of the application
+ (iup:show (main-panel my-window-id))
+ ;; Yes, running iup:show will pop up a new panel
+ ;; (iup:show (main-panel my-window-id))
+ (iup:callback-set! *tim*
+ "ACTION_CB"
+ (lambda (x)
+ ;; Want to dedicate no more than 50% of the time to this so skip if
+ ;; 2x delta time has not passed since last query
+ (if (< nextmintime (current-milliseconds))
+ (let* ((starttime (current-milliseconds))
+ ;; (changes (dcommon:run-update keys data runname keypatts testpatt states statuses 'full my-window-id))
+ (endtime (current-milliseconds)))
+ (set! nextmintime (+ endtime (* 2 (- endtime starttime))))
+ ;; (debug:print 11 *default-log-port* "CHANGE(S): " (car changes) "..."))
+ )
+ (debug:print-info 11 *default-log-port* "Server overloaded"))))))
+
+;; (dboard:data-updaters-set! *data* (make-hash-table))
+(newdashboard #f) ;; *dbstruct-local*)
+(iup:main-loop)
ADDED attic_modular/ods.import.scm
Index: attic_modular/ods.import.scm
==================================================================
--- /dev/null
+++ attic_modular/ods.import.scm
@@ -0,0 +1,34 @@
+;;;; ods.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ files
+ ports
+ commonmod
+ debugprint
+ regex
+ srfi-13
+ posix))
+(##sys#register-compiled-module
+ 'ods
+ (list)
+ '((ods:list->ods . ods#ods:list->ods)
+ (ods:add-non-content-files . ods#ods:add-non-content-files)
+ (ods:construct-dir . ods#ods:construct-dir)
+ (ods:cell . ods#ods:cell)
+ (ods:row . ods#ods:row)
+ (ods:column . ods#ods:column)
+ (ods:sheet . ods#ods:sheet)
+ (ods:make-thumbnail . ods#ods:make-thumbnail)
+ (ods:content-footer . ods#ods:content-footer)
+ (ods:content-header . ods#ods:content-header)
+ (ods:files . ods#ods:files)
+ (ods:0-len-files . ods#ods:0-len-files)
+ (ods:dirs . ods#ods:dirs))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/ods.scm
Index: attic_modular/ods.scm
==================================================================
--- /dev/null
+++ attic_modular/ods.scm
@@ -0,0 +1,240 @@
+;; Copyright 2011, 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 .
+;;
+
+(use csv-xml regex)
+(declare (unit ods))
+(declare (uses commonmod))
+(declare (uses debugprint))
+
+(module ods
+*
+
+(import scheme chicken data-structures extras files ports)
+(import commonmod)
+(import debugprint)
+(import regex
+ srfi-13
+ posix
+ )
+
+(define ods:dirs
+ '("Configurations2"
+ "Configurations2/toolpanel"
+ "Configurations2/menubar"
+ "Configurations2/toolbar"
+ "Configurations2/progressbar"
+ "Configurations2/floater"
+ "Configurations2/images"
+ "Configurations2/images/Bitmaps"
+ "Configurations2/statusbar"
+ "Configurations2/popupmenu"
+ "Configurations2/accelerator"
+ "META-INF"
+ "Thumbnails"))
+
+(define ods:0-len-files
+ '("Configurations2/accelerator/current.xml"
+ ;; "Thumbnails/thumbnail.png"
+ "content.xml"
+ ))
+
+(define ods:files
+ '(("META-INF/manifest.xml"
+ ("\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"))
+ ("styles.xml"
+ ("\n"
+ "$-$???Page 1??? (???)09/06/2011, 20:48:51Page 1 / 99\n"))
+ ("settings.xml"
+ ("\n"
+ "0045161799view100000020000010060true04000020000010060trueSheet2270010060falsetruetruetrue12632256truetruetruetruefalsefalse1270127011truefalsetrue3falsetruetruetrue12701270false1truetrue1true12632256falsefalsetrue0truetruetruefalsetrue\n"))
+ ("mimetype"
+ ("application/vnd.oasis.opendocument.spreadsheet"))
+ ("meta.xml"
+ ("\n"
+ "Matt Welland2011-09-06T20:46:232011-09-06T20:48:51Matt WellandPT2M29S1LibreOffice/3.3$Linux LibreOffice_project/330m19$Build-301\n"))))
+
+(define ods:content-header
+ '("\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"))
+
+(define ods:content-footer
+ '("\n"
+ "\n"
+ "\n"))
+
+(define (ods:make-thumbnail path)
+ (let ((oup (open-output-pipe (conc "uudecode -o " path "/Thumbnails/thumbnail.png"))))
+ (with-output-to-port oup
+ (lambda ()
+ (print "begin-base64 640 Thumbnail.png
+iVBORw0KGgoAAAANSUhEUgAAAL4AAAEACAIAAACCoVt7AAAEWElEQVR4nO3X
+MU4bWQCA4bGUo5gUKCcgJwCaVNvShdI06VKmSxNKp6PdKg3xCcgJIhr7Ll6P
+DTgBRbv5i11W+r7Gw7yZx0jv5415sV6vB/h9L/7rB+D/apfO4nxy8nk8OPq0
+vDm9Pr8+nc+mv75pcXl5MNtfsLp8fXDxbRjefl3Pj//xb340yW+N8gyM6awu
+vxwu1+txnVar1Xj2z7PJpoUxhYNdFmNSs+EukdHRcHpzt7Kr69s/luub6Wa1
+V8Px9tx9TLsSH2a4OxwjWx5+uLgYhtOr4ezXo8Ori4tt0b8XJf+KMZ3p7N3w
+ejIZV227hMP3V+/XNweX59erxZddK98uPi5eDvfdbC672u8I09l8tvlYDC/v
+z93HNJa4+Hj7fr0+3mxs54vTw1e7BM+vh9n7T8PBbPlx8jD/k9HT4WzsRzfP
+0/aFtVi+vNl9W75b4MODhwv2C7c4vz/e7C8/zzK+8Iav6ycLPJ1Ol3/zAPv5
+N5vfo7tnN+vZuIFNJvJ5frYvrOHLh8nJyfjjuOsM1/slPH53uNmPTnYDD8dH
+R5ut4uGFdf9F6WQy3C3wdPbmdjKZDNsw7u56PPMw3F6cXS6vDs/u57/66cE2
+o+e3w+fP203p7RvdPDvbF9bx/GY935/bvYDuPsa//IeBH473jufrH+9+cu54
+f9dPM893u9QPcz4dnT+emGfDP+dE0iGSDpF0iKRDJB0i6RBJh0g6RNIhkg6R
+dIikQyQdIukQSYdIOkTSIZIOkXSIpEMkHSLpEEmHSDpE0iGSDpF0iKRDJB0i
+6RBJh0g6RNIhkg6RdIikQyQdIukQSYdIOkTSIZIOkXSIpEMkHSLpEEmHSDpE
+0iGSDpF0iKRDJB0i6RBJh0g6RNIhkg6RdIikQyQdIukQSYdIOkTSIZIOkXSI
+pEMkHSLpEEmHSDpE0iGSDpF0iKRDJB0i6RBJh0g6RNIhkg6RdIikQyQdIukQ
+SYdIOkTSIZIOkXSIpEMkHSLpEEmHSDpE0iGSDpF0iKRDJB0i6RBJh0g6RNIh
+kg6RdIikQyQdIukQSYdIOkTSIZIOkXSIpEMkHSLpEEmHSDpE0iGSDpF0iKRD
+JB0i6RBJh0g6RNIhkg6RdIikQyQdIukQSYdIOkTSIZIOkXSIpEMkHSLpEEmH
+SDpE0iGSDpF0iKRDJB0i6RBJh0g6RNIhkg6RdIikQyQdIukQSYdIOkTSIZIO
+kXSIpEMkHSLpEEmHSDpE0iGSDpF0iKRDJB0i6RBJh0g6RNIhkg6RdIikQyQd
+IukQSYdIOkTSIZIOkXSIpEMkHSLpEEmHSDpE0iGSDpF0iKRDJB0i6RBJh0g6
+RNIhkg6RdIikQyQdIukQSYdIOkTSIZIOkXSIpEMkHSLpEEmHSDpE0iGSDpF0
+iKRDJB0i6RBJh0g6RNIhkg6RdIikQyQdIukQSYdIOkTSIZIOkXSIpEMkHSLp
+EEmHSDpE0iGSDpF0iKRDJB0i6RBJh+gv8TgE/jVPQbMAAAAASUVORK5CYII=
+====")))))
+
+;; sheetdat is '("sheetname" (r1c1 r2c2 ...)(r2c1 r2c2 ...) ...)
+(define (ods:sheet sheetdat)
+ (let ((name (car sheetdat))
+ (rows (cdr sheetdat)))
+ (conc "\n"
+ (conc (ods:column)
+ (string-join (map ods:row rows) ""))
+ "")))
+
+;; seems to be called once at top of each sheet, i.e. a column of rows
+(define (ods:column)
+ "\n")
+
+;; cells is a list of ...
+(define (ods:row cells)
+ (conc "\n"
+ (string-join (map ods:cell cells) "")
+ "\n"))
+
+;; types are "string" or "float"
+(define (ods:cell value)
+ (let* ((type (cond
+ ((string? value) "string")
+ ((symbol? value) "string")
+ ((number? value) "float")
+ (else #f)))
+ (tmpval (if (symbol? value)
+ (symbol->string value)
+ (if type value ""))) ;; convert everything else to an empty string
+ (escval (if (string? tmpval)(string-substitute (regexp "<") "<" (string-substitute (regexp ">") ">" tmpval)) tmpval)))
+ (conc "\n"
+ "" escval "" "\n"
+ "" "\n")))
+
+;; create the directories
+(define (ods:construct-dir path)
+ (for-each
+ (lambda (subdir)
+ (system (conc "mkdir -p " path "/" subdir)))
+ ods:dirs))
+
+;; populate the necessary, non-constructed, files
+(define (ods:add-non-content-files path)
+ ;; first the zero-length files, nb// the dir should already be created
+ (for-each
+ (lambda (fname)
+ (system (conc "touch " path "/" fname)))
+ ods:0-len-files)
+ ;; create the files with stuff in them
+ (for-each
+ (lambda (fdat)
+ (let* ((name (car fdat))
+ (lines (cadr fdat)))
+ (with-output-to-file (conc path "/" name)
+ (lambda ()
+ (for-each
+ (lambda (line)
+ (display line))
+ lines)))))
+ ods:files))
+
+;; data format:
+;; '( (sheet1 (r1c1 r1c2 r1c3 ...)
+;; (r2c1 r2c3 r2c3 ...) )
+;; (sheet2 ( ... )
+;; ( ... ) ) )
+(define (ods:list->ods path fname data)
+ (if (not (common:file-exists? path))
+ (print "ERROR: path to create ods data must pre-exist")
+ (begin
+ (with-output-to-file (conc path "/content.xml")
+ (lambda ()
+ (ods:construct-dir path)
+ (ods:add-non-content-files path)
+ (ods:make-thumbnail path)
+ (map display ods:content-header)
+ ;; process each sheet
+ (map print
+ (map ods:sheet data))
+ (map display ods:content-footer)))
+ (system (conc "cd " path "; zip " fname " -n mimetype mimetype `find . |grep -v mimetype` > /dev/null")))))
+
+;;======================================================================the end
+
+)
ADDED attic_modular/pgdb.import.scm
Index: attic_modular/pgdb.import.scm
==================================================================
--- /dev/null
+++ attic_modular/pgdb.import.scm
@@ -0,0 +1,113 @@
+;;;; pgdb.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ data-structures
+ chicken
+ commonmod
+ configfmod
+ margsmod
+ debugprint
+ srfi-1
+ srfi-69
+ typed-records
+ (prefix dbi dbi:)))
+(##sys#register-compiled-module
+ 'pgdb
+ (list)
+ '((pgdb:get-pg-lst . pgdb#pgdb:get-pg-lst)
+ (pgdb:get-history-hash . pgdb#pgdb:get-history-hash)
+ (pgdb:runs-to-hash . pgdb#pgdb:runs-to-hash)
+ (pgdb:coalesce-runs-by-slice . pgdb#pgdb:coalesce-runs-by-slice)
+ (pgdb:ordered-data->b-keys . pgdb#pgdb:ordered-data->b-keys)
+ (pgdb:ordered-data->a-keys . pgdb#pgdb:ordered-data->a-keys)
+ (pgdb:ordered-data->b-keys . pgdb#pgdb:ordered-data->b-keys)
+ (pgdb:ordered-data->a-keys . pgdb#pgdb:ordered-data->a-keys)
+ (pgdb:coalesce-runs1 . pgdb#pgdb:coalesce-runs1)
+ (pgdb:coalesce-runs . pgdb#pgdb:coalesce-runs)
+ (pgdb:mk-pattern . pgdb#pgdb:mk-pattern)
+ (pgdb:get-test-by-id . pgdb#pgdb:get-test-by-id)
+ (pgdb:get-runs-by-target . pgdb#pgdb:get-runs-by-target)
+ (pgdb:get-targets-of-type . pgdb#pgdb:get-targets-of-type)
+ (pgdb:get-targets . pgdb#pgdb:get-targets)
+ (pgdb:get-distict-target-slice3 . pgdb#pgdb:get-distict-target-slice3)
+ (pgdb:get-distict-target-slice . pgdb#pgdb:get-distict-target-slice)
+ (pgdb:get-target-types . pgdb#pgdb:get-target-types)
+ (pgdb:get-slice-cnt . pgdb#pgdb:get-slice-cnt)
+ (pgdb:get-count-data-stats-target-slice
+ .
+ pgdb#pgdb:get-count-data-stats-target-slice)
+ (pgdb:get-all-run-stats-target-slice
+ .
+ pgdb#pgdb:get-all-run-stats-target-slice)
+ (pgdb:get-run-stats-history-given-target
+ .
+ pgdb#pgdb:get-run-stats-history-given-target)
+ (pgdb:get-latest-run-cnt-by-pattern
+ .
+ pgdb#pgdb:get-latest-run-cnt-by-pattern)
+ (pgdb:get-count-data-stats-latest-pattern
+ .
+ pgdb#pgdb:get-count-data-stats-latest-pattern)
+ (pgdb:get-latest-run-cnt . pgdb#pgdb:get-latest-run-cnt)
+ (pgdb:get-count-data-stats-target-latest
+ .
+ pgdb#pgdb:get-count-data-stats-target-latest)
+ (pgdb:get-latest-run-stats-given-pattern
+ .
+ pgdb#pgdb:get-latest-run-stats-given-pattern)
+ (pgdb:get-latest-run-stats-given-target
+ .
+ pgdb#pgdb:get-latest-run-stats-given-target)
+ (pgdb:get-stats-given-target . pgdb#pgdb:get-stats-given-target)
+ (pgdb:get-stats-given-type-target . pgdb#pgdb:get-stats-given-type-target)
+ (pgdb:get-tests . pgdb#pgdb:get-tests)
+ (pgdb:update-test . pgdb#pgdb:update-test)
+ (pgdb:insert-test . pgdb#pgdb:insert-test)
+ (pgdb:get-test-last-update . pgdb#pgdb:get-test-last-update)
+ (pgdb:get-test-id . pgdb#pgdb:get-test-id)
+ (pgdb:update-test-data . pgdb#pgdb:update-test-data)
+ (pgdb:insert-test-data . pgdb#pgdb:insert-test-data)
+ (pgdb:get-test-data-last-update . pgdb#pgdb:get-test-data-last-update)
+ (pgdb:get-test-data-id . pgdb#pgdb:get-test-data-id)
+ (pgdb:update-test-step . pgdb#pgdb:update-test-step)
+ (pgdb:insert-test-step . pgdb#pgdb:insert-test-step)
+ (pgdb:get-test-step-last-update . pgdb#pgdb:get-test-step-last-update)
+ (pgdb:get-test-step-id . pgdb#pgdb:get-test-step-id)
+ (pgdb:insert-run . pgdb#pgdb:insert-run)
+ (pgdb:refresh-run-info . pgdb#pgdb:refresh-run-info)
+ (pgdb:get-run-info . pgdb#pgdb:get-run-info)
+ (pgdb:get-run-last-update . pgdb#pgdb:get-run-last-update)
+ (pgdb:get-run-id . pgdb#pgdb:get-run-id)
+ (pgdb:is-run-taged-with-a-tag . pgdb#pgdb:is-run-taged-with-a-tag)
+ (pgdb:is-area-taged-with-a-tag . pgdb#pgdb:is-area-taged-with-a-tag)
+ (pgdb:is-area-taged . pgdb#pgdb:is-area-taged)
+ (pgdb:insert-run-tag . pgdb#pgdb:insert-run-tag)
+ (pgdb:insert-area-tag . pgdb#pgdb:insert-area-tag)
+ (pgdb:insert-tag . pgdb#pgdb:insert-tag)
+ (pgdb:get-tag-info-by-name . pgdb#pgdb:get-tag-info-by-name)
+ (pgdb:get-ttype . pgdb#pgdb:get-ttype)
+ (pgdb:write-sync-time . pgdb#pgdb:write-sync-time)
+ (pgdb:get-area-by-path . pgdb#pgdb:get-area-by-path)
+ (pgdb:get-areas . pgdb#pgdb:get-areas)
+ (pgdb:add-area . pgdb#pgdb:add-area)
+ (alist->area . pgdb#alist->area)
+ (area->alist . pgdb#area->alist)
+ (update-area . pgdb#update-area)
+ (set-area! . pgdb#set-area!)
+ (make-area . pgdb#make-area)
+ (area-last-update . pgdb#area-last-update)
+ (area-last-update-set! . pgdb#area-last-update-set!)
+ (area-area-path . pgdb#area-area-path)
+ (area-area-path-set! . pgdb#area-area-path-set!)
+ (area-area-name . pgdb#area-area-name)
+ (area-area-name-set! . pgdb#area-area-name-set!)
+ (area-id . pgdb#area-id)
+ (area-id-set! . pgdb#area-id-set!)
+ (area? . pgdb#area?)
+ (make-area . pgdb#make-area)
+ (pgdb:open . pgdb#pgdb:open))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/pgdb.scm
Index: attic_modular/pgdb.scm
==================================================================
--- /dev/null
+++ attic_modular/pgdb.scm
@@ -0,0 +1,661 @@
+;;======================================================================
+;; Copyright 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 .
+
+;;======================================================================
+
+(declare (unit pgdb))
+(declare (uses configf))
+(declare (uses configfmod))
+(declare (uses commonmod))
+(declare (uses margsmod))
+(declare (uses debugprint))
+
+(module pgdb
+ *
+
+(import scheme)
+(import data-structures)
+(import chicken)
+(import commonmod)
+(import configfmod)
+(import margsmod)
+(import debugprint)
+
+(import srfi-1 srfi-69 typed-records (prefix dbi dbi:))
+
+;; given a configdat lookup the connection info and open the db
+;;
+(define (pgdb:open configdat #!key (dbname #f)(dbispec #f))
+ (let ((pgconf (or dbispec
+ (args:get-arg "-pgsync")
+ (if configdat
+ (configf:lookup configdat "ext-sync" (or dbname "pgdb"))
+ #f)
+ )))
+ (if pgconf
+ (let* ((confdat (map (lambda (conf-item)
+ (let ((parts (string-split conf-item ":")))
+ (if (> (length parts) 1)
+ (let ((key (car parts))
+ (val (cadr parts)))
+ (cons (string->symbol key) val))
+ (begin
+ (print "ERROR: Bad config setting " conf-item ", should be key:val")
+ `(,(string->symbol (car parts)) . #f)))))
+ (string-split pgconf)))
+ (dbtype (string->symbol (or (alist-ref 'dbtype confdat) "pg"))))
+ (if (alist-ref 'dbtype confdat)
+ (dbi:open dbtype (alist-delete 'dbtype confdat))))
+ #f)))
+
+;;======================================================================
+;; A R E A S
+;;======================================================================
+
+(defstruct area id area-name area-path last-update)
+
+(define (pgdb:add-area dbh area-name area-path)
+ (dbi:exec dbh "INSERT INTO areas (area_name,area_path) VALUES (?,?)" area-name area-path))
+
+(define (pgdb:get-areas dbh)
+ ;; (map
+ ;; (lambda (row)
+ ;; (print "row: " row))
+ (dbi:get-rows dbh "SELECT id,area_name,area_path,last_sync FROM areas;")) ;; )
+
+;; given an area_path get the area info
+;;
+(define (pgdb:get-area-by-path dbh area-path)
+ (dbi:get-one-row dbh "SELECT id,area_name,area_path,last_sync FROM areas WHERE area_path=?;" area-path))
+
+(define (pgdb:write-sync-time dbh area-info new-sync-time)
+ (let ((area-id (vector-ref area-info 0)))
+ (dbi:exec dbh "UPDATE areas SET last_sync=? WHERE id=?;" new-sync-time area-id)))
+
+;;======================================================================
+;; T A R G E T S
+;;======================================================================
+
+;; Given a target-spec, return the id. Should probably handle this with a join...
+;; if target-spec not found, create a record for it.
+;;
+(define (pgdb:get-ttype dbh target-spec)
+ (let ((spec-id (dbi:get-one dbh "SELECT id FROM ttype WHERE target_spec=?;" target-spec)))
+ (or spec-id
+ (if (handle-exceptions
+ exn
+ (begin
+ (print-call-chain)
+ (debug:print 0 *default-log-port* "ERROR: cannot create ttype entry, " ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (dbi:exec dbh "INSERT INTO ttype (target_spec) VALUES (?);" target-spec))
+ (pgdb:get-ttype dbh target-spec)))))
+
+;;======================================================================
+;; T A G S
+;;======================================================================
+
+
+(define (pgdb:get-tag-info-by-name dbh tag)
+ (dbi:get-one-row dbh "SELECT id,tag_name FROM tags where tag_name=?;" tag))
+
+(define (pgdb:insert-tag dbh name )
+ (dbi:exec dbh "INSERT INTO tags (tag_name) VALUES (?)" name ))
+
+(define (pgdb:insert-area-tag dbh tag-id area-id )
+ (dbi:exec dbh "INSERT INTO area_tags (tag_id, area_id) VALUES (?,?)" tag-id area-id ))
+
+(define (pgdb:insert-run-tag dbh tag-id run-id )
+ (dbi:exec dbh "INSERT INTO run_tags (tag_id, run_id) VALUES (?,?)" tag-id run-id ))
+
+
+(define (pgdb:is-area-taged dbh area-id)
+ (let ((area-tag-id (dbi:get-one dbh "SELECT id FROM area_tags WHERE area_id=?;" area-id)))
+ (if area-tag-id
+ #t
+ #f)))
+
+(define (pgdb:is-area-taged-with-a-tag dbh tag-id area-id)
+ (let ((area-tag-id (dbi:get-one dbh "SELECT id FROM area_tags WHERE area_id=? and tag_id=?;" area-id tag-id)))
+ (if area-tag-id
+ #t
+ #f)))
+
+(define (pgdb:is-run-taged-with-a-tag dbh tag-id run-id)
+ (let ((run-tag-id (dbi:get-one dbh "SELECT id FROM run_tags WHERE run_id=? and tag_id=?;" run-id tag-id)))
+ (if run-tag-id
+ #t
+ #f)))
+
+
+
+;;======================================================================
+;; R U N S
+;;======================================================================
+
+;; given a target spec id, target and run-name return the run-id
+;; if no run found return #f
+;;
+(define (pgdb:get-run-id dbh spec-id target run-name area-id)
+ (dbi:get-one dbh "SELECT id FROM runs WHERE ttype_id=? AND target=? AND run_name=? and area_id=?;"
+ spec-id target run-name area-id))
+
+;; given a target spec id, target and run-name return the run-id
+;; if no run found return #f
+;;
+(define (pgdb:get-run-last-update dbh id )
+ (dbi:get-one dbh "SELECT last_update FROM runs WHERE id=?;"
+ id))
+
+;; given a run-id return all the run info
+;;
+(define (pgdb:get-run-info dbh run-id ) ;; to join ttype or not?
+ (dbi:get-one-row
+ dbh ;; 0 1 2 3 4 5 6 7 8 9 10 11 12
+ "SELECT id,target,ttype_id,run_name,state,status,owner,event_time,comment,fail_count,pass_count,last_update,area_id
+ FROM runs WHERE id=? ;" run-id ))
+
+;; refresh the data in a run record
+;;
+(define (pgdb:refresh-run-info dbh run-id state status owner event-time comment fail-count pass-count area-id last_update publish-time) ;; area-id)
+ (dbi:exec
+ dbh
+ "UPDATE runs SET
+ state=?,status=?,owner=?,event_time=?,comment=?,fail_count=?,pass_count=?,last_update=?,publish_time=?
+ WHERE id=? and area_id=?;"
+ state status owner event-time comment fail-count pass-count last_update publish-time run-id area-id ))
+
+;; given all needed info create run record
+;;
+(define (pgdb:insert-run dbh ttype-id target run-name state status owner event-time comment fail-count pass-count area-id last-update publish-time)
+ (dbi:exec
+ dbh
+ "INSERT INTO runs (ttype_id,target,run_name,state,status,owner,event_time,comment,fail_count,pass_count,area_id,last_update,publish_time)
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?, ?);"
+ ttype-id target run-name state status owner event-time comment fail-count pass-count area-id last-update publish-time))
+
+;;======================================================================
+;; T E S T - S T E P S
+;;======================================================================
+
+(define (pgdb:get-test-step-id dbh test-id stepname state)
+ (dbi:get-one
+ dbh
+ "SELECT id FROM test_steps WHERE test_id=? AND stepname=? and state = ? ;"
+ test-id stepname state))
+
+(define (pgdb:get-test-step-last-update dbh id )
+ (dbi:get-one
+ dbh
+ "SELECT last_update FROM test_steps WHERE id=? ;"
+ id))
+
+(define (pgdb:insert-test-step dbh test-id stepname state status event_time comment logfile last-update )
+ (dbi:exec
+ dbh
+ "INSERT INTO test_steps (test_id,stepname,state,status,event_time,logfile,comment,last_update)
+ VALUES (?,?,?,?,?,?,?,? );"
+ test-id stepname state status event_time logfile comment last-update))
+
+(define (pgdb:update-test-step dbh step-id test-id stepname state status event_time comment logfile last-update)
+ (dbi:exec
+ dbh
+ "UPDATE test_steps SET
+ test_id=?,stepname=?,state=?,status=?,event_time=?,logfile=?,comment=?,last_update=?
+ WHERE id=?;"
+ test-id stepname state status event_time logfile comment last-update step-id))
+
+
+;;======================================================================
+;; T E S T - D A T A
+;;======================================================================
+
+(define (pgdb:get-test-data-id dbh test-id category variable)
+ (dbi:get-one
+ dbh
+ "SELECT id FROM test_data WHERE test_id=? AND category=? and variable = ? ;"
+ test-id category variable))
+
+(define (pgdb:get-test-data-last-update dbh test-data-id )
+ (dbi:get-one
+ dbh
+ "SELECT last_update FROM test_data WHERE id=? ;"
+ test-data-id))
+
+(define (pgdb:insert-test-data dbh test-id category variable value expected tol units comment status type last-update)
+ ; (print "INSERT INTO test_data (test_id, category, variable, value, expected, tol, units, comment, status, type)
+ ; VALUES (?,?,?,?,?,?,?,?,?,?) " test-id " " category " " variable " " value " " expected " " tol " " units " " comment " " status " " type)
+ (if (not (string? units))
+ (set! units "" ))
+ (if (not (string? variable))
+ (set! variable "" ))
+ (if (not (real? value))
+ (set! value 0 ))
+ (if (not (real? expected))
+ (set! expected 0 ))
+(if (not (real? tol))
+ (set! tol 0 ))
+
+ (dbi:exec
+ dbh
+ "INSERT INTO test_data (test_id, category, variable, value, expected, tol, units, comment, status, type, last_update)
+ VALUES (?,?,?,?,?,?,?,?,?,?, ?);"
+ test-id category variable value expected tol units comment status type last-update))
+
+(define (pgdb:update-test-data dbh data-id test-id category variable value expected tol units comment status type last-update)
+ (dbi:exec
+ dbh
+ "UPDATE test_data SET
+ test_id=?, category=?, variable=?, value=?, expected=?, tol=?, units=?, comment=?, status=?, type=?, last_update=?
+ WHERE id=?;"
+ test-id category variable value expected tol units comment status type last-update data-id ))
+
+
+
+;;======================================================================
+;; T E S T S
+;;======================================================================
+
+;; given run-id, test_name and item_path return test-id
+;;
+(define (pgdb:get-test-id dbh run-id test-name item-path)
+ (dbi:get-one
+ dbh
+ "SELECT id FROM tests WHERE run_id=? AND test_name=? AND item_path=?;"
+ run-id test-name item-path))
+
+(define (pgdb:get-test-last-update dbh id)
+ (dbi:get-one
+ dbh
+ "SELECT last_update FROM tests WHERE id=? ;"
+ id ))
+
+
+;; create new test record
+;;
+(define (pgdb:insert-test dbh run-id test-name item-path state status host cpuload diskfree uname run-dir log-file run-duration comment event-time archived last-update pid)
+ (dbi:exec
+ dbh
+ "INSERT INTO tests (run_id,test_name,item_path,state,status,host,cpuload,diskfree,uname,rundir,final_logf,run_duration,comment,event_time,archived,last_update,attemptnum)
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
+
+ run-id test-name item-path state status host cpuload diskfree uname
+ run-dir log-file run-duration comment event-time archived last-update pid))
+
+;; update existing test record
+;;
+(define (pgdb:update-test dbh test-id run-id test-name item-path state status host cpuload diskfree uname run-dir log-file run-duration comment event-time archived last-update pid)
+ (dbi:exec
+ dbh
+ "UPDATE tests SET
+ run_id=?,test_name=?,item_path=?,state=?,status=?,host=?,cpuload=?,diskfree=?,uname=?,rundir=?,final_logf=?,run_duration=?,comment=?,event_time=?,archived=?,last_update=?,attemptnum=?
+ WHERE id=?;"
+
+ run-id test-name item-path state status host cpuload diskfree uname
+ run-dir log-file run-duration comment event-time archived last-update pid test-id))
+
+(define (pgdb:get-tests dbh target-patt)
+ (dbi:get-rows
+ dbh
+ "SELECT t.id,t.run_id,t.test_name,t.item_path,t.state,t.status,t.host,t.cpuload,t.diskfree,t.uname,t.rundir,t.final_logf,t.run_duration,t.comment,t.event_time,t.archived,
+ r.id,r.target,r.ttype_id,r.run_name,r.state,r.status,r.owner,r.event_time,r.comment
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE r.target LIKE ?;" target-patt))
+
+(define (pgdb:get-stats-given-type-target dbh ttype-id target-patt)
+ (dbi:get-rows
+ dbh
+ ;; "SELECT COUNT(t.id),t.status,r.target FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ ;; WHERE t.state='COMPLETED' AND ttype_id=? AND r.target LIKE ? GROUP BY r.target,t.status;"
+ "SELECT r.target,COUNT(*) AS total,
+ SUM(CASE WHEN t.status='PASS' THEN 1 ELSE 0 END) AS pass,
+ SUM(CASE WHEN t.status='FAIL' THEN 1 ELSE 0 END) AS fail,
+ SUM(CASE WHEN t.status IN ('PASS','FAIL') THEN 0 ELSE 1 END) AS other
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE t.state='COMPLETED' AND ttype_id=? AND r.target LIKE ? GROUP BY r.target;"
+ ttype-id target-patt))
+
+(define (pgdb:get-stats-given-target dbh target-patt)
+ (dbi:get-rows
+ dbh
+ ;; "SELECT COUNT(t.id),t.status,r.target FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ ;; WHERE t.state='COMPLETED' AND ttype_id=? AND r.target LIKE ? GROUP BY r.target,t.status;"
+ "SELECT r.target,COUNT(*) AS total,
+ SUM(CASE WHEN t.status='PASS' THEN 1 ELSE 0 END) AS pass,
+ SUM(CASE WHEN t.status='FAIL' THEN 1 ELSE 0 END) AS fail,
+ SUM(CASE WHEN t.status IN ('PASS','FAIL') THEN 0 ELSE 1 END) AS other
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE t.state='COMPLETED' AND r.target LIKE ? GROUP BY r.target;"
+ target-patt))
+
+
+(define (pgdb:get-latest-run-stats-given-target dbh ttype-id target-patt limit offset)
+ (dbi:get-rows
+ dbh
+ ;; "SELECT COUNT(t.id),t.status,r.target FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ ;; WHERE t.state='COMPLETED' AND ttype_id=? AND r.target LIKE ? GROUP BY r.target,t.status;"
+ "SELECT r.target, r.event_time, COUNT(*) AS total,
+ SUM(CASE WHEN t.status='PASS' THEN 1 ELSE 0 END) AS pass,
+ SUM(CASE WHEN t.status='FAIL' THEN 1 ELSE 0 END) AS fail,
+ SUM(CASE WHEN t.status IN ('PASS','FAIL') THEN 0 ELSE 1 END) AS other, r.id
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE t.state like '%' AND ttype_id=? AND r.target LIKE ?
+ and r.id in
+ (SELECT DISTINCT on (target) id from runs where target like ? AND ttype_id=? order by target,event_time desc)
+ GROUP BY r.target,r.id
+ order by r.event_time desc limit ? offset ? ;"
+ ttype-id target-patt target-patt ttype-id limit offset))
+
+(define (pgdb:get-latest-run-stats-given-pattern dbh patt limit offset)
+ (dbi:get-rows
+ dbh
+ ;; "SELECT COUNT(t.id),t.status,r.target FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ ;; WHERE t.state='COMPLETED' AND ttype_id=? AND r.target ILIKE ? GROUP BY r.target,t.status;"
+ "SELECT r.target, r.event_time, COUNT(*) AS total,
+ SUM(CASE WHEN t.status='PASS' THEN 1 ELSE 0 END) AS pass,
+ SUM(CASE WHEN t.status='FAIL' THEN 1 ELSE 0 END) AS fail,
+ SUM(CASE WHEN t.status IN ('PASS','FAIL') THEN 0 ELSE 1 END) AS other, r.id
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE t.state like '%' AND r.target ILIKE ?
+ and r.id in
+ (SELECT DISTINCT on (target) id from runs where target ilike ? order by target,event_time desc)
+ GROUP BY r.target,r.id
+ order by r.event_time desc limit ? offset ? ;"
+ patt patt limit offset))
+
+
+(define (pgdb:get-count-data-stats-target-latest dbh ttype-id target-patt)
+ (dbi:get-rows
+ dbh
+ "SELECT count(*) from
+ (SELECT DISTINCT on (target) id
+ from runs where target like ? AND ttype_id = ?
+ order by target, event_time desc
+ ) as x;"
+ target-patt ttype-id))
+
+(define (pgdb:get-latest-run-cnt dbh ttype-id target-patt)
+ (let* ((cnt-result (pgdb:get-count-data-stats-target-latest dbh ttype-id target-patt))
+ ;(cnt-row (car (cnt-result)))
+ (cnt 0)
+ )
+ (for-each
+ (lambda (row)
+ (set! cnt (vector-ref row 0 )))
+ cnt-result)
+
+cnt))
+
+(define (pgdb:get-count-data-stats-latest-pattern dbh patt)
+ (dbi:get-rows
+ dbh
+ "SELECT count(*) from
+ (SELECT DISTINCT on (target) id
+ from runs where target ilike ?
+ order by target, event_time desc
+ ) as x;"
+ patt))
+
+(define (pgdb:get-latest-run-cnt-by-pattern dbh target-patt)
+ (let* ((cnt-result (pgdb:get-count-data-stats-latest-pattern dbh target-patt))
+ ;(cnt-row (car (cnt-result)))
+ (cnt 0)
+ )
+ (for-each
+ (lambda (row)
+ (set! cnt (vector-ref row 0 )))
+ cnt-result)
+
+cnt))
+
+
+
+
+
+(define (pgdb:get-run-stats-history-given-target dbh ttype-id target-patt)
+ (dbi:get-rows
+ dbh
+ ;; "SELECT COUNT(t.id),t.status,r.target FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ ;; WHERE t.state='COMPLETED' AND ttype_id=? AND r.target LIKE ? GROUP BY r.target,t.status;"
+ "SELECT r.run_name,COUNT(*) AS total,
+ SUM(CASE WHEN t.status='PASS' THEN 1 ELSE 0 END) AS pass,
+ SUM(CASE WHEN t.status='FAIL' THEN 1 ELSE 0 END) AS fail,
+ SUM(CASE WHEN t.status IN ('PASS','FAIL') THEN 0 ELSE 1 END) AS other
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE t.state like '%' AND ttype_id=? AND r.target LIKE ?
+ GROUP BY r.run_name;"
+ ttype-id target-patt ))
+
+(define (pgdb:get-all-run-stats-target-slice dbh target-patt limit offset)
+ (dbi:get-rows
+ dbh
+ "SELECT r.target, r.run_name,r.event_time, COUNT(*) AS total,
+ SUM(CASE WHEN t.status='PASS' THEN 1 ELSE 0 END) AS pass,
+ SUM(CASE WHEN t.status='FAIL' THEN 1 ELSE 0 END) AS fail,
+ SUM(CASE WHEN t.status IN ('PASS','FAIL') THEN 0 ELSE 1 END) AS other
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE r.target LIKE ?
+ GROUP BY r.target,r.run_name, r.event_time
+ order by r.target,r.event_time desc limit ? offset ? ;"
+ target-patt limit offset))
+
+
+(define (pgdb:get-count-data-stats-target-slice dbh target-patt)
+ (dbi:get-rows
+ dbh
+ "SELECT count(*) from (SELECT r.target, r.run_name,r.event_time, COUNT(*) AS total
+ FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id
+ WHERE r.target LIKE ?
+ GROUP BY r.target,r.run_name, r.event_time
+ ) as x;"
+ target-patt))
+
+(define (pgdb:get-slice-cnt dbh target-patt)
+ (let* ((cnt-result (pgdb:get-count-data-stats-target-slice dbh target-patt))
+ ;(cnt-row (car (cnt-result)))
+ (cnt 0)
+ )
+ (for-each
+ (lambda (row)
+ (set! cnt (vector-ref row 0 )))
+ cnt-result)
+
+cnt))
+
+
+(define (pgdb:get-target-types dbh)
+ (dbi:get-rows dbh "SELECT id,target_spec FROM ttype;"))
+
+ (define (pgdb:get-distict-target-slice dbh)
+ (dbi:get-rows dbh " select distinct on (split_part (target, '/', 1)) (split_part (target, '/', 1)) from runs;"))
+
+ (define (pgdb:get-distict-target-slice3 dbh)
+ (dbi:get-rows dbh " select distinct on (split_part (target, '/', 3)) (split_part (target, '/', 3)) from runs;"))
+;;
+(define (pgdb:get-targets dbh target-patt)
+ (let ((ttypes (pgdb:get-target-types dbh)))
+ (map
+ (lambda (ttype-dat)
+ (let ((tt-id (vector-ref ttype-dat 0))
+ (ttype (vector-ref ttype-dat 1)))
+ (cons ttype
+ (dbi:get-rows
+ dbh
+ "SELECT DISTINCT target FROM runs WHERE target LIKE ? AND ttype_id=?;" target-patt tt-id))
+ ))
+ ttypes)))
+
+(define (pgdb:get-targets-of-type dbh ttype-id target-patt)
+ (dbi:get-rows dbh "SELECT DISTINCT target FROM runs WHERE target LIKE ? AND ttype_id=?;" target-patt ttype-id))
+
+(define (pgdb:get-runs-by-target dbh targets run-patt)
+ (dbi:get-rows dbh "SELECT r.run_name, t.test_name, t.status, t.item_path, t.id, t.rundir, t.final_logf FROM runs as r INNER JOIN tests AS t ON t.run_id=r.id
+ WHERE t.state='COMPLETED' AND r.target like ? AND r.run_name like ?;" targets run-patt)
+)
+
+(define (pgdb:get-test-by-id dbh id)
+ (dbi:get-rows dbh "SELECT t.test_name, t.item_path, t.rundir, t.final_logf FROM runs as r INNER JOIN tests AS t ON t.run_id=r.id
+ WHERE t.id = ?;" id)
+)
+
+;;======================================================================
+;; V A R I O U S D A T A M A S S A G E R O U T I N E S
+;;======================================================================
+
+;; probably want to move these to a different model file
+
+;; create a hash of hashes with keys extracted from all-parts
+;; using row-or-col to choose row or column
+;; ht{row key}=>ht{col key}=>data
+;;
+;; fnum is the field number in the tuples to be split
+;;
+
+(define (pgdb:mk-pattern dot type bp rel)
+ (let* ((typ (if (equal? type "all")
+ "%"
+ type))
+ (dotprocess (if (equal? dot "all")
+ "%"
+ dot))
+ (rel-num (if (equal? rel "")
+ "%"
+ rel))
+ (pattern (conc "%/" bp "/" dotprocess "/" typ "_" rel-num)))
+pattern))
+
+(define (pgdb:coalesce-runs dbh runs all-parts row-or-col fnum)
+ (let* ((data (make-hash-table)))
+
+ (for-each
+ (lambda (run)
+ (let* ((target (vector-ref run fnum))
+ (parts (string-split target "/"))
+ (first (car parts))
+ (rest (string-intersperse (cdr parts) "/"))
+ (coldat (hash-table-ref/default data first #f)))
+ (if (not coldat)(let ((newht (make-hash-table)))
+ (hash-table-set! data first newht)
+ (set! coldat newht)))
+ (hash-table-set! coldat rest run)))
+ runs)
+ data))
+
+
+(define (pgdb:coalesce-runs1 runs )
+ (let* ((data (make-hash-table)))
+
+ (for-each
+ (lambda (run)
+ (let* ((target (vector-ref run 0))
+ (parts (string-split target "/"))
+ (first (car parts))
+ (rest (string-intersperse (cdr parts) "/"))
+ (coldat (hash-table-ref/default data first #f)))
+ (if (not coldat)(let ((newht (make-hash-table)))
+ (hash-table-set! data first newht)
+ (set! coldat newht)))
+ (hash-table-set! coldat rest run)))
+ runs)
+ data))
+
+;; given ordered data hash return a-keys
+;;
+(define (pgdb:ordered-data->a-keys ordered-data)
+ (sort (hash-table-keys ordered-data) string>=?))
+
+;; given ordered data hash return b-keys
+;;
+(define (pgdb:ordered-data->b-keys ordered-data a-keys)
+ (delete-duplicates
+ (sort (apply
+ append
+ (map (lambda (sub-key)
+ (let ((subdat (hash-table-ref ordered-data sub-key)))
+ (hash-table-keys subdat)))
+ a-keys))
+ string>=?)))
+
+;; given ordered data hash return a-keys
+;;
+(define (pgdb:ordered-data->a-keys ordered-data)
+ (sort (hash-table-keys ordered-data) string>=?))
+
+;; given ordered data hash return b-keys
+;;
+(define (pgdb:ordered-data->b-keys ordered-data a-keys)
+ (delete-duplicates
+ (sort (apply
+ append
+ (map (lambda (sub-key)
+ (let ((subdat (hash-table-ref ordered-data sub-key)))
+ (hash-table-keys subdat)))
+ a-keys))
+ string>=?)))
+
+(define (pgdb:coalesce-runs-by-slice runs slice)
+ (let* ((data (make-hash-table)))
+ (for-each
+ (lambda (run)
+ (let* ((target (vector-ref run 0))
+ (run-name (vector-ref run 1))
+ (parts (string-split target "/"))
+ (first (car parts))
+ (rest (string-intersperse (cdr parts) "/"))
+ (coldat (hash-table-ref/default data rest #f)))
+ (if (not coldat)(let ((newht (make-hash-table)))
+ (hash-table-set! data rest newht)
+ (set! coldat newht)))
+ (hash-table-set! coldat run-name run)))
+ runs)
+ data))
+
+
+(define (pgdb:runs-to-hash runs )
+ (let* ((data (make-hash-table)))
+ (for-each
+ (lambda (run)
+ (let* ((run-name (vector-ref run 0))
+ (test (conc (vector-ref run 1) ":" (vector-ref run 3)))
+ (coldat (hash-table-ref/default data run-name #f)))
+ (if (not coldat)(let ((newht (make-hash-table)))
+ (hash-table-set! data run-name newht)
+ (set! coldat newht)))
+ (hash-table-set! coldat test run)))
+ runs)
+ data))
+
+(define (pgdb:get-history-hash runs)
+ (let* ((data (make-hash-table)))
+ (for-each
+ (lambda (run)
+ (let* ((run-name (vector-ref run 0)))
+ (hash-table-set! data run-name run)))
+ runs)
+ data))
+
+(define (pgdb:get-pg-lst tab2-pages)
+ (let loop ((i 1)
+ (lst `()))
+ (cond
+ ((> i tab2-pages )
+ lst)
+ (else
+ (loop (+ i 1) (append lst (list i)))))))
+
+)
ADDED attic_modular/pkts.scm
Index: attic_modular/pkts.scm
==================================================================
--- /dev/null
+++ attic_modular/pkts.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit pkts))
+
+(include "pkts/pkts.scm")
ADDED attic_modular/portlogger.import.scm
Index: attic_modular/portlogger.import.scm
==================================================================
--- /dev/null
+++ attic_modular/portlogger.import.scm
@@ -0,0 +1,38 @@
+;;;; portlogger.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ srfi-18
+ extras
+ tcp
+ s11n
+ (prefix sqlite3 sqlite3:)
+ srfi-1
+ posix
+ srfi-69
+ hostinfo
+ dot-locking
+ z3
+ commonmod
+ debugprint
+ configfmod
+ dbmod))
+(##sys#register-compiled-module
+ 'portlogger
+ (list)
+ '((portlogger:main . portlogger#portlogger:main)
+ (portlogger:set-failed . portlogger#portlogger:set-failed)
+ (portlogger:set-port . portlogger#portlogger:set-port)
+ (portlogger:find-port . portlogger#portlogger:find-port)
+ (portlogger:get-prev-used-port . portlogger#portlogger:get-prev-used-port)
+ (portlogger:take-port . portlogger#portlogger:take-port)
+ (portlogger:open-run-close . portlogger#portlogger:open-run-close)
+ (portlogger:open-db . portlogger#portlogger:open-db))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/portlogger.scm
Index: attic_modular/portlogger.scm
==================================================================
--- /dev/null
+++ attic_modular/portlogger.scm
@@ -0,0 +1,204 @@
+
+;; Copyright 2006-2014, 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 .
+;;
+
+
+
+(declare (unit portlogger))
+;; (declare (uses db))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses configfmod))
+(declare (uses dbmod))
+
+(module portlogger
+ *
+
+(import scheme chicken data-structures extras ports)
+(import (srfi 18) extras tcp s11n)
+
+(use (prefix sqlite3 sqlite3:) srfi-1 posix srfi-69 hostinfo dot-locking z3)
+
+(import commonmod)
+(import debugprint)
+(import configfmod)
+(import dbmod)
+
+;; lsof -i
+
+(define (portlogger:open-db fname)
+ (let* ((avail (tasks:wait-on-journal fname 5 remove: #t)) ;; wait up to about 10 seconds for the journal to go away
+ (exists (common:file-exists? fname))
+ (db (if avail
+ (sqlite3:open-database fname)
+ (begin
+ (system (conc "rm -f " fname))
+ (sqlite3:open-database fname))))
+ (handler (sqlite3:make-busy-timeout 136000))
+ (canwrite (file-write-access? fname)))
+ ;; (db-init (lambda ()
+ ;; (sqlite3:execute
+ ;; db
+ ;; "CREATE TABLE IF NOT EXISTS ports (
+ ;; port INTEGER PRIMARY KEY,
+ ;; state TEXT DEFAULT 'not-used',
+ ;; fail_count INTEGER DEFAULT 0,
+ ;; update_time TIMESTAMP DEFAULT (strftime('%s','now')) );"))))
+ (sqlite3:set-busy-handler! db handler)
+ (db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = 0;")
+ ;; (if (not exists) ;; needed with IF NOT EXISTS?
+ (sqlite3:execute
+ db
+ "CREATE TABLE IF NOT EXISTS ports (
+ port INTEGER PRIMARY KEY,
+ state TEXT DEFAULT 'not-used',
+ fail_count INTEGER DEFAULT 0,
+ update_time TIMESTAMP DEFAULT (strftime('%s','now')) );")
+ db))
+
+(define (portlogger:open-run-close proc . params)
+ (let* ((fname (conc "/tmp/." (current-user-name) "-portlogger.db"))
+ (avail (tasks:wait-on-journal fname 10))) ;; wait up to about 10 seconds for the journal to go away
+ (handle-exceptions
+ exn
+ (begin
+ ;; (release-dot-lock fname)
+ (debug:print-error 0 *default-log-port* "portlogger:open-run-close failed. " proc " " params)
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* "exn=" (condition->list exn))
+ (if (common:file-exists? fname)(delete-file fname)) ;; brutally get rid of it
+ (print-call-chain (current-error-port)))
+ (let* (;; (lock (obtain-dot-lock fname 2 9 10))
+ (db (portlogger:open-db fname))
+ (res (apply proc db params)))
+ (sqlite3:finalize! db)
+ ;; (release-dot-lock fname)
+ res))))
+
+;; (fold-row PROC INIT DATABASE SQL . PARAMETERS)
+(define (portlogger:take-port db portnum)
+ (let* ((qry1 (sqlite3:prepare db "INSERT INTO ports (port,state) VALUES (?,?);"))
+ (qry2 (sqlite3:prepare db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;"))
+ (qry3 (sqlite3:prepare db "SELECT state FROM ports WHERE port=?;"))
+ (res (sqlite3:with-transaction
+ db
+ (lambda ()
+ ;; (fold-row (lambda (var curr) (or var curr)) #f db "SELECT var FROM foo WHERE id=100;")
+ (let* ((curr #f)
+ (res #f))
+ (set! curr (sqlite3:fold-row
+ (lambda (var curr)
+ (or curr var curr))
+ "not-tried"
+ qry3
+ portnum))
+ ;; (print "curr=" curr)
+ (set! res (case (string->symbol curr)
+ ((released) (sqlite3:execute qry2 "taken" portnum) 'taken)
+ ((not-tried) (sqlite3:execute qry1 portnum "taken") 'taken)
+ ((taken) 'already-taken)
+ ((failed) 'failed)
+ (else 'error)))
+ ;; (print "res=" res)
+ res)))))
+ (sqlite3:finalize! qry1)
+ (sqlite3:finalize! qry2)
+ (sqlite3:finalize! qry3)
+ res))
+
+(define (portlogger:get-prev-used-port db)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "EXCEPTION: portlogger database probably overloaded or unreadable. If you see this message again remove /tmp/.$USER-portlogger.db")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* "exn=" (condition->list exn))
+ (print-call-chain (current-error-port))
+ (debug:print 0 *default-log-port* "Continuing anyway.")
+ #f)
+ (sqlite3:fold-row
+ (lambda (var curr)
+ (or curr var curr))
+ #f
+ db
+ "SELECT (port) FROM ports WHERE state='released' LIMIT 1;")))
+
+(define (portlogger:find-port db)
+ (let* ((lowport (let ((val (configf:lookup *configdat* "server" "lowport")))
+ (if (and val
+ (string->number val))
+ (string->number val)
+ 32768)))
+ (portnum (or (portlogger:get-prev-used-port db)
+ (+ lowport ;; top of registered ports is 49152 but lets use ports in the registered range
+ (random (- 64000 lowport))))))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "EXCEPTION: portlogger database probably overloaded or unreadable. If you see this message again remove /tmp/.$USER-portlogger.db")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* "exn=" (condition->list exn))
+ (print-call-chain (current-error-port))
+ (debug:print 0 *default-log-port* "Continuing anyway."))
+ (portlogger:take-port db portnum))
+ portnum))
+
+;; set port to "released", "failed" etc.
+;;
+(define (portlogger:set-port db portnum value)
+ (sqlite3:execute db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;" value portnum))
+
+;; set port to failed (attempted to take but got error)
+;;
+(define (portlogger:set-failed db portnum)
+ (sqlite3:execute db "UPDATE ports SET state='failed',fail_count=fail_count+1,update_time=strftime('%s','now') WHERE port=?;" portnum))
+
+;;======================================================================
+;; MAIN
+;;======================================================================
+
+(define (portlogger:main . args)
+ (let* ((dbfname (conc "/tmp/." (current-user-name) "-portlogger.db"))
+ (db (portlogger:open-db dbfname))
+ (numargs (length args))
+ (result
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "EXCEPTION: portlogger database at " dbfname " probably overloaded or unreadable. Try removing it.")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* "exn=" (condition->list exn))
+ (debug:print 0 *default-log-port* " status: " ((condition-property-accessor 'sqlite3 'status) exn))
+ (print-call-chain (current-error-port))
+ #f)
+ (case (string->symbol (car args)) ;; commands with two or more params
+ ((take)(portlogger:take-port db (string->number (cadr args))))
+ ((find)(portlogger:find-port db))
+ ((set) (let ((port (cadr args))
+ (state (caddr args)))
+ (portlogger:set-port db
+ (if (number? port) port (string->number port))
+ state)
+ state))
+ ((failed)(portlogger:set-failed db (string->number (cadr args))) 'failed)))))
+ (sqlite3:finalize! db)
+ result))
+
+;; (print (apply portlogger:main (cdr (argv))))
+
+)
ADDED attic_modular/process.scm
Index: attic_modular/process.scm
==================================================================
--- /dev/null
+++ attic_modular/process.scm
@@ -0,0 +1,32 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+
+;;======================================================================
+
+;;======================================================================
+;; Process convience utils
+;;======================================================================
+
+(use regex directory-utils)
+(declare (unit process))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
ADDED attic_modular/readline-fix.scm
Index: attic_modular/readline-fix.scm
==================================================================
--- /dev/null
+++ attic_modular/readline-fix.scm
@@ -0,0 +1,1 @@
+(define *use-new-readline* #t)
ADDED attic_modular/records-vs-vectors-vs-coops.scm
Index: attic_modular/records-vs-vectors-vs-coops.scm
==================================================================
--- /dev/null
+++ attic_modular/records-vs-vectors-vs-coops.scm
@@ -0,0 +1,110 @@
+;; 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 .
+
+;; (include "vg.scm")
+
+;; (declare (uses vg))
+
+(use foof-loop defstruct coops)
+
+(defstruct obj type fill-color angle)
+
+(define (make-vg:obj)(make-vector 3))
+(define-inline (vg:obj-get-type vec) (vector-ref vec 0))
+(define-inline (vg:obj-get-fill-color vec) (vector-ref vec 1))
+(define-inline (vg:obj-get-angle vec) (vector-ref vec 2))
+(define-inline (vg:obj-set-type! vec val)(vector-set! vec 0 val))
+(define-inline (vg:obj-set-fill-color! vec val)(vector-set! vec 1 val))
+(define-inline (vg:obj-set-angle! vec val)(vector-set! vec 2 val))
+
+(use simple-exceptions)
+(define vgs:obj-exn (make-exception "wrong record type, expected vgs:obj." 'assert))
+(define (make-vgs:obj)(let ((v (make-vector 4)))(vector-set! v 0 'vgs:obj) v))
+(define-inline (vgs:obj-type vec)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-ref vec 1)(raise (vgs:obj-exn 'vgs:obj-type 'xpr))))
+(define-inline (vgs:obj-fill-color vec)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-ref vec 2)(raise (vgs:obj-exn 'vgs:obj-fill-color 'xpr))))
+(define-inline (vgs:obj-angle vec)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-ref vec 3)(raise (vgs:obj-exn 'vgs:obj-angle 'xpr))))
+(define-inline (vgs:obj-type-set! vec val)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-set! vec 1 val)(raise (vgs:obj-exn 'type))))
+(define-inline (vgs:obj-fill-color-set! vec val)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-set! vec 2 val)(raise (vgs:obj-exn 'fill-color))))
+(define-inline (vgs:obj-angle-set! vec val)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-set! vec 3 val)(raise (vgs:obj-exn 'angle))))
+
+(define-class ()
+ ((type)
+ (fill-color)
+ (angle)))
+
+
+;; first use raw vectors
+(print "Using vectors")
+(time
+ (loop ((for r (up-from 0 (to 255))))
+ (loop ((for g (up-from 0 (to 255))))
+ (loop ((for b (up-from 0 (to 255))))
+ (let ((obj (make-vg:obj)))
+ (vg:obj-set-type! obj 'abc)
+ (vg:obj-set-fill-color! obj "green")
+ (vg:obj-set-angle! obj 135)
+ (let ((a (vg:obj-get-type obj))
+ (b (vg:obj-get-fill-color obj))
+ (c (vg:obj-get-angle obj)))
+ obj))))))
+
+;; first use raw vectors with safe mode
+(print "Using vectors (safe mode)")
+(time
+ (loop ((for r (up-from 0 (to 255))))
+ (loop ((for g (up-from 0 (to 255))))
+ (loop ((for b (up-from 0 (to 255))))
+ (let ((obj (make-vgs:obj)))
+ ;; (badobj (make-vector 20)))
+ (vgs:obj-type-set! obj 'abc)
+ (vgs:obj-fill-color-set! obj "green")
+ (vgs:obj-angle-set! obj 135)
+ (let ((a (vgs:obj-type obj))
+ (b (vgs:obj-fill-color obj))
+ (c (vgs:obj-angle obj)))
+ obj))))))
+
+;; first use defstruct
+(print "Using defstruct")
+(time
+ (loop ((for r (up-from 0 (to 255))))
+ (loop ((for g (up-from 0 (to 255))))
+ (loop ((for b (up-from 0 (to 255))))
+ (let ((obj (make-obj)))
+ (obj-type-set! obj 'abc)
+ (obj-fill-color-set! obj "green")
+ (obj-angle-set! obj 135)
+ (let ((a (obj-type obj))
+ (b (obj-fill-color obj))
+ (c (obj-angle obj)))
+ obj))))))
+
+
+;; first use defstruct
+(print "Using coops")
+(time
+ (loop ((for r (up-from 0 (to 255))))
+ (loop ((for g (up-from 0 (to 255))))
+ (loop ((for b (up-from 0 (to 255))))
+ (let ((obj (make )))
+ (set! (slot-value obj 'type) 'abc)
+ (set! (slot-value obj 'fill-color) "green")
+ (set! (slot-value obj 'angle) 135)
+ (let ((a (slot-value obj 'type))
+ (b (slot-value obj 'fill-color))
+ (c (slot-value obj 'angle)))
+ obj))))))
ADDED attic_modular/rmt.scm
Index: attic_modular/rmt.scm
==================================================================
--- /dev/null
+++ attic_modular/rmt.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; 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 .
+;;
+;;======================================================================
+
+(use format typed-records) ;; RADT => purpose of json format??
+
+(declare (unit rmt))
ADDED attic_modular/rmtdb.scm
Index: attic_modular/rmtdb.scm
==================================================================
--- /dev/null
+++ attic_modular/rmtdb.scm
@@ -0,0 +1,20 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+
+;;======================================================================
+
ADDED attic_modular/rmtmod.import.scm
Index: attic_modular/rmtmod.import.scm
==================================================================
--- /dev/null
+++ attic_modular/rmtmod.import.scm
@@ -0,0 +1,325 @@
+;;;; rmtmod.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ (prefix sqlite3 sqlite3:)
+ directory-utils
+ intarweb
+ matchable
+ md5
+ message-digest
+ uri-common
+ spiffy
+ spiffy-directory-listing
+ spiffy-request-vars
+ http-client
+ posix
+ posix-extras
+ regex
+ typed-records
+ srfi-1
+ srfi-13
+ srfi-18
+ srfi-69
+ tcp
+ apimod
+ commonmod
+ debugprint
+ dbmod
+ configfmod
+ margsmod
+ portlogger
+ items
+ tdb))
+(##sys#register-compiled-module
+ 'rmtmod
+ (list)
+ '((tdb:open-test-db-by-test-id . rmtmod#tdb:open-test-db-by-test-id)
+ (tdb:load-logpro-data . rmtmod#tdb:load-logpro-data)
+ (tdb:load-test-data . rmtmod#tdb:load-test-data)
+ (client:setup-http . rmtmod#client:setup-http)
+ (client:setup . rmtmod#client:setup)
+ (client:get-signature . rmtmod#client:get-signature)
+ (common:get-launcher . rmtmod#common:get-launcher)
+ (common:get-least-loaded-host . rmtmod#common:get-least-loaded-host)
+ (common:update-host-loads-table . rmtmod#common:update-host-loads-table)
+ (common:api-changed? . rmtmod#common:api-changed?)
+ (common:version-changed? . rmtmod#common:version-changed?)
+ (common:version-db-delta . rmtmod#common:version-db-delta)
+ (common:get-last-run-version-number
+ .
+ rmtmod#common:get-last-run-version-number)
+ (common:set-last-run-version . rmtmod#common:set-last-run-version)
+ (common:get-last-run-version . rmtmod#common:get-last-run-version)
+ (std-exit-procedure . rmtmod#std-exit-procedure)
+ (common:get-host-info . rmtmod#common:get-host-info)
+ (common:simple-unlock . rmtmod#common:simple-unlock)
+ (common:simple-lock . rmtmod#common:simple-lock)
+ (common:faux-unlock . rmtmod#common:faux-unlock)
+ (common:faux-lock . rmtmod#common:faux-lock)
+ (http-transport:launch . rmtmod#http-transport:launch)
+ (http-transport:server-shutdown . rmtmod#http-transport:server-shutdown)
+ (http-transport:keep-running . rmtmod#http-transport:keep-running)
+ (http-transport:client-connect . rmtmod#http-transport:client-connect)
+ (http-transport:server-dat-update-last-access
+ .
+ rmtmod#http-transport:server-dat-update-last-access)
+ (http-transport:server-dat-make-url
+ .
+ rmtmod#http-transport:server-dat-make-url)
+ (http-transport:server-dat-get-server-id
+ .
+ rmtmod#http-transport:server-dat-get-server-id)
+ (http-transport:server-dat-get-last-access
+ .
+ rmtmod#http-transport:server-dat-get-last-access)
+ (http-transport:server-dat-get-api-req
+ .
+ rmtmod#http-transport:server-dat-get-api-req)
+ (http-transport:server-dat-get-api-url
+ .
+ rmtmod#http-transport:server-dat-get-api-url)
+ (http-transport:server-dat-get-api-uri
+ .
+ rmtmod#http-transport:server-dat-get-api-uri)
+ (http-transport:server-dat-get-port
+ .
+ rmtmod#http-transport:server-dat-get-port)
+ (http-transport:server-dat-get-iface
+ .
+ rmtmod#http-transport:server-dat-get-iface)
+ (make-http-transport:server-dat . rmtmod#make-http-transport:server-dat)
+ (http-transport:close-connections
+ .
+ rmtmod#http-transport:close-connections)
+ (http-transport:client-api-send-receive
+ .
+ rmtmod#http-transport:client-api-send-receive)
+ (http-transport:inc-requests-and-prep-to-close-all-connections
+ .
+ rmtmod#http-transport:inc-requests-and-prep-to-close-all-connections)
+ (http-transport:dec-requests-count-and-close-all-connections
+ .
+ rmtmod#http-transport:dec-requests-count-and-close-all-connections)
+ (http-transport:dec-requests-count
+ .
+ rmtmod#http-transport:dec-requests-count)
+ (http-transport:inc-requests-count
+ .
+ rmtmod#http-transport:inc-requests-count)
+ (http-transport:get-time-to-cleanup
+ .
+ rmtmod#http-transport:get-time-to-cleanup)
+ (*http-connections-next-cleanup* . rmtmod#*http-connections-next-cleanup*)
+ (*http-requests-in-progress* . rmtmod#*http-requests-in-progress*)
+ (*http-mutex* . rmtmod#*http-mutex*)
+ (server:try-running . rmtmod#server:try-running)
+ (server:check-server . rmtmod#server:check-server)
+ (server:check-if-running . rmtmod#server:check-if-running)
+ (server:start-and-wait . rmtmod#server:start-and-wait)
+ (server:ping . rmtmod#server:ping)
+ (server:run . rmtmod#server:run)
+ (server:launch . rmtmod#server:launch)
+ (server:expiration-timeout . rmtmod#server:expiration-timeout)
+ (server:login . rmtmod#server:login)
+ (server:ping-server . rmtmod#server:ping-server)
+ (server:kill . rmtmod#server:kill)
+ (server:get-num-servers . rmtmod#server:get-num-servers)
+ (server:wait-for-server-start-last-flag
+ .
+ rmtmod#server:wait-for-server-start-last-flag)
+ (server:get-client-signature . rmtmod#server:get-client-signature)
+ (server:record->url . rmtmod#server:record->url)
+ (server:record->id . rmtmod#server:record->id)
+ (server:get-rand-best . rmtmod#server:get-rand-best)
+ (server:get-first-best . rmtmod#server:get-first-best)
+ (server:get-best . rmtmod#server:get-best)
+ (server:get-num-alive . rmtmod#server:get-num-alive)
+ (server:kind-run . rmtmod#server:kind-run)
+ (server:reply . rmtmod#server:reply)
+ (server:mk-signature . rmtmod#server:mk-signature)
+ (server:make-server-url . rmtmod#server:make-server-url)
+ (http-transport:try-start-server . rmtmod#http-transport:try-start-server)
+ (http-transport:run . rmtmod#http-transport:run)
+ (http-transport:make-server-url . rmtmod#http-transport:make-server-url)
+ (extras-transport-succeded . rmtmod#extras-transport-succeded)
+ (extras-transport-failed . rmtmod#extras-transport-failed)
+ (extras-readonly-mode . rmtmod#extras-readonly-mode)
+ (rmt:test-get-archive-block-info . rmtmod#rmt:test-get-archive-block-info)
+ (rmt:test-set-archive-block-id . rmtmod#rmt:test-set-archive-block-id)
+ (rmt:archive-register-disk . rmtmod#rmt:archive-register-disk)
+ (rmt:archive-allocate-testsuite/area-to-block
+ .
+ rmtmod#rmt:archive-allocate-testsuite/area-to-block)
+ (rmt:archive-register-block-name . rmtmod#rmt:archive-register-block-name)
+ (rmt:archive-get-allocations . rmtmod#rmt:archive-get-allocations)
+ (rmt:no-sync-get-lock . rmtmod#rmt:no-sync-get-lock)
+ (rmt:no-sync-del! . rmtmod#rmt:no-sync-del!)
+ (rmt:no-sync-get/default . rmtmod#rmt:no-sync-get/default)
+ (rmt:no-sync-set . rmtmod#rmt:no-sync-set)
+ (rmt:tasks-get-last . rmtmod#rmt:tasks-get-last)
+ (rmt:tasks-set-state-given-param-key
+ .
+ rmtmod#rmt:tasks-set-state-given-param-key)
+ (rmt:tasks-add . rmtmod#rmt:tasks-add)
+ (rmt:tasks-find-task-queue-records
+ .
+ rmtmod#rmt:tasks-find-task-queue-records)
+ (rmt:csv->test-data . rmtmod#rmt:csv->test-data)
+ (rmt:test-data-rollup . rmtmod#rmt:test-data-rollup)
+ (rmt:testmeta-update-field . rmtmod#rmt:testmeta-update-field)
+ (rmt:testmeta-get-record . rmtmod#rmt:testmeta-get-record)
+ (rmt:testmeta-add-record . rmtmod#rmt:testmeta-add-record)
+ (rmt:get-data-info-by-id . rmtmod#rmt:get-data-info-by-id)
+ (rmt:read-test-data-varpatt . rmtmod#rmt:read-test-data-varpatt)
+ (rmt:read-test-data . rmtmod#rmt:read-test-data)
+ (rmt:get-steps-info-by-id . rmtmod#rmt:get-steps-info-by-id)
+ (rmt:get-steps-for-test . rmtmod#rmt:get-steps-for-test)
+ (rmt:delete-steps-for-test! . rmtmod#rmt:delete-steps-for-test!)
+ (rmt:teststep-set-status! . rmtmod#rmt:teststep-set-status!)
+ (rmt:get-run-stats . rmtmod#rmt:get-run-stats)
+ (rmt:get-previous-test-run-record
+ .
+ rmtmod#rmt:get-previous-test-run-record)
+ (rmt:find-and-mark-incomplete-all-runs
+ .
+ rmtmod#rmt:find-and-mark-incomplete-all-runs)
+ (rmt:add-var . rmtmod#rmt:add-var)
+ (rmt:dec-var . rmtmod#rmt:dec-var)
+ (rmt:inc-var . rmtmod#rmt:inc-var)
+ (rmt:set-var . rmtmod#rmt:set-var)
+ (rmt:del-var . rmtmod#rmt:del-var)
+ (rmt:get-var . rmtmod#rmt:get-var)
+ (rmt:get-main-run-stats . rmtmod#rmt:get-main-run-stats)
+ (rmt:find-and-mark-incomplete . rmtmod#rmt:find-and-mark-incomplete)
+ (rmt:get-runs-by-patt . rmtmod#rmt:get-runs-by-patt)
+ (rmt:update-run-event_time . rmtmod#rmt:update-run-event_time)
+ (rmt:update-tesdata-on-repilcate-db
+ .
+ rmtmod#rmt:update-tesdata-on-repilcate-db)
+ (rmt:set-run-state-status . rmtmod#rmt:set-run-state-status)
+ (rmt:set-run-status . rmtmod#rmt:set-run-status)
+ (rmt:get-run-state . rmtmod#rmt:get-run-state)
+ (rmt:get-run-status . rmtmod#rmt:get-run-status)
+ (rmt:lock/unlock-run . rmtmod#rmt:lock/unlock-run)
+ (rmt:get-prev-run-ids . rmtmod#rmt:get-prev-run-ids)
+ (rmt:get-all-run-ids . rmtmod#rmt:get-all-run-ids)
+ (rmt:simple-get-runs . rmtmod#rmt:simple-get-runs)
+ (rmt:get-runs . rmtmod#rmt:get-runs)
+ (rmt:delete-old-deleted-test-records
+ .
+ rmtmod#rmt:delete-old-deleted-test-records)
+ (rmt:update-run-stats . rmtmod#rmt:update-run-stats)
+ (rmt:delete-run . rmtmod#rmt:delete-run)
+ (rmt:get-run-name-from-id . rmtmod#rmt:get-run-name-from-id)
+ (rmt:register-run . rmtmod#rmt:register-run)
+ (rmt:get-runs-cnt-by-patt . rmtmod#rmt:get-runs-cnt-by-patt)
+ (rmt:get-num-runs . rmtmod#rmt:get-num-runs)
+ (rmt:get-run-info . rmtmod#rmt:get-run-info)
+ (rmt:get-test-times . rmtmod#rmt:get-test-times)
+ (rmt:get-raw-run-stats . rmtmod#rmt:get-raw-run-stats)
+ (rmt:top-test-set-per-pf-counts . rmtmod#rmt:top-test-set-per-pf-counts)
+ (rmt:update-pass-fail-counts . rmtmod#rmt:update-pass-fail-counts)
+ (rmt:set-state-status-and-roll-up-run
+ .
+ rmtmod#rmt:set-state-status-and-roll-up-run)
+ (rmt:set-state-status-and-roll-up-items
+ .
+ rmtmod#rmt:set-state-status-and-roll-up-items)
+ (rmt:get-count-tests-running-in-jobgroup
+ .
+ rmtmod#rmt:get-count-tests-running-in-jobgroup)
+ (rmt:get-count-tests-running-for-testname
+ .
+ rmtmod#rmt:get-count-tests-running-for-testname)
+ (rmt:get-count-tests-running . rmtmod#rmt:get-count-tests-running)
+ (rmt:get-not-completed-cnt . rmtmod#rmt:get-not-completed-cnt)
+ (rmt:get-count-tests-running-for-run-id
+ .
+ rmtmod#rmt:get-count-tests-running-for-run-id)
+ (rmt:get-prereqs-not-met . rmtmod#rmt:get-prereqs-not-met)
+ (rmt:test-get-paths-matching-keynames-target-new
+ .
+ rmtmod#rmt:test-get-paths-matching-keynames-target-new)
+ (rmt:get-run-ids-matching-target . rmtmod#rmt:get-run-ids-matching-target)
+ (rmt:test-get-top-process-pid . rmtmod#rmt:test-get-top-process-pid)
+ (rmt:test-set-top-process-pid . rmtmod#rmt:test-set-top-process-pid)
+ (rmt:test-set-log! . rmtmod#rmt:test-set-log!)
+ (rmt:get-testinfo-state-status . rmtmod#rmt:get-testinfo-state-status)
+ (rmt:test-get-records-for-index-file
+ .
+ rmtmod#rmt:test-get-records-for-index-file)
+ (rmt:test-get-logfile-info . rmtmod#rmt:test-get-logfile-info)
+ (rmt:get-matching-previous-test-run-records
+ .
+ rmtmod#rmt:get-matching-previous-test-run-records)
+ (rmt:test-toplevel-num-items . rmtmod#rmt:test-toplevel-num-items)
+ (rmt:test-set-state-status . rmtmod#rmt:test-set-state-status)
+ (rmt:delete-test-records . rmtmod#rmt:delete-test-records)
+ (rmt:get-tests-for-runs-mindata . rmtmod#rmt:get-tests-for-runs-mindata)
+ (rmt:get-tests-for-run-mindata . rmtmod#rmt:get-tests-for-run-mindata)
+ (rmt:synchash-get . rmtmod#rmt:synchash-get)
+ (rmt:get-tests-for-run-state-status
+ .
+ rmtmod#rmt:get-tests-for-run-state-status)
+ (rmt:get-tests-for-run . rmtmod#rmt:get-tests-for-run)
+ (rmt:set-tests-state-status . rmtmod#rmt:set-tests-state-status)
+ (rmt:test-set-state-status-by-id . rmtmod#rmt:test-set-state-status-by-id)
+ (rmt:open-test-db-by-test-id . rmtmod#rmt:open-test-db-by-test-id)
+ (rmt:test-get-rundir-from-test-id
+ .
+ rmtmod#rmt:test-get-rundir-from-test-id)
+ (rmt:get-test-info-by-id . rmtmod#rmt:get-test-info-by-id)
+ (rmt:get-test-id . rmtmod#rmt:get-test-id)
+ (rmt:register-test . rmtmod#rmt:register-test)
+ (rmt:get-run-times . rmtmod#rmt:get-run-times)
+ (rmt:get-target . rmtmod#rmt:get-target)
+ (rmt:get-targets . rmtmod#rmt:get-targets)
+ (rmt:get-key-vals . rmtmod#rmt:get-key-vals)
+ (rmt:get-keys-write . rmtmod#rmt:get-keys-write)
+ (rmt:get-keys . rmtmod#rmt:get-keys)
+ (rmt:get-key-val-pairs . rmtmod#rmt:get-key-val-pairs)
+ (rmt:get-tests-tags . rmtmod#rmt:get-tests-tags)
+ (rmt:create-all-triggers . rmtmod#rmt:create-all-triggers)
+ (rmt:drop-all-triggers . rmtmod#rmt:drop-all-triggers)
+ (rmt:get-changed-record-ids . rmtmod#rmt:get-changed-record-ids)
+ (rmt:get-run-record-ids . rmtmod#rmt:get-run-record-ids)
+ (rmt:runtests . rmtmod#rmt:runtests)
+ (rmt:sdb-qry . rmtmod#rmt:sdb-qry)
+ (rmt:get-latest-host-load . rmtmod#rmt:get-latest-host-load)
+ (rmt:general-call . rmtmod#rmt:general-call)
+ (rmt:login-no-auto-client-setup . rmtmod#rmt:login-no-auto-client-setup)
+ (rmt:login . rmtmod#rmt:login)
+ (rmt:start-server . rmtmod#rmt:start-server)
+ (rmt:kill-server . rmtmod#rmt:kill-server)
+ (rmt:send-receive-no-auto-client-setup
+ .
+ rmtmod#rmt:send-receive-no-auto-client-setup)
+ (rmt:open-qry-close-locally . rmtmod#rmt:open-qry-close-locally)
+ (rmt:get-max-query-average . rmtmod#rmt:get-max-query-average)
+ (rmt:print-db-stats . rmtmod#rmt:print-db-stats)
+ (extras-case-11 . rmtmod#extras-case-11)
+ (rmt:send-receive . rmtmod#rmt:send-receive)
+ (rmt:init-remote . rmtmod#rmt:init-remote)
+ (create-remote-record . rmtmod#create-remote-record)
+ (rmt:get-connection-info . rmtmod#rmt:get-connection-info)
+ (rmtmod:calc-ro-mode . rmtmod#rmtmod:calc-ro-mode)
+ (alist->alldat . rmtmod#alist->alldat)
+ (alldat->alist . rmtmod#alldat->alist)
+ (update-alldat . rmtmod#update-alldat)
+ (set-alldat! . rmtmod#set-alldat!)
+ (make-alldat . rmtmod#make-alldat)
+ (alldat-ulexdat . rmtmod#alldat-ulexdat)
+ (alldat-ulexdat-set! . rmtmod#alldat-ulexdat-set!)
+ (alldat-areapath . rmtmod#alldat-areapath)
+ (alldat-areapath-set! . rmtmod#alldat-areapath-set!)
+ (alldat? . rmtmod#alldat?)
+ (make-alldat . rmtmod#make-alldat))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/rmtmod.scm
Index: attic_modular/rmtmod.scm
==================================================================
--- /dev/null
+++ attic_modular/rmtmod.scm
@@ -0,0 +1,2615 @@
+;;======================================================================
+;; Copyright 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 .
+
+;;======================================================================
+
+(declare (unit rmtmod))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses apimod))
+(declare (uses dbmod))
+(declare (uses configfmod))
+(declare (uses margsmod))
+(declare (uses portlogger))
+(declare (uses items))
+(declare (uses tdb))
+
+(module rmtmod
+ *
+
+(import scheme chicken data-structures extras ports)
+(import (prefix sqlite3 sqlite3:)
+ directory-utils
+ intarweb
+ matchable
+ md5
+ message-digest
+ uri-common
+ spiffy
+ spiffy-directory-listing
+ spiffy-request-vars
+ http-client
+ posix
+ posix-extras
+ regex
+ typed-records
+ srfi-1
+ srfi-13
+ srfi-18
+ srfi-69
+ tcp)
+(import apimod)
+(import commonmod)
+(import debugprint)
+(import dbmod)
+(import configfmod)
+(import margsmod)
+(import portlogger)
+(import items)
+(import tdb)
+
+(defstruct alldat
+ (areapath #f)
+ (ulexdat #f)
+ )
+
+(define (rmtmod:calc-ro-mode runremote *toppath*)
+ (if (and runremote
+ (remote-ro-mode-checked runremote))
+ (remote-ro-mode runremote)
+ (let* ((ro-mode (not (db:writeable *toppath* "megatest.db"))))
+ (if runremote
+ (begin
+ (remote-ro-mode-set! runremote ro-mode)
+ (remote-ro-mode-checked-set! runremote #t)
+ ro-mode)
+ ro-mode))))
+
+;;
+;; THESE ARE ALL CALLED ON THE CLIENT SIDE!!!
+;;
+
+;; generate entries for ~/.megatestrc with the following
+;;
+;; grep define ../rmt.scm | grep rmt: |perl -pi -e 's/\(define\s+\((\S+)\W.*$/\1/'|sort -u
+
+;;======================================================================
+;; S U P P O R T F U N C T I O N S
+;;======================================================================
+
+;; if a server is either running or in the process of starting call client:setup
+;; else return #f to let the calling proc know that there is no server available
+;;
+(define (rmt:get-connection-info areapath #!key (area-dat #f)) ;; TODO: push areapath down.
+ (let* ((runremote (or area-dat *runremote*))
+ (cinfo (if (remote? runremote)
+ (remote-conndat runremote)
+ #f)))
+ (if cinfo
+ cinfo
+ (if (server:check-if-running areapath)
+ (client:setup areapath)
+ #f))))
+
+;;======================================================================
+
+(define (create-remote-record)
+ (let ((rr (make-remote)))
+ (rmt:init-remote rr)
+ rr))
+
+(define (rmt:init-remote rr)
+ (remote-hh-dat-set! rr (common:get-homehost)) ;
+ (remote-server-info-set! rr (if *toppath* (server:check-if-running *toppath*) #f))
+ (remote-transport-set! rr *transport-type*)
+ (remote-server-timeout-set! rr (server:expiration-timeout))
+ rr)
+
+;; RA => e.g. usage (rmt:send-receive 'get-var #f (list varname))
+;;
+(define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) ;; start attemptnum at 1 so the modulo below works as expected
+
+ #;(common:telemetry-log (conc "rmt:"(->string cmd))
+ payload: `((rid . ,rid)
+ (params . ,params)))
+
+ (if (> attemptnum 2)
+ (debug:print 0 *default-log-port* "INFO: attemptnum in rmt:send-receive is " attemptnum))
+
+ (cond
+ ((> attemptnum 2) (thread-sleep! 0.05))
+ ((> attemptnum 10) (thread-sleep! 0.5))
+ ((> attemptnum 20) (thread-sleep! 1)))
+ (if (and (> attemptnum 5) (= 0 (modulo attemptnum 15)))
+ (begin (server:run *toppath*) (thread-sleep! 3)))
+
+
+ ;;DOT digraph megatest_state_status {
+ ;;DOT ranksep=0;
+ ;;DOT // rankdir=LR;
+ ;;DOT node [shape="box"];
+ ;;DOT "rmt:send-receive" -> MUTEXLOCK;
+ ;;DOT { edge [style=invis];"case 1" -> "case 2" -> "case 3" -> "case 4" -> "case 5" -> "case 6" -> "case 7" -> "case 8" -> "case 9" -> "case 10" -> "case 11"; }
+ ;; do all the prep locked under the rmt-mutex
+ (mutex-lock! *rmt-mutex*)
+
+ ;; set up runremote record earlier than the loop below
+ (if (not *runremote*) ;; can remove this one. should never get here.
+ (begin
+ (set! *runremote* (create-remote-record))
+ (let* ((server-info (remote-server-info *runremote*)))
+ (if server-info
+ (begin
+ (remote-server-url-set! *runremote* (server:record->url server-info))
+ (remote-server-id-set! *runremote* (server:record->id server-info)))))
+ #;(set! area-dat *runremote*))) ;; new runremote will come from this on next iteration
+
+ ;; 1. check if server is started IFF cmd is a write OR if we are not on the homehost, store in runremote
+ ;; 2. check the age of the connections. refresh the connection if it is older than timeout-20 seconds.
+ ;; 3. do the query, if on homehost use local access
+ ;;
+ (let* ((start-time (current-seconds)) ;; snapshot time so all use cases get same value
+ (areapath *toppath*);; TODO - resolve from dbstruct to be compatible with multiple areas
+ (runremote (or area-dat
+ *runremote*))
+ (attemptnum (+ 1 attemptnum))
+ (readonly-mode (rmtmod:calc-ro-mode runremote *toppath*)))
+
+ ;; DOT INIT_RUNREMOTE; // leaving off - doesn't really add to the clarity
+ ;; DOT MUTEXLOCK -> INIT_RUNREMOTE [label="no remote?"];
+ ;; DOT INIT_RUNREMOTE -> MUTEXLOCK;
+ ;; ensure we have a record for our connection for given area
+ ;; DOT SET_HOMEHOST; // leaving off - doesn't really add to the clarity
+ ;; DOT MUTEXLOCK -> SET_HOMEHOST [label="no homehost?"];
+ ;; DOT SET_HOMEHOST -> MUTEXLOCK;
+ ;; ensure we have a homehost record
+ (if (not (pair? (remote-hh-dat runremote))) ;; not on homehost
+ (thread-sleep! 0.1) ;; since we shouldn't get here, delay a little
+ (remote-hh-dat-set! runremote (common:get-homehost)))
+
+ ;;(print "BB> readonly-mode is "readonly-mode" dbfile is "dbfile)
+ (cond
+ ;;DOT EXIT;
+ ;;DOT MUTEXLOCK -> EXIT [label="> 15 attempts"]; {rank=same "case 1" "EXIT" }
+ ;; give up if more than 150 attempts
+ ((> attemptnum 150)
+ (debug:print 0 *default-log-port* "ERROR: 150 tries to start/connect to server. Giving up.")
+ (exit 1))
+
+ ;;DOT CASE2 [label="local\nreadonly\nquery"];
+ ;;DOT MUTEXLOCK -> CASE2; {rank=same "case 2" CASE2}
+ ;;DOT CASE2 -> "rmt:open-qry-close-locally";
+ ;; readonly mode, read request- handle it - case 2
+ ((and readonly-mode
+ (member cmd api:read-only-queries))
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 2")
+ (rmt:open-qry-close-locally cmd 0 params)
+ )
+
+ ;;DOT CASE3 [label="write in\nread-only mode"];
+ ;;DOT MUTEXLOCK -> CASE3 [label="readonly\nmode?"]; {rank=same "case 3" CASE3}
+ ;;DOT CASE3 -> "#f";
+ ;; readonly mode, write request. Do nothing, return #f
+ (readonly-mode (extras-readonly-mode *rmt-mutex* *default-log-port* cmd params))
+
+ ;; This block was for pre-emptively resetting the connection if there had been no communication for some time.
+ ;; I don't think it adds any value. If the server is not there, just fail and start a new connection.
+ ;; also, the expire-time calculation might not be correct. We want, time-since-last-server-access > (server:get-timeout)
+ ;;
+ ;;DOT CASE4 [label="reset\nconnection"];
+ ;;DOT MUTEXLOCK -> CASE4 [label="have connection,\nlast_access > expire_time"]; {rank=same "case 4" CASE4}
+ ;;DOT CASE4 -> "rmt:send-receive";
+ ;; reset the connection if it has been unused too long
+ ((and runremote
+ (remote-conndat runremote)
+ (> (current-seconds) ;; if it has been more than server-timeout seconds since last contact, close this connection and start a new on
+ (+ (http-transport:server-dat-get-last-access (remote-conndat runremote))
+ (remote-server-timeout runremote))))
+ (debug:print-info 0 *default-log-port* "Connection to " (remote-server-url runremote) " expired due to no accesses, forcing new connection.")
+ (http-transport:close-connections area-dat: runremote)
+ (remote-conndat-set! runremote #f) ;; invalidate the connection, thus forcing a new connection.
+ (mutex-unlock! *rmt-mutex*)
+ (rmt:send-receive cmd rid params attemptnum: attemptnum))
+
+ ;;DOT CASE5 [label="local\nread"];
+ ;;DOT MUTEXLOCK -> CASE5 [label="server not required,\non homehost,\nread-only query"]; {rank=same "case 5" CASE5};
+ ;;DOT CASE5 -> "rmt:open-qry-close-locally";
+
+ ;; on homehost and this is a read
+ ((and (not (remote-force-server runremote)) ;; honor forced use of server, i.e. server NOT required
+ (cdr (remote-hh-dat runremote)) ;; on homehost
+ (member cmd api:read-only-queries)) ;; this is a read
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 5")
+ (rmt:open-qry-close-locally cmd 0 params))
+
+ ;;DOT CASE6 [label="init\nremote"];
+ ;;DOT MUTEXLOCK -> CASE6 [label="on homehost,\nwrite query,\nhave server,\ncan't reach it"]; {rank=same "case 6" CASE6};
+ ;;DOT CASE6 -> "rmt:send-receive";
+ ;; on homehost and this is a write, we already have a server, but server has died
+ ((and (cdr (remote-hh-dat runremote)) ;; on homehost
+ (not (member cmd api:read-only-queries)) ;; this is a write
+ (remote-server-url runremote) ;; have a server
+ (not (server:ping (remote-server-url runremote) (remote-server-id runremote)))) ;; server has died. NOTE: this is not a cheap call! Need better approach.
+ (set! *runremote* (create-remote-record))
+ (let* ((server-info (remote-server-info *runremote*)))
+ (if server-info
+ (begin
+ (remote-server-url-set! *runremote* (server:record->url server-info))
+ (remote-server-id-set! *runremote* (server:record->id server-info)))))
+ (remote-force-server-set! runremote (common:force-server?))
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 6")
+ (rmt:send-receive cmd rid params attemptnum: attemptnum))
+
+ ;;DOT CASE7 [label="homehost\nwrite"];
+ ;;DOT MUTEXLOCK -> CASE7 [label="server not required,\non homehost,\na write,\nhave a server"]; {rank=same "case 7" CASE7};
+ ;;DOT CASE7 -> "rmt:open-qry-close-locally";
+ ;; on homehost and this is a write, we already have a server
+ ((and (not (remote-force-server runremote)) ;; honor forced use of server, i.e. server NOT required
+ (cdr (remote-hh-dat runremote)) ;; on homehost
+ (not (member cmd api:read-only-queries)) ;; this is a write
+ (remote-server-url runremote)) ;; have a server
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 4.1")
+ (rmt:open-qry-close-locally cmd 0 params))
+
+ ;;DOT CASE8 [label="force\nserver"];
+ ;;DOT MUTEXLOCK -> CASE8 [label="server not required,\nhave homehost info,\nno connection yet,\nnot a read-only query"]; {rank=same "case 8" CASE8};
+ ;;DOT CASE8 -> "rmt:open-qry-close-locally";
+ ;; on homehost, no server contact made and this is a write, passively start a server
+ ((and (not (remote-force-server runremote)) ;; honor forced use of server, i.e. server NOT required
+ (cdr (remote-hh-dat runremote)) ;; have homehost
+ (not (remote-server-url runremote)) ;; no connection yet
+ (not (member cmd api:read-only-queries))) ;; not a read-only query
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 8")
+ (let ((server-info (server:check-if-running *toppath*))) ;; (server:read-dotserver->url *toppath*))) ;; (server:check-if-running *toppath*))) ;; Do NOT want to run server:check-if-running - very expensive to do for every write call
+ (if server-info
+ (begin
+ (remote-server-url-set! runremote (server:record->url server-info)) ;; the string can be consumed by the client setup if needed
+ (remote-server-id-set! runremote (server:record->id server-info)))
+ (if (common:force-server?)
+ (server:start-and-wait *toppath*)
+ (server:kind-run *toppath*)))
+ (remote-force-server-set! runremote (common:force-server?))
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 8.1")
+ (rmt:open-qry-close-locally cmd 0 params)))
+
+ ;;DOT CASE9 [label="force server\nnot on homehost"];
+ ;;DOT MUTEXLOCK -> CASE9 [label="no connection\nand either require server\nor not on homehost"]; {rank=same "case 9" CASE9};
+ ;;DOT CASE9 -> "start\nserver" -> "rmt:send-receive";
+ ((or (and (remote-force-server runremote) ;; we are forcing a server and don't yet have a connection to one
+ (not (remote-conndat runremote)))
+ (and (not (cdr (remote-hh-dat runremote))) ;; not on a homehost
+ (not (remote-conndat runremote)))) ;; and no connection
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 9, hh-dat: " (remote-hh-dat runremote) " conndat: " (remote-conndat runremote))
+ (mutex-unlock! *rmt-mutex*)
+ (if (not (server:check-if-running *toppath*)) ;; who knows, maybe one has started up?
+ (server:start-and-wait *toppath*))
+ (remote-conndat-set! runremote (rmt:get-connection-info *toppath*)) ;; calls client:setup which calls client:setup-http
+ (rmt:send-receive cmd rid params attemptnum: attemptnum)) ;; TODO: add back-off timeout as
+
+ ;;DOT CASE10 [label="on homehost"];
+ ;;DOT MUTEXLOCK -> CASE10 [label="server not required,\non homehost"]; {rank=same "case 10" CASE10};
+ ;;DOT CASE10 -> "rmt:open-qry-close-locally";
+ ;; all set up if get this far, dispatch the query
+ ((and (not (remote-force-server runremote))
+ (cdr (remote-hh-dat runremote))) ;; we are on homehost
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 10")
+ (rmt:open-qry-close-locally cmd (if rid rid 0) params))
+
+ ;;DOT CASE11 [label="send_receive"];
+ ;;DOT MUTEXLOCK -> CASE11 [label="else"]; {rank=same "case 11" CASE11};
+ ;;DOT CASE11 -> "rmt:send-receive" [label="call failed"];
+ ;;DOT CASE11 -> "RESULT" [label="call succeeded"];
+ ;; not on homehost, do server query
+ (else (extras-case-11 *default-log-port* runremote cmd params attemptnum rid)))))
+ ;;DOT }
+
+;; bunch of small functions factored out of send-receive to make debug easier
+;;
+
+(define (extras-case-11 *default-log-port* runremote cmd params attemptnum rid)
+ ;; (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 9")
+ ;; (mutex-lock! *rmt-mutex*)
+ (let* ((conninfo (remote-conndat runremote))
+ (dat-in (case (remote-transport runremote)
+ ((http) (condition-case ;; handling here has
+ ;; caused a lot of
+ ;; problems. However it
+ ;; is needed to deal with
+ ;; attemtped
+ ;; communication to
+ ;; servers that have gone
+ ;; away
+ (http-transport:client-api-send-receive 0 conninfo cmd params)
+ ((servermismatch) (vector #f "Server id mismatch" ))
+ ((commfail)(vector #f "communications fail"))
+ ((exn)(vector #f "other fail" (print-call-chain)))))
+ (else
+ (debug:print 0 *default-log-port* "ERROR: transport " (remote-transport runremote) " not supported")
+ (exit))))
+
+;; No Title
+;; Error: (vector-ref) out of range
+;; #(# (#("db.scm:3740: regex#regexp" #f #f) #("db.scm:3739: regex#string-substitute" #f #f) #("db.scm:3738: base64#base64-decode" #f #f) #("db.scm:3737: z3#z3:decode-buffer" #f #f) #("db.scm:3736: with-input-from-string" #f #f) #("db.scm:3741: s11n#deserialize" #f #f) #("api.scm:374: api:execute-requests" #f #f) #("api.scm:139: call-with-current-continuation" #f #f) #("api.scm:139: with-exception-handler" #f #f) #("api.scm:139: ##sys#call-with-values" #f #f) #("api.scm:158: string->symbol" #f #f) #("api.scm:160: current-milliseconds" #f #f) #("api.scm:161: dbr:dbstruct-read-only" #f #f) #("api.scm:139: k15" #f #f) #("api.scm:139: g19" #f #f) #("api.scm:142: get-call-chain" #f #f)) #("get-test-info-by-id" (1102 507299)))
+;; 6
+;;
+;; Call history:
+;;
+;; http-transport.scm:306: thread-terminate!
+;; http-transport.scm:307: debug:print-info
+;; common_records.scm:235: debug:debug-mode
+;; rmt.scm:259: k587
+;; rmt.scm:259: g591
+;; rmt.scm:276: http-transport:server-dat-update-last-access
+;; http-transport.scm:364: current-seconds
+;; rmt.scm:282: debug:print-info
+;; common_records.scm:235: debug:debug-mode
+;; rmt.scm:283: mutex-unlock!
+;; rmt.scm:287: extras-transport-succeded <--
+;; +-----------------------------------------------------------------------------+
+;; | Exit Status : 70
+;;
+
+ (dat (if (and (vector? dat-in) ;; ... check it is a correct size
+ (> (vector-length dat-in) 1))
+ dat-in
+ (vector #f (conc "communications fail (type 2), dat-in=" dat-in))))
+ (success (if (vector? dat) (vector-ref dat 0) #f))
+ (res (if (vector? dat) (vector-ref dat 1) #f)))
+ (if (and (vector? conninfo) (< 5 (vector-length conninfo)))
+ (http-transport:server-dat-update-last-access conninfo) ;; refresh access time
+ (begin
+ (debug:print 0 *default-log-port* "INFO: Should not get here! conninfo=" conninfo)
+ (set! conninfo #f)
+ (remote-conndat-set! *runremote* #f) ;; NOTE: *runremote* is global copy of runremote. Purpose: factor out global.
+ (http-transport:close-connections area-dat: runremote)))
+ (debug:print-info 13 *default-log-port* "rmt:send-receive, case 9. conninfo=" conninfo " dat=" dat " runremote = " runremote)
+ (mutex-unlock! *rmt-mutex*)
+ (if success ;; success only tells us that the transport was
+ ;; successful, have to examine the data to see if
+ ;; there was a detected issue at the other end
+ (extras-transport-succeded *default-log-port* *rmt-mutex* attemptnum runremote res params rid cmd)
+ (begin
+ (debug:print-error 0 *default-log-port* " dat=" dat)
+ (extras-transport-failed *default-log-port* *rmt-mutex* attemptnum runremote cmd rid params))
+ )))
+
+(define (rmt:print-db-stats)
+ (let ((fmtstr "~40a~7-d~9-d~20,2-f")) ;; "~20,2-f"
+ (debug:print 18 *default-log-port* "DB Stats\n========")
+ (debug:print 18 *default-log-port* (format #f "~40a~8a~10a~10a" "Cmd" "Count" "TotTime" "Avg"))
+ (for-each (lambda (cmd)
+ (let ((cmd-dat (hash-table-ref *db-stats* cmd)))
+ (debug:print 18 *default-log-port* (format #f fmtstr cmd (vector-ref cmd-dat 0) (vector-ref cmd-dat 1) (/ (vector-ref cmd-dat 1)(vector-ref cmd-dat 0))))))
+ (sort (hash-table-keys *db-stats*)
+ (lambda (a b)
+ (> (vector-ref (hash-table-ref *db-stats* a) 0)
+ (vector-ref (hash-table-ref *db-stats* b) 0)))))))
+
+(define (rmt:get-max-query-average run-id)
+ (mutex-lock! *db-stats-mutex*)
+ (let* ((runkey (conc "run-id=" run-id " "))
+ (cmds (filter (lambda (x)
+ (substring-index runkey x))
+ (hash-table-keys *db-stats*)))
+ (res (if (null? cmds)
+ (cons 'none 0)
+ (let loop ((cmd (car cmds))
+ (tal (cdr cmds))
+ (max-cmd (car cmds))
+ (res 0))
+ (let* ((cmd-dat (hash-table-ref *db-stats* cmd))
+ (tot (vector-ref cmd-dat 0))
+ (curravg (/ (vector-ref cmd-dat 1) (vector-ref cmd-dat 0))) ;; count is never zero by construction
+ (currmax (max res curravg))
+ (newmax-cmd (if (> curravg res) cmd max-cmd)))
+ (if (null? tal)
+ (if (> tot 10)
+ (cons newmax-cmd currmax)
+ (cons 'none 0))
+ (loop (car tal)(cdr tal) newmax-cmd currmax)))))))
+ (mutex-unlock! *db-stats-mutex*)
+ res))
+
+(define (rmt:open-qry-close-locally cmd run-id params #!key (remretries 5))
+ (let* ((qry-is-write (not (member cmd api:read-only-queries)))
+ (db-file-path (common:get-db-tmp-area)) ;; db:dbfile-path)) ;; 0))
+ (dbstruct-local (db:setup #t)) ;; make-dbr:dbstruct path: dbdir local: #t)))
+ (read-only (not (file-write-access? db-file-path)))
+ (start (current-milliseconds))
+ (resdat (if (not (and read-only qry-is-write))
+ (let ((v (api:execute-requests dbstruct-local (vector (symbol->string cmd) params))))
+ (handle-exceptions ;; there has been a long history of receiving strange errors from values returned by the client when things go wrong..
+ exn ;; This is an attempt to detect that situation and recover gracefully
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: bad data from server " v " message: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn)
+ (vector #t '())) ;; should always get a vector but if something goes wrong return a dummy
+ (if (and (vector? v)
+ (> (vector-length v) 1))
+ (let ((newvec (vector (vector-ref v 0)(vector-ref v 1))))
+ newvec) ;; by copying the vector while inside the error handler we should force the detection of a corrupted record
+ (vector #t '())))) ;; we could also check that the returned types are valid
+ (vector #t '())))
+ (success (vector-ref resdat 0))
+ (res (vector-ref resdat 1))
+ (duration (- (current-milliseconds) start)))
+ (if (and read-only qry-is-write)
+ (debug:print 0 *default-log-port* "ERROR: attempt to write to read-only database ignored. cmd=" cmd))
+ (if (not success)
+ (if (> remretries 0)
+ (begin
+ (debug:print-error 0 *default-log-port* "local query failed. Trying again.")
+ (thread-sleep! (/ (random 5000) 1000)) ;; some random delay
+ (rmt:open-qry-close-locally cmd run-id params remretries: (- remretries 1)))
+ (begin
+ (debug:print-error 0 *default-log-port* "too many retries in rmt:open-qry-close-locally, giving up")
+ #f))
+ (begin
+ ;; (rmt:update-db-stats run-id cmd params duration)
+ ;; mark this run as dirty if this was a write, the watchdog is responsible for syncing it
+ (if qry-is-write
+ (let ((start-time (current-seconds)))
+ (mutex-lock! *db-multi-sync-mutex*)
+ (set! *db-last-access* start-time) ;; THIS IS PROBABLY USELESS? (we are on a client)
+ (mutex-unlock! *db-multi-sync-mutex*)))))
+ res))
+
+(define (rmt:send-receive-no-auto-client-setup connection-info cmd run-id params)
+ (let* ((run-id (if run-id run-id 0))
+ (res (handle-exceptions
+ exn
+ (begin
+ (print "transport failed. exn=" exn)
+ #f)
+ (http-transport:client-api-send-receive run-id connection-info cmd params))))
+ (if (and res (vector-ref res 0))
+ (vector-ref res 1) ;;; YES!! THIS IS CORRECT!! CHANGE IT HERE, THEN CHANGE rmt:send-receive ALSO!!!
+ #f)))
+
+;;======================================================================
+;;
+;; A C T U A L A P I C A L L S
+;;
+;;======================================================================
+
+;;======================================================================
+;; S E R V E R
+;;======================================================================
+
+(define (rmt:kill-server run-id)
+ (rmt:send-receive 'kill-server run-id (list run-id)))
+
+(define (rmt:start-server run-id)
+ (rmt:send-receive 'start-server 0 (list run-id)))
+
+;;======================================================================
+;; M I S C
+;;======================================================================
+
+(define (rmt:login run-id)
+ (assert *my-client-signature* "ERROR: login attempted without first calling (client:get-signature).")
+ (rmt:send-receive 'login run-id (list *toppath* megatest-version *my-client-signature*)))
+
+;; This login does no retries under the hood - it acts a bit like a ping.
+;; Deprecated for nmsg-transport.
+;;
+(define (rmt:login-no-auto-client-setup connection-info)
+ (case *transport-type* ;; run-id of 0 is just a placeholder
+ ((http)(rmt:send-receive-no-auto-client-setup connection-info 'login 0 (list *toppath* megatest-version *my-client-signature*)))
+ ;;((nmsg)(nmsg-transport:client-api-send-receive run-id connection-info 'login (list *toppath* megatest-version run-id *my-client-signature*)))
+ ))
+
+;; hand off a call to one of the db:queries statements
+;; added run-id to make looking up the correct db possible
+;;
+(define (rmt:general-call stmtname run-id . params)
+ (rmt:send-receive 'general-call run-id (append (list stmtname run-id) params)))
+
+
+;; given a hostname, return a pair of cpu load and update time representing latest intelligence from tests running on that host
+(define (rmt:get-latest-host-load hostname)
+ (rmt:send-receive 'get-latest-host-load 0 (list hostname)))
+
+(define (rmt:sdb-qry qry val run-id)
+ ;; add caching if qry is 'getid or 'getstr
+ (rmt:send-receive 'sdb-qry run-id (list qry val)))
+
+;; NOT COMPLETED
+(define (rmt:runtests user run-id testpatt params)
+ (rmt:send-receive 'runtests run-id testpatt))
+
+(define (rmt:get-run-record-ids target run keynames test-patt)
+ (rmt:send-receive 'get-run-record-ids #f (list target run keynames test-patt)))
+
+(define (rmt:get-changed-record-ids since-time)
+ (rmt:send-receive 'get-changed-record-ids #f (list since-time)) )
+
+(define (rmt:drop-all-triggers)
+ (rmt:send-receive 'drop-all-triggers #f '()))
+
+(define (rmt:create-all-triggers)
+ (rmt:send-receive 'create-all-triggers #f '()))
+
+;;======================================================================
+;; T E S T M E T A
+;;======================================================================
+
+(define (rmt:get-tests-tags)
+ (rmt:send-receive 'get-tests-tags #f '()))
+
+;;======================================================================
+;; K E Y S
+;;======================================================================
+
+;; These require run-id because the values come from the run!
+;;
+(define (rmt:get-key-val-pairs run-id)
+ (rmt:send-receive 'get-key-val-pairs run-id (list run-id)))
+
+(define (rmt:get-keys)
+ (if *db-keys* *db-keys*
+ (let ((res (rmt:send-receive 'get-keys #f '())))
+ (set! *db-keys* res)
+ res)))
+
+(define (rmt:get-keys-write) ;; dummy query to force server start
+ (let ((res (rmt:send-receive 'get-keys-write #f '())))
+ (set! *db-keys* res)
+ res))
+
+;; we don't reuse run-id's (except possibly *after* a db cleanup) so it is safe
+;; to cache the resuls in a hash
+;;
+(define (rmt:get-key-vals run-id)
+ (or (hash-table-ref/default *keyvals* run-id #f)
+ (let ((res (rmt:send-receive 'get-key-vals #f (list run-id))))
+ (hash-table-set! *keyvals* run-id res)
+ res)))
+
+(define (rmt:get-targets)
+ (rmt:send-receive 'get-targets #f '()))
+
+(define (rmt:get-target run-id)
+ (rmt:send-receive 'get-target run-id (list run-id)))
+
+(define (rmt:get-run-times runpatt targetpatt)
+ (rmt:send-receive 'get-run-times #f (list runpatt targetpatt )))
+
+
+;;======================================================================
+;; T E S T S
+;;======================================================================
+
+;; Just some syntatic sugar
+(define (rmt:register-test run-id test-name item-path)
+ (rmt:general-call 'register-test run-id run-id test-name item-path))
+
+(define (rmt:get-test-id run-id testname item-path)
+ (rmt:send-receive 'get-test-id run-id (list run-id testname item-path)))
+
+;; run-id is NOT used
+;;
+(define (rmt:get-test-info-by-id run-id test-id)
+ (if (number? test-id)
+ (rmt:send-receive 'get-test-info-by-id run-id (list run-id test-id))
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Bad data handed to rmt:get-test-info-by-id run-id=" run-id ", test-id=" test-id)
+ (print-call-chain (current-error-port))
+ #f)))
+
+(define (rmt:test-get-rundir-from-test-id run-id test-id)
+ (rmt:send-receive 'test-get-rundir-from-test-id run-id (list run-id test-id)))
+
+(define (rmt:open-test-db-by-test-id run-id test-id #!key (work-area #f))
+ (let* ((test-path (if (string? work-area)
+ work-area
+ (rmt:test-get-rundir-from-test-id run-id test-id))))
+ (debug:print 3 *default-log-port* "TEST PATH: " test-path)
+ (open-test-db test-path)))
+
+;; WARNING: This currently bypasses the transaction wrapped writes system
+(define (rmt:test-set-state-status-by-id run-id test-id newstate newstatus newcomment)
+ (rmt:send-receive 'test-set-state-status-by-id run-id (list run-id test-id newstate newstatus newcomment)))
+
+(define (rmt:set-tests-state-status run-id testnames currstate currstatus newstate newstatus)
+ (rmt:send-receive 'set-tests-state-status run-id (list run-id testnames currstate currstatus newstate newstatus)))
+
+(define (rmt:get-tests-for-run run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals last-update mode)
+ ;; (if (number? run-id)
+ (rmt:send-receive 'get-tests-for-run run-id (list run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals last-update mode)))
+ ;; (begin
+ ;; (debug:print-error 0 *default-log-port* "rmt:get-tests-for-run called with bad run-id=" run-id)
+ ;; (print-call-chain (current-error-port))
+ ;; '())))
+
+(define (rmt:get-tests-for-run-state-status run-id testpatt last-update)
+ (rmt:send-receive 'get-tests-for-run-state-status run-id (list run-id testpatt last-update)))
+
+;; get stuff via synchash
+(define (rmt:synchash-get run-id proc synckey keynum params)
+ (rmt:send-receive 'synchash-get run-id (list run-id proc synckey keynum params)))
+
+(define (rmt:get-tests-for-run-mindata run-id testpatt states status not-in)
+ (rmt:send-receive 'get-tests-for-run-mindata run-id (list run-id testpatt states status not-in)))
+
+;; IDEA: Threadify these - they spend a lot of time waiting ...
+;;
+(define (rmt:get-tests-for-runs-mindata run-ids testpatt states status not-in)
+ (let ((multi-run-mutex (make-mutex))
+ (run-id-list (if run-ids
+ run-ids
+ (rmt:get-all-run-ids)))
+ (result '()))
+ (if (null? run-id-list)
+ '()
+ (let loop ((hed (car run-id-list))
+ (tal (cdr run-id-list))
+ (threads '()))
+ (if (> (length threads) 5)
+ (loop hed tal (filter (lambda (th)(not (member (thread-state th) '(terminated dead)))) threads))
+ (let* ((newthread (make-thread
+ (lambda ()
+ (let ((res (rmt:send-receive 'get-tests-for-run-mindata hed (list hed testpatt states status not-in))))
+ (if (list? res)
+ (begin
+ (mutex-lock! multi-run-mutex)
+ (set! result (append result res))
+ (mutex-unlock! multi-run-mutex))
+ (debug:print-error 0 *default-log-port* "get-tests-for-run-mindata failed for run-id " hed ", testpatt " testpatt ", states " states ", status " status ", not-in " not-in))))
+ (conc "multi-run-thread for run-id " hed)))
+ (newthreads (cons newthread threads)))
+ (thread-start! newthread)
+ (thread-sleep! 0.05) ;; give that thread some time to start
+ (if (null? tal)
+ newthreads
+ (loop (car tal)(cdr tal) newthreads))))))
+ result))
+
+;; ;; IDEA: Threadify these - they spend a lot of time waiting ...
+;; ;;
+;; (define (rmt:get-tests-for-runs-mindata run-ids testpatt states status not-in)
+;; (let ((run-id-list (if run-ids
+;; run-ids
+;; (rmt:get-all-run-ids))))
+;; (apply append (map (lambda (run-id)
+;; (rmt:send-receive 'get-tests-for-run-mindata run-id (list run-ids testpatt states status not-in)))
+;; run-id-list))))
+
+(define (rmt:delete-test-records run-id test-id)
+ (rmt:send-receive 'delete-test-records run-id (list run-id test-id)))
+
+(define (rmt:test-set-state-status run-id test-id state status msg)
+ (rmt:send-receive 'test-set-state-status run-id (list run-id test-id state status msg)))
+
+(define (rmt:test-toplevel-num-items run-id test-name)
+ (rmt:send-receive 'test-toplevel-num-items run-id (list run-id test-name)))
+
+;; (define (rmt:get-previous-test-run-record run-id test-name item-path)
+;; (rmt:send-receive 'get-previous-test-run-record run-id (list run-id test-name item-path)))
+
+(define (rmt:get-matching-previous-test-run-records run-id test-name item-path)
+ (rmt:send-receive 'get-matching-previous-test-run-records run-id (list run-id test-name item-path)))
+
+(define (rmt:test-get-logfile-info run-id test-name)
+ (rmt:send-receive 'test-get-logfile-info run-id (list run-id test-name)))
+
+(define (rmt:test-get-records-for-index-file run-id test-name)
+ (rmt:send-receive 'test-get-records-for-index-file run-id (list run-id test-name)))
+
+(define (rmt:get-testinfo-state-status run-id test-id)
+ (rmt:send-receive 'get-testinfo-state-status run-id (list run-id test-id)))
+
+(define (rmt:test-set-log! run-id test-id logf)
+ (if (string? logf)(rmt:general-call 'test-set-log run-id logf test-id)))
+
+(define (rmt:test-set-top-process-pid run-id test-id pid)
+ (rmt:send-receive 'test-set-top-process-pid run-id (list run-id test-id pid)))
+
+(define (rmt:test-get-top-process-pid run-id test-id)
+ (rmt:send-receive 'test-get-top-process-pid run-id (list run-id test-id)))
+
+(define (rmt:get-run-ids-matching-target keynames target res runname testpatt statepatt statuspatt)
+ (rmt:send-receive 'get-run-ids-matching-target #f (list keynames target res runname testpatt statepatt statuspatt)))
+
+;; NOTE: This will open and access ALL run databases.
+;;
+(define (rmt:test-get-paths-matching-keynames-target-new keynames target res testpatt statepatt statuspatt runname)
+ (let ((run-ids (rmt:get-run-ids-matching-target keynames target res runname testpatt statepatt statuspatt)))
+ (apply append
+ (map (lambda (run-id)
+ (rmt:send-receive 'test-get-paths-matching-keynames-target-new run-id (list run-id keynames target res testpatt statepatt statuspatt runname)))
+ run-ids))))
+
+(define (rmt:get-prereqs-not-met run-id waitons ref-test-name ref-item-path #!key (mode '(normal))(itemmaps #f))
+ (rmt:send-receive 'get-prereqs-not-met run-id (list run-id waitons ref-test-name ref-item-path mode itemmaps)))
+
+(define (rmt:get-count-tests-running-for-run-id run-id)
+ (if (number? run-id)
+ (rmt:send-receive 'get-count-tests-running-for-run-id run-id (list run-id))
+ 0))
+
+(define (rmt:get-not-completed-cnt run-id)
+ (rmt:send-receive 'get-not-completed-cnt run-id (list run-id)))
+
+
+;; Statistical queries
+
+(define (rmt:get-count-tests-running run-id)
+ (rmt:send-receive 'get-count-tests-running run-id (list run-id)))
+
+(define (rmt:get-count-tests-running-for-testname run-id testname)
+ (rmt:send-receive 'get-count-tests-running-for-testname run-id (list run-id testname)))
+
+(define (rmt:get-count-tests-running-in-jobgroup run-id jobgroup)
+ (rmt:send-receive 'get-count-tests-running-in-jobgroup run-id (list run-id jobgroup)))
+
+;; state and status are extra hints not usually used in the calculation
+;;
+(define (rmt:set-state-status-and-roll-up-items run-id test-name item-path state status comment)
+ (rmt:send-receive 'set-state-status-and-roll-up-items run-id (list run-id test-name item-path state status comment)))
+
+(define (rmt:set-state-status-and-roll-up-run run-id state status)
+ (rmt:send-receive 'set-state-status-and-roll-up-run run-id (list run-id state status)))
+
+
+(define (rmt:update-pass-fail-counts run-id test-name)
+ (rmt:general-call 'update-pass-fail-counts run-id test-name test-name test-name))
+
+(define (rmt:top-test-set-per-pf-counts run-id test-name)
+ (rmt:send-receive 'top-test-set-per-pf-counts run-id (list run-id test-name)))
+
+(define (rmt:get-raw-run-stats run-id)
+ (rmt:send-receive 'get-raw-run-stats run-id (list run-id)))
+
+(define (rmt:get-test-times runname target)
+ (rmt:send-receive 'get-test-times #f (list runname target )))
+
+;;======================================================================
+;; R U N S
+;;======================================================================
+
+(define (rmt:get-run-info run-id)
+ (rmt:send-receive 'get-run-info run-id (list run-id)))
+
+(define (rmt:get-num-runs runpatt)
+ (rmt:send-receive 'get-num-runs #f (list runpatt)))
+
+(define (rmt:get-runs-cnt-by-patt runpatt targetpatt keys)
+ (rmt:send-receive 'get-runs-cnt-by-patt #f (list runpatt targetpatt keys)))
+
+;; Use the special run-id == #f scenario here since there is no run yet
+(define (rmt:register-run keyvals runname state status user contour)
+ (rmt:send-receive 'register-run #f (list keyvals runname state status user contour)))
+
+(define (rmt:get-run-name-from-id run-id)
+ (rmt:send-receive 'get-run-name-from-id run-id (list run-id)))
+
+(define (rmt:delete-run run-id)
+ (rmt:send-receive 'delete-run run-id (list run-id)))
+
+(define (rmt:update-run-stats run-id stats)
+ (rmt:send-receive 'update-run-stats #f (list run-id stats)))
+
+(define (rmt:delete-old-deleted-test-records)
+ (rmt:send-receive 'delete-old-deleted-test-records #f '()))
+
+(define (rmt:get-runs runpatt count offset keypatts)
+ (rmt:send-receive 'get-runs #f (list runpatt count offset keypatts)))
+
+(define (rmt:simple-get-runs runpatt count offset target last-update)
+ (rmt:send-receive 'simple-get-runs #f (list runpatt count offset target last-update)))
+
+(define (rmt:get-all-run-ids)
+ (rmt:send-receive 'get-all-run-ids #f '()))
+
+(define (rmt:get-prev-run-ids run-id)
+ (rmt:send-receive 'get-prev-run-ids #f (list run-id)))
+
+(define (rmt:lock/unlock-run run-id lock unlock user)
+ (rmt:send-receive 'lock/unlock-run #f (list run-id lock unlock user)))
+
+;; set/get status
+(define (rmt:get-run-status run-id)
+ (rmt:send-receive 'get-run-status #f (list run-id)))
+
+(define (rmt:get-run-state run-id)
+ (rmt:send-receive 'get-run-state #f (list run-id)))
+
+
+(define (rmt:set-run-status run-id run-status #!key (msg #f))
+ (rmt:send-receive 'set-run-status #f (list run-id run-status msg)))
+
+(define (rmt:set-run-state-status run-id state status )
+ (rmt:send-receive 'set-run-state-status #f (list run-id state status)))
+
+(define (rmt:update-tesdata-on-repilcate-db old-lt new-lt)
+(rmt:send-receive 'update-tesdata-on-repilcate-db #f (list old-lt new-lt)))
+
+(define (rmt:update-run-event_time run-id)
+ (rmt:send-receive 'update-run-event_time #f (list run-id)))
+
+(define (rmt:get-runs-by-patt keys runnamepatt targpatt offset limit fields last-runs-update #!key (sort-order "asc")) ;; fields of #f uses default
+ (rmt:send-receive 'get-runs-by-patt #f (list keys runnamepatt targpatt offset limit fields last-runs-update sort-order)))
+
+(define (rmt:find-and-mark-incomplete run-id ovr-deadtime)
+ ;; (if (rmt:send-receive 'have-incompletes? run-id (list run-id ovr-deadtime))
+ (rmt:send-receive 'mark-incomplete run-id (list run-id ovr-deadtime))) ;; )
+
+(define (rmt:get-main-run-stats run-id)
+ (rmt:send-receive 'get-main-run-stats #f (list run-id)))
+
+(define (rmt:get-var varname)
+ (rmt:send-receive 'get-var #f (list varname)))
+
+(define (rmt:del-var varname)
+ (rmt:send-receive 'del-var #f (list varname)))
+
+(define (rmt:set-var varname value)
+ (rmt:send-receive 'set-var #f (list varname value)))
+
+(define (rmt:inc-var varname)
+ (rmt:send-receive 'inc-var #f (list varname)))
+
+(define (rmt:dec-var varname)
+ (rmt:send-receive 'dec-var #f (list varname)))
+
+(define (rmt:add-var varname value)
+ (rmt:send-receive 'add-var #f (list varname value)))
+
+;;======================================================================
+;; M U L T I R U N Q U E R I E S
+;;======================================================================
+
+;; Need to move this to multi-run section and make associated changes
+(define (rmt:find-and-mark-incomplete-all-runs #!key (ovr-deadtime #f))
+ (let ((run-ids (rmt:get-all-run-ids)))
+ (for-each (lambda (run-id)
+ (rmt:find-and-mark-incomplete run-id ovr-deadtime))
+ run-ids)))
+
+;; get the previous record for when this test was run where all keys match but runname
+;; returns #f if no such test found, returns a single test record if found
+;;
+;; Run this at the client end since we have to connect to multiple run-id dbs
+;;
+(define (rmt:get-previous-test-run-record run-id test-name item-path)
+ (let* ((keyvals (rmt:get-key-val-pairs run-id))
+ (keys (rmt:get-keys))
+ (selstr (string-intersperse keys ","))
+ (qrystr (string-intersperse (map (lambda (x)(conc x "=?")) keys) " AND ")))
+ (if (not keyvals)
+ #f
+ (let ((prev-run-ids (rmt:get-prev-run-ids run-id)))
+ ;; for each run starting with the most recent look to see if there is a matching test
+ ;; if found then return that matching test record
+ (debug:print 4 *default-log-port* "selstr: " selstr ", qrystr: " qrystr ", keyvals: " keyvals ", previous run ids found: " prev-run-ids)
+ (if (null? prev-run-ids) #f
+ (let loop ((hed (car prev-run-ids))
+ (tal (cdr prev-run-ids)))
+ (let ((results (rmt:get-tests-for-run hed (conc test-name "/" item-path) '() '() ;; run-id testpatt states statuses
+ #f #f #f ;; offset limit not-in hide/not-hide
+ #f #f #f #f 'normal))) ;; sort-by sort-order qryvals last-update mode
+ (debug:print 4 *default-log-port* "Got tests for run-id " run-id ", test-name " test-name ", item-path " item-path ": " results)
+ (if (and (null? results)
+ (not (null? tal)))
+ (loop (car tal)(cdr tal))
+ (if (null? results) #f
+ (car results))))))))))
+
+(define (rmt:get-run-stats)
+ (rmt:send-receive 'get-run-stats #f '()))
+
+;;======================================================================
+;; S T E P S
+;;======================================================================
+
+;; Getting steps is more complicated.
+;;
+;; If given work area
+;; 1. Find the testdat.db file
+;; 2. Open the testdat.db file and do the query
+;; If not given the work area
+;; 1. Do a remote call to get the test path
+;; 2. Continue as above
+;;
+;;(define (rmt:get-steps-for-test run-id test-id)
+;; (rmt:send-receive 'get-steps-data run-id (list test-id)))
+
+(define (rmt:teststep-set-status! run-id test-id teststep-name state-in status-in comment logfile)
+ (let* ((state (items:check-valid-items "state" state-in))
+ (status (items:check-valid-items "status" status-in)))
+ (if (or (not state)(not status))
+ (debug:print 3 *default-log-port* "WARNING: Invalid " (if status "status" "state")
+ " value \"" (if status state-in status-in) "\", update your validvalues section in megatest.config"))
+ (rmt:send-receive 'teststep-set-status! run-id (list run-id test-id teststep-name state-in status-in comment logfile))))
+
+
+(define (rmt:delete-steps-for-test! run-id test-id)
+ (rmt:send-receive 'delete-steps-for-test! run-id (list run-id test-id)))
+
+(define (rmt:get-steps-for-test run-id test-id)
+ (rmt:send-receive 'get-steps-for-test run-id (list run-id test-id)))
+
+(define (rmt:get-steps-info-by-id test-step-id)
+ (rmt:send-receive 'get-steps-info-by-id #f (list test-step-id)))
+
+;;======================================================================
+;; T E S T D A T A
+;;======================================================================
+
+(define (rmt:read-test-data run-id test-id categorypatt #!key (work-area #f))
+ (rmt:send-receive 'read-test-data run-id (list run-id test-id categorypatt)))
+
+(define (rmt:read-test-data-varpatt run-id test-id categorypatt varpatt #!key (work-area #f))
+ (rmt:send-receive 'read-test-data-varpatt run-id (list run-id test-id categorypatt varpatt)))
+
+(define (rmt:get-data-info-by-id test-data-id)
+ (rmt:send-receive 'get-data-info-by-id #f (list test-data-id)))
+
+(define (rmt:testmeta-add-record testname)
+ (rmt:send-receive 'testmeta-add-record #f (list testname)))
+
+(define (rmt:testmeta-get-record testname)
+ (rmt:send-receive 'testmeta-get-record #f (list testname)))
+
+(define (rmt:testmeta-update-field test-name fld val)
+ (rmt:send-receive 'testmeta-update-field #f (list test-name fld val)))
+
+(define (rmt:test-data-rollup run-id test-id status)
+ (rmt:send-receive 'test-data-rollup run-id (list run-id test-id status)))
+
+(define (rmt:csv->test-data run-id test-id csvdata)
+ (rmt:send-receive 'csv->test-data run-id (list run-id test-id csvdata)))
+
+;;======================================================================
+;; T A S K S
+;;======================================================================
+
+(define (rmt:tasks-find-task-queue-records target run-name test-patt state-patt action-patt)
+ (rmt:send-receive 'find-task-queue-records #f (list target run-name test-patt state-patt action-patt)))
+
+(define (rmt:tasks-add action owner target runname testpatt params)
+ (rmt:send-receive 'tasks-add #f (list action owner target runname testpatt params)))
+
+(define (rmt:tasks-set-state-given-param-key param-key new-state)
+ (rmt:send-receive 'tasks-set-state-given-param-key #f (list param-key new-state)))
+
+(define (rmt:tasks-get-last target runname)
+ (rmt:send-receive 'tasks-get-last #f (list target runname)))
+
+;;======================================================================
+;; N O S Y N C D B
+;;======================================================================
+
+(define (rmt:no-sync-set var val)
+ (rmt:send-receive 'no-sync-set #f `(,var ,val)))
+
+(define (rmt:no-sync-get/default var default)
+ (rmt:send-receive 'no-sync-get/default #f `(,var ,default)))
+
+(define (rmt:no-sync-del! var)
+ (rmt:send-receive 'no-sync-del! #f `(,var)))
+
+(define (rmt:no-sync-get-lock keyname)
+ (rmt:send-receive 'no-sync-get-lock #f `(,keyname)))
+
+;;======================================================================
+;; A R C H I V E S
+;;======================================================================
+
+(define (rmt:archive-get-allocations testname itempath dneeded)
+ (rmt:send-receive 'archive-get-allocations #f (list testname itempath dneeded)))
+
+(define (rmt:archive-register-block-name bdisk-id archive-path)
+ (rmt:send-receive 'archive-register-block-name #f (list bdisk-id archive-path)))
+
+(define (rmt:archive-allocate-testsuite/area-to-block block-id testsuite-name areakey)
+ (rmt:send-receive 'archive-allocate-test-to-block #f (list block-id testsuite-name areakey)))
+
+(define (rmt:archive-register-disk bdisk-name bdisk-path df)
+ (rmt:send-receive 'archive-register-disk #f (list bdisk-name bdisk-path df)))
+
+(define (rmt:test-set-archive-block-id run-id test-id archive-block-id)
+ (rmt:send-receive 'test-set-archive-block-id run-id (list run-id test-id archive-block-id)))
+
+(define (rmt:test-get-archive-block-info archive-block-id)
+ (rmt:send-receive 'test-get-archive-block-info #f (list archive-block-id)))
+
+(define (extras-readonly-mode rmt-mutex log-port cmd params)
+ (mutex-unlock! rmt-mutex)
+ (debug:print-info 12 log-port "rmt:send-receive, case 3")
+ (debug:print 0 log-port "WARNING: write transaction requested on a readonly area. cmd="cmd" params="params)
+ #f)
+
+(define (extras-transport-failed *default-log-port* *rmt-mutex* attemptnum runremote cmd rid params)
+ (debug:print 0 *default-log-port* "WARNING: communication failed. Trying again, try num: " attemptnum)
+ (mutex-lock! *rmt-mutex*)
+ (remote-conndat-set! runremote #f)
+ (http-transport:close-connections area-dat: runremote)
+ (remote-server-url-set! runremote #f)
+ (mutex-unlock! *rmt-mutex*)
+ (debug:print-info 12 *default-log-port* "rmt:send-receive, case 9.1")
+ (rmt:send-receive cmd rid params attemptnum: (+ attemptnum 1)))
+
+(define (extras-transport-succeded *default-log-port* *rmt-mutex* attemptnum runremote res params rid cmd)
+ (if (and (vector? res)
+ (eq? (vector-length res) 2)
+ (eq? (vector-ref res 1) 'overloaded)) ;; since we are
+ ;; looking at the
+ ;; data to carry the
+ ;; error we'll use a
+ ;; fairly obtuse
+ ;; combo to minimise
+ ;; the chances of
+ ;; some sort of
+ ;; collision. this
+ ;; is the case where
+ ;; the returned data
+ ;; is bad or the
+ ;; server is
+ ;; overloaded and we
+ ;; want to ease off
+ ;; the queries
+ (let ((wait-delay (+ attemptnum (* attemptnum 10))))
+ (debug:print 0 *default-log-port* "WARNING: server is overloaded. Delaying " wait-delay " seconds and trying call again.")
+ (mutex-lock! *rmt-mutex*)
+ (http-transport:close-connections area-dat: runremote)
+ (set! *runremote* #f) ;; force starting over
+ (mutex-unlock! *rmt-mutex*)
+ (thread-sleep! wait-delay)
+ (rmt:send-receive cmd rid params attemptnum: (+ attemptnum 1)))
+ res)) ;; All good, return res
+
+#;(set-functions rmt:send-receive remote-server-url-set!
+ http-transport:close-connections remote-conndat-set!
+ debug:print debug:print-info
+ remote-ro-mode remote-ro-mode-set!
+ remote-ro-mode-checked-set! remote-ro-mode-checked)
+
+;;======================================================================
+;; EVERYTHING FROM TRANSPORT
+;;======================================================================
+
+(define (http-transport:make-server-url hostport)
+ (if (not hostport)
+ #f
+ (conc "http://" (car hostport) ":" (cadr hostport))))
+
+;;======================================================================
+;; S E R V E R
+;; ======================================================================
+
+;; Call this to start the actual server
+;;
+
+;; (define *db:process-queue-mutex* (make-mutex))
+
+(define (http-transport:run hostn)
+ ;; Configurations for server
+ (tcp-buffer-size 2048)
+ (max-connections 2048)
+ (debug:print 2 *default-log-port* "Attempting to start the server ...")
+ (let* ((db #f) ;; (open-db)) ;; we don't want the server to be opening and closing the db unnecesarily
+ (hostname (get-host-name))
+ (ipaddrstr (let ((ipstr (if (string=? "-" hostn)
+ ;; (string-intersperse (map number->string (u8vector->list (hostname->ip hostname))) ".")
+ (server:get-best-guess-address hostname)
+ #f)))
+ (if ipstr ipstr hostn))) ;; hostname)))
+ (start-port (portlogger:open-run-close
+ (lambda (db)
+ (portlogger:find-port db))))
+ (link-tree-path (common:get-linktree))
+ (tmp-area (common:get-db-tmp-area))
+ (start-file (conc tmp-area "/.server-start")))
+ (debug:print-info 0 *default-log-port* "portlogger recommended port: " start-port)
+ ;; set some parameters for the server
+ (root-path (if link-tree-path
+ link-tree-path
+ (current-directory))) ;; WARNING: SECURITY HOLE. FIX ASAP!
+ (handle-directory spiffy-directory-listing)
+ (handle-exception (lambda (exn chain)
+ (signal (make-composite-condition
+ (make-property-condition
+ 'server
+ 'message "server error")))))
+
+ ;; http-transport:handle-directory) ;; simple-directory-handler)
+ ;; Setup the web server and a /ctrl interface
+ ;;
+ (vhost-map `(((* any) . ,(lambda (continue)
+ ;; open the db on the first call
+ ;; This is were we set up the database connections
+ (let* (($ (request-vars source: 'both))
+ (dat ($ 'dat))
+ (res #f))
+ (cond
+ ((equal? (uri-path (request-uri (current-request)))
+ '(/ "api"))
+ (send-response body: (api:process-request *dbstruct-db* $) ;; the $ is the request vars proc
+ headers: '((content-type text/plain)))
+ (mutex-lock! *heartbeat-mutex*)
+ (set! *db-last-access* (current-seconds))
+ (mutex-unlock! *heartbeat-mutex*))
+ ;; ((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ ""))
+ ;; (send-response body: (http-transport:main-page)))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ "json_api"))
+ ;; (send-response body: (http-transport:main-page)))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ "runs"))
+ ;; (send-response body: (http-transport:main-page)))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ any))
+ ;; (send-response body: "hey there!\n"
+ ;; headers: '((content-type text/plain))))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ "hey"))
+ ;; (send-response body: "hey there!\n"
+ ;; headers: '((content-type text/plain))))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ "jquery3.1.0.js"))
+ ;; (send-response body: (http-transport:show-jquery)
+ ;; headers: '((content-type application/javascript))))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ "test_log"))
+ ;; (send-response body: (http-transport:html-test-log $)
+ ;; headers: '((content-type text/HTML))))
+ ;;((equal? (uri-path (request-uri (current-request)))
+ ;; '(/ "dashboard"))
+ ;; (send-response body: (http-transport:html-dboard $)
+ ;; headers: '((content-type text/HTML))))
+ (else (continue))))))))
+ (handle-exceptions
+ exn
+ (debug:print 0 *default-log-port* "Failed to create file " start-file ", exn=" exn)
+ (with-output-to-file start-file (lambda ()(print (current-process-id)))))
+ (http-transport:try-start-server ipaddrstr start-port)))
+
+
+;; This is recursively run by http-transport:run until sucessful
+;;
+(define (http-transport:try-start-server ipaddrstr portnum)
+ (let ((config-hostname (configf:lookup *configdat* "server" "hostname"))
+ (config-use-proxy (equal? (configf:lookup *configdat* "client" "use-http_proxy") "yes")))
+ (if (not config-use-proxy)
+ (determine-proxy (constantly #f)))
+ (debug:print-info 0 *default-log-port* "http-transport:try-start-server time=" (seconds->time-string (current-seconds)) " ipaddrsstr=" ipaddrstr " portnum=" portnum " config-hostname=" config-hostname)
+ (handle-exceptions
+ exn
+ (begin
+ (print-error-message exn)
+ (if (< portnum 64000)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: attempt to start server failed. Trying again ...")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* "exn=" (condition->list exn))
+ (portlogger:open-run-close portlogger:set-failed portnum)
+ (debug:print 0 *default-log-port* "WARNING: failed to start on portnum: " portnum ", trying next port")
+ (thread-sleep! 0.1)
+
+ ;; get_next_port goes here
+ (http-transport:try-start-server ipaddrstr
+ (portlogger:open-run-close portlogger:find-port)))
+ (begin
+ (print "ERROR: Tried and tried but could not start the server"))))
+ ;; any error in following steps will result in a retry
+ (set! *server-info* (list ipaddrstr portnum))
+ (debug:print 0 *default-log-port* "INFO: Trying to start server on " ipaddrstr ":" portnum)
+ ;; This starts the spiffy server
+ ;; NEED WAY TO SET IP TO #f TO BIND ALL
+ ;; (start-server bind-address: ipaddrstr port: portnum)
+ (if config-hostname ;; this is a hint to bind directly
+ (start-server port: portnum bind-address: (if (equal? config-hostname "-")
+ ipaddrstr
+ config-hostname))
+ (start-server port: portnum))
+ (portlogger:open-run-close
+ (lambda (db)
+ (portlogger:set-port db portnum "released")))
+ (debug:print 1 *default-log-port* "INFO: server has been stopped"))))
+
+
+;;======================================================================
+;; EVERYTHING FROM SERVERMOD
+;;======================================================================
+
+(define (server:make-server-url hostport)
+ (if (not hostport)
+ #f
+ (conc "http://" (car hostport) ":" (cadr hostport))))
+
+;;======================================================================
+;; S E R V E R U T I L I T I E S
+;;======================================================================
+
+;; Get the transport
+#;(define (server:get-transport)
+ (if *transport-type*
+ *transport-type*
+ (let ((ttype (string->symbol
+ (or (args:get-arg "-transport")
+ (configf:lookup *configdat* "server" "transport")
+ "rpc"))))
+ (set! *transport-type* ttype)
+ ttype)))
+
+;; Generate a unique signature for this server
+(define (server:mk-signature)
+ (message-digest-string (md5-primitive)
+ (with-output-to-string
+ (lambda ()
+ (write (list (current-directory)
+ (current-process-id)
+ (argv)))))))
+
+;; When using zmq this would send the message back (two step process)
+;; with spiffy or rpc this simply returns the return data to be returned
+;;
+(define (server:reply return-addr query-sig success/fail result)
+ (debug:print-info 11 *default-log-port* "server:reply return-addr=" return-addr ", result=" result)
+ ;; (send-message pubsock target send-more: #t)
+ ;; (send-message pubsock
+ (db:obj->string (vector success/fail query-sig result)))
+;; (case (server:get-transport)
+;; ((rpc) (db:obj->string (vector success/fail query-sig result)))
+;; ((http) (db:obj->string (vector success/fail query-sig result)))
+;; ((fs) result)
+;; (else
+;; (debug:print-error 0 *default-log-port* "unrecognised transport type: " *transport-type*)
+;; result)))
+
+(define (server:kind-run areapath)
+ ;; look for $MT_RUN_AREA_HOME/logs/server-start-last
+ ;; and wait for it to be at least 3 seconds old
+ (server:wait-for-server-start-last-flag areapath)
+ (if (not (server:check-if-running areapath)) ;; why try if there is already a server running?
+ (let* ((last-run-dat (hash-table-ref/default *server-kind-run* areapath '(0 0))) ;; callnum, whenrun
+ (call-num (car last-run-dat))
+ (when-run (cadr last-run-dat))
+ (run-delay (+ (case call-num
+ ((0) 0)
+ ((1) 20)
+ ((2) 300)
+ (else 600))
+ (random 5))) ;; add a small random number just in case a lot of jobs hit the work hosts simultaneously
+ (lock-file (conc areapath "/logs/server-start.lock")))
+ (if (> (- (current-seconds) when-run) run-delay)
+ (let* ((start-flag (conc areapath "/logs/server-start-last")))
+ (common:simple-file-lock-and-wait lock-file expire-time: 15)
+ (debug:print-info 0 *default-log-port* "server:kind-run: touching " start-flag)
+ (system (conc "touch " start-flag)) ;; lazy but safe
+ (server:run areapath)
+ (thread-sleep! 2) ;; don't release the lock for at least a few seconds
+ (common:simple-file-release-lock lock-file)))
+ (hash-table-set! *server-kind-run* areapath (list (+ call-num 1)(current-seconds))))))
+
+
+(define (server:get-num-alive srvlst)
+ (let ((num-alive 0))
+ (for-each
+ (lambda (server)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 0 *default-log-port* "Unable to get server start-time and/or mod-time from " server ", exn=" exn))
+ (match-let (((mod-time host port start-time server-id pid)
+ server))
+ (let* ((uptime (- (current-seconds) mod-time))
+ (runtime (if start-time
+ (- mod-time start-time)
+ 0)))
+ (if (< uptime 5)(set! num-alive (+ num-alive 1)))))))
+ srvlst)
+ num-alive))
+
+;; given a list of servers get a list of valid servers, i.e. at least
+;; 10 seconds old, has started and is less than 1 hour old and is
+;; active (i.e. mod-time < 10 seconds
+;;
+;; mod-time host port start-time pid
+;;
+;; sort by start-time descending. I.e. get the oldest first. Young servers will thus drop off
+;; and servers should stick around for about two hours or so.
+;;
+(define (server:get-best srvlst)
+ (let* ((nums (server:get-num-servers))
+ (now (current-seconds))
+ (slst (sort
+ (filter (lambda (rec)
+ (if (and (list? rec)
+ (> (length rec) 2))
+ (let ((start-time (list-ref rec 3))
+ (mod-time (list-ref rec 0)))
+ ;; (print "start-time: " start-time " mod-time: " mod-time)
+ (and start-time mod-time
+ (> (- now start-time) 0) ;; been running at least 0 seconds
+ (< (- now mod-time) 16) ;; still alive - file touched in last 16 seconds
+ (or (not (configf:lookup *configdat* "server" "runtime")) ;; skip if not set
+ (< (- now start-time)
+ (+ (- (string->number (configf:lookup *configdat* "server" "runtime"))
+ 180)
+ (random 360)))) ;; under one hour running time +/- 180
+ ))
+ #f))
+ srvlst)
+ (lambda (a b)
+ (< (list-ref a 3)
+ (list-ref b 3))))))
+ (if (> (length slst) nums)
+ (take slst nums)
+ slst)))
+
+(define (server:get-first-best areapath)
+ (let ((srvrs (server:get-best (server:get-list areapath))))
+ (if (and srvrs
+ (not (null? srvrs)))
+ (car srvrs)
+ #f)))
+
+(define (server:get-rand-best areapath)
+ (let ((srvrs (server:get-best (server:get-list areapath))))
+ (if (and (list? srvrs)
+ (not (null? srvrs)))
+ (let* ((len (length srvrs))
+ (idx (random len)))
+ (list-ref srvrs idx))
+ #f)))
+
+(define (server:record->id servr)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 0 *default-log-port* "Unable to get server id from " servr ", exn=" exn)
+ #f)
+ (match-let (((mod-time host port start-time server-id pid)
+ servr))
+ (if server-id
+ server-id
+ #f))))
+
+(define (server:record->url servr)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 0 *default-log-port* "Unable to get server url from " servr ", exn=" exn)
+ #f)
+ (match-let (((mod-time host port start-time server-id pid)
+ servr))
+ (if (and host port)
+ (conc host ":" port)
+ #f))))
+
+(define (server:get-client-signature) ;; BB> why is this proc named "get-"? it returns nothing -- set! has not return value.
+ (if *my-client-signature* *my-client-signature*
+ (let ((sig (server:mk-signature)))
+ (set! *my-client-signature* sig)
+ *my-client-signature*)))
+
+;; wait for server=start-last to be three seconds old
+;;
+(define (server:wait-for-server-start-last-flag areapath)
+ (let* ((start-flag (conc areapath "/logs/server-start-last"))
+ ;;; THIS INTERACTS WITH [server] timeout. Suggest using 0.1 or above for timeout (6 seconds)
+ (reftime (configf:lookup-number *configdat* "server" "idletime" default: 4))
+ (server-key (conc (get-host-name) "-" (current-process-id))))
+ (if (file-exists? start-flag)
+ (let* ((fmodtime (file-modification-time start-flag))
+ (delta (- (current-seconds) fmodtime))
+ (all-go (> delta reftime)))
+ (if (and all-go
+ (begin
+ (with-output-to-file start-flag
+ (lambda ()
+ (print server-key)))
+ (thread-sleep! 0.25)
+ (let ((res (with-input-from-file start-flag
+ (lambda ()
+ (read-line)))))
+ (equal? server-key res))))
+ #t ;; (system (conc "touch " start-flag)) ;; lazy but safe
+ (begin
+ (debug:print-info 0 *default-log-port* "Gating server start, last start: "
+ fmodtime ", delta: " delta ", reftime: " reftime ", all-go=" all-go)
+ (thread-sleep! reftime)
+ (server:wait-for-server-start-last-flag areapath)))))))
+
+(define (server:get-num-servers #!key (numservers 2))
+ (let ((ns (string->number
+ (or (configf:lookup *configdat* "server" "numservers") "notanumber"))))
+ (or ns numservers)))
+
+(define (server:kill servr)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 0 *default-log-port* "Unable to get host and/or port from " servr ", exn=" exn)
+ #f)
+ (match-let (((mod-time hostname port start-time server-id pid)
+ servr))
+ (tasks:kill-server hostname pid))))
+
+;; called in megatest.scm, host-port is string hostname:port
+;;
+;; NOTE: This is NOT called directly from clients as not all transports support a client running
+;; in the same process as the server.
+;;
+;; run ping in separate process, safest way in some cases
+;;
+(define (server:ping-server ifaceport)
+ (with-input-from-pipe
+ (conc (common:get-megatest-exe) " -ping " ifaceport)
+ (lambda ()
+ (let loop ((inl (read-line))
+ (res "NOREPLY"))
+ (if (eof-object? inl)
+ (case (string->symbol res)
+ ((NOREPLY) #f)
+ ((LOGIN_OK) #t)
+ (else #f))
+ (loop (read-line) inl))))))
+
+;; NOT USED (well, ok, reference in rpc-transport but otherwise not used).
+;;
+(define (server:login toppath)
+ (lambda (toppath)
+ (set! *db-last-access* (current-seconds)) ;; might not be needed.
+ (if (equal? *toppath* toppath)
+ #t
+ #f)))
+
+;; timeout is hms string: 1h 5m 3s, default is 1 minute
+;;
+(define (server:expiration-timeout)
+ (let ((tmo (configf:lookup *configdat* "server" "timeout")))
+ (if (and (string? tmo)
+ (common:hms-string->seconds tmo)) ;; BUG: hms-string->seconds is broken, if given "10" returns 0. Also, it doesn't belong in this logic unless the string->number is changed below
+ (* 3600 (string->number tmo))
+ 60)))
+
+;; (define server:sync-lock-token "SERVER_SYNC_LOCK")
+;; (define (server:release-sync-lock)
+;; (db:no-sync-del! *no-sync-db* server:sync-lock-token))
+;; (define (server:have-sync-lock?)
+;; (let* ((have-lock-pair (db:no-sync-get-lock *no-sync-db* server:sync-lock-token))
+;; (have-lock? (car have-lock-pair))
+;; (lock-time (cdr have-lock-pair))
+;; (lock-age (- (current-seconds) lock-time)))
+;; (cond
+;; (have-lock? #t)
+;; ((>lock-age
+;; (* 3 (configf:lookup-number *configdat* "server" "minimum-intersync-delay" default: 180)))
+;; (server:release-sync-lock)
+;; (server:have-sync-lock?))
+;; (else #f))))
+
+
+;; (define (debug:print . params) #f)
+;; (define (debug:print-info . params) #f)
+;;
+;; (define (set-functions dbgp dbgpinfo)
+;; (set! debug:print dbgp)
+;; (set! debug:print-info dbgpinfo))
+
+;; (define *server-loop-heart-beat* (current-seconds))
+
+;;======================================================================
+;; P K T S S T U F F
+;;======================================================================
+
+;; ???
+
+;;======================================================================
+;; P K T S S T U F F
+;;======================================================================
+
+;; ???
+
+;;======================================================================
+;; S E R V E R
+;;======================================================================
+
+;; Call this to start the actual server
+;;
+
+;; all routes though here end in exit ...
+;;
+;; start_server
+;;
+(define (server:launch run-id transport-type)
+ (case transport-type
+ ((http)(http-transport:launch))
+ ;;((nmsg)(nmsg-transport:launch run-id))
+ ;;((rpc) (rpc-transport:launch run-id))
+ (else (debug:print-error 0 *default-log-port* "unknown server type " transport-type))))
+
+;; Given a run id start a server process ### NOTE ### > file 2>&1
+;; if the run-id is zero and the target-host is set
+;; try running on that host
+;; incidental: rotate logs in logs/ dir.
+;;
+(define (server:run areapath) ;; areapath is *toppath* for a given testsuite area
+ (let* ((curr-host (get-host-name))
+ ;; (attempt-in-progress (server:start-attempted? areapath))
+ ;; (dot-server-url (server:check-if-running areapath))
+ (curr-ip (server:get-best-guess-address curr-host))
+ (curr-pid (current-process-id))
+ (homehost (common:get-homehost)) ;; configf:lookup *configdat* "server" "homehost" ))
+ (target-host (car homehost))
+ (testsuite (common:get-testsuite-name))
+ (logfile (conc areapath "/logs/server.log")) ;; -" curr-pid "-" target-host ".log"))
+ (profile-mode (or (configf:lookup *configdat* "misc" "profilesw")
+ ""))
+ (cmdln (conc (common:get-megatest-exe)
+ " -server " (or target-host "-") (if (equal? (configf:lookup *configdat* "server" "daemonize") "yes")
+ " -daemonize "
+ "")
+ ;; " -log " logfile
+ " -m testsuite:" testsuite
+ " " profile-mode
+ )) ;; (conc " >> " logfile " 2>&1 &")))))
+ (log-rotate (make-thread common:rotate-logs "server run, rotate logs thread")) ;; why are we rotating logs here? This is a sensitive location with a lot going on!?
+ (load-limit (configf:lookup-number *configdat* "jobtools" "max-server-start-load" default: 3.0)))
+ ;; we want the remote server to start in *toppath* so push there
+ (push-directory areapath)
+ (debug:print 0 *default-log-port* "INFO: Trying to start server (" cmdln ") ...")
+ (thread-start! log-rotate)
+
+ ;; host.domain.tld match host?
+ (if (and target-host
+ ;; look at target host, is it host.domain.tld or ip address and does it
+ ;; match current ip or hostname
+ (not (string-match (conc "("curr-host "|" curr-host"\\..*)") target-host))
+ (not (equal? curr-ip target-host)))
+ (begin
+ (debug:print-info 0 *default-log-port* "Starting server on " target-host ", logfile is " logfile)
+ (setenv "TARGETHOST" target-host)))
+
+ (setenv "TARGETHOST_LOGF" logfile)
+ (thread-sleep! (/ (random 5000) 1000)) ;; add about a random (up to 5 seconds) initial delay. It seems pretty common that many running tests request a server at the same time
+ ;; (common:wait-for-normalized-load load-limit " delaying server start due to load" target-host) ;; do not try starting servers on an already overloaded machine, just wait forever
+ #;(common:wait-for-homehost-load load-limit (conc " delaying server start due to load on homehost. limit is " load-limit))
+ (system (conc "nbfake " cmdln))
+ (unsetenv "TARGETHOST_LOGF")
+ (if (get-environment-variable "TARGETHOST")(unsetenv "TARGETHOST"))
+ (thread-join! log-rotate)
+ (pop-directory)))
+
+
+
+
+
+
+
+
+
+
+
+(define (server:ping host-port-in server-id #!key (do-exit #f))
+ (let ((host:port (if (not host-port-in) ;; use read-dotserver to find
+ #f ;; (server:check-if-running *toppath*)
+ ;; (if (number? host-port-in) ;; we were handed a server-id
+ ;; (let ((srec (tasks:get-server-by-id (db:delay-if-busy (tasks:open-db)) host-port-in)))
+ ;; ;; (print "srec: " srec " host-port-in: " host-port-in)
+ ;; (if srec
+ ;; (conc (vector-ref srec 3) ":" (vector-ref srec 4))
+ ;; (conc "no such server-id " host-port-in)))
+ host-port-in))) ;; )
+ (let* ((host-port (if host:port
+ (let ((slst (string-split host:port ":")))
+ (if (eq? (length slst) 2)
+ (list (car slst)(string->number (cadr slst)))
+ #f))
+ #f)))
+;; (toppath (launch:setup)))
+ ;; (print "host-port=" host-port)
+ (if (not host-port)
+ (begin
+ (if host-port-in
+ (debug:print 0 *default-log-port* "ERROR: bad host:port"))
+ (if do-exit (exit 1))
+ #f)
+ (let* ((iface (car host-port))
+ (port (cadr host-port))
+ (server-dat (http-transport:client-connect iface port server-id))
+ (login-res (rmt:login-no-auto-client-setup server-dat)))
+ (if (and (list? login-res)
+ (car login-res))
+ (begin
+ ;; (print "LOGIN_OK")
+ (if do-exit (exit 0))
+ #t)
+ (begin
+ ;; (print "LOGIN_FAILED")
+ (if do-exit (exit 1))
+ #f)))))))
+
+
+;; kind start up of servers, wait 40 seconds before allowing another server for a given
+;; run-id to be launched
+;;
+;; this one seems to be the general entry point
+;;
+(define (server:start-and-wait areapath #!key (timeout 60))
+ (let ((give-up-time (+ (current-seconds) timeout)))
+ (let loop ((server-info (server:check-if-running areapath))
+ (try-num 0))
+ (if (or server-info
+ (> (current-seconds) give-up-time)) ;; server-url will be #f if no server available.
+ (server:record->url server-info)
+ (let ((num-ok (length (server:get-best (server:get-list areapath)))))
+ (if (and (> try-num 0) ;; first time through simply wait a little while then try again
+ (< num-ok 1)) ;; if there are no decent candidates for servers then try starting a new one
+ (server:kind-run areapath))
+ (thread-sleep! 5)
+ (loop (server:check-if-running areapath)
+ (+ try-num 1)))))))
+
+
+;; no longer care if multiple servers are started by accident. older servers will drop off in time.
+;;
+(define (server:check-if-running areapath) ;; #!key (numservers "2"))
+ (let* ((ns (server:get-num-servers))
+ (servers (server:get-best (server:get-list areapath))))
+ (if (or (and servers
+ (null? servers))
+ (not servers)
+ (and (list? servers)
+ (< (length servers) (random ns)))) ;; somewhere between 0 and numservers
+ #f
+ (let loop ((hed (car servers))
+ (tal (cdr servers)))
+ (let ((res (server:check-server hed)))
+ (if res
+ hed
+ (if (null? tal)
+ #f
+ (loop (car tal)(cdr tal)))))))))
+
+;; ping the given server
+;;
+(define (server:check-server server-record)
+ (let* ((server-url (server:record->url server-record))
+ (server-id (server:record->id server-record))
+ (res (case *transport-type*
+ ((http)(server:ping server-url server-id))
+ ;; ((nmsg)(nmsg-transport:ping (tasks:hostinfo-get-interface server)
+ )))
+ (if res
+ server-url
+ #f)))
+
+
+(define server:try-running server:run) ;; there is no more per-run servers ;; REMOVE ME. BUG.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+;;======================================================================
+;; REMANANTS OF HTTP_TRANSPORT
+;;======================================================================
+
+(define *http-mutex* (make-mutex))
+
+;; NOTE: Large block of code from 32436b426188080f72fceb6894af541fbad9921e removed here
+;; I'm pretty sure it is defunct.
+
+;; This next block all imported en-mass from the api branch
+(define *http-requests-in-progress* 0)
+(define *http-connections-next-cleanup* (current-seconds))
+
+(define (http-transport:get-time-to-cleanup)
+ (let ((res #f))
+ (mutex-lock! *http-mutex*)
+ (set! res (> (current-seconds) *http-connections-next-cleanup*))
+ (mutex-unlock! *http-mutex*)
+ res))
+
+(define (http-transport:inc-requests-count)
+ (mutex-lock! *http-mutex*)
+ (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*))
+ ;; Use this opportunity to slow things down iff there are too many requests in flight
+ (if (> *http-requests-in-progress* 5)
+ (begin
+ (debug:print-info 0 *default-log-port* "Whoa there buddy, ease up...")
+ (thread-sleep! 1)))
+ (mutex-unlock! *http-mutex*))
+
+(define (http-transport:dec-requests-count proc)
+ (mutex-lock! *http-mutex*)
+ (proc)
+ (set! *http-requests-in-progress* (- *http-requests-in-progress* 1))
+ (mutex-unlock! *http-mutex*))
+
+(define (http-transport:dec-requests-count-and-close-all-connections)
+ (set! *http-requests-in-progress* (- *http-requests-in-progress* 1))
+ (let loop ((etime (+ (current-seconds) 5))) ;; give up in five seconds
+ (if (> *http-requests-in-progress* 0)
+ (if (> etime (current-seconds))
+ (begin
+ (thread-sleep! 0.05)
+ (loop etime))
+ (debug:print-error 0 *default-log-port* "requests still in progress after 5 seconds of waiting. I'm going to pass on cleaning up http connections"))
+ (close-all-connections!)))
+ (set! *http-connections-next-cleanup* (+ (current-seconds) 10))
+ (mutex-unlock! *http-mutex*))
+
+(define (http-transport:inc-requests-and-prep-to-close-all-connections)
+ (mutex-lock! *http-mutex*)
+ (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*)))
+
+;; Send "cmd" with json payload "params" to serverdat and receive result
+;;
+(define (http-transport:client-api-send-receive run-id serverdat cmd params #!key (numretries 3)(area-dat #f))
+ (let* ((fullurl (if (vector? serverdat)
+ (http-transport:server-dat-get-api-req serverdat)
+ (begin
+ (debug:print 0 *default-log-port* "FATAL ERROR: http-transport:client-api-send-receive called with no server info")
+ (exit 1))))
+ (res (vector #f "uninitialized"))
+ (success #t)
+ (sparams (db:obj->string params transport: 'http))
+ (runremote (or area-dat *runremote*))
+ (server-id (if (vector? serverdat)
+ (http-transport:server-dat-get-server-id serverdat)
+ (begin
+ (debug:print 0 *default-log-port* "FATAL ERROR: http-transport:client-api-send-receive called with no server info")
+ (exit 1)))))
+ (debug:print-info 11 *default-log-port* "cmd=" cmd " fullurl=" fullurl " server-id=" server-id " current time:" (current-seconds))
+
+ ;; set up the http-client here
+ (max-retry-attempts 1)
+ ;; consider all requests indempotent
+ (retry-request? (lambda (request)
+ #f))
+ ;; send the data and get the response
+ ;; extract the needed info from the http data and
+ ;; process and return it.
+ (let* ((send-recieve (lambda ()
+ (mutex-lock! *http-mutex*)
+ ;; (condition-case (with-input-from-request "http://localhost"; #f read-lines)
+ ;; ((exn http client-error) e (print e)))
+ (set! res (vector ;;; DON'T FORGET - THIS IS THE CLIENT SIDE! NOTE: consider moving this to client.scm since we are only supporting http transport at this time.
+ success
+ (db:string->obj
+ (handle-exceptions
+ exn
+ (let ((call-chain (get-call-chain))
+ (msg ((condition-property-accessor 'exn 'message) exn)))
+ (set! success #f)
+ (if (debug:debug-mode 1)
+ (debug:print-info 0 *default-log-port* "couldn't talk to server, trying again ...")
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: failure in with-input-from-request to " fullurl ".")
+ (debug:print 0 *default-log-port* " message: " msg ", exn=" exn)
+ (debug:print 0 *default-log-port* " cmd: " cmd " params: " params " key:" (or server-id "thekey"))
+ (debug:print 0 *default-log-port* " call-chain: " call-chain)))
+ (if runremote
+ (remote-conndat-set! runremote #f))
+ ;; Killing associated server to allow clean retry.")
+ ;; (tasks:kill-server-run-id run-id) ;; better to kill the server in the logic that called this routine?
+ (mutex-unlock! *http-mutex*)
+ ;;; (signal (make-composite-condition
+ ;;; (make-property-condition 'commfail 'message "failed to connect to server")))
+ ;;; "communications failed"
+ (db:obj->string #f))
+ (with-input-from-request ;; was dat
+ fullurl
+ (list (cons 'key (or server-id "thekey"))
+ (cons 'cmd cmd)
+ (cons 'params sparams))
+ read-string))
+ transport: 'http)
+ 0)) ;; added this speculatively
+ ;; Shouldn't this be a call to the managed call-all-connections stuff above?
+ (close-all-connections!)
+ (mutex-unlock! *http-mutex*)
+ ))
+ (time-out (lambda ()
+ (thread-sleep! 45)
+ (debug:print 0 *default-log-port* "WARNING: send-receive took more than 45 seconds!!")
+ #f))
+ (th1 (make-thread send-recieve "with-input-from-request"))
+ (th2 (make-thread time-out "time out")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1)
+ (vector-set! res 0 success)
+ (thread-terminate! th2)
+ (if (vector? res)
+ (if (vector-ref res 0) ;; this is the first flag or the second flag?
+ (let* ((res-dat (vector-ref res 1)))
+ (if (and (string? res-dat) (string-contains res-dat "server-id mismatch"))
+ (signal (make-composite-condition
+ (make-property-condition
+ 'servermismatch
+ 'message (vector-ref res 1))))
+ res)) ;; this is the *inner* vector? seriously? why?
+ (if (debug:debug-mode 11)
+ (let ((call-chain (get-call-chain))) ;; note: this code also called in nmsg-transport - consider consolidating it
+ (print-call-chain (current-error-port))
+ (debug:print-error 11 *default-log-port* "error above occured at server, res=" res) ;; " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 11 *default-log-port* " server call chain:")
+ (pp (vector-ref res 1) (current-error-port))
+ (signal (vector-ref res 0)))
+ res))
+ (signal (make-composite-condition
+ (make-property-condition
+ 'timeout
+ 'message "nmsg-transport:client-api-send-receive-raw timed out talking to server")))))))
+
+;; careful closing of connections stored in *runremote*
+;;
+(define (http-transport:close-connections #!key (area-dat #f))
+ (let* ((runremote (or area-dat *runremote*))
+ (server-dat (if runremote
+ (remote-conndat runremote)
+ #f))) ;; (hash-table-ref/default *runremote* run-id #f)))
+ (if (vector? server-dat)
+ (let ((api-dat (http-transport:server-dat-get-api-uri server-dat)))
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain *default-log-port*)
+ (debug:print-error 0 *default-log-port* " closing connection failed with error: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn))
+ (close-connection! api-dat)
+ ;;(close-idle-connections!)
+ #t))
+ #f)))
+
+
+(define (make-http-transport:server-dat)(make-vector 6))
+(define (http-transport:server-dat-get-iface vec) (vector-ref vec 0))
+(define (http-transport:server-dat-get-port vec) (vector-ref vec 1))
+(define (http-transport:server-dat-get-api-uri vec) (vector-ref vec 2))
+(define (http-transport:server-dat-get-api-url vec) (vector-ref vec 3))
+(define (http-transport:server-dat-get-api-req vec) (vector-ref vec 4))
+(define (http-transport:server-dat-get-last-access vec) (vector-ref vec 5))
+;(define (http-transport:server-dat-get-socket vec) (vector-ref vec 6))
+(define (http-transport:server-dat-get-server-id vec) (vector-ref vec 6))
+
+(define (http-transport:server-dat-make-url vec)
+ (if (and (http-transport:server-dat-get-iface vec)
+ (http-transport:server-dat-get-port vec))
+ (conc "http://"
+ (http-transport:server-dat-get-iface vec)
+ ":"
+ (http-transport:server-dat-get-port vec))
+ #f))
+
+(define (http-transport:server-dat-update-last-access vec)
+ (if (vector? vec)
+ (vector-set! vec 5 (current-seconds))
+ (begin
+ (print-call-chain (current-error-port))
+ (debug:print-error 0 *default-log-port* "call to http-transport:server-dat-update-last-access with non-vector!!"))))
+
+;;
+;; connect
+;;
+(define (http-transport:client-connect iface port server-id)
+ (let* ((api-url (conc "http://" iface ":" port "/api"))
+ (api-uri (uri-reference (conc "http://" iface ":" port "/api")))
+ (api-req (make-request method: 'POST uri: api-uri))
+ (server-dat (vector iface port api-uri api-url api-req (current-seconds) server-id)))
+ server-dat))
+
+;; run http-transport:keep-running in a parallel thread to monitor that the db is being
+;; used and to shutdown after sometime if it is not.
+;;
+(define (http-transport:keep-running)
+ ;; if none running or if > 20 seconds since
+ ;; server last used then start shutdown
+ ;; This thread waits for the server to come alive
+ (debug:print-info 0 *default-log-port* "Starting the sync-back, keep alive thread in server")
+ (let* ((sdat #f)
+ (tmp-area (common:get-db-tmp-area))
+ (started-file (conc tmp-area "/.server-started"))
+ (server-start-time (current-seconds))
+ (server-info (let loop ((start-time (current-seconds))
+ (changed #t)
+ (last-sdat "not this"))
+ (begin ;; let ((sdat #f))
+ (thread-sleep! 0.01)
+ (debug:print-info 0 *default-log-port* "Waiting for server alive signature")
+ (mutex-lock! *heartbeat-mutex*)
+ (set! sdat *server-info*)
+ (mutex-unlock! *heartbeat-mutex*)
+ (if (and sdat
+ (not changed)
+ (> (- (current-seconds) start-time) 2))
+ (begin
+ (debug:print-info 0 *default-log-port* "Received server alive signature")
+ (common:save-pkt `((action . alive)
+ (T . server)
+ (pid . ,(current-process-id))
+ (ipaddr . ,(car sdat))
+ (port . ,(cadr sdat)))
+ *configdat* #t)
+ sdat)
+ (begin
+ (debug:print-info 0 *default-log-port* "Still waiting, last-sdat=" last-sdat)
+ (sleep 4)
+ (if (> (- (current-seconds) start-time) 120) ;; been waiting for two minutes
+ (begin
+ (debug:print-error 0 *default-log-port* "transport appears to have died, exiting server")
+ (common:save-pkt `((action . died)
+ (T . server)
+ (pid . ,(current-process-id))
+ (ipaddr . ,(car sdat))
+ (port . ,(cadr sdat))
+ (msg . "Transport died?"))
+ *configdat* #t)
+ (exit))
+ (loop start-time
+ (equal? sdat last-sdat)
+ sdat)))))))
+ (iface (car server-info))
+ (port (cadr server-info))
+ (last-access 0)
+ (server-timeout (server:expiration-timeout))
+ (server-going #f)
+ (server-log-file (args:get-arg "-log"))) ;; always set when we are a server
+
+ (handle-exceptions
+ exn
+ (debug:print 0 *default-log-port* "Failed to create " started-file ", exn=" exn)
+ (with-output-to-file started-file (lambda ()(print (current-process-id)))))
+
+ (let loop ((count 0)
+ (server-state 'available)
+ (bad-sync-count 0)
+ (start-time (current-milliseconds)))
+ ;; Use this opportunity to sync the tmp db to megatest.db
+ (if (not server-going) ;; *dbstruct-db*
+ (begin
+ (debug:print 0 *default-log-port* "SERVER: dbprep")
+ (set! *dbstruct-db* (db:setup #t)) ;; run-id))
+ (set! server-going #t)
+ (debug:print 0 *default-log-port* "SERVER: running, megatest version: " (common:get-full-version)) ;; NOTE: the server is NOT yet marked as running in the log. We do that in the keep-running routine.
+ (thread-start! *watchdog*)))
+
+ ;; when things go wrong we don't want to be doing the various queries too often
+ ;; so we strive to run this stuff only every four seconds or so.
+ (let* ((sync-time (- (current-milliseconds) start-time))
+ (rem-time (quotient (- 4000 sync-time) 1000)))
+ (if (and (<= rem-time 4)
+ (> rem-time 0))
+ (thread-sleep! rem-time)))
+
+ (if (< count 1) ;; 3x3 = 9 secs aprox
+ (loop (+ count 1) 'running bad-sync-count (current-milliseconds)))
+
+ ;; Check that iface and port have not changed (can happen if server port collides)
+ (mutex-lock! *heartbeat-mutex*)
+ (set! sdat *server-info*)
+ (mutex-unlock! *heartbeat-mutex*)
+
+ (if (not (equal? sdat (list iface port)))
+ (let ((new-iface (car sdat))
+ (new-port (cadr sdat)))
+ (debug:print-info 0 *default-log-port* "WARNING: interface changed, refreshing iface and port info")
+ (set! iface new-iface)
+ (set! port new-port)
+ (if (not *server-id*)
+ (set! *server-id* (server:mk-signature)))
+ (debug:print 0 *default-log-port* (current-seconds) (current-directory) (current-process-id) (argv))
+ (debug:print 0 *default-log-port* "SERVER STARTED: " iface ":" port " AT " (current-seconds) " server-id: " *server-id*)
+ (flush-output *default-log-port*)))
+
+ ;; Transfer *db-last-access* to last-access to use in checking that we are still alive
+ (mutex-lock! *heartbeat-mutex*)
+ (set! last-access *db-last-access*)
+ (mutex-unlock! *heartbeat-mutex*)
+
+ (if (common:low-noise-print 120 (conc "server running on " iface ":" port))
+ (begin
+ (if (not *server-id*)
+ (set! *server-id* (server:mk-signature)))
+ (debug:print 0 *default-log-port* (current-seconds) (current-directory) (current-process-id) (argv))
+ (debug:print 0 *default-log-port* "SERVER STARTED: " iface ":" port " AT " (current-seconds) " server-id: " *server-id*)
+ (flush-output *default-log-port*)))
+ (if (common:low-noise-print 60 "dbstats")
+ (begin
+ (debug:print 0 *default-log-port* "Server stats:")
+ (db:print-current-query-stats)))
+ (let* ((hrs-since-start (/ (- (current-seconds) server-start-time) 3600)))
+ (cond
+ ((and *server-run*
+ (> (+ last-access server-timeout)
+ (current-seconds)))
+ (if (common:low-noise-print 120 "server continuing")
+ (debug:print-info 0 *default-log-port* "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
+ (let ((curr-time (current-seconds)))
+ (handle-exceptions
+ exn
+ (debug:print 0 *default-log-port* "ERROR: Failed to change timestamp on log file " server-log-file ". Are you out of space on that disk? exn=" exn)
+ (if (not *server-overloaded*)
+ (change-file-times server-log-file curr-time curr-time)))))
+ (loop 0 server-state bad-sync-count (current-milliseconds)))
+ (else
+ (debug:print-info 0 *default-log-port* "Server timed out. seconds since last db access: " (- (current-seconds) last-access))
+ (http-transport:server-shutdown port)))))))
+
+(define (http-transport:server-shutdown port)
+ (begin
+ ;;(BB> "http-transport:server-shutdown called")
+ (debug:print-info 0 *default-log-port* "Starting to shutdown the server. pid="(current-process-id))
+ ;;
+ ;; start_shutdown
+ ;;
+ (set! *time-to-exit* #t) ;; tell on-exit to be fast as we've already cleaned up
+ (portlogger:open-run-close portlogger:set-port port "released")
+ (thread-sleep! 1)
+
+ ;; (debug:print-info 0 *default-log-port* "Max cached queries was " *max-cache-size*)
+ ;; (debug:print-info 0 *default-log-port* "Number of cached writes " *number-of-writes*)
+ ;; (debug:print-info 0 *default-log-port* "Average cached write time "
+ ;; (if (eq? *number-of-writes* 0)
+ ;; "n/a (no writes)"
+ ;; (/ *writes-total-delay*
+ ;; *number-of-writes*))
+ ;; " ms")
+ ;; (debug:print-info 0 *default-log-port* "Number non-cached queries " *number-non-write-queries*)
+ ;; (debug:print-info 0 *default-log-port* "Average non-cached time "
+ ;; (if (eq? *number-non-write-queries* 0)
+ ;; "n/a (no queries)"
+ ;; (/ *total-non-write-delay*
+ ;; *number-non-write-queries*))
+ ;; " ms")
+
+ (db:print-current-query-stats)
+ (common:save-pkt `((action . exit)
+ (T . server)
+ (pid . ,(current-process-id)))
+ *configdat* #t)
+ (debug:print-info 0 *default-log-port* "Server shutdown complete. Exiting")
+ (exit)))
+
+;; all routes though here end in exit ...
+;;
+;; start_server?
+;;
+(define (http-transport:launch)
+ ;; check that a server start is in progress, pause or exit if so
+ (let* ((tmp-area (common:get-db-tmp-area))
+ (server-start (conc tmp-area "/.server-start"))
+ (server-started (conc tmp-area "/.server-started"))
+ (start-time (common:lazy-modification-time server-start))
+ (started-time (common:lazy-modification-time server-started))
+ (server-starting (< start-time started-time)) ;; if start-time is less than started-time then a server is still starting
+ (start-time-old (> (- (current-seconds) start-time) 5))
+ (cleanup-proc (lambda (msg)
+ (let* ((serv-fname (conc "server-" (current-process-id) "-" (get-host-name) ".log"))
+ (full-serv-fname (conc *toppath* "/logs/" serv-fname))
+ (new-serv-fname (conc *toppath* "/logs/" "defunct-" serv-fname)))
+ (debug:print 0 *default-log-port* msg)
+ (if (common:file-exists? full-serv-fname)
+ (system (conc "sleep 1;mv -f " full-serv-fname " " new-serv-fname))
+ (debug:print 0 *default-log-port* "INFO: cannot move " full-serv-fname " to " new-serv-fname))
+ (exit)))))
+ #;(if (and (not start-time-old) ;; last server start try was less than five seconds ago
+ (not server-starting))
+ (begin
+ (cleanup-proc "NOT starting server, there is either a recently started server or a server in process of starting")
+ (exit)))
+ ;; lets not even bother to start if there are already three or more server files ready to go
+ #;(let* ((num-alive (server:get-num-alive (server:get-list *toppath*))))
+ (if (> num-alive 3)
+ (begin
+ (cleanup-proc (conc "ERROR: Aborting server start because there are already " num-alive " possible servers either running or starting up"))
+ (exit))))
+ (common:save-pkt `((action . start)
+ (T . server)
+ (pid . ,(current-process-id)))
+ *configdat* #t)
+ (let* ((th2 (make-thread (lambda ()
+ (debug:print-info 0 *default-log-port* "Server run thread started")
+ (http-transport:run
+ (if (args:get-arg "-server")
+ (args:get-arg "-server")
+ "-")
+ )) "Server run"))
+ (th3 (make-thread (lambda ()
+ (debug:print-info 0 *default-log-port* "Server monitor thread started")
+ (http-transport:keep-running)
+ "Keep running"))))
+ (thread-start! th2)
+ (thread-sleep! 0.25) ;; give the server time to settle before starting the keep-running monitor.
+ (thread-start! th3)
+ (set! *didsomething* #t)
+ (thread-join! th2)
+ (exit))))
+
+;; (define (http-transport:server-signal-handler signum)
+;; (signal-mask! signum)
+;; (handle-exceptions
+;; exn
+;; (debug:print 0 *default-log-port* " ... exiting ...")
+;; (let ((th1 (make-thread (lambda ()
+;; (thread-sleep! 1))
+;; "eat response"))
+;; (th2 (make-thread (lambda ()
+;; (debug:print-error 0 *default-log-port* "Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
+;; (thread-sleep! 3) ;; give the flush three seconds to do it's stuff
+;; (debug:print 0 *default-log-port* " Done.")
+;; (exit 4))
+;; "exit on ^C timer")))
+;; (thread-start! th2)
+;; (thread-start! th1)
+;; (thread-join! th2))))
+
+;;======================================================================
+;; faux-lock is deprecated. Please use simple-lock below
+;;======================================================================
+;;======================================================================
+;;
+(define (common:faux-lock keyname #!key (wait-time 8)(allow-lock-steal #t))
+ (if (rmt:no-sync-get/default keyname #f) ;; do not be tempted to compare to pid. locking is a one-shot action, if already locked for this pid it doesn't actually count
+ (if (> wait-time 0)
+ (begin
+ (thread-sleep! 1)
+ (if (eq? wait-time 1) ;; only one second left, steal the lock
+ (begin
+ (debug:print-info 0 *default-log-port* "stealing lock for " keyname)
+ (common:faux-unlock keyname force: #t)))
+ (common:faux-lock keyname wait-time: (- wait-time 1)))
+ #f)
+ (begin
+ (rmt:no-sync-set keyname (conc (current-process-id)))
+ (equal? (conc (current-process-id)) (conc (rmt:no-sync-get/default keyname #f))))))
+
+(define (common:faux-unlock keyname #!key (force #f))
+ (if (or force (equal? (conc (current-process-id)) (conc (rmt:no-sync-get/default keyname #f))))
+ (begin
+ (if (rmt:no-sync-get/default keyname #f) (rmt:no-sync-del! keyname))
+ #t)
+ #f))
+;;======================================================================
+
+;;======================================================================
+;; simple lock. improve and converge on this one.
+;;
+(define (common:simple-lock keyname)
+ (rmt:no-sync-get-lock keyname))
+
+(define (common:simple-unlock keyname #!key (force #f))
+ (rmt:no-sync-del! keyname))
+
+;;======================================================================
+;; ideally put all this info into the db, no need to preserve it across moving homehost
+;;
+;; return list of
+;; ( reachable? cpuload update-time )
+(define (common:get-host-info hostname)
+ (let* ((loadinfo (rmt:get-latest-host-load hostname)) ;; if this host happens to have been recently used by a test reuse the load data
+ (load (car loadinfo))
+ (load-sample-time (cdr loadinfo))
+ (load-sample-age (- (current-seconds) load-sample-time))
+ (loadinfo-timeout-seconds 6) ;; this was 20 seconds, seems way too lax. Switch to 6 seconds
+ (host-last-update-timeout-seconds 4)
+ (host-rec (hash-table-ref/default *host-loads* hostname #f))
+ )
+ (cond
+ ((< load-sample-age loadinfo-timeout-seconds)
+ (list #t
+ load-sample-time
+ load))
+ ((and host-rec
+ (< (current-seconds) (+ (host-last-update host-rec) host-last-update-timeout-seconds)))
+ (list #t
+ (host-last-update host-rec)
+ (host-last-cpuload host-rec )))
+ ((common:unix-ping hostname)
+ (list #t
+ (current-seconds)
+ (alist-ref 'adj-core-load (common:get-normalized-cpu-load hostname)))) ;; this is cheaper than you might think. get-normalized-cpu-load is cached for up to 5 seconds
+ (else
+ (list #f 0 -1) ;; bad host, don't use!
+ ))))
+
+(define (std-exit-procedure)
+ ;;(common:telemetry-log-close)
+ (on-exit (lambda () 0))
+ ;;(debug:print-info 13 *default-log-port* "std-exit-procedure called; *time-to-exit*="*time-to-exit*)
+ (let ((no-hurry (if *time-to-exit* ;; hurry up
+ #f
+ (begin
+ (set! *time-to-exit* #t)
+ #t))))
+ (debug:print-info 4 *default-log-port* "starting exit process, finalizing databases.")
+ (if (and no-hurry (debug:debug-mode 18))
+ (rmt:print-db-stats))
+ (let ((th1 (make-thread (lambda () ;; thread for cleaning up, give it five seconds
+ (if *dbstruct-db* (db:close-all *dbstruct-db*)) ;; one second allocated
+ (if *task-db*
+ (let ((db (cdr *task-db*)))
+ (if (sqlite3:database? db)
+ (begin
+ (sqlite3:interrupt! db)
+ (sqlite3:finalize! db #t)
+ ;; (vector-set! *task-db* 0 #f)
+ (set! *task-db* #f)))))
+ (http-client#close-all-connections!)
+ ;; (if (and *runremote*
+ ;; (remote-conndat *runremote*))
+ ;; (begin
+ ;; (http-client#close-all-connections!))) ;; for http-client
+ (if (not (eq? *default-log-port* (current-error-port)))
+ (close-output-port *default-log-port*))
+ (set! *default-log-port* (current-error-port))) "Cleanup db exit thread"))
+ (th2 (make-thread (lambda ()
+ (debug:print 4 *default-log-port* "Attempting clean exit. Please be patient and wait a few seconds...")
+ (if no-hurry
+ (begin
+ (thread-sleep! 5)) ;; give the clean up few seconds to do it's stuff
+ (begin
+ (thread-sleep! 2)))
+ (debug:print 4 *default-log-port* " ... done")
+ )
+ "clean exit")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1)
+ )
+ )
+
+ 0)
+
+;;======================================================================
+;; from metadat lookup MEGATEST_VERSION
+;;
+(define (common:get-last-run-version) ;; RADT => How does this work in send-receive function??; assume it is the value saved in some DB
+ (rmt:get-var "MEGATEST_VERSION"))
+
+(define (common:set-last-run-version)
+ (rmt:set-var "MEGATEST_VERSION" (common:version-signature)))
+
+(define (common:get-last-run-version-number)
+ (string->number
+ (substring (common:get-last-run-version) 0 6)))
+
+(define (common:version-db-delta)
+ (- megatest-version (common:get-last-run-version-number)))
+
+(define (common:version-changed?)
+ (not (equal? (common:get-last-run-version)
+ (common:version-signature))))
+
+(define (common:api-changed? dbstruct)
+ (not (equal? (substring (->string megatest-version) 0 4)
+ (substring (conc (common:get-last-run-version)) 0 4))))
+
+;;======================================================================
+;; see defstruct host at top of file.
+;; host: reachable last-update last-used last-cpuload
+;;
+(define (common:update-host-loads-table hosts-raw)
+ (let* ((hosts (filter (lambda (x)
+ (string-match (regexp "^\\S+$") x))
+ hosts-raw)))
+ (for-each
+ (lambda (hostname)
+ (let* ((rec (let ((h (hash-table-ref/default *host-loads* hostname #f)))
+ (if h
+ h
+ (let ((h (make-host)))
+ (hash-table-set! *host-loads* hostname h)
+ h))))
+ (host-info (common:get-host-info hostname))
+ (is-reachable (car host-info))
+ (last-reached-time (cadr host-info))
+ (load (caddr host-info)))
+ (host-reachable-set! rec is-reachable)
+ (host-last-update-set! rec last-reached-time)
+ (host-last-cpuload-set! rec load)))
+ hosts)))
+
+;;======================================================================
+;; go through the hosts from least recently used to most recently used, pick the first that meets the load criteral from the
+;; [host-rules] section.
+;;
+(define (common:get-least-loaded-host hosts-raw host-type configdat)
+ (let* ((rdat (configf:lookup configdat "host-rules" host-type))
+ (rules (common:val->alist (or rdat "") convert: #t)) ;; maxnload, maxnjobs, maxjobrate
+ (maxnload (common:alist-ref/default 'maxnload rules 1.5)) ;; max normalized load
+ (maxnjobs (common:alist-ref/default 'maxnjobs rules 1.5)) ;; max normalized number of jobs
+ (maxjobrate (common:alist-ref/default 'maxjobrate rules (/ 1 6))) ;; max rate of submitting jobs to a given host in jobs/second
+ (hosts (filter (lambda (x)
+ (string-match (regexp "^\\S+$") x))
+ hosts-raw))
+ ;; (best-host #f)
+ (get-rec (lambda (hostname)
+ ;; (print "get-rec hostname=" hostname)
+ (let ((h (hash-table-ref/default *host-loads* hostname #f)))
+ (if h
+ h
+ (let ((h (make-host)))
+ (hash-table-set! *host-loads* hostname h)
+ h)))))
+ (best-load 99999)
+ (curr-time (current-seconds))
+ (get-hosts-sorted (lambda (hosts)
+ (sort hosts (lambda (a b)
+ (let ((a-rec (get-rec a))
+ (b-rec (get-rec b)))
+ ;; (print "a=" a " a-rec=" a-rec " host-last-used=" (host-last-used a-rec))
+ ;; (print "b=" b " b-rec=" b-rec " host-last-used=" (host-last-used b-rec))
+ (< (host-last-used a-rec)
+ (host-last-used b-rec))))))))
+ (debug:print 0 *default-log-port* "INFO: hosts-sorted=" (get-hosts-sorted hosts))
+ (if (null? hosts)
+ #f ;; no hosts to select from. All done and giving up now.
+ (let ((hosts-sorted (get-hosts-sorted hosts)))
+ (common:update-host-loads-table hosts)
+ (let loop ((hostname (car hosts-sorted))
+ (tal (cdr hosts-sorted))
+ (best-host #f))
+ (let* ((rec (get-rec hostname))
+ (reachable (host-reachable rec))
+ (load (host-last-cpuload rec))
+ (last-used (host-last-used rec))
+ (delta (- curr-time last-used))
+ (job-rate (if (> delta 0)
+ (/ 1 delta)
+ 999)) ;; jobs per second
+ (new-best
+ (cond
+ ((not reachable)
+ (debug:print 0 *default-log-port* "Skipping host " hostname " as it cannot be reached.")
+ best-host)
+ ((and (< load maxnload) ;; load is acceptable
+ (< job-rate maxjobrate)) ;; job rate is acceptable
+ (set! best-load load)
+ hostname)
+ (else best-host))))
+ (debug:print 0 *default-log-port* "INFO: Trying host " hostname " with load " load ", last used " delta " seconds ago, with job-rate " job-rate " for running a test." )
+ (if new-best
+ (begin ;; found a host, return it
+ (debug:print 0 *default-log-port* "INFO: Found host: " new-best " load: " load " last-used: " delta " seconds ago, with job-rate: " job-rate)
+ (host-last-used-set! rec curr-time)
+ new-best)
+ (if (null? tal) #f (loop (car tal)(cdr tal) best-host)))))))))
+
+;;======================================================================
+;; T E S T L A U N C H I N G P E R I T E M W I T H H O S T T Y P E S
+;;======================================================================
+;;
+;; [hosts]
+;; arm cubie01 cubie02
+;; x86_64 zeus xena myth01
+;; allhosts #{g hosts arm} #{g hosts x86_64}
+;;
+;; [host-types]
+;; general #MTLOWESTLOAD #{g hosts allhosts}
+;; arm #MTLOWESTLOAD #{g hosts arm}
+;; nbgeneral nbjob run JOBCOMMAND -log $MT_LINKTREE/$MT_TARGET/$MT_RUNNAME.$MT_TESTNAME-$MT_ITEM_PATH.lgo
+;;
+;; [host-rules]
+;; # maxnload => max normalized load
+;; # maxnjobs => max jobs per cpu
+;; # maxjobrate => max jobs per second
+;; general maxnload=1.1; maxnjobs=1.2; maxjobrate=0.1
+;;
+;; [launchers]
+;; envsetup general
+;; xor/%/n 4C16G
+;; % nbgeneral
+;;
+;; [jobtools]
+;; # if defined and not "no" flexi-launcher will bypass "launcher" unless no match.
+;; flexi-launcher yes
+;; launcher nbfake
+;;
+(define (common:get-launcher configdat testname itempath)
+ (let ((fallback-launcher (configf:lookup configdat "jobtools" "launcher")))
+ (if (and (configf:lookup configdat "jobtools" "flexi-launcher") ;; overrides launcher
+ (not (equal? (configf:lookup configdat "jobtools" "flexi-launcher") "no")))
+ (let* ((launchers (hash-table-ref/default configdat "launchers" '())))
+ (if (null? launchers)
+ fallback-launcher
+ (let loop ((hed (car launchers))
+ (tal (cdr launchers)))
+ (let ((patt (car hed))
+ (host-type (cadr hed)))
+ (if (tests:match patt testname itempath)
+ (begin
+ (debug:print-info 2 *default-log-port* "Have flexi-launcher match for " testname "/" itempath " = " host-type)
+ (let ((launcher (configf:lookup configdat "host-types" host-type)))
+ (if launcher
+ (let* ((launcher-parts (string-split launcher))
+ (launcher-exe (car launcher-parts)))
+ (if (equal? launcher-exe "#MTLOWESTLOAD") ;; this is our special case, we will find the lowest load and craft a nbfake commandline
+ (let host-loop ((targ-host (common:get-least-loaded-host (cdr launcher-parts) host-type configdat))
+ (count 100))
+ (if targ-host
+ (conc "remrun " targ-host)
+ (if (> count 0)
+ (begin
+ (debug:print 0 *default-log-port* "INFO: Waiting for a host for host-type " host-type)
+ (thread-sleep! (- 101 count))
+ (host-loop (common:get-least-loaded-host (cdr launcher-parts) host-type configdat)
+ (- count 1)))
+ (begin
+ (debug:print 0 *default-log-port* "FATAL: Failed to find a host from #MTLOWESTLOAD for host-type " host-type)
+ (exit)))))
+ launcher))
+ (begin
+ (debug:print-info 0 *default-log-port* "WARNING: no launcher found for host-type " host-type)
+ (if (null? tal)
+ fallback-launcher
+ (loop (car tal)(cdr tal)))))))
+ ;; no match, try again
+ (if (null? tal)
+ fallback-launcher
+ (loop (car tal)(cdr tal))))))))
+ fallback-launcher)))
+
+;;======================================================================
+;; everything from client moved here
+;;======================================================================
+;; client:get-signature
+(define (client:get-signature)
+ (if *my-client-signature* *my-client-signature*
+ (let ((sig (conc (get-host-name) " " (current-process-id))))
+ (set! *my-client-signature* sig)
+ *my-client-signature*)))
+
+;; Not currently used! But, I think it *should* be used!!!
+#;(define (client:logout serverdat)
+ (let ((ok (and (socket? serverdat)
+ (cdb:logout serverdat *toppath* (client:get-signature)))))
+ ok))
+
+#;(define (client:connect iface port)
+ (http-transport:client-connect iface port)
+ #;(case (server:get-transport)
+ ((rpc) (rpc:client-connect iface port))
+ ((http) (http:client-connect iface port))
+ ((zmq) (zmq:client-connect iface port))
+ (else (rpc:client-connect iface port))))
+
+(define (client:setup areapath #!key (remaining-tries 100) (failed-connects 0))
+ (client:setup-http areapath remaining-tries: remaining-tries failed-connects: failed-connects)
+ #;(case (server:get-transport)
+ ((rpc) (rpc-transport:client-setup remaining-tries: remaining-tries failed-connects: failed-connects)) ;;(client:setup-rpc run-id))
+ ((http)(client:setup-http areapath remaining-tries: remaining-tries failed-connects: failed-connects))
+ (else (rpc-transport:client-setup remaining-tries: remaining-tries failed-connects: failed-connects)))) ;; (client:setup-rpc run-id))))
+
+;; Do all the connection work, look up the transport type and set up the
+;; connection if required.
+;;
+;; There are two scenarios.
+;; 1. We are a test manager and we received *transport-type* and *runremote* via cmdline
+;; 2. We are a run tests, list runs or other interactive process and we must figure out
+;; *transport-type* and *runremote* from the monitor.db
+;;
+;; client:setup
+;;
+;; lookup_server, need to remove *runremote* stuff
+;;
+
+(define (client:setup-http areapath #!key (remaining-tries 100) (failed-connects 0)(area-dat #f))
+ (debug:print-info 2 *default-log-port* "client:setup remaining-tries=" remaining-tries)
+ (server:start-and-wait areapath)
+ (if (<= remaining-tries 0)
+ (begin
+ (debug:print-error 0 *default-log-port* "failed to start or connect to server")
+ (exit 1))
+ ;;
+ ;; Alternatively here, we can get the list of candidate servers and work our way
+ ;; through them searching for a good one.
+ ;;
+ (let* ((server-dat (server:get-rand-best areapath)) ;; (server:get-first-best areapath))
+ (runremote (or area-dat *runremote*)))
+ (if (not server-dat) ;; no server found
+ (client:setup-http areapath remaining-tries: (- remaining-tries 1))
+ (let ((host (cadr server-dat))
+ (port (caddr server-dat))
+ (server-id (caddr (cddr server-dat))))
+ (debug:print-info 4 *default-log-port* "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
+ (if (and (not area-dat)
+ (not *runremote*))
+ (begin
+ ;; POSSIBLE BUG. I removed the full initialization call. mrw
+ (set! *runremote* (create-remote-record))
+ (let* ((server-info (remote-server-info *runremote*)))
+ (if server-info
+ (begin
+ (remote-server-url-set! *runremote* (server:record->url server-info))
+ (remote-server-id-set! *runremote* (server:record->id server-info)))))))
+ (if (and host port server-id)
+ (let* ((start-res (http-transport:client-connect host port server-id))
+ (ping-res (rmt:login-no-auto-client-setup start-res)))
+ (if (and start-res
+ ping-res)
+ (let ((runremote (or area-dat *runremote*))) ;; it might have been generated only a few statements ago
+ (remote-conndat-set! runremote start-res) ;; (hash-table-set! runremote run-id start-res)
+ (debug:print-info 2 *default-log-port* "connected to " (http-transport:server-dat-make-url start-res))
+ start-res)
+ (begin ;; login failed but have a server record, clean out the record and try again
+ (debug:print-info 0 *default-log-port* "client:setup, login unsuccessful, will attempt to start server ... start-res=" start-res ", server-dat=" server-dat) ;; had runid. Fixes part of Randy;s ticket 1405717332
+ (case *transport-type*
+ ((http)(http-transport:close-connections)))
+ (remote-conndat-set! runremote #f) ;; (hash-table-delete! runremote run-id)
+ (thread-sleep! 1)
+ (client:setup-http areapath remaining-tries: (- remaining-tries 1))
+ )))
+ (begin ;; no server registered
+ ;; (server:kind-run areapath)
+ (server:start-and-wait areapath)
+ (debug:print-info 0 *default-log-port* "client:setup, no server registered, remaining-tries=" remaining-tries)
+ (thread-sleep! 1) ;; (+ 5 (random (- 20 remaining-tries)))) ;; give server a little time to start up, randomize a little to avoid start storms.
+ (client:setup-http areapath remaining-tries: (- remaining-tries 1)))))))))
+
+;; NOTE: Run this local with #f for db !!!
+(define (tdb:load-test-data run-id test-id)
+ (let loop ((lin (read-line)))
+ (if (not (eof-object? lin))
+ (begin
+ (debug:print 4 *default-log-port* lin)
+ ;;(when lin ;; this when blocked stack dump caused by .dat file from logpro being 0-byte. fixed by upgrading logpro
+ (rmt:csv->test-data run-id test-id lin)
+ ;;)
+ (loop (read-line)))))
+ ;; roll up the current results.
+ ;; FIXME: Add the status too
+ (rmt:test-data-rollup run-id test-id #f))
+
+;; NOTE: Run this local with #f for db !!!
+(define (tdb:load-logpro-data run-id test-id)
+ (let loop ((lin (read-line)))
+ (if (not (eof-object? lin))
+ (begin
+ (debug:print 4 *default-log-port* lin)
+ ;;(when lin ;; this when blocked stack dump caused by .dat file from logpro being 0-byte. fixed by upgrading logpro
+ (rmt:csv->test-data run-id test-id lin)
+ ;;)
+ (loop (read-line)))))
+ ;; roll up the current results.
+ ;; FIXME: Add the status too
+ (rmt:test-data-rollup run-id test-id #f))
+
+;; find and open the testdat.db file for an existing test
+(define (tdb:open-test-db-by-test-id test-id #!key (work-area #f))
+ (let* ((test-path (if work-area
+ work-area
+ (rmt:test-get-rundir-from-test-id test-id))))
+ (debug:print 3 *default-log-port* "TEST PATH: " test-path)
+ (open-test-db test-path)))
+
+
+)
ADDED attic_modular/run_records.scm
Index: attic_modular/run_records.scm
==================================================================
--- /dev/null
+++ attic_modular/run_records.scm
@@ -0,0 +1,48 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+;;
+;;======================================================================
+
+(define-inline (runs:runrec-make-record) (make-vector 13))
+(define-inline (runs:runrec-get-target vec)(vector-ref vec 0)) ;; a/b/c
+(define-inline (runs:runrec-get-runname vec)(vector-ref vec 1)) ;; string
+(define-inline (runs:runrec-testpatt vec)(vector-ref vec 2)) ;; a,b/c,d%
+(define-inline (runs:runrec-keys vec)(vector-ref vec 3)) ;; (key1 key2 ...)
+(define-inline (runs:runrec-keyvals vec)(vector-ref vec 4)) ;; ((key1 val1)(key2 val2) ...)
+(define-inline (runs:runrec-environment vec)(vector-ref vec 5)) ;; environment, alist key val
+(define-inline (runs:runrec-mconfig vec)(vector-ref vec 6)) ;; megatest.config
+(define-inline (runs:runrec-runconfig vec)(vector-ref vec 7)) ;; runconfigs.config
+(define-inline (runs:runrec-serverdat vec)(vector-ref vec 8)) ;; (host port)
+(define-inline (runs:runrec-transport vec)(vector-ref vec 9)) ;; 'http
+(define-inline (runs:runrec-db vec)(vector-ref vec 10)) ;; (if 'fs)
+(define-inline (runs:runrec-top-path vec)(vector-ref vec 11)) ;; *toppath*
+(define-inline (runs:runrec-run_id vec)(vector-ref vec 12)) ;; run-id
+
+(define-inline (test:get-id vec) (vector-ref vec 0))
+(define-inline (test:get-run_id vec) (vector-ref vec 1))
+(define-inline (test:get-test-name vec)(vector-ref vec 2))
+(define-inline (test:get-state vec) (vector-ref vec 3))
+(define-inline (test:get-status vec) (vector-ref vec 4))
+(define-inline (test:get-item-path vec)(vector-ref vec 5))
+
+(define-inline (test:test-get-fullname test)
+ (conc (db:test-get-testname test)
+ (if (equal? (db:test-get-item-path test) "")
+ ""
+ (conc "(" (db:test-get-item-path test) ")"))))
+
ADDED attic_modular/runconfig.scm
Index: attic_modular/runconfig.scm
==================================================================
--- /dev/null
+++ attic_modular/runconfig.scm
@@ -0,0 +1,169 @@
+;; 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 .
+
+;;======================================================================
+;; read a config file, loading only the section pertinent
+;; to this run field1val/field2val/field3val ...
+;;======================================================================
+
+(use format directory-utils)
+
+(declare (unit runconfig))
+(declare (uses common))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(include "common_records.scm")
+
+(define (runconfig:read fname target environ-patt)
+ (let ((ht (make-hash-table)))
+ (if target (hash-table-set! ht target '()))
+ (read-config fname ht #t environ-patt: environ-patt sections: (if target (list "default" target) #f))))
+
+;; NB// to process a runconfig ensure to use environ-patt with target!
+;;
+(define (setup-env-defaults fname run-id already-seen keyvals #!key (environ-patt #f)(change-env #t))
+ (let* ((keys (map car keyvals))
+ (thekey (if keyvals
+ (string-intersperse (map (lambda (x)(if x x "-na-")) (map cadr keyvals)) "/")
+ (or (common:args-get-target)
+ (get-environment-variable "MT_TARGET")
+ (begin
+ (debug:print-error 0 *default-log-port* "setup-env-defaults called with no run-id or -target or -reqtarg")
+ "nothing matches this I hope"))))
+ ;; Why was system disallowed in the reading of the runconfigs file?
+ ;; NOTE: Should be setting env vars based on (target|default)
+ (confdat (runconfig:read fname thekey environ-patt))
+ (whatfound (make-hash-table))
+ (finaldat (make-hash-table))
+ (sections (list "default" thekey)))
+ (if (not *target*)(set! *target* thekey)) ;; may save a db access or two but repeats db:get-target code
+ (debug:print 4 *default-log-port* "Using key=\"" thekey "\"")
+
+ (if change-env
+ (for-each ;; NB// This can be simplified with new content of keyvals having all that is needed.
+ (lambda (keyval)
+ (safe-setenv (car keyval)(cadr keyval)))
+ keyvals))
+
+ (for-each
+ (lambda (section)
+ (let ((section-dat (hash-table-ref/default confdat section #f)))
+ (if section-dat
+ (for-each
+ (lambda (envvar)
+ (let ((val (cadr (assoc envvar section-dat))))
+ (hash-table-set! whatfound section (+ (hash-table-ref/default whatfound section 0) 1))
+ (if (and (string? envvar)
+ (string? val)
+ change-env)
+ (safe-setenv envvar val))
+ (hash-table-set! finaldat envvar val)))
+ (map car section-dat)))))
+ sections)
+ (if already-seen
+ (begin
+ (debug:print 2 *default-log-port* "Key settings found in runconfigs.config:")
+ (for-each (lambda (fullkey)
+ (debug:print 2 *default-log-port* (format #f "~20a ~a\n" fullkey (hash-table-ref/default whatfound fullkey 0))))
+ sections)
+ (debug:print 2 *default-log-port* "---")
+ (set! *already-seen-runconfig-info* #t)))
+ ;; finaldat ;; was returning this "finaldat" which would be good but conflicts with other uses
+ confdat
+ ))
+
+(define (set-run-config-vars run-id keyvals targ-from-db)
+ (push-directory *toppath*) ;; the push/pop doesn't appear to do anything ...
+ (let ((runconfigf (conc *toppath* "/runconfigs.config"))
+ (targ (or (common:args-get-target)
+ targ-from-db
+ (get-environment-variable "MT_TARGET"))))
+ (pop-directory)
+ (if (common:file-exists? runconfigf)
+ (setup-env-defaults runconfigf run-id #t keyvals
+ environ-patt: (conc "(default"
+ (if targ
+ (conc "|" targ ")")
+ ")")))
+ (debug:print 0 *default-log-port* "WARNING: You do not have a run config file: " runconfigf))))
+
+;; given (a (b c) d) return ((a b d)(a c d))
+;; NOTE: this feels like it has been done before - perhaps with items handling?
+;;
+(define (runconfig:combinations inlst)
+ (let loop ((hed (car inlst))
+ (tal (cdr inlst))
+ (res '()))
+ ;; (print "res: " res " hed: " hed)
+ (if (list? hed)
+ (let ((newres (if (null? res) ;; first time through convert incoming items to list of items
+ (map list hed)
+ (apply append
+ (map (lambda (r) ;; iterate over items in res
+ (map (lambda (h) ;; iterate over items in hed
+ (append r (list h)))
+ hed))
+ res)))))
+ ;; (print "newres1: " newres)
+ (if (null? tal)
+ newres
+ (loop (car tal)(cdr tal) newres)))
+ (let ((newres (if (null? res)
+ (list (list hed))
+ (map (lambda (r)
+ (append r (list hed)))
+ res))))
+ ;; (print "newres2: " newres)
+ (if (null? tal)
+ newres
+ (loop (car tal)(cdr tal) newres))))))
+
+;; multi-part expand
+;; Given a/b,c,d/e,f return a/b/e a/b/f a/c/e a/c/f a/d/e a/d/f
+;;
+(define (runconfig:expand target)
+ (let* ((parts (map (lambda (x)
+ (string-split x ","))
+ (string-split target "/"))))
+ (map (lambda (x)
+ (string-intersperse x "/"))
+ (runconfig:combinations parts))))
+
+;; multi-target expansion
+;; a/b/c/x,y,z a/b/d/x,y => a/b/c/x a/b/c/y a/b/c/z a/b/d/x a/b/d/y
+;;
+(define (runconfig:expand-target target-strs)
+ (delete-duplicates
+ (apply append (map runconfig:expand (string-split target-strs " ")))))
+
+#|
+ (if (null? target-strs)
+ '()
+ (let loop ((hed (car target-strs))
+ (tal (cdr target-strs))
+ (res '()))
+ ;; first break all parts into individual target patterns
+ (if (string-index hed " ") ;; this is a multi-target target
+ (let ((newres (append (string-split hed " ") res)))
+ (runconfig:expand-target newres))
+ (if (string-index hed ",") ;; this is a multi-target where one or more parts are comma separated
+
+|#
ADDED attic_modular/runs-launch-loop-test.scm
Index: attic_modular/runs-launch-loop-test.scm
==================================================================
--- /dev/null
+++ attic_modular/runs-launch-loop-test.scm
@@ -0,0 +1,76 @@
+;; 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 .
+;;
+(use srfi-69)
+
+(define (runs:queue-next-hed tal reg n regful)
+ (if regful
+ (car reg)
+ (car tal)))
+
+(define (runs:queue-next-tal tal reg n regful)
+ (if regful
+ tal
+ (let ((newtal (cdr tal)))
+ (if (null? newtal)
+ reg
+ newtal
+ ))))
+
+(define (runs:queue-next-reg tal reg n regful)
+ (if regful
+ (cdr reg)
+ (if (eq? (length tal) 1)
+ '()
+ reg)))
+
+(use trace)
+(trace runs:queue-next-hed
+ runs:queue-next-tal
+ runs:queue-next-reg)
+
+
+(define tests '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20))
+
+(define test-registry (make-hash-table))
+
+(define n 3)
+
+(let loop ((hed (car tests))
+ (tal (cdr tests))
+ (reg '()))
+ (let* ((reglen (length reg))
+ (regful (> reglen n)))
+ (print "hed=" hed ", length reg=" (length reg) ", (> lenreg n)=" (> (length reg) n))
+ (let ((newtal (append tal (list hed)))) ;; used if we are not done with this test
+ (cond
+ ((not (hash-table-ref/default test-registry hed #f))
+ (hash-table-set! test-registry hed #t)
+ (print "Registering #" hed)
+ (if (not (null? tal))
+ (loop (runs:queue-next-hed tal reg n regful)
+ (runs:queue-next-tal tal reg n regful)
+ (let ((newl (append reg (list hed))))
+ (if regful
+ (cdr newl)
+ newl)))))
+ (else
+ (print "Running #" hed)
+ (if (not (null? tal))
+ (loop (runs:queue-next-hed tal reg n regful)
+ (runs:queue-next-tal tal reg n regful)
+ (runs:queue-next-reg tal reg n regful))))))))
ADDED attic_modular/runs.scm
Index: attic_modular/runs.scm
==================================================================
--- /dev/null
+++ attic_modular/runs.scm
@@ -0,0 +1,3516 @@
+;; Copyright 2006-2016, 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 .
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+(use (prefix sqlite3 sqlite3:) srfi-1 posix regex regex-case srfi-69 (srfi 18)
+ posix-extras directory-utils pathname-expand typed-records format sxml-serializer
+ sxml-modifications matchable)
+
+(declare (unit runs))
+(declare (uses db))
+(declare (uses common))
+(declare (uses items))
+(declare (uses runconfig))
+(declare (uses tests))
+(declare (uses server))
+(declare (uses mt))
+(declare (uses archive))
+;; (declare (uses filedb))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses dbmod))
+(import dbmod)
+
+(declare (uses servermod))
+(import servermod)
+
+(declare (uses margsmod))
+(import margsmod)
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "run_records.scm")
+(include "test_records.scm")
+
+;; (include "debugger.scm")
+
+;; use this struct to facilitate refactoring
+;;
+
+(defstruct runs:dat
+ reglen regfull
+ runname max-concurrent-jobs run-id
+ test-patts required-tests test-registry
+ registry-mutex flags keyvals run-info all-tests-registry
+ ;; stores results from last runs:can-run-more-tests
+ (can-run-more-tests #f) ;; (list can-run-more-flag num-running num-running-in-jobgroup max-concurrent-jobs job-group-limit)
+ ((can-run-more-tests-count 0) : fixnum)
+ (last-fuel-check 0) ;; time when we last checked fuel
+ (beginning-of-time (current-seconds))
+ (load-mgmt-function #f)
+ (wait-for-jobs-function #f)
+ (last-load-check-time 0)
+ (last-jobs-check-time 0)
+ )
+
+(defstruct runs:testdat
+ hed tal reg reruns test-record
+ test-name item-path jobgroup
+ waitons testmode newtal itemmaps prereqs-not-met)
+
+;; look in the $MT_RUN_AREA_HOME/.softlocks directory for key-host-pid.softlock files
+;; - remove any that are over 3600 seconds old
+;; - if there are any that are younger than 10 seconds
+;; * sleep 10 seconds
+;; * touch my key-host-pid.softlock file
+;; * return
+;; - if there are no files younger than 10 seconds
+;; * touch my key-host-pid.softlock file
+;; * return
+;;
+(define (runs:wait-on-softlock rdat key)
+ (if (not (and *toppath* (file-exists? *toppath*))) ;; don't seem to have toppath yet
+ (debug:print-info 0 *default-log-port* "Can't create softlocks - don't see MTRAH yet.")
+ (let* ((softlocks-dir (conc *toppath* "/.softlocks")))
+ (if (not (file-exists? softlocks-dir))
+ (create-directory softlocks-dir #t))
+ (let* ((my-lock-file (conc softlocks-dir "/" key "-" (get-host-name) "-" (current-process-id) ".softlock"))
+ (lock-files (filter (lambda (x)
+ (not (equal? x my-lock-file)))
+ (glob (conc softlocks-dir "/" key "*.softlock"))))
+ (fresh-locks (any (lambda (x) ;; do we have any locks younger than 10 seconds
+ (let* ((mod-time (file-modification-time x))
+ (age (- (current-seconds) mod-time)))
+ (cond
+ ((> age 3600) ;; too old to keep, remove it
+ (delete-file* x) #f)
+ ((< age 10) #t)
+ (else #f))))
+ lock-files)))
+ (if fresh-locks
+ (begin
+ (if (runs:lownoise "runners-softlock-wait" 360)
+ (debug:print-info 0 *default-log-port* "Other runners in flight, giving up some time..."))
+ (thread-sleep! 2))
+ (begin
+ (if (runs:lownoise "runners-softlock-nowait" 360)
+ (debug:print-info 0 *default-log-port* "No runners in flight, updating softlock"))
+ (let* ((ouf (open-output-file my-lock-file)))
+ (with-output-to-port ouf
+ (lambda ()(print (current-seconds))))
+ (close-output-port ouf))))
+ (runs:dat-last-fuel-check-set! rdat (current-seconds))))))
+
+;; Fourth try, do accounting through time
+;;
+(define (runs:parallel-runners-mgmt rdat)
+ (let ((time-to-check (configf:lookup-number *configdat* "runners" "time-to-check" default: 10)) ;; 28
+ (time-to-wait (configf:lookup-number *configdat* "runners" "time-to-wait" default: 30))
+ (now-time (current-seconds)))
+ (if (> (- now-time (runs:dat-last-fuel-check rdat)) time-to-check) ;; time to check
+ (runs:wait-on-softlock rdat "runners"))))
+
+;; To test parallel-runners management start a repl:
+;; megatest -repl
+;; then run:
+;; (runs:test-parallel-runners 60)
+;;
+(define (runs:test-parallel-runners duration #!optional (proc #f))
+ (let* ((rdat (make-runs:dat))
+ (rtime 0)
+ (startt (current-seconds))
+ (endt (+ startt duration)))
+ ((or proc runs:parallel-runners-mgmt) rdat)
+ (let loop ()
+ (let* ((wstart (current-seconds)))
+ (if (< wstart endt)
+ (let* ((work-time (random 10)))
+ #;(debug:print-info 0 *default-log-port* "working for " work-time
+ " seconds. Total work: " rtime ", elapsed time: " (- wstart startt))
+ (thread-sleep! work-time)
+ (set! rtime (+ rtime work-time))
+ ((or proc runs:parallel-runners-mgmt) rdat)
+ (loop)))))
+ (let* ((done-time (current-seconds)))
+ (debug:print-info 0 *default-log-port* "DONE: rtime=" rtime ", elapsed time=" (- done-time startt)
+ ", ratio=" (/ rtime (- done-time startt))))))
+
+(define (runs:get-mt-env-alist run-id runname target testname itempath)
+ ;;(bb-check-path msg: "runs:set-megatest-env-vars entry")
+ `(("MT_TEST_NAME" . ,testname)
+
+ ("MT_ITEMPATH" . ,itempath)
+
+ ("MT_TARGET" . ,target)
+
+ ("MT_RUNNAME" . ,runname)
+
+ ("MT_RUN_AREA_HOME" . ,*toppath*)
+
+ ,@(let* ((link-tree (common:get-linktree))) ;; (configf:lookup *configdat* "setup" "linktree")))
+ (if link-tree
+ (list (cons "MT_LINKTREE" link-tree)
+
+ (cons "MT_TEST_RUN_DIR"
+ (conc link-tree "/" target "/" runname "/" testname
+ (if (and (string? itempath) (not (equal? itempath "")))
+ (conc "/" itempath)
+ "")))
+ )
+ '()))
+
+ ,@(map
+ (lambda (key)
+ (cons (car key) (cadr key)))
+ (keys:target->keyval (rmt:get-keys) target))
+
+ ,@(map (lambda (var)
+ (let ((val (configf:lookup *configdat* "env-override" var)))
+ (cons var val)))
+ (configf:section-vars *configdat* "env-override"))))
+
+;; set up needed environment variables given a run-id and optionally a target, itempath etc.
+;;
+(define (runs:set-megatest-env-vars run-id #!key (inkeys #f)(inrunname #f)(inkeyvals #f)(intarget #f)(testname #f)(itempath #f))
+ ;;(bb-check-path msg: "runs:set-megatest-env-vars entry")
+ (let* ((target (or intarget
+ (common:args-get-target)
+ (get-environment-variable "MT_TARGET")))
+ (keys (if inkeys inkeys (rmt:get-keys)))
+ (keyvals (if inkeyvals inkeyvals (keys:target->keyval keys target)))
+ (vals (hash-table-ref/default *env-vars-by-run-id* run-id #f))
+ (link-tree (common:get-linktree))) ;; (configf:lookup *configdat* "setup" "linktree")))
+ (if testname (setenv "MT_TEST_NAME" testname))
+ (if itempath (setenv "MT_ITEMPATH" itempath))
+
+ ;; get the info from the db and put it in the cache
+ (if link-tree
+ (setenv "MT_LINKTREE" link-tree)
+ (debug:print-error 0 *default-log-port* "linktree not set, should be set in megatest.config in [setup] section."))
+ (if (not vals)
+ (let ((ht (make-hash-table)))
+ (hash-table-set! *env-vars-by-run-id* run-id ht)
+ (set! vals ht)
+ (for-each
+ (lambda (key)
+ (hash-table-set! vals (car key) (cadr key)))
+ keyvals)))
+ ;; from the cached data set the vars
+
+ (hash-table-for-each
+ vals
+ (lambda (key val)
+ (debug:print 2 *default-log-port* "setenv " key " " val)
+ (safe-setenv key val)))
+ ;;(bb-check-path msg: "runs:set-megatest-env-vars block 1")
+ ;;(BB> "*env-vars-by-run-id*/runid("run-id" vals="(hash-table->alist vals))
+
+ (if (not (get-environment-variable "MT_TARGET"))(setenv "MT_TARGET" target))
+ ;; we had a case where there was an exception generated by the hash-table-ref
+ ;; due to *configdat* being #f Adding a handle and exit
+ (let fatal-loop ((count 0))
+ (handle-exceptions
+ exn
+ (let ((call-chain (get-call-chain))
+ (msg ((condition-property-accessor 'exn 'message) exn)))
+ (if (< count 5)
+ (begin ;; this call is colliding, do some crude stuff to fix it.
+ (debug:print 0 *default-log-port* "ERROR: *configdat* was inaccessible! This should never happen. Retry #" count
+ ", exn=" exn)
+ (launch:setup force-reread: #t)
+ (fatal-loop (+ count 1)))
+ (begin
+ (debug:print 0 *default-log-port* "FATAL: *configdat* was inaccessible! This should never happen. Retried " count
+ " times. Message: " msg)
+ (debug:print 0 *default-log-port* "Call chain:")
+ (with-output-to-port *default-log-port*
+
+ (lambda ()
+ (print "*configdat* is >>"*configdat*"<<")
+ (pp *configdat*)
+ (pp call-chain)))
+
+ (exit 1))))
+ ;;(bb-check-path msg: "runs:set-megatest-env-vars block 1.5")
+ (when (or (not *configdat*) (not (hash-table? *configdat*)))
+ (debug:print 0 *default-log-port* "WARNING: *configdat* was inaccessible! This should never happen. Brute force reread.")
+ ;;(BB> "ERROR: *configdat* was inaccessible! This should never happen. Brute force reread.")
+ (thread-sleep! 2) ;; assuming nfs lag.
+ (launch:setup force-reread: #t))
+ (alist->env-vars (hash-table-ref/default *configdat* "env-override" '())))) ;;;; environment is tainted HERE in this let block.
+ ;;(bb-check-path msg: "runs:set-megatest-env-vars block 2")
+ ;; Lets use this as an opportunity to put MT_RUNNAME in the environment
+ (let ((runname (if inrunname inrunname (rmt:get-run-name-from-id run-id))))
+ (if runname
+ (setenv "MT_RUNNAME" runname)
+ (debug:print-error 0 *default-log-port* "no value for runname for id " run-id)))
+ (setenv "MT_RUN_AREA_HOME" *toppath*)
+ ;; if a testname and itempath are available set the remaining appropriate variables
+ (if testname (setenv "MT_TEST_NAME" testname))
+ (if itempath (setenv "MT_ITEMPATH" itempath))
+ ;;(bb-check-path msg: "runs:set-megatest-env-vars block 3")
+ (if (and testname link-tree)
+ (setenv "MT_TEST_RUN_DIR" (conc (getenv "MT_LINKTREE") "/"
+ (getenv "MT_TARGET") "/"
+ (getenv "MT_RUNNAME") "/"
+ (getenv "MT_TEST_NAME")
+ (if (and itempath
+ (not (equal? itempath "")))
+ (conc "/" itempath)
+ ""))))))
+
+(define (set-item-env-vars itemdat)
+ (for-each (lambda (item)
+ (debug:print 2 *default-log-port* "setenv " (car item) " " (cadr item))
+ (setenv (car item) (cadr item)))
+ itemdat))
+
+;; Every time can-run-more-tests is called increment the delay
+;;
+;; NOTE: We run this server-side!! Do not use this global except in the runs:can-run-more-tests routine
+;;
+(define *last-num-running-tests* 0)
+;; (define *runs:can-run-more-tests-count* 0)
+(define (runs:shrink-can-run-more-tests-count runsdat)
+ (runs:dat-can-run-more-tests-count-set! runsdat 0))
+
+(define (runs:inc-can-run-more-tests-count runsdat)
+ (runs:dat-can-run-more-tests-count-set!
+ runsdat
+ (+ (runs:dat-can-run-more-tests-count runsdat) 1)))
+
+;; (set! *runs:can-run-more-tests-count* 0)) ;; (/ *runs:can-run-more-tests-count* 2)))
+
+;; Temporary globals. Move these into the logic or into common
+;;
+(define *seen-cant-run-tests* (make-hash-table)) ;; use to track tests that we suspect cannot be run
+(define (runs:inc-cant-run-tests testname)
+ (hash-table-set! *seen-cant-run-tests* testname
+ (+ (hash-table-ref/default *seen-cant-run-tests* testname 0) 1)))
+
+(define (runs:can-keep-running? testname n)
+ (< (hash-table-ref/default *seen-cant-run-tests* testname 0) n))
+
+(define *runs:denoise* (make-hash-table)) ;; key => last-time-ran
+
+;; mechanism to limit printing info to the screen that is repetitive.
+;;
+;; Example:
+;; (if (runs:lownoise "waiting on tasks" 60)
+;; (debug:print-info 2 *default-log-port* "waiting for tasks to complete, sleeping briefly ..."))
+;;
+(define (runs:lownoise key waitval)
+ (let ((lasttime (hash-table-ref/default *runs:denoise* key 0))
+ (currtime (current-seconds)))
+ (if (> (- currtime lasttime) waitval)
+ (begin
+ (hash-table-set! *runs:denoise* key currtime)
+ #t)
+ #f)))
+
+(define (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs)
+
+ ;; Take advantage of a good place to exit if running the one-pass methodology
+ (if (and (> (runs:dat-can-run-more-tests-count runsdat) 20)
+ (args:get-arg "-one-pass"))
+ (exit 0))
+
+ (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+
+ (let* ((num-running (rmt:get-count-tests-running run-id))
+ (num-running-in-jobgroup (rmt:get-count-tests-running-in-jobgroup run-id jobgroup))
+ (job-group-limit (let ((jobg-count (configf:lookup *configdat* "jobgroups" jobgroup)))
+ (if (string? jobg-count)
+ (string->number jobg-count)
+ jobg-count))))
+ (if (> (+ num-running num-running-in-jobgroup) 0)
+ (runs:inc-can-run-more-tests-count runsdat)) ;; (set! *runs:can-run-more-tests-count* (+ *runs:can-run-more-tests-count* 1)))
+ (if (not (eq? *last-num-running-tests* num-running))
+ (begin
+ (debug:print 2 *default-log-port* "max-concurrent-jobs: " max-concurrent-jobs ", num-running: " num-running)
+ (set! *last-num-running-tests* num-running)))
+ (if (not (eq? 0 *globalexitstatus*))
+ (list #f num-running num-running-in-jobgroup max-concurrent-jobs job-group-limit)
+ (let* ((can-not-run-more (cond
+ ;; if max-concurrent-jobs is set and the number running is greater
+ ;; than it then cannot run more jobs
+ ((and max-concurrent-jobs (>= num-running max-concurrent-jobs))
+ (if (runs:lownoise "mcj msg" 60)
+ (debug:print 0 *default-log-port* "WARNING: Max running jobs exceeded, current number running: " num-running
+ ", max_concurrent_jobs: " max-concurrent-jobs))
+ #t)
+ ;; if job-group-limit is set and number of jobs in the group is greater
+ ;; than the limit then cannot run more jobs of this kind
+ ((and job-group-limit
+ (>= num-running-in-jobgroup job-group-limit))
+ (if (runs:lownoise (conc "maxjobgroup " jobgroup) 60)
+ (debug:print 1 *default-log-port* "WARNING: number of jobs " num-running-in-jobgroup
+ " in jobgroup \"" jobgroup "\" exceeds limit of " job-group-limit))
+ #t)
+ (else #f))))
+ (list (not can-not-run-more) num-running num-running-in-jobgroup max-concurrent-jobs job-group-limit)))))
+
+(define (runs:run-pre-hook run-id)
+ (let* ((run-pre-hook (configf:lookup *configdat* "runs" "pre-hook"))
+ (existing-tests (if run-pre-hook
+ (rmt:get-tests-for-run run-id "%" '() '() ;; run-id testpatt states statuses
+ #f #f ;; offset limit
+ #f ;; not-in
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; get full data (not 'shortlist)
+ 0 ;; (runs:gendat-inc-results-last-update *runs:general-data*) ;; last update time
+ 'dashboard)
+ '()))
+ (log-dir (conc *toppath* "/logs"))
+ (log-file (conc "pre-hook-" (string-translate (getenv "MT_TARGET") "/" "-") "-" (getenv "MT_RUNNAME") ".log"))
+ (full-log-fname (conc log-dir "/" log-file)))
+ (if run-pre-hook
+ (if (null? existing-tests)
+ (let* ((use-log-dir (if (not (directory-exists? log-dir))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Failed to create " log-dir ", exn=" exn)
+ #f)
+ (create-directory log-dir #t)
+ #t)
+ #t))
+ (start-time (current-seconds))
+ (actual-logf (if use-log-dir full-log-fname log-file)))
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain *default-log-port*)
+ (debug:print 0 *default-log-port* "Message: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn)
+ (debug:print 0 *default-log-port* "ERROR: failed to run pre-hook " run-pre-hook ", check the log " log-file))
+ (debug:print-info 0 *default-log-port* "running run-pre-hook: \"" run-pre-hook "\", log is " actual-logf)
+ (system (conc run-pre-hook " >> " actual-logf " 2>&1"))
+ (debug:print-info 0 *default-log-port* "pre-hook \"" run-pre-hook "\" took " (- (current-seconds) start-time) " seconds to run.")))
+ (debug:print 0 *default-log-port* "Skipping pre-hook call \"" run-pre-hook "\" as there are existing tests for this run.")))))
+
+
+
+(define (runs:run-post-hook run-id)
+ (let* ((run-post-hook (configf:lookup *configdat* "runs" "post-hook"))
+ (existing-tests (if run-post-hook
+ (rmt:get-tests-for-run run-id "%" '() '() ;; run-id testpatt states statuses
+ #f #f ;; offset limit
+ #f ;; not-in
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; get full data (not 'shortlist)
+ 0 ;; (runs:gendat-inc-results-last-update *runs:general-data*) ;; last update time
+ 'dashboard)
+ '()))
+ (log-dir (conc *toppath* "/logs"))
+ (log-file (conc "post-hook-" (string-translate (getenv "MT_TARGET") "/" "-") "-" (getenv "MT_RUNNAME") ".log"))
+ (full-log-fname (conc log-dir "/" log-file)))
+ (if run-post-hook
+ ;; (if (null? existing-tests)
+ ;; (debug:print 0 *default-log-port* "Skipping post-hook call \"" run-post-hook "\" as there are existing tests for this run.")))))
+ (let* ((use-log-dir (if (not (directory-exists? log-dir))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Failed to create " log-dir ", exn=" exn)
+ #f)
+ (create-directory log-dir #t)
+ #t)
+ #t))
+ (start-time (current-seconds))
+ (actual-logf (if use-log-dir full-log-fname log-file)))
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain *default-log-port*)
+ (debug:print 0 *default-log-port* "Message: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn)
+ (debug:print 0 *default-log-port* "ERROR: failed to run post-hook " run-post-hook ", check the log " log-file))
+ (debug:print-info 0 *default-log-port* "running run-post-hook: \"" run-post-hook "\", log is " actual-logf)
+ (system (conc run-post-hook " >> " actual-logf " 2>&1"))
+ (debug:print-info 0 *default-log-port* "post-hook \"" run-post-hook "\" took " (- (current-seconds) start-time) " seconds to run."))))))
+
+
+(define (runs:rerun-hook test-id new-test-path testdat rerunlst)
+ (let* ((rerun-hook (configf:lookup *configdat* "runs" "rerun-hook"))
+ (log-dir (conc *toppath* "/reruns/logs"))
+ (target (getenv "MT_TARGET"))
+ (runname (common:args-get-runname))
+ (rundir (db:test-get-rundir testdat))
+ (tarfiledir (conc *toppath* "/reruns"))
+ (status (db:test-get-status testdat))
+ (comment (conc "\"" (db:test-get-comment testdat) "\"" ))
+ (testname (db:test-get-testname testdat))
+ (itempath (db:test-get-item-path testdat))
+ (file-body (conc status "-" (string-translate target "/" "-") "-" runname "." testname (if (not (string=? itempath "")) (conc "." (string-translate itempath "/" "-")) "")))
+ (log-file (conc file-body ".log"))
+ ;; (log-file (conc status "-" (string-translate target "/" "-") "-" runname "." testname (if (not (string=? itempath "")) (conc "." (string-translate itempath "/" "-")) "") ".log"))
+ (full-log-fname (conc log-dir "/" log-file))
+ (tarfilename (conc file-body ".tar"))
+ ;; (tarfilename (conc status "." (string-translate target "/" "-") "." runname "." testname (if (not (string=? itempath "")) (conc "." (string-translate itempath "/" "-")) "") ".tar"))
+ )
+ (if rerun-hook
+ (let* ((use-log-dir (if (not (directory-exists? log-dir))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: Failed to create " log-dir ", exn=" exn)
+ #f)
+ (create-directory log-dir #t)
+ #t)
+ #t))
+ (start-time (current-seconds))
+ (actual-logf (if use-log-dir full-log-fname log-file))
+ (sys-call-text (conc rerun-hook " " tarfilename " " rundir " " actual-logf " " runname " " tarfiledir " " status " " target " " comment " " testname " " itempath " >> " actual-logf " 2>&1"))
+ )
+ (debug:print 2 *default-log-port* "Found rerun-hook in config:" rerun-hook)
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain *default-log-port*)
+ (debug:print 0 *default-log-port* "Message: " ((condition-property-accessor 'exn 'message) exn) ", exn=" exn)
+ (debug:print 0 *default-log-port* "ERROR: failed to run rerun-hook " rerun-hook ", check the log " log-file))
+ (debug:print-info 0 *default-log-port* "running rerun-hook: \"" rerun-hook "\", log is " actual-logf)
+ ;; call the hook
+ (debug:print-info 0 *default-log-port* "Calling rerun-hook for " test-id new-test-path testdat rerunlst)
+ (debug:print-info 0 *default-log-port* "rerun hook: " rerun-hook)
+ (debug:print-info 0 *default-log-port* "tarfilename: " tarfilename)
+ (debug:print-info 0 *default-log-port* "rundir: " rundir)
+ (debug:print-info 0 *default-log-port* "actual-logf: " actual-logf)
+ (debug:print-info 0 *default-log-port* "runname: " runname)
+ (debug:print-info 0 *default-log-port* "sys-call-text: " sys-call-text)
+ (system sys-call-text)
+ (debug:print-info 0 *default-log-port* "rerun-hook \"" rerun-hook "\" took " (- (current-seconds) start-time) " seconds to run."))))))
+
+
+
+
+;; return #t when all items in waitors-upon list are represented in test-patt, #f otherwise.
+(define (runs:testpatts-mention-waitors-upon? test-patt waitors-upon)
+ (null? (tests:filter-test-names-not-matched waitors-upon test-patt)))
+
+;;======================================================================
+;; runs:run-tests is called from megatest.scm and itself
+;;======================================================================
+;;
+;; test-names: Comma separated patterns same as test-patts but used in selection
+;; of tests to run. The item portions are not respected.
+;; FIXME: error out if /patt specified
+;;
+(define (runs:run-tests target runname test-patts user flags #!key (run-count 1)) ;; test-names
+ (let* ((keys (keys:config-get-fields *configdat*))
+ (keyvals (keys:target->keyval keys target))
+ (run-id (rmt:register-run keyvals runname "new" "n/a" user (args:get-arg "-contour"))) ;; test-name)))
+ ;; (deferred '()) ;; delay running these since they have a waiton clause
+ (runconfigf (conc *toppath* "/runconfigs.config"))
+ (dbfile (conc *toppath* "/megatest.db"))
+ (readonly-mode (not (file-write-access? dbfile)))
+ (test-records (make-hash-table))
+ ;; need to process runconfigs before generating these lists
+ (all-tests-registry #f) ;; (tests:get-all)) ;; (tests:get-valid-tests (make-hash-table) test-search-path)) ;; all valid tests to check waiton names
+ (all-test-names #f) ;; (hash-table-keys all-tests-registry))
+ (test-names #f) ;; Generated by a call to (tests:filter-test-names all-test-names test-patts))
+ (required-tests #f) ;; Put fully qualified test/testpath names in this list to be done
+ (waitors-upon (make-hash-table)) ;; given a test, return list of tests waiting upon this test.
+ (task-key (conc (hash-table->alist flags) " " (get-host-name) " " (current-process-id)))
+ ;; (tdbdat (tasks:open-db))
+ (config-reruns (let ((x (configf:lookup *configdat* "setup" "reruns")))
+ (if x (string->number x) #f)))
+ (allowed-tests #f)
+ (runconf #f))
+
+ ;; check if readonly
+ (when readonly-mode
+ (debug:print-error 0 *default-log-port* "megatest.db is readonly. Cannot proceed.")
+ (exit 1))
+
+ ;; per user request. If less than 100Meg space on dbdir partition, bail out with error
+ ;; this will reduce issues in database corruption
+ (common:check-db-dir-and-exit-if-insufficient)
+
+ ;; override the number of reruns from the configs
+ ;; this needs to be done at the place where is first runs:run-tests called
+ ;(if (and config-reruns
+ ; (> run-count config-reruns))
+ ;(set! run-count config-reruns))
+
+ ;; (if (tasks:need-server run-id)(tasks:start-and-wait-for-server tdbdat run-id 10))
+
+ (let ((sighand (lambda (signum)
+ ;; (signal-mask! signum) ;; to mask or not? seems to cause issues in exiting
+ (set! *time-to-exit* #t)
+ (print "Received signal " signum ", cleaning up before exit. Please wait...")
+ (let ((th1 (make-thread (lambda ()
+ ;; (let ((tdbdat (tasks:open-db)))
+ (rmt:tasks-set-state-given-param-key task-key "killed") ;; )
+ (print "Killed by signal " signum ". Exiting")
+ (thread-sleep! 3)
+ (exit))))
+ (th2 (make-thread (lambda ()
+ (thread-sleep! 5)
+ (debug:print 0 *default-log-port* "Done")
+ (exit 4)))))
+ (thread-start! th2)
+ (thread-start! th1)
+ (thread-join! th2)))))
+ (set-signal-handler! signal/int sighand)
+ (set-signal-handler! signal/term sighand))
+
+ ;; force the starting of a server -- removed BB 17ww28 - no longer needed.
+ ;;(debug:print 0 *default-log-port* "waiting on server...")
+ ;;(server:start-and-wait *toppath*)
+
+ (runs:set-megatest-env-vars run-id inkeys: keys inrunname: runname) ;; these may be needed by the launching process
+ (set! runconf (if (common:file-exists? runconfigf)
+ (setup-env-defaults runconfigf run-id *already-seen-runconfig-info* keyvals target)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: You do not have a run config file: " runconfigf)
+ #f)))
+
+ (if (not test-patts) ;; first time in - adjust testpatt
+ (set! test-patts (common:args-get-testpatt runconf)))
+ ;; if test-patts is #f at this point there is something wrong and we need to bail out
+ (if (not test-patts)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: there is no test pattern for this run. Exiting now.")
+ (exit 0)))
+
+ (if (args:get-arg "-tagexpr")
+ (begin
+ (set! allowed-tests (string-join (runs:get-tests-matching-tags (args:get-arg "-tagexpr")) ","))
+ (debug:print-info 0 *default-log-port* "filtering initial test list with tagexpr: " (args:get-arg "-tagexpr") " => " allowed-tests)
+ ));; tests will be ANDed with this list
+
+ ;; register this run in monitor.db
+ (rmt:tasks-add "run-tests" user target runname test-patts task-key) ;; params)
+ (rmt:tasks-set-state-given-param-key task-key "running")
+
+ #;(common:telemetry-log "run-tests"
+ payload:
+ `( (target . ,target)
+ (run-name . ,runname)
+ (test-patts . ,test-patts) ) )
+
+
+ ;; Now generate all the tests lists
+ (set! all-tests-registry (tests:get-all)) ;; hash of testname => path-to-test
+ (set! all-test-names (hash-table-keys all-tests-registry))
+ ;; filter first for allowed-tests (from -tagexpr) then for test-patts.
+ (set! test-names (tests:filter-test-names
+ (if allowed-tests
+ (tests:filter-test-names all-test-names allowed-tests)
+ all-test-names)
+ test-patts))
+
+ ;; I think seeding required-tests with all test-names makes sense but lack analysis to back that up.
+
+ ;; NEW STRATEGY HERE:
+ ;; 1. fill required tests with test-patts
+ ;; 2. scan testconfigs and if waitons, itemwait, itempatt calc prior test test-patt
+ ;; 3. repeat until all deps propagated
+
+ ;; any tests with direct mention in test-patts can be added to required
+ ;;(set! required-tests (lset-intersection equal? (string-split test-patts ",") all-test-names))
+ (set! required-tests (tests:filter-test-names all-test-names test-patts))
+ ;;
+ ;; (set! required-tests (lset-intersection equal? test-names all-test-names))
+
+ ;; look up all tests matching the comma separated list of globs in
+ ;; test-patts (using % as wildcard)
+
+ ;; (set! test-names (delete-duplicates (tests:get-valid-tests *toppath* test-patts)))
+ (debug:print-info 0 *default-log-port* "tests search path: " (string-intersperse (tests:get-tests-search-path *configdat*) " "))
+ (debug:print-info 0 *default-log-port* "all tests: " (string-intersperse (sort all-test-names string<) " "))
+ (debug:print-info 0 *default-log-port* "test names: " (string-intersperse (sort test-names string<) " "))
+ (debug:print-info 0 *default-log-port* "required tests: " (string-intersperse (sort required-tests string<) " "))
+
+ ;; on the first pass or call to run-tests set FAILS to NOT_STARTED if
+ ;; -keepgoing is specified
+ (if (eq? *passnum* 0)
+ (begin
+ ;; Is this still necessary? I think not. Unreachable tests are marked as such and
+ ;; should not cause problems here.
+ ;;
+ ;; have to delete test records where NOT_STARTED since they can cause -keepgoing to
+ ;; get stuck due to becoming inaccessible from a failed test. I.e. if test B depends
+ ;; on test A but test B reached the point on being registered as NOT_STARTED and test
+ ;; A failed for some reason then on re-run using -keepgoing the run can never complete.
+ ;;
+ ;; (rmt:general-call 'delete-tests-in-state run-id "NOT_STARTED")
+
+ ;; Now convert anything in allow-auto-rerun to NOT_STARTED
+ ;;
+ (for-each
+ (lambda (state-status)
+ (let* ((ss-lst (string-split-fields "/" state-status #:infix))
+ (state (if (> (length ss-lst) 0)(car ss-lst) #f))
+ (status (if (> (length ss-lst) 1)(cadr ss-lst) #f)))
+ (rmt:set-tests-state-status run-id test-names state status "NOT_STARTED" status)))
+ ;; list of state/status pairs separated by spaces
+ (string-split (or (configf:lookup *configdat* "setup" "allow-auto-rerun") "")))))
+
+ ;; Ensure all tests are registered in the test_meta table
+ (runs:update-all-test_meta #f)
+
+ ;; run the run prehook if there are no tests yet run for this run:
+ ;;
+ (runs:run-pre-hook run-id)
+ ;; mark all test launched flag as false in the meta table
+ (rmt:set-var (conc "lunch-complete-" run-id) "no")
+ (debug:print-info 1 *default-log-port* "Setting end-of-run to no")
+ (let* ((config-reruns (let ((x (configf:lookup *configdat* "setup" "reruns")))
+ (if x (string->number x) #f)))
+ (config-rerun-cnt (if config-reruns
+ config-reruns
+ 1)))
+ (if (eq? config-rerun-cnt run-count)
+ (rmt:set-var (conc "end-of-run-" run-id) "no")))
+
+ (rmt:set-run-state-status run-id "new" "n/a")
+ ;; now add non-directly referenced dependencies (i.e. waiton)
+ ;;======================================================================
+ ;; refactoring this block into tests:get-full-data
+ ;;
+ ;; What happended, this code is now duplicated in tests!?
+ ;;
+ ;;======================================================================
+
+ (if (not (null? test-names)) ;; BEGIN test-names loop
+ (let loop ((hed (car test-names)) ;; NOTE: This is the main loop that iterates over the test-names
+ (tal (cdr test-names))) ;; 'return-procs tells the config reader to prep running system but return a proc
+ (debug:print-info 4 *default-log-port* "\n\ntestpatt elaboration loop => hed="hed " tal="tal" test-patts="test-patts" test-names="test-names)
+ (change-directory *toppath*) ;; PLEASE OPTIMIZE ME!!! I think this should be a no-op but there are several places where change-directories could be happening.
+ (setenv "MT_TEST_NAME" hed) ;;
+ (let*-values (((waitons waitors config) (tests:get-waitons hed all-tests-registry))
+
+ ;; NOTE: Have the config - can extract [waitons] section
+
+ ((hed-mode)
+ (let ((m (configf:lookup config "requirements" "mode")))
+ (if m (map string->symbol (string-split m)) '(normal))))
+ ((hed-itemized-waiton) ;; are items in hed waiting on items of waiton?
+ (not (null? (lset-intersection eq? hed-mode '(itemmatch itemwait)))))
+ )
+ (debug:print-info 8 *default-log-port* "waitons: " waitons)
+ ;; check for hed in waitons => this would be circular, remove it and issue an
+ ;; error
+ (if (or (member hed waitons)
+ (member hed waitors))
+ (begin
+ (debug:print-error 0 *default-log-port* "test " hed " has listed itself as a waiton or waitor, please correct this!")
+ (set! waitons (filter (lambda (x)(not (equal? x hed))) waitons))
+ (set! waitors (filter (lambda (x)(not (equal? x hed))) waitors))))
+
+ ;; (items (items:get-items-from-config config)))
+ (if (not (hash-table-ref/default test-records hed #f)) ;; waiton-tconfig below will be #f until that test is visted here at least once
+ (hash-table-set! test-records ;; BB: we are doing a manual make-tests:testqueue
+ hed (vector hed ;; 0 ;; testname
+ config ;; 1
+ waitons ;; 2
+ (configf:lookup config "requirements" "priority") ;; priority 3
+ (tests:get-items config) ;; 4 ;; expand the [items] and or [itemstable] into explict items
+ #f ;; itemsdat 5
+ #f ;; spare - used for item-path
+ waitors ;;
+ )))
+ ;; update waitors-upon here
+ (for-each
+ (lambda (waiton)
+ (let* ((current-waitors-upon (hash-table-ref/default waitors-upon waiton '())))
+ (debug:print-info 8 *default-log-port* " current-waiters-upon["waiton"] is "current-waitors-upon )
+ (when (not (member hed current-waitors-upon))
+ (debug:print-info 8 *default-log-port* " current-waiters-upon["waiton"] << "hed )
+ (hash-table-set! waitors-upon waiton (cons hed current-waitors-upon)))))
+ (if (list? waitons) waitons '()))
+ (debug:print-info 8 *default-log-port* " process waitons&waitors of "hed": "(delete-duplicates (append waitons waitors)))
+ (for-each
+ (lambda (waiton)
+ (if (and waiton (not (member waiton test-names)))
+ (let* ((waitors-in-testpatt (runs:testpatts-mention-waitors-upon? test-patts (hash-table-ref/default waitors-upon waiton '())))
+ (waiton-record (hash-table-ref/default test-records waiton #f))
+ (waiton-tconfig (if waiton-record (vector-ref waiton-record 1) #f))
+ (waiton-itemized (and waiton-tconfig
+ (or (hash-table-ref/default waiton-tconfig "items" #f)
+ (hash-table-ref/default waiton-tconfig "itemstable" #f))))
+ (itemmaps (tests:get-itemmaps config)) ;; (configf:lookup config "requirements" "itemmap"))
+ (new-test-patts (tests:extend-test-patts test-patts hed waiton itemmaps hed-itemized-waiton)))
+ (debug:print-info 0 *default-log-port* "Test " waiton " has " (if waiton-record "a" "no") " waiton-record and" (if waiton-itemized " " " no ") "items")
+ ;; need to account for test-patt here, if I am test "a", selected with a test-patt of "hed/b%"
+ ;; and we are waiting on "waiton" we need to add "waiton/,waiton/b%" to test-patt
+ ;; is this satisfied by merely appending "/" to the waiton name added to the list?
+ ;;
+ ;; This approach causes all of the items in an upstream test to be run
+ ;; if we have this waiton already processed once we can analzye it for extending
+ ;; tests to be run, since we can't properly process waitons unless they have been
+ ;; initially added we add them again to be processed on second round AND add the hed
+ ;; back in to also be processed on second round
+ (if waiton-tconfig ;; BB: waiter should be in test-patts as well as the waiton have a tconfig.
+ (if waiton-itemized
+ (if waitors-in-testpatt
+ (begin
+ (debug:print-info 0 *default-log-port* "New test patts: " new-test-patts ", prev test patts: " test-patts)
+ (set! test-names (cons waiton test-names)) ;; need to process this one, only add once the waiton tconfig read
+ (set! required-tests (cons (conc waiton "/") required-tests))
+ (set! test-patts new-test-patts))
+ (begin
+ (debug:print-info 0 *default-log-port* "Waitor(s) not yet on testpatt for " waiton ", setting up to re-process it")
+ (set! tal (append (cons waiton tal)(list hed)))))
+ (begin
+ (debug:print-info 0 *default-log-port* "Adding non-itemized test " waiton " to required-tests")
+ (set! required-tests (cons waiton required-tests))
+ (set! test-patts new-test-patts)))
+ (begin
+ (debug:print-info 0 *default-log-port* "No testconfig info yet for " waiton ", setting up to re-process it")
+ (set! tal (append (cons waiton tal)(list hed))))) ;; (cons (conc waiton "/") required-tests))
+ ;; NOPE: didn't work. required needs to be plain test names. Try tacking on to test-patts
+ ;; - doesn't work
+ ;; (set! test-patts (conc test-patts "," waiton "/"))
+ ;; (set! test-names (cons waiton test-names))))) ;; was an append, now a cons
+ )))
+ (delete-duplicates (append waitons waitors)))
+ (let ((remtests (delete-duplicates (append waitons tal))))
+ (debug:print-info 8 *default-log-port* " remtests are "remtests)
+ (if (not (null? remtests))
+ (begin
+ ;; (debug:print-info 0 *default-log-port* "Preprocessing continues for " (string-intersperse remtests ", "))
+ (loop (car remtests)(cdr remtests)))))))) ;; END test-names loop
+
+ (if (not (null? required-tests))
+ (debug:print-info 1 *default-log-port* "Adding \"" (string-intersperse required-tests " ") "\" to the run queue"))
+ ;; NOTE: these are all parent tests, items are not expanded yet.
+ (debug:print-info 4 *default-log-port* "test-records=" (hash-table->alist test-records))
+ (let ((reglen (configf:lookup *configdat* "setup" "runqueue")))
+ (if (> (length (hash-table-keys test-records)) 0)
+ (let* ((keep-going #t)
+ (run-queue-retries 5)
+ #;(th1 (make-thread (lambda ()
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain)
+ (print " message: " ((condition-property-accessor 'exn 'message) exn)))
+ (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests
+ (any->number reglen) all-tests-registry)))
+ "runs:run-tests-queue"))
+ (th2 (make-thread (lambda () ;; BBQ: why are we visiting ALL runs here?
+ ;; (rmt:find-and-mark-incomplete-all-runs))))) CAN'T INTERRUPT IT ...
+ (let ((run-ids (rmt:get-all-run-ids)))
+ (for-each (lambda (run-id)
+ (if keep-going
+ (handle-exceptions
+ exn
+ (debug:print 0 *default-log-port* "error in calling find-and-mark-incomplete for run-id " run-id ", exn=" exn)
+ (rmt:find-and-mark-incomplete run-id #f)
+ (launch:end-of-run-check run-id)
+
+ ))) ;; ovr-deadtime))) ;; could be root of https://hsdes.intel.com/appstore/article/#/220546828/main -- Title: Megatest jobs show DEAD even though they are still running (1.64/27)
+ run-ids)))
+ "runs: mark-incompletes")))
+ ;; (thread-start! th1)
+ (thread-start! th2)
+ ;; (thread-join! th1)
+ ;; just do the main stuff in the main thread
+ (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests
+ (any->number reglen) all-tests-registry)
+ (set! keep-going #f)
+ (thread-join! th2)
+ ;; if run-count > 0 call, set -preclean and -rerun STUCK/DEAD
+ (if (> run-count 0) ;; handle reruns
+ (begin
+ (if (not (hash-table-ref/default flags "-preclean" #f))
+ (hash-table-set! flags "-preclean" #t))
+ (if (not (hash-table-ref/default flags "-rerun" #f))
+ (hash-table-set! flags "-rerun" "ABORT,STUCK/DEAD,n/a,ZERO_ITEMS"))
+ ;; recursive call to self
+ (runs:run-tests target runname test-patts user flags run-count: (- run-count 1)))
+ (launch:end-of-run-check run-id)))
+ (debug:print-info 0 *default-log-port* "No tests to run")))
+ (debug:print-info 4 *default-log-port* "All done by here")
+ ;; TODO: try putting post hook call here
+
+ ; (debug:print-info 2 *default-log-port* " run-count " run-count)
+ ; (runs:run-post-hook run-id))
+ ; (debug:print-info 2 *default-log-port* "Not calling post hook runcount = " run-count ))
+ (rmt:tasks-set-state-given-param-key task-key "done")
+
+ ;; (sqlite3:finalize! tasks-db)
+ ))
+
+
+;; loop logic. These are used in runs:run-tests-queue to make it a bit more readable.
+;;
+;; If reg not full and have items in tal then loop with (car tal)(cdr tal) reg reruns
+;; If reg is full (i.e. length >= n
+;; loop with (car reg) tal (cdr reg) reruns
+;; If tal is empty
+;; but have items in reg; loop with (car reg)(cdr reg) '() reruns
+;; If reg is empty => all done
+
+(define (runs:queue-next-hed tal reg n regfull)
+ (if regfull
+ (if (null? reg) #f (car reg))
+ (if (null? tal) ;; tal is used up, pop from reg
+ (if (null? reg) #f (car reg))
+ (car tal))))
+
+(define (runs:queue-next-tal tal reg n regfull)
+ (if regfull
+ tal
+ (if (null? tal) ;; must transfer from reg
+ (if (null? reg) '() (cdr reg))
+ (cdr tal))))
+
+(define (runs:queue-next-reg tal reg n regfull)
+ (if regfull
+ (if (null? reg) '() (cdr reg)) ;; EXPLORE: reorder (cdr reg) such that looping is more efficient
+ (if (null? tal) ;; if tal is null and reg not full then '() as reg contents moved to tal
+ '()
+ reg)))
+
+;; this is the list of parameters to the named loop "loop" near the top of runs:run-tests-queue, look around line 1216
+;;
+(define (runs:loop-values tal reg reglen regfull reruns)
+ (list (runs:queue-next-hed tal reg reglen regfull) ;; hed
+ (runs:queue-next-tal tal reg reglen regfull) ;; tal
+ (runs:queue-next-reg tal reg reglen regfull) ;; reg
+ reruns)) ;; reruns
+
+;; objective - iterate thru tests
+;; => want to prioritize tests we haven't seen before
+;; => sometimes need to squeeze things in (added to reg)
+;; => review of a previously seen test is higher priority of never visited test
+;; reg - list of previously visited tests
+;; tal - list of never visited tests
+;; prefer next hed to be from reg than tal.
+
+(define runs:nothing-left-in-queue-count 0)
+
+;;======================================================================
+;; runs:expand-items is called by runs:run-tests-queue
+;;======================================================================
+;;
+;; return value of runs:expand-items is passed back to runs-tests-queue and is fed to named loop with this signature:
+;; (let loop ((hed (car sorted-test-names))
+;; (tal (cdr sorted-test-names))
+;; (reg '()) ;; registered, put these at the head of tal
+;; (reruns '()))
+(define (runs:expand-items hed tal reg reruns regfull newtal jobgroup max-concurrent-jobs run-id waitons item-path testmode test-record can-run-more items runname tconfig reglen test-registry test-records itemmaps)
+ (let* ((loop-list (list hed tal reg reruns))
+ (prereqs-not-met (let ((res (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps)))
+ (if (list? res)
+ res
+ (begin
+ (debug:print 0 *default-log-port*
+ "ERROR: rmt:get-prereqs-not-met returned non-list!\n"
+ " res=" res " run-id=" run-id " waitons=" waitons " hed=" hed " item-path=" item-path " testmode=" testmode " itemmaps=" itemmaps)
+ '()))))
+ (have-itemized (not (null? (lset-intersection eq? testmode '(itemmatch itemwait)))))
+ ;; (prereqs-not-met (mt:lazy-get-prereqs-not-met run-id waitons item-path mode: testmode itemmap: itemmap))
+ (fails (runs:calc-fails prereqs-not-met))
+ (prereq-fails (runs:calc-prereq-fail prereqs-not-met))
+ (non-completed (runs:calc-not-completed prereqs-not-met))
+ (runnables (runs:calc-runnable prereqs-not-met))
+ (unexpanded-prereqs
+ (filter (lambda (testname)
+ (let* ((test-rec (hash-table-ref test-records testname))
+ (items (tests:testqueue-get-items test-rec)))
+ ;;(BB> "HEY " testname "=>"items)
+ (or (procedure? items)(eq? items 'have-procedure))))
+ waitons))
+
+
+ )
+ (debug:print-info 4 *default-log-port* "START OF INNER COND #2 "
+ "\n can-run-more: " can-run-more
+ "\n testname: " hed
+ "\n prereqs-not-met: " (runs:pretty-string prereqs-not-met)
+ "\n non-completed: " (runs:pretty-string non-completed)
+ "\n prereq-fails: " (runs:pretty-string prereq-fails)
+ "\n fails: " (runs:pretty-string fails)
+ "\n testmode: " testmode
+ "\n (member 'toplevel testmode): " (member 'toplevel testmode)
+ "\n (null? non-completed): " (null? non-completed)
+ "\n reruns: " reruns
+ "\n items: " items
+ "\n can-run-more: " can-run-more)
+
+ (cond
+ ;; all prereqs met, fire off the test
+ ;; or, if it is a 'toplevel test and all prereqs not met are COMPLETED then launch
+
+ ((and (not (member 'toplevel testmode))
+ (member (hash-table-ref/default test-registry (db:test-make-full-name hed item-path) 'n/a)
+ '(DONOTRUN removed CANNOTRUN))) ;; *common:cant-run-states-sym*) ;; '(COMPLETED KILLED WAIVED UNKNOWN INCOMPLETE)) ;; try to catch repeat processing of COMPLETED tests here
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-1")
+ (debug:print-info 1 *default-log-port* "Test " hed " set to \"" (hash-table-ref test-registry (db:test-make-full-name hed item-path)) "\". Removing it from the queue")
+ (if (or (not (null? tal))
+ (not (null? reg)))
+ (runs:loop-values tal reg reglen regfull reruns)
+ (begin
+ (debug:print-info 0 *default-log-port* "Nothing left in the queue!")
+ ;; If get here twice then we know we've tried to expand all items
+ ;; since there must be a logic issue with the handling of loops in the
+ ;; items expand phase we will brute force an exit here.
+ (if (> runs:nothing-left-in-queue-count 2)
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: this condition is triggered when there were no items to expand and nothing to run. Please check your run for completeness")
+ (exit 0))
+ (set! runs:nothing-left-in-queue-count (+ runs:nothing-left-in-queue-count 1)))
+ #f)))
+
+ ;; desired result of below cond branch:
+ ;; we want to expand items in our test of interest (hed) in the following cases:
+ ;; case 1 - mode is itemmatch or itemwait:
+ ;; - all prereq tests have been expanded
+ ;; - at least one prereq's items have completed
+ ;; case 2 - mode is toplevel
+ ;; - prereqs are completed.
+ ;; - or no prereqs can complete
+ ;; case 3 - mode not specified
+ ;; - prereqs are completed and passed (we could consider removing "and passed" -- it would change behavior from current)
+ ((or (null? prereqs-not-met)
+ (and (member 'toplevel testmode)
+ (null? non-completed)))
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-2")
+ (debug:print-info 4 *default-log-port* "runs:expand-items: (or (null? prereqs-not-met) (and (member 'toplevel testmode)(null? non-completed)))")
+ (let ((test-name (tests:testqueue-get-testname test-record)))
+ (setenv "MT_TEST_NAME" test-name) ;;
+ (setenv "MT_RUNNAME" runname)
+ (runs:set-megatest-env-vars run-id inrunname: runname) ;; these may be needed by the launching process
+ (let ((items-list (items:get-items-from-config tconfig)))
+ (if (list? items-list)
+ (begin
+ (if (null? items-list)
+ (let ((test-id (rmt:get-test-id run-id test-name ""))
+ (num-items (rmt:test-toplevel-num-items run-id test-name)))
+ (if (and test-id
+ (not (> num-items 0)))
+ (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "ZERO_ITEMS" "Failed to run due to failed prerequisites"))))
+ (tests:testqueue-set-items! test-record items-list)
+ (list hed tal reg reruns))
+ (begin
+ (debug:print-error 0 *default-log-port* "The proc from reading the items table did not yield a list - please report this")
+ (exit 1))))))
+
+ ((and (null? fails)
+ (null? prereq-fails)
+ (not (null? non-completed)))
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-3")
+ (let* ((allinqueue (map (lambda (x)(if (string? x) x (db:test-get-testname x)))
+ (append newtal reruns)))
+ ;; prereqstrs is a list of test names as strings that are prereqs for hed
+ (prereqstrs (delete-duplicates (map (lambda (x)(if (string? x) x (db:test-get-testname x)))
+ prereqs-not-met)))
+ ;; a prereq that is not found in allinqueue will be put in the notinqueue list
+ ;;
+ ;; (notinqueue (filter (lambda (x)
+ ;; (not (member x allinqueue)))
+ ;; prereqstrs))
+ (give-up #f))
+
+ ;; We can get here when a prereq has not been run due to *it* having a prereq that failed.
+ ;; We need to use this to dequeue this item as CANNOTRUN
+ ;;
+ (if (member 'toplevel testmode) ;; '(toplevel)) ;; NOTE: this probably should be (member 'toplevel testmode)
+ (for-each (lambda (prereq)
+ (if (eq? (hash-table-ref/default test-registry prereq 'justfine) 'CANNOTRUN)
+ (set! give-up #t)))
+ prereqstrs))
+
+ (if (and give-up
+ (not (and (null? tal)(null? reg))))
+ (let ((trimmed-tal (mt:discard-blocked-tests run-id hed tal test-records))
+ (trimmed-reg (mt:discard-blocked-tests run-id hed reg test-records)))
+ (debug:print 1 *default-log-port* "WARNING: test " hed " has discarded prerequisites, removing it from the queue")
+
+ (let ((test-id (rmt:get-test-id run-id hed "")))
+ (if test-id (mt:test-set-state-status-by-id run-id test-id "COMPLETED" "PREQ_DISCARDED" "Failed to run due to discarded prerequisites")))
+
+ (if (and (null? trimmed-tal)
+ (null? trimmed-reg))
+ #f
+ (runs:loop-values trimmed-tal trimmed-reg reglen regfull reruns)
+ ))
+ (list (car newtal)(append (cdr newtal) reg) '() reruns))))
+
+ ((and (null? fails) ;; have not-started tests, but unable to run them. everything looks completed with no prospect of unsticking something that is stuck. we should mark hed as moribund and exit or continue if there are more tests to consider
+ (null? prereq-fails)
+ (null? non-completed))
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-4")
+ (if (runs:can-keep-running? hed 20)
+ (begin
+ (runs:inc-cant-run-tests hed)
+ (debug:print-info 0 *default-log-port* "no fails in prerequisites for " hed " but also none running, keeping " hed " for now. Try count: " (hash-table-ref/default *seen-cant-run-tests* hed 0) ", going to wait 60 sec.") ;;
+ ;; getting here likely means the system is way overloaded, kill a full minute before continuing
+ ;; (thread-sleep! 60) ;; TODO: gate by normalized server load > 1.0 (maxload config thing) CHECKTHIS!!!
+ ;; No runsdat, can't do this yet
+ ;; (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+ ;;
+ (thread-sleep! 5) ;; TODO: gate by normalized server load > 1.0 (maxload config thing)
+ ;; num-retries code was here
+ ;; we use this opportunity to move contents of reg to tal
+ (list (car newtal)(append (cdr newtal) reg) '() reruns)) ;; an issue with prereqs not yet met?
+ (begin
+ (debug:print-info 1 *default-log-port* "no fails in prerequisites for " hed " but nothing seen running in a while, dropping test " hed " from the run queue")
+ (let ((test-id (rmt:get-test-id run-id hed "")))
+ (if test-id (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "TIMED_OUT" "Nothing seen running in a while.")))
+ (runs:loop-values tal reg reglen regfull reruns)
+ )))
+
+ ((and
+ (or (not (null? fails))
+ (not (null? prereq-fails)))
+ (member 'normal testmode))
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-5")
+ (debug:print-info 1 *default-log-port* "test " hed " (mode=" testmode ") has failed prerequisite(s); "
+ (string-intersperse (map (lambda (t)(conc (db:test-get-testname t) ":" (db:test-get-state t)"/"(db:test-get-status t))) fails) ", ")
+ ", removing it from to-do list")
+ (let ((test-id (rmt:get-test-id run-id hed "")))
+ (if test-id
+ (if (not (null? prereq-fails))
+ (mt:test-set-state-status-by-id-unless-completed run-id test-id "COMPLETED" "PREQ_DISCARDED" "Failed to run due to prior failed prerequisites")
+ (mt:test-set-state-status-by-id-unless-completed run-id test-id "COMPLETED" "PREQ_FAIL" "Failed to run due to failed prerequisites"))))
+ ;; (debug:print 4 *default-log-port*"BB> set PREQ_FAIL on "hed)
+ ;; (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "PREQ_FAIL" "Failed to run due to failed prerequisites")))) ;; BB: this works, btu equivalent for itemwait mode does not work.
+ (if (or (not (null? reg))(not (null? tal)))
+ (begin
+ (hash-table-set! test-registry hed 'CANNOTRUN)
+ (runs:loop-values tal reg reglen regfull (cons hed reruns))
+ )
+ #f)) ;; #f flags do not loop
+
+ ((and (not (null? fails))(member 'toplevel testmode))
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-6")
+ (if (or (not (null? reg))(not (null? tal)))
+ (list (car newtal)(append (cdr newtal) reg) '() reruns)
+ #f))
+ ((null? runnables)
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-7")
+ #f) ;; if we get here and non-completed is null then it is all over.
+ (else
+ (debug:print-info 4 *default-log-port* "cond branch - " "ei-8")
+ (debug:print 0 *default-log-port* "WARNING: FAILS or incomplete tests maybe preventing completion of this run. Watch for issues with test " hed ", continuing for now")
+ (list (car newtal)(cdr newtal) reg reruns)))))
+
+(define (runs:mixed-list-testname-and-testrec->list-of-strings inlst)
+ (if (null? inlst)
+ '()
+ (map (lambda (t)
+ (cond
+ ((vector? t)
+ (let ((test-name (db:test-get-testname t))
+ (item-path (db:test-get-item-path t))
+ (test-state (db:test-get-state t))
+ (test-status (db:test-get-status t)))
+ (conc test-name (if (equal? item-path "") "" "/") item-path ":" test-state "/" test-status)))
+ ((string? t)
+ t)
+ (else
+ (conc t))))
+ inlst)))
+
+
+;; hed tal reg reruns reglen regfull test-record runname test-name item-path jobgroup max-concurrent-jobs run-id waitons item-path testmode test-patts required-tests test-registry registry-mutex flags keyvals run-info newtal all-tests-registry itemmaps)
+(define (runs:process-expanded-tests runsdat testdat)
+ ;; unroll the contents of runsdat and testdat (due to ongoing refactoring).
+ (debug:print 2 *default-log-port* "runs:process-expanded-tests; testdat:" )
+ (debug:print 2 *default-log-port* (with-output-to-string
+ (lambda () (pp (runs:testdat->alist testdat) ))))
+ (let* ((hed (runs:testdat-hed testdat))
+ (tal (runs:testdat-tal testdat))
+ (reg (runs:testdat-reg testdat))
+ (reruns (runs:testdat-reruns testdat))
+ (test-name (runs:testdat-test-name testdat))
+ (item-path (runs:testdat-item-path testdat))
+ (jobgroup (runs:testdat-jobgroup testdat))
+ (waitons (runs:testdat-waitons testdat))
+ (item-path (runs:testdat-item-path testdat))
+ (testmode (runs:testdat-testmode testdat))
+ (newtal (runs:testdat-newtal testdat))
+ (itemmaps (runs:testdat-itemmaps testdat))
+ (test-record (runs:testdat-test-record testdat))
+ (prereqs-not-met (runs:testdat-prereqs-not-met testdat))
+
+ (reglen (runs:dat-reglen runsdat))
+ (regfull (runs:dat-regfull runsdat))
+ (runname (runs:dat-runname runsdat))
+ (max-concurrent-jobs (runs:dat-max-concurrent-jobs runsdat))
+ (run-id (runs:dat-run-id runsdat))
+ (test-patts (runs:dat-test-patts runsdat))
+ (required-tests (runs:dat-required-tests runsdat))
+ (test-registry (runs:dat-test-registry runsdat))
+ (registry-mutex (runs:dat-registry-mutex runsdat))
+ (flags (runs:dat-flags runsdat))
+ (keyvals (runs:dat-keyvals runsdat))
+ (run-info (runs:dat-run-info runsdat))
+ (all-tests-registry (runs:dat-all-tests-registry runsdat))
+ (run-limits-info (runs:dat-can-run-more-tests runsdat))
+ ;; (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs)) ;; look at the test jobgroup and tot jobs running
+ (have-resources (car run-limits-info))
+ (num-running (list-ref run-limits-info 1))
+ (num-running-in-jobgroup(list-ref run-limits-info 2))
+ (max-concurrent-jobs (list-ref run-limits-info 3))
+ (job-group-limit (list-ref run-limits-info 4))
+ ;; (prereqs-not-met (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps))
+ ;; (prereqs-not-met (mt:lazy-get-prereqs-not-met run-id waitons item-path mode: testmode itemmap: itemmap))
+ (fails (if (list? prereqs-not-met) ;; TODO: rename fails to failed-prereqs
+ (runs:calc-fails prereqs-not-met)
+ (begin
+ (debug:print-error 0 *default-log-port* "prereqs-not-met is not a list! " prereqs-not-met)
+ '())))
+ (non-completed (filter (lambda (x) ;; remove hed from not completed list, duh, of course it is not completed!
+ (not (equal? x hed)))
+ (runs:calc-not-completed prereqs-not-met)))
+ (loop-list (list hed tal reg reruns))
+ ;; configure the load runner
+ (maxload (string->number (or (configf:lookup *configdat* "jobtools" "maxload") "3.0"))) ;; use a non-number string to disable
+ (maxhomehostload (string->number (or (configf:lookup *configdat* "jobtools" "maxhomehostload") "2.0"))) ;; use a non-number string to disable
+ (waitdelay (string->number (or (configf:lookup *configdat* "jobtools" "waitdelay") "60"))))
+ (debug:print-info 4 *default-log-port* "have-resources: " have-resources " prereqs-not-met: ("
+ (string-intersperse
+ (map (lambda (t)
+ (if (vector? t)
+ (conc (db:test-get-state t) "/" (db:test-get-status t))
+ (conc " WARNING: t is not a vector=" t )))
+ prereqs-not-met)
+ ", ") ") fails: " fails
+ "\nregistered? " (hash-table-ref/default test-registry (db:test-make-full-name test-name item-path) #f))
+
+ ;; well, first lets see if cpu load throttling is enabled. If so wait around until the
+ ;; average cpu load is under the threshold before continuing
+ ;;
+ (if (runs:dat-load-mgmt-function runsdat)
+ ((runs:dat-load-mgmt-function runsdat))
+ (runs:dat-load-mgmt-function-set!
+ runsdat
+ (lambda ()
+ ;; jobtools maxload is useful for where the full Megatest run is done on one machine
+ (if (and (not (common:on-homehost?))
+ maxload) ;; only gate if maxload is specified, NOTE: maxload is normalized, i.e. load=1 means all cpus fully utilized
+ (common:wait-for-normalized-load maxload "Waiting for load to drop before starting more tests" #f))
+
+ ;; jobtools maxhomehostload is intended to prevent overloading on the homehost which can cause database corruption issues
+ (if maxhomehostload
+ (common:wait-for-homehost-load maxhomehostload
+ (conc "Waiting for homehost load to drop below normalized value of " maxhomehostload))))))
+
+
+
+ (if (and (not (null? prereqs-not-met))
+ (runs:lownoise (conc "waiting on tests " prereqs-not-met hed) 60))
+ (debug:print-info 2 *default-log-port* "waiting on tests; " (string-intersperse (runs:mixed-list-testname-and-testrec->list-of-strings prereqs-not-met) ", ")))
+
+ ;; Don't know at this time if the test have been launched at some time in the past
+ ;; i.e. is this a re-launch?
+ (debug:print-info 4 *default-log-port* "run-limits-info = " run-limits-info)
+
+ (cond ; cond 894- 1067
+
+ ;; Check item path against item-patts,
+ ;;
+ ((not (tests:match test-patts (tests:testqueue-get-testname test-record) item-path required: required-tests)) ;; This test/itempath is not to be run
+ ;; else the run is stuck, temporarily or permanently
+ ;; but should check if it is due to lack of resources vs. prerequisites
+ (debug:print-info 1 *default-log-port* "Skipping " (tests:testqueue-get-testname test-record) " " item-path " as it doesn't match " test-patts)
+ (if (or (not (null? tal))(not (null? reg)))
+ (runs:loop-values tal reg reglen regfull reruns)
+ #f))
+
+ ;; Register tests
+ ;;
+ ((not (hash-table-ref/default test-registry (db:test-make-full-name test-name item-path) #f))
+ (debug:print-info 4 *default-log-port* "Pre-registering test " test-name "/" item-path " to create placeholder" )
+ ;; always do firm registration now in v1.60 and greater ;; (eq? *transport-type* 'fs) ;; no point in parallel registration if use fs
+ (let register-loop ((numtries 15))
+ (rmt:register-test run-id test-name item-path)
+ (if (rmt:get-test-id run-id test-name item-path)
+ (hash-table-set! test-registry (db:test-make-full-name test-name item-path) 'done)
+ (if (> numtries 0)
+ (begin
+ (thread-sleep! 0.5)
+ (register-loop (- numtries 1)))
+ (debug:print-error 0 *default-log-port* "failed to register test " (db:test-make-full-name test-name item-path)))))
+ (if (not (eq? (hash-table-ref/default test-registry (db:test-make-full-name test-name "") #f) 'done))
+ (begin
+ (rmt:register-test run-id test-name "")
+ (if (rmt:get-test-id run-id test-name "")
+ (hash-table-set! test-registry (db:test-make-full-name test-name "") 'done))))
+ (runs:shrink-can-run-more-tests-count runsdat) ;; DELAY TWEAKER (still needed?)
+ (if (and (null? tal)(null? reg))
+ (list hed tal (append reg (list hed)) reruns)
+ (list (runs:queue-next-hed tal reg reglen regfull) ;; cannot replace with a call to runs:loop-values as the logic is different for reg
+ (runs:queue-next-tal tal reg reglen regfull)
+ ;; NB// Here we are building reg as we register tests
+ ;; if regfull we must pop the front item off reg
+ (if regfull
+ (append (cdr reg) (list hed))
+ (append reg (list hed)))
+ reruns)))
+
+ ;; At this point hed test registration must be completed.
+ ;;
+ ((eq? (hash-table-ref/default test-registry (db:test-make-full-name test-name item-path) #f)
+ 'start)
+ (debug:print-info 0 *default-log-port* "Waiting on test registration(s): "
+ (string-intersperse
+ (filter (lambda (x)
+ (eq? (hash-table-ref/default test-registry x #f) 'start))
+ (hash-table-keys test-registry))
+ ", "))
+ (thread-sleep! 0.051)
+ (list hed tal reg reruns))
+
+ ;; If no resources are available just kill time and loop again
+ ;;
+ ((not have-resources) ;; simply try again after waiting a second
+ (if (runs:lownoise "no resources" 60)
+ (debug:print-info 1 *default-log-port* "no resources to run new tests, waiting ..."))
+ ;; Have gone back and forth on this but db starvation is an issue.
+ ;; wait one second before looking again to run jobs.
+ (thread-sleep! 1) ;; changed back to 1 from 0.25
+ ;; could have done hed tal here but doing car/cdr of newtal to rotate tests
+ (list (car newtal)(cdr newtal) reg reruns))
+
+ ;; This is the final stage, everything is in place so launch the test
+ ;;
+ ((and have-resources
+ (or (null? prereqs-not-met)
+ (and (member 'toplevel testmode) ;; 'toplevel)
+ (null? non-completed)
+ (not (member 'exclusive testmode)))))
+ ;; (hash-table-delete! *max-tries-hash* (db:test-make-full-name test-name item-path))
+ ;; we are going to reset all the counters for test retries by setting a new hash table
+ ;; this means they will increment only when nothing can be run
+ (set! *max-tries-hash* (make-hash-table))
+
+ (run:test run-id run-info keyvals runname test-record flags #f test-registry all-tests-registry runsdat testdat)
+ (runs:incremental-print-results run-id)
+ (hash-table-set! test-registry (db:test-make-full-name test-name item-path) 'running)
+ (runs:shrink-can-run-more-tests-count runsdat) ;; DELAY TWEAKER (still needed?)
+ ;; (thread-sleep! *global-delta*)
+ (if (or (not (null? tal))(not (null? reg)))
+ (runs:loop-values tal reg reglen regfull reruns) ;; hed should be dropped at this time
+ #f))
+
+ ;; must be we have unmet prerequisites
+ ;;
+ (else
+ (debug:print 4 *default-log-port* "FAILS: " fails)
+ ;; If one or more of the prereqs-not-met are FAIL then we can issue
+ ;; a message and drop hed from the items to be processed.
+ ;; (runs:mixed-list-testname-and-testrec->list-of-strings prereqs-not-met)
+ (if (and (not (null? prereqs-not-met))
+ (runs:lownoise (conc "waiting on tests " prereqs-not-met hed) 60))
+ (debug:print-info 1 *default-log-port* "waiting on tests; " (string-intersperse
+ (runs:mixed-list-testname-and-testrec->list-of-strings
+ prereqs-not-met) ", ")))
+ (if (or (null? fails)
+ (member 'toplevel testmode))
+ (begin
+ ;; couldn't run, take a breather
+ (if (runs:lownoise "Waiting for more work to do..." 60)
+ (debug:print-info 0 *default-log-port* "Waiting for more work to do..."))
+
+ ;; (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+ (thread-sleep! 5)
+ (list (car newtal)(cdr newtal) reg reruns))
+ ;; the waiton is FAIL so no point in trying to run hed ever again
+ (begin
+ (let ((my-test-id (rmt:get-test-id run-id test-name item-path)))
+ (mt:test-set-state-status-by-id-unless-completed run-id my-test-id "COMPLETED" "PREQ_FAIL" "Failed to run due to failed prerequisites2"))
+ (if (or (not (null? reg))(not (null? tal)))
+ (if (vector? hed)
+ (begin
+ (debug:print 1 *default-log-port* "WARNING: Dropping test " test-name "/" item-path
+ " from the launch list as it has prerequistes that are FAIL")
+ (let ((test-id (rmt:get-test-id run-id hed "")))
+ (if test-id (mt:test-set-state-status-by-id-unless-completed run-id test-id "COMPLETED" "PREQ_FAIL" "Failed to run due to failed prerequisites")))
+ (runs:shrink-can-run-more-tests-count runsdat) ;; DELAY TWEAKER (still needed?)
+ ;; (thread-sleep! *global-delta*)
+ ;; This next is for the items
+
+ (if (not (null? fails))
+ ;;(mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "PREQ_FAIL" #f)
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path "NOT_STARTED" "PREQ_FAIL" #f)
+ ;;(mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "BLOCKED" #f)
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path "NOT_STARTED" "BLOCKED" #f) )
+ (hash-table-set! test-registry (db:test-make-full-name test-name item-path) 'removed)
+ (runs:loop-values tal reg reglen regfull reruns))
+ (let ((nth-try (hash-table-ref/default test-registry hed 0))) ;; hed not a vector...
+ (debug:print 2 *default-log-port* "nth-try("hed")="nth-try)
+ (cond
+ ((member "RUNNING" (map db:test-get-state prereqs-not-met))
+ (if (runs:lownoise (conc "possible RUNNING prerequistes " hed) 60)
+ (debug:print 0 *default-log-port* "WARNING: test " hed " has possible RUNNING prerequisites, don't give up on it yet."))
+ (thread-sleep! 0.1)
+ (runs:loop-values tal reg reglen regfull reruns))
+ ((or (not nth-try) ;; BB: condition on subsequent tries, condition below fires on first try
+ (and (number? nth-try)
+ (< nth-try 2)))
+ (hash-table-set! test-registry hed (if (number? nth-try)
+ (+ nth-try 1)
+ 0))
+ (if (runs:lownoise (conc "not removing test " hed) 60)
+ (debug:print 1 *default-log-port* "WARNING: not removing test " hed " from queue although it may not be runnable due to FAILED prerequisites"))
+ ;; may not have processed correctly. Could be a race condition in your test implementation? Dropping test " hed) ;; " as it has prerequistes that are FAIL. (NOTE: hed is not a vector)")
+ (runs:shrink-can-run-more-tests-count runsdat) ;; DELAY TWEAKER (still needed?)
+ (runs:loop-values newtal reg reglen regfull reruns))
+ ((symbol? nth-try) ;; BB: 'done matches here in one case where prereq itemwait failed. This is first "try"
+ (if (eq? nth-try 'removed) ;; removed is removed - drop it NOW
+ (if (null? tal)
+ #f ;; yes, really
+ (list (car tal)(cdr tal) reg reruns))
+ (begin
+ (if (runs:lownoise (conc "FAILED prerequisites or other issue" hed) 60)
+ (debug:print 0 *default-log-port* "WARNING: test " hed " has FAILED prerequisites or other issue. Internal state >" nth-try "< will be overridden and we'll retry."))
+ ;; was: (mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "KEEP_TRYING" #f)
+ (mt:test-set-state-status-by-testname-unless-completed run-id test-name item-path "COMPLETED" "PREQ_FAIL" #f)
+ (hash-table-set! test-registry hed 'removed) ;; was 0
+ (if (not (and (null? reg) (null? tal)))
+ (runs:loop-values tal reg reglen regfull reruns)
+ #f))))
+ (else
+ (if (runs:lownoise (conc "FAILED prerequitests and we tried" hed) 60)
+ (debug:print 0 *default-log-port* "WARNING: test " hed " has FAILED prerequitests and we've tried at least 10 times to run it. Giving up now."))
+ ;; (debug:print 0 *default-log-port* " prereqs: " prereqs-not-met)
+ (hash-table-set! test-registry hed 'removed)
+ (mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "TEN_STRIKES" #f)
+ ;; I'm unclear on if this roll up is needed - it may be the root cause of the "all set to FAIL" bug.
+ (rmt:set-state-status-and-roll-up-items run-id test-name item-path #f "FAIL" #f) ;; treat as FAIL
+ (list (if (null? tal)(car newtal)(car tal))
+ tal
+ reg
+ reruns)))))
+ ;; ELSE: can't drop this - maybe running? Just keep trying
+
+ ;;(if (not (or (not (null? reg))(not (null? tal)))) ;; old experiment
+ (let ((runable-tests (runs:runable-tests prereqs-not-met))) ;; SUSPICIOUS: Should look at more than just prereqs-not-met?
+ (if (null? runable-tests)
+ #f ;; I think we are truly done here
+ (runs:loop-values newtal reg reglen regfull reruns)))
+ ;;) ;;from old experiment
+ ) ;; end if (or (not (null? reg))(not (null? tal)))
+ ))))))
+
+;; scan a list of tests looking to see if any are potentially runnable
+;;
+(define (runs:runable-tests tests)
+ (filter (lambda (t)
+ (if (not (vector? t))
+ t
+ (let ((state (db:test-get-state t))
+ (status (db:test-get-status t)))
+ (case (string->symbol state)
+ ((COMPLETED INCOMPLETE) #f)
+ ((NOT_STARTED)
+ (if (member status '("TEN_STRIKES" "BLOCKED" "PREQ_FAIL" "ZERO_ITEMS" "PREQ_DISCARDED" "TIMED_OUT" ))
+ #f
+ t))
+ ((DELETED) #f)
+ (else t)))))
+ tests))
+
+;; move all the miscellanea into this struct
+;;
+(defstruct runs:gendat inc-results inc-results-last-update inc-results-fmt run-info runname target)
+
+(define *runs:general-data*
+ (make-runs:gendat
+ inc-results: (make-hash-table)
+ inc-results-last-update: 0
+ inc-results-fmt: "~12a~12a~20a~12a~40a\n" ;; state status time duration test-name item-path
+ run-info: #f
+ runname: #f
+ target: #f
+ )
+ )
+
+(define (runs:incremental-print-results run-id)
+ (let ((curr-sec (current-seconds))
+ (last-update (runs:gendat-inc-results-last-update *runs:general-data*)))
+ (if (> (- curr-sec last-update) 5) ;; at least five seconds since last update
+ (let* ((run-dat (or (runs:gendat-run-info *runs:general-data*)(rmt:get-run-info run-id)))
+ (runname (or (runs:gendat-runname *runs:general-data*)
+ (db:get-value-by-header (db:get-rows run-dat)
+ (db:get-header run-dat) "runname")))
+ (target (or (runs:gendat-target *runs:general-data*)(rmt:get-target run-id)))
+ (testsdat (let ((res (rmt:get-tests-for-run
+ run-id "%" '() '() ;; run-id testpatt states statuses
+ #f #f ;; offset limit
+ #f ;; not-in
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; get full data (not 'shortlist)
+ last-update
+ 'dashboard)))
+ (if (list? res)
+ res
+ (begin
+ (debug:print-error
+ 0 *default-log-port*
+ "FAILED TO GET DATA using rmt:get-tests-for-run. Notify developers if you see this. result: " res)
+ '())))))
+ (runs:gendat-inc-results-last-update-set! *runs:general-data* (- curr-sec 1))
+ (if (not (runs:gendat-run-info *runs:general-data*))
+ (runs:gendat-run-info-set! *runs:general-data* run-dat))
+ (if (not (runs:gendat-runname *runs:general-data*))
+ (runs:gendat-runname-set! *runs:general-data* runname))
+ (if (not (runs:gendat-target *runs:general-data*))
+ (runs:gendat-target-set! *runs:general-data* target))
+ (for-each
+ (lambda (testdat)
+ (let* ((test-id (db:test-get-id testdat))
+ (prevdat (hash-table-ref/default (runs:gendat-inc-results *runs:general-data*)
+ (conc run-id "," test-id) #f))
+ (test-name (db:test-get-testname testdat))
+ (item-path (db:test-get-item-path testdat))
+ (state (db:test-get-state testdat))
+ (status (db:test-get-status testdat))
+ (event-time (db:test-get-event_time testdat))
+ (duration (db:test-get-run_duration testdat)))
+ (if (and (not (member state '("DELETED" "REMOTEHOSTSTART" "RUNNING" "LAUNCHED""NOT_STARTED")))
+ (not (and prevdat
+ (equal? state (db:test-get-state prevdat))
+ (equal? status (db:test-get-status prevdat)))))
+ (let ((fmt (runs:gendat-inc-results-fmt *runs:general-data*))
+ (dtime (seconds->year-work-week/day-time event-time)))
+ (if (runs:lownoise "inc-print" 600)
+ (format #t fmt "State" "Status" "Start Time" "Duration" "Test path"))
+ ;; (debug:print 0 *default-log-port* "fmt: " fmt " state: " state " status: " status " test-name: " test-name " item-path: " item-path " dtime: " dtime)
+ ;; (debug:print 0 #f "event-time: " event-time " duration: " duration)
+ (format #t fmt
+ state
+ status
+ dtime
+ (seconds->hr-min-sec duration)
+ (conc "lt/" target "/" runname "/" test-name (if (string-null? item-path) "" (conc "/" item-path))))
+ (hash-table-set! (runs:gendat-inc-results *runs:general-data*) (conc run-id "," test-id) testdat)))))
+ testsdat)))
+
+ ;; I don't think this should be here? -- Matt
+ #;(runs:gendat-inc-results-last-update-set! *runs:general-data* (- curr-sec 10))
+
+ ))
+
+;; every time though the loop increment the test/itempatt val.
+;; when the min is > max-allowed and none running then force exit
+;;
+(define *max-tries-hash* (make-hash-table))
+
+(define (runs:pretty-long-list lst)
+ (if (> (length lst) 8)(append (take lst 3)(list "...")) lst))
+
+;;======================================================================
+;; runs:run-tests-queue is called by runs:run-tests
+;;======================================================================
+;;
+;; test-records is a hash table testname:item_path => vector < testname testconfig waitons priority items-info ... >
+(define (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests reglen-in all-tests-registry)
+ ;; At this point the list of parent tests is expanded
+ ;; NB// Should expand items here and then insert into the run queue.
+ (debug:print 5 *default-log-port* "test-records: " test-records ", flags: " (hash-table->alist flags))
+
+ ;; Do mark-and-find clean up of db before starting runing of quue
+ ;;
+ ;; (rmt:find-and-mark-incomplete)
+
+ (let* ((run-info (rmt:get-run-info run-id))
+ (tests-info (mt:get-tests-for-run run-id #f '() '())) ;; qryvals: "id,testname,item_path"))
+ (sorted-test-names (tests:sort-by-priority-and-waiton test-records))
+ (test-registry (make-hash-table))
+ (registry-mutex (make-mutex))
+ (num-retries 0)
+ (max-retries (configf:lookup *configdat* "setup" "maxretries"))
+ (max-concurrent-jobs (configf:lookup-number *configdat* "setup" "max_concurrent_jobs" default: 50))
+ (reglen (if (number? reglen-in) reglen-in 1))
+ (last-time-incomplete (- (current-seconds) 900)) ;; force at least one clean up cycle
+ (last-time-some-running (current-seconds))
+ ;; (tdbdat (tasks:open-db))
+ (runsdat (make-runs:dat
+ ;; hed: hed
+ ;; tal: tal
+ ;; reg: reg
+ ;; reruns: reruns
+ reglen: reglen
+ regfull: #f ;; regfull
+ ;; test-record: test-record
+ runname: runname
+ ;; test-name: test-name
+ ;; item-path: item-path
+ ;; jobgroup: jobgroup
+ max-concurrent-jobs: max-concurrent-jobs
+ run-id: run-id
+ ;; waitons: waitons
+ ;; testmode: testmode
+ test-patts: test-patts
+ required-tests: required-tests
+ test-registry: test-registry
+ registry-mutex: registry-mutex
+ flags: flags
+ keyvals: keyvals
+ run-info: run-info
+ ;; newtal: newtal
+ all-tests-registry: all-tests-registry
+ ;; itemmaps: itemmaps
+ ;; prereqs-not-met: (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps)
+ ;; can-run-more-tests: (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs) ;; look at the test jobgroup and tot jobs running
+ )))
+
+ ;; Initialize the test-registery hash with tests that already have a record
+ ;; convert state to symbol and use that as the hash value
+ (for-each (lambda (trec)
+ (let ((id (db:test-get-id trec))
+ (tn (db:test-get-testname trec))
+ (ip (db:test-get-item-path trec))
+ (st (db:test-get-state trec)))
+ (if (not (equal? st "DELETED"))
+ (hash-table-set! test-registry (db:test-make-full-name tn ip) (string->symbol st)))))
+ tests-info)
+ (set! max-retries (if (and max-retries (string->number max-retries))(string->number max-retries) 100))
+
+ (let loop ((hed (car sorted-test-names))
+ (tal (cdr sorted-test-names))
+ (reg '()) ;; registered, put these at the head of tal
+ (reruns '()))
+
+ (runs:incremental-print-results run-id)
+
+ (if (not (null? reruns))(debug:print-info 4 *default-log-port* "reruns=" reruns))
+
+ ;; Here we mark any old defunct tests as incomplete. Do this every fifteen minutes
+ ;; moving this to a parallel thread and just run it once.
+ ;;
+ (if (> (current-seconds)(+ last-time-incomplete 900))
+ (begin
+ (set! last-time-incomplete (current-seconds))
+ ;; (rmt:find-and-mark-incomplete-all-runs)
+ ))
+
+ ;; (print "Top of loop, hed=" hed ", tal=" tal " ,reruns=" reruns)
+ (let* ((test-record (hash-table-ref test-records hed))
+ (test-name (tests:testqueue-get-testname test-record))
+ (tconfig (tests:testqueue-get-testconfig test-record))
+ (jobgroup (configf:lookup tconfig "test_meta" "jobgroup"))
+ (testmode (let ((m (configf:lookup tconfig "requirements" "mode")))
+ (if m (map string->symbol (string-split m)) '(normal))))
+ (itemmaps (tests:get-itemmaps tconfig)) ;; (configf:lookup tconfig "requirements" "itemmap"))
+ (priority (tests:testqueue-get-priority test-record))
+ (itemdat (tests:testqueue-get-itemdat test-record)) ;; itemdat can be a string, list or #f
+ (items (tests:testqueue-get-items test-record))
+ (item-path (item-list->path itemdat))
+ (tfullname (db:test-make-full-name test-name item-path))
+ ;; these are hard coded item-item waits test/item-path => test/item-path2 ...
+ (extra-waits (let* ((section (configf:get-section (tests:testqueue-get-testconfig test-record) "waitons"))
+ (myextra (alist-ref tfullname section equal?)))
+ (if myextra
+ (let ((extras (string-split (car myextra))))
+ (if (runs:lownoise (conc tfullname "extra-waitons" tfullname) 60)
+ (debug:print-info 0 *default-log-port* "HAVE EXTRA WAITONS for test " tfullname ": " myextra))
+ (for-each
+ (lambda (extra)
+ ;; (debug:print 0 *default-log-port* "FYI: extra = " extra " reruns = " reruns)
+ (let ((basetestname (car (string-split extra "/"))))
+ #;(if (not (member extra tal))
+ (set! reruns (append tal (list extra))))
+ (if (not (member basetestname tal))
+ (set! reruns (append tal (list basetestname))))
+ ))
+ extras)
+ extras)
+ '())))
+ (waitons (delete-duplicates (append (tests:testqueue-get-waitons test-record) extra-waits) equal?))
+ (newtal (append tal (list hed)))
+ (regfull (>= (length reg) reglen))
+ (num-running (rmt:get-count-tests-running-for-run-id run-id))
+ (testdat (make-runs:testdat
+ hed: hed
+ tal: tal
+ reg: reg
+ reruns: reruns
+ test-record: test-record
+ test-name: test-name
+ item-path: item-path
+ jobgroup: jobgroup
+ waitons: waitons
+ testmode: testmode
+ newtal: newtal
+ itemmaps: itemmaps
+ ;; prereqs-not-met: prereqs-not-met
+ )))
+ (runs:dat-regfull-set! runsdat regfull)
+
+ (if (> num-running 0)
+ (set! last-time-some-running (current-seconds)))
+
+ (if (> (current-seconds)(+ last-time-some-running (or (configf:lookup *configdat* "setup" "give-up-waiting") 36000)))
+ (hash-table-set! *max-tries-hash* tfullname (+ (hash-table-ref/default *max-tries-hash* tfullname 0) 1)))
+ ;; (debug:print 0 *default-log-port* "max-tries-hash: " (hash-table->alist *max-tries-hash*))
+
+ ;; Ensure all top level tests get registered. This way they show up as "NOT_STARTED" on the dashboard
+ ;; and it is clear they *should* have run but did not.
+ (if (not (hash-table-ref/default test-registry (db:test-make-full-name test-name "") #f))
+ (begin
+ (rmt:register-test run-id test-name "")
+ (hash-table-set! test-registry (db:test-make-full-name test-name "") 'done)))
+
+ ;; Fast skip of tests that are already "COMPLETED" - NO! Cannot do that as the items may not have been expanded yet :(
+ ;;
+ (if (member (hash-table-ref/default test-registry tfullname #f)
+ '(DONOTRUN removed)) ;; *common:cant-run-states-sym*) ;; '(COMPLETED KILLED WAIVED UNKNOWN INCOMPLETE))
+ (begin
+ (if (runs:lownoise (conc "been marked do not run " tfullname) 60)
+ (debug:print-info 0 *default-log-port* "Skipping test " tfullname " as it has been marked do not run due to being completed or not runnable"))
+ (if (or (not (null? tal))(not (null? reg)))
+ (loop (runs:queue-next-hed tal reg reglen regfull)
+ (runs:queue-next-tal tal reg reglen regfull)
+ (runs:queue-next-reg tal reg reglen regfull)
+ reruns))))
+ ;; (loop (car tal)(cdr tal) reg reruns))))
+
+ (runs:incremental-print-results run-id)
+ (debug:print 4 *default-log-port* "TOP OF LOOP => "
+ "test-name: " test-name
+ "\n hed: " hed
+ "\n tal: " (runs:pretty-long-list tal)
+ "\n reg: " reg
+ "\n test-record " test-record
+ "\n itemdat: " itemdat
+ "\n items: " items
+ "\n item-path: " item-path
+ "\n waitons: " waitons
+ "\n num-retries: " num-retries
+ "\n reruns: " reruns
+ "\n regfull: " regfull
+ "\n reglen: " reglen
+ "\n length reg: " (length reg)
+ )
+
+ ;; (runs:parallel-runners-mgmt runsdat)
+
+ ;; check for hed in waitons => this would be circular, remove it and issue an
+ ;; error
+ (if (member test-name waitons)
+ (begin
+ (debug:print-error 0 *default-log-port* "test " test-name " has listed itself as a waiton, please correct this!")
+ (set! waiton (filter (lambda (x)(not (equal? x hed))) waitons))))
+
+ (cond
+
+ ;; We want to catch tests that have waitons that are NOT in the queue and discard them IFF
+ ;; they have been through the wringer 10 or more times
+ ((and (list? waitons)
+ (not (null? waitons))
+ (> (hash-table-ref/default *max-tries-hash* tfullname 0) 10)
+ (not (null? (filter
+ number?
+ (map (lambda (waiton)
+ (if (and (not (member waiton tal)) ;; this waiton is not in the list to be tried to run
+ (not (member waiton reruns)))
+ 1
+ #f))
+ waitons))))) ;; could do this more elegantly with a marker....
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-1")
+ (debug:print 0 *default-log-port* "WARNING: Marking test " tfullname " as not runnable. It is waiting on tests that cannot be run. Giving up now.")
+ (hash-table-set! test-registry tfullname 'removed))
+
+ ;; items is #f then the test is ok to be handed off to launch (but not before)
+ ;;
+ ((not items)
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-2")
+ (debug:print-info 4 *default-log-port* "OUTER COND: (not items)")
+ (if (and (not (tests:match test-patts (tests:testqueue-get-testname test-record) item-path required: required-tests))
+ (not (null? tal)))
+ (loop (car tal)(cdr tal) reg reruns))
+
+ ;; gonna try a strategy change here.
+ ;;
+ ;; check if can run more tests. if yes, continue, if no, rest until can run more
+ ;; look at the test jobgroup and tot jobs running
+ ;;
+ ;; NOTE: This does NOT actually gate here, only captures the proc to be called later
+ ;;
+ (if (not (runs:dat-wait-for-jobs-function runsdat))
+ (runs:dat-wait-for-jobs-function-set!
+ runsdat
+ (lambda (testdat-in)
+ (let* ((jobgroup (runs:testdat-jobgroup testdat-in))
+ (can-run-more-tests (runs:dat-can-run-more-tests runsdat))
+ (last-jobs-check-time (runs:dat-last-jobs-check-time runsdat))
+ (should-check-jobs (match can-run-more-tests
+ ((can-run-more-flag num-running nr-in-jobgroup max-concurrent-jobs . params)
+ (if (< (- max-concurrent-jobs num-running) 25)
+ (begin
+ (debug:print-info 0 *default-log-port*
+ "less than 20 jobs headroom, ("max-concurrent-jobs
+ "-"num-running")>20. Forcing prelaunch check.")
+ #t)
+ #f))
+ (else #f)))) ;; no record yet
+ (if should-check-jobs
+ (let loop-can-run-more
+ ((res (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs))
+ (remtries 1440)) ;; we can wait for up to two hours for jobs to get done
+ (match res
+ ((run-more num-running . rem)
+ (if (or run-more
+ (< remtries 1))
+ (begin
+ (if (runs:lownoise "num-running" 30)
+ (debug:print-info 0 *default-log-port* "Have "num-running" tests of max " max-concurrent-jobs))
+ (runs:dat-can-run-more-tests-set! runsdat res)) ;; capture the result and then drop through
+ (begin
+ (if (runs:lownoise "num-running" 10)
+ (debug:print-info 0 *default-log-port* "Can't run more tests, have "num-running" tests of "
+ max-concurrent-jobs " allowed."))
+ (thread-sleep! 5) ;; if we've hit max concurrent jobs take a breather, nb// make this configurable
+
+ ;; wait for load here
+ (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+ (loop-can-run-more (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs)
+ (- remtries 1)))))))
+ )))))
+
+ ;; I'm not clear on why prereqs are gathered here TODO: verfiy this is needed
+ (runs:testdat-prereqs-not-met-set! testdat (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps))
+
+ ;; I'm not clear on why we'd capture running job counts here TODO: verify this is needed
+ (runs:dat-can-run-more-tests-set! runsdat (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs))
+
+ (let ((loop-list (runs:process-expanded-tests runsdat testdat))) ;; in process-expanded-tests ultimately run:test -> launch-test -> test actually running
+ (if loop-list (apply loop loop-list))))
+
+ ;; items processed into a list but not came in as a list been processed
+ ;;
+ ((and (list? items) ;; thus we know our items are already calculated
+ (not itemdat)) ;; and not yet expanded into the list of things to be done
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-3")
+ (debug:print-info 4 *default-log-port* "OUTER COND: (and (list? items)(not itemdat))")
+ ;; Must determine if the items list is valid. Discard the test if it is not.
+ (if (and (list? items)
+ (> (length items) 0)
+ (and (list? (car items))
+ (> (length (car items)) 0))
+ (debug:debug-mode 1))
+ (debug:print 2 *default-log-port* (map (lambda (row)
+ (conc (string-intersperse
+ (map (lambda (varval)
+ (string-intersperse varval "="))
+ row)
+ " ")
+ "\n"))
+ items)))
+
+ (let* ((items-in-testpatt
+ (filter
+ (lambda (my-itemdat)
+ (tests:match test-patts hed (item-list->path my-itemdat) ))
+ ;; was: (tests:match test-patts hed (item-list->path my-itemdat) required: required-tests))
+ items) ))
+ (if (null? items-in-testpatt)
+ (debug:print-error 0 *default-log-port* "Test " (tests:testqueue-get-testname test-record) " is itemized but has no items matching the test pattern")
+
+ (for-each (lambda (my-itemdat)
+ (let* ((new-test-record (let ((newrec (make-tests:testqueue)))
+ (vector-copy! test-record newrec)
+ newrec))
+ (my-item-path (item-list->path my-itemdat))
+
+ (newtestname (db:test-make-full-name hed my-item-path))) ;; test names are unique on testname/item-path
+ (tests:testqueue-set-items! new-test-record #f)
+ (tests:testqueue-set-itemdat! new-test-record my-itemdat)
+ (tests:testqueue-set-item_path! new-test-record my-item-path)
+ (hash-table-set! test-records newtestname new-test-record)
+ (set! tal (append tal (list newtestname))))) ;; since these are itemized create new test names testname/itempath
+ items-in-testpatt)))
+
+
+
+ ;; At this point we have possibly added items to tal but all must be handed off to
+ ;; INNER COND logic. I think loop without rotating the queue
+ ;; (loop hed tal reg reruns))
+ ;; (let ((newtal (append tal (list hed)))) ;; We should discard hed as it has been expanded into it's items? Yes, but only if this *is* an itemized test
+ ;; (loop (car newtal)(cdr newtal) reg reruns)
+ (if (null? tal)
+ #f
+ (loop (car tal)(cdr tal) reg reruns)))
+
+ ;; if items is a proc then need to run items:get-items-from-config, get the list and loop
+ ;; - but only do that if resources exist to kick off the job
+ ;; EXPAND ITEMS
+ ((or (procedure? items)(eq? items 'have-procedure))
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-4")
+ (let ((can-run-more #f)) ;; (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs)))
+ (if (not can-run-more) #;(and (list? can-run-more)
+ (car can-run-more))
+ (let ((loop-list (runs:expand-items hed tal reg reruns regfull newtal jobgroup max-concurrent-jobs run-id waitons item-path testmode test-record can-run-more items runname tconfig reglen test-registry test-records itemmaps))) ;; itemized test expanded here
+ (if loop-list
+ (apply loop loop-list)
+ (debug:print-info 4 *default-log-port* " -- Can't expand hed="hed)
+ )
+ )
+ ;; if can't run more just loop with next possible test
+ (loop (car newtal)(cdr newtal) reg reruns))))
+
+ ;; this case should not happen, added to help catch any bugs
+ ((and (list? items) itemdat)
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-5")
+ (debug:print-error 0 *default-log-port* "Should not have a list of items in a test and the itemspath set - please report this")
+ (exit 1))
+ ((not (null? reruns))
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-6")
+ (let* ((newlst (tests:filter-non-runnable run-id tal test-records)) ;; i.e. not FAIL, WAIVED, INCOMPLETE, PASS, KILLED,
+ (junked (lset-difference equal? tal newlst)))
+ (debug:print-info 4 *default-log-port* "full drop through, if reruns is less than 100 we will force retry them, reruns=" reruns ", tal=" tal)
+ (if (< num-retries max-retries)
+ (set! newlst (append reruns newlst)))
+ (set! num-retries (+ num-retries 1))
+ ;; (thread-sleep! (+ 1 *global-delta*))
+ (if (not (null? newlst))
+ ;; since reruns have been tacked on to newlst create new reruns from junked
+ (loop (car newlst)(cdr newlst) reg (delete-duplicates junked)))))
+ ((not (null? tal))
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-7")
+ (debug:print-info 4 *default-log-port* "I'm pretty sure I shouldn't get here."))
+ ((not (null? reg)) ;; could we get here with leftovers?
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-8")
+ (debug:print-info 0 *default-log-port* "Have leftovers!")
+ (loop (car reg)(cdr reg) '() reruns))
+ (else
+ (debug:print-info 4 *default-log-port* "cond branch - " "rtq-9")
+ (debug:print-info 4 *default-log-port* "Exiting loop with...\n hed=" hed "\n tal=" tal "\n reruns=" reruns))
+ ))) ;; end loop on sorted test names
+ ;; this is the point where everything is launched and now you can mark the run in metadata table as all launched
+ (rmt:set-var (conc "lunch-complete-" run-id) "yes")
+
+ ;; now *if* -run-wait we wait for all tests to be done
+ ;; Now wait for any RUNNING tests to complete (if in run-wait mode)
+ ;; (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+ (thread-sleep! 10) ;; I think there is a race condition here. Let states/statuses settle
+
+ (let wait-loop ((num-running (rmt:get-count-tests-running-for-run-id run-id))
+ (prev-num-running 0))
+ ;; (debug:print-info 13 *default-log-port* "num-running=" num-running ", prev-num-running=" prev-num-running)
+ (if (and (or (args:get-arg "-run-wait")
+ (equal? (configf:lookup *configdat* "setup" "run-wait") "yes"))
+ (> num-running 0))
+ (begin
+ ;; Here we mark any old defunct tests as incomplete. Do this every fifteen minutes
+ ;; (debug:print 0 *default-log-port* "Got here eh! num-running=" num-running " (> num-running 0) " (> num-running 0))
+ (if (> (current-seconds)(+ last-time-incomplete 900))
+ (let ((actual-num-running (rmt:get-count-tests-running-for-run-id run-id)))
+ (debug:print-info 0 *default-log-port* "Marking stuck tests as INCOMPLETE while waiting for run " run-id
+ ". Running as pid " (current-process-id) " on " (get-host-name))
+ (set! last-time-incomplete (current-seconds)) ;; FIXME, this might be causing slow down - use of set!
+ (rmt:find-and-mark-incomplete run-id #f)
+ ;;call end of eud of run detection for posthook
+ (launch:end-of-run-check run-id)
+ (debug:print-info 0 *default-log-port* "run-wait specified, waiting on " actual-num-running
+ " tests in RUNNING, REMOTEHOSTSTART or LAUNCHED state at "
+ (time->string (seconds->local-time (current-seconds))))))
+ ;; (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+ (thread-sleep! 5) ;; (if (>= num-running max-concurrent-jobs) 5 1))
+ (wait-loop (rmt:get-count-tests-running-for-run-id run-id)
+ num-running))))
+ ;; LET* ((test-record
+ ;; we get here on "drop through". All done!
+ ;; this is moved to runs:run-testes since this function is getting called twice to ensure everthing is completed.
+ ;; (debug:print-info 0 *default-log-port* "Calling Post Hook")
+ ;; (runs:run-post-hook run-id)
+ (debug:print-info 1 *default-log-port* "All tests launched")))
+
+(define (runs:calc-fails prereqs-not-met)
+ (filter (lambda (test)
+ (and (vector? test) ;; not (string? test))
+ (member (db:test-get-state test) '("INCOMPLETE" "COMPLETED")) ;; TODO: pull from *common:stuff...*
+ (not (member (db:test-get-status test)
+ '("PASS" "WARN" "WAIVED" "SKIP")))))
+ prereqs-not-met))
+
+(define (runs:calc-prereq-fail prereqs-not-met) ;; REMOVEME since NOT_STARTED/PREQ_FAIL is now COMPLETED/PREQ_FAIL
+ (filter (lambda (test)
+ (and (vector? test) ;; not (string? test))
+ (equal? (db:test-get-state test) "NOT_STARTED")
+ (not (member (db:test-get-status test)
+ '("n/a" "KEEP_TRYING")))))
+ prereqs-not-met))
+
+(define (runs:calc-not-completed prereqs-not-met)
+ (filter
+ (lambda (t)
+ (or (not (vector? t))
+ (not (member (db:test-get-state t) '("INCOMPLETE" "COMPLETED")))))
+ prereqs-not-met))
+
+;; (define (runs:calc-not-completed prereqs-not-met)
+;; (filter
+;; (lambda (t)
+;; (or (not (vector? t))
+;; (not (equal? "COMPLETED" (db:test-get-state t)))))
+;; prereqs-not-met))
+
+(define (runs:calc-runnable prereqs-not-met)
+ (filter
+ (lambda (t)
+ (or (not (vector? t))
+ (and (equal? "NOT_STARTED" (db:test-get-state t))
+ (member (db:test-get-status t)
+ '("n/a" "KEEP_TRYING")))
+ (and (equal? "RUNNING" (db:test-get-state t))))) ;; account for a test that is running
+ prereqs-not-met))
+
+(define (runs:pretty-string lst)
+ (map (lambda (t)
+ (if (not (vector? t))
+ (conc t)
+ (conc (db:test-get-testname t) ":" (db:test-get-state t) "/" (db:test-get-status t))))
+ lst))
+
+;; parent-test is there as a placeholder for when parent-tests can be run as a setup step
+;;
+(define (run:test run-id run-info keyvals runname test-record flags parent-test test-registry all-tests-registry runsdat testdat-rec)
+ ;; All these vars might be referenced by the testconfig file reader
+ ;;
+ ;; NEED to reprocess testconfig here, ensuring that item variables are available.
+ ;; This is for Tal's issue with item-specific env vars not being set for use in skip.
+ ;; HSD https://hsdes.intel.com/appstore/icf/index.html#/article?articleId=1408763273
+ ;;
+ (let* ((test-name (tests:testqueue-get-testname test-record))
+ (test-waitons (tests:testqueue-get-waitons test-record))
+ (itemdat (tests:testqueue-get-itemdat test-record))
+ (item-path "")
+ (db #f)
+ (full-test-name #f))
+
+ ;; setting itemdat to a list if it is #f
+ (if (not itemdat)(set! itemdat '()))
+ (set! item-path (item-list->path itemdat))
+ (set! full-test-name (db:test-make-full-name test-name item-path))
+ (runs:set-megatest-env-vars run-id inrunname: runname testname: test-name itempath: item-path) ;; these may be needed by the launching process
+
+ (let* ((test-conf ;; re-instate the tests:get-testconfig once the kinks are worked out. FIXME!!!
+ ;; (tests:get-testconfig test-name item-path all-tests-registry #t force-create: #t))
+ (tests:testqueue-get-testconfig test-record ))
+ (test-path (hash-table-ref all-tests-registry test-name)) ;; (conc *toppath* "/tests/" test-name)) ;; could use tests:get-testconfig here ...
+
+ (force (hash-table-ref/default flags "-force" #f))
+ (rerun (hash-table-ref/default flags "-rerun" #f))
+ (keepgoing (hash-table-ref/default flags "-keepgoing" #f))
+ (incomplete-timeout (string->number (or (configf:lookup *configdat* "setup" "incomplete-timeout") "x")))
+ )
+
+ (debug:print-info 4 *default-log-port*
+ "\nTESTNAME: " full-test-name
+ "\n test-config: " (hash-table->alist test-conf)
+ "\n itemdat: " itemdat
+ )
+ (debug:print 2 *default-log-port* "Attempting to launch test " full-test-name)
+ ;; (setenv "MT_TEST_NAME" test-name) ;;
+ ;; (setenv "MT_ITEMPATH" item-path)
+ ;; (setenv "MT_RUNNAME" runname)
+ (change-directory *toppath*)
+
+ ;; Here is where the test_meta table is best updated
+ ;; Yes, another use of a global for caching. Need a better way?
+ ;;
+ ;; There is now a single call to runs:update-all-test_meta and this
+ ;; per-test call is not needed. Given the delicacy of the move to
+ ;; v1.55 this code is being left in place for the time being.
+ ;;
+ (if (not (hash-table-ref/default *test-meta-updated* test-name #f))
+ (begin
+ (hash-table-set! *test-meta-updated* test-name #t)
+ (runs:update-test_meta test-name test-conf)))
+
+ ;; itemdat => ((ripeness "overripe") (temperature "cool") (season "summer"))
+ (let* ((new-test-path (string-intersperse (cons test-path (map cadr itemdat)) "/"))
+ (test-id (rmt:get-test-id run-id test-name item-path))
+ (testdat (if test-id (rmt:get-test-info-by-id run-id test-id) #f)))
+ (if (not testdat)
+ (let loop ()
+ ;; ensure that the path exists before registering the test
+ ;; NOPE: Cannot! Don't know yet which disk area will be assigned....
+ ;; (system (conc "mkdir -p " new-test-path))
+ ;;
+ ;; (open-run-close tests:register-test db run-id test-name item-path)
+ ;;
+ ;; NB// for the above line. I want the test to be registered long before this routine gets called!
+ ;;
+ (if (not test-id)(set! test-id (rmt:get-test-id run-id test-name item-path)))
+ (if (not test-id)
+ (begin
+ (debug:print 2 *default-log-port* "WARN: Test not pre-created? test-name=" test-name ", item-path=" item-path ", run-id=" run-id)
+ (rmt:register-test run-id test-name item-path)
+ (set! test-id (rmt:get-test-id run-id test-name item-path))))
+ (debug:print-info 4 *default-log-port* "test-id=" test-id ", run-id=" run-id ", test-name=" test-name ", item-path=\"" item-path "\"")
+ (set! testdat (rmt:get-test-info-by-id run-id test-id))
+ (if (not testdat)
+ (begin
+ (debug:print-info 0 *default-log-port* "WARNING: server is overloaded, trying again in two seconds")
+ ;; (if (runs:dat-load-mgmt-function runsdat)((runs:dat-load-mgmt-function runsdat)))
+ (thread-sleep! 2)
+ (loop)))))
+ (if (not testdat) ;; should NOT happen
+ (debug:print-error 0 *default-log-port* "failed to get test record for test-id " test-id))
+ (set! test-id (db:test-get-id testdat))
+ (if (common:file-exists? test-path)
+ (change-directory test-path)
+ (begin
+ (debug:print-error 0 *default-log-port* "test run path not created before attempting to run the test. Perhaps you are running -remove-runs at the same time?")
+ (change-directory *toppath*)))
+ (case (if force ;; (args:get-arg "-force")
+ 'NOT_STARTED
+ (if testdat
+ (string->symbol (test:get-state testdat))
+ 'failed-to-insert))
+ ((failed-to-insert)
+ (debug:print-error 0 *default-log-port* "Failed to insert the record into the db"))
+ ((NOT_STARTED COMPLETED DELETED INCOMPLETE)
+ (let ((runflag #f))
+ (cond
+ ;; -force, run no matter what
+ (force (set! runflag #t))
+ ;; NOT_STARTED, run no matter what
+ ((member (test:get-state testdat) '("DELETED" "NOT_STARTED" "INCOMPLETE"))(set! runflag #t))
+ ;; not -rerun and PASS, WARN or CHECK, do no run
+ ((and (or (not rerun)
+ keepgoing)
+ ;; Require to force re-run for COMPLETED or *anything* + PASS,WARN or CHECK
+ (or (member (test:get-status testdat) '("PASS" "WARN" "CHECK" "SKIP" "WAIVED"))
+ (member (test:get-state testdat) '("COMPLETED"))))
+ (debug:print-info 2 *default-log-port* "running test " test-name "/" item-path " suppressed as it is " (test:get-state testdat) " and " (test:get-status testdat))
+ (hash-table-set! test-registry full-test-name 'DONOTRUN) ;; COMPLETED)
+ (set! runflag #f))
+
+ ;; -rerun and status is one of the specifed, run it
+ ((and rerun
+ (let* ((rerunlst (string-split rerun ","))
+ (must-rerun (member (test:get-status testdat) rerunlst)))
+ (debug:print-info 3 *default-log-port* "-rerun list: " rerun ", test-status: " (test:get-status testdat)", must-rerun: " must-rerun)
+ must-rerun))
+ (debug:print-info 2 *default-log-port* "Rerun forced for test " test-name "/" item-path)
+ (set! runflag #t)
+ (debug:print-info 2 *default-log-port* "Calling rerun hook")
+ (runs:rerun-hook test-id new-test-path testdat rerun)
+ )
+
+
+
+ ;; -keepgoing, do not rerun FAIL
+ ((and keepgoing
+ (member (test:get-status testdat) '("FAIL")))
+ (set! runflag #f))
+
+ ((and (not rerun)
+ (member (test:get-status testdat) '("FAIL" "n/a")))
+ (set! runflag #t))
+
+ (else (set! runflag #f)))
+ (debug:print 4 *default-log-port* "RUNNING => runflag: " runflag " STATE: " (test:get-state testdat) " STATUS: " (test:get-status testdat))
+ (if (not runflag)
+ (if (not parent-test)
+ (if (runs:lownoise (conc "not starting test" full-test-name) 60)
+ (debug:print 1 *default-log-port* "NOTE: Not starting test " full-test-name " as it is state \"" (test:get-state testdat)
+ "\" and status \"" (test:get-status testdat) "\", use -rerun \"" (test:get-status testdat)
+ "\" or -force to override")))
+ ;; NOTE: No longer be checking prerequisites here! Will never get here unless prereqs are
+ ;; already met.
+ ;; This would be a great place to do the process-fork
+ ;;
+ (let ((skip-test #f)
+ (skip-check (configf:get-section test-conf "skip")))
+ (cond
+ ;; Have to check for skip conditions. This one skips if there are same-named tests
+ ;; currently running
+ ((and skip-check
+ (configf:lookup test-conf "skip" "prevrunning"))
+ ;; run-ids = #f means *all* runs
+ (let ((running-tests (rmt:get-tests-for-runs-mindata #f full-test-name '("RUNNING" "REMOTEHOSTSTART" "LAUNCHED") '() #f)))
+ (if (not (null? running-tests)) ;; have to skip
+ (set! skip-test "Skipping due to previous tests running"))))
+
+ ;; split the string and OR of file-exists?
+ ((and skip-check
+ (configf:lookup test-conf "skip" "fileexists"))
+ (let* ((files (string-split (configf:lookup test-conf "skip" "fileexists")))
+ (existing (filter common:file-exists? files)))
+ (if (not (null? existing)) ;; (common:file-exists? (configf:lookup test-conf "skip" "fileexists"))
+ (set! skip-test (conc "Skipping due to existance of file(s) " (string-intersperse existing ", ")))))) ;; (configf:lookup test-conf "skip" "fileexists")))))
+
+ ((and skip-check
+ (configf:lookup test-conf "skip" "filenotexists"))
+ (let* ((files (string-split (configf:lookup test-conf "skip" "filenotexists")))
+ (existing (filter common:file-exists? files)))
+ (if (null? existing) ;; (common:file-exists? (configf:lookup test-conf "skip" "filenotexists")))
+ (set! skip-test (conc "Skipping due to non existance of files " (string-intersperse files ", ")))))) ;; (configf:lookup test-conf "skip" "filenotexists")))))
+
+ ((and skip-check
+ (configf:lookup test-conf "skip" "script"))
+ (if (= (system (configf:lookup test-conf "skip" "script")) 0)
+ (set! skip-test (conc "Skipping due to zero return value of script " (configf:lookup test-conf "skip" "script")))))
+
+ ((and skip-check
+ (configf:lookup test-conf "skip" "rundelay"))
+ ;; run-ids = #f means *all* runs
+ (let* ((numseconds (common:hms-string->seconds (configf:lookup test-conf "skip" "rundelay")))
+ (running-tests (rmt:get-tests-for-runs-mindata #f full-test-name '("RUNNING" "REMOTEHOSTSTART" "LAUNCHED") '() #f))
+ (completed-tests (rmt:get-tests-for-runs-mindata #f full-test-name '("COMPLETED" "INCOMPLETE") '("PASS" "FAIL" "ABORT") #f)) ;; ironically INCOMPLETE is same as COMPLETED in this contex
+ (last-run-times (map db:mintest-get-event_time completed-tests))
+ (time-since-last (- (current-seconds) (if (null? last-run-times) 0 (common:max last-run-times)))))
+ (if (or (not (null? running-tests)) ;; have to skip if test is running
+ (> numseconds time-since-last))
+ (set! skip-test (conc "Skipping due to previous test run less than " (configf:lookup test-conf "skip" "rundelay") " ago"))))))
+
+ (if skip-test
+ (begin
+ (mt:test-set-state-status-by-id run-id test-id "COMPLETED" "SKIP" skip-test)
+ (debug:print-info 1 *default-log-port* "SKIPPING Test " full-test-name " due to " skip-test))
+ ;;
+ ;; Here the test is handed off to launch.scm for launch-test to complete the launch process
+ ;;
+ (begin
+ ;; wait for less than max jobs here
+ (if (runs:dat-wait-for-jobs-function runsdat)
+ ((runs:dat-wait-for-jobs-function runsdat) testdat-rec))
+
+ (if (not (launch-test test-id run-id run-info keyvals runname test-conf test-name test-path itemdat flags))
+ (begin
+ (print "ERROR: Failed to launch the test. Exiting as soon as possible")
+ (set! *globalexitstatus* 1) ;;
+ (process-signal (current-process-id) signal/kill))
+ )
+ ;; wait again here?
+ ))))))
+ ((KILLED)
+ (debug:print 1 *default-log-port* "NOTE: " full-test-name " is already running or was explictly killed, use -force to launch it.")
+ (hash-table-set! test-registry (db:test-make-full-name test-name test-path) 'DONOTRUN)) ;; KILLED))
+ ((LAUNCHED REMOTEHOSTSTART RUNNING)
+ (debug:print 2 *default-log-port* "NOTE: " test-name " is already running"))
+ ;; (if (> (- (current-seconds)(+ (db:test-get-event_time testdat)
+ ;; (db:test-get-run_duration testdat)))
+ ;; (or incomplete-timeout
+ ;; 6000)) ;; i.e. no update for more than 6000 seconds
+ ;; (begin
+ ;; (debug:print 0 *default-log-port* "WARNING: Test " test-name " appears to be dead. Forcing it to state INCOMPLETE and status STUCK/DEAD")
+ ;; (tests:test-set-status! run-id test-id "INCOMPLETE" "STUCK/DEAD" "" #f))
+ ;; ;; (tests:test-set-status! test-id "INCOMPLETE" "STUCK/DEAD" "" #f))
+ ;; (debug:print 2 *default-log-port* "NOTE: " test-name " is already running")))
+ (else
+ (debug:print-error 0 *default-log-port* "Failed to launch test " full-test-name ". Unrecognised state " (test:get-state testdat))
+ (case (string->symbol (test:get-state testdat))
+ ((COMPLETED INCOMPLETE)
+ (hash-table-set! test-registry (db:test-make-full-name test-name test-path) 'DONOTRUN))
+ (else
+ (hash-table-set! test-registry (db:test-make-full-name test-name test-path) 'DONOTRUN)))))))))
+
+;;======================================================================
+;; END OF NEW STUFF
+;;======================================================================
+
+(define (get-dir-up-n dir . params)
+ (let ((dparts (string-split dir "/"))
+ (count (if (null? params) 1 (car params))))
+ (conc "/" (string-intersperse
+ (take dparts (- (length dparts) count))
+ "/"))))
+
+(define (runs:recursive-delete-with-error-msg real-dir)
+ (if (> (system (conc "rm -rf " real-dir)) 0)
+ (begin
+ ;; FAILED, possibly due to permissions, do chmod a+rwx then try one more time
+ (system (conc "chmod -R a+rwx " real-dir))
+ (if (> (system (conc "rm -rf " real-dir)) 0)
+ (debug:print-error 0 *default-log-port* "There was a problem removing " real-dir " with rm -f")))))
+
+(define (runs:safe-delete-test-dir real-dir)
+ ;; first delete all sub-directories
+ (directory-fold
+ (lambda (f x)
+ (let ((fullname (conc real-dir "/" f)))
+ (if (directory? fullname)(runs:recursive-delete-with-error-msg fullname)))
+ (+ 1 x))
+ 0 real-dir)
+ ;; then files other than *testdat.db*
+ (directory-fold
+ (lambda (f x)
+ (let ((fullname (conc real-dir "/" f)))
+ (if (not (string-search (regexp "testdat.db") f))
+ (runs:recursive-delete-with-error-msg fullname)))
+ (+ 1 x))
+ 0 real-dir #t)
+ ;; then the entire directory
+ (runs:recursive-delete-with-error-msg real-dir))
+
+;; cleanup often needs to remove all but the last N runs per target
+;;
+;; target-patts a1/b1/c1,a2/b2/c2 ...
+;;
+;; This will fail if called with empty target or a bad target (i.e. missing or extra fields)
+;;
+(define (runs:get-hash-by-target target-patts runpatt)
+ (let* ((targets (string-split target-patts ","))
+ (keys (rmt:get-keys))
+ (res-ht (make-hash-table))) ;; target -> ( runrecord1 runrecord2 ... )
+ (for-each
+ (lambda (target-patt)
+ (let ((runs (rmt:simple-get-runs runpatt #f #f target-patt #f)))
+ (for-each
+ (lambda (run)
+ (let ((target (simple-run-target run)))
+ (hash-table-set! res-ht target (cons run (hash-table-ref/default res-ht target '())))))
+ runs)))
+ targets)
+ res-ht))
+
+;; delete runs older than X (weeks, days, months years etc.)
+;; delete redundant runs within a target - N is the input
+;; delete redundant runs within a target IFF older than given date/time AND keep at least N
+;;
+(define (runs:remove-all-but-last-n-runs-per-target target-patts runpatt num-to-keep #!key (actions '(print)))
+ (let* ((runs-ht (runs:get-hash-by-target target-patts runpatt))
+ (age (if (args:get-arg "-age")(common:hms-string->seconds (args:get-arg "-age")) #f))
+ (age-mark (if age (- (current-seconds) age) (+ (current-seconds) 86400)))
+ (precmd (or (args:get-arg "-precmd") ""))
+ (action-chk (member (string->symbol "remove-runs") actions)))
+ ;; check the sequence of actions archive must comme before remove-runs
+ (if (and action-chk (member (string->symbol "archive") action-chk))
+ (begin
+ (debug:print-error 0 *default-log-port* "action remove-runs must come after archive")
+ (exit 1)))
+ (print "Actions: " actions " age: " age)
+ (for-each
+ (lambda (action)
+ (for-each
+ (lambda (target)
+ (let* ((runs (hash-table-ref runs-ht target))
+ (sorted (sort runs (lambda (a b)(< (simple-run-event_time a)(simple-run-event_time b)))))
+ (to-remove (let* ((len (length sorted))
+ (trim-amt (- len num-to-keep)))
+ (if (> trim-amt 0)
+ (take sorted trim-amt)
+ '()))))
+ (hash-table-set! runs-ht target to-remove)
+ (print target ":")
+ (for-each
+ (lambda (run)
+ (let ((remove (member run to-remove (lambda (a b)
+ (eq? (simple-run-id a)
+ (simple-run-id b))))))
+ (if (and age (> (simple-run-event_time run) age-mark))
+ (print "Skipping handling of " target "/" (simple-run-runname run) " as it is younger than " (args:get-arg "-age"))
+ (case action
+ ((print)
+ (print " " (simple-run-runname run)
+ " " (time->string (seconds->local-time (simple-run-event_time run)) "WW%V.%u %H:%M:%S")
+ " " (if remove "REMOVE" "")))
+ ((remove-runs)
+ (if remove (system (conc precmd " megatest -remove-runs -target " target " -runname " (simple-run-runname run) " -testpatt %"
+ (if (member 'kill-runs actions) ;; if kill-runs is specified then set -kill-wait to 0
+ " -kill-wait 0"
+ "")))))
+ ((archive)
+ (if remove (system (conc precmd " megatest -archive save-remove -target " target " -runname " (simple-run-runname run) " -testpatt %"))))
+ ((kill-runs)
+ (if remove (system (conc precmd " megatest -kill-runs -target " target " -runname " (simple-run-runname run) " -testpatt %"))))))))
+ sorted)))
+ (hash-table-keys runs-ht)))
+ actions)
+ runs-ht))
+
+(define (remove-last-path-directory path-in)
+ (let* ((dparts (string-split path-in "/"))
+ (path-out (conc "/" (string-intersperse (take dparts (- (length dparts) 1)) "/")))
+ )
+ path-out
+ )
+)
+
+
+(define (runs:operate-on action target runnamepatt testpatt #!key (state #f)(status #f)(new-state-status #f)(mode #f)(options '()))
+ (common:clear-caches) ;; clear all caches
+ (let* ((db #f)
+ ;; (tdbdat (tasks:open-db))
+ (keys (rmt:get-keys))
+ (rundat (mt:get-runs-by-patt keys runnamepatt target))
+ (header (vector-ref rundat 0))
+ (runs (vector-ref rundat 1))
+ (states (if state (string-split state ",") '()))
+ (statuses (if status (string-split status ",") '()))
+ (state-status (if (string? new-state-status) (string-split new-state-status ",") '(#f #f)))
+ (rp-mutex (make-mutex))
+ (bup-mutex (make-mutex))
+ (keep-records (args:get-arg "-keep-records")) ;; used in conjunction with -remove-runs to keep the records, TODO: consolidate this with "mode".
+ (test-records '())) ;; for tasks that we wish to operate on all tests in one fell swoop
+
+ (let* ((write-access-actions '(remove-runs set-state-status archive run-wait kill-runs))
+ (dbfile (conc *toppath* "/megatest.db"))
+ (readonly-mode (not (file-write-access? dbfile))))
+ (when (and readonly-mode
+ (member action write-access-actions))
+ (debug:print-error 0 *default-log-port* "megatest.db is readonly. Cannot proceed with action ["action"] in which write-access isrequired .")
+ (exit 1)))
+
+ (debug:print-info 4 *default-log-port* "runs:operate-on => Header: " header " action: " action " new-state-status: " new-state-status)
+ (if (> 2 (length state-status))
+ (begin
+ (debug:print-error 0 *default-log-port* "the parameter to -set-state-status is a comma delimited string. E.g. COMPLETED,FAIL")
+ (exit)))
+ (for-each
+ (lambda (run)
+ (let ((runkey (string-intersperse (map (lambda (k)
+ (db:get-value-by-header run header k)) keys) "/"))
+ (dirs-to-remove (make-hash-table))
+ (proc-get-tests (lambda (run-id)
+ (mt:get-tests-for-run run-id
+ testpatt states statuses
+ not-in: #f
+ sort-by: (case action
+ ((remove-runs) 'rundir)
+ (else 'event_time))))))
+ (let* ((run-id (db:get-value-by-header run header "id"))
+ (run-state (db:get-value-by-header run header "state"))
+ (run-name (db:get-value-by-header run header "runname"))
+ (tests (if (not (equal? run-state "locked"))
+ (proc-get-tests run-id)
+ '()))
+ (lasttpath "/does/not/exist/I/hope")
+ (lastrealpath "/does/not/exist/I/hope")
+ ;; there may be a number of different disks used in the same run.
+ (run-paths-hash (make-hash-table))
+ (worker-thread #f))
+ (debug:print-info 4 *default-log-port* "runs:operate-on run=" run ", header=" header)
+ (if (not (null? tests))
+ (begin
+ (case action
+ ((kill-runs)
+ (tasks:kill-runner target run-name "%")
+ (debug:print 1 *default-log-port* "Killing tests for run: " runkey " " (db:get-value-by-header run header "runname"))
+ )
+ ((remove-runs)
+ ;; (if (tasks:need-server run-id)(tasks:start-and-wait-for-server tdbdat run-id 10))
+ ;; seek and kill in flight -runtests with % as testpatt here
+ ;; (if (equal? testpatt "%")
+ (tasks:kill-runner target run-name testpatt)
+ ;; (debug:print 0 *default-log-port* "not attempting to kill any run launcher processes as testpatt is " testpatt))
+ (debug:print 1 *default-log-port* "Removing tests for run: " runkey " " (db:get-value-by-header run header "runname")))
+ ((set-state-status)
+ ;; (if (tasks:need-server run-id)(tasks:start-and-wait-for-server tdbdat run-id 10))
+ (debug:print 1 *default-log-port* "Modifying state and staus for tests for run: " runkey " " (db:get-value-by-header run header "runname")))
+ ((print-run)
+ (debug:print 1 *default-log-port* "Printing info for run " runkey ", run=" run ", tests=" tests ", header=" header)
+ action)
+ ((run-wait)
+ (debug:print 1 *default-log-port* "Waiting for run " runkey ", run=" runnamepatt " to complete"))
+ ((archive)
+ (debug:print 1 *default-log-port* "Archiving/restoring (" (args:get-arg "-archive") ") data for run: " runkey " " (db:get-value-by-header run header "runname"))
+ (let ((op (string->symbol (args:get-arg "-archive"))))
+ (set! worker-thread
+ (make-thread
+ (lambda ()
+ (case op
+ ((save save-remove keep-html)
+ (archive:run-bup op run-id run-name tests rp-mutex bup-mutex))
+ ((restore)
+ (archive:bup-restore op run-id run-name tests rp-mutex bup-mutex))
+ ((get) ;;; NOTE: This is a special case. We wish to operate on ALL tests in one go
+ (set! test-records (append tests test-records)))
+ (else
+ (debug:print-error 0 *default-log-port* "unrecognised sub command " op " for -archive. Run \"megatest\" to see help")
+ (exit))))
+ "archive-bup-thread"))
+ (thread-start! worker-thread)
+ (if (eq? op 'get)
+ (thread-join! worker-thread)) ;; we need the test-records set to not overlap
+ ))
+ (else
+ (debug:print-info 0 *default-log-port* "action not recognised " action)))
+
+ ;; actions that operate on one test at a time can be handled below
+ ;;
+ (let ((sorted-tests (filter
+ vector?
+ (sort tests (lambda (a b)(let ((dira ;; (rmt:sdb-qry 'getstr
+ (db:test-get-rundir a)) ;; ) ;; (filedb:get-path *fdb* (db:test-get-rundir a)))
+ (dirb ;; (rmt:sdb-qry 'getstr
+ (db:test-get-rundir b))) ;; ) ;; ((filedb:get-path *fdb* (db:test-get-rundir b))))
+ (if (and (string? dira)(string? dirb))
+ (> (string-length dira)(string-length dirb))
+ #f))))))
+ (toplevel-retries (make-hash-table)) ;; try three times to loop through and remove top level tests
+ (test-retry-time (make-hash-table))
+ (backgrounded-remove-status (make-hash-table))
+ (backgrounded-remove-last-visit (make-hash-table))
+ (backgrounded-remove-result (make-hash-table))
+ (allow-run-time (string->number (or (args:get-arg "-kill-wait") "10")))) ;; seconds to allow for killing tests before just brutally killing 'em
+ (let loop ((test (car sorted-tests))
+ (tal (cdr sorted-tests)))
+ (let* ((test-id (db:test-get-id test))
+ (new-test-dat (rmt:get-test-info-by-id run-id test-id)))
+ (if (not new-test-dat)
+ (begin
+ (debug:print-error 0 *default-log-port* "We have a test-id of " test-id " but no record was found. NOTE: No locking of records is done between processes, do not simultaneously remove the same run from two processes!")
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))))
+ (let* ((item-path (db:test-get-item-path new-test-dat))
+ (test-name (db:test-get-testname new-test-dat))
+ (run-dir ;;(filedb:get-path *fdb*
+ ;; (rmt:sdb-qry 'getid
+ (db:test-get-rundir new-test-dat)) ;; ) ;; run dir is from the link tree
+ (has-subrun (and (subrun:subrun-test-initialized? run-dir)
+ (not (subrun:subrun-removed? run-dir))))
+ (test-state (db:test-get-state new-test-dat))
+ (test-status (db:test-get-status new-test-dat))
+ (test-fulln (db:test-get-fullname new-test-dat))
+ (uname (db:test-get-uname new-test-dat))
+ (toplevel-with-children (and (db:test-get-is-toplevel test)
+ (> (rmt:test-toplevel-num-items run-id test-name) 0))))
+
+ (case action
+ ((remove-runs)
+ ;; if the test is a toplevel-with-children issue an error and do not remove
+ (cond
+ (toplevel-with-children
+ (debug:print 0 *default-log-port* "WARNING: skipping removal of " test-fulln " with run-id " run-id " as it has sub tests")
+ (hash-table-set! toplevel-retries test-fulln (+ (hash-table-ref/default toplevel-retries test-fulln 0) 1))
+ (if (> (hash-table-ref toplevel-retries test-fulln) 3)
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))) ;; no else clause - drop it if no more in queue and > 3 tries
+ (let ((newtal (append tal (list test))))
+ (loop (car newtal)(cdr newtal))))) ;; loop with test still in queue
+ (has-subrun
+ ;;
+ (let ((last-visit (hash-table-ref/default backgrounded-remove-last-visit test-fulln 0))
+ (now (current-seconds))
+ (rem-status (hash-table-ref/default backgrounded-remove-status test-fulln 'not-started)))
+ (case rem-status
+ ((not-started)
+ (debug:print 0 *default-log-port* "WARNING: postponing removal of " test-fulln " with run-id " run-id " as it has a subrun")
+ (hash-table-set! backgrounded-remove-status test-fulln 'started)
+ (hash-table-set! backgrounded-remove-last-visit test-fulln (current-seconds))
+ (common:send-thunk-to-background-thread
+ (lambda ()
+ (let* ((subrun-remove-succeeded
+ (subrun:remove-subrun run-dir keep-records)))
+ (hash-table-set! backgrounded-remove-result test-fulln subrun-remove-succeeded)
+ (hash-table-set! backgrounded-remove-status test-fulln 'done)))
+ name: (conc "remove-subrun:"test-fulln))
+
+ ;; send to back of line, loop
+ (let ((newtal (append tal (list test))))
+ (loop (car newtal)(cdr newtal)))
+ )
+ ((started)
+ ;; if last visit was within last second, sleep 1 second
+ (if (< (- now last-visit) 1.0)
+ (thread-sleep! 1.0))
+ (hash-table-set! backgrounded-remove-last-visit test-fulln (current-seconds))
+ ;; send to back of line, loop
+ (let ((newtal (append tal (list test))))
+ (loop (car newtal)(cdr newtal)))
+ )
+ ((done)
+ ;; drop this one; if remaining, loop, else finish
+ (hash-table-set! backgrounded-remove-last-visit test-fulln (current-seconds))
+ (let ((subrun-remove-succeeded (hash-table-ref/default backgrounded-remove-result test-fulln 'exception)))
+ (cond
+ ((eq? subrun-remove-succeeded 'exception)
+ (let* ((logfile (subrun:get-log-path run-dir "remove")))
+ (debug:print 0 *default-log-port* "ERROR: removing subrun of of " test-fulln " with run-id " run-id " ; see logfile @ "logfile))
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))))
+ (subrun-remove-succeeded
+ (debug:print 0 *default-log-port* "Now removing of " test-fulln " with run-id " run-id " since subrun was removed.")
+ ;;(runs:remove-test-directory new-test-dat mode) ;; let normal case handle this. it will go thru loop again as non-subrun
+ (let ((newtal (append tal (list test))))
+ (loop (car newtal)(cdr newtal))))
+ (else
+ (let* ((logfile (subrun:get-log-path run-dir "remove")))
+ (debug:print 0 *default-log-port* "WARNING: removal of subrun failed. Please check "logfile" for details."))
+ ;; send to back of line, loop (will not match has-subrun next time through)
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))))))
+ )
+ ) ; end case rem-status
+ ) ; end let
+ ); end cond has-subrun
+
+ (else
+ ;; BB - TODO - consider backgrounding to threads to delete tests (work below)
+ (debug:print-info 0 *default-log-port* "test: " test-name " itest-state: " test-state)
+ (if (member test-state (list "RUNNING" "LAUNCHED" "REMOTEHOSTSTART" "KILLREQ"))
+ (begin
+ (if (not (hash-table-ref/default test-retry-time test-fulln #f))
+ (begin
+ ;; want to set to REMOVING BUT CANNOT do it here?
+ (hash-table-set! test-retry-time test-fulln (current-seconds))))
+ (if (> (- (current-seconds)(hash-table-ref test-retry-time test-fulln)) allow-run-time)
+ ;; This test is not in a correct state for cleaning up. Let's try some graceful shutdown steps first
+ ;; Set the test to "KILLREQ" and wait five seconds then try again. Repeat up to five times then give
+ ;; up and blow it away.
+ (begin
+ (debug:print 0 *default-log-port* "WARNING: could not gracefully remove test " test-fulln ", tried to kill it to no avail. Forcing state to FAILEDKILL and continuing")
+ (mt:test-set-state-status-by-id run-id (db:test-get-id test) "FAILEDKILL" "n/a" #f)
+ (thread-sleep! 1))
+ (begin
+ (mt:test-set-state-status-by-id run-id (db:test-get-id test) "KILLREQ" "n/a" #f)
+ (thread-sleep! 1)))
+ ;; NOTE: This is suboptimal as the testdata will be used later and the state/status may have changed ...
+ (if (null? tal)
+ (loop new-test-dat tal)
+ (loop (car tal)(append tal (list new-test-dat)))))
+ (begin
+ (let ((rundir (db:test-get-rundir new-test-dat)))
+ (if (and (not (string= rundir "/tmp/badname"))
+ (file-exists? rundir)
+ (substring-index run-name rundir)
+ (tests:glob-like-match (conc "%/" target "/%") rundir)
+ )
+ (begin
+ (set! lasttpath (db:test-get-rundir new-test-dat)) ;; remember this path for run removal
+ (set! lastrealpath (remove-last-path-directory (resolve-pathname lasttpath)))
+ (hash-table-set! run-paths-hash lastrealpath 1)
+ (runs:remove-test-directory new-test-dat mode) ;; 'remove-all)
+ )
+ (begin
+ (debug:print 2 *default-log-port* "Not removing directory " rundir " because either it doesn't exist or has a bad name")
+ (debug:print 2 *default-log-port* "Is /tmp/badname: " (string= rundir "/tmp/badname"))
+ (debug:print 2 *default-log-port* "Exists: " (file-exists? rundir))
+ (debug:print 2 *default-log-port* "Has run-name: " (substring-index run-name rundir))
+ (debug:print 2 *default-log-port* "Has target: " (tests:glob-like-match (conc "%/" target "/%") rundir))
+ (debug:print 2 *default-log-port* "Target: " target)
+
+ ;;PJH remove record from db no need to cleanup directory
+ (case mode
+ ((remove-data-only)(mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) (db:test-get-state test)(db:test-get-status test) #f))
+ ((archive-remove) (mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) "ARCHIVED" #f #f))
+ (else (rmt:delete-test-records (db:test-get-run_id test) (db:test-get-id test))))
+
+ )
+ )
+ )
+
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal)))))))
+ (rmt:update-run-stats run-id (rmt:get-raw-run-stats run-id)))
+ ((kill-runs)
+ ;; RUNNING -> KILLREQ
+ ;; LAUNCHED,RUNNING,REMOTEHOSTSTART -> NOT STARTED
+ (cond
+ ((and has-subrun (member test-state (list "RUNNING" "LAUNCHED" "REMOTEHOSTSTART" "KILLREQ")))
+ (common:send-thunk-to-background-thread
+ (lambda ()
+ (let* ((subrun-remove-succeeded
+ (subrun:kill-subrun run-dir keep-records)))
+ #t)))
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal)))
+ )
+ ((member test-state (list "RUNNING" "LAUNCHED" "REMOTEHOSTSTART" "KILLREQ"))
+ (debug:print 1 *default-log-port* "INFO: issuing killreq to test "test-fulln)
+ (mt:test-set-state-status-by-id run-id (db:test-get-id test) "KILLREQ" "n/a" #f)
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))))
+ ((and (member test-status '("PREQ_FAIL" "PREQ_DISCARDED" "BLOCKED" "ZERO_ITEMS" "KEEP_TRYING" "TEN_STRIKES" "TIMED_OUT")))
+ (rmt:set-state-status-and-roll-up-items run-id (db:test-get-id test) 'foo "NOT_STARTED" "n/a" (conc "kill-run moved from "test-state":"test-status" to NOT_STARTED:n/a"))
+ ;;(mt:test-set-state-status-by-id run-id (db:test-get-id test) "NOT_STARTED" "n/a" (conc "kill-run moved from "test-state":"test-status" to NOT_STARTED:n/a"))
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal)))
+ )
+ (else
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal)))
+ )))
+ ((set-state-status)
+ (let* ((new-state (car state-status))
+ (new-status (cadr state-status))
+ (test-id (db:test-get-id test))
+ (test-run-dir (db:test-get-rundir new-test-dat))
+ (has-subrun (and (subrun:subrun-test-initialized? test-run-dir)
+ (not (subrun:subrun-removed? test-run-dir)))))
+ (when has-subrun
+ (common:send-thunk-to-background-thread
+ (lambda ()
+ (subrun:set-state-status test-run-dir state status new-state-status)
+ )
+ )
+ )
+ (debug:print-info 2 *default-log-port* "new state " new-state ", new status " new-status )
+ (mt:test-set-state-status-by-id run-id test-id new-state new-status #f))
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))))
+ ((run-wait)
+ ;; BB TODO - manage has-subrun case
+ (debug:print-info 2 *default-log-port* "still waiting, " (length tests) " tests still running")
+ (thread-sleep! 5)
+ (let ((new-tests (proc-get-tests run-id)))
+ (if (null? new-tests)
+ (debug:print-info 1 *default-log-port* "Run completed according to zero tests matching provided criteria.")
+ (loop (car new-tests)(cdr new-tests)))))
+ ((archive)
+ ;; BB TODO - manage has-subrun case
+ (if (and run-dir (not toplevel-with-children))
+ (let ((ddir (conc run-dir "/")))
+ (case (string->symbol (args:get-arg "-archive"))
+ ((save save-remove keep-html)
+ (if (common:file-exists? ddir)
+ (debug:print-info 0 *default-log-port* "Estimating disk space usage for " test-fulln ": " (common:get-disk-space-used ddir)))))))
+ (if (not (null? tal))
+ (loop (car tal)(cdr tal))))
+ )))
+ )
+ (if worker-thread (thread-join! worker-thread)))
+ (common:join-backgrounded-threads))))
+
+ ;; remove the run if zero tests remain
+ (if (eq? action 'remove-runs)
+ (let* ((run-id (db:get-value-by-header run header "id")) ;; NB// masks run-id from above?
+ (remtests (mt:get-tests-for-run run-id #f '("DELETED") '("n/a") not-in: #t)))
+ (if (null? remtests) ;; no more tests remaining
+ (let* ((linkspath (remove-last-path-directory lasttpath))
+ (runpaths (hash-table-keys run-paths-hash))
+ )
+
+ (debug:print 2 *default-log-port* "run-paths-hash: " (hash-table-keys run-paths-hash))
+
+ (debug:print 1 *default-log-port* "Removing target " target "run: " run-name)
+ (if (not keep-records)
+ (begin
+ (debug:print 1 *default-log-port* "Removing DB records for the run.")
+ (rmt:delete-run run-id)
+ (rmt:delete-old-deleted-test-records))
+ )
+ (if (not (equal? linkspath "/does/not/exist/I"))
+ (begin
+ (debug:print 1 *default-log-port* "Recursively removing links dir " linkspath)
+ (runs:recursive-delete-with-error-msg linkspath)))
+
+ (for-each (lambda(runpath)
+ (debug:print 1 *default-log-port* "Recursively removing runs dir " runpath)
+ (runs:recursive-delete-with-error-msg runpath)
+ )
+ runpaths
+ )
+ )))))
+ ))
+ runs)
+ ;; special case - archive get
+ (if (equal? (args:get-arg "-archive") "get")
+ (archive:bup-get-data "get" #f #f test-records rp-mutex bup-mutex))
+ (if (or (equal? (args:get-arg "-archive") "save") (equal? (args:get-arg "-archive") "save-remove"))
+ (begin
+ (print "db archive started")
+ (archive:megatest-db target runnamepatt)
+ (print "db archived")))
+ )
+ #t
+ )
+
+(define (runs:remove-test-directory test mode) ;; remove-data-only)
+ (let* ((run-dir (db:test-get-rundir test)) ;; run dir is from the link tree
+ (real-dir (if (common:file-exists? run-dir)
+ ;; (resolve-pathname run-dir)
+ (common:nice-path run-dir)
+ #f))
+ (clean-mode (or mode 'remove-all))
+ (test-id (db:test-get-id test))
+ ;; (lock-key (conc "test-" test-id))
+ ;; (got-lock (let loop ((lock (rmt:no-sync-get-lock lock-key))
+ ;; (expire-time (+ (current-seconds) 30))) ;; give up on getting the lock and steal it after 15 seconds
+ ;; (if (car lock)
+ ;; #t
+ ;; (if (> (current-seconds) expire-time)
+ ;; (begin
+ ;; (debug:print-info 0 *default-log-port* "Timed out waiting for a lock to clean test with id " test-id)
+ ;; (rmt:no-sync-del! lock-key) ;; destroy the lock
+ ;; (loop (rmt:no-sync-get-lock lock-key) expire-time)) ;;
+ ;; (begin
+ ;; (thread-sleep! 1)
+ ;; (loop (rmt:no-sync-get-lock lock-key) expire-time)))))))
+ )
+ (case clean-mode
+ ((remove-data-only)(mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) "CLEANING" "LOCKED" #f))
+ ((remove-all) (mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) "REMOVING" "LOCKED" #f))
+ ((archive-remove) (mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) "ARCHIVE_REMOVING" #f #f)))
+ (debug:print-info 1 *default-log-port* "Attempting to remove " (if real-dir (conc " dir " real-dir " and ") "") " link " run-dir)
+ (if (and real-dir
+ (> (string-length real-dir) 5)
+ (common:file-exists? real-dir)) ;; bad heuristic but should prevent /tmp /home etc.
+ (let* ((realpath (resolve-pathname run-dir)))
+ (debug:print-info 1 *default-log-port* "Recursively removing " realpath)
+ (if (common:file-exists? realpath)
+ (runs:safe-delete-test-dir realpath)
+ (debug:print 0 *default-log-port* "WARNING: test dir " realpath " appears to not exist or is not readable")))
+ (if real-dir
+ (debug:print 0 *default-log-port* "WARNING: directory " real-dir " does not exist")
+ (debug:print 0 *default-log-port* "WARNING: no real directory corrosponding to link " run-dir ", nothing done")))
+ (if (symbolic-link? run-dir)
+ (begin
+ (debug:print-info 1 *default-log-port* "Removing symlink " run-dir)
+ (handle-exceptions
+ exn
+ (debug:print-error 0 *default-log-port* " Failed to remove symlink " run-dir ((condition-property-accessor 'exn 'message) exn) ", attempting to continue, exn=" exn)
+ (delete-file run-dir)))
+ (if (directory? run-dir)
+ (if (> (directory-fold (lambda (f x)(+ 1 x)) 0 run-dir) 0)
+ (debug:print 0 *default-log-port* "WARNING: refusing to remove " run-dir " as it is not empty")
+ (handle-exceptions
+ exn
+ (debug:print-error 0 *default-log-port* " Failed to remove directory " run-dir ((condition-property-accessor 'exn 'message) exn) ", attempting to continue, exn=" exn)
+ (delete-directory run-dir)))
+ (if (and run-dir
+ (not (member run-dir (list "n/a" "/tmp/badname"))))
+ (debug:print 0 *default-log-port* "WARNING: not removing " run-dir " as it either doesn't exist or is not a symlink")
+ (debug:print 0 *default-log-port* "NOTE: the run dir for this test is undefined. Test may have already been deleted."))
+ ))
+ ;; Only delete the records *after* removing the directory. If things fail we have a record
+ (case clean-mode
+ ((remove-data-only)(mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) (db:test-get-state test)(db:test-get-status test) #f))
+ ((archive-remove) (mt:test-set-state-status-by-id (db:test-get-run_id test)(db:test-get-id test) "ARCHIVED" #f #f))
+ (else (rmt:delete-test-records (db:test-get-run_id test) (db:test-get-id test))))
+ ;; (rmt:no-sync-del! lock-key)
+ ))
+
+;;======================================================================
+;; Routines for manipulating runs
+;;======================================================================
+
+;; Since many calls to a run require pretty much the same setup
+;; this wrapper is used to reduce the replication of code
+(define (general-run-call switchname action-desc proc)
+ (let ((runname (common:args-get-runname))
+ (target (common:args-get-target)))
+ (cond
+ ((not target)
+ (debug:print-error 0 *default-log-port* "Missing required parameter for " switchname ", you must specify the target with -target")
+ (exit 3))
+ ((not runname)
+ (debug:print-error 0 *default-log-port* "Missing required parameter for " switchname ", you must specify the run name with -runname runname")
+ (exit 3))
+ (else
+ (let (;; (db #f)
+ (keys #f))
+ (if (launch:setup)
+ (begin
+ (full-runconfigs-read) ;; cache the run config
+ ;; (launch:cache-config) ;; there are two independent config cache locations, turning this one off for now. MRW.
+ ) ;; do not cache here - need to be sure runconfigs is processed
+ (begin
+ (debug:print 0 *default-log-port* "Failed to setup, exiting")
+ (exit 1)))
+
+
+ (set! keys (keys:config-get-fields *configdat*))
+ ;; have enough to process -target or -reqtarg here
+ (if (args:get-arg "-reqtarg")
+ (let* ((runconfigf (conc *toppath* "/runconfigs.config")) ;; DO NOT EVALUATE ALL
+ (runconfig (read-config runconfigf #f #t environ-patt: #f)))
+ (if (hash-table-ref/default runconfig (args:get-arg "-reqtarg") #f)
+ (keys:target-set-args keys (args:get-arg "-reqtarg") args:arg-hash)
+
+ (begin
+ (debug:print-error 0 *default-log-port* "[" (args:get-arg "-reqtarg") "] not found in " runconfigf)
+ ;; (if db (sqlite3:finalize! db))
+ (exit 1)
+ )))
+ (if (args:get-arg "-target")
+ (keys:target-set-args keys (args:get-arg "-target" args:arg-hash) args:arg-hash)))
+ (if (not (car *configinfo*))
+ (begin
+ (debug:print-error 0 *default-log-port* "Attempted to " action-desc " but run area config file not found")
+ (exit 1))
+ ;; Extract out stuff needed in most or many calls
+ ;; here then call proc
+ (let* ((keyvals (keys:target->keyval keys target)))
+ (proc target runname keys keyvals)))
+ ;; (if db (sqlite3:finalize! db))
+ (set! *didsomething* #t))))))
+
+;;======================================================================
+;; Lock/unlock runs
+;;======================================================================
+
+(define (runs:handle-locking target keys runname lock unlock user)
+ (let* ((db #f)
+ (rundat (mt:get-runs-by-patt keys runname target))
+ (header (vector-ref rundat 0))
+ (runs (vector-ref rundat 1)))
+ (for-each (lambda (run)
+ (let ((run-id (db:get-value-by-header run header "id"))
+ (str (if lock
+ "lock"
+ "unlock")))
+ (if (or lock
+ (and unlock
+ (or (args:get-arg "-force")
+ (begin
+ (print "Do you really wish to unlock run " run-id "?\n y/n: ")
+ (equal? "y" (read-line))))))
+ (begin
+ (rmt:lock/unlock-run run-id lock unlock user)
+ (debug:print-info 0 *default-log-port* "Done " str " on run id " run-id))
+ (debug:print-info 0 *default-log-port* "Skipping lock/unlock on " run-id))))
+ runs)))
+;;======================================================================
+;; Rollup runs
+;;======================================================================
+
+;; Update the test_meta table for this test
+(define (runs:update-test_meta test-name test-conf)
+ (let ((currrecord (rmt:testmeta-get-record test-name)))
+ (if (not currrecord)
+ (begin
+ (set! currrecord (make-vector 11 #f))
+ (rmt:testmeta-add-record test-name)))
+ (for-each
+ (lambda (key)
+ (let* ((idx (cadr key))
+ (fld (car key))
+ (val (configf:lookup test-conf "test_meta" fld)))
+ ;; (debug:print 5 *default-log-port* "idx: " idx " fld: " fld " val: " val)
+ (if (and val (not (equal? (vector-ref currrecord idx) val)))
+ (begin
+ (print "Updating " test-name " " fld " to " val)
+ (rmt:testmeta-update-field test-name fld val)))))
+ '(("author" 2)("owner" 3)("description" 4)("reviewed" 5)("tags" 9)("jobgroup" 10)))))
+
+;; find tests with matching tags, tagpatt is a string "tagpatt1,tagpatt2%, ..."
+;;
+(define (runs:get-tests-matching-tags tagpatt)
+ (let* ((tagdata (rmt:get-tests-tags))
+ (res '())) ;; list of tests that match one or more tags
+ (for-each
+ (lambda (row)
+ (let* ((tag (car row))
+ (tests (cdr row)))
+ (if (patt-list-match tag tagpatt)
+ (set! res (append tests res)))))
+ tagdata)
+ res))
+
+
+;; Update test_meta for all tests
+(define (runs:update-all-test_meta db)
+ (let ((test-names (tests:get-all))) ;; (tests:get-valid-tests)))
+ (for-each
+ (lambda (test-name)
+ (let* ((test-conf (mt:lazy-read-test-config test-name)))
+ (if test-conf (runs:update-test_meta test-name test-conf))))
+ (hash-table-keys test-names))))
+
+;; This could probably be refactored into one complex query ...
+;; NOT PORTED - DO NOT USE YET
+;;
+#;(define (runs:rollup-run keys runname user keyvals)
+ (debug:print 4 *default-log-port* "runs:rollup-run, keys: " keys " -runname " runname " user: " user)
+ (let* ((db #f)
+ ;; register run operates on the main db
+ (new-run-id (rmt:register-run keyvals runname "new" "n/a" user (args:get-arg "-contour")))
+ (prev-tests (rmt:get-matching-previous-test-run-records new-run-id "%" "%"))
+ (curr-tests (mt:get-tests-for-run new-run-id "%/%" '() '()))
+ (curr-tests-hash (make-hash-table)))
+ (rmt:update-run-event_time new-run-id)
+ ;; index the already saved tests by testname and itemdat in curr-tests-hash
+ (for-each
+ (lambda (testdat)
+ (let* ((testname (db:test-get-testname testdat))
+ (item-path (db:test-get-item-path testdat))
+ (full-name (conc testname "/" item-path)))
+ (hash-table-set! curr-tests-hash full-name testdat)))
+ curr-tests)
+ ;; NOPE: Non-optimal approach. Try this instead.
+ ;; 1. tests are received in a list, most recent first
+ ;; 2. replace the rollup test with the new *always*
+ (for-each
+ (lambda (testdat)
+ (let* ((testname (db:test-get-testname testdat))
+ (item-path (db:test-get-item-path testdat))
+ (full-name (conc testname "/" item-path))
+ (prev-test-dat (hash-table-ref/default curr-tests-hash full-name #f))
+ (test-steps (rmt:get-steps-for-test (db:test-get-id testdat)))
+ (new-test-record #f))
+ ;; replace these with insert ... select
+ (apply sqlite3:execute
+ db
+ (conc "INSERT OR REPLACE INTO tests (run_id,testname,state,status,event_time,host,cpuload,diskfree,uname,rundir,item_path,run_duration,final_logf,comment) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);")
+ new-run-id (cddr (vector->list testdat)))
+ (set! new-testdat (car (mt:get-tests-for-run new-run-id (conc testname "/" item-path) '() '())))
+ (hash-table-set! curr-tests-hash full-name new-testdat) ;; this could be confusing, which record should go into the lookup table?
+ ;; Now duplicate the test steps
+ (debug:print 4 *default-log-port* "Copying records in test_steps from test_id=" (db:test-get-id testdat) " to " (db:test-get-id new-testdat))
+ (cdb:remote-run ;; to be replaced, note: this routine is not used currently
+ (lambda ()
+ (sqlite3:execute
+ db
+ (conc "INSERT OR REPLACE INTO test_steps (test_id,stepname,state,status,event_time,comment) "
+ "SELECT " (db:test-get-id new-testdat) ",stepname,state,status,event_time,comment FROM test_steps WHERE test_id=?;")
+ (db:test-get-id testdat))
+ ;; Now duplicate the test data
+ (debug:print 4 *default-log-port* "Copying records in test_data from test_id=" (db:test-get-id testdat) " to " (db:test-get-id new-testdat))
+ (sqlite3:execute
+ db
+ (conc "INSERT OR REPLACE INTO test_data (test_id,category,variable,value,expected,tol,units,comment) "
+ "SELECT " (db:test-get-id new-testdat) ",category,variable,value,expected,tol,units,comment FROM test_data WHERE test_id=?;")
+ (db:test-get-id testdat))))
+ ))
+ prev-tests)))
+
+(define doc-template
+ '(*TOP*
+ (*PI* xml "version='1.0'")
+ (testsuite)))
+
+(define (runs:update-junit-test-reporter-xml run-id)
+ (let* (
+ (junit-test-reporter (configf:lookup *configdat* "runs" "junit-test-reporter-xml"))
+ (junit-test-report-dir (configf:lookup *configdat* "runs" "junit-test-report-dir"))
+ (xml-dir (if (and junit-test-reporter (equal? junit-test-reporter "yes" ))
+ (if junit-test-report-dir
+ junit-test-report-dir
+ (conc (getenv "MT_LINKTREE") "/" (getenv "MT_TARGET") "/" (getenv "MT_RUNNAME")))
+ #f))
+ (xml-ts-name (if xml-dir
+ (conc (getenv "MT_TESTSUITENAME")"."(string-translate (getenv "MT_TARGET") "/" ".") "." (getenv "MT_RUNNAME"))
+ #f))
+ (keyname (if xml-ts-name (common:get-signature xml-ts-name) #f))
+ (xml-path (if xml-dir
+ (conc xml-dir "/" keyname ".xml")
+ #f))
+
+ (test-data (if xml-dir
+ (rmt:get-tests-for-run run-id "%" '() '() ;; run-id testpatt states statuses
+ #f #f ;; offset limit
+ #f ;; not-in
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; get full data (not 'shortlist)
+ 0 ;; (runs:gendat-inc-results-last-update *runs:general-data*) ;; last update time
+ #f)
+ '()))
+ (tests-count (if xml-dir (length test-data) #f)))
+ (if (and junit-test-reporter (equal? junit-test-reporter "yes" ))
+ (begin
+ ;((sxml-modify! `("testsuite" insert-into (@ (name ,xml-ts-name) (tests ,tests-count)))) doc)
+
+ (let loop ((test (car test-data))
+ (tail (cdr test-data))
+ (doc doc-template)
+ (fail-cnt 0)
+ (error-cnt 0))
+ (let* ((test-name (vector-ref test 2))
+ (test-itempath (vector-ref test 11))
+ (tc-name (conc test-name (if (and test-itempath (not (equal? test-itempath ""))) (conc "." (string-translate test-itempath "/" "." )) "")))
+ (test-state (vector-ref test 3))
+ (comment (vector-ref test 14))
+ (test-status (vector-ref test 4))
+ (exc-msg (conc "No bucket for State " test-state " Status " test-status))
+ (new-doc (cond
+ ((member test-state (list "RUNNING" ))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name)) (inProgress)))) doc))
+ ((member test-state (list "LAUNCHED" "REMOTEHOSTSTART" "NOT_STARTED"))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name)) (inQueue)))) doc))
+ ((member test-status (list "PASS" "WARN" "WAIVED"))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name))))) doc))
+ ((member test-status (list "FAIL" "CHECK"))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name)) (failure (@ (message ,comment) (type "failure")))))) doc))
+ ((member test-status (list "DEAD" "KILLED" "ABORT" "PREQ_FAIL" "PREQ_DISCARDED"))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name)) (failure (@ (message ,comment) (type "error")))))) doc))
+ ((member test-status (list "SKIP"))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name)) (skipped (@ (type "skipped")))))) doc))
+ (else
+ (debug:print 0 *default-log-port* (conc "What do I do with State " test-state " Status " test-status))
+ ((sxml-modify `("testsuite" insert-into (testcase (@ (name ,tc-name)) (failure (@ (message ,exc-msg) (type "error")))))) doc))))
+ (new-error-cnt (if (member test-status (list "DEAD" "KILLED" "ABORT" "PREQ_FAIL" "PREQ_DISCARDED"))
+ (+ error-cnt 1)
+ error-cnt))
+ (new-fail-cnt (if (member test-status (list "FAIL" "CHECK"))
+ (+ fail-cnt 1)
+ fail-cnt)))
+ (if (null? tail)
+ (let* ((final-doc ((sxml-modify `("testsuite" insert-into (@ (name ,xml-ts-name) (tests ,tests-count) (errors ,error-cnt) (failures ,fail-cnt)))) new-doc)))
+ (debug:print 0 *default-log-port* "modify attrib error=" error-cnt " fail= " fail-cnt)
+ (handle-exceptions
+ exn
+ (let* ((msg ((condition-property-accessor 'exn 'message) exn)))
+ (debug:print 0 *default-log-port* (conc "WARNING: Failed to update file" xml-path". Message:" msg ", exn=" exn)))
+
+ (if (not (file-exists? xml-dir))
+ (create-directory xml-dir #t))
+ (if (not (rmt:no-sync-get/default keyname #f))
+ (begin
+ (rmt:no-sync-set keyname "on")
+ (debug:print 0 *default-log-port* "creating xml at " xml-path)
+ (with-output-to-file xml-path
+ (lambda ()
+ (print (sxml-serializer#serialize-sxml final-doc ns-prefixes: (list (cons 'gnm "http://foo"))))))
+ (rmt:no-sync-del! keyname))
+ (debug:print 0 *default-log-port* "Could not get the lock. Skip writing the xml file."))))
+ (loop (car tail) (cdr tail) new-doc new-fail-cnt new-error-cnt))))))))
+
+
+;; clean cache files
+(define (runs:clean-cache target runname toppath)
+ (if target
+ (if runname
+ (let* ((linktree (common:get-linktree)) ;; (if toppath (configf:lookup *configdat* "setup" "linktree")))
+ (runtop (conc linktree "/" target "/" runname))
+ (files (if (common:file-exists? runtop)
+ (append (glob (conc runtop "/.megatest*"))
+ (glob (conc runtop "/.runconfig*")))
+ '())))
+ (if (null? files)
+ (debug:print-info 0 *default-log-port* "No cached megatest or runconfigs files found. None removed.")
+ (begin
+ (debug:print-info 0 *default-log-port* "Removing cached files:\n " (string-intersperse files "\n "))
+ (for-each
+ (lambda (f)
+ (handle-exceptions
+ exn
+ (debug:print 0 *default-log-port* "WARNING: Failed to remove file " f ", exn=" exn)
+ (delete-file f)))
+ files))))
+ (debug:print-error 0 *default-log-port* "-clean-cache requires -runname."))
+ (debug:print-error 0 *default-log-port* "-clean-cache requires -target or -reqtarg")))
+
+
+;;======================================================================
+;; escaping dependecy challenges - moves some tasks stuff here
+;;======================================================================
+
+;; kill any runner processes (i.e. processes handling -runtests) that match target/runname
+;;
+;; do a remote call to get the task queue info but do the killing as self here.
+;;
+(define (tasks:kill-runner target run-name testpatt)
+ (let ((records (rmt:tasks-find-task-queue-records target run-name testpatt "running" "run-tests"))
+ (hostpid-rx (regexp "\\s+(\\w+)\\s+(\\d+)$"))) ;; host pid is at end of param string
+ (if (null? records)
+ (debug:print 0 *default-log-port* "No run launching processes found for " target " / " run-name " with testpatt " (or testpatt "* no testpatt specified! *"))
+ (debug:print 0 *default-log-port* "Found " (length records) " run(s) to kill."))
+ (for-each
+ (lambda (record)
+ (let* ((param-key (list-ref record 8))
+ (match-dat (string-search hostpid-rx param-key)))
+ (if match-dat
+ (let ((hostname (cadr match-dat))
+ (pid (string->number (caddr match-dat))))
+ (debug:print 0 *default-log-port* "Sending SIGINT to process " pid " on host " hostname)
+ (if (equal? (get-host-name) hostname)
+ (if (process:alive? pid)
+ (begin
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "Kill of process " pid " on host " hostname " failed.")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ #t)
+ (process-signal pid signal/int)
+ (thread-sleep! 5)
+ (if (process:alive? pid)
+ (process-signal pid signal/kill)))))
+ ;; (call-with-environment-variables
+ (let ((old-targethost (getenv "TARGETHOST")))
+ (setenv "TARGETHOST" hostname)
+ (setenv "TARGETHOST_LOGF" "server-kills.log")
+ (system (conc "nbfake kill " pid))
+ (if old-targethost (setenv "TARGETHOST" old-targethost))
+ (unsetenv "TARGETHOST")
+ (unsetenv "TARGETHOST_LOGF"))))
+ (debug:print-error 0 *default-log-port* "no record or improper record for " target "/" run-name " in tasks_queue in main.db"))))
+ records)))
+
+(define (task:get-run-times)
+ (let* (
+ (run-patt (if (args:get-arg "-run-patt")
+ (args:get-arg "-run-patt")
+ "%"))
+ (target-patt (if (args:get-arg "-target-patt")
+ (args:get-arg "-target-patt")
+ "%"))
+
+ (run-times (rmt:get-run-times run-patt target-patt )))
+ (if (eq? (length run-times) 0)
+ (begin
+ (print "Data not found!!")
+ (exit)))
+ (if (equal? (args:get-arg "-dumpmode") "json")
+ (task:print-runtime-as-json run-times)
+ (if (equal? (args:get-arg "-dumpmode") "csv")
+ (task:print-runtime run-times ",")
+ (task:print-runtime run-times " ")))))
+
+(define (task:get-test-times)
+ (let* ((runname (if (args:get-arg "-runname")
+ (args:get-arg "-runname")
+ #f))
+ (target (if (args:get-arg "-target")
+ (args:get-arg "-target")
+ #f))
+
+ (test-times (rmt:get-test-times runname target )))
+ (if (not runname)
+ (begin
+ (print "Error: Missing argument -runname")
+ (exit)))
+ (if (string-contains runname "%")
+ (begin
+ (print "Error: Invalid runname, '%' not allowed (" runname ") ")
+ (exit)))
+ (if (not target)
+ (begin
+ (print "Error: Missing argument -target")
+ (exit)))
+ (if (string-contains target "%")
+ (begin
+ (print "Error: Invalid target, '%' not allowed (" target ") ")
+ (exit)))
+
+ (if (eq? (length test-times) 0)
+ (begin
+ (print "Data not found!!")
+ (exit)))
+ (if (equal? (args:get-arg "-dumpmode") "json")
+ (task:print-testtime-as-json test-times)
+ (if (equal? (args:get-arg "-dumpmode") "csv")
+ (task:print-testtime test-times ",")
+ (task:print-testtime test-times " ")))))
+
+
+;; gets mtpg-run-id and syncs the record if different
+;;
+(define (tasks:run-id->mtpg-run-id dbh cached-info run-id area-info smallest-last-update-time)
+ (let* ((runs-ht (hash-table-ref cached-info 'runs))
+ (runinf (hash-table-ref/default runs-ht run-id #f))
+ (area-id (vector-ref area-info 0)))
+ (if runinf
+ runinf ;; already cached
+ (let* ((run-dat (rmt:get-run-info run-id)) ;; NOTE: get-run-info returns a vector < row header >
+ (run-name (rmt:get-run-name-from-id run-id))
+ (row (db:get-rows run-dat)) ;; yes, this returns a single row
+ (header (db:get-header run-dat))
+ (state (db:get-value-by-header row header "state"))
+ (status (db:get-value-by-header row header "status"))
+ (owner (db:get-value-by-header row header "owner"))
+ (event-time (db:get-value-by-header row header "event_time"))
+ (comment (db:get-value-by-header row header "comment"))
+ (fail-count (db:get-value-by-header row header "fail_count"))
+ (pass-count (db:get-value-by-header row header "pass_count"))
+ (db-contour (db:get-value-by-header row header "contour"))
+ (contour (if (args:get-arg "-prepend-contour")
+ (if (and db-contour (not (equal? db-contour "")) (string? db-contour ))
+ (begin
+ (debug:print-info 10 *default-log-port* "db-contour" db-contour)
+ db-contour)
+ (args:get-arg "-contour"))))
+ (run-tag (if (args:get-arg "-run-tag")
+ (args:get-arg "-run-tag")
+ ""))
+ (last-update (db:get-value-by-header row header "last_update"))
+ (keytarg (if (or (args:get-arg "-prepend-contour") (args:get-arg "-prefix-target"))
+ (conc "MT_CONTOUR/MT_AREA/" (string-intersperse (rmt:get-keys) "/")) (string-intersperse (rmt:get-keys) "/"))) ;; e.g. version/iteration/platform
+ (base-target (rmt:get-target run-id))
+ (target (if (or (args:get-arg "-prepend-contour") (args:get-arg "-prefix-target"))
+ (conc (or (args:get-arg "-prefix-target") (conc contour "/" (common:get-area-name) "/")) base-target) base-target)) ;; e.g. v1.63/a3e1/ubuntu
+ (spec-id (pgdb:get-ttype dbh keytarg))
+ (publish-time (if (args:get-arg "-cp-eventtime-to-publishtime")
+ event-time
+ (current-seconds)))
+ (new-run-id (if (and run-name base-target) (pgdb:get-run-id dbh spec-id target run-name area-id) #f)))
+ (if new-run-id
+ (begin ;; let ((run-record (pgdb:get-run-info dbh new-run-id))
+ (hash-table-set! runs-ht run-id new-run-id)
+ ;; ensure key fields are up to date
+ ;; if last_update == pgdb_last_update do not update smallest-last-update-time
+ (let* ((pgdb-last-update (pgdb:get-run-last-update dbh new-run-id))
+ (smallest-time (hash-table-ref/default smallest-last-update-time "smallest-time" #f)))
+ (if (and (> last-update pgdb-last-update) (or (not smallest-time) (< last-update smallest-time)))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update)))
+ (pgdb:refresh-run-info
+ dbh
+ new-run-id
+ state status owner event-time comment fail-count pass-count area-id last-update publish-time)
+ (debug:print-info 4 *default-log-port* "Working on run-id " run-id " pgdb-id " new-run-id )
+ (if (not (equal? run-tag ""))
+ (task:add-run-tag dbh new-run-id run-tag))
+ new-run-id)
+
+ (if (or (not state) (equal? state "deleted"))
+ (begin
+ (debug:print-info 1 *default-log-port* "Warning: Run with id " run-id " was created after previous sync and deleted before the sync") #f)
+ (if (handle-exceptions
+ exn
+ (begin (print-call-chain)
+ (print ((condition-property-accessor 'exn 'message) exn))
+ #f)
+
+ (pgdb:insert-run
+ dbh
+ spec-id target run-name state status owner event-time comment fail-count pass-count area-id last-update publish-time))
+ (let* ((smallest-time (hash-table-ref/default smallest-last-update-time "smallest-time" #f)))
+ (if (or (not smallest-time) (< last-update smallest-time))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update))
+ (tasks:run-id->mtpg-run-id dbh cached-info run-id area-info smallest-last-update-time))
+ #f)))))))
+(define (tasks:sync-test-steps dbh cached-info test-step-ids smallest-last-update-time)
+ ; (print "Sync Steps " test-step-ids )
+ (let ((test-ht (hash-table-ref cached-info 'tests))
+ (step-ht (hash-table-ref cached-info 'steps)))
+ (for-each
+ (lambda (test-step-id)
+ (let* ((test-step-info (rmt:get-steps-info-by-id test-step-id))
+ (step-id (tdb:step-get-id test-step-info))
+ (test-id (tdb:step-get-test_id test-step-info))
+ (stepname (tdb:step-get-stepname test-step-info))
+ (state (tdb:step-get-state test-step-info))
+ (status (tdb:step-get-status test-step-info))
+ (event_time (tdb:step-get-event_time test-step-info))
+ (comment (tdb:step-get-comment test-step-info))
+ (logfile (tdb:step-get-logfile test-step-info))
+ (last-update (tdb:step-get-last_update test-step-info))
+ (pgdb-test-id (hash-table-ref/default test-ht test-id #f))
+ (smallest-time (hash-table-ref/default smallest-last-update-time "smallest-time" #f))
+ (pgdb-step-id (if pgdb-test-id
+ (pgdb:get-test-step-id dbh pgdb-test-id stepname state)
+ #f)))
+ (if step-id
+ (begin
+ (if pgdb-test-id
+ (begin
+ (if pgdb-step-id
+ (begin
+ (debug:print-info 4 *default-log-port* "Updating existing test-step with test-id: " test-id " and step-id " step-id " pgdb test id: " pgdb-test-id " pgdb step id " pgdb-step-id )
+ (let* ((pgdb-last-update (pgdb:get-test-step-last-update dbh pgdb-step-id)))
+ (if (and (> last-update pgdb-last-update) (or (not smallest-time) (< last-update smallest-time)))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update)))
+ (pgdb:update-test-step dbh pgdb-step-id pgdb-test-id stepname state status event_time comment logfile last-update))
+ (begin
+ (debug:print-info 4 *default-log-port* "Inserting test-step with test-id: " test-id " and step-id " step-id " pgdb test id: " pgdb-test-id)
+ (if (or (not smallest-time) (< last-update smallest-time))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update))
+ (pgdb:insert-test-step dbh pgdb-test-id stepname state status event_time comment logfile last-update )
+ (set! pgdb-step-id (pgdb:get-test-step-id dbh pgdb-test-id stepname state))))
+ (hash-table-set! step-ht step-id pgdb-step-id ))
+ (debug:print-info 1 *default-log-port* "Error: Test not cashed")))
+ (debug:print-info 1 *default-log-port* "Error: Could not get test step info for step id " test-step-id )))) ;; this is a wierd senario need to debug
+ test-step-ids)))
+
+(define (tasks:sync-test-gen-data dbh cached-info test-data-ids smallest-last-update-time)
+ (let ((test-ht (hash-table-ref cached-info 'tests))
+ (data-ht (hash-table-ref cached-info 'data)))
+ (for-each
+ (lambda (test-data-id)
+ (let* ((test-data-info (rmt:get-data-info-by-id test-data-id))
+ (data-id (db:test-data-get-id test-data-info))
+ (test-id (db:test-data-get-test_id test-data-info))
+ (category (db:test-data-get-category test-data-info))
+ (variable (db:test-data-get-variable test-data-info))
+ (value (db:test-data-get-value test-data-info))
+ (expected (db:test-data-get-expected test-data-info))
+ (tol (db:test-data-get-tol test-data-info))
+ (units (db:test-data-get-units test-data-info))
+ (comment (db:test-data-get-comment test-data-info))
+ (status (db:test-data-get-status test-data-info))
+ (type (db:test-data-get-type test-data-info))
+ (last-update (db:test-data-get-last_update test-data-info))
+ (smallest-time (hash-table-ref/default smallest-last-update-time "smallest-time" #f))
+
+ (pgdb-test-id (hash-table-ref/default test-ht test-id #f))
+ (pgdb-data-id (if pgdb-test-id
+ (pgdb:get-test-data-id dbh pgdb-test-id category variable)
+ #f)))
+ (if data-id
+ (begin
+ (if pgdb-test-id
+ (begin
+ (if pgdb-data-id
+ (begin
+ (debug:print-info 4 *default-log-port* "Updating existing test-data with test-id: " test-id " and data-id " data-id " pgdb test id: " pgdb-test-id " pgdb data id " pgdb-data-id)
+ (let* ((pgdb-last-update (pgdb:get-test-data-last-update dbh pgdb-data-id)))
+ (if (and (> last-update pgdb-last-update) (or (not smallest-time) (< last-update smallest-time)))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update)))
+ (pgdb:update-test-data dbh pgdb-data-id pgdb-test-id category variable value expected tol units comment status type last-update))
+ (begin
+ (debug:print-info 4 *default-log-port* "Inserting test-data with test-id: " test-id " and data-id " data-id " pgdb test id: " pgdb-test-id)
+ (if (handle-exceptions
+ exn
+ (begin (print-call-chain)
+ (print ((condition-property-accessor 'exn 'message) exn))
+ #f)
+
+ (pgdb:insert-test-data dbh pgdb-test-id category variable value expected tol units comment status type last-update))
+ ;(tasks:run-id->mtpg-run-id dbh cached-info run-id area-info)
+ (begin
+ ;(pgdb:insert-test-data dbh pgdb-test-id category variable value expected tol units comment status type )
+ (if (or (not smallest-time) (< last-update smallest-time))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update))
+ (set! pgdb-data-id (pgdb:get-test-data-id dbh pgdb-test-id category variable)))
+ #f)))
+ (hash-table-set! data-ht data-id pgdb-data-id ))
+ (begin
+ (debug:print-info 1 *default-log-port* "Error: Test not in pgdb"))))
+
+ (debug:print-info 1 *default-log-port* "Error: Could not get test data info for data id " test-data-id )))) ;; this is a wierd senario need to debug
+ test-data-ids)))
+
+
+
+(define (tasks:sync-tests-data dbh cached-info test-ids area-info smallest-last-update-time)
+ (let ((test-ht (hash-table-ref cached-info 'tests)))
+ (for-each
+ (lambda (test-id)
+ ; (print test-id)
+ (let* ((test-info (rmt:get-test-info-by-id #f test-id))
+ (run-id (db:test-get-run_id test-info)) ;; look these up in db_records.scm
+ (test-id (db:test-get-id test-info))
+ (test-name (db:test-get-testname test-info))
+ (item-path (db:test-get-item-path test-info))
+ (state (db:test-get-state test-info))
+ (status (db:test-get-status test-info))
+ (host (db:test-get-host test-info))
+ (pid (db:test-get-process_id test-info))
+ (cpuload (db:test-get-cpuload test-info))
+ (diskfree (db:test-get-diskfree test-info))
+ (uname (db:test-get-uname test-info))
+ (run-dir (db:test-get-rundir test-info))
+ (log-file (db:test-get-final_logf test-info))
+ (run-duration (db:test-get-run_duration test-info))
+ (comment (db:test-get-comment test-info))
+ (event-time (db:test-get-event_time test-info))
+ (archived (db:test-get-archived test-info))
+ (last-update (db:test-get-last_update test-info))
+ (pgdb-run-id (tasks:run-id->mtpg-run-id dbh cached-info run-id area-info smallest-last-update-time))
+ (smallest-time (hash-table-ref/default smallest-last-update-time "smallest-time" #f))
+ (pgdb-test-id (if pgdb-run-id
+ (begin
+ ;(print pgdb-run-id)
+ (pgdb:get-test-id dbh pgdb-run-id test-name item-path))
+ #f)))
+ ;; "id" "run_id" "testname" "state" "status" "event_time"
+ ;; "host" "cpuload" "diskfree" "uname" "rundir" "item_path"
+ ;; "run_duration" "final_logf" "comment" "shortdir" "attemptnum" "archived"
+ (if (or (not item-path) (string-null? item-path))
+ (debug:print-info 0 *default-log-port* "Working on Run id : " run-id "and test name : " test-name))
+ (if pgdb-run-id
+ (begin
+ (if pgdb-test-id ;; have a record
+ (begin ;; let ((key-name (conc run-id "/" test-name "/" item-path)))
+ (debug:print-info 4 *default-log-port* "Updating existing test with run-id: " run-id " and test-id: " test-id " pgdb run id: " pgdb-run-id " pgdb-test-id " pgdb-test-id)
+ (let* ((pgdb-last-update (pgdb:get-test-last-update dbh pgdb-test-id)))
+ (if (and (> last-update pgdb-last-update) (or (not smallest-time) (< last-update smallest-time))) ;;if last-update is same as pgdb-last-update then it is safe to assume the records are identical and we can use a larger last update time.
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update)))
+ (pgdb:update-test dbh pgdb-test-id pgdb-run-id test-name item-path state status host cpuload diskfree uname run-dir log-file run-duration comment event-time archived last-update pid))
+ (begin
+ (debug:print-info 4 *default-log-port* "Inserting test with run-id: " run-id " and test-id: " test-id " pgdb run id: " pgdb-run-id)
+ (pgdb:insert-test dbh pgdb-run-id test-name item-path state status host cpuload diskfree uname run-dir log-file run-duration comment event-time archived last-update pid)
+ (if (or (not smallest-time) (< last-update smallest-time))
+ (hash-table-set! smallest-last-update-time "smallest-time" last-update))
+ (set! pgdb-test-id (pgdb:get-test-id dbh pgdb-run-id test-name item-path))))
+ (hash-table-set! test-ht test-id pgdb-test-id))
+ (debug:print-info 1 *default-log-port* "WARNING: Skipping run with run-id:" run-id ". This run was created after privious sync and removed before this sync."))))
+ test-ids)))
+
+
+;; get runs changed since last sync
+;; (define (tasks:sync-test-data dbh cached-info area-info)
+;; (let* ((
+
+(define (tasks:sync-to-postgres configdat dest)
+ (print "In sync")
+ (let* ((dbh (pgdb:open configdat dbname: dest))
+ (area-info (pgdb:get-area-by-path dbh *toppath*))
+ (cached-info (make-hash-table))
+ (start (current-seconds))
+ (test-patt (if (args:get-arg "-testpatt")
+ (args:get-arg "-testpatt")
+ "%"))
+ (target (if (args:get-arg "-target")
+ (args:get-arg "-target")
+ #f))
+ (run-name (if (args:get-arg "-runname")
+ (args:get-arg "-runname")
+ #f)))
+ (if (and target (not run-name))
+ (begin
+ (print "Error: Provide runname")
+ (exit 1)))
+ (if (and (not target) run-name)
+ (begin
+ (print "Error: Provide target")
+ (exit 1)))
+ ;(print "123")
+ ;(exit 1)
+ (for-each (lambda (dtype)
+ (hash-table-set! cached-info dtype (make-hash-table)))
+ '(runs targets tests steps data))
+ (hash-table-set! cached-info 'start start) ;; when done we'll set sync times to this
+ (if area-info
+ (let* ((last-sync-time (vector-ref area-info 3))
+ (smallest-last-update-time (make-hash-table))
+ (changed (if (and target run-name)
+ (rmt:get-run-record-ids target run-name (rmt:get-keys) test-patt)
+ (rmt:get-changed-record-ids last-sync-time)))
+ (run-ids (alist-ref 'runs changed))
+ (test-ids (alist-ref 'tests changed))
+ (test-step-ids (alist-ref 'test_steps changed))
+ (test-data-ids (alist-ref 'test_data changed))
+ (run-stat-ids (alist-ref 'run_stats changed))
+ (area-tag (if (args:get-arg "-area-tag")
+ (args:get-arg "-area-tag")
+ (if (args:get-arg "-area")
+ (args:get-arg "-area")
+ ""))))
+ (if (and (equal? area-tag "") (not (pgdb:is-area-taged dbh (vector-ref area-info 0))))
+ (set! area-tag *default-area-tag*))
+ (if (not (equal? area-tag ""))
+ (task:add-area-tag dbh area-info area-tag))
+ (if (or (not (null? test-ids)) (not (null? run-ids)))
+ (begin
+ (debug:print-info 0 *default-log-port* "syncing runs")
+ (tasks:sync-run-data dbh cached-info run-ids area-info smallest-last-update-time)
+ (debug:print-info 0 *default-log-port* "syncing tests")
+ (tasks:sync-tests-data dbh cached-info test-ids area-info smallest-last-update-time)
+ (debug:print-info 0 *default-log-port* "syncing test steps")
+ (tasks:sync-test-steps dbh cached-info test-step-ids smallest-last-update-time)
+ (debug:print-info 0 *default-log-port* "syncing test data")
+ (tasks:sync-test-gen-data dbh cached-info test-data-ids smallest-last-update-time)
+ (print "----------done---------------")))
+ (let* ((smallest-time (hash-table-ref/default smallest-last-update-time "smallest-time" (current-seconds))))
+ (debug:print-info 0 "smallest-time :" smallest-time " last-sync-time " last-sync-time)
+ (if (not (and target run-name))
+ (if (or (and smallest-time (> smallest-time last-sync-time)) (and smallest-time (eq? last-sync-time 0)))
+ (pgdb:write-sync-time dbh area-info smallest-time))))) ;;this needs to be changed
+ (if (tasks:set-area dbh configdat)
+ (tasks:sync-to-postgres configdat dest)
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: unable to create an area record")
+ #f)))))
+
+(define (tasks:sync-run-data dbh cached-info run-ids area-info smallest-last-update-time)
+ (for-each
+ (lambda (run-id)
+ (debug:print-info 4 *default-log-port* "Check if run with " run-id " needs to be synced" )
+ (tasks:run-id->mtpg-run-id dbh cached-info run-id area-info smallest-last-update-time))
+run-ids))
+
ADDED attic_modular/sdb.scm
Index: attic_modular/sdb.scm
==================================================================
--- /dev/null
+++ attic_modular/sdb.scm
@@ -0,0 +1,116 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+
+;;======================================================================
+
+;;======================================================================
+;; Simple persistant strings lookup table. Keep out of the main db
+;; so writes/reads don't slow down central access.
+;;======================================================================
+
+(require-extension (srfi 18) extras)
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 csv-xml s11n md5 message-digest base64)
+(import (prefix sqlite3 sqlite3:))
+(import (prefix base64 base64:))
+
+(declare (unit sdb))
+
+;;
+(define (sdb:open fname)
+ (let* ((dbpath (pathname-directory fname))
+ (dbexists (let ((fe (common:file-exists? fname)))
+ (if fe
+ fe
+ (begin
+ (create-directory dbpath #t)
+ #f))))
+ (sdb (sqlite3:open-database fname))
+ (handler (make-busy-timeout 136000)))
+ (sqlite3:set-busy-handler! sdb handler)
+ (if (not dbexists)
+ (sdb:initialize sdb))
+ (sqlite3:execute sdb "PRAGMA synchronous = 1;")
+ sdb))
+
+(define (sdb:initialize sdb)
+ (sqlite3:execute sdb "CREATE TABLE IF NOT EXISTS strs
+ (id INTEGER PRIMARY KEY,
+ str TEXT,
+ CONSTRAINT str UNIQUE (str));")
+ (sqlite3:execute sdb "CREATE INDEX IF NOT EXISTS strindx ON strs (str);"))
+
+;; (define sumup (let ((a 0))(lambda (x)(set! a (+ x a)) a)))
+
+(define (sdb:register-string sdb str)
+ (sqlite3:execute sdb "INSERT OR IGNORE INTO strs (str) VALUES (?);" str))
+
+(define (sdb:string->id sdb str-cache str)
+ (let ((id (hash-table-ref/default str-cache str #f)))
+ (if (not id)
+ (sqlite3:for-each-row
+ (lambda (sid)
+ (set! id sid)
+ (hash-table-set! str-cache str id))
+ sdb
+ "SELECT id FROM strs WHERE str=?;" str))
+ id))
+
+(define (sdb:id->string sdb id-cache id)
+ (let ((str (hash-table-ref/default id-cache id #f)))
+ (if (not str)
+ (sqlite3:for-each-row
+ (lambda (istr)
+ (set! str istr)
+ (hash-table-set! id-cache id str))
+ sdb
+ "SELECT str FROM strs WHERE id=?;" id))
+ str))
+
+;; Numbers get passed though in both directions
+;;
+(define (make-sdb:qry fname)
+ (let ((sdb #f)
+ (scache (make-hash-table))
+ (icache (make-hash-table)))
+ (lambda (cmd var)
+ (case cmd
+ ((setup) (set! sdb (if (not sdb)
+ (sdb:open (if var var fname)))))
+ ((setdb) (set! sdb var))
+ ((getdb) sdb)
+ ((finalize) (if sdb
+ (begin
+ (sqlite3:finalize! sdb)
+ (set! sdb #f))))
+ ((getid) (let ((id (if (or (number? var)
+ (string->number var))
+ var
+ (sdb:string->id sdb scache var))))
+ (if id
+ id
+ (begin
+ (sdb:register-string sdb var)
+ (sdb:string->id sdb scache var)))))
+ ((getstr) (if (or (number? var)
+ (string->number var))
+ (sdb:id->string sdb icache var)
+ var))
+ ((passid) var)
+ ((passstr) var)
+ (else #f)))))
+
ADDED attic_modular/serialize-env.scm
Index: attic_modular/serialize-env.scm
==================================================================
--- /dev/null
+++ attic_modular/serialize-env.scm
@@ -0,0 +1,9 @@
+(use z3)
+(use base64)
+
+(let* ((env-str (with-output-to-string (lambda () (pp (get-environment-variables)))))
+ (zipped-env-str (z3:encode-buffer env-str))
+ (b64-env-str (base64-encode zipped-env-str)))
+ (print b64-env-str))
+
+
ADDED attic_modular/server.scm
Index: attic_modular/server.scm
==================================================================
--- /dev/null
+++ attic_modular/server.scm
@@ -0,0 +1,53 @@
+;; 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 .
+;;
+
+(require-extension (srfi 18) extras tcp s11n)
+
+(use srfi-1 posix regex regex-case srfi-69 hostinfo md5 message-digest
+ directory-utils posix-extras matchable)
+
+(use spiffy uri-common intarweb http-client spiffy-request-vars)
+
+(declare (unit server))
+
+;; (declare (uses common))
+;; (declare (uses db))
+;; (declare (uses margsmod))
+;; (import margsmod)
+;;
+;; (declare (uses http-transport))
+;; (declare (uses launch))
+;;
+;; (declare (uses commonmod))
+(declare (uses debugprint))
+;; (import commonmod)
+(import debugprint)
+;;
+;; (declare (uses dbmod))
+;; (import dbmod)
+;;
+;; (declare (uses configfmod))
+;; (import configfmod)
+;;
+;; (declare (uses servermod))
+;; (import servermod)
+;;
+;; (include "common_records.scm")
+;; (include "db_records.scm")
+;;
+;;
ADDED attic_modular/servermod.import.scm
Index: attic_modular/servermod.import.scm
==================================================================
--- /dev/null
+++ attic_modular/servermod.import.scm
@@ -0,0 +1,29 @@
+;;;; servermod.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ files
+ (prefix sqlite3 sqlite3:)
+ posix
+ typed-records
+ srfi-18
+ srfi-1
+ srfi-69
+ srfi-4
+ message-digest
+ hostinfo
+ regex
+ matchable
+ md5
+ commonmod
+ debugprint
+ configfmod
+ dbmod
+ rmtmod))
+(##sys#register-compiled-module 'servermod (list) '() (list) (list))
+
+;; END OF FILE
ADDED attic_modular/servermod.scm
Index: attic_modular/servermod.scm
==================================================================
--- /dev/null
+++ attic_modular/servermod.scm
@@ -0,0 +1,45 @@
+;;======================================================================
+;; Copyright 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 .
+
+;;======================================================================
+
+(declare (unit servermod))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses configfmod))
+(declare (uses dbmod))
+(declare (uses rmtmod))
+
+(module servermod
+ *
+
+(import scheme chicken data-structures extras ports files)
+(import (prefix sqlite3 sqlite3:) posix
+ typed-records srfi-18 srfi-1 srfi-69 srfi-4
+ message-digest hostinfo
+ regex matchable
+ md5)
+
+(import commonmod)
+(import debugprint)
+(import configfmod)
+(import dbmod)
+(import rmtmod)
+
+
+)
ADDED attic_modular/sharedat.scm
Index: attic_modular/sharedat.scm
==================================================================
--- /dev/null
+++ attic_modular/sharedat.scm
@@ -0,0 +1,517 @@
+
+;; Copyright 2006-2013, 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 .
+
+
+(use defstruct)
+
+;; (use ssax)
+;; (use sxml-serializer)
+;; (use sxml-modifications)
+;; (use regex)
+;; (use srfi-69)
+;; (use regex-case)
+;; (use posix)
+;; (use json)
+;; (use csv)
+(use srfi-18)
+(use format)
+
+(require-library ini-file)
+(import (prefix ini-file ini:))
+
+(use sql-de-lite srfi-1 posix regex regex-case srfi-69)
+;; (import (prefix sqlite3 sqlite3:))
+;;
+(declare (uses configf))
+;; (declare (uses tree))
+(declare (uses margsmod))
+;; (declare (uses dcommon))
+;; (declare (uses launch))
+;; (declare (uses gutils))
+;; (declare (uses db))
+;; (declare (uses synchash))
+;; (declare (uses server))
+(declare (uses megatest-version))
+;; (declare (uses tbd))
+
+(include "megatest-fossil-hash.scm")
+
+;;
+;; GLOBALS
+;;
+(define *spublish:current-tab-number* 0)
+(define *args-hash* (make-hash-table))
+(define spublish:help (conc "Usage: spublish [action [params ...]]
+
+ ls : list contents of target area
+ cp|publish : copy file to target area
+ mkdir : makes directory in target area
+ rm : remove file from target area
+ ln : creates a symlink
+ log :
+
+ options:
+
+ -m \"message\" : describe what was done
+
+Part of the Megatest tool suite.
+Learn more at http://www.kiatoa.com/fossils/megatest
+
+Version: " megatest-fossil-hash)) ;; "
+
+;;======================================================================
+;; RECORDS
+;;======================================================================
+
+;;======================================================================
+;; DB
+;;======================================================================
+
+(define (spublish:initialize-db db)
+ (for-each
+ (lambda (qry)
+ (exec (sql db qry)))
+ (list
+ "CREATE TABLE IF NOT EXISTS actions
+ (id INTEGER PRIMARY KEY,
+ action TEXT NOT NULL,
+ submitter TEXT NOT NULL,
+ datetime TIMESTAMP DEFAULT (strftime('%s','now')),
+ srcpath TEXT NOT NULL,
+ comment TEXT DEFAULT '' NOT NULL,
+ state TEXT DEFAULT 'new');"
+ )))
+
+(define (spublish:register-action db action submitter source-path comment)
+ (exec (sql db "INSERT INTO actions (action,submitter,srcpath,comment)
+ VALUES(?,?,?,?)")
+ action
+ submitter
+ source-path
+ comment))
+
+;; (call-with-database
+;; (lambda (db)
+;; (set-busy-handler! db (busy-timeout 10000)) ; 10 second timeout
+;; ...))
+
+;; Create the sqlite db
+(define (spublish:db-do configdat proc)
+ (let ((path (configf:lookup configdat "database" "location")))
+ (if (not path)
+ (begin
+ (print "[database]\nlocation /some/path\n\n Is missing from the config file!")
+ (exit 1)))
+ (if (and path
+ (directory? path)
+ (file-read-access? path))
+ (let* ((dbpath (conc path "/spublish.db"))
+ (writeable (file-write-access? dbpath))
+ (dbexists (file-exists? dbpath)))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 2 *default-log-port* "ERROR: problem accessing db " dbpath
+ ((condition-property-accessor 'exn 'message) exn))
+ (exit 1))
+ (call-with-database
+ dbpath
+ (lambda (db)
+ ;; (print "calling proc " proc " on db " db)
+ (set-busy-handler! db (busy-timeout 10000)) ;; 10 sec timeout
+ (if (not dbexists)(spublish:initialize-db db))
+ (proc db)))))
+ (print "ERROR: invalid path for storing database: " path))))
+
+;; copy in file to dest, validation is done BEFORE calling this
+;;
+(define (spublish:cp configdat submitter source-path target-dir targ-file dest-dir comment)
+ (let ((dest-dir-path (conc target-dir "/" dest-dir))
+ (targ-path (conc target-dir "/" dest-dir "/" targ-file)))
+ (if (file-exists? targ-path)
+ (begin
+ (print "ERROR: target file already exists, remove it before re-publishing")
+ (exit 1)))
+ (if (not(file-exists? dest-dir-path))
+ (begin
+ (print "ERROR: target directory " target-dir " does not exists." )
+ (exit 1)))
+
+ (spublish:db-do
+ configdat
+ (lambda (db)
+ (spublish:register-action db "cp" submitter source-path comment)))
+ (let* (;; (target-path (configf:lookup "settings" "target-path"))
+ (th1 (make-thread
+ (lambda ()
+ (file-copy source-path targ-path #t))
+ (print " ... file " targ-path " copied to" targ-path)
+ ;; (let ((pid (process-run "cp" (list source-path target-dir))))
+ ;; (process-wait pid)))
+ "copy thread"))
+ (th2 (make-thread
+ (lambda ()
+ (let loop ()
+ (thread-sleep! 15)
+ (display ".")
+ (flush-output)
+ (loop)))
+ "action is happening thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1))
+ (cons #t "Successfully saved data")))
+
+(define (spublish:validate target-dir targ-mk)
+ (let* ((normal-path (normalize-pathname targ-mk))
+ (targ-path (conc target-dir "/" normal-path)))
+ (if (string-contains normal-path "..")
+ (begin
+ (print "ERROR: Path " targ-mk " resolved outside target area " target-dir )
+ (exit 1)))
+
+ (if (not (string-contains targ-path target-dir))
+ (begin
+ (print "ERROR: You cannot update data outside " target-dir ".")
+ (exit 1)))
+ (print "Path " targ-mk " is valid.")
+ ))
+;; make directory in dest
+;;
+
+(define (spublish:mkdir configdat submitter target-dir targ-mk comment)
+ (let ((targ-path (conc target-dir "/" targ-mk)))
+
+ (if (file-exists? targ-path)
+ (begin
+ (print "ERROR: target Directory " targ-path " already exist!!")
+ (exit 1)))
+ (spublish:db-do
+ configdat
+ (lambda (db)
+ (spublish:register-action db "mkdir" submitter targ-mk comment)))
+ (let* ((th1 (make-thread
+ (lambda ()
+ (create-directory targ-path #t)
+ (print " ... dir " targ-path " created"))
+ "mkdir thread"))
+ (th2 (make-thread
+ (lambda ()
+ (let loop ()
+ (thread-sleep! 15)
+ (display ".")
+ (flush-output)
+ (loop)))
+ "action is happening thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1))
+ (cons #t "Successfully saved data")))
+
+;; create a symlink in dest
+;;
+(define (spublish:ln configdat submitter target-dir targ-link link-name comment)
+ (let ((targ-path (conc target-dir "/" link-name)))
+ (if (file-exists? targ-path)
+ (begin
+ (print "ERROR: target file " targ-path " already exist!!")
+ (exit 1)))
+ (if (not (file-exists? targ-link ))
+ (begin
+ (print "ERROR: target file " targ-link " does not exist!!")
+ (exit 1)))
+
+ (spublish:db-do
+ configdat
+ (lambda (db)
+ (spublish:register-action db "ln" submitter link-name comment)))
+ (let* ((th1 (make-thread
+ (lambda ()
+ (create-symbolic-link targ-link targ-path )
+ (print " ... link " targ-path " created"))
+ "symlink thread"))
+ (th2 (make-thread
+ (lambda ()
+ (let loop ()
+ (thread-sleep! 15)
+ (display ".")
+ (flush-output)
+ (loop)))
+ "action is happening thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1))
+ (cons #t "Successfully saved data")))
+
+
+;; remove copy of file in dest
+;;
+(define (spublish:rm configdat submitter target-dir targ-file comment)
+ (let ((targ-path (conc target-dir "/" targ-file)))
+ (if (not (file-exists? targ-path))
+ (begin
+ (print "ERROR: target file " targ-path " not found, nothing to remove.")
+ (exit 1)))
+ (spublish:db-do
+ configdat
+ (lambda (db)
+ (spublish:register-action db "rm" submitter targ-file comment)))
+ (let* ((th1 (make-thread
+ (lambda ()
+ (delete-file targ-path)
+ (print " ... file " targ-path " removed"))
+ "rm thread"))
+ (th2 (make-thread
+ (lambda ()
+ (let loop ()
+ (thread-sleep! 15)
+ (display ".")
+ (flush-output)
+ (loop)))
+ "action is happening thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1))
+ (cons #t "Successfully saved data")))
+
+(define (spublish:backup-move path)
+ (let* ((trashdir (conc (pathname-directory path) "/.trash"))
+ (trashfile (conc trashdir "/" (current-seconds) "-" (pathname-file path))))
+ (create-directory trashdir #t)
+ (if (directory? path)
+ (system (conc "mv " path " " trashfile))
+ (file-move path trash-file))))
+
+
+(define (spublish:lst->path pathlst)
+ (conc "/" (string-intersperse (map conc pathlst) "/")))
+
+(define (spublish:path->lst path)
+ (string-split path "/"))
+
+(define (spublish:pathdat-apply-heuristics configdat path)
+ (cond
+ ((file-exists? path) "found")
+ (else (conc path " not installed"))))
+
+;;======================================================================
+;; MISC
+;;======================================================================
+
+(define (spublish:do-as-calling-user proc)
+ (let ((eid (current-effective-user-id))
+ (cid (current-user-id)))
+ (if (not (eq? eid cid)) ;; running suid
+ (set! (current-effective-user-id) cid))
+ ;; (print "running as " (current-effective-user-id))
+ (proc)
+ (if (not (eq? eid cid))
+ (set! (current-effective-user-id) eid))))
+
+(define (spublish:find name paths)
+ (if (null? paths)
+ #f
+ (let loop ((hed (car paths))
+ (tal (cdr paths)))
+ (if (file-exists? (conc hed "/" name))
+ hed
+ (if (null? tal)
+ #f
+ (loop (car tal)(cdr tal)))))))
+
+;;======================================================================
+;; MAIN
+;;======================================================================
+
+(define (spublish:load-config exe-dir exe-name)
+ (let* ((fname (conc exe-dir "/." exe-name ".config")))
+ (ini:property-separator-patt " * *")
+ (ini:property-separator #\space)
+ (if (file-exists? fname)
+ ;; (ini:read-ini fname)
+ (read-config fname #f #t)
+ (make-hash-table))))
+
+(define (spublish:process-action configdat action . args)
+ (let* ((target-dir (configf:lookup configdat "settings" "target-dir"))
+ (user (current-user-name))
+ (allowed-users (string-split
+ (or (configf:lookup configdat "settings" "allowed-users")
+ ""))))
+ (if (not target-dir)
+ (begin
+ (print "[settings]\ntarget-dir /some/path\n\n Is MISSING from the config file!")
+ (exit)))
+ (if (null? allowed-users)
+ (begin
+ (print "[setings]\nallowed-users user1 user2 ...\n\n Is MISSING from the config file!")
+ (exit)))
+ (if (not (member user allowed-users))
+ (begin
+ (print "User \"" (current-user-name) "\" does not have access. Exiting")
+ (exit 1)))
+ (case (string->symbol action)
+ ((cp publish)
+ (if (< (length args) 2)
+ (begin
+ (print "ERROR: Missing arguments; " (string-intersperse args ", "))
+ (exit 1)))
+ (let* ((remargs (args:get-args args '("-m") '() args:arg-hash 0))
+ (dest-dir (cadr args))
+ (src-path-in (car args))
+ (src-path (with-input-from-pipe
+ (conc "readlink -f " src-path-in)
+ (lambda ()
+ (read-line))))
+ (msg (or (args:get-arg "-m") ""))
+ (targ-file (pathname-strip-directory src-path)))
+ (if (not (file-read-access? src-path))
+ (begin
+ (print "ERROR: source file not readable: " src-path)
+ (exit 1)))
+ (if (directory? src-path)
+ (begin
+ (print "ERROR: source file is a directory, this is not supported yet.")
+ (exit 1)))
+ (print "publishing " src-path-in " to " target-dir)
+ (spublish:validate target-dir dest-dir)
+ (spublish:cp configdat user src-path target-dir targ-file dest-dir msg)))
+ ((mkdir)
+ (if (< (length args) 1)
+ (begin
+ (print "ERROR: Missing arguments; " (string-intersperse args ", "))
+ (exit 1)))
+ (let* ((targ-mk (car args))
+ (msg (or (args:get-arg "-m") "")))
+ (print "attempting to create directory " targ-mk " in " target-dir)
+ (spublish:validate target-dir targ-mk)
+ (spublish:mkdir configdat user target-dir targ-mk msg)))
+
+ ((ln)
+ (if (< (length args) 2)
+ (begin
+ (print "ERROR: Missing arguments; " (string-intersperse args ", "))
+ (exit 1)))
+ (let* ((targ-link (car args))
+ (link-name (cadr args))
+ (sub-path (string-reverse (string-join (cdr (string-split (string-reverse link-name) "/")) "/")))
+ (msg (or (args:get-arg "-m") "")))
+ (if(not (equal? sub-path link-name))
+ (begin
+ (print "attempting to create directory " sub-path " in " target-dir)
+ (spublish:validate target-dir sub-path)
+
+ (spublish:mkdir configdat user target-dir sub-path msg)))
+
+ (print "attempting to create link " link-name " in " target-dir)
+ (spublish:ln configdat user target-dir targ-link link-name msg)))
+
+ ((rm)
+ (if (< (length args) 1)
+ (begin
+ (print "ERROR: Missing arguments; " (string-intersperse args ", "))
+ (exit 1)))
+ (let* ((targ-file (car args))
+ (msg (or (args:get-arg "-m") "")))
+ (print "attempting to remove " targ-file " from " target-dir)
+ (spublish:validate target-dir targ-file)
+
+ (spublish:rm configdat user target-dir targ-file msg)))
+ ((publish)
+ (if (< (length args) 3)
+ (begin
+ (print "ERROR: Missing arguments; " (string-intersperse args ", "))
+ (exit 1))
+ (let* ((srcpath (list-ref args 0))
+ (areaname (list-ref args 1))
+ (version (list-ref args 2))
+ (remargs (args:get-args (drop args 2)
+ '("-type" ;; link or copy (default is copy)
+ "-m")
+ '()
+ args:arg-hash
+ 0))
+ (publish-type (if (equal? (args:get-arg "-type") "link") 'link 'copy))
+ (comment (or (args:get-arg "-m") ""))
+ (submitter (current-user-name))
+ (quality (args:get-arg "-quality"))
+ (publish-res (spublish:publish configdat publish-type areaname version comment srcpath submitter quality)))
+ (if (not (car publish-res))
+ (begin
+ (print "ERROR: " (cdr publish-res))
+ (exit 1))))))
+ ((list-versions)
+ (let ((area-name (car args)) ;; version patt full print
+ (remargs (args:get-args args '("-vpatt") '("-full") args:arg-hash 0))
+ (db (spublish:open-db configdat))
+ (versions (spublish:get-versions-for-area db (car args) version-patt: (args:get-arg "-vpatt"))))
+ ;; (print "area-name=" area-name " args=" args " *args-hash*=" (hash-table->alist *args-hash*))
+ (map (lambda (x)
+ (if (args:get-arg "-full")
+ (format #t
+ "~10a~10a~4a~27a~30a\n"
+ (vector-ref x 0)
+ (vector-ref x 1)
+ (vector-ref x 2)
+ (conc "\"" (time->string (seconds->local-time (vector-ref x 3))) "\"")
+ (conc "\"" (vector-ref x 4) "\""))
+ (print (vector-ref x 0))))
+ versions)))
+ (else (print "Unrecognised command " action)))))
+
+;; ease debugging by loading ~/.dashboardrc - REMOVE FROM PRODUCTION!
+;; (let ((debugcontrolf (conc (get-environment-variable "HOME") "/.spublishrc")))
+;; (if (file-exists? debugcontrolf)
+;; (load debugcontrolf)))
+
+(define (main)
+ (let* ((args (argv))
+ (prog (car args))
+ (rema (cdr args))
+ (exe-name (pathname-file (car (argv))))
+ (exe-dir (or (pathname-directory prog)
+ (spublish:find exe-name (string-split (get-environment-variable "PATH") ":"))))
+ (configdat (spublish:load-config exe-dir exe-name)))
+ (cond
+ ;; one-word commands
+ ((eq? (length rema) 1)
+ (case (string->symbol (car rema))
+ ((help -h -help --h --help)
+ (print spublish:help))
+ ((list-vars) ;; print out the ini file
+ (map print (spublish:get-areas configdat)))
+ ((ls)
+ (let ((target-dir (configf:lookup configdat "settings" "target-dir")))
+ (print "Files in " target-dir)
+ (system (conc "ls " target-dir))))
+ ((log)
+ (spublish:db-do configdat (lambda (db)
+ (print "Listing actions")
+ (query (for-each-row
+ (lambda (row)
+ (apply print (intersperse row " | "))))
+ (sql db "SELECT * FROM actions")))))
+ (else
+ (print "ERROR: Unrecognised command. Try \"spublish help\""))))
+ ;; multi-word commands
+ ((null? rema)(print spublish:help))
+ ((>= (length rema) 2)
+ (apply spublish:process-action configdat (car rema)(cdr rema)))
+ (else (print "ERROR: Unrecognised command. Try \"spublish help\"")))))
+
+(main)
ADDED attic_modular/show-uncalled-procedures.scm
Index: attic_modular/show-uncalled-procedures.scm
==================================================================
--- /dev/null
+++ attic_modular/show-uncalled-procedures.scm
@@ -0,0 +1,30 @@
+;; 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 .
+;;
+(include "codescanlib.scm")
+
+(define (show-danglers)
+ (let* ((all-scm-files (glob "*.scm"))
+ (xref (get-xref all-scm-files))
+ (dangling-procs
+ (map car (filter (lambda (x) (equal? 1 (length x))) xref))))
+ (for-each print dangling-procs) ;; our product.
+ ))
+
+(show-danglers)
+
+
ADDED attic_modular/spublish.scm
Index: attic_modular/spublish.scm
==================================================================
--- /dev/null
+++ attic_modular/spublish.scm
@@ -0,0 +1,820 @@
+
+;; Copyright 2006-2013, 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 .
+
+(use defstruct)
+(use scsh-process)
+(use refdb)
+(use srfi-18)
+(use srfi-19)
+(use format)
+(use sql-de-lite srfi-1 posix regex regex-case srfi-69)
+
+;(declare (uses configf))
+;; (declare (uses tree))
+(declare (uses margsmod))
+
+(include "megatest-version.scm")
+(include "megatest-fossil-hash.scm")
+;;; please create this file before using sautherise. For sample file is avaliable sample-sauth-paths.scm.
+(include "sauth-paths.scm")
+(include "sauth-common.scm")
+(define (toplevel-command . args) #f)
+(use readline)
+
+;;
+;; GLOBALS
+;;
+(define *spublish:current-tab-number* 0)
+(define *args-hash* (make-hash-table))
+(define spublish:help (conc "Usage: spublish [action [params ...]]
+
+ ls : list contents of target area
+ cp|publish : copy file to target area
+ mkdir : maks directory in target area
+ rm : remove file from target area
+ ln : creates a symlink
+
+ options:
+
+ -m \"message\" : describe what was done
+Note: All the target locations relative to base path
+Part of the Megatest tool suite.
+Learn more at http://www.kiatoa.com/fossils/megatest
+
+Version: " megatest-fossil-hash)) ;; "
+
+;;======================================================================
+;; RECORDS
+;;======================================================================
+
+;;======================================================================
+;; DB
+;;======================================================================
+
+(define *default-log-port* (current-error-port))
+(define *verbosity* 1)
+
+;(define (spublish:initialize-db db)
+; (for-each
+; (lambda (qry)
+; (exec (sql db qry)))
+; (list
+; "CREATE TABLE IF NOT EXISTS actions
+; (id INTEGER PRIMARY KEY,
+; action TEXT NOT NULL,
+; submitter TEXT NOT NULL,
+; datetime TIMESTAMP DEFAULT (strftime('%s','now')),
+; srcpath TEXT NOT NULL,
+; comment TEXT DEFAULT '' NOT NULL,
+; state TEXT DEFAULT 'new');"
+; )))
+
+;(define (spublish:register-action db action submitter source-path comment)
+; (exec (sql db "INSERT INTO actions (action,submitter,srcpath,comment)
+; VALUES(?,?,?,?)")
+; action
+; submitter
+; source-path
+; comment))
+
+;; (call-with-database
+;; (lambda (db)
+;; (set-busy-handler! db (busy-timeout 10000)) ; 10 second timeout
+;; ...))
+
+;; Create the sqlite db
+;(define (spublish:db-do configdat proc)
+; (let ((path (configf:lookup configdat "database" "location")))
+; (if (not path)
+; (begin
+; (print "[database]\nlocation /some/path\n\n Is missing from the config file!")
+; (exit 1)))
+; (if (and path
+; (directory? path)
+; (file-read-access? path))
+; (let* ((dbpath (conc path "/spublish.db"))
+; (writeable (file-write-access? dbpath))
+; (dbexists (file-exists? dbpath)))
+; (handle-exceptions
+; exn
+; (begin
+; (debug:print 2 *default-log-port* "ERROR: problem accessing db " dbpath
+; ((condition-property-accessor 'exn 'message) exn))
+; (exit 1))
+; (call-with-database
+; dbpath
+; (lambda (db)
+; ;; (print "calling proc " proc " on db " db)
+; (set-busy-handler! db (busy-timeout 10000)) ;; 10 sec timeout
+; (if (not dbexists)(spublish:initialize-db db))
+; (proc db)))))
+; (print "ERROR: invalid path for storing database: " path))))
+;
+;;; copy in file to dest, validation is done BEFORE calling this
+;;;
+;(define (spublish:cp configdat submitter source-path target-dir targ-file dest-dir comment)
+; (let ((dest-dir-path (conc target-dir "/" dest-dir))
+; (targ-path (conc target-dir "/" dest-dir "/" targ-file)))
+; (if (file-exists? targ-path)
+; (begin
+; (print "ERROR: target file already exists, remove it before re-publishing")
+; (exit 1)))
+; (if (not(file-exists? dest-dir-path))
+; (begin
+; (print "ERROR: target directory " dest-dir-path " does not exists." )
+; (exit 1)))
+;
+; (spublish:db-do
+; configdat
+; (lambda (db)
+; (spublish:register-action db "cp" submitter source-path comment)))
+; (let* (;; (target-path (configf:lookup "settings" "target-path"))
+; (th1 (make-thread
+; (lambda ()
+; (file-copy source-path targ-path #t))
+; (print " ... file " targ-path " copied to " targ-path)
+; ;; (let ((pid (process-run "cp" (list source-path target-dir))))
+; ;; (process-wait pid)))
+; "copy thread"))
+; (th2 (make-thread
+; (lambda ()
+; (let loop ()
+; (thread-sleep! 15)
+; (display ".")
+; (flush-output)
+; (loop)))
+; "action is happening thread")))
+; (thread-start! th1)
+; (thread-start! th2)
+; (thread-join! th1))
+; (cons #t "Successfully saved data")))
+;
+;;; copy directory to dest, validation is done BEFORE calling this
+;;;
+;
+;(define (spublish:tar configdat submitter target-dir dest-dir comment)
+; (let ((dest-dir-path (conc target-dir "/" dest-dir)))
+; (if (not(file-exists? dest-dir-path))
+; (begin
+; (print "ERROR: target directory " dest-dir-path " does not exists." )
+; (exit 1)))
+; ;;(print dest-dir-path )
+; (spublish:db-do
+; configdat
+; (lambda (db)
+; (spublish:register-action db "tar" submitter dest-dir-path comment)))
+; (change-directory dest-dir-path)
+; (process-wait (process-run "/bin/tar" (list "xf" "-")))
+; (print "Data copied to " dest-dir-path)
+;
+; (cons #t "Successfully saved data")))
+
+
+;(define (spublish:validate target-dir targ-mk)
+; (let* ((normal-path (normalize-pathname targ-mk))
+; (targ-path (conc target-dir "/" normal-path)))
+; (if (string-contains normal-path "..")
+; (begin
+; (print "ERROR: Path " targ-mk " resolved outside target area " target-dir )
+; (exit 1)))
+;
+; (if (not (string-contains targ-path target-dir))
+; (begin
+; (print "ERROR: You cannot update data outside " target-dir ".")
+; (exit 1)))
+; (print "Path " targ-mk " is valid.")
+; ))
+;; make directory in dest
+;;
+
+;(define (spublish:mkdir configdat submitter target-dir targ-mk comment)
+; (let ((targ-path (conc target-dir "/" targ-mk)))
+;
+; (if (file-exists? targ-path)
+; (begin
+; (print "ERROR: target Directory " targ-path " already exist!!")
+; (exit 1)))
+; (spublish:db-do
+; configdat
+; (lambda (db)
+; (spublish:register-action db "mkdir" submitter targ-mk comment)))
+; (let* ((th1 (make-thread
+; (lambda ()
+; (create-directory targ-path #t)
+; (print " ... dir " targ-path " created"))
+; "mkdir thread"))
+; (th2 (make-thread
+; (lambda ()
+; (let loop ()
+; (thread-sleep! 15)
+; (display ".")
+; (flush-output)
+; (loop)))
+; "action is happening thread")))
+; (thread-start! th1)
+; (thread-start! th2)
+; (thread-join! th1))
+; (cons #t "Successfully saved data")))
+
+;; create a symlink in dest
+;;
+;(define (spublish:ln configdat submitter target-dir targ-link link-name comment)
+; (let ((targ-path (conc target-dir "/" link-name)))
+; (if (file-exists? targ-path)
+; (begin
+; (print "ERROR: target file " targ-path " already exist!!")
+; (exit 1)))
+; (if (not (file-exists? targ-link ))
+; (begin
+; (print "ERROR: target file " targ-link " does not exist!!")
+; (exit 1)))
+;
+; (spublish:db-do
+; configdat
+; (lambda (db)
+; (spublish:register-action db "ln" submitter link-name comment)))
+; (let* ((th1 (make-thread
+; (lambda ()
+; (create-symbolic-link targ-link targ-path )
+; (print " ... link " targ-path " created"))
+; "symlink thread"))
+; (th2 (make-thread
+; (lambda ()
+; (let loop ()
+; (thread-sleep! 15)
+; (display ".")
+; (flush-output)
+; (loop)))
+; "action is happening thread")))
+; (thread-start! th1)
+; (thread-start! th2)
+; (thread-join! th1))
+; (cons #t "Successfully saved data")))
+
+
+;; remove copy of file in dest
+;;
+;(define (spublish:rm configdat submitter target-dir targ-file comment)
+; (let ((targ-path (conc target-dir "/" targ-file)))
+; (if (not (file-exists? targ-path))
+; (begin
+; (print "ERROR: target file " targ-path " not found, nothing to remove.")
+; (exit 1)))
+; (spublish:db-do
+; configdat
+; (lambda (db)
+; (spublish:register-action db "rm" submitter targ-file comment)))
+; (let* ((th1 (make-thread
+; (lambda ()
+; (delete-file targ-path)
+; (print " ... file " targ-path " removed"))
+; "rm thread"))
+; (th2 (make-thread
+; (lambda ()
+; (let loop ()
+; (thread-sleep! 15)
+; (display ".")
+; (flush-output)
+; (loop)))
+; "action is happening thread")))
+; (thread-start! th1)
+; (thread-start! th2)
+; (thread-join! th1))
+; (cons #t "Successfully saved data")))
+
+(define (spublish:backup-move path)
+ (let* ((trashdir (conc (pathname-directory path) "/.trash"))
+ (trashfile (conc trashdir "/" (current-seconds) "-" (pathname-file path))))
+ (create-directory trashdir #t)
+ (if (directory? path)
+ (system (conc "mv " path " " trashfile))
+ (file-move path trash-file))))
+
+
+(define (spublish:lst->path pathlst)
+ (conc "/" (string-intersperse (map conc pathlst) "/")))
+
+(define (spublish:path->lst path)
+ (string-split path "/"))
+
+(define (spublish:pathdat-apply-heuristics configdat path)
+ (cond
+ ((file-exists? path) "found")
+ (else (conc path " not installed"))))
+
+;;======================================================================
+;; MISC
+;;======================================================================
+
+;(define (spublish:do-as-calling-user proc)
+; (let ((eid (current-effective-user-id))
+; (cid (current-user-id)))
+; (if (not (eq? eid cid)) ;; running suid
+; (set! (current-effective-user-id) cid))
+; ;; (print "running as " (current-effective-user-id))
+; (proc)
+; (if (not (eq? eid cid))
+; (set! (current-effective-user-id) eid))))
+
+;(define (spublish:find name paths)
+; (if (null? paths)
+; #f
+; (let loop ((hed (car paths))
+; (tal (cdr paths)))
+; (if (file-exists? (conc hed "/" name))
+; hed
+; (if (null? tal)
+; #f
+; (loop (car tal)(cdr tal)))))))
+
+;;========================================================================
+;;Shell
+;;========================================================================
+(define (spublish:get-accessable-projects area)
+ (let* ((projects `()))
+ (if (spublish:has-permission area)
+ (set! projects (cons area projects))
+ (begin
+ (print "User cannot access area " area "!!")
+ (exit 1)))
+ projects))
+
+;; function to find sheets to which use has access
+(define (spublish:has-permission area)
+ ;(print "in spublish:has-permission")
+ (let* ((username (current-user-name))
+ (ret-val #f))
+ (cond
+ ((equal? (is-admin username) #t)
+ (set! ret-val #t))
+ ((equal? (is-user "publish" username area) #t)
+ (set! ret-val #t))
+ ((equal? (is-user "writer-admin" username area) #t)
+ (set! ret-val #t))
+
+ ((equal? (is-user "area-admin" username area) #t)
+ (set! ret-val #t))
+ (else
+ (set! ret-val #f)))
+ ret-val))
+
+(define (is_directory target-path)
+ (let* ((retval #f))
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ ;(print (current-effective-user-id) )
+ (if (directory? target-path)
+ (set! retval #t))))
+ ;(print (current-effective-user-id))
+ retval))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; shell functions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(define (spublish:shell-cp src-path target-path)
+ (cond
+ ((not (file-exists? target-path))
+ (sauth:print-error (conc " target Directory " target-path " does not exist!!")))
+ ((not (file-exists? src-path))
+ (sauth:print-error (conc "Source path " src-path " does not exist!!" )))
+ (else
+ (if (< (sauth-common:space-left-at-dest target-path) (sauth-common:src-size src-path))
+ (begin
+ (sauth:print-error "Destination does not have enough disk space.")
+ (exit 1)))
+ (if (is_directory src-path)
+ (begin
+ (let* ((parent-dir src-path)
+ (start-dir target-path))
+ (run (pipe
+ (begin (system (conc "cd " parent-dir " ;tar chf - ." )))
+ (begin (change-directory start-dir)
+ ;(print "123")
+ (run-cmd "tar" (list "xf" "-")))))
+ (print "Copied data to " start-dir)))
+ (begin
+ (let*((parent-dir (pathname-directory src-path))
+ (start-dir target-path)
+ (filename (if (pathname-extension src-path)
+ (conc(pathname-file src-path) "." (pathname-extension src-path))
+ (pathname-file src-path))))
+ ;(print "parent-dir " parent-dir " start-dir " start-dir)
+ (run (pipe
+ (begin (system (conc "cd " parent-dir ";tar chf - " filename )))
+ (begin (change-directory start-dir)
+ (run-cmd "tar" (list "xf" "-")))))
+ (print "Copied data to " start-dir)))))))
+
+
+(define (spublish:shell-mkdir targ-path)
+ (if (file-exists? targ-path)
+ (begin
+ (print "Info: Target Directory " targ-path " already exist!!"))
+ (let* ((th1 (make-thread
+ (lambda ()
+ (create-directory targ-path #t)
+ (print " ... dir " targ-path " created"))
+ "mkdir thread"))
+ (th2 (make-thread
+ (lambda ()
+ (let loop ()
+ (thread-sleep! 15)
+ (display ".")
+ (flush-output)
+ (loop)))
+ "action is happening thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1)
+ (cons #t "Successfully saved data"))))
+
+
+(define (spublish:shell-rm targ-path iport)
+ (if (not (file-exists? targ-path))
+ (begin
+ (sauth:print-error (conc "target path " targ-path " does not exist!!")))
+ (begin
+ (print "Are you sure you want to delete " targ-path "?[y/n]")
+ (let* ((inl (read-line iport)))
+ (if (equal? inl "y")
+ (let* ((th1 (make-thread
+ (lambda ()
+ (if (symbolic-link? targ-path)
+ (delete-file targ-path )
+ (if (directory? targ-path)
+ (delete-directory targ-path #t)
+ (delete-file targ-path )))
+ (print " ... path " targ-path " deleted"))
+ "rm thread"))
+ (th2 (make-thread
+ (lambda ()
+ (let loop ()
+ (thread-sleep! 15)
+ (display ".")
+ (flush-output)
+ (loop)))
+ "action is happening thread")))
+ (thread-start! th1)
+ (thread-start! th2)
+ (thread-join! th1)
+ (cons #t "Successfully saved data")))))))
+
+(define (spublish:shell-ln src-path target-path sub-path)
+ (if (not (file-exists? sub-path))
+ (sauth:print-error (conc "Path " sub-path " does not exist!! cannot proceed with link creation!!"))
+ (begin
+ (if (not (file-exists? src-path))
+ (sauth:print-error (conc "Path " src-path " does not exist!! cannot proceed with link creation!!"))
+ (begin
+ (if (file-exists? target-path)
+ (sauth:print-error (conc "Path " target-path "already exist!! cannot proceed with link creation!!"))
+ (begin
+ (create-symbolic-link src-path target-path )
+ (print " ... link " target-path " created"))))))))
+
+(define (spublish:shell-help)
+(conc "Usage: [action [params ...]]
+
+ ls [target path] : list contents of target area.
+ cd : To change the current directory within the sretrive shell.
+ pwd : Prints the full pathname of the current directory within the sretrive shell.
+ mkdir : creates directory. Note it does not create's a path recursive manner.
+ rm : removes files and emoty directories
+ cp : copy a file/dir to target path. if src is a dir it automatically makes a recursive copy.
+ ln TARGET LINK_NAME : creates a symlink
+Part of the Megatest tool suite.
+Learn more at http://www.kiatoa.com/fossils/megatest
+
+Version: " megatest-fossil-hash)
+)
+
+(define (toplevel-command . args) #f)
+
+(define (spublish:shell area)
+ ; (print area)
+ (use readline)
+
+ (let* ((path '())
+ (prompt "spublish> ")
+ (args (argv))
+ (usr (current-user-name) )
+ (top-areas (spublish:get-accessable-projects area))
+ (close-port #f)
+ (area-obj (get-obj-by-code area))
+ (user-obj (get-user usr))
+ (base-path (if (null? area-obj)
+ ""
+ (caddr (cdr area-obj))))
+ (iport (make-readline-port prompt)))
+ ;(print base-path)
+ (if (null? area-obj)
+ (begin
+ (print "Area " area " does not exist")
+ (exit 1)))
+ ; (print "here")
+ (let loop ((inl (read-line iport)))
+ (if (not (or (or (eof-object? inl)
+ (equal? inl "exit")) (port-closed? iport)))
+ (let* ((parts (string-split inl))
+ (cmd (if (null? parts) #f (car parts))))
+ (if (and (not cmd) (not (port-closed? iport)))
+ (loop (read-line))
+ (case (string->symbol cmd)
+ ((cd)
+ (if (> (length parts) 1) ;; have a parameter
+ (begin
+ (let*((arg (cadr parts))
+ (resolved-path (sauth-common:resolve-path arg path top-areas))
+ (target-path (sauth-common:get-target-path path arg top-areas base-path)))
+ (if (not (equal? target-path #f))
+ (if (or (equal? resolved-path #f) (not (file-exists? target-path)))
+ (print "Invalid argument " arg ".. ")
+ (begin
+ (set! path resolved-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "cd"))))
+ )))))
+ (set! path '())))
+ ((pwd)
+ (if (null? path)
+ (print "/")
+ (print "/" (string-join path "/"))))
+ ((ls)
+ (let* ((thepath (if (> (length parts) 1) ;; have a parameter
+ (cdr parts)
+ `()))
+ (plen (length thepath)))
+ (cond
+ ((null? thepath)
+ (sauth-common:shell-ls-cmd path "" top-areas base-path '())
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "ls")))) )
+ ((< plen 2)
+ (sauth-common:shell-ls-cmd path (car thepath) top-areas base-path '())
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "ls")))))
+ (else
+ (if (equal? (car thepath) "|")
+ (sauth-common:shell-ls-cmd path "" top-areas base-path thepath)
+ (sauth-common:shell-ls-cmd path (car thepath) top-areas base-path (cdr thepath)))
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "ls"))))))))
+ ((mkdir)
+ (let* ((thepath (if (> (length parts) 1) ;; have a parameter
+ (cdr parts)
+ `()))
+ (plen (length thepath)))
+ (cond
+ ((null? thepath)
+ (print "mkdir takes one argument"))
+ ((< plen 2)
+ (let*((mk-path (cadr parts))
+ (resolved-path (sauth-common:resolve-path mk-path path top-areas))
+ (target-path (sauth-common:get-target-path path mk-path top-areas base-path)))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " mk-path ".. ")
+ (begin
+ (print "here")
+ (spublish:shell-mkdir target-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "mkdir")))))))
+ )))))
+ ((rm)
+ (let* ((thepath (if (> (length parts) 1) ;; have a parameter
+ (cdr parts)
+ `()))
+ (plen (length thepath)))
+ (cond
+ ((null? thepath)
+ (print "rm takes one argument"))
+ ((< plen 2)
+ (let*((rm-path (cadr parts))
+ (resolved-path (sauth-common:resolve-path rm-path path top-areas))
+ (target-path (sauth-common:get-target-path path rm-path top-areas base-path)))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " rm-path ".. ")
+ (begin
+ (spublish:shell-rm target-path iport)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "rm")))))))
+ )))))
+
+ ((cp publish)
+ (let* ((thepath (if (> (length parts) 1) ;; have a parameter
+ (cdr parts)
+ `()))
+ (plen (length thepath)))
+ (cond
+ ((or (null? thepath) (< plen 2))
+ (print "cp takes two argument"))
+ ((< plen 3)
+ (let*((src-path (car thepath))
+ (dest-path (cadr thepath))
+ (resolved-path (sauth-common:resolve-path dest-path path top-areas))
+ (target-path (sauth-common:get-target-path path dest-path top-areas base-path)))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " dest-path ".. ")
+ (begin
+ (spublish:shell-cp src-path target-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "cp")))))))
+ )))))
+ ((ln)
+ (let* ((thepath (if (> (length parts) 1) ;; have a parameter
+ (cdr parts)
+ `()))
+ (plen (length thepath)))
+ (cond
+ ((or (null? thepath) (< plen 2))
+ (print "ln takes two argument"))
+ ((< plen 3)
+ (let*((src-path (car thepath))
+ (dest-path (cadr thepath))
+ (resolved-path (sauth-common:resolve-path dest-path path top-areas))
+ (target-path (sauth-common:get-target-path path dest-path top-areas base-path))
+ (sub-path (conc "/" (string-reverse (string-join (cdr (string-split (string-reverse target-path) "/")) "/")))))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " dest-path ".. ")
+ (begin
+ (spublish:shell-ln src-path target-path sub-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\"" inl "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "ln")))))))
+ )))))
+ ((exit)
+ (print "got exit"))
+ ((help)
+ (print (spublish:shell-help)))
+ (else
+ (print "Got command: " inl))))
+ (loop (read-line iport)))))))
+
+
+;;======================================================================
+;; MAIN
+;;======================================================================
+
+;(define (spublish:load-config exe-dir exe-name)
+; (let* ((fname (conc exe-dir "/." exe-name ".config")))
+ ;; (ini:property-separator-patt " * *")
+ ;; (ini:property-separator #\space)
+; (if (file-exists? fname)
+; ;; (ini:read-ini fname)
+; (read-config fname #f #t)
+; (make-hash-table))))
+
+(define (spublish:process-action action . args)
+ ;(print args)
+ (let* ((usr (current-user-name))
+ (user-obj (get-user usr))
+ (area (car args))
+ (area-obj (get-obj-by-code area))
+ (top-areas (spublish:get-accessable-projects area))
+ (base-path (if (null? area-obj)
+ ""
+ (caddr (cdr area-obj))))
+ (remargs (cdr args)))
+ (if (null? area-obj)
+ (begin
+ (print "Area " area " does not exist")
+ (exit 1)))
+ (case (string->symbol action)
+ ((cp publish)
+ (if (< (length remargs) 2)
+ (begin
+ (print "ERROR: Missing arguments; spublish " )
+ (exit 1)))
+ (let* ((filter-args (args:get-args args '("-m") '() args:arg-hash 0))
+ (src-path-in (car filter-args))
+ (dest-path (cadr filter-args))
+ (src-path (with-input-from-pipe
+ (conc "readlink -f " src-path-in)
+ (lambda ()
+ (read-line))))
+ (msg (or (args:get-arg "-m") ""))
+ (resolved-path (sauth-common:resolve-path (conc area "/" dest-path) `() top-areas))
+ (target-path (sauth-common:get-target-path `() (conc area "/" dest-path) top-areas base-path)))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " dest-path ".. ")
+ (begin
+ (spublish:shell-cp src-path target-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\" cp " src-path-in " " dest-path "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "cp")))))))))
+ ((mkdir)
+ (if (< (length remargs) 1)
+ (begin
+ (print "ERROR: Missing arguments; ")
+ (exit 1)))
+ (let* ((filter-args (args:get-args args '("-m") '() args:arg-hash 0))
+ (mk-path (car filter-args))
+ (msg (or (args:get-arg "-m") ""))
+ (resolved-path (sauth-common:resolve-path mk-path (list area) top-areas))
+ (target-path (sauth-common:get-target-path (list area) mk-path top-areas base-path)))
+ (print "attempting to create directory " mk-path )
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " mk-path ".. ")
+ (begin
+ (spublish:shell-mkdir target-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\" mkdir " mk-path "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "mkdir")))))))))
+ ((ln)
+ (if (< (length remargs) 2)
+ (begin
+ (print "ERROR: Missing arguments; " )
+ (exit 1)))
+ (let* ((filter-args (args:get-args args '("-m") '() args:arg-hash 0))
+ (src-path (car filter-args))
+ (dest-path (cadr filter-args))
+ (resolved-path (sauth-common:resolve-path dest-path (list area) top-areas))
+ (target-path (sauth-common:get-target-path (list area) dest-path top-areas base-path))
+ (sub-path (conc "/" (string-reverse (string-join (cdr (string-split (string-reverse target-path) "/")) "/")))))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " dest-path ".. ")
+ (begin
+ (spublish:shell-ln src-path target-path sub-path)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\" ln " src-path " " dest-path "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "ln")))))))))
+ ((rm)
+ (if (< (length remargs) 1)
+ (begin
+ (print "ERROR: Missing arguments; ")
+ (exit 1)))
+ (let* ((filter-args (args:get-args args '("-m") '() args:arg-hash 0))
+ (rm-path (car filter-args))
+ (resolved-path (sauth-common:resolve-path rm-path (list area) top-areas))
+ (prompt ">")
+ (iport (make-readline-port prompt))
+ (target-path (sauth-common:get-target-path (list area) rm-path top-areas base-path)))
+ (if (not (equal? target-path #f))
+ (if (equal? resolved-path #f)
+ (print "Invalid argument " rm-path ".. ")
+ (begin
+ (spublish:shell-rm target-path iport)
+ (sauthorize:do-as-calling-user
+ (lambda ()
+ (run-cmd (conc *sauth-path* "/sauthorize") (list "register-log" (conc "\" rm " rm-path "\"") (number->string (car user-obj)) (number->string (caddr area-obj)) "rm")))))))))
+ ((shell)
+ (if (< (length args) 1)
+ (begin
+ (print "ERROR: Missing arguments area!!" )
+ (exit 1))
+ (spublish:shell area)))
+ (else (print "Unrecognised command " action)))))
+
+;; ease debugging by loading ~/.dashboardrc - REMOVE FROM PRODUCTION!
+;; (let ((debugcontrolf (conc (get-environment-variable "HOME") "/.spublishrc")))
+;; (if (file-exists? debugcontrolf)
+;; (load debugcontrolf)))
+
+(define (main)
+ (let* ((args (argv))
+ (prog (car args))
+ (rema (cdr args))
+ (exe-name (pathname-file (car (argv)))))
+ (cond
+ ;; one-word commands
+ ((eq? (length rema) 1)
+ (case (string->symbol (car rema))
+ ((help -h -help --h --help)
+ (print spublish:help))
+ (else
+ (print "ERROR: Unrecognised command. Try \"spublish help\""))))
+ ;; multi-word commands
+ ((null? rema)(print spublish:help))
+ ((>= (length rema) 2)
+ (apply spublish:process-action (car rema)(cdr rema)))
+ (else (print "ERROR: Unrecognised command2. Try \"spublish help\"")))))
+
+(main)
ADDED attic_modular/stml2.scm
Index: attic_modular/stml2.scm
==================================================================
--- /dev/null
+++ attic_modular/stml2.scm
@@ -0,0 +1,23 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit stml2))
+
+(include "stml2/stml2.scm")
ADDED attic_modular/subrun.scm
Index: attic_modular/subrun.scm
==================================================================
--- /dev/null
+++ attic_modular/subrun.scm
@@ -0,0 +1,281 @@
+
+;; Copyright 2006-2016, 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 .
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+(use (prefix sqlite3 sqlite3:) srfi-1 posix regex regex-case srfi-69 (srfi 18)
+ posix-extras directory-utils pathname-expand typed-records format
+ call-with-environment-variables)
+(declare (unit subrun))
+;;(declare (uses runs))
+(declare (uses db))
+(declare (uses common))
+;;(declare (uses items))
+;;(declare (uses runconfig))
+;;(declare (uses tests))
+;;(declare (uses server))
+(declare (uses mt))
+;;(declare (uses archive))
+;; (declare (uses filedb))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses dbmod))
+(import dbmod)
+
+;;(include "common_records.scm")
+;;(include "key_records.scm")
+(include "db_records.scm") ;; provides db:test-get-id
+;;(include "run_records.scm")
+;;(include "test_records.scm")
+
+(define (subrun:subrun-test-initialized? test-run-dir)
+ (if (and (common:file-exists? (conc test-run-dir "/subrun-area") )
+ (common:file-exists? (conc test-run-dir "/testconfig.subrun") ))
+ #t
+ #f))
+
+(define (subrun:launch-dashboard test-run-dir #!key (target #f)(runname #f))
+ (if (subrun:subrun-test-initialized? test-run-dir)
+ (let* ((subarea (subrun:get-runarea test-run-dir))
+ (params (conc (if target (conc " -target " target) "")
+ (if runname (conc " -runname " runname) ""))))
+ (if (and subarea (common:file-exists? subarea))
+ (system (conc "cd " subarea ";env -i PATH=$PATH DISPLAY=$DISPLAY HOME=$HOME USER=$USER nbfake dashboard " params))))))
+
+(define (subrun:subrun-removed? test-run-dir)
+ (if (subrun:subrun-test-initialized? test-run-dir)
+ (let ((flagfile (conc test-run-dir "/subrun.removed")))
+ (if (common:file-exists? flagfile)
+ #t
+ #f))
+ #t))
+
+(define (subrun:set-subrun-removed test-run-dir)
+ (let ((flagfile (conc test-run-dir "/subrun.removed")))
+ (if (and (subrun:subrun-test-initialized? test-run-dir) (not (common:file-exists? flagfile)))
+ (with-output-to-file flagfile
+ (lambda () (print (current-seconds)))))))
+
+(define (subrun:unset-subrun-removed test-run-dir)
+ (let ((flagfile (conc test-run-dir "/subrun.removed")))
+ (if (and (subrun:subrun-test-initialized? test-run-dir) (common:file-exists? flagfile))
+ (delete-file flagfile))))
+
+
+(define (subrun:testconfig-defines-subrun? testconfig)
+ (configf:lookup testconfig "subrun" "runwait")) ;; we use runwait as the flag that a subrun is requested
+
+(define (subrun:initialize-toprun-test testconfig test-run-dir)
+ (let ((ra (configf:lookup testconfig "subrun" "run-area"))
+ (logpro (configf:lookup testconfig "subrun" "logpro"))
+ (symlink-target (conc test-run-dir "/subrun-area"))
+ )
+ (if (not ra) ;; when runarea is not set we default to *toppath*. However
+ (let ((fallback-run-area (or *toppath* (conc test-run-dir "/subrun"))))
+ ;; we need to force the setting in the testconfig so it will
+ ;; be preserved in the testconfig.subrun file
+ (configf:set-section-var testconfig "subrun" "run-area" fallback-run-area)
+ (set! ra fallback-run-area)))
+ (configf:set-section-var testconfig "logpro" "subrun" logpro) ;; append the logpro rules to the logpro section as stepname subrun
+ (if (common:file-exists? symlink-target)
+ (delete-file symlink-target))
+ (create-symbolic-link ra symlink-target)
+ (configf:write-alist testconfig "testconfig.subrun")))
+
+(define (subrun:set-state-status test-run-dir state status new-state-status)
+ (if (and (not (subrun:subrun-removed? test-run-dir)) (subrun:subrun-test-initialized? test-run-dir))
+ (let* ((action-switches-str
+ (conc "-set-state-status "new-state-status
+ (if state (conc " -state "state) "")
+ (if status (conc " -status "status) "")))
+ (log-prefix
+ (subrun:sanitize-path
+ (conc "set-state-status="new-state-status
+ (if state (conc ":state="state) "")
+ (if status (conc "+status="status) ""))))
+ (submt-result
+ (subrun:exec-sub-megatest test-run-dir action-switches-str log-prefix)))
+ submt-result)))
+
+(define (subrun:remove-subrun test-run-dir keep-records )
+ (if (and (not (subrun:subrun-removed? test-run-dir)) (subrun:subrun-test-initialized? test-run-dir))
+ (let* ((action-switches-str
+ (conc "-remove-runs"
+ (if keep-records "-keep-records " "")
+ ))
+ (remove-result
+ (subrun:exec-sub-megatest test-run-dir action-switches-str "remove")))
+ (if remove-result
+ (begin
+ (subrun:set-subrun-removed test-run-dir)
+ #t)
+ #f))
+ #t))
+
+(define (subrun:kill-subrun test-run-dir )
+ (if (and (not (subrun:subrun-removed? test-run-dir)) (subrun:subrun-test-initialized? test-run-dir))
+ (let* ((action-switches-str
+ (conc "-kill-runs" ))
+ (kill-result
+ (subrun:exec-sub-megatest test-run-dir action-switches-str "kill")))
+ kill-result)
+ #t))
+
+(define (subrun:launch-cmd test-run-dir #!optional (sub-cmd "-run")) ;; BUG: "-run" should be changed to "-rerun-clean" but current doesn't work
+ (if (subrun:subrun-removed? test-run-dir)
+ (subrun:unset-subrun-removed test-run-dir))
+
+ (let* ((log-prefix "run")
+ (switches (subrun:selector+log-switches test-run-dir log-prefix))
+ (run-wait #t)
+ (cmd (conc "megatest " sub-cmd " " switches" "
+ (if run-wait "-run-wait " ""))))
+ cmd))
+
+
+(define (subrun:sanitize-path inpath)
+ (let* ((insane-pattern (irregex "[^[a-zA-Z0-9_\\-]")))
+ (regex#string-substitute insane-pattern "_" inpath #t)))
+
+(define (subrun:get-runarea test-run-dir)
+ (if (subrun:subrun-test-initialized? test-run-dir)
+ (let* ((info-alist (subrun:selector+log-alist
+ test-run-dir
+ "foo"))
+ (run-area (if (list? info-alist)
+ (alist-ref "-start-dir" info-alist equal? #f)
+ #f)))
+ run-area)
+ #f))
+
+(define (subrun:selector+log-alist test-run-dir log-prefix)
+ (let* ((switch-def-alist (common:get-param-mapping flavor: 'config))
+ (subrunfile (conc test-run-dir "/testconfig.subrun" ))
+ (subrundata (with-input-from-file subrunfile read))
+ (subrunconfig (configf:alist->config subrundata))
+ (run-area (configf:lookup subrunconfig "subrun" "run-area"))
+ (defvals `(("start-dir" . ,(or run-area ;; default values if not specified in subrun section of tconf
+ (get-environment-variable "MT_RUN_AREA_HOME")
+ "/no/rundir/found"))
+ ("run-name" . ,(or (get-environment-variable "MT_RUNNAME") "NO-RUNNAME"))
+ ("target" . ,(or (get-environment-variable "MT_TARGET") "NO-TARGET"))))
+ (switch-alist-pre (filter-map (lambda (item)
+ (let* ((config-key (car item))
+ (switch (cdr item))
+ (defval (alist-ref config-key defvals equal? #f))
+ (val (or (configf:lookup subrunconfig "subrun" config-key)
+ defval)))
+ (if val
+ (cons switch val)
+ #f)))
+ switch-def-alist))
+
+ ;; testpatt may be modified if all three of mode-patt, tag-expr, and testpatt are null
+ (mode-patt (alist-ref "-modepatt" switch-alist-pre equal? #f))
+ (tag-expr (alist-ref "-tagexpr" switch-alist-pre equal? #f))
+ (testpatt (alist-ref "-testpatt" switch-alist-pre equal?
+ (if (not (or mode-patt tag-expr)) "%" #f))) ;; testpatt is % if not
+ ;; otherwise specified
+
+ ;; define compact-stem for logfile
+ (target (alist-ref "-target" switch-alist-pre equal? #f)) ;; want data-structures alist-ref, not alist-lib alist-ref
+ (runname (alist-ref "-runname" switch-alist-pre equal? #f))
+
+
+ (compact-stem (subrun:sanitize-path
+ (conc
+ target
+ "-"
+ runname
+ "-" (or testpatt mode-patt tag-expr "NO-TESTPATT"))))
+ (logfile (conc
+ test-run-dir "/"
+ (if log-prefix
+ (conc (subrun:sanitize-path log-prefix) "-")
+ "")
+ compact-stem
+ ".log"))
+ ;; swap out testpatt with modified test-patt and add -log
+ (switch-alist (cons
+ (cons "-log" logfile)
+ (map (lambda (item)
+ (if (equal? (car item) "-testpatt")
+ (cons "-testpatt" testpatt)
+ item))
+ switch-alist-pre))))
+ (with-output-to-file "subrun-command-parts.sexp"
+ (lambda ()
+ (pp switch-alist)))
+ switch-alist))
+ ;; note - get precmd from subrun section
+ ;; apply to submegatest commands
+
+(define (subrun:get-log-path test-run-dir log-prefix)
+ (let* ((alist (subrun:selector+log-alist test-run-dir log-prefix))
+ (res (alist-ref "-log" alist equal? #f)))
+ res))
+
+(define (subrun:selector+log-switches test-run-dir log-prefix)
+ (let* ((switch-alist (subrun:selector+log-alist test-run-dir log-prefix))
+ (res
+ (string-intersperse
+ (apply
+ append
+ (map
+ (lambda (x)
+ (list (car x) (cdr x)))
+ switch-alist))
+ " ")))
+ res))
+
+(define (subrun:exec-sub-megatest test-run-dir action-switches-str log-prefix)
+ (let* ((selector-switches (subrun:selector+log-switches test-run-dir log-prefix))
+ (cmd (conc "megatest " selector-switches " " action-switches-str ))
+ (pid #f)
+ (proc (lambda ()
+ (debug:print-info 0 *default-log-port* "Running sub megatest command: "cmd)
+ ;;(set! pid (process-run "/usr/bin/xterm" (list ))))))
+ (set! pid (process-run "/bin/bash" (list "-c" cmd))))))
+ (call-with-environment-variables
+ (list (cons "PATH" (conc (get-environment-variable "PATH") ":.")))
+ (lambda ()
+ (common:without-vars proc "^MT_.*")))
+ (let processloop ((i 0))
+ (let-values (((pid-val exit-status exit-code)(process-wait pid #t)))
+ (if (eq? pid-val 0)
+ (begin
+ (thread-sleep! 2)
+ (processloop (+ i 1)))
+ (begin
+ (debug:print-info 0 *default-log-port* "sub megatest " action-switches-str " completed with exit code " exit-code)
+ (if (eq? 0 exit-code)
+ (begin
+ #t)
+ (begin
+ #f))))))))
+
+
+
+;; (subrun:exec-sub-megatest "/nfs/pdx/disks/icf_env_disk001/bjbarcla/gwa/issues/mtdev/165/megatest/ext-tests/tests/subrun-usecases/toparea/links/SYSTEM_val/RELEASE_val/go/toptest" "-foo" "foo")
ADDED attic_modular/synchash.scm
Index: attic_modular/synchash.scm
==================================================================
--- /dev/null
+++ attic_modular/synchash.scm
@@ -0,0 +1,137 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+;;
+;;======================================================================
+
+;;======================================================================
+;; A hash of hashes that can be kept in sync by sending minial deltas
+;;======================================================================
+
+(use format)
+(use srfi-1 srfi-69 sqlite3)
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit synchash))
+(declare (uses db))
+(declare (uses server))
+
+(declare (uses dbmod))
+(import dbmod)
+
+(include "db_records.scm")
+
+(define (synchash:make)
+ (make-hash-table))
+
+;; given an alist of objects '((id obj) ...)
+;; 1. remove unchanged objects from the list
+;; 2. create a list of removed objects by id
+;; 3. remove removed objects from synchash
+;; 4. replace or add new or changed objects to synchash
+;;
+(define (synchash:get-delta indat synchash)
+ (let ((deleted '())
+ (changed '())
+ (found '())
+ (orig-keys (hash-table-keys synchash)))
+ (for-each
+ (lambda (item)
+ (let* ((id (car item))
+ (dat (cadr item))
+ (ref (hash-table-ref/default synchash id #f)))
+ (if (not (equal? dat ref)) ;; item changed or new
+ (begin
+ (set! changed (cons item changed))
+ (hash-table-set! synchash id dat)))
+ (set! found (cons id found))))
+ indat)
+ (for-each
+ (lambda (id)
+ (if (not (member id found))
+ (begin
+ (set! deleted (cons id deleted))
+ (hash-table-delete! synchash id))))
+ orig-keys)
+ (list changed deleted)
+ ;; (list indat '()) ;; just for debugging
+ ))
+
+;; keynum => the field to use as the unique key (usually 0 but can be other field)
+;;
+(define (synchash:client-get proc synckey keynum synchash run-id . params)
+ (let* ((data (rmt:synchash-get run-id proc synckey keynum params))
+ (newdat (car data))
+ (removs (cadr data))
+ (myhash (hash-table-ref/default synchash synckey #f)))
+ (if (not myhash)
+ (begin
+ (set! myhash (make-hash-table))
+ (hash-table-set! synchash synckey myhash)))
+ (for-each
+ (lambda (item)
+ (let ((id (car item))
+ (dat (cadr item)))
+ ;; (debug:print-info 2 *default-log-port* "Processing item: " item)
+ (hash-table-set! myhash id dat)))
+ newdat)
+ (for-each
+ (lambda (id)
+ (hash-table-delete! myhash id))
+ removs)
+ ;; WHICH ONE!?
+ ;; data)) ;; return the changed and deleted list
+ (list newdat removs))) ;; synchash))
+
+(define *synchashes* (make-hash-table))
+
+(define (synchash:server-get dbstruct run-id proc synckey keynum params)
+ ;; (debug:print-info 2 *default-log-port* "synckey: " synckey ", keynum: " keynum ", params: " params)
+ (let* ((dbdat (db:get-db dbstruct run-id))
+ (db (db:dbdat-get-db dbdat))
+ (synchash (hash-table-ref/default *synchashes* synckey #f))
+ (newdat (apply (case proc
+ ((db:get-runs) db:get-runs)
+ ((db:get-tests-for-run-mindata) db:get-tests-for-run-mindata)
+ ((db:get-test-info-by-ids) db:get-test-info-by-ids)
+ (else
+ (print "ERROR: sync for hash " proc " not setup! Edits needed in synchash.scm")
+ print))
+ db params))
+ (postdat #f)
+ (make-indexed (lambda (x)
+ (list (vector-ref x keynum) x))))
+ ;; Now process newdat based on the query type
+ (set! postdat (case proc
+ ((db:get-runs)
+ ;; (debug:print-info 2 *default-log-port* "Get runs call")
+ (let ((header (vector-ref newdat 0))
+ (data (vector-ref newdat 1)))
+ ;; (debug:print-info 2 *default-log-port* "header: " header ", data: " data)
+ (cons (list "header" header) ;; add the header keyed by the word "header"
+ (map make-indexed data)))) ;; add each element keyed by the keynum'th val
+ (else
+ ;; (debug:print-info 2 *default-log-port* "Non-get runs call")
+ (map make-indexed newdat))))
+ ;; (debug:print-info 2 *default-log-port* "postdat: " postdat)
+ ;; (if (not indb)(sqlite3:finalize! db))
+ (if (not synchash)
+ (begin
+ (set! synchash (make-hash-table))
+ (hash-table-set! *synchashes* synckey synchash)))
+ (synchash:get-delta postdat synchash)))
+
ADDED attic_modular/task_records.scm
Index: attic_modular/task_records.scm
==================================================================
--- /dev/null
+++ attic_modular/task_records.scm
@@ -0,0 +1,44 @@
+;;======================================================================
+;; Copyright 2006-2012, 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 .
+;;======================================================================
+
+;; make-vector-record tasks task id action owner state target name test item params creation_time execution_time
+(define (make-tasks:task)(make-vector 11))
+(define-inline (tasks:task-get-id vec) (vector-ref vec 0))
+(define-inline (tasks:task-get-action vec) (vector-ref vec 1))
+(define-inline (tasks:task-get-owner vec) (vector-ref vec 2))
+(define-inline (tasks:task-get-state vec) (vector-ref vec 3))
+(define-inline (tasks:task-get-target vec) (vector-ref vec 4))
+(define-inline (tasks:task-get-name vec) (vector-ref vec 5))
+(define-inline (tasks:task-get-testpatt vec) (vector-ref vec 6))
+(define-inline (tasks:task-get-keylock vec) (vector-ref vec 7))
+(define-inline (tasks:task-get-params vec) (vector-ref vec 8))
+(define-inline (tasks:task-get-creation_time vec) (vector-ref vec 9))
+(define-inline (tasks:task-get-execution_time vec) (vector-ref vec 10))
+
+(define-inline (tasks:task-set-state! vec val)(vector-set! vec 3 val))
+
+
+;; make-vector-record tasks monitor id pid start_time last_update hostname username
+(define (make-tasks:monitor)(make-vector 5))
+(define-inline (tasks:monitor-get-id vec) (vector-ref vec 0))
+(define-inline (tasks:monitor-get-pid vec) (vector-ref vec 1))
+(define-inline (tasks:monitor-get-start_time vec) (vector-ref vec 2))
+(define-inline (tasks:monitor-get-last_update vec) (vector-ref vec 3))
+(define-inline (tasks:monitor-get-hostname vec) (vector-ref vec 4))
+(define-inline (tasks:monitor-get-username vec) (vector-ref vec 5))
ADDED attic_modular/tasks.import.scm
Index: attic_modular/tasks.import.scm
==================================================================
--- /dev/null
+++ attic_modular/tasks.import.scm
@@ -0,0 +1,70 @@
+;;;; tasks.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ sqlite3
+ srfi-1
+ posix
+ regex
+ regex-case
+ srfi-69
+ dot-locking
+ format
+ srfi-18
+ (prefix sqlite3 sqlite3:)
+ commonmod
+ debugprint
+ configfmod
+ dbmod
+ margsmod
+ pgdb))
+(##sys#register-compiled-module
+ 'tasks
+ (list)
+ '((task:add-area-tag . tasks#task:add-area-tag)
+ (task:add-run-tag . tasks#task:add-run-tag)
+ (task:print-testtime-as-json . tasks#task:print-testtime-as-json)
+ (task:print-testtime . tasks#task:print-testtime)
+ (task:print-runtime-as-json . tasks#task:print-runtime-as-json)
+ (task:print-runtime . tasks#task:print-runtime)
+ (tasks:set-area . tasks#tasks:set-area)
+ (tasks:find-task-queue-records . tasks#tasks:find-task-queue-records)
+ (tasks:get-records-given-param-key
+ .
+ tasks#tasks:get-records-given-param-key)
+ (tasks:set-state-given-param-key . tasks#tasks:set-state-given-param-key)
+ (tasks:param-key->id . tasks#tasks:param-key->id)
+ (tasks:set-state . tasks#tasks:set-state)
+ (tasks:tasks->text . tasks#tasks:tasks->text)
+ (tasks:remove-queue-entries . tasks#tasks:remove-queue-entries)
+ (tasks:get-last . tasks#tasks:get-last)
+ (tasks:get-tasks . tasks#tasks:get-tasks)
+ (tasks:reset-stuck-tasks . tasks#tasks:reset-stuck-tasks)
+ (tasks:snag-a-task . tasks#tasks:snag-a-task)
+ (keys:key-vals-hash->target . tasks#keys:key-vals-hash->target)
+ (tasks:add . tasks#tasks:add)
+ (tasks:get-num-alive-monitors . tasks#tasks:get-num-alive-monitors)
+ (tasks:register-monitor . tasks#tasks:register-monitor)
+ (tasks:monitors-update . tasks#tasks:monitors-update)
+ (tasks:monitors->text-table . tasks#tasks:monitors->text-table)
+ (tasks:get-monitors . tasks#tasks:get-monitors)
+ (tasks:remove-monitor-record . tasks#tasks:remove-monitor-record)
+ (tasks:need-server . tasks#tasks:need-server)
+ (tasks:hostinfo-get-hostname . tasks#tasks:hostinfo-get-hostname)
+ (tasks:hostinfo-get-pid . tasks#tasks:hostinfo-get-pid)
+ (tasks:hostinfo-get-transport . tasks#tasks:hostinfo-get-transport)
+ (tasks:hostinfo-get-pubport . tasks#tasks:hostinfo-get-pubport)
+ (tasks:hostinfo-get-port . tasks#tasks:hostinfo-get-port)
+ (tasks:hostinfo-get-interface . tasks#tasks:hostinfo-get-interface)
+ (tasks:hostinfo-get-id . tasks#tasks:hostinfo-get-id)
+ (tasks:open-db . tasks#tasks:open-db)
+ (tasks:get-task-db-path . tasks#tasks:get-task-db-path)
+ (make-tasks:monitor . tasks#make-tasks:monitor)
+ (make-tasks:task . tasks#make-tasks:task))
+ (list)
+ (list))
+
+;; END OF FILE
ADDED attic_modular/tasks.scm
Index: attic_modular/tasks.scm
==================================================================
--- /dev/null
+++ attic_modular/tasks.scm
@@ -0,0 +1,648 @@
+;; Copyright 2006-2012, 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 .
+;;
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+(declare (unit tasks))
+(declare (uses pgdb))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses configfmod))
+(declare (uses dbmod))
+(declare (uses margsmod))
+
+(module tasks
+*
+
+(import scheme chicken data-structures extras)
+(use sqlite3 srfi-1 posix regex regex-case
+ srfi-69 dot-locking format srfi-18)
+(import (prefix sqlite3 sqlite3:))
+(import commonmod)
+(import debugprint)
+(import configfmod)
+(import dbmod)
+(import margsmod)
+(import pgdb)
+
+(include "task_records.scm")
+;; (include "db_records.scm")
+
+;;======================================================================
+;; Tasks db
+;;======================================================================
+
+(define (tasks:get-task-db-path)
+ (let ((dbdir (or (configf:lookup *configdat* "setup" "monitordir")
+ (configf:lookup *configdat* "setup" "dbdir")
+ (conc (common:get-linktree) "/.db"))))
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-error 0 *default-log-port* "Couldn't create path to " dbdir ", exn=" exn)
+ (exit 1))
+ (if (not (directory? dbdir))(create-directory dbdir #t)))
+ dbdir))
+
+;; If file exists AND
+;; file readable
+;; ==> open it
+;; If file exists AND
+;; file NOT readable
+;; ==> open in-mem version
+;; If file NOT exists
+;; ==> open in-mem version
+;;
+(define (tasks:open-db #!key (numretries 4))
+ (if *task-db*
+ *task-db*
+ (handle-exceptions
+ exn
+ (if (> numretries 0)
+ (begin
+ (print-call-chain (current-error-port))
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* " exn=" (condition->list exn))
+ (thread-sleep! 1)
+ (tasks:open-db numretries (- numretries 1)))
+ (begin
+ (print-call-chain (current-error-port))
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* " exn=" (condition->list exn))))
+ (let* ((dbpath (db:dbfile-path )) ;; (tasks:get-task-db-path))
+ (dbfile (conc dbpath "/monitor.db"))
+ (avail (tasks:wait-on-journal dbpath 10)) ;; wait up to about 10 seconds for the journal to go away
+ (exists (common:file-exists? dbpath))
+ (write-access (file-write-access? dbpath))
+ (mdb (cond ;; what the hek is *toppath* doing here?
+ ((and (string? *toppath*)(file-write-access? *toppath*))
+ (sqlite3:open-database dbfile))
+ ((file-read-access? dbpath) (sqlite3:open-database dbfile))
+ (else (sqlite3:open-database ":memory:")))) ;; (never-give-up-open-db dbpath))
+ (handler (sqlite3:make-busy-timeout 36000)))
+ (if (and exists
+ (not write-access))
+ (set! *db-write-access* write-access)) ;; only unset so other db's also can use this control
+ (sqlite3:set-busy-handler! mdb handler)
+ (db:set-sync mdb) ;; (sqlite3:execute mdb (conc "PRAGMA synchronous = 0;"))
+ ;; (if (or (and (not exists)
+ ;; (file-write-access? *toppath*))
+ ;; (not (file-read-access? dbpath)))
+ ;; (begin
+ ;;
+ ;; TASKS QUEUE MOVED TO main.db
+ ;;
+ ;; (sqlite3:execute mdb "CREATE TABLE IF NOT EXISTS tasks_queue (id INTEGER PRIMARY KEY,
+ ;; action TEXT DEFAULT '',
+ ;; owner TEXT,
+ ;; state TEXT DEFAULT 'new',
+ ;; target TEXT DEFAULT '',
+ ;; name TEXT DEFAULT '',
+ ;; testpatt TEXT DEFAULT '',
+ ;; keylock TEXT,
+ ;; params TEXT,
+ ;; creation_time TIMESTAMP,
+ ;; execution_time TIMESTAMP);")
+ (sqlite3:execute mdb "CREATE TABLE IF NOT EXISTS monitors (id INTEGER PRIMARY KEY,
+ pid INTEGER,
+ start_time TIMESTAMP,
+ last_update TIMESTAMP,
+ hostname TEXT,
+ username TEXT,
+ CONSTRAINT monitors_constraint UNIQUE (pid,hostname));")
+ (sqlite3:execute mdb "CREATE TABLE IF NOT EXISTS servers (id INTEGER PRIMARY KEY,
+ pid INTEGER,
+ interface TEXT,
+ hostname TEXT,
+ port INTEGER,
+ pubport INTEGER,
+ start_time TIMESTAMP,
+ priority INTEGER,
+ state TEXT,
+ mt_version TEXT,
+ heartbeat TIMESTAMP,
+ transport TEXT,
+ run_id INTEGER);")
+ ;; CONSTRAINT servers_constraint UNIQUE (pid,hostname,port));")
+ (sqlite3:execute mdb "CREATE TABLE IF NOT EXISTS clients (id INTEGER PRIMARY KEY,
+ server_id INTEGER,
+ pid INTEGER,
+ hostname TEXT,
+ cmdline TEXT,
+ login_time TIMESTAMP,
+ logout_time TIMESTAMP DEFAULT -1,
+ CONSTRAINT clients_constraint UNIQUE (pid,hostname));")
+
+ ;))
+ (set! *task-db* (cons mdb dbpath))
+ *task-db*))))
+
+;;======================================================================
+;; Server and client management
+;;======================================================================
+
+;; make-vector-record tasks hostinfo id interface port pubport transport pid hostname
+(define (tasks:hostinfo-get-id vec) (vector-ref vec 0))
+(define (tasks:hostinfo-get-interface vec) (vector-ref vec 1))
+(define (tasks:hostinfo-get-port vec) (vector-ref vec 2))
+(define (tasks:hostinfo-get-pubport vec) (vector-ref vec 3))
+(define (tasks:hostinfo-get-transport vec) (vector-ref vec 4))
+(define (tasks:hostinfo-get-pid vec) (vector-ref vec 5))
+(define (tasks:hostinfo-get-hostname vec) (vector-ref vec 6))
+
+(define (tasks:need-server run-id)
+ (equal? (configf:lookup *configdat* "server" "required") "yes"))
+
+
+;;======================================================================
+;; M O N I T O R S
+;;======================================================================
+
+(define (tasks:remove-monitor-record mdb)
+ (sqlite3:execute mdb "DELETE FROM monitors WHERE pid=? AND hostname=?;"
+ (current-process-id)
+ (get-host-name)))
+
+(define (tasks:get-monitors mdb)
+ (let ((res '()))
+ (sqlite3:for-each-row
+ (lambda (a . rem)
+ (set! res (cons (apply vector a rem) res)))
+ mdb
+ "SELECT id,pid,strftime('%m/%d/%Y %H:%M',datetime(start_time,'unixepoch'),'localtime'),strftime('%m/%d/%Y %H:%M:%S',datetime(last_update,'unixepoch'),'localtime'),hostname,username FROM monitors ORDER BY last_update ASC;")
+ (reverse res)
+ ))
+
+(define (tasks:monitors->text-table monitors)
+ (let ((fmtstr "~4a~8a~20a~20a~10a~10a"))
+ (conc (format #f fmtstr "id" "pid" "start time" "last update" "hostname" "user") "\n"
+ (string-intersperse
+ (map (lambda (monitor)
+ (format #f fmtstr
+ (tasks:monitor-get-id monitor)
+ (tasks:monitor-get-pid monitor)
+ (tasks:monitor-get-start_time monitor)
+ (tasks:monitor-get-last_update monitor)
+ (tasks:monitor-get-hostname monitor)
+ (tasks:monitor-get-username monitor)))
+ monitors)
+ "\n"))))
+
+;; update the last_update field with the current time and
+;; if any monitors appear dead, remove them
+(define (tasks:monitors-update mdb)
+ (sqlite3:execute mdb "UPDATE monitors SET last_update=strftime('%s','now') WHERE pid=? AND hostname=?;"
+ (current-process-id)
+ (get-host-name))
+ (let ((deadlist '()))
+ (sqlite3:for-each-row
+ (lambda (id pid host last-update delta)
+ (print "Going to delete stale record for monitor with pid " pid " on host " host " last updated " delta " seconds ago")
+ (set! deadlist (cons id deadlist)))
+ mdb
+ "SELECT id,pid,hostname,last_update,strftime('%s','now')-last_update AS delta FROM monitors WHERE delta > 700;")
+ (sqlite3:execute mdb (conc "DELETE FROM monitors WHERE id IN ('" (string-intersperse (map conc deadlist) "','") "');")))
+ )
+(define (tasks:register-monitor db port)
+ (let* ((pid (current-process-id))
+ (hostname (get-host-name))
+ (userinfo (user-information (current-user-id)))
+ (username (car userinfo)))
+ (print "Register monitor, pid: " pid ", hostname: " hostname ", port: " port ", username: " username)
+ (sqlite3:execute db "INSERT INTO monitors (pid,start_time,last_update,hostname,username) VALUES (?,strftime('%s','now'),strftime('%s','now'),?,?);"
+ pid hostname username)))
+
+(define (tasks:get-num-alive-monitors mdb)
+ (let ((res 0))
+ (sqlite3:for-each-row
+ (lambda (count)
+ (set! res count))
+ mdb
+ "SELECT count(id) FROM monitors WHERE last_update < (strftime('%s','now') - 300) AND username=?;"
+ (car (user-information (current-user-id))))
+ res))
+
+;;
+;; (define (tasks:start-monitor db mdb)
+;; (if (> (tasks:get-num-alive-monitors mdb) 2) ;; have two running, no need for more
+;; (debug:print-info 1 *default-log-port* "Not starting monitor, already have more than two running")
+;; (let* ((megatestdb (conc *toppath* "/megatest.db"))
+;; (monitordbf (conc (db:dbfile-path #f) "/monitor.db"))
+;; (last-db-update 0)) ;; (file-modification-time megatestdb)))
+;; (task:register-monitor mdb)
+;; (let loop ((count 0)
+;; (next-touch 0)) ;; next-touch is the time where we need to update last_update
+;; ;; if the db has been modified we'd best look at the task queue
+;; (let ((modtime (file-modification-time megatestdbpath )))
+;; (if (> modtime last-db-update)
+;; (tasks:process-queue db)) ;; BROKEN. mdb last-db-update megatestdb next-touch))
+;; ;; WARNING: Possible race conditon here!!
+;; ;; should this update be immediately after the task-get-action call above?
+;; (if (> (current-seconds) next-touch)
+;; (begin
+;; (tasks:monitors-update mdb)
+;; (loop (+ count 1)(+ (current-seconds) 240)))
+;; (loop (+ count 1) next-touch)))))))
+
+;;======================================================================
+;; T A S K S Q U E U E
+;;
+;; NOTE:: These operate on task_queue which is in main.db
+;;
+;;======================================================================
+
+;; NOTE: It might be good to add one more layer of checking to ensure
+;; that no task gets run in parallel.
+
+;; id INTEGER PRIMARY KEY,
+;; action TEXT DEFAULT '',
+;; owner TEXT,
+;; state TEXT DEFAULT 'new',
+;; target TEXT DEFAULT '',
+;; name TEXT DEFAULT '',
+;; testpatt TEXT DEFAULT '',
+;; keylock TEXT,
+;; params TEXT,
+;; creation_time TIMESTAMP DEFAULT (strftime('%s','now')),
+;; execution_time TIMESTAMP);
+
+
+;; register a task
+(define (tasks:add dbstruct action owner target runname testpatt params)
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ (sqlite3:execute db "INSERT INTO tasks_queue (action,owner,state,target,name,testpatt,params,creation_time,execution_time)
+ VALUES (?,?,'new',?,?,?,?,strftime('%s','now'),0);"
+ action
+ owner
+ target
+ runname
+ testpatt
+ (if params params "")))))
+
+(define (keys:key-vals-hash->target keys key-params)
+ (let ((tmp (hash-table-ref/default key-params (vector-ref (car keys) 0) "")))
+ (if (> (length keys) 1)
+ (for-each (lambda (key)
+ (set! tmp (conc tmp "/" (hash-table-ref/default key-params (vector-ref key 0) ""))))
+ (cdr keys)))
+ tmp))
+
+;; for use from the gui, not ported
+;;
+;; (define (tasks:add-from-params mdb action keys key-params var-params)
+;; (let ((target (keys:key-vals-hash->target keys key-params))
+;; (owner (car (user-information (current-user-id))))
+;; (runname (hash-table-ref/default var-params "runname" #f))
+;; (testpatts (hash-table-ref/default var-params "testpatts" "%"))
+;; (params (hash-table-ref/default var-params "params" "")))
+;; (tasks:add mdb action owner target runname testpatts params)))
+
+;; return one task from those who are 'new' OR 'waiting' AND more than 10sec old
+;;
+(define (tasks:snag-a-task dbstruct)
+ (let ((res #f)
+ (keytxt (conc (current-process-id) "-" (get-host-name) "-" (car (user-information (current-user-id))))))
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ ;; first randomly set a new to pid-hostname-hostname
+ (sqlite3:execute
+ db
+ "UPDATE tasks_queue SET keylock=? WHERE id IN
+ (SELECT id FROM tasks_queue
+ WHERE state='new' OR
+ (state='waiting' AND (strftime('%s','now')-execution_time) > 10) OR
+ state='reset'
+ ORDER BY RANDOM() LIMIT 1);" keytxt)
+
+ (sqlite3:for-each-row
+ (lambda (id . rem)
+ (set! res (apply vector id rem)))
+ db
+ "SELECT id,action,owner,state,target,name,test,item,params,creation_time,execution_time FROM tasks_queue WHERE keylock=? ORDER BY execution_time ASC LIMIT 1;" keytxt)
+ (if res ;; yep, have work to be done
+ (begin
+ (sqlite3:execute db "UPDATE tasks_queue SET state='inprogress',execution_time=strftime('%s','now') WHERE id=?;"
+ (tasks:task-get-id res))
+ res)
+ #f)))))
+
+(define (tasks:reset-stuck-tasks dbstruct)
+ (let ((res '()))
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ (sqlite3:for-each-row
+ (lambda (id delta)
+ (set! res (cons id res)))
+ db
+ "SELECT id,strftime('%s','now')-execution_time AS delta FROM tasks_queue WHERE state='inprogress' AND delta>700 ORDER BY delta DESC LIMIT 2;")
+ (sqlite3:execute
+ db
+ (conc "UPDATE tasks_queue SET state='reset' WHERE id IN ('" (string-intersperse (map conc res) "','") "');")
+ )))))
+
+;; return all tasks in the tasks_queue table
+;;
+(define (tasks:get-tasks dbstruct types states)
+ (let ((res '()))
+ (db:with-db
+ dbstruct #f #f
+ (lambda (db)
+ (sqlite3:for-each-row
+ (lambda (id . rem)
+ (set! res (cons (apply vector id rem) res)))
+ db
+ (conc "SELECT id,action,owner,state,target,name,test,item,params,creation_time,execution_time
+ FROM tasks_queue "
+ ;; WHERE
+ ;; state IN " statesstr " AND
+ ;; action IN " actionsstr
+ " ORDER BY creation_time DESC;"))
+ res))))
+
+(define (tasks:get-last dbstruct target runname)
+ (let ((res #f))
+ (db:with-db
+ dbstruct #f #f
+ (lambda (db)
+ (sqlite3:for-each-row
+ (lambda (id . rem)
+ (set! res (apply vector id rem)))
+ db
+ (conc "SELECT id,action,owner,state,target,name,testpatt,keylock,params,creation_time,execution_time
+ FROM tasks_queue
+ WHERE
+ target = ? AND name =?
+ ORDER BY creation_time DESC LIMIT 1;")
+ target runname)
+ res))))
+
+;; remove tasks given by a string of numbers comma separated
+(define (tasks:remove-queue-entries dbstruct task-ids)
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ (sqlite3:execute db (conc "DELETE FROM tasks_queue WHERE id IN (" task-ids ");")))))
+
+;; (define (tasks:process-queue dbstruct)
+;; (let* ((task (tasks:snag-a-task dbstruct))
+;; (action (if task (tasks:task-get-action task) #f)))
+;; (if action (print "tasks:process-queue task: " task))
+;; (if action
+;; (case (string->symbol action)
+;; ((run) (tasks:start-run dbstruct task))
+;; ((remove) (tasks:remove-runs dbstruct task))
+;; ((lock) (tasks:lock-runs dbstruct task))
+;; ;; ((monitor) (tasks:start-monitor db task))
+;; #;((rollup) (tasks:rollup-runs dbstruct task))
+;; ((updatemeta)(tasks:update-meta dbstruct task))
+;; #;((kill) (tasks:kill-monitors dbstruct task))))))
+
+(define (tasks:tasks->text tasks)
+ (let ((fmtstr "~10a~10a~10a~12a~20a~12a~12a~10a"))
+ (conc (format #f fmtstr "id" "action" "owner" "state" "target" "runname" "testpatts" "params") "\n"
+ (string-intersperse
+ (map (lambda (task)
+ (format #f fmtstr
+ (tasks:task-get-id task)
+ (tasks:task-get-action task)
+ (tasks:task-get-owner task)
+ (tasks:task-get-state task)
+ (tasks:task-get-target task)
+ (tasks:task-get-name task)
+ (tasks:task-get-testpatt task)
+ ;; (tasks:task-get-item task)
+ (tasks:task-get-params task)))
+ tasks) "\n"))))
+
+(define (tasks:set-state dbstruct task-id state)
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ (sqlite3:execute db "UPDATE tasks_queue SET state=? WHERE id=?;"
+ state
+ task-id))))
+
+;;======================================================================
+;; Access using task key (stored in params; (hash-table->alist flags) hostname pid
+;;======================================================================
+
+(define (tasks:param-key->id dbstruct task-params)
+ (db:with-db
+ dbstruct #f #f
+ (lambda (db)
+ (handle-exceptions
+ exn
+ #f
+ (sqlite3:first-result db "SELECT id FROM tasks_queue WHERE params LIKE ?;"
+ task-params)))))
+
+(define (tasks:set-state-given-param-key dbstruct param-key new-state)
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ (sqlite3:execute db "UPDATE tasks_queue SET state=? WHERE params LIKE ?;" new-state param-key))))
+
+(define (tasks:get-records-given-param-key dbstruct param-key state-patt action-patt test-patt)
+ (db:with-db
+ dbstruct #f #f
+ (lambda (db)
+ (handle-exceptions
+ exn
+ '()
+ (sqlite3:first-row db "SELECT id,action,owner,state,target,name,testpatt,keylock,params WHERE
+ params LIKE ? AND state LIKE ? AND action LIKE ? AND testpatt LIKE ?;"
+ param-key state-patt action-patt test-patt)))))
+
+(define (tasks:find-task-queue-records dbstruct target run-name test-patt state-patt action-patt)
+ ;; (handle-exceptions
+ ;; exn
+ ;; '()
+ ;; (sqlite3:first-row
+ (let (;; (db (db:get-db dbstruct))
+ (res '()))
+ (db:with-db
+ dbstruct #f #t
+ (lambda (db)
+ (sqlite3:for-each-row
+ (lambda (a . b)
+ (set! res (cons (cons a b) res)))
+ db
+ "SELECT id,action,owner,state,target,name,testpatt,keylock,params FROM tasks_queue
+ WHERE
+ target = ? AND name = ? AND state LIKE ? AND action LIKE ? AND testpatt LIKE ?;"
+ target run-name state-patt action-patt test-patt)
+ res)))) ;; )
+
+;; (define (tasks:start-run dbstruct mdb task)
+;; (let ((flags (make-hash-table)))
+;; (hash-table-set! flags "-rerun" "NOT_STARTED")
+;; (if (not (string=? (tasks:task-get-params task) ""))
+;; (hash-table-set! flags "-setvars" (tasks:task-get-params task)))
+;; (print "Starting run " task)
+;; ;; sillyness, just call the damn routine with the task vector and be done with it. FIXME SOMEDAY
+;; (runs:run-tests db
+;; (tasks:task-get-target task)
+;; (tasks:task-get-name task)
+;; (tasks:task-get-test task)
+;; (tasks:task-get-item task)
+;; (tasks:task-get-owner task)
+;; flags)
+;; (tasks:set-state mdb (tasks:task-get-id task) "waiting")))
+;;
+;; (define (tasks:rollup-runs db mdb task)
+;; (let* ((flags (make-hash-table))
+;; (keys (db:get-keys db))
+;; (keyvals (keys:target-keyval keys (tasks:task-get-target task))))
+;; ;; (hash-table-set! flags "-rerun" "NOT_STARTED")
+;; (print "Starting rollup " task)
+;; ;; sillyness, just call the damn routine with the task vector and be done with it. FIXME SOMEDAY
+;; (runs:rollup-run db
+;; keys
+;; keyvals
+;; (tasks:task-get-name task)
+;; (tasks:task-get-owner task))
+;; (tasks:set-state mdb (tasks:task-get-id task) "waiting")))
+
+;;======================================================================
+;; S Y N C T O P O S T G R E S Q L
+;;======================================================================
+
+;; In the spirit of "dump your junk in the tasks module" I'll put the
+;; sync to postgres here for now.
+
+;; attempt to automatically set up an area. call only if get area by path
+;; returns naught of interest
+;;
+(define (tasks:set-area dbh configdat #!key (toppath #f)) ;; could I safely put *toppath* in for the default for toppath? when would it be evaluated?
+ (let loop ((area-name (or (configf:lookup configdat "setup" "area-name")
+ (common:get-area-name)))
+ (modifier 'none))
+ (let ((success (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: cannot create area entry, " ((condition-property-accessor 'exn 'message) exn))
+ #f) ;; FIXME: I don't care for now but I should look at *why* there was an exception
+ (pgdb:add-area dbh area-name (or toppath *toppath*)))))
+ (or success
+ (case modifier
+ ((none)(loop (conc (current-user-name) "_" area-name) 'user))
+ ((user)(loop (conc (substring (common:get-area-path-signature) 0 4)
+ area-name) 'areasig))
+ (else #f)))))) ;; give up
+
+(define (task:print-runtime run-times saperator)
+ (for-each
+ (lambda (run-time-info)
+ (let* ((run-name (vector-ref run-time-info 0))
+ (run-time (vector-ref run-time-info 1))
+ (target (vector-ref run-time-info 2)))
+ (print target saperator run-name saperator run-time )))
+ run-times))
+
+(define (task:print-runtime-as-json run-times)
+ (let loop ((run-time-info (car run-times))
+ (rema (cdr run-times))
+ (str ""))
+ (let* ((run-name (vector-ref run-time-info 0))
+ (run-time (vector-ref run-time-info 1))
+ (target (vector-ref run-time-info 2)))
+ ;(print (not (equal? str "")))
+ (if (not (equal? str ""))
+ (set! str (conc str ",")))
+ (if (null? rema)
+ (print "[" str "{target:" target ",run-name:" run-name ", run-time:" run-time "}]")
+ (loop (car rema) (cdr rema) (conc str "{target:" target ", run-name:" run-name ", run-time:" run-time "}"))))))
+
+
+(define (task:print-testtime test-times saperator)
+ (for-each
+ (lambda (test-time-info)
+ (let* ((test-name (vector-ref test-time-info 0))
+ (test-time (vector-ref test-time-info 2))
+ (test-item (if (eq? (string-length (vector-ref test-time-info 1)) 0)
+ "N/A"
+ (vector-ref test-time-info 1))))
+ (print test-name saperator test-item saperator test-time )))
+ test-times))
+
+(define (task:print-testtime-as-json test-times)
+ (let loop ((test-time-info (car test-times))
+ (rema (cdr test-times))
+ (str ""))
+ (let* ((test-name (vector-ref test-time-info 0))
+ (test-time (vector-ref test-time-info 2))
+ (item (vector-ref test-time-info 1)))
+ ;(print (not (equal? str "")))
+ (if (not (equal? str ""))
+ (set! str (conc str ",")))
+ (if (null? rema)
+ (print "[" str "{test-name:" test-name ", item-path:" item ", test-time:" test-time "}]")
+ (loop (car rema) (cdr rema) (conc str "{test-name:" test-name ", item-path:" item ", test-time:" test-time "}"))))))
+
+
+
+
+(define (task:add-run-tag dbh run-id tag)
+ (let* ((tag-info (pgdb:get-tag-info-by-name dbh tag)))
+ (if (not tag-info)
+ (begin
+ (if (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 1 *default-log-port* ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (pgdb:insert-tag dbh tag))
+ (set! tag-info (pgdb:get-tag-info-by-name dbh tag))
+ #f)))
+ ;;add to area_tags
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 1 *default-log-port* ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (if (not (pgdb:is-run-taged-with-a-tag dbh (vector-ref tag-info 0) run-id))
+ (pgdb:insert-run-tag dbh (vector-ref tag-info 0) run-id)))))
+
+
+(define (task:add-area-tag dbh area-info tag)
+ (let* ((tag-info (pgdb:get-tag-info-by-name dbh tag)))
+ (if (not tag-info)
+ (begin
+ (if (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 1 *default-log-port* ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (pgdb:insert-tag dbh tag))
+ (set! tag-info (pgdb:get-tag-info-by-name dbh tag))
+ #f)))
+ ;;add to area_tags
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print-info 1 *default-log-port* ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ (if (not (pgdb:is-area-taged-with-a-tag dbh (vector-ref tag-info 0) (vector-ref area-info 0)))
+ (pgdb:insert-area-tag dbh (vector-ref tag-info 0) (vector-ref area-info 0))))))
+
+
+)
ADDED attic_modular/tcmt.scm
Index: attic_modular/tcmt.scm
==================================================================
--- /dev/null
+++ attic_modular/tcmt.scm
@@ -0,0 +1,391 @@
+;; 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 .
+
+;;======================================================================
+;;
+;; Wrapper to enable running Megatest flows under teamcity
+;;
+;; 1. Run the megatest process and pass it all the needed parameters
+;; 2. Every five seconds check for state/status changes and print the info
+;;
+
+(use srfi-1 posix srfi-69 srfi-18 regex defstruct)
+
+(use trace)
+;; (trace-call-sites #t)
+
+(declare (uses rmt))
+(declare (uses common))
+(declare (uses margsmod))
+(import margsmod)
+
+;; (declare (uses megatest-version))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(include "megatest-version.scm")
+(include "megatest-fossil-hash.scm")
+(include "db_records.scm")
+
+(define origargs (cdr (argv)))
+(define remargs (args:get-args
+ (argv)
+ `( "-target"
+ "-reqtarg"
+ "-runname"
+ "-delay" ;; how long to wait for unexpected changes to
+ )
+ `("-tc-repl"
+ )
+ args:arg-hash
+ 0))
+
+(defstruct testdat
+ (tc-type #f)
+ (state #f)
+ (status #f)
+ (overall #f)
+ (flowid #f)
+ tctname
+ tname
+ (event-time #f)
+ details
+ comment
+ duration
+ (start-printed #f)
+ (end-printed #f))
+
+;;======================================================================
+;; GLOBALS
+;;======================================================================
+
+;; Gotta have a global? Stash it in the *global* hash table.
+;;
+(define *global* (make-hash-table))
+
+(define (tcmt:print tdat flush-mode)
+ (let* ((comment (if (testdat-comment tdat)
+ (conc " message='" (testdat-comment tdat) "'")
+ ""))
+ (details (if (testdat-details tdat)
+ (conc " details='" (testdat-details tdat) "'")
+ ""))
+ (flowid (conc " flowId='" (testdat-flowid tdat) "'"))
+ (duration (conc " duration='" (* 1e3 (testdat-duration tdat)) "'"))
+ (tcname (conc " name='" (testdat-tctname tdat) "'"))
+ (state (string->symbol (testdat-state tdat)))
+ (status (string->symbol (testdat-status tdat)))
+ (startp (testdat-start-printed tdat))
+ (endp (testdat-end-printed tdat))
+ (etime (testdat-event-time tdat))
+ (overall (case state
+ ((RUNNING) state)
+ ((COMPLETED) state)
+ (else 'UNK)))
+ (tstmp (conc " timestamp='" (time->string (seconds->local-time etime) "%FT%T.000") "'")))
+ (case overall
+ ((RUNNING)
+ (if (not startp)
+ (begin
+ (print "##teamcity[testStarted " tcname flowid tstmp "]")
+ (testdat-start-printed-set! tdat #t))))
+ ((COMPLETED)
+ (if (not startp) ;; start stanza never printed
+ (begin
+ (print "##teamcity[testStarted " tcname flowid tstmp "]")
+ (testdat-start-printed-set! tdat #t)))
+ (if (not endp)
+ (begin
+ (if (not (member status '(PASS WARN SKIP WAIVED)))
+ (print "##teamcity[testFailed " tcname flowid comment details "]"))
+ (print "##teamcity[testFinished" tcname flowid comment details duration "]")
+ (testdat-end-printed-set! tdat #t))))
+ (else
+ (if flush-mode
+ (begin
+ (if (not startp)
+ (begin
+ (print "##teamcity[testStarted " tcname flowid tstmp "]")
+ (testdat-start-printed-set! tdat #t)))
+ (if (not endp)
+ (begin
+ (print "##teamcity[testFailed " tcname flowid comment details "]")
+ (print "##teamcity[testFinished" tcname flowid comment details duration "]")
+ (testdat-end-printed-set! tdat #t)))))))
+ ;; (print "ERROR: tc-type \"" (testdat-tc-type tdat) "\" not recognised for " tcname)))
+ (flush-output)))
+
+;; ;; returns values: flag newlst
+;; (define (remove-duplicate-completed tdats)
+;; (let* ((flag #f)
+;; (state (testdat-state tdat))
+;; (status (testdat-status tdat))
+;; (event-time (testdat-event-time tdat))
+;; (tname (testdat-tname tdat)))
+;; (let loop ((hed (car tdats))
+;; (tal (cdr tdats))
+;; (new '()))
+;; (if (and (equal? state "COMPLETED")
+;; (equal? tname (testdat-tname hed))
+;; (equal? state (testdat-state hed))) ;; we have a duplicate COMPLETED call
+;; (begin
+;; (set! flag #t) ;; A changed completed
+
+;; process the queue of tests gathered so far. List includes one entry for every test so far seen
+;; the last record for a test is preserved. Items are only removed from the list if over 15 seconds
+;; have passed since it happened. This allows for compression of COMPLETED/FAIL followed by some other
+;; state/status
+;;
+(define (process-queue data age flush-mode)
+ ;; here we process tqueue and gather those over 15 seconds (configurable?) old
+ (let* ((print-time (- (current-seconds) age)) ;; print stuff over 15 seconds old
+ (tqueue-raw (hash-table-ref/default data 'tqueue '()))
+ (tqueue (reverse (delete-duplicates tqueue-raw ;; REMOVE duplicates by testname and state
+ (lambda (a b)
+ (and (equal? (testdat-tname a)(testdat-tname b)) ;; need oldest to newest
+ (equal? (testdat-state a) (testdat-state b)))))))) ;; "COMPLETED")
+ ;; (equal? (testdat-state b) "COMPLETED")))))))
+ (if (not (null? tqueue))
+ (hash-table-set!
+ data
+ 'tqueue
+ (let loop ((hed (car tqueue)) ;; by this point all duplicates by state COMPLETED are removed
+ (tal (cdr tqueue))
+ (rem '()))
+ (if (> print-time (testdat-event-time hed)) ;; event happened over 15 seconds ago
+ (begin
+ (tcmt:print hed flush-mode)
+ (if (null? tal)
+ rem ;; return rem to be processed in the future
+ (loop (car tal)(cdr tal) rem)))
+ (if (null? tal)
+ (cons hed rem) ;; return rem + hed for future processing
+ (loop (car tal)(cdr tal)(cons hed rem)))))))))
+
+;; ##teamcity[testStarted name='suite.testName']
+;; ##teamcity[testStdOut name='suite.testName' out='text']
+;; ##teamcity[testStdErr name='suite.testName' out='error text']
+;; ##teamcity[testFailed name='suite.testName' message='failure message' details='message and stack trace']
+;; ##teamcity[testFinished name='suite.testName' duration='50']
+;;
+;; flush; #f, normal call. #t, last call, print out something for NOT_STARTED, etc.
+;;
+
+;;;;;;; (begin
+;;;;;;; (case (string->symbol newstat)
+;;;;;;; ((UNK) ) ;; do nothing
+;;;;;;; ((RUNNING) (print "##teamcity[testStarted name='" tctname "' flowId='" flowid "']"))
+;;;;;;; ((PASS SKIP WARN WAIVED) (print "##teamcity[testFinished name='" tctname "' duration='" (* 1e3 duration) "'" cmtstr details " flowId='" flowid "']"))
+;;;;;;; (else
+;;;;;;; (print "##teamcity[testFailed name='" tctname "' " cmtstr details " flowId='" flowid "']")))
+;;;;;;; (flush-output)
+
+;; (trace rmt:get-tests-for-run)
+
+(define (update-queue-since data run-ids last-update tsname target runname flowid flush #!key (delay-flag #t)) ;;
+ (let ((now (current-seconds))
+ (still-running #f))
+;; (handle-exceptions
+;; exn
+;; (begin (print-call-chain) (print "Error message: " ((condition-property-accessor 'exn 'message) exn)))
+ (for-each
+ (lambda (run-id)
+ (let* ((tests (rmt:get-tests-for-run run-id "%" '() '() #f #f #f #f #f #f last-update #f)))
+ ;; (print "DEBUG: got tests=" tests)
+ (for-each
+ (lambda (test-rec)
+ (let* ((tqueue (hash-table-ref/default data 'tqueue '())) ;; NOTE: the key is a symbol! This allows keeping disparate info in the one hash, lazy but a quick solution for right now.
+ (is-top (db:test-get-is-toplevel test-rec))
+ (tname (db:test-get-fullname test-rec))
+ (testname (db:test-get-testname test-rec))
+ (itempath (db:test-get-item-path test-rec))
+ (tctname (if (string=? itempath "") testname (conc testname "." (string-translate itempath "/" "."))))
+ (state (db:test-get-state test-rec))
+ (status (db:test-get-status test-rec))
+ (etime (db:test-get-event_time test-rec))
+ (duration (or (any->number (db:test-get-run_duration test-rec)) 0))
+ (comment (db:test-get-comment test-rec))
+ (logfile (db:test-get-final_logf test-rec))
+ (hostn (db:test-get-host test-rec))
+ (pid (db:test-get-process_id test-rec))
+ (test-cont (> (+ etime duration 40) (current-seconds))) ;; test has not been over for more than 20 seconds
+ (adj-state (if delay-flag
+ (if test-cont
+ (begin
+ (set! still-running #t)
+ "RUNNING")
+ state)
+ state))
+ (newstat (cond
+ ;; ((or (not delay-flag)
+ ;; (< (+ etime duration)
+ ;; (- (current-seconds) 10)))
+ ;; (print "Skipping as delay hasn't hit") "RUNNING")
+ ((equal? adj-state "RUNNING")
+ (set! still-running #t)
+ "RUNNING")
+ ((equal? adj-state "COMPLETED")
+ status)
+ (flush (conc state "/" status))
+ (else "UNK")))
+ (cmtstr (if (and (not flush) comment)
+ comment
+ (if flush
+ (conc "Test ended in state/status="
+ state "/" status
+ (if (string-match "^\\s*$" comment)
+ ", no Megatest comment found."
+ (conc ", Megatest comment=\"" comment "\""))) ;; special case, we are handling stragglers
+ #f)))
+ (details (if (string-match ".*html$" logfile)
+ (conc *toppath* "/lt/" target "/" runname "/" testname
+ (if (equal? itempath "") "/" (conc "/" itempath "/"))
+ logfile)
+ #f))
+ (prev-tdat (hash-table-ref/default data tname #f))
+ (tdat (if is-top
+ #f
+ (let ((new (or prev-tdat (make-testdat)))) ;; recycle the record so we keep track of already printed items
+ (testdat-flowid-set! new (or (testdat-flowid new)
+ (if (eq? pid 0)
+ tctname
+ (conc hostn "-" pid))))
+ (testdat-tctname-set! new tctname)
+ (testdat-tname-set! new tname)
+ (testdat-state-set! new adj-state)
+ (testdat-status-set! new status)
+ (testdat-comment-set! new cmtstr)
+ (testdat-details-set! new details)
+ (testdat-duration-set! new duration)
+ (testdat-event-time-set! new etime) ;; (current-seconds))
+ (testdat-overall-set! new newstat)
+ (hash-table-set! data tname new)
+ new))))
+ (if (not is-top)
+ (hash-table-set! data 'tqueue (cons tdat tqueue)))
+ (hash-table-set! data tname tdat)
+ ))
+ tests)))
+ run-ids)
+ (list now still-running)))
+
+(define (monitor pid)
+ (let* ((run-ids '())
+ (testdats (make-hash-table)) ;; each entry is a list of testdat structs
+ (keys #f)
+ (last-update 0)
+ (target (or (args:get-arg "-target")
+ (args:get-arg "-reqtarg")))
+ (runname (args:get-arg "-runname"))
+ (tsname #f)
+ (flowid (conc target "/" runname))
+ (tdelay (string->number (or (args:get-arg "-delay") "15"))))
+ (if (and target runname)
+ (begin
+ (launch:setup)
+ (set! keys (rmt:get-keys))))
+ (set! tsname (common:get-testsuite-name))
+ (print "TCMT: for testsuite=" tsname " found runname=" runname ", target=" target ", keys=" keys " and successfully ran launch:setup. Using " flowid " as the flowId.")
+ (let loop ()
+ ;;;;;; (handle-exceptions
+ ;;;;;; exn
+ ;;;;;; ;; (print "Process done.")
+ ;;;;;; (begin (print-call-chain) (print "Error message: " ((condition-property-accessor 'exn 'message) exn)))
+ (let-values (((pidres exittype exitstatus)
+ (process-wait pid #t)))
+ (if (and keys
+ (or (not run-ids)
+ (null? run-ids)))
+ (let* ((runs (rmt:get-runs-by-patt keys
+ runname
+ target
+ #f ;; offset
+ #f ;; limit
+ #f ;; fields
+ 0 ;; last-update
+ ))
+ (header (db:get-header runs))
+ (rows (db:get-rows runs))
+ (run-ids-in (map (lambda (row)
+ (db:get-value-by-header row header "id"))
+ rows)))
+ (set! run-ids run-ids-in)))
+ ;; (print "TCMT: pidres=" pidres " exittype=" exittype " exitstatus=" exitstatus " run-ids=" run-ids)
+ (if (eq? pidres 0)
+ (begin
+ (if keys
+ (begin
+ (set! last-update (- (car (update-queue-since testdats run-ids last-update tsname target runname flowid #f delay-flag: #t)) 5))
+ (process-queue testdats tdelay #f)))
+ (thread-sleep! 3)
+ (loop)))))
+ ;; the megatest runner is done - now wait for all processes to be COMPLETED or NO Processes to be RUNNING > 1 minute
+ (let loop ()
+ (let* ((new-last-update-info (update-queue-since testdats run-ids last-update tsname target runname flowid #f delay-flag: #t))
+ (still-running (cadr new-last-update-info))
+ (new-last-update (- (car new-last-update-info) 5)))
+ (process-queue testdats tdelay #f)
+ (if still-running
+ (begin
+ (print "TCMT: Tests still running, keep watching...")
+ (thread-sleep! 3)
+ (loop)))))
+
+ ;; (print "TCMT: pidres=" pidres " exittype=" exittype " exitstatus=" exitstatus " run-ids=" run-ids)
+ (print "TCMT: processing any tests that did not formally complete.")
+ (update-queue-since testdats run-ids 0 tsname target runname flowid #t #f delay-flag: #f) ;; call in flush mode
+ (process-queue testdats 0 #t)
+ (print "TCMT: All done.")
+ ))
+
+;;;;; )
+
+;; (trace print-changes-since)
+
+;; (if (not (eq? pidres 0)) ;; (not exitstatus))
+;; (begin
+;; (thread-sleep! 3)
+;; (loop))
+;; (print "Process: megatest " (string-intersperse origargs " ") " is done.")))))
+
+(if (file-exists? ".tcmtrc")
+ (load ".tcmtrc"))
+
+(define (main)
+ (let* ((mt-done #f)
+ (pid #f)
+ (th1 (make-thread (lambda ()
+ (print "Running megatest " (string-intersperse origargs " "))
+ (set! pid (process-run "megatest" origargs)))
+ "Megatest job"))
+ (th2 (make-thread (lambda ()
+ (monitor pid))
+ "Monitor job")))
+ (thread-start! th1)
+ (thread-sleep! 1) ;; give the process time to get going
+ (thread-start! th2)
+ (thread-join! th2)))
+
+(if (args:get-arg "-tc-repl")
+ (repl)
+ (main))
+
+;; (process-wait)
+
ADDED attic_modular/tdb.import.scm
Index: attic_modular/tdb.import.scm
==================================================================
--- /dev/null
+++ attic_modular/tdb.import.scm
@@ -0,0 +1,118 @@
+;;;; tdb.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ srfi-18
+ extras
+ tcp
+ sqlite3
+ srfi-1
+ posix
+ regex
+ regex-case
+ srfi-69
+ csv-xml
+ s11n
+ md5
+ message-digest
+ base64
+ (prefix sqlite3 sqlite3:)
+ (prefix base64 base64:)
+ margsmod
+ commonmod
+ debugprint
+ dbmod
+ ods
+ postgresql))
+(##sys#register-compiled-module
+ 'tdb
+ (list)
+ '((tdb:get-compressed-steps . tdb#tdb:get-compressed-steps)
+ (tdb:get-steps-table-list . tdb#tdb:get-steps-table-list)
+ (tdb:get-steps-table . tdb#tdb:get-steps-table)
+ (tdb:step-get-time-as-string . tdb#tdb:step-get-time-as-string)
+ (tdb:read-test-data . tdb#tdb:read-test-data)
+ (tdb:testdb-initialize . tdb#tdb:testdb-initialize)
+ (tdb:open-run-close-db-by-test-id-local
+ .
+ tdb#tdb:open-run-close-db-by-test-id-local)
+ (tdb:open-test-db-by-test-id-local . tdb#tdb:open-test-db-by-test-id-local)
+ (open-test-db . tdb#open-test-db)
+ (tdb:step-stable-set-runtime! . tdb#tdb:step-stable-set-runtime!)
+ (tdb:step-stable-set-status! . tdb#tdb:step-stable-set-status!)
+ (tdb:step-stable-set-end! . tdb#tdb:step-stable-set-end!)
+ (tdb:step-stable-set-start! . tdb#tdb:step-stable-set-start!)
+ (tdb:step-stable-set-stepname! . tdb#tdb:step-stable-set-stepname!)
+ (tdb:steps-table-get-log-file . tdb#tdb:steps-table-get-log-file)
+ (tdb:steps-table-get-runtime . tdb#tdb:steps-table-get-runtime)
+ (tdb:steps-table-get-status . tdb#tdb:steps-table-get-status)
+ (tdb:steps-table-get-end . tdb#tdb:steps-table-get-end)
+ (tdb:steps-table-get-start . tdb#tdb:steps-table-get-start)
+ (tdb:steps-table-get-stepname . tdb#tdb:steps-table-get-stepname)
+ (make-db:steps-table . tdb#make-db:steps-table)
+ (tdb:step-set-comment! . tdb#tdb:step-set-comment!)
+ (tdb:step-set-logfile! . tdb#tdb:step-set-logfile!)
+ (tdb:step-set-event_time! . tdb#tdb:step-set-event_time!)
+ (tdb:step-set-status! . tdb#tdb:step-set-status!)
+ (tdb:step-set-state! . tdb#tdb:step-set-state!)
+ (tdb:step-set-stepname! . tdb#tdb:step-set-stepname!)
+ (tdb:step-set-test_id! . tdb#tdb:step-set-test_id!)
+ (tdb:step-set-id! . tdb#tdb:step-set-id!)
+ (tdb:step-get-last_update . tdb#tdb:step-get-last_update)
+ (tdb:step-get-comment . tdb#tdb:step-get-comment)
+ (tdb:step-get-logfile . tdb#tdb:step-get-logfile)
+ (tdb:step-get-event_time . tdb#tdb:step-get-event_time)
+ (tdb:step-get-status . tdb#tdb:step-get-status)
+ (tdb:step-get-state . tdb#tdb:step-get-state)
+ (tdb:step-get-stepname . tdb#tdb:step-get-stepname)
+ (tdb:step-get-test_id . tdb#tdb:step-get-test_id)
+ (tdb:step-get-id . tdb#tdb:step-get-id)
+ (make-db:step . tdb#make-db:step)
+ (make-cdb:packet . dbmod#make-cdb:packet)
+ (make-db:test-data . dbmod#make-db:test-data)
+ (make-db:testmeta . dbmod#make-db:testmeta)
+ (make-db:mintest . dbmod#make-db:mintest)
+ (db:test-get-is-toplevel . dbmod#db:test-get-is-toplevel)
+ (db:test-make-full-name . dbmod#db:test-make-full-name)
+ (make-db:test . dbmod#make-db:test)
+ (*available-db* . commonmod#*available-db*))
+ (list (cons 'debug:catch-and-dump
+ (syntax-rules
+ ()
+ ((debug:catch-and-dump proc procname)
+ (begin
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain (current-error-port))
+ (with-output-to-port
+ (current-error-port)
+ (lambda ()
+ (print ((condition-property-accessor 'exn 'message) exn))
+ (print "Callback error in " procname)
+ (print "Full condition info:\n"
+ (condition->list exn)))))
+ (proc))))))
+ (cons 'common:handle-exceptions
+ (syntax-rules () ((_ exn errstmt body ...) (begin body ...))))
+ (cons 'common:debug-handle-exceptions
+ (syntax-rules
+ ()
+ ((_ debug exn errstmt body ...)
+ (if debug
+ (begin body ...)
+ (handle-exceptions exn errstmt body ...)))))
+ (cons 'define-simple-syntax
+ (syntax-rules
+ ()
+ ((_ (name arg ...) body ...)
+ (define-syntax
+ name
+ (syntax-rules () ((name arg ...) (begin body ...))))))))
+ (list))
+
+;; END OF FILE
ADDED attic_modular/tdb.scm
Index: attic_modular/tdb.scm
==================================================================
--- /dev/null
+++ attic_modular/tdb.scm
@@ -0,0 +1,436 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+;;
+;;======================================================================
+
+;;======================================================================
+;; Database access
+;;======================================================================
+
+(declare (unit tdb))
+(declare (uses common))
+(declare (uses client))
+(declare (uses mt))
+(declare (uses db))
+(declare (uses margsmod))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses dbmod))
+(declare (uses ods))
+
+(module tdb
+ *
+
+(import scheme chicken data-structures extras ports)
+
+(import (srfi 18) extras tcp)
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 csv-xml s11n md5 message-digest base64)
+
+
+
+(import (prefix sqlite3 sqlite3:))
+(import (prefix base64 base64:))
+
+(import margsmod)
+
+(import commonmod)
+(import debugprint)
+
+(import dbmod)
+
+(import ods)
+
+(include "common_records.scm")
+(include "db_records.scm")
+(include "key_records.scm")
+(include "run_records.scm")
+
+;;======================================================================
+;;
+;; T E S T D A T A B A S E S
+;;
+;;======================================================================
+;;======================================================================
+;; S T E P S
+;;======================================================================
+
+;; Run steps
+;; make-vector-record "Run steps" db step id test_id stepname step_complete step_pass event_time
+(define (make-db:step)(make-vector 9))
+(define (tdb:step-get-id vec) (vector-ref vec 0))
+(define (tdb:step-get-test_id vec) (vector-ref vec 1))
+(define (tdb:step-get-stepname vec) (vector-ref vec 2))
+(define (tdb:step-get-state vec) (vector-ref vec 3))
+(define (tdb:step-get-status vec) (vector-ref vec 4))
+(define (tdb:step-get-event_time vec) (vector-ref vec 5))
+(define (tdb:step-get-logfile vec) (vector-ref vec 6))
+(define (tdb:step-get-comment vec) (vector-ref vec 7))
+(define (tdb:step-get-last_update vec) (vector-ref vec 8))
+(define (tdb:step-set-id! vec val)(vector-set! vec 0 val))
+(define (tdb:step-set-test_id! vec val)(vector-set! vec 1 val))
+(define (tdb:step-set-stepname! vec val)(vector-set! vec 2 val))
+(define (tdb:step-set-state! vec val)(vector-set! vec 3 val))
+(define (tdb:step-set-status! vec val)(vector-set! vec 4 val))
+(define (tdb:step-set-event_time! vec val)(vector-set! vec 5 val))
+(define (tdb:step-set-logfile! vec val)(vector-set! vec 6 val))
+(define (tdb:step-set-comment! vec val)(vector-set! vec 7 val))
+
+
+;; The steps table
+(define (make-db:steps-table)(make-vector 5))
+(define (tdb:steps-table-get-stepname vec) (vector-ref vec 0))
+(define (tdb:steps-table-get-start vec) (vector-ref vec 1))
+(define (tdb:steps-table-get-end vec) (vector-ref vec 2))
+(define (tdb:steps-table-get-status vec) (vector-ref vec 3))
+(define (tdb:steps-table-get-runtime vec) (vector-ref vec 4))
+(define (tdb:steps-table-get-log-file vec) (vector-ref vec 5))
+
+(define (tdb:step-stable-set-stepname! vec val)(vector-set! vec 0 val))
+(define (tdb:step-stable-set-start! vec val)(vector-set! vec 1 val))
+(define (tdb:step-stable-set-end! vec val)(vector-set! vec 2 val))
+(define (tdb:step-stable-set-status! vec val)(vector-set! vec 3 val))
+(define (tdb:step-stable-set-runtime! vec val)(vector-set! vec 4 val))
+
+
+;;======================================================================
+;; T E S T S P E C I F I C D B
+;;======================================================================
+
+;; Create the sqlite db for the individual test(s)
+;;
+;; Moved these tables into .db
+;; THIS CODE TO BE REMOVED
+;;
+(define (open-test-db work-area)
+ (debug:print-info 11 *default-log-port* "open-test-db " work-area)
+ (if (and work-area
+ (directory? work-area)
+ (file-read-access? work-area))
+ (let* ((dbpath (conc work-area "/testdat.db"))
+ (dbexists (common:file-exists? dbpath))
+ (work-area-writeable (file-write-access? work-area))
+ (db (handle-exceptions ;; open the db if area writeable or db pre-existing. open in-mem otherwise. if exception, open in-mem
+ exn
+ (begin
+ (print-call-chain (current-error-port))
+ (debug:print 2 *default-log-port* "ERROR: problem accessing test db " work-area ", you probably should clean and re-run this test"
+ ((condition-property-accessor 'exn 'message) exn))
+ (set! dbexists #f) ;; must force re-creation of tables, more tom-foolery
+ (sqlite3:open-database ":memory:")) ;; open an in-memory db to allow readonly access
+ (if (or work-area-writeable
+ dbexists)
+ (sqlite3:open-database dbpath)
+ (sqlite3:open-database ":memory:"))))
+ (tdb-writeable (and (file-write-access? work-area)
+ (file-write-access? dbpath)))
+ (handler (sqlite3:make-busy-timeout (if (args:get-arg "-override-timeout")
+ (string->number (args:get-arg "-override-timeout"))
+ 136000))))
+
+ (if (and tdb-writeable
+ *db-write-access*)
+ (sqlite3:set-busy-handler! db handler))
+ (if (not dbexists)
+ (begin
+ (db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = FULL;")
+ (debug:print-info 11 *default-log-port* "Initialized test database " dbpath)
+ (tdb:testdb-initialize db)))
+ ;; (sqlite3:execute db "PRAGMA synchronous = 0;")
+ (debug:print-info 11 *default-log-port* "open-test-db END (sucessful)" work-area)
+ ;; now let's test that everything is correct
+ (handle-exceptions
+ exn
+ (begin
+ (print-call-chain (current-error-port))
+ (debug:print-error 0 *default-log-port* "problem accessing test db " work-area ", you probably should clean and re-run this test or remove the file "
+ dbpath ".\n "
+ ((condition-property-accessor 'exn 'message) exn))
+ #f)
+ ;; Is there a cheaper single line operation that will check for existance of a table
+ ;; and raise an exception ?
+ (sqlite3:execute db "SELECT id FROM test_data LIMIT 1;"))
+ db)
+ ;; no work-area or not readable - create a placeholder to fake rest of world out
+ (let ((baddb (sqlite3:open-database ":memory:")))
+ (debug:print-info 11 *default-log-port* "open-test-db END (unsucessful)" work-area)
+ ;; provide an in-mem db (this is dangerous!)
+ (tdb:testdb-initialize baddb)
+ baddb)))
+
+;; find and open the testdat.db file for an existing test
+(define (tdb:open-test-db-by-test-id-local dbstruct run-id test-id #!key (work-area #f))
+ (let* ((test-path (if work-area
+ work-area
+ (db:test-get-rundir-from-test-id dbstruct run-id test-id))))
+ (debug:print 3 *default-log-port* "TEST PATH: " test-path)
+ (open-test-db test-path)))
+
+;; find and open the testdat.db file for an existing test
+(define (tdb:open-run-close-db-by-test-id-local dbstruct run-id test-id work-area proc . params)
+ (let* ((test-path (if work-area
+ work-area
+ (db:test-get-rundir-from-test-id dbstruct run-id test-id)))
+ (tdb (open-test-db test-path)))
+ (apply proc tdb params)))
+
+(define (tdb:testdb-initialize db)
+ (debug:print 11 *default-log-port* "db:testdb-initialize START")
+ (sqlite3:with-transaction
+ db
+ (lambda ()
+ (for-each
+ (lambda (sqlcmd)
+ (sqlite3:execute db sqlcmd))
+ (list "CREATE TABLE IF NOT EXISTS test_rundat (
+ id INTEGER PRIMARY KEY,
+ update_time TIMESTAMP,
+ cpuload INTEGER DEFAULT -1,
+ diskfree INTEGER DEFAULT -1,
+ diskusage INTGER DEFAULT -1,
+ run_duration INTEGER DEFAULT 0);"
+ "CREATE TABLE IF NOT EXISTS test_data (
+ id INTEGER PRIMARY KEY,
+ test_id INTEGER,
+ category TEXT DEFAULT '',
+ variable TEXT,
+ value REAL,
+ expected REAL,
+ tol REAL,
+ units TEXT,
+ comment TEXT DEFAULT '',
+ status TEXT DEFAULT 'n/a',
+ type TEXT DEFAULT '',
+ CONSTRAINT test_data_constraint UNIQUE (test_id,category,variable));"
+ "CREATE TABLE IF NOT EXISTS test_steps (
+ id INTEGER PRIMARY KEY,
+ test_id INTEGER,
+ stepname TEXT,
+ state TEXT DEFAULT 'NOT_STARTED',
+ status TEXT DEFAULT 'n/a',
+ event_time TIMESTAMP,
+ comment TEXT DEFAULT '',
+ logfile TEXT DEFAULT '',
+ CONSTRAINT test_steps_constraint UNIQUE (test_id,stepname,state));"
+ ;; test_meta can be used for handing commands to the test
+ ;; e.g. KILLREQ
+ ;; the ackstate is set to 1 once the command has been completed
+ "CREATE TABLE IF NOT EXISTS test_meta (
+ id INTEGER PRIMARY KEY,
+ var TEXT,
+ val TEXT,
+ ackstate INTEGER DEFAULT 0,
+ CONSTRAINT metadat_constraint UNIQUE (var));"))))
+ (debug:print 11 *default-log-port* "db:testdb-initialize END"))
+
+;; This routine moved to db:read-test-data
+;;
+(define (tdb:read-test-data tdb test-id categorypatt)
+ (let ((res '()))
+ (sqlite3:for-each-row
+ (lambda (id test_id category variable value expected tol units comment status type)
+ (set! res (cons (vector id test_id category variable value expected tol units comment status type) res)))
+ tdb
+ "SELECT id,test_id,category,variable,value,expected,tol,units,comment,status,type FROM test_data WHERE test_id=? AND category LIKE ? ORDER BY category,variable;" test-id categorypatt)
+ (sqlite3:finalize! tdb)
+ (reverse res)))
+
+;;======================================================================
+;; T E S T D A T A
+;;======================================================================
+
+;; ;; get a list of test_data records matching categorypatt
+;; (define (tdb:read-test-data test-id categorypatt #!key (work-area #f))
+;; (let ((tdb (tdb:open-test-db-by-test-id test-id work-area: work-area)))
+;; (if (sqlite3:database? tdb)
+;; (let ((res '()))
+;; (sqlite3:for-each-row
+;; (lambda (id test_id category variable value expected tol units comment status type)
+;; (set! res (cons (vector id test_id category variable value expected tol units comment status type) res)))
+;; tdb
+;; "SELECT id,test_id,category,variable,value,expected,tol,units,comment,status,type FROM test_data WHERE test_id=? AND category LIKE ? ORDER BY category,variable;" test-id categorypatt)
+;; (sqlite3:finalize! tdb)
+;; (reverse res))
+;; '())))
+
+;;======================================================================
+;; S T E P S
+;;======================================================================
+
+(define (tdb:step-get-time-as-string vec)
+ (seconds->time-string (tdb:step-get-event_time vec)))
+
+;; get a pretty table to summarize steps
+;;
+;; NOT USED, WILL BE REMOVED
+;;
+(define (tdb:get-steps-table steps);; organise the steps for better readability
+ (let ((res (make-hash-table)))
+ (for-each
+ (lambda (step)
+ (debug:print 6 *default-log-port* "step=" step)
+ (let ((record (hash-table-ref/default
+ res
+ (tdb:step-get-stepname step)
+ ;; stepname start end status Duration Logfile
+ (vector (tdb:step-get-stepname step) "" "" "" "" ""))))
+ (debug:print 6 *default-log-port* "record(before) = " record
+ "\nid: " (tdb:step-get-id step)
+ "\nstepname: " (tdb:step-get-stepname step)
+ "\nstate: " (tdb:step-get-state step)
+ "\nstatus: " (tdb:step-get-status step)
+ "\ntime: " (tdb:step-get-event_time step))
+ (case (string->symbol (tdb:step-get-state step))
+ ((start)(vector-set! record 1 (tdb:step-get-event_time step))
+ (vector-set! record 3 (if (equal? (vector-ref record 3) "")
+ (tdb:step-get-status step)))
+ (if (> (string-length (tdb:step-get-logfile step))
+ 0)
+ (vector-set! record 5 (tdb:step-get-logfile step))))
+ ((end)
+ (vector-set! record 2 (any->number (tdb:step-get-event_time step)))
+ (vector-set! record 3 (tdb:step-get-status step))
+ (vector-set! record 4 (let ((startt (any->number (vector-ref record 1)))
+ (endt (any->number (vector-ref record 2))))
+ (debug:print 4 *default-log-port* "record[1]=" (vector-ref record 1)
+ ", startt=" startt ", endt=" endt
+ ", get-status: " (tdb:step-get-status step))
+ (if (and (number? startt)(number? endt))
+ (seconds->hr-min-sec (- endt startt)) "-1")))
+ (if (> (string-length (tdb:step-get-logfile step))
+ 0)
+ (vector-set! record 5 (tdb:step-get-logfile step))))
+ (else
+ (vector-set! record 2 (tdb:step-get-state step))
+ (vector-set! record 3 (tdb:step-get-status step))
+ (vector-set! record 4 (tdb:step-get-event_time step))))
+ (hash-table-set! res (tdb:step-get-stepname step) record)
+ (debug:print 6 *default-log-port* "record(after) = " record
+ "\nid: " (tdb:step-get-id step)
+ "\nstepname: " (tdb:step-get-stepname step)
+ "\nstate: " (tdb:step-get-state step)
+ "\nstatus: " (tdb:step-get-status step)
+ "\ntime: " (tdb:step-get-event_time step))))
+ ;; (else (vector-set! record 1 (tdb:step-get-event_time step)))
+ (sort steps (lambda (a b)
+ (cond
+ ((< (tdb:step-get-event_time a)(tdb:step-get-event_time b)) #t)
+ ((eq? (tdb:step-get-event_time a)(tdb:step-get-event_time b))
+ (< (tdb:step-get-id a) (tdb:step-get-id b)))
+ (else #f)))))
+ res))
+
+;; Move this to steps.scm
+;;
+;; get a pretty table to summarize steps
+;;
+(define (tdb:get-steps-table-list steps)
+ ;; organise the steps for better readability
+ (let ((res (make-hash-table)))
+ (for-each
+ (lambda (step)
+ (debug:print 6 *default-log-port* "step=" step)
+ (let ((record (hash-table-ref/default
+ res
+ (tdb:step-get-stepname step)
+ ;; stepname start end status
+ (vector (tdb:step-get-stepname step) "" "" "" "" ""))))
+ (debug:print 6 *default-log-port* "record(before) = " record
+ "\nid: " (tdb:step-get-id step)
+ "\nstepname: " (tdb:step-get-stepname step)
+ "\nstate: " (tdb:step-get-state step)
+ "\nstatus: " (tdb:step-get-status step)
+ "\ntime: " (tdb:step-get-event_time step))
+ (case (string->symbol (tdb:step-get-state step))
+ ((start)(vector-set! record 1 (tdb:step-get-event_time step))
+ (vector-set! record 3 (if (equal? (vector-ref record 3) "")
+ (tdb:step-get-status step)))
+ (if (> (string-length (tdb:step-get-logfile step))
+ 0)
+ (vector-set! record 5 (tdb:step-get-logfile step))))
+ ((end)
+ (vector-set! record 2 (any->number (tdb:step-get-event_time step)))
+ (vector-set! record 3 (tdb:step-get-status step))
+ (vector-set! record 4 (let ((startt (any->number (vector-ref record 1)))
+ (endt (any->number (vector-ref record 2))))
+ (debug:print 4 *default-log-port* "record[1]=" (vector-ref record 1)
+ ", startt=" startt ", endt=" endt
+ ", get-status: " (tdb:step-get-status step))
+ (if (and (number? startt)(number? endt))
+ (seconds->hr-min-sec (- endt startt)) "-1")))
+ (if (> (string-length (tdb:step-get-logfile step))
+ 0)
+ (vector-set! record 5 (tdb:step-get-logfile step))))
+ (else
+ (vector-set! record 2 (tdb:step-get-state step))
+ (vector-set! record 3 (tdb:step-get-status step))
+ (vector-set! record 4 (tdb:step-get-event_time step))))
+ (hash-table-set! res (tdb:step-get-stepname step) record)
+ (debug:print 6 *default-log-port* "record(after) = " record
+ "\nid: " (tdb:step-get-id step)
+ "\nstepname: " (tdb:step-get-stepname step)
+ "\nstate: " (tdb:step-get-state step)
+ "\nstatus: " (tdb:step-get-status step)
+ "\ntime: " (tdb:step-get-event_time step))))
+ ;; (else (vector-set! record 1 (tdb:step-get-event_time step)))
+ (sort steps (lambda (a b)
+ (cond
+ ((< (tdb:step-get-event_time a)(tdb:step-get-event_time b)) #t)
+ ((eq? (tdb:step-get-event_time a)(tdb:step-get-event_time b))
+ (< (tdb:step-get-id a) (tdb:step-get-id b)))
+ (else #f)))))
+ res))
+
+;;
+;; Move to steps.scm
+;;
+(define (tdb:get-compressed-steps comprsteps) ;; from tdb:get-steps-table
+ (map (lambda (x)
+ ;; take advantage of the \n on time->string
+ (vector
+ (vector-ref x 0)
+ (let ((s (vector-ref x 1)))
+ (if (number? s)(seconds->time-string s) s))
+ (let ((s (vector-ref x 2)))
+ (if (number? s)(seconds->time-string s) s))
+ (vector-ref x 3) ;; status
+ (vector-ref x 4)
+ (vector-ref x 5))) ;; time delta
+ (sort (hash-table-values comprsteps)
+ (lambda (a b)
+ (let ((time-a (vector-ref a 1))
+ (time-b (vector-ref b 1)))
+ (if (and (number? time-a)(number? time-b))
+ (if (< time-a time-b)
+ #t
+ (if (eq? time-a time-b)
+ (string (conc (vector-ref a 2))
+ (conc (vector-ref b 2)))
+ #f))
+ (string (conc time-a)(conc time-b))))))))
+
+;;
+#;(define (tdb:remote-update-testdat-meta-info run-id test-id work-area cpuload diskfree minutes)
+ (let ((tdb (rmt:open-test-db-by-test-id run-id test-id work-area: work-area)))
+ (if (sqlite3:database? tdb)
+ (begin
+ (sqlite3:execute tdb "INSERT INTO test_rundat (update_time,cpuload,diskfree,run_duration) VALUES (strftime('%s','now'),?,?,?);"
+ cpuload diskfree minutes)
+ (sqlite3:finalize! tdb))
+ (debug:print 2 *default-log-port* "Can't update testdat.db for test " test-id " read-only or non-existant"))))
+
+)
ADDED attic_modular/test_records.scm
Index: attic_modular/test_records.scm
==================================================================
--- /dev/null
+++ attic_modular/test_records.scm
@@ -0,0 +1,36 @@
+;; 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 .
+
+;; make-vector-record tests testqueue testname testconfig waitons priority items
+(define (make-tests:testqueue)(make-vector 7 #f))
+(define-inline (tests:testqueue-get-testname vec) (vector-ref vec 0))
+(define-inline (tests:testqueue-get-testconfig vec) (vector-ref vec 1))
+(define-inline (tests:testqueue-get-waitons vec) (vector-ref vec 2))
+(define-inline (tests:testqueue-get-priority vec) (vector-ref vec 3))
+;; items: #f=no items, list=list of items remaining, proc=need to call to get items
+(define-inline (tests:testqueue-get-items vec) (vector-ref vec 4))
+(define-inline (tests:testqueue-get-itemdat vec) (vector-ref vec 5))
+(define-inline (tests:testqueue-get-item_path vec) (vector-ref vec 6))
+
+(define-inline (tests:testqueue-set-testname! vec val)(vector-set! vec 0 val))
+(define-inline (tests:testqueue-set-testconfig! vec val)(vector-set! vec 1 val))
+(define-inline (tests:testqueue-set-waitons! vec val)(vector-set! vec 2 val))
+(define-inline (tests:testqueue-set-priority! vec val)(vector-set! vec 3 val))
+(define-inline (tests:testqueue-set-items! vec val)(vector-set! vec 4 val))
+(define-inline (tests:testqueue-set-itemdat! vec val)(vector-set! vec 5 val))
+(define-inline (tests:testqueue-set-item_path! vec val)(vector-set! vec 6 val))
+
ADDED attic_modular/tests.scm
Index: attic_modular/tests.scm
==================================================================
--- /dev/null
+++ attic_modular/tests.scm
@@ -0,0 +1,2009 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+;;
+;;======================================================================
+
+;;======================================================================
+;; Tests
+;;======================================================================
+
+(declare (unit tests))
+(declare (uses lock-queue))
+(declare (uses db))
+(declare (uses tdb))
+(declare (uses common))
+(declare (uses items))
+(declare (uses runconfig))
+(declare (uses server))
+(declare (uses margsmod))
+(import margsmod)
+
+(use sqlite3 srfi-1 posix regex regex-case srfi-69 dot-locking tcp directory-utils)
+(import (prefix sqlite3 sqlite3:))
+(require-library stml)
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses dbmod))
+(import dbmod)
+
+(declare (uses configfmod))
+(import configfmod)
+
+(declare (uses servermod))
+(import servermod)
+
+(include "common_records.scm")
+(include "key_records.scm")
+(include "db_records.scm")
+(include "run_records.scm")
+(include "test_records.scm")
+(include "js-path.scm")
+
+(define (init-java-script-lib)
+ (set! *java-script-lib* (conc (common:get-install-area) "/share/js/jquery-3.1.0.slim.min.js"))
+ )
+
+
+;;======================================================================
+;; Stuff from http-transport
+;;======================================================================
+
+;;===============================================
+;; Java script
+;;===============================================
+(define (http-transport:show-jquery)
+ (let* ((data (tests:readlines *java-script-lib*)))
+(string-join data "\n")))
+
+;;======================================================================
+;; web pages
+;;======================================================================
+
+(define (http-transport:html-test-log $)
+ (let* ((run-id ($ 'runid))
+ (test-item ($ 'testname))
+ (parts (string-split test-item ":"))
+ (test-name (car parts))
+
+ (item-name (if (equal? (length parts) 1)
+ ""
+ (cadr parts))))
+ ;(print $)
+(tests:get-test-log run-id test-name item-name)))
+
+
+(define (http-transport:html-dboard $)
+ (let* ((page ($ 'page))
+ (oup (open-output-string))
+ (bdy "--------------------------")
+
+ (ret (tests:dynamic-dboard page)))
+ (s:output-new oup ret)
+ (close-output-port oup)
+
+ (set! bdy (get-output-string oup))
+ (conc "Dashboard
" bdy "
" )))
+
+(define (http-transport:main-page)
+ (let ((linkpath (root-path)))
+ (conc "" (pathname-strip-directory *toppath*) "
"
+ ""
+ "Run area: " *toppath*
+ "Server Stats
"
+ (http-transport:stats-table)
+ "
"
+ (http-transport:runs linkpath)
+ "
"
+ ;; (http-transport:run-stats)
+ ""
+ )))
+
+(define (http-transport:stats-table)
+ (mutex-lock! *heartbeat-mutex*)
+ (let ((res
+ (conc ""
+ ;; "Max cached queries | " *max-cache-size* " |
"
+ "Number of cached writes | " *number-of-writes* " |
"
+ "Average cached write time | " (if (eq? *number-of-writes* 0)
+ "n/a (no writes)"
+ (/ *writes-total-delay*
+ *number-of-writes*))
+ " ms |
"
+ "Number non-cached queries | " *number-non-write-queries* " |
"
+ ;; "Average non-cached time | " (if (eq? *number-non-write-queries* 0)
+ ;; "n/a (no queries)"
+ ;; (/ *total-non-write-delay*
+ ;; *number-non-write-queries*))
+ " ms |
"
+ "Last access | " (seconds->time-string *db-last-access*) " |
"
+ "
")))
+ (mutex-unlock! *heartbeat-mutex*)
+ res))
+
+(define (http-transport:runs linkpath)
+ (conc "Runs
"
+ (string-intersperse
+ (let ((files (map pathname-strip-directory (glob (conc linkpath "/*")))))
+ (map (lambda (p)
+ (conc "" p "
"))
+ files))
+ " ")))
+
+#;(define (http-transport:run-stats)
+ (let ((stats (open-run-close db:get-running-stats #f)))
+ (conc ""
+ (string-intersperse
+ (map (lambda (stat)
+ (conc "" (car stat) " | " (cadr stat) " |
"))
+ stats)
+ " ")
+ "
")))
+
+
+
+;; Call this one to do all the work and get a standardized list of tests
+;; gets paths from configs and finds valid tests
+;; returns hash of testname --> fullpath
+;;
+(define (tests:get-all)
+ (let* ((test-search-path (tests:get-tests-search-path *configdat*)))
+ (tests:get-valid-tests (make-hash-table) test-search-path)))
+
+(define (tests:get-valid-tests test-registry tests-paths)
+ (if (null? tests-paths)
+ test-registry
+ (let loop ((hed (car tests-paths))
+ (tal (cdr tests-paths)))
+ (if (common:file-exists? hed)
+ (for-each (lambda (test-path)
+ (let* ((tname (last (string-split test-path "/")))
+ (tconfig (conc test-path "/testconfig")))
+ (if (and (not (hash-table-ref/default test-registry tname #f))
+ (common:file-exists? tconfig))
+ (hash-table-set! test-registry tname test-path))))
+ (glob (conc hed "/*"))))
+ (if (null? tal)
+ test-registry
+ (loop (car tal)(cdr tal))))))
+
+(define (tests:filter-test-names-not-matched test-names test-patts)
+ (delete-duplicates
+ (filter (lambda (testname)
+ (not (tests:match test-patts testname #f)))
+ test-names)))
+
+
+(define (tests:filter-test-names test-names test-patts)
+ (delete-duplicates
+ (filter (lambda (testname)
+ (tests:match test-patts testname #f))
+ test-names)))
+
+;; itemmap is a list of testname patterns to maps
+;; test1 .*/bar/(\d+) foo/\1
+;; % foo/([^/]+) \1/bar
+;;
+;; # NOTE: the line with the single % could be the result of
+;; # itemmap entry in requirements (legacy). The itemmap
+;; # requirements entry is deprecated
+;;
+(define (tests:get-itemmaps tconfig)
+ (let ((base-itemmap (configf:lookup tconfig "requirements" "itemmap"))
+ (itemmap-table (configf:get-section tconfig "itemmap")))
+ (append (if base-itemmap
+ (list (list "%" base-itemmap))
+ '())
+ (if itemmap-table
+ itemmap-table
+ '()))))
+
+;; return items given config
+;;
+(define (tests:get-items tconfig)
+ (let ((items (hash-table-ref/default tconfig "items" #f)) ;; items 4
+ (itemstable (hash-table-ref/default tconfig "itemstable" #f)))
+ ;; if either items or items table is a proc return it so test running
+ ;; process can know to call items:get-items-from-config
+ ;; if either is a list and none is a proc go ahead and call get-items
+ ;; otherwise return #f - this is not an iterated test
+ (cond
+ ((procedure? items)
+ (debug:print-info 4 *default-log-port* "items is a procedure, will calc later")
+ items) ;; calc later
+ ((procedure? itemstable)
+ (debug:print-info 4 *default-log-port* "itemstable is a procedure, will calc later")
+ itemstable) ;; calc later
+ ((filter (lambda (x)
+ (let ((val (car x)))
+ (if (procedure? val) val #f)))
+ (append (if (list? items) items '())
+ (if (list? itemstable) itemstable '())))
+ 'have-procedure)
+ ((or (list? items)(list? itemstable)) ;; calc now
+ (debug:print-info 4 *default-log-port* "items and itemstable are lists, calc now\n"
+ " items: " items " itemstable: " itemstable)
+ (items:get-items-from-config tconfig))
+ (else #f)))) ;; not iterated
+
+
+;; returns waitons waitors tconfigdat
+;;
+(define (tests:get-waitons test-name all-tests-registry)
+ (let* ((config (tests:get-testconfig test-name #f all-tests-registry 'return-procs))) ;; assuming no problems with immediate evaluation, this could be simplified ('return-procs -> #t)
+ (let ((instr (if config
+ (configf:lookup config "requirements" "waiton")
+ (begin ;; No config means this is a non-existant test
+ (debug:print-error 0 *default-log-port* "non-existent required test \"" test-name "\"")
+ (exit 1))))
+ (instr2 (if config
+ (configf:lookup config "requirements" "waitor")
+ "")))
+ (debug:print-info 8 *default-log-port* "waitons string is " instr ", waitors string is " instr2)
+ (let ((newwaitons
+ (string-split (cond
+ ((procedure? instr) ;; here
+ (let ((res (instr)))
+ (debug:print-info 8 *default-log-port* "waiton procedure results in string " res " for test " test-name)
+ res))
+ ((string? instr) instr)
+ (else
+ ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print-error 0 *default-log-port* "something went wrong in processing waitons for test " test-name)
+ ""))))
+ (newwaitors
+ (string-split (cond
+ ((procedure? instr2)
+ (let ((res (instr2)))
+ (debug:print-info 8 *default-log-port* "waitor procedure results in string " res " for test " test-name)
+ res))
+ ((string? instr2) instr2)
+ (else
+ ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print-error 0 *default-log-port* "something went wrong in processing waitons for test " test-name)
+ "")))))
+ (values
+ ;; the waitons
+ (filter (lambda (x)
+ (if (hash-table-ref/default all-tests-registry x #f)
+ #t
+ (begin
+ (debug:print-error 0 *default-log-port* "test " test-name " has unrecognised waiton testname " x)
+ #f)))
+ newwaitons)
+ (filter (lambda (x)
+ (if (hash-table-ref/default all-tests-registry x #f)
+ #t
+ (begin
+ (debug:print-error 0 *default-log-port* "test " test-name " has unrecognised waiton testname " x)
+ #f)))
+ newwaitors)
+ config)))))
+
+;; given waiting-test that is waiting on waiton-test extend test-patt appropriately
+;;
+;; genlib/testconfig sim/testconfig
+;; genlib/sch sim/sch/cell1
+;;
+;; [requirements] [requirements]
+;; mode itemwait
+;; # trim off the cell to determine what to run for genlib
+;; itemmap /.*
+;;
+;; waiting-test is waiting on waiton-test so we need to create a pattern for waiton-test given waiting-test and itemmap
+;; BB> (tests:extend-test-patts "normal-second/2" "normal-second" "normal-first" '())
+;; observed -> "normal-first/2,normal-first/,normal-second/2,normal-second/"
+;; expected -> "normal-first,normal-second/2,normal-second/"
+;; testpatt = normal-second/2
+;; waiting-test = normal-second
+;; waiton-test = normal-first
+;; itemmaps = ()
+
+(define (tests:extend-test-patts test-patt waiting-test waiton-test itemmaps itemized-waiton)
+ (cond
+ (itemized-waiton
+ (let* ((itemmap (tests:lookup-itemmap itemmaps waiton-test))
+ (patts (string-split test-patt ","))
+ (waiting-test-len (+ (string-length waiting-test) 1))
+ (patts-waiton (map (lambda (x) ;; for each incoming patt that matches the waiting test
+ (let* ((modpatt (if itemmap (db:convert-test-itempath x itemmap) x))
+ (newpatt (conc waiton-test "/" (substring modpatt waiting-test-len (string-length modpatt)))))
+ ;; (conc waiting-test "/," waiting-test "/" (substring modpatt waiton-test-len (string-length modpatt)))))
+ ;; (print "in map, x=" x ", newpatt=" newpatt)
+ newpatt))
+ (filter (lambda (x)
+ (eq? (substring-index (conc waiting-test "/") x) 0)) ;; is this patt pertinent to the waiting test
+ patts)))
+ (extended-test-patt (append patts (if (null? patts-waiton)
+ (list (conc waiton-test "/%")) ;; really shouldn't add the waiton forcefully like this
+ patts-waiton)))
+ (extended-test-patt-with-toplevels
+ (fold (lambda (testpatt-item accum )
+ (let ((my-match (string-match "^([^%\\/]+)\\/.+$" testpatt-item)))
+ (cons testpatt-item
+ (if my-match
+ (cons
+ (conc (cadr my-match) "/")
+ accum)
+ accum))))
+ '()
+ extended-test-patt)))
+ (string-intersperse (delete-duplicates extended-test-patt-with-toplevels) ",")))
+ (else ;; not waiting on items, waiting on entire waiton test.
+ (let* ((patts (string-split test-patt ","))
+ (new-patts (if (member waiton-test patts)
+ patts
+ (cons waiton-test patts))))
+ (string-intersperse (delete-duplicates new-patts) ",")))))
+
+;; Check for waiver eligibility
+;;
+(define (tests:check-waiver-eligibility testdat prev-testdat)
+ (let* ((test-registry (make-hash-table))
+ (testconfig (tests:get-testconfig (db:test-get-testname testdat) (db:test-get-item-path testdat) test-registry #f))
+ (test-rundir ;; (sdb:qry 'passstr
+ (db:test-get-rundir testdat)) ;; )
+ (prev-rundir ;; (sdb:qry 'passstr
+ (db:test-get-rundir prev-testdat)) ;; )
+ (waivers (if testconfig (configf:section-vars testconfig "waivers") '()))
+ (waiver-rx (regexp "^(\\S+)\\s+(.*)$"))
+ (diff-rule "diff %file1% %file2%")
+ (logpro-rule "diff %file1% %file2% | logpro %waivername%.logpro %waivername%.html"))
+ (if (not (common:file-exists? test-rundir))
+ (begin
+ (debug:print-error 0 *default-log-port* "test run directory is gone, cannot propagate waiver")
+ #f)
+ (begin
+ (push-directory test-rundir)
+ (let ((result (if (null? waivers)
+ #f
+ (let loop ((hed (car waivers))
+ (tal (cdr waivers)))
+ (debug:print 0 *default-log-port* "INFO: Applying waiver rule \"" hed "\"")
+ (let* ((waiver (configf:lookup testconfig "waivers" hed))
+ (wparts (if waiver (string-match waiver-rx waiver) #f))
+ (waiver-rule (if wparts (cadr wparts) #f))
+ (waiver-glob (if wparts (caddr wparts) #f))
+ (logpro-file (if waiver
+ (let ((fname (conc hed ".logpro")))
+ (if (common:file-exists? fname)
+ fname
+ (begin
+ (debug:print 0 *default-log-port* "INFO: No logpro file " fname " falling back to diff")
+ #f)))
+ #f))
+ ;; if rule by name of waiver-rule is found in testconfig - use it
+ ;; else if waivername.logpro exists use logpro-rule
+ ;; else default to diff-rule
+ (rule-string (let ((rule (configf:lookup testconfig "waiver_rules" waiver-rule)))
+ (if rule
+ rule
+ (if logpro-file
+ logpro-rule
+ (begin
+ (debug:print 0 *default-log-port* "INFO: No logpro file " logpro-file " found, using diff rule")
+ diff-rule)))))
+ ;; (string-substitute "%file1%" "foofoo.txt" "This is %file1% and so is this %file1%." #t)
+ (processed-cmd (string-substitute
+ "%file1%" (conc test-rundir "/" waiver-glob)
+ (string-substitute
+ "%file2%" (conc prev-rundir "/" waiver-glob)
+ (string-substitute
+ "%waivername%" hed rule-string #t) #t) #t))
+ (res #f))
+ (debug:print 0 *default-log-port* "INFO: waiver command is \"" processed-cmd "\"")
+ (if (eq? (system processed-cmd) 0)
+ (if (null? tal)
+ #t
+ (loop (car tal)(cdr tal)))
+ #f))))))
+ (pop-directory)
+ result)))))
+
+;; Do not rpc this one, do the underlying calls!!!
+(define (tests:test-set-status! run-id test-id state status comment dat #!key (work-area #f))
+ (let* ((real-status status)
+ (otherdat (if dat dat (make-hash-table)))
+ (testdat (rmt:get-test-info-by-id run-id test-id))
+ (test-name (db:test-get-testname testdat))
+ (item-path (db:test-get-item-path testdat))
+ ;; before proceeding we must find out if the previous test (where all keys matched except runname)
+ ;; was WAIVED if this test is FAIL
+
+ ;; NOTES:
+ ;; 1. Is the call to test:get-previous-run-record remotified?
+ ;; 2. Add test for testconfig waiver propagation control here
+ ;;
+ (prev-test (if (equal? status "FAIL")
+ (rmt:get-previous-test-run-record run-id test-name item-path)
+ #f))
+ (waived (if prev-test
+ (if prev-test ;; true if we found a previous test in this run series
+ (let ((prev-status (db:test-get-status prev-test))
+ (prev-state (db:test-get-state prev-test))
+ (prev-comment (db:test-get-comment prev-test)))
+ (debug:print 4 *default-log-port* "prev-status " prev-status ", prev-state " prev-state ", prev-comment " prev-comment)
+ (if (and (equal? prev-state "COMPLETED")
+ (equal? prev-status "WAIVED"))
+ (if comment
+ comment
+ prev-comment) ;; waived is either the comment or #f
+ #f))
+ #f)
+ #f)))
+ (if (and waived
+ (tests:check-waiver-eligibility testdat prev-test))
+ (set! real-status "WAIVED"))
+
+ (debug:print 4 *default-log-port* "real-status " real-status ", waived " waived ", status " status)
+
+ ;; update the primary record IF state AND status are defined
+ (if (and state status)
+ (begin
+ (rmt:set-state-status-and-roll-up-items run-id test-id item-path state real-status (if waived waived comment))
+ ;; (mt:process-triggers run-id test-id state real-status) ;; triggers are called in test-set-state-status
+ ))
+
+ ;; if status is "AUTO" then call rollup (note, this one modifies data in test
+ ;; run area, it does remote calls under the hood.
+ ;; (if (and test-id state status (equal? status "AUTO"))
+ ;; (rmt:test-data-rollup run-id test-id status))
+
+ ;; add metadata (need to do this way to avoid SQL injection issues)
+
+ ;; :first_err
+ ;; (let ((val (hash-table-ref/default otherdat ":first_err" #f)))
+ ;; (if val
+ ;; (sqlite3:execute db "UPDATE tests SET first_err=? WHERE run_id=? AND testname=? AND item_path=?;" val run-id test-name item-path)))
+ ;;
+ ;; ;; :first_warn
+ ;; (let ((val (hash-table-ref/default otherdat ":first_warn" #f)))
+ ;; (if val
+ ;; (sqlite3:execute db "UPDATE tests SET first_warn=? WHERE run_id=? AND testname=? AND item_path=?;" val run-id test-name item-path)))
+
+ (let ((category (hash-table-ref/default otherdat ":category" ""))
+ (variable (hash-table-ref/default otherdat ":variable" ""))
+ (value (hash-table-ref/default otherdat ":value" #f))
+ (expected (hash-table-ref/default otherdat ":expected" "n/a"))
+ (tol (hash-table-ref/default otherdat ":tol" "n/a"))
+ (units (hash-table-ref/default otherdat ":units" ""))
+ (type (hash-table-ref/default otherdat ":type" ""))
+ (dcomment (hash-table-ref/default otherdat ":comment" "")))
+ (debug:print 4 *default-log-port*
+ "category: " category ", variable: " variable ", value: " value
+ ", expected: " expected ", tol: " tol ", units: " units)
+ (if (and value) ;; require only value; BB was- all three required
+ (let ((dat (conc category ","
+ variable ","
+ value ","
+ expected ","
+ tol ","
+ units ","
+ dcomment ",," ;; extra comma for status
+ type )))
+ ;; This was run remote, don't think that makes sense. Perhaps not, but that is the easiest path for the moment.
+ (rmt:csv->test-data run-id test-id
+ dat)
+ ;; This was added in check-in a5adfa3f9a. Message was: "...added delay in set-values to allow for delayed write on server start"
+ ;; I'm inserting an arbitrary rmt: call to force/ensure that the server is available to (hopefully) prevent a communication issue.
+ (rmt:get-var "MEGATEST_VERSION") ;; this does NOTHING but ensure the server is reachable. This is almost certainly NOT needed :)
+ ;; BB - commentiong out arbitrary 10 second wait (thread-sleep! 10) ;; add 10 second delay before quit incase rmt needs time to start a server.
+ )))
+
+ ;; need to update the top test record if PASS or FAIL and this is a subtest
+ ;;;;;; (if (not (equal? item-path ""))
+ ;;;;;; (rmt:set-state-status-and-roll-up-items run-id test-name item-path state status #f) ;;;;;)
+
+ (if (or (and (string? comment)
+ (string-match (regexp "\\S+") comment))
+ waived)
+ (let ((cmt (if waived waived comment)))
+ (rmt:general-call 'set-test-comment run-id cmt test-id)))))
+
+(define (tests:test-set-toplog! run-id test-name logf)
+ (rmt:general-call 'tests:test-set-toplog run-id logf run-id test-name))
+
+(define (tests:summarize-items run-id test-id test-name force)
+ ;; if not force then only update the record if one of these is true:
+ ;; 1. logf is "log/final.log
+ ;; 2. logf is same as outputfilename
+ (let* ((outputfilename (conc "megatest-rollup-" test-name ".html"))
+ (orig-dir (current-directory))
+ (logf-info (rmt:test-get-logfile-info run-id test-name))
+ (logf (if logf-info (cadr logf-info) #f))
+ (path (if logf-info (car logf-info) #f)))
+ ;; This query finds the path and changes the directory to it for the test
+ (if (and (string? path)
+ (directory? path)) ;; can get #f here under some wierd conditions. why, unknown ...
+ (begin
+ (debug:print 4 *default-log-port* "Found path: " path)
+ (change-directory path))
+ ;; (set! outputfilename (conc path "/" outputfilename)))
+ (debug:print-error 0 *default-log-port* "summarize-items for run-id=" run-id ", test-name=" test-name ", no such path: " path))
+ (debug:print 4 *default-log-port* "summarize-items with logf " logf ", outputfilename " outputfilename " and force " force)
+ (if (or (equal? logf "logs/final.log")
+ (equal? logf outputfilename)
+ force)
+ (let ((my-start-time (current-seconds))
+ (lockf (conc outputfilename ".lock")))
+ (let loop ((have-lock (common:simple-file-lock lockf)))
+ (if have-lock
+ (let ((script (configf:lookup *configdat* "testrollup" test-name)))
+ (print "Obtained lock for " outputfilename)
+ (rmt:set-state-status-and-roll-up-items run-id test-name "" #f #f #f)
+ (if script
+ (system (conc script " > " outputfilename " & "))
+ (tests:generate-html-summary-for-iterated-test run-id test-id test-name outputfilename))
+ (common:simple-file-release-lock lockf)
+ (change-directory orig-dir)
+ ;; NB// tests:test-set-toplog! is remote internal...
+ (tests:test-set-toplog! run-id test-name outputfilename))
+ ;; didn't get the lock, check to see if current update started later than this
+ ;; update, if so we can exit without doing any work
+ (if (> my-start-time (handle-exceptions
+ exn
+ (begin
+ (print "failed to get mod time on " lockf ", exn=" exn)
+ 0)
+ (file-modification-time lockf)))
+ ;; we started since current re-gen in flight, delay a little and try again
+ (begin
+ (debug:print-info 1 *default-log-port* "Waiting to update " outputfilename ", another test currently updating it")
+ (thread-sleep! (+ 5 (random 5))) ;; delay between 5 and 10 seconds
+ (loop (common:simple-file-lock lockf))))))))))
+
+(define (tests:generate-html-summary-for-iterated-test run-id test-id test-name outputfilename)
+ (let ((counts (make-hash-table))
+ (statecounts (make-hash-table))
+ (outtxt "")
+ (tot 0)
+ (testdat (rmt:test-get-records-for-index-file run-id test-name)))
+ (with-output-to-file outputfilename
+ (lambda ()
+ (set! outtxt (conc outtxt "Summary: " test-name
+ "Summary for " test-name "
"))
+ (for-each
+ (lambda (testrecord)
+ (let ((id (vector-ref testrecord 0))
+ (itempath (vector-ref testrecord 1))
+ (state (vector-ref testrecord 2))
+ (status (vector-ref testrecord 3))
+ (run_duration (vector-ref testrecord 4))
+ (logf (vector-ref testrecord 5))
+ (comment (vector-ref testrecord 6)))
+ (hash-table-set! counts status (+ 1 (hash-table-ref/default counts status 0)))
+ (hash-table-set! statecounts state (+ 1 (hash-table-ref/default statecounts state 0)))
+ (set! outtxt (conc outtxt ""
+ ;; " " itempath " | "
+ " " itempath " | "
+ "" state " | "
+ "" status " | "
+ "" (if (equal? comment "")
+ " "
+ comment) " | "
+ "
"))))
+ (if (list? testdat)
+ testdat
+ (begin
+ (print "ERROR: failed to get records with rmt:test-get-records-for-index-file run-id=" run-id "test-name=" test-name)
+ '())))
+
+ (print "")
+ ;; Print out stats for status
+ (set! tot 0)
+ (print "State stats | ")
+ (for-each (lambda (state)
+ (set! tot (+ tot (hash-table-ref statecounts state)))
+ (print "" state " | " (hash-table-ref statecounts state) " | "))
+ (hash-table-keys statecounts))
+ (print "Total | " tot " | ")
+ (print " | ")
+ ;; Print out stats for state
+ (set! tot 0)
+ (print "Status stats | ")
+ (for-each (lambda (status)
+ (set! tot (+ tot (hash-table-ref counts status)))
+ (print "" status
+ " | " (hash-table-ref counts status) " | "))
+ (hash-table-keys counts))
+ (print "Total | " tot " | ")
+ (print " |
")
+
+ (print ""
+ "Item | State | Status | Comment | "
+ outtxt "
")
+ ;; (release-dot-lock outputfilename)
+ ;;(rmt:update-run-stats
+ ;; run-id
+ ;; (hash-table-map
+ ;; state-status-counts
+ ;; (lambda (key val)
+ ;; (append key (list val)))))
+ ))))
+
+(define tests:css-jscript-block
+#<
+ul.LinkedList { display: block; }
+/* ul.LinkedList ul { display: none; } */
+.HandCursorStyle { cursor: pointer; cursor: hand; } /* For IE */
+th {background-color: #8c8c8c;}
+td.test {background-color: #d9dbdd;}
+td.PASS {background-color: #347533;}
+td.FAIL {background-color: #cc2812;}
+td.SKIP{background-color: #FFD733;}
+td.WARN {background-color: #EA8724;}
+td.WAIVED {background-color: #838A12;}
+td.ABORT{background-color: #EA24B7;}
+.PASS .link, .SKIP .link, .WARN .link,.WAIVED .link,.ABORT .link, .FAIL .link{color: #FFFFFF;}
+
+
+
+
+
+
+EOF
+)
+
+(define tests:css-jscript-block-dynamic
+#<
+EOF
+)
+
+(define (test:js-block javascript-lib)
+ (conc "" ))
+
+
+(define tests:css-jscript-block-static (test:js-block *java-script-lib*))
+
+(define (tests:css-jscript-block-cond dynamic)
+ (if (equal? dynamic #t)
+ tests:css-jscript-block-dynamic
+ tests:css-jscript-block-static))
+
+
+(define (tests:run-record->test-path run numkeys)
+ (append (take (vector->list run) numkeys)
+ (list (vector-ref run (+ 1 numkeys)))))
+
+
+(define (tests:get-rest-data runs header numkeys)
+ (let ((resh (make-hash-table)))
+ (for-each
+ (lambda (run)
+ (let* ((run-id (db:get-value-by-header run header "id"))
+ (run-dir (tests:run-record->test-path run numkeys))
+ (test-data (rmt:get-tests-for-run
+ run-id
+ "%" ;; testnamepatt
+ '() ;; states
+ '() ;; statuses
+ #f ;; offset
+ #f ;; num-to-get
+ #f ;; hide/not-hide
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; 'shortlist ;; qrytype
+ 0 ;; last update
+ #f)))
+
+ (map (lambda (test)
+ (let* ((test-name (vector-ref test 2))
+ (test-html-path (conc (vector-ref test 10) "/" (vector-ref test 13)))
+ (test-item (conc test-name ":" (vector-ref test 11)))
+ (test-status (vector-ref test 4)))
+
+ (if (not (hash-table-ref/default resh test-name #f))
+ (hash-table-set! resh test-name (make-hash-table)))
+ (if (not (hash-table-ref/default (hash-table-ref/default resh test-name #f) test-item #f))
+ (hash-table-set! (hash-table-ref/default resh test-name #f) test-item (make-hash-table)))
+ (hash-table-set! (hash-table-ref/default (hash-table-ref/default resh test-name #f) test-item #f) run-id (list test-status test-html-path))))
+ test-data)))
+ runs)
+ resh))
+
+
+;; tests:genrate dashboard body
+;;
+
+(define (tests:dashboard-body page pg-size keys numkeys total-runs linktree area-name get-prev-links get-next-links flag run-patt target-patt)
+ (let* ((start (* page pg-size))
+ ;(runsdat (rmt:get-runs "%" pg-size start (map (lambda (x)(list x "%")) keys)))
+ (runsdat (rmt:get-runs-by-patt keys run-patt target-patt start pg-size #f 0 sort-order: "desc"))
+ ; db:get-runs-by-patt keys runnamepatt targpatt offset limit fields last-update
+ (header (vector-ref runsdat 0))
+ (runs (vector-ref runsdat 1))
+ (ctr 0)
+ (test-runs-hash (tests:get-rest-data runs header numkeys))
+ (test-list (hash-table-keys test-runs-hash)))
+
+ (s:html tests:css-jscript-block (tests:css-jscript-block-cond flag)
+ (s:title "Summary for " area-name)
+ (s:body 'onload "addEvents();"
+ (get-prev-links page linktree)
+ (get-next-links page linktree total-runs)
+
+ (s:h1 "Summary for " area-name)
+ (s:h3 "Filter" )
+ (s:input 'type "text" 'name "testname" 'id "testname" 'length "30" 'onkeyup "filtersome()")
+ ;; top list
+
+ (s:table 'id "LinkedList1" 'border "1" 'cellspacing 0
+ (map (lambda (key)
+ (let* ((res (s:tr 'class "something"
+ (s:th key )
+ (map (lambda (run)
+ (s:th (vector-ref run ctr)))
+ runs))))
+ (set! ctr (+ ctr 1))
+ res))
+ keys)
+ (s:tr
+ (s:th "Run Name")
+ (map (lambda (run)
+ (s:th (db:get-value-by-header run header "runname")))
+ runs))
+
+ (map (lambda (test-name)
+ (let* ((item-hash (hash-table-ref/default test-runs-hash test-name #f))
+ (item-keys (sort (hash-table-keys item-hash) string<=?)))
+ (map (lambda (item-name)
+ (let* ((res (s:tr 'class item-name
+ (s:td item-name 'class "test" )
+ (map (lambda (run)
+ (let* ((run-test (hash-table-ref/default item-hash item-name #f))
+ (run-id (db:get-value-by-header run header "id"))
+ (result (hash-table-ref/default run-test run-id "n/a"))
+ ;(relative-path (get-relative-path))
+ (status (if (string? result)
+ result
+ (car result)))
+ (link (if (string? result)
+ result
+ (if (equal? flag #t)
+ (s:a (car result) 'href (conc "./test_log?runid=" run-id "&testname=" item-name ))
+ (s:a (car result) 'href (string-substitute (conc linktree "/") "" (cadr result) "-"))))))
+ (s:td link 'class status)))
+ runs))))
+ res))
+ item-keys)))
+ test-list))))))
+
+;; (tests:create-html-tree "test-index.html")
+;;
+(define (tests:create-html-tree outf)
+ (let* ((lockfile (conc outf ".lock"))
+ (runs-to-process '())
+ (linktree (common:get-linktree))
+ (area-name (common:get-testsuite-name))
+ (keys (rmt:get-keys))
+ (numkeys (length keys))
+ (run-patt (or (args:get-arg "-run-patt")
+ (args:get-arg "-runname")
+ "%"))
+ (target (or (args:get-arg "-target-patt")
+ (args:get-arg "-target")
+ "%"))
+ (targlist (string-split target "/"))
+ (numtarg (length targlist))
+ (targtweaked (if (> numkeys numtarg)
+ (append targlist (make-list (- numkeys numtarg) "%"))
+ targlist))
+ (target-patt (string-join targtweaked "/"))
+ ;(total-runs (rmt:get-num-runs "%")) ;;this needs to be changed to filter by target
+ (total-runs (rmt:get-runs-cnt-by-patt run-patt target-patt keys ))
+ (pg-size 10))
+ (if (common:simple-file-lock lockfile)
+ (begin
+ ;(print total-runs)
+ (let loop ((page 0))
+ (let* ((oup (open-output-file (or outf (conc linktree "/page" page ".html"))))
+ (get-prev-links (lambda (page linktree )
+ (let* ((link (if (not (eq? page 0))
+ (s:a "<<prev" 'href (conc "page" (- page 1) ".html"))
+ (s:a "" 'href (conc "page" page ".html")))))
+ link)))
+ (get-next-links (lambda (page linktree total-runs)
+ (let* ((link (if (> total-runs (+ 10 (* page pg-size)))
+ (s:a "next>>" 'href (conc "page" (+ page 1) ".html"))
+ (s:a "" 'href (conc "page" page ".html")))))
+ link))) )
+ (print "total runs: " total-runs)
+ (s:output-new
+ oup
+ (tests:dashboard-body page pg-size keys numkeys total-runs linktree area-name get-prev-links get-next-links #f run-patt target-patt)) ;; update this function
+ (close-output-port oup)
+ ; (set! page (+ 1 page))
+ (if (> total-runs (* (+ 1 page) pg-size))
+ (loop (+ 1 page)))))
+ (common:simple-file-release-lock lockfile))
+ (begin
+ (debug-print 0 *default-log-port* "Failed to get lock on file outf, lockfile: " lockfile) #f))))
+
+
+(define (tests:readlines filename)
+ (call-with-input-file filename
+ (lambda (p)
+ (let loop ((line (read-line p))
+ (result '()))
+ (if (eof-object? line)
+ (reverse result)
+ (loop (read-line p) (cons line result)))))))
+
+(define (tests:get-test-log run-id test-name item-name)
+ (let* ((test-data (rmt:get-tests-for-run
+ (string->number run-id)
+ test-name ;; testnamepatt
+ '() ;; states
+ '() ;; statuses
+ #f ;; offset
+ #f ;; num-to-get
+ #f ;; hide/not-hide
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; 'shortlist ;; qrytype
+ 0 ;; last update
+ #f))
+ (path "")
+ (found 0))
+ (debug:print-info 0 *default-log-port* "found: " found )
+
+ (let loop ((hed (car test-data))
+ (tal (cdr test-data)))
+ (debug:print-info 0 *default-log-port* "item: " (vector-ref hed 11) (vector-ref hed 10) "/" (vector-ref hed 13))
+
+ (if (equal? (vector-ref hed 11) item-name)
+ (begin
+ (set! found 1)
+ (set! path (conc (vector-ref hed 10) "/" (vector-ref hed 13)))))
+ (if (and (not (null? tal)) (equal? found 0))
+ (loop (car tal)(cdr tal))))
+ (if (equal? path "")
+ "Data not found
"
+ (string-join (tests:readlines path) "\n"))))
+
+
+(define (tests:dynamic-dboard page)
+;(define (tests:create-html-tree o)
+ (let* (
+;(page "1")
+ (linktree (common:get-linktree))
+ (area-name (common:get-testsuite-name))
+ (keys (rmt:get-keys))
+ (numkeys (length keys))
+ (targtweaked (make-list numkeys "%"))
+ (target-patt (string-join targtweaked "/"))
+ (total-runs (rmt:get-num-runs "%"))
+ (pg-size 10)
+ (pg (if (equal? page #f)
+ 0
+ (- (string->number page) 1)))
+ (get-prev-links (lambda (pg linktree)
+ (debug:print-info 0 *default-log-port* "val: " (- 1 pg))
+ (let* ((link (if (not (eq? pg 0))
+ (s:a "<<prev " 'href (conc "dashboard?page=" pg ))
+ (s:a "" 'href (conc "dashboard?page=" pg)))))
+ link)))
+ (get-next-links (lambda (pg linktree total-runs)
+ (debug:print-info 0 *default-log-port* "val: " pg)
+ (debug:print-info 0 *default-log-port* "val: " total-runs " size" pg-size)
+
+ (let* ((link (if (> total-runs (+ 10 (* pg pg-size)))
+ (s:a "next>> " 'href (conc "dashboard?page=" (+ pg 2) ))
+ (s:a "" 'href (conc "dashboard?page=" pg )))))
+ link)))
+ (html-body (tests:dashboard-body pg pg-size keys numkeys total-runs linktree area-name get-prev-links get-next-links #t "%" target-patt))) ;; update tis function
+ html-body))
+
+(define (tests:create-html-summary outf)
+ (let* ((lockfile (conc outf ".lock"))
+ (linktree (common:get-linktree))
+ (keys (rmt:get-keys))
+ (area-name (common:get-testsuite-name))
+ (run-patt (or (args:get-arg "-run-patt")
+ (args:get-arg "-runname")
+ "%"))
+ (target (or (args:get-arg "-target-patt")
+ (args:get-arg "-target")
+ "%"))
+ (targlist (string-split target "/"))
+ (numkeys (length keys))
+ (numtarg (length targlist))
+ (targtweaked (if (> numkeys numtarg)
+ (append targlist (make-list (- numkeys numtarg) "%"))
+ targlist))
+ (target-patt (string-join targtweaked "/")))
+ (if (common:simple-file-lock lockfile)
+ (begin
+ (let* (;(runsdat1 (rmt:get-runs run-patt #f #f (map (lambda (x)(list x "%")) keys)))
+ (runsdat (rmt:get-runs-by-patt keys run-patt target-patt #f #f #f 0))
+ (runs (vector-ref runsdat 1))
+ (header (vector-ref runsdat 0))
+ (oup (open-output-file (or outf (conc linktree "/targets.html"))))
+ (target-hash (test:create-target-hash runs header (length keys))))
+ (test:create-target-html target-hash oup area-name linktree)
+ (test:create-run-html runs area-name linktree (length keys) header))
+ (common:simple-file-release-lock lockfile))
+ #f)))
+
+(define (test:get-test-hash test-data)
+ (let ((resh (make-hash-table)))
+ (map (lambda (test)
+ (let* ((test-name (vector-ref test 2))
+ (test-html-path (if (file-exists? (conc (vector-ref test 10) "/test-summary.html"))
+ (conc (vector-ref test 10) "/test-summary.html" )
+ (conc (vector-ref test 10) "/" (vector-ref test 13))))
+ (test-item (vector-ref test 11))
+ (test-status (vector-ref test 4)))
+ (if (not (hash-table-ref/default resh test-item #f))
+ (hash-table-set! resh test-item (make-hash-table)))
+ (hash-table-set! (hash-table-ref/default resh test-item #f) test-name (list test-status test-html-path))))
+ test-data)
+resh))
+
+(define (test:get-data->b-keys ordered-data a-keys)
+ (delete-duplicates
+ (sort (apply
+ append
+ (map (lambda (sub-key)
+ (let ((subdat (hash-table-ref ordered-data sub-key)))
+ (hash-table-keys subdat)))
+ a-keys))
+ string>=?)))
+
+
+(define (test:create-run-html runs area-name linktree numkeys header)
+ (map (lambda (run)
+ (let* ((target (string-join (take (vector->list run) numkeys) "/"))
+ (run-name (db:get-value-by-header run header "runname"))
+ (run-time (seconds->work-week/day-time (db:get-value-by-header run header "event_time")))
+ (oup (if (file-exists? (conc linktree "/" target "/" run-name))
+ (open-output-file (conc linktree "/" target "/" run-name "/run.html"))
+ #f))
+ (run-id (db:get-value-by-header run header "id"))
+ (test-data (rmt:get-tests-for-run
+ run-id
+ "%" ;; testnamepatt
+ '() ;; states
+ '() ;; statuses
+ #f ;; offset
+ #f ;; num-to-get
+ #f ;; hide/not-hide
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; 'shortlist ;; qrytype
+ 0 ;; last update
+ #f))
+ (item-test-hash (test:get-test-hash test-data))
+ (items (hash-table-keys item-test-hash))
+ (test-names (test:get-data->b-keys item-test-hash items)))
+ (if oup
+ (begin
+ (s:output-new
+ oup
+ (s:html tests:css-jscript-block (tests:css-jscript-block-cond #f)
+ (s:title "Runs View " run-name)
+ (s:body
+ (s:h1 "Runs View " )
+ (s:h3 "Target" target)
+ (s:p
+ (s:b "Run name" ) run-name)
+ (s:p
+ (s:b "Run Date" ) run-time)
+ (s:table 'border 1 'cellspacing 0
+ (s:tr
+ (s:th "Items")
+ (map (lambda (test)
+ (s:th test))
+ test-names))
+ (map (lambda (item)
+ (let* ((test-hash (hash-table-ref/default item-test-hash item #f)))
+ (if test-hash
+ (begin
+ (s:tr
+ (s:td 'class "test" item)
+ (map (lambda (test)
+ (let* ((test-details (hash-table-ref/default test-hash test #f))
+ (status (if test-details
+ (car test-details)))
+ (link (if test-details
+ (string-substitute (conc linktree "/" target "/" run-name "/") "" (cadr test-details) "-"))))
+ (if test-details
+ (s:td 'class status
+ (s:a 'class "link" 'href link status ))
+ (s:td ""))))
+ test-names))))))
+ (sort items string<=?))))))
+ (close-output-port oup))
+ (debug:print-info 0 "Skip: Dirctory structure " linktree "/" target "/" run-name " does not exist. Megatest will not create run.html"))))
+runs))
+
+(define (test:create-target-hash runs header numkeys)
+ (let ((resh (make-hash-table)))
+ (for-each
+ (lambda (run)
+ (let* ((run-name (db:get-value-by-header run header "runname"))
+ (target (string-join (take (vector->list run) numkeys) "/"))
+ (run-list (hash-table-ref/default resh target #f)))
+
+ (if (not run-list)
+ (hash-table-set! resh target (list run-name))
+ (hash-table-set! resh target (cons run-name run-list)))))
+ runs)
+ resh))
+
+(define (test:get-max-run-cnt target-hash targets)
+ (let* ((cnt 0 ))
+ (map (lambda (target)
+ (let* ((runs (hash-table-ref/default target-hash target #f))
+ (run-length (if runs
+ (length runs)
+ 0)))
+
+ (if (< cnt run-length)
+ (set! cnt run-length))))
+ targets)
+cnt))
+
+(define (test:pad-runs target-hash targets max-row-length)
+ (map (lambda (target)
+ (let loop ((run-list (hash-table-ref/default target-hash target #f)))
+ (if (< (length run-list) max-row-length)
+ (begin
+ (hash-table-set! target-hash target (cons "" run-list))
+ (loop (hash-table-ref/default target-hash target #f) )))))
+ targets)
+ target-hash)
+
+(define (test:create-target-html target-hash oup area-name linktree)
+ (let* ((targets (hash-table-keys target-hash))
+ (max-row-length (test:get-max-run-cnt target-hash targets))
+ (pad-runs-hash (test:pad-runs target-hash targets max-row-length)))
+ (s:output-new
+ oup
+ (s:html tests:css-jscript-block (tests:css-jscript-block-cond #f)
+
+ (s:title "Target View " area-name)
+ (s:body
+ (s:h1 "Target View " area-name)
+ (s:table 'id "LinkedList1" 'border "1" 'cellspacing 0
+ (s:tr 'class "something"
+ (s:th "Target")
+ (s:th 'colspan max-row-length "Runs"))
+ (let* ((tbl (map (lambda (target)
+ (s:tr
+ (s:td 'class "test" target)
+ (let* ((runs (hash-table-ref/default target-hash target #f))
+ (rest-row (map (lambda (run)
+ (if (equal? run "")
+ (s:td run)
+ (if (file-exists?(conc linktree "/" target "/" run ))
+ (begin
+ (s:td
+ (s:a 'href (conc target "/" run "/run.html") run))))))
+ (reverse runs))))
+ rest-row)))
+ targets)))
+ tbl)))))
+ (close-output-port oup)))
+
+
+(define (tests:create-html-tree-old outf)
+ (let* ((lockfile (conc outf ".lock"))
+ (runs-to-process '()))
+ (if (common:simple-file-lock lockfile)
+ (let* ((linktree (common:get-linktree))
+ (oup (open-output-file (or outf (conc linktree "/runs-index.html"))))
+ (area-name (common:get-testsuite-name))
+ (keys (rmt:get-keys))
+ (numkeys (length keys))
+ (runsdat (rmt:get-runs "%" #f #f (map (lambda (x)(list x "%")) keys)))
+ (header (vector-ref runsdat 0))
+ (runs (vector-ref runsdat 1))
+ (runtreedat (map (lambda (x)
+ (tests:run-record->test-path x numkeys))
+ runs))
+ (runs-htree (common:list->htree runtreedat)))
+ (set! runs-to-process runs)
+ (s:output-new
+ oup
+ (s:html tests:css-jscript-block
+ (s:title "Summary for " area-name)
+ (s:body 'onload "addEvents();"
+ (s:h1 "Summary for " area-name)
+ ;; top list
+ (s:ul 'id "LinkedList1" 'class "LinkedList"
+ (s:li
+ "Runs"
+ (common:htree->html runs-htree
+ '()
+ (lambda (x p)
+ (let* ((targ-path (string-intersperse p "/"))
+ (full-path (conc linktree "/" targ-path))
+ (run-name (car (reverse p))))
+ (if (and (common:file-exists? full-path)
+ (directory? full-path)
+ (file-write-access? full-path))
+ (s:a run-name 'href (conc targ-path "/run-summary.html"))
+ (begin
+ (debug:print 0 *default-log-port* "INFO: Can't create " targ-path "/run-summary.html")
+ (conc run-name " (Not able to create summary at " targ-path ")")))))))))))
+ (close-output-port oup)
+ (common:simple-file-release-lock lockfile)
+
+ (for-each
+ (lambda (run)
+ (let* ((test-subpath (tests:run-record->test-path run numkeys))
+ (run-id (db:get-value-by-header run header "id"))
+ (run-dir (tests:run-record->test-path run numkeys))
+ (test-dats (rmt:get-tests-for-run
+ run-id
+ "%/" ;; testnamepatt
+ '() ;; states
+ '() ;; statuses
+ #f ;; offset
+ #f ;; num-to-get
+ #f ;; hide/not-hide
+ #f ;; sort-by
+ #f ;; sort-order
+ #f ;; 'shortlist ;; qrytype
+ 0 ;; last update
+ #f))
+ (tests-tree-dat (map (lambda (test-dat)
+ ;; (tests:run-record->test-path x numkeys))
+ (let* ((test-name (db:test-get-testname test-dat))
+ (item-path (db:test-get-item-path test-dat))
+ (full-name (db:test-make-full-name test-name item-path))
+ (path-parts (string-split full-name)))
+ path-parts))
+ test-dats))
+ (tests-htree (common:list->htree tests-tree-dat))
+ (html-dir (conc linktree "/" (string-intersperse run-dir "/")))
+ (html-path (conc html-dir "/run-summary.html"))
+ (oup (if (and (common:file-exists? html-dir)
+ (directory? html-dir)
+ (file-write-access? html-dir))
+ (open-output-file html-path)
+ #f)))
+ ;; (print "run-dir: " run-dir ", tests-tree-dat: " tests-tree-dat)
+ (if oup
+ (begin
+ (s:output-new
+ oup
+ (s:html tests:css-jscript-block
+ (s:title "Summary for " area-name)
+ (s:body 'onload "addEvents();"
+ (s:h1 "Summary for " (string-intersperse run-dir "/"))
+ ;; top list
+ (s:ul 'id "LinkedList1" 'class "LinkedList"
+ (s:li
+ "Tests"
+ (common:htree->html tests-htree
+ '()
+ (lambda (x p)
+ (let* ((targ-path (string-intersperse p "/"))
+ (test-name (car p))
+ (item-path ;; (if (> (length p) 2) ;; test-name + run-name
+ (string-intersperse p "/"))
+ (full-targ (conc html-dir "/" targ-path))
+ (std-file (conc full-targ "/test-summary.html"))
+ (alt-file (conc full-targ "/megatest-rollup-" test-name ".html"))
+ (html-file (if (common:file-exists? alt-file)
+ alt-file
+ std-file))
+ (run-name (car (reverse p))))
+ (if (and (not (common:file-exists? full-targ))
+ (directory? full-targ)
+ (file-write-access? full-targ))
+ (tests:summarize-test
+ run-id
+ (rmt:get-test-id run-id test-name item-path)))
+ (if (common:file-exists? full-targ)
+ (s:a run-name 'href html-file)
+ (begin
+ (debug:print 0 *default-log-port* "ERROR: can't access " full-targ)
+ (conc "No summary for " run-name)))))
+ ))))))
+ (close-output-port oup)))))
+ runs)
+ #t)
+ #f)))
+
+
+
+
+
+
+
+;; CHECK - WAS THIS ADDED OR REMOVED? MANUAL MERGE WITH API STUFF!!!
+;;
+;; get a pretty table to summarize steps
+;;
+;; (define (dcommon:process-steps-table steps);; db test-id #!key (work-area #f))
+(define (tests:process-steps-table steps);; db test-id #!key (work-area #f))
+;; (let ((steps (db:get-steps-for-test db test-id work-area: work-area)))
+ ;; organise the steps for better readability
+ (let ((res (make-hash-table)))
+ (for-each
+ (lambda (step)
+ (debug:print 6 *default-log-port* "step=" step)
+ (let ((record (hash-table-ref/default
+ res
+ (tdb:step-get-stepname step)
+ ;; 0 1 2 3 4 5 6 7
+ ;; stepname start end status Duration Logfile Comment first-id
+ (vector (tdb:step-get-stepname step) "" "" "" "" "" "" #f))))
+ (debug:print 6 *default-log-port* "record(before) = " record
+ "\nid: " (tdb:step-get-id step)
+ "\nstepname: " (tdb:step-get-stepname step)
+ "\nstate: " (tdb:step-get-state step)
+ "\nstatus: " (tdb:step-get-status step)
+ "\ntime: " (tdb:step-get-event_time step))
+ (if (not (vector-ref record 7))(vector-set! record 7 (tdb:step-get-id step))) ;; do not clobber the id if previously set
+ (case (string->symbol (tdb:step-get-state step))
+ ((start)(vector-set! record 1 (tdb:step-get-event_time step))
+ (vector-set! record 3 (if (equal? (vector-ref record 3) "")
+ (tdb:step-get-status step)))
+ (if (> (string-length (tdb:step-get-logfile step))
+ 0)
+ (vector-set! record 5 (tdb:step-get-logfile step))))
+ ((end)
+ (vector-set! record 2 (any->number (tdb:step-get-event_time step)))
+ (vector-set! record 3 (tdb:step-get-status step))
+ (vector-set! record 4 (let ((startt (any->number (vector-ref record 1)))
+ (endt (any->number (vector-ref record 2))))
+ (debug:print 4 *default-log-port* "record[1]=" (vector-ref record 1)
+ ", startt=" startt ", endt=" endt
+ ", get-status: " (tdb:step-get-status step))
+ (if (and (number? startt)(number? endt))
+ (seconds->hr-min-sec (- endt startt)) "-1")))
+ (if (> (string-length (tdb:step-get-logfile step))
+ 0)
+ (vector-set! record 5 (tdb:step-get-logfile step)))
+ (if (> (string-length (tdb:step-get-comment step))
+ 0)
+ (vector-set! record 6 (tdb:step-get-comment step))))
+ (else
+ (vector-set! record 2 (tdb:step-get-state step))
+ (vector-set! record 3 (tdb:step-get-status step))
+ (vector-set! record 4 (tdb:step-get-event_time step))
+ (vector-set! record 6 (tdb:step-get-comment step))))
+ (hash-table-set! res (tdb:step-get-stepname step) record)
+ (debug:print 6 *default-log-port* "record(after) = " record
+ "\nid: " (tdb:step-get-id step)
+ "\nstepname: " (tdb:step-get-stepname step)
+ "\nstate: " (tdb:step-get-state step)
+ "\nstatus: " (tdb:step-get-status step)
+ "\ntime: " (tdb:step-get-event_time step))))
+ ;; (else (vector-set! record 1 (tdb:step-get-event_time step)))
+ (sort steps (lambda (a b)
+ (cond
+ ((< (tdb:step-get-event_time a)(tdb:step-get-event_time b)) #t)
+ ((eq? (tdb:step-get-event_time a)(tdb:step-get-event_time b))
+ (< (tdb:step-get-id a) (tdb:step-get-id b)))
+ (else #f)))))
+ res))
+
+;;
+;;
+(define (tests:get-compressed-steps run-id test-id)
+ (let* ((steps-data (rmt:get-steps-for-test run-id test-id)) ;; 0 1 2 3 4 5 6 7
+ (comprsteps (tests:process-steps-table steps-data))) ;; #
+ (map (lambda (x)
+ ;; take advantage of the \n on time->string
+ (vector ;; we are constructing basically the original vector but collapsing start end records
+ (vector-ref x 0) ;; id 0
+ (let ((s (vector-ref x 1)))
+ (if (number? s)(seconds->time-string s) s)) ;; starttime 1
+ (let ((s (vector-ref x 2)))
+ (if (number? s)(seconds->time-string s) s)) ;; endtime 2
+ (vector-ref x 3) ;; status 3
+ (vector-ref x 4) ;; duration 4
+ (vector-ref x 5) ;; logfile 5
+ (vector-ref x 6) ;; comment 6
+ (vector-ref x 7))) ;; id 7
+ (sort (hash-table-values comprsteps)
+ (lambda (a b)
+ (let ((time-a (vector-ref a 1))
+ (time-b (vector-ref b 1))
+ (id-a (vector-ref a 7))
+ (id-b (vector-ref b 7)))
+ (if (and (number? time-a)(number? time-b))
+ (if (< time-a time-b)
+ #t
+ (if (eq? time-a time-b)
+ (< id-a id-b)
+ ;; (string (conc (vector-ref a 2))
+ ;; (conc (vector-ref b 2)))
+ #f))
+ (string (conc time-a)(conc time-b)))))))))
+
+
+;; Save test state and status in to a file .final-status in the test directory
+;;
+(define (tests:save-final-status run-id test-id)
+ (let* ((test-dat (rmt:get-test-info-by-id run-id test-id))
+ (out-dir (db:test-get-rundir test-dat))
+ (status-file (conc out-dir "/.final-status"))
+ )
+ ;; first verify we are able to write the output file
+ (if (not (file-write-access? out-dir))
+ (debug:print 0 *default-log-port* "ERROR: cannot write .final-status to " out-dir)
+ (let*
+ ((outp (open-output-file status-file))
+ (status (db:test-get-status test-dat))
+ (state (db:test-get-state test-dat)))
+ (fprintf outp "~S\n" state)
+ (fprintf outp "~S\n" status)
+ (close-output-port outp)))))
+
+
+;; summarize test in to a file test-summary.html in the test directory
+;;
+(define (tests:summarize-test run-id test-id)
+ (let* ((test-dat (rmt:get-test-info-by-id run-id test-id))
+ (out-dir (db:test-get-rundir test-dat))
+ (out-file (conc out-dir "/test-summary.html")))
+ ;; first verify we are able to write the output file
+ (if (not (file-write-access? out-dir))
+ (debug:print 0 *default-log-port* "ERROR: cannot write test-summary.html to " out-dir)
+ (let* (;; (steps-dat (rmt:get-steps-for-test run-id test-id))
+ (test-name (db:test-get-testname test-dat))
+ (item-path (db:test-get-item-path test-dat))
+ (full-name (db:test-make-full-name test-name item-path))
+ (oup (open-output-file out-file))
+ (status (db:test-get-status test-dat))
+ (color (common:get-color-from-status status))
+ (logf (db:test-get-final_logf test-dat))
+ (steps-dat (tests:get-compressed-steps run-id test-id)))
+ ;; (dcommon:get-compressed-steps #f 1 30045)
+ ;; (#("wasting_time" "23:36:13" "23:36:21" "0" "8.0s" "wasting_time.log"))
+
+ (s:output-new
+ oup
+ (s:html
+ (s:title "Summary for " full-name)
+ (s:body
+ (s:h2 "Summary for " full-name)
+ (s:table 'cellspacing "0" 'border "1"
+ (s:tr (s:td "run id") (s:td (db:test-get-run_id test-dat))
+ (s:td "test id") (s:td (db:test-get-id test-dat)))
+ (s:tr (s:td "testname") (s:td test-name)
+ (s:td "itempath") (s:td item-path))
+ (s:tr (s:td "state") (s:td (db:test-get-state test-dat))
+ (s:td "status") (s:td (s:a 'href logf (s:font 'color color status))))
+ (s:tr (s:td "TestDate") (s:td (seconds->work-week/day-time
+ (db:test-get-event_time test-dat)))
+ (s:td "Duration") (s:td (seconds->hr-min-sec (db:test-get-run_duration test-dat)))))
+ (s:h3 "Log files")
+ (s:table
+ 'cellspacing "0" 'border "1"
+ (s:tr (s:td "Final log")(s:td (s:a 'href logf logf))))
+ (s:table
+ 'cellspacing "0" 'border "1"
+ (s:tr (s:td "Step Name")(s:td "Start")(s:td "End")(s:td "Status")(s:td "Duration")(s:td "Log File"))
+ (map (lambda (step-dat)
+ (s:tr (s:td (tdb:steps-table-get-stepname step-dat))
+ (s:td (tdb:steps-table-get-start step-dat))
+ (s:td (tdb:steps-table-get-end step-dat))
+ (s:td (tdb:steps-table-get-status step-dat))
+ (s:td (tdb:steps-table-get-runtime step-dat))
+ (s:td (let ((step-log (tdb:steps-table-get-log-file step-dat)))
+ (s:a 'href step-log step-log)))))
+ steps-dat))
+ )))
+ (close-output-port oup)))))
+
+
+;; MUST BE CALLED local!
+;;
+(define (tests:test-get-paths-matching keynames target fnamepatt #!key (res '()))
+ ;; BUG: Move the values derived from args to parameters and push to megatest.scm
+ (let* ((testpatt (or (args:get-arg "-testpatt")(args:get-arg "-testpatt") "%"))
+ (statepatt (or (args:get-arg "-state") (args:get-arg ":state") "%"))
+ (statuspatt (or (args:get-arg "-status") (args:get-arg ":status") "%"))
+ (runname (or (args:get-arg "-runname") (args:get-arg ":runname") "%"))
+ (paths-from-db (rmt:test-get-paths-matching-keynames-target-new keynames target res
+ testpatt
+ statepatt
+ statuspatt
+ runname)))
+ (if fnamepatt
+ (apply append
+ (map (lambda (p)
+ (if (directory-exists? p)
+ (let ((glob-query (conc p "/" fnamepatt)))
+ (handle-exceptions
+ exn
+ (begin
+ (print "built-in glob on " glob-query ", failed, try using the shell. exn=" exn)
+ (with-input-from-pipe
+ (conc "echo " glob-query)
+ read-lines)) ;; we aren't going to try too hard. If glob breaks it is likely because someone tried to do */*/*.log or similar
+ (glob glob-query)))
+ '()))
+ paths-from-db))
+ paths-from-db)))
+
+
+;;======================================================================
+;; Gather data from test/task specifications
+;;======================================================================
+
+;; (define (tests:get-valid-tests testsdir test-patts) ;; #!key (test-names '()))
+;; (let ((tests (glob (conc testsdir "/tests/*")))) ;; " (string-translate patt "%" "*")))))
+;; (set! tests (filter (lambda (test)(common:file-exists? (conc test "/testconfig"))) tests))
+;; (delete-duplicates
+;; (filter (lambda (testname)
+;; (tests:match test-patts testname #f))
+;; (map (lambda (testp)
+;; (last (string-split testp "/")))
+;; tests)))))
+
+(define (tests:get-test-path-from-environment)
+ (if (and (getenv "MT_LINKTREE")
+ (getenv "MT_TARGET")
+ (getenv "MT_RUNNAME")
+ (getenv "MT_TEST_NAME")
+ (getenv "MT_ITEMPATH"))
+ (conc (getenv "MT_LINKTREE") "/"
+ (getenv "MT_TARGET") "/"
+ (getenv "MT_RUNNAME") "/"
+ (getenv "MT_TEST_NAME")
+ (if (and (getenv "MT_ITEMPATH")
+ (not (string=? "" (getenv "MT_ITEMPATH"))))
+ (conc "/" (getenv "MT_ITEMPATH"))
+ ""))
+ #f))
+
+;; if .testconfig exists in test directory read and return it
+;; else if have cached copy in *testconfigs* return it IFF there is a section "have fulldata"
+;; else read the testconfig file
+;; if have path to test directory save the config as .testconfig and return it
+;;
+(define (tests:get-testconfig test-name item-path test-registry system-allowed #!key (force-create #f)(allow-write-cache #t)(wait-a-minute #f))
+ (let* ((use-cache (common:use-cache?))
+ (cache-path (tests:get-test-path-from-environment))
+ (cache-file (and cache-path (conc cache-path "/.testconfig")))
+ (cache-exists (and cache-file
+ (not force-create) ;; if force-create then pretend there is no cache to read
+ (common:file-exists? cache-file)))
+ (cached-dat (if (and (not force-create)
+ cache-exists
+ use-cache)
+ (handle-exceptions
+ exn
+ (begin
+ (debug:print 0 *default-log-port* "failed to read " cache-file ", exn=" exn)
+ #f) ;; any issues, just give up with the cached version and re-read
+ (configf:read-alist cache-file))
+ #f))
+ (test-full-name (if (and item-path (not (string-null? item-path)))
+ (conc test-name "/" item-path)
+ test-name)))
+ (if cached-dat
+ cached-dat
+ (let ((dat (hash-table-ref/default *testconfigs* test-full-name #f)))
+ (if (and dat ;; have a locally cached version
+ (hash-table-ref/default dat "have fulldata" #f)) ;; marked as good data?
+ dat
+ ;; no cached data available
+ (let* ((treg (or test-registry
+ (tests:get-all)))
+ (test-path (or (hash-table-ref/default treg test-name #f)
+ (let* ((local-tcdir (conc (getenv "MT_LINKTREE") "/"
+ (getenv "MT_TARGET") "/"
+ (getenv "MT_RUNNAME") "/"
+ test-name "/" item-path))
+ (local-tcfg (conc local-tcdir "/testconfig")))
+ (if (common:file-exists? local-tcfg)
+ local-tcdir
+ #f))
+ (conc *toppath* "/tests/" test-name)))
+ (test-configf (conc test-path "/testconfig"))
+ (testexists (let loopa ((tries-left 30))
+ (cond
+ (
+ (and (common:file-exists? test-configf)(file-read-access? test-configf))
+ #t)
+ (
+ (common:file-exists? test-configf)
+ (debug:print 0 *default-log-port* "WARNING: Cannot read testconfig file: "test-configf)
+ #f)
+ (
+ (and wait-a-minute (> tries-left 0))
+ (thread-sleep! 10)
+ (debug:print 0 *default-log-port* "WARNING: testconfig file does not exist: "test-configf" will retry in 10 seconds. Tries left: "tries-left) ;; BB: this fires
+ (loopa (sub1 tries-left)))
+ (else
+ (debug:print 0 *default-log-port* "WARNING: testconfig file does not exist: "test-configf) ;; BB: this fires
+ #f))))
+ (tcfg (if testexists
+ (read-config test-configf #f system-allowed
+ environ-patt: (if system-allowed
+ "pre-launch-env-vars"
+ #f))
+ #f)))
+ (if (and tcfg cache-file) (hash-table-set! tcfg "have fulldata" #t)) ;; mark this as fully read data
+ (if tcfg (hash-table-set! *testconfigs* test-full-name tcfg))
+ (if (and testexists
+ cache-file
+ (file-write-access? cache-path)
+ allow-write-cache)
+ (let ((tpath (conc cache-path "/.testconfig")))
+ (debug:print-info 1 *default-log-port* "Caching testconfig for " test-name " in " tpath)
+ (if (and tcfg (not (common:in-running-test?)))
+ (configf:write-alist tcfg tpath))))
+ tcfg))))))
+
+;; sort tests by priority and waiton
+;; Move test specific stuff to a test unit FIXME one of these days
+(define (tests:sort-by-priority-and-waiton test-records)
+ (if (eq? (hash-table-size test-records) 0)
+ '()
+ (let* ((mungepriority (lambda (priority)
+ (if priority
+ (let ((tmp (any->number priority)))
+ (if tmp tmp (begin (debug:print-error 0 *default-log-port* "bad priority value " priority ", using 0") 0)))
+ 0)))
+ (all-tests (hash-table-keys test-records))
+ (all-waited-on (let loop ((hed (car all-tests))
+ (tal (cdr all-tests))
+ (res '()))
+ (let* ((trec (hash-table-ref test-records hed))
+ (waitons (or (tests:testqueue-get-waitons trec) '())))
+ (if (null? tal)
+ (append res waitons)
+ (loop (car tal)(cdr tal)(append res waitons))))))
+ (sort-fn1
+ (lambda (a b)
+ (let* ((a-record (hash-table-ref test-records a))
+ (b-record (hash-table-ref test-records b))
+ (a-waitons (or (tests:testqueue-get-waitons a-record) '()))
+ (b-waitons (or (tests:testqueue-get-waitons b-record) '()))
+ (a-config (tests:testqueue-get-testconfig a-record))
+ (b-config (tests:testqueue-get-testconfig b-record))
+ (a-raw-pri (configf:lookup a-config "requirements" "priority"))
+ (b-raw-pri (configf:lookup b-config "requirements" "priority"))
+ (a-priority (mungepriority a-raw-pri))
+ (b-priority (mungepriority b-raw-pri)))
+ (tests:testqueue-set-priority! a-record a-priority)
+ (tests:testqueue-set-priority! b-record b-priority)
+ ;; (debug:print 0 *default-log-port* "a=" a ", b=" b ", a-waitons=" a-waitons ", b-waitons=" b-waitons)
+ (cond
+ ;; is
+ ((member a b-waitons) ;; is b waiting on a?
+ ;; (debug:print 0 *default-log-port* "case1")
+ #t)
+ ((member b a-waitons) ;; is a waiting on b?
+ ;; (debug:print 0 *default-log-port* "case2")
+ #f)
+ ((and (not (null? a-waitons)) ;; both have waitons - do not disturb
+ (not (null? b-waitons)))
+ ;; (debug:print 0 *default-log-port* "case2.1")
+ #t)
+ ((and (null? a-waitons) ;; no waitons for a but b has waitons
+ (not (null? b-waitons)))
+ ;; (debug:print 0 *default-log-port* "case3")
+ #f)
+ ((and (not (null? a-waitons)) ;; a has waitons but b does not
+ (null? b-waitons))
+ ;; (debug:print 0 *default-log-port* "case4")
+ #t)
+ ((not (eq? a-priority b-priority)) ;; use
+ (> a-priority b-priority))
+ (else
+ ;; (debug:print 0 *default-log-port* "case5")
+ (string>? a b))))))
+
+ (sort-fn2
+ (lambda (a b)
+ (> (mungepriority (tests:testqueue-get-priority (hash-table-ref test-records a)))
+ (mungepriority (tests:testqueue-get-priority (hash-table-ref test-records b)))))))
+ ;; (let ((dot-res (tests:run-dot (tests:tests->dot test-records) "plain")))
+ ;; (debug:print "dot-res=" dot-res))
+ ;; (let ((data (map cdr (filter
+ ;; (lambda (x)(equal? "node" (car x)))
+ ;; (map string-split (tests:easy-dot test-records "plain"))))))
+ ;; (map car (sort data (lambda (a b)
+ ;; (> (string->number (caddr a))(string->number (caddr b)))))))
+ ;; ))
+ (sort all-tests sort-fn1)))) ;; avoid dealing with deleted tests, look at the hash table
+
+(define (tests:easy-dot test-records outtype)
+ (let-values (((fd temp-path) (file-mkstemp (conc "/tmp/" (current-user-name) ".XXXXXX"))))
+ (let ((all-testnames (hash-table-keys test-records))
+ (temp-port (open-output-file* fd)))
+ ;; (format temp-port "This file is ~A.~%" temp-path)
+ (format temp-port "digraph tests {\n")
+ (format temp-port " size=4,8\n")
+ ;; (format temp-port " splines=none\n")
+ (for-each
+ (lambda (testname)
+ (let* ((testrec (hash-table-ref test-records testname))
+ (waitons (or (tests:testqueue-get-waitons testrec) '()))
+ (my-mt-waitons (tests:get-mt-waitons testname #t)))
+ ;; (print "my-mt-waitons=" my-mt-waitons)
+ (for-each
+ (lambda (waiton)
+ (format temp-port (conc " " waiton " -> " testname " [splines=ortho]\n")))
+ (append waitons my-mt-waitons))))
+ all-testnames)
+ (format temp-port "}\n")
+ (close-output-port temp-port)
+ (with-input-from-pipe
+ (conc "env -i PATH=$PATH dot -T" outtype " < " temp-path)
+ (lambda ()
+ (let ((res (read-lines)))
+ ;; (delete-file temp-path)
+ res))))))
+
+(define (tests:write-dot-file test-records fname sizex sizey)
+ (if (file-write-access? (pathname-directory fname))
+ (with-output-to-file fname
+ (lambda ()
+ (map print (tests:tests->dot test-records sizex sizey))))))
+
+(define (tests:tests->dot test-records sizex sizey)
+ (let ((all-testnames (hash-table-keys test-records)))
+ (if (null? all-testnames)
+ '()
+ (let loop ((hed (car all-testnames))
+ (tal (cdr all-testnames))
+ (res (list "digraph tests {"
+ (conc " size=\"" (or sizex 11) "," (or sizey 11) "\";")
+ " ratio=0.95;"
+ )))
+ (let* ((testrec (hash-table-ref test-records hed))
+ (waitons (or (tests:testqueue-get-waitons testrec) '()))
+ (my-mt-waitons (tests:get-mt-waitons hed #t))
+ (all-waitons (delete-duplicates (append waitons my-mt-waitons)))
+ (newres (append res
+ (if (null? all-waitons)
+ (list (conc " \"" hed "\" [shape=box];"))
+ (map (lambda (waiton)
+ (conc " \"" waiton "\" -> \"" hed "\" [shape=box];"))
+ all-waitons)))))
+ ;; (debug:print 0 *default-log-port* "For test "hed" got "all-waitons)
+ (if (null? tal)
+ (append newres (list "}"))
+ (loop (car tal)(cdr tal) newres)
+ ))))))
+
+;; (tests:run-dot (list "digraph tests {" "a -> b" "}") "plain")
+
+(define (tests:run-dot indat outtype) ;; outtype is plain, fig, dot, etc. http://www.graphviz.org/content/output-formats
+ (let-values (((inp oup pid)(process "env -i PATH=$PATH dot" (list "-T" outtype))))
+ (with-output-to-port oup
+ (lambda ()
+ (map print indat)))
+ (close-output-port oup)
+ (let ((res (with-input-from-port inp
+ (lambda ()
+ (read-lines)))))
+ (close-input-port inp)
+ res)))
+
+;; read data from tmp file or create if not exists
+;; if exists regen in background
+;;
+(define (tests:lazy-dot testrecords outtype sizex sizey)
+ (let ((dfile (conc "/tmp/." (current-user-name) "-" (server:mk-signature) ".dot"))
+ (fname (conc "/tmp/." (current-user-name) "-" (server:mk-signature) ".dotdat")))
+ (tests:write-dot-file testrecords dfile sizex sizey)
+ (if (common:file-exists? fname)
+ (let ((res (with-input-from-file fname
+ (lambda ()
+ (read-lines)))))
+ (system (conc "env -i PATH=$PATH dot -T " outtype " < " dfile " > " fname "&"))
+ res)
+ (begin
+ (system (conc "env -i PATH=$PATH dot -T " outtype " < " dfile " > " fname))
+ (with-input-from-file fname
+ (lambda ()
+ (read-lines)))))))
+
+
+;; for each test:
+;;
+(define (tests:filter-non-runnable run-id testkeynames testrecordshash)
+ (let ((runnables '()))
+ (for-each
+ (lambda (testkeyname)
+ (let* ((test-record (hash-table-ref testrecordshash testkeyname))
+ (test-name (tests:testqueue-get-testname test-record))
+ (itemdat (tests:testqueue-get-itemdat test-record))
+ (item-path (tests:testqueue-get-item_path test-record))
+ (waitons (tests:testqueue-get-waitons test-record))
+ (keep-test #t)
+ (test-id (rmt:get-test-id run-id test-name item-path))
+ (tdat (rmt:get-testinfo-state-status run-id test-id))) ;; (cdb:get-test-info-by-id *runremote* test-id)))
+ (if tdat
+ (begin
+ ;; Look at the test state and status
+ (if (or (and (member (db:test-get-status tdat)
+ '("PASS" "WARN" "WAIVED" "CHECK" "SKIP"))
+ (equal? (db:test-get-state tdat) "COMPLETED"))
+ (member (db:test-get-state tdat)
+ '("INCOMPLETE" "KILLED")))
+ (set! keep-test #f))
+
+ ;; examine waitons for any fails. If it is FAIL or INCOMPLETE then eliminate this test
+ ;; from the runnable list
+ (if keep-test
+ (for-each (lambda (waiton)
+ ;; for now we are waiting only on the parent test
+ (let* ((parent-test-id (rmt:get-test-id run-id waiton ""))
+ (wtdat (rmt:get-testinfo-state-status run-id test-id))) ;; (cdb:get-test-info-by-id *runremote* test-id)))
+ (if (or (and (equal? (db:test-get-state wtdat) "COMPLETED")
+ (member (db:test-get-status wtdat) '("FAIL" "ABORT")))
+ (member (db:test-get-status wtdat) '("KILLED"))
+ (member (db:test-get-state wtdat) '("INCOMPETE")))
+ ;; (if (or (member (db:test-get-status wtdat)
+ ;; '("FAIL" "KILLED"))
+ ;; (member (db:test-get-state wtdat)
+ ;; '("INCOMPETE")))
+ (set! keep-test #f)))) ;; no point in running this one again
+ waitons))))
+ (if keep-test (set! runnables (cons testkeyname runnables)))))
+ testkeynames)
+ runnables))
+
+;;======================================================================
+;; refactoring this block into tests:get-full-data from line 263 of runs.scm
+;;======================================================================
+;; hed is the test name
+;; test-records is a hash of test-name => test record
+(define (tests:get-full-data test-names test-records required-tests all-tests-registry)
+ (if (not (null? test-names))
+ (let loop ((hed (car test-names))
+ (tal (cdr test-names))) ;; 'return-procs tells the config reader to prep running system but return a proc
+ (debug:print-info 4 *default-log-port* "hed=" hed " at top of loop")
+ ;; don't know item-path at this time, let the testconfig get the top level testconfig
+ (let* ((config (tests:get-testconfig hed #f all-tests-registry 'return-procs))
+ (waitons (let ((instr (if config
+ (configf:lookup config "requirements" "waiton")
+ (begin ;; No config means this is a non-existant test
+ (debug:print-error 0 *default-log-port* "non-existent required test \"" hed "\", grep through your testconfigs to find and remove or create the test. Discarding and continuing.")
+ ""))))
+ (debug:print-info 8 *default-log-port* "waitons string is " instr)
+ (string-split (cond
+ ((procedure? instr)
+ (let ((res (instr)))
+ (debug:print-info 8 *default-log-port* "waiton procedure results in string " res " for test " hed)
+ res))
+ ((string? instr) instr)
+ (else
+ ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print-error 0 *default-log-port* "something went wrong in processing waitons for test " hed)
+ ""))))))
+ (if (not config) ;; this is a non-existant test called in a waiton.
+ (if (null? tal)
+ test-records
+ (loop (car tal)(cdr tal)))
+ (begin
+ (debug:print-info 8 *default-log-port* "waitons: " waitons)
+ ;; check for hed in waitons => this would be circular, remove it and issue an
+ ;; error
+ (if (member hed waitons)
+ (begin
+ (debug:print-error 0 *default-log-port* "test " hed " has listed itself as a waiton, please correct this!")
+ (set! waitons (filter (lambda (x)(not (equal? x hed))) waitons))))
+
+ ;; (items (items:get-items-from-config config)))
+ (if (not (hash-table-ref/default test-records hed #f))
+ (hash-table-set! test-records
+ hed (vector hed ;; 0
+ config ;; 1
+ waitons ;; 2
+ (configf:lookup config "requirements" "priority") ;; priority 3
+ (let ((items (hash-table-ref/default config "items" #f)) ;; items 4
+ (itemstable (hash-table-ref/default config "itemstable" #f)))
+ ;; if either items or items table is a proc return it so test running
+ ;; process can know to call items:get-items-from-config
+ ;; if either is a list and none is a proc go ahead and call get-items
+ ;; otherwise return #f - this is not an iterated test
+ (cond
+ ((procedure? items)
+ (debug:print-info 4 *default-log-port* "items is a procedure, will calc later")
+ items) ;; calc later
+ ((procedure? itemstable)
+ (debug:print-info 4 *default-log-port* "itemstable is a procedure, will calc later")
+ itemstable) ;; calc later
+ ((filter (lambda (x)
+ (let ((val (car x)))
+ (if (procedure? val) val #f)))
+ (append (if (list? items) items '())
+ (if (list? itemstable) itemstable '())))
+ 'have-procedure)
+ ((or (list? items)(list? itemstable)) ;; calc now
+ (debug:print-info 4 *default-log-port* "items and itemstable are lists, calc now\n"
+ " items: " items " itemstable: " itemstable)
+ (items:get-items-from-config config))
+ (else #f))) ;; not iterated
+ #f ;; itemsdat 5
+ #f ;; spare - used for item-path
+ )))
+ (for-each
+ (lambda (waiton)
+ (if (and waiton (not (member waiton test-names)))
+ (begin
+ (set! required-tests (cons waiton required-tests))
+ (set! test-names (cons waiton test-names))))) ;; was an append, now a cons
+ waitons)
+ (let ((remtests (delete-duplicates (append waitons tal))))
+ (if (not (null? remtests))
+ (loop (car remtests)(cdr remtests))
+ test-records))))))))
+
+;;======================================================================
+;; test steps
+;;======================================================================
+
+;; teststep-set-status! used to be here
+
+(define (test-get-kill-request run-id test-id) ;; run-id test-name itemdat)
+ (let* ((testdat (rmt:get-test-info-by-id run-id test-id)))
+ (and testdat
+ (equal? (test:get-state testdat) "KILLREQ"))))
+
+(define (test:tdb-get-rundat-count tdb)
+ (if tdb
+ (let ((res 0))
+ (sqlite3:for-each-row
+ (lambda (count)
+ (set! res count))
+ tdb
+ "SELECT count(id) FROM test_rundat;")
+ res))
+ 0)
+
+(define (tests:update-central-meta-info run-id test-id cpuload diskfree minutes uname hostname)
+ (rmt:general-call 'update-test-rundat run-id test-id (current-seconds) (or cpuload -1)(or diskfree -1) -1 (or minutes -1))
+ (if (and cpuload diskfree)
+ (rmt:general-call 'update-cpuload-diskfree run-id cpuload diskfree test-id))
+ (if minutes
+ (rmt:general-call 'update-run-duration run-id minutes test-id))
+ (if (and uname hostname)
+ (rmt:general-call 'update-uname-host run-id uname hostname test-id)))
+
+;; This one is for running with no db access (i.e. via rmt: internally)
+(define (tests:set-full-meta-info db test-id run-id minutes work-area remtries)
+;; (define (tests:set-full-meta-info test-id run-id minutes work-area)
+;; (let ((remtries 10))
+ (let* ((cpuload (get-cpu-load))
+ (diskfree (get-df (current-directory)))
+ (uname (get-uname "-srvpio"))
+ (hostname (get-host-name)))
+ (tests:update-central-meta-info run-id test-id cpuload diskfree minutes uname hostname)))
+
+;; (define (tests:set-partial-meta-info test-id run-id minutes work-area)
+#;(define (tests:set-partial-meta-info test-id run-id minutes work-area remtries)
+ (let* ((cpuload (get-cpu-load))
+ (diskfree (get-df (current-directory)))
+ (remtries 10))
+ (handle-exceptions
+ exn
+ (if (> remtries 0)
+ (begin
+ (print-call-chain (current-error-port))
+ (debug:print-info 0 *default-log-port* "WARNING: failed to set meta info. Will try " remtries " more times")
+ (set! remtries (- remtries 1))
+ (thread-sleep! 10)
+ (tests:set-full-meta-info db test-id run-id minutes work-area (- remtries 1)))
+ (let ((err-status ((condition-property-accessor 'sqlite3 'status #f) exn)))
+ (debug:print-error 0 *default-log-port* "tried for over a minute to update meta info and failed. Giving up")
+ (debug:print 0 *default-log-port* "EXCEPTION: database probably overloaded or unreadable.")
+ (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
+ (debug:print 5 *default-log-port* "exn=" (condition->list exn))
+ (debug:print 0 *default-log-port* " status: " ((condition-property-accessor 'sqlite3 'status) exn))
+ (print-call-chain (current-error-port))))
+ (tests:update-testdat-meta-info db test-id work-area cpuload diskfree minutes)
+ )))
+
+;;======================================================================
+;; A R C H I V I N G
+;;======================================================================
+
+(define (test:archive db test-id)
+ #f)
+
+(define (test:archive-tests db keynames target)
+ #f)
+
ADDED attic_modular/transport.import.scm
Index: attic_modular/transport.import.scm
==================================================================
--- /dev/null
+++ attic_modular/transport.import.scm
@@ -0,0 +1,47 @@
+;;;; transport.import.scm - GENERATED BY CHICKEN 4.13.0 -*- Scheme -*-
+
+(eval '(import
+ scheme
+ chicken
+ data-structures
+ extras
+ ports
+ commonmod
+ debugprint
+ configfmod
+ apimod
+ portlogger
+ servermod
+ (prefix base64 base64:)
+ (prefix sqlite3 sqlite3:)
+ call-with-environment-variables
+ csv
+ csv-xml
+ directory-utils
+ files
+ hostinfo
+ http-client
+ intarweb
+ matchable
+ md5
+ message-digest
+ posix
+ posix-extras
+ regex
+ regex-case
+ s11n
+ spiffy
+ spiffy-directory-listing
+ spiffy-request-vars
+ srfi-1
+ srfi-13
+ srfi-18
+ srfi-69
+ stack
+ tcp
+ typed-records
+ uri-common
+ z3))
+(##sys#register-compiled-module 'transport (list) '() (list) (list))
+
+;; END OF FILE
ADDED attic_modular/transport.scm
Index: attic_modular/transport.scm
==================================================================
--- /dev/null
+++ attic_modular/transport.scm
@@ -0,0 +1,75 @@
+;;======================================================================
+;; Copyright 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 .
+
+;;======================================================================
+
+(declare (unit transport))
+(declare (uses commonmod))
+(declare (uses debugprint))
+(declare (uses configfmod))
+(declare (uses portlogger))
+(declare (uses apimod))
+(declare (uses servermod))
+
+(module transport
+ *
+
+(import scheme chicken data-structures extras ports)
+
+(import commonmod)
+(import debugprint)
+(import configfmod)
+(import apimod)
+(import portlogger)
+(import servermod)
+
+(import
+ (prefix base64 base64:)
+ (prefix sqlite3 sqlite3:)
+ call-with-environment-variables
+ csv
+ csv-xml
+ directory-utils
+ files
+ hostinfo
+ http-client
+ intarweb
+ matchable
+ md5
+ message-digest
+ posix
+ posix-extras
+ regex
+ regex-case
+ s11n
+ spiffy
+ spiffy-directory-listing
+ spiffy-request-vars
+ srfi-1
+ srfi-13
+ srfi-18
+ srfi-69
+ stack
+ tcp
+ typed-records
+ uri-common
+ z3
+ )
+
+
+)
ADDED attic_modular/tree.scm
Index: attic_modular/tree.scm
==================================================================
--- /dev/null
+++ attic_modular/tree.scm
@@ -0,0 +1,52 @@
+;;======================================================================
+;; Copyright 2006-2013, 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 .
+;;
+;;======================================================================
+
+(use format)
+(require-library iup)
+(import (prefix iup iup:))
+(use canvas-draw)
+
+(use sqlite3 srfi-1 posix regex regex-case srfi-69)
+(import (prefix sqlite3 sqlite3:))
+
+(declare (unit tree))
+(declare (uses margsmod))
+(declare (uses launch))
+;; (declare (uses megatest-version))
+(declare (uses gutils))
+(declare (uses db))
+(declare (uses server))
+;; (declare (uses synchash))
+(declare (uses dcommon))
+
+(declare (uses commonmod))
+(declare (uses debugprint))
+(import commonmod)
+(import debugprint)
+
+(declare (uses dbmod))
+(import dbmod)
+
+
+(include "megatest-version.scm")
+(include "common_records.scm")
+(include "db_records.scm")
+(include "key_records.scm")
+
ADDED attic_modular/ulex.scm
Index: attic_modular/ulex.scm
==================================================================
--- /dev/null
+++ attic_modular/ulex.scm
@@ -0,0 +1,24 @@
+;;======================================================================
+;; Copyright 2019, 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 .
+
+;;======================================================================
+
+(declare (unit ulex))
+(declare (uses pkts))
+
+(include "ulex/ulex.scm")
ADDED attic_modular/vg-test.scm
Index: attic_modular/vg-test.scm
==================================================================
--- /dev/null
+++ attic_modular/vg-test.scm
@@ -0,0 +1,119 @@
+;; 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 .
+;;
+(use canvas-draw iup foof-loop)
+(import canvas-draw-iup)
+
+(load "vg.scm")
+
+(define numtorun 1000)
+;; (if (> (length (argv)) 1)
+;; (string->number (cadr (argv)))
+;; 1000))
+
+ (use trace)
+ ;; (trace
+ ;; ;; vg:draw-rect
+ ;; ;; vg:grow-rect
+ ;; vg:get-extents-for-objs
+ ;; vg:components-get-extents
+ ;; vg:instances-get-extents
+ ;; vg:get-extents-for-two-rects
+ ;; canvas-line!)
+
+(define d1 (vg:drawing-new))
+(define l1 (vg:lib-new))
+(define c1 (vg:comp-new))
+(define c2 (vg:comp-new))
+(define bt1 (vg:make-rect-obj 10 40 20 50 text: "A long piece of text" font: "Helvetica, -10"))
+
+(let ((r1 (vg:make-rect-obj 20 20 30 30 text: "r1" font: "Helvetica, -20"))
+ (r2 (vg:make-rect-obj 30 30 60 60 text: "r2" font: "Helvetica, -10"))
+ (t1 (vg:make-text-obj 60 60 "The middle" font: "Helvetica, -10")))
+ (vg:add-objs-to-comp c1 r1 r2 t1 bt1))
+
+(loop ((for x (up-from 0 (to 20))))
+ (loop ((for y (up-from 0 (to 20))))
+ (vg:add-objs-to-comp c1 (vg:make-rect-obj x y (+ x 5)(+ y 5)))))
+
+(let ((start (current-seconds)))
+ (let loop ((i 0))
+ (vg:add-obj-to-comp c1 (vg:make-rect-obj 0 0 100 100))
+ (if (< i numtorun)(loop (+ i 1))))
+ (print "Run time: " (- (current-seconds) start)))
+
+(vg:add-obj-to-comp c1 (vg:make-line-obj 0 0 100 100))
+
+;; add the c1 component to lib l1 with name firstcomp
+(vg:add-comp-to-lib l1 "firstcomp" c1)
+(vg:add-comp-to-lib l1 "secondcomp" c2)
+
+;; add the l1 lib to drawing with name firstlib
+(vg:add-lib d1 "firstlib" l1)
+
+;; instantiate firstlib/firstcomp as inst1 in drawing d1 at 0,0
+(vg:instantiate d1 "firstlib" "firstcomp" "inst1" 0 0)
+(vg:instantiate d1 "firstlib" "firstcomp" "inst2" 200 200)
+
+
+;; (vg:drawing-scalex-set! d1 1.1)
+;; (vg:drawing-scaley-set! d1 0.5)
+
+;; (define xtnts (vg:scale-offset-xy
+;; (vg:component-get-extents c1)
+;; 1.1 1.1 -2 -2))
+
+;; get extents of c1 and put a rectange around it
+;;
+(define xtnts (apply vg:grow-rect 10 10 (vg:components-get-extents d1 c1)))
+(vg:add-objs-to-comp c1 (apply vg:make-rect-obj xtnts))
+
+(define bt1xt (vg:obj-get-extents d1 bt1))
+(print "bt1xt: " bt1xt)
+(vg:add-objs-to-comp c1 (apply vg:make-rect-obj bt1xt))
+
+;; get extents of all objects and put rectangle around it
+;;
+(define big-xtnts (vg:instances-get-extents d1))
+(vg:add-objs-to-comp c2 (apply vg:make-rect-obj big-xtnts))
+(vg:instantiate d1 "firstlib" "secondcomp" "inst3" 0 0)
+
+(vg:drawing-scalex-set! d1 1.5)
+(vg:drawing-scaley-set! d1 1.5)
+
+(define cnv #f)
+(define the-cnv (canvas
+ #:size "500x400"
+ #:expand "YES"
+ #:scrollbar "YES"
+ #:posx "0.5"
+ #:posy "0.5"
+ #:action (make-canvas-action
+ (lambda (c xadj yadj)
+ (set! cnv c)))))
+
+(show
+ (dialog
+ (vbox
+ the-cnv)))
+
+(vg:drawing-cnv-set! d1 cnv)
+(vg:draw d1 #t)
+
+;; (canvas-rectangle! cnv 10 100 10 80)
+
+(main-loop)
ADDED attic_modular/vg.scm
Index: attic_modular/vg.scm
==================================================================
--- /dev/null
+++ attic_modular/vg.scm
@@ -0,0 +1,666 @@
+;;
+;; Copyright 2016 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 .
+
+;; strftime('%m/%d/%Y %H:%M:%S','now','localtime')
+
+(use typed-records srfi-1)
+
+(declare (unit vg))
+(use canvas-draw iup)
+(import canvas-draw-iup)
+
+(include "vg_records.scm")
+
+;; ;; structs
+;; ;;
+;; (defstruct vg:lib comps)
+;; (defstruct vg:comp objs name file)
+;; ;; extents caches extents calculated on draw
+;; ;; proc is called on draw and takes the obj itself as a parameter
+;; ;; attrib is an alist of parameters
+;; (defstruct vg:obj type pts fill-color text line-color call-back angle font attrib extents proc)
+;; (defstruct vg:inst libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache)
+;; (defstruct vg:drawing libs insts scalex scaley xoff yoff cnv cache) ;; libs: hash of name->lib, insts: hash of instname->inst
+
+;; inits
+;;
+(define (vg:comp-new)
+ (make-vg:comp objs: '() name: #f file: #f))
+
+(define (vg:lib-new)
+ (make-vg:lib comps: (make-hash-table)))
+
+(define (vg:drawing-new)
+ (make-vg:drawing scalex: 1
+ scaley: 1
+ xoff: 0
+ yoff: 0
+ libs: (make-hash-table)
+ insts: (make-hash-table)
+ cache: '()))
+
+;;======================================================================
+;; scaling and offsets
+;;======================================================================
+
+(define-inline (vg:scale-offset val s o)
+ (+ o (* val s)))
+ ;; (* (+ o val) s))
+
+;; apply scale and offset to a list of x y values
+;;
+(define (vg:scale-offset-xy lstxy sx sy ox oy)
+ (if (> (length lstxy) 1) ;; have at least one xy pair
+ (let loop ((x (car lstxy))
+ (y (cadr lstxy))
+ (tal (cddr lstxy))
+ (res '()))
+ (let ((newres (cons (vg:scale-offset y sy oy)
+ (cons (vg:scale-offset x sx ox)
+ res))))
+ (if (> (length tal) 1)
+ (loop (car tal)(cadr tal)(cddr tal) newres)
+ (reverse newres))))
+ '()))
+
+;; apply drawing offset and scaling to the points in lstxy
+;;
+(define (vg:drawing-apply-scale drawing lstxy)
+ (vg:scale-offset-xy
+ lstxy
+ (vg:drawing-scalex drawing)
+ (vg:drawing-scaley drawing)
+ (vg:drawing-xoff drawing)
+ (vg:drawing-yoff drawing)))
+
+;; apply instance offset and scaling to the points in lstxy
+;;
+(define (vg:inst-apply-scale inst lstxy)
+ (vg:scale-offset-xy
+ lstxy
+ (vg:inst-scalex inst)
+ (vg:inst-scaley inst)
+ (vg:inst-xoff inst)
+ (vg:inst-yoff inst)))
+
+;; apply both drawing and instance scaling to a list of xy points
+;;
+(define (vg:drawing-inst-apply-scale-offset drawing inst lstxy)
+ (vg:drawing-apply-scale
+ drawing
+ (vg:inst-apply-scale inst lstxy)))
+
+;;======================================================================
+;; objects
+;;======================================================================
+
+;; (vg:inst-apply-scale
+;; inst
+;; (vg:drawing-apply-scale drawing lstxy)))
+
+;; make a rectangle obj
+;;
+(define (vg:make-rect-obj x1 y1 x2 y2 #!key (line-color #f)(fill-color #f)(text #f)(font #f)(extents #f))
+ (make-vg:obj type: 'r pts: (list x1 y1 x2 y2) text: text font: font line-color: line-color fill-color: fill-color extents: extents))
+
+;; make a rectangle obj
+;;
+(define (vg:make-line-obj x1 y1 x2 y2 #!key (line-color #f)(fill-color #f)(text #f)(font #f)(extents #f))
+ (make-vg:obj type: 'l pts: (list x1 y1 x2 y2) text: text font: font line-color: line-color extents: extents))
+
+;; make a text obj
+;;
+(define (vg:make-text-obj x1 y1 text #!key (line-color #f)(fill-color #f)
+ (angle #f)(scale-with-zoom #f)(font #f)
+ (font-size #f))
+ (make-vg:obj type: 't pts: (list x1 y1) text: text
+ line-color: line-color fill-color: fill-color
+ angle: angle font: font extents: #f
+ attributes: (vg:make-attrib 'font-size font-size)))
+
+;; proc takes startnum and endnum and yields scalef, per-grad and unitname
+;;
+(define (vg:make-xaxis-obj x1 y1 x2 y2 #!key (line-color #f)(fill-color #f)(text #f)(font #f)(proc #f))
+ (make-vg:obj type: 'x pts: (list x1 y1 x2 y2) text: text font: font line-color: line-color fill-color: fill-color extents: #f proc: proc))
+
+;;======================================================================
+;; obj modifiers and queries
+;;======================================================================
+
+;; get extents, use knowledge of type ...
+;;
+(define (vg:obj-get-extents drawing obj)
+ (let ((type (vg:obj-type obj)))
+ (case type
+ ((l)(vg:rect-get-extents obj))
+ ((r)(vg:rect-get-extents obj))
+ ((t)(vg:draw-text drawing obj draw: #f))
+ (else #f))))
+
+(define (vg:rect-get-extents obj)
+ (vg:obj-pts obj)) ;; extents are just the points for a rectangle
+
+(define (vg:grow-rect borderx bordery x1 y1 x2 y2)
+ (list
+ (- x1 borderx)
+ (- y1 bordery)
+ (+ x2 borderx)
+ (+ y2 bordery)))
+
+(define (vg:make-attrib . attrib-list)
+ #f)
+
+;;======================================================================
+;; components
+;;======================================================================
+
+;; add obj to comp
+;;
+(define (vg:add-objs-to-comp comp . objs)
+ (vg:comp-objs-set! comp (append (vg:comp-objs comp) objs)))
+
+(define (vg:add-obj-to-comp comp obj)
+ (vg:comp-objs-set! comp (cons obj (vg:comp-objs comp))))
+
+;; use the struct. leave this here to remind of this!
+;;
+;; (define (vg:comp-get-objs comp)
+;; (vg:comp-objs comp))
+
+;; add comp to lib
+;;
+(define (vg:add-comp-to-lib lib compname comp)
+ (hash-table-set! (vg:lib-comps lib) compname comp))
+
+;; instanciate component in drawing
+;;
+(define (vg:instantiate drawing libname compname instname xoff yoff #!key (theta 0)(scalex 1)(scaley 1)(mirrx #f)(mirry #f))
+ (let ((inst (make-vg:inst libname: libname compname: compname xoff: xoff yoff: yoff theta: theta scalex: scalex scaley: scaley mirrx: mirrx mirry: mirry)) )
+ (hash-table-set! (vg:drawing-insts drawing) instname inst)))
+
+(define (vg:instance-move drawing instname newx newy)
+ (let ((inst (hash-table-ref (vg:drawing-insts drawing) instname)))
+ (vg:inst-xoff-set! inst newx)
+ (vg:inst-yoff-set! inst newy)))
+
+;; get component from drawing (look in apropriate lib) given libname and compname
+(define (vg:get-component drawing libname compname)
+ (let* ((lib (hash-table-ref (vg:drawing-libs drawing) libname))
+ (inst (hash-table-ref (vg:lib-comps lib) compname)))
+ inst))
+
+(define (vg:get-extents-for-objs drawing objs)
+ (if (or (not objs)
+ (null? objs))
+ #f
+ (let loop ((hed (car objs))
+ (tal (cdr objs))
+ (extents (vg:obj-get-extents drawing (car objs))))
+ (let ((newextents
+ (vg:get-extents-for-two-rects
+ extents
+ (vg:obj-get-extents drawing hed))))
+ (if (null? tal)
+ extents
+ (loop (car tal)(cdr tal) newextents))))))
+
+;; (let ((extents #f))
+;; (for-each
+;; (lambda (obj)
+;; (set! extents
+;; (vg:get-extents-for-two-rects
+;; extents
+;; (vg:obj-get-extents drawing obj))))
+;; objs)
+;; extents))
+
+;; given rectangles r1 and r2, return the box that bounds both
+;;
+(define (vg:get-extents-for-two-rects r1 r2)
+ (if (not r1)
+ r2
+ (if (not r2)
+ r1 ;; #f ;; no extents from #f #f
+ (list (min (car r1)(car r2)) ;; llx
+ (min (cadr r1)(cadr r2)) ;; lly
+ (max (caddr r1)(caddr r2)) ;; ulx
+ (max (cadddr r1)(cadddr r2)))))) ;; uly
+
+(define (vg:components-get-extents drawing . comps)
+ (if (null? comps)
+ #f
+ (let loop ((hed (car comps))
+ (tal (cdr comps))
+ (extents #f))
+ (let* ((objs (vg:comp-objs hed))
+ (newextents (if extents
+ (vg:get-extents-for-two-rects
+ extents
+ (vg:get-extents-for-objs drawing objs))
+ (vg:get-extents-for-objs drawing objs))))
+ (if (null? tal)
+ newextents
+ (loop (car tal)(cdr tal) newextents))))))
+
+;;======================================================================
+;; libraries
+;;======================================================================
+
+;; register lib with drawing
+
+;;
+(define (vg:add-lib drawing libname lib)
+ (hash-table-set! (vg:drawing-libs drawing) libname lib))
+
+(define (vg:get-lib drawing libname)
+ (hash-table-ref/default (vg:drawing-libs drawing) libname #f))
+
+(define (vg:get/create-lib drawing libname)
+ (let ((lib (vg:get-lib drawing libname)))
+ (if lib
+ lib
+ (let ((newlib (vg:lib-new)))
+ (vg:add-lib drawing libname newlib)
+ newlib))))
+
+;;======================================================================
+;; map objects given offset, scale and mirror, resulting obj is displayed
+;;======================================================================
+
+;; dispatch the drawing of obj off to the correct drawing routine
+;;
+(define (vg:map-obj drawing inst obj)
+ (case (vg:obj-type obj)
+ ((l)(vg:map-line drawing inst obj))
+ ((r)(vg:map-rect drawing inst obj))
+ ((t)(vg:map-text drawing inst obj))
+ ((x)(vg:map-xaxis drawing inst obj))
+ (else #f)))
+
+;; given a drawing and a inst map a rectangle to it screen coordinates
+;;
+(define (vg:map-rect drawing inst obj)
+ (let ((res (make-vg:obj type: 'r ;; is there a defstruct copy?
+ fill-color: (vg:obj-fill-color obj)
+ text: (vg:obj-text obj)
+ line-color: (vg:obj-line-color obj)
+ font: (vg:obj-font obj)))
+ (pts (vg:obj-pts obj)))
+ (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
+ (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) ))
+ res))
+
+;; given a drawing and a inst map a line to it screen coordinates
+;;
+(define (vg:map-line drawing inst obj)
+ (let ((res (make-vg:obj type: 'l ;; is there a defstruct copy?
+ line-color: (vg:obj-line-color obj)
+ font: (vg:obj-font obj)))
+ (pts (vg:obj-pts obj)))
+ (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
+ (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) ))
+ res))
+
+;; given a drawing and a inst map a text to it screen coordinates
+;;
+(define (vg:map-text drawing inst obj)
+ (let ((res (make-vg:obj type: 't
+ fill-color: (vg:obj-fill-color obj)
+ text: (vg:obj-text obj)
+ line-color: (vg:obj-line-color obj)
+ font: (vg:obj-font obj)
+ angle: (vg:obj-angle obj)
+ attrib: (vg:obj-attrib obj)))
+ (pts (vg:obj-pts obj)))
+ (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
+ (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing)))
+ res))
+
+;; given a drawing and a inst map a line to it screen coordinates
+;;
+(define (vg:map-xaxis drawing inst obj)
+ (let ((res (make-vg:obj type: 'x ;; is there a defstruct copy?
+ line-color: (vg:obj-line-color obj)
+ font: (vg:obj-font obj)))
+ (pts (vg:obj-pts obj)))
+ (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
+ (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) ))
+ res))
+
+;;======================================================================
+;; instances
+;;======================================================================
+
+(define (vg:instances-get-extents drawing . instance-names)
+ (let ((xtnt-lst (vg:draw drawing #f)))
+ (if (null? xtnt-lst)
+ #f
+ (let loop ((extents (car xtnt-lst))
+ (tal (cdr xtnt-lst))
+ (llx #f)
+ (lly #f)
+ (ulx #f)
+ (uly #f))
+ (let ((nllx (if llx (min llx (list-ref extents 0))(list-ref extents 0)))
+ (nlly (if lly (min lly (list-ref extents 1))(list-ref extents 1)))
+ (nulx (if ulx (max ulx (list-ref extents 2))(list-ref extents 2)))
+ (nuly (if uly (max uly (list-ref extents 3))(list-ref extents 3))))
+ (if (null? tal)
+ (list llx lly ulx uly)
+ (loop (car tal)(cdr tal) nllx nlly nulx nuly)))))))
+
+(define (vg:lib-get-component lib instname)
+ (hash-table-ref/default (vg:lib-comps lib) instname #f))
+
+;;======================================================================
+;; color
+;;======================================================================
+
+(define (vg:rgb->number r g b #!key (a 0))
+ (bitwise-ior
+ (arithmetic-shift a 24)
+ (arithmetic-shift r 16)
+ (arithmetic-shift g 8)
+ b))
+
+;; Obsolete function
+;;
+(define (vg:generate-color)
+ (vg:rgb->number (random 255)
+ (random 255)
+ (random 255)))
+
+;; Need to return a string of random iup-color for graph
+;;
+(define (vg:generate-color-rgb)
+ (conc (number->string (random 255)) " "
+ (number->string (random 255)) " "
+ (number->string (random 255))))
+
+(define (vg:iup-color->number iup-color)
+ (apply vg:rgb->number (map string->number (string-split iup-color))))
+
+;;======================================================================
+;; graphing
+;;======================================================================
+
+(define (vg:make-xaxis drawing component x1 y1 x2 y2 startnum endnum scaleproc)
+ (let ((obj (vg:make-xaxis-obj x1 y1 x2 y2)))
+ #f))
+
+;;======================================================================
+;; Unravel and draw the objects
+;;======================================================================
+
+;; with get-extents = #t return the extents
+;; with draw = #f don't actually draw the object
+;;
+(define (vg:draw-obj drawing obj #!key (draw #t))
+ ;; (print "obj type: " (vg:obj-type obj))
+ (case (vg:obj-type obj)
+ ((l)(vg:draw-line drawing obj draw: draw))
+ ((r)(vg:draw-rect drawing obj draw: draw))
+ ((t)(vg:draw-text drawing obj draw: draw))))
+
+;; given a rect obj draw it on the canvas applying first the drawing
+;; scale and offset
+;;
+(define (vg:draw-rect drawing obj #!key (draw #t))
+ (let* ((cnv (vg:drawing-cnv drawing))
+ (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
+ (fill-color (vg:obj-fill-color obj))
+ (line-color (vg:obj-line-color obj))
+ (text (vg:obj-text obj))
+ (font (vg:obj-font obj))
+ (llx (car pts))
+ (lly (cadr pts))
+ (ulx (caddr pts))
+ (uly (cadddr pts))
+ (w (- ulx llx))
+ (h (- uly lly))
+ (text-xmax #f)
+ (text-ymax #f))
+ (if draw
+ (let ((prev-background-color (canvas-background cnv))
+ (prev-foreground-color (canvas-foreground cnv)))
+ (if fill-color
+ (begin
+ (canvas-foreground-set! cnv fill-color)
+ (canvas-box! cnv llx ulx lly uly))) ;; docs are all over the place on this one.;; w h)
+ (if line-color
+ (canvas-foreground-set! cnv line-color)
+ (if fill-color
+ (canvas-foreground-set! cnv prev-foreground-color)))
+ (canvas-rectangle! cnv llx ulx lly uly)
+ (canvas-foreground-set! cnv prev-foreground-color)
+ (if text
+ (let* ((prev-font (canvas-font cnv))
+ (font-changed (and font (not (equal? font prev-font)))))
+ (if font-changed (canvas-font-set! cnv font))
+ (canvas-text! cnv (+ 2 llx)(+ 2 lly) text)
+ (if (eq? draw 'get-extents)
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (set! text-xmax xmax)(set! text-ymax ymax)))
+ (if font-changed (canvas-font-set! cnv prev-font))))))
+ ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax)
+ (if (vg:obj-extents obj)
+ (vg:obj-extents obj)
+ (if (not text)
+ pts ;; no text
+ (if (and text-xmax text-ymax) ;; have text
+ (let ((xt (list llx lly
+ (max ulx (+ llx text-xmax))
+ (max uly (+ lly text-ymax)))))
+ (vg:obj-extents-set! obj xt)
+ xt)
+ (if cnv
+ (if (eq? draw 'get-extents)
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (let ((xt (list llx lly
+ (max ulx (+ llx xmax))
+ (max uly (+ lly ymax)))))
+ (vg:obj-extents-set! obj xt)
+ xt))
+ pts)
+ pts)))))) ;; return extents
+
+;; given a rect obj draw it on the canvas applying first the drawing
+;; scale and offset
+;;
+(define (vg:draw-line drawing obj #!key (draw #t))
+ (let* ((cnv (vg:drawing-cnv drawing))
+ (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
+ ;; (fill-color (vg:obj-fill-color obj))
+ (line-color (vg:obj-line-color obj))
+ (text (vg:obj-text obj))
+ (font (vg:obj-font obj))
+ (llx (car pts))
+ (lly (cadr pts))
+ (ulx (caddr pts))
+ (uly (cadddr pts))
+ (w (- ulx llx))
+ (h (- uly lly))
+ (text-xmax #f)
+ (text-ymax #f))
+ (if draw
+ (let ((prev-background-color (canvas-background cnv))
+ (prev-foreground-color (canvas-foreground cnv)))
+ ;; (if fill-color
+ ;; (begin
+ ;; (canvas-foreground-set! cnv fill-color)
+ ;; (canvas-box! cnv llx ulx lly uly))) ;; docs are all over the place on this one.;; w h)
+ (if line-color
+ (canvas-foreground-set! cnv line-color))
+ ;; (if fill-color
+ ;; (canvas-foreground-set! cnv prev-foreground-color)))
+ (canvas-line! cnv llx lly ulx uly)
+ (canvas-foreground-set! cnv prev-foreground-color)
+ (if text
+ (let* ((prev-font (canvas-font cnv))
+ (font-changed (and font (not (equal? font prev-font)))))
+ (if font-changed (canvas-font-set! cnv font))
+ (canvas-text! cnv (+ 2 llx)(+ 2 lly) text)
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (set! text-xmax xmax)(set! text-ymax ymax))
+ (if font-changed (canvas-font-set! cnv prev-font))))))
+ ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax)
+ (if (vg:obj-extents obj)
+ (vg:obj-extents obj)
+ (if (not text)
+ pts
+ (if (and text-xmax text-ymax)
+ (let ((xt (list llx lly
+ (max ulx (+ llx text-xmax))
+ (max uly (+ lly text-ymax)))))
+ (vg:obj-extents-set! obj xt)
+ xt)
+ (if cnv
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (let ((xt (list llx lly
+ (max ulx (+ llx xmax))
+ (max uly (+ lly ymax)))))
+ (vg:obj-extents-set! obj xt)
+ xt))
+ pts)))))) ;; return extents
+
+;; given a rect obj draw it on the canvas applying first the drawing
+;; scale and offset
+;;
+(define (vg:draw-xaxis drawing obj #!key (draw #t))
+ (let* ((cnv (vg:drawing-cnv drawing))
+ (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
+ ;; (fill-color (vg:obj-fill-color obj))
+ (line-color (vg:obj-line-color obj))
+ (text (vg:obj-text obj))
+ (font (vg:obj-font obj))
+ (llx (car pts))
+ (lly (cadr pts))
+ (ulx (caddr pts))
+ (uly (cadddr pts))
+ (w (- ulx llx))
+ (h (- uly lly))
+ (text-xmax #f)
+ (text-ymax #f))
+ (if draw
+ (let ((prev-background-color (canvas-background cnv))
+ (prev-foreground-color (canvas-foreground cnv)))
+ ;; (if fill-color
+ ;; (begin
+ ;; (canvas-foreground-set! cnv fill-color)
+ ;; (canvas-box! cnv llx ulx lly uly))) ;; docs are all over the place on this one.;; w h)
+ (if line-color
+ (canvas-foreground-set! cnv line-color)
+ #;(if fill-color
+ (canvas-foreground-set! cnv prev-foreground-color)))
+ (canvas-line! cnv llx ulx lly uly)
+ (canvas-foreground-set! cnv prev-foreground-color)
+ (if text
+ (let* ((prev-font (canvas-font cnv))
+ (font-changed (and font (not (equal? font prev-font)))))
+ (if font-changed (canvas-font-set! cnv font))
+ (canvas-text! cnv (+ 2 llx)(+ 2 lly) text)
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (set! text-xmax xmax)(set! text-ymax ymax))
+ (if font-changed (canvas-font-set! cnv prev-font))))))
+ ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax)
+ (if (vg:obj-extents obj)
+ (vg:obj-extents obj)
+ (if (not text)
+ pts
+ (if (and text-xmax text-ymax)
+ (let ((xt (list llx lly
+ (max ulx (+ llx text-xmax))
+ (max uly (+ lly text-ymax)))))
+ (vg:obj-extents-set! obj xt)
+ xt)
+ (if cnv
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (let ((xt (list llx lly
+ (max ulx (+ llx xmax))
+ (max uly (+ lly ymax)))))
+ (vg:obj-extents-set! obj xt)
+ xt))
+ pts)))))) ;; return extents
+
+;; given a rect obj draw it on the canvas applying first the drawing
+;; scale and offset
+;;
+(define (vg:draw-text drawing obj #!key (draw #t))
+ (let* ((cnv (vg:drawing-cnv drawing))
+ (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
+ (text (vg:obj-text obj))
+ (font (vg:obj-font obj))
+ (fill-color (vg:obj-fill-color obj))
+ (line-color (vg:obj-line-color obj))
+ (llx (car pts))
+ (lly (cadr pts)))
+ (if draw
+ (let* ((prev-background-color (canvas-background cnv))
+ (prev-foreground-color (canvas-foreground cnv))
+ (prev-font (canvas-font cnv))
+ (font-changed (and font (not (equal? font prev-font)))))
+ (if line-color
+ (canvas-foreground-set! cnv line-color)
+ (if fill-color
+ (canvas-foreground-set! cnv prev-foreground-color)))
+ (if font-changed (canvas-font-set! cnv font))
+ (canvas-text! cnv llx lly text)
+ ;; NOTE: we do not set the font back!!
+ (canvas-foreground-set! cnv prev-foreground-color)))
+ (if cnv
+ (if (eq? draw 'get-extents)
+ (let-values (((xmax ymax)(canvas-text-size cnv text)))
+ (append pts (list (+ llx xmax)(+ lly ymax)))) ;; will be wrong if text is rotated?
+ (append pts pts))
+ (append pts pts))))
+
+(define (vg:draw-inst drawing inst #!key (draw-mode #t)(prev-extents '()))
+ (let* ((libname (vg:inst-libname inst))
+ (compname (vg:inst-compname inst))
+ (comp (vg:get-component drawing libname compname))
+ (objs (vg:comp-objs comp)))
+ ;; (print "comp: " comp)
+ (if (null? objs)
+ prev-extents
+ (let loop ((obj (car objs))
+ (tal (cdr objs))
+ (res prev-extents))
+ (let* ((obj-xfrmd (vg:map-obj drawing inst obj))
+ (newres (cons (vg:draw-obj drawing obj-xfrmd draw: draw-mode) res)))
+ (if (null? tal)
+ newres
+ (loop (car tal)(cdr tal) newres)))))))
+
+(define (vg:draw drawing draw-mode . instnames)
+ (let* ((insts (vg:drawing-insts drawing))
+ (all-inst-names (hash-table-keys insts))
+ (master-list (if (null? instnames)
+ all-inst-names
+ instnames)))
+ (if (null? master-list)
+ '()
+ (let loop ((instname (car master-list))
+ (tal (cdr master-list))
+ (res '()))
+ (let* ((inst (hash-table-ref/default insts instname #f))
+ (newres (if inst
+ (vg:draw-inst drawing inst draw-mode: draw-mode prev-extents: res)
+ res)))
+ (if (null? tal)
+ newres
+ (loop (car tal)(cdr tal) newres)))))))
ADDED attic_modular/vg_records.scm
Index: attic_modular/vg_records.scm
==================================================================
--- /dev/null
+++ attic_modular/vg_records.scm
@@ -0,0 +1,171 @@
+;; Created by records.sh. DO NOT EDIT THIS FILE. Edit records.sh instead
+;; Generated using make-vector-record -safe vg lib comps
+
+;; 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 .
+;;
+
+(use simple-exceptions)
+(define vg:lib-exn (make-exception "wrong record type, expected vg:lib." 'assert))
+(define (pmake-vg:lib . params)(let ((v (if (null? params)(make-vector 2)(apply vector 'vg:lib params)))) v))
+(define (make-vg:lib #!key
+ (comps #f)
+ )
+ (vector 'vg:lib comps))
+
+(define-inline (vg:lib-comps vec)(if (eq? (vector-ref vec 0) 'vg:lib)(vector-ref vec 1)(raise (vg:lib-exn 'vg:lib-comps 'xpr))))
+
+(define-inline (vg:lib-comps-set! vec val)(if (eq? (vector-ref vec 0) 'vg:lib)(vector-set! vec 1 val)(raise (vg:lib-exn 'comps))))
+;; Generated using make-vector-record -safe vg comp objs name file
+
+(use simple-exceptions)
+(define vg:comp-exn (make-exception "wrong record type, expected vg:comp." 'assert))
+(define (pmake-vg:comp . params)(let ((v (if (null? params)(make-vector 4)(apply vector 'vg:comp params)))) v))
+(define (make-vg:comp #!key
+ (objs #f)
+ (name #f)
+ (file #f)
+ )
+ (vector 'vg:comp objs name file))
+
+(define-inline (vg:comp-objs vec)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-ref vec 1)(raise (vg:comp-exn 'vg:comp-objs 'xpr))))
+(define-inline (vg:comp-name vec)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-ref vec 2)(raise (vg:comp-exn 'vg:comp-name 'xpr))))
+(define-inline (vg:comp-file vec)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-ref vec 3)(raise (vg:comp-exn 'vg:comp-file 'xpr))))
+
+(define-inline (vg:comp-objs-set! vec val)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-set! vec 1 val)(raise (vg:comp-exn 'objs))))
+(define-inline (vg:comp-name-set! vec val)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-set! vec 2 val)(raise (vg:comp-exn 'name))))
+(define-inline (vg:comp-file-set! vec val)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-set! vec 3 val)(raise (vg:comp-exn 'file))))
+;; Generated using make-vector-record -safe vg obj type pts fill-color text line-color call-back angle font attrib extents proc
+
+(use simple-exceptions)
+(define vg:obj-exn (make-exception "wrong record type, expected vg:obj." 'assert))
+(define (pmake-vg:obj . params)(let ((v (if (null? params)(make-vector 12)(apply vector 'vg:obj params)))) v))
+(define (make-vg:obj #!key
+ (type #f)
+ (pts #f)
+ (fill-color #f)
+ (text #f)
+ (line-color #f)
+ (call-back #f)
+ (angle #f)
+ (font #f)
+ (attrib #f)
+ (extents #f)
+ (proc #f)
+ )
+ (vector 'vg:obj type pts fill-color text line-color call-back angle font attrib extents proc))
+
+(define-inline (vg:obj-type vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 1)(raise (vg:obj-exn 'vg:obj-type 'xpr))))
+(define-inline (vg:obj-pts vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 2)(raise (vg:obj-exn 'vg:obj-pts 'xpr))))
+(define-inline (vg:obj-fill-color vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 3)(raise (vg:obj-exn 'vg:obj-fill-color 'xpr))))
+(define-inline (vg:obj-text vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 4)(raise (vg:obj-exn 'vg:obj-text 'xpr))))
+(define-inline (vg:obj-line-color vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 5)(raise (vg:obj-exn 'vg:obj-line-color 'xpr))))
+(define-inline (vg:obj-call-back vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 6)(raise (vg:obj-exn 'vg:obj-call-back 'xpr))))
+(define-inline (vg:obj-angle vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 7)(raise (vg:obj-exn 'vg:obj-angle 'xpr))))
+(define-inline (vg:obj-font vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 8)(raise (vg:obj-exn 'vg:obj-font 'xpr))))
+(define-inline (vg:obj-attrib vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 9)(raise (vg:obj-exn 'vg:obj-attrib 'xpr))))
+(define-inline (vg:obj-extents vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 10)(raise (vg:obj-exn 'vg:obj-extents 'xpr))))
+(define-inline (vg:obj-proc vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref vec 11)(raise (vg:obj-exn 'vg:obj-proc 'xpr))))
+
+(define-inline (vg:obj-type-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 1 val)(raise (vg:obj-exn 'type))))
+(define-inline (vg:obj-pts-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 2 val)(raise (vg:obj-exn 'pts))))
+(define-inline (vg:obj-fill-color-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 3 val)(raise (vg:obj-exn 'fill-color))))
+(define-inline (vg:obj-text-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 4 val)(raise (vg:obj-exn 'text))))
+(define-inline (vg:obj-line-color-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 5 val)(raise (vg:obj-exn 'line-color))))
+(define-inline (vg:obj-call-back-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 6 val)(raise (vg:obj-exn 'call-back))))
+(define-inline (vg:obj-angle-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 7 val)(raise (vg:obj-exn 'angle))))
+(define-inline (vg:obj-font-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 8 val)(raise (vg:obj-exn 'font))))
+(define-inline (vg:obj-attrib-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 9 val)(raise (vg:obj-exn 'attrib))))
+(define-inline (vg:obj-extents-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 10 val)(raise (vg:obj-exn 'extents))))
+(define-inline (vg:obj-proc-set! vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 11 val)(raise (vg:obj-exn 'proc))))
+;; Generated using make-vector-record -safe vg inst libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache
+
+(use simple-exceptions)
+(define vg:inst-exn (make-exception "wrong record type, expected vg:inst." 'assert))
+(define (pmake-vg:inst . params)(let ((v (if (null? params)(make-vector 12)(apply vector 'vg:inst params)))) v))
+(define (make-vg:inst #!key
+ (libname #f)
+ (compname #f)
+ (theta #f)
+ (xoff #f)
+ (yoff #f)
+ (scalex #f)
+ (scaley #f)
+ (mirrx #f)
+ (mirry #f)
+ (call-back #f)
+ (cache #f)
+ )
+ (vector 'vg:inst libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache))
+
+(define-inline (vg:inst-libname vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 1)(raise (vg:inst-exn 'vg:inst-libname 'xpr))))
+(define-inline (vg:inst-compname vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 2)(raise (vg:inst-exn 'vg:inst-compname 'xpr))))
+(define-inline (vg:inst-theta vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 3)(raise (vg:inst-exn 'vg:inst-theta 'xpr))))
+(define-inline (vg:inst-xoff vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 4)(raise (vg:inst-exn 'vg:inst-xoff 'xpr))))
+(define-inline (vg:inst-yoff vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 5)(raise (vg:inst-exn 'vg:inst-yoff 'xpr))))
+(define-inline (vg:inst-scalex vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 6)(raise (vg:inst-exn 'vg:inst-scalex 'xpr))))
+(define-inline (vg:inst-scaley vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 7)(raise (vg:inst-exn 'vg:inst-scaley 'xpr))))
+(define-inline (vg:inst-mirrx vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 8)(raise (vg:inst-exn 'vg:inst-mirrx 'xpr))))
+(define-inline (vg:inst-mirry vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 9)(raise (vg:inst-exn 'vg:inst-mirry 'xpr))))
+(define-inline (vg:inst-call-back vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 10)(raise (vg:inst-exn 'vg:inst-call-back 'xpr))))
+(define-inline (vg:inst-cache vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref vec 11)(raise (vg:inst-exn 'vg:inst-cache 'xpr))))
+
+(define-inline (vg:inst-libname-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 1 val)(raise (vg:inst-exn 'libname))))
+(define-inline (vg:inst-compname-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 2 val)(raise (vg:inst-exn 'compname))))
+(define-inline (vg:inst-theta-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 3 val)(raise (vg:inst-exn 'theta))))
+(define-inline (vg:inst-xoff-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 4 val)(raise (vg:inst-exn 'xoff))))
+(define-inline (vg:inst-yoff-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 5 val)(raise (vg:inst-exn 'yoff))))
+(define-inline (vg:inst-scalex-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 6 val)(raise (vg:inst-exn 'scalex))))
+(define-inline (vg:inst-scaley-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 7 val)(raise (vg:inst-exn 'scaley))))
+(define-inline (vg:inst-mirrx-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 8 val)(raise (vg:inst-exn 'mirrx))))
+(define-inline (vg:inst-mirry-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 9 val)(raise (vg:inst-exn 'mirry))))
+(define-inline (vg:inst-call-back-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 10 val)(raise (vg:inst-exn 'call-back))))
+(define-inline (vg:inst-cache-set! vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 11 val)(raise (vg:inst-exn 'cache))))
+;; Generated using make-vector-record -safe vg drawing libs insts scalex scaley xoff yoff cnv cache
+
+(use simple-exceptions)
+(define vg:drawing-exn (make-exception "wrong record type, expected vg:drawing." 'assert))
+(define (pmake-vg:drawing . params)(let ((v (if (null? params)(make-vector 9)(apply vector 'vg:drawing params)))) v))
+(define (make-vg:drawing #!key
+ (libs #f)
+ (insts #f)
+ (scalex #f)
+ (scaley #f)
+ (xoff #f)
+ (yoff #f)
+ (cnv #f)
+ (cache #f)
+ )
+ (vector 'vg:drawing libs insts scalex scaley xoff yoff cnv cache))
+
+(define-inline (vg:drawing-libs vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 1)(raise (vg:drawing-exn 'vg:drawing-libs 'xpr))))
+(define-inline (vg:drawing-insts vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 2)(raise (vg:drawing-exn 'vg:drawing-insts 'xpr))))
+(define-inline (vg:drawing-scalex vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 3)(raise (vg:drawing-exn 'vg:drawing-scalex 'xpr))))
+(define-inline (vg:drawing-scaley vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 4)(raise (vg:drawing-exn 'vg:drawing-scaley 'xpr))))
+(define-inline (vg:drawing-xoff vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 5)(raise (vg:drawing-exn 'vg:drawing-xoff 'xpr))))
+(define-inline (vg:drawing-yoff vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 6)(raise (vg:drawing-exn 'vg:drawing-yoff 'xpr))))
+(define-inline (vg:drawing-cnv vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 7)(raise (vg:drawing-exn 'vg:drawing-cnv 'xpr))))
+(define-inline (vg:drawing-cache vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref vec 8)(raise (vg:drawing-exn 'vg:drawing-cache 'xpr))))
+
+(define-inline (vg:drawing-libs-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 1 val)(raise (vg:drawing-exn 'libs))))
+(define-inline (vg:drawing-insts-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 2 val)(raise (vg:drawing-exn 'insts))))
+(define-inline (vg:drawing-scalex-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 3 val)(raise (vg:drawing-exn 'scalex))))
+(define-inline (vg:drawing-scaley-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 4 val)(raise (vg:drawing-exn 'scaley))))
+(define-inline (vg:drawing-xoff-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 5 val)(raise (vg:drawing-exn 'xoff))))
+(define-inline (vg:drawing-yoff-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 6 val)(raise (vg:drawing-exn 'yoff))))
+(define-inline (vg:drawing-cnv-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 7 val)(raise (vg:drawing-exn 'cnv))))
+(define-inline (vg:drawing-cache-set! vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 8 val)(raise (vg:drawing-exn 'cache))))
ADDED attic_modular/widgets.scm
Index: attic_modular/widgets.scm
==================================================================
--- /dev/null
+++ attic_modular/widgets.scm
@@ -0,0 +1,206 @@
+;; 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 .
+
+(require-library srfi-4 iup)
+(import srfi-4 iup iup-pplot iup-glcanvas) ;; iup-web
+
+(define (popup dlg . args)
+ (apply show dlg #:modal? 'yes args)
+ (destroy! dlg))
+
+(define (properties ih)
+ (popup (element-properties-dialog ih))
+ 'default)
+
+(define dlg
+ (dialog
+ (vbox
+ (hbox ; headline
+ (fill)
+ (frame (label " Inspect control and dialog classes "
+ fontsize: 15))
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Dialogs" fontsize: 12)
+ (hbox
+ (button "dialog"
+ action: (lambda (self) (properties (dialog (vbox)))))
+ (button "color-dialog"
+ action: (lambda (self) (properties (color-dialog))))
+ (button "file-dialog"
+ action: (lambda (self) (properties (file-dialog))))
+ (button "font-dialog"
+ action: (lambda (self) (properties (font-dialog))))
+ (button "message-dialog"
+ action: (lambda (self) (properties (message-dialog))))
+ (fill)
+ margin: '0x0)
+ (hbox
+ (button "layout-dialog"
+ action: (lambda (self) (properties (layout-dialog))))
+ (button "element-properties-dialog"
+ action: (lambda (self)
+ (properties
+ (element-properties-dialog (create 'user)))))
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Composition widgets" fontsize: 12)
+ (hbox
+ (button "fill"
+ action: (lambda (self) (properties (fill))))
+ (button "hbox"
+ action: (lambda (self) (properties (hbox))))
+ (button "vbox"
+ action: (lambda (self) (properties (vbox))))
+ (button "zbox"
+ action: (lambda (self) (properties (zbox))))
+ (button "radio"
+ action: (lambda (self) (properties (radio (vbox)))))
+ (button "normalizer"
+ action: (lambda (self) (properties (normalizer))))
+ (button "cbox"
+ action: (lambda (self) (properties (cbox))))
+ (button "sbox"
+ action: (lambda (self) (properties (sbox (vbox)))))
+ (button "split"
+ action: (lambda (self) (properties (split (vbox) (vbox)))))
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Standard widgets" fontsize: 12)
+ (hbox
+ (button "button"
+ action: (lambda (self) (properties (button))))
+ (button "canvas"
+ action: (lambda (self) (properties (canvas))))
+ (button "frame"
+ action: (lambda (self) (properties (frame))))
+ (button "label"
+ action: (lambda (self) (properties (label))))
+ (button "listbox"
+ action: (lambda (self) (properties (listbox))))
+ (button "progress-bar"
+ action: (lambda (self) (properties (progress-bar))))
+ (button "spin"
+ action: (lambda (self) (properties (spin))))
+ (fill)
+ margin: '0x0)
+ (hbox
+ (button "tabs"
+ action: (lambda (self) (properties (tabs))))
+ (button "textbox"
+ action: (lambda (self) (properties (textbox))))
+ (button "toggle"
+ action: (lambda (self) (properties (toggle))))
+ (button "treebox"
+ action: (lambda (self) (properties (treebox))))
+ (button "valuator"
+ action: (lambda (self) (properties (valuator ""))))
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Additional widgets" fontsize: 12)
+ (hbox
+ (button "cells"
+ action: (lambda (self) (properties (cells))))
+ (button "color-bar"
+ action: (lambda (self) (properties (color-bar))))
+ (button "color-browser"
+ action: (lambda (self) (properties (color-browser))))
+ (button "dial"
+ action: (lambda (self) (properties (dial ""))))
+ (button "matrix"
+ action: (lambda (self) (properties (matrix))))
+ (fill)
+ margin: '0x0)
+ (hbox
+ (button "pplot"
+ action: (lambda (self) (properties (pplot))))
+ (button "glcanvas"
+ action: (lambda (self) (properties (glcanvas))))
+ ;; (button "web-browser"
+ ;; action: (lambda (self) (properties (web-browser))))
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Menu widgets" fontsize: 12)
+ (hbox
+ (button "menu"
+ action: (lambda (self) (properties (menu))))
+ (button "menu-item"
+ action: (lambda (self) (properties (menu-item))))
+ (button "menu-separator"
+ action: (lambda (self) (properties (menu-separator))))
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Images" fontsize: 12)
+ (hbox
+ (button "image/palette"
+ action: (lambda (self)
+ (properties
+ (image/palette 1 1 (u8vector->blob (u8vector 0))))))
+ (button "image/rgb"
+ action: (lambda (self)
+ (properties
+ (image/rgb 1 1 (u8vector->blob (u8vector 0))))))
+ (button "image/rgba"
+ action: (lambda (self)
+ (properties
+ (image/rgba 1 1 (u8vector->blob (u8vector 0))))))
+ (button "image/file"
+ action: (lambda (self)
+ (properties
+ ;; same attributes as image/palette
+ (image/palette 1 1 (u8vector->blob (u8vector 0))))))
+ ;; needs a file in current directory
+ ;(image/file "chicken.ico")))) ; ok
+ ;(image/file "chicken.png")))) ; doesn't work
+ (fill)
+ margin: '0x0)
+
+ (label "")
+ (label "Other widgets" fontsize: 12)
+ (hbox
+ (button "clipboard"
+ action: (lambda (self) (properties (clipboard))))
+ (button "timer"
+ action: (lambda (self) (properties (timer))))
+ (button "spinbox"
+ action: (lambda (self) (properties (spinbox (vbox)))))
+ (fill)
+ margin: '0x0)
+
+ (fill)
+ (button "E&xit"
+ expand: 'horizontal
+ action: (lambda (self) 'close))
+ )
+ margin: '15x15
+ title: "Iup inspector"))
+
+(show dlg)
+(main-loop)
+(exit 0)