︙ | | | ︙ | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
(declare (uses mtver))
(declare (uses debugprint))
(declare (uses stml2))
(declare (uses pkts))
(declare (uses processmod))
(declare (uses mtargs))
(declare (uses configfmod))
(declare (uses hostinfo))
(declare (uses keysmod))
;; odd but it works?
;; (declare (uses itemsmod))
(module commonmod
(
|
|
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
(declare (uses mtver))
(declare (uses debugprint))
(declare (uses stml2))
(declare (uses pkts))
(declare (uses processmod))
(declare (uses mtargs))
(declare (uses configfmod))
;; (declare (uses hostinfo))
(declare (uses keysmod))
;; odd but it works?
;; (declare (uses itemsmod))
(module commonmod
(
|
︙ | | | ︙ | |
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
|
runs:runrec-mconfig
runs:runrec-runconfig
runs:runrec-serverdat
runs:runrec-transport
runs:runrec-db
runs:runrec-top-path
runs:runrec-run_id
test:get-id
test:get-run_id
test:get-test-name
test:get-state
test:get-status
test:get-item-path
test:test-get-fullname
make-and-init-bigdata
call-with-environment-variables
common:simple-file-lock
common:simple-file-lock-and-wait
common:simple-file-release-lock
common:fail-safe
get-file-descriptor-count
common:get-this-exe-fullpath
common:get-sync-lock-filepath
common:find-local-megatest
common:logpro-exit-code->status-sym
common:worse-status-sym
|
>
>
|
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
|
runs:runrec-mconfig
runs:runrec-runconfig
runs:runrec-serverdat
runs:runrec-transport
runs:runrec-db
runs:runrec-top-path
runs:runrec-run_id
test:testdat?
test:get-id
test:get-run_id
test:get-test-name
test:get-state
test:get-status
test:get-item-path
test:test-get-fullname
make-and-init-bigdata
call-with-environment-variables
common:simple-file-lock
common:simple-file-lock-and-wait
common:simple-file-release-lock
common:with-simple-file-lock
common:fail-safe
get-file-descriptor-count
common:get-this-exe-fullpath
common:get-sync-lock-filepath
common:find-local-megatest
common:logpro-exit-code->status-sym
common:worse-status-sym
|
︙ | | | ︙ | |
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
*task-db*
*db-access-allowed*
*db-access-mutex*
*db-transaction-mutex*
*db-cache-path*
*db-with-db-mutex*
*db-api-call-time*
*no-sync-db*
*my-signature*
*transport-type*
*logged-in-clients*
*server-info*
*server-run*
*run-id*
*server-kind-run*
*home-host*
*heartbeat-mutex*
*api-process-request-count*
*max-api-process-requests*
|
>
<
|
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
*task-db*
*db-access-allowed*
*db-access-mutex*
*db-transaction-mutex*
*db-cache-path*
*db-with-db-mutex*
*db-api-call-time*
*didsomething*
*no-sync-db*
*my-signature*
*transport-type*
*logged-in-clients*
*server-run*
*run-id*
*server-kind-run*
*home-host*
*heartbeat-mutex*
*api-process-request-count*
*max-api-process-requests*
|
︙ | | | ︙ | |
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
runs:gendat-inc-results-last-update-set!
runs:gendat-inc-results-fmt-set!
runs:gendat-run-info-set!
runs:gendat-runname-set!
runs:gendat-target-set!
megatest-fossil-hash
)
(import scheme
chicken.base
chicken.condition
chicken.file
|
>
>
>
>
|
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
runs:gendat-inc-results-last-update-set!
runs:gendat-inc-results-fmt-set!
runs:gendat-run-info-set!
runs:gendat-runname-set!
runs:gendat-target-set!
megatest-fossil-hash
rmt:mk-signature
rmt:get-signature
)
(import scheme
chicken.base
chicken.condition
chicken.file
|
︙ | | | ︙ | |
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
chicken.io
chicken.string
chicken.sort
chicken.time.posix
(prefix base64 base64:)
(prefix sqlite3 sqlite3:)
directory-utils
matchable
md5
message-digest
regex
regex-case
sparse-vectors
|
>
>
|
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
chicken.io
chicken.string
chicken.sort
chicken.time.posix
(prefix base64 base64:)
(prefix sqlite3 sqlite3:)
address-info
directory-utils
matchable
md5
message-digest
regex
regex-case
sparse-vectors
|
︙ | | | ︙ | |
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
stml2
pkts
processmod
(prefix mtargs args:)
configfmod
keysmod
;; itemsmod
hostinfo
)
;;======================================================================
;; CONTENTS
;;
;; config file utils
;; misc conversion, data manipulation functions
|
|
|
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
stml2
pkts
processmod
(prefix mtargs args:)
configfmod
keysmod
;; itemsmod
;; hostinfo
)
;;======================================================================
;; CONTENTS
;;
;; config file utils
;; misc conversion, data manipulation functions
|
︙ | | | ︙ | |
840
841
842
843
844
845
846
847
848
849
850
851
852
853
|
(define (test:get-id vec) (vector-ref vec 0))
(define (test:get-run_id vec) (vector-ref vec 1))
(define (test:get-test-name vec)(vector-ref vec 2))
(define (test:get-state vec) (vector-ref vec 3))
(define (test:get-status vec) (vector-ref vec 4))
(define (test:get-item-path vec)(vector-ref vec 5))
(define (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) ")"))))
;;======================================================================
|
>
>
>
>
|
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
|
(define (test:get-id vec) (vector-ref vec 0))
(define (test:get-run_id vec) (vector-ref vec 1))
(define (test:get-test-name vec)(vector-ref vec 2))
(define (test:get-state vec) (vector-ref vec 3))
(define (test:get-status vec) (vector-ref vec 4))
(define (test:get-item-path vec)(vector-ref vec 5))
(define (test:testdat? testdat)
(and (vector? testdat)
(>= (vector-length testdat) 6)))
(define (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) ")"))))
;;======================================================================
|
︙ | | | ︙ | |
923
924
925
926
927
928
929
930
931
932
933
934
935
936
|
;; (define *watchdog* #f)
;; A hash table that can be accessed by #{scheme ...} calls in
;; config files. Allows communicating between confgs
;;
(define *user-hash-data* (make-hash-table))
(define *db-keys* #f)
(define *pkts-info* (make-hash-table)) ;; store stuff like the last parent here
(define *configinfo* #f) ;; raw results from setup, includes toppath and table from megatest.config
(define *runconfigdat* #f) ;; run configs data
(define *configdat* #f) ;; megatest.config data ==> moved to configfmod
(define *configstatus* #f) ;; status of data; 'fulldata : all processing done, #f : no data yet, 'partialdata : partial read done
(define *toppath* #f)
|
>
|
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
|
;; (define *watchdog* #f)
;; A hash table that can be accessed by #{scheme ...} calls in
;; config files. Allows communicating between confgs
;;
(define *user-hash-data* (make-hash-table))
(define *db-keys* #f)
(define *didsomething* #f)
(define *pkts-info* (make-hash-table)) ;; store stuff like the last parent here
(define *configinfo* #f) ;; raw results from setup, includes toppath and table from megatest.config
(define *runconfigdat* #f) ;; run configs data
(define *configdat* #f) ;; megatest.config data ==> moved to configfmod
(define *configstatus* #f) ;; status of data; 'fulldata : all processing done, #f : no data yet, 'partialdata : partial read done
(define *toppath* #f)
|
︙ | | | ︙ | |
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
|
(define *my-signature* #f)
(define *transport-type* 'http) ;; override with [server] transport http|rpc|nmsg
;; replaced by *rmt:remote*
;; (define *runremote* #f) ;; if set up for server communication this will hold <host port>
;; (define *max-cache-size* 0)
(define *logged-in-clients* (make-hash-table))
;; (define *server-id* #f)
(define *server-info* #f) ;; good candidate for easily convert to non-global
;; (define *time-to-exit* #f)
(define *server-run* #t)
(define *run-id* #f)
(define *server-kind-run* (make-hash-table))
(define *home-host* #f)
;; (define *total-non-write-delay* 0)
(define *heartbeat-mutex* (make-mutex))
(define *api-process-request-count* 0)
|
<
<
|
985
986
987
988
989
990
991
992
993
994
995
996
997
998
|
(define *my-signature* #f)
(define *transport-type* 'http) ;; override with [server] transport http|rpc|nmsg
;; replaced by *rmt:remote*
;; (define *runremote* #f) ;; if set up for server communication this will hold <host port>
;; (define *max-cache-size* 0)
(define *logged-in-clients* (make-hash-table))
;; (define *server-id* #f)
(define *server-run* #t)
(define *run-id* #f)
(define *server-kind-run* (make-hash-table))
(define *home-host* #f)
;; (define *total-non-write-delay* 0)
(define *heartbeat-mutex* (make-mutex))
(define *api-process-request-count* 0)
|
︙ | | | ︙ | |
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
|
;; (define db:dbfile-path common:get-db-tmp-area)
(define *global-db-store* (make-hash-table))
;;======================================================================
;; end globals
;;======================================================================
;; 0 1 2 3
(defstruct launch:einf (pid #t)(exit-status #t)(exit-code #t)(rollup-status 0))
;; copied from egg call-with-environment-variables
;;
(define (call-with-environment-variables variables thunk)
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
|
;; (define db:dbfile-path common:get-db-tmp-area)
(define *global-db-store* (make-hash-table))
;;======================================================================
;; end globals
;;======================================================================
;; Generate a unique signature for this process, used at both client and
;; server side
(define (rmt:mk-signature)
(message-digest-string (md5-primitive)
(with-output-to-string
(lambda ()
(write (list (current-directory)
(current-process-id)
(argv)))))))
(define (rmt:get-signature)
(if *my-signature* *my-signature*
(let ((sig (rmt:mk-signature)))
(set! *my-signature* sig)
*my-signature*)))
;; 0 1 2 3
(defstruct launch:einf (pid #t)(exit-status #t)(exit-code #t)(rollup-status 0))
;; copied from egg call-with-environment-variables
;;
(define (call-with-environment-variables variables thunk)
|
︙ | | | ︙ | |
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
|
#f)))))
(define (common:simple-file-release-lock fname)
(handle-exceptions
exn
#f ;; I don't really care why this failed (at least for now)
(delete-file* fname)))
;;======================================================================
;; PUlled below from common.scm
;;======================================================================
;; execute thunk, return value. If exception thrown, trap exception, return #f, and emit nonfatal condition note to *default-log-port* .
;; arguments - thunk, message
|
>
>
>
>
>
>
>
|
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
|
#f)))))
(define (common:simple-file-release-lock fname)
(handle-exceptions
exn
#f ;; I don't really care why this failed (at least for now)
(delete-file* fname)))
(define (common:with-simple-file-lock fname proc)
(let* ((lkfname (conc fname ".lock")))
(common:simple-file-lock-and-wait lkfname)
(let ((res (proc)))
(common:simple-file-release-lock lkfname)
res)))
;;======================================================================
;; PUlled below from common.scm
;;======================================================================
;; execute thunk, return value. If exception thrown, trap exception, return #f, and emit nonfatal condition note to *default-log-port* .
;; arguments - thunk, message
|
︙ | | | ︙ | |
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
|
(loop (car tal)(cdr tal) loads proc-num phys-num core-num)))))))))))
(define (common:unix-ping hostname)
(let ((res (system (conc "ping -c 1 " hostname " > /dev/null"))))
(eq? res 0)))
(define (launch:is-test-alive host pid)
(if (and host pid (not (equal? host "n/a")))
(let* ((cmd (conc "ssh " host " pstree -A " pid))
(output (with-input-from-pipe cmd read-lines)))
(debug:print 2 *default-log-port* "Running " cmd " received " output)
(if (eq? (length output) 0)
#f
#t))
#t))
(define (common:get-num-cpus remote-host)
(let* ((actual-host (or remote-host (get-host-name))))
;; hosts had better not be changing the number of cpus too often!
(or (hash-table-ref/default *numcpus-cache* actual-host #f)
(let* ((numcpus (or (common:get-cached-info actual-host "num-cpus" age: (+ 2592000 (pseudo-random-integer 3600)))
(let* ((proc (lambda ()
|
>
>
>
>
|
|
|
|
|
|
|
<
>
|
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
|
(loop (car tal)(cdr tal) loads proc-num phys-num core-num)))))))))))
(define (common:unix-ping hostname)
(let ((res (system (conc "ping -c 1 " hostname " > /dev/null"))))
(eq? res 0)))
(define (launch:is-test-alive host pid)
(let* ((same-host (equal? host (get-host-name)))
(cmd (conc
(if same-host "" (conc "ssh "host" "))
"pstree -A "pid)))
(if (and host pid
(not (equal? host "n/a")))
(let* ((output (with-input-from-pipe cmd read-lines)))
(debug:print 2 *default-log-port* "Running " cmd " received " output)
(if (eq? (length output) 0)
#f
#t))
#t))) ;; assuming bad query is about a live test is likely not the right thing to do?
(define (common:get-num-cpus remote-host)
(let* ((actual-host (or remote-host (get-host-name))))
;; hosts had better not be changing the number of cpus too often!
(or (hash-table-ref/default *numcpus-cache* actual-host #f)
(let* ((numcpus (or (common:get-cached-info actual-host "num-cpus" age: (+ 2592000 (pseudo-random-integer 3600)))
(let* ((proc (lambda ()
|
︙ | | | ︙ | |
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
|
d
(begin
;; (if (common:low-noise-print 60 "tests:get-tests-search-path" d)
;; (debug:print 0 *default-log-port* "WARNING: problem with directory " d ", dropping it from tests path"))
#f)))
(append paths (list (conc *toppath* "/tests"))))))
(define (server:get-best-guess-address hostname)
(let ((res #f))
(for-each
(lambda (adr)
(if (not (eq? (u8vector-ref adr 0) 127))
(set! res adr)))
;; NOTE: This can fail when there is no mention of the host in /etc/hosts. FIXME
(vector->list (hostinfo-addresses (hostname->hostinfo hostname))))
(string-intersperse
(map number->string
(u8vector->list
(if res res (hostname->ip hostname)))) ".")))
(define (tests:readlines filename)
(call-with-input-file filename
(lambda (p)
(let loop ((line (read-line p))
(result '()))
(if (eof-object? line)
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
|
d
(begin
;; (if (common:low-noise-print 60 "tests:get-tests-search-path" d)
;; (debug:print 0 *default-log-port* "WARNING: problem with directory " d ", dropping it from tests path"))
#f)))
(append paths (list (conc *toppath* "/tests"))))))
;;======================================================================
;; network utilities
;;======================================================================
#;(define (server:get-best-guess-address hostname)
(let ((res #f))
(for-each
(lambda (adr)
(if (not (eq? (u8vector-ref adr 0) 127))
(set! res adr)))
;; NOTE: This can fail when there is no mention of the host in /etc/hosts. FIXME
(vector->list (hostinfo-addresses (hostname->hostinfo hostname))))
(string-intersperse
(map number->string
(u8vector->list
(if res res (hostname->ip hostname)))) ".")))
;; NOTE: Look at address-info egg as alternative to some of this
(define (rate-ip ipaddr)
(regex-case ipaddr
( "^127\\..*" _ 0 )
( "^(10\\.0|192\\.168)\\..*" _ 1 )
( else 2 ) ))
;; Change this to bias for addresses with a reasonable broadcast value?
;;
(define (ip-pref-less? a b)
(> (rate-ip a) (rate-ip b)))
(define (server:get-best-guess-address hostname)
(let ((all-addresses (get-all-ips hostname)))
(cond
((null? all-addresses)
hostname #;(get-host-name)) ;; no interfaces?
((eq? (length all-addresses) 1)
(car all-addresses)) ;; only one to choose from, just go with it
(else
(car (sort all-addresses ip-pref-less?))))))
(define (get-all-ips-sorted)
(sort (get-all-ips) ip-pref-less?))
(define (get-all-ips hostname)
(map address-info-host
(filter (lambda (x)
(equal? (address-info-type x) 'tcp))
(address-infos hostname))))
(define (tests:readlines filename)
(call-with-input-file filename
(lambda (p)
(let loop ((line (read-line p))
(result '()))
(if (eof-object? line)
|
︙ | | | ︙ | |