Megatest

Changes On Branch 41915f799710b83b
Login

Changes In Branch cached-copy-srehman Through [41915f7997] Excluding Merge-Ins

This is equivalent to a diff from 5ff16368ff to 41915f7997

2016-10-27
23:52
Converted -list-runs to use cached db check-in: cbeea6e758 user: matt tags: cached-copy-srehman
20:55
Fixed bad call to rmt:get-runs-by-patt in megatest.scm check-in: 2e18664666 user: matt tags: v1.62
17:55
Merged in v1.62 and few minor fixes check-in: 41915f7997 user: mrwellan tags: cached-copy-srehman
16:24
added caching of specified databases (defaulted to megatest.db) check-in: 32dacffcc7 user: srehman tags: cached-copy-srehman
15:21
Run tab resize fixed check-in: 5ff16368ff user: ritikaag tags: v1.62
2016-10-26
14:21
added support for -kill-servers and -transport switches on megatest check-in: cfb9ac119d user: bjbarcla tags: v1.62

Modified db.scm from [29d75e1de6] to [320057ef6f].

202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216







-
+







;;
(define (db:lock-create-open fname initproc)
  ;; (if (file-exists? fname)
  ;;     (let ((db (sqlite3:open-database fname)))
  ;;       (sqlite3:set-busy-handler! db (make-busy-timeout 136000))
  ;;       (db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = 0;")
  ;;       db)
  (let* ((parent-dir   (pathname-directory fname))
  (let* ((parent-dir   (or (pathname-directory fname)(current-directory))) ;; no parent? go local
	 (dir-writable (file-write-access? parent-dir))
	 (file-exists  (file-exists? fname))
	 (file-write   (if file-exists
			   (file-write-access? fname)
			   dir-writable )))
    (if file-write ;; dir-writable
	(let (;; (lock    (obtain-dot-lock fname 1 5 10))
320
321
322
323
324
325
326
327
328


329
330
331
332
333
334
335
320
321
322
323
324
325
326


327
328
329
330
331
332
333
334
335







-
-
+
+







(define (db:setup run-id #!key (local #f))
  (let* ((dbdir    (db:dbfile-path #f)) ;; (conc (configf:lookup *configdat* "setup" "linktree") "/.db"))
	 (dbstruct (make-dbr:dbstruct path: dbdir local: local)))
    dbstruct))

;; Open the classic megatest.db file in toppath
;;
(define (db:open-megatest-db)
  (let* ((dbpath       (conc *toppath* "/megatest.db"))
(define (db:open-megatest-db #!key (path #f))
  (let* ((dbpath       (or path (conc *toppath* "/megatest.db")))
	 (dbexists     (file-exists? dbpath))
	 (db           (db:lock-create-open dbpath
					    (lambda (db)
					      (db:initialize-main-db db)
					      (db:initialize-run-id-db db))))
	 (write-access (file-write-access? dbpath)))
    (if (and dbexists (not write-access))
779
780
781
782
783
784
785























786
787
788
789
790
791
792
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







                              last_update INTEGER DEFAULT (strftime('%s','now')))")
  (sqlite3:execute maindb "CREATE TRIGGER  IF NOT EXISTS update_run_stats_trigger AFTER UPDATE ON run_stats
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE run_stats SET last_update=(strftime('%s','now'))
                                   WHERE id=old.id;
                               END;"))

(define (db:cache-for-read-only source target)
  (let* ((toppath   (launch:setup))
         (cache-db  (db:open-megatest-db path: target))
         (source-db (db:open-megatest-db path: source))
         (curr-time (current-seconds))
         (res      '()))
    (print source-db)
    (begin
      (if (not (file-exists? target)) 
          ((db:sync-tables (db:sync-main-list source-db) source-db cache-db)
           (db:sync-tables db:sync-tests-only source-db cache-db)
           (db:clean-up-rundb cache-db))
          ((sqlite3:for-each-row
            (lambda (id release runname state status owner event_time comment fail_count pass_count )
              (set! res (cons (id release runname state status owner event_time comment fail_count pass_count ) res)))
            (db:dbdat-get-db source-db)
            "SELECT id, release, runname, state, status, owner, event_time, comment, fail_count, pass_count FROM runs;"))
          )
      (print res)
      (sqlite3:finalize! (db:dbdat-get-db cache-db))
      ))
  )

;; options:
;;
;;  'killservers  - kills all servers
;;  'dejunk       - removes junk records
;;  'adj-testids  - move test-ids into correct ranges
;;  'old2new      - sync megatest.db records to .db/{main,1,2 ...}.db
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
840
841
842
843
844
845
846

847
848
849
850
851
852
853
854







-
+







	 servers))

    ;; clear out junk records
    ;;
    (if (member 'dejunk options)
	(begin
	  (db:delay-if-busy mtdb)
	  (db:clean-up mtdb)))
	  (db:clean-up mtdb)))	

    ;; adjust test-ids to fit into proper range
    ;;
    (if (member 'adj-testids options)
	(begin
	  (db:delay-if-busy mtdb)
	  (db:prep-megatest.db-for-migration mtdb)))

Modified megatest.scm from [7f46162c88] to [d0741b04ce].

257
258
259
260
261
262
263


264
265


266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
257
258
259
260
261
262
263
264
265


266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291







+
+
-
-
+
+
















-
+







			"-o"
			"-log"
			"-archive"
			"-since"
			"-fields"
			"-recover-test" ;; run-id,test-id - used internally to recover a test stuck in RUNNING state
			"-sort"
			"-target-db"
			"-source-db"
			) 
		 (list  "-h" "-help" "--help"
			)
 		 (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"

			"-cache-db"
			;; misc
			"-repl"
			"-lock"
			"-unlock"
			"-list-servers"
                        "-run-wait"      ;; wait on a run to complete (i.e. no RUNNING)
			"-local"         ;; run some commands using local db access
479
480
481
482
483
484
485








486
487
488
489
490
491
492
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502







+
+
+
+
+
+
+
+







    (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")
    (begin
      (set! *didsomething* #t) ;; suppress the help output.
      (if (getenv "MT_TARGET") ;; no point in trying if no target