Megatest

Diff
Login

Differences From Artifact [5c480362d7]:

To Artifact [2c62a156d9]:


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
124
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
153
154
155

156
157
158
159
160

161
162
163
164
165

166
167
168
169
170

171
172
173
174
175

176
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
229
    ;;======================================================================
    ;; db specials here
    ;;======================================================================
    ;; ** set-tests-state-status
    (rpc:publish-procedure!
     'rdb:set-tests-state-status 
     (lambda (run-id testnames currstate currstatus newstate newstatus)

       (db:set-tests-state-status db run-id testnames currstate currstatus newstate newstatus)))

    (rpc:publish-procedure!
     'rdb:teststep-set-status!
     (lambda (run-id test-name teststep-name state-in status-in item-path comment logfile)

       (db:teststep-set-status! db run-id test-name teststep-name state-in status-in item-path comment logfile)))

    (rpc:publish-procedure!
     'rdb:test-update-meta-info
     (lambda (run-id testname item-path minutes cpuload diskfree tmpfree)

       (db:test-update-meta-info db run-id testname item-path minutes cpuload diskfree tmpfree)))
     
    (rpc:publish-procedure!
     'rdb:test-set-state-status-by-run-id-testname
     (lambda (run-id test-name item-path status state)

       (db:test-set-state-status-by-run-id-testname db run-id test-name item-path status state)))

    (rpc:publish-procedure!
     'rdb:csv->test-data 
     (lambda (test-id csvdata)

       (db:csv->data db test-id csvdata)))

    (rpc:publish-procedure!
     'rdb:roll-up-pass-fail-counts
     (lambda (run-id test-name item-path status)

       (db:roll-up-pass-fail-counts db run-id test-name item-path status)))

    (rpc:publish-procedure!
     'rdb:test-set-comment 
     (lambda (run-id test-name item-path comment)

       (db:test-set-comment db run-id test-name item-path comment)))
    
    (rpc:publish-procedure!
     'rdb:test-set-log!
     (lambda (run-id test-name item-path logf)

       (db:test-set-log! db run-id test-name item-path logf)))
    
    (rpc:publish-procedure!
     'rpc:get-test-data-by-id
     (lambda (test-id)

       (db:get-test-data-by-id db test-id)))

    (rpc:publish-procedure!
     'serve:get-toppath
     (lambda ()

       *toppath*))

    (rpc:publish-procedure!
     'serve:login
     (lambda (toppath)

       (if (equal? *toppath* toppath)
	   (begin
	     (debug:print 2 "INFO: login successful")
	     #t)
	   #f)))	     
    
    (rpc:publish-procedure!
     'rdb:get-runs
     (lambda (runnamepatt numruns startrunoffset keypatts)

       (db:get-runs db runnamepatt numruns startrunoffset keypatts)))

    (rpc:publish-procedure!
     'rdb:get-tests-for-run 
     (lambda (run-id testpatt itempatt states statuses)

       (db:get-tests-for-run db run-id testpatt itempatt states statuses)))

    (rpc:publish-procedure!
     'rdb:get-keys
     (lambda ()

       (db:get-keys db)))

    (rpc:publish-procedure!
     'rdb:get-num-runs
     (lambda (runpatt)

       (db:get-num-runs db runpatt)))

    (rpc:publish-procedure!
     'rdb:test-set-state-status-by-id
     (lambda (test-id newstate newstatus newcomment)

       (db:test-set-state-status-by-id db test-id newstate newstatus newcomment)))

    (rpc:publish-procedure!
     'rdb:get-key-val-pairs
     (lambda (run-id)

       (db:get-key-val-pairs db run-id)))

    (rpc:publish-procedure!
     'rdb:get-key-vals
     (lambda (run-id)

       (db:get-key-vals db run-id)))

    (rpc:publish-procedure!
     'rdb:testmeta-get-record
     (lambda (run-id)

       (db:testmeta-get-record db run-id)))

    (rpc:publish-procedure!
     'rdb:get-test-data-by-id
     (lambda (test-id)

       (db:get-test-data-by-id db test-id)))

    (rpc:publish-procedure!
     'rdb:get-run-info
     (lambda (run-id)

       (db:get-run-info db run-id)))

    (rpc:publish-procedure!
     'rdb:get-steps-for-test
     (lambda (test-id)

       (db:get-steps-for-test db test-id)))

    (rpc:publish-procedure!
     'rdb:get-steps-table
     (lambda (test-id)

       (db:get-steps-table db test-id)))

    (rpc:publish-procedure!
     'rdb:read-test-data
     (lambda (test-id categorypatt)

       (db:read-test-data db test-id categorypatt)))

    (rpc:publish-procedure!
     'rdb:get-test-info
     (lambda (run-id testname item-path)

       (db:get-test-info db  run-id testname item-path)))

    (rpc:publish-procedure!
     'rdb:delete-test-records
     (lambda (test-id)

       (db:delete-test-records db test-id)))

    (rpc:publish-procedure!
     'rtests:register-test
     (lambda (run-id test-name item-path)

       (tests:register-test db run-id test-name item-path)))

















    (set! *rpc:listener* rpc:listener)
    (on-exit (lambda ()
	       (sqlite3:execute db "DELETE FROM metadat WHERE var='SERVER' and val=?;" host:port)
	       (sqlite3:finalize! db)))
    (thread-start! th1)
    (thread-start! th2)



    (thread-join!  th2))) ;; rpc:server)))


















