Index: api.scm ================================================================== --- api.scm +++ api.scm @@ -13,64 +13,64 @@ (declare (uses rmt)) (declare (uses db)) ;; These are called by the server on recipt of /api calls -(define (api:execute-requests db cmd params) +(define (api:execute-requests dbstruct cmd params) (case (string->symbol cmd) ;; KEYS - ((get-key-val-pairs) (apply db:get-key-val-pairs db params)) + ((get-key-val-pairs) (apply db:get-key-val-pairs dbstruct params)) ((get-keys) (db:get-keys db)) ;; TESTS ;; json doesn't do vectors, convert to list - ((get-test-info-by-id) (apply db:get-test-info-by-id db params)) - ((test-get-rundir-from-test-id) (apply db:test-get-rundir-from-test-id db params)) - ((test-set-state-status-by-id) (apply db:test-set-state-status-by-id db params)) + ((get-test-info-by-id) (apply db:get-test-info-by-id dbstruct params)) + ((test-get-rundir-from-test-id) (apply db:test-get-rundir-from-test-id dbstruct params)) + ((test-set-state-status-by-id) (apply db:test-set-state-status-by-id dbstruct params)) ((get-count-tests-running) (db:get-count-tests-running db)) - ((get-count-tests-running-in-jobgroup) (apply db:get-count-tests-running-in-jobgroup db params)) - ((delete-test-records) (apply db:delete-test-records db params)) + ((get-count-tests-running-in-jobgroup) (apply db:get-count-tests-running-in-jobgroup dbstruct params)) + ((delete-test-records) (apply db:delete-test-records dbstruct params)) ((delete-old-deleted-test-records) (db:delete-old-deleted-test-records db)) - ((test-set-status-state) (apply db:test-set-status-state db params)) - ((get-previous-test-run-record) (apply db:get-previous-test-run-record db params)) - ((get-matching-previous-test-run-records)(apply db:get-matching-previous-test-run-records db params)) - ((db:test-get-logfile-info) (apply db:test-get-logfile-info db params)) - ((test-get-records-for-index-file (apply db:test-get-records-for-index-file db params))) - ((get-testinfo-state-status) (apply db:get-testinfo-state-status db params)) - ((test-get-paths-matching-keynames-target-new) (apply db:test-get-paths-matching-keynames-target-new db params)) - ((get-prereqs-not-met) (apply db:get-prereqs-not-met db params)) - ((roll-up-pass-fail-counts) (apply db:roll-up-pass-fail-counts db params)) - ((update-fail-pass-counts) (apply db:general-call db 'update-pass-fail-counts params)) - ((get-count-tests-running-for-run-id) (apply db:get-count-tests-running-for-run-id db params)) + ((test-set-status-state) (apply db:test-set-status-state dbstruct params)) + ((get-previous-test-run-record) (apply db:get-previous-test-run-record dbstruct params)) + ((get-matching-previous-test-run-records)(apply db:get-matching-previous-test-run-records dbstruct params)) + ((db:test-get-logfile-info) (apply db:test-get-logfile-info dbstruct params)) + ((test-get-records-for-index-file (apply db:test-get-records-for-index-file dbstruct params))) + ((get-testinfo-state-status) (apply db:get-testinfo-state-status dbstruct params)) + ((test-get-paths-matching-keynames-target-new) (apply db:test-get-paths-matching-keynames-target-new dbstruct params)) + ((get-prereqs-not-met) (apply db:get-prereqs-not-met dbstruct params)) + ((roll-up-pass-fail-counts) (apply db:roll-up-pass-fail-counts dbstruct params)) + ((update-fail-pass-counts) (apply db:general-call dbstruct 'update-pass-fail-counts params)) + ((get-count-tests-running-for-run-id) (apply db:get-count-tests-running-for-run-id dbstruct params)) ;; RUNS - ((get-run-info) (apply db:get-run-info db params)) - ((register-run) (apply db:register-run db params)) - ((set-tests-state-status) (apply db:set-tests-state-status db params)) - ((get-tests-for-run) (apply db:get-tests-for-run db params)) - ((get-test-id) (apply db:get-test-id-not-cached db params)) - ((get-tests-for-runs-mindata) (apply db:get-tests-for-runs-mindata db params)) - ((get-run-name-from-id) (apply db:get-run-name-from-id db params)) - ((delete-run) (apply db:delete-run db params)) - ((get-runs) (apply db:get-runs db params)) - ((get-runs-by-patt) (apply db:get-runs-by-patt db params)) - ((lock/unlock-run) (apply db:lock/unlock-run db params)) - ((update-run-event_time) (apply db:update-run-event_time db params)) + ((get-run-info) (apply db:get-run-info dbstruct params)) + ((register-run) (apply db:register-run dbstruct params)) + ((set-tests-state-status) (apply db:set-tests-state-status dbstruct params)) + ((get-tests-for-run) (apply db:get-tests-for-run dbstruct params)) + ((get-test-id) (apply db:get-test-id-not-cached dbstruct params)) + ((get-tests-for-runs-mindata) (apply db:get-tests-for-runs-mindata dbstruct params)) + ((get-run-name-from-id) (apply db:get-run-name-from-id dbstruct params)) + ((delete-run) (apply db:delete-run dbstruct params)) + ((get-runs) (apply db:get-runs dbstruct params)) + ((get-runs-by-patt) (apply db:get-runs-by-patt dbstruct params)) + ((lock/unlock-run) (apply db:lock/unlock-run dbstruct params)) + ((update-run-event_time) (apply db:update-run-event_time dbstruct params)) ;; STEPS - ((teststep-set-status!) (apply db:teststep-set-status! db params)) + ((teststep-set-status!) (apply db:teststep-set-status! dbstruct params)) ;; TEST DATA - ((test-data-rollup) (apply db:test-data-rollup db params)) - ((csv->test-data) (apply db:csv->test-data db params)) - ((get-steps-data) (apply db:get-steps-data db params)) + ((test-data-rollup) (apply db:test-data-rollup dbstruct params)) + ((csv->test-data) (apply db:csv->test-data dbstruct params)) + ((get-steps-data) (apply db:get-steps-data dbstruct params)) ;; MISC - ((login) (apply db:login db params)) + ((login) (apply db:login dbstruct params)) ((general-call) (let ((stmtname (car params)) (realparams (cdr params))) - (db:general-call db stmtname realparams))) + (db:general-call dbstruct stmtname realparams))) ((sync-inmem->db) (db:sync-back)) ((kill-server) (db:sync-tables (db:tbls *inmemdb*) *inmemdb* *db*) ;; (db:sync-to *inmemdb* *db*) (let ((hostname (car *runremote*)) (port (cadr *runremote*)) @@ -87,27 +87,27 @@ (process-signal pid signal/kill) (thread-start! th1)) '(#t "exit process started"))) ;; TESTMETA - ((testmeta-get-record) (apply db:testmeta-get-record db params)) - ((testmeta-add-record) (apply db:testmeta-add-record db params)) - ((testmeta-update-field) (apply db:testmeta-update-field db params)) + ((testmeta-get-record) (apply db:testmeta-get-record dbstruct params)) + ((testmeta-add-record) (apply db:testmeta-add-record dbstruct params)) + ((testmeta-update-field) (apply db:testmeta-update-field dbstruct params)) (else (list "ERROR" 0)))) ;; http-server send-response ;; api:process-request ;; db:* ;; ;; NB// Runs on the server as part of the server loop ;; -(define (api:process-request db $) ;; the $ is the request vars proc +(define (api:process-request dbstruct $) ;; the $ is the request vars proc (let* ((cmd ($ 'cmd)) (paramsj ($ 'params)) (params (db:string->obj paramsj)) ;; (rmt:json-str->dat paramsj)) - (res (api:execute-requests db cmd params))) + (res (api:execute-requests dbstruct cmd params))) ;; This can be here but needs controls to ensure it doesn't run more than every 4 seconds ;; (rmt:dat->json-str ;; (if (or (string? res) ;; (list? res) Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -1302,11 +1302,12 @@ "SELECT count(id) FROM tests WHERE state in ('LAUNCHED','NOT_STARTED','REMOTEHOSTSTART','RUNNING','KILLREQ');") res)) ;; map run-id, testname item-path to test-id (define (db:get-test-id dbstruct run-id testname item-path) - (let* ((res #f)) + (let* ((db (db:get-db dbstruct run-id)) + (res #f)) (sqlite3:for-each-row (lambda (id) ;; run-id testname state status event-time host cpuload diskfree uname rundir item-path run_duration final_logf comment ) (set! res id)) ;; (vector id run-id testname state status event-time host cpuload diskfree uname rundir item-path run_duration final_logf comment ))) (db:get-db dbstruct run-id) "SELECT id FROM tests WHERE testname=? AND item_path=?;" @@ -1316,11 +1317,12 @@ (define db:test-record-qry-selector "id,run_id,testname,state,status,event_time,host,cpuload,diskfree,uname,rundir_id,item_path,run_duration,final_logf,comment,realdir_id") ;; NOTE: Use db:test-get* to access records ;; NOTE: This needs rundir_id decoding? Decide, decode here or where used? For the moment decode where used. (define (db:get-all-tests-info-by-run-id dbstruct run-id) - (let ((res '())) + (let ((db (db:get-db dbstruct run-id)) + (res '())) (sqlite3:for-each-row (lambda (id run-id testname state status event-time host cpuload diskfree uname rundir item-path run_duration final_logf comment) ;; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (set! res (cons (vector id run-id testname state status event-time host cpuload diskfree uname rundir item-path run_duration final_logf comment) res))) @@ -1329,12 +1331,13 @@ run-id) res)) ;; Get test data using test_id (define (db:get-test-info-by-id dbstruct run-id test-id) - (let ((res #f)) - (sqlite3:for-each-row + (let ((db (db:get-db dbstruct run-id)) + (res #f)) + (sqlite3:for-each-row (lambda (id run-id testname state status event-time host cpuload diskfree uname rundir-id item-path run_duration final_logf comment realdir-id) ;; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (set! res (vector id run-id testname state status event-time host cpuload diskfree uname rundir-id item-path run_duration final_logf comment realdir-id))) (db:get-db dbstruct run-id) (conc "SELECT " db:test-record-qry-selector " FROM tests WHERE id=?;") @@ -1343,12 +1346,13 @@ ;; Use db:test-get* to access ;; Get test data using test_ids. NB// Only works within a single run!! ;; (define (db:get-test-info-by-ids dbstruct run-id test-ids) - (let ((res '())) - (sqlite3:for-each-row + (let ((db (db:get-db dbstruct run-id)) + (res '())) + (sqlite3:for-each-row (lambda (id run-id testname state status event-time host cpuload diskfree uname rundir-id item-path run_duration final_logf comment realdir-id) ;; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (set! res (cons (vector id run-id testname state status event-time host cpuload diskfree uname rundir-id item-path run_duration final_logf comment realdir-id) res))) (db:get-db dbstruct run-id) @@ -1355,21 +1359,23 @@ (conc "SELECT " db:test-record-qry-selector " FROM tests WHERE id in (" (string-intersperse (map conc test-ids) ",") ");")) res)) (define (db:get-test-info dbstruct run-id testname item-path) - (let ((res #f)) + (let ((db (db:get-db dbstruct run-id)) + (res #f)) (sqlite3:for-each-row (lambda (a . b) (set! res (apply vector a b))) (db:get-db dbstruct run-id) (conc "SELECT " db:test-record-qry-selector " FROM tests WHERE testname=? AND item_path=?;") test-name item-path) res)) (define (db:test-get-rundir-from-test-id dbstruct run-id test-id) - (let ((res #f)) + (let ((db (db:get-db dbstruct run-id)) + (res #f)) (sqlite3:for-each-row (lambda (tpath) (set! res tpath)) (db:get-db dbstruct run-id) "SELECT rundir FROM tests WHERE id=?;" @@ -1378,31 +1384,34 @@ ;;====================================================================== ;; S T E P S ;;====================================================================== -(define (db:teststep-set-status! db test-id teststep-name state-in status-in comment logfile) - (sqlite3:execute - db - "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);" - test-id teststep-name state-in status-in (current-seconds) - (sdb:qry 'getid (if comment comment "")) - (sdb:qry 'getid (if logfile logfile "")))) +(define (db:teststep-set-status! dbstruct run-id test-id teststep-name state-in status-in comment logfile) + (let ((db (db:get-db dbstruct run-id))) + (sqlite3:execute + db + "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);" + test-id teststep-name state-in status-in (current-seconds) + (sdb:qry 'getid (if comment comment "")) + (sdb:qry 'getid (if logfile logfile ""))))) ;; db-get-test-steps-for-run -(define (db:get-steps-for-test db test-id) - (let* ((res '())) +(define (db:get-steps-for-test db run-id test-id) + (let* ((db (db:get-db dbstruct run-id)) + (res '())) (sqlite3:for-each-row (lambda (id test-id stepname state status event-time logfile) (set! res (cons (vector id test-id stepname state status event-time (if (string? logfile) logfile "")) res))) db "SELECT id,test_id,stepname,state,status,event_time,logfile FROM test_steps WHERE status != 'DELETED' AND test_id=? ORDER BY id ASC;" ;; event_time DESC,id ASC; test-id) (reverse res))) -(define (db:get-steps-data db test-id) - (let ((res '())) +(define (db:get-steps-data db run-id test-id) + (let ((db (db:get-db dbstruct run-id)) + (res '())) (sqlite3:for-each-row (lambda (id test-id stepname state status event-time logfile) (set! res (cons (vector id test-id stepname state status event-time (if (string? logfile) logfile "")) res))) db "SELECT id,test_id,stepname,state,status,event_time,logfile FROM test_steps WHERE status != 'DELETED' AND test_id=? ORDER BY id ASC;" ;; event_time DESC,id ASC; @@ -1416,12 +1425,13 @@ ;; WARNING: Do NOT call this for the parent test on an iterated test ;; Roll up test_data pass/fail results ;; look at the test_data status field, ;; if all are pass (any case) and the test status is PASS or NULL or '' then set test status to PASS. ;; if one or more are fail (any case) then set test status to PASS, non "pass" or "fail" are ignored -(define (db:test-data-rollup db test-id status) - (let ((fail-count 0) +(define (db:test-data-rollup dbstruct run-id test-id status) + (let ((db (db:get-db dbstruct run-id)) + (fail-count 0) (pass-count 0)) (sqlite3:for-each-row (lambda (fcount pcount) (set! fail-count fcount) (set! pass-count pcount)) @@ -1432,13 +1442,14 @@ ;; Now rollup the counts to the central megatest.db (db:general-call db 'pass-fail-counts (list pass-count fail-count test-id)) ;; if the test is not FAIL then set status based on the fail and pass counts. (db:general-call db 'test_data-pf-rollup (list test-id test-id test-id test-id)))) -(define (db:csv->test-data db test-id csvdata) +(define (db:csv->test-data dbstruct run-id test-id csvdata) (debug:print 4 "test-id " test-id ", csvdata: " csvdata) - (let ((csvlist (csv->list (make-csv-reader + (let ((db (db:get-db dbstruct run-id)) + (csvlist (csv->list (make-csv-reader (open-input-string csvdata) '((strip-leading-whitespace? #t) (strip-trailing-whitespace? #t)) )))) ;; (csv->list csvdata))) (for-each (lambda (csvrow) @@ -1495,11 +1506,11 @@ ;; Misc. test related queries ;;====================================================================== ;; MUST BE CALLED local! ;; -(define (db:test-get-paths-matching dbstruct keynames target fnamepatt #!key (res '())) +(define (db: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 (if (args:get-arg "-testpatt")(args:get-arg "-testpatt") "%")) (statepatt (if (args:get-arg ":state") (args:get-arg ":state") "%")) (statuspatt (if (args:get-arg ":status") (args:get-arg ":status") "%")) (runname (if (args:get-arg ":runname") (args:get-arg ":runname") "%")) @@ -1515,34 +1526,10 @@ (glob (conc p "/" fnamepatt)) '())) paths-from-db)) paths-from-db))) -(define (db:test-get-paths-matching-keynames-target db keynames target res - #!key - (testpatt "%") - (statepatt "%") - (statuspatt "%") - (runname "%")) - (let* ((keystr (string-intersperse - (map (lambda (key val) - (conc "r." key " like '" val "'")) - keynames - (string-split target "/")) - " AND ")) - (testqry (tests:match->sqlqry testpatt)) - (qrystr (conc "SELECT t.rundir FROM tests AS t INNER JOIN runs AS r ON t.run_id=r.id WHERE " - keystr " AND r.runname LIKE '" runname "' AND " testqry - " AND t.state LIKE '" statepatt "' AND t.status LIKE '" statuspatt - "' ORDER BY t.event_time ASC;"))) - (sqlite3:for-each-row - (lambda (p) - (set! res (cons p res))) - db - qrystr) - res)) - (define (db:test-get-paths-matching-keynames-target-new dbstruct keynames target res testpatt statepatt statuspatt runname) (let* ((row-ids '()) (keystr (string-intersperse (map (lambda (key val) (conc key " like '" val "'"))