Megatest

Diff
Login

Differences From Artifact [c1de7ba151]:

To Artifact [367fc15066]:


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
31
32
33
34
35
36
37















































































38
39
40
41
42
43
44







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







(define dashboard:update-summary-tab #f)
(define dashboard:update-servers-table #f)

;;======================================================================
;; C O M M O N   D A T A   S T R U C T U R E
;;======================================================================
;; 
;; A single data structure for all the data used in a dashboard.
;; Share this structure between newdashboard and dashboard with the 
;; intent of converging on a single app.
;;
(define *data* (make-vector 25 #f))
(define (dboard:data-runs          vec)    (vector-ref  vec 0))
(define (dboard:data-tests         vec)    (vector-ref  vec 1))
(define (dboard:data-runs-matrix   vec)    (vector-ref  vec 2))
(define (dboard:data-tests-tree    vec)    (vector-ref  vec 3))
(define (dboard:data-run-keys      vec)    (vector-ref  vec 4))
(define (dboard:data-curr-test-ids vec)    (vector-ref  vec 5))
;; (define (dboard:data-test-details  vec)    (vector-ref  vec 6))
(define (dboard:data-path-test-ids vec)    (vector-ref  vec 7))
(define (dboard:data-updaters      vec)    (vector-ref  vec 8))
(define (dboard:data-path-run-ids  vec)    (vector-ref  vec 9))
(define (dboard:data-curr-run-id   vec)    (vector-ref  vec 10))
(define (dboard:data-runs-tree     vec)    (vector-ref  vec 11))
;; For test-patts convert #f to ""
(define (dboard:data-test-patts    vec)    
  (let ((val (vector-ref  vec 12)))(if val val "")))
(define (dboard:data-states        vec)    (vector-ref vec 13))
(define (dboard:data-statuses      vec)    (vector-ref vec 14))
(define (dboard:data-logs-textbox  vec val)(vector-ref vec 15))
(define (dboard:data-command       vec)    (vector-ref vec 16))
(define (dboard:data-command-tb    vec)    (vector-ref vec 17))
(define (dboard:data-target        vec)    (vector-ref vec 18))
(define (dboard:data-target-string vec)
  (let ((targ (dboard:data-target vec)))
    (if (list? targ)(string-intersperse targ "/") "no-target-specified")))
(define (dboard:data-run-name      vec)    (vector-ref vec 19))
(define (dboard:data-runs-listbox  vec)    (vector-ref vec 20))
(define (dboard:data-updater-for-runs vec) (vector-ref vec 21))

(defstruct d:data runs tests runs-matrix tests-tree run-keys
  curr-test-ids updaters path-run-ids curr-run-id runs-tree test-patts
  states statuses logs-textbox command command-tb target run-name
  runs-listbox)

(define (dboard:data-runs-set!          vec val)(vector-set! vec 0 val))
(define (dboard:data-tests-set!         vec val)(vector-set! vec 1 val))
(define (dboard:data-runs-matrix-set!   vec val)(vector-set! vec 2 val))
(define (dboard:data-tests-tree-set!    vec val)(vector-set! vec 3 val))
(define (dboard:data-run-keys-set!      vec val)(vector-set! vec 4 val))
(define (dboard:data-curr-test-ids-set! vec val)(vector-set! vec 5 val))
;; (define (dboard:data-test-details-set!  vec val)(vector-set! vec 6 val))
(define (dboard:data-path-test-ids-set! vec val)(vector-set! vec 7 val))
(define (dboard:data-updaters-set!      vec val)(vector-set! vec 8 val))
(define (dboard:data-path-run-ids-set!  vec val)(vector-set! vec 9 val))
(define (dboard:data-curr-run-id-set!   vec val)(vector-set! vec 10 val))
(define (dboard:data-runs-tree-set!     vec val)(vector-set! vec 11 val))
;; For test-patts convert "" to #f 
(define (dboard:data-test-patts-set!    vec val)
  (vector-set! vec 12 (if (equal? val "") #f val)))
(define (dboard:data-states-set!        vec val)(vector-set! vec 13 val))
(define (dboard:data-statuses-set!      vec val)(vector-set! vec 14 val))
(define (dboard:data-logs-textbox-set!  vec val)(vector-set! vec 15 val))
(define (dboard:data-command-set!       vec val)(vector-set! vec 16 val))
(define (dboard:data-command-tb-set!    vec val)(vector-set! vec 17 val))
(define (dboard:data-target-set!        vec val)(vector-set! vec 18 val))
(define (dboard:data-run-name-set!      vec val)(vector-set! vec 19 val))
(define (dboard:data-runs-listbox-set!  vec val)(vector-set! vec 20 val))
(define (dboard:data-updater-for-runs-set! vec val)(vector-set! vec 21 val))

(dboard:data-run-keys-set! *data* (make-hash-table))

;; List of test ids being viewed in various panels
(dboard:data-curr-test-ids-set! *data* (make-hash-table))

;; Look up test-ids by (key1 key2 ... testname [itempath])
(dboard:data-path-test-ids-set! *data* (make-hash-table))

;; Look up run-ids by ??
(dboard:data-path-run-ids-set! *data* (make-hash-table))

(define (d:data-init dat)
  (d:data-run-keys-set!      dat (make-hash-table))
  (d:data-curr-test-ids-set! dat (make-hash-table))
  (d:data-path-run-ids-set!  dat (make-hash-table))
  dat)

;;======================================================================
;; D O T F I L E
;;======================================================================

(define (dcommon:write-dotfile fname dat)
  (with-output-to-file fname
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91







-
+







  (let* (;; count and offset => #f so not used
	 ;; the synchash calls modify the "data" hash
	 (get-runs-sig    (conc (client:get-signature) " get-runs"))
	 (get-tests-sig   (conc (client:get-signature) " get-tests"))
	 (get-details-sig (conc (client:get-signature) " get-test-details"))

	 ;; test-ids to get and display are indexed on window-id in curr-test-ids hash
	 (test-ids        (hash-table-values (dboard:data-curr-test-ids *data*)))
	 (test-ids        (hash-table-values (dboard:tabdat-curr-test-ids data)))
	 ;; run-id is #f in next line to send the query to server 0
 	 (run-changes     (synchash:client-get 'db:get-runs get-runs-sig (length keypatts) data #f runname #f #f keypatts))
	 (tests-detail-changes (if (not (null? test-ids))
				   (synchash:client-get 'db:get-test-info-by-ids get-details-sig 0  data #f test-ids)
				   '()))

	 ;; Now can calculate the run-ids
204
205
206
207
208
209
210
211
212


213
214
215
216

217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
125
126
127
128
129
130
131


132
133
134
135
136

137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152







-
-
+
+



-
+







-
+







    (for-each (lambda (run-id)
		(let* ((run-record (hash-table-ref/default runs-hash run-id #f))
		       (key-vals   (map (lambda (key)(db:get-value-by-header run-record header key))
					keys))
		       (run-name   (db:get-value-by-header run-record header "runname"))
		       (col-name   (conc (string-intersperse key-vals "\n") "\n" run-name))
		       (run-path   (append key-vals (list run-name))))
		  (hash-table-set! (dboard:data-run-keys *data*) run-id run-path)
		  (iup:attribute-set! (dboard:data-runs-matrix *data*)
		  (hash-table-set! (dboard:tabdat-run-keys data) run-id run-path)
		  (iup:attribute-set! (dboard:tabdat-runs-matrix data)
				      (conc rownum ":" colnum) col-name)
		  (hash-table-set! runid-to-col run-id (list colnum run-record))
		  ;; Here we update the tests treebox and tree keys
		  (tree:add-node (dboard:data-tests-tree *data*) "Runs" (append key-vals (list run-name))
		  (tree:add-node (dboard:tabdat-tests-tree data) "Runs" (append key-vals (list run-name))
				 userdata: (conc "run-id: " run-id))
		  (set! colnum (+ colnum 1))))
	      run-ids)

    ;; Scan all tests to be displayed and organise all the test names, respecting what is in the hash table
    ;; Do this analysis in the order of the run-ids, the most recent run wins
    (for-each (lambda (run-id)
		(let* ((run-path       (hash-table-ref (dboard:data-run-keys *data*) run-id))
		(let* ((run-path       (hash-table-ref (dboard:tabdat-run-keys data) run-id))
		       (test-changes   (hash-table-ref all-test-changes run-id))
		       (new-test-dat   (car test-changes))
		       (removed-tests  (cadr test-changes))
		       (tests          (sort (map cadr (filter (lambda (testrec)
								 (eq? run-id (db:mintest-get-run_id (cadr testrec))))
							       new-test-dat))
					     (lambda (a b)
256
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
292
293
294
295
296
297

298
299
300

301
302
303
304
305
306
307
177
178
179
180
181
182
183

184
185

186
187
188
189
190
191
192

193
194
195
196
197
198
199
200

201
202
203
204
205

206
207
208
209
210

211
212
213
214
215
216
217

218
219
220

221
222
223
224
225
226
227
228







-
+

-
+






-
+







-
+




-
+




-
+






-
+


-
+







				     (itempath  (db:mintest-get-item_path test))
				     (fullname  (conc testname "/" itempath))
				     (dispname  (if (string=? itempath "") testname (conc "   " itempath)))
				     (rownum    (hash-table-ref/default testname-to-row fullname #f))
				     (test-path (append run-path (if (equal? itempath "") 
								     (list testname)
								     (list testname itempath))))
				     (tb         (dboard:data-tests-tree *data*)))
				     (tb         (dboard:tabdat-tests-tree data)))
				(print "INFONOTE: run-path: " run-path)
				(tree:add-node (dboard:data-tests-tree *data*) "Runs" 
				(tree:add-node (dboard:tabdat-tests-tree data) "Runs" 
					       test-path
					       userdata: (conc "test-id: " test-id))
				(let ((node-num (tree:find-node tb (cons "Runs" test-path)))
				      (color    (car (gutils:get-color-for-state-status state status))))
				  (debug:print 0 *default-log-port* "node-num: " node-num ", color: " color)
				  (iup:attribute-set! tb (conc "COLOR" node-num) color))
				(hash-table-set! (dboard:data-path-test-ids *data*) test-path test-id)
				(hash-table-set! (dboard:tabdat-path-test-ids data) test-path test-id)
				(if (not rownum)
				    (let ((rownums (hash-table-values testname-to-row)))
				      (set! rownum (if (null? rownums)
						       1
						       (+ 1 (apply max rownums))))
				      (hash-table-set! testname-to-row fullname rownum)
				      ;; create the label
				      (iup:attribute-set! (dboard:data-runs-matrix *data*)
				      (iup:attribute-set! (dboard:tabdat-runs-matrix data)
							  (conc rownum ":" 0) dispname)
				      ))
				;; set the cell text and color
				;; (debug:print 2 *default-log-port* "rownum:colnum=" rownum ":" colnum ", state=" status)
				(iup:attribute-set! (dboard:data-runs-matrix *data*)
				(iup:attribute-set! (dboard:tabdat-runs-matrix data)
						    (conc rownum ":" colnum)
						    (if (member state '("ARCHIVED" "COMPLETED"))
							status
							state))
				(iup:attribute-set! (dboard:data-runs-matrix *data*)
				(iup:attribute-set! (dboard:tabdat-runs-matrix data)
						    (conc "BGCOLOR" rownum ":" colnum)
						    (car (gutils:get-color-for-state-status state status)))
				))
			    tests)))
	      run-ids)

    (let ((updater (hash-table-ref/default  (dboard:data-updaters *data*) window-id #f)))
    (let ((updater (hash-table-ref/default  (dboard:commondat-updaters commondat) window-id #f)))
      (if updater (updater (hash-table-ref/default data get-details-sig #f))))

    (iup:attribute-set! (dboard:data-runs-matrix *data*) "REDRAW" "ALL")
    (iup:attribute-set! (dboard:tabdat-runs-matrix data) "REDRAW" "ALL")
    ;; (debug:print 2 *default-log-port* "run-changes: " run-changes)
    ;; (debug:print 2 *default-log-port* "test-changes: " test-changes)
    (list run-changes all-test-changes)))

;;======================================================================
;; TESTS DATA
;;======================================================================
433
434
435
436
437
438
439
440

441
442
443
444

445
446
447
448
449
450
451

452
453
454
455
456
457
458
354
355
356
357
358
359
360

361
362
363
364

365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+



-
+






-
+







    ;; (iup:attribute-set! general-matrix "2:1" *toppath*)
    ;; Megatest version
    (iup:attribute-set! general-matrix "2:0" "Version")
    (iup:attribute-set! general-matrix "2:1" (conc megatest-version "-" (substring megatest-fossil-hash 0 4)))

    general-matrix))

(define (dcommon:run-stats dbstruct)
(define (dcommon:run-stats alldat)
  (let* ((stats-matrix (iup:matrix expand: "YES"))
	 (changed      #f)
	 (updater      (lambda ()
			 (let* ((run-stats    (db:get-run-stats dbstruct))
			 (let* ((run-stats    (rmt:get-run-stats))
				(indices      (common:sparse-list-generate-index run-stats)) ;;  proc: set-cell))
				(row-indices  (car indices))
				(col-indices  (cadr indices))
				(max-row      (if (null? row-indices) 1 (apply max (map cadr row-indices))))
				(max-col      (if (null? col-indices) 1 
						  (apply max (map cadr col-indices))))
				(max-visible  (max (- (d:alldat-num-tests *alldat*) 15) 3))
				(max-visible  (max (- (dboard:tabdat-num-tests alldat) 15) 3))
				(max-col-vis  (if (> max-col 10) 10 max-col))
				(numrows      1)
				(numcols      1))
			   (iup:attribute-set! stats-matrix "CLEARVALUE" "CONTENTS")
			   (iup:attribute-set! stats-matrix "NUMCOL" max-col )
			   (iup:attribute-set! stats-matrix "NUMLIN" (if (< max-row max-visible) max-visible max-row)) ;; min of 20
			   (iup:attribute-set! stats-matrix "NUMCOL_VISIBLE" max-col-vis)
921
922
923
924
925
926
927
928

929
930
931
932
933

934
935
936
937
938
939
940
941
942
943
944
945
946
947

948
949
950
951

952
953
954
955
956
957
958
959
960
961

962
963

964
965
966
967
968
969
970

971
972
973

974
975

976
977
978
979
980
981
982
983
984
985

986
987

988
989
990
991
992
993
994
995
996
997
998
999
1000
1001


1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
842
843
844
845
846
847
848

849
850
851
852
853

854
855
856
857
858
859
860
861
862
863
864
865
866
867

868
869
870
871

872
873
874
875
876
877
878
879
880
881

882
883

884
885
886
887
888
889
890

891
892
893

894


895

896
897
898
899
900
901
902
903

904
905

906
907
908
909
910
911
912
913
914
915
916
917
918


919
920
921
922
923

924
925
926
927
928
929
930
931







-
+




-
+













-
+



-
+









-
+

-
+






-
+


-
+
-
-
+
-








-
+

-
+












-
-
+
+



-
+







      (iup:toggle "Server" #:size "40x")))
    (let ((tb (iup:textbox 
	       #:value "megatest "
	       #:expand "HORIZONTAL"
	       #:readonly "YES"
	       #:font "Courier New, -12"
	       )))
      (dboard:data-command-tb-set! data tb)
      (dboard:tabdat-command-tb-set! data tb)
      tb)
    (iup:button "Execute" #:size "50x"
		#:action (lambda (obj)
			   (let ((cmd (conc "xterm -geometry 180x20 -e \""
					    (iup:attribute (dboard:data-command-tb data) "VALUE")
					    (iup:attribute (dboard:tabdat-command-tb data) "VALUE")
					    ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
			     (system cmd)))))))

(define (dcommon:command-action-selector data)
  (iup:frame
   #:title "Set the action to take"
   (iup:hbox
    ;; (iup:label "Command to run" #:expand "HORIZONTAL" #:size "70x" #:alignment "LEFT:ACENTER")
    (let* ((cmds-list '("run" "remove-runs" "set-state-status" "lock-runs" "unlock-runs"))
	   (lb         (iup:listbox #:expand "HORIZONTAL"
				    #:dropdown "YES"
				    #:action (lambda (obj val index lbstate)
					       ;; (print obj " " val " " index " " lbstate)
					       (dboard:data-command-set! data val)
					       (dboard:tabdat-command-set! data val)
					       (dashboard:update-run-command data))))
	   (default-cmd (car cmds-list)))
      (iuplistbox-fill-list lb cmds-list selected-item: default-cmd)
      (dboard:data-command-set! data default-cmd)
      (dboard:tabdat-command-set! data default-cmd)
      lb))))

(define (dcommon:command-runname-selector alldat data)
  (iup:frame
   #:title "Runname"
   (let* ((default-run-name (seconds->work-week/day (current-seconds)))
	  (tb (iup:textbox #:expand "HORIZONTAL"
			   #:action (lambda (obj val txt)
				      ;; (print "obj: " obj " val: " val " unk: " unk)
				      (dboard:data-run-name-set! data txt) ;; (iup:attribute obj "VALUE"))
				      (dboard:tabdat-run-name-set! data txt) ;; (iup:attribute obj "VALUE"))
				      (dashboard:update-run-command data))
			   #:value (or default-run-name (dboard:data-run-name data))))
			   #:value (or default-run-name (dboard:tabdat-run-name data))))
	  (lb (iup:listbox #:expand "HORIZONTAL"
			   #:dropdown "YES"
			   #:action (lambda (obj val index lbstate)
				      (if (not (equal? val ""))
					  (begin
					    (iup:attribute-set! tb "VALUE" val)
					    (dboard:data-run-name-set! data val)
					    (dboard:tabdat-run-name-set! data val)
					    (dashboard:update-run-command data))))))
	  (refresh-runs-list (lambda ()
			       (let* ((target        (dboard:data-target-string data))
			       (let* ((target        (dboard:tabdat-target-string data))
				      (runs-for-targ (if (d:alldat-useserver alldat)
							 (rmt:get-runs-by-patt (d:alldat-keys alldat) "%" target #f #f #f)
				      (runs-for-targ (rmt:get-runs-by-patt (dboard:tabdat-keys alldat) "%" target #f #f #f))
							 (db:get-runs-by-patt (d:alldat-dblocal alldat) (d:alldat-keys alldat) "%" target #f #f #f)))
				      (runs-header   (vector-ref runs-for-targ 0))
				      (runs-dat      (vector-ref runs-for-targ 1))
				      (run-names     (cons default-run-name 
							   (map (lambda (x)
								  (db:get-value-by-header x runs-header "runname"))
								runs-dat))))
				 ;; (iup:attribute-set! lb "REMOVEITEM" "ALL")
				 (iuplistbox-fill-list lb run-names selected-item: default-run-name)))))
     (dboard:data-updater-for-runs-set! data refresh-runs-list)
     (dboard:tabdat-updater-for-runs-set! data refresh-runs-list)
     (refresh-runs-list)
     (dboard:data-run-name-set! data default-run-name)
     (dboard:tabdat-run-name-set! data default-run-name)
     (iup:hbox
      tb
      lb))))

(define (dcommon:command-testname-selector alldat data update-keyvals key-listboxes)
  (iup:frame
   #:title "SELECTORS"
   (iup:vbox
    ;; Text box for test patterns
    (iup:frame
     #:title "Test patterns (one per line)"
     (let ((tb (iup:textbox #:action (lambda (val a b)
				       (dboard:data-test-patts-set!
					*data*
				       (dboard:tabdat-test-patts-set!-use
					data
					(dboard:lines->test-patt b))
				       (dashboard:update-run-command data))
			    #:value (dboard:test-patt->lines
				     (dboard:data-test-patts *data*))
				     (dboard:tabdat-test-patts-use data))
			    #:expand "YES"
			    #:size "x50"
			    #:multiline "YES")))
       (set! test-patterns-textbox tb)
       tb))
    (iup:frame
     #:title "Target"
1021
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036

1037
1038
1039
1040
1041
1042
1043
940
941
942
943
944
945
946

947
948
949
950
951
952
953
954

955
956
957
958
959
960
961
962







-
+







-
+







     ;; Text box for STATES
     (iup:frame
      #:title "States"
      (dashboard:text-list-toggle-box 
       ;; Move these definitions to common and find the other useages and replace!
       (map cadr *common:std-states*) ;; '("COMPLETED" "RUNNING" "STUCK" "INCOMPLETE" "LAUNCHED" "REMOTEHOSTSTART" "KILLED")
       (lambda (all)
	 (dboard:data-states-set! *data* all)
	 (dboard:tabdat-states-set! data all)
	 (dashboard:update-run-command data))))
     ;; Text box for STATES
     (iup:frame
      #:title "Statuses"
      (dashboard:text-list-toggle-box 
       (map cadr *common:std-statuses*) ;; '("PASS" "FAIL" "n/a" "CHECK" "WAIVED" "SKIP" "DELETED" "STUCK/DEAD")
       (lambda (all)
	 (dboard:data-statuses-set! *data* all)
	 (dboard:tabdat-statuses-set! data all)
	 (dashboard:update-run-command data))))))))

(define (dcommon:command-tests-tasks-canvas data test-records sorted-testnames tests-draw-state)
  (iup:frame
   #:title "Tests and Tasks"
   (let* ((updater #f)
	  (last-xadj 0)
1103
1104
1105
1106
1107
1108
1109
1110

1111
1112
1113
1114
1115
1116
1117
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036







-
+







								  (newpatt-list (if selected
										    (cons test-name patterns)
										    (delete test-name patterns)))
								  (newpatt      (string-intersperse newpatt-list "\n")))
							     (iup:attribute-set! obj "REDRAW" "ALL")
							     (hash-table-set! selected-tests test-name selected)
							     (iup:attribute-set! test-patterns-textbox "VALUE" newpatt)
							     (dboard:data-test-patts-set! data (dboard:lines->test-patt newpatt))
							     (dboard:tabdat-test-patts-set!-use data (dboard:lines->test-patt newpatt))
							     (dashboard:update-run-command data)
							     (if updater (updater last-xadj last-yadj)))))))
						 (hash-table-keys tests-info)))))))
     canvas-obj)))

;;======================================================================
;;  S T E P S