(define (server:find-free-port-and-open port)
  (handle-exceptions
   exn
   (begin
     (print "Failed to bind to port " (rpc:default-server-port) ", trying next port")
     (server:find-free-port-and-open (+ port 1)))
   (rpc:default-server-port port)
   (tcp-listen (rpc:default-server-port))))

(define (server:client-setup db)
  (if *runremote*

      (debug:print 0 "ERROR: Attempt to connect to server but already connected")

      (let* ((hostinfo (db:get-var db "SERVER"))
	     (hostdat  (if hostinfo (string-split hostinfo ":")))
	     (host     (if hostinfo (car hostdat)))
	     (port     (if (and hostinfo (> (length hostdat) 1))(cadr hostdat) #f)))
	(if (and port
		 (string->number port))
	    (let ((portn (string->number port)))







>




|
>
|




>





>





>
|




>





>





>
|


|

>





>





>









>





>





>





>





>





>





>





>





>





>





>





>





>





>





>





>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>
|
>







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
124
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
    ;;======================================================================
    ;; db specials here
    ;;======================================================================
    ;; ** set-tests-state-status
    (rpc:publish-procedure!
     'rdb:set-tests-state-status 
     (lambda (run-id testnames currstate currstatus newstate newstatus)
       (set! *last-db-access* (current-seconds))
       (db:set-tests-state-status db run-id testnames currstate currstatus newstate newstatus)))

    (rpc:publish-procedure!
     'rdb:teststep-set-status!
     (lambda (test-id teststep-name state-in status-in item-path comment logfile)
       (set! *last-db-access* (current-seconds))
       (db:teststep-set-status! db test-id teststep-name state-in status-in item-path comment logfile)))

    (rpc:publish-procedure!
     'rdb:test-update-meta-info
     (lambda (run-id testname item-path minutes cpuload diskfree tmpfree)
       (set! *last-db-access* (current-seconds))
       (db:test-update-meta-info db run-id testname item-path minutes cpuload diskfree tmpfree)))
     
    (rpc:publish-procedure!
     'rdb:test-set-state-status-by-run-id-testname
     (lambda (run-id test-name item-path status state)
       (set! *last-db-access* (current-seconds))
       (db:test-set-state-status-by-run-id-testname db run-id test-name item-path status state)))

    (rpc:publish-procedure!
     'rdb:csv->test-data 
     (lambda (test-id csvdata)
       (set! *last-db-access* (current-seconds))
       (db:csv->test-data db test-id csvdata)))

    (rpc:publish-procedure!
     'rdb:roll-up-pass-fail-counts
     (lambda (run-id test-name item-path status)
       (set! *last-db-access* (current-seconds))
       (db:roll-up-pass-fail-counts db run-id test-name item-path status)))

    (rpc:publish-procedure!
     'rdb:test-set-comment 
     (lambda (run-id test-name item-path comment)
       (set! *last-db-access* (current-seconds))
       (db:test-set-comment db run-id test-name item-path comment)))
    
    (rpc:publish-procedure!
     'rdb:test-set-log!
     (lambda (run-id test-name item-path logf)
       (set! *last-db-access* (current-seconds))
       (db:test-set-log! db test-id logf)))
    
    (rpc:publish-procedure!
     'rdb:get-test-data-by-id
     (lambda (test-id)
       (set! *last-db-access* (current-seconds))
       (db:get-test-data-by-id db test-id)))

    (rpc:publish-procedure!
     'serve:get-toppath
     (lambda ()
       (set! *last-db-access* (current-seconds))
       *toppath*))

    (rpc:publish-procedure!
     'serve:login
     (lambda (toppath)
       (set! *last-db-access* (current-seconds))
       (if (equal? *toppath* toppath)
	   (begin
	     (debug:print 2 "INFO: login successful")
	     #t)
	   #f)))	     
    
    (rpc:publish-procedure!
     'rdb:get-runs
     (lambda (runnamepatt numruns startrunoffset keypatts)
       (set! *last-db-access* (current-seconds))
       (db:get-runs db runnamepatt numruns startrunoffset keypatts)))

    (rpc:publish-procedure!
     'rdb:get-tests-for-run 
     (lambda (run-id testpatt itempatt states statuses)
       (set! *last-db-access* (current-seconds))
       (db:get-tests-for-run db run-id testpatt itempatt states statuses)))

    (rpc:publish-procedure!
     'rdb:get-keys
     (lambda ()
       (set! *last-db-access* (current-seconds))
       (db:get-keys db)))

    (rpc:publish-procedure!
     'rdb:get-num-runs
     (lambda (runpatt)
       (set! *last-db-access* (current-seconds))
       (db:get-num-runs db runpatt)))

    (rpc:publish-procedure!
     'rdb:test-set-state-status-by-id
     (lambda (test-id newstate newstatus newcomment)
       (set! *last-db-access* (current-seconds))
       (db:test-set-state-status-by-id db test-id newstate newstatus newcomment)))

    (rpc:publish-procedure!
     'rdb:get-key-val-pairs
     (lambda (run-id)
       (set! *last-db-access* (current-seconds))
       (db:get-key-val-pairs db run-id)))

    (rpc:publish-procedure!
     'rdb:get-key-vals
     (lambda (run-id)
       (set! *last-db-access* (current-seconds))
       (db:get-key-vals db run-id)))

    (rpc:publish-procedure!
     'rdb:testmeta-get-record
     (lambda (run-id)
       (set! *last-db-access* (current-seconds))
       (db:testmeta-get-record db run-id)))

    (rpc:publish-procedure!
     'rdb:get-test-data-by-id
     (lambda (test-id)
       (set! *last-db-access* (current-seconds))
       (db:get-test-data-by-id db test-id)))

    (rpc:publish-procedure!
     'rdb:get-run-info
     (lambda (run-id)
       (set! *last-db-access* (current-seconds))
       (db:get-run-info db run-id)))

    (rpc:publish-procedure!
     'rdb:get-steps-for-test
     (lambda (test-id)
       (set! *last-db-access* (current-seconds))
       (db:get-steps-for-test db test-id)))

    (rpc:publish-procedure!
     'rdb:get-steps-table
     (lambda (test-id)
       (set! *last-db-access* (current-seconds))
       (db:get-steps-table db test-id)))

    (rpc:publish-procedure!
     'rdb:read-test-data
     (lambda (test-id categorypatt)
       (set! *last-db-access* (current-seconds))
       (db:read-test-data db test-id categorypatt)))

    (rpc:publish-procedure!
     'rdb:get-test-info
     (lambda (run-id testname item-path)
       (set! *last-db-access* (current-seconds))
       (db:get-test-info db  run-id testname item-path)))

    (rpc:publish-procedure!
     'rdb:delete-test-records
     (lambda (test-id)
       (set! *last-db-access* (current-seconds))
       (db:delete-test-records db test-id)))

    (rpc:publish-procedure!
     'rtests:register-test
     (lambda (run-id test-name item-path)
       (set! *last-db-access* (current-seconds))
       (tests:register-test db run-id test-name item-path)))

    (rpc:publish-procedure!
     'rdb:test-data-rollup
     (lambda (test-id status)
       (set! *last-db-access* (current-seconds))
       (db:test-data-rollup db test-id status)))
    
    (rpc:publish-procedure!
     'rtests:test-set-status!
     (lambda (run-id test-name state status itemdat-or-path comment dat)
       (set! *last-db-access* (current-seconds))
       (test-set-status! db run-id test-name state status itemdat-or-path comment dat)))

    ;;======================================================================
    ;; end of publish-procedure section
    ;;======================================================================

    (set! *rpc:listener* rpc:listener)
    (on-exit (lambda ()
	       (sqlite3:execute db "DELETE FROM metadat WHERE var='SERVER' and val=?;" host:port)
	       (sqlite3:finalize! db)))
    (thread-start! th1)
    (thread-start! th2)
    ;; (thread-join!  th2)
    ;; return th2 for the calling process to do a join with 
    th2
    )) ;; rpc:server)))

(define (server:keep-running db)
  ;; if none running or if > 20 seconds since 
  ;; server last used then start shutdown
  (let loop ((count 0))
    (thread-sleep! 20) ;; no need to do this very often
    (let ((numrunning (db:get-count-tests-running db)))
      (if (or (not (> numrunning 0))
	      (> *last-db-access* (+ (current-seconds) 20)))
	  (begin
	    (debug:print 0 "INFO: Starting to shutdown the server side")
	    (sqlite3:execute db "DELETE FROM metadat WHERE var='SERVER'"); ;;  AND val like ?;"
			  ;; host:port) ;; need to delete only *my* server entry (future use)
	    (thread-sleep! 10)
	    (debug:print 0 "INFO: Server shutdown complete. Exiting")
	    (exit))))
    (loop (+ 1 count))))

(define (server:find-free-port-and-open port)
  (handle-exceptions
   exn
   (begin
     (print "Failed to bind to port " (rpc:default-server-port) ", trying next port")
     (server:find-free-port-and-open (+ port 1)))
   (rpc:default-server-port port)
   (tcp-listen (rpc:default-server-port))))

(define (server:client-setup db)
  (if *runremote*
      (begin
	(debug:print 0 "ERROR: Attempt to connect to server but already connected")
	#f)
      (let* ((hostinfo (db:get-var db "SERVER"))
	     (hostdat  (if hostinfo (string-split hostinfo ":")))
	     (host     (if hostinfo (car hostdat)))
	     (port     (if (and hostinfo (> (length hostdat) 1))(cadr hostdat) #f)))
	(if (and port
		 (string->number port))
	    (let ((portn (string->number port)))