Megatest

Check-in [fb4085dbbf]
Login
Overview
Comment:Merged v1.61 into re-refactor-dbr:dbstruct branch. Can use meld to bring some of the work to v1.62
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | re-refactor-vec2defstruct
Files: files | file ages | folders
SHA1: fb4085dbbf3ba36ec20ae9ee353cc3a2b691fb89
User & Date: matt on 2016-09-09 00:00:24
Other Links: branch diff | manifest | tags
Context
2016-09-09
00:00
Merged v1.61 into re-refactor-dbr:dbstruct branch. Can use meld to bring some of the work to v1.62 Closed-Leaf check-in: fb4085dbbf user: matt tags: re-refactor-vec2defstruct
2016-09-08
18:30
Fixed the tree browser filters in runs tab check-in: 78514dad40 user: ritikaag tags: v1.61
2016-01-29
17:04
Migrated db:mintest-get -> dbr:mintest check-in: b7a6ca20cb user: mrwellan tags: re-refactor-vec2defstruct
Changes

Modified .fossil-settings/ignore-glob from [4907666f99] to [b21de9c0d5].


1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
+







altdb.scm
utils/build/*
*~
*.o
bin/*
megatest.db
monitor.db
megatest

Modified Makefile from [c0b2515300] to [867a54f75f].

1
2
3
4
5
6
7
8
9
10
11
12
13








14
15
16
17
18
19



20
21

22
23
24
25
26
27
28
1
2
3
4
5








6
7
8
9
10
11
12
13
14
15
16



17
18
19
20

21
22
23
24
25
26
27
28





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
-
-
+
+
+

-
+







# make install CSCOPTS='-accumulate-profile -profile-name $(PWD)/profile-ww$(shell date +%V.%u)'
PREFIX=$(PWD)
CSCOPTS= 
INSTALL=install
SRCFILES = common.scm items.scm launch.scm \
           ods.scm runconfig.scm server.scm configf.scm \
           db.scm keys.scm margs.scm megatest-version.scm \
           process.scm runs.scm tasks.scm tests.scm genexample.scm \
	   http-transport.scm nmsg-transport.scm filedb.scm \
           client.scm gutils.scm synchash.scm daemon.scm mt.scm dcommon.scm \
	   tree.scm ezsteps.scm lock-queue.scm sdb.scm \
	   rmt.scm api.scm tdb.scm rpc-transport.scm \
	   portlogger.scm archive.scm
   ods.scm runconfig.scm server.scm configf.scm \
   db.scm keys.scm margs.scm megatest-version.scm \
   process.scm runs.scm tasks.scm tests.scm genexample.scm \
   http-transport.scm nmsg-transport.scm filedb.scm \
   client.scm synchash.scm daemon.scm mt.scm \
   ezsteps.scm lock-queue.scm sdb.scm \
   rmt.scm api.scm tdb.scm rpc-transport.scm \
   portlogger.scm archive.scm env.scm

# Eggs to install (straightforward ones)
EGGS=matchable readline apropos base64 regex-literals format regex-case test coops trace csv \
     dot-locking posix-utils posix-extras directory-utils hostinfo tcp-server rpc csv-xml fmt \
     json md5 awful http-client spiffy uri-common intarweb spiffy-request-vars \
     spiffy-directory-listing ssax sxml-serializer sxml-modifications iup canvas-draw sqlite3
dot-locking posix-utils posix-extras directory-utils hostinfo tcp-server rpc csv-xml fmt \
json md5 awful http-client spiffy uri-common intarweb spiffy-request-vars \
spiffy-directory-listing ssax sxml-serializer sxml-modifications iup canvas-draw sqlite3

GUISRCF  = dashboard-tests.scm dashboard-guimonitor.scm 
GUISRCF  = dashboard-tests.scm dashboard-guimonitor.scm gutils.scm dcommon.scm tree.scm vg.scm

OFILES   = $(SRCFILES:%.scm=%.o)
GOFILES  = $(GUISRCF:%.scm=%.o)

ADTLSCR=mt_laststep mt_runstep mt_ezstep
HELPERS=$(addprefix $(PREFIX)/bin/,$(ADTLSCR))
DEPLOYHELPERS=$(addprefix deploytarg/,$(ADTLSCR))
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
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







-
+


-
+


-
+







-
+





-
+
+
+













-
+








-
+






-
+








all : $(PREFIX)/bin/.$(ARCHSTR) mtest dboard 

mtest: $(OFILES) readline-fix.scm megatest.o
	csc $(CSCOPTS) $(OFILES) megatest.o -o mtest

dboard : $(OFILES) $(GOFILES) dashboard.scm
	csc $(OFILES) dashboard.scm $(GOFILES) -o dboard
	csc $(CSCOPTS) $(OFILES) dashboard.scm $(GOFILES) -o dboard

ndboard : newdashboard.scm $(OFILES) $(GOFILES)
	csc $(OFILES) $(GOFILES) newdashboard.scm -o ndboard
	csc $(CSCOPTS) $(OFILES) $(GOFILES) newdashboard.scm -o ndboard

multi-dboard : multi-dboard.scm $(OFILES) $(GOFILES)
	csc $(OFILES) $(GOFILES) multi-dboard.scm -o multi-dboard
	csc $(CSCOPTS) $(OFILES) $(GOFILES) multi-dboard.scm -o multi-dboard

# 
# $(PREFIX)/bin/revtagfsl : utils/revtagfsl.scm
#	csc utils/revtagfsl.scm -o $(PREFIX)/bin/revtagfsl

# Special dependencies for the includes
tests.o db.o launch.o runs.o dashboard-tests.o dashboard-guimonitor.o dashboard-main.o monitor.o dashboard.o  \
  archive.o megatest.o : db_records.scm
archive.o megatest.o : db_records.scm
tests.o runs.o dashboard.o dashboard-tests.o dashboard-main.o  : run_records.scm
db.o ezsteps.o keys.o launch.o megatest.o monitor.o runs-for-ref.o runs.o tests.o : key_records.scm
tests.o tasks.o dashboard-tasks.o : task_records.scm
runs.o : test_records.scm
megatest.o : megatest-fossil-hash.scm
client.scm common.scm configf.scm dashboard-guimonitor.scm dashboard-tests.scm dashboard.scm db.scm dcommon.scm ezsteps.scm fs-transport.scm http-transport.scm index-tree.scm items.scm keys.scm launch.scm megatest.scm monitor.scm mt.scm newdashboard.scm runconfig.scm runs.scm server.scm tdb.scm tests.scm tree.scm zmq-transport.scm : common_records.scm rpc-transport.scm
client.scm common.scm configf.scm dashboard-guimonitor.scm dashboard-tests.scm dashboard.scm db.scm dcommon.scm ezsteps.scm fs-transport.scm http-transport.scm index-tree.scm items.scm keys.scm launch.scm megatest.scm monitor.scm mt.scm newdashboard.scm runconfig.scm runs.scm server.scm tdb.scm tests.scm tree.scm : common_records.scm rpc-transport.scm
common_records.scm : altdb.scm
vg.o dashboard.o : vg_records.scm

# Temporary while transitioning to new routine
# runs.o : run-tests-queue-classic.scm  run-tests-queue-new.scm

megatest-fossil-hash.scm : $(SRCFILES) megatest.scm *_records.scm
	echo "(define megatest-fossil-hash \"$(MTESTHASH)\")" > megatest-fossil-hash.new
	if ! diff -q megatest-fossil-hash.new megatest-fossil-hash.scm ; then echo copying .new to .scm;cp -f megatest-fossil-hash.new megatest-fossil-hash.scm;fi

$(OFILES) $(GOFILES) : common_records.scm 

%.o : %.scm
	csc $(CSCOPTS) -c $<

$(PREFIX)/bin/.$(ARCHSTR)/mtest : mtest
$(PREFIX)/bin/.$(ARCHSTR)/mtest : mtest utils/mk_wrapper
	@echo Installing to PREFIX=$(PREFIX)
	$(INSTALL) mtest $(PREFIX)/bin/.$(ARCHSTR)/mtest
	utils/mk_wrapper $(PREFIX) mtest $(PREFIX)/bin/megatest
	chmod a+x $(PREFIX)/bin/megatest

$(PREFIX)/bin/.$(ARCHSTR)/ndboard : ndboard
	$(INSTALL) ndboard $(PREFIX)/bin/.$(ARCHSTR)/ndboard

$(PREFIX)/bin/newdashboard : $(PREFIX)/bin/.$(ARCHSTR)/ndboard
$(PREFIX)/bin/newdashboard : $(PREFIX)/bin/.$(ARCHSTR)/ndboard utils/mk_wrapper
	utils/mk_wrapper $(PREFIX) ndboard $(PREFIX)/bin/newdashboard
	chmod a+x $(PREFIX)/bin/newdashboard

$(PREFIX)/bin/.$(ARCHSTR)/mdboard : multi-dboard
	$(INSTALL) multi-dboard $(PREFIX)/bin/.$(ARCHSTR)/mdboard

$(PREFIX)/bin/mdboard : $(PREFIX)/bin/.$(ARCHSTR)/mdboard
$(PREFIX)/bin/mdboard : $(PREFIX)/bin/.$(ARCHSTR)/mdboard  utils/mk_wrapper
	utils/mk_wrapper $(PREFIX) mdboard $(PREFIX)/bin/mdboard
	chmod a+x $(PREFIX)/bin/mdboard

# $(HELPERS) : utils/%
# 	$(INSTALL) $< $@
# 	chmod a+x $@

138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154







-
+








deploytarg/nbfind : utils/nbfind
	$(INSTALL) $< $@
	chmod a+x $@


# install dashboard as dboard so wrapper script can be called dashboard
$(PREFIX)/bin/.$(ARCHSTR)/dboard : dboard $(FILES)
$(PREFIX)/bin/.$(ARCHSTR)/dboard : dboard $(FILES) utils/mk_wrapper
	utils/mk_wrapper $(PREFIX) dboard $(PREFIX)/bin/dashboard
	chmod a+x $(PREFIX)/bin/dashboard
	$(INSTALL) dboard $(PREFIX)/bin/.$(ARCHSTR)/dboard

install : $(PREFIX)/bin/.$(ARCHSTR) $(PREFIX)/bin/.$(ARCHSTR)/mtest $(PREFIX)/bin/megatest \
          $(PREFIX)/bin/.$(ARCHSTR)/dboard $(PREFIX)/bin/dashboard $(HELPERS) $(PREFIX)/bin/nbfake \
	  $(PREFIX)/bin/nbfind $(PREFIX)/bin/loadrunner $(PREFIX)/bin/mt_xterm \
162
163
164
165
166
167
168
169

170








171

172

173
174
175
176
177
178

179
180
181
182
183
184
185
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







-
+

+
+
+
+
+
+
+
+

+
-
+





-
+







	mkdir -p ext-tests
	cd ext-tests;fossil open --nested $(MTQA_FOSSIL)

$(MTQA_FOSSIL) :
	fossil clone https://www.kiatoa.com/fossils/megatest_qa $(MTQA_FOSSIL)

clean : 
	rm -f $(OFILES) $(GOFILES) megatest dboard dboard.o megatest.o dashboard.o
	rm -f $(OFILES) $(GOFILES) megatest dboard dboard.o megatest.o dashboard.o megatest-fossil-hash.* altdb.scm

#======================================================================
# Make the records files
#======================================================================

# vg_records.scm : records.sh
#	./records.sh

#======================================================================
# Deploy section (not complete yet)
#======================================================================
#

$(DEPLOYHELPERS) : utils/mt_*
	$(INSTALL) $< $@
	chmod a+X $@

deploytarg/apropos.so : Makefile
	chicken-install -p deploytarg -deploy $(EGGS)
	chicken-install -p deploytarg -deploy -keep-installed $(EGGS)

#	for i in apropos base64 canvas-draw csv-xml directory-utils dot-locking extras fmt format hostinfo http-client intarweb json md5 message-digest posix posix-extras readline regex regex-case s11n spiffy spiffy-request-vars sqlite3 srfi-1 srfi-18 srfi-69 tcp test uri-common check-errors synch matchable sql-null tcp-server rpc blob-utils string-utils variable-item defstruct uri-generic sendfile opensll openssl lookup-table list-utils stack; do \
#	chicken-install -prefix deploytarg -deploy $$i;done

# deploytarg/libsqlite3.so : 
# 	CSC_OPTIONS="-Ideploytarg -Ldeploytarg" $CHICKEN_INSTALL -prefix deploytarg -deploy sqlite3

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













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







-
+


-
+








-
+

-
-
+
+
+
+
+
+
+

+
+
+

+
+

-
-
+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
deploytarg/dboard :  $(OFILES) $(GOFILES) dashboard.scm deploytarg/apropos.so
	csc -deploy $(OFILES) $(GOFILES) dashboard.scm -o deploytarg
	mv deploytarg/deploytarg deploytarg/dboard

# DATASHAREO=configf.o common.o process.o tree.o dcommon.o margs.o launch.o gutils.o db.o synchash.o server.o \
#            megatest-version.o tdb.o ods.o mt.o keys.o
datashare-testing/sd : datashare.scm $(OFILES)
	csc datashare.scm $(OFILES) -o datashare-testing/sd
	csc $(CSCOPTS) datashare.scm $(OFILES) -o datashare-testing/sd

datashare-testing/sdat: sharedat.scm $(OFILES)
	csc sharedat.scm $(OFILES) -o datashare-testing/sdat
	csc $(CSCOPTS) sharedat.scm $(OFILES) -o datashare-testing/sdat

sd : datashare-testing/sd
	mkdir -p /tmp/$(USER)/datashare/disk1 /tmp/$(USER)/basepath

xterm : sd
	(export BASEPATH=/tmp/$(USER)/basepath ; export PATH="$(PWD)/datashare-testing:$(PATH)" ; xterm &)

datashare-testing/spublish : spublish.scm $(OFILES)
	csc spublish.scm $(OFILES) -o datashare-testing/spublish
	csc $(CSCOPTS) spublish.scm $(OFILES) -o datashare-testing/spublish

datashare-testing/sretrieve : sretrieve.scm $(OFILES)
	csc sretrieve.scm $(OFILES) -o datashare-testing/sretrieve
datashare-testing/sretrieve : sretrieve.scm megatest-version.o margs.o configf.o process.o 
	csc $(CSCOPTS) sretrieve.scm megatest-version.o margs.o configf.o process.o -o datashare-testing/sretrieve

sretrieve/sretrieve : datashare-testing/sretrieve
	csc $(CSCOPTS) -deploy -deployed sretrieve.scm megatest-version.o margs.o configf.o process.o
	chicken-install -keep-installed $(PROXY) -deploy -prefix sretrieve defstruct srfi-18 format sql-de-lite \
             srfi-1 posix regex regex-case srfi-69

# base64 dot-locking \
#             csv-xml z3

#  "(define (toplevel-command . a) #f)"
# if egrep 'version.*3.0' $(shell dirname $(shell dirname $(shell which csi)))/lib/chicken/7/readline.setup-info;then \

readline-fix.scm :
	if egrep 'version.*3.0' $(shell dirname $(shell dirname $(shell which csi)))/lib/chicken/7/readline.setup-info;then \
           echo "(use-legacy-bindings)" > readline-fix.scm; \
	if [[ $(shell chicken-status | grep readline | awk '{print $4}' | cut -d. -f1) -gt 3 ]];then \
	   echo "(define *use-new-readline* #f)" > readline-fix.scm; \
	else \
	   echo "" > readline-fix.scm;\
	   echo "(define *use-new-readline* #t)" > readline-fix.scm;\
	fi

altdb.scm :
	echo ";; optional alternate db setup" > altdb.scm
	echo "(define *available-db* (make-hash-table))" >> altdb.scm
	if  csi -ne '(use mysql-client)';then \
           echo "(use mysql-client)(hash-table-set! *available-db* 'mysql #t)" >> altdb.scm; \
	fi
	if csi -ne '(use postgresql)';then \
	   echo "(use postgresql)(hash-table-set! *available-db* 'postgresql #t)" >> altdb.scm;\
	fi

portlogger-example : portlogger-example.scm api.o archive.o client.o common.o configf.o daemon.o dashboard-tests.o db.o dcommon.o ezsteps.o filedb.o genexample.o gutils.o http-transport.o items.o keys.o launch.o lock-queue.o margs.o megatest-version.o mt.o nmsg-transport.o ods.o portlogger.o process.o rmt.o rpc-transport.o runconfig.o runs.o sdb.o server.o synchash.o tasks.o tdb.o tests.o tree.o
	csc $(CSCOPTS) portlogger-example.scm api.o archive.o client.o common.o configf.o daemon.o dashboard-tests.o db.o dcommon.o ezsteps.o filedb.o genexample.o gutils.o http-transport.o items.o keys.o launch.o lock-queue.o margs.o megatest-version.o mt.o nmsg-transport.o ods.o portlogger.o process.o rmt.o rpc-transport.o runconfig.o runs.o sdb.o server.o synchash.o tasks.o tdb.o tests.o tree.o

Added README version [412df20f12].










1
2
3
4
5
6
7
8
9
+
+
+
+
+
+
+
+
+
Megatest 

To build:

1. Install chicken scheme. See utils/Makefile.installall

2. Compile with "make -j install PREFIX=/some/path"

3. To test ....

Modified api.scm from [7425d00411] to [d744d47aad].

45
46
47
48
49
50
51

52
53
54
55
56
57
58
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59







+







    get-num-runs
    get-all-run-ids
    get-prev-run-ids
    get-run-ids-matching-target
    get-runs-by-patt
    get-steps-data
    get-steps-for-test
    read-test-data
    login
    testmeta-get-record
    have-incompletes?
    synchash-get
    ))

(define api:write-queries
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119







-
+







;;    - returns #( flag result )
;;
(define (api:execute-requests dbstruct dat)
  (handle-exceptions
   exn
   (let ((call-chain (get-call-chain)))
     (print-call-chain (current-error-port))
     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))       
     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))       
     (vector #f (vector exn call-chain dat))) ;; return some stuff for debug if an exception happens
   (if (not (vector? dat))                    ;; it is an error to not receive a vector
       (vector #f #f "remote must be called with a vector")       
       (vector                                   ;; return a vector + the returned data structure
	#t 
	(let ((cmd    (vector-ref dat 0))
	      (params (vector-ref dat 1)))
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
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







+
+




















+















+
-
+








	    ;; RUNS
	    ((register-run)                 (apply db:register-run dbstruct params))
	    ((set-tests-state-status)       (apply db:set-tests-state-status dbstruct params))
	    ((delete-run)                   (apply db:delete-run dbstruct params))
	    ((lock/unlock-run)              (apply db:lock/unlock-run dbstruct params))
	    ((update-run-event_time)        (apply db:update-run-event_time dbstruct params))
	    ((update-run-stats)             (apply db:update-run-stats dbstruct params))
	    ((set-var)                      (apply db:set-var dbstruct params))

	    ;; STEPS
	    ((teststep-set-status!)         (apply db:teststep-set-status! dbstruct params))

	    ;; TEST DATA
	    ((test-data-rollup)             (apply db:test-data-rollup dbstruct params))
	    ((csv->test-data)               (apply db:csv->test-data dbstruct params))

	    ;; MISC
	    ((sync-inmem->db)               (let ((run-id (car params)))
					      (db:sync-touched dbstruct run-id force-sync: #t)))
	    ((mark-incomplete)              (apply db:find-and-mark-incomplete dbstruct params))

	    ;; TESTMETA
	    ((testmeta-add-record)       (apply db:testmeta-add-record dbstruct params))
	    ((testmeta-update-field)     (apply db:testmeta-update-field dbstruct params))

	    ;; TASKS
	    ((tasks-add)                 (apply tasks:add dbstruct params))   
	    ((tasks-set-state-given-param-key) (apply tasks:set-state-given-param-key dbstruct params))
	    ((tasks-get-last)            (apply tasks:get-last dbstruct params))

	    ;; ARCHIVES
	    ;; ((archive-get-allocations)   
	    ((archive-register-disk)     (apply db:archive-register-disk dbstruct params))
	    ((archive-register-block-name)(apply db:archive-register-block-name dbstruct params))
	    ((archive-allocate-testsuite/area-to-block)(apply db:archive-allocate-testsuite/area-to-block dbstruct block-id testsuite-name areakey))

	    ;;======================================================================
	    ;; READ ONLY QUERIES
	    ;;======================================================================

	    ;; KEYS
	    ((get-key-val-pairs)               (apply db:get-key-val-pairs dbstruct params))
	    ((get-keys)                        (db:get-keys dbstruct))
	    ((get-key-vals)                    (apply db:get-key-vals dbstruct params))
	    ((get-target)                      (apply db:get-target dbstruct params))
	    ((get-targets)                     (db:get-targets  dbstruct))
	    ((get-targets)                     (db:get-targets dbstruct))

	    ;; ARCHIVES
	    ((test-get-archive-block-info)     (apply db:test-get-archive-block-info dbstruct params))
	    
	    ;; TESTS
	    ((test-toplevel-num-items)         (apply db:test-toplevel-num-items dbstruct params))
	    ((get-test-info-by-id)	       (apply db:get-test-info-by-id dbstruct params))
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
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







+















+
+
+





+
+
+







	    ((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-top-process-pid)        (apply db:test-get-top-process-pid 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))
	    ((get-count-tests-running-for-run-id) (apply db:get-count-tests-running-for-run-id dbstruct params))
	    ((synchash-get)                    (apply synchash:server-get dbstruct params))
	    ((get-raw-run-stats)               (apply db:get-raw-run-stats dbstruct params))

	    ;; RUNS
	    ((get-run-info)                 (apply db:get-run-info dbstruct params))
	    ((get-run-status)               (apply db:get-run-status dbstruct params))
	    ((set-run-status)               (apply db:set-run-status dbstruct params))
	    ((get-tests-for-run)            (apply db:get-tests-for-run dbstruct params))
	    ((get-test-id)                  (apply db:get-test-id dbstruct params))
	    ((get-tests-for-run-mindata)    (apply db:get-tests-for-run-mindata dbstruct params))
	    ((get-runs)                     (apply db:get-runs dbstruct params))
	    ((get-num-runs)                 (apply db:get-num-runs dbstruct params))
	    ((get-all-run-ids)              (db:get-all-run-ids dbstruct))
	    ((get-prev-run-ids)             (apply db:get-prev-run-ids dbstruct params))
	    ((get-run-ids-matching-target)  (apply db:get-run-ids-matching-target dbstruct params))
	    ((get-runs-by-patt)             (apply db:get-runs-by-patt dbstruct params))
	    ((get-run-name-from-id)         (apply db:get-run-name-from-id dbstruct params))
	    ((get-main-run-stats)           (apply db:get-main-run-stats dbstruct params))
	    ((get-var)                      (apply db:get-var dbstruct params))
	    ((get-run-stats)                (apply db:get-run-stats dbstruct params))

	    ;; STEPS
	    ((get-steps-data)               (apply db:get-steps-data dbstruct params))
	    ((get-steps-for-test)           (apply db:get-steps-for-test dbstruct params))

	    ;; TEST DATA
	    ((read-test-data)               (apply db:read-test-data dbstruct params))

	    ;; MISC
	    ((have-incompletes?)            (apply db:have-incompletes? dbstruct params))
	    ((login)                        (apply db:login dbstruct params))
	    ((general-call)                 (let ((stmtname   (car params))
						  (run-id     (cadr params))
						  (realparams (cddr params)))
					      (db:with-db dbstruct run-id #t ;; these are all for modifying the db

Modified archive.scm from [8332ff81c6] to [83d8cc9455].

66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+







  (let* ((existing-blocks (rmt:archive-get-allocations testname itempath dused))
	 (candidate-disks (map (lambda (block)
				 (list
				  (vector-ref block 1)   ;; archive-area-name
				  (vector-ref block 2))) ;; disk-path
			       existing-blocks)))
    (or (common:get-disk-with-most-free-space candidate-disks dused)
	(archive:allocate-new-archive-block testname itempath))))
	(archive:allocate-new-archive-block #f #f #f)))) ;; BROKEN. testname itempath))))

;; allocate a new archive area
;;
(define (archive:allocate-new-archive-block run-area-home testsuite-name dneeded)
  (let* ((adisks    (archive:get-archive-disks))
	 (best-disk (common:get-disk-with-most-free-space adisks dneeded)))
    (if best-disk
113
114
115
116
117
118
119
120
121
122



123
124

125
126
127
128
129
130
131
113
114
115
116
117
118
119



120
121
122
123

124
125
126
127
128
129
130
131







-
-
-
+
+
+

-
+







	 (test-groups  (make-hash-table)) ;; these two (disk and test groups) could be combined nicely
	 (bup-exe      (or (configf:lookup *configdat* "archive" "bup") "bup"))
	 (compress     (or (configf:lookup *configdat* "archive" "compress") "9"))
	 (linktree     (configf:lookup *configdat* "setup" "linktree")))

    (if (not archive-dir) ;; no archive disk found, this is fatal
	(begin
	  (debug:print 0 "FATAL: No archive disks found. Please add disks with at least " min-space " MB space to the [archive-disks] section of megatest.config")
	  (debug:print 0 "       use [archive] minspace to specify minimum available space")
	  (debug:print 0 "   disks: " (string-intersperse (map cadr (archive:get-archive-disks)) "\n         "))
	  (debug:print 0 *default-log-port* "FATAL: No archive disks found. Please add disks with at least " min-space " MB space to the [archive-disks] section of megatest.config")
	  (debug:print 0 *default-log-port* "       use [archive] minspace to specify minimum available space")
	  (debug:print 0 *default-log-port* "   disks: " (string-intersperse (map cadr (archive:get-archive-disks)) "\n         "))
	  (exit 1))
	(debug:print-info 0 "Using path " archive-dir " for archiving"))
	(debug:print-info 0 *default-log-port* "Using path " archive-dir " for archiving"))

    ;; from the test info bin the path to the test by stem
    ;;
    (for-each
     (lambda (test-dat)
       (let* ((item-path         (dbr:test-item-path test-dat))
	      (test-name         (dbr:test-testname  test-dat))
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
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







-
+

-
+

-
+













-
+















-
+




-
+


-
+







				     (substring test-physical-path
						0
						partial-path-index)
				     #f)))
	 
 	 (cond
	  (toplevel/children
	   (debug:print 0 "WARNING: cannot archive " test-name " with id " test-id " as it is a toplevel test with children"))
	   (debug:print 0 *default-log-port* "WARNING: cannot archive " test-name " with id " test-id " as it is a toplevel test with children"))
	  ((not (file-exists? test-path))
	   (debug:print 0 "WARNING: Cannot archive " test-name "/" item-path " as path " test-path " does not exist"))
	   (debug:print 0 *default-log-port* "WARNING: Cannot archive " test-name "/" item-path " as path " test-path " does not exist"))
	  (else
	   (debug:print 0
	   (debug:print 0 *default-log-port*
			"From test-dat=" test-dat " derived the following:\n"
			"test-partial-path  = " test-partial-path "\n"
			"test-path          = " test-path "\n"
			"test-physical-path = " test-physical-path "\n"
			"partial-path-index = " partial-path-index "\n"
			"test-base          = " test-base)
	   (hash-table-set! disk-groups test-base (cons test-physical-path (hash-table-ref/default disk-groups test-base '())))
	   (hash-table-set! test-groups test-base (cons test-dat (hash-table-ref/default test-groups test-base '())))
	   test-path))))
     tests)
    ;; for each disk-group
    (for-each 
     (lambda (disk-group)
       (debug:print 0 "Processing disk-group " disk-group)
       (debug:print 0 *default-log-port* "Processing disk-group " disk-group)
       (let* ((test-paths (hash-table-ref disk-groups disk-group))
	      ;; ((string-intersperse (map cadr (rmt:get-key-val-pairs 1)) "-")
	      (bup-init-params  (list "-d" archive-dir "init"))
	      (bup-index-params (append (list "-d" archive-dir "index") test-paths))
	      (bup-save-params  (append (list "-d" archive-dir "save" ;; (conc "--strip-path=" linktree)
					      (conc "-" compress) ;; or (conc "--compress=" compress)
					      "-n" (conc (common:get-testsuite-name) "-" run-id)
					      (conc "--strip-path=" disk-group))
					test-paths))
	      (print-prefix      #f)) ;; "Running: ")) ;; change to #f to turn off printing
	 (if (not (file-exists? archive-dir))
	     (create-directory archive-dir #t))
	 (if (not (file-exists? (conc archive-dir "/HEAD")))
	     (begin
	       ;; replace this with jobrunner stuff enventually
	       (debug:print-info 0 "Init bup in " archive-dir)
	       (debug:print-info 0 *default-log-port* "Init bup in " archive-dir)
	       ;; (mutex-lock! bup-mutex)
	       (run-n-wait bup-exe params: bup-init-params print-cmd: print-prefix)
	       ;; (mutex-unlock! bup-mutex)
	       ))
	 (debug:print-info 0 "Indexing data to be archived")
	 (debug:print-info 0 *default-log-port* "Indexing data to be archived")
	 ;; (mutex-lock! bup-mutex)
	 (run-n-wait bup-exe params: bup-index-params print-cmd: print-prefix)
	 (debug:print-info 0 "Archiving data with bup")
	 (debug:print-info 0 *default-log-port* "Archiving data with bup")
	 (run-n-wait bup-exe params: bup-save-params print-cmd: print-prefix)
	 ;; (mutex-unlock! bup-mutex)
	 (for-each
	  (lambda (test-dat)
	    (let ((test-id           (dbr:test-id        test-dat))
		  (run-id            (dbr:test-run_id    test-dat)))
	      (rmt:test-set-archive-block-id run-id test-id archive-id)
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266







-
+







	 ;;
	 (if (and (not toplevel/children)  ;; special handling needed for toplevel with children
		  prev-test-physical-path
		  (file-exists? prev-test-physical-path)) ;; what to do? abort or clean up or link it in?
	     (let* ((base (pathname-directory prev-test-physical-path))
		    (dirn (pathname-file      prev-test-physical-path))
		    (newn (conc base "/." dirn)))
	       (debug:print 0 "ERROR: the old directory " prev-test-physical-path ", still exists! Moving it to " newn)
	       (debug:print-error 0 *default-log-port* "the old directory " prev-test-physical-path ", still exists! Moving it to " newn)
	       (rename-file prev-test-physical-path newn)))

	 (if (and archive-path ;; no point in proceeding if there is no actual archive
		  (not toplevel/children))
	     (begin
	       ;; CREATE WORK AREA
	       ;; test-src-path == #f     ==> don't copy in data from tests directory
274
275
276
277
278
279
280
281

282
283
284
285

286
287
288
289
290

291
292
274
275
276
277
278
279
280

281
282
283
284

285
286
287
288
289

290
291
292







-
+



-
+




-
+


	       ;; bup -d /tmp/matt/adisk1/2015_q1/fullrun_e1a40/ restore -C /tmp/seeme fullrun-30/latest/ubuntu/nfs/none/w02.1.20.54_b/

	       ;; DO BUP RESTORE
	       (let* ((new-test-dat        (rmt:get-test-info-by-id run-id test-id))
		      (new-test-path       (if (vector? new-test-dat )
					       (dbr:test-rundir new-test-dat)
					       (begin
						 (debug:print 0 "ERROR: unable to get data for run-id=" run-id ", test-id=" test-id)
						 (debug:print-error 0 *default-log-port* "unable to get data for run-id=" run-id ", test-id=" test-id)
						 (exit 1))))
		      ;; new-test-path won't work - must use best-disk instead? Nope, new-test-path but tack on /..
		      (bup-restore-params  (list "-d" archive-path "restore" "-C" (conc new-test-path "/..") archive-internal-path)))
		 (debug:print-info 0 "Restoring archived data to " new-test-physical-path " from archive in " archive-path " ... " archive-internal-path)
		 (debug:print-info 0 *default-log-port* "Restoring archived data to " new-test-physical-path " from archive in " archive-path " ... " archive-internal-path)
		 ;; (mutex-lock! bup-mutex)
		 (run-n-wait bup-exe params: bup-restore-params print-cmd: #f)
		 ;; (mutex-unlock! bup-mutex)
		 (mt:test-set-state-status-by-id run-id test-id "COMPLETED" #f #f)))
	     (debug:print 0 "ERROR: No archive path in the record for run-id=" run-id " test-id=" test-id))))
	     (debug:print-error 0 *default-log-port* "No archive path in the record for run-id=" run-id " test-id=" test-id))))
     (filter vector? tests))))
	 

Modified client.scm from [ecbc2f1355] to [3a2fa3c3cb].

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
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
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
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







-
+


-
+


-
+












-
+










-
+




-
+












-
+












-
+









-
+




















-
+



-
+


-
+

















-
+


-
+


















-
+
















-
+




-
+

-
+














-
+

-
+


;; (define (client:login-no-auto-setup server-info run-id)
;;   (case (server:get-transport)
;;     ((rpc)  (rpc:login-no-auto-client-setup server-info run-id))
;;     ((http) (rmt:login-no-auto-client-setup server-info run-id))
;;     (else   (rpc:login-no-auto-client-setup server-info run-id))))
;; 
;; (define (client:setup-rpc run-id)
;;   (debug:print 0 "INFO: client:setup remaining-tries=" remaining-tries)
;;   (debug:print 0 *default-log-port* "INFO: client:setup remaining-tries=" remaining-tries)
;;   (if (<= remaining-tries 0)
;;       (begin
;; 	(debug:print 0 "ERROR: failed to start or connect to server for run-id " run-id)
;; 	(debug:print-error 0 *default-log-port* "failed to start or connect to server for run-id " run-id)
;; 	(exit 1))
;;       (let ((host-info (hash-table-ref/default *runremote* run-id #f)))
;; 	(debug:print-info 0 "client:setup host-info=" host-info ", remaining-tries=" remaining-tries)
;; 	(debug:print-info 0 *default-log-port* "client:setup host-info=" host-info ", remaining-tries=" remaining-tries)
;; 	(if host-info
;; 	    (let* ((iface     (car  host-info))
;; 		   (port      (cadr host-info))
;; 		   (start-res (client:connect iface port))
;; 		   ;; (ping-res  (server:ping-server run-id iface port))
;; 		   (ping-res  (client:login-no-auto-setup start-res run-id)))
;; 	      (if ping-res   ;; sucessful login?
;; 		  (begin
;; 		    (hash-table-set! *runremote* run-id start-res)
;; 		    start-res)  ;; return the server info
;; 		  (if (member remaining-tries '(3 4 6))
;; 		      (begin    ;; login failed
;; 			(debug:print 25 "INFO: client:setup start-res=" start-res ", run-id=" run-id ", server-dat=" host-info)
;; 			(debug:print 25 *default-log-port* "INFO: client:setup start-res=" start-res ", run-id=" run-id ", server-dat=" host-info)
;; 			(hash-table-delete! *runremote* run-id)
;; 			(open-run-close tasks:server-force-clean-run-record
;; 			 		tasks:open-db
;; 			 		run-id 
;; 			 		(car  host-info)
;; 			 		(cadr host-info)
;; 					" client:setup (host-info=#t)")
;; 			(thread-sleep! 5)
;; 			(client:setup run-id remaining-tries: 10)) ;; (- remaining-tries 1)))
;; 		      (begin
;; 			(debug:print 25 "INFO: client:setup failed to connect, start-res=" start-res ", run-id=" run-id ", host-info=" host-info)
;; 			(debug:print 25 *default-log-port* "INFO: client:setup failed to connect, start-res=" start-res ", run-id=" run-id ", host-info=" host-info)
;; 			(thread-sleep! 5)
;; 			(client:setup run-id remaining-tries: (- remaining-tries 1))))))
;; 	    ;; YUK: rename server-dat here
;; 	    (let* ((server-dat (open-run-close tasks:get-server tasks:open-db run-id)))
;; 	      (debug:print-info 0 "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
;; 	      (debug:print-info 0 *default-log-port* "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
;; 	      (if server-dat
;; 		  (let* ((iface     (tasks:hostinfo-get-interface server-dat))
;; 			 (port      (tasks:hostinfo-get-port      server-dat))
;; 			 (start-res (http-transport:client-connect iface port))
;; 			 ;; (ping-res  (server:ping-server run-id iface port))
;; 			 (ping-res  (rmt:login-no-auto-client-setup start-res run-id)))
;; 		    (if start-res
;; 			(begin
;; 			  (hash-table-set! *runremote* run-id start-res)
;; 			  start-res)
;; 			(if (member remaining-tries '(2 5))
;; 			    (begin    ;; login failed
;; 			      (debug:print 25 "INFO: client:setup start-res=" start-res ", run-id=" run-id ", server-dat=" server-dat)
;; 			      (debug:print 25 *default-log-port* "INFO: client:setup start-res=" start-res ", run-id=" run-id ", server-dat=" server-dat)
;; 			      (hash-table-delete! *runremote* run-id)
;; 			      (open-run-close tasks:server-force-clean-run-record
;; 					      tasks:open-db
;; 					      run-id 
;; 					      (tasks:hostinfo-get-interface server-dat)
;; 					      (tasks:hostinfo-get-port      server-dat)
;; 					      " client:setup (server-dat = #t)")
;; 			      (thread-sleep! 2)
;; 			      (server:try-running run-id)
;; 			      (thread-sleep! 10) ;; give server a little time to start up
;; 			      (client:setup run-id remaining-tries: 10)) ;; (- remaining-tries 1)))
;; 			    (begin
;; 			      (debug:print 25 "INFO: client:setup start-res=" start-res ", run-id=" run-id ", server-dat=" server-dat)
;; 			      (debug:print 25 *default-log-port* "INFO: client:setup start-res=" start-res ", run-id=" run-id ", server-dat=" server-dat)
;; 			      (thread-sleep! 5)
;; 			      (client:setup run-id remaining-tries: (- remaining-tries 1))))))
;; 		  (begin    ;; no server registered
;; 		    (if (eq? remaining-tries 2)
;; 			(begin
;; 			  ;; (open-run-close tasks:server-clean-out-old-records-for-run-id tasks:open-db run-id " client:setup (server-dat=#f)")
;; 			  (client:setup run-id remaining-tries: 10))
;; 			(begin
;; 			  (thread-sleep! 2) 
;; 			  (debug:print 25 "INFO: client:setup start-res (not defined here), run-id=" run-id ", server-dat=" server-dat)
;; 			  (debug:print 25 *default-log-port* "INFO: client:setup start-res (not defined here), run-id=" run-id ", server-dat=" server-dat)
;; 			  (if (< (open-run-close tasks:num-in-available-state tasks:open-db run-id) 3)
;; 			      (begin
;; 				;; (open-run-close tasks:server-clean-out-old-records-for-run-id tasks:open-db run-id " client:setup (server-dat=#f)")
;; 				(server:try-running run-id)))
;; 			  (thread-sleep! 10) ;; give server a little time to start up
;; 			  (client:setup run-id remaining-tries: (- remaining-tries 1)))))))))))

;; Do all the connection work, look up the transport type and set up the
;; connection if required.
;;
;; There are two scenarios. 
;;   1. We are a test manager and we received *transport-type* and *runremote* via cmdline
;;   2. We are a run tests, list runs or other interactive process and we must figure out
;;      *transport-type* and *runremote* from the monitor.db
;;
;; client:setup
;;
;; lookup_server, need to remove *runremote* stuff
;;
(define (client:setup-http run-id #!key (remaining-tries 10) (failed-connects 0))
  (debug:print-info 2 "client:setup remaining-tries=" remaining-tries)
  (debug:print-info 2 *default-log-port* "client:setup remaining-tries=" remaining-tries)
  (let* ((tdbdat (tasks:open-db)))
    (if (<= remaining-tries 0)
	(begin
	  (debug:print 0 "ERROR: failed to start or connect to server for run-id " run-id)
	  (debug:print-error 0 *default-log-port* "failed to start or connect to server for run-id " run-id)
	  (exit 1))
	(let* ((server-dat (tasks:get-server (db:delay-if-busy tdbdat) run-id)))
	  (debug:print-info 4 "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
	  (debug:print-info 4 *default-log-port* "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
	  (if server-dat
	      (let* ((iface     (tasks:hostinfo-get-interface server-dat))
		     (hostname  (tasks:hostinfo-get-hostname  server-dat))
		     (port      (tasks:hostinfo-get-port      server-dat))
		     (start-res (case *transport-type*
				  ((http)(http-transport:client-connect iface port))
				  ((nmsg)(nmsg-transport:client-connect hostname port))))
		     (ping-res  (case *transport-type* 
				  ((http)(rmt:login-no-auto-client-setup start-res run-id))
				  ((nmsg)(let ((logininfo (rmt:login-no-auto-client-setup start-res run-id)))
 					   (if logininfo
 					       (car (vector-ref logininfo 1))
 					       #f))))))
		(if (and start-res
			 ping-res)
		    (begin
		      (hash-table-set! *runremote* run-id start-res)
		      (debug:print-info 2 "connected to " (http-transport:server-dat-make-url start-res))
		      (debug:print-info 2 *default-log-port* "connected to " (http-transport:server-dat-make-url start-res))
		      start-res)
		    (begin    ;; login failed but have a server record, clean out the record and try again
		      (debug:print-info 0 "client:setup, login failed, will attempt to start server ... start-res=" start-res ", run-id=" run-id ", server-dat=" server-dat)
		      (debug:print-info 0 *default-log-port* "client:setup, login failed, will attempt to start server ... start-res=" start-res ", run-id=" run-id ", server-dat=" server-dat)
		      (case *transport-type* 
			((http)(http-transport:close-connections run-id)))
		      (hash-table-delete! *runremote* run-id)
		      (tasks:kill-server-run-id run-id)
		      (tasks:server-force-clean-run-record (db:delay-if-busy tdbdat)
							   run-id 
							   (tasks:hostinfo-get-interface server-dat)
							   (tasks:hostinfo-get-port      server-dat)
							   " client:setup (server-dat = #t)")
		      (if (> remaining-tries 8)
			  (thread-sleep! (+ 1 (random 5))) ;; spread out the starts a little
			  (thread-sleep! (+ 15 (random 20)))) ;; it isn't going well. give it plenty of time
		      (server:try-running run-id)
		      (thread-sleep! 5)   ;; give server a little time to start up
		      (client:setup run-id remaining-tries: (- remaining-tries 1))
		      )))
	      (begin    ;; no server registered
		(let ((num-available (tasks:num-in-available-state (db:dbdat-get-db tdbdat) run-id)))
		  (debug:print-info 0 "client:setup, no server registered, remaining-tries=" remaining-tries " num-available=" num-available)
		  (debug:print-info 0 *default-log-port* "client:setup, no server registered, remaining-tries=" remaining-tries " num-available=" num-available)
		  (if (< num-available 2)
		      (server:try-running run-id))
		  (thread-sleep! (+ 5 (random (- 20 remaining-tries))))  ;; give server a little time to start up, randomize a little to avoid start storms.
		  (client:setup run-id remaining-tries: (- remaining-tries 1)))))))))

;; keep this as a function to ease future 
(define (client:start run-id server-info)
  (http-transport:client-connect (tasks:hostinfo-get-interface server-info)
				 (tasks:hostinfo-get-port server-info)))

;; ;; client:signal-handler
;; (define (client:signal-handler signum)
;;   (signal-mask! signum)
;;   (set! *time-to-exit* #t)
;;   (handle-exceptions
;;    exn
;;    (debug:print " ... exiting ...")
;;    (debug:print 0 *default-log-port* " ... exiting ...")
;;    (let ((th1 (make-thread (lambda ()
;; 			     "") ;; do nothing for now (was flush out last call if applicable)
;; 			   "eat response"))
;; 	 (th2 (make-thread (lambda ()
;; 			     (debug:print 0 "ERROR: Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
;; 			     (debug:print-error 0 *default-log-port* "Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
;; 			     (thread-sleep! 1) ;; give the flush one second to do it's stuff
;; 			     (debug:print 0 "       Done.")
;; 			     (debug:print 0 *default-log-port* "       Done.")
;; 			     (exit 4))
;; 			   "exit on ^C timer")))
;;      (thread-start! th2)
;;      (thread-start! th1)
;;      (thread-join! th2))))
;; 
;; ;; client:launch
;; ;; Need to set the signal handler somewhere other than here as this
;; ;; routine will go away.
;; ;;
;; (define (client:launch run-id)
;;   (set-signal-handler! signal/int  client:signal-handler)
;;   (set-signal-handler! signal/term client:signal-handler)
;;   (if (client:setup run-id)
;;       (debug:print-info 2 "connected as client")
;;       (debug:print-info 2 *default-log-port* "connected as client")
;;       (begin
;; 	(debug:print 0 "ERROR: Failed to connect as client")
;; 	(debug:print-error 0 *default-log-port* "Failed to connect as client")
;; 	(exit))))
;; 

Modified common.scm from [83d9632595] to [8d88deb1b5].

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
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







-
+

-
+






+
-
-
-
+
+
+
+
+

+







+







;;       (old-exit code)))

(define getenv get-environment-variable)
(define (safe-setenv key val)
  (if (and (string? val)(string? key))
      (handle-exceptions
       exn
       (debug:print 0 "ERROR: bad value for setenv, key=" key ", value=" val)
       (debug:print-error 0 *default-log-port* "bad value for setenv, key=" key ", value=" val)
       (setenv key val))
      (debug:print 0 "ERROR: bad value for setenv, key=" key ", value=" val)))
      (debug:print-error 0 *default-log-port* "bad value for setenv, key=" key ", value=" val)))

(define home (getenv "HOME"))
(define user (getenv "USER"))

;; GLOBAL GLETCHES
(define *db-keys* #f)

(define *configinfo* #f)
(define *configdat*  #f)
(define *toppath*    #f)
(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
(define *configstatus* #f)   ;; status of data; 'fulldata : all processing done, #f : no data yet, 'partialdata : partial read done
(define *toppath*      #f)
(define *already-seen-runconfig-info* #f)

(define *waiting-queue*     (make-hash-table))
(define *test-meta-updated* (make-hash-table))
(define *globalexitstatus*  0) ;; attempt to work around possible thread issues
(define *passnum*           0) ;; when running track calls to run-tests or similar
(define *write-frequency*   (make-hash-table)) ;; run-id => (vector (current-seconds) 0))
(define *alt-log-file* #f)  ;; used by -log
(define *common:denoise*    (make-hash-table)) ;; for low noise printing
(define *default-log-port*  (current-error-port))

;; DATABASE
(define *dbstruct-db*  #f)
(define *db-stats*            (make-hash-table)) ;; hash of vectors < count duration-total >
(define *db-stats-mutex*      (make-mutex))
(define *db-sync-mutex*       (make-mutex))
(define *db-multi-sync-mutex* (make-mutex))
123
124
125
126
127
128
129






















































































130
131
132
133
134
135
136
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







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







  (set! *env-vars-by-run-id* (make-hash-table))
  (set! *test-id-cache*      (make-hash-table)))

;; Generic string database
(define sdb:qry #f) ;; (make-sdb:qry)) ;;  'init #f)
;; Generic path database
(define *fdb* #f)

;;======================================================================
;; V E R S I O N
;;======================================================================

(define (common:get-full-version)
  (conc megatest-version "-" megatest-fossil-hash))

(define (common:version-signature)
  (conc megatest-version "-" (substring megatest-fossil-hash 0 4)))

;; from metadat lookup MEGATEST_VERSION
;;
(define (common:get-last-run-version)
  (rmt:get-var "MEGATEST_VERSION"))

(define (common:set-last-run-version)
  (rmt:set-var "MEGATEST_VERSION" (common:version-signature)))

(define (common:version-changed?)
  (not (equal? (common:get-last-run-version)
	       (common:version-signature))))

;; Move me elsewhere ...
;;
(define (common:cleanup-db)
  (db:multi-db-sync 
   #f ;; do all run-ids
   ;; 'new2old
   'killservers
   'dejunk
   ;; 'adj-testids
   ;; 'old2new
   'new2old)
  (if (common:version-changed?)
      (common:set-last-run-version)))

(define (common:exit-on-version-changed)
  (if (common:version-changed?)
      (let ((mtconf (conc (get-environment-variable "MT_RUN_AREA_HOME") "/megatest.config")))
        (debug:print 0 *default-log-port*
		     "ERROR: Version mismatch!\n"
		     "   expected: " (common:version-signature) "\n"
		     "   got:      " (common:get-last-run-version))
	(if (and (file-exists? mtconf)
		 (eq? (current-user-id)(file-owner mtconf))) ;; safe to run -cleanup-db
	    (begin
	      (debug:print 0 *default-log-port* "   I see you are the owner of megatest.config, attempting to cleanup and reset to new version")
	      (handle-exceptions
	       exn
	       (begin
		 (debug:print 0 *default-log-port* "Failed to switch versions.")
		 (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
		 (print-call-chain (current-error-port))
		 (exit 1))
	       (common:cleanup-db)))
	    (begin
	      (debug:print 0 *default-log-port* " to switch versions you can run: \"megatest -cleanup-db\"")
	      (exit 1))))))

;;======================================================================
;; S P A R S E   A R R A Y S
;;======================================================================

(define (make-sparse-array)
  (let ((a (make-sparse-vector)))
    (sparse-vector-set! a 0 (make-sparse-vector))
    a))

(define (sparse-array? a)
  (and (sparse-vector? a)
       (sparse-vector? (sparse-vector-ref a 0))))

(define (sparse-array-ref a x y)
  (let ((row (sparse-vector-ref a x)))
    (if row
	(sparse-vector-ref row y)
	#f)))

(define (sparse-array-set! a x y val)
  (let ((row (sparse-vector-ref a x)))
    (if row
	(sparse-vector-set! row y val)
	(let ((new-row (make-sparse-vector)))
	  (sparse-vector-set! a x new-row)
	  (sparse-vector-set! new-row y val)))))

;;======================================================================
;; L O C K E R S   A N D   B L O C K E R S 
;;======================================================================

;; block further accesses to databases. Call this before shutting db down
(define (common:db-block-further-queries)
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
272
273
274
275
276
277
278

279
280
281
282
283
284
285
286







-
+








(define (common:read-encoded-string instr)
  (handle-exceptions
   exn
   (handle-exceptions
    exn
    (begin
      (debug:print 0 "ERROR: received bad encoded string \"" instr "\", message: " ((condition-property-accessor 'exn 'message) exn))
      (debug:print-error 0 *default-log-port* "received bad encoded string \"" instr "\", message: " ((condition-property-accessor 'exn 'message) exn))
      (print-call-chain (current-error-port))
      #f)
    (read (open-input-string (base64:base64-decode instr))))
   (read (open-input-string (z3:decode-buffer (base64:base64-decode instr))))))

;; dot-locking egg seems not to work, using this for now
;; if lock is older than expire-time then remove it and try again
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388







-
+








(define (std-exit-procedure)
  (let ((no-hurry  (if *time-to-exit* ;; hurry up
		       #f
		       (begin
			 (set! *time-to-exit* #t)
			 #t))))
    (debug:print-info 4 "starting exit process, finalizing databases.")
    (debug:print-info 4 *default-log-port* "starting exit process, finalizing databases.")
    (if (and no-hurry (debug:debug-mode 18))
	(rmt:print-db-stats))
    (let ((th1 (make-thread (lambda () ;; thread for cleaning up, give it five seconds
			      (let ((run-ids (hash-table-keys *db-local-sync*)))
				(if (and (not (null? run-ids))
					 (or (common:legacy-sync-recommended)
					     (configf:lookup *configdat* "setup" "megatest-db")))
306
307
308
309
310
311
312
313



314
315

316
317
318
319

320
321
322
323
324
325
326
327
328
329

330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
397
398
399
400
401
402
403

404
405
406
407

408
409
410
411

412
413
414
415
416
417
418
419
420
421

422
423
424
425
426
427

428
429
430
431
432
433

























434
435
436
437
438
439
440







-
+
+
+

-
+



-
+









-
+





-
+





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







				    (set! *megatest-db* #f)))
			      (if *task-db*    
				  (let ((db (cdr *task-db*)))
				    (if (sqlite3:database? db)
					(begin
					  (sqlite3:interrupt! db)
					  (sqlite3:finalize! db #t)
					  (vector-set! *task-db* 0 #f)))))) "Cleanup db exit thread"))
					  (vector-set! *task-db* 0 #f)))))
			      (close-output-port *default-log-port*)
			      (set! *default-log-port* (current-error-port))) "Cleanup db exit thread"))
	  (th2 (make-thread (lambda ()
			      (debug:print 4 "Attempting clean exit. Please be patient and wait a few seconds...")
			      (debug:print 4 *default-log-port* "Attempting clean exit. Please be patient and wait a few seconds...")
			      (if no-hurry
				  (thread-sleep! 5) ;; give the clean up few seconds to do it's stuff
				  (thread-sleep! 2))
			      (debug:print 4 " ... done")
			      (debug:print 4 *default-log-port* " ... done")
			      )
			    "clean exit")))
      (thread-start! th1)
      (thread-start! th2)
      (thread-join! th1))))

(define (std-signal-handler signum)
  ;; (signal-mask! signum)
  (set! *time-to-exit* #t)
  (debug:print 0 "ERROR: Received signal " signum " exiting promptly")
  (debug:print-error 0 *default-log-port* "Received signal " signum " exiting promptly")
  ;; (std-exit-procedure) ;; shouldn't need this since we are exiting and it will be called anyway
  (exit))

(set-signal-handler! signal/int  std-signal-handler)  ;; ^C
(set-signal-handler! signal/term std-signal-handler)
(set-signal-handler! signal/stop std-signal-handler)  ;; ^Z
;; (set-signal-handler! signal/stop std-signal-handler)  ;; ^Z NO, do NOT handle ^Z!

;;======================================================================
;; M I S C   U T I L S
;;======================================================================

;; Convert strings like "5s 2h 3m" => 60x60x2 + 3x60 + 5
(define (common:hms-string->seconds tstr)
  (let ((parts     (string-split tstr))
	(time-secs 0)
	;; s=seconds, m=minutes, h=hours, d=days
	(trx       (regexp "(\\d+)([smhd])")))
    (for-each (lambda (part)
		(let ((match  (string-match trx part)))
		  (if match
		      (let ((val (string->number (cadr match)))
			    (unt (caddr match)))
			(if val 
			    (set! time-secs (+ time-secs (* val
							    (case (string->symbol unt)
							      ((s) 1)
							      ((m) 60)
							      ((h) (* 60 60))
							      ((d) (* 24 60 60))
							      (else 0))))))))))
	      parts)
    time-secs))
		       
(define (common:version-signature)
  (conc megatest-version "-" (substring megatest-fossil-hash 0 4)))

;; one-of args defined
(define (args-defined? . param)
  (let ((res #f))
    (for-each 
     (lambda (arg)
       (if (args:get-arg arg)(set! res #t)))
     param)
381
382
383
384
385
386
387
388

389
390
391
392
393
394

395
396
397
398
399
400
401
449
450
451
452
453
454
455

456
457
458
459
460
461

462
463
464
465
466
467
468
469







-
+





-
+







   (else #f)))

(define (any->number-if-possible val)
  (let ((num (any->number val)))
    (if num num val)))

(define (patt-list-match item patts)
  (debug:print-info 8 "patt-list-match item=" item " patts=" patts)
  (debug:print-info 8 *default-log-port* "patt-list-match item=" item " patts=" patts)
  (if (and item patts)  ;; here we are filtering for matches with item patterns
      (let ((res #f))   ;; look through all the item-patts if defined, format is patt1,patt2,patt3 ... wildcard is %
	(for-each 
	 (lambda (patt)
	   (let ((modpatt (string-substitute "%" ".*" patt #t)))
	     (debug:print-info 10 "patt " patt " modpatt " modpatt)
	     (debug:print-info 10 *default-log-port* "patt " patt " modpatt " modpatt)
	     (if (string-match (regexp modpatt) item)
		 (set! res #t))))
	 (string-split patts ","))
	res)
      #t))

;; (map print (map car (hash-table->alist (read-config "runconfigs.config" #f #t))))
420
421
422
423
424
425
426








427
428
429
430
431
432
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
459
460



461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523
524
525


526
527
528
529
530
531
532

533
534


535



536
537
538
539
540



541
542
543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
558







+
+
+
+
+
+
+
+














-
+


+
+
+
+
+

-
-
+
+
+
+
+


-
+

-
-
+
-
-
-
+
+


+
-
-
-
+
+
+







-
+







   "disks" '("none" "")))

;;======================================================================
;; T A R G E T S  ,   S T A T E ,   S T A T U S ,   
;;                    R U N N A M E    A N D   T E S T P A T T
;;======================================================================

;; Lookup a value in runconfigs based on -reqtarg or -target
(define (runconfigs-get config var)
  (let ((targ (common:args-get-target))) ;; (or (args:get-arg "-reqtarg")(args:get-arg "-target")(getenv "MT_TARGET"))))
    (if targ
	(or (configf:lookup config targ var)
	    (configf:lookup config "default" var))
	(configf:lookup config "default" var))))

(define (common:args-get-state)
  (or (args:get-arg "-state")(args:get-arg ":state")))

(define (common:args-get-status)
  (or (args:get-arg "-status")(args:get-arg ":status")))

(define (common:args-get-testpatt rconf)
  (let* ((rtestpatt     (if rconf (runconfigs-get rconf "TESTPATT") #f))
	 (args-testpatt (or (args:get-arg "-testpatt")
			    (args:get-arg "-runtests")
			    "%"))
	 (testpatt    (or (and (equal? args-testpatt "%")
			       rtestpatt)
			  args-testpatt)))
    (if rtestpatt (debug:print-info 0 "TESTPATT from runconfigs: " rtestpatt))
    (if rtestpatt (debug:print-info 0 *default-log-port* "TESTPATT from runconfigs: " rtestpatt))
    testpatt))

(define (common:get-linktree)
  (or (getenv "MT_LINKTREE")
      (if *configdat*
	  (configf:lookup *configdat* "setup" "linktree"))))

(define (common:args-get-runname)
  (or (args:get-arg "-runname")
      (args:get-arg ":runname")))
  (let ((res (or (args:get-arg "-runname")
		 (args:get-arg ":runname")
		 (getenv "MT_RUNNAME"))))
    ;; (if res (set-environment-variable "MT_RUNNAME" res)) ;; not sure if this is a good idea. side effect and all ...
    res))

(define (common:args-get-target #!key (split #f))
  (let* ((keys    (keys:config-get-fields *configdat*))
  (let* ((keys    (if (hash-table? *configdat*) (keys:config-get-fields *configdat*) '()))
	 (numkeys (length keys))
	 (target  (if (args:get-arg "-reqtarg")
		      (args:get-arg "-reqtarg")
	 (target  (or (args:get-arg "-reqtarg")
		      (if (args:get-arg "-target")
			  (args:get-arg "-target")
			  (getenv "MT_TARGET"))))
		      (args:get-arg "-target")
		      (getenv "MT_TARGET")))
	 (tlist   (if target (string-split target "/" #t) '()))
	 (valid   (if target
		      (or (null? keys) ;; probably don't know our keys yet
		      (and (not (null? tlist))
			   (eq? numkeys (length tlist))
			   (null? (filter string-null? tlist)))
			  (and (not (null? tlist))
			       (eq? numkeys (length tlist))
			       (null? (filter string-null? tlist))))
		      #f)))
    (if valid
	(if split
	    tlist
	    target)
	(if target
	    (begin
	      (debug:print 0 "ERROR: Invalid target, spaces or blanks not allowed \"" target "\", target should be: " (string-intersperse keys "/"))
	      (debug:print-error 0 *default-log-port* "Invalid target, spaces or blanks not allowed \"" target "\", target should be: " (string-intersperse keys "/") ", have " tlist " for elements")
	      #f)
	    #f))))

;;======================================================================
;; M I S C   L I S T S
;;======================================================================

504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601







-
+







	(loop (max hed max-val)
	      (car tal)
	      (cdr tal))
	(max hed max-val))))


;;======================================================================
;; Munge data into nice forms
;; M U N G E   D A T A   I N T O   N I C E   F O R M S
;;======================================================================

;; Generate an index for a sparse list of key values
;;   ( (rowname1 colname1 val1)(rowname2 colname2 val2) )
;;
;; => 
;;
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552
553
554

555
556
557
558
559
560
561







562














563
564
565

566
567
568
569
570
571
572
617
618
619
620
621
622
623

624
625
626
627
628
629
630
631
632
633
634
635
636

637
638
639
640




641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664

665
666
667
668
669
670
671
672







-
+












-
+



-
-
-
-
+
+
+
+
+
+
+

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


-
+







	       (value           (caddr hed))
	       (existing-rowdat (assoc rowkey rownames))
	       (existing-coldat (assoc colkey colnames))
	       (curr-rownum     (if existing-rowdat rownum (+ rownum 1)))
	       (curr-colnum     (if existing-coldat colnum (+ colnum 1)))
	       (new-rownames    (if existing-rowdat rownames (cons (list rowkey curr-rownum) rownames)))
	       (new-colnames    (if existing-coldat colnames (cons (list colkey curr-colnum) colnames))))
	  ;; (debug:print-info 0 "Processing record: " hed )
	  ;; (debug:print-info 0 *default-log-port* "Processing record: " hed )
	  (if proc (proc curr-rownum curr-colnum rowkey colkey value))
	  (if (null? tal)
	      (list new-rownames new-colnames)
	      (loop (car tal)
		    (cdr tal)
		    new-rownames
		    new-colnames
		    (if (> curr-rownum rownum) curr-rownum rownum)
		    (if (> curr-colnum colnum) curr-colnum colnum)
		    ))))))

;;======================================================================
;; System stuff
;; S Y S T E M   S T U F F
;;======================================================================

;; return a nice clean pathname made absolute
(define (nice-path dir)
  (normalize-pathname (if (absolute-pathname? dir)
			  dir
			  (conc (current-directory) "/" dir))))
(define (common:nice-path dir)
  (let ((match (string-match "^(~[^\\/]*)(\\/.*|)$" dir)))
    (if match ;; using ~ for home?
	(common:nice-path (conc (common:read-link-f (cadr match)) "/" (caddr match)))
	(normalize-pathname (if (absolute-pathname? dir)
				dir
				(conc (current-directory) "/" dir))))))

;; make "nice-path" available in config files and the repl
(define nice-path common:nice-path)

(define (common:read-link-f path)
  (handle-exceptions
      exn
      (begin
	(debug:print-error 0 *default-log-port* "command \"/bin/readlink -f " path "\" failed.")
	path) ;; just give up
    (with-input-from-pipe
	(conc "/bin/readlink -f " path)
      (lambda ()
	(read-line)))))

(define (get-cpu-load)
  (car (common:get-cpu-load)))
;;   (let* ((load-res (cmd-run->list "uptime"))
;;   (let* ((load-res (process:cmd-run->list "uptime"))
;; 	 (load-rx  (regexp "load average:\\s+(\\d+)"))
;; 	 (cpu-load #f))
;;     (for-each (lambda (l)
;; 		(let ((match (string-search load-rx l)))
;; 		  (if match
;; 		      (let ((newval (string->number (cadr match))))
;; 			(if (number? newval)
585
586
587
588
589
590
591
592

593
594
595
596
597

598
599
600
601
602
603
604
685
686
687
688
689
690
691

692
693
694
695
696

697
698
699
700
701
702
703
704







-
+




-
+







	 (first   (car loadavg))
	 (next    (cadr loadavg))
	 (adjload (* maxload numcpus))
	 (loadjmp (- first next)))
    (cond
     ((and (> first adjload)
	   (> count 0))
      (debug:print-info 0 "waiting " waitdelay " seconds due to load " first " exceeding max of " adjload (if msg msg ""))
      (debug:print-info 0 *default-log-port* "waiting " waitdelay " seconds due to load " first " exceeding max of " adjload (if msg msg ""))
      (thread-sleep! waitdelay)
      (common:wait-for-cpuload maxload numcpus waitdelay count: (- count 1)))
     ((and (> loadjmp numcpus)
	   (> count 0))
      (debug:print-info 0 "waiting " waitdelay " seconds due to load jump " loadjmp " > numcpus " numcpus (if msg msg ""))
      (debug:print-info 0 *default-log-port* "waiting " waitdelay " seconds due to load jump " loadjmp " > numcpus " numcpus (if msg msg ""))
      (thread-sleep! waitdelay)
      (common:wait-for-cpuload maxload numcpus waitdelay count: (- count 1))))))

(define (common:get-num-cpus)
  (with-input-from-file "/proc/cpuinfo"
    (lambda ()
      (let loop ((numcpu 0)
613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
713
714
715
716
717
718
719

720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
737







-
+









-
+







;; wait for normalized cpu load to drop below maxload
;;
(define (common:wait-for-normalized-load maxload #!key (msg #f))
  (let ((num-cpus (common:get-num-cpus)))
    (common:wait-for-cpuload maxload num-cpus 15 msg: msg)))

(define (get-uname . params)
  (let* ((uname-res (cmd-run->list (conc "uname " (if (null? params) "-a" (car params)))))
  (let* ((uname-res (process:cmd-run->list (conc "uname " (if (null? params) "-a" (car params)))))
	 (uname #f))
    (if (null? (car uname-res))
	"unknown"
	(caar uname-res))))

;; for reasons I don't understand multiple calls to real-path in parallel threads
;; must be protected by mutexes
;;
(define (common:real-path inpath)
  ;; (cmd-run-with-stderr->list "readlink" "-f" inpath)) ;; cmd . params)
  ;; (process:cmd-run-with-stderr->list "readlink" "-f" inpath)) ;; cmd . params)
  ;; (let-values 
  ;;  (((inp oup pid) (process "readlink" (list "-f" inpath))))
  ;;  (with-input-from-port inp
  ;;    (let loop ((inl (read-line))
  ;;       	(res #f))
  ;;      (print "inl=" inl)
  ;;      (if (eof-object? inl)
646
647
648
649
650
651
652



653










654

655
656
657
658
659
660
661
662
663
664
665





























666
667
668
669
670
671
672
673
674
675
676
677
678


679
680
681
682


683
684
685
686


687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705






706
707
708
709
710
711
712
713
714
715
716
717

718
719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766

767
768
769
770
771
772
773
774
775
776
777
778
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
816
817
818


819
820
821
822


823
824
825
826


827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
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







+
+
+

+
+
+
+
+
+
+
+
+
+
-
+











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











-
-
+
+


-
-
+
+


-
-
+
+


















-
+
+
+
+
+
+











-
+












-
+







;;======================================================================
;; D I S K   S P A C E 
;;======================================================================

(define (common:get-disk-space-used fpath)
  (with-input-from-pipe (conc "/usr/bin/du -s " fpath) read))

;; given path get free space, allows override in [setup]
;; with free-space-script /path/to/some/script.sh
;;
(define (get-df path)
  (if (configf:lookup *configdat* "setup" "free-space-script")
      (with-input-from-pipe 
       (conc (configf:lookup *configdat* "setup" "free-space-script") " " path)
       (lambda ()
	 (let ((res (read-line)))
	   (if (string? res)
	       (string->number res)))))
      (get-unix-df path)))

(define (get-unix-df path)
  (let* ((df-results (cmd-run->list (conc "df " path)))
  (let* ((df-results (process:cmd-run->list (conc "df " path)))
	 (space-rx   (regexp "([0-9]+)\\s+([0-9]+)%"))
	 (freespc    #f))
    ;; (write df-results)
    (for-each (lambda (l)
		(let ((match (string-search space-rx l)))
		  (if match 
		      (let ((newval (string->number (cadr match))))
			(if (number? newval)
			    (set! freespc newval))))))
	      (car df-results))
    freespc))

;; check space in dbdir
;; returns: ok/not dbspace required-space
;;
(define (common:check-db-dir-space)
  (let* ((dbdir    (db:get-dbdir))
	 (dbspace  (if (directory? dbdir)
		       (get-df dbdir)
		       0))
	 (required (string->number 
		    (or (configf:lookup *configdat* "setup" "dbdir-space-required")
			"100000"))))
    (list (> dbspace required)
	  dbspace
	  required
	  dbdir)))

;; check available space in dbdir, exit if insufficient
;;
(define (common:check-db-dir-and-exit-if-insufficient)
  (let* ((spacedat (common:check-db-dir-space))
	 (is-ok    (car spacedat))
	 (dbspace  (cadr spacedat))
	 (required (caddr spacedat))
	 (dbdir    (cadddr spacedat)))
    (if (not is-ok)
	(begin
	  (debug:print-error 0 *default-log-port* "Insufficient space in " dbdir ", require " required ", have " dbspace  ", exiting now.")
	  (exit 1)))))
  
;; paths is list of lists ((name path) ... )
;;
(define (common:get-disk-with-most-free-space disks minsize)
  (let ((best     #f)
	(bestsize 0))
    (for-each 
     (lambda (disk-num)
       (let* ((dirpath    (cadr (assoc disk-num disks)))
	      (freespc    (cond
			   ((not (directory? dirpath))
			    (if (common:low-noise-print 50 "disks not a dir " disk-num)
				(debug:print 0 "WARNING: disk " disk-num " at path \"" dirpath "\" is not a directory - ignoring it."))
			    (if (common:low-noise-print 300 "disks not a dir " disk-num)
				(debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not a directory - ignoring it."))
			    -1)
			   ((not (file-write-access? dirpath))
			    (if (common:low-noise-print 50 "disks not writeable " disk-num)
				(debug:print 0 "WARNING: disk " disk-num " at path \"" dirpath "\" is not writeable - ignoring it."))
			    (if (common:low-noise-print 300 "disks not writeable " disk-num)
				(debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not writeable - ignoring it."))
			    -1)
			   ((not (eq? (string-ref dirpath 0) #\/))
			    (if (common:low-noise-print 50 "disks not a proper path " disk-num)
				(debug:print 0 "WARNING: disk " disk-num " at path \"" dirpath "\" is not a fully qualified path - ignoring it."))
			    (if (common:low-noise-print 300 "disks not a proper path " disk-num)
				(debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not a fully qualified path - ignoring it."))
			    -1)
			   (else
			    (get-df dirpath)))))
	 (if (> freespc bestsize)
	     (begin
	       (set! best     (cons disk-num dirpath))
	       (set! bestsize freespc)))))
     (map car disks))
    (if (and best (> bestsize minsize))
	best
	#f))) ;; #f means no disk candidate found

;;======================================================================
;; E N V I R O N M E N T   V A R S
;;======================================================================
	      
(define (save-environment-as-files fname #!key (ignorevars (list "USER" "HOME" "DISPLAY" "LS_COLORS" "XKEYSYMDB" "EDITOR" "MAKEFLAGS" "MAKEF" "MAKEOVERRIDES")))
  (let ((envvars (get-environment-variables))
        (whitesp (regexp "[^a-zA-Z0-9_\\-:,.\\/%$]")))
        (whitesp (regexp "[^a-zA-Z0-9_\\-:,.\\/%$]"))
	(mungeval (lambda (val)
		    (cond
		     ((eq? val #t) "") ;; convert #t to empty string
		     ((eq? val #f) #f) ;; convert #f to itself (still thinking about this one
		     (else val)))))
     (with-output-to-file (conc fname ".csh")
       (lambda ()
          (for-each (lambda (keyval)
		      (let* ((key   (car keyval))
			     (val   (cdr keyval))
			     (delim (if (string-search whitesp val) 
					"\""
					"")))
			(print (if (member key ignorevars)
				   "# setenv "
				   "setenv ")
			       key " " delim val delim)))
			       key " " delim (mungeval val) delim)))
		    envvars)))
     (with-output-to-file (conc fname ".sh")
       (lambda ()
          (for-each (lambda (keyval)
		      (let* ((key (car keyval))
			     (val (cdr keyval))
			     (delim (if (string-search whitesp val) 
					"\""
					"")))
			(print (if (member key ignorevars)
				   "# export "
				   "export ")
			       key "=" delim val delim)))
			       key "=" delim (mungeval val) delim)))
                    envvars)))))

;; set some env vars from an alist, return an alist with original values
;; (("VAR" "value") ...)
(define (alist->env-vars lst)
  (if (list? lst)
      (let ((res '()))
768
769
770
771
772
773
774
775








776
777

778
779






















780
781
782
783
784
785
786
915
916
917
918
919
920
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







-
+
+
+
+
+
+
+
+

-
+


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







     ((string? proc)(system proc))
     (proc          (proc)))
    (hash-table-for-each
     vars
     (lambda (var val)
       (setenv var val)))
    vars))
		  

(define (common:run-a-command cmd)
  (let ((fullcmd  (conc (dtests:get-pre-command)
			cmd 
			(dtests:get-post-command))))
    (debug:print-info 02 *default-log-port* "Running command: " fullcmd)
    (common:without-vars fullcmd "MT_.*")))
		  
;;======================================================================
;; time and date nice to have stuff
;; T I M E   A N D   D A T E
;;======================================================================

;; Convert strings like "5s 2h 3m" => 60x60x2 + 3x60 + 5
(define (common:hms-string->seconds tstr)
  (let ((parts     (string-split tstr))
	(time-secs 0)
	;; s=seconds, m=minutes, h=hours, d=days
	(trx       (regexp "(\\d+)([smhd])")))
    (for-each (lambda (part)
		(let ((match  (string-match trx part)))
		  (if match
		      (let ((val (string->number (cadr match)))
			    (unt (caddr match)))
			(if val 
			    (set! time-secs (+ time-secs (* val
							    (case (string->symbol unt)
							      ((s) 1)
							      ((m) 60)
							      ((h) (* 60 60))
							      ((d) (* 24 60 60))
							      (else 0))))))))))
	      parts)
    time-secs))
		       
(define (seconds->hr-min-sec secs)
  (let* ((hrs (quotient secs 3600))
	 (min (quotient (- secs (* hrs 3600)) 60))
	 (sec (- secs (* hrs 3600)(* min 60))))
    (conc (if (> hrs 0)(conc hrs "hr ") "")
	  (if (> min 0)(conc min "m ")  "")
	  sec "s")))
799
800
801
802
803
804
805




806

807
808
809
810
811
812
813
814
815
816
817
818




































819
820

821
822
823
824
825
826
827
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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042
1043







+
+
+
+
-
+












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

-
+








(define (seconds->year-work-week/day sec)
  (time->string
   (seconds->local-time sec) "%yww%V.%w"))

(define (seconds->year-work-week/day-time sec)
  (time->string
   (seconds->local-time sec) "%Yww%V.%w %H:%M"))

(define (seconds->year-week/day-time sec)
  (time->string
   (seconds->local-time sec) "%yww%V.%w %H:%M"))
   (seconds->local-time sec) "%Yw%V.%w %H:%M"))

(define (seconds->quarter sec)
  (case (string->number
	 (time->string 
	  (seconds->local-time sec)
	  "%m"))
    ((1 2 3) 1)
    ((4 5 6) 2)
    ((7 8 9) 3)
    ((10 11 12) 4)
    (else #f)))

;; given span of seconds tstart to tend
;; find start time to mark and mark delta
;;
(define (common:find-start-mark-and-mark-delta tstart tend)
  (let* ((deltat   (- (max tend (+ tend 10)) tstart)) ;; can't handle runs of less than 4 seconds. Pad it to 10 seconds ...
	 (result   #f)
	 (min      60)
	 (hr       (* 60 60))
	 (day      (* 24 hr))
	 (yr       (* 365 day)) ;; year
	 (mo       (/ yr 12))
	 (wk       (* day 7)))
    (for-each
     (lambda (max-blks)
       (for-each
	(lambda (span) ;; 5 2 1
	  (if (not result)
	      (for-each 
	       (lambda (timeunit timesym) ;; year month day hr min sec
		 (if (not result)
		     (let* ((time-blk (* span timeunit))
			    (num-blks (quotient deltat time-blk)))
		       (if (and (> num-blks 4)(< num-blks max-blks))
			   (let ((first (* (quotient tstart time-blk) time-blk)))
			     (set! result (list span timeunit time-blk first timesym))
			     )))))
	       (list yr mo wk day hr min 1)
	       '(     y  mo w  d   h  m   s))))
	(list 8 6 5 2 1)))
     '(5 10 15 20 30 40 50 500))
    (if values
	(apply values result)
	(values 0 day 1 0 'd))))
	    
	  

;;======================================================================
;; Colors
;; C O L O R S
;;======================================================================
      
(define (common:name->iup-color name)
  (case (string->symbol (string-downcase name))
    ((red)    "223 33 49")
    ((grey)   "192 192 192")
    ((orange) "255 172 13")
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1082
1083
1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299







-
+




-
+









	      fallback-launcher
	      (let loop ((hed (car launchers))
			 (tal (cdr launchers)))
		(let ((patt      (car hed))
		      (host-type (cadr hed)))
		  (if (tests:match patt testname itempath)
		      (begin
			(debug:print-info 0 "Have flexi-launcher match for " testname "/" itempath " = " host-type)
			(debug:print-info 2 *default-log-port* "Have flexi-launcher match for " testname "/" itempath " = " host-type)
			(let ((launcher (configf:lookup configdat "host-types" host-type)))
			  (if launcher
			      launcher
			      (begin
				(debug:print-info 0 "WARNING: no launcher found for host-type " host-type)
				(debug:print-info 0 *default-log-port* "WARNING: no launcher found for host-type " host-type)
				(if (null? tal)
				    fallback-launcher
				    (loop (car tal)(cdr tal)))))))
		      ;; no match, try again
		      (if (null? tal)
			  fallback-launcher
			  (loop (car tal)(cdr tal))))))))
	fallback-launcher)))
  

Modified common_records.scm from [b04cfb11d1] to [a408794bcc].

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31














32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54












+
+



















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







;;======================================================================
;; Copyright 2006-2012, Matthew Welland.
;; 
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;; 
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.
;;======================================================================

;; (use trace)

(include "altdb.scm")

;; Some of these routines use:
;;
;;     http://www.cs.toronto.edu/~gfb/scheme/simple-macros.html
;;
;; Syntax for defining macros in a simple style similar to function definiton,
;;  when there is a single pattern for the argument list and there are no keywords.
;;
;; (define-simple-syntax (name arg ...) body ...)
;;

(define-syntax define-simple-syntax
  (syntax-rules ()
    ((_ (name arg ...) body ...)
     (define-syntax name (syntax-rules () ((name arg ...) (begin body ...)))))))

(define-syntax common:handle-exceptions
  (syntax-rules ()
    ((_ exn-in errstmt ...)(handle-exceptions exn-in errstmt ...))))

;; iup callbacks are not dumping the stack, this is a work-around
;;
(define-simple-syntax (debug:catch-and-dump proc procname)
  (handle-exceptions
   exn
   (begin
     (print-call-chain (current-error-port))
     (with-output-to-port (current-error-port)
       (lambda ()
	 (print ((condition-property-accessor 'exn 'message) exn))
	 (print "Callback error in " procname)
	 (print "Full condition info:\n" (condition->list exn)))))
   (proc)))

(define (debug:calc-verbosity vstr)
  (cond
   ((number? vstr) vstr)
   ((not (string?  vstr))   1)
   ;; ((string-match  "^\\s*$" vstr) 1)
   (vstr           (let ((debugvals  (filter number? (map string->number (string-split vstr ",")))))
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
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







+
+
+
+
+
+
+
+

-
+
+

-
+




-
-
+
+
+
+
+
+
+
+

-
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+






    (if (not *verbosity*)(set! *verbosity* 1))
    (if (or (args:get-arg "-debug")
	    (not (getenv "MT_DEBUG_MODE")))
	(setenv "MT_DEBUG_MODE" (if (list? *verbosity*)
				    (string-intersperse (map conc *verbosity*) ",")
				    (conc *verbosity*))))))
  
(define (debug:print n e . params)
  (if (debug:debug-mode n)
      (with-output-to-port (or e (current-error-port))
	(lambda ()
	  (if *logging*
	      (db:log-event (apply conc params))
	      (apply print params)
	      )))))

(define (debug:print n . params)
(define (debug:print-error n e . params)
  ;; normal print
  (if (debug:debug-mode n)
      (with-output-to-port (current-error-port)
      (with-output-to-port (or e (current-error-port))
	(lambda ()
	  (if *logging*
	      (db:log-event (apply conc params))
	      ;; (apply print "pid:" (current-process-id) " " params)
	      (apply print params)
	      )))))
	      (apply print "ERROR: " params)
	      ))))
  ;; pass important messages to stderr
  (if (and (eq? n 0)(not (eq? e (current-error-port)))) 
      (with-output-to-port (current-error-port)
	(lambda ()
	  (apply print "ERROR: " params)
	  ))))

(define (debug:print-info n . params)
(define (debug:print-info n e . params)
  (if (debug:debug-mode n)
      (with-output-to-port (current-error-port)
      (with-output-to-port (or e (current-error-port))
	(lambda ()
	  (let ((res (format#format #f "INFO: (~a) ~a" n (apply conc params))))
	    (if *logging*
		(db:log-event res)
		;; (apply print "pid:" (current-process-id) " " "INFO: (" n ") " params) ;; res)
		(apply print "INFO: (" n ") " params) ;; res)
		))))))
	  (if *logging*
	      (let ((res (format#format #f "INFO: (~a) ~a" n (apply conc params))))
		(db:log-event res))
	      ;; (apply print "pid:" (current-process-id) " " "INFO: (" n ") " params) ;; res)
	      (apply print "INFO: (" n ") " params) ;; res)
	      )))))

;; if a value is printable (i.e. string or number) return the value
;; else return an empty string
(define-inline (printable val)
  (if (or (number? val)(string? val)) val ""))

Modified configf.scm from [6f6eea6687] to [d9393dba52].

9
10
11
12
13
14
15
16

17
18
19


20
21
22
23
24
25
26
9
10
11
12
13
14
15

16
17


18
19
20
21
22
23
24
25
26







-
+

-
-
+
+







;;  PURPOSE.
;;======================================================================

;;======================================================================
;; Config file handling
;;======================================================================

(use regex regex-case directory-utils)
(use regex regex-case) ;;  directory-utils)
(declare (unit configf))
(declare (uses common))
(declare (uses process))
(declare (uses process))
(declare (uses env))

(include "common_records.scm")

;; return list (path fullpath configname)
(define (find-config configname #!key (toppath #f))
  (if toppath
      (let ((cfname (conc toppath "/" configname)))
44
45
46
47
48
49
50
51

52
53

54
55
56
57
58
59
60
44
45
46
47
48
49
50

51
52

53
54
55
56
57
58
59
60







-
+

-
+







			       (list key val metadata)
			       (list key val))))))

(define (config:eval-string-in-environment str)
  (handle-exceptions
   exn
   (begin
     (debug:print 0 "ERROR: problem evaluating \"" str "\" in the shell environment")
     (debug:print-error 0 *default-log-port* "problem evaluating \"" str "\" in the shell environment")
     #f)
   (let ((cmdres (cmd-run->list (conc "echo " str))))
   (let ((cmdres (process:cmd-run->list (conc "echo " str))))
     (if (null? cmdres) ""
	 (caar cmdres)))))

;;======================================================================
;; Make the regexp's needed globally available
;;======================================================================

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
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







-
+
+
+











-
-
+
+






-
+






-
+







-
-
-
-
-
-
-
-







				((runconfigs-get) (conc "(lambda (ht)(runconfigs-get ht \"" cmd "\"))"))
				((rget)           (conc "(lambda (ht)(runconfigs-get ht \"" cmd "\"))"))
				(else "(lambda (ht)(print \"ERROR\") \"ERROR\")"))))
		;; (print "fullcmd=" fullcmd)
		(handle-exceptions
		 exn
		 (begin
		   (debug:print 0 "WARNING: failed to process config input \"" l "\"")
		   (debug:print 0 *default-log-port* "WARNING: failed to process config input \"" l "\"")
		   (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
		   ;; (print "exn=" (condition->list exn))
		   (set! result (conc "#{( " cmdtype ") " cmd"}")))
		 (if (or allow-system
			 (not (member cmdtype '("system" "shell"))))
		     (with-input-from-string fullcmd
		       (lambda ()
			 (set! result ((eval (read)) ht))))
		    (set! result (conc "#{(" cmdtype ") "  cmd "}"))))
		(case cmdsym
		  ((system shell scheme)
		   (let ((delta (- (current-seconds) start-time)))
		     (if (> delta 2)
			 (debug:print-info 0 "for line \"" l "\"\n command:  " cmd " took " delta " seconds to run with output:\n   " result)
			 (debug:print-info 9 "for line \"" l "\"\n command:  " cmd " took " delta " seconds to run with output:\n   " result)))))
			 (debug:print-info 0 *default-log-port* "for line \"" l "\"\n command:  " cmd " took " delta " seconds to run with output:\n   " result)
			 (debug:print-info 9 *default-log-port* "for line \"" l "\"\n command:  " cmd " took " delta " seconds to run with output:\n   " result)))))
		(loop (conc prestr result poststr)))
	      res))
	res)))

;; Run a shell command and return the output as a string
(define (shell cmd)
  (let* ((output (cmd-run->list cmd))
  (let* ((output (process:cmd-run->list cmd))
	 (res    (car output))
	 (status (cadr output)))
    (if (equal? status 0)
	(let ((outres (string-intersperse 
		       res
		       "\n")))
	  (debug:print-info 4 "shell result:\n" outres)
	  (debug:print-info 4 *default-log-port* "shell result:\n" outres)
	  outres)
	(begin
	  (with-output-to-port (current-error-port)
	    (lambda ()
	      (print "ERROR: " cmd " returned bad exit code " status)))
	  ""))))

;; Lookup a value in runconfigs based on -reqtarg or -target
(define (runconfigs-get config var)
  (let ((targ (common:args-get-target))) ;; (or (args:get-arg "-reqtarg")(args:get-arg "-target")(getenv "MT_TARGET"))))
    (if targ
	(or (configf:lookup config targ var)
	    (configf:lookup config "default" var))
	(configf:lookup config "default" var))))

;; this was inline but I'm pretty sure that is a hold over from when it was *very* simple ...
;;
(define (configf:read-line p ht allow-processing settings)
  (let loop ((inl (read-line p)))
    (let ((cont-line (and (string? inl)
			  (not (string-null? inl))
			  (equal? "\\" (string-take-right inl 1)))))
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308



309
310

311
312
313
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
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

295





296
297
298
299
300
301
302
303
304
305
306
307
308



309
310
311
312

313
314
315
316
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331







-
+
+
+
+
+
+
+
+










-
-
+
+


-
+







-
+



-
+




-
+



-
-
+
+


-
+



-
+







-
+


-
+

-
-
-
+
+
+









-
+





-
+



-
+



-
+


-
+


-
-
+
+






-
+




-
-
+
+
+
+
+
+
+
+
+





-
+

-
+


-
+
-
-
-
-
-













-
-
-
+
+
+

-
+










-
+







			inl)
		       (else
			(configf:process-line inl ht allow-processing)))))
	    (if (and (string? res)
		     (not (equal? (hash-table-ref/default settings "trim-trailing-spaces" "no") "no")))
		(string-substitute "\\s+$" "" res)
		res))))))
      
  
(define (calc-allow-system allow-system section sections)
  (if sections
      (and (or (equal? "default" section)
	       (member section sections))
	   allow-system) ;; account for sections and return allow-system as it might be a symbol such as return-strings
      allow-system))
    
;; read a config file, returns hash table of alists

;; read a config file, returns hash table of alists
;; adds to ht if given (must be #f otherwise)
;; envion-patt is a regex spec that identifies sections that will be eval'd
;; in the environment on the fly
;; sections: #f => get all, else list of sections to gather
;; post-section-procs alist of section-pattern => proc, where: (proc section-name next-section-name ht curr-path)
;;
(define (read-config path ht allow-system #!key (environ-patt #f)(curr-section #f)(sections #f)(settings (make-hash-table))(keep-filenames #f)(post-section-procs '()))
  (debug:print-info 5 "read-config " path " allow-system " allow-system " environ-patt " environ-patt " curr-section: " curr-section " sections: " sections " pwd: " (current-directory))
  (debug:print 9 "START: " path)
  (debug:print-info 5 *default-log-port* "read-config " path " allow-system " allow-system " environ-patt " environ-patt " curr-section: " curr-section " sections: " sections " pwd: " (current-directory))
  (debug:print 9 *default-log-port* "START: " path)
  (if (not (file-exists? path))
      (begin 
	(debug:print-info 1 "read-config - file not found " path " current path: " (current-directory))
	(debug:print-info 1 *default-log-port* "read-config - file not found " path " current path: " (current-directory))
	;; WARNING: This is a risky change but really, we should not return an empty hash table if no file read?
	#f) ;; (if (not ht)(make-hash-table) ht))
      (let ((inp        (open-input-file path))
	    (res        (if (not ht)(make-hash-table) ht))
	    (metapath   (if (or (debug:debug-mode 9)
				keep-filenames)
			    path #f)))
	(let loop ((inl               (configf:read-line inp res allow-system settings)) ;; (read-line inp))
	(let loop ((inl               (configf:read-line inp res (calc-allow-system allow-system curr-section sections) settings)) ;; (read-line inp))
		   (curr-section-name (if curr-section curr-section "default"))
		   (var-flag #f);; turn on for key-var-pr and cont-ln-rx, turn off elsewhere
		   (lead     #f))
	  (debug:print-info 8 "curr-section-name: " curr-section-name " var-flag: " var-flag "\n   inl: \"" inl "\"")
	  (debug:print-info 8 *default-log-port* "curr-section-name: " curr-section-name " var-flag: " var-flag "\n   inl: \"" inl "\"")
	  (if (eof-object? inl) 
	      (begin
		(close-input-port inp)
		(hash-table-delete! res "") ;; we are using "" as a dumping ground and must remove it before returning the ht
		(debug:print 9 "END: " path)
		(debug:print 9 *default-log-port* "END: " path)
		res)
	      (regex-case 
	       inl 
	       (configf:comment-rx _                  (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f))
	       (configf:blank-l-rx _                  (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f))
	       (configf:comment-rx _                  (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f))
	       (configf:blank-l-rx _                  (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f))
	       (configf:settings   ( x setting val  ) (begin
							(hash-table-set! settings setting val)
							(loop (configf:read-line inp res allow-system settings) curr-section-name #f #f)))
							(loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f)))
	       (configf:include-rx ( x include-file ) (let* ((curr-conf-dir (pathname-directory path))
							     (full-conf     (if (absolute-pathname? include-file)
										include-file
										(nice-path 
										(common:nice-path 
										 (conc (if curr-conf-dir
											   curr-conf-dir
											   ".")
										       "/" include-file)))))
							(if (file-exists? full-conf)
							    (begin
							      ;; (push-directory conf-dir)
							      (debug:print 9 "Including: " full-conf)
							      (debug:print 9 *default-log-port* "Including: " full-conf)
							      (read-config full-conf res allow-system environ-patt: environ-patt curr-section: curr-section-name sections: sections settings: settings keep-filenames: keep-filenames)
							      ;; (pop-directory)
							      (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f))
							      (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f))
							    (begin
							      (debug:print '(2 9) "INFO: include file " include-file " not found (called from " path ")")
							      (debug:print 2 "        " full-conf)
							      (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f)))))
							      (debug:print '(2 9) #f "INFO: include file " include-file " not found (called from " path ")")
							      (debug:print 2 *default-log-port* "        " full-conf)
							      (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f)))))
	       (configf:section-rx ( x section-name ) (begin
							;; call post-section-procs
							(for-each 
							 (lambda (dat)
							   (let ((patt (car dat))
								 (proc (cdr dat)))
							     (if (string-match patt curr-section-name)
								 (proc curr-section-name section-name res path))))
							 post-section-procs)
							(loop (configf:read-line inp res allow-system settings)
							(loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings)
							      ;; if we have the sections list then force all settings into "" and delete it later?
							      (if (or (not sections) 
								      (member section-name sections))
								  section-name "") ;; stick everything into ""
							      #f #f)))
	       (configf:key-sys-pr ( x key cmd      ) (if allow-system
	       (configf:key-sys-pr ( x key cmd      ) (if (calc-allow-system allow-system curr-section-name sections)
							  (let ((alist    (hash-table-ref/default res curr-section-name '()))
								(val-proc (lambda ()
									    (let* ((start-time (current-seconds))
										   (cmdres     (cmd-run->list cmd))
										   (cmdres     (process:cmd-run->list cmd))
										   (delta      (- (current-seconds) start-time))
										   (status     (cadr cmdres))
										   (res        (car  cmdres)))
									      (debug:print-info 4 "" inl "\n => " (string-intersperse res "\n"))
									      (debug:print-info 4 *default-log-port* "" inl "\n => " (string-intersperse res "\n"))
									      (if (not (eq? status 0))
										  (begin
										    (debug:print 0 "ERROR: problem with " inl ", return code " status
										    (debug:print-error 0 *default-log-port* "problem with " inl ", return code " status
												 " output: " cmdres)))
									      (if (> delta 2)
										  (debug:print-info 0 "for line \"" inl "\"\n  command: " cmd " took " delta " seconds to run with output:\n   " res)
										  (debug:print-info 9 "for line \"" inl "\"\n  command: " cmd " took " delta " seconds to run with output:\n   " res))
										  (debug:print-info 0 *default-log-port* "for line \"" inl "\"\n  command: " cmd " took " delta " seconds to run with output:\n   " res)
										  (debug:print-info 9 *default-log-port* "for line \"" inl "\"\n  command: " cmd " took " delta " seconds to run with output:\n   " res))
									      (if (null? res)
										  ""
										  (string-intersperse res " "))))))
							    (hash-table-set! res curr-section-name 
									     (config:assoc-safe-add alist
									   			    key 
												    (case allow-system
												    (case (calc-allow-system allow-system curr-section-name sections)
												      ((return-procs) val-proc)
												      ((return-string) cmd)
												      (else (val-proc)))
												    metadata: metapath))
							    (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f))
							  (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f)))
							    (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f))
							  (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f)))
	       (configf:key-no-val ( x key val)            (let* ((alist   (hash-table-ref/default res curr-section-name '()))
								  (fval    (or (if (string? val) val #f) ""))) ;; fval should be either "" or " " (one or more spaces)
							     (debug:print 10 *default-log-port* "   setting: [" curr-section-name "] " key " = #t")
							     (safe-setenv key fval)
							     (hash-table-set! res curr-section-name 
									      (config:assoc-safe-add alist key fval metadata: metapath))
							     (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name key #f)))
	       (configf:key-val-pr ( x key unk1 val unk2 ) (let* ((alist   (hash-table-ref/default res curr-section-name '()))
								  (envar   (and environ-patt (string-search (regexp environ-patt) curr-section-name)))
								  (realval (if envar
									       (config:eval-string-in-environment val)
									       val)))
							     (debug:print-info 6 "read-config env setting, envar: " envar " realval: " realval " val: " val " key: " key " curr-section-name: " curr-section-name)
							     (debug:print-info 6 *default-log-port* "read-config env setting, envar: " envar " realval: " realval " val: " val " key: " key " curr-section-name: " curr-section-name)
							     (if envar (safe-setenv key realval))
							     (debug:print 10 "   setting: [" curr-section-name "] " key " = " val)
							     (debug:print 10 *default-log-port* "   setting: [" curr-section-name "] " key " = " val)
							     (hash-table-set! res curr-section-name 
									      (config:assoc-safe-add alist key realval metadata: metapath))
							     (loop (configf:read-line inp res allow-system settings) curr-section-name key #f)))
							     (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name key #f)))
	       (configf:key-no-val ( x key val)             (let* ((alist   (hash-table-ref/default res curr-section-name '())))
							      (debug:print 10 "   setting: [" curr-section-name "] " key " = #t")
							      (hash-table-set! res curr-section-name 
									       (config:assoc-safe-add alist key #t metadata: metapath))
							      (loop (configf:read-line inp res allow-system settings) curr-section-name key #f)))
	       ;; if a continued line
	       (configf:cont-ln-rx ( x whsp val     ) (let ((alist (hash-table-ref/default res curr-section-name '())))
						(if var-flag             ;; if set to a string then we have a continued var
						    (let ((newval (conc 
								   (config-lookup res curr-section-name var-flag) "\n"
								   ;; trim lead from the incoming whsp to support some indenting.
								   (if lead
								       (string-substitute (regexp lead) "" whsp)
								       "")
								   val)))
						      ;; (print "val: " val "\nnewval: \"" newval "\"\nvarflag: " var-flag)
						      (hash-table-set! res curr-section-name 
								       (config:assoc-safe-add alist var-flag newval metadata: metapath))
						      (loop (configf:read-line inp res allow-system settings) curr-section-name var-flag (if lead lead whsp)))
						    (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f))))
	       (else (debug:print 0 "ERROR: problem parsing " path ",\n   \"" inl "\"")
						      (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name var-flag (if lead lead whsp)))
						    (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f))))
	       (else (debug:print-error 0 *default-log-port* "problem parsing " path ",\n   \"" inl "\"")
		     (set! var-flag #f)
		     (loop (configf:read-line inp res allow-system settings) curr-section-name #f #f))))))))
		     (loop (configf:read-line inp res (calc-allow-system allow-system curr-section-name sections) settings) curr-section-name #f #f))))))))
  
;; pathenvvar will set the named var to the path of the config
(define (find-and-read-config fname #!key (environ-patt #f)(given-toppath #f)(pathenvvar #f))
  (let* ((curr-dir   (current-directory))
         (configinfo (find-config fname toppath: given-toppath))
	 (toppath    (car configinfo))
	 (configfile (cadr configinfo))
	 (set-fields (lambda (curr-section next-section ht path)
		       (let ((field-names (if ht (keys:config-get-fields ht) '()))
			     (target      (or (getenv "MT_TARGET")(args:get-arg "-reqtarg")(args:get-arg "-target"))))
			 (debug:print-info 9 "set-fields with field-names=" field-names " target=" target " curr-section=" curr-section " next-section=" next-section " path=" path " ht=" ht)
			 (debug:print-info 9 *default-log-port* "set-fields with field-names=" field-names " target=" target " curr-section=" curr-section " next-section=" next-section " path=" path " ht=" ht)
			 (if (not (null? field-names))(keys:target-set-args field-names target #f))))))
    (if toppath (change-directory toppath)) 
    (if (and toppath pathenvvar)(setenv pathenvvar toppath))
    (let ((configdat  (if configfile 
			  (read-config configfile #f #t environ-patt: environ-patt post-section-procs: (list (cons "^fields$" set-fields)) #f))))
      (if toppath (change-directory curr-dir))
      (list configdat toppath configfile fname))))
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365







-
+







	'()
	(map car sectdat))))

(define (configf:get-section cfgdat section)
  (hash-table-ref/default cfgdat section '()))

(define (setup)
  (let* ((configf (find-config))
  (let* ((configf (find-config "megatest.config"))
	 (config  (if configf (read-config configf #f #t) #f)))
    (if config
	(setenv "RUN_AREA_HOME" (pathname-directory configf)))
    config))

;;======================================================================
;; Non destructive writing of config file
463
464
465
466
467
468
469
470

471
472

473
474
475
476
477
478
479
466
467
468
469
470
471
472

473
474

475
476
477
478
479
480
481
482







-
+

-
+







			   (set! res (append res (list hed))))
			  ((not newval) ;; key has been removed
			   (set! new #f))
			  ((not (equal? newval val))
			     (hash-table-set! sechash key newval)
			     (set! new (conc key " " newval)))
			  (else
			   (debug:print 0 "ERROR: problem parsing line number " lnum "\"" hed "\"")))))
			   (debug:print-error 0 *default-log-port* "problem parsing line number " lnum "\"" hed "\"")))))
	   (else
	    (debug:print 0 "ERROR: Problem parsing line num " lnum " :\n   " hed )))
	    (debug:print-error 0 *default-log-port* "Problem parsing line num " lnum " :\n   " hed )))
	  (if (not (null? tal))
	      (loop (car tal)(cdr tal)(if new (append res (list new)) res)(+ lnum 1)))
	  ;; drop to here when done processing, res contains modified list of lines
	  (set! fdat res)))

    ;; step 4: Append new values to the section
    (for-each 

Modified dashboard-tests.scm from [f8dc64a39c] to [c2ec614a7f].

233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247







-
+







	    )))))

;; if there is a submegatest create a button to launch dashboard in that area
;;
(define (submegatest-panel dbstruct keydat testdat runname testconfig)
  (let* ((subarea (configf:lookup testconfig "setup" "submegatest"))
	 (area-exists (and subarea (file-exists? subarea))))
    (debug:print-info 0 "Megatest subarea=" subarea ", area-exists=" area-exists)
    ;; (debug:print-info 0 *default-log-port* "Megatest subarea=" subarea ", area-exists=" area-exists)
    (if subarea
	(iup:frame 
	 #:title "Megatest Run Info" ; #:expand "YES"
	 (iup:button
	  "Launch Dashboard"
	  #:action (lambda (obj)
		     (system (conc "cd " subarea ";env -i PATH=$PATH DISPLAY=$DISPLAY HOME=$HOME USER=$USER dashboard &")))))
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446

447
448
449
450
451
452
453
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
+
















-
+







					   local: #t))
	 (testdat        (rmt:get-test-info-by-id run-id test-id)) ;; (db:get-test-info-by-id dbstruct run-id test-id))
	 (db-mod-time   0) ;; (file-modification-time db-path))
	 (last-update   0) ;; (current-seconds))
	 (request-update #t))
    (if (not testdat)
	(begin
	  (debug:print 2 "ERROR: No test data found for test " test-id ", exiting")
	  (debug:print 2 *default-log-port* "ERROR: No test data found for test " test-id ", exiting")
	  (exit 1))
	(let* (;; (run-id        (if testdat (dbr:test-run_id testdat) #f))
	       (test-registry (tests:get-all))
	       (keydat        (if testdat (rmt:get-key-val-pairs run-id) #f))
	       (rundat        (if testdat (rmt:get-run-info run-id) #f))
	       (runname       (if testdat (db:get-value-by-header (db:get-rows rundat)
								  (db:get-header rundat)
								  "runname") #f))
	       ;; (tdb           (tdb:open-test-db-by-test-id-local dbstruct run-id test-id))
	       ;; These next two are intentional bad values to ensure errors if they should not
	       ;; get filled in properly.
	       (logfile       "/this/dir/better/not/exist")
	       (rundir        (if testdat 
				  (dbr:test-rundir testdat)
				  logfile))
	       ;; (testdat-path  (conc rundir "/testdat.db")) ;; this gets recalculated until found 
	       (teststeps     (if testdat (tests:get-compressed-steps #f run-id test-id) '()))
	       (teststeps     (if testdat (tests:get-compressed-steps run-id test-id) '()))
	       (testfullname  (if testdat (dbr:test-fullname testdat) "Gathering data ..."))
	       (testname      (if testdat (dbr:test-testname testdat) "n/a"))
	       ;; (tests:get-testconfig testdat testname 'return-procs))
	       (testmeta      (if testdat 
				  (let ((tm (rmt:testmeta-get-record testname)))
				    (if tm tm (make-db:testmeta)))
				  (make-db:testmeta)))
509
510
511
512
513
514
515
516

517
518

519
520
521
522

523
524
525
526
527

528
529
530
531
532
533
534
509
510
511
512
513
514
515

516
517

518
519
520
521

522
523
524
525
526

527
528
529
530
531
532
533
534







-
+

-
+



-
+




-
+







							    (> (current-milliseconds)(+ last-update 250))) ;; every half seconds if db touched
						       (> (current-milliseconds)(+ last-update 10000))     ;; force update even 10 seconds
						       request-update))
				    (newtestdat (if need-update 
						    ;; NOTE: BUG HIDER, try to eliminate this exception handler
						    (handle-exceptions
						     exn 
						     (debug:print-info 0 "test db access issue in examine test for run-id " run-id ", test-id " test-id ": " ((condition-property-accessor 'exn 'message) exn))
						     (debug:print-info 0 *default-log-port* "test db access issue in examine test for run-id " run-id ", test-id " test-id ": " ((condition-property-accessor 'exn 'message) exn))
						     (rmt:get-test-info-by-id run-id test-id )))))
			       ;; (debug:print-info 0 "need-update= " need-update " curr-mod-time = " curr-mod-time)
			       ;; (debug:print-info 0 *default-log-port* "need-update= " need-update " curr-mod-time = " curr-mod-time)
			       (cond
				((and need-update newtestdat)
				 (set! testdat newtestdat)
				 (set! teststeps    (tests:get-compressed-steps #f run-id test-id))
				 (set! teststeps    (tests:get-compressed-steps run-id test-id))
				 (set! logfile      (conc (dbr:test-rundir testdat) "/" (dbr:test-final_logf testdat)))
				 (set! rundir       ;; (filedb:get-path *fdb* 
				       (dbr:test-rundir testdat)) ;; )
				 (set! testfullname (dbr:test-fullname testdat))
				 ;; (debug:print 0 "INFO: teststeps=" (intersperse teststeps "\n    "))
				 ;; (debug:print 0 *default-log-port* "INFO: teststeps=" (intersperse teststeps "\n    "))
				 
				 ;; I don't see why this was implemented this way. Please comment it ...
				 ;; (if (eq? curr-mod-time db-mod-time) ;; do only once if same
				 ;;     (set! db-mod-time (+ curr-mod-time 1))
				 ;;     (set! db-mod-time curr-mod-time))

				 (if (not (eq? curr-mod-time db-mod-time))
573
574
575
576
577
578
579
580

581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608

609
610
611
612
613
614
615

616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637
638
639
640
573
574
575
576
577
578
579

580



581


582
583
584
585
586
587
588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638







-
+
-
-
-
+
-
-















-
+






-
+







+


















+







					;(mutex-lock! mx1)
							 (iup:attribute-set! lbl "TITLE" newval)
					;(mutex-unlock! mx1)
							 )))))
			      lbl))
	       (store-button store-label)
	       (command-proc (lambda (command-text-box)
			       (let* ((cmd     (iup:attribute command-text-box "VALUE"))
			       (let* ((cmd     (iup:attribute command-text-box "VALUE")))
				      (fullcmd (conc (dtests:get-pre-command)
						     cmd 
						     (dtests:get-post-command))))
				 (common:run-a-command cmd))))
				 (debug:print-info 02 "Running command: " fullcmd)
				 (common:without-vars fullcmd "MT_.*"))))
	       (command-text-box (iup:textbox
				  #:expand "HORIZONTAL"
				  #:font "Courier New, -10"
				  #:action (lambda (obj cnum val)
					     ;; (print "cnum=" cnum)
					     (if (eq? cnum 13)
						 (command-prox obj)))
				  ))
	       (command-launch-button (iup:button "Execute!" #:action (lambda (x)
									(command-proc command-text-box))))
	;; (lambda (x)
	;; 								(let* ((cmd     (iup:attribute command-text-box "VALUE"))
	;; 								       (fullcmd (conc (dtests:get-pre-command)
	;; 										      cmd 
	;; 										      (dtests:get-post-command))))
	;; 								  (debug:print-info 02 "Running command: " fullcmd)
	;; 								  (debug:print-info 02 *default-log-port* "Running command: " fullcmd)
	;; 								  (common:without-vars fullcmd "MT_.*")))))
	       (kill-jobs (lambda (x)
			    (iup:attribute-set! 
			     command-text-box "VALUE"
			     (conc "megatest -target " keystring " -runname "  runname 
				   " -set-state-status KILLREQ,n/a -testpatt %/% "
				   " -state RUNNING"))))
				   " -state RUNNING,REMOTEHOSTSTART,LAUNCHED"))))
	       (run-test  (lambda (x)
			    (iup:attribute-set! 
			     command-text-box "VALUE"
			     (conc "megatest -target " keystring " -runname " runname 
				   " -run -testpatt " (conc testname "/" (if (equal? item-path "")
									"%" 
									item-path))
				   " -clean-cache"
				   ))))
	       (remove-test (lambda (x)
			      (iup:attribute-set!
			       command-text-box "VALUE"
			       (conc "megatest -remove-runs -target " keystring " -runname " runname
				     " -testpatt " (conc testname "/" (if (equal? item-path "")
									  "%"
									  item-path))
				     " -v"))))
	       (clean-run-execute  (lambda (x)
				     (let ((cmd (conc "megatest -remove-runs -target " keystring " -runname " runname
						      " -testpatt " (conc testname "/" (if (equal? item-path "")
						       					   "%"
						       					   item-path))
						      ";megatest -target " keystring " -runname " runname 
						      " -run -preclean -testpatt " (conc testname "/" (if (equal? item-path "")
											   "%" 
											   item-path))
						      " -clean-cache"
						      )))
				       (common:without-vars
					(conc (dtests:get-pre-command)
					      cmd 
					      (dtests:get-post-command))
					"MT_.*"))))
	       (remove-test (lambda (x)
689
690
691
692
693
694
695
696
697
698



699
700
701
702
703
704
705
687
688
689
690
691
692
693



694
695
696
697
698
699
700
701
702
703







-
-
-
+
+
+







			       (let ((tabs 
				      (iup:tabs
				       ;; Replace here with matrix
				       (let ((steps-matrix (iup:matrix
							    #:font   "Courier New, -8"
							    #:expand "YES"
							    #:scrollbar "YES"
							    #:numcol 6
							    #:numlin 30
							    #:numcol-visible 6
							    #:numcol 7
							    #:numlin 100
							    #:numcol-visible 7
							    #:numlin-visible 5
							    #:click-cb (lambda (obj lin col status)
									 ;; (if (equal? col 6)
									 (let* ((mtrx-rc (conc lin ":" 6))
										(fname   (iup:attribute obj mtrx-rc))) ;; col))))
									   (if (eq? col 6)
									       (view-a-log fname)
716
717
718
719
720
721
722

723
724
725
726
727
728
729
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728







+







					 (iup:attribute-set! steps-matrix "0:2" "Start")
					 (iup:attribute-set! steps-matrix "0:3" "End")
					 (iup:attribute-set! steps-matrix "WIDTH3" "50")
					 (iup:attribute-set! steps-matrix "0:4" "Status")
					 (iup:attribute-set! steps-matrix "WIDTH4" "50")
					 (iup:attribute-set! steps-matrix "0:5" "Duration")
					 (iup:attribute-set! steps-matrix "0:6" "Log File")
					 (iup:attribute-set! steps-matrix "0:7" "Comment")
					 (iup:attribute-set! steps-matrix "ALIGNMENT1" "ALEFT")
					 ;; (iup:attribute-set! steps-matrix "FIXTOTEXT" "C1")
					 (iup:attribute-set! steps-matrix "RESIZEMATRIX" "YES")
					 (let ((proc
						(lambda (testdat)
						  (dcommon:populate-steps teststeps steps-matrix))))
					   (hash-table-set! widgets "StepsMatrix" proc)
738
739
740
741
742
743
744
745

746
747
748
749
750
751
752
737
738
739
740
741
742
743

744
745
746
747
748
749
750
751







-
+







						#:expand "YES"
						#:multiline "YES"
						#:font "Courier New, -10"
						#:size "100x100")))
					  (hash-table-set! widgets "Test Data"
							   (lambda (testdat) ;; 
							     (let* ((currval (iup:attribute test-data "VALUE")) ;; "TITLE"))
								    (fmtstr  "~10a~10a~10a~10a~7a~7a~6a~6a~a") ;; category,variable,value,expected,tol,units,type,comment
								    (fmtstr  "~10a~10a~10a~10a~7a~7a~6a~7a~a") ;; category,variable,value,expected,tol,units,type,comment
								    (newval  (string-intersperse 
									      (append
									       (list 
										(format #f fmtstr "Category" "Variable" "Value" "Expected" "Tol" "Status" "Units" "Type" "Comment")
										(format #f fmtstr "========" "========" "=====" "========" "===" "======" "=====" "====" "======="))
									       (map (lambda (x)
										      (format #f fmtstr

Modified dashboard.scm from [286fefb12f] to [1b8610629a].

1
2

3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
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
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
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387

-
+










+






-
+















+








+

+


-
+

-
+


-
+
-
-
-
+
+


-
+
+

+
+
+
+





+


+











+
-
+








-
+




+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
+
+
+
+

+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
-
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-

-
-
-
+
+
+
-
-

-
-

+
+







;;======================================================================
;; Copyright 2006-2012, Matthew Welland.
;; Copyright 2006-2016, Matthew Welland.
;; 
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;; 
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.
;;======================================================================

(use format)

(require-library iup)
(import (prefix iup iup:))

(use canvas-draw)
(import canvas-draw-iup)

(use sqlite3 srfi-1 posix regex regex-case srfi-69)
(use sqlite3 srfi-1 posix regex regex-case srfi-69 typed-records sparse-vectors)
(import (prefix sqlite3 sqlite3:))

(declare (uses common))
(declare (uses margs))
(declare (uses keys))
(declare (uses items))
(declare (uses db))
(declare (uses configf))
(declare (uses process))
(declare (uses launch))
(declare (uses runs))
(declare (uses dashboard-tests))
(declare (uses dashboard-guimonitor))
(declare (uses tree))
(declare (uses dcommon))
(declare (uses vg))

;; (declare (uses dashboard-main))
(declare (uses megatest-version))
(declare (uses mt))

(include "common_records.scm")
(include "db_records.scm")
(include "run_records.scm")
(include "task_records.scm")
(include "megatest-fossil-hash.scm")
(include "vg_records.scm")

(define help (conc 
"Megatest Dashboard, documentation at http://www.kiatoa.com/fossils/megatest
	      "Megatest Dashboard, documentation at http://www.kiatoa.com/fossils/megatest
  version " megatest-version "
  license GPL, Copyright (C) Matt Welland 2012-2014
  license GPL, Copyright (C) Matt Welland 2012-2016

Usage: dashboard [options]
  -h                   : this help
  -h                    : this help
  -server host:port    : connect to host:port instead of db access
  -test run-id,test-id : control test identified by testid
  -guimonitor          : control panel for runs
  -test run-id,test-id  : control test identified by testid
  -skip-version-check   : skip the version check

Misc
  -rows N         : set number of rows
  -rows R         : set number of rows
  -cols C         : set number of columns
"))

;;   -server host:port     : connect to host:port instead of db access
;;   -xterm run-id,test-id : Start a new xterm with specified run-id and test-id
;;   -guimonitor           : control panel for runs

;; process args
(define remargs (args:get-args 
		 (argv)
		 (list  "-rows"
			"-cols"
			"-run"
			"-test"
                        "-xterm"
			"-debug"
			"-host" 
			"-transport"
			) 
		 (list  "-h"
			"-use-server"
			"-guimonitor"
			"-main"
			"-v"
			"-q"
			"-use-local"
			"-skip-version-check"
		       )
			)
		 args:arg-hash
		 0))

(if (args:get-arg "-h")
    (begin
      (print help)
      (exit)))

(if (not (launch:setup-for-run))
(if (not (launch:setup))
    (begin
      (print "Failed to find megatest.config, exiting") 
      (exit 1)))

;; data common to all tabs goes here
;;
(defstruct dboard:commondat
  curr-tab-num
  please-update  
  tabdats
  update-mutex
  updaters 
  updating
  uidat ;; needs to move to tabdat at some time
  hide-not-hide-tabs
  )
(define *useserver* (or(not (args:get-arg "-use-local"))
			(configf:lookup *configdat* "dashboard" "use-server")))

(define (dboard:commondat-make)
  (make-dboard:commondat
   curr-tab-num:         0
   tabdats:              (make-hash-table)
   please-update:        #t
   update-mutex:         (make-mutex)
   updaters:             (make-hash-table)
   updating:             #f
   hide-not-hide-tabs:   #f
   ))

(define (dboard:common-get-tabdat commondat #!key (tab-num #f))
  (hash-table-ref/default 
   (dboard:commondat-tabdats commondat)
   (or tab-num (dboard:commondat-curr-tab-num commondat))
   #f))

(define (dboard:common-set-tabdat! commondat tabnum tabdat)
  (hash-table-set!
   (dboard:commondat-tabdats commondat)
   tabnum
   tabdat))
(define *dbdir* (db:dbfile-path #f)) ;; (conc (configf:lookup *configdat* "setup" "linktree") "/.db"))
(define *dbstruct-local*  (make-dbr:dbstruct path:  *dbdir*
					     local: #t))
(define *db-file-path* (db:dbfile-path 0))

;; gets and calls updater based on curr-tab-num
(define (dboard:common-run-curr-updaters commondat #!key (tab-num #f))
  (if (dboard:common-get-tabdat commondat tab-num: tab-num) ;; only update if there is a tabdat
      (let* ((tnum     (or tab-num (dboard:commondat-curr-tab-num commondat)))
	     (updaters (hash-table-ref/default (dboard:commondat-updaters commondat)
					       tnum
					       '())))
	(debug:print 4 *default-log-port* "Found these updaters: " updaters " for tab-num: " tnum)
	(for-each
	 (lambda (updater)
	   ;; (debug:print 3 *default-log-port* "Running " updater)
	   (updater))
	 updaters))))

;; if tab-num passed in then use it, otherwise look in commondat at curr-tab-num
;;
(define (dboard:commondat-add-updater commondat updater #!key (tab-num #f))
  (let* ((tnum          (or tab-num
			     (dboard:commondat-curr-tab-num commondat)))
	 (curr-updaters (hash-table-ref/default (dboard:commondat-updaters commondat) tnum '())))
    (hash-table-set! (dboard:commondat-updaters commondat)
		     tnum
		     (cons updater curr-updaters))))

;; data for each specific tab goes here
;;
(defstruct dboard:tabdat 
  ;; runs
  ((allruns         '())                 : list)        ;; list of dboard:rundat records
  ((allruns-by-id    (make-hash-table))  : hash-table)  ;; hash of run-id -> dboard:rundat records
  ((done-runs       '())                 : list)        ;; list of runs already drawn
  ((not-done-runs   '())                 : list)        ;; list of runs not yet drawn
  (header            #f)                                ;; header for decoding the run records
  (keys              #f)                                ;; keys for this run (i.e. target components)
  ((numruns          (string->number (or (args:get-arg "-cols") "8")))                 : number)      ;; 
  ((tot-runs          0)                 : number)
  ((last-data-update  0)                 : number)      ;; last time the data in allruns was updated
  (runs-mutex         (make-mutex))                     ;; use to prevent parallel access to draw objects
  ((run-update-times  (make-hash-table)) : hash-table)  ;; update times indexed by run-id
  ((last-test-dat      (make-hash-table)) : hash-table)  ;; cache last tests dat by run-id
  ((run-db-paths      (make-hash-table)) : hash-table)  ;; cache the paths to the run db files

;; HACK ALERT: this is a hack, please fix.
(define *read-only* (not (file-read-access? *db-file-path*)))
  ;; Runs view
  ((buttondat         (make-hash-table)) : hash-table)  ;;     
  ((item-test-names  '())                : list)        ;; list of itemized tests
  ((run-keys          (make-hash-table)) : hash-table)
  (runs-matrix        #f)                               ;; used in newdashboard
  ((start-run-offset   0)                : number)      ;; left-right slider value
  ((start-test-offset  0)                : number)      ;; up-down slider value
  ((runs-btn-height    (or (configf:lookup *configdat* "dashboard" "btn-height") "x14")) : string)  ;; was 12
  ((runs-btn-fontsz    (or (configf:lookup *configdat* "dashboard" "btn-fontsz") "10")) : string)   ;; was 8
  ((runs-cell-width    (or (configf:lookup *configdat* "dashboard" "cell-width") "60")) : string)   ;; was 50
  ((all-test-names     '())              : list)
  
  ;; Canvas and drawing data
  (cnv                #f)
  (cnv-obj            #f)
  (drawing            #f)
  ((run-start-row     0)                 : number)
  ((max-row           0)                 : number)
  ((running-layout    #f)                : boolean)
  (originx            #f)
  (originy            #f)
  ((layout-update-ok  #t)                : boolean)
  ((compact-layout    #t)                : boolean)

  ;; Controls used to launch runs etc.
  ((command          "")                 : string)      ;; for run control this is the command being built up
(define toplevel #f)
(define dlg      #f)
(define max-test-num 0)
(define *keys*   (if *useserver*
		     (rmt:get-keys)
		     (db:get-keys *dbstruct-local*)))
  (command-tb        #f)			         
  (key-listboxes     #f)			         
  (key-lbs           #f)			         
  run-name                                              ;; from run name setting widget
  states                                                ;; states for -state s1,s2 ...
  statuses                                              ;; statuses for -status s1,s2 ...
						         
  ;; Selector variables				         
  curr-run-id                                           ;; current row to display in Run summary view
  curr-test-ids                                         ;; used only in dcommon:run-update which is used in newdashboard
  ((filters-changed  #f)                  : boolean)    ;; to to indicate that the user changed filters for this tab
  ((last-filter-str  "")                  : string)      ;; conc the target runname and testpatt for a signature of changed filters
  ((hide-empty-runs  #f)                  : boolean)     
  ((hide-not-hide    #t)                  : boolean)     ;; toggle for hide/not hide empty runs
  (hide-not-hide-button #f)
  ((searchpatts        (make-hash-table)) : hash-table)  ;;
  ((state-ignore-hash  (make-hash-table)) : hash-table)  ;; hash of  STATE => #t/#f for display control
  ((status-ignore-hash (make-hash-table)) : hash-table)  ;; hash of STATUS => #t/#f
  (target              #f)
  (test-patts          #f)

  ;; db info to file the .db files for the area
  (dbdir               #f)
  (dbfpath             #f)
  (dbkeys              #f)
  ((last-db-update     0)                : number)      ;; last db file timestamp
  (monitor-db-path     #f)                              ;; where to find monitor.db
  ro                                                    ;; is the database read-only?

  ;; tests data
  ((num-tests          10)               : number)      ;; total number of tests to show (used in the old runs display)
(define *dbkeys*  (append *keys* (list "runname")))

  ;; runs tree
  ((path-run-ids       (make-hash-table)) : hash-table) ;; path (target / runname) => id
  (runs-tree           #f)

  ;; tab data
  ((view-changed       #t)                : boolean)   
  ((xadj               0)                 : number)     ;; x slider number (if using canvas)
  ((yadj               0)                 : number)     ;; y slider number (if using canvas)
(define *header*       #f)
(define *allruns*     '())
(define *allruns-by-id* (make-hash-table)) ;; 
(define *runchangerate* (make-hash-table))

(define *buttondat*    (make-hash-table)) ;; <run-id color text test run-key>
(define *alltestnamelst* '())
(define *searchpatts*  (make-hash-table))
(define *num-runs*      8)
(define *tot-run-count* (if *useserver*
			    (rmt:get-num-runs "%")
			    (db:get-num-runs *dbstruct-local* "%")))

;; (define *tot-run-count* (db:get-num-runs *dbstruct-local* "%"))

  tests-tree       ;; used in newdashboard
  )

(define (dboard:tabdat-target-string vec)
  (let ((targ (dboard:tabdat-target vec)))
    (if (list? targ)(string-intersperse targ "/") "no-target-specified")))

(define (dboard:tabdat-test-patts-use vec)    
  (let ((val (dboard:tabdat-test-patts vec)))(if val val "")))

;; additional setters for dboard:data
(define (dboard:tabdat-test-patts-set!-use    vec val)
  (dboard:tabdat-test-patts-set! vec (if (equal? val "") #f val)))

(define (dboard:tabdat-make-data)
  (let ((dat (make-dboard:tabdat)))
    (dboard:setup-tabdat dat)
    (dboard:setup-num-rows dat)
    dat))

(define (dboard:setup-tabdat tabdat)
  (dboard:tabdat-dbdir-set! tabdat (db:dbfile-path #f)) ;; (conc (configf:lookup *configdat* "setup" "linktree") "/.db"))
  (dboard:tabdat-dbfpath-set! tabdat (db:dbfile-path 0))
  (dboard:tabdat-monitor-db-path-set! tabdat (conc (dboard:tabdat-dbdir tabdat) "/monitor.db"))

  ;; HACK ALERT: this is a hack, please fix.
  (dboard:tabdat-ro-set! tabdat (not (file-read-access? (dboard:tabdat-dbfpath tabdat))))
  
  (dboard:tabdat-keys-set! tabdat (rmt:get-keys))
  (dboard:tabdat-dbkeys-set! tabdat (append (dboard:tabdat-keys tabdat) (list "runname")))
  (dboard:tabdat-tot-runs-set! tabdat (rmt:get-num-runs "%"))
  )

;; data for runs, tests etc. was used in run summary?
;;
(defstruct dboard:runsdat
  ;; new system
  runs-index    ;; target/runname => colnum
  tests-index   ;; testname/itempath => rownum
  matrix-dat    ;; vector of vectors rows/cols
  )

(define (dboard:runsdat-make-init)
  (make-dboard:runsdat
   runs-index: (make-hash-table)
   tests-index: (make-hash-table)
   matrix-dat: (make-sparse-array)))

;; used to keep the rundata from rmt:get-tests-for-run
;; in sync. 
;;
(defstruct dboard:rundat
  run
  tests-drawn    ;; list of id's already drawn on screen
  tests-notdrawn ;; list of id's NOT already drawn
  rowsused       ;; hash of lists covering what areas used - replace with quadtree
  hierdat        ;; put hierarchial sorted list here
  tests          ;; hash of id => testdat
  ((tests-by-name (make-hash-table)) : hash-table) ;; hash of testfullname => testdat
  key-vals
  ((last-update   0)                 : fixnum) ;; last query to db got records from before last-update
  ((data-changed  #f)                : boolean)
  ((run-data-offset  0)              : number)      ;; get only 100 items per call, set back to zero when received less that 100 items
  (db-path #f)
  )

(define (dboard:rundat-make-init #!key (run #f)(key-vals #f)(tests #f));; -100 is before time began
  (make-dboard:rundat 
   run: run
   tests: (or tests (make-hash-table))
   key-vals: key-vals 
   )) 

(define (dboard:rundat-copy-tests-to-by-name rundat)
  (let ((src-ht (dboard:rundat-tests rundat))
	(trg-ht (dboard:rundat-tests-by-name rundat)))
    (if (and (hash-table? src-ht)(hash-table? trg-ht))
	(begin
	  (hash-table-clear! trg-ht)
	  (for-each
	   (lambda (testdat)
	     (hash-table-set! trg-ht (test:test-get-fullname testdat) testdat))
	   (hash-table-values src-ht)))
	(debug:print 0 *default-log-port* "WARNING: src-ht " src-ht " trg-ht " trg-ht))))
  
(defstruct dboard:testdat
  id       ;; testid
  state    ;; test state
  status   ;; test status
  )

(define (dboard:runsdat-get-col-num dat target runname force-set)
  (let* ((runs-index (dboard:runsdat-runs-index dat))
	 (col-name   (conc target "/" runname))
	 (res        (hash-table-ref/default runs-index col-name #f)))
    (if res
	res
	(if force-set
	    (let ((max-col-num (+ 1 (apply max -1 (hash-table-values runs-index)))))
	      (hash-table-set! runs-index col-name max-col-num)
	      max-col-num)))))

(define (dboard:runsdat-get-row-num dat testname itempath force-set)
  (let* ((tests-index (dboard:runsdat-runs-index dat))
	 (row-name    (conc testname "/" itempath))
	 (res         (hash-table-ref/default runs-index row-name #f)))
    (if res
	res
	(if force-set
	    (let ((max-row-num (+ 1 (apply max -1 (hash-table-values tests-index)))))
	      (hash-table-set! runs-index row-name max-row-num)
	      max-row-num)))))
;; Update management

;; default is to NOT set the cell if the column and row names are not pre-existing
;;
(define *last-update*   (current-seconds))
(define *last-db-update-time* 0)
(define *please-update-buttons* #t)
(define *delayed-update* 0)
(define *update-is-running* #f)
(define (dboard:runsdat-set-test-cell dat target runname testname itempath test-id state status #!key (force-set #f))
  (let* ((col-num  (dboard:runsdat-get-col-num dat target runname force-set))
	 (row-num  (dboard:runsdat-get-row-num dat testname itempath force-set)))
    (if (and row-num col-num)
	(let ((tdat (dboard:testdat 
		     id: test-id
		     state: state
		     status: status)))
	  (sparse-array-set! (dboard:runsdat-matrix-dat dat) col-num row-num tdat)
	  tdat)
	#f)))
(define *update-mutex* (make-mutex))

(define *all-item-test-names* '())
(define *num-tests*     15)
(define *start-run-offset*  0)
(define *dashboard-mode* (string->symbol (or (configf:lookup *configdat* "dashboard" "mode") "dashboard")))
  

(define *start-test-offset* 0)
(define *examine-test-dat* (make-hash-table))
(define *exit-started* #f)
(define *status-ignore-hash* (make-hash-table))
(define *state-ignore-hash*  (make-hash-table))

;; sorting global data (would apply to many testsuites so leave it global for now)
;;
(define *tests-sort-options* (vector (vector "Sort +a" 'testname   "ASC")
				     (vector "Sort -a" 'testname   "DESC")
				     (vector "Sort +t" 'event_time "ASC")
				     (vector "Sort -t" 'event_time "DESC")
				     (vector "Sort +s" 'statestatus "ASC")
				     (vector "Sort -s" 'statestatus "DESC")
				     (vector "Sort +a" 'testname   "ASC")))
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
405
406
407
408
409
410
411








412
413

414
415
416
417
418
419
420
421







-
-
-
-
-
-
-
-


-
+







    (if t-sort
	(cadr t-sort)
	3)))

(define (get-curr-sort)
  (vector-ref *tests-sort-options* *tests-sort-reverse*))

(define *hide-empty-runs* #f)
(define *hide-not-hide* #t) ;; toggle for hide/not hide
(define *hide-not-hide-button* #f)
(define *hide-not-hide-tabs* #f)

(define *current-tab-number* 0)
(define *updaters* (make-hash-table))

(debug:setup)

(define uidat #f)
;; (define uidat #f)

(define-inline (dboard:uidat-get-keycol  vec)(vector-ref vec 0))
(define-inline (dboard:uidat-get-lftcol  vec)(vector-ref vec 1))
(define-inline (dboard:uidat-get-header  vec)(vector-ref vec 2))
(define-inline (dboard:uidat-get-runsvec vec)(vector-ref vec 3))

(if (get-environment-variable "MT_RUN_AREA_HOME")(change-directory (get-environment-variable "MT_RUN_AREA_HOME")))
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
295
296


297
298
299
300
301
302
303








304
305






306
307
308
309
310

311
312
313
314
315

316
317
318

319
320
321

322
323

324
325
326
327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467


468
469




470
471
472
473
474
475


476






477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589




590
591
592
593
594
595
596
597
598
599
600
601
602
603
604






605
606










607
608
609
610
611
612






613
614
615






616
617
618
619
620
621
622



623
624







625
626
627
628
629
630
631
632


633
634
635
636
637
638
639
640

641

642
643
644
645
646

647
648
649

650
651
652

653
654

655
656
657
658
659
660
661
662
663
664
665
666
667

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687

688
689
690
691
692
693


694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713







-
+


















-
-
+
+
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+





-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+


-

-
+




-
+


-
+


-
+

-
+












-
+



















-
+





-
-
+
+










-
+








(define (colors-similar? color1 color2)
  (let* ((c1    (map string->number (string-split color1)))
	 (c2    (map string->number (string-split color2)))
	 (delta (map (lambda (a b)(abs (- a b))) c1 c2)))
    (null? (filter (lambda (x)(> x 3)) delta))))

(define (compare-tests test1 test2)
(define (dboard:compare-tests test1 test2)
  (let* ((test-name1  (dbr:test-testname  test1))
	 (item-path1  (dbr:test-item-path test1))
	 (eventtime1  (dbr:test-event_time test1))
	 (test-name2  (dbr:test-testname  test2))
	 (item-path2  (dbr:test-item-path test2))
	 (eventtime2  (dbr:test-event_time test2))
	 (same-name   (equal? test-name1 test-name2))
	 (test1-top   (equal? item-path1 ""))
	 (test2-top   (equal? item-path2 ""))
	 (test1-older (> eventtime1 eventtime2))
	 (same-time   (equal? eventtime1 eventtime2)))			 
    (if same-name
	(if same-time
	    (string>? item-path1 item-path2)
	    test1-older)
	(if same-time
	    (string>? test-name1 test-name2)
	    test1-older))))
    
;; keypatts: ( (KEY1 "abc%def")(KEY2 "%") )

;; This is roughly the same as dboard:get-tests-dat, should merge them if possible
(define (update-rundat runnamepatt numruns testnamepatt keypatts)
  (let* ((referenced-run-ids '())
	 (allruns     (if *useserver*
			  (rmt:get-runs runnamepatt numruns *start-run-offset* keypatts)
;;
;; gets all the tests for run-id that match testnamepatt and key-vals, merges them
;;
;;    NOTE: Yes, this is used
;;
(define (dboard:get-tests-for-run-duplicate tabdat run-id run testnamepatt key-vals)
			  (db:get-runs *dbstruct-local* runnamepatt numruns ;; (+ numruns 1) ;; (/ numruns 2))
				      *start-run-offset* keypatts)))
  (let* ((num-to-get  20)
	 (header      (db:get-header allruns))
	 (runs        (db:get-rows   allruns))
	 (result      '())
	 (maxtests    0)
	 (states      (hash-table-keys *state-ignore-hash*))
	 (statuses    (hash-table-keys *status-ignore-hash*))
	 (states      (hash-table-keys (dboard:tabdat-state-ignore-hash tabdat)))
	 (statuses    (hash-table-keys (dboard:tabdat-status-ignore-hash tabdat)))
	 (sort-info   (get-curr-sort))
	 (sort-by     (vector-ref sort-info 1))
	 (sort-order  (vector-ref sort-info 2))
	 (bubble-type (if (member sort-order '(testname))
			  'testname
			  'itempath)))
			  'itempath))
	 ;; note: the rundat is normally created in "update-rundat". 
	 (run-dat    (or (hash-table-ref/default (dboard:tabdat-allruns-by-id tabdat) run-id #f)
			 (let ((rd (dboard:rundat-make-init run: run key-vals: key-vals)))
			   (hash-table-set! (dboard:tabdat-allruns-by-id tabdat) run-id rd)
			   rd)))
	 ;; (prev-tests  (dboard:rundat-tests prev-dat)) ;; (vector-ref prev-dat 1))
	 (last-update (dboard:rundat-last-update run-dat)) ;; (vector-ref prev-dat 3))
	 (db-path     (or (dboard:rundat-db-path run-dat)
			  (let* ((db-dir (tasks:get-task-db-path))
				 (db-pth (conc db-dir "/" run-id ".db")))
			    (dboard:rundat-db-path-set! run-dat db-pth)
			    db-pth)))
	 (tmptests    (if (or (configf:lookup *configdat* "setup" "do-not-use-db-file-timestamps")
			      (>= (file-modification-time db-path) last-update))
			  (rmt:get-tests-for-run run-id testnamepatt states statuses  ;; run-id testpatt states statuses
						 (dboard:rundat-run-data-offset run-dat)
						 num-to-get
						 (dboard:tabdat-hide-not-hide tabdat) ;; no-in
						 sort-by                              ;; sort-by
						 sort-order                           ;; sort-order
						 #f ;; 'shortlist                           ;; qrytype
						 (if (dboard:tabdat-filters-changed tabdat) 
						     0
						     last-update) ;; last-update
						 *dashboard-mode*) ;; use dashboard mode
			  '()))
	 (use-new    (dboard:tabdat-hide-not-hide tabdat))
	 (tests-ht   (if (dboard:tabdat-filters-changed tabdat)
			 (let ((ht (make-hash-table)))
			   (dboard:rundat-tests-set! run-dat ht)
			   ht)
			 (dboard:rundat-tests run-dat)))
	 (start-time (current-seconds)))

    ;; to limit the amount of data transferred each cycle use limit of num-to-get and offset
    (dboard:rundat-run-data-offset-set! 
     run-dat 
     (if (< (length tmptests) num-to-get)
	 0
	 (let ((newval (+ num-to-get (dboard:rundat-run-data-offset run-dat))))
	   ;; (print "Incremental get, offset=" (dboard:rundat-run-data-offset run-dat) " retrieved: " (length tmptests) " newval: " newval)
	   newval)))
     
    (for-each 
     (lambda (tdat)
       (let ((test-id (db:test-get-id tdat))
	     (state   (db:test-get-state tdat)))
	 (dboard:rundat-data-changed-set! run-dat #t)
	 (if (equal? state "DELETED")
	     (hash-table-delete! tests-ht test-id)
	     (hash-table-set! tests-ht test-id tdat))))
     tmptests)
    
    ;; set last-update to 0 if still getting data incrementally

    (if (> (dboard:rundat-run-data-offset run-dat) 0)
	(begin
	  ;; (print "run-data-offset: " (dboard:rundat-run-data-offset run-dat) ", setting last-update to 0")
	  (dboard:rundat-last-update-set! run-dat 0))
	(dboard:rundat-last-update-set! run-dat (- (current-seconds) 2))) ;; go back two seconds in time to ensure all changes are captured.

    ;; (debug:print-info 0 *default-log-port* "tests-ht: " (hash-table-keys tests-ht))
    tests-ht))

;; tmptests   - new tests data
;; prev-tests - old tests data
;;
;; (define (dashboard:merge-changed-tests tabdat tests tmptests) ;;  use-new prev-tests) 
;;   (let* ((newdat     (filter
;; 		      (lambda (x)
;; 			(not (equal? (db:test-get-state x) "DELETED"))) ;; remove deleted tests but do it after merging
;; 		      (delete-duplicates (if use-new ;; (dboard:tabdat-filters-changed tabdat)
;; 					     tmptests
;; 					     (append tmptests prev-tests))
;; 					 (lambda (a b)
;; 					   (eq? (db:test-get-id a)(db:test-get-id b)))))))
;;     (print "Time took: " (- (current-seconds) start-time))
;;     (if (eq? *tests-sort-reverse* 3) ;; +event_time
;; 	(sort newdat dboard:compare-tests)
;; 	newdat)))

;; this calls dboard:get-tests-for-run-duplicate for each run
;;
;; create a virtual table of all the tests
;; keypatts: ( (KEY1 "abc%def")(KEY2 "%") )
;;
(define (update-rundat tabdat runnamepatt numruns testnamepatt keypatts)
  (let* (
         (allruns     (rmt:get-runs runnamepatt numruns (dboard:tabdat-start-run-offset tabdat) keypatts))
         ;;(allruns-tree (rmt:get-runs-by-patt (dboard:tabdat-keys tabdat) "%" #f #f #f #f))
         (allruns-tree    (rmt:get-runs "%" #f "0" '()))
	 (header      (db:get-header allruns))
	 (runs        (db:get-rows   allruns)) ;; RA => Filtered as per runpatt selected
         (runs-tree   (db:get-rows   allruns-tree)) ;; RA => Returns complete list of runs
	 (start-time  (current-seconds))
	 (runs-hash   (let ((ht (make-hash-table)))
			 (for-each (lambda (run)
				     (hash-table-set! ht (db:get-value-by-header run header "id") run))
				   runs-tree) ;; (vector-ref runs-dat 1))
			 ht))
	 (tb          (dboard:tabdat-runs-tree tabdat)))
    (dboard:tabdat-header-set! tabdat header)
    ;; 
    ;; trim runs to only those that are changing often here
    ;; 
    (for-each (lambda (run)
		(let* ((run-id      (db:get-value-by-header run header "id"))
		       (tmptests    (if *useserver*
					(rmt:get-tests-for-run run-id testnamepatt states statuses
    (if (null? runs)
	(begin
	  (dboard:tabdat-allruns-set! tabdat '())
	  (dboard:tabdat-all-test-names-set! tabdat '())
	  (dboard:tabdat-item-test-names-set! tabdat '())
	  (hash-table-clear! (dboard:tabdat-allruns-by-id tabdat)))
	(let loop ((run      (car runs))
		   (tal      (cdr runs))
		   (res     '())
		   (maxtests 0))
	  (let* ((run-id       (db:get-value-by-header run header "id"))
		 (run-struct   (hash-table-ref/default (dboard:tabdat-allruns-by-id tabdat) run-id #f))
		 (last-update  (if run-struct (dboard:rundat-last-update run-struct) 0))
		 (key-vals     (rmt:get-key-vals run-id))
		 (tests-ht     (dboard:get-tests-for-run-duplicate tabdat run-id run testnamepatt key-vals))
							       #f #f
							       *hide-not-hide*
							       sort-by
							       sort-order
							       'shortlist)
					(db:get-tests-for-run *dbstruct-local* run-id testnamepatt states statuses
		 ;; GET RID OF dboard:get-tests-dat - it is superceded by dboard:get-tests-for-run-duplicate
		 ;;  dboard:get-tests-for-run-duplicate - returns a hash table
							      #f #f
							      *hide-not-hide*
							      sort-by
							      sort-order
							      'shortlist)))
		       (tests       (if (eq? *tests-sort-reverse* 3) ;; +event_time
					(sort tmptests compare-tests)
					tmptests))
		       ;; NOTE: bubble-up also sets the global *all-item-test-names*
		       ;; (tests       (bubble-up tmptests priority: bubble-type))
		 ;;  (dboard:get-tests-dat tabdat run-id last-update))
		 (all-test-ids (hash-table-keys tests-ht))
		 (num-tests    (length all-test-ids)))
	    ;; (print "run-struct: " run-struct)
	    ;; NOTE: bubble-up also sets the global (dboard:tabdat-item-test-names tabdat)
	    ;; (tests       (bubble-up tmptests priority: bubble-type))
		       (key-vals    (if *useserver* 
					(rmt:get-key-vals run-id)
					(db:get-key-vals *dbstruct-local* run-id))))
		  ;; NOTE: 11/01/2013 This routine is *NOT* getting called excessively.
		  ;; (debug:print 0 "Getting data for run " run-id " with key-vals=" key-vals)
		  ;; Not sure this is needed?
	    ;; NOTE: 11/01/2013 This routine is *NOT* getting called excessively.
	    ;; (debug:print 0 *default-log-port* "Getting data for run " run-id " with key-vals=" key-vals)
	    ;; Not sure this is needed?
		  (set! referenced-run-ids (cons run-id referenced-run-ids))
		  (if (> (length tests) maxtests)
		      (set! maxtests (length tests)))
		  (if (or (not *hide-empty-runs*) ;; this reduces the data burden when set
			  (not (null? tests)))
		      (let ((dstruct (vector run tests key-vals)))
	    (let* ((newmaxtests (max num-tests maxtests))
		   (last-update (- (current-seconds) 10))
		   (run-struct  (or run-struct
				    (dboard:rundat-make-init
				     run:         run 
				     tests:       tests-ht
				     key-vals:    key-vals)))
			;;
			;; compare the tests with the tests in *allruns-by-id* same run-id 
			;; if different then increment value in *runchangerate*
		   (new-res     (if (null? all-test-ids) res (cons run-struct res)))
		   (elapsed-time (- (current-seconds) start-time)))
			;;
			(hash-table-set! *allruns-by-id* run-id dstruct)
			(set! result (cons dstruct result))))))
	      runs)

    (set! *header*  header)
    (set! *allruns* result)
	      (if (null? all-test-ids)
		  (hash-table-delete! (dboard:tabdat-allruns-by-id tabdat) run-id)
		  (hash-table-set!    (dboard:tabdat-allruns-by-id tabdat) run-id run-struct))
	      (if (or (null? tal)
		      (> elapsed-time 2)) ;; stop loading data after 5 seconds, on the next call more data *should* be loaded since get-tests-for-run uses last update
		  (begin
		    (if (> elapsed-time 2)(print "WARNING: timed out in update-testdat " elapsed-time "s"))
		    (dboard:tabdat-allruns-set! tabdat new-res)
    (debug:print-info 6 "*allruns* has " (length *allruns*) " runs")
    maxtests))
		    maxtests)
		  (if (> (dboard:rundat-run-data-offset run-struct) 0)
		      (loop run tal new-res newmaxtests) ;; not done getting data for this run
		      (loop (car tal)(cdr tal) new-res newmaxtests)))))))
    (dboard:tabdat-filters-changed-set! tabdat #f)
    (dboard:update-tree tabdat runs-hash header tb)))

(define *collapsed* (make-hash-table))
; (define *row-lookup* (make-hash-table)) ;; testname => (rownum lableobj)

(define (toggle-hide lnum) ; fulltestname)
(define (toggle-hide lnum uidat) ; fulltestname)
  (let* ((btn (vector-ref (dboard:uidat-get-lftcol uidat) lnum))
	 (fulltestname (iup:attribute btn "TITLE"))
	 (parts        (string-split fulltestname "("))
	 (basetestname (if (null? parts) "" (car parts))))
    ;(print "Toggling " basetestname " currently " (hash-table-ref/default *collapsed* basetestname #f))
					;(print "Toggling " basetestname " currently " (hash-table-ref/default *collapsed* basetestname #f))
    (if (hash-table-ref/default *collapsed* basetestname #f)
	(begin
	  ;(iup:attribute-set! btn "FGCOLOR" "0 0 0")
					;(iup:attribute-set! btn "FGCOLOR" "0 0 0")
	  (hash-table-delete! *collapsed* basetestname))
	(begin
	  ;(iup:attribute-set! btn "FGCOLOR" "0 192 192")
					;(iup:attribute-set! btn "FGCOLOR" "0 192 192")
	  (hash-table-set! *collapsed* basetestname #t)))))
  

(define blank-line-rx (regexp "^\\s*$"))

(define (run-item-name->vectors lst)
  (map (lambda (x)
	 (let ((splst (string-split x "("))
	       (res   (vector "" "")))
	   (vector-set! res 0 (car splst))
	   (if (> (length splst) 1)
	       (vector-set! res 1 (car (string-split (cadr splst) ")"))))
	   res))
       lst))

(define (collapse-rows inlst)
(define (collapse-rows tabdat inlst)
  (let* ((sort-info   (get-curr-sort))
	 (sort-by     (vector-ref sort-info 1))
	 (sort-order  (vector-ref sort-info 2))
	 (bubble-type (if (member sort-order '(testname))
			  'testname
			  'itempath))
	 (newlst      (filter (lambda (x)
				(let* ((tparts    (string-split x "("))
				       (basetname (if (null? tparts) x (car tparts))))
					;(print "x " x " tparts: " tparts " basetname: " basetname)
				  (cond
				   ((string-match blank-line-rx x) #f)
				   ((equal? x basetname) #t)
				   ((hash-table-ref/default *collapsed* basetname #f) 
					;(print "Removing " basetname " from items")
				    #f)
				   (else #t))))
			      inlst))
	 (vlst         (run-item-name->vectors newlst))
	 (vlst2        (bubble-up vlst priority: bubble-type)))
	 (vlst2        (bubble-up tabdat vlst priority: bubble-type)))
    (map (lambda (x)
	   (if (equal? (vector-ref x 1) "")
	       (vector-ref x 0)
	       (conc (vector-ref x 0) "(" (vector-ref x 1) ")")))
	 vlst2)))
    
(define (update-labels uidat)

(define (update-labels uidat alltestnames)
  (let* ((rown    0)
	 (keycol  (dboard:uidat-get-keycol uidat))
	 (lftcol  (dboard:uidat-get-lftcol uidat))
	 (numcols (vector-length lftcol))
	 (maxn    (- numcols 1))
	 (allvals (make-vector numcols "")))
    (for-each (lambda (name)
		(if (<= rown maxn)
		    (vector-set! allvals rown name)) ;)
		(set! rown (+ 1 rown)))
	      *alltestnamelst*)
	      alltestnames)
    (let loop ((i 0))
      (let* ((lbl    (vector-ref lftcol i))
	     (keyval (vector-ref keycol i))
	     (oldval (iup:attribute lbl "TITLE"))
	     (newval (vector-ref allvals i)))
	(if (not (equal? oldval newval))
	    (let ((munged-val (let ((parts (string-split newval "(")))
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
731
732
733
734
735
736
737

738
739
740
741
742
743
744
745







-
+







			  (set! tnames (append tnames (list tname)))))))
	      test-dats)
    tnames))

;; Bubble up the top tests to above the items, collect the items underneath
;; all while preserving the sort order from the SQL query as best as possible.
;;
(define (bubble-up test-dats #!key (priority 'itempath))
(define (bubble-up tabdat test-dats #!key (priority 'itempath))
  (if (null? test-dats)
      test-dats
      (begin
	(let* ((tnames   '())                ;; list of names used to reserve order
	       (tests    (make-hash-table))  ;; hash of lists, used to build as we go
	       (itemized (get-itemized-tests test-dats)))
	  (for-each 
425
426
427
428
429
430
431
432
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
459
460
461
462
463






464
465
466

467
468
469
470
471





472
473
474
475
476
477














478
479

480

481
482
483
484
485
486
487
488
489
490











491
492

493
494
495
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510
511
512
513
514










515
516
517

518
519
520
521
522
523
524
525
526
527
528







529
530
531
532
533
534
535
536
537
538
539
540

541
542
543

544
545
546
547
548
549
550

551
552
553
554
555
556





557
558
559
560
561
562


563
564
565
566




567
568
569



570
571
572
573
574
575
576
577
757
758
759
760
761
762
763








764
765
766
767
768
769
770
771
772
773
774
775
776
777
778





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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830

831










832
833
834
835
836
837
838
839
840
841
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
932
933
934
935







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







-
-
-
-
-
+
+
+
+
+
+
+
+



-
-
+
+
+

+


-
-
-
-
+
+
+
+
+
+


-
+
-
-



+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


+










+




-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+











-
+


-
+






-
+

-
-
-
-
-
+
+
+
+
+





-
+
+

-
-
-
+
+
+
+

-
-
+
+
+
-







	       (if (equal? ipath "")
		   ;; This a top level, prepend it
		   (hash-table-set! tests tname (cons testdat (hash-table-ref/default tests tname '())))
		   ;; This is item, append it
		   (hash-table-set! tests tname (append (hash-table-ref/default tests tname '())(list testdat))))))
	   test-dats)
	  ;; Set all tests with items 
	  (set! *all-item-test-names* (append (if (null? tnames)
						  '()
						  (filter (lambda (tname)
							    (let ((tlst (hash-table-ref tests tname)))
							      (and (list tlst)
								   (> (length tlst) 1))))
							  tnames))
					      *all-item-test-names*))
	  (dboard:tabdat-item-test-names-set! tabdat (append (if (null? tnames)
							      '()
							      (filter (lambda (tname)
									(let ((tlst (hash-table-ref tests tname)))
									  (and (list tlst)
									       (> (length tlst) 1))))
								      tnames))
							  (dboard:tabdat-item-test-names tabdat)))
	  (let loop ((hed (car tnames))
		     (tal (cdr tnames))
		     (res '()))
	    (let ((newres (append res (hash-table-ref tests hed))))
	      (if (null? tal)
		  newres
		  (loop (car tal)(cdr tal) newres))))))))
      
(define (update-buttons uidat numruns numtests)
  (let* ((runs        (if (> (length *allruns*) numruns)
			  (take-right *allruns* numruns)
			  (pad-list *allruns* numruns)))

;; optimized to get runs constrained by what is visible on the screen
;;  - not appropriate for where all the runs are needed
;;
(define (update-buttons tabdat uidat numruns numtests)
  (let* ((runs        (if (> (length (dboard:tabdat-allruns tabdat)) numruns)
			  (take-right (dboard:tabdat-allruns tabdat) numruns)
			  (pad-list (dboard:tabdat-allruns tabdat) numruns)))
	 (lftcol      (dboard:uidat-get-lftcol uidat))
	 (tableheader (dboard:uidat-get-header uidat))
	 (table       (dboard:uidat-get-runsvec uidat))
	 (coln        0))
    (set! *alltestnamelst* '())
	 (coln        0)
	 (all-test-names (make-hash-table)))

    ;; create a concise list of test names
    ;;
    (for-each
     (lambda (rundat)
       (if (vector? rundat)
	   (let* ((testdat   (vector-ref rundat 1))
		  (testnames (map test:test-get-fullname testdat)))
	     (if (not (and *hide-empty-runs*
       (if rundat
	   (let* ((testdats  (dboard:rundat-tests rundat))
		  (testnames (map test:test-get-fullname (hash-table-values testdats))))
	     (dboard:rundat-copy-tests-to-by-name rundat)
	     ;; for the normalized list of testnames (union of all runs)
	     (if (not (and (dboard:tabdat-hide-empty-runs tabdat)
			   (null? testnames)))
		 (for-each (lambda (testname)
			     (if (not (member testname *alltestnamelst*))
			     (hash-table-set! all-test-names testname #t))
				 (begin
				   (set! *alltestnamelst* (append *alltestnamelst* (list testname))))))
			   testnames)))))
     runs)

    ;; create the minimize list of testnames to be displayed. Sorting
    ;; happens here *before* trimming
    ;;
    (dboard:tabdat-all-test-names-set!
     tabdat
    (set! *alltestnamelst* (collapse-rows *alltestnamelst*)) ;;; argh. please clean up this sillyness
    (set! *alltestnamelst* (let ((xl (if (> (length *alltestnamelst*) *start-test-offset*)
					 (drop *alltestnamelst* *start-test-offset*)
					 '())))
			     (append xl (make-list (- *num-tests* (length xl)) ""))))
    (update-labels uidat)
     (collapse-rows
      tabdat
      (sort (hash-table-keys all-test-names) string>?))) ;; FIXME: Sorting needs to happen here

    ;; Trim the names list to fit the matrix of buttons
    ;;
    (dboard:tabdat-all-test-names-set!
     tabdat
     (let ((xl (if (> (length (dboard:tabdat-all-test-names tabdat)) (dboard:tabdat-start-test-offset tabdat))
		   (drop (dboard:tabdat-all-test-names tabdat)
			 (dboard:tabdat-start-test-offset tabdat))
		   '())))
       (append xl (make-list (- (dboard:tabdat-num-tests tabdat) (length xl)) ""))))
    (update-labels uidat (dboard:tabdat-all-test-names tabdat))
    (for-each
     (lambda (rundat)
       ;; if rundat is junk clobber it with a decent placeholder
       (if (not rundat) ;; handle padded runs
       (if (or (not rundat) ;; handle padded runs
	   ;;           ;; id run-id testname state status event-time host cpuload diskfree uname rundir item-path run-duration
	   (set! rundat (vector (make-vector 20 #f) '() (map (lambda (x) "") *keys*))));; 3)))
       (let* ((run      (vector-ref rundat 0))
	      (testsdat (vector-ref rundat 1))
	      (key-val-dat (vector-ref rundat 2))
	      (run-id   (db:get-value-by-header run *header* "id"))
	      (key-vals (append key-val-dat
				(list (let ((x (db:get-value-by-header run *header* "runname")))
					(if x x "")))))
	      (run-key  (string-intersperse key-vals "\n")))
	       (not (dboard:rundat-run rundat)))
	   (set! rundat (dboard:rundat-make-init
			 key-vals: (map (lambda (x) "")(dboard:tabdat-keys tabdat)))))
       (let* ((run              (dboard:rundat-run rundat))
	      (testsdat-by-name (dboard:rundat-tests-by-name rundat))
	      (key-val-dat      (dboard:rundat-key-vals rundat))
	      (run-id           (db:get-value-by-header run (dboard:tabdat-header tabdat) "id"))
	      (key-vals         (append key-val-dat
					(list (let ((x (db:get-value-by-header run (dboard:tabdat-header tabdat) "runname")))
						(if x x "")))))
	      (run-key          (string-intersperse key-vals "\n")))
	 
	 ;; fill in the run header key values
	 ;;
	 (let ((rown      0)
	       (headercol (vector-ref tableheader coln)))
	   (for-each (lambda (kval)
		       (let* ((labl      (vector-ref headercol rown)))
			 (if (not (equal? kval (iup:attribute labl "TITLE")))
			     (iup:attribute-set! (vector-ref headercol rown) "TITLE" kval))
			 (set! rown (+ rown 1))))
		     key-vals))
	 
	 ;; For this run now fill in the buttons for each test
	 ;;
	 (let ((rown 0)
	       (columndat  (vector-ref table coln)))
	   (for-each
	    (lambda (testname)
	      (let ((buttondat  (hash-table-ref/default *buttondat* (mkstr coln rown) #f)))
		(if buttondat
		    (let* ((test       (let ((matching (filter 
							(lambda (x)(equal? (test:test-get-fullname x) testname))
							testsdat)))
					 (if (null? matching)
					     (vector -1 -1 "" "" "" 0 "" "" 0 "" "" "" 0 "" "")
					     (car matching))))
	      (let ((buttondat  (hash-table-ref/default (dboard:tabdat-buttondat tabdat) (mkstr coln rown) #f)))
		(if (and buttondat
			 (hash-table? testsdat-by-name))
		    (let* ((testdat      (let ((matching (hash-table-ref/default testsdat-by-name testname #f)))
					   ;; (filter 
					   ;;   (lambda (x)(equal? (test:test-get-fullname x) testname))
					   ;;     testsdat)))
					   (if (not matching)
					       (vector -1 -1 "" "" "" 0 "" "" 0 "" "" "" 0 "" "")
					       ;; (car matching))))
			   (testname   (dbr:test-testname  test))
			   (itempath   (dbr:test-item-path test))
			   (testfullname (test:test-get-fullname test))
			   (itempath     (db:test-get-item-path  testdat))
			   (teststatus (dbr:test-status   test))
			   (teststate  (dbr:test-state    test))
			   ;;(teststart  (dbr:test-event_time test))
			   ;;(runtime    (dbr:test-run_duration test))
			   (buttontxt  (cond
					((member teststate '("COMPLETED" "ARCHIVED")) teststatus)
					((and (equal? teststate "NOT_STARTED")
					      (member teststatus '("ZERO_ITEMS" "BLOCKED" "PREQ_FAIL" "PREQ_DISCARDED" "TIMED_OUT" "KEEP_TRYING" "TEN_STRIKES")))
					 teststatus)
					(else
					 teststate)))
			   (buttontxt    (cond
					  ((member teststate '("COMPLETED" "ARCHIVED")) teststatus)
					  ((and (equal? teststate "NOT_STARTED")
						(member teststatus '("ZERO_ITEMS" "BLOCKED" "PREQ_FAIL" "PREQ_DISCARDED" "TIMED_OUT" "KEEP_TRYING" "TEN_STRIKES")))
					   teststatus)
					  (else
					   teststate)))
			   (button     (vector-ref columndat rown))
			   (color      (car (gutils:get-color-for-state-status teststate teststatus)))
			   (curr-color (vector-ref buttondat 1)) ;; (iup:attribute button "BGCOLOR"))
			   (curr-title (vector-ref buttondat 2))) ;; (iup:attribute button "TITLE")))
		      (if (not (equal? curr-color color))
			  (iup:attribute-set! button "BGCOLOR" color))
		      (if (not (equal? curr-title buttontxt))
			  (iup:attribute-set! button "TITLE"   buttontxt))
		      (vector-set! buttondat 0 run-id)
		      (vector-set! buttondat 1 color)
		      (vector-set! buttondat 2 buttontxt)
		      (vector-set! buttondat 3 test)
		      (vector-set! buttondat 3 testdat)
		      (vector-set! buttondat 4 run-key)))
		(set! rown (+ rown 1))))
	    *alltestnamelst*))
	    (dboard:tabdat-all-test-names tabdat)))
	 (set! coln (+ coln 1))))
     runs)))

(define (mkstr . x)
  (string-intersperse (map conc x) ","))

(define (set-bg-on-filter)
(define (set-bg-on-filter commondat tabdat)
  (let ((search-changed (not (null? (filter (lambda (key)
					      (not (equal? (hash-table-ref *searchpatts* key) "%")))
					    (hash-table-keys *searchpatts*)))))
	(state-changed  (not (null? (hash-table-keys *state-ignore-hash*))))
	(status-changed (not (null? (hash-table-keys *status-ignore-hash*)))))
    (iup:attribute-set! *hide-not-hide-tabs* "BGCOLOR"
					      (not (equal? (hash-table-ref (dboard:tabdat-searchpatts tabdat) key) "%")))
					    (hash-table-keys (dboard:tabdat-searchpatts tabdat))))))
	(state-changed  (not (null? (hash-table-keys (dboard:tabdat-state-ignore-hash tabdat)))))
	(status-changed (not (null? (hash-table-keys (dboard:tabdat-status-ignore-hash tabdat))))))
    (iup:attribute-set! (dboard:commondat-hide-not-hide-tabs commondat) "BGCOLOR"
			(if (or search-changed
				state-changed
				status-changed)
			    "190 180 190"
			    "190 190 190"
			    ))))
			    ))
    (dboard:tabdat-filters-changed-set! tabdat #t)))

(define (update-search x val)
  (hash-table-set! *searchpatts* x val)
  (set-bg-on-filter))
(define (update-search commondat tabdat x val)
  (hash-table-set! (dboard:tabdat-searchpatts tabdat) x val)
  (dboard:tabdat-filters-changed-set! tabdat #t)
  (set-bg-on-filter commondat tabdat))

(define (mark-for-update)
  (set! *last-db-update-time* 0)
(define (mark-for-update tabdat)
  (dboard:tabdat-filters-changed-set! tabdat #t)
  (dboard:tabdat-last-db-update-set! tabdat 0))
  (set! *delayed-update* 1))

;;======================================================================
;; R U N C O N T R O L
;;======================================================================

;; target populating logic
;;  
611
612
613
614
615
616
617
618

619

620

621
622
623
624
625
626
627
628
629
630
631












632

633
634
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649



650
651
652
653
654
655
656
657
658
659
660
661
662










663
664
665
666
667
668
669
670
671
672
673
674
675
676
677

678
679


680
681
682
683
684






685
686
687

688
689
690
691
692




693
694
695
696



697
698

699
700
701
702

703
704
705
706

707
708
709

710
711


712
713
714
715
716

717
718
719
720
721
722
723
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
1013
1014
1015
1016
1017
1018








1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048





1049
1050
1051
1052
1053
1054
1055
1056

1057
1058




1059
1060
1061
1062
1063



1064
1065
1066
1067

1068
1069
1070
1071

1072
1073
1074
1075

1076
1077
1078

1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095







-
+

+
-
+
-
-


-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

+









-
+





-
-
+
+
+





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+















+


+
+
-
-
-
-
-
+
+
+
+
+
+


-
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
+



-
+



-
+


-
+

-
+
+





+







      (if val
	  val
	  (if (not (null? values))
	      (let ((newval (car values)))
		(iup:attribute-set! lb "VALUE" newval)
		newval))))))

(define (dashboard:update-target-selector key-lbs #!key (action-proc #f))
(define (dashboard:update-target-selector tabdat #!key (action-proc #f))
  (let* ((runconf-targs (common:get-runconfig-targets))
	 (key-lbs       (dboard:tabdat-key-listboxes tabdat))
	 (db-target-dat (if *useserver* 
	 (db-target-dat (rmt:get-targets))
			    (rmt:get-targets)
			    (db:get-targets *dbstruct-local*)))
	 (header        (vector-ref db-target-dat 0))
	 (db-targets    (vector-ref db-target-dat 1))
	 (all-targets   (append db-targets
				(map (lambda (x)
				       (list->vector
					(take (append (string-split x "/")
						      (make-list (length header) "na"))
					      (length header))))
				     runconf-targs)))
	 (munge-target  (lambda (x)            ;; create a target vector from a string. Pad with na if needed.
			  (list->vector
			   (take (append (string-split x "/")
					 (make-list (length header) "na"))
				 (length header)))))
	 (all-targets   (append (list (munge-target (string-intersperse 
						     (map (lambda (x) "%") header)
						     "/")))
				db-targets
				(map munge-target
				     runconf-targs)
				))
	 (key-listboxes (if key-lbs key-lbs (make-list (length header) #f))))
    (if (not (dboard:tabdat-key-listboxes tabdat))(dboard:tabdat-key-listboxes-set! tabdat key-listboxes))
    (let loop ((key     (car header))
	       (remkeys (cdr header))
	       (refvals '())
	       (indx    0)
	       (lbs     '()))
      (let* ((lb (let ((lb (list-ref key-listboxes indx)))
		   (if lb
		       lb
		       (iup:listbox 
			#:size "45x50" 
			#:size "x60" 
			#:fontsize "10"
			#:expand "YES" ;; "VERTICAL"
			;; #:dropdown "YES"
			#:editbox "YES"
			#:action (lambda (obj a b c)
				   (action-proc))
			#:caret_cb (lambda (obj a b c)(action-proc))
				   (debug:catch-and-dump action-proc "update-target-selector"))
			#:caret_cb (lambda (obj a b c)
				     (debug:catch-and-dump action-proc "update-target-selector"))
			))))
	     ;; loop though all the targets and build the list for this dropdown
	     (selected-value (dashboard:populate-target-dropdown lb refvals all-targets)))
	(if (null? remkeys)
	    ;; return a list of the listbox items and an iup:hbox with the labels and listboxes
	    (let ((listboxes (append lbs (list lb))))
	      (list listboxes
		    (map (lambda (htxt lb)
			   (iup:vbox
			    (iup:label htxt) 
			    lb))
			 header
			 listboxes)))
	    (let* ((listboxes (append lbs (list lb)))
		   (res       (list listboxes
				    (map (lambda (htxt lb)
					   (iup:vbox
					    (iup:label htxt) 
					    lb))
					 header
					 listboxes))))
	      (dboard:tabdat-key-listboxes-set! tabdat res)
	      res)
	    (loop (car remkeys)
		  (cdr remkeys)
		  (append refvals (list selected-value))
		  (+ indx 1)
		  (append lbs (list lb))))))))

;; Make a vertical list of toggles using items, when toggled call proc with the conc'd string 
;; interspersed with commas
;;
(define (dashboard:text-list-toggle-box items proc)
  (let ((alltgls (make-hash-table)))
    (apply iup:vbox
	   (map (lambda (item)
		  (iup:toggle 
		   item
		   #:fontsize 8
		   #:expand "YES"
		   #:action (lambda (obj tstate)
			       (debug:catch-and-dump 
				(lambda ()
			      (if (eq? tstate 0)
				  (hash-table-delete! alltgls item)
				  (hash-table-set! alltgls item #t))
			      (let ((all (hash-table-keys alltgls)))
				(proc all)))))
				  (if (eq? tstate 0)
				      (hash-table-delete! alltgls item)
				      (hash-table-set! alltgls item #t))
				  (let ((all (hash-table-keys alltgls)))
				    (proc all)))
				"text-list-toggle-box"))))
		items))))

;; Extract the various bits of data from *data* and create the command line equivalent that will be displayed
;; Extract the various bits of data from tabdat and create the command line equivalent that will be displayed
;;
(define (dashboard:update-run-command)
  (let* ((cmd-tb       (dboard:data-get-command-tb *data*))
	 (cmd          (dboard:data-get-command    *data*))
	 (test-patt    (let ((tp (dboard:data-get-test-patts *data*)))
(define (dashboard:update-run-command tabdat)
  (let* ((cmd-tb       (dboard:tabdat-command-tb tabdat))
	 (cmd          (dboard:tabdat-command    tabdat))
	 (test-patt    (let ((tp (dboard:tabdat-test-patts tabdat)))
			 (if (equal? tp "") "%" tp)))
	 (states       (dboard:data-get-states     *data*))
	 (statuses     (dboard:data-get-statuses   *data*))
	 (target       (let ((targ-list (dboard:data-get-target     *data*)))
	 (states       (dboard:tabdat-states     tabdat))
	 (statuses     (dboard:tabdat-statuses   tabdat))
	 (target       (let ((targ-list (dboard:tabdat-target     tabdat)))
			 (if targ-list (string-intersperse targ-list "/") "no-target-selected")))
	 (run-name     (dboard:data-get-run-name   *data*))
	 (run-name     (dboard:tabdat-run-name   tabdat))
	 (states-str   (if (or (not states)
			       (null? states))
			   ""
			   (conc " :state "  (string-intersperse states ","))))
			   (conc " -state "  (string-intersperse states ","))))
	 (statuses-str (if (or (not statuses)
			       (null? statuses))
			   ""
			   (conc " :status " (string-intersperse statuses ","))))
			   (conc " -status " (string-intersperse statuses ","))))
	 (full-cmd  "megatest"))
    (case (string->symbol cmd)
      ((runtests)
      ((run)
       (set! full-cmd (conc full-cmd 
			    " -runtests "
			    " -run"
			    " -testpatt "
			    test-patt
			    " -target "
			    target
			    " -runname "
			    run-name
			    " -clean-cache"
			    )))
      ((remove-runs)
       (set! full-cmd (conc full-cmd
			    " -remove-runs -runname "
			    run-name
			    " -target " 
			    target
732
733
734
735
736
737
738
739
740
741
742
743
744






745
746
747
748



749
750
751
752
753
































































































































754
755
756
757
758
759
760
761

762
763
764
765
766
767
768

769
770
771
772
773
774
775
776
777
778












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
816









817
818

819
820
821


822
823

824
825
826

827
828
829
830








831
832
833


834
835
836

837
838

839
840
841
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
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
1013
1014



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033




























1034
1035
1036
1037
1038
1039
1040
1041



1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083

1084
1085
1086



1087
1088
1089
1090
1091
1092


1093
1094
1095
1096
1097
1098
1099
1100
1101
1102














1103
1104
1105
1106
1107
1108
1109
1110
1111

1112
1113

1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
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
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

1234
1235

1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252






1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264

1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276






1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287


1288
1289

1290
1291

1292
1293

1294
1295
1296
1297
1298
1299
1300
1301
1302
1303

1304
1305
1306

1307
1308
1309
1310

1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350


































































































1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
















1365
1366
1367
1368
1369
1370
1371
























































































































1372
1373
1374
1375
1376
1377
1378
1379
1380


1381
1382
1383


1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399




1400
1401
1402
1403
1404
1405
1406
1407
1408
1409

1410
1411
1412
1413
1414
1415
1416



1417
1418
1419


1420
1421
1422

1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456












1457
1458





















1459

1460
1461
1462



1463
1464
1465
1466
1467
1468
1469
1470
1471
1472







1473
1474
1475
1476
1477
1478








1479
1480








1481
1482
1483




1484
1485
1486




1487
1488
1489
1490
1491
1492



1493

1494
1495











1496
1497


1498
1499


1500
1501
1502

1503
1504
1505

1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517


1518
1519
1520


1521
1522
1523
1524
1525
1526
1527
1528

1529
1530
1531
1532
1533
1534

1535
1536
1537
1538

1539
1540
1541
1542

1543
1544
1545
1546
1547
1548






1549
1550
1551

1552
1553
1554
1555


1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
































































































































































































































































































































































































































































































































































































































































1583
1584
1585
1586
1587
1588
1589
1590
1591
1592




1593

1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642



























































1643
1644
1645
1646

1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658




1659
1660

1104
1105
1106
1107
1108
1109
1110






1111
1112
1113
1114
1115
1116




1117
1118
1119





1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254

1255







1256










1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268





1269
1270
1271
1272





1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283


1284
1285






1286
1287
1288
1289
1290
1291





1292
1293
1294
1295






1296









1297
1298
1299
1300
1301
1302
1303
1304
1305


1306



1307
1308


1309



1310




1311
1312
1313
1314
1315
1316
1317
1318



1319
1320



1321


1322










1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334


1335





1336
1337
1338







1339
1340
1341
1342
1343
1344


1345
1346








1347
1348
1349
1350




1351
1352


1353
1354
1355
1356





















1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386





1387



1388





1389
1390







1391
1392
1393





1394
1395
1396
1397
1398
1399
1400
1401





1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413







1414
1415
1416
1417
1418
1419
1420
1421
1422









1423
1424











1425
1426
1427
1428
1429
1430
1431
1432
1433
1434






















1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464









1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476


1477
1478
1479


1480









1481
1482
1483
1484
1485
1486










1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497



1498
1499
1500



















1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534


1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564

1565
1566
1567
1568
1569
1570
1571
1572





1573


1574



1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585










1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607

1608
1609

1610

















































1611






1612




1613






1614


1615


1616
1617
1618










1619








1620











1621






















1622


1623












1624





1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635







1636












1637
1638
1639
1640
1641
1642











1643
1644


1645


1646


1647










1648



1649




1650








































1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748













1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765







1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892


1893
1894
1895


1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909




1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922

1923
1924
1925
1926
1927



1928
1929
1930
1931


1932
1933
1934
1935

1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947

1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963







1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998

1999



2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010


2011
2012
2013
2014
2015
2016
2017






2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035



2036
2037
2038
2039
2040


2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055


2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070


2071
2072



2073



2074
2075
2076
2077
2078
2079



2080
2081


2082
2083
2084


2085
2086
2087
2088
2089
2090
2091
2092
2093

2094
2095
2096
2097
2098
2099

2100
2101
2102
2103

2104
2105
2106
2107

2108
2109





2110
2111
2112
2113
2114
2115



2116
2117
2118
2119
2120
2121
2122



























2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
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
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776

2777

















































2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836




2837












2838
2839
2840
2841
2842

2843







-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
+
+
-
-
+
-
-
-
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+

-
-
-
-
+
+
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
-
+
+
+















-
+











-
+







-
-
-
-
-
+
-
-
+
-
-
-
+
+
+






+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
+
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+





-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
+
+

-
-
+
+












-
-
-
-
+
+
+
+









-
+




-
-
-
+
+
+

-
-
+
+


-
+











-
+















-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+








-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
-
-
-
+
+
+
+

-
-
+
+
+
+






+
+
+

+
-
-
+
+
+
+
+
+
+
+
+
+
+


+
+
-
-
+
+
-
-
-
+
-
-
-
+





-
-
-


-
-
+
+

-
-
+
+







-
+





-
+



-
+



-
+

-
-
-
-
-
+
+
+
+
+
+
-
-
-
+




+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
+
;; Display the tests as rows of boxes on the test/task pane
;;
(define (dashboard:draw-tests cnv xadj yadj tests-draw-state sorted-testnames test-records)
  (canvas-clear! cnv)
  (canvas-font-set! cnv "Helvetica, -10")
  (let-values (((sizex sizey sizexmm sizeymm) (canvas-size cnv))
	       ((originx originy)             (canvas-origin cnv)))
      ;; (print "originx: " originx " originy: " originy)
      ;; (canvas-origin-set! cnv 0 (- (/ sizey 2)))
      (if (hash-table-ref/default tests-draw-state 'first-time #t)
	  (begin
	    (hash-table-set! tests-draw-state 'first-time #f)
	    (hash-table-set! tests-draw-state 'scalef 1)
    ;; (print "originx: " originx " originy: " originy)
    ;; (canvas-origin-set! cnv 0 (- (/ sizey 2)))
    (if (hash-table-ref/default tests-draw-state 'first-time #t)
	(begin
	  (hash-table-set! tests-draw-state 'first-time #f)
	  (hash-table-set! tests-draw-state 'scalef 1)
	    (hash-table-set! tests-draw-state 'dotscale 60)
	    (hash-table-set! tests-draw-state 'tests-info (make-hash-table))
	    (hash-table-set! tests-draw-state 'selected-tests (make-hash-table))
	    ;; set these 
	  (hash-table-set! tests-draw-state 'tests-info (make-hash-table))
	  (hash-table-set! tests-draw-state 'selected-tests (make-hash-table))
	  ;; set these 
	    (hash-table-set! tests-draw-state 'test-browse-xoffset 20) ;; (- 0 (* (/ sizex 2) (* 8 xadj))))
	    (hash-table-set! tests-draw-state 'test-browse-yoffset 20) ;; (- 0 (* (/ sizey 2) (* 8 (- 1 yadj)))))))
	    (dcommon:initial-draw-tests cnv xadj yadj sizex sizey sizexmm sizeymm originx originy tests-draw-state sorted-testnames test-records))
	  (dcommon:redraw-tests cnv xadj yadj sizex sizey sizexmm sizeymm originx originy tests-draw-state sorted-testnames test-records))
      ))
	  (dcommon:initial-draw-tests cnv xadj yadj sizex sizey sizexmm sizeymm originx originy tests-draw-state sorted-testnames test-records))
	(dcommon:redraw-tests cnv xadj yadj sizex sizey sizexmm sizeymm originx originy tests-draw-state sorted-testnames test-records))
    ))

;;======================================================================
;; R U N   C O N T R O L S
;;======================================================================
;;
;; A gui for launching tests
;;

(define (dboard:target-updater tabdat) ;;  key-listboxes)
  (let ((targ (map (lambda (x)
		     (iup:attribute x "VALUE"))
		   (car (dashboard:update-target-selector tabdat))))
	(curr-runname (dboard:tabdat-run-name tabdat)))
    (dboard:tabdat-target-set! tabdat targ)
    ;; (if (dboard:tabdat-updater-for-runs tabdat)
    ;; 	 ((dboard:tabdat-updater-for-runs tabdat)))
    (if (or (not (equal? curr-runname (dboard:tabdat-run-name tabdat)))
	    (equal? (dboard:tabdat-run-name tabdat) ""))
	(dboard:tabdat-run-name-set! tabdat curr-runname))
    (dashboard:update-run-command tabdat)))

;; used by run-controls
;;
(define (dashboard:update-tree-selector tabdat #!key (action-proc #f))
  (let* ((tb            (dboard:tabdat-runs-tree tabdat))
	 (runconf-targs (common:get-runconfig-targets))
	 (db-target-dat (rmt:get-targets))
	 (header        (vector-ref db-target-dat 0))
	 (db-targets    (vector-ref db-target-dat 1))
	 (munge-target  (lambda (x)            ;; create a target vector from a string. Pad with na if needed.
			  (take (append (string-split x "/")
					(make-list (length header) "na"))
				(length header))))
	 (all-targets   (append (list (munge-target (string-intersperse 
						     (map (lambda (x) "%") header)
						     "/")))
				(map vector->list db-targets)
				(map munge-target
				     runconf-targs)
				)))
    (for-each
     (lambda (target)
       (tree:add-node tb "Runs" target)) ;; (append key-vals (list run-name))
     all-targets)))

(define (dashboard:run-controls commondat tabdat #!key (tab-num #f))
  (let* ((targets       (make-hash-table))
	 (test-records  (make-hash-table))
	 (all-tests-registry (tests:get-all)) ;; (tests:get-valid-tests *toppath* '()))
	 (test-names    (hash-table-keys all-tests-registry))
	 (sorted-testnames #f)
	 (action        "-run")
	 (cmdln         "")
	 (runlogs       (make-hash-table))
	 ;;; (key-listboxes #f)
	 (update-keyvals (lambda () ;; gets called in dashboard:update-target-selector as "action-proc"
			   (dboard:target-updater (dboard:tabdat-key-listboxes tabdat))))
	 (tests-draw-state (make-hash-table)) ;; use for keeping state of the test canvas
	 (test-patterns-textbox  #f))
    (hash-table-set! tests-draw-state 'first-time #t)
    ;; (hash-table-set! tests-draw-state 'scalef 1)
    (tests:get-full-data test-names test-records '() all-tests-registry)
    (set! sorted-testnames (tests:sort-by-priority-and-waiton test-records))
    
    ;; refer to (dboard:tabdat-keys tabdat), (dboard:tabdat-dbkeys tabdat) for keys
    (let* ((result
	    (iup:vbox
	     (dcommon:command-execution-control tabdat)
	     (iup:split
	      #:orientation "VERTICAL" ;; "HORIZONTAL"
	      #:value 200
	      ;; 
	     ;;       (iup:split
	     ;;        #:value 300

	     ;; Target, testpatt, state and status input boxes
	     ;;
	     (iup:vbox
	      ;; Command to run, placed over the top of the canvas
	      (dcommon:command-action-selector commondat tabdat tab-num: tab-num)
	      (dboard:runs-tree-browser commondat tabdat)
	      (dcommon:command-runname-selector commondat tabdat tab-num: tab-num)
	      (dcommon:command-testname-selector commondat tabdat update-keyvals))
	     ;;  key-listboxes))
	     (dcommon:command-tests-tasks-canvas tabdat test-records sorted-testnames tests-draw-state))))
	   (tb (dboard:tabdat-runs-tree tabdat)))
      (dboard:commondat-add-updater 
       commondat 
       (lambda ()
	 (dashboard:update-tree-selector tabdat))
       tab-num: tab-num)
      result)))

 ;;(iup:frame
 ;; #:title "Logs" ;; To be replaced with tabs
 ;; (let ((logs-tb (iup:textbox #:expand "YES"
 ;;				   #:multiline "YES")))
 ;;	 (dboard:tabdat-logs-textbox-set! tabdat logs-tb)
 ;;	 logs-tb))

(define (dboard:runs-tree-browser commondat tabdat)
  (let* ((tb      (iup:treebox
		   #:value 0
		   #:name "Runs"
		   #:expand "YES"
		   #:addexpanded "NO"
		   #:selection-cb
		   (lambda (obj id state)
		     (debug:catch-and-dump
		      (lambda ()
			(let* ((run-path (tree:node->path obj id))
			       (run-id    (tree-path->run-id tabdat (cdr run-path))))
                          ;; (dboard:tabdat-view-changed-set! tabdat #t) ;; ?? done below when run-id is a number
			  (dboard:tabdat-target-set! tabdat (cdr run-path)) ;; (print "run-path: " run-path)			    
			  (dboard:tabdat-layout-update-ok-set! tabdat #f)
			  (if (number? run-id)
			      (begin
				(dboard:tabdat-curr-run-id-set! tabdat run-id)
				(dboard:tabdat-view-changed-set! tabdat #t))
			      (debug:print-error 5 *default-log-port* "tree-path->run-id returned non-number " run-id))))
		      "treebox"))
		   ;; (print "path: " (tree:node->path obj id) " run-id: " run-id)
		   )))
    (dboard:tabdat-runs-tree-set! tabdat tb)
    tb))

;;======================================================================
;; R U N   C O N T R O L S
;;======================================================================
;;
;; A gui for launching tests
;;
(define (dashboard:run-controls)
(define (dashboard:run-times commondat tabdat #!key (tab-num #f))
  (let* ((targets       (make-hash-table))
	 (test-records  (make-hash-table))
	 (all-tests-registry (tests:get-all)) ;; (tests:get-valid-tests *toppath* '()))
	 (test-names    (hash-table-keys all-tests-registry))
	 (sorted-testnames #f)
	 (action        "-runtests")
	 (cmdln         "")
  (let* ((drawing               (vg:drawing-new))
	 (runlogs       (make-hash-table))
	 (key-listboxes #f)
	 (updater-for-runs #f)
	 (update-keyvals (lambda ()
			   (let ((targ (map (lambda (x)
					      (iup:attribute x "VALUE"))
					    (car (dashboard:update-target-selector key-listboxes)))))
			     (dboard:data-set-target! *data* targ)
			     (if updater-for-runs (updater-for-runs))
			     (dashboard:update-run-command))))
	 (run-times-tab-updater (lambda ()	
				  (debug:catch-and-dump 
				   (lambda ()
				     (let ((tabdat        (dboard:common-get-tabdat commondat tab-num: tab-num)))
				       (if tabdat
					   (let ((last-data-update (dboard:tabdat-last-data-update tabdat))
						 (now-time         (current-seconds)))
					     (dashboard:run-times-tab-canvas-updater commondat tabdat tab-num)
					     (if (> (- now-time last-data-update) 5)
						 (if (not (dboard:tabdat-running-layout tabdat))
						     (begin
						       (dashboard:run-times-tab-run-data-updater commondat tabdat tab-num)
	 (tests-draw-state (make-hash-table)) ;; use for keeping state of the test canvas
	 (test-patterns-textbox  #f))
    (hash-table-set! tests-draw-state 'first-time #t)
    ;; (hash-table-set! tests-draw-state 'scalef 1)
    ;; (hash-table-set! tests-draw-state 'dotscale 60)
						       (dboard:tabdat-last-data-update-set! tabdat now-time)
						       (thread-start! (make-thread
								       (lambda ()
									 (dboard:tabdat-running-layout-set! tabdat #t)
    (tests:get-full-data test-names test-records '() all-tests-registry)
    (set! sorted-testnames (tests:sort-by-priority-and-waiton test-records))
    
    ;; refer to *keys*, *dbkeys* for keys
    (iup:vbox
									 (dashboard:run-times-tab-layout-updater commondat tabdat tab-num)
									 (dboard:tabdat-running-layout-set! tabdat #f))
								       "run-times-tab-layout-updater")))
						     ))))))
				   "dashboard:run-times-tab-updater")))
	 (key-listboxes #f) ;; 
	 (update-keyvals (lambda ()
			   (dboard:target-updater tabdat))))
    (dboard:tabdat-drawing-set! tabdat drawing)
    (dboard:commondat-add-updater commondat run-times-tab-updater tab-num: tab-num)
    (iup:split
     ;; The command line display/exectution control
     (iup:frame
     #:orientation "VERTICAL" ;; "HORIZONTAL"
     #:value 150
      #:title "Command to be exectuted"
      (iup:hbox
       (iup:label "Run on" #:size "40x")
       (iup:radio 
	(iup:hbox
	 (iup:toggle "Local" #:size "40x")
     (iup:vbox

      (dboard:runs-tree-browser commondat tabdat)

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

     (iup:split
      #:orientation "HORIZONTAL"
      
      (iup:split
		   (debug:catch-and-dump 
		    (lambda ()
		      (print "tstate: " tstate)
		      (if (eq? tstate 0)
			  (dboard:tabdat-compact-layout-set! tabdat #f)
			  (dboard:tabdat-compact-layout-set! tabdat #t))
		      (dboard:tabdat-last-filter-str-set! tabdat "")
		      )
		    "text-list-toggle-box"))))
       #:value 300

      (dcommon:command-runname-selector commondat tabdat tab-num: tab-num)
       ;; Target, testpatt, state and status input boxes
       ;;
       (iup:vbox
      (dcommon:command-testname-selector commondat tabdat update-keyvals))
     (iup:vbox
	;; Command to run
	(iup:frame
      (let* ((cnv-obj (iup:canvas 
	 #:title "Set the action to take"
	 (iup:hbox
	  ;; (iup:label "Command to run" #:expand "HORIZONTAL" #:size "70x" #:alignment "LEFT:ACENTER")
		       ;; #:size "500x400"
	  (let* ((cmds-list '("runtests" "remove-runs" "set-state-status" "lock-runs" "unlock-runs"))
		 (lb         (iup:listbox #:expand "HORIZONTAL"
					  #:dropdown "YES"
					  #:action (lambda (obj val index lbstate)
		       #:expand "YES"
		       #:scrollbar "YES"
		       #:posx "0.5"
		       #:posy "0.5"
		       #:action (make-canvas-action
				  (lambda (c xadj yadj)
				    (debug:catch-and-dump
				     (lambda ()
						     ;; (print obj " " val " " index " " lbstate)
						     (dboard:data-set-command! *data* val)
						     (dashboard:update-run-command))))
				       (if (not (dboard:tabdat-cnv tabdat))
					   (let ((cnv     (dboard:tabdat-cnv tabdat)))
		 (default-cmd (car cmds-list)))
	    (iuplistbox-fill-list lb cmds-list selected-item: default-cmd)
	    (dboard:data-set-command! *data* default-cmd)
					     (dboard:tabdat-cnv-set! tabdat c)
	    lb)))

					     (vg:drawing-cnv-set! (dboard:tabdat-drawing tabdat)
	(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-set-run-name! *data* txt) ;; (iup:attribute obj "VALUE"))
					    (dashboard:update-run-command))
				 #:value default-run-name))
		(lb (iup:listbox #:expand "HORIZONTAL"
								  (dboard:tabdat-cnv tabdat))))
				       (let ((drawing (dboard:tabdat-drawing tabdat))
					     (old-xadj (dboard:tabdat-xadj   tabdat))
					     (old-yadj (dboard:tabdat-yadj   tabdat)))
					 (if (not (and (eq? xadj old-xadj)(eq? yadj old-yadj)))
					     (begin
					       ;; (print  "xadj: " xadj " yadj: " yadj "changed: "(eq? xadj old-xadj) " " (eq? yadj old-yadj))
					       (dboard:tabdat-view-changed-set! tabdat #t)
					       (dboard:tabdat-xadj-set! tabdat (* -2000 (- xadj 0.5)))
					       (dboard:tabdat-yadj-set! tabdat (*  2000 (- yadj 0.5)))
					       ))))
				     "iup:canvas action")))
				 #:dropdown "YES"
				 #:action (lambda (obj val index lbstate)
		       #:wheel-cb  (lambda (obj step x y dir) ;; dir is 4 for up and 5 for down. I think.
					    (iup:attribute-set! tb "VALUE" val)
					    (dboard:data-set-run-name! *data* val)
					    (dashboard:update-run-command))))
		(refresh-runs-list (lambda ()
				     (let* ((target        (dboard:data-get-target-string *data*))
				     (debug:catch-and-dump
				      (lambda ()
					(let* ((drawing (dboard:tabdat-drawing tabdat))
					    (runs-for-targ (if *useserver*
							       (rmt:get-runs-by-patt *keys* "%" target #f #f #f)
							       (db:get-runs-by-patt *dbstruct-local* *keys* "%" 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)
					       (scalex  (vg:drawing-scalex drawing)))
					  (dboard:tabdat-view-changed-set! tabdat #t)
					  ;; (print "step: " step " x: " x " y: " y " dir: " dir " scalex: " scalex)
					  (vg:drawing-scalex-set! drawing
								  (+ scalex
								     (if (> step 0)
									(db:get-value-by-header x runs-header "runname"))
								      runs-dat))))
									 (* scalex  0.02)
									 (* scalex -0.02))))))
				       (iup:attribute-set! lb "REMOVEITEM" "ALL")
				       (iuplistbox-fill-list lb run-names selected-item: default-run-name)))))
	   (set! updater-for-runs refresh-runs-list)
	   (refresh-runs-list)
	   (dboard:data-set-run-name! *data* default-run-name)
	   (iup:hbox
	    tb
	    lb)))
				      "wheel-cb"))
		       )))
	cnv-obj)))))

	(iup:frame
	 #:title "SELECTORS"
	 (iup:vbox
	  ;; Text box for test patterns
;;======================================================================
;; R U N
	  (iup:frame
	   #:title "Test patterns (one per line)"
;;======================================================================
;;
;; display and manage a single run at a time

	   (let ((tb (iup:textbox #:action (lambda (val a b)
					     (dboard:data-set-test-patts!
					      *data*
					      (dboard:lines->test-patt b))
					     (dashboard:update-run-command))
				  #:value (dboard:test-patt->lines
					   (dboard:data-get-test-patts *data*))
				  #:expand "YES"
				  #:size "x50"
				  #:multiline "YES")))
	     (set! test-patterns-textbox tb)
	     tb))
	  (iup:frame
	   #:title "Target"
	   ;; Target selectors
	   (apply iup:hbox
		  (let* ((dat      (dashboard:update-target-selector key-listboxes action-proc: update-keyvals))
			 (key-lb   (car dat))
			 (combos   (cadr dat)))
		    (set! key-listboxes key-lb)
		    combos)))
(define (tree-path->run-id tabdat path)
  (if (not (null? path))
      (hash-table-ref/default (dboard:tabdat-path-run-ids tabdat) path #f)
      #f))

(define (dboard:get-tests-dat tabdat run-id last-update)
  (let* ((tdat (if run-id (rmt:get-tests-for-run run-id 
					     (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "test-name" "%/%")
					     (hash-table-keys (dboard:tabdat-state-ignore-hash tabdat))  ;; '()
					     (hash-table-keys (dboard:tabdat-status-ignore-hash tabdat)) ;; '()
					     #f #f                                                       ;; offset limit
					     (dboard:tabdat-hide-not-hide tabdat)                        ;; not-in
					     #f #f                                                       ;; sort-by sort-order
					     #f ;; get all? "id,testname,item_path,state,status,event_time,run_duration"                        ;; qryval
					     (if (dboard:tabdat-filters-changed tabdat)
						 0
						 last-update)
					     *dashboard-mode*)
		  '()))) ;; get 'em all
    ;; (debug:print 0 *default-log-port* "dboard:get-tests-dat: got " (length tdat) " test records for run " run-id)
    (sort tdat (lambda (a b)
		 (let* ((aval (vector-ref a 2))
			(bval (vector-ref b 2))
			(anum (string->number aval))
			(bnum (string->number bval)))
		   (if (and anum bnum)
		       (< anum bnum)
		       (string<= aval bval)))))))


	  (iup:hbox
	   ;; Text box for STATES
	   (iup:frame
	    #:title "States"
	    (dashboard:text-list-toggle-box 
(define (dashboard:safe-cadr-assoc name lst)
	     ;; 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)
  (let ((res (assoc name lst)))
	       (dboard:data-set-states! *data* all)
	       (dashboard:update-run-command))))
	   ;; Text box for STATES
	   (iup:frame
	    #:title "Statuses"
    (if (and res (> (length res) 1))
	(cadr res)
	    (dashboard:text-list-toggle-box 
	     (map cadr *common:std-statuses*) ;; '("PASS" "FAIL" "n/a" "CHECK" "WAIVED" "SKIP" "DELETED" "STUCK/DEAD")
	     (lambda (all)
	       (dboard:data-set-statuses! *data* all)
	       (dashboard:update-run-command))))))))
      
       (iup:frame
	#f)))

(define (dboard:update-tree tabdat runs-hash runs-header tb)
	#:title "Tests and Tasks"
	(let* ((updater #f)
	       (last-xadj 0)
	       (last-yadj 0)
	       (the-cnv   #f)
  (let* ((run-ids (sort (filter number? (hash-table-keys runs-hash))
			(lambda (a b)
			  (let* ((record-a (hash-table-ref runs-hash a))
				 (record-b (hash-table-ref runs-hash b))
				 (time-a   (db:get-value-by-header record-a runs-header "event_time"))
				 (time-b   (db:get-value-by-header record-b runs-header "event_time")))
			    (< time-a time-b)))))
         (changed      #f)
	       (canvas-obj 
                (iup:canvas #:action (make-canvas-action
				      (lambda (cnv xadj yadj)
					(if (not updater)
					    (set! updater (lambda (xadj yadj)
	 (runs-dat     (rmt:get-runs-by-patt (dboard:tabdat-keys tabdat) "%" #f #f #f #f)))
    (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 runs-header key))
					(dboard:tabdat-keys tabdat)))
		       (run-name   (db:get-value-by-header run-record runs-header "runname"))
		       (col-name   (conc (string-intersperse key-vals "\n") "\n" run-name))
		       (run-path   (append key-vals (list run-name)))
		       (existing   (tree:find-node tb run-path)))
		  (if (not (hash-table-ref/default (dboard:tabdat-path-run-ids tabdat) run-path #f))
		      (begin
			(hash-table-set! (dboard:tabdat-run-keys tabdat) run-id run-path)
							    ;; (print "cnv: " cnv " xadj: " xadj " yadj: " yadj)
							    (dashboard:draw-tests cnv xadj yadj tests-draw-state sorted-testnames test-records)
							    (set! last-xadj xadj)
							    (set! last-yadj yadj))))
					(updater xadj yadj)
					(set! the-cnv cnv)
					))
			;; (iup:attribute-set! (dboard:tabdat-runs-matrix tabdat)
			;;    		 (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 tb "Runs" run-path ;; (append key-vals (list run-name))
				       userdata: (conc "run-id: " run-id))
			(hash-table-set! (dboard:tabdat-path-run-ids tabdat) run-path run-id)
			;; (set! colnum (+ colnum 1))
			))))
			    ;; Following doesn't work 
			    #:wheel-cb (lambda (obj step x y dir) ;; dir is 4 for up and 5 for down. I think.
					 (let ((scalef (hash-table-ref tests-draw-state 'scalef)))
					   ;; (debug:print 0 "step=" step ", dir=" dir ", scalef=" scalef ", x=" x ", y=" y)
					   ;; (let (;; (xadj last-xadj)
					   ;; (yadj (+ last-yadj (if (> step 0)
					   ;;		      -0.01
					   ;;			      0.01))))
					   (hash-table-set! tests-draw-state 'scalef (+ scalef
	      run-ids)))
  
											(if (> step 0)
											    0.01
											    -0.01)))

					   ;; (print "step: " step " x: " x " y: " y " dir: \"" dir "\"")
					   ;; (print "the-cnv: " the-cnv " obj: " obj " xadj: " xadj " yadj: " yadj " dir: " dir)
					   (if the-cnv
					       (dashboard:draw-tests the-cnv last-xadj last-yadj tests-draw-state sorted-testnames test-records))
					   ;; (set! last-xadj xadj)
					   ;; (set! last-yadj yadj)
					   ))
(define (dashboard:one-run-updater commondat tabdat tb cell-lookup run-matrix)
  (let* ((runs-dat     (rmt:get-runs-by-patt (dboard:tabdat-keys tabdat) "%" #f #f #f #f))
	 (runs-header  (vector-ref runs-dat 0)) ;; 0 is header, 1 is list of records
	 (run-id       (dboard:tabdat-curr-run-id tabdat))
	 (last-update  (hash-table-ref/default (dboard:tabdat-run-update-times tabdat) run-id 0))
	 (db-path      (or (hash-table-ref/default (dboard:tabdat-run-db-paths tabdat) run-id #f)
			   (let* ((db-dir (tasks:get-task-db-path))
				  (db-pth (conc db-dir "/" run-id ".db")))
			     (hash-table-set! (dboard:tabdat-run-db-paths tabdat) run-id db-pth)
			     db-pth)))
			    ;; #:size "50x50"
			    #:expand "YES"
			    #:scrollbar "YES"
			    #:posx "0.5"
			    #:posy "0.5"
			    #:button-cb (lambda (obj btn pressed x y status)
					  (print "obj: " obj ", pressed " pressed ", status " status)
					  (print "canvas-origin: " (canvas-origin the-cnv))
					  (let-values (((xx yy)(canvas-origin the-cnv)))
					    (canvas-transform-set! the-cnv #f)
					    (print "canvas-origin: " xx " " yy " click at " x " " y))
					  (let ((tests-info     (hash-table-ref tests-draw-state  'tests-info))
						(selected-tests (hash-table-ref tests-draw-state  'selected-tests)))
					    ;; (print "\tx\ty\tllx\tlly\turx\tury")
					    (for-each (lambda (test-name)
							(let* ((rec-coords (hash-table-ref tests-info test-name))
							       (llx        (list-ref rec-coords 0))
							       (urx        (list-ref rec-coords 1))
							       (lly        (list-ref rec-coords 2))
							       (ury        (list-ref rec-coords 3)))
							  ;; (print "\t" x "\t" y "\t" llx "\t" lly "\t" urx "\t" ury "\t" test-name " ")
							  (if (and (eq? pressed 1)
	 (tests-dat    (if (or (not run-id)
			       (configf:lookup *configdat* "setup" "do-not-use-db-file-timestamps")
                               (not (hash-table-exists? (dboard:tabdat-last-test-dat tabdat) run-id))
			       (>= (file-modification-time db-path) last-update))
			   (dboard:get-tests-dat tabdat run-id last-update)
			   (hash-table-ref (dboard:tabdat-last-test-dat tabdat) run-id)))
	 (tests-mindat (dcommon:minimize-test-data tests-dat))
	 (indices      (common:sparse-list-generate-index tests-mindat)) ;;  proc: set-cell))
	 (row-indices  (cadr indices))
	 (col-indices  (car indices))
	 (max-row      (if (null? row-indices) 1 (common:max (map cadr row-indices))))
	 (max-col      (if (null? col-indices) 1 (common:max (map cadr col-indices))))
	 (max-visible  (max (- (dboard:tabdat-num-tests tabdat) 15) 3)) ;; (dboard:tabdat-num-tests tabdat) is proportional to the size of the window
	 (numrows      1)
	 (numcols      1)
	 (changed      #f)
	 (runs-hash    (let ((ht (make-hash-table)))
			 (for-each (lambda (run)
				     (hash-table-set! ht (db:get-value-by-header run runs-header "id") run))
				   (vector-ref runs-dat 1))
			 ht)))
    (hash-table-set! (dboard:tabdat-last-test-dat tabdat) run-id tests-dat)
    (hash-table-set! (dboard:tabdat-run-update-times tabdat) run-id (- (current-seconds) 10))
    (dboard:tabdat-filters-changed-set! tabdat #f)
    (let loop ((pass-num 0)
	       (changed  #f))
      ;; Update the runs tree
      (dboard:update-tree tabdat runs-hash runs-header tb)
      
      (if (eq? pass-num 1)
								   (> x llx)
								   (> y lly)
								   (< x urx)
								   (< y ury))
							      (let ((patterns (string-split (iup:attribute test-patterns-textbox "VALUE"))))
								(let* ((selected     (not (member test-name patterns)))
								       (newpatt-list (if selected
											 (cons test-name patterns)
											 (delete test-name patterns)))
	  (begin ;; big reset
	    (iup:attribute-set! run-matrix "CLEARVALUE" "ALL") ;; NOTE: Was CONTENTS
	    (iup:attribute-set! run-matrix "CLEARATTRIB" "CONTENTS")
	    (iup:attribute-set! run-matrix "RESIZEMATRIX" "YES")
	    (iup:attribute-set! run-matrix "NUMCOL" max-col )
	    (iup:attribute-set! run-matrix "NUMLIN" (if (< max-row max-visible) max-visible max-row)))) ;; min of 20
      
      ;; Row labels
      (for-each (lambda (ind)
		  (let* ((name (car ind))
			 (num  (cadr ind))
			 (key  (conc num ":0")))
								       (newpatt      (string-intersperse newpatt-list "\n")))
								  ;; (if cnv-obj
		    (if (not (equal? (iup:attribute run-matrix key) name))
			(begin
			  (set! changed #t)
								  ;;    (dashboard:draw-tests cnv-obj 0 0 tests-draw-state sorted-testnames))
								  (iup:attribute-set! obj "REDRAW" "ALL")
			  (iup:attribute-set! run-matrix key name)))))
								  (hash-table-set! selected-tests test-name selected)
								  (iup:attribute-set! test-patterns-textbox "VALUE" newpatt)
								  (dboard:data-set-test-patts! *data* (dboard:lines->test-patt newpatt))
								  (dashboard:update-run-command)
								  (if updater (updater last-xadj last-yadj)))))))
						      (hash-table-keys tests-info)))))))
	  canvas-obj)))
      ;; (print "obj: " obj " btn: " btn " pressed: " pressed " x: " x " y: " y " status: " status))
       
		row-indices)
      
      ;; (print "row-indices: " row-indices " col-indices: " col-indices)
      (if (and (eq? pass-num 0) changed)
	  (loop 1 #t)) ;; force second pass
      
      (iup:frame
       #:title "Logs" ;; To be replaced with tabs
       (let ((logs-tb (iup:textbox #:expand "YES"
				   #:multiline "YES")))
	 (dboard:data-set-logs-textbox! *data* logs-tb)
	 logs-tb))))))


;; (trace dashboard:populate-target-dropdown
;;        common:list-is-sublist)
      ;; Cell contents
      (for-each (lambda (entry)
		  ;; (print "entry: " entry)
		  (let* ((row-name  (cadr entry))
			 (col-name  (car entry))
			 (valuedat  (caddr entry))
			 (test-id   (list-ref valuedat 0))
			 (test-name row-name) ;; (list-ref valuedat 1))
			 (item-path col-name) ;; (list-ref valuedat 2))
			 (state     (list-ref valuedat 1))
			 (status    (list-ref valuedat 2))
;; 
;;       ;; key1 key2 key3 ...
;;       ;; target entry (wild cards allowed)
			 (value     (gutils:get-color-for-state-status state status))
			 (row-num   (cadr (assoc row-name row-indices)))
			 (col-num   (cadr (assoc col-name col-indices)))
;;       
;;       ;; The action
;;       (iup:hbox
;;        ;; label Action | action selector
;;        ))
;;      ;; Test/items selector
;;      (iup:hbox
;;       ;; tests
;;       ;; items
;;       ))
;;     ;; The command line
;;     (iup:hbox
;;      ;; commandline entry
;;      ;; GO button
;;      )
;;     ;; The command log monitor
;;     (iup:tabs
;;      ;; log monitor
;;      )))
			 (key       (conc row-num ":" col-num)))
		    (hash-table-set! cell-lookup key test-id)
		    (if (not (equal? (iup:attribute run-matrix key) (cadr value)))
			(begin
			  (set! changed #t)
			  (iup:attribute-set! run-matrix key (cadr value))
			  (iup:attribute-set! run-matrix (conc "BGCOLOR" key) (car value))))))
		tests-mindat)
      
      ;; Col labels - do after setting Cell contents so they are accounted for in the size calc.
      
      (for-each (lambda (ind)
		  (let* ((name (car ind))
			 (num  (cadr ind))
			 (key  (conc "0:" num)))
		    (if (not (equal? (iup:attribute run-matrix key) name))
			(begin
			  (set! changed #t)
			  (iup:attribute-set! run-matrix key name)
			  (iup:attribute-set! run-matrix "FITTOTEXT" (conc "C" num))))))
		col-indices)
      
      (if (and (eq? pass-num 0) changed)
	  (loop 1 #t)) ;; force second pass due to column labels changing
      
      ;; (debug:print 0 *default-debug-port* "one-run-updater, changed: " changed " pass-num: " pass-num)
      ;; (print "one-run-updater, changed: " changed " pass-num: " pass-num)
      (if changed (iup:attribute-set! run-matrix "REDRAW" "ALL")))))

;;======================================================================
;; S U M M A R Y 
;;======================================================================
;;
;; General info about the run(s) and megatest area
(define (dashboard:summary db)
  (let ((rawconfig        (read-config (conc *toppath* "/megatest.config") #f #f))) ;; changed to #f since I want #{} to be expanded by [system ...] to NOT be expanded. WAS: 'return-string)))
(define (dashboard:summary commondat tabdat #!key (tab-num #f))
  (let* ((rawconfig        (read-config (conc *toppath* "/megatest.config") #f #f)) ;; changed to #f since I want #{} to be expanded by [system ...] to NOT be expanded. WAS: 'return-string)))
	 (changed          #f))
    (iup:vbox
     (iup:split
      #:value 500
      (iup:frame 
       #:title "General Info"
       (iup:vbox
	(iup:hbox
	 (iup:label "Area Path")
	 (iup:textbox #:value *toppath* #:expand "HORIZONTAL"))
	(iup:hbox 
	 (dcommon:keys-matrix rawconfig)
	 (dcommon:general-info)
	 )))
      (iup:frame
       #:title "Server"
       (dcommon:servers-table)))
       (dcommon:servers-table commondat tabdat)))
     (iup:frame 
      #:title "Megatest config settings"
      (iup:hbox
       (dcommon:section-matrix rawconfig "setup" "Varname" "Value")
       (iup:vbox
	(dcommon:section-matrix rawconfig "server" "Varname" "Value")
	;; (iup:frame
	;; #:title "Disks Areas"
	(dcommon:section-matrix rawconfig "disks" "Disk area" "Path"))))
     (iup:frame
      #:title "Run statistics"
      (dcommon:run-stats db)))))
      (dcommon:run-stats commondat tabdat tab-num: tab-num)))))

;;======================================================================
;; R U N
;;======================================================================
;;
;; display and manage a single run at a time

(define (tree-path->run-id path)
  (if (not (null? path))
      (hash-table-ref/default (dboard:data-get-path-run-ids *data*) path #f)
      #f))

;; This is the Run Summary tab
(define dashboard:update-run-summary-tab #f)

;; 
;; (define (tests window-id)
(define (dashboard:one-run db)
  (let* ((tb      (iup:treebox
(define (dashboard:one-run commondat tabdat #!key (tab-num #f))
  (let* ((update-mutex (dboard:commondat-update-mutex commondat))
	 (tb      (iup:treebox
		   #:value 0
		   #:name "Runs"
		   #:expand "YES"
		   #:addexpanded "NO"
		   #:selection-cb
		   (lambda (obj id state)
		     (debug:catch-and-dump
		      (lambda ()
		     ;; (print "obj: " obj ", id: " id ", state: " state)
		     (let* ((run-path (tree:node->path obj id))
			    (run-id   (tree-path->run-id (cdr run-path))))
		       (if (number? run-id)
			   (begin
			     (dboard:data-set-curr-run-id! *data* run-id)
			     (dashboard:update-run-summary-tab))
			   (debug:print 0 "ERROR: tree-path->run-id returned non-number " run-id)))
		       ;; (print "path: " (tree:node->path obj id) " run-id: " run-id)
		       )))
			;; (print "obj: " obj ", id: " id ", state: " state)
			(let* ((run-path (tree:node->path obj id))
			       (run-id   (tree-path->run-id tabdat (cdr run-path))))
			  (if (number? run-id)
			      (begin
				(dboard:tabdat-curr-run-id-set! tabdat run-id)
				(dboard:tabdat-layout-update-ok-set! tabdat #f)
				;; (dashboard:update-run-summary-tab)
				)
			      ;; (debug:print-error 0 *default-log-port* "tree-path->run-id returned non-number " run-id)
			      )))
		      "selection-cb in one-run")
		     ;; (print "path: " (tree:node->path obj id) " run-id: " run-id)
		     )))
	 (cell-lookup (make-hash-table))
	 (run-matrix (iup:matrix
		      #:expand "YES"
		      #:click-cb
		      (lambda (obj lin col status)
			(let* ((toolpath (car (argv)))
			       (key      (conc lin ":" col))
			       (test-id  (hash-table-ref/default cell-lookup key -1))
			       (cmd      (conc toolpath " -test " (dboard:data-get-curr-run-id *data*) "," test-id "&")))
			       (cmd      (conc toolpath " -test " (dboard:tabdat-curr-run-id tabdat) "," test-id "&")))
			  (system cmd)))))
	 (updater  (lambda ()
	 (one-run-updater  
		     (let* ((runs-dat     (if *useserver*
					      (rmt:get-runs-by-patt *keys* "%" #f #f #f #f)
					      (db:get-runs-by-patt db *keys* "%" #f #f #f #f)))
			    (runs-header  (vector-ref runs-dat 0)) ;; 0 is header, 1 is list of records
			    (run-id       (dboard:data-get-curr-run-id *data*))
			    (tests-dat    (let ((tdat (if run-id
							  (if *useserver*
							      (rmt:get-tests-for-run run-id 
										     (hash-table-ref/default *searchpatts* "test-name" "%/%")
										     (hash-table-keys *state-ignore-hash*) ;; '()
										     (hash-table-keys *status-ignore-hash*) ;; '()
										     #f #f
										     *hide-not-hide*
										     #f #f
										     "id,testname,item_path,state,status") ;; get 'em all
							      (db:get-tests-for-run db run-id 
										    (hash-table-ref/default *searchpatts* "test-name" "%/%")
										    (hash-table-keys *state-ignore-hash*) ;; '()
										    (hash-table-keys *status-ignore-hash*) ;; '()
										    #f #f
										    *hide-not-hide*
										    #f #f
										    "id,testname,item_path,state,status"))
							  '()))) ;; get 'em all
					    (sort tdat (lambda (a b)
							 (let* ((aval (vector-ref a 2))
								(bval (vector-ref b 2))
								(anum (string->number aval))
								(bnum (string->number bval)))
							   (if (and anum bnum)
							       (< anum bnum)
							       (string<= aval bval)))))))
			    (tests-mindat (dcommon:minimize-test-data tests-dat))
			    (indices      (common:sparse-list-generate-index tests-mindat)) ;;  proc: set-cell))
			    (row-indices  (cadr indices))
			    (col-indices  (car indices))
			    (max-row      (if (null? row-indices) 1 (common:max (map cadr row-indices))))
			    (max-col      (if (null? col-indices) 1 (common:max (map cadr col-indices))))
			    (max-visible  (max (- *num-tests* 15) 3)) ;; *num-tests* is proportional to the size of the window
			    (numrows      1)
			    (numcols      1)
			    (changed      #f)
			    (runs-hash    (let ((ht (make-hash-table)))
					    (for-each (lambda (run)
							(hash-table-set! ht (db:get-value-by-header run runs-header "id") run))
						      (vector-ref runs-dat 1))
					    ht))
			    (run-ids      (sort (filter number? (hash-table-keys runs-hash))
						(lambda (a b)
          (lambda ()
						  (let* ((record-a (hash-table-ref runs-hash a))
							 (record-b (hash-table-ref runs-hash b))
							 (time-a   (db:get-value-by-header record-a runs-header "event_time"))
							 (time-b   (db:get-value-by-header record-b runs-header "event_time")))
						    (< time-a time-b))))))
		       
	    (mutex-lock! update-mutex)
		       ;; (iup:attribute-set! tb "VALUE" "0")
		       ;; (iup:attribute-set! tb "NAME" "Runs")
		       ;; Update the runs tree
		       (for-each (lambda (run-id)
            (when (not run-matrix)
				   (let* ((run-record (hash-table-ref/default runs-hash run-id #f))
					  (key-vals   (map (lambda (key)(db:get-value-by-header run-record runs-header key))
							   *keys*))
					  (run-name   (db:get-value-by-header run-record runs-header "runname"))
					  (col-name   (conc (string-intersperse key-vals "\n") "\n" run-name))
					  (run-path   (append key-vals (list run-name)))
              (print "BB> What?? run-matrix is #f"))
					  (existing   (tree:find-node tb run-path)))
				     (if (not (hash-table-ref/default (dboard:data-get-path-run-ids *data*) run-path #f))
            (if  (or (dashboard:database-changed? commondat tabdat)
					 (begin
					   (hash-table-set! (dboard:data-get-run-keys *data*) run-id run-path)
                     (dboard:tabdat-view-changed tabdat))
                 (debug:catch-and-dump
                  (lambda () ;; check that run-matrix is initialized before calling the updater
					   ;; (iup:attribute-set! (dboard:data-get-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 tb "Runs" run-path ;; (append key-vals (list run-name))
							  userdata: (conc "run-id: " run-id))
					   (hash-table-set! (dboard:data-get-path-run-ids *data*) run-path run-id)
					   ;; (set! colnum (+ colnum 1))
					   ))))
				 run-ids)
		    (if run-matrix 
		       (iup:attribute-set! run-matrix "CLEARVALUE" "ALL") ;; NOTE: Was CONTENTS
		       (iup:attribute-set! run-matrix "CLEARATTRIB" "CONTENTS")
		       (iup:attribute-set! run-matrix "RESIZEMATRIX" "YES")
		       (iup:attribute-set! run-matrix "NUMCOL" max-col )
		       (iup:attribute-set! run-matrix "NUMLIN" (if (< max-row max-visible) max-visible max-row)) ;; min of 20
		       ;; (iup:attribute-set! run-matrix "NUMCOL_VISIBLE" max-col)
		       ;; (iup:attribute-set! run-matrix "NUMLIN_VISIBLE" (if (> max-row max-visible) max-visible max-row))
		       
			(dashboard:one-run-updater commondat tabdat tb cell-lookup run-matrix)))
		       ;; Row labels
		       (for-each (lambda (ind)
				   (let* ((name (car ind))
					  (num  (cadr ind))
					  (key  (conc num ":0")))
				     (if (not (equal? (iup:attribute run-matrix key) name))
					 (begin
					   (set! changed #t)
					   (iup:attribute-set! run-matrix key name)))))
				 row-indices)
		       
                  "dashboard:one-run-updater")
		       ;; Cell contents
		       (for-each (lambda (entry)
				   (let* ((row-name  (cadr entry))
					  (col-name  (car entry))
					  (valuedat  (caddr entry))
					  (test-id   (list-ref valuedat 0))
					  (test-name row-name) ;; (list-ref valuedat 1))
					  (item-path col-name) ;; (list-ref valuedat 2))
					  (state     (list-ref valuedat 1))
					  (status    (list-ref valuedat 2))
					  (value     (gutils:get-color-for-state-status state status))
					  (row-num   (cadr (assoc row-name row-indices)))
					  (col-num   (cadr (assoc col-name col-indices)))
					  (key       (conc row-num ":" col-num)))
				     (hash-table-set! cell-lookup key test-id)
				     (if (not (equal? (iup:attribute run-matrix key) (cadr value)))
					 (begin
					   (set! changed #t)
					   (iup:attribute-set! run-matrix key (cadr value))
					   (iup:attribute-set! run-matrix (conc "BGCOLOR" key) (car value))))))
				 tests-mindat)
		       
                 )
		       ;; Col labels - do after setting Cell contents so they are accounted for in the size calc.

	    (mutex-unlock! update-mutex))))
		       (for-each (lambda (ind)
				   (let* ((name (car ind))
					  (num  (cadr ind))
					  (key  (conc "0:" num)))
				     (if (not (equal? (iup:attribute run-matrix key) name))
					 (begin
					   (set! changed #t)
					   (iup:attribute-set! run-matrix key name)
					   (iup:attribute-set! run-matrix "FITTOTEXT" (conc "C" num))))))
				 col-indices)
		       (if changed (iup:attribute-set! run-matrix "REDRAW" "ALL"))))))
    
    (dboard:commondat-add-updater commondat one-run-updater tab-num: tab-num)
    (set! dashboard:update-run-summary-tab updater)
    (dboard:data-set-runs-tree! *data* tb)
    (iup:split
     tb
     run-matrix)))
    (dboard:tabdat-runs-tree-set! tabdat tb)
    (iup:vbox
     (iup:split
      tb
      run-matrix)
     (dboard:make-controls commondat tabdat))))

;;======================================================================
;; R U N S 
;;======================================================================

(define (make-dashboard-buttons db nruns ntests keynames)
  (let* ((nkeys   (length keynames))
	 (runsvec (make-vector nruns))
	 (header  (make-vector nruns))
	 (lftcol  (make-vector ntests))
	 (keycol  (make-vector ntests))
	 (controls '())
(define (dboard:make-controls commondat tabdat)
	 (lftlst  '())
	 (hdrlst  '())
	 (bdylst  '())
	 (result  '())
	 (i       0))
    ;; controls (along bottom)
    (set! controls
	  (iup:hbox
	   (iup:vbox
	    (iup:frame 
	     #:title "filter test and items"
	     (iup:hbox
  (let ((btn-fontsz  (dboard:tabdat-runs-btn-fontsz tabdat)))
    (iup:hbox
     (iup:vbox
      (iup:frame 
       #:title "filter test and items"
       (iup:hbox
	      (iup:textbox #:size "120x15" #:fontsize "10" #:value "%"
			   #:action (lambda (obj unk val)
				      (mark-for-update)
				      (update-search "test-name" val)))
	      ;;(iup:textbox #:size "60x15" #:fontsize "10" #:value "%"
	      ;;  	   #:action (lambda (obj unk val)
	      ;;  		      (mark-for-update)
	      ;;  		      (update-search "item-name" val))
	      ))
	    (iup:vbox
	     (iup:hbox
	(iup:vbox
	 (iup:textbox #:size "120x15" #:fontsize "10" #:value "%"
	      (let* ((cmds-list '("+testname" "-testname" "+event_time" "-event_time" "+statestatus" "-statestatus"))
		     (lb         (iup:listbox #:expand "HORIZONTAL"
		      #:expand "NO"
					      #:dropdown "YES"
					      #:action (lambda (obj val index lbstate)
		      #:action (lambda (obj unk val)
							 (set! *tests-sort-reverse* index)
							 (mark-for-update))))
				 (debug:catch-and-dump
		     (default-cmd (car (list-ref *tests-sort-type-index* *tests-sort-reverse*))))
		(iuplistbox-fill-list lb cmds-list selected-item: default-cmd)
		(mark-for-update)
		;; (set! *tests-sort-reverse* *tests-sort-reverse*0)
		lb)
	      ;; (iup:button "Sort -t"   #:action (lambda (obj)
	      ;;   				 (next-sort-option)
	      ;;   				 (iup:attribute-set! obj "TITLE" (vector-ref (vector-ref *tests-sort-options* *tests-sort-reverse*) 0))
	      ;;   				 (mark-for-update)))
	      (iup:button "HideEmpty" #:action (lambda (obj)
				  (lambda ()
						 (set! *hide-empty-runs* (not *hide-empty-runs*))
						 (iup:attribute-set! obj "TITLE" (if *hide-empty-runs* "+HideE" "-HideE"))
						 (mark-for-update)))
				    (mark-for-update tabdat)
	      (let ((hideit (iup:button "HideTests" #:action (lambda (obj)
							       (set! *hide-not-hide* (not *hide-not-hide*))
							       (iup:attribute-set! obj "TITLE" (if *hide-not-hide* "HideTests" "NotHide"))
							       (mark-for-update)))))
				    (update-search commondat tabdat "test-name" val))
		(set! *hide-not-hide-button* hideit)
		hideit))
	     (iup:hbox
	      (iup:button "Quit"      #:action (lambda (obj)
						 ;; (if *dbstruct-local* (db:close-all *dbstruct-local*))
						 (exit)))
	      (iup:button "Refresh"   #:action (lambda (obj)
						 (mark-for-update)))
	      (iup:button "Collapse"  #:action (lambda (obj)
						 (let ((myname (iup:attribute obj "TITLE")))
						   (if (equal? myname "Collapse")
						       (begin
							 (for-each (lambda (tname)
								     (hash-table-set! *collapsed* tname #t))
								   *all-item-test-names*)
							 (iup:attribute-set! obj "TITLE" "Expand"))
						       (begin
							 (for-each (lambda (tname)
								     (hash-table-delete! *collapsed* tname))
								   (hash-table-keys *collapsed*))
							 (iup:attribute-set! obj "TITLE" "Collapse"))))
						 (mark-for-update))))))
	   (iup:frame 
	    #:title "state/status filter"
	    (iup:vbox
	     (apply 
	      iup:hbox
	      (map (lambda (status)
		     (iup:toggle status  #:action   (lambda (obj val)
						      (mark-for-update)
						      (if (eq? val 1)
							  (hash-table-set! *status-ignore-hash* status #t)
							  (hash-table-delete! *status-ignore-hash* status))
						      (set-bg-on-filter))))
		   (map cadr *common:std-statuses*))) ;; '("PASS" "FAIL" "WARN" "CHECK" "WAIVED" "STUCK/DEAD" "n/a" "SKIP")))
	     (apply 
	      iup:hbox
	      (map (lambda (state)
		     (iup:toggle state   #:action   (lambda (obj val)
						      (mark-for-update)
				  "make-controls")))
	 (iup:hbox
	  (iup:button "Quit"      #:action (lambda (obj)
					     ;; (if (dboard:tabdat-dblocal tabdat) (db:close-all (dboard:tabdat-dblocal tabdat)))
					     (exit))
		      #:expand "NO" #:size "40x15")
	  (iup:button "Refresh"   #:action (lambda (obj)
					     (mark-for-update tabdat))
		      #:expand "NO" #:size "40x15")
	  (iup:button "Collapse"  #:action (lambda (obj)
					     (debug:catch-and-dump 
					      (lambda ()
						(let ((myname (iup:attribute obj "TITLE")))
						  (if (equal? myname "Collapse")
						      (begin
							(for-each (lambda (tname)
								    (hash-table-set! *collapsed* tname #t))
								  (dboard:tabdat-item-test-names tabdat))
							(iup:attribute-set! obj "TITLE" "Expand"))
						      (begin
							(for-each (lambda (tname)
								    (hash-table-delete! *collapsed* tname))
								  (hash-table-keys *collapsed*))
							(iup:attribute-set! obj "TITLE" "Collapse"))))
						(mark-for-update tabdat))
					      "make-controls collapse button"))
		      #:expand "NO" #:size "40x15")))
	(iup:vbox
	 ;; (iup:button "Sort -t"   #:action (lambda (obj)
	 ;;   				 (next-sort-option)
	 ;;   				 (iup:attribute-set! obj "TITLE" (vector-ref (vector-ref *tests-sort-options* *tests-sort-reverse*) 0))
	 ;;   				 (mark-for-update tabdat)))
	 
	 (let* ((hide #f)
		(show #f)
		(hide-empty #f)
		(sel-color    "180 100 100")
		(nonsel-color "170 170 170")
		(cmds-list '("+testname" "-testname" "+event_time" "-event_time" "+statestatus" "-statestatus"))
		(sort-lb    (iup:listbox #:expand "NO" ;; "HORIZONTAL"
					 #:size   "80x15"
					 #:dropdown "YES"
					 #:action (lambda (obj val index lbstate)
						    (set! *tests-sort-reverse* index)
						    (mark-for-update tabdat))))
		(default-cmd (car (list-ref *tests-sort-type-index* *tests-sort-reverse*))))
	   (iuplistbox-fill-list sort-lb cmds-list selected-item: default-cmd)
	   
	   (set! hide-empty (iup:button "HideEmpty"
					;; #:expand HORIZONTAL"
					#:expand "NO" #:size "80x15"
					#:action (lambda (obj)
						   (dboard:tabdat-hide-empty-runs-set! tabdat (not (dboard:tabdat-hide-empty-runs tabdat)))
						   (iup:attribute-set! obj "TITLE" (if (dboard:tabdat-hide-empty-runs tabdat) "+HideE" "-HideE"))
						   (mark-for-update tabdat))))
	   (set! hide (iup:button "Hide"
				  #:expand "NO" #:size "40x15" ;; #:expand "HORIZONTAL"
				  #:action (lambda (obj)
					     (dboard:tabdat-hide-not-hide-set! tabdat #t) ;; (not (dboard:tabdat-hide-not-hide tabdat)))
					     ;; (iup:attribute-set! obj "TITLE" (if (dboard:tabdat-hide-not-hide tabdat) "HideTests" "NotHide"))
					     (iup:attribute-set! hide "BGCOLOR" sel-color)
					     (iup:attribute-set! show "BGCOLOR" nonsel-color)
					     (mark-for-update tabdat))))
	   (set! show (iup:button "Show"
				  #:expand "NO" #:size "40x15" ;; #:expand "HORIZONTAL"
				  #:action (lambda (obj)
					     (dboard:tabdat-hide-not-hide-set! tabdat #f) ;; (not (dboard:tabdat-hide-not-hide tabdat)))
					     (iup:attribute-set! show "BGCOLOR" sel-color)
					     (iup:attribute-set! hide "BGCOLOR" nonsel-color)
					     (mark-for-update tabdat))))
	   (iup:attribute-set! hide "BGCOLOR" sel-color)
	   (iup:attribute-set! show "BGCOLOR" nonsel-color)
	   ;; (dboard:tabdat-hide-not-hide-button-set! tabdat hideit) ;; never used, can eliminate ...
	   (iup:vbox
	    (iup:hbox hide show)
	    hide-empty sort-lb)))
	)))
     (iup:frame 
      #:title "state/status filter"
      (iup:vbox
       (apply 
	iup:hbox
	(map (lambda (status)
	       (iup:toggle (conc status "  ")
			   #:fontsize btn-fontsz ;; "10"
			   #:expand "HORIZONTAL"
			   #:action   (lambda (obj val)
					(mark-for-update tabdat)
					(if (eq? val 1)
					    (hash-table-set! (dboard:tabdat-status-ignore-hash tabdat) status #t)
					    (hash-table-delete! (dboard:tabdat-status-ignore-hash tabdat) status))
					(set-bg-on-filter commondat tabdat))))
	     (map cadr *common:std-statuses*))) ;; '("PASS" "FAIL" "WARN" "CHECK" "WAIVED" "STUCK/DEAD" "n/a" "SKIP")))
       (apply 
	iup:hbox
	(map (lambda (state)
	       (iup:toggle (conc state "  ")
			   #:fontsize btn-fontsz
						      (if (eq? val 1)
							  (hash-table-set! *state-ignore-hash* state #t)
							  (hash-table-delete! *state-ignore-hash* state))
						      (set-bg-on-filter))))
		   (map cadr *common:std-states*))) ;; '("RUNNING" "COMPLETED" "INCOMPLETE" "LAUNCHED" "NOT_STARTED" "KILLED" "DELETED")))
	     (iup:valuator #:valuechanged_cb (lambda (obj)
					       (let ((val (inexact->exact (round (/ (string->number (iup:attribute obj "VALUE")) 10))))
						     (oldmax   (string->number (iup:attribute obj "MAX")))
						     (maxruns  *tot-run-count*))
						 (set! *start-run-offset* val)
						 (mark-for-update)
						 (debug:print 6 "*start-run-offset* " *start-run-offset* " maxruns: " maxruns ", val: " val " oldmax: " oldmax)
						 (iup:attribute-set! obj "MAX" (* maxruns 10))))
			   #:expand "HORIZONTAL"
			   #:action   (lambda (obj val)
					(mark-for-update tabdat)
					(if (eq? val 1)
					    (hash-table-set! (dboard:tabdat-state-ignore-hash tabdat) state #t)
					    (hash-table-delete! (dboard:tabdat-state-ignore-hash tabdat) state))
					(set-bg-on-filter commondat tabdat))))
	     (map cadr *common:std-states*))) ;; '("RUNNING" "COMPLETED" "INCOMPLETE" "LAUNCHED" "NOT_STARTED" "KILLED" "DELETED")))
       (iup:valuator #:valuechanged_cb (lambda (obj)
					 (let ((val (inexact->exact (round (/ (string->number (iup:attribute obj "VALUE")) 10))))
					       (oldmax   (string->number (iup:attribute obj "MAX")))
					       (maxruns  (dboard:tabdat-tot-runs tabdat)))
					   (dboard:tabdat-start-run-offset-set! tabdat val)
					   (mark-for-update tabdat)
					   (debug:print 6 *default-log-port* "(dboard:tabdat-start-run-offset tabdat) " (dboard:tabdat-start-run-offset tabdat) " maxruns: " maxruns ", val: " val " oldmax: " oldmax)
					   (iup:attribute-set! obj "MAX" (* maxruns 10))))
		     #:expand "HORIZONTAL"
			   #:max (* 10 (length *allruns*))
			   #:min 0
			   #:step 0.01)))
					;(iup:button "inc rows" #:action (lambda (obj)(set! *num-tests* (+ *num-tests* 1))))
					;(iup:button "dec rows" #:action (lambda (obj)(set! *num-tests* (if (> *num-tests* 0)(- *num-tests* 1) 0))))
	   )
	  )
		     #:max (* 10 (length (dboard:tabdat-allruns tabdat)))
		     #:min 0
		     #:step 0.01)))
					;(iup:button "inc rows" #:action (lambda (obj)(dboard:tabdat-num-tests-set! tabdat (+ (dboard:tabdat-num-tests tabdat) 1))))
					;(iup:button "dec rows" #:action (lambda (obj)(dboard:tabdat-num-tests-set! tabdat (if (> (dboard:tabdat-num-tests tabdat) 0)(- (dboard:tabdat-num-tests tabdat) 1) 0))))
     )))

(define (dashboard:popup-menu buttndat run-id test-id target runname test-name testpatt)
  (iup:menu 
   (iup:menu-item
    "Run"
    (iup:menu              
     (iup:menu-item
      (conc "Rerun " testpatt)
      #:action
      (lambda (obj)
        ;;(print "buttndat: " buttndat " run-id: " run-id " test-id: " test-id " target: " target " runname: " runname " test-name: " test-name " testpatt: " testpatt)
	(common:run-a-command
	 (conc "megatest -run -target " target
	       " -runname " runname
	       " -testpatt " testpatt
	       " -preclean -clean-cache")
	 )))
     (iup:menu-item
      "Rerun Complete Run"
      #:action
      (lambda (obj)
        (common:run-a-command
         (conc "megatest -set-state-status NOT_STARTED,n/a -run -target " target
               " -runname " runname
               " -testpatt % "
               " -preclean -clean-cache"))))
     (iup:menu-item
      "Clean Complete Run"
      #:action
      (lambda (obj)
        (common:run-a-command
         (conc "megatest -remove-runs -target " target
               " -runname " runname
               " -testpatt % "))))))
   (iup:menu-item
    "Test"
    (iup:menu 
     (iup:menu-item
      (conc "Rerun " test-name)
      #:action
      (lambda (obj)
	(common:run-a-command
	 (conc "megatest -set-state-status NOT_STARTED,n/a -run -target " target
               " -runname " runname
	       " -testpatt " test-name
	       " -preclean -clean-cache"))))
     (iup:menu-item
      (conc "Kill " test-name)
      #:action
      (lambda (obj)
        ;; (rmt:test-set-state-status-by-id run-id test-id "KILLREQ" #f #f)
	(common:run-a-command
	 (conc "megatest -set-state-status KILLREQ,n/a -target " target
               " -runname " runname
	       " -testpatt " test-name
	       " -state RUNNING,REMOTEHOSTSTART,LAUNCHED"))))
     (iup:menu-item
      (conc "Clean " test-name)
      #:action
      (lambda (obj)
	(common:run-a-command
	 (conc "megatest -remove-runs -target " target
               " -runname " runname
	       " -testpatt " test-name))))
     (iup:menu-item
      "Start xterm"
      #:action
      (lambda (obj)
        (dcommon:examine-xterm run-id test-id)))
	;;(let* ((cmd (conc (car (argv)) " -xterm " run-id "," test-id "&")))
	;; (system cmd))))
     (iup:menu-item
      "Edit testconfig"
      #:action
      (lambda (obj)
	(let* ((all-tests (tests:get-all))
	       (editor-rx (or (configf:lookup *configdat* "setup" "editor-regex") 
			      "\\b(vim?|nano|pico)\\b"))
	       (editor (or (configf:lookup *configdat* "setup" "editor")
			   (get-environment-variable "VISUAL")
			   (get-environment-variable "EDITOR") "vi"))
	       (tconfig (conc (hash-table-ref all-tests test-name) "/testconfig"))
	       (cmd (conc (if (string-search editor-rx editor)
			      (conc "xterm -e " editor)
			      editor)
			  " " tconfig " &")))
	  (system cmd))))
     ))))

(define (make-dashboard-buttons commondat) ;;  runs-sum-dat new-view-dat)
  (let* ((stats-dat       (dboard:tabdat-make-data))
	 (runs-dat        (dboard:tabdat-make-data))
	 (onerun-dat      (dboard:tabdat-make-data))
	 (runcontrols-dat (dboard:tabdat-make-data))
	 (runtimes-dat    (dboard:tabdat-make-data))
	 (nruns           (dboard:tabdat-numruns runs-dat))
	 (ntests          (dboard:tabdat-num-tests runs-dat))
	 (keynames        (dboard:tabdat-dbkeys runs-dat))
	 (nkeys           (length keynames))
	 (runsvec         (make-vector nruns))
	 (header          (make-vector nruns))
	 (lftcol          (make-vector ntests))
	 (keycol          (make-vector ntests))
	 (controls        (dboard:make-controls commondat runs-dat)) ;; '())
	 (lftlst          '())
	 (hdrlst          '())
	 (bdylst          '())
	 (result          '())
	 (i               0)
	 (btn-height      (dboard:tabdat-runs-btn-height runs-dat))
	 (btn-fontsz      (dboard:tabdat-runs-btn-fontsz runs-dat))
	 (cell-width      (dboard:tabdat-runs-cell-width runs-dat)))
    ;; controls (along bottom)
    ;; (set! controls (dboard:make-controls commondat runs-dat))
    
    ;; create the left most column for the run key names and the test names 
    (set! lftlst (list (iup:hbox
			(iup:label) ;; (iup:valuator)
			(apply iup:vbox 
			       (map (lambda (x)		
				      (let ((res (iup:hbox #:expand "HORIZONTAL"
							   (iup:label x #:size "x15" #:fontsize "10" #:expand "HORIZONTAL")
							   (iup:textbox #:size "x15" #:fontsize "10" #:value "%" #:expand "HORIZONTAL"
							   (iup:label x #:size (conc 40 btn-height) #:fontsize btn-fontsz #:expand "NO") ;; "HORIZONTAL")
							   (iup:textbox #:size (conc 35 btn-height) #:fontsize btn-fontsz #:value "%" #:expand "NO" ;; "HORIZONTAL"
									#:action (lambda (obj unk val)
										   (mark-for-update)
										   (update-search x val))))))
										   (mark-for-update runs-dat)
										   (update-search commondat runs-dat x val))))))
					(set! i (+ i 1))
					res))
				    keynames)))))
    (let loop ((testnum  0)
	       (res      '()))
      (cond
       ((>= testnum ntests)
	;; now lftlst will be an hbox with the test keys and the test name labels
	(set! lftlst (append lftlst (list (iup:hbox  #:expand "HORIZONTAL"
						     (iup:valuator #:valuechanged_cb (lambda (obj)
										       (let ((val (string->number (iup:attribute obj "VALUE")))
											     (oldmax  (string->number (iup:attribute obj "MAX")))
											     (newmax  (* 10 (length *alltestnamelst*))))
											 (set! *please-update-buttons* #t)
											 (set! *start-test-offset* (inexact->exact (round (/ val 10))))
											 (debug:print 6 "*start-test-offset* " *start-test-offset* " val: " val " newmax: " newmax " oldmax: " oldmax)
											     (newmax  (* 10 (length (dboard:tabdat-all-test-names runs-dat)))))
											 (dboard:commondat-please-update-set! commondat #t)
											 (dboard:tabdat-start-test-offset-set! runs-dat (inexact->exact (round (/ val 10))))
											 (debug:print 6 *default-log-port* "(dboard:tabdat-start-test-offset runs-dat) " (dboard:tabdat-start-test-offset runs-dat) " val: " val " newmax: " newmax " oldmax: " oldmax)
											 (if (< val 10)
											     (iup:attribute-set! obj "MAX" newmax))
											 ))
								   #:expand "VERTICAL" 
								   #:orientation "VERTICAL"
								   #:min 0
								   #:step 0.01)
						     (apply iup:vbox (reverse res)))))))
       (else
	(let ((labl  (iup:button "" 
	(let ((labl  (iup:button "" ;; the testname labels
				 #:flat "YES" 
				 #:alignment "ALEFT"
					; #:image img1
					; #:impress img2
				 #:size "x15"
				 #:expand "HORIZONTAL"
				 #:fontsize "10"
				 #:size  (conc cell-width btn-height)
				 #:expand  "HORIZONTAL"
				 #:fontsize btn-fontsz
				 #:action (lambda (obj)
					    (mark-for-update)
					    (toggle-hide testnum))))) ;; (iup:attribute obj "TITLE"))))
					    (mark-for-update runs-dat)
					    (toggle-hide testnum (dboard:commondat-uidat commondat)))))) ;; (iup:attribute obj "TITLE"))))
	  (vector-set! lftcol testnum labl)
	  (loop (+ testnum 1)(cons labl res))))))
    ;; 
    ;; These are the headers for each row
    (let loop ((runnum  0)
	       (keynum  0)
	       (keyvec  (make-vector nkeys))
	       (res    '()))
      (cond ;; nb// no else for this approach.
       ((>= runnum nruns) #f)
       ((>= keynum nkeys) 
	(vector-set! header runnum keyvec)
	(set! hdrlst (cons (apply iup:vbox (reverse res)) hdrlst))
	(loop (+ runnum 1) 0 (make-vector nkeys) '()))
       (else
	(let ((labl  (iup:label "" #:size "60x15" #:fontsize "10" #:expand "HORIZONTAL"))) ;; #:expand "HORIZONTAL"
	(let ((labl  (iup:label "" #:size (conc cell-width btn-height)  #:fontsize btn-fontsz #:expand "NO"))) ;; #:expand "HORIZONTAL" "60x15" 
	  (vector-set! keyvec keynum labl)
	  (loop runnum (+ keynum 1) keyvec (cons labl res))))))
    ;; By here the hdrlst contains a list of vboxes containing nkeys labels
    (let loop ((runnum  0)
	       (testnum 0)
	       (testvec  (make-vector ntests))
	       (res    '()))
      (cond
       ((>= runnum nruns) #f) ;;  (vector tableheader runsvec))
       ((>= testnum ntests) 
	(vector-set! runsvec runnum testvec)
	(set! bdylst (cons (apply iup:vbox (reverse res)) bdylst))
	(loop (+ runnum 1) 0 (make-vector ntests) '()))
       (else
	(let* ((button-key (mkstr runnum testnum))
	       (butn       (iup:button "" ;; button-key 
				       #:size "60x15" 
				       #:expand "HORIZONTAL"
				       #:fontsize "10" 
				       #:action (lambda (x)
						  (let* ((toolpath (car (argv)))
							 (buttndat (hash-table-ref *buttondat* button-key))
	       (butn       (iup:button
			    "" ;; button-key 
			    #:size (conc cell-width btn-height )
			    #:expand "NO"
			    #:fontsize btn-fontsz
			    #:button-cb
			    (lambda (obj a pressed x y btn . rem)
			      ;; (print "pressed= " pressed " x= " x " y= " y " rem=" rem " btn=" btn " string? " (string? btn))
			      (if  (substring-index "3" btn)
				   (if (eq? pressed 1)
				       (let* ((toolpath (car (argv)))
					      (buttndat (hash-table-ref (dboard:tabdat-buttondat runs-dat) button-key))
							 (test-id  (dbr:test-id (vector-ref buttndat 3)))
							 (run-id   (dbr:test-run_id (vector-ref buttndat 3)))
					      (run-info (rmt:get-run-info run-id))
					      (target   (rmt:get-target run-id))
					      (runname  (db:get-value-by-header (db:get-rows run-info)
										(db:get-header run-info) "runname"))
					      (test-name (db:test-get-testname (rmt:get-test-info-by-id run-id test-id)))
					      (testpatt  (let ((tlast (rmt:tasks-get-last target runname)))
							   (if tlast
							       (let ((tpatt (tasks:task-get-testpatt tlast)))
								 (if (member tpatt '("0" 0)) ;; known bad historical value - remove in 2017
								     "%"
								     tpatt))
							       "%"))))
					 (iup:show (dashboard:popup-menu buttndat run-id test-id target runname test-name testpatt) ;; popup-menu
						   #:x 'mouse
						   #:y 'mouse
						   #:modal? "NO")
					 ;; (print "got here")
					 ))
				   (if (eq? pressed 0)
				       (let* ((toolpath (car (argv)))
					      (buttndat (hash-table-ref (dboard:tabdat-buttondat runs-dat) button-key))
							 (cmd  (conc toolpath " -test " run-id "," test-id "&")))
					      (cmd  (conc toolpath " -test " run-id "," test-id "&")))
					;(print "Launching " cmd)
						    (system cmd))))))
	  (hash-table-set! *buttondat* button-key (vector 0 "100 100 100" button-key #f #f)) 
					 (system cmd)))
				   )))))
	  (hash-table-set! (dboard:tabdat-buttondat runs-dat) button-key (vector 0 "100 100 100" button-key #f #f)) 
	  (vector-set! testvec testnum butn)
	  (loop runnum (+ testnum 1) testvec (cons butn res))))))
    ;; now assemble the hdrlst and bdylst and kick off the dialog
    (iup:show
     (iup:dialog 
      #:title (conc "Megatest dashboard " (current-user-name) ":" *toppath*)
      #:menu (dcommon:main-menu)
      (let* ((runs-view (iup:vbox
			 (apply iup:hbox 
				(cons (apply iup:vbox lftlst)
			 (iup:split
			  #:orientation "VERTICAL" ;; "HORIZONTAL"
			  #:value 150
			  (dboard:runs-tree-browser commondat runs-dat)
			  (iup:split
			   ;; left most block, including row names
			   (apply iup:vbox lftlst)
				      (list 
				       (iup:vbox
					;; the header
					(apply iup:hbox (reverse hdrlst))
					(apply iup:hbox (reverse bdylst))))))
			 controls))
			   ;; right hand block, including cells
			   (iup:vbox
			    ;; the header
			    (apply iup:hbox (reverse hdrlst))
			    (apply iup:hbox (reverse bdylst)))))
			 controls
			 ))
	     ;; (data (dboard:tabdat-init (make-d:data)))
	     (tabs (iup:tabs
		    #:tabchangepos-cb (lambda (obj curr prev)
					(debug:catch-and-dump
					 (lambda ()
					   (let* ((tab-num (dboard:commondat-curr-tab-num commondat))
						  (tabdat  (dboard:common-get-tabdat commondat tab-num: tab-num)))
					     (dboard:tabdat-layout-update-ok-set! tabdat #f))
					   (dboard:commondat-curr-tab-num-set! commondat curr)
					   (let* ((tab-num (dboard:commondat-curr-tab-num commondat))
						  (tabdat  (dboard:common-get-tabdat commondat tab-num: tab-num)))
					(set! *please-update-buttons* #t)
					(set! *current-tab-number* curr))
		    (dashboard:summary db)
					     (dboard:commondat-please-update-set! commondat #t)
					     (dboard:tabdat-layout-update-ok-set! tabdat #t)))
					 "tabchangepos"))
		    (dashboard:summary commondat stats-dat tab-num: 0)
		    runs-view
		    (dashboard:one-run db)
		    (dashboard:run-controls)
		    (dashboard:one-run commondat onerun-dat tab-num: 2)
		    ;; (dashboard:new-view db data new-view-dat tab-num: 3)
		    (dashboard:run-controls commondat runcontrols-dat tab-num: 3)
		    (dashboard:run-times commondat runtimes-dat tab-num: 4)
		    )))
	;; (set! (iup:callback tabs tabchange-cb:) (lambda (a b c)(print "SWITCHED TO TAB: " a " " b " " c)))
	(iup:attribute-set! tabs "TABTITLE0" "Summary")
	(iup:attribute-set! tabs "TABTITLE1" "Runs")
	(iup:attribute-set! tabs "TABTITLE2" "Run Summary")
	(iup:attribute-set! tabs "TABTITLE3" "Run Control")
	(iup:attribute-set! tabs "TABTITLE4" "Run Times")
	;; (iup:attribute-set! tabs "TABTITLE3" "New View")
	;; (iup:attribute-set! tabs "TABTITLE4" "Run Control")
	(iup:attribute-set! tabs "BGCOLOR" "190 190 190")
	;; make the iup tabs object available (for changing color for example)
	(set! *hide-not-hide-tabs* tabs)
	tabs)))
	(dboard:commondat-hide-not-hide-tabs-set! commondat tabs)
	;; now set up the tabdat lookup
	(dboard:common-set-tabdat! commondat 0 stats-dat)
	(dboard:common-set-tabdat! commondat 1 runs-dat)
	(dboard:common-set-tabdat! commondat 2 onerun-dat)
	(dboard:common-set-tabdat! commondat 3 runcontrols-dat)
	(dboard:common-set-tabdat! commondat 4 runtimes-dat)
	(iup:vbox
	 tabs
	 ;; controls
	 ))))
    (vector keycol lftcol header runsvec)))

(define (dboard:setup-num-rows tabdat)
  (dboard:tabdat-num-tests-set! tabdat (string->number
(if (or (args:get-arg "-rows")
	(get-environment-variable "DASHBOARDROWS" ))
					(or (args:get-arg "-rows")
					    (get-environment-variable "DASHBOARDROWS")
    (begin
      (set! *num-tests* (string->number (or (args:get-arg "-rows")
					    (get-environment-variable "DASHBOARDROWS"))))
					    "15"))))
      (update-rundat "%" *num-runs* "%/%" '()))
    (set! *num-tests* (min (max (update-rundat "%" *num-runs* "%/%" '()) 8) 20)))

  
(define *tim* (iup:timer))
(define *ord* #f)
(iup:attribute-set! *tim* "TIME" 300)
(iup:attribute-set! *tim* "RUN" "YES")

;; Move this stuff to db.scm? I'm not sure that is the right thing to do...
;;
(define *last-db-update-time* (file-modification-time *db-file-path*)) ;; (conc *toppath* "/db/main.db")))
(define *last-recalc-ended-time* 0)

(define (dashboard:been-changed)
  (> (file-modification-time *db-file-path*) *last-db-update-time*))
(define (dashboard:been-changed tabdat)
  (> (file-modification-time (dboard:tabdat-dbfpath tabdat)) (dboard:tabdat-last-db-update tabdat)))

(define (dashboard:set-db-update-time)
  (set! *last-db-update-time* (file-modification-time *db-file-path*)))
(define (dashboard:set-db-update-time tabdat)
  (dboard:tabdat-last-db-update-set! tabdat (file-modification-time (dboard:tabdat-dbfpath tabdat))))

(define (dashboard:recalc modtime please-update-buttons last-db-update-time)
  (or please-update-buttons
      (and (> (current-milliseconds)(+ *last-recalc-ended-time* 150))
	   (> modtime last-db-update-time)
	   (> (current-seconds)(+ last-db-update-time 1)))))

(define *monitor-db-path* (conc *dbdir* "/monitor.db"))
;; (define *monitor-db-path* #f)
(define *last-monitor-update-time* 0)

;; Force creation of the db in case it isn't already there.
(tasks:open-db)

(define (dashboard:get-youngest-run-db-mod-time)
(define (dashboard:get-youngest-run-db-mod-time tabdat)
  (handle-exceptions
   exn
   (begin
     (debug:print 0 "WARNING: error in accessing databases in get-youngest-run-db-mod-time: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 *default-log-port* "WARNING: error in accessing databases in get-youngest-run-db-mod-time: " ((condition-property-accessor 'exn 'message) exn))
     (current-seconds)) ;; something went wrong - just print an error and return current-seconds
   (apply max (map (lambda (filen)
		     (file-modification-time filen))
		   (glob (conc *dbdir* "/*.db"))))))
		   (glob (conc (dboard:tabdat-dbdir tabdat) "/*.db"))))))

(define (dashboard:run-update x)
  (let* ((modtime         (dashboard:get-youngest-run-db-mod-time)) ;; (file-modification-time *db-file-path*))
	 (monitor-modtime (if (file-exists? *monitor-db-path*)
			      (file-modification-time *monitor-db-path*)
			      -1))
(define (dashboard:monitor-changed? commondat tabdat)
  (let* ((run-update-time (current-seconds))
	 (monitor-db-path (dboard:tabdat-monitor-db-path tabdat))
	 (monitor-modtime (if (and monitor-db-path (file-exists? monitor-db-path))
			      (file-modification-time monitor-db-path)
			      -1)))
	 (run-update-time (current-seconds))
	 (recalc          (dashboard:recalc modtime *please-update-buttons* *last-db-update-time*)))
    (if (and (eq? *current-tab-number* 0)
    (if (and (eq? (dboard:commondat-curr-tab-num commondat) 0)
	     (or (> monitor-modtime *last-monitor-update-time*)
		 (> (- run-update-time *last-monitor-update-time*) 5))) ;; update every 1/2 minute just in case
	(begin
	  (set! *last-monitor-update-time* run-update-time) ;; monitor-modtime)
	  #t)
	#f)))
	  (if dashboard:update-servers-table (dashboard:update-servers-table))))
    (if recalc
	(begin	
	  (case *current-tab-number* 
	    ((0) 
	     (if dashboard:update-summary-tab (dashboard:update-summary-tab)))
	    ((1) ;; The runs table is active
	     (update-rundat (hash-table-ref/default *searchpatts* "runname" "%") *num-runs*
			    (hash-table-ref/default *searchpatts* "test-name" "%/%")
			    ;; (hash-table-ref/default *searchpatts* "item-name" "%")
			    (let ((res '()))
			      (for-each (lambda (key)
					  (if (not (equal? key "runname"))
					      (let ((val (hash-table-ref/default *searchpatts* key #f)))
						(if val (set! res (cons (list key val) res))))))
					*dbkeys*)
			      res))
	     (update-buttons uidat *num-runs* *num-tests*))
	    ((2)
	     (dashboard:update-run-summary-tab))
	    (else
	     (let ((updater (hash-table-ref/default *updaters* *current-tab-number* #f)))
	       (if updater (updater)))))
	  (set! *please-update-buttons* #f)
	  (set! *last-db-update-time* modtime)
	  (set! *last-update* run-update-time)
	  (set! *last-recalc-ended-time* (current-milliseconds))))))

(define (dashboard:database-changed? commondat tabdat)
  (let* ((run-update-time (current-seconds))
	 (modtime         (dashboard:get-youngest-run-db-mod-time tabdat)) ;; NOTE: ensure this is tabdat!! 
	 (recalc          (dashboard:recalc modtime (dboard:commondat-please-update commondat) (dboard:tabdat-last-db-update tabdat))))
     (dboard:commondat-please-update-set! commondat #f)
     recalc))

;; point inside line
;;
(define-inline (dashboard:px-between px lx1 lx2)
  (and (< lx1 px)(> lx2 px)))

;; can a bar be placed in row "rownum" covering x1 to x2 without overlapping with existing 
;; bars? Use num-rows to check that a block will fit from rownum to (+ rownum num-rows)
;;
(define (dashboard:row-collision rowhash rownum x1 x2 #!key (num-rows #f))
  (let ((lastrow   (if num-rows (+ rownum num-rows) rownum)))
    (let loop ((i      0)
	       (rowdat (hash-table-ref/default rowhash rownum '())))
      (if (null? rowdat)
	  #f
	  (let rowloop ((bar (car rowdat))
			(tal (cdr rowdat)))
	    (let ((bx1 (car bar))
		  (bx2 (cdr bar)))
	      (cond
	       ;; newbar x1 inside bar
	       ((dashboard:px-between x1 bx1 bx2) #t)
	       ((dashboard:px-between x2 bx1 bx2) #t)
	       ((and (<= x1 bx1)(>= x2 bx2))      #t)
	       (else (if (null? tal)
			 (if (< i lastrow)
			     (loop (+ i 1)
				   (hash-table-ref/default rowhash (+ rownum i) '()))
			     #f)
			 (rowloop (car tal)(cdr tal)))))))))))

(define (dashboard:add-bar rowhash rownum x1 x2 #!key (num-rows 0))
  (let loop ((i 0))
    (hash-table-set! rowhash 
		     (+ i rownum)
		     (cons (cons x1 x2) 
			   (hash-table-ref/default rowhash (+ i rownum) '())))
    (if (< i num-rows)
	(loop (+ i 1)))))

;; get min or max, use > for max and < for min, this works around the limits on apply
;;
(define (dboard:min-max comp lst)
  (if (null? lst)
      #f ;; better than an exception for my needs
      (fold (lambda (a b)
	      (if (comp a b) a b))
	    (car lst)
	    lst)))

;; sort a list of test-ids by the event _time using a hash table of id => testdat
;;
(define-inline (dboard:sort-testsdat-by-event-time test-ids tests-ht)
  (sort test-ids
	(lambda (a b)
	  (< (db:test-get-event_time (hash-table-ref tests-ht a))
	     (db:test-get-event_time (hash-table-ref tests-ht b))))))

;; first group items into lists, then sort by time
;; finally sort by first item time
;; 
;; NOTE: we are returning lists of lists of ids!
;;
(define (dboard:tests-sort-by-time-group-by-item testsdat)
  (let ((test-ids (hash-table-keys testsdat)))
    (if (null? test-ids)
	test-ids
	;; now group all tests by testname tname => (id1 id2 ...), tname2 => ( ...
	(let* ((test-ids-by-name
		(let ((ht (make-hash-table)))
		  (for-each
		   (lambda (tdat)
		     (let ((testname (db:test-get-testname tdat))
			   (test-id  (db:test-get-id tdat)))
		       (hash-table-set! 
			ht 
			testname
			(cons test-id (hash-table-ref/default ht testname '())))))
		   (hash-table-values testsdat))
		  ht)))
	;; remove toplevel tests from iterated tests, sort tests in the list by event time
	(for-each 
	 (lambda (testname)
	   (let ((tests-id-lst (hash-table-ref test-ids-by-name testname)))
	     (if (> (length tests-id-lst) 1) ;; must be iterated
		 (let ((item-tests (filter (lambda (tid) ;; filter out toplevel tests
					     (let ((tdat (hash-table-ref testsdat tid)))
					       (not (equal? (db:test-get-item-path tdat) ""))))
					   tests-id-lst)))
		   (if (not (null? item-tests)) ;; resist bad data, generally should not fail this condition
		       (hash-table-set! test-ids-by-name 
					testname 
					(dboard:sort-testsdat-by-event-time item-tests testsdat)))))))
	 (hash-table-keys test-ids-by-name))
	;; finally sort by the event time of the first test
	(sort (hash-table-values test-ids-by-name)
	      (lambda (a b)
		(< (db:test-get-event_time (hash-table-ref testsdat (car a)))
		   (db:test-get-event_time (hash-table-ref testsdat (car b))))))))))

;; run times tab data updater
;;
(define (dashboard:run-times-tab-run-data-updater commondat tabdat tab-num)
  (let* ((runs-dat      (rmt:get-runs-by-patt (dboard:tabdat-keys tabdat) "%" #f #f #f #f))
	 (runs-header   (vector-ref runs-dat 0)) ;; 0 is header, 1 is list of records
	 (runs-hash     (let ((ht (make-hash-table)))
			  (for-each (lambda (run)
				      (hash-table-set! ht (db:get-value-by-header run runs-header "id") run))
				    (vector-ref runs-dat 1))
			  ht))
	 (run-ids       (sort (filter number? (hash-table-keys runs-hash))
			      (lambda (a b)
				(let* ((record-a (hash-table-ref runs-hash a))
				       (record-b (hash-table-ref runs-hash b))
				       (time-a   (db:get-value-by-header record-a runs-header "event_time"))
				       (time-b   (db:get-value-by-header record-b runs-header "event_time")))
				  (< time-a time-b)))))
	 (tb            (dboard:tabdat-runs-tree tabdat))
	 (num-runs      (length (hash-table-keys runs-hash)))
	 (update-start-time (current-seconds))
	 (inc-mode      #f))
    ;; fill in the tree
    (if (and tb 
	     (not inc-mode))
	(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 runs-header key))
				   (dboard:tabdat-keys tabdat)))
		  (run-name   (db:get-value-by-header run-record runs-header "runname"))
		  (col-name   (conc (string-intersperse key-vals "\n") "\n" run-name))
		  (run-path   (append key-vals (list run-name)))
		  (existing   (tree:find-node tb run-path)))
	     (if (not (hash-table-ref/default (dboard:tabdat-path-run-ids tabdat) run-path #f))
		 (begin
		   (hash-table-set! (dboard:tabdat-run-keys tabdat) run-id run-path)
		   ;; Here we update the tests treebox and tree keys
		   (tree:add-node tb "Runs" run-path ;; (append key-vals (list run-name))
				  userdata: (conc "run-id: " run-id))
		   (hash-table-set! (dboard:tabdat-path-run-ids tabdat) run-path run-id)
		   ;; (set! colnum (+ colnum 1))
		   ))))
	 run-ids))
    ;; (print "Updating rundat")
    (if (dboard:tabdat-keys tabdat) ;; have keys yet?
	(let* ((num-keys (length (dboard:tabdat-keys tabdat)))
	       (targpatt (map (lambda (k v)
				(list k v))
			      (dboard:tabdat-keys tabdat)
			      (take (append (or (dboard:tabdat-target tabdat);; (string-split (dboard: "/")
						'("%" "%"))
					    (make-list num-keys "%"))
				    num-keys)
			      ))
	       (runpatt   (if (dboard:tabdat-target tabdat)
			     (last (dboard:tabdat-target tabdat))
			     "%"))
	       (testpatt  (or (dboard:tabdat-test-patts tabdat) "%"))
	       (filtrstr  (conc targpatt "/" runpatt "/" testpatt)))
	  ;; (print "targpatt: " targpatt " runpatt: " runpatt " testpatt: " testpatt)

	  (if (not (equal? (dboard:tabdat-last-filter-str tabdat) filtrstr))
	      (let ((dwg (dboard:tabdat-drawing tabdat)))
		(print "reseting drawing")
		(dboard:tabdat-layout-update-ok-set! tabdat #f)
		(vg:drawing-libs-set! dwg (make-hash-table))
		(vg:drawing-insts-set! dwg (make-hash-table))
		(vg:drawing-cache-set! dwg '())
		(dboard:tabdat-allruns-by-id-set! tabdat (make-hash-table))
		;; (dboard:tabdat-allruns-set! tabdat '())
		(dboard:tabdat-max-row-set! tabdat 0)
		(dboard:tabdat-last-filter-str-set! tabdat filtrstr)))
	  (update-rundat tabdat
			 runpatt
			 ;; (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "runname" "%") 
			 10  ;; (dboard:tabdat-numruns tabdat)
			 testpatt ;; (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "test-name" "%/%")
			 ;; (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "item-name" "%")
			 
			 targpatt
			 
			 ;; old method 
			 ;; (let ((res '()))
			 ;;   (for-each (lambda (key)
			 ;;      	 (if (not (equal? key "runname"))
			 ;;      	     (let ((val (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) key #f)))
			 ;;      	       (if val (set! res (cons (list key val) res))))))
			 ;;             (dboard:tabdat-dbkeys tabdat))
			 ;;   res)
			 )))))

;; run times canvas updater
;;
(define (dashboard:run-times-tab-canvas-updater commondat tabdat tab-num)
  (let ((cnv (dboard:tabdat-cnv tabdat))
	(dwg (dboard:tabdat-drawing tabdat))
	(mtx (dboard:tabdat-runs-mutex tabdat))
	(vch (dboard:tabdat-view-changed tabdat)))
    (if (and cnv dwg vch)
	(begin
	  (vg:drawing-xoff-set! dwg (dboard:tabdat-xadj tabdat))
	  (vg:drawing-yoff-set! dwg (dboard:tabdat-yadj tabdat))
	  (mutex-lock! mtx)
	  (canvas-clear! cnv)
	  (vg:draw dwg tabdat)
	  (mutex-unlock! mtx)
	  (dboard:tabdat-view-changed-set! tabdat #f)))))
  
;; doesn't work.
;;
;;(define (gotoescape tabdat escape)
;;  (or (dboard:tabdat-layout-update-ok tabdat)
;;      (escape #t)))

(define (dboard:graph-db-open dbstr)
  (let* ((parts (string-split dbstr ":"))
	 (dbpth (if (< (length parts) 2) ;; assume then a filename was provided
		    dbstr
		    (if (equal? (car parts) "sqlite3")
			(cadr parts)
			(begin
			  (debug:print 0 *default-log-port* "ERROR: I only know sqlite3 databases for now: " dbstr)
			  #f)))))
    (if (and dbpth (file-read-access? dbpth))
	(let ((db (sqlite3:open-database dbpth))) ;; (open-database dbpth)))
	  (sqlite3:set-busy-handler! db (make-busy-timeout 10000))
	  db)
	#f)))

;; sqlite3:path tablename timefieldname varfieldname field1 field2 ...
;;
(define (dboard:graph-read-data cmdstring tstart tend)
  (let* ((parts (string-split cmdstring))) ;; spaces not allowed
    (if (< (length parts) 6) ;; sqlite3:path tablename timefieldname varfname valfname field1 field2 ...
	(debug:print 0 *default-log-port* "ERROR: malformed graph line: " cmdstring)
	(let* ((dbdef  (list-ref parts 0))
	       (tablen (list-ref parts 1))
	       (timef  (list-ref parts 2))
	       (varfn  (list-ref parts 3))
	       (valfn  (list-ref parts 4))
	       (fields (cdr  (cddddr parts)))
	       (db     (dboard:graph-db-open dbdef))
	       (res-ht (make-hash-table)))
	  (if db
	      (begin
		(for-each
		 (lambda (fieldname) ;; fields
		   (let ((all-dat-qrystr (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " >= " tstart " AND " timef " <= " tend " ORDER BY " timef " ASC"))
			 (zeroth-point   (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " < " tstart " LIMIT 1")))
		     (hash-table-set! res-ht fieldname ;; (fetch-rows (sql db qrystr)))))
				      (reverse
				       (sqlite3:fold-row
					(lambda (res t var val)
					  (cons (vector t var val) res))
					'() db all-dat-qrystr)))
		     (let ((zeropt (handle-exceptions
				    exn
				    #f
				    (sqlite3:first-row db all-dat-qrystr))))
		       (if zeropt ;; NOTE: Add zeropt to the beginning of the list as the list was reversed above.
			   (hash-table-set! res-ht
					    fieldname
					    (cons
					     (apply vector tstart (cdr zeropt))						    
					     (hash-table-ref/default res-ht fieldname '())))))))
		 fields)
		res-ht)
	      #f)))))
  
;; graph data 
;;  tsc=timescale, tfn=function; time->x
;;
(define (dboard:graph commondat tabdat tabnum llx lly ulx uly tstart tend tsc tfn compname cmargin)
  (let* ((dwg      (dboard:tabdat-drawing tabdat))
	 (lib      (vg:get/create-lib dwg "runslib"))
	 (cnv      (dboard:tabdat-cnv tabdat))
	 (dur      (- tstart tend)) ;; time duration
	 (cmp      (vg:get-component dwg "runslib" compname))
	 (cfg      (configf:get-section *configdat* "graph"))
	 (stdcolor (vg:rgb->number 120 130 140))
	 (delta-y  (- uly lly)))
    (vg:add-obj-to-comp
     cmp 
     (vg:make-rect-obj llx lly ulx uly))
    (vg:add-obj-to-comp
     cmp
     (vg:make-text-obj (- (tfn tstart) 10)(- lly 10)(seconds->year-week/day-time tstart)))
    (let*-values (((span timeunit time-blk first timesym) (common:find-start-mark-and-mark-delta tstart tend)))
		 (let loop ((mark  first)
			    (count 0))
		   (let* ((smark (tfn mark))           ;; scale the mark
			  (mark-delta (quotient (- mark tstart) time-blk)) ;; how far from first mark
			  (label      (conc (* count span) timesym))) ;; was mark-delta
		     (if (> count 2)
			 (begin
			   (vg:add-obj-to-comp
			    cmp
			    (vg:make-rect-obj (- smark 1)(- lly 2)(+ smark 1) lly))
			   (vg:add-obj-to-comp
			    cmp
			    (vg:make-text-obj (- smark 1)(- lly 10) label))))
		     (if (< mark (- tend time-blk))
			 (loop (+ mark time-blk)(+ count 1))))))
    (for-each 
     (lambda (cf)
       (let* ((alldat  (dboard:graph-read-data (cadr cf) tstart tend)))
	 (if alldat
	     (for-each
	      (lambda (fieldn)
		(let* ((dat     (hash-table-ref alldat fieldn))
		       (vals    (map (lambda (x)(vector-ref x 2)) dat)))
		  (if (not (null? vals))
		      (let* ((maxval   (apply max vals))
			     (minval   (min 0 (apply min vals)))
			     (yoff     (- minval lly)) ;;  minval))
			     (deltaval (- maxval minval))
			     (yscale   (/ delta-y (if (zero? deltaval) 1 deltaval)))
			     (yfunc    (lambda (y)(+ lly (* yscale (- y minval))))) ;; (lambda (y)(* (+ y yoff) yscale))))
                             (graph-color (vg:generate-color)))
			;; (print (car cf) "; maxval: " maxval " minval: " minval " deltaval: " deltaval " yscale: " yscale)
			(vg:add-obj-to-comp
			 cmp 
			 (vg:make-text-obj (- llx 10)(yfunc maxval) (conc maxval)))
			(vg:add-obj-to-comp
			 cmp 
			 (vg:make-text-obj (- llx 10)(yfunc minval) (conc minval)))
			(fold 
			 (lambda (next prev)  ;; #(time ? val) #(time ? val)
			   (if prev
			       (let* ((yval        (vector-ref prev 2))
                                      (yval-next   (vector-ref next 2))
				      (last-tval   (tfn   (vector-ref prev 0)))
				      (last-yval   (yfunc yval)) ;; (+ lly (* yscale (vector-ref prev 2))))
                                      (next-yval   (yfunc yval-next))
				      (curr-tval   (tfn   (vector-ref next 0))))
				 (if (>= curr-tval last-tval)
                                     (begin
                                       (vg:add-obj-to-comp
                                        cmp 
                                        ;;(vg:make-rect-obj last-tval lly curr-tval last-yval ;; (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
                                        (vg:make-line-obj last-tval last-yval curr-tval last-yval
                                                          line-color: graph-color))
                                       (vg:add-obj-to-comp
                                        cmp 
                                        ;;(vg:make-rect-obj last-tval lly curr-tval last-yval ;; (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
                                        (vg:make-line-obj curr-tval last-yval curr-tval next-yval
                                                 line-color: graph-color)))         
				     (print "ERROR: curr-tval is not > last-tval; curr-tval " curr-tval ", last-tval " last-tval))))
			   next)
			 ;; for init create vector tstart,0
			 #f ;; (vector tstart minval minval)
			 dat)
			   
			 ;; (for-each
			;;  (lambda (dpt)
			;;    (let* ((tval  (vector-ref dpt 0))
			 ;; 	  (yval  (vector-ref dpt 2))
			;; 	  (stval (tfn tval))
			;; 	  (syval (yfunc yval)))
			;;      (vg:add-obj-to-comp
			;;       cmp 
			;;       (vg:make-rect-obj (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
			;; 			fill-color: stdcolor))))
			;;  dat)
			)))) ;; for each data point in the series
	      (hash-table-keys alldat)))))
     cfg)))
	 
;; run times tab
;;
(define (dashboard:run-times-tab-layout-updater commondat tabdat tab-num)
  ;; each test is an object in the run component
  ;; each run is a component
  ;; all runs stored in runslib library
  (let escapeloop ((escape #f))
    (if (and (not escape)
	     tabdat)
	(let* ((canvas-margin 10)
	       (not-done-runs (dboard:tabdat-not-done-runs tabdat))
	       (mtx           (dboard:tabdat-runs-mutex tabdat))
	       (drawing      (dboard:tabdat-drawing tabdat))
	       (runslib      (vg:get/create-lib drawing "runslib")) ;; creates and adds lib
	       (allruns      (dboard:tabdat-allruns tabdat))
	       (num-runs     (length allruns))
	       (cnv          (dboard:tabdat-cnv tabdat))
	       (compact-layout (dboard:tabdat-compact-layout tabdat))
	       (row-height     (if compact-layout 2 10))
	       (graph-height 120)
	       (run-to-run-margin 25))
	  (dboard:tabdat-layout-update-ok-set! tabdat #t)
	  (if (canvas? cnv)
	      (let*-values (((sizex sizey sizexmm sizeymm) (canvas-size cnv))
			    ((originx originy)             (canvas-origin cnv))
			    ((calc-y)                      (lambda (rownum)
							     (- (/ sizey 2)
								(* rownum row-height))))
			    ((fixed-originx)               (if (dboard:tabdat-originx tabdat)
							       (dboard:tabdat-originx tabdat)
							       (begin
							 	 (dboard:tabdat-originx-set! tabdat originx)
							 	 originx)))
			    ((fixed-originy)               (if (dboard:tabdat-originy tabdat)
							       (dboard:tabdat-originy tabdat)
							       (begin
								 (dboard:tabdat-originy-set! tabdat originy)
								 originy))))
		;; (print "allruns: " allruns)
		(let runloop ((rundat   (car allruns))
			      (runtal   (cdr allruns))
			      (run-num   1)
			      (doneruns '()))
		  (let* ((run         (dboard:rundat-run rundat))
			 (rowhash     (make-hash-table)) ;; store me in tabdat
			 (key-val-dat (dboard:rundat-key-vals rundat))
			 (run-id      (db:get-value-by-header run (dboard:tabdat-header tabdat) "id"))
			 (key-vals    (append key-val-dat
					      (list (let ((x (db:get-value-by-header run (dboard:tabdat-header tabdat) "runname")))
						      (if x x "")))))
			 (run-key  (string-intersperse key-vals "\n"))
			 (run-full-name (string-intersperse key-vals "/"))
			 (curr-run-start-row  (dboard:tabdat-max-row tabdat)))
		    ;; (print "run: " run-full-name " curr-run-start-row: " curr-run-start-row)
		    (if (not (vg:lib-get-component runslib run-full-name))
			(let* ((hierdat   (if (or (dboard:rundat-data-changed rundat) ;; attempt to not sort when possible.
						  (not (dboard:rundat-hierdat rundat)))
					      (let ((hd (dboard:tests-sort-by-time-group-by-item (dboard:rundat-tests rundat)))) ;; hierarchial list of ids
						(dboard:rundat-hierdat-set! rundat hd)
						hd)
					      (dboard:rundat-hierdat rundat)))
			       (tests-ht  (dboard:rundat-tests rundat))
			       (all-tids  (hash-table-keys   tests-ht)) ;; (apply append hierdat)) ;; was testsdat
			       (testsdat  (hash-table-values tests-ht))
			       (runcomp   (vg:comp-new));; new component for this run
			       (rows-used (make-hash-table)) ;; keep track of what parts of the rows are used here row1 = (obj1 obj2 ...)
			       ;; (row-height 4)
			       (run-start  (dboard:min-max < (map db:test-get-event_time testsdat)))
			       (run-end    (let ((re (dboard:min-max > (map (lambda (t)(+ (db:test-get-event_time t)(db:test-get-run_duration t))) testsdat))))
					     (max re (+ 1 run-start)))) ;; use run-start+1 if run-start == run-end so delta is not zero
			       (timeoffset (- run-start)) ;; (+ fixed-originx canvas-margin) run-start))
			       (run-duration (- run-end run-start))
			       (timescale  (/ (- sizex (* 2 canvas-margin))
					      (if (> run-duration 0)
						  run-duration
						  (current-seconds)))) ;; a least lously guess
			       (maptime    (lambda (tsecs)(* timescale (+ tsecs timeoffset))))
			       (num-tests  (length hierdat))
			       (tot-tests  (length testsdat))
			       (width      (* timescale run-duration))
			       (graph-lly  (calc-y (/ -50 row-height)))
			       (graph-uly  (- (calc-y 0) canvas-margin))
			       (sec-per-50pt (/ 50 timescale))
			       )
			  ;; (print "timeoffset: " timeoffset " timescale: " timescale " run-duration: " (seconds->hr-min-sec run-duration) " width: " width " sec-per-50pt: " sec-per-50pt)
			  ;; (print "timescale: " timescale " timeoffset: " timeoffset " sizex: " sizex " originx: " originx)
			  (mutex-lock! mtx)
			  (vg:add-comp-to-lib runslib run-full-name runcomp)
			  ;; Have to keep moving the instantiated box as it is anchored at the lower left
			  ;; this should have worked for x in next statement? (maptime run-start)
			  ;; add 60 to make room for the graph
			  (vg:instantiate drawing "runslib" run-full-name run-full-name 8 (- (calc-y curr-run-start-row) (+ 5 graph-height run-to-run-margin)))
			  (mutex-unlock! mtx)
			  ;; (set! run-start-row (+ max-row 2))
			  ;; (dboard:tabdat-start-row-set! tabdat (+ new-run-start-row 1))
			  ;; get tests in list sorted by event time ascending
			  (let testsloop ((test-ids  (car hierdat))              ;; loop on tests (NOTE: not items!)
					  (tests-tal (cdr hierdat))
					  (test-num  1))
			    (let ((iterated     (> (length test-ids) 1))
				  (first-rownum #f)
				  (num-items    (length test-ids)))
			      (let testitemloop ((test-id  (car test-ids))    ;; loop on test or test items
						 (tidstal  (cdr test-ids))
						 (item-num 1)
						 (test-objs '()))
				(let* ((testdat      (hash-table-ref tests-ht test-id))
				       (event-time   (maptime (db:test-get-event_time   testdat)))
				       (test-duration (* timescale (db:test-get-run_duration testdat)))
				       (end-time     (+ event-time test-duration))
				       (test-name    (db:test-get-testname     testdat))
				       (item-path    (db:test-get-item-path    testdat))
				       (state         (db:test-get-state       testdat))
				       (status        (db:test-get-status      testdat))
				       (test-fullname (conc test-name "/" item-path))
				       (name-color    (gutils:get-color-for-state-status state status))
				       (new-test-objs 
					(let loop ((rownum 0)) ;;  new-run-start-row)) ;; (+ start-row 1)))
					  (if (dashboard:row-collision rowhash rownum event-time end-time)
					      (loop (+ rownum 1))
					      (let* ((title   (if iterated (if compact-layout #f item-path) test-name))
						     (lly     (calc-y rownum)) ;; (- sizey (* rownum row-height)))
						     (uly     (+ lly row-height))
						     (use-end (if (< (- end-time event-time) 2)(+ event-time 2) end-time)) ;; if short grow it a little to give the user something to click on
						     (obj     (vg:make-rect-obj event-time lly use-end uly
										fill-color: (vg:iup-color->number (car name-color))
										text: title
										font: "Helvetica -10")) 
						     (bar-end (max use-end
								   (+ event-time 
								      (if compact-layout
									  1
									  (+ 7 (* (string-length title) 10))))))) ;; 8 pixels per letter
						;; (if iterated
						;;     (dashboard:add-bar rowhash (- rownum 1) event-time end-time num-rows: (+ 1 num-items))
						;; (if (not first-rownum)
						;;     (begin
						;;       (dashboard:row-collision rowhash (- rownum 1) event-time end-time num-rows: num-items)
						;;       (set! first-rownum rownum)))
						(dboard:tabdat-max-row-set! tabdat (max (+ curr-run-start-row rownum)
											(dboard:tabdat-max-row tabdat))) ;; track the max row used
						;; bar-end has some margin for text - accounting for text in extents not yet working.
						(dashboard:add-bar rowhash rownum event-time bar-end) ;; (+ end-time 5))
						(vg:add-obj-to-comp runcomp obj)
						;; (vg:instance-move drawing run-full-name 0 (calc-y (dboard:tabdat-max-row tabdat)))
						(dboard:tabdat-view-changed-set! tabdat #t)
						(cons obj test-objs))))))
				  ;; (print "event_time: " (db:test-get-event_time   testdat) " mapped event_time: " event-time)
				  ;; (print "run-duration: "  (db:test-get-run_duration testdat) " mapped run_duration: " run-duration)
				  (if (> item-num 50)
				      (if (eq? 0 (modulo item-num 50))
					  (print "processing " run-num " of " num-runs " runs " item-num " of " num-items " of test " test-name ", " test-num " of " num-tests " tests")))
				  ;; (print "test-name: " test-name " event-time: " event-time " run-duration: " run-duration)
				  (let ((newdoneruns (cons rundat doneruns)))
				    (if (null? tidstal)
					(if iterated
					    (let* ((xtents (vg:get-extents-for-objs drawing new-test-objs))
						   (llx (- (car xtents)  10))
						   (lly (- (cadr xtents) 10))
						   (ulx (+ 5 (caddr xtents)))
						   (uly (+ 10 (cadddr xtents))))
					      ;; (dashboard:add-bar rowhash 0 llx ulx num-rows:  num-items)
					      ;; This is the box around the tests of an iterated test
					      (vg:add-obj-to-comp runcomp (vg:make-rect-obj llx lly ulx uly
											    text:  (db:test-get-testname (hash-table-ref tests-ht (car test-ids)))
											    line-color:  (vg:rgb->number  0 0 255 a: 128)
											    font: "Helvetica -10"))
					      ;; (vg:instance-move drawing run-full-name 0 (dboard:tabdat-max-row tabdat))
					      (dboard:tabdat-view-changed-set! tabdat #t))) ;; trigger a redraw
					(if (dboard:tabdat-layout-update-ok tabdat)
					    (testitemloop (car tidstal)(cdr tidstal)(+ item-num 1) new-test-objs)
					    (escapeloop #t) ;; (dboard:tabdat-layout-update-ok tabdat)
					    )))))
			      ;; If it is an iterated test put box around it now.
			      (if (not (null? tests-tal))
				  (if #f ;; (> (- (current-seconds) update-start-time) 5)
				      (print "drawing runs taking too long")
				      (if (dboard:tabdat-layout-update-ok tabdat)
					  (testsloop  (car tests-tal)(cdr tests-tal)(+ test-num 1))
					  (escapeloop #t) ;; (dboard:tabdat-layout-update-ok tabdat)
					  )))))
			  ;; placeholder box
			  (dboard:tabdat-max-row-set! tabdat (+ (dboard:tabdat-max-row tabdat) 1))
			  ;; (let ((y  (calc-y (dboard:tabdat-max-row tabdat)))) ;;  (- sizey (* (dboard:tabdat-max-row tabdat) row-height))))
			  ;;   (vg:add-obj-to-comp runcomp (vg:make-rect-obj 0 y 0 y)))
			  ;; instantiate the component
			  (let* ((extents   (vg:components-get-extents drawing runcomp))
				 (new-xtnts (apply vg:grow-rect 5 5 extents))
				 (llx       (list-ref new-xtnts 0))
				 (lly       (list-ref new-xtnts 1))
				 (ulx       (list-ref new-xtnts 2))
				 (uly       (list-ref new-xtnts 3))
				 (outln     (vg:make-rect-obj -5 lly ulx uly 
							      text: run-full-name
							      line-color:  (vg:rgb->number  255 0 255 a: 128))))
					;  (vg:components-get-extents d1 c1)))
			    ;; this is the box around the run
			    (mutex-lock! mtx)
			    (vg:add-obj-to-comp runcomp outln)
			    (mutex-unlock! mtx)
			    ;; this is where we have enough info to place the graph
			    (dboard:graph commondat tabdat tab-num -5 (+ uly 10) ulx (+ uly graph-height 3) run-start run-end timescale maptime run-full-name canvas-margin)
			    (dboard:tabdat-max-row-set! tabdat (+ (dboard:tabdat-max-row tabdat)(quotient (+ graph-height 40 3) row-height)))
			    ;; (vg:instance-move drawing run-full-name 0 (dboard:tabdat-max-row tabdat))
			    ))
			;; end of the run handling loop 
			(if (not (dboard:tabdat-layout-update-ok tabdat))
			    (escapeloop #t) ;; (dboard:tabdat-layout-update-ok tabdat)
			    (let ((newdoneruns (cons rundat doneruns)))
			      (if (null? runtal)
				  (begin
				    (dboard:rundat-data-changed-set! rundat #f) 
				    (dboard:tabdat-not-done-runs-set! tabdat '())
				    (dboard:tabdat-done-runs-set! tabdat allruns))
				  (if #f ;; (> (- (current-seconds) update-start-time) 5)
				      (begin
					(print "drawing runs taking too long....  have " (length runtal) " remaining")
					;; (dboard:tabdat-done-runs-set! tabdat newdoneruns) ;; taking too long? stop here!
					;; (time (vg:draw (dboard:tabdat-drawing tabdat) #t))
					(dboard:tabdat-not-done-runs-set! tabdat runtal))
				      (begin
					(if (dboard:tabdat-layout-update-ok tabdat)
					    (runloop (car runtal)(cdr runtal) (+ run-num 1) newdoneruns)
					    (escapeloop #t) ;; (dboard:tabdat-layout-update-ok tabdat)
					    ))))))))) ;;  new-run-start-row
		)))
	(debug:print 2 *default-log-port* "no tabdat for run-times-tab-updater"))))

(define (dashboard:runs-tab-updater commondat tab-num)
  (debug:catch-and-dump 
   (lambda ()
     (let* ((tabdat (dboard:common-get-tabdat commondat tab-num: tab-num))
	    (dbkeys (dboard:tabdat-dbkeys tabdat)))
       (update-rundat tabdat
		      (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "runname" "%")
		      (dboard:tabdat-numruns tabdat)
		      (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "test-name" "%/%")
		      ;; (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) "item-name" "%")
		      (let* ((dbkeys (dboard:tabdat-dbkeys tabdat)))
			;; (print "dbkeys: " dbkeys)
			(let ((fres   (if (dboard:tabdat-target tabdat)
					 (let ((ptparts (append (dboard:tabdat-target tabdat)(make-list (length dbkeys) "%"))))
					   (map (lambda (k v)(list k v)) dbkeys ptparts))
					 (let ((res '()))
					   ;; (print "target: " (dboard:tabdat-target tabdat))
					   (for-each (lambda (key)
						       (if (not (equal? key "runname"))
							   (let ((val (hash-table-ref/default (dboard:tabdat-searchpatts tabdat) key #f)))
							     (if val (set! res (cons (list key val) res))))))
						     dbkeys)
					   res))))
			  ;; (debug:print 0 *default-log-port* "fres: " fres)
			  fres)))
       (let ((uidat (dboard:commondat-uidat commondat)))
	 (update-buttons tabdat uidat (dboard:tabdat-numruns tabdat) (dboard:tabdat-num-tests tabdat)))
       ))
   "dashboard:runs-tab-updater"))

;; ((2)
;;  (dashboard:update-run-summary-tab))
;; ((3)
;;  (dashboard:update-new-view-tab))
;; (else
;;  (dboard:common-run-curr-updater commondat)))
;; (set! *last-recalc-ended-time* (current-milliseconds))))))))

;;======================================================================
;; The heavy lifting starts here
;;======================================================================

;; ease debugging by loading ~/.dashboardrc
(let ((debugcontrolf (conc (get-environment-variable "HOME") "/.dashboardrc")))
  (if (file-exists? debugcontrolf)
      (load debugcontrolf)))

(define (main)
  (if (not (args:get-arg "-skip-version-check"))(common:exit-on-version-changed))
  (let* ((commondat       (dboard:commondat-make)))
    ;; Move this stuff to db.scm? I'm not sure that is the right thing to do...
(cond 
    (cond 
 ((args:get-arg "-run")
  (let ((runid (string->number (args:get-arg "-run"))))
    (if runid
	(begin
	  (lambda (x)
	    (on-exit std-exit-procedure)
	    (examine-run *dbstruct-local* runid)))
	(begin
	  (print "ERROR: runid is not a number " (args:get-arg "-run"))
	  (exit 1)))))
 ((args:get-arg "-test") ;; run-id,test-id
  (let* ((dat     (let ((d (map string->number (string-split (args:get-arg "-test") ","))))
		    (if (> (length d) 1)
			d
			(list #f #f))))
	 (run-id  (car dat))
	 (test-id (cadr dat)))
    (if (and (number? run-id)
	     (number? test-id)
	     (>= test-id 0))
	(examine-test run-id test-id)
	(begin
	  (debug:print 3 "INFO: tried to open test with invalid run-id,test-id. " (args:get-arg "-test"))
	  (exit 1)))))
 ((args:get-arg "-guimonitor")
  (gui-monitor *dbstruct-local*))
 (else
  (set! uidat (make-dashboard-buttons *dbstruct-local* *num-runs* *num-tests* *dbkeys*))
  (iup:callback-set! *tim*
		     "ACTION_CB"
		     (lambda (x)
		       (let ((update-is-running #f))
			 (mutex-lock! *update-mutex*)
			 (set! update-is-running *update-is-running*)
			 (if (not update-is-running)
			     (set! *update-is-running* #t))
			 (mutex-unlock! *update-mutex*)
			 (if (not update-is-running)
			   (begin
			     (dashboard:run-update x)
			     (mutex-lock! *update-mutex*)
			     (set! *update-is-running* #f)
			     (mutex-unlock! *update-mutex*))))
		       1))))

(let ((th1 (make-thread (lambda ()
			  (thread-sleep! 1)
			  (set! *please-update-buttons* #t)
			  (dashboard:run-update 1)) "update buttons once"))
     ((args:get-arg "-test") ;; run-id,test-id
      (let* ((dat     (let ((d (map string->number (string-split (args:get-arg "-test") ","))))
			(if (> (length d) 1)
			    d
			    (list #f #f))))
	     (run-id  (car dat))
	     (test-id (cadr dat)))
	(if (and (number? run-id)
		 (number? test-id)
		 (>= test-id 0))
	    (examine-test run-id test-id)
	    (begin
	      (debug:print 3 *default-log-port* "INFO: tried to open test with invalid run-id,test-id. " (args:get-arg "-test"))
	      (exit 1)))))
     ;; ((args:get-arg "-guimonitor")
     ;;  (gui-monitor (dboard:tabdat-dblocal tabdat)))
     (else
      (dboard:commondat-uidat-set! commondat (make-dashboard-buttons commondat)) ;; (dboard:tabdat-dblocal data)
					  ;; (dboard:tabdat-numruns tabdat)
					  ;; (dboard:tabdat-num-tests tabdat)
					  ;; (dboard:tabdat-dbkeys tabdat)
					  ;; runs-sum-dat new-view-dat))
      ;; legacy setup of updaters for summary tab and runs tab
      ;; summary tab
      ;; (dboard:commondat-add-updater 
      ;;  commondat 
      ;;  (lambda ()
      ;; 	 (dashboard:summary-tab-updater commondat 0))
      ;;  tab-num: 0)
      ;; runs tab
      (dboard:commondat-curr-tab-num-set! commondat 0)
      (dboard:commondat-add-updater 
       commondat 
       (lambda ()
      	 (dashboard:runs-tab-updater commondat 1))
       tab-num: 1)
      (iup:callback-set! *tim*
			 "ACTION_CB"
			 (lambda (time-obj)
			   (let ((update-is-running #f))
			     (mutex-lock! (dboard:commondat-update-mutex commondat))
			     (set! update-is-running (dboard:commondat-updating commondat))
			     (if (not update-is-running)
				 (dboard:commondat-updating-set! commondat #t))
			     (mutex-unlock! (dboard:commondat-update-mutex commondat))
			     (if (not update-is-running) ;; we know that the update was not running and we now have a lock on doing an update
				 (begin
				   (dboard:common-run-curr-updaters commondat) ;; (dashboard:run-update commondat)
				   (mutex-lock! (dboard:commondat-update-mutex commondat))
				   (dboard:commondat-updating-set! commondat #f)
				   (mutex-unlock! (dboard:commondat-update-mutex commondat)))
				 ))
			   1))))
    
    (let ((th1 (make-thread (lambda ()
			      (thread-sleep! 1)
			      (dboard:common-run-curr-updaters commondat 0) ;; force update of summary tab 
			      ;; (dboard:commondat-please-update-set! commondat #t) ;; MRW: ww36.3 - why was please update set true here? Removing it for now.
			      ;; (dashboard:run-update commondat)
			  ;; need to wait for first *update-is-running* #t
			  ;; (let loop ()
			  ;;   (mutex-lock! *update-mutex*)
			  ;;   (if *update-is-running*
			      ) "update buttons once"))
			  ;;       (begin
			  ;;         (set! *please-update-buttons* #t)
			  ;;         (mark-for-update)
			  ;;         (print "Did redraw trigger")) "First update after startup")
			  ;;   (mutex-unlock! *update-mutex*)
			  ;;   (thread-sleep! 1)
			  ;;   (if (not *please-update-buttons*)
			  ;;       (loop))))))
      (th2 (make-thread iup:main-loop "Main loop")))
  (thread-start! th1)
  (thread-start! th2)
  (thread-join! th2))
	  (th2 (make-thread iup:main-loop "Main loop")))
      (thread-start! th1)
      (thread-start! th2)
      (thread-join! th2))))

;; (iup:main-loop)(db:close-all *dbstruct-local*)
(main)

Modified datashare-testing/.sretrieve.config from [e657ec9c50] to [71cb2ce9dc].

1
2
3


4
5
6

7
8
9
10
11
12
13
14
15
16
17
1


2
3
4


5








6
7
8

-
-
+
+

-
-
+
-
-
-
-
-
-
-
-



[settings]
base-dir      /tmp/matt/datashare/disk1
allowed-users matt mrwellan pjhatwal
base-dir      /tmp/delme_data
allowed-users matt
allowed-chars [0-9a-zA-Z\-\.]+
default-area  megatest

allowed-sub-paths [0-9a-zA-Z\-\.]+
# NOTE: packages-metadir defaults to exe dir if not specified here
# packages-metadir  /tmp/#{getenv USER}/packages

# conversion-script has semantics as cp, takes file1 and outputs file2
#   cp file1 file2
conversion-script cp
upstream-file     packages.config

[database]
location #{scheme (create-directory "/tmp/#{getenv USER}" #t)}

Modified datashare.scm from [578f007a04] to [aff106f1a7].

229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+







	(let* ((dbpath    (conc path "/datashare.db"))
	       (writeable (file-write-access? dbpath))
	       (dbexists  (file-exists? dbpath))
	       (handler   (make-busy-timeout 136000)))
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 2 "ERROR: problem accessing db " dbpath
	     (debug:print 2 *default-log-port* "ERROR: problem accessing db " dbpath
			  ((condition-property-accessor 'exn 'message) exn))
	     (exit))
	   (set! db (sqlite3:open-database dbpath)))
	  (if *db-write-access* (sqlite3:set-busy-handler! db handler))
	  (if (not dbexists)
	      (begin
		(datashare:initialize-db db)))

Modified db.scm from [3b72cbaf00] to [9b66096f5a].

34
35
36
37
38
39
40







41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
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







+
+
+
+
+
+
+









-
+







(define *number-of-writes* 0)
(define *number-non-write-queries* 0)

;;======================================================================
;; SQLITE3 HELPERS
;;======================================================================

(define (db:general-sqlite-error-dump exn stmt . params)
  (let ((err-status ((condition-property-accessor 'sqlite3 'status #f) exn)))
    ;; check for (exn sqlite3) ((condition-property-accessor 'exn 'message) exn)
    (print "err-status: " err-status)
    (debug:print-error 0 *default-log-port* " query " stmt " failed, params: " params ", error: " ((condition-property-accessor 'exn 'message) exn))
    (print-call-chain (current-error-port))))

;; convert to -inline
(define (db:first-result-default db stmt default . params)
  (handle-exceptions
   exn
   (let ((err-status ((condition-property-accessor 'sqlite3 'status #f) exn)))
     ;; check for (exn sqlite3) ((condition-property-accessor 'exn 'message) exn)
     (if (eq? err-status 'done)
	 default
	 (begin
	   (debug:print 0 "ERROR:  query " stmt " failed, params: " params ", error: " ((condition-property-accessor 'exn 'message) exn))
	   (debug:print-error 0 *default-log-port* " query " stmt " failed, params: " params ", error: " ((condition-property-accessor 'exn 'message) exn))
	   (print-call-chain (current-error-port))
	   default)))
   (apply sqlite3:first-result db stmt params)))

;; Get/open a database
;;    if run-id => get run specific db
;;    if #f     => get main db
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123







-
+







		    (db:get-db dbstruct run-id)
		    dbstruct)) ;; cheat, allow for passing in a dbdat
	 (db    (db:dbdat-get-db dbdat)))
    (db:delay-if-busy dbdat)
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "ERROR: sqlite3 issue in db:with-db, dbstruct=" dbstruct ", run-id=" run-id ", proc=" proc ", params=" params " error: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print-error 0 *default-log-port* "sqlite3 issue in db:with-db, dbstruct=" dbstruct ", run-id=" run-id ", proc=" proc ", params=" params " error: " ((condition-property-accessor 'exn 'message) exn))
       (print-call-chain (current-error-port)))
     (let ((res (apply proc db params)))
       (if (vector? dbstruct)(db:done-with dbstruct run-id r/w))
       res))))

;;======================================================================
;; K E E P   F I L E D B   I N   dbstruct
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
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







-
+
-






-
+





+
+
+
+







;;   (let ((fdb (db:get-filedb dbstruct)))
;;     (filedb:get-path db id)))

;; NB// #f => return dbdir only
;;      (was planned to be;  zeroth db with name=main.db)
;;
(define (db:dbfile-path run-id)
  (let* ((dbdir           (or (configf:lookup *configdat* "setup" "dbdir")
  (let* ((dbdir           (db:get-dbdir))
			      (conc (configf:lookup *configdat* "setup" "linktree") "/.db")))
	 (fname           (if run-id
			      (if (eq? run-id 0) "main.db" (conc run-id ".db"))
			      #f)))
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "ERROR: Couldn't create path to " dbdir)
       (debug:print-error 0 *default-log-port* "Couldn't create path to " dbdir)
       (exit 1))
     (if (not (directory? dbdir))(create-directory dbdir #t)))
    (if fname
	(conc dbdir "/" fname)
	dbdir)))

(define (db:get-dbdir)
  (or (configf:lookup *configdat* "setup" "dbdir")
      (conc (configf:lookup *configdat* "setup" "linktree") "/.db")))
	       
(define (db:set-sync db)
  (let ((syncprag (configf:lookup *configdat* "setup" "sychronous")))
    (sqlite3:execute db (conc "PRAGMA synchronous = " (or syncprag 1) ";"))))

;; open an sql database inside a file lock
;;
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204







-
+







	      (db      (sqlite3:open-database fname)))
	  (sqlite3:set-busy-handler! db (make-busy-timeout 136000))
	  (db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = 0;")
	  (if (not file-exists)(initproc db))
	  ;; (release-dot-lock fname)
	  db)
	(begin
	  (debug:print 2 "WARNING: opening db in non-writable dir " fname)
	  (debug:print 2 *default-log-port* "WARNING: opening db in non-writable dir " fname)
	  (sqlite3:open-database fname))))) ;; )

;; This routine creates the db. It is only called if the db is not already opened
;; 
(define (db:open-rundb dbstruct run-id #!key (attemptnum 0)(do-not-open #f)) ;;  (conc *toppath* "/megatest.db") (car *configinfo*)))
  (let* ((local  (dbr:dbstruct-local dbstruct))
	 (rdb    (if local
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230







-
+







		 (db           (db:lock-create-open dbpath ;; this is the database physically on disk
						    (lambda (db)
						      (handle-exceptions
						       exn
						       (begin
							 ;; (release-dot-lock dbpath)
							 (if (> attemptnum 2)
							     (debug:print 0 "ERROR: tried twice, cannot create/initialize db for run-id " run-id ", at path " dbpath)
							     (debug:print-error 0 *default-log-port* "tried twice, cannot create/initialize db for run-id " run-id ", at path " dbpath)
							     (db:open-rundb dbstruct run-id attemptnum (+ attemptnum 1))))
						       (db:initialize-run-id-db db)
						       (sqlite3:execute 
							db
							"INSERT OR IGNORE INTO tests (id,run_id,testname,event_time,item_path,state,status) VALUES (?,?,'bogustest',strftime('%s','now'),'nowherepath','DELETED','n/a');"
							(* run-id 30000) ;; allow for up to 30k tests per run
							run-id)
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+



















-
+







	(rundb  (dbr:dbstruct-rundb dbstruct))
	(inmem  (dbr:dbstruct-inmem dbstruct))
	(maindb (dbr:dbstruct-main  dbstruct))
	(refdb  (dbr:dbstruct-refdb dbstruct))
	(olddb  (dbr:dbstruct-olddb dbstruct))
	;; (runid  (dbr:dbstruct-run-id dbstruct))
	)
    (debug:print-info 4 "Syncing for run-id: " run-id)
    (debug:print-info 4 *default-log-port* "Syncing for run-id: " run-id)
    ;; (mutex-lock! *http-mutex*)
    (if (eq? run-id 0)
	;; runid equal to 0 is main.db
	(if maindb
	    (if (or (not (number? mtime))
		    (not (number? stime))
		    (> mtime stime)
		    force-sync)
		(begin
		  (db:delay-if-busy maindb)
		  (db:delay-if-busy olddb)
		  (let ((num-synced (db:sync-tables (db:sync-main-list maindb) maindb olddb)))
		    (dbr:dbstruct-stime-set! dbstruct (current-milliseconds))
		    num-synced)
		  0))
	    (begin
	      ;; this can occur when using local access (i.e. not in a server)
	      ;; need a flag to turn it off.
	      ;;
	      (debug:print 3 "WARNING: call to sync main.db to megatest.db but main not initialized")
	      (debug:print 3 *default-log-port* "WARNING: call to sync main.db to megatest.db but main not initialized")
	      0))
	;; any other runid is a run
	(if (or (not (number? mtime))
		(not (number? stime))
		(> mtime stime)
		force-sync)
	    (begin
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
384
385
386
387
388
389
390

391
392
393
394









395
















396
397
398
399
400
401
402







-
+



-
-
-
-
-
-
-
-
-

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








  (db:close-main dbstruct)
  
  (let ((locdbs (dbr:dbstruct-locdbs dbstruct)))
    (if (hash-table? locdbs)
	(for-each (lambda (run-id)
		    (db:close-run-db dbstruct run-id))
		  (hash-table-keys locdbs))))
		  (hash-table-keys locdbs)))))

  ;; (let* ((local (dbr:dbstruct-local dbstruct))
  ;;        (rundb (db:dbdat-get-db (dbr:dbstruct-rundb dbstruct))))
  ;;   (if local
  ;;       (for-each
  ;;        (lambda (dbdat)
  ;;          (let ((db (db:dbdat-get-db dbdat)))
  ;;            (if (sqlite3:database? db)
  ;;       	 (begin
  ;;       	   (sqlite3:interrupt! db)
  ;;       	   (sqlite3:finalize! db #t)))))
  ;;        ;; TODO: Come back to this and rework to delete from hashtable when finalized
  ;;        (hash-table-values (dbr:dbstruct-locdbs dbstruct))))
  ;;   (thread-sleep! 3)
  ;;   (if (and rundb
  ;;            (sqlite3:database? rundb))
  ;;       (handle-exceptions
  ;;        exn
  ;;        (begin 
  ;;          (debug:print 0 "WARNING: database files may not have been closed correctly. Consider running -cleanup-db")
  ;;          (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
  ;;          (debug:print 0 " db: " rundb)
  ;;          (print-call-chain (current-error-port))
  ;;          #f)
  ;;        (sqlite3:interrupt! rundb)
  ;;        (sqlite3:finalize! rundb #t))))
  ;; ;; (mutex-unlock! *db-sync-mutex*)
  )

(define (db:open-inmem-db)
  (let* ((db      (sqlite3:open-database ":memory:"))
	 (handler (make-busy-timeout 3600)))
    (sqlite3:set-busy-handler! db handler)
    (db:initialize-run-id-db db)
    (cons db #f)))

497
498
499
500
501
502
503
504

505
506
507
508
509

510
511
512
513
514
515
516
517
518
519
520
521
522

523
524
525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541


542
543
544
545
546
547
548
482
483
484
485
486
487
488

489
490
491
492
493

494
495
496
497
498
499
500
501
502
503
504
505
506

507
508
509

510
511
512
513
514
515
516
517
518
519
520
521
522
523
524


525
526
527
528
529
530
531
532
533







-
+




-
+












-
+


-
+














-
-
+
+







(define (db:move-and-recreate-db dbdat)
  (let* ((dbpath   (db:dbdat-get-path        dbdat))
	 (dbdir    (pathname-directory       dbpath))
	 (fname    (pathname-strip-directory dbpath))
	 (fnamejnl (conc fname "-journal"))
	 (tmpname  (conc fname "." (current-process-id)))
	 (tmpjnl   (conc fnamejnl "." (current-process-id))))
    (debug:print 0 "ERROR: " fname " appears corrupted. Making backup \"old/" fname "\"")
    (debug:print-error 0 *default-log-port* "" fname " appears corrupted. Making backup \"old/" fname "\"")
    (system (conc "cd " dbdir ";mkdir -p old;cat " fname " > old/" tmpname))
    (system (conc "rm -f " dbpath))
    (if (file-exists? fnamejnl)
	(begin
	  (debug:print 0 "ERROR: " fnamejnl " found, moving it to old dir as " tmpjnl)
	  (debug:print-error 0 *default-log-port* "" fnamejnl " found, moving it to old dir as " tmpjnl)
	  (system (conc "cd " dbdir ";mkdir -p old;cat " fnamejnl " > old/" tmpjnl))
	  (system (conc "rm -f " dbdir "/" fnamejnl))))
    ;; attempt to recreate database
    (system (conc "cd " dbdir ";sqlite3 old/" tmpname " .dump | sqlite3 " fname))))
    
;; return #f to indicate the dbdat should be closed/reopened
;; else return dbdat
;;
(define (db:repair-db dbdat #!key (numtries 1))
  (let* ((dbpath   (db:dbdat-get-path        dbdat))
	 (dbdir    (pathname-directory       dbpath))
	 (fname    (pathname-strip-directory dbpath)))
    (debug:print-info 0 "Checking db " dbpath " for errors.")
    (debug:print-info 0 *default-log-port* "Checking db " dbpath " for errors.")
    (cond
     ((not (file-write-access? dbdir))
      (debug:print 0 "WARNING: can't write to " dbdir ", can't fix " fname)
      (debug:print 0 *default-log-port* "WARNING: can't write to " dbdir ", can't fix " fname)
      #f)

     ;; handle special cases, megatest.db and monitor.db
     ;; 
     ;;  NOPE: apply this same approach to all db files
     ;;
     (else ;; ((equal? fname "megatest.db") ;; this file can be regenerated if needed
      (handle-exceptions
       exn
       (begin
	 ;; (db:move-and-recreate-db dbdat)
	 (if (> numtries 0)
	     (db:repair-db dbdat numtries: (- numtries 1))
	     #f)
	 (debug:print 0 "FATAL: file " dbpath " was found corrupted, an attempt to fix has been made but you must start over.")
	 (debug:print 0
	 (debug:print 0 *default-log-port* "FATAL: file " dbpath " was found corrupted, an attempt to fix has been made but you must start over.")
	 (debug:print 0 *default-log-port*
		      "   check the following:\n"
		      "      1. full directories, look in ~/ /tmp and " dbdir "\n"
		      "      2. write access to " dbdir "\n\n"
		      "   if the automatic recovery failed you may be able to recover data by doing \"" 
		      (if (member fname '("megatest.db" "monitor.db"))
			  "megatest -cleanup-db"
			  "megatest -import-megatest.db;megatest -cleanup-db")
571
572
573
574
575
576
577
578

579
580

581
582
583


584
585
586

587
588
589

590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605


606
607

608
609

610
611
612
613
614
615
616
556
557
558
559
560
561
562

563
564

565
566


567
568
569
570

571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588


589
590
591

592
593

594
595
596
597
598
599
600
601







-
+

-
+

-
-
+
+


-
+


-
+














-
-
+
+

-
+

-
+







;;
(define (db:sync-tables tbls fromdb todb . slave-dbs)
  (mutex-lock! *db-sync-mutex*)
  (handle-exceptions
   exn
   (begin
     (mutex-unlock! *db-sync-mutex*)
     (debug:print 0 "EXCEPTION: database probably overloaded or unreadable in db:sync-tables.")
     (debug:print 0 *default-log-port* "EXCEPTION: database probably overloaded or unreadable in db:sync-tables.")
     (print-call-chain (current-error-port))
     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
     (print "exn=" (condition->list exn))
     (debug:print 0 " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
     (debug:print 0 " src db:  " (db:dbdat-get-path fromdb))
     (debug:print 0 *default-log-port* " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
     (debug:print 0 *default-log-port* " src db:  " (db:dbdat-get-path fromdb))
     (for-each (lambda (dbdat)
		 (let ((dbpath (db:dbdat-get-path dbdat)))
		   (debug:print 0 " dbpath:  " dbpath)
		   (debug:print 0 *default-log-port* " dbpath:  " dbpath)
		   (if (not (db:repair-db dbdat))
		       (begin
			 (debug:print 0 "ERROR: Failed to rebuild " dbpath ", exiting now.")
			 (debug:print-error 0 *default-log-port* "Failed to rebuild " dbpath ", exiting now.")
			 (exit)))))
	       (cons todb slave-dbs))
     
     0)
;;      (if *server-run* ;; we are inside a server, throw a sync-failed error
;; 	 (signal (make-composite-condition
;; 		 (make-property-condition 'sync-failed 'message "db:sync-tables failed in a server context.")))
;; 	 0)) ;; return zero for num synced

	 ;; (set! *time-to-exit* #t) ;; let watch dog know that it is time to die.
	 ;; (tasks:server-set-state! (db:delay-if-busy tdbdat) server-id "shutting-down")
	 ;; (portlogger:open-run-close portlogger:set-port port "released")
	 ;; (exit 1)))
   (cond
    ((not fromdb) (debug:print 3 "WARNING: db:sync-tables called with fromdb missing") -1)
    ((not todb)   (debug:print 3 "WARNING: db:sync-tables called with todb missing") -2)
    ((not fromdb) (debug:print 3 *default-log-port* "WARNING: db:sync-tables called with fromdb missing") -1)
    ((not todb)   (debug:print 3 *default-log-port* "WARNING: db:sync-tables called with todb missing") -2)
    ((not (sqlite3:database? (db:dbdat-get-db fromdb)))
     (debug:print 0 "ERROR: db:sync-tables called with fromdb not a database " fromdb) -3)
     (debug:print-error 0 *default-log-port* "db:sync-tables called with fromdb not a database " fromdb) -3)
    ((not (sqlite3:database? (db:dbdat-get-db todb)))
     (debug:print 0 "ERROR: db:sync-tables called with todb not a database " todb) -4)
     (debug:print-error 0 *default-log-port* "db:sync-tables called with todb not a database " todb) -4)
    (else
     (let ((stmts       (make-hash-table)) ;; table-field => stmt
	   (all-stmts   '())              ;; ( ( stmt1 value1 ) ( stml2 value2 ))
	   (numrecs     (make-hash-table))
	   (start-time  (current-milliseconds))
	   (tot-count   0))
       (for-each ;; table
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650







-
+







	     full-sel)
	    
	    ;; tack on remaining records in fromdat
	    (if (not (null? fromdat))
		(set! fromdats (cons fromdat fromdats)))

	    (if (common:low-noise-print 120 "sync-records")
		(debug:print-info 4 "found " totrecords " records to sync"))
		(debug:print-info 4 *default-log-port* "found " totrecords " records to sync"))

	    ;; read the target table
	    (sqlite3:for-each-row
	     (lambda (a . b)
	       (hash-table-set! todat a (apply vector a b)))
	     (db:dbdat-get-db todb)
	     full-sel)
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709

710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726

727
728
729
730
731
732
733
680
681
682
683
684
685
686

687
688
689
690
691
692
693

694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710

711
712
713
714
715
716
717
718







-
+






-
+
















-
+







		  ))
		  fromdats)
		 (sqlite3:finalize! stmth)))
	     (append (list todb) slave-dbs))))
	tbls)
       (let* ((runtime      (- (current-milliseconds) start-time))
	      (should-print (common:low-noise-print 120 "db sync" (> runtime 500)))) ;; low and high sync times treated as separate.
	 (if should-print (debug:print 3 "INFO: db sync, total run time " runtime " ms"))
	 (if should-print (debug:print 3 *default-log-port* "INFO: db sync, total run time " runtime " ms"))
	 (for-each 
	  (lambda (dat)
	    (let ((tblname (car dat))
		  (count   (cdr dat)))
	      (set! tot-count (+ tot-count count))
	      (if (> count 0)
		  (if should-print (debug:print 0 (format #f "    ~10a ~5a" tblname count))))))
		  (if should-print (debug:print 0 *default-log-port* (format #f "    ~10a ~5a" tblname count))))))
	  (sort (hash-table->alist numrecs)(lambda (a b)(> (cdr a)(cdr b))))))
       tot-count)))
   (mutex-unlock! *db-sync-mutex*)))

;; 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
;;  'new2old      - sync .db/{main,1,2,3 ...}.db to megatest.db
;;  'closeall     - close all opened dbs
;;
;;  run-ids: '(1 2 3 ...) or #f (for all)
;;
(define (db:multi-db-sync run-ids . options)
  (let* ((toppath  (launch:setup-for-run))
  (let* ((toppath  (launch:setup))
	 (dbstruct (if toppath (make-dbr:dbstruct path: toppath) #f))
	 (mtdb     (if toppath (db:open-megatest-db)))
	 (allow-cleanup (if run-ids #f #t))
	 (run-ids  (if run-ids 
		       run-ids
		       (if toppath (begin
				     (db:delay-if-busy mtdb)
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
778
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
816
817
818
819

820
821
822
823
824
825

826
827

828
829
830
831

832
833
834
835
836
837
838
839
840
841
842
843
844
845


846
847

848
849
850

851
852
853
854
855
856
857
748
749
750
751
752
753
754

755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
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







-
+
















-
+







-
+

-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+







-
+


+






-
+





-
+

-
+



-
+












-
-
+
+

-
+


-
+







	(begin
	  (db:sync-tables (db:sync-main-list mtdb) mtdb (db:get-db dbstruct #f))
	  (for-each 
	   (lambda (run-id)
	     (db:delay-if-busy mtdb)
	     (let ((testrecs (db:get-all-tests-info-by-run-id mtdb run-id))
		   (dbstruct (if toppath (make-dbr:dbstruct path: toppath local: #t) #f)))
	       (debug:print 0 "INFO: Propagating " (length testrecs) " records for run-id=" run-id " to run specific db")
	       (debug:print 0 *default-log-port* "INFO: Propagating " (length testrecs) " records for run-id=" run-id " to run specific db")
	       (db:replace-test-records dbstruct run-id testrecs)
	       (sqlite3:finalize! (db:dbdat-get-db (dbr:dbstruct-rundb dbstruct)))))
	   run-ids)))

    ;; now ensure all newdb data are synced to megatest.db
    ;; do not use the run-ids list passed in to the function
    ;;
    (if (member 'new2old options)
	(let* ((maindb      (make-dbr:dbstruct path: toppath local: #t))
	       (src-run-ids (if run-ids run-ids (db:get-all-run-ids (db:dbdat-get-db (db:get-db maindb 0)))))
	       (all-run-ids (sort (delete-duplicates (cons 0 src-run-ids)) <))
	       (count       1)
	       (total       (length all-run-ids))
	       (dead-runs  '()))
	  (for-each
	   (lambda (run-id)
	     (debug:print 0 "Processing run " (if (eq? run-id 0) " main.db " run-id) ", " count " of " total)
	     (debug:print 0 *default-log-port* "Processing run " (if (eq? run-id 0) " main.db " run-id) ", " count " of " total)
	     (set! count (+ count 1))
	     (let* ((fromdb (if toppath (make-dbr:dbstruct path: toppath local: #t) #f))
		    (frundb (db:dbdat-get-db (db:get-db fromdb run-id))))
	       ;; (db:delay-if-busy frundb)
	       ;; (db:delay-if-busy mtdb)
	       ;; (db:clean-up frundb)
	       (if (eq? run-id 0)
		   (begin
		   (let ((maindb  (db:dbdat-get-db (db:get-db fromdb #f))))
		     (db:sync-tables (db:sync-main-list dbstruct) (db:get-db fromdb #f) mtdb)
		     (set! dead-runs (db:clean-up-maindb (db:get-db fromdb #f))))
		     (set! dead-runs (db:clean-up-maindb (db:get-db fromdb #f)))
		     ;; 
		     ;; Feb 18, 2016: add field last_update to runs table
		     ;;
		     ;; remove all these some time after september 2016 (added in v1.6031
		     ;;
		     (handle-exceptions
		      exn
		      (if (string-match ".*duplicate.*" ((condition-property-accessor 'exn 'message) exn))
			  (debug:print 0 *default-log-port* "Column last_update already added to runs table")
			  (db:general-sqlite-error-dump exn "alter table runs ..." run-id "none"))
		      (sqlite3:execute
		       maindb
		       "ALTER TABLE runs ADD COLUMN last_update INTEGER DEFAULT 0"))
		     ;; these schema changes don't need exception handling
		     (sqlite3:execute
		      maindb
		      "CREATE TRIGGER IF NOT EXISTS update_runs_trigger AFTER UPDATE ON runs
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE runs SET last_update=(strftime('%s','now'))
                                   WHERE id=old.id;
                               END;")
		     (sqlite3:execute maindb "CREATE TABLE IF NOT EXISTS run_stats (
                              id     INTEGER PRIMARY KEY,
                              run_id INTEGER,
                              state  TEXT,
                              status TEXT,
                              count  INTEGER,
                              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;")
		     )
		   (begin
		     ;; NB// must sync first to ensure deleted tests get marked as such in megatest.db
		     (db:sync-tables db:sync-tests-only (db:get-db fromdb run-id) mtdb)
		     (db:clean-up-rundb (db:get-db fromdb run-id))
		     ;;
		     ;; Feb 18, 2016: add field last_update to tests, test_steps and test_data
		     ;;
		     ;; remove this some time after September 2016 (added in version v1.6031
		     ;;
		     (for-each
		      (lambda (table-name)
			(handle-exceptions
			 exn
			 (if (string-match ".*duplicate.*" ((condition-property-accessor 'exn 'message) exn))
			     (debug:print 0 *default-log-port* "Column last_update already added to " table-name " table")
			     (db:general-sqlite-error-dump exn "alter table " table-name " ..." #f "none"))
			 (sqlite3:execute
			  frundb
			  (conc "ALTER TABLE " table-name " ADD COLUMN last_update INTEGER DEFAULT 0")))
			(sqlite3:execute
			 frundb
			 (conc "DROP TRIGGER IF EXISTS update_" table-name "_trigger;"))
			(sqlite3:execute
			 frundb
			 (conc "CREATE TRIGGER IF NOT EXISTS update_" table-name "_trigger AFTER UPDATE ON " table-name "
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE " table-name " SET last_update=(strftime('%s','now'))
                                   WHERE id=old.id;
		     ))))
                               END;"))
			)
		      '("tests" "test_steps" "test_data"))))))
	   all-run-ids)
	  ;; removed deleted runs
	  (let ((dbdir (tasks:get-task-db-path)))
	    (for-each (lambda (run-id)
			(let ((fullname (conc dbdir "/" run-id ".db")))
			  (if (file-exists? fullname)
			      (begin
				(debug:print 0 "Removing database file for deleted run " fullname)
				(debug:print 0 *default-log-port* "Removing database file for deleted run " fullname)
				(delete-file fullname)))))
		      dead-runs))))

    ;; (db:close-all dbstruct)
    ;; (sqlite3:finalize! mdb)
    ))

;; keeping it around for debugging purposes only
(define (open-run-close-no-exception-handling  proc idb . params)
  (debug:print-info 11 "open-run-close-no-exception-handling START given a db=" (if idb "yes " "no ") ", params=" params)
  (debug:print-info 11 *default-log-port* "open-run-close-no-exception-handling START given a db=" (if idb "yes " "no ") ", params=" params)
  (if (or *db-write-access*
	  (not (member proc *db:all-write-procs*)))
      (let* ((db (cond
		  ((pair? idb)                 (db:dbdat-get-db idb))
		  ((sqlite3:database? idb)     idb)
		  ((not idb)                   (debug:print 0 "ERROR: cannot open-run-close with #f anymore"))
		  ((not idb)                   (debug:print-error 0 *default-log-port* "cannot open-run-close with #f anymore"))
		  ((procedure? idb)            (idb))
		  (else   	               (debug:print 0 "ERROR: cannot open-run-close with #f anymore"))))
		  (else   	               (debug:print-error 0 *default-log-port* "cannot open-run-close with #f anymore"))))
	     (res #f))
	(set! res (apply proc db params))
	(if (not idb)(sqlite3:finalize! dbstruct))
	(debug:print-info 11 "open-run-close-no-exception-handling END" )
	(debug:print-info 11 *default-log-port* "open-run-close-no-exception-handling END" )
	res)
      #f))

(define (open-run-close-exception-handling proc idb . params)
  (handle-exceptions
   exn
   (let ((sleep-time (random 30))
	 (err-status ((condition-property-accessor 'sqlite3 'status #f) exn)))
     (case err-status
       ((busy)
	(thread-sleep! sleep-time))
       (else
	(debug:print 0 "EXCEPTION: database probably overloaded or unreadable.")
	(debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	(debug:print 0 *default-log-port* "EXCEPTION: database probably overloaded or unreadable.")
	(debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	(print "exn=" (condition->list exn))
	(debug:print 0 " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
	(debug:print 0 *default-log-port* " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
	(print-call-chain (current-error-port))
	(thread-sleep! sleep-time)
	(debug:print-info 0 "trying db call one more time....this may never recover, if necessary kill process " (current-process-id) " on host " (get-host-name) " to clean up")))
	(debug:print-info 0 *default-log-port* "trying db call one more time....this may never recover, if necessary kill process " (current-process-id) " on host " (get-host-name) " to clean up")))
     (apply open-run-close-exception-handling proc idb params))
   (apply open-run-close-no-exception-handling proc idb params)))

;; (define open-run-close 
(define open-run-close open-run-close-exception-handling)
		;;	   open-run-close-no-exception-handling
;;			   open-run-close-exception-handling)
887
888
889
890
891
892
893

894



















895
896
897
898
899
900
901
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







+

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







			 state      TEXT DEFAULT '',
			 status     TEXT DEFAULT '',
			 owner      TEXT DEFAULT '',
			 event_time TIMESTAMP DEFAULT (strftime('%s','now')),
			 comment    TEXT DEFAULT '',
			 fail_count INTEGER DEFAULT 0,
			 pass_count INTEGER DEFAULT 0,
                         last_update INTEGER DEFAULT (strftime('%s','now')),
			 CONSTRAINT runsconstraint UNIQUE (runname" (if havekeys "," "") keystr "));"))
       (sqlite3:execute db "CREATE TRIGGER IF NOT EXISTS update_runs_trigger AFTER UPDATE ON runs
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE runs SET last_update=(strftime('%s','now'))
                                   WHERE id=old.id;
                               END;")
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS run_stats (
                              id     INTEGER PRIMARY KEY,
                              run_id INTEGER,
                              state  TEXT,
                              status TEXT,
                              count  INTEGER,
                              last_update INTEGER DEFAULT (strftime('%s','now')))")
       (sqlite3:execute db "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;")
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS test_meta (
                                     id          INTEGER PRIMARY KEY,
                                     testname    TEXT DEFAULT '',
                                     author      TEXT DEFAULT '',
                                     owner       TEXT DEFAULT '',
                                     description TEXT DEFAULT '',
                                     reviewed    TIMESTAMP,
947
948
949
950
951
952
953
954
955


956
957
958
959
960
961
962
1016
1017
1018
1019
1020
1021
1022


1023
1024
1025
1026
1027
1028
1029
1030
1031







-
-
+
+







       ;; (sqlite3:execute db "CREATE VIEW runs_tests AS SELECT * FROM runs INNER JOIN tests ON runs.id=tests.run_id;")
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS extradat (id INTEGER PRIMARY KEY, run_id INTEGER, key TEXT, val TEXT);")
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS metadat (id INTEGER PRIMARY KEY, var TEXT, val TEXT,
                                  CONSTRAINT metadat_constraint UNIQUE (var));")
       (sqlite3:execute db "CREATE TABLE IF NOT EXISTS access_log (id INTEGER PRIMARY KEY, user TEXT, accessed TIMESTAMP, args TEXT);")
       ;; Must do this *after* running patch db !! No more. 
       ;; cannot use db:set-var since it will deadlock, hardwire the code here
       (sqlite3:execute db "INSERT OR REPLACE INTO metadat (var,val) VALUES (?,?);" "MEGATEST_VERSION" megatest-version)
       (debug:print-info 11 "db:initialize END")))))
       (sqlite3:execute db "INSERT OR REPLACE INTO metadat (var,val) VALUES (?,?);" "MEGATEST_VERSION" (common:version-signature))
       (debug:print-info 11 *default-log-port* "db:initialize END")))))

;;======================================================================
;; R U N   S P E C I F I C   D B 
;;======================================================================

(define (db:initialize-run-id-db db)
  (sqlite3:with-transaction 
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
1013
1014
1015
1016
1017
1018

1019
1020
1021







1022
1023
1024
1025
1026
1027
1028
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076

1077


1078
1079
1080





1081
1082

1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095


1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109







+


+
+
+
+
+
+









+

+
-
+
-
-
+
+
+
-
-
-
-
-
+
+
-











+

-
-
+
+
+
+
+
+
+







                     logdat       TEXT      DEFAULT '', 
                     run_duration INTEGER   DEFAULT 0,
                     comment      TEXT      DEFAULT '',
                     event_time   TIMESTAMP DEFAULT (strftime('%s','now')),
                     fail_count   INTEGER   DEFAULT 0,
                     pass_count   INTEGER   DEFAULT 0,
                     archived     INTEGER   DEFAULT 0, -- 0=no, > 1=archive block id where test data can be found
                     last_update  INTEGER DEFAULT (strftime('%s','now')),
                        CONSTRAINT testsconstraint UNIQUE (run_id, testname, item_path));")
     (sqlite3:execute db "CREATE INDEX IF NOT EXISTS tests_index ON tests (run_id, testname, item_path);")
     (sqlite3:execute db "CREATE TRIGGER  IF NOT EXISTS update_tests_trigger AFTER UPDATE ON tests
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE tests SET last_update=(strftime('%s','now'))
                                   WHERE id=old.id;
                               END;")
     (sqlite3:execute db "CREATE TABLE IF NOT EXISTS test_steps 
                              (id INTEGER PRIMARY KEY,
                               test_id INTEGER, 
                               stepname TEXT, 
                               state TEXT DEFAULT 'NOT_STARTED', 
                               status TEXT DEFAULT 'n/a',
                               event_time TIMESTAMP,
                               comment TEXT DEFAULT '',
                               logfile TEXT DEFAULT '',
                               last_update  INTEGER DEFAULT (strftime('%s','now')),
                               CONSTRAINT test_steps_constraint UNIQUE (test_id,stepname,state));")
     (sqlite3:execute db "CREATE INDEX IF NOT EXISTS teststeps_index ON tests (run_id, testname, item_path);")
     ;;   (sqlite3:execute db "CREATE TABLE IF NOT EXISTS test_data 
     (sqlite3:execute db "CREATE TRIGGER  IF NOT EXISTS update_teststeps_trigger AFTER UPDATE ON test_steps
     ;;                               (id          INTEGER PRIMARY KEY,
     ;;                                      reviewed    TIMESTAMP DEFAULT (strftime('%s','now')),
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE test_steps SET last_update=(strftime('%s','now'))
     ;;                                      iterated    TEXT DEFAULT '',
     ;;                                      avg_runtime REAL DEFAULT -1,
     ;;                                      avg_disk    REAL DEFAULT -1,
     ;;                                      tags        TEXT DEFAULT '',
     ;;                                      jobgroup    TEXT DEFAULT 'default',
                                   WHERE id=old.id;
                               END;")
     ;;                                 CONSTRAINT test_meta_constraint UNIQUE (testname));")
     (sqlite3:execute db "CREATE TABLE IF NOT EXISTS test_data (id INTEGER PRIMARY KEY,
                                test_id INTEGER,
                                category TEXT DEFAULT '',
                                variable TEXT,
	                        value REAL,
	                        expected REAL,
	                        tol REAL,
                                units TEXT,
                                comment TEXT DEFAULT '',
                                status TEXT DEFAULT 'n/a',
                                type TEXT DEFAULT '',
                                last_update  INTEGER DEFAULT (strftime('%s','now')),
                              CONSTRAINT test_data_constraint UNIQUE (test_id,category,variable));")
     ;; Why use FULL here? This data is not that critical
     ;; (sqlite3:execute db "PRAGMA synchronous = FULL;")
     (sqlite3:execute db "CREATE INDEX IF NOT EXISTS test_data_index ON test_data (test_id);")
     (sqlite3:execute db "CREATE TRIGGER  IF NOT EXISTS update_test_data_trigger AFTER UPDATE ON test_data
                             FOR EACH ROW
                               BEGIN 
                                 UPDATE test_data SET last_update=(strftime('%s','now'))
                                   WHERE id=old.id;
                               END;")
     (sqlite3:execute db "CREATE TABLE IF NOT EXISTS test_rundat (
                              id           INTEGER PRIMARY KEY,
                              test_id      INTEGER,
                              update_time  TIMESTAMP,
                              cpuload      INTEGER DEFAULT -1,
                              diskfree     INTEGER DEFAULT -1,
                              diskusage    INTGER DEFAULT -1,
1228
1229
1230
1231
1232
1233
1234
1235

1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335

1336
1337
1338
1339
1340
1341
1342
1343







-
+



















-
+







    (sqlite3:for-each-row 
     (lambda (test-id run-dir uname testname item-path)
       (if (and (equal? uname "n/a")
		(equal? item-path "")) ;; this is a toplevel test
	   ;; what to do with toplevel? call rollup?
	   (begin
	     (set! toplevels   (cons (list test-id run-dir uname testname item-path run-id) toplevels))
	     (debug:print-info 0 "Found old toplevel test in RUNNING state, test-id=" test-id))
	     (debug:print-info 0 *default-log-port* "Found old toplevel test in RUNNING state, test-id=" test-id))
	   (set! incompleted (cons (list test-id run-dir uname testname item-path run-id) incompleted))))
     db
     "SELECT id,rundir,uname,testname,item_path FROM tests WHERE run_id=? AND (strftime('%s','now') - event_time) > (run_duration + ?) AND state IN ('RUNNING','REMOTEHOSTSTART');"
     run-id deadtime)

    ;; in LAUNCHED for more than one day. Could be long due to job queues TODO/BUG: Need override for this in config
    ;;
    (db:delay-if-busy dbdat)
    (sqlite3:for-each-row
     (lambda (test-id run-dir uname testname item-path)
       (if (and (equal? uname "n/a")
		(equal? item-path "")) ;; this is a toplevel test
	   ;; what to do with toplevel? call rollup?
	   (set! toplevels   (cons (list test-id run-dir uname testname item-path run-id) toplevels))
	   (set! oldlaunched (cons (list test-id run-dir uname testname item-path run-id) oldlaunched))))
     db
     "SELECT id,rundir,uname,testname,item_path FROM tests WHERE run_id=? AND (strftime('%s','now') - event_time) > 86400 AND state IN ('LAUNCHED');"
     run-id)
    
    (debug:print-info 18 "Found " (length oldlaunched) " old LAUNCHED items, " (length toplevels) " old LAUNCHED toplevel tests and " (length incompleted) " tests marked RUNNING but apparently dead.")
    (debug:print-info 18 *default-log-port* "Found " (length oldlaunched) " old LAUNCHED items, " (length toplevels) " old LAUNCHED toplevel tests and " (length incompleted) " tests marked RUNNING but apparently dead.")
    (if (and (null? incompleted)
	     (null? oldlaunched)
	     (null? toplevels))
	#f
	#t)))

;;  select end_time-now from
1287
1288
1289
1290
1291
1292
1293
1294

1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314

1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337
1368
1369
1370
1371
1372
1373
1374

1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414
1415
1416
1417
1418







-
+



















-
+















-
+







    (sqlite3:for-each-row 
     (lambda (test-id run-dir uname testname item-path)
       (if (and (equal? uname "n/a")
		(equal? item-path "")) ;; this is a toplevel test
	   ;; what to do with toplevel? call rollup?
	   (begin
	     (set! toplevels   (cons (list test-id run-dir uname testname item-path run-id) toplevels))
	     (debug:print-info 0 "Found old toplevel test in RUNNING state, test-id=" test-id))
	     (debug:print-info 0 *default-log-port* "Found old toplevel test in RUNNING state, test-id=" test-id))
	   (set! incompleted (cons (list test-id run-dir uname testname item-path run-id) incompleted))))
     db
     "SELECT id,rundir,uname,testname,item_path FROM tests WHERE run_id=? AND (strftime('%s','now') - event_time) > (run_duration + ?) AND state IN ('RUNNING','REMOTEHOSTSTART');"
     run-id deadtime)

    ;; in LAUNCHED for more than one day. Could be long due to job queues TODO/BUG: Need override for this in config
    ;;
    (db:delay-if-busy dbdat)
    (sqlite3:for-each-row
     (lambda (test-id run-dir uname testname item-path)
       (if (and (equal? uname "n/a")
		(equal? item-path "")) ;; this is a toplevel test
	   ;; what to do with toplevel? call rollup?
	   (set! toplevels   (cons (list test-id run-dir uname testname item-path run-id) toplevels))
	   (set! oldlaunched (cons (list test-id run-dir uname testname item-path run-id) oldlaunched))))
     db
     "SELECT id,rundir,uname,testname,item_path FROM tests WHERE run_id=? AND (strftime('%s','now') - event_time) > 86400 AND state IN ('LAUNCHED');"
     run-id)
    
    (debug:print-info 18 "Found " (length oldlaunched) " old LAUNCHED items, " (length toplevels) " old LAUNCHED toplevel tests and " (length incompleted) " tests marked RUNNING but apparently dead.")
    (debug:print-info 18 *default-log-port* "Found " (length oldlaunched) " old LAUNCHED items, " (length toplevels) " old LAUNCHED toplevel tests and " (length incompleted) " tests marked RUNNING but apparently dead.")

    ;; These are defunct tests, do not do all the overhead of set-state-status. Force them to INCOMPLETE.
    ;;
    (db:delay-if-busy dbdat)
    (let* (;; (min-incompleted (filter (lambda (x)
	   ;;      		      (let* ((testpath (cadr x))
	   ;;      			     (tdatpath (conc testpath "/testdat.db"))
	   ;;      			     (dbexists (file-exists? tdatpath)))
	   ;;      			(or (not dbexists) ;; if no file then something wrong - mark as incomplete
	   ;;      			    (> (- (current-seconds)(file-modification-time tdatpath)) 600)))) ;; no change in 10 minutes to testdat.db - she's dead Jim
	   ;;      		    incompleted))
	   (min-incompleted-ids (map car incompleted)) ;; do 'em all
	   (all-ids             (append min-incompleted-ids (map car oldlaunched))))
      (if (> (length all-ids) 0)
	  (begin
	    (debug:print 0 "WARNING: Marking test(s); " (string-intersperse (map conc all-ids) ", ") " as INCOMPLETE")
	    (debug:print 0 *default-log-port* "WARNING: Marking test(s); " (string-intersperse (map conc all-ids) ", ") " as INCOMPLETE")
	    (sqlite3:execute 
	     db
	     (conc "UPDATE tests SET state='INCOMPLETE' WHERE id IN (" 
		   (string-intersperse (map conc all-ids) ",")
		   ");")))))

    ;; Now do rollups for the toplevel tests
1356
1357
1358
1359
1360
1361
1362
1363

1364
1365
1366
1367
1368
1369
1370
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
1451







-
+







;;    a. If test dir exists, set the the test to state='UNKNOWN', Set the run to 'unknown'
;;    b. If test dir gone, delete the test record
;; 2. Look at run records
;;    a. If have tests that are not deleted, set state='unknown'
;;    b. ....
;;
(define (db:clean-up dbdat)
  ;; (debug:print 0 "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db")
  ;; (debug:print 0 *default-log-port* "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db")
  (let* ((db         (db:dbdat-get-db dbdat))
	 (count-stmt (sqlite3:prepare db "SELECT (SELECT count(id) FROM tests)+(SELECT count(id) FROM runs);"))
	(statements
	 (map (lambda (stmt)
		(sqlite3:prepare db stmt))
	      (list
	       ;; delete all tests that belong to runs that are 'deleted'
1379
1380
1381
1382
1383
1384
1385
1386

1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427

1428
1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469
1470

1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490

1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507

1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531

1532
1533
1534
1535
1536
1537
1538
1539







-
+



-
+



















-
+
















-
+



-
+



















-
+







	       "DELETE FROM runs WHERE id NOT IN (SELECT DISTINCT r.id FROM runs AS r INNER JOIN tests AS t ON t.run_id=r.id);"
	       ))))
    (db:delay-if-busy dbdat)
    (sqlite3:with-transaction 
     db
     (lambda ()
       (sqlite3:for-each-row (lambda (tot)
			       (debug:print-info 0 "Records count before clean: " tot))
			       (debug:print-info 0 *default-log-port* "Records count before clean: " tot))
			     count-stmt)
       (map sqlite3:execute statements)
       (sqlite3:for-each-row (lambda (tot)
			       (debug:print-info 0 "Records count after  clean: " tot))
			       (debug:print-info 0 *default-log-port* "Records count after  clean: " tot))
			     count-stmt)))
    (map sqlite3:finalize! statements)
    (sqlite3:finalize! count-stmt)
    ;; (db:find-and-mark-incomplete db)
    (db:delay-if-busy dbdat)
    (sqlite3:execute db "VACUUM;")))

;; Clean out old junk and vacuum the database
;;
;; Ultimately do something like this:
;;
;; 1. Look at test records either deleted or part of deleted run:
;;    a. If test dir exists, set the the test to state='UNKNOWN', Set the run to 'unknown'
;;    b. If test dir gone, delete the test record
;; 2. Look at run records
;;    a. If have tests that are not deleted, set state='unknown'
;;    b. ....
;;
(define (db:clean-up-rundb dbdat)
  ;; (debug:print 0 "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db")
  ;; (debug:print 0 *default-log-port* "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db")
  (let* ((db         (db:dbdat-get-db dbdat))
	 (count-stmt (sqlite3:prepare db "SELECT (SELECT count(id) FROM tests);"))
	(statements
	 (map (lambda (stmt)
		(sqlite3:prepare db stmt))
	      (list
	       ;; delete all tests that belong to runs that are 'deleted'
	       ;; (conc "DELETE FROM tests WHERE run_id NOT IN (" (string-intersperse (map conc valid-runs) ",") ");")
	       ;; delete all tests that are 'DELETED'
	       "DELETE FROM tests WHERE state='DELETED';"
	       ))))
    (db:delay-if-busy dbdat)
    (sqlite3:with-transaction 
     db
     (lambda ()
       (sqlite3:for-each-row (lambda (tot)
			       (debug:print-info 0 "Records count before clean: " tot))
			       (debug:print-info 0 *default-log-port* "Records count before clean: " tot))
			     count-stmt)
       (map sqlite3:execute statements)
       (sqlite3:for-each-row (lambda (tot)
			       (debug:print-info 0 "Records count after  clean: " tot))
			       (debug:print-info 0 *default-log-port* "Records count after  clean: " tot))
			     count-stmt)))
    (map sqlite3:finalize! statements)
    (sqlite3:finalize! count-stmt)
    ;; (db:find-and-mark-incomplete db)
    (db:delay-if-busy dbdat)
    (sqlite3:execute db "VACUUM;")))

;; Clean out old junk and vacuum the database
;;
;; Ultimately do something like this:
;;
;; 1. Look at test records either deleted or part of deleted run:
;;    a. If test dir exists, set the the test to state='UNKNOWN', Set the run to 'unknown'
;;    b. If test dir gone, delete the test record
;; 2. Look at run records
;;    a. If have tests that are not deleted, set state='unknown'
;;    b. ....
;;
(define (db:clean-up-maindb dbdat)
  ;; (debug:print 0 "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db")
  ;; (debug:print 0 *default-log-port* "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db")
  (let* ((db         (db:dbdat-get-db dbdat))
	 (count-stmt (sqlite3:prepare db "SELECT (SELECT count(id) FROM runs);"))
	 (statements
	  (map (lambda (stmt)
		 (sqlite3:prepare db stmt))
	       (list
		;; delete all tests that belong to runs that are 'deleted'
1467
1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512





1513
1514
1515
1516
1517
1518
1519
1520








1521
1522
1523
1524
1525


1526
1527
1528
1529
1530
1531
1532
1533
1548
1549
1550
1551
1552
1553
1554

1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574


1575




1576
1577
1578

1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592








1593
1594
1595
1596
1597
1598
1599
1600

1601
1602


1603
1604

1605
1606
1607
1608
1609
1610
1611







-
+



-
+















-
-

-
-
-
-
+


-









+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-


-
-
+
+
-







       db
       "SELECT id FROM runs WHERE state='deleted';")
    (db:delay-if-busy dbdat)
    (sqlite3:with-transaction 
     db
     (lambda ()
       (sqlite3:for-each-row (lambda (tot)
			       (debug:print-info 0 "Records count before clean: " tot))
			       (debug:print-info 0 *default-log-port* "Records count before clean: " tot))
			     count-stmt)
       (map sqlite3:execute statements)
       (sqlite3:for-each-row (lambda (tot)
			       (debug:print-info 0 "Records count after  clean: " tot))
			       (debug:print-info 0 *default-log-port* "Records count after  clean: " tot))
			     count-stmt)))
    (map sqlite3:finalize! statements)
    (sqlite3:finalize! count-stmt)
    ;; (db:find-and-mark-incomplete db)
    (db:delay-if-busy dbdat)
    (sqlite3:execute db "VACUUM;")
    dead-runs))

;;======================================================================
;; M E T A   G E T   A N D   S E T   V A R S
;;======================================================================

;; returns number if string->number is successful, string otherwise
;; also updates *global-delta*
;;
;; Operates on megatestdb
;;
(define (db:get-var dbstruct var)
  (let* ((start-ms (current-milliseconds))
         (throttle (let ((t  (config-lookup *configdat* "setup" "throttle")))
		     (if t (string->number t) t)))
	 (res      #f)
  (let* ((res      #f)
	 (dbdat    (db:get-db dbstruct #f))
	 (db       (db:dbdat-get-db dbdat)))
    (db:delay-if-busy dbdat)
    (sqlite3:for-each-row
     (lambda (val)
       (set! res val))
     db
     "SELECT val FROM metadat WHERE var=?;" var)
    ;; convert to number if can
    (if (string? res)
	(let ((valnum (string->number res)))
	  (if valnum (set! res valnum))))
    res))

;; This was part of db:get-var. It was used to estimate the load on
;; the database files.
;;
    ;; scale by 10, average with current value.
    (set! *global-delta* (/ (+ *global-delta* (* (- (current-milliseconds) start-ms)
						 (if throttle throttle 0.01)))
			    2))
    (if (> (abs (- *last-global-delta-printed* *global-delta*)) 0.08) ;; don't print all the time, only if it changes a bit
	(begin
	  (debug:print-info 4 "launch throttle factor=" *global-delta*)
	  (set! *last-global-delta-printed* *global-delta*)))
;; scale by 10, average with current value.
;;     (set! *global-delta* (/ (+ *global-delta* (* (- (current-milliseconds) start-ms)
;; 						 (if throttle throttle 0.01)))
;; 			    2))
;;     (if (> (abs (- *last-global-delta-printed* *global-delta*)) 0.08) ;; don't print all the time, only if it changes a bit
;; 	(begin
;; 	  (debug:print-info 4 *default-log-port* "launch throttle factor=" *global-delta*)
;; 	  (set! *last-global-delta-printed* *global-delta*)))
    res))

(define (db:set-var dbstruct var val)
  (let ((dbdat (db:get-db dbstruct #f))
	(db    (db:dbdat-get-db dbdat)))
  (let* ((dbdat (db:get-db dbstruct #f))
	 (db    (db:dbdat-get-db dbdat)))
    (db:delay-if-busy dbdat)
    (sqlite3:execute db "INSERT OR REPLACE INTO metadat (var,val) VALUES (?,?);" var val)))

(define (db:del-var dbstruct var)
  ;; (db:delay-if-busy)
  (db:with-db dbstruct #f #t 
	      (lambda (db)
		(sqlite3:execute db "DELETE FROM metadat WHERE var=?;" var))))
1550
1551
1552
1553
1554
1555
1556
1557


1558
1559
1560
1561
1562
1563
1564
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638
1639
1640
1641
1642
1643







-
+
+







		       db
		       "SELECT fieldname FROM keys ORDER BY id DESC;")))
	(set! *db-keys* res)
	res)))

;; look up values in a header/data structure
(define (db:get-value-by-header row header field)
  (if (null? header) #f
  (if (or (null? header) (not row))
      #f
      (let loop ((hed (car header))
		 (tal (cdr header))
		 (n   0))
	(if (equal? hed field)
	    (vector-ref row n)
	    (if (null? tal) #f (loop (car tal)(cdr tal)(+ n 1)))))))

1632
1633
1634
1635
1636
1637
1638
1639
1640


1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652

1653
1654
1655
1656
1657
1658
1659

1660
1661
1662
1663
1664
1665
1666
1711
1712
1713
1714
1715
1716
1717


1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730

1731
1732
1733
1734
1735
1736
1737

1738
1739
1740
1741
1742
1743
1744
1745







-
-
+
+











-
+






-
+







	 (keystr    (keys->keystr keys))	 
	 (comma     (if (> (length keys) 0) "," ""))
	 (andstr    (if (> (length keys) 0) " AND " ""))
	 (valslots  (keys->valslots keys)) ;; ?,?,? ...
	 (allvals   (append (list runname state status user) (map cadr keyvals)))
	 (qryvals   (append (list runname) (map cadr keyvals)))
	 (key=?str  (string-intersperse (map (lambda (k)(conc k "=?")) keys) " AND ")))
    (debug:print 3 "keys: " keys " allvals: " allvals " keyvals: " keyvals " key=?str is " key=?str)
    (debug:print 2 "NOTE: using target " (string-intersperse (map cadr keyvals) "/") " for this run")
    (debug:print 3 *default-log-port* "keys: " keys " allvals: " allvals " keyvals: " keyvals " key=?str is " key=?str)
    (debug:print 2 *default-log-port* "NOTE: using target " (string-intersperse (map cadr keyvals) "/") " for this run")
    (if (and runname (null? (filter (lambda (x)(not x)) keyvals))) ;; there must be a better way to "apply and"
	(let ((res #f))
	  (db:delay-if-busy dbdat)
	  (apply sqlite3:execute db (conc "INSERT OR IGNORE INTO runs (runname,state,status,owner,event_time" comma keystr ") VALUES (?,?,?,?,strftime('%s','now')" comma valslots ");")
		 allvals)
	  (db:delay-if-busy dbdat)
	  (apply sqlite3:for-each-row 
		 (lambda (id)
		   (set! res id))
		 db
		 (let ((qry (conc "SELECT id FROM runs WHERE (runname=? " andstr key=?str ");")))
					;(debug:print 4 "qry: " qry) 
					;(debug:print 4 *default-log-port* "qry: " qry) 
		   qry)
		 qryvals)
	  (db:delay-if-busy dbdat)
	  (sqlite3:execute db "UPDATE runs SET state=?,status=?,event_time=strftime('%s','now') WHERE id=? AND state='deleted';" state status res)
	  res) 
	(begin
	  (debug:print 0 "ERROR: Called without all necessary keys")
	  (debug:print-error 0 *default-log-port* "Called without all necessary keys")
	  #f))))

;; replace header and keystr with a call to runs:get-std-run-fields
;;
;; keypatts: ( (KEY1 "abc%def")(KEY2 "%") )
;; runpatts: patt1,patt2 ...
;;
1686
1687
1688
1689
1690
1691
1692
1693

1694
1695
1696
1697
1698
1699
1700
1701
1702

1703
1704


1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717

1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1765
1766
1767
1768
1769
1770
1771

1772
1773
1774
1775
1776
1777
1778
1779
1780

1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797

1798
1799
1800
1801













































1802
1803
1804
1805
1806
1807
1808







-
+








-
+


+
+












-
+



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







			   " AND state != 'deleted' ORDER BY event_time DESC "
			   (if (number? count)
			       (conc " LIMIT " count)
			       "")
			   (if (number? offset)
			       (conc " OFFSET " offset)
			       ""))))
    (debug:print-info 11 "db:get-runs START qrystr: " qrystr " keypatts: " keypatts " offset: " offset " limit: " count)
    (debug:print-info 11 *default-log-port* "db:get-runs START qrystr: " qrystr " keypatts: " keypatts " offset: " offset " limit: " count)
    (db:with-db dbstruct #f #f
		(lambda (db)		
		  (sqlite3:for-each-row
		   (lambda (a . x)
		     (set! res (cons (apply vector a x) res)))
		   db
		   qrystr
		   )))
    (debug:print-info 11 "db:get-runs END qrystr: " qrystr " keypatts: " keypatts " offset: " offset " limit: " count)
    (debug:print-info 11 *default-log-port* "db:get-runs END qrystr: " qrystr " keypatts: " keypatts " offset: " offset " limit: " count)
    (vector header res)))

;; TODO: Switch this to use max(update_time) from each run db? Then if using a server there is no disk traffic (using inmem db)
;;
(define (db:get-changed-run-ids since-time)
  (let* ((dbdir      (db:dbfile-path #f)) ;; (configf:lookup *configdat* "setup" "dbdir"))
	 (alldbs     (glob (conc dbdir "/[0-9]*.db")))
	 (changed    (filter (lambda (dbfile)
			       (> (file-modification-time dbfile) since-time))
			     alldbs)))
    (delete-duplicates
     (map (lambda (dbfile)
	    (let* ((res (string-match ".*\\/(\\d)*\\.db" dbfile)))
	      (if res
		  (string->number (cadr res))
		  (begin
		    (debug:print 2 "WARNING: Failed to process " dbfile " for run-id")
		    (debug:print 2 *default-log-port* "WARNING: Failed to process " dbfile " for run-id")
		    0))))
	  changed))))

;; db:get-runs-by-patt
;; get runs by list of criteria
;; register a test run with the db
;;
;; Use: (db:get-value-by-header (db:get-header runinfo)(db:get-rows runinfo))
;;  to extract info from the structure returned
;;
;; NOTE: THIS IS COMPLETELY UNFINISHED. IT GOES WITH rmt:get-get-paths-matching-keynames
;;
;; (define (db:get-run-ids-matching dbstruct keynames target res)
;; ;; (define (db:get-runs-by-patt dbstruct keys runnamepatt targpatt offset limit) ;; test-name)
;;   (let* ((tmp      (runs:get-std-run-fields keys '("id" "runname" "state" "status" "owner" "event_time")))
;; 	 (keystr   (car tmp))
;; 	 (header   (cadr tmp))
;; 	 (res     '())
;; 	 (key-patt "")
;; 	 (runwildtype (if (substring-index "%" runnamepatt) "like" "glob"))
;; 	 (qry-str  #f)
;; 	 (keyvals  (if targpatt (keys:target->keyval keys targpatt) '())))
;;     (for-each (lambda (keyval)
;; 		(let* ((key    (car keyval))
;; 		       (patt   (cadr keyval))
;; 		       (fulkey (conc ":" key))
;; 		       (wildtype (if (substring-index "%" patt) "like" "glob")))
;; 		  (if patt
;; 		      (set! key-patt (conc key-patt " AND " key " " wildtype " '" patt "'"))
;; 		      (begin
;; 			(debug:print 0 "ERROR: searching for runs with no pattern set for " fulkey)
;; 			(exit 6)))))
;; 	      keyvals)
;;     (set! qry-str (conc "SELECT " keystr " FROM runs WHERE state != 'deleted' AND runname " runwildtype " ? " key-patt " ORDER BY event_time "
;; 			(if limit  (conc " LIMIT " limit)   "")
;; 			(if offset (conc " OFFSET " offset) "")
;; 			";"))
;;     (debug:print-info 4 "runs:get-runs-by-patt qry=" qry-str " " runnamepatt)
;;     (db:with-db dbstruct #f #f ;; reads db, does not write to it.
;; 		(lambda (db)
;; 		  (sqlite3:for-each-row
;; 		   (lambda (a . r)
;; 		     (set! res (cons (list->vector (cons a r)) res)))
;; 		   (db:get-db dbstruct #f)
;; 		   qry-str
;; 		   runnamepatt)))
;;     (vector header res)))

;; Get all targets from the db
;;
(define (db:get-targets dbstruct)
  (let* ((res       '())
	 (keys       (db:get-keys dbstruct))
	 (header     keys) ;; (map key:get-fieldname keys))
	 (keystr     (keys->keystr keys))
1782
1783
1784
1785
1786
1787
1788
1789

1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800

1801
1802
1803
1804
1805
1806

1807























































1808
1809
1810
1811
1812
1813
1814
1818
1819
1820
1821
1822
1823
1824

1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835

1836
1837
1838
1839
1840
1841

1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905







-
+










-
+





-
+

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







	  (let ((targ (cons a x)))
	    (if (not (hash-table-ref/default seen targ #f))
		(begin
		  (hash-table-set! seen targ #t)
		  (set! res (cons (apply vector targ) res))))))
	db
	qrystr)
       (debug:print-info 11 "db:get-targets END qrystr: " qrystr )
       (debug:print-info 11 *default-log-port* "db:get-targets END qrystr: " qrystr )
       (vector header res)))))

;; just get count of runs
(define (db:get-num-runs dbstruct runpatt)
  (db:with-db
   dbstruct
   #f
   #f
   (lambda (db)
     (let ((numruns 0))
       (debug:print-info 11 "db:get-num-runs START " runpatt)
       (debug:print-info 11 *default-log-port* "db:get-num-runs START " runpatt)
       (sqlite3:for-each-row 
	(lambda (count)
	  (set! numruns count))
	db
	"SELECT COUNT(id) FROM runs WHERE runname LIKE ? AND state != 'deleted';" runpatt)
       (debug:print-info 11 "db:get-num-runs END " runpatt)
       (debug:print-info 11 *default-log-port* "db:get-num-runs END " runpatt)
       numruns))))

;; (sqlite3#fold-row proc3670 init3671 db-or-stmt3672 . params3673)>
;; 
(define (db:get-raw-run-stats dbstruct run-id)
  (db:with-db
   dbstruct
   run-id
   #f
   (lambda (db)
     (sqlite3:fold-row
	(lambda (res state status count)
	  (cons (list state status count) res))
	'()
	db
	"SELECT state,status,count(id) AS count FROM tests WHERE run_id=? AND NOT(uname='n/a' AND item_path='') GROUP BY state,status;;"
	run-id))))

;; Update run_stats for given run_id
;; input data is a list (state status count)
;;
(define (db:update-run-stats dbstruct run-id stats)
  (db:with-db
   dbstruct
   #f
   #f
   (lambda (db)
     ;; remove previous data
     (let* ((stmt1 (sqlite3:prepare db "DELETE FROM run_stats WHERE run_id=? AND state=? AND status=?;"))
	    (stmt2 (sqlite3:prepare db "INSERT INTO run_stats (run_id,state,status,count) VALUES (?,?,?,?);"))
	    (res
	     (sqlite3:with-transaction
	      db
	      (lambda ()
		(for-each
		 (lambda (dat)
		   (sqlite3:execute stmt1 run-id (car dat)(cadr dat))
		   (apply sqlite3:execute stmt2 run-id dat))
		 stats)))))
       (sqlite3:finalize! stmt1)
       (sqlite3:finalize! stmt2)
       res))))

(define (db:get-main-run-stats dbstruct run-id)
  (db:with-db
   dbstruct
   #f ;; this data comes from main
   #f
   (lambda (db)
     (sqlite3:fold-row
	(lambda (res state status count)
	  (cons (list state status count) res))
	'()
	db
	"SELECT state,status,count FROM run_stats WHERE run_id=? AND run_id IN (SELECT id FROM runs WHERE state NOT IN ('DELETED','deleted'));"
	run-id))))

(define (db:get-all-run-ids dbstruct)
  (db:with-db
   dbstruct
   #f
   #f
   (lambda (db)
1889
1890
1891
1892
1893
1894
1895
1896

1897
1898
1899
1900
1901
1902
1903

1904
1905
1906
1907
1908
1909
1910
1980
1981
1982
1983
1984
1985
1986

1987
1988
1989
1990
1991
1992
1993

1994
1995
1996
1997
1998
1999
2000
2001







-
+






-
+







		(let* ((key    (car keyval))
		       (patt   (cadr keyval))
		       (fulkey (conc ":" key))
		       (wildtype (if (substring-index "%" patt) "like" "glob")))
		  (if patt
		      (set! key-patt (conc key-patt " AND " key " " wildtype " '" patt "'"))
		      (begin
			(debug:print 0 "ERROR: searching for runs with no pattern set for " fulkey)
			(debug:print-error 0 *default-log-port* "searching for runs with no pattern set for " fulkey)
			(exit 6)))))
	      keyvals)
    (set! qry-str (conc "SELECT " keystr " FROM runs WHERE state != 'deleted' AND runname " runwildtype " ? " key-patt " ORDER BY event_time "
			(if limit  (conc " LIMIT " limit)   "")
			(if offset (conc " OFFSET " offset) "")
			";"))
    (debug:print-info 4 "runs:get-runs-by-patt qry=" qry-str " " runnamepatt)
    (debug:print-info 4 *default-log-port* "runs:get-runs-by-patt qry=" qry-str " " runnamepatt)
    (db:with-db dbstruct #f #f ;; reads db, does not write to it.
		(lambda (db)
		  (sqlite3:for-each-row
		   (lambda (a . r)
		     (set! res (cons (list->vector (cons a r)) res)))
		   db
		   qry-str
1919
1920
1921
1922
1923
1924
1925
1926

1927
1928
1929
1930
1931
1932
1933
1934

1935
1936
1937
1938
1939
1940
1941
2010
2011
2012
2013
2014
2015
2016

2017
2018
2019
2020
2021
2022
2023
2024

2025
2026
2027
2028
2029
2030
2031
2032







-
+







-
+







	 (db        (db:dbdat-get-db dbdat))
	 (res       (vector #f #f #f #f))
	 (keys      (db:get-keys dbstruct))
	 (remfields (list "id" "runname" "state" "status" "owner" "event_time"))
	 (header    (append keys remfields))
	 (keystr    (conc (keys->keystr keys) ","
			  (string-intersperse remfields ","))))
    (debug:print-info 11 "db:get-run-info run-id: " run-id " header: " header " keystr: " keystr)
    (debug:print-info 11 *default-log-port* "db:get-run-info run-id: " run-id " header: " header " keystr: " keystr)
    (db:delay-if-busy dbdat)
    (sqlite3:for-each-row
     (lambda (a . x)
       (set! res (apply vector a x)))
     db 
     (conc "SELECT " keystr " FROM runs WHERE id=? AND state != 'deleted';")
     run-id)
    (debug:print-info 11 "db:get-run-info run-id: " run-id " header: " header " keystr: " keystr)
    (debug:print-info 11 *default-log-port* "db:get-run-info run-id: " run-id " header: " header " keystr: " keystr)
    (let ((finalres (vector header res)))
      ;; (hash-table-set! *run-info-cache* run-id finalres)
      finalres)))

(define (db:set-comment-for-run dbstruct run-id comment)
  (db:with-db
   dbstruct
1976
1977
1978
1979
1980
1981
1982
1983

1984
1985
1986
1987
1988
1989
1990
2067
2068
2069
2070
2071
2072
2073

2074
2075
2076
2077
2078
2079
2080
2081







-
+







     (let ((newlockval (if lock "locked"
			   (if unlock
			       "unlocked"
			       "locked")))) ;; semi-failsafe
       (sqlite3:execute db "UPDATE runs SET state=? WHERE id=?;" newlockval run-id)
       (sqlite3:execute db "INSERT INTO access_log (user,accessed,args) VALUES(?,strftime('%s','now'),?);"
			user (conc newlockval " " run-id))
       (debug:print-info 1 "" newlockval " run number " run-id)))))
       (debug:print-info 1 *default-log-port* "" newlockval " run number " run-id)))))

(define (db:set-run-status dbstruct run-id status msg)
  (let* ((dbdat (db:get-db dbstruct #f))
	 (db    (db:dbdat-get-db dbdat)))
    (db:delay-if-busy dbdat)
    (if msg
	(sqlite3:execute db "UPDATE runs SET status=?,comment=? WHERE id=?;" status msg run-id)
2073
2074
2075
2076
2077
2078
2079



2080

2081
2082
2083

2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094


2095
2096
2097



2098
2099
2100
2101
2102


2103
2104
2105



2106
2107




2108
2109
2110







2111

2112


2113

2114


2115

2116
2117
2118
2119


2120
2121

2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135

2136
2137
2138
2139
2140
2141
2142
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173

2174
2175
2176

2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190



2191
2192
2193
2194
2195
2196
2197
2198
2199
2200



2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219

2220
2221
2222
2223

2224
2225
2226
2227

2228
2229
2230
2231

2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249

2250
2251
2252
2253
2254
2255
2256
2257







+
+
+
-
+


-
+











+
+
-
-
-
+
+
+





+
+
-
-
-
+
+
+


+
+
+
+



+
+
+
+
+
+
+
-
+

+
+
-
+

+
+
-
+



-
+
+


+













-
+







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

;; states and statuses are lists, turn them into ("PASS","FAIL"...) and use NOT IN
;; i.e. these lists define what to NOT show.
;; states and statuses are required to be lists, empty is ok
;; not-in #t = above behaviour, #f = must match
;; mode:
;;  'dashboard - use state = 'COMPLETED' AND status in ( statuses ) OR state in ( states )
;;
(define (db:get-tests-for-run dbstruct run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals)
(define (db:get-tests-for-run dbstruct run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals last-update mode)
  (if (not (number? run-id))
      (begin ;; no need to treat this as an error by default
	(debug:print 4 "WARNING: call to db:get-tests-for-run with bad run-id=" run-id)
	(debug:print 4 *default-log-port* "WARNING: call to db:get-tests-for-run with bad run-id=" run-id)
	;; (print-call-chain (current-error-port))
	'())
      (let* ((qryvalstr       (case qryvals
				((shortlist) "id,run_id,testname,item_path,state,status")
				((#f)        db:test-record-qry-selector) ;; "id,run_id,testname,state,status,event_time,host,cpuload,diskfree,uname,rundir,item_path,run_duration,final_logf,comment")
				(else        qryvals)))
	     (res            '())
	     ;; if states or statuses are null then assume match all when not-in is false
	     (states-qry      (if (null? states) 
				  #f
				  (conc " state "  
					(if (eq? mode 'dashboard)
					    " IN ('"
					(if not-in
					    " NOT IN ('"
					    " IN ('") 
					    (if not-in
						" NOT IN ('"
						" IN ('")) 
					(string-intersperse states   "','")
					"')")))
	     (statuses-qry    (if (null? statuses)
				  #f
				  (conc " status "
					(if (eq? mode 'dashboard)
					    " IN ('"
					(if not-in 
					    " NOT IN ('"
					    " IN ('") 
					    (if not-in 
						" NOT IN ('"
						" IN ('") )
					(string-intersperse statuses "','")
					"')")))
	     (interim-qry       (conc " AND " (if not-in "NOT " "") "( state='COMPLETED' " (if statuses-qry (conc " AND " statuses-qry " ) ") " ) ")
				      (if states-qry
					  (conc (if not-in " AND " " OR ") states-qry ) ;; " ) ")
					  "")))
	     (states-statuses-qry 
	      (cond 
	       ((and states-qry statuses-qry)
		(case mode
		  ((dashboard) 
		   (if not-in
		       (conc " AND (state='COMPLETED' AND status NOT IN ('" (string-intersperse statuses "','") "')) "
			     " OR (state != 'COMPLETED' AND state NOT IN ('" (string-intersperse states "','") "')) ")
		       (conc " AND (state='COMPLETED' AND status IN ('" (string-intersperse statuses "','") "')) "
			     " OR (state NOT IN ('COMPLETED','DELETED') AND state IN ('" (string-intersperse states "','") "')) ")))
		(conc " AND ( " states-qry " AND " statuses-qry " ) "))
		  (else       (conc " AND ( " states-qry " AND " statuses-qry " ) "))))
	       (states-qry  
		(case mode
		  ((dashboard) (conc " AND " (if not-in "NOT " "") " state IN ('" (string-intersperse states    "','") "') ")) ;; interim-qry)
		(conc " AND " states-qry))
		  (else        (conc " AND " states-qry))))
	       (statuses-qry 
		(case mode
		  ((dashboard) (conc " AND " (if not-in "NOT " "") " status IN ('" (string-intersperse statuses "','") "') ")) ;; interim-qry)
		(conc " AND " statuses-qry))
		  (else        (conc " AND " statuses-qry))))
	       (else "")))
	     (tests-match-qry (tests:match->sqlqry testpatt))
	     (qry             (conc "SELECT " qryvalstr
				    " FROM tests WHERE run_id=? AND state != 'DELETED' "
				    " FROM tests WHERE run_id=? "
				    (if last-update " " " AND state != 'DELETED' ") ;; if using last-update we want deleted tests?
				    states-statuses-qry
				    (if tests-match-qry (conc " AND (" tests-match-qry ") ") "")
				    (if last-update (conc " AND last_update >= " last-update " ") "")
				    (case sort-by
				      ((rundir)      " ORDER BY length(rundir) ")
				      ((testname)    (conc " ORDER BY testname " (if sort-order (conc sort-order ",") "") " item_path "))
				      ((statestatus) (conc " ORDER BY state " (if  sort-order (conc sort-order ",") "") " status "))
				      ((event_time)  " ORDER BY event_time ")
				      (else          (if (string? sort-by)
							 (conc " ORDER BY " sort-by " ")
							 " ")))
				    (if sort-order sort-order " ")
				    (if limit  (conc " LIMIT " limit)   " ")
				    (if offset (conc " OFFSET " offset) " ")
				    ";"
				    )))
	(debug:print-info 8 "db:get-tests-for-run run-id=" run-id ", qry=" qry)
	(debug:print-info 8 *default-log-port* "db:get-tests-for-run run-id=" run-id ", qry=" qry)
	(db:with-db dbstruct run-id #f
		    (lambda (db)
		      (sqlite3:for-each-row 
		       (lambda (a . b) ;; id run-id testname state status event-time host cpuload diskfree uname rundir item-path run-duration final-logf comment)
			 (set! res (cons (apply vector a b) res))) ;; id run-id testname state status event-time host cpuload diskfree uname rundir item-path run-duration final-logf comment) res)))
		       db
		       qry
2160
2161
2162
2163
2164
2165
2166
2167

2168
2169
2170
2171
2172
2173
2174
2275
2276
2277
2278
2279
2280
2281

2282
2283
2284
2285
2286
2287
2288
2289







-
+







	  -1 "-" "-"))

(define (db:get-tests-for-run-state-status dbstruct run-id testpatt)
  (let* ((res            '())
	 (tests-match-qry (tests:match->sqlqry testpatt))
	 (qry             (conc "SELECT id,testname,item_path,state,status FROM tests WHERE run_id=? " 
				(if tests-match-qry (conc " AND (" tests-match-qry ") ") ""))))
    (debug:print-info 8 "db:get-tests-for-run qry=" qry)
    (debug:print-info 8 *default-log-port* "db:get-tests-for-run qry=" qry)
    (db:with-db dbstruct run-id #f
		(lambda (db)
		  (sqlite3:for-each-row
		   (lambda (id testname item-path state status)
		     ;;                      id,run_id,testname,state,status,event_time,host,cpuload,diskfree,uname,rundir,item_path,run_duration,final_logf,comment
		     (set! res (cons (vector id run-id testname state status -1         ""     -1      -1       ""    "-"  item-path -1           "-"         "-") res)))
		   db 
2187
2188
2189
2190
2191
2192
2193
2194

2195
2196
2197
2198
2199
2200
2201
2202
2203

2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214

2215
2216
2217
2218
2219
2220
2221
2302
2303
2304
2305
2306
2307
2308

2309







2310

2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321

2322
2323
2324
2325
2326
2327
2328
2329







-
+
-
-
-
-
-
-
-

-
+










-
+







		   db 
		   "SELECT run_id,testname,item_path,state,status FROM tests WHERE id=?;" 
		   test-id)))
    res))

;; get a useful subset of the tests data (used in dashboard
;; use db:mintest-get-{id ,run_id,testname ...}
;; 
;;
(define (db:get-tests-for-runs-mindata dbstruct run-ids testpatt states statuses not-in)
  (debug:print 0 "ERROR: BROKN!")
  ;; (db:get-tests-for-runs dbstruct run-ids testpatt states statuses not-in: not-in qryvals: "id,run_id,testname,state,status,event_time,item_path"))
)

;; get a useful subset of the tests data (used in dashboard
;;
(define (db:get-tests-for-run-mindata dbstruct run-id testpatt states statuses not-in)
  (db:get-tests-for-run dbstruct run-id testpatt states statuses #f #f not-in #f #f "id,run_id,testname,state,status,event_time,item_path"))
  (db:get-tests-for-run dbstruct run-id testpatt states statuses #f #f not-in #f #f "id,run_id,testname,state,status,event_time,item_path" 0 #f))

;; do not use.
;;
(define (db:get-tests-for-runs dbstruct run-ids testpatt states statuses #!key (not-in #f)(qryvals #f))
  ;; (db:delay-if-busy)
  (let ((res '()))
    (for-each 
     (lambda (run-id)
       (set! res (append 
		  res 
		  (db:get-tests-for-run dbstruct run-id testpatt states statuses #f #f not-in #f #f qryvals))))
		  (db:get-tests-for-run dbstruct run-id testpatt states statuses #f #f not-in #f #f qryvals #f 'normal))))
     (if run-ids
	 run-ids
	 (db:get-all-run-ids dbstruct)))
    res))

;; Convert calling routines to get list of run-ids and loop, do not use the get-tests-for-runs
;;
2242
2243
2244
2245
2246
2247
2248
2249

2250
2251
2252
2253
2254
2255
2256
2350
2351
2352
2353
2354
2355
2356

2357
2358
2359
2360
2361
2362
2363
2364







-
+







     run-ids)))

;; set tests with state currstate and status currstatus to newstate and newstatus
;; use currstate = #f and or currstatus = #f to apply to any state or status respectively
;; WARNING: SQL injection risk. NB// See new but not yet used "faster" version below
;;
;;  AND NOT (item_path='' AND testname in (SELECT DISTINCT testname FROM tests WHERE testname=? AND item_path != ''));")))
;;  (debug:print 0 "QRY: " qry)
;;  (debug:print 0 *default-log-port* "QRY: " qry)
;;  (db:delay-if-busy)
;;
;; NB// This call only operates on toplevel tests. Consider replacing it with more general call
;;
(define (db:set-tests-state-status dbstruct run-id testnames currstate currstatus newstate newstatus)
  (for-each (lambda (testname)
	      (let ((qry (conc "UPDATE tests SET state=?,status=? WHERE "
2470
2471
2472
2473
2474
2475
2476
2477

2478
2479
2480
2481
2482
2483

2484
2485
2486
2487
2488
2489
2490
2578
2579
2580
2581
2582
2583
2584

2585
2586
2587
2588
2589
2590

2591
2592
2593
2594
2595
2596
2597
2598







-
+





-
+








(define (db:replace-test-records dbstruct run-id testrecs)
  (db:with-db dbstruct run-id #t 
	      (lambda (db)
		(let* ((qmarks (string-intersperse (make-list (length db:test-record-fields) "?") ","))
		       (qrystr (conc "INSERT OR REPLACE INTO tests (" db:test-record-qry-selector ") VALUES (" qmarks ");"))
		       (qry    (sqlite3:prepare db qrystr)))
		  (debug:print 0 "INFO: migrating test records for run with id " run-id)
		  (debug:print 0 *default-log-port* "INFO: migrating test records for run with id " run-id)
		  (sqlite3:with-transaction
		   db
		   (lambda ()
		     (for-each 
		      (lambda (rec)
			;; (debug:print 0 "INFO: Inserting values: " (string-intersperse (map conc (vector->list rec)) ",") "\n")
			;; (debug:print 0 *default-log-port* "INFO: Inserting values: " (string-intersperse (map conc (vector->list rec)) ",") "\n")
			(apply sqlite3:execute qry (vector->list rec)))
		      testrecs)))
		  (sqlite3:finalize! qry)))))

;; map a test-id into the proper range
;;
(define (db:adj-test-id mtdb min-test-id test-id)
2498
2499
2500
2501
2502
2503
2504
2505

2506
2507
2508
2509
2510
2511

2512
2513
2514
2515
2516
2517
2518
2606
2607
2608
2609
2610
2611
2612

2613
2614
2615
2616
2617
2618

2619
2620
2621
2622
2623
2624
2625
2626







-
+





-
+







	   (db:dbdat-get-db mtdb)
	   "SELECT id FROM tests WHERE id=?;"
	   new-id)
	  ;; if test-id-found then need to try again
	  (if test-id-found
	      (loop (+ new-id 1))
	      (begin
		(debug:print-info 0 "New test id " new-id " selected for test with id " test-id)
		(debug:print-info 0 *default-log-port* "New test id " new-id " selected for test with id " test-id)
		(sqlite3:execute mtdb "UPDATE tests SET id=? WHERE id=?;" new-id test-id)))))))

;; move test ids into the 30k * run_id range
;;
(define (db:prep-megatest.db-adj-test-ids mtdb run-id testrecs)
  (debug:print-info 0 "Adjusting test ids in megatest.db for run " run-id)
  (debug:print-info 0 *default-log-port* "Adjusting test ids in megatest.db for run " run-id)
  (let ((min-test-id (* run-id 30000)))
    (for-each 
     (lambda (testrec)
       (let* ((test-id (vector-ref testrec (db:field->number "id" db:test-record-fields))))
	 (db:adj-test-id (db:dbdat-get-db mtdb) min-test-id test-id)))
     testrecs)))
	
2612
2613
2614
2615
2616
2617
2618
2619
2620


2621
2622

2623
2624
2625
2626
2627
2628
2629
2720
2721
2722
2723
2724
2725
2726


2727
2728
2729

2730
2731
2732
2733
2734
2735
2736
2737







-
-
+
+

-
+







  (db:with-db
   dbstruct
   run-id
   #f
   (lambda (db)
     (let* ((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)))
	(lambda (id test-id stepname state status event-time logfile comment)
	  (set! res (cons (vector id test-id stepname state status event-time (if (string? logfile) logfile "") comment) 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;
	"SELECT id,test_id,stepname,state,status,event_time,logfile,comment 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 dbstruct run-id test-id)
  (db:with-db
   dbstruct
   run-id
2662
2663
2664
2665
2666
2667
2668

2669
2670
















































































2671
2672

2673
2674
2675
2676
2677
2678
2679

2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696

2697
2698
2699
2700
2701
2702
2703
2704
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
2731
2770
2771
2772
2773
2774
2775
2776
2777


2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858

2859
2860
2861
2862
2863
2864
2865

2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882

2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893

2894
2895
2896
2897
2898
2899
2900
2901

2902
2903
2904
2905
2906
2907
2908
2909
2910

2911
2912
2913
2914
2915
2916
2917
2918







+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+






-
+
















-
+










-
+







-
+








-
+







             (SELECT count(id) FROM test_data WHERE test_id=? AND status like 'pass') AS pass_count;"
     test-id test-id)
    ;; Now rollup the counts to the central megatest.db
    (db:general-call dbdat '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 dbdat 'test_data-pf-rollup (list test-id test-id test-id test-id))))

;; each section is a rule except "final" which is the final result
;; NOT USED!?
;;
;;
;; [rule-5]
;; operator in
;; section LogFileBody
;; desc Output voltage
;; status OK
;; expected 1.9
;; measured 1.8
;; type +/-
;; tolerance 0.1
;; pass 1
;; fail 0
;; 
;; [final]
;; exit-code 6
;; exit-status SKIP
;; message If flagged we are asking for this to exit with code 6
;;
;; recorded in steps table:
;;   category: stepname
;;   variable: rule-N
;;   value:    measured
;;   expected: expected
;;   tol:      tolerance
;;   units:    -
;;   comment:  desc or message
;;   status:   status
;;   type:     type
;; 
(define (db:logpro-dat->csv dat stepname)
  (let ((res '()))
    (for-each
     (lambda (entry-name)
       (if (equal? entry-name "final")
	   (set! res (append 
		      res
		      (list
		       (list stepname
			     entry-name
			     (configf:lookup dat entry-name "exit-code")    ;; 0 ;; Value
			     0                                              ;; 1 ;; Expected
			     0                                              ;; 2 ;; Tolerance
			     "n/a"					    ;; 3 ;; Units
			     (configf:lookup dat entry-name "message")      ;; 4 ;; Comment
			     (configf:lookup dat entry-name "exit-status")  ;; 5 ;; Status
			     "logpro"                                       ;; 6 ;; Type
			     ))))
	   (let* ((value     (or (configf:lookup dat entry-name "measured")  "n/a"))
		  (expected  (or (configf:lookup dat entry-name "expected")  "n/a"))
		  (tolerance (or (configf:lookup dat entry-name "tolerance") "n/a"))
		  (comment   (or (configf:lookup dat entry-name "comment")
				 (configf:lookup dat entry-name "desc")      "n/a"))
		  (status    (or (configf:lookup dat entry-name "status")    "n/a"))
		  (type      (or (configf:lookup dat entry-name "expected")  "n/a")))
	     (set! res (append
			res  
			(list (list stepname
				    entry-name 
				    value        ;; 0
				    expected     ;; 1
				    tolerance    ;; 2
				    "n/a"        ;; 3 Units
				    comment      ;; 4
				    status       ;; 5
				    type         ;; 6
				    )))))))
     (hash-table-keys dat))
    res))

;; $MT_MEGATEST -load-test-data << EOF
;; foo,bar,   1.2,  1.9, >
;; foo,rab, 1.0e9, 10e9, 1e9
;; foo,bla,   1.2,  1.9, <
;; foo,bal,   1.2,  1.2, <   ,     ,Check for overload
;; foo,alb,   1.2,  1.2, <=  , Amps,This is the high power circuit test
;; foo,abl,   1.2,  1.3, 0.1
;; foo,bra,   1.2, pass, silly stuff
;; faz,bar,    10,  8mA,     ,     ,"this is a comment"
;; EOF

(define (db:csv->test-data dbstruct run-id test-id csvdata)
  (debug:print 4 "test-id " test-id ", csvdata: " csvdata)
  (debug:print 4 *default-log-port* "test-id " test-id ", csvdata: " csvdata)
  (let* ((dbdat   (db:get-db dbstruct run-id))
	 (db      (db:dbdat-get-db dbdat))
	 (csvlist (csv->list (make-csv-reader
			      (open-input-string csvdata)
			      '((strip-leading-whitespace? #t)
				(strip-trailing-whitespace? #t)))))) ;; (csv->list csvdata)))
    (for-each 
    (for-each
     (lambda (csvrow)
       (let* ((padded-row  (take (append csvrow (list #f #f #f #f #f #f #f #f #f)) 9))
	      (category    (list-ref padded-row 0))
	      (variable    (list-ref padded-row 1))
	      (value       (any->number-if-possible (list-ref padded-row 2)))
	      (expected    (any->number-if-possible (list-ref padded-row 3)))
	      (tol         (any->number-if-possible (list-ref padded-row 4))) ;; >, <, >=, <=, or a number
	      (units       (list-ref padded-row 5))
	      (comment     (list-ref padded-row 6))
	      (status      (let ((s (list-ref padded-row 7)))
			     (if (and (string? s)(or (string-match (regexp "^\\s*$") s)
						     (string-match (regexp "^n/a$") s)))
				 #f
				 s))) ;; if specified on the input then use, else calculate
	      (type        (list-ref padded-row 8)))
	 ;; look up expected,tol,units from previous best fit test if they are all either #f or ''
	 (debug:print 4 "BEFORE: category: " category " variable: " variable " value: " value 
	 (debug:print 4 *default-log-port* "BEFORE: category: " category " variable: " variable " value: " value 
		      ", expected: " expected " tol: " tol " units: " units " status: " status " comment: " comment " type: " type)
	 
	 (if (and (or (not expected)(equal? expected ""))
		  (or (not tol)     (equal? expected ""))
		  (or (not units)   (equal? expected "")))
	     (let-values (((new-expected new-tol new-units)(tdb:get-prev-tol-for-test #f test-id category variable)))
			 (set! expected new-expected)
			 (set! tol      new-tol)
			 (set! units    new-units)))
	 
	 (debug:print 4 "AFTER:  category: " category " variable: " variable " value: " value 
	 (debug:print 4 *default-log-port* "AFTER:  category: " category " variable: " variable " value: " value 
		      ", expected: " expected " tol: " tol " units: " units " status: " status " comment: " comment)
	 ;; calculate status if NOT specified
	 (if (and (not status)(number? expected)(number? value)) ;; need expected and value to be numbers
	     (if (number? tol) ;; if tol is a number then we do the standard comparison
		 (let* ((max-val (+ expected tol))
			(min-val (- expected tol))
			(result  (and (>=  value min-val)(<= value max-val))))
		   (debug:print 4 "max-val: " max-val " min-val: " min-val " result: " result)
		   (debug:print 4 *default-log-port* "max-val: " max-val " min-val: " min-val " result: " result)
		   (set! status (if result "pass" "fail")))
		 (set! status ;; NB// need to assess each one (i.e. not return operator since need to act if not valid op.
		       (case (string->symbol tol) ;; tol should be >, <, >=, <=
			 ((>)  (if (>  value expected) "pass" "fail"))
			 ((<)  (if (<  value expected) "pass" "fail"))
			 ((>=) (if (>= value expected) "pass" "fail"))
			 ((<=) (if (<= value expected) "pass" "fail"))
			 (else (conc "ERROR: bad tol comparator " tol))))))
	 (debug:print 4 "AFTER2: category: " category " variable: " variable " value: " value 
	 (debug:print 4 *default-log-port* "AFTER2: category: " category " variable: " variable " value: " value 
		      ", expected: " expected " tol: " tol " units: " units " status: " status " comment: " comment)
	 (db:delay-if-busy dbdat)
	 (sqlite3:execute db "INSERT OR REPLACE INTO test_data (test_id,category,variable,value,expected,tol,units,comment,status,type) VALUES (?,?,?,?,?,?,?,?,?,?);"
			  test-id category variable value expected tol units (if comment comment "") status type)))
     csvlist)))

;; This routine moved from tdb.scm, tdb:read-test-data
2754
2755
2756
2757
2758
2759
2760
2761

2762
2763
2764
2765
2766
2767
2768
2941
2942
2943
2944
2945
2946
2947

2948
2949
2950
2951
2952
2953
2954
2955







-
+







		  (map (lambda (key val)
			 (conc key " like '" val "'"))
		       keynames 
		       (string-split target "/"))
		  " AND "))
	 ;; (testqry (tests:match->sqlqry testpatt))
	 (runsqry (sqlite3:prepare db (conc "SELECT id FROM runs WHERE " keystr " AND runname LIKE '" runname "';"))))
    ;; (debug:print 8 "db:test-get-paths-matching-keynames-target-new\n  runsqry=" runsqry "\n  tstsqry=" testqry)
    ;; (debug:print 8 *default-log-port* "db:test-get-paths-matching-keynames-target-new\n  runsqry=" runsqry "\n  tstsqry=" testqry)
    (sqlite3:for-each-row
     (lambda (rid)
       (set! row-ids (cons rid row-ids)))
     runsqry)
    (sqlite3:finalize! runsqry)
    row-ids))

2824
2825
2826
2827
2828
2829
2830
2831

2832
2833
2834
2835
2836
2837
2838
3011
3012
3013
3014
3015
3016
3017

3018
3019
3020
3021
3022
3023
3024
3025







-
+







	 (with-input-from-string 
	     (z3:decode-buffer
	      (base64:base64-decode
	       (string-substitute 
		(regexp "_") "=" msg #t)))
	   (lambda ()(deserialize)))
	 (begin
	   (debug:print 0 "ERROR: reception failed. Received " msg " but cannot translate it.")
	   (debug:print-error 0 *default-log-port* "reception failed. Received " msg " but cannot translate it.")
	   msg))) ;; crude reply for when things go awry
    ((zmq nmsg)(with-input-from-string msg (lambda ()(deserialize))))
    (else msg)))

(define (db:test-set-status-state dbstruct run-id test-id status state msg)
  (let ((dbdat  (db:get-db dbstruct run-id)))
    (if (member state '("LAUNCHED" "REMOTEHOSTSTART"))
2881
2882
2883
2884
2885
2886
2887
2888
2889


2890
2891
2892
2893
2894
2895
2896
3068
3069
3070
3071
3072
3073
3074


3075
3076
3077
3078
3079
3080
3081
3082
3083







-
-
+
+







       (sqlite3:for-each-row 
	(lambda (path final_logf)
	  ;; (let ((path       (sdb:qry 'getstr path-id))
	  ;;       (final_logf (sdb:qry 'getstr final_logf-id)))
	  (set! logf final_logf)
	  (set! res (list path final_logf))
	  (if (directory? path)
	      (debug:print 2 "Found path: " path)
	      (debug:print 2 "No such path: " path))) ;; )
	      (debug:print 2 *default-log-port* "Found path: " path)
	      (debug:print 2 *default-log-port* "No such path: " path))) ;; )
	db
	"SELECT rundir,final_logf FROM tests WHERE testname=? AND item_path='';"
	test-name)
       res))))

;;======================================================================
;; A G R E G A T E D   T R A N S A C T I O N   D B   W R I T E S 
3136
3137
3138
3139
3140
3141
3142
3143

3144
3145
3146
3147
3148
3149


3150
3151
3152
3153
3154
3155
3156
3323
3324
3325
3326
3327
3328
3329

3330
3331
3332
3333
3334


3335
3336
3337
3338
3339
3340
3341
3342
3343







-
+




-
-
+
+







	  (apply sqlite3:for-each-row
		 (lambda (id)
		   (set! prev-run-ids (cons id prev-run-ids)))
		 db
		 (conc "SELECT id FROM runs WHERE " qrystr " AND id != ?;") (append keyvals (list run-id)))
	  ;; collect all matching tests for the runs then
	  ;; extract the most recent test and return that.
	  (debug:print 4 "selstr: " selstr ", qrystr: " qrystr ", keyvals: " keyvals 
	  (debug:print 4 *default-log-port* "selstr: " selstr ", qrystr: " qrystr ", keyvals: " keyvals 
		       ", previous run ids found: " prev-run-ids)
	  (if (null? prev-run-ids) '()  ;; no previous runs? return null
	      (let loop ((hed (car prev-run-ids))
			 (tal (cdr prev-run-ids)))
		(let ((results (db:get-tests-for-run dbstruct hed (conc test-name "/" item-path) '() '() #f #f #f #f #f #f)))
		  (debug:print 4 "Got tests for run-id " run-id ", test-name " test-name 
		(let ((results (db:get-tests-for-run dbstruct hed (conc test-name "/" item-path) '() '() #f #f #f #f #f #f #f 'normal)))
		  (debug:print 4 *default-log-port* "Got tests for run-id " run-id ", test-name " test-name 
			       ", item-path " item-path " results: " (intersperse results "\n"))
		  ;; Keep only the youngest of any test/item combination
		  (for-each 
		   (lambda (testdat)
		     (let* ((full-testname (conc (dbr:test-testname testdat) "/" (dbr:test-item-path testdat)))
			    (stored-test   (hash-table-ref/default tests-hash full-testname #f)))
		       (if (or (not stored-test)
3169
3170
3171
3172
3173
3174
3175
3176

3177
3178
3179
3180
3181
3182
3183
3356
3357
3358
3359
3360
3361
3362

3363
3364
3365
3366
3367
3368
3369
3370







-
+







      (if dbdat
	  (let* ((dbpath (db:dbdat-get-path dbdat))
		 (db     (db:dbdat-get-db   dbdat)) ;; we'll return this so (db:delay--if-busy can be called inline
		 (dbfj   (conc dbpath "-journal")))
	    (if (handle-exceptions
		 exn
		 (begin
		   (debug:print-info 0 "WARNING: failed to test for existance of " dbfj)
		   (debug:print-info 0 *default-log-port* "WARNING: failed to test for existance of " dbfj)
		   (thread-sleep! 1)
		   (db:delay-if-busy count (- count 1)))
		 (file-exists? dbfj))
		(case count
		  ((6)
		   (thread-sleep! 0.2)
		   (db:delay-if-busy count: 5))
3193
3194
3195
3196
3197
3198
3199
3200

3201
3202
3203
3204
3205
3206
3207
3380
3381
3382
3383
3384
3385
3386

3387
3388
3389
3390
3391
3392
3393
3394







-
+







		  ((2)
		   (thread-sleep! 3.2)
		   (db:delay-if-busy count: 1))
		  ((1)
		   (thread-sleep! 6.4)
		   (db:delay-if-busy count: 0))
		  (else
		   (debug:print-info 0 "delaying db access due to high database load.")
		   (debug:print-info 0 *default-log-port* "delaying db access due to high database load.")
		   (thread-sleep! 12.8))))
	    db)
	  "bogus result from db:delay-if-busy")))

(define (db:test-get-records-for-index-file dbstruct run-id test-name)
  (let ((res '()))
    (db:with-db
3219
3220
3221
3222
3223
3224
3225
3226

3227
3228
3229
3230
3231
3232
3233
3406
3407
3408
3409
3410
3411
3412

3413
3414
3415
3416
3417
3418
3419
3420







-
+








;;======================================================================
;; Tests meta data
;;======================================================================

;; read the record given a testname
(define (db:testmeta-get-record dbstruct testname)
  (let ((res #f))
  (let ((res   #f))
    (db:with-db
     dbstruct
     #f
     #f
     (lambda (db)
       (sqlite3:for-each-row
	(lambda (id testname author owner description reviewed iterated avg_runtime avg_disk tags jobgroup)
3270
3271
3272
3273
3274
3275
3276
3277

3278
3279
3280
3281

3282
3283
3284
3285
3286
3287
3288
3289
3290

3291
3292
3293
3294
3295
3296
3297
3457
3458
3459
3460
3461
3462
3463

3464
3465
3466
3467

3468
3469
3470
3471
3472
3473
3474
3475
3476

3477
3478
3479
3480
3481
3482
3483
3484







-
+



-
+








-
+








;; A routine to map itempaths using a itemmap
;; patha and pathb must be strings or this will fail
;;
;; path-b is waiting on path-a
;;
(define (db:compare-itempaths test-b-name path-a path-b itemmaps )
  (debug:print-info 6 "ITEMMAPS: " itemmaps)
  (debug:print-info 6 *default-log-port* "ITEMMAPS: " itemmaps)
  (let* ((itemmap    (tests:lookup-itemmap itemmaps test-b-name)))
    (if itemmap
	(let ((path-b-mapped (db:multi-pattern-apply path-b itemmap)))
	  (debug:print-info 6 "ITEMMAP is " itemmap ", path: " path-b ", mapped path: " path-b-mapped)
	  (debug:print-info 6 *default-log-port* "ITEMMAP is " itemmap ", path: " path-b ", mapped path: " path-b-mapped)
	  (equal? path-a path-b-mapped))
	(equal? path-b path-a))))

;; A routine to convert test/itempath using a itemmap
;; NOTE: to process only an itempath (i.e. no prepended testname)
;;       just call db:multi-pattern-apply
;;
(define (db:convert-test-itempath path-in itemmap)
  (debug:print-info 6 "ITEMMAP is " itemmap)
  (debug:print-info 6 *default-log-port* "ITEMMAP is " itemmap)
  (let* ((path-parts  (string-split path-in "/"))
	 (test-name   (if (null? path-parts) "" (car path-parts)))
	 (item-path   (string-intersperse (if (null? path-parts) '() (cdr path-parts)) "/")))
    (conc test-name "/" 
	  (db:multi-pattern-apply item-path itemmap))))

;; patterns are:
3308
3309
3310
3311
3312
3313
3314
3315

3316
3317
3318
3319
3320
3321
3322
3495
3496
3497
3498
3499
3500
3501

3502
3503
3504
3505
3506
3507
3508
3509







-
+







		   (res item-path))
	  (let* ((parts (string-split hed))
		 (patt  (car parts))
		 (repl  (if (> (length parts) 1)(cadr parts) ""))
		 (newr  (if (and patt repl)
			    (string-substitute patt repl res)
			    (begin
			      (debug:print 0 "WARNING: itemmap has problem \"" itemmap "\", patt: " patt ", repl: " repl)
			      (debug:print 0 *default-log-port* "WARNING: itemmap has problem \"" itemmap "\", patt: " patt ", repl: " repl)
			      res))))
	    (if (null? tal)
		newr
		(loop (car tal)(cdr tal) newr)))))))

;; the new prereqs calculation, looks also at itempath if specified
;; all prereqs must be met
3443
3444
3445
3446
3447
3448
3449
3450

3451
3452
3453
3454
3455
3456
3457
3630
3631
3632
3633
3634
3635
3636

3637
3638
3639
3640
3641
3642
3643
3644







-
+







              tm.tags,r.owner,t.comment,
              author,
              tm.owner,reviewed,
              diskfree,uname,rundir,
              host,cpuload
            FROM tests AS t JOIN runs AS r ON t.run_id=r.id JOIN test_meta AS tm ON tm.testname=t.testname
            WHERE runname LIKE ? AND " keyqry ";")))
    (debug:print 2 "Using " tempdir " for constructing the ods file. keyqry: " keyqry " keystr: " keysstr " with keys: " (map cadr keypatt-alist)
    (debug:print 2 *default-log-port* "Using " tempdir " for constructing the ods file. keyqry: " keyqry " keystr: " keysstr " with keys: " (map cadr keypatt-alist)
		 "\n      mainqry: " mainqry)
    ;; "Expected Value"
    ;; "Value Found"
    ;; "Tolerance"
    (apply sqlite3:for-each-row
	   (lambda (test-id . b)
	     (set! test-ids (cons test-id test-ids))   ;; test-id is now testname
3467
3468
3469
3470
3471
3472
3473
3474

3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492

3493
3494
3495
3496
3497
3498
3499
3654
3655
3656
3657
3658
3659
3660

3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678

3679
3680
3681
3682
3683
3684
3685
3686







-
+

















-
+







								      (append res (list (vector-ref vb (+ i 2))))))))
					       (runname   (vector-ref vb 1))
					       (testname  (vector-ref vb (+  2 numkeys)))
					       (item-path (vector-ref vb (+  3 numkeys)))
					       (final-log (vector-ref vb (+  7 numkeys)))
					       (run-dir   (vector-ref vb (+ 18 numkeys)))
					       (log-fpath (conc run-dir "/"  final-log))) ;; (string-intersperse keyvals "/") "/" testname "/" item-path "/"
					  (debug:print 4 "log: " log-fpath " exists: " (file-exists? log-fpath))
					  (debug:print 4 *default-log-port* "log: " log-fpath " exists: " (file-exists? log-fpath))
					  (vector-set! vb (+ 7 numkeys) (if (file-exists? log-fpath)
									    (let ((newpath (conc pathmod "/"
												 (string-intersperse keyvals "/")
												 "/" runname "/" testname "/"
												 (if (string=? item-path "") "" (conc "/" item-path))
												 final-log)))
									      ;; for now throw away newpath and use the log-fpath conc'd with pathmod
									      (set! newpath (conc pathmod log-fpath))
									      (if windows (string-translate newpath "/" "\\") newpath))
									    (if (debug:debug-mode 1)
										(conc final-log " not-found")
										"")))
					  (vector->list vb))
					b)))))
	   db
	   mainqry
	   runspatt (map cadr keypatt-alist))
    (debug:print 2 "Found " (length test-ids) " records")
    (debug:print 2 *default-log-port* "Found " (length test-ids) " records")
    (set! results (list (cons "Runs" results)))
    ;; now, for each test, collect the test_data info and add a new sheet
    (for-each
     (lambda (test-id)
       (let ((test-data (list testdata-header))
	     (curr-test-name #f))
	 (sqlite3:for-each-row
3511
3512
3513
3514
3515
3516
3517
3518

3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3698
3699
3700
3701
3702
3703
3704

3705
3706
3707
3708
3709
3710
3711
3712





















3713







-
+







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

    (system (conc "mkdir -p " tempdir))
    ;; (pp results)
    (ods:list->ods 
     tempdir
     (if (string-match (regexp "^[/~]+.*") outputfile) ;; full path?
	 outputfile
	 (begin
	   (debug:print 0 "WARNING: path given, " outputfile " is relative, prefixing with current directory")
	   (debug:print 0 *default-log-port* "WARNING: path given, " outputfile " is relative, prefixing with current directory")
	   (conc (current-directory) "/" outputfile)))
     results)
    ;; brutal clean up
    (system "rm -rf tempdir")))

;; (db:extract-ods-file db "outputfile.ods" '(("sysname" "%")("fsname" "%")("datapath" "%")) "%")

;; This is a list of all procs that write to the db
;;
;; (define *db:all-write-procs*
;;   (list 
;;    db:set-var 
;;    db:del-var
;;    db:register-run
;;    db:set-comment-for-run
;;    db:delete-run
;;    db:update-run-event_time
;;    db:lock/unlock-run 
;;    db:delete-test-step-records
;;    db:delete-test-records
;;    db:delete-tests-for-run
;;    db:delete-old-deleted-test-records
;;    db:set-tests-state-status
;;    db:test-set-state-status-by-id
;;    db:test-set-state-status-by-run-id-testname
;;    db:testmeta-add-record
;;    db:csv->test-data
;;    ))

Modified db_records.scm from [b1470dce48] to [cd73c6e413].

184
185
186
187
188
189
190

191
192
193
194
195
196
197

198
199
200
201
202
203
204
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206







+







+







(define-inline (tdb:step-get-id              vec)    (vector-ref  vec 0))
(define-inline (tdb:step-get-test_id         vec)    (vector-ref  vec 1))
(define-inline (tdb:step-get-stepname        vec)    (vector-ref  vec 2))
(define-inline (tdb:step-get-state           vec)    (vector-ref  vec 3))
(define-inline (tdb:step-get-status          vec)    (vector-ref  vec 4))
(define-inline (tdb:step-get-event_time      vec)    (vector-ref  vec 5))
(define-inline (tdb:step-get-logfile         vec)    (vector-ref  vec 6))
(define-inline (tdb:step-get-comment         vec)    (vector-ref  vec 7))
(define-inline (tdb:step-set-id!             vec val)(vector-set! vec 0 val))
(define-inline (tdb:step-set-test_id!        vec val)(vector-set! vec 1 val))
(define-inline (tdb:step-set-stepname!       vec val)(vector-set! vec 2 val))
(define-inline (tdb:step-set-state!          vec val)(vector-set! vec 3 val))
(define-inline (tdb:step-set-status!         vec val)(vector-set! vec 4 val))
(define-inline (tdb:step-set-event_time!     vec val)(vector-set! vec 5 val))
(define-inline (tdb:step-set-logfile!        vec val)(vector-set! vec 6 val))
(define-inline (tdb:step-set-comment!        vec vak)(vector-set! vec 7 val))


;; The steps table
(define (make-db:steps-table)(make-vector 5))
(define-inline (tdb:steps-table-get-stepname   vec)    (vector-ref  vec 0))
(define-inline (tdb:steps-table-get-start      vec)    (vector-ref  vec 1))
(define-inline (tdb:steps-table-get-end        vec)    (vector-ref  vec 2))

Modified dcommon.scm from [7deac09b14] to [233a5860ad].

9
10
11
12
13
14
15

16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37


































































38
39
40
41
42
43
44







+
-
+




















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







;;  PURPOSE.
;;======================================================================

(use format)
(require-library iup)
(import (prefix iup iup:))
(use canvas-draw)
(import canvas-draw-iup)
(use regex)
(use regex defstruct)

(declare (unit dcommon))

(declare (uses megatest-version))
(declare (uses gutils))
(declare (uses db))
(declare (uses synchash))

(include "common_records.scm")
(include "db_records.scm")
(include "key_records.scm")

;; yes, this is non-ideal 
(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-get-runs          vec)    (vector-ref  vec 0))
(define (dboard:data-get-tests         vec)    (vector-ref  vec 1))
(define (dboard:data-get-runs-matrix   vec)    (vector-ref  vec 2))
(define (dboard:data-get-tests-tree    vec)    (vector-ref  vec 3))
(define (dboard:data-get-run-keys      vec)    (vector-ref  vec 4))
(define (dboard:data-get-curr-test-ids vec)    (vector-ref  vec 5))
;; (define (dboard:data-get-test-details  vec)    (vector-ref  vec 6))
(define (dboard:data-get-path-test-ids vec)    (vector-ref  vec 7))
(define (dboard:data-get-updaters      vec)    (vector-ref  vec 8))
(define (dboard:data-get-path-run-ids  vec)    (vector-ref  vec 9))
(define (dboard:data-get-curr-run-id   vec)    (vector-ref  vec 10))
(define (dboard:data-get-runs-tree     vec)    (vector-ref  vec 11))
;; For test-patts convert #f to ""
(define (dboard:data-get-test-patts    vec)    
  (let ((val (vector-ref  vec 12)))(if val val "")))
(define (dboard:data-get-states        vec)    (vector-ref vec 13))
(define (dboard:data-get-statuses      vec)    (vector-ref vec 14))
(define (dboard:data-get-logs-textbox  vec val)(vector-ref vec 15))
(define (dboard:data-get-command       vec)    (vector-ref vec 16))
(define (dboard:data-get-command-tb    vec)    (vector-ref vec 17))
(define (dboard:data-get-target        vec)    (vector-ref vec 18))
(define (dboard:data-get-target-string vec)
  (let ((targ (dboard:data-get-target vec)))
    (if (list? targ)(string-intersperse targ "/") "no-target-specified")))
(define (dboard:data-get-run-name      vec)    (vector-ref vec 19))
(define (dboard:data-get-runs-listbox  vec)    (vector-ref vec 20))

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

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

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

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

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

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

(define (dcommon:write-dotfile fname dat)
  (with-output-to-file fname
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
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







+
+
+
+
+
+
+
+
+
+
+





+
+





+





-
+







;; P R O C E S S   R U N S
;;======================================================================

;; MOVE THIS INTO *data*
(define *cachedata* (make-hash-table))
(hash-table-set! *cachedata* "runid-to-col"    (make-hash-table))
(hash-table-set! *cachedata* "testname-to-row" (make-hash-table))

;; modify a cell if the data is changed, return #t or-ed with previous if modified, #f elsewise
;;
(define (dcommon:modifiy-if-different mtrx cell-name new-val prev-changed)
  (let ((curr-val (iup:attribute mtrx cell-name)))
    (if (not (equal? curr-val new-val)) 
	(begin
	  (iup:attribute-set! mtrx cell-name col-name)
	  #t) ;; need a re-draw
	prev-changed)))


;; TO-DO
;;  1. Make "data" hash-table hierarchial store of all displayed data
;;  2. Update synchash to understand "get-runs", "get-tests" etc.
;;  3. Add extraction of filters to synchash calls
;;
;;    NOTE: Used in newdashboard
;;
;; Mode is 'full or 'incremental for full refresh or incremental refresh
(define (dcommon:run-update keys data runname keypatts testpatt states statuses mode window-id)
  (let* (;; count and offset => #f so not used
	 ;; the synchash calls modify the "data" hash
	 (changed         #f)
	 (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-get-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
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
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







-
-
+
+
+
















-
-
+
+
+
-


-
+







-
+







				      (time-a   (db:get-value-by-header record-a header "event_time"))
				      (time-b   (db:get-value-by-header record-b header "event_time")))
				 (> time-a time-b)))
			     ))
	 (runid-to-col    (hash-table-ref *cachedata* "runid-to-col"))
	 (testname-to-row (hash-table-ref *cachedata* "testname-to-row")) 
	 (colnum       1)
	 (rownum       0)) ;; rownum = 0 is the header
;; (debug:print 0 "test-ids " test-ids ", tests-detail-changes " tests-detail-changes)
	 (rownum       0)
	 (cellname (conc rownum ":" colnum))) ;; rownum = 0 is the header
;; (debug:print 0 *default-log-port* "test-ids " test-ids ", tests-detail-changes " tests-detail-changes)
    
	 ;; tests related stuff
	 ;; (all-testnames (delete-duplicates (map dbr:test-testname test-changes))))

    ;; Given a run-id and testname/item_path calculate a cell R:C

    ;; NOTE: Also build the test tree browser and look up table
    ;;
    ;; Each run is unique on its keys and runname or run-id, store in hash on colnum
    (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-get-run-keys *data*) run-id run-path)
		  (iup:attribute-set! (dboard:data-get-runs-matrix *data*)
		  (hash-table-set! (dboard:tabdat-run-keys data) run-id run-path)
		  ;; modify cell - but only if changed
		  (set! changed (dcommon:modifiy-if-different (dboard:tabdat-runs-matrix data) cellname col-name changed))
				      (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-get-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-get-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 (dbr:mintest-run_id (cadr testrec))))
							       new-test-dat))
					     (lambda (a b)
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
295
296
297
298
299
300
301
302
303
304
305
306
307





308
309
310
311
312


























313
314
315
316
317
318
319
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318







-
+

-
+




-
-
-
+
+
+
+
+
+
+
+
+
+







+
+
+
+
+
-
-
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+


-
-
-
+
+
+














-
-
-
-
-
+
+
+
+
+




-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				     (itempath  (dbr:mintest-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-get-tests-tree *data*)))
				     (tb         (dboard:tabdat-tests-tree data)))
				(print "INFONOTE: run-path: " run-path)
				(tree:add-node (dboard:data-get-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 "node-num: " node-num ", color: " color)
				  (iup:attribute-set! tb (conc "COLOR" node-num) color))
				(hash-table-set! (dboard:data-get-path-test-ids *data*) test-path test-id)
				  (debug:print 0 *default-log-port* "node-num: " node-num ", color: " color)

				  (set! changed (dcommon:modifiy-if-different 
						 tb
						 (conc "COLOR" node-num)
						 color changed))

				  ;; (iup:attribute-set! tb (conc "COLOR" node-num) color)
				  )
				(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
				      (set! changed (dcommon:modifiy-if-different 
						     (dboard:tabdat-runs-matrix data)
						     (conc rownum ":" 0)
						     dispname
						     changed))
				      (iup:attribute-set! (dboard:data-get-runs-matrix *data*)
							  (conc rownum ":" 0) dispname)
				      ;; (iup:attribute-set! (dboard:tabdat-runs-matrix data)
				      ;;   		  (conc rownum ":" 0) dispname)
				      ))
				;; set the cell text and color
				;; (debug:print 2 "rownum:colnum=" rownum ":" colnum ", state=" status)
				(iup:attribute-set! (dboard:data-get-runs-matrix *data*)
						    (conc rownum ":" colnum)
						    (if (member state '("ARCHIVED" "COMPLETED"))
							status
							state))
				(iup:attribute-set! (dboard:data-get-runs-matrix *data*)
						    (conc "BGCOLOR" rownum ":" colnum)
						    (car (gutils:get-color-for-state-status state status)))
				;; (debug:print 2 *default-log-port* "rownum:colnum=" rownum ":" colnum ", state=" status)
				(set! changed (dcommon:modifiy-if-different 
						     (dboard:tabdat-runs-matrix data)
						     (conc rownum ":" colnum)
						     (if (member state '("ARCHIVED" "COMPLETED"))
							 status
							 state)
						     changed))
				;; (iup:attribute-set! (dboard:tabdat-runs-matrix data)
				;; 		    (conc rownum ":" colnum)
				;; 		    (if (member state '("ARCHIVED" "COMPLETED"))
				;; 			status
				;; 			state))
				(set! changed (dcommon:modifiy-if-different 
					       (dboard:tabdat-runs-matrix data)
					       (conc "BGCOLOR" rownum ":" colnum)
					       (car (gutils:get-color-for-state-status state status))
					       changed))
				;; (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-get-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-get-runs-matrix *data*) "REDRAW" "ALL")
    ;; (debug:print 2 "run-changes: " run-changes)
    ;; (debug:print 2 "test-changes: " test-changes)
    (if changed (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
;;======================================================================

;; Produce a list of lists ready for common:sparse-list-generate-index
;;
(define (dcommon:minimize-test-data tests-dat)
  (if (null? tests-dat) 
      '()
      (let loop ((hed (car tests-dat))
		 (tal (cdr tests-dat))
		 (res '()))
	(let* ((test-id    (vector-ref hed 0)) ;; look at the tests-dat spec for locations
	       (test-name  (vector-ref hed 1))
	       (item-path  (vector-ref hed 2))
	       (state      (vector-ref hed 3))
	       (status     (vector-ref hed 4))
	(let* ((test-id    (db:test-get-id hed)) ;; look at the tests-dat spec for locations
	       (test-name  (db:test-get-testname hed))
	       (item-path  (db:test-get-item-path hed))
	       (state      (db:test-get-state hed))
	       (status     (db:test-get-status hed))
	       (newitem    (list test-name item-path (list test-id state status))))
	  (if (null? tal)
	      (reverse (cons newitem res))
	      (loop (car tal)(cdr tal)(cons newitem res)))))))
	  

(define (dcommon:examine-xterm run-id test-id)
  (let* ((testdat (rmt:get-test-info-by-id run-id test-id)))
    (if (not testdat)
	(begin
	  (debug:print 2 "ERROR: No test data found for test " test-id ", exiting")
	  (exit 1))
        (let*
            ((rundir        (if testdat 
				(db:test-get-rundir testdat)
				  logfile))
             (testfullname  (if testdat (db:test-get-fullname testdat) "Gathering data ..."))
             (xterm      (lambda ()
                           (if (directory-exists? rundir)
                               (let* ((shell (if (get-environment-variable "SHELL") 
                                                (conc "-e " (get-environment-variable "SHELL"))
                                                ""))
                                      (command (conc "cd " rundir 
                                                     ";mt_xterm -T \"" (string-translate testfullname "()" "  ") "\" " shell "&")))
                                 (print "Command =" command)
                                 (common:without-vars
                                  command
                                  "MT_.*"))
                               (message-window  (conc "Directory " rundir " not found"))))))
          (xterm)
          (print "Adding xterm code")))))

;;======================================================================
;; D A T A   T A B L E S
;;======================================================================

;; Table of keys
(define (dcommon:keys-matrix rawconfig)
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363







-
+







	 (key-vals        (configf:section-vars rawconfig sectionname))
	 (section-matrix  (iup:matrix
			   #:alignment1 "ALEFT"
			   #:expand "YES" ;; "HORIZONTAL"
			   #:numcol 1
			   #:numlin (length key-vals)
			   #:numcol-visible 1
			   #:numlin-visible (length key-vals)
			   #:numlin-visible (min 10 (length key-vals))
			   #:scrollbar "YES")))
    (iup:attribute-set! section-matrix "0:0" varcolname)
    (iup:attribute-set! section-matrix "0:1" valcolname)
    (iup:attribute-set! section-matrix "WIDTH1" "200")
    ;; fill in keys
    (for-each 
     (lambda (var)
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420


















421
422
423
424
425
426
427
428
429
430
431










432
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
459

















460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513






































514
515
516
517
518
519
520


521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549




























550
551
552
553
554
555
556
393
394
395
396
397
398
399

400
401
402

















403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421










422
423
424
425
426
427
428
429
430
431
432










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
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477






































478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521

522
523
524




























525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559







-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+










+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    ;; (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 commondat tabdat #!key (tab-num #f))
  (let* ((stats-matrix (iup:matrix expand: "YES"))
	 (changed      #f)
	 (updater      (lambda ()
			 (let* ((run-stats    (db:get-run-stats dbstruct))
				(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 (- *num-tests* 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)
			   (iup:attribute-set! stats-matrix "NUMLIN_VISIBLE" (if (> max-row max-visible) max-visible max-row))
	 (stats-updater (lambda ()
			 (if (dashboard:database-changed? commondat tabdat)
			     (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 (- (dboard:tabdat-num-tests tabdat) 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)
			       (iup:attribute-set! stats-matrix "NUMLIN_VISIBLE" (if (> max-row max-visible) max-visible max-row))

			   ;; Row labels
			   (for-each (lambda (ind)
				       (let* ((name (car ind))
					      (num  (cadr ind))
					      (key  (conc num ":0")))
					 (if (not (equal? (iup:attribute stats-matrix key) name))
					     (begin
					       (set! changed #t)
					       (iup:attribute-set! stats-matrix key name)))))
				     row-indices)
			       ;; Row labels
			       (for-each (lambda (ind)
					   (let* ((name (car ind))
						  (num  (cadr ind))
						  (key  (conc num ":0")))
					     (if (not (equal? (iup:attribute stats-matrix key) name))
						 (begin
						   (set! changed #t)
						   (iup:attribute-set! stats-matrix key name)))))
					 row-indices)

			   ;; Col labels
			   (for-each (lambda (ind)
				       (let* ((name (car ind))
					      (num  (cadr ind))
					      (key  (conc "0:" num)))
					 (if (not (equal? (iup:attribute stats-matrix key) name))
					     (begin
					       (set! changed #t)
					       (iup:attribute-set! stats-matrix key name)))))
				     col-indices)
			       ;; Col labels
			       (for-each (lambda (ind)
					   (let* ((name (car ind))
						  (num  (cadr ind))
						  (key  (conc "0:" num)))
					     (if (not (equal? (iup:attribute stats-matrix key) name))
						 (begin
						   (set! changed #t)
						   (iup:attribute-set! stats-matrix key name)))))
					 col-indices)

			   ;; Cell contents
			   (for-each (lambda (entry)
				       (let* ((row-name (car entry))
					      (col-name (cadr entry))
					      (value    (caddr entry))
					      (row-num  (cadr (assoc row-name row-indices)))
					      (col-num  (cadr (assoc col-name col-indices)))
					      (key      (conc row-num ":" col-num)))
					 (if (not (equal? (iup:attribute stats-matrix key) value))
					     (begin
					       (set! changed #t)
					       (iup:attribute-set! stats-matrix key value)))))
				     run-stats)
			   (if changed (iup:attribute-set! stats-matrix "REDRAW" "ALL"))))))
    (updater)
    (set! dashboard:update-summary-tab updater)
			       ;; Cell contents
			       (for-each (lambda (entry)
					   (let* ((row-name (car entry))
						  (col-name (cadr entry))
						  (value    (caddr entry))
						  (row-num  (cadr (assoc row-name row-indices)))
						  (col-num  (cadr (assoc col-name col-indices)))
						  (key      (conc row-num ":" col-num)))
					     (if (not (equal? (iup:attribute stats-matrix key) value))
						 (begin
						   (set! changed #t)
						   (iup:attribute-set! stats-matrix key value)))))
					 run-stats)
			       (if changed (iup:attribute-set! stats-matrix "REDRAW" "ALL")))))))
    (stats-updater)
    (dboard:commondat-add-updater commondat stats-updater tab-num: tab-num)
    ;; (set! dashboard:update-summary-tab updater)
    (iup:attribute-set! stats-matrix "WIDTHDEF" "40")
    (iup:vbox
     ;; (iup:label "Run statistics"  #:expand "HORIZONTAL")
     stats-matrix)))

(define (dcommon:servers-table)
(define (dcommon:servers-table commondat tabdat)
  (let* ((tdbdat         (tasks:open-db))
	 (colnum         0)
	 (rownum         0)
	 (servers-matrix (iup:matrix #:expand "YES"
				     #:numcol 7
				     #:numcol-visible 7
				     #:numlin-visible 5
				     ))
	 (colnames       (list "Id" "MTver" "Pid" "Host" "Interface:OutPort" "RunTime" "State" "RunId"))
	 (updater        (lambda ()
			   (if (dashboard:monitor-changed? commondat tabdat)
			   (let ((servers (tasks:get-all-servers (db:delay-if-busy tdbdat))))
			     (iup:attribute-set! servers-matrix "NUMLIN" (length servers))
			     ;; (set! colnum 0)
			     ;; (for-each (lambda (colname)
			     ;;    	 ;; (print "colnum: " colnum " colname: " colname)
			     ;;    	 (iup:attribute-set! servers-matrix (conc "0:" colnum) colname)
			     ;;    	 (set! colnum (+ 1 colnum)))
			     ;;           colnames)
			     (set! rownum 1)
			     (for-each 
			      (lambda (server)
				(set! colnum 0)
				(let* ((vals (list (vector-ref server 0) ;; Id
						   (vector-ref server 9) ;; MT-Ver
						   (vector-ref server 1) ;; Pid
						   (vector-ref server 2) ;; Hostname
						   (conc (vector-ref server 3) ":" (vector-ref server 4)) ;; IP:Port
						   (seconds->hr-min-sec (- (current-seconds)(vector-ref server 6)))
						   ;; (vector-ref server 5) ;; Pubport
						   ;; (vector-ref server 10) ;; Last beat
						   ;; (vector-ref server 6) ;; Start time
						   ;; (vector-ref server 7) ;; Priority
						   ;; (vector-ref server 8) ;; State
						   (vector-ref server 8) ;; State
						   (vector-ref server 12)  ;; RunId
						   )))
				  (for-each (lambda (val)
					      (let* ((row-col (conc rownum ":" colnum))
						     (curr-val (iup:attribute servers-matrix row-col)))
						(if (not (equal? (conc val) curr-val))
						    (begin
						      (iup:attribute-set! servers-matrix row-col val)
						      (iup:attribute-set! servers-matrix "FITTOTEXT" (conc "C" colnum))))
						(set! colnum (+ 1 colnum))))
					    vals)
				  (set! rownum (+ rownum 1)))
				 (iup:attribute-set! servers-matrix "REDRAW" "ALL"))
			      servers)))))
			       (let ((servers (tasks:get-all-servers (db:delay-if-busy tdbdat))))
				 (iup:attribute-set! servers-matrix "NUMLIN" (length servers))
				 ;; (set! colnum 0)
				 ;; (for-each (lambda (colname)
				 ;;    	 ;; (print "colnum: " colnum " colname: " colname)
				 ;;    	 (iup:attribute-set! servers-matrix (conc "0:" colnum) colname)
				 ;;    	 (set! colnum (+ 1 colnum)))
				 ;;           colnames)
				 (set! rownum 1)
				 (for-each 
				  (lambda (server)
				    (set! colnum 0)
				    (let* ((vals (list (vector-ref server 0) ;; Id
						       (vector-ref server 9) ;; MT-Ver
						       (vector-ref server 1) ;; Pid
						       (vector-ref server 2) ;; Hostname
						       (conc (vector-ref server 3) ":" (vector-ref server 4)) ;; IP:Port
						       (seconds->hr-min-sec (- (current-seconds)(vector-ref server 6)))
						       ;; (vector-ref server 5) ;; Pubport
						       ;; (vector-ref server 10) ;; Last beat
						       ;; (vector-ref server 6) ;; Start time
						       ;; (vector-ref server 7) ;; Priority
						       ;; (vector-ref server 8) ;; State
						       (vector-ref server 8) ;; State
						       (vector-ref server 12)  ;; RunId
						       )))
				      (for-each (lambda (val)
						  (let* ((row-col (conc rownum ":" colnum))
							 (curr-val (iup:attribute servers-matrix row-col)))
						    (if (not (equal? (conc val) curr-val))
							(begin
							  (iup:attribute-set! servers-matrix row-col val)
							  (iup:attribute-set! servers-matrix "FITTOTEXT" (conc "C" colnum))))
						    (set! colnum (+ 1 colnum))))
						vals)
				      (set! rownum (+ rownum 1)))
				    (iup:attribute-set! servers-matrix "REDRAW" "ALL"))
				  servers))))))
    (set! colnum 0)
    (for-each (lambda (colname)
		(iup:attribute-set! servers-matrix (conc "0:" colnum) colname)
		(iup:attribute-set! servers-matrix "FITTOTEXT" (conc "C" colnum))
		(set! colnum (+ colnum 1)))
	      colnames)
    (set! dashboard:update-servers-table updater) 
    ;; (set! dashboard:update-servers-table updater) 
    (dboard:commondat-add-updater commondat updater)
    ;; (iup:attribute-set! servers-matrix "WIDTHDEF" "40")
   ;;  (iup:hbox
   ;;   (iup:vbox
   ;;    (iup:button "Start"
   ;;      	  ;; #:size "50x"
   ;;      	  #:expand "YES"
   ;;      	  #:action (lambda (obj)
   ;;      		     (let ((cmd (conc ;; "xterm -geometry 180x20 -e \""
   ;;      				      "megatest -server - &")))
   ;;      				      ;; ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
   ;;      		       (system cmd))))
   ;;    (iup:button "Stop"
   ;;      	  #:expand "YES"
   ;;      	  ;; #:size "50x"
   ;;      	  #:action (lambda (obj)
   ;;      		     (let ((cmd (conc ;; "xterm -geometry 180x20 -e \""
   ;;      				      "megatest -stop-server 0 &")))
   ;;      				      ;; ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
   ;;      		       (system cmd))))
   ;;    (iup:button "Restart"
   ;;      	  #:expand "YES"
   ;;      	  ;; #:size "50x"
   ;;      	  #:action (lambda (obj)
   ;;      		     (let ((cmd (conc ;; "xterm -geometry 180x20 -e \""
   ;;      				      "megatest -stop-server 0;megatest -server - &")))
   ;;      				      ;; ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
   ;;      		       (system cmd)))))
   ;;    servers-matrix
   ;;   )))
    ;;  (iup:hbox
    ;;   (iup:vbox
    ;;    (iup:button "Start"
    ;;      	  ;; #:size "50x"
    ;;      	  #:expand "YES"
    ;;      	  #:action (lambda (obj)
    ;;      		     (let ((cmd (conc ;; "xterm -geometry 180x20 -e \""
    ;;      				      "megatest -server - &")))
    ;;      				      ;; ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
    ;;      		       (system cmd))))
    ;;    (iup:button "Stop"
    ;;      	  #:expand "YES"
    ;;      	  ;; #:size "50x"
    ;;      	  #:action (lambda (obj)
    ;;      		     (let ((cmd (conc ;; "xterm -geometry 180x20 -e \""
    ;;      				      "megatest -stop-server 0 &")))
    ;;      				      ;; ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
    ;;      		       (system cmd))))
    ;;    (iup:button "Restart"
    ;;      	  #:expand "YES"
    ;;      	  ;; #:size "50x"
    ;;      	  #:action (lambda (obj)
    ;;      		     (let ((cmd (conc ;; "xterm -geometry 180x20 -e \""
    ;;      				      "megatest -stop-server 0;megatest -server - &")))
    ;;      				      ;; ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
    ;;      		       (system cmd)))))
    ;;    servers-matrix
    ;;   )))
    servers-matrix
    ))

;; The main menu
(define (dcommon:main-menu)
  (iup:menu ;; a menu is a special attribute to a dialog (think Gnome putting the menu at screen top)
   (iup:menu-item "Files" (iup:menu   ;; Note that you can use either #:action or action: for options
577
578
579
580
581
582
583
584
585
586
587
588
589






590
591
592
593
594
595
596
580
581
582
583
584
585
586






587
588
589
590
591
592
593
594
595
596
597
598
599







-
-
-
-
-
-
+
+
+
+
+
+







			   ;;  )					     
			   ))))

;;======================================================================
;; CANVAS STUFF FOR TESTS
;;======================================================================

(define (dcommon:draw-test cnv scalef x y w h name selected)
  (let* ((llx (* scalef x))
	 (lly (* scalef y))
	 (urx (* scalef (+ x w)))
	 (ury (* scalef (+ y h))))
    (canvas-text! cnv (+ llx 5)(+ lly 5) name) ;; (conc testname " (" xtorig "," ytorig ")"))
(define (dcommon:draw-test cnv xoffset yoffset scalef x y w h name selected)
  (let* ((llx (dcommon:x->canvas x scalef xoffset))
	 (lly (dcommon:y->canvas y scalef yoffset))
	 (urx (dcommon:x->canvas (+ x w) scalef xoffset))
	 (ury (dcommon:y->canvas (+ y h) scalef yoffset)))
    (canvas-text! cnv (+ llx 5)(+ lly 5) name)
    (canvas-rectangle! cnv llx urx lly ury)
    (if selected (canvas-box! cnv llx (+ llx 5) lly (+ lly 5)))))

(define (dcommon:draw-arrow cnv test-box-center waiton-center)
  (let* ((test-box-center-x (vector-ref test-box-center 0))
	 (test-box-center-y (vector-ref test-box-center 1))
	 (waiton-center-x   (vector-ref waiton-center   0))
628
629
630
631
632
633
634
635
636
637



638
639
640
641
642
643
644

645
646
647
648
649
650
651
652





653

654
655



656
657


658
659
660
661
662
663
664
665
666
667
668
669
670
671
672


673
674








































675
676
677
678
679
680
681
682





683
684
685
686
687
688
689
690
















691
692
693
694
695
696
697


698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728









































729
730










731
732
733
734



735
736
737

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
631
632
633
634
635
636
637



638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654
655
656
657
658
659
660

661
662

663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681


682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728





729
730
731
732
733








734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758































759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
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
816
817

818

819
820
821




822
823
824
825
826
827
828







-
-
-
+
+
+






-
+








+
+
+
+
+
-
+

-
+
+
+

-
+
+













-
-
+
+


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



-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+


-
+
-



-
-
-
-







		new-waiton-x
		new-waiton-y
		)
  (canvas-mark! cnv new-waiton-x new-waiton-y)))

(define (dcommon:get-box-center box)
  (let* ((llx  (list-ref box 0))
	 (lly  (list-ref box 4))
	 (boxw (list-ref box 5))
	 (boxh (list-ref box 6)))
	 (lly  (list-ref box 1))
	 (boxw (list-ref box 4))
	 (boxh (list-ref box 5)))
    (vector (+ llx (/ boxw 2))
	    (+ lly (/ boxh 2)))))

(define-inline (num->int num)
  (inexact->exact (round num)))

(define (dcommon:draw-edges cnv scalef edges)
(define (dcommon:draw-edges cnv xoffset yoffset scalef edges)
  (for-each
   (lambda (e)
     (let loop ((x1 (car e))
		(y1 (cadr e))
		(x2 #f)
		(y2 #f)
		(tal (cddr e)))
       (if (and x1 y1 x2 y2)
	   (canvas-line! 
	    cnv 
	    (num->int (dcommon:x->canvas x1 scalef xoffset))
	    (num->int (dcommon:y->canvas y1 scalef yoffset))
	    (num->int (dcommon:x->canvas x2 scalef xoffset))
	   (canvas-line! cnv x1 y1 x2 y2)) ;; (num->int x1)(num->int y1)(num->int x2)(num->int y2)))
	    (num->int (dcommon:y->canvas y2 scalef yoffset)))) ;; (num->int x1)(num->int y1)(num->int x2)(num->int y2)))
       (if (< (length tal) 2)
	   (canvas-mark! cnv x1 y1) ;; (num->int x1)(num->int y1))
	   (canvas-mark! cnv
			 (num->int (dcommon:x->canvas x1 scalef xoffset))
			 (num->int (dcommon:y->canvas y1 scalef yoffset))) ;; (num->int x1)(num->int y1))
	   (loop (car tal)(cadr tal) x1 y1 (cddr tal)))))
   (map (lambda (e)(map (lambda (x)(num->int (* x scalef))) e)) edges)))
   ;; (map (lambda (e)(map (lambda (x)(num->int (* x scalef))) e)) edges)))
   edges))


(define (dcommon:draw-arrows cnv testname tests-hash test-records)
  (let* ((test-box-info   (hash-table-ref tests-hash testname))
	 (test-box-center (dcommon:get-box-center test-box-info))
	 (test-record     (hash-table-ref test-records testname))
	 (waitons         (vector-ref test-record 2)))
    (for-each
     (lambda (waiton)
       (let* ((waiton-box-info (hash-table-ref/default tests-hash waiton #f))
	      (waiton-center   (dcommon:get-box-center (or waiton-box-info test-box-info))))
	 (dcommon:draw-arrow cnv test-box-center waiton-center)))
     waitons)
    ;; (debug:print 0 "test-box-info=" test-box-info)
    ;; (debug:print 0 "test-record=" test-record)
    ;; (debug:print 0 *default-log-port* "test-box-info=" test-box-info)
    ;; (debug:print 0 *default-log-port* "test-record=" test-record)
    ))

(define (dcommon:estimate-scale sizex sizey originx originy nodes)
  ;; (print "sizex: " sizex " sizey: " sizey " originx: " originx " originy: " originy " nodes: " nodes)
  (let* ((maxx 1)
	 (maxy 1))
    (for-each
     (lambda (node)
       (if (equal? (car node) "node")
	   (let ((x (string->number (list-ref node 2)))
		 (y (string->number (list-ref node 3))))
	     (if (and x (> x maxx))(set! maxx x))
	     (if (and y (> y maxy))(set! maxy y)))))
     nodes)
    (let ((scalex (/ sizex maxx))
	  (scaley (/ sizey maxy)))
      ;; (print "maxx: " maxx " maxy: " maxy " scalex: " scalex " scaley: " scaley)
      (min scalex scaley))))

(define (dcommon:get-xoffset tests-draw-state sizex-in xadj-in)
  (let ((xadj  (or xadj-in  (hash-table-ref/default tests-draw-state 'xadj 0)))
	(sizex (or sizex-in (hash-table-ref/default tests-draw-state 'sizex 500))))
    (hash-table-set! tests-draw-state 'xadj xadj) ;; for use in de-scaling when handling mouse clicks
    (hash-table-set! tests-draw-state 'sizex sizex)
    (* (/ sizex 2) (- 0.5 xadj))))

(define (dcommon:get-yoffset tests-draw-state sizey-in yadj-in)
  (let ((yadj  (or yadj-in  (hash-table-ref/default tests-draw-state 'yadj 0)))
	(sizey (or sizey-in (hash-table-ref/default tests-draw-state 'sizey 500))))
    (hash-table-set! tests-draw-state 'yadj yadj) ;; for use in de-scaling when handling mouse clicks
    (hash-table-set! tests-draw-state 'sizey sizey)
    (* (/ sizey 2) (- yadj 0.5))))

(define (dcommon:x->canvas x scalef xoffset)
  (+ xoffset (* x scalef)))

(define (dcommon:y->canvas y scalef yoffset)
  (+ yoffset (* y scalef)))

;; sizex, sizey     - canvas size
;; originx, originy - canvas origin
;;
(define (dcommon:initial-draw-tests cnv xadj yadj sizex sizey sizexmm sizeymm originx originy tests-draw-state sorted-testnames test-records)
  (let* ((dot-data ;; (map cdr (filter
		   ;; 	  (lambda (x)(equal? "node" (car x)))
	  (map string-split (tests:lazy-dot test-records "plain"))) ;; (tests:easy-dot test-records "plain")))
	 (scalef (hash-table-ref   tests-draw-state 'scalef))
	 (dotscale (hash-table-ref tests-draw-state 'dotscale))
	 (test-browse-xoffset (hash-table-ref tests-draw-state 'test-browse-xoffset))
	 (test-browse-yoffset (hash-table-ref tests-draw-state 'test-browse-yoffset))
	  (map string-split (tests:lazy-dot test-records "plain" sizex sizey))) ;; (tests:easy-dot test-records "plain")))
	 (xoffset	 (dcommon:get-xoffset tests-draw-state sizex xadj))
	 (yoffset        (dcommon:get-yoffset tests-draw-state sizey yadj))
	 (no-dot         (configf:lookup *configdat* "setup" "nodot"))
	 (boxh           15)
	 (xtorig (+ test-browse-xoffset (* (/ sizex 2) 1 (- 0.5 xadj)))) ;;  (- xadj 1))))
	 (ytorig (+ test-browse-yoffset (* (/ sizey 2) 1 (- yadj 0.5))))
	 (boxw   10)
	 (tests-hash     (hash-table-ref tests-draw-state 'tests-info))
	 (selected-tests (hash-table-ref tests-draw-state 'selected-tests )))
    ;; (print "dot-data=" dot-data)
    (hash-table-set! tests-draw-state 'xtorig xtorig)
    (hash-table-set! tests-draw-state 'ytorig ytorig)
	 (boxw           10)
	 (margin         5)
	 (tests-info     (hash-table-ref tests-draw-state 'tests-info))
	 (selected-tests (hash-table-ref tests-draw-state 'selected-tests ))
	 (scalef         (if no-dot
			     1
			     (dcommon:estimate-scale sizex sizey originx originy dot-data)))
	 (sorted-testnames (if no-dot
			       (sort sorted-testnames string>=?)
			       sorted-testnames))
	 (curr-x         0)  ;; NB// NOT screen units
	 (curr-y         (/ (- sizey boxh margin) scalef)) ;; used when no-dot
	 (scaled-sizex   (/ sizex scalef)))

    (hash-table-set! tests-draw-state 'scalef scalef)
    
    (let ((longest-str   (if (null? sorted-testnames) "         " (car (sort sorted-testnames (lambda (a b)(>= (string-length a)(string-length b))))))))
      (let-values (((x-max y-max) (canvas-text-size cnv longest-str)))
	(if (> x-max boxw)(set! boxw (+ 10 x-max)))))
    ;; (print "sizex: " sizex " sizey: " sizey " font: " (canvas-font cnv) " originx: " originx " originy: " originy " xtorig: " xtorig " ytorig: " ytorig " xadj: " xadj " yadj: " yadj)
    (if (not (null? sorted-testnames))
	(let loop ((hed (car (reverse sorted-testnames)))
		   (tal (cdr (reverse sorted-testnames))))
	  (let* ((nodedat (if no-dot
			      #f
	  (let* ((nodedat (let ((tmpres (filter (lambda (x)
						  (if (and (not (null? x))
							   (equal? (car x) "node"))
						      (equal? hed (cadr x))
						      #f))
						dot-data)))
			    (if (null? tmpres)
				;;           llx  lly boxw boxh
				(list "0" "1" "1" (conc (length tal)) "2" "0.5") ;; return some junk
				(car tmpres))))
		 (edgedat (let ((edges (filter (lambda (x)  ;; filter for edge
						 (if (and (not (null? x))
							  (equal? (car x) "edge"))
						     (equal? hed (cadr x))
						     #f))
					       dot-data)))
			    (map (lambda (inlst)
				   (dcommon:process-polyline 
				    (map (lambda (instr)
					   (* dotscale (string->number instr))) ;; convert to number and scale
					 (let ((il (cddddr inlst)))
					   (take il (- (length il) 2))))
				    (lambda (x y)
				      (list (+ x xtorig)
					    (+ y ytorig)))
				    #f #f)) ;; process polyline
				 edges)))
		 (llx  (* (string->number (list-ref nodedat 2)) dotscale))
		 (lly  (* (string->number (list-ref nodedat 3)) dotscale))
		 (boxw (* (string->number (list-ref nodedat 4)) dotscale))
		 (boxh (* (string->number (list-ref nodedat 5)) dotscale))
			      (let ((tmpres (filter (lambda (x)
						      (if (and (not (null? x))
							       (equal? (car x) "node"))
							  (equal? hed (cadr x))
							  #f))
						    dot-data)))
				(if (null? tmpres)
				    ;;           llx  lly boxw boxh
				    (list "0" "1" "1" (conc (length tal)) "2" "0.5") ;; return some placeholder junk if no dat found
				    (car tmpres)))))
		 (edgedat (if no-dot
			      '()
			      (let ((edges (filter (lambda (x)  ;; filter for edge
						     (if (and (not (null? x))
							      (equal? (car x) "edge"))
							 (equal? hed (cadr x))
							 #f))
						   dot-data)))
				(map (lambda (inlst)
				       (dcommon:process-polyline 
					(map (lambda (instr)
					       (string->number instr)) ;; convert to number and scale
					     (let ((il (cddddr inlst)))
					       (take il (- (length il) 2))))
					(lambda (x y)
					  (list (+ x 0)   ;; xtorig)
						(+ y 0))) ;; ytorig)))
					#f #f)) ;; process polyline
				     edges))))
		 (llx  (if no-dot
			   curr-x
			   (string->number (list-ref nodedat 2))))
		 (lly  (if no-dot
			   curr-y
			   (string->number (list-ref nodedat 3))))
		 (boxw (if no-dot
			   boxw
			   (string->number (list-ref nodedat 4))))
		 (boxh (if no-dot
			   boxh
			   (string->number (list-ref nodedat 5))))
		 (urx  (+ llx boxw))
		 (ury  (+ lly boxh)))

	    ;; if we are in no-dot mode then increment curr-x and curr-y as needed
	    (if no-dot
		(begin
		  (cond 
		   ((< curr-x (- scaled-sizex boxw boxw margin))
		    (set! curr-x (+ curr-x boxw margin)))
		   ((> curr-x (- scaled-sizex boxw boxw margin))
		    (set! curr-x 0)
		    (set! curr-y (- curr-y (+ boxh margin)))))))
					; (print "hed " hed " llx " llx " lly " lly " urx " urx " ury " ury)
	    (dcommon:draw-test cnv scalef llx lly boxw boxh hed (hash-table-ref/default selected-tests hed #f))
	    ;; (dcommon:draw-arrows cnv testname tests-hash test-records))
	    (dcommon:draw-edges cnv scalef edgedat)
	    (dcommon:draw-test cnv xoffset yoffset scalef llx lly boxw boxh hed (hash-table-ref/default selected-tests hed #f))
	    ;; (dcommon:draw-arrows cnv testname tests-info test-records))
	    (dcommon:draw-edges cnv xoffset yoffset scalef edgedat)
	    
	    ;; data used by mouse click calc. keep the wacky order for now.
	    (hash-table-set! tests-hash hed  (list llx urx (- sizey ury)(- sizey lly) lly boxw boxh edgedat)) 
	    (hash-table-set! tests-info hed  (list llx lly urx ury boxw boxh edgedat)) 
	    ;; (list llx lly boxw boxh)) ;; NB// Swap ury and lly
	    (if (not (null? tal))
		(loop (car tal)
		      (cdr tal))))))
    ;; (for-each
    ;;  (lambda (testname)
    ;;    (dcommon:draw-arrows cnv testname tests-hash test-records))
    ;;  sorted-testnames))
    ))

;; per-point-proc required, remainder optional
;;
(define (dcommon:process-polyline line per-point-proc per-segment-proc last-segment-proc)
  (if (< (length line) 2)
      '()
762
763
764
765
766
767
768
769
770
771
772
773


774
775

776
777
778
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
816
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
832
833
834
835
836



837
838
839

840
841
842
843
844
845

846
847
848
838
839
840
841
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
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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102

1103
1104
1105
1106
1107
1108
1109
1110
1111
1112



1113
1114
1115
1116
1117

1118
1119
1120
1121
1122
1123

1124
1125
1126
1127







-
-
-
-
-
+
+
-
-
+

-
-



-
-
-
-
-
+
+
+
+
+



-
+
-

-
+


-
-
+
+
-




-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+
+










-
+









-
-
-
+
+
+


-
+





-
+



	    (begin
	      (if last-segment-proc (last-segment-proc x1 y1 x2 y2))
	      (append res (per-point-proc x1 y1)))
	    (loop (car tal)(cadr tal) x1 y1 (cddr tal) (append res (per-point-proc x1 y1)))))))

(define (dcommon:redraw-tests cnv xadj yadj sizex sizey sizexmm sizeymm originx originy tests-draw-state sorted-testnames test-records)
  (let* ((scalef              (hash-table-ref tests-draw-state 'scalef))
	 (test-browse-xoffset (hash-table-ref tests-draw-state 'test-browse-xoffset))
	 (test-browse-yoffset (hash-table-ref tests-draw-state 'test-browse-yoffset))
	 (xtorig              (+ test-browse-xoffset (* (/ sizex 2) (- xadj 0.5)))) ;;  (- xadj 1))))
	 (ytorig              (+ test-browse-yoffset (* (/ sizey 2) (- 0.5 yadj))))
	 (xdelta              (- (hash-table-ref tests-draw-state 'xtorig) xtorig))
	 (xoffset             (dcommon:get-xoffset tests-draw-state sizex xadj))
	 (yoffset             (dcommon:get-yoffset tests-draw-state sizey yadj))
	 (ydelta              (- (hash-table-ref tests-draw-state 'ytorig) ytorig))
	 (tests-hash          (hash-table-ref tests-draw-state 'tests-info))
	 (tests-info          (hash-table-ref tests-draw-state 'tests-info))
	 (selected-tests      (hash-table-ref tests-draw-state 'selected-tests )))
    (hash-table-set! tests-draw-state 'xtorig xtorig)
    (hash-table-set! tests-draw-state 'ytorig ytorig)
    (if (not (null? sorted-testnames))
	(let loop ((hed (car (reverse sorted-testnames)))
		   (tal (cdr (reverse sorted-testnames))))
	  (let* ((tvals (hash-table-ref tests-hash hed))
		 (llx   (+ xdelta (list-ref tvals 0)))
		 (lly   (+ ydelta (list-ref tvals 4)))
		 (boxw  (list-ref tvals 5))
		 (boxh  (list-ref tvals 6))
	  (let* ((tvals (hash-table-ref tests-info hed))
		 (llx   (list-ref tvals 0))
		 (lly   (list-ref tvals 1))
		 (boxw  (list-ref tvals 4))
		 (boxh  (list-ref tvals 5))
		 (edges (map (lambda (pline)
			       (dcommon:process-polyline pline
							 (lambda (x1 y1)
							   (list (+ x1 xdelta)
							   (list x1 y1))
								 (+ y1 ydelta)))
							 #f #f))
			     (list-ref tvals 7)))
			     (list-ref tvals 6)))
		 (urx   (+ llx boxw))
		 (ury   (+ lly boxh)))
	    (dcommon:draw-test cnv scalef llx lly boxw boxh hed (hash-table-ref/default selected-tests hed #f))
	    (dcommon:draw-edges cnv scalef edges)
	    (dcommon:draw-test cnv xoffset yoffset scalef llx lly boxw boxh hed (hash-table-ref/default selected-tests hed #f))
	    (dcommon:draw-edges cnv xoffset yoffset scalef edges)
	    (hash-table-set! tests-hash hed (list llx urx (- sizey ury)(- sizey lly) lly boxw boxh edges))
	    (if (not (null? tal))
		;; leave a column of space to the right to list items
		(loop (car tal)
		      (cdr tal))))))))
    ;; (for-each
    ;;  (lambda (testname)
    ;;    (dcommon:draw-edges cnv scalef edges)) ;; (dcommon:draw-arrows cnv testname tests-hash test-records))
    ;;  sorted-testnames)))

;;======================================================================
;; RUN CONTROLS
;;======================================================================

(define (dcommon:command-execution-control data)
  ;; The command line display/exectution control
  (iup:frame
   #:title "Command to be exectuted"
   (iup:hbox
    (iup:label "Run on" #:size "40x")
    (iup:radio 
     (iup:hbox
      (iup:toggle "Local" #:size "40x")
      (iup:toggle "Server" #:size "40x")))
    (let ((tb (iup:textbox 
	       #:value "megatest "
	       #:expand "HORIZONTAL"
	       #:readonly "YES"
	       #:font "Courier New, -12"
	       )))
      (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:tabdat-command-tb data) "VALUE")
					    ";echo Press any key to continue;bash -c 'read -n 1 -s'\" &")))
			     (system cmd)))))))

(define (dcommon:command-action-selector commondat tabdat #!key (tab-num #f))
  (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:tabdat-command-set! tabdat val)
					       (dashboard:update-run-command tabdat))))
	   (default-cmd (car cmds-list)))
      (iuplistbox-fill-list lb cmds-list selected-item: default-cmd)
      (dboard:tabdat-command-set! tabdat default-cmd)
      lb))))

(define (dcommon:command-runname-selector commondat tabdat #!key (tab-num #f)) ;; 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)
				      (debug:catch-and-dump
				       (lambda ()
					 ;; (print "obj: " obj " val: " val " unk: " unk)
					 (dboard:tabdat-run-name-set! tabdat txt) ;; (iup:attribute obj "VALUE"))
					 (dashboard:update-run-command tabdat))
				       "command-runname-selector tb action"))
			   #:value (or default-run-name (dboard:tabdat-run-name tabdat))))
	  (lb (iup:listbox #:expand "HORIZONTAL"
			   #:dropdown "YES"
			   #:action (lambda (obj val index lbstate)
				      (debug:catch-and-dump
				       (lambda ()
					 (if (not (equal? val ""))
					     (begin
					       (iup:attribute-set! tb "VALUE" val)
					       (dboard:tabdat-run-name-set! tabdat val)
					       (dashboard:update-run-command tabdat))))
				       "command-runname-selector lb action"))))
	  (refresh-runs-list (lambda ()
			       (if (dashboard:database-changed? commondat tabdat)
				   (let* ((target        (dboard:tabdat-target-string tabdat))
					  (runs-for-targ (rmt:get-runs-by-patt (dboard:tabdat-keys tabdat) "%" 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:tabdat-updater-for-runs-set! tabdat refresh-runs-list)
     (dboard:commondat-add-updater commondat refresh-runs-list tab-num: tab-num)
     (refresh-runs-list)
     (dboard:tabdat-run-name-set! tabdat default-run-name)
     (iup:hbox
      tb
      lb))))

(define (dcommon:command-testname-selector commondat tabdat update-keyvals) ;;  key-listboxes)
  (iup:vbox
   ;; Text box for test patterns
   (iup:frame
    #:title "Test patterns (one per line)"
    (let ((tb (iup:textbox #:action (lambda (val a b)
				      (debug:catch-and-dump
				       (lambda ()
					 (dboard:tabdat-test-patts-set!-use
					  tabdat
					  (dboard:lines->test-patt b))
					 (dashboard:update-run-command tabdat))
				       "command-testname-selector tb action"))
			   #:value (dboard:test-patt->lines
				    (dboard:tabdat-test-patts-use tabdat))
			   #:expand "YES"
			   #:size "10x30"
			   #:multiline "YES")))
      (set! test-patterns-textbox tb)
      tb))
;; (iup:frame
;;  #:title "Target"
;;  ;; Target selectors
;;  (apply iup:hbox
;; 	   (let* ((dat      (dashboard:update-target-selector tabdat action-proc: update-keyvals))
;; 		  (key-lb   (car dat))
;; 		  (combos   (cadr dat)))
;; 	     combos)))
   (iup:hbox
    ;; 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:tabdat-states-set! tabdat all)
	(dashboard:update-run-command tabdat))))
    ;; 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:tabdat-statuses-set! tabdat all)
	(dashboard:update-run-command tabdat)))))))

(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)
	  (last-yadj 0)
	  (the-cnv   #f)
	  (canvas-obj 
	   (iup:canvas #:action (make-canvas-action
				 (lambda (cnv xadj yadj)
				   (if (not updater)
				       (set! updater (lambda (xadj yadj)
						       ;; (print "cnv: " cnv " xadj: " xadj " yadj: " yadj)
						       (dashboard:draw-tests cnv xadj yadj tests-draw-state sorted-testnames test-records)
						       (set! last-xadj xadj)
						       (set! last-yadj yadj))))
				   (updater xadj yadj)
				   (set! the-cnv cnv)
				   ))
		       ;; Following doesn't work 
		       #:wheel-cb (lambda (obj step x y dir) ;; dir is 4 for up and 5 for down. I think.
				    (let ((scalef (hash-table-ref tests-draw-state 'scalef)))
				      (hash-table-set! tests-draw-state 'scalef (+ scalef
										   (if (> step 0)
										       (* scalef 0.01)
										       (* scalef -0.01))))
				      (if the-cnv
					  (dashboard:draw-tests the-cnv last-xadj last-yadj tests-draw-state sorted-testnames test-records))
				      ))
		       ;; #:size "50x50"
		       #:expand "YES"
		       #:scrollbar "YES"
		       #:posx "0.5"
		       #:posy "0.5"
		       #:button-cb (lambda (obj btn pressed x y status)
				     ;; (print "obj: " obj ", pressed " pressed ", status " status)
					; (print "canvas-origin: " (canvas-origin the-cnv))
				     ;; (let-values (((xx yy)(canvas-origin the-cnv)))
				     ;; (canvas-transform-set! the-cnv #f)
				     ;; (print "canvas-origin: " xx " " yy " click at " x " " y))
				     (let* ((tests-info     (hash-table-ref tests-draw-state 'tests-info))
					    (selected-tests (hash-table-ref tests-draw-state 'selected-tests))
					    (scalef         (hash-table-ref tests-draw-state 'scalef))
					    (sizey          (hash-table-ref tests-draw-state 'sizey))
					    (xoffset        (dcommon:get-xoffset tests-draw-state #f #f))
					    (yoffset        (dcommon:get-yoffset tests-draw-state #f #f))
					    (new-y          (- sizey y)))
				       ;; (print "xoffset=" xoffset ", yoffset=" yoffset)
				       ;; (print "\tx\ty\tllx\tlly\turx\tury")
				       (for-each (lambda (test-name)
						   (let* ((rec-coords (hash-table-ref tests-info test-name))
							  (llx        (dcommon:x->canvas (list-ref rec-coords 0) scalef xoffset))
							  (lly        (dcommon:y->canvas (list-ref rec-coords 1) scalef yoffset))
							  (urx        (dcommon:x->canvas (list-ref rec-coords 2) scalef xoffset))
							  (ury        (dcommon:y->canvas (list-ref rec-coords 3) scalef yoffset)))
						     ;; (if (eq? pressed 1)
						     ;;    (print "\tx=" x "\ty=" y "\tnew-y=" new-y "\tllx=" llx "\tlly=" lly "\turx=" urx "\tury=" ury "\t" test-name " "))
						     (if (and (eq? pressed 1)
							      (>= x llx)
							      (>= new-y lly)
							      (<= x urx)
							      (<= new-y ury))
							 (let ((patterns (string-split (iup:attribute test-patterns-textbox "VALUE"))))
							   (let* ((selected     (not (member test-name patterns)))
								  (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: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
;;======================================================================

(define (dcommon:populate-steps teststeps steps-matrix)
  (let ((max-row 0))
  (let ((max-row 0)
	(max-col 7))
    (if (null? teststeps)
	(iup:attribute-set! steps-matrix "CLEARVALUE" "CONTENTS")
	(let loop ((hed    (car teststeps))
		   (tal    (cdr teststeps))
		   (rownum 1)
		   (colnum 1))
	  (if (> rownum max-row)(set! max-row rownum))
	  (let ((val     (vector-ref hed (- colnum 1)))
		(mtrx-rc (conc rownum ":" colnum)))
	    (iup:attribute-set! steps-matrix  mtrx-rc (if val (conc val) ""))
	    (if (< colnum 6)
	    (if (< colnum max-col)
		(loop hed tal rownum (+ colnum 1))
		(if (not (null? tal))
		    (loop (car tal)(cdr tal)(+ rownum 1) 1))))))
    (if (> max-row 0)
	(begin
	  ;; we are going to speculatively clear rows until we find a row that is already cleared
	  (let loop ((rownum  (+ max-row 1))
		     (colnum  0)
		     (deleted #f))
	    ;; (debug:print-info 0 "cleaning " rownum ":" colnum)
	    (let* ((next-row (if (eq? colnum 6) (+ rownum 1) rownum))
		   (next-col (if (eq? colnum 6) 1 (+ colnum 1)))
	    ;; (debug:print-info 0 *default-log-port* "cleaning " rownum ":" colnum)
	    (let* ((next-row (if (eq? colnum max-col) (+ rownum 1) rownum))
		   (next-col (if (eq? colnum max-col) 1 (+ colnum 1)))
		   (mtrx-rc  (conc rownum ":" colnum))
		   (curr-val (iup:attribute steps-matrix mtrx-rc)))
	      ;; (debug:print-info 0 "cleaning " rownum ":" colnum " currval= " curr-val)
	      ;; (debug:print-info 0 *default-log-port* "cleaning " rownum ":" colnum " currval= " curr-val)
	      (if (and (string? curr-val)
		       (not (equal? curr-val "")))
		  (begin
		    (iup:attribute-set! steps-matrix mtrx-rc "")
		    (loop next-row next-col #t))
		  (if (eq? colnum 6) ;; not done, didn't get a full blank row
		  (if (eq? colnum max-col) ;; not done, didn't get a full blank row
		      (if deleted (loop next-row next-col #f)) ;; exit on this not met
		      (loop next-row next-col deleted)))))
	  (iup:attribute-set! steps-matrix "REDRAW" "ALL")))))

Added debugger.scm version [f446c83fb1].










































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
(use iup)

(define *debugger-control* #f)
(define *debugger-rownum*  0)
(define *debugger-matrix*  #f)
(define *debugger*         #f)

(define (debugger)
  (if (not *debugger*)
      (set! *debugger* 
	    (thread-start!
	     (make-thread
	      (lambda ()
		(show
		 (dialog
		  (let ((pause #f)
			(mtrx  (matrix
				#:expand "YES"
				#:numlin 30
				#:numcol 3
				#:numlin-visible 20
				#:numcol-visible 2
				#:alignment1 "ALEFT"
				)))
		    (set! pause (button "Pause" 
					#:action (lambda (obj)
						   (set! *debugger-control* (not *debugger-control*))
						   (attribute-set! pause "BGCOLOR" (if *debugger-control*
										       "200 0 0"
										       "0 0 200")))))
		    (set! *debugger-matrix* mtrx)
		    (attribute-set! mtrx "WIDTH1" "300")
		    (vbox
		     mtrx
		     (hbox
		      pause)))))
		(main-loop)))))))

(define (debugger-start #!key (start 2))
  (set! *debugger-rownum* start))

(define (debugger-trace-var varname varval)
  (let ((oldval (attribute *debugger-matrix* (conc *debugger-rownum* ":1")))
	(newval (conc varval)))
    (if (not (equal? oldval newval))
	(begin
	  ;; (print "DEBUG: " varname " = " newval)
	  (attribute-set! *debugger-matrix* (conc *debugger-rownum* ":0") varname)
	  (attribute-set! *debugger-matrix* (conc *debugger-rownum* ":1") (conc varval))
	  ;; (attribute-set! *debugger-matrix* "FITTOTEXT" "C1")
	  ))
    (set! *debugger-rownum* (+ *debugger-rownum* 1))))


(define (debugger-pauser)
  (debugger)
  (attribute-set! *debugger-matrix* "REDRAW" "ALL")
  (let loop ()
    (if *debugger-control*
	(begin
	  (print "PAUSED!")
	  (thread-sleep! 1)
	  (loop))
	;;(thread-sleep! 0.01)
	)))
		  
;;    ;; lets use the debugger eh?
;;    (debugger-start)
;;    (debugger-trace-var "can-run-more"     can-run-more)
;;    (debugger-trace-var "hed"              hed)
;;    (debugger-trace-var "prereqs-not-met"  (runs:pretty-string prereqs-not-met))
;;    (debugger-pauser)

Modified docs/Makefile from [4f9f6e9c2f] to [ef7610ee8e].









1

2
3
4
5
6
7
8
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
+
+
+
+
+
+
+
+
-
+







ASCPATH = $(shell which asciidoc)
EXEPATH = $(shell readlink -f $(ASCPATH))
BINPATH = $(shell dirname $(EXEPATH))
DISPATH = $(shell dirname $(BINPATH))

api.html : api.txt
	asciidoc  -b html5 -a icons -a iconsdir=$(DISPATH)/images/icons -a toc2 api.txt

all : html/megatest.html megatest.pdf
# all : html/megatest.html megatest.pdf

html/megatest.html : megatest.lyx
	elyxer megatest.lyx html/megatest.html
	fossil add html/*

megatest.pdf : megatest.lyx
	lyx -e pdf2 megatest.lyx

Added docs/api.html version [c2276e6b3d].




























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
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
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
1013
1014
1015
1016
1017
1018
1019
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.7">
<title>Megatest Web App API Specificiation</title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */

/* Default font. */
body {
  font-family: Georgia,serif;
}

/* Title font. */
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
  font-family: Arial,Helvetica,sans-serif;
}

body {
  margin: 1em 5% 1em 5%;
}

a {
  color: blue;
  text-decoration: underline;
}
a:visited {
  color: fuchsia;
}

em {
  font-style: italic;
  color: navy;
}

strong {
  font-weight: bold;
  color: #083194;
}

h1, h2, h3, h4, h5, h6 {
  color: #527bbd;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

h1, h2, h3 {
  border-bottom: 2px solid silver;
}
h2 {
  padding-top: 0.5em;
}
h3 {
  float: left;
}
h3 + * {
  clear: left;
}
h5 {
  font-size: 1.0em;
}

div.sectionbody {
  margin-left: 0;
}

hr {
  border: 1px solid silver;
}

p {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

ul, ol, li > p {
  margin-top: 0;
}
ul > li     { color: #aaa; }
ul > li > * { color: black; }

pre {
  padding: 0;
  margin: 0;
}

#author {
  color: #527bbd;
  font-weight: bold;
  font-size: 1.1em;
}
#email {
}
#revnumber, #revdate, #revremark {
}

#footer {
  font-size: small;
  border-top: 2px solid silver;
  padding-top: 0.5em;
  margin-top: 4.0em;
}
#footer-text {
  float: left;
  padding-bottom: 0.5em;
}
#footer-badges {
  float: right;
  padding-bottom: 0.5em;
}

#preamble {
  margin-top: 1.5em;
  margin-bottom: 1.5em;
}
div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.admonitionblock {
  margin-top: 2.0em;
  margin-bottom: 2.0em;
  margin-right: 10%;
  color: #606060;
}

div.content { /* Block element content. */
  padding: 0;
}

/* Block element titles. */
div.title, caption.title {
  color: #527bbd;
  font-weight: bold;
  text-align: left;
  margin-top: 1.0em;
  margin-bottom: 0.5em;
}
div.title + * {
  margin-top: 0;
}

td div.title:first-child {
  margin-top: 0.0em;
}
div.content div.title:first-child {
  margin-top: 0.0em;
}
div.content + div.title {
  margin-top: 0.0em;
}

div.sidebarblock > div.content {
  background: #ffffee;
  border: 1px solid #dddddd;
  border-left: 4px solid #f0f0f0;
  padding: 0.5em;
}

div.listingblock > div.content {
  border: 1px solid #dddddd;
  border-left: 5px solid #f0f0f0;
  background: #f8f8f8;
  padding: 0.5em;
}

div.quoteblock, div.verseblock {
  padding-left: 1.0em;
  margin-left: 1.0em;
  margin-right: 10%;
  border-left: 5px solid #f0f0f0;
  color: #888;
}

div.quoteblock > div.attribution {
  padding-top: 0.5em;
  text-align: right;
}

div.verseblock > pre.content {
  font-family: inherit;
  font-size: inherit;
}
div.verseblock > div.attribution {
  padding-top: 0.75em;
  text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
  text-align: left;
}

div.admonitionblock .icon {
  vertical-align: top;
  font-size: 1.1em;
  font-weight: bold;
  text-decoration: underline;
  color: #527bbd;
  padding-right: 0.5em;
}
div.admonitionblock td.content {
  padding-left: 0.5em;
  border-left: 3px solid #dddddd;
}

div.exampleblock > div.content {
  border-left: 3px solid #dddddd;
  padding-left: 0.5em;
}

div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }

dl {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
dt {
  margin-top: 0.5em;
  margin-bottom: 0;
  font-style: normal;
  color: navy;
}
dd > *:first-child {
  margin-top: 0.1em;
}

ul, ol {
    list-style-position: outside;
}
ol.arabic {
  list-style-type: decimal;
}
ol.loweralpha {
  list-style-type: lower-alpha;
}
ol.upperalpha {
  list-style-type: upper-alpha;
}
ol.lowerroman {
  list-style-type: lower-roman;
}
ol.upperroman {
  list-style-type: upper-roman;
}

div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
  margin-top: 0.1em;
  margin-bottom: 0.1em;
}

tfoot {
  font-weight: bold;
}
td > div.verse {
  white-space: pre;
}

div.hdlist {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
div.hdlist tr {
  padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
  font-weight: bold;
}
td.hdlist1 {
  vertical-align: top;
  font-style: normal;
  padding-right: 0.8em;
  color: navy;
}
td.hdlist2 {
  vertical-align: top;
}
div.hdlist.compact tr {
  margin: 0;
  padding-bottom: 0;
}

.comment {
  background: yellow;
}

.footnote, .footnoteref {
  font-size: 0.8em;
}

span.footnote, span.footnoteref {
  vertical-align: super;
}

#footnotes {
  margin: 20px 0 20px 0;
  padding: 7px 0 0 0;
}

#footnotes div.footnote {
  margin: 0 0 5px 0;
}

#footnotes hr {
  border: none;
  border-top: 1px solid silver;
  height: 1px;
  text-align: left;
  margin-left: 0;
  width: 20%;
  min-width: 100px;
}

div.colist td {
  padding-right: 0.5em;
  padding-bottom: 0.3em;
  vertical-align: top;
}
div.colist td img {
  margin-top: 0.3em;
}

@media print {
  #footer-badges { display: none; }
}

#toc {
  margin-bottom: 2.5em;
}

#toctitle {
  color: #527bbd;
  font-size: 1.1em;
  font-weight: bold;
  margin-top: 1.0em;
  margin-bottom: 0.1em;
}

div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
  margin-top: 0;
  margin-bottom: 0;
}
div.toclevel2 {
  margin-left: 2em;
  font-size: 0.9em;
}
div.toclevel3 {
  margin-left: 4em;
  font-size: 0.9em;
}
div.toclevel4 {
  margin-left: 6em;
  font-size: 0.9em;
}

span.aqua { color: aqua; }
span.black { color: black; }
span.blue { color: blue; }
span.fuchsia { color: fuchsia; }
span.gray { color: gray; }
span.green { color: green; }
span.lime { color: lime; }
span.maroon { color: maroon; }
span.navy { color: navy; }
span.olive { color: olive; }
span.purple { color: purple; }
span.red { color: red; }
span.silver { color: silver; }
span.teal { color: teal; }
span.white { color: white; }
span.yellow { color: yellow; }

span.aqua-background { background: aqua; }
span.black-background { background: black; }
span.blue-background { background: blue; }
span.fuchsia-background { background: fuchsia; }
span.gray-background { background: gray; }
span.green-background { background: green; }
span.lime-background { background: lime; }
span.maroon-background { background: maroon; }
span.navy-background { background: navy; }
span.olive-background { background: olive; }
span.purple-background { background: purple; }
span.red-background { background: red; }
span.silver-background { background: silver; }
span.teal-background { background: teal; }
span.white-background { background: white; }
span.yellow-background { background: yellow; }

span.big { font-size: 2em; }
span.small { font-size: 0.6em; }

span.underline { text-decoration: underline; }
span.overline { text-decoration: overline; }
span.line-through { text-decoration: line-through; }

div.unbreakable { page-break-inside: avoid; }


/*
 * xhtml11 specific
 *
 * */

tt {
  font-family: "Courier New", Courier, monospace;
  font-size: inherit;
  color: navy;
}

div.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.tableblock > table {
  border: 3px solid #527bbd;
}
thead, p.table.header {
  font-weight: bold;
  color: #527bbd;
}
p.table {
  margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
  border-style: none;
}
div.tableblock > table[frame="hsides"] {
  border-left-style: none;
  border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
  border-top-style: none;
  border-bottom-style: none;
}


/*
 * html5 specific
 *
 * */

.monospaced {
  font-family: "Courier New", Courier, monospace;
  font-size: inherit;
  color: navy;
}

table.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
thead, p.tableblock.header {
  font-weight: bold;
  color: #527bbd;
}
p.tableblock {
  margin-top: 0;
}
table.tableblock {
  border-width: 3px;
  border-spacing: 0px;
  border-style: solid;
  border-color: #527bbd;
  border-collapse: collapse;
}
th.tableblock, td.tableblock {
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #527bbd;
}

table.tableblock.frame-topbot {
  border-left-style: hidden;
  border-right-style: hidden;
}
table.tableblock.frame-sides {
  border-top-style: hidden;
  border-bottom-style: hidden;
}
table.tableblock.frame-none {
  border-style: hidden;
}

th.tableblock.halign-left, td.tableblock.halign-left {
  text-align: left;
}
th.tableblock.halign-center, td.tableblock.halign-center {
  text-align: center;
}
th.tableblock.halign-right, td.tableblock.halign-right {
  text-align: right;
}

th.tableblock.valign-top, td.tableblock.valign-top {
  vertical-align: top;
}
th.tableblock.valign-middle, td.tableblock.valign-middle {
  vertical-align: middle;
}
th.tableblock.valign-bottom, td.tableblock.valign-bottom {
  vertical-align: bottom;
}


/*
 * manpage specific
 *
 * */

body.manpage h1 {
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  border-top: 2px solid silver;
  border-bottom: 2px solid silver;
}
body.manpage h2 {
  border-style: none;
}
body.manpage div.sectionbody {
  margin-left: 3em;
}

@media print {
  body.manpage div#toc { display: none; }
}
@media screen {
  body {
    max-width: 50em; /* approximately 80 characters wide */
    margin-left: 16em;
  }

  #toc {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 13em;
    padding: 0.5em;
    padding-bottom: 1.5em;
    margin: 0;
    overflow: auto;
    border-right: 3px solid #f8f8f8;
    background-color: white;
  }

  #toc .toclevel1 {
    margin-top: 0.5em;
  }

  #toc .toclevel2 {
    margin-top: 0.25em;
    display: list-item;
    color: #aaaaaa;
  }

  #toctitle {
    margin-top: 0.5em;
  }
}
</style>
<script type="text/javascript">
/*<![CDATA[*/
var asciidoc = {  // Namespace.

/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////

/* Author: Mihai Bazon, September 2002
 * http://students.infoiasi.ro/~mishoo
 *
 * Table Of Content generator
 * Version: 0.4
 *
 * Feel free to use this script under the terms of the GNU General Public
 * License, as long as you do not remove or alter this notice.
 */

 /* modified by Troy D. Hanson, September 2006. License: GPL */
 /* modified by Stuart Rackham, 2006, 2009. License: GPL */

// toclevels = 1..4.
toc: function (toclevels) {

  function getText(el) {
    var text = "";
    for (var i = el.firstChild; i != null; i = i.nextSibling) {
      if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
        text += i.data;
      else if (i.firstChild != null)
        text += getText(i);
    }
    return text;
  }

  function TocEntry(el, text, toclevel) {
    this.element = el;
    this.text = text;
    this.toclevel = toclevel;
  }

  function tocEntries(el, toclevels) {
    var result = new Array;
    var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
    // Function that scans the DOM tree for header elements (the DOM2
    // nodeIterator API would be a better technique but not supported by all
    // browsers).
    var iterate = function (el) {
      for (var i = el.firstChild; i != null; i = i.nextSibling) {
        if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
          var mo = re.exec(i.tagName);
          if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
            result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
          }
          iterate(i);
        }
      }
    }
    iterate(el);
    return result;
  }

  var toc = document.getElementById("toc");
  if (!toc) {
    return;
  }

  // Delete existing TOC entries in case we're reloading the TOC.
  var tocEntriesToRemove = [];
  var i;
  for (i = 0; i < toc.childNodes.length; i++) {
    var entry = toc.childNodes[i];
    if (entry.nodeName.toLowerCase() == 'div'
     && entry.getAttribute("class")
     && entry.getAttribute("class").match(/^toclevel/))
      tocEntriesToRemove.push(entry);
  }
  for (i = 0; i < tocEntriesToRemove.length; i++) {
    toc.removeChild(tocEntriesToRemove[i]);
  }

  // Rebuild TOC entries.
  var entries = tocEntries(document.getElementById("content"), toclevels);
  for (var i = 0; i < entries.length; ++i) {
    var entry = entries[i];
    if (entry.element.id == "")
      entry.element.id = "_toc_" + i;
    var a = document.createElement("a");
    a.href = "#" + entry.element.id;
    a.appendChild(document.createTextNode(entry.text));
    var div = document.createElement("div");
    div.appendChild(a);
    div.className = "toclevel" + entry.toclevel;
    toc.appendChild(div);
  }
  if (entries.length == 0)
    toc.parentNode.removeChild(toc);
},


/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////

/* Based on footnote generation code from:
 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
 */

footnotes: function () {
  // Delete existing footnote entries in case we're reloading the footnodes.
  var i;
  var noteholder = document.getElementById("footnotes");
  if (!noteholder) {
    return;
  }
  var entriesToRemove = [];
  for (i = 0; i < noteholder.childNodes.length; i++) {
    var entry = noteholder.childNodes[i];
    if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
      entriesToRemove.push(entry);
  }
  for (i = 0; i < entriesToRemove.length; i++) {
    noteholder.removeChild(entriesToRemove[i]);
  }

  // Rebuild footnote entries.
  var cont = document.getElementById("content");
  var spans = cont.getElementsByTagName("span");
  var refs = {};
  var n = 0;
  for (i=0; i<spans.length; i++) {
    if (spans[i].className == "footnote") {
      n++;
      var note = spans[i].getAttribute("data-note");
      if (!note) {
        // Use [\s\S] in place of . so multi-line matches work.
        // Because JavaScript has no s (dotall) regex flag.
        note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
        spans[i].innerHTML =
          "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
        spans[i].setAttribute("data-note", note);
      }
      noteholder.innerHTML +=
        "<div class='footnote' id='_footnote_" + n + "'>" +
        "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
        n + "</a>. " + note + "</div>";
      var id =spans[i].getAttribute("id");
      if (id != null) refs["#"+id] = n;
    }
  }
  if (n == 0)
    noteholder.parentNode.removeChild(noteholder);
  else {
    // Process footnoterefs.
    for (i=0; i<spans.length; i++) {
      if (spans[i].className == "footnoteref") {
        var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
        href = href.match(/#.*/)[0];  // Because IE return full URL.
        n = refs[href];
        spans[i].innerHTML =
          "[<a href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
      }
    }
  }
},

install: function(toclevels) {
  var timerId;

  function reinstall() {
    asciidoc.footnotes();
    if (toclevels) {
      asciidoc.toc(toclevels);
    }
  }

  function reinstallAndRemoveTimer() {
    clearInterval(timerId);
    reinstall();
  }

  timerId = setInterval(reinstall, 500);
  if (document.addEventListener)
    document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
  else
    window.onload = reinstallAndRemoveTimer;
}

}
asciidoc.install(2);
/*]]>*/
</script>
</head>
<body class="article">
<div id="header">
<h1>Megatest Web App API Specificiation</h1>
<span id="author">Matt Welland</span><br>
<span id="email" class="monospaced">&lt;<a href="mailto:matt@kiatoa.com">matt@kiatoa.com</a>&gt;</span><br>
<span id="revnumber">version 1.0,</span>
<span id="revdate">2013-12</span>
<div id="toc">
  <div id="toctitle">Table of Contents</div>
  <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>Megatest Web App</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
See runs
</p>
</li>
<li>
<p>
Manage jobs
</p>
</li>
<li>
<p>
Debug
</p>
</li>
</ol></div>
</div>
</div>
<div class="sect1">
<h2 id="_example_abstract">Example Abstract</h2>
<div class="sectionbody">
<div class="paragraph"><p>The Megatest Web App aims to make as much of the power of the dashboard available to the web based user.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_common">1. Common</h2>
<div class="sectionbody">
<div class="paragraph"><p>This is an example endpoint. You will need to use your own cgi server to serve out your megatest runs.</p></div>
<div class="paragraph"><p>Endpoint: <a href="http://kiatoa.com/cgi-bin/megatest">http://kiatoa.com/cgi-bin/megatest</a></p></div>
<div class="sect2">
<h3 id="_error_format_response">1.1. Error format response</h3>
<div class="paragraph"><p>All API errors are returned in the following format:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>{ "<span class="blue">error</span>" : "<span class="red">Error message</span>" }</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_get_list_of_runs">1.2. Get List of Runs</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs</p></div>
<div class="paragraph"><p>Method: GET</p></div>
<div class="paragraph"><p>Filter Params: target, testpatt, offset, limit</p></div>
<div class="paragraph"><p>Response:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>[
  {
    "<span class="red">run_id</span>" : "1",
    "<span class="red">name</span>"   : "runname1",
    "<span class="red">target</span>" : "target1",
    "<span class="red">tests</span>"  :
      [
          "<span class="green">test</span>":
              [
                   {"<span class="blue">id</span>": 1, "<span class="blue">name</span>":test1, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target1/runname1/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS#"}
                   {"<span class="blue">id</span>": 2, "<span class="blue">name</span>":test2, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target1/runname1/test2", "<span class="blue">final_logf</span>": "megatest-rollup-test2.html",  "<span class="blue">status</span>": "PASS"}
                   {"<span class="blue">id</span>": 3, "<span class="blue">name</span>":test3, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target1/runname1/test3", "<span class="blue">final_logf</span>": "megatest-rollup-test3.html",  "<span class="blue">status</span>": "PASS"}
              ]
      ]
   },
   {
    "<span class="red">run_id</span>" : "2",
    "<span class="red">name</span>"   : "runname2",
    "<span class="red">target</span>" : "target2",
    "<span class="red">tests</span>"  :
      [
          "<span class="green">test</span>:
              [
                   {"<span class="blue">id</span>": 4, "<span class="blue">name</span>":[blue]test1, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}
                   {"<span class="blue">id</span>": 5, "<span class="blue">name</span>":[blue]test2, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test2", "<span class="blue">final_logf</span>": "megatest-rollup-test2.html",  "<span class="blue">status</span>": "FAIL"}
                   {"<span class="blue">id</span>": 6, "<span class="blue">name</span>":test3, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test3", "<span class="blue">final_logf</span>": "megatest-rollup-test3.html",  "<span class="blue">status</span>": "PASS"}
              ]
      ]
   }
]</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_trigger_a_new_run">1.3. Trigger a new Run</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs</p></div>
<div class="paragraph"><p>Method: POST</p></div>
<div class="paragraph"><p>Request Params:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>{"<span class="blue">target</span>": "target_value", "<span class="blue">runname</span>" : "runname", "<span class="blue">test_pattern</span>": "optional test pattern"}</p></div>
</div></div>
<div class="paragraph"><p>Response:</p></div>
<div class="paragraph"><p>If Error</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>{ "<span class="blue">error</span>" : "<span class="red">Error message</span>" }</p></div>
</div></div>
<div class="paragraph"><p>If Success returns the results of the run</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>[
   {
    "<span class="red">run_id</span>" : "2",
    "<span class="red">name</span>"   : "runname2",
    "<span class="red">target</span>" : "target2",
    "<span class="red">tests</span>"  :
      [
          "<span class="green">test</span>:
              [
                   {"<span class="blue">id</span>": 4, "<span class="blue">name</span>":[blue]test1, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}
                   {"<span class="blue">id</span>": 5, "<span class="blue">name</span>":[blue]test2, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test2", "<span class="blue">final_logf</span>": "megatest-rollup-test2.html",  "<span class="blue">status</span>": "FAIL"}
                   {"<span class="blue">id</span>": 6, "<span class="blue">name</span>":test3, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test3", "<span class="blue">final_logf</span>": "megatest-rollup-test3.html",  "<span class="blue">status</span>": "PASS"}
              ]
      ]
   }
]</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_get_perticular_run">1.4. Get perticular Run</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs/:id</p></div>
<div class="paragraph"><p>Method: GET</p></div>
<div class="paragraph"><p>Filter Params: testpatt</p></div>
<div class="paragraph"><p>Response:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>[
   {
    "<span class="red">run_id</span>" : "2",
    "<span class="red">name</span>"   : "runname2",
    "<span class="red">target</span>" : "target2",
    "<span class="red">tests</span>"  :
      [
          "<span class="green">test</span>":
              [
                   {"<span class="blue">id</span>": 4, "<span class="blue">name</span>":[blue]test1, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}
                   {"<span class="blue">id</span>": 5, "<span class="blue">name</span>":[blue]test2, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test2", "<span class="blue">final_logf</span>": "megatest-rollup-test2.html",  "<span class="blue">status</span>": "FAIL"}
                   {"<span class="blue">id</span>": 6, "<span class="blue">name</span>":test3, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test3", "<span class="blue">final_logf</span>": "megatest-rollup-test3.html",  "<span class="blue">status</span>": "PASS"}
              ]
      ]
   }
]</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_re_execute_a_run">1.5. Re-execute a run</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs/:id</p></div>
<div class="paragraph"><p>Method: PUT/PATCH</p></div>
<div class="paragraph"><p>Request Params: {"testpatt" : "pattern"}</p></div>
<div class="paragraph"><p>Response:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>[
   {
    "<span class="red">run_id</span>" : "2",
    "<span class="red">name</span>"   : "runname2",
    "<span class="red">target</span>" : "target2",
    "<span class="red">tests</span>"  :
      [
          "<span class="green">test</span>":
              [
                   {"<span class="blue">id</span>": 4, "<span class="blue">name</span>":[blue]test1, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}
                   {"<span class="blue">id</span>": 5, "<span class="blue">name</span>":[blue]test2, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test2", "<span class="blue">final_logf</span>": "megatest-rollup-test2.html",  "<span class="blue">status</span>": "FAIL"}
                   {"<span class="blue">id</span>": 6, "<span class="blue">name</span>":test3, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test3", "<span class="blue">final_logf</span>": "megatest-rollup-test3.html",  "<span class="blue">status</span>": "PASS"}
              ]
      ]
   }
]</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_get_list_of_tests_within_a_run">1.6. Get List of tests within a run</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs/:id/tests</p></div>
<div class="paragraph"><p>Method: GET</p></div>
<div class="paragraph"><p>Response:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>[
     "<span class="red">tests</span>"  :
              [
                   {"<span class="blue">id</span>": 4, "<span class="blue">name</span>":[blue]test1, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}
                   {"<span class="blue">id</span>": 5, "<span class="blue">name</span>":[blue]test2, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test2", "<span class="blue">final_logf</span>": "megatest-rollup-test2.html",  "<span class="blue">status</span>": "FAIL"}
                   {"<span class="blue">id</span>": 6, "<span class="blue">name</span>":test3, "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test3", "<span class="blue">final_logf</span>": "megatest-rollup-test3.html",  "<span class="blue">status</span>": "PASS"}
              ]
]</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_re_execute_a_test_within_a_run">1.7. Re-execute a test within a run</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs/:id/tests/:id</p></div>
<div class="paragraph"><p>Method: PUT/PATCH</p></div>
<div class="paragraph"><p>Response:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>{"<span class="blue">id</span>": "4", "<span class="blue">name</span>":"test1", "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}</p></div>
</div></div>
</div>
<div class="sect2">
<h3 id="_get_perticular_test_that_belongs_to_a_runs">1.8. Get perticular test that belongs to a Runs</h3>
<div class="paragraph"><p>URL: &lt;base&gt;/runs/:id/tests/:id</p></div>
<div class="paragraph"><p>Method: GET</p></div>
<div class="paragraph"><p>Response:</p></div>
<div class="exampleblock">
<div class="content">
<div class="paragraph"><p>{"<span class="blue">id</span>": "4", "<span class="blue">name</span>":"test1", "<span class="blue">item_path</span>": "", "<span class="blue">shortdir</span>": "/temp/foo/bar/target2/runname2/test1", "<span class="blue">final_logf</span>": "megatest-rollup-test1.html",  "<span class="blue">status</span>": "PASS"}</p></div>
</div></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_notes">2. Notes</h2>
<div class="sectionbody">
<div class="paragraph"><p>Misc &#8230;</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
blah
</p>
</li>
<li>
<p>
baz
</p>
</li>
</ol></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
Version 1.0<br>
Last updated 2016-08-04 09:33:43 PDT
</div>
</div>
</body>
</html>

Added docs/api.txt version [bcdb746fea].



















































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Megatest Web App API Specificiation
===================================
Matt Welland <matt@kiatoa.com>
v1.0, 2013-12

Megatest Web App

. See runs
. Manage jobs
. Debug

:numbered!:
[abstract]
Example Abstract
----------------

The Megatest Web App aims to make as much of the power of the dashboard available to the web based user.

:numbered:

Common
------

This is an example endpoint. You will need to use your own cgi server to serve out your megatest runs.

Endpoint: http://kiatoa.com/cgi-bin/megatest

Error format response
~~~~~~~~~~~~~~~~~~~~~
All API errors are returned in the following format:

===================
{ "[blue]#error#" : "[red]#Error message#" }
===================

Get List of Runs
~~~~~~~~~~~~~~~~

URL: <base>/runs

Method: GET

Filter Params: target, testpatt, offset, limit

Response:


==================
[
  {
    "[red]#run_id#" : "1",
    "[red]#name#"   : "runname1",
    "[red]#target#" : "target1",
    "[red]#tests#"  :
      [
          "[green]#test#":
              [
                   {"[blue]#id#": 1, "[blue]#name#":test1, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target1/runname1/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS#"}
		   {"[blue]#id#": 2, "[blue]#name#":test2, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target1/runname1/test2", "[blue]#final_logf#": "megatest-rollup-test2.html",  "[blue]#status#": "PASS"}
                   {"[blue]#id#": 3, "[blue]#name#":test3, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target1/runname1/test3", "[blue]#final_logf#": "megatest-rollup-test3.html",  "[blue]#status#": "PASS"}
              ]  
      ]
   },
   {
    "[red]#run_id#" : "2",
    "[red]#name#"   : "runname2",
    "[red]#target#" : "target2",
    "[red]#tests#"  :
      [
          "[green]#test#:
              [
                   {"[blue]#id#": 4, "[blue]#name#":[blue]#test1#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
		   {"[blue]#id#": 5, "[blue]#name#":[blue]#test2#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test2", "[blue]#final_logf#": "megatest-rollup-test2.html",  "[blue]#status#": "FAIL"}
                   {"[blue]#id#": 6, "[blue]#name#":test3, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test3", "[blue]#final_logf#": "megatest-rollup-test3.html",  "[blue]#status#": "PASS"}
              ]  
      ]
   }
]
==================


Trigger a new Run
~~~~~~~~~~~~~~~~~~

URL: <base>/runs

Method: POST

Request Params: 
==================
{"[blue]#target#": "target_value", "[blue]#runname#" : "runname", "[blue]#test_pattern#": "optional test pattern"}
==================

Response: 

If Error
===================
{ "[blue]#error#" : "[red]#Error message#" }
===================

If Success returns the results of the run

==================
[
   {
    "[red]#run_id#" : "2",
    "[red]#name#"   : "runname2",
    "[red]#target#" : "target2",
    "[red]#tests#"  :
      [
          "[green]#test#:
              [
                   {"[blue]#id#": 4, "[blue]#name#":[blue]#test1#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
		   {"[blue]#id#": 5, "[blue]#name#":[blue]#test2#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test2", "[blue]#final_logf#": "megatest-rollup-test2.html",  "[blue]#status#": "FAIL"}
                   {"[blue]#id#": 6, "[blue]#name#":test3, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test3", "[blue]#final_logf#": "megatest-rollup-test3.html",  "[blue]#status#": "PASS"}
              ]  
      ]
   }
]
==================



Get perticular Run
~~~~~~~~~~~~~~~~~~~

URL: <base>/runs/:id

Method: GET

Filter Params: testpatt

Response: 

==================
[
   {
    "[red]#run_id#" : "2",
    "[red]#name#"   : "runname2",
    "[red]#target#" : "target2",
    "[red]#tests#"  :
      [
          "[green]#test#":
              [
                   {"[blue]#id#": 4, "[blue]#name#":[blue]#test1#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
		   {"[blue]#id#": 5, "[blue]#name#":[blue]#test2#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test2", "[blue]#final_logf#": "megatest-rollup-test2.html",  "[blue]#status#": "FAIL"}
                   {"[blue]#id#": 6, "[blue]#name#":test3, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test3", "[blue]#final_logf#": "megatest-rollup-test3.html",  "[blue]#status#": "PASS"}
              ]  
      ]
   }
]
==================
 

Re-execute a run
~~~~~~~~~~~~~~~~~

URL: <base>/runs/:id

Method: PUT/PATCH

Request Params: {"testpatt" : "pattern"}

Response: 

==================
[
   {
    "[red]#run_id#" : "2",
    "[red]#name#"   : "runname2",
    "[red]#target#" : "target2",
    "[red]#tests#"  :
      [
          "[green]#test#":
              [
                   {"[blue]#id#": 4, "[blue]#name#":[blue]#test1#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
		   {"[blue]#id#": 5, "[blue]#name#":[blue]#test2#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test2", "[blue]#final_logf#": "megatest-rollup-test2.html",  "[blue]#status#": "FAIL"}
                   {"[blue]#id#": 6, "[blue]#name#":test3, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test3", "[blue]#final_logf#": "megatest-rollup-test3.html",  "[blue]#status#": "PASS"}
              ]  
      ]
   }
]
==================
 


Get List of tests within a run 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

URL: <base>/runs/:id/tests

Method: GET

Response: 
==================
[
     "[red]#tests#"  :
              [
                   {"[blue]#id#": 4, "[blue]#name#":[blue]#test1#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
		   {"[blue]#id#": 5, "[blue]#name#":[blue]#test2#, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test2", "[blue]#final_logf#": "megatest-rollup-test2.html",  "[blue]#status#": "FAIL"}
                   {"[blue]#id#": 6, "[blue]#name#":test3, "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test3", "[blue]#final_logf#": "megatest-rollup-test3.html",  "[blue]#status#": "PASS"}
              ]  
]
==================


Re-execute a test within a run
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

URL: <base>/runs/:id/tests/:id

Method: PUT/PATCH

Response: 

==================
{"[blue]#id#": "4", "[blue]#name#":"test1", "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
==================


Get perticular test that belongs to a Runs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

URL: <base>/runs/:id/tests/:id

Method: GET

Response: 

==================
{"[blue]#id#": "4", "[blue]#name#":"test1", "[blue]#item_path#": "", "[blue]#shortdir#": "/temp/foo/bar/target2/runname2/test1", "[blue]#final_logf#": "megatest-rollup-test1.html",  "[blue]#status#": "PASS"}
==================



Notes
-----

Misc ...

  1. blah
  2. baz

Modified docs/manual/Makefile from [e2d37f7054] to [a64e790e18].

1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+








ASCPATH = $(shell which asciidoc)
EXEPATH = $(shell realpath $(ASCPATH))
EXEPATH = $(shell readlink -f $(ASCPATH))
BINPATH = $(shell dirname $(EXEPATH))
DISPATH = $(shell dirname $(BINPATH))

# broad_goals.csv  needed_features.csv : tables/*.dat
#         ./refdb2csv tables

# in a makefile recipe, $< denotes the first dependency; $@ the target

Modified docs/manual/megatest_manual.html from [56893fab94] to [77414f8407].

795
796
797
798
799
800
801
802
803
804












































805
806
807
808
809
810
811
795
796
797
798
799
800
801



802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852







-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







<div class="sect2">
<h3 id="_megatest_design_philosophy">Megatest Design Philosophy</h3>
<div class="paragraph"><p>Megatest is intended to provide the minimum needed resources to make
writing a suite of tests and tasks for implementing continuous build
for software, design engineering or process control (via owlfs for
example) without being specialized for any specific problem
space. Megatest in of itself does not know what constitutes a PASS or
FAIL of a test. In most cases megatest is best used in conjunction
with logpro or a similar tool to parse, analyze and decide on the test
outcome.</p></div>
FAIL of a test or task. In most cases megatest is best used in
conjunction with logpro or a similar tool to parse, analyze and decide
on the test outcome.</p></div>
<div class="ulist"><ul>
<li>
<p>
Self-checking -Repeatable strive for directed or self-checking test
   as opposed to delta based tests
</p>
</li>
<li>
<p>
Traceable - environment variables, host OS and other possibly influential
   variables are captured and kept recorded.
</p>
</li>
<li>
<p>
Immutable - once this test is run it cannot be easily overwritten or
   accidentally modified.
</p>
</li>
<li>
<p>
Repeatable - this test result can be recreated in the future
</p>
</li>
<li>
<p>
Relocatable - the testsuite or automation area can be checked out and the tests run anywhere
</p>
</li>
<li>
<p>
Encapsulated - the area where the tests run are self-contained and all inputs
   and outputs to the process can be found in the run areas.
</p>
</li>
<li>
<p>
Deployable - anyone on the team, at any site, at any time can run the flow
</p>
</li>
</ul></div>
</div>
<div class="sect2">
<h3 id="_megatest_architecture">Megatest Architecture</h3>
<div class="paragraph"><p>All data to specify the tests and configure the system is stored in
plain text files. All system state is stored in an sqlite3
database. Tests are launched using the launching system available for
the distributed compute platform in use. A template script is provided
1090
1091
1092
1093
1094
1095
1096















1097
1098
1099
1100
1101
1102
1103
1104


1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120


1121
1122

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139

1140
1141


1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155


1156
1157




































































































1158
1159
1160
1161
1162
1163
1164
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199


1200
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213

1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324







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








+
+
-
+













-
-
+
+


+

















+
-
-
+
+







-





-
+
+


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







</div>
</div>
</div>
<h1 id="_reference">Reference</h1>
<div class="sect1">
<h2 id="_megatest_config_file_settings">Megatest Config File Settings</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_disk_space_checks">Disk Space Checks</h3>
<div class="paragraph"><p>Some parameters you can put in the [setup] section of megatest.config:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># minimum space required in a run disk
minspace 10000000

# minimum space required in dbdir:
dbdir-space-required 100000

# script that takes path as parameter and returns number of bytes available:
free-space-script check-space.sh</pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_trim_trailing_spaces">Trim trailing spaces</h3>
<div class="listingblock">
<div class="content monospaced">
<pre>[configf:settings trim-trailing-spaces yes]</pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_job_submission_control">Job Submission Control</h3>
<div class="sect3">
<h3 id="_submit_jobs_to_host_types_based_on_test_name_2">Submit jobs to Host Types based on Test Name</h3>
<h4 id="_submit_jobs_to_host_types_based_on_test_name_2">Submit jobs to Host Types based on Test Name</h4>
<div class="listingblock">
<div class="title">In megatest.config</div>
<div class="content monospaced">
<pre>[host-types]
general   nbfake
remote    bsub

[launchers]
runfirst/sum% remote
% general

[jobtools]
launcher bsub
# if defined and not "no" flexi-launcher will bypass launcher unless there is no
# match.
# if defined and not "no" flexi-launcher will bypass launcher unless
# there is no host-type match.
flexi-launcher yes</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_host_types">host-types</h4>
<div class="paragraph"><p>List of host types and the commandline to run a job on that host type.</p></div>
<div class="listingblock">
<div class="title">host-type &#8658; launch command</div>
<div class="content monospaced">
<pre>general nbfake</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_launchers">launchers</h4>
<div class="listingblock">
<div class="title">test/itempath &#8658; host-type</div>
<div class="content monospaced">
<pre>runfirst/sum% remote</pre>
</div></div>
</div>
</div>
<div class="sect3">
<h4 id="_miscellaneous_setup_items">Miscellaneous Setup Items</h4>
<div class="sect2">
<h3 id="_miscellaneous_setup_items">Miscellaneous Setup Items</h3>
<div class="paragraph"><p>Attempt to rerun tests in "STUCK/DEAD", "n/a", "ZERO_ITEMS" states.</p></div>
<div class="listingblock">
<div class="title">In megatest.config</div>
<div class="content monospaced">
<pre>[setup]
reruns 5</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_run_time_limit">Run time limit</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>[setup]
runtimelim 1h 2m 3s  # this will automatically kill the test if it runs for more than 1h 2m and 3s</pre>
# this will automatically kill the test if it runs for more than 1h 2m and 3s
runtimelim 1h 2m 3s</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_tests_browser_view">Tests browser view</h4>
<div class="paragraph"><p>The tests browser (see the Run Control tab on the dashboard) has two views for displaying the tests.</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Dot (graphviz) based tree
</p>
</li>
<li>
<p>
No dot, plain listing
</p>
</li>
</ol></div>
<div class="paragraph"><p>The default is the graphviz based tree but if your tests don&#8217;t view
well in that mode then use "nodot" to turn it off.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>[setup]
nodot</pre>
</div></div>
</div>
</div>
<div class="sect2">
<h3 id="_database_settings">Database settings</h3>
<table class="tableblock frame-topbot grid-all"
style="
width:70%;
">
<caption class="title">Table 1. Database config settings in [setup] section of megatest.config</caption>
<col style="width:14%;">
<col style="width:28%;">
<col style="width:28%;">
<col style="width:28%;">
<thead>
<tr>
<th class="tableblock halign-center valign-top" >Var                       </th>
<th class="tableblock halign-left valign-top" > Purpose            </th>
<th class="tableblock halign-left valign-top" > Valid values            </th>
<th class="tableblock halign-left valign-top" > Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">delay-on-busy</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Prevent concurrent access issues</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">yes|no or not defined</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Default=no, may help on some network file systems, may slow things down also.</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">daemonize</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Daemonize the server on start</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">yes|no or not defined</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Default=no</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">faststart</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">All direct file access to sqlite db files</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">yes|no or not defined</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Default=yes, suggest no for central automated systems and yes for interactive use</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">homehost</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Start servers on this host</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">&lt;hostname&gt;</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Defaults to local host</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">hostname</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Hostname to bind to</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">&lt;hostname&gt;|-</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">On multi-homed hosts allows binding to specific hostname</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">lowport</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Start searching for a port at this portnum</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">32768</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced"></p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">required</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Server required</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">yes|no or not defined</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Default=no, force start of server always</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">server-query-threshold</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Start server when queries take longer than this</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">number in milliseconds</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Default=300</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">timeout</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">http api timeout</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">number in hours</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Default is 1 minute, do not change</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_the_testconfig_file">The testconfig File</h2>
<div class="sectionbody">
<div class="sect2">
1175
1176
1177
1178
1179
1180
1181
1182

1183
1184

1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1335
1336
1337
1338
1339
1340
1341

1342


1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353







-
+
-
-
+



-







<div class="content monospaced">
<pre>runscript main.csh</pre>
</div></div>
</div>
</div>
<div class="sect2">
<h3 id="_requirements_section">Requirements section</h3>
<div class="sect3">
<div class="listingblock">
<h4 id="_header_2">Header</h4>
<div class="listingblock">
<div class="title">Header</div>
<div class="content monospaced">
<pre>[requirements]</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_wait_on_other_tests">Wait on Other Tests</h4>
<div class="listingblock">
<div class="content monospaced">
<pre># A normal waiton waits for the prior tests to be COMPLETED
# and PASS, CHECK or WAIVED
waiton test1 test2</pre>
1216
1217
1218
1219
1220
1221
1222















1223
1224
1225
1226
1227
1228
1229
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402







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







"itemmatch" are synonyms.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>[requirements]
mode itemmatch</pre>
</div></div>
</div>
</div>
<div class="sect2">
<h3 id="_overriding_enviroment_variables">Overriding Enviroment Variables</h3>
<div class="paragraph"><p>Override variables before starting the test. Can include files (perhaps generated by megatest -envdelta or similar).</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>[pre-launch-env-vars]
VAR1 value1

# Get some generated settings
[include ../generated-vars.config]

# Use this trick to unset variables
#{scheme (unsetenv "FOOBAR")}</pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_itemmap_handling">Itemmap Handling</h3>
<div class="paragraph"><p>For cases were the dependent test has a similar but not identical
itempath to the downstream test an itemmap can allow for itemmatch
mode</p></div>
<div class="listingblock">
1289
1290
1291
1292
1293
1294
1295
1296

1297
1298
1299
1300
1301
1302
1303
1462
1463
1464
1465
1466
1467
1468

1469
1470
1471
1472
1473
1474
1475
1476







-
+







<div class="title">Testconfig for Test C</div>
<div class="content monospaced">
<pre>[requirements]
waiton A B

[itemmap]
A (\d+)/aa aa/\1
B (\d+)/bb bb/\1</pre>
B (\d+)/bb</pre>
</div></div>
<div class="listingblock">
<div class="title">Testconfig for Test D</div>
<div class="content monospaced">
<pre>[requirements]
waiton C
itemmap (\d+)/res \1/aa</pre>
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328

1329

1330
1331
1332
1333
1334
1335
1336
1488
1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502

1503
1504
1505
1506
1507
1508
1509
1510







-
+






+
-
+







<div class="listingblock">
<div class="title">Autogeneration waiton list for dynamic flow dependency trees</div>
<div class="content monospaced">
<pre>[requirements]
# With a toplevel test you may wish to generate your list
# of tests to run dynamically
#
# waiton #{shell get-valid-tests-to-run.sh}</pre>
waiton #{shell get-valid-tests-to-run.sh}</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_run_time_limit_2">Run time limit</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>[requirements]
<pre>runtimelim 1h 2m 3s  # this will automatically kill the test if it runs for more than 1h 2m and 3s</pre>
runtimelim 1h 2m 3s  # this will automatically kill the test if it runs for more than 1h 2m and 3s</pre>
</div></div>
</div>
<div class="sect3">
<h4 id="_skip">Skip</h4>
<div class="paragraph"><p>A test with a skip section will conditional skip running.</p></div>
<div class="listingblock">
<div class="title">Skip section example</div>
1484
1485
1486
1487
1488
1489
1490











































1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712








































1713
1714
1715
1716
1717
1718
1719







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





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







# Archives will be organised under these paths like this:
#  &lt;testsuite&gt;/&lt;creationdate&gt;
# Within the archive the data is structured like this:
#  &lt;target&gt;/&lt;runname&gt;/&lt;test&gt;/
archive0 /mfs/myarchive-data/adisk1</pre>
</div></div>
</div>
</div>
<div class="sect1">
<h2 id="_handling_environment_variables">Handling Environment Variables</h2>
<div class="sectionbody">
<div class="paragraph"><p>It is often necessary to capture and or manipulate environment
variables. Megatest has some facilities built in to help.</p></div>
<div class="sect2">
<h3 id="_capture_variables">Capture variables</h3>
<div class="listingblock">
<div class="title">Commands</div>
<div class="content monospaced">
<pre># capture the current enviroment into a db called envdat.db under
# the context "before"
megatest -envcap before

# capture the current environment into a db called startup.db with
# context "after"
megatest -envcap after startup.db

# write the diff from before to after
megatest -envdelta before-after -dumpmode bash</pre>
</div></div>
<div class="paragraph"><p>Dump modes include bash, csh and config. You can include config data
into megatest.config or runconfigs.config.</p></div>
<div class="listingblock">
<div class="title">Example of generating and using config data</div>
<div class="content monospaced">
<pre>megatest -envcap original
# do some stuff here
megatest -envcap munged
megatest -envdelta original-munged -dumpmode ini -o modified.config</pre>
</div></div>
<div class="paragraph"><p>Then in runconfigs.config</p></div>
<div class="listingblock">
<div class="title">Example of using modified.config in a testconfig</div>
<div class="content monospaced">
<pre>cat testconfig

[pre-launch-env-vars]
[include modified.config]</pre>
</div></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_programming_api">Programming API</h2>
<div class="sectionbody">
<div class="paragraph"><p>These routines can be called from the megatest repl.</p></div>
<table class="tableblock frame-topbot grid-all"
style="
width:70%;
">
<caption class="title">Table 1. API Server Management Calls</caption>
<col style="width:14%;">
<col style="width:28%;">
<col style="width:28%;">
<col style="width:28%;">
<thead>
<tr>
<th class="tableblock halign-center valign-top" >API Call                  </th>
<th class="tableblock halign-left valign-top" > Purpose comments   </th>
<th class="tableblock halign-left valign-top" > Returns                 </th>
<th class="tableblock halign-left valign-top" > Comments</th>
</tr>
</thead>
<tfoot>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">(rmt:login        run-id)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Verify the the version, testsuite area etc. are correct.</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">#( #t "successful login" )</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced"></p></td>
</tr>
</tfoot>
<tbody>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">(rmt:start-server run-id)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced"></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">#( success/fail   n/a )</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced"></p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock">(rmt:kill-server  run-id)</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced"></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">#( success/fail   n/a )</p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock monospaced">Works only if the server is still reachable</p></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-topbot grid-all"
style="
width:70%;
">
<caption class="title">Table 2. API Keys Related Calls</caption>
<col style="width:14%;">
<col style="width:28%;">
1654
1655
1656
1657
1658
1659
1660
1661

1662
1663
1664
1665
1666
1831
1832
1833
1834
1835
1836
1837

1838

1839
1840
1841
1842







-
+
-




</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
Version 1.0<br>
Last updated
Last updated 2016-08-20 20:32:22 MST
 2015-09-10 21:54:17 MST
</div>
</div>
</body>
</html>

Modified docs/manual/megatest_manual.txt from [38919c0414] to [49b99544b8].

26
27
28
29
30
31
32
33
34
35





















36
37
38
39
40
41
42
26
27
28
29
30
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







-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







~~~~~~~~~~~~~~~~~~~~~~~~~~

Megatest is intended to provide the minimum needed resources to make
writing a suite of tests and tasks for implementing continuous build
for software, design engineering or process control (via owlfs for
example) without being specialized for any specific problem
space. Megatest in of itself does not know what constitutes a PASS or
FAIL of a test. In most cases megatest is best used in conjunction
with logpro or a similar tool to parse, analyze and decide on the test
outcome.
FAIL of a test or task. In most cases megatest is best used in
conjunction with logpro or a similar tool to parse, analyze and decide
on the test outcome. 

 * Self-checking -Repeatable strive for directed or self-checking test
   as opposed to delta based tests

 * Traceable - environment variables, host OS and other possibly influential
   variables are captured and kept recorded.

 * Immutable - once this test is run it cannot be easily overwritten or
   accidentally modified.

 * Repeatable - this test result can be recreated in the future

 * Relocatable - the testsuite or automation area can be checked out and the tests run anywhere

 * Encapsulated - the tests run in self-contained directories and all inputs
   and outputs to the process can be found in the run areas.

 * Deployable - anyone on the team, at any site, at any time can run the flow

Megatest Architecture
~~~~~~~~~~~~~~~~~~~~~

All data to specify the tests and configure the system is stored in
plain text files. All system state is stored in an sqlite3
database. Tests are launched using the launching system available for

Modified docs/manual/reference.txt from [88bde1cc13] to [262af5e4f5].

1
2
3
4
5
6
7
















8
9
10
11
12
13
14
15
16





17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30


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







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







-
-
+
+
+
+
+













-
-
+
+








Reference
=========

Megatest Config File Settings
-----------------------------

Disk Space Checks
~~~~~~~~~~~~~~~~~

Some parameters you can put in the [setup] section of megatest.config:

-------------------
# minimum space required in a run disk 
minspace 10000000

# minimum space required in dbdir:
dbdir-space-required 100000

# script that takes path as parameter and returns number of bytes available:
free-space-script check-space.sh
-------------------

Trim trailing spaces
~~~~~~~~~~~~~~~~~~~~

------------------
[configf:settings trim-trailing-spaces yes]
------------------

Submit jobs to Host Types based on Test Name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Job Submission Control
~~~~~~~~~~~~~~~~~~~~~~

Submit jobs to Host Types based on Test Name
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.In megatest.config
------------------------
[host-types]
general   nbfake
remote    bsub

[launchers]
runfirst/sum% remote
% general

[jobtools]
launcher bsub
# if defined and not "no" flexi-launcher will bypass launcher unless there is no
# match.
# if defined and not "no" flexi-launcher will bypass launcher unless 
# there is no host-type match.
flexi-launcher yes
------------------------

host-types
^^^^^^^^^^

List of host types and the commandline to run a job on that host type.
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
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







-
+














-
+
+


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







^^^^^^^^^
.test/itempath => host-type
------------
runfirst/sum% remote
------------

Miscellaneous Setup Items
^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~

Attempt to rerun tests in "STUCK/DEAD", "n/a", "ZERO_ITEMS" states.

.In megatest.config
------------------
[setup]
reruns 5
------------------

Run time limit
^^^^^^^^^^^^^^

-----------------
[setup]
runtimelim 1h 2m 3s  # this will automatically kill the test if it runs for more than 1h 2m and 3s
# this will automatically kill the test if it runs for more than 1h 2m and 3s
runtimelim 1h 2m 3s
-----------------

Tests browser view
^^^^^^^^^^^^^^^^^^

The tests browser (see the Run Control tab on the dashboard) has two views for displaying the tests. 

. Dot (graphviz) based tree
. No dot, plain listing

The default is the graphviz based tree but if your tests don't view
well in that mode then use "nodot" to turn it off.

-----------------
[setup]
nodot
-----------------

Database settings
~~~~~~~~~~~~~~~~~

.Database config settings in [setup] section of megatest.config
[width="70%",cols="^,2m,2m,2m",frame="topbot",options="header"]
|======================
|Var                       | Purpose            | Valid values            | Comments
|delay-on-busy             | Prevent concurrent access issues | yes\|no or not defined | Default=no, may help on some network file systems, may slow things down also.
|daemonize                 | Daemonize the server on start | yes\|no or not defined | Default=no
|faststart		   | All direct file access to sqlite db files | yes\|no or not defined | Default=yes, suggest no for central automated systems and yes for interactive use
|homehost 		   | Start servers on this host | <hostname> | Defaults to local host
|hostname		   | Hostname to bind to | <hostname>\|-	  | On multi-homed hosts allows binding to specific hostname
|lowport		   | Start searching for a port at this portnum| 32768 | 
|required		   | Server required    | yes\|no or not defined  | Default=no, force start of server always
|server-query-threshold	   | Start server when queries take longer than this | number in milliseconds | Default=300
|timeout		   | http api timeout 	| number in hours	  | Default is 1 minute, do not change
|======================

The testconfig File
-------------------

Setup section
~~~~~~~~~~~~~

Header
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
141
142
143
144
145
146
147

148


149
150
151
152
153
154
155







-
+
-
-







-------------------
runscript main.csh
-------------------

Requirements section
~~~~~~~~~~~~~~~~~~~~

Header
.Header
^^^^^^

-------------------
[requirements]
-------------------

Wait on Other Tests
^^^^^^^^^^^^^^^^^^^

130
131
132
133
134
135
136
















137
138
139
140
141
142
143
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







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







was historically called "itemwait" mode. The terms "itemwait" and
"itemmatch" are synonyms.

-------------------
[requirements]
mode itemmatch
-------------------

Overriding Enviroment Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Override variables before starting the test. Can include files (perhaps generated by megatest -envdelta or similar).

--------------------
[pre-launch-env-vars]
VAR1 value1

# Get some generated settings
[include ../generated-vars.config]

# Use this trick to unset variables
#{scheme (unsetenv "FOOBAR")}
--------------------

Itemmap Handling
~~~~~~~~~~~~~~~~

For cases were the dependent test has a similar but not identical
itempath to the downstream test an itemmap can allow for itemmatch
mode
184
185
186
187
188
189
190

191

192
193
194
195
196
197
198
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267







+
-
+







.Testconfig for Test C
----------------------
[requirements]
waiton A B

[itemmap]
A (\d+)/aa aa/\1
B (\d+)/bb 
B (\d+)/bb --------------------
----------------------

.Testconfig for Test D
----------------------
[requirements]
waiton C
itemmap (\d+)/res \1/aa
----------------------
382
383
384
385
386
387
388
389


390
391












392


393

394



395
396
397
398
399
400
401
402



























403
404
405
406
407
408
409
410
411
412
413
414
451
452
453
454
455
456
457
458
459
460


461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

476
477
478
479
480








481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519








+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
+

+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













# Archives will be organised under these paths like this:
#  <testsuite>/<creationdate>
# Within the archive the data is structured like this:
#  <target>/<runname>/<test>/
archive0 /mfs/myarchive-data/adisk1
--------------

Handling Environment Variables
------------------------------
Programming API
---------------

It is often necessary to capture and or manipulate environment
variables. Megatest has some facilities built in to help.

Capture variables
~~~~~~~~~~~~~~~~~

.Commands
------------------------------
# capture the current enviroment into a db called envdat.db under
# the context "before"
megatest -envcap before

# capture the current environment into a db called startup.db with 
# context "after"
These routines can be called from the megatest repl. 
megatest -envcap after startup.db

# write the diff from before to after
megatest -envdelta before-after -dumpmode bash
------------------------------
.API Server Management Calls
[width="70%",cols="^,2m,2m,2m",frame="topbot",options="header,footer"]
|======================
|API Call                  | Purpose comments   | Returns                 | Comments
|(rmt:start-server run-id) |                    | #( success/fail   n/a ) | 
|(rmt:kill-server  run-id) |                    | #( success/fail   n/a ) | Works only if the server is still reachable
|(rmt:login        run-id) | Verify the the version, testsuite area etc. are correct. | #( #t "successful login" ) |
|======================

Dump modes include bash, csh and config. You can include config data
into megatest.config or runconfigs.config.

.Example of generating and using config data
------------------------------
megatest -envcap original
# do some stuff here
megatest -envcap munged
megatest -envdelta original-munged -dumpmode ini -o modified.config
------------------------------

Then in runconfigs.config

.Example of using modified.config in a testconfig
------------------------------
cat testconfig

[pre-launch-env-vars]
[include modified.config]
------------------------------


Programming API
---------------

These routines can be called from the megatest repl. 

.API Keys Related Calls
[width="70%",cols="^,2m,2m,2m",frame="topbot",options="header,footer"]
|======================
|API Call                        | Purpose comments   | Returns                 | Comments
|(rmt:get-keys run-id)           |                    | ( key1 key2 ... )       | 
| (rmt:get-key-val-pairs run-id) |                    | #t=success/#f=fail      | Works only if the server is still reachable
|======================


:numbered!:

Modified docs/manual/server.png from [524d8b2847] to [a508d3edd1].

cannot compute difference between binary files

Modified docs/megatest-about.svg from [5cfe75c45c] to [e2e8c71c8d].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
















































































































































































21
22
23



24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304





















































305
306
307
308
309
310
311
312
313
314
315





























































































316
317
318
319




























320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380







































































































381
382
383
384













































385
386
387
























388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412






























































































































413
414
415
416













































417
418
419
420




421
422
423
424
425
426
427
428
429
430
431
432






























































































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
459
460
461





























































































462
463
464
465
466
467
468
469
470
471
472
473


























































474
475
476
477
478
479
480












































481
482
483
484
485
486
487
488
489
490
491




























































































492




















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511




512











513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586














587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685











686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737


































































































































































738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
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
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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759



1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804











1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855











1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908











1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001




2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029










































2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292



















2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395




2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440



2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464

























2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590




2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635




2636
2637
2638
2639












2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
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
2731
2732
2733











2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794







2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833











2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926












2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984







2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028











3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="744.09448819"
   height="1052.3622047"
   id="svg2"
   version="1.1"
   inkscape:version="0.48.3.1 r9886"
   sodipodi:docname="megatest-about.svg">
  <defs
     id="defs4">
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="744.094px" height="1052.363px" viewBox="0 0 744.094 1052.363" enable-background="new 0 0 744.094 1052.363"
	 xml:space="preserve">
<g id="svg2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:cc="http://creativecommons.org/ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" inkscape:version="0.91 r13725" sodipodi:docname="megatest-about.svg">
	
		<sodipodi:namedview  borderopacity="1.0" inkscape:cy="534.40312" bordercolor="#666666" pagecolor="#ffffff" inkscape:cx="263.11623" inkscape:zoom="0.7" showgrid="false" id="base" inkscape:window-width="1527" inkscape:window-height="1016" inkscape:pageopacity="0.0" inkscape:document-units="px" inkscape:pageshadow="2" inkscape:window-x="2114" inkscape:current-layer="layer1" inkscape:window-y="55" inkscape:window-maximized="0">
		</sodipodi:namedview>
	<g id="flowRoot2985">
	</g>
	
		<image display="none" overflow="visible" enable-background="new    " width="137" height="70" id="image3139_1_" xlink:href="F1A10024.png"  transform="matrix(1.2499 0 0 1.2499 65.0952 42.7969)">
	</image>
	<g>
		<path fill="#231F20" d="M241.394,125.221V72.085h16.057l9.642,36.246l9.532-36.246h16.093v53.136h-9.967V83.394l-10.548,41.828
			h-10.33l-10.511-41.828v41.828H241.394z"/>
		<path fill="#231F20" d="M303.374,125.221V72.085h39.399v8.989h-28.67v11.78h26.677v8.953h-26.677v14.462h29.685v8.953H303.374z"/>
		<path fill="#231F20" d="M377.606,105.685v-8.953h23.125v21.167c-2.248,2.175-5.504,4.09-9.77,5.745
			c-4.264,1.655-8.584,2.483-12.957,2.483c-5.558,0-10.403-1.166-14.535-3.498c-4.132-2.332-7.237-5.666-9.315-10.003
			c-2.079-4.337-3.117-9.055-3.117-14.154c0-5.533,1.16-10.451,3.479-14.752c2.32-4.301,5.714-7.599,10.185-9.895
			c3.407-1.764,7.648-2.646,12.722-2.646c6.598,0,11.75,1.384,15.459,4.15c3.709,2.767,6.096,6.591,7.158,11.472l-10.656,1.993
			c-0.75-2.609-2.156-4.669-4.223-6.18c-2.066-1.51-4.645-2.265-7.738-2.265c-4.688,0-8.415,1.486-11.182,4.458
			c-2.767,2.972-4.15,7.382-4.15,13.229c0,6.307,1.401,11.037,4.205,14.19c2.803,3.153,6.475,4.73,11.018,4.73
			c2.248,0,4.5-0.44,6.76-1.323c2.26-0.882,4.199-1.951,5.818-3.208v-6.742H377.606z"/>
		<path fill="#231F20" d="M458.542,125.221h-11.671l-4.64-12.07h-21.24l-4.386,12.07h-11.381l20.696-53.136h11.345L458.542,125.221z
			 M438.789,104.199l-7.321-19.718l-7.177,19.718H438.789z"/>
		<path fill="#231F20" d="M470.684,125.221V81.074h-15.767v-8.989h42.227v8.989h-15.73v44.147H470.684z"/>
		<path fill="#231F20" d="M504.067,125.221V72.085h39.399v8.989h-28.671v11.78h26.678v8.953h-26.678v14.462h29.686v8.953H504.067z"
			/>
		<path fill="#231F20" d="M550.861,107.932l10.438-1.015c0.628,3.504,1.902,6.078,3.824,7.72c1.921,1.644,4.512,2.465,7.774,2.465
			c3.455,0,6.059-0.73,7.811-2.193c1.752-1.461,2.628-3.171,2.628-5.129c0-1.256-0.368-2.325-1.105-3.208
			c-0.737-0.882-2.023-1.649-3.86-2.302c-1.257-0.435-4.12-1.208-8.59-2.32c-5.751-1.425-9.786-3.177-12.106-5.255
			c-3.262-2.923-4.893-6.488-4.893-10.692c0-2.706,0.767-5.238,2.302-7.594c1.534-2.356,3.745-4.15,6.633-5.382
			c2.887-1.232,6.373-1.849,10.457-1.849c6.669,0,11.688,1.462,15.06,4.386c3.371,2.924,5.141,6.827,5.311,11.708l-10.729,0.471
			c-0.459-2.73-1.443-4.694-2.954-5.89c-1.51-1.196-3.775-1.794-6.796-1.794c-3.117,0-5.558,0.641-7.321,1.921
			c-1.136,0.822-1.704,1.921-1.704,3.298c0,1.257,0.531,2.332,1.596,3.226c1.353,1.136,4.639,2.319,9.858,3.552
			s9.079,2.507,11.58,3.824c2.501,1.317,4.459,3.117,5.872,5.4c1.414,2.284,2.12,5.105,2.12,8.463c0,3.045-0.846,5.896-2.537,8.554
			c-1.691,2.658-4.084,4.634-7.177,5.926c-3.093,1.292-6.947,1.939-11.562,1.939c-6.719,0-11.877-1.552-15.478-4.658
			C553.711,118.401,551.561,113.876,550.861,107.932z"/>
		<path fill="#231F20" d="M615.051,125.221V81.074h-15.767v-8.989h42.227v8.989h-15.73v44.147H615.051z"/>
	</g>
</g>
<g id="Layer_3">
	<path fill="#E6E7E8" d="M642.453,974.71c0,9.836-7.367,17.807-16.456,17.807h-501.9c-9.088,0-16.455-7.971-16.455-17.807V367.856
		c0-9.833,7.367-17.805,16.455-17.805h501.9c9.089,0,16.456,7.971,16.456,17.805V974.71z"/>
	<g>
		<path fill="#231F20" d="M249.928,194.867l8.521-15.032h2.369l2.481,15.032h-1.948l-0.728-4.327h-6.081l-2.41,4.327H249.928z
			 M255.403,188.991h4.973l-0.584-3.773c-0.226-1.497-0.366-2.745-0.42-3.743c-0.342,0.861-0.841,1.883-1.497,3.066L255.403,188.991
			z"/>
		<path fill="#231F20" d="M272.486,192.898c-1.306,1.477-2.642,2.215-4.009,2.215c-0.841,0-1.52-0.241-2.035-0.723
			c-0.517-0.482-0.774-1.072-0.774-1.769c0-0.458,0.116-1.244,0.349-2.358l1.313-6.286h1.856l-1.456,6.962
			c-0.123,0.581-0.185,1.032-0.185,1.354c0,0.41,0.125,0.73,0.375,0.958c0.249,0.229,0.617,0.344,1.102,0.344
			c0.52,0,1.027-0.126,1.523-0.379c0.495-0.253,0.923-0.595,1.281-1.025c0.359-0.431,0.651-0.94,0.877-1.528
			c0.15-0.376,0.325-1.036,0.523-1.979l0.984-4.707h1.856l-2.276,10.89h-1.712L272.486,192.898z"/>
		<path fill="#231F20" d="M281.069,193.359l-0.308,1.518c-0.444,0.116-0.875,0.174-1.292,0.174c-0.738,0-1.326-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.089-0.79,0.267-1.651l1.323-6.327h-1.466l0.297-1.436h1.466l0.564-2.676
			l2.123-1.282l-0.831,3.958h1.825l-0.308,1.436h-1.815l-1.261,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C280.382,193.482,280.748,193.441,281.069,193.359z"/>
		<path fill="#231F20" d="M282.894,190.734c0-2.126,0.625-3.886,1.876-5.281c1.032-1.148,2.386-1.723,4.061-1.723
			c1.313,0,2.37,0.41,3.173,1.23s1.205,1.928,1.205,3.322c0,1.251-0.253,2.415-0.759,3.491c-0.506,1.077-1.226,1.902-2.158,2.477
			c-0.934,0.574-1.916,0.861-2.948,0.861c-0.848,0-1.619-0.181-2.313-0.543s-1.224-0.875-1.589-1.538
			C283.077,192.368,282.894,191.603,282.894,190.734z M284.75,190.55c0,1.025,0.246,1.803,0.738,2.333
			c0.492,0.53,1.118,0.795,1.876,0.795c0.396,0,0.79-0.08,1.179-0.241c0.39-0.16,0.752-0.405,1.087-0.733s0.621-0.703,0.856-1.123
			c0.236-0.421,0.426-0.874,0.569-1.359c0.212-0.677,0.318-1.326,0.318-1.948c0-0.984-0.248-1.749-0.744-2.292
			c-0.496-0.544-1.119-0.815-1.871-0.815c-0.581,0-1.111,0.139-1.589,0.415c-0.479,0.277-0.911,0.682-1.297,1.215
			s-0.67,1.154-0.851,1.861C284.84,189.366,284.75,189.996,284.75,190.55z"/>
		<path fill="#231F20" d="M294.235,194.867l2.276-10.89h1.856l-0.379,1.794c0.69-0.772,1.307-1.306,1.851-1.6
			c0.543-0.294,1.133-0.441,1.769-0.441c0.677,0,1.242,0.18,1.697,0.538c0.454,0.359,0.753,0.86,0.897,1.502
			c0.554-0.684,1.136-1.195,1.749-1.533c0.611-0.339,1.256-0.508,1.933-0.508c0.909,0,1.591,0.215,2.046,0.646
			c0.454,0.431,0.682,1.036,0.682,1.815c0,0.335-0.079,0.889-0.236,1.661l-1.466,7.014h-1.856l1.497-7.198
			c0.13-0.588,0.195-1.008,0.195-1.261c0-0.355-0.113-0.636-0.338-0.841s-0.543-0.308-0.954-0.308c-0.554,0-1.118,0.167-1.692,0.502
			s-1.02,0.774-1.338,1.317c-0.317,0.544-0.596,1.379-0.835,2.507l-1.107,5.281h-1.856l1.538-7.352
			c0.109-0.499,0.164-0.854,0.164-1.066c0-0.355-0.111-0.643-0.333-0.861c-0.223-0.219-0.511-0.328-0.867-0.328
			c-0.526,0-1.079,0.167-1.656,0.502c-0.578,0.335-1.048,0.802-1.41,1.399c-0.362,0.599-0.66,1.451-0.892,2.559l-1.077,5.147
			H294.235z"/>
		<path fill="#231F20" d="M319.08,193.513c-0.643,0.554-1.261,0.959-1.856,1.215c-0.595,0.257-1.23,0.385-1.907,0.385
			c-1.005,0-1.815-0.295-2.43-0.887s-0.923-1.349-0.923-2.271c0-0.608,0.139-1.146,0.415-1.615c0.277-0.468,0.645-0.844,1.103-1.128
			c0.458-0.283,1.019-0.487,1.682-0.61c0.417-0.082,1.208-0.147,2.374-0.195c1.165-0.048,2.001-0.171,2.507-0.369
			c0.144-0.506,0.215-0.926,0.215-1.261c0-0.431-0.157-0.769-0.472-1.015c-0.431-0.342-1.06-0.513-1.887-0.513
			c-0.779,0-1.417,0.173-1.913,0.518c-0.496,0.346-0.856,0.836-1.082,1.472l-1.876-0.164c0.383-1.08,0.989-1.907,1.82-2.481
			c0.83-0.574,1.878-0.861,3.143-0.861c1.347,0,2.413,0.321,3.199,0.964c0.602,0.479,0.902,1.101,0.902,1.866
			c0,0.581-0.085,1.254-0.256,2.02l-0.605,2.707c-0.191,0.861-0.287,1.562-0.287,2.102c0,0.342,0.075,0.834,0.226,1.477h-1.876
			C319.193,194.511,319.121,194.06,319.08,193.513z M319.767,189.35c-0.26,0.103-0.539,0.181-0.835,0.236
			c-0.298,0.055-0.795,0.113-1.492,0.174c-1.08,0.096-1.842,0.217-2.287,0.364s-0.779,0.381-1.005,0.702s-0.338,0.677-0.338,1.066
			c0,0.52,0.18,0.947,0.538,1.282c0.359,0.335,0.87,0.502,1.533,0.502c0.615,0,1.207-0.162,1.774-0.487
			c0.567-0.324,1.015-0.777,1.343-1.358S319.583,190.423,319.767,189.35z"/>
		<path fill="#231F20" d="M327.755,193.359l-0.308,1.518c-0.444,0.116-0.875,0.174-1.292,0.174c-0.738,0-1.326-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.089-0.79,0.267-1.651l1.323-6.327h-1.466l0.297-1.436h1.466l0.564-2.676
			l2.123-1.282l-0.831,3.958h1.825l-0.308,1.436h-1.815l-1.261,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C327.068,193.482,327.434,193.441,327.755,193.359z"/>
		<path fill="#231F20" d="M329.18,194.867l2.276-10.89h1.856l-2.276,10.89H329.18z M331.887,181.937l0.441-2.102h1.846l-0.441,2.102
			H331.887z"/>
		<path fill="#231F20" d="M334.246,190.734c0-2.126,0.625-3.886,1.876-5.281c1.032-1.148,2.386-1.723,4.061-1.723
			c1.313,0,2.37,0.41,3.173,1.23s1.205,1.928,1.205,3.322c0,1.251-0.253,2.415-0.759,3.491c-0.506,1.077-1.226,1.902-2.158,2.477
			c-0.934,0.574-1.916,0.861-2.948,0.861c-0.848,0-1.619-0.181-2.313-0.543s-1.224-0.875-1.589-1.538
			C334.428,192.368,334.246,191.603,334.246,190.734z M336.102,190.55c0,1.025,0.246,1.803,0.738,2.333
			c0.492,0.53,1.118,0.795,1.876,0.795c0.396,0,0.79-0.08,1.179-0.241c0.39-0.16,0.752-0.405,1.087-0.733s0.621-0.703,0.856-1.123
			c0.236-0.421,0.426-0.874,0.569-1.359c0.212-0.677,0.318-1.326,0.318-1.948c0-0.984-0.248-1.749-0.744-2.292
			c-0.496-0.544-1.119-0.815-1.871-0.815c-0.581,0-1.111,0.139-1.589,0.415c-0.479,0.277-0.911,0.682-1.297,1.215
			s-0.67,1.154-0.851,1.861C336.192,189.366,336.102,189.996,336.102,190.55z"/>
		<path fill="#231F20" d="M345.597,194.867l2.276-10.89h1.682l-0.4,1.897c0.731-0.745,1.415-1.289,2.051-1.63
			s1.285-0.513,1.948-0.513c0.882,0,1.574,0.239,2.077,0.718c0.502,0.479,0.753,1.118,0.753,1.917c0,0.403-0.089,1.039-0.267,1.907
			l-1.384,6.593h-1.856l1.446-6.901c0.144-0.67,0.215-1.166,0.215-1.487c0-0.362-0.125-0.656-0.375-0.882s-0.61-0.338-1.082-0.338
			c-0.95,0-1.796,0.342-2.538,1.025c-0.742,0.684-1.287,1.856-1.636,3.517l-1.056,5.065H345.597z"/>
	</g>
	<g>
		<path fill="#E6E7E8" d="M244.237,193.64c0,5.657-4.586,10.243-10.243,10.243h-6.005c-5.657,0-10.242-4.586-10.242-10.243v-6.004
			c0-5.656,4.585-10.243,10.242-10.243h6.005c5.656,0,10.243,4.586,10.243,10.243V193.64z"/>
		<path fill="#58595B" d="M244.437,193.65c0,0-0.021,0.344-0.061,0.99c-0.086,0.658-0.235,1.625-0.68,2.771
			c-0.44,1.141-1.159,2.484-2.347,3.745c-1.187,1.247-2.846,2.433-4.966,3.041c-1.035,0.299-2.258,0.43-3.34,0.461
			c-1.116,0.061-2.271,0.121-3.457,0.162c-0.616,0.017-1.144,0.062-1.854,0.057c-0.31-0.011-0.6-0.006-0.93-0.03
			c-0.352-0.044-0.707-0.089-1.063-0.134c-1.356-0.244-2.7-0.745-3.929-1.499c-2.461-1.492-4.431-4.048-5.16-7.06
			c-0.18-0.75-0.291-1.52-0.326-2.298c-0.038-0.736-0.042-1.385-0.066-2.084c-0.037-1.375-0.075-2.756-0.112-4.136
			c-0.115-3.198,1.195-6.438,3.447-8.726c2.214-2.329,5.475-3.628,8.532-3.601c1.294,0.011,2.567-0.003,3.813,0.037
			c0.623,0.014,1.239,0.028,1.848,0.042l0.329,0.009l0.227,0.021l0.451,0.041c0.266,0.013,0.665,0.081,1.042,0.15
			c2.885,0.548,5.103,2.154,6.566,4.005c1.468,1.864,2.126,3.942,2.338,5.732c0.038,0.452,0.07,0.888,0.072,1.305
			c-0.02,0.416-0.028,0.83-0.059,1.191c-0.052,0.728-0.101,1.397-0.144,2c-0.088,1.208-0.121,2.157-0.141,2.805
			c-0.02,0.647-0.031,0.992-0.031,0.992L244.437,193.65z M244.037,193.64c0,0-0.011-0.345-0.031-0.992
			c-0.02-0.647-0.053-1.597-0.141-2.805c-0.112-1.208-0.081-2.718-0.583-4.187c-0.509-1.483-1.469-2.995-2.887-4.127
			c-0.696-0.576-1.505-1.036-2.355-1.419c-0.846-0.355-1.845-0.582-2.711-0.662c-0.208-0.022-0.398-0.058-0.735-0.05l-0.453-0.005
			l-0.228-0.002c-0.1-0.002,0.104,0.003,0.073,0.002l-0.028,0.001l-0.057,0.001l-0.114,0.003c-0.608,0.014-1.225,0.028-1.848,0.042
			c-1.246,0.04-2.519,0.025-3.813,0.037c-2.12-0.035-4.236,0.659-5.934,2.134c-1.695,1.455-2.771,3.684-2.845,6.026
			c-0.038,1.38-0.075,2.761-0.112,4.136c-0.015,0.676-0.047,1.4-0.047,2.032c-0.005,0.591,0.047,1.179,0.15,1.757
			c0.425,2.318,1.836,4.41,3.731,5.707c0.944,0.654,2.001,1.117,3.086,1.375l0.774,0.147c0.283,0.038,0.606,0.051,0.904,0.078
			c0.506,0.037,1.182,0.051,1.752,0.078c1.187,0.041,2.341,0.101,3.457,0.162c1.15,0.075,2.095,0.098,3.082-0.056
			c1.941-0.3,3.615-1.204,4.835-2.293c1.225-1.099,1.973-2.377,2.412-3.474c0.467-1.102,0.542-2.046,0.626-2.664
			c0.025-0.646,0.039-0.992,0.039-0.992L244.037,193.64z"/>
	</g>
	<g>
		<path fill="#231F20" d="M322.007,228.647c0.506,0.602,1.189,1.183,2.051,1.743l-0.892,1.189c-0.909-0.595-1.726-1.316-2.451-2.164
			c-1.019,0.479-1.989,0.718-2.912,0.718c-0.738,0-1.548-0.14-2.43-0.42s-1.62-0.704-2.215-1.271s-1.061-1.297-1.4-2.189
			c-0.338-0.892-0.507-1.878-0.507-2.958c0-1.306,0.25-2.557,0.749-3.753c0.417-0.984,0.959-1.833,1.625-2.548
			c0.667-0.714,1.396-1.267,2.189-1.656c1.046-0.513,2.177-0.769,3.394-0.769c1.873,0,3.399,0.61,4.579,1.831
			c1.179,1.22,1.769,2.855,1.769,4.906c0,1.511-0.314,2.904-0.943,4.179S323.115,227.813,322.007,228.647z M320.777,227.355
			c0.827-0.643,1.497-1.526,2.01-2.65s0.769-2.295,0.769-3.512c0-1.518-0.417-2.722-1.251-3.615
			c-0.834-0.892-1.856-1.338-3.066-1.338c-1.012,0-1.986,0.296-2.922,0.887c-0.937,0.592-1.685,1.458-2.246,2.6
			s-0.841,2.386-0.841,3.732c0,1.688,0.526,2.994,1.579,3.917c0.82,0.718,1.699,1.077,2.635,1.077c0.745,0,1.415-0.116,2.01-0.349
			c-0.622-0.567-1.261-1.022-1.917-1.364l0.728-1.251c0.444,0.191,0.846,0.419,1.205,0.682
			C319.829,226.434,320.264,226.829,320.777,227.355z"/>
		<path fill="#231F20" d="M333.779,227.888c-1.306,1.477-2.642,2.215-4.009,2.215c-0.841,0-1.52-0.241-2.035-0.723
			c-0.517-0.482-0.774-1.072-0.774-1.769c0-0.458,0.116-1.244,0.349-2.358l1.313-6.286h1.856l-1.456,6.962
			c-0.123,0.581-0.185,1.032-0.185,1.354c0,0.41,0.125,0.73,0.375,0.958c0.249,0.229,0.617,0.344,1.102,0.344
			c0.52,0,1.027-0.126,1.523-0.379c0.495-0.253,0.923-0.595,1.281-1.025c0.359-0.431,0.651-0.94,0.877-1.528
			c0.15-0.376,0.325-1.036,0.523-1.979l0.984-4.707h1.856l-2.276,10.89h-1.712L333.779,227.888z"/>
		<path fill="#231F20" d="M345.366,228.503c-0.643,0.554-1.261,0.959-1.856,1.215c-0.595,0.257-1.23,0.385-1.907,0.385
			c-1.005,0-1.815-0.295-2.43-0.887s-0.923-1.349-0.923-2.271c0-0.608,0.139-1.146,0.415-1.615c0.277-0.468,0.645-0.844,1.103-1.128
			c0.458-0.283,1.019-0.487,1.682-0.61c0.417-0.082,1.208-0.147,2.374-0.195c1.165-0.048,2.001-0.171,2.507-0.369
			c0.144-0.506,0.215-0.926,0.215-1.261c0-0.431-0.157-0.769-0.472-1.015c-0.431-0.342-1.06-0.513-1.887-0.513
			c-0.779,0-1.417,0.173-1.913,0.518c-0.496,0.346-0.856,0.836-1.082,1.472l-1.876-0.164c0.383-1.08,0.989-1.907,1.82-2.481
			c0.83-0.574,1.878-0.861,3.143-0.861c1.347,0,2.413,0.321,3.199,0.964c0.602,0.479,0.902,1.101,0.902,1.866
			c0,0.581-0.085,1.254-0.256,2.02l-0.605,2.707c-0.191,0.861-0.287,1.562-0.287,2.102c0,0.342,0.075,0.834,0.226,1.477h-1.876
			C345.479,229.501,345.407,229.05,345.366,228.503z M346.053,224.34c-0.26,0.103-0.539,0.181-0.835,0.236
			c-0.298,0.055-0.795,0.113-1.492,0.174c-1.08,0.096-1.842,0.217-2.287,0.364s-0.779,0.381-1.005,0.702s-0.338,0.677-0.338,1.066
			c0,0.52,0.18,0.947,0.538,1.282c0.359,0.335,0.87,0.502,1.533,0.502c0.615,0,1.207-0.162,1.774-0.487
			c0.567-0.324,1.015-0.777,1.343-1.358S345.868,225.414,346.053,224.34z"/>
		<path fill="#231F20" d="M349.56,229.857l3.138-15.032h1.856l-3.138,15.032H349.56z"/>
		<path fill="#231F20" d="M354.297,229.857l2.276-10.89h1.856l-2.276,10.89H354.297z M357.004,216.927l0.441-2.102h1.846
			l-0.441,2.102H357.004z"/>
		<path fill="#231F20" d="M363.372,228.35l-0.308,1.518c-0.444,0.116-0.875,0.174-1.292,0.174c-0.738,0-1.326-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.089-0.79,0.267-1.651l1.323-6.327h-1.466l0.297-1.436h1.466l0.564-2.676
			l2.123-1.282l-0.831,3.958h1.825l-0.308,1.436h-1.815l-1.261,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C362.685,228.473,363.05,228.432,363.372,228.35z"/>
		<path fill="#231F20" d="M364.171,234.061l0.113-1.743c0.383,0.109,0.755,0.164,1.118,0.164c0.376,0,0.68-0.085,0.913-0.256
			c0.301-0.226,0.629-0.649,0.984-1.271l0.595-1.066l-1.815-10.92h1.825l0.82,5.506c0.164,1.087,0.304,2.174,0.42,3.261l4.871-8.767
			h1.938l-6.942,12.335c-0.67,1.203-1.265,2-1.784,2.389s-1.118,0.584-1.794,0.584C365.002,234.276,364.582,234.205,364.171,234.061
			z"/>
		<path fill="#231F20" d="M379.306,229.857l8.521-15.032h2.369l2.482,15.032h-1.949L390,225.53h-6.08l-2.41,4.327H379.306z
			 M384.782,223.981h4.973l-0.584-3.773c-0.225-1.497-0.365-2.745-0.42-3.743c-0.342,0.861-0.842,1.883-1.498,3.066L384.782,223.981
			z"/>
		<path fill="#231F20" d="M394.604,226.135l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
    <linearGradient
       inkscape:collect="always"
       id="linearGradient4210">
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
      <stop
         style="stop-color:#000000;stop-opacity:1;"
         offset="0"
         id="stop4212" />
      <stop
         style="stop-color:#000000;stop-opacity:0;"
         offset="1"
         id="stop4214" />
    </linearGradient>
    <linearGradient
			c-1.258,0-2.328-0.311-3.209-0.933C394.973,228.548,394.556,227.536,394.604,226.135z"/>
		<path fill="#231F20" d="M405.104,226.135l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
			c-1.258,0-2.328-0.311-3.209-0.933C405.473,228.548,405.056,227.536,405.104,226.135z"/>
		<path fill="#231F20" d="M422.864,227.888c-1.306,1.477-2.642,2.215-4.009,2.215c-0.841,0-1.52-0.241-2.035-0.723
			c-0.517-0.482-0.774-1.072-0.774-1.769c0-0.458,0.116-1.244,0.349-2.358l1.313-6.286h1.856l-1.457,6.962
			c-0.123,0.581-0.184,1.032-0.184,1.354c0,0.41,0.124,0.73,0.374,0.958c0.249,0.229,0.616,0.344,1.103,0.344
			c0.519,0,1.026-0.126,1.522-0.379c0.495-0.253,0.923-0.595,1.281-1.025c0.359-0.431,0.651-0.94,0.877-1.528
			c0.15-0.376,0.324-1.036,0.522-1.979l0.984-4.707h1.856l-2.276,10.89h-1.713L422.864,227.888z"/>
		<path fill="#231F20" d="M427.11,229.857l2.276-10.89h1.641l-0.462,2.225c0.561-0.841,1.109-1.463,1.646-1.866
			c0.536-0.403,1.085-0.605,1.646-0.605c0.369,0,0.823,0.133,1.364,0.4l-0.76,1.723c-0.321-0.232-0.673-0.349-1.056-0.349
			c-0.649,0-1.316,0.362-1.999,1.087c-0.685,0.725-1.221,2.027-1.61,3.907l-0.923,4.368H427.11z"/>
		<path fill="#231F20" d="M441.445,228.503c-0.643,0.554-1.262,0.959-1.855,1.215c-0.596,0.257-1.23,0.385-1.908,0.385
			c-1.004,0-1.814-0.295-2.43-0.887s-0.923-1.349-0.923-2.271c0-0.608,0.139-1.146,0.415-1.615c0.277-0.468,0.645-0.844,1.103-1.128
			c0.458-0.283,1.019-0.487,1.682-0.61c0.417-0.082,1.208-0.147,2.374-0.195c1.165-0.048,2.001-0.171,2.507-0.369
			c0.144-0.506,0.216-0.926,0.216-1.261c0-0.431-0.158-0.769-0.473-1.015c-0.43-0.342-1.06-0.513-1.887-0.513
			c-0.779,0-1.416,0.173-1.912,0.518c-0.495,0.346-0.855,0.836-1.082,1.472l-1.876-0.164c0.383-1.08,0.989-1.907,1.82-2.481
			c0.83-0.574,1.878-0.861,3.143-0.861c1.347,0,2.413,0.321,3.199,0.964c0.602,0.479,0.902,1.101,0.902,1.866
			c0,0.581-0.086,1.254-0.257,2.02l-0.604,2.707c-0.191,0.861-0.287,1.562-0.287,2.102c0,0.342,0.075,0.834,0.226,1.477h-1.877
			C441.558,229.501,441.486,229.05,441.445,228.503z M442.132,224.34c-0.261,0.103-0.539,0.181-0.836,0.236
			c-0.298,0.055-0.795,0.113-1.492,0.174c-1.08,0.096-1.843,0.217-2.287,0.364s-0.779,0.381-1.004,0.702
			c-0.227,0.321-0.339,0.677-0.339,1.066c0,0.52,0.18,0.947,0.538,1.282c0.359,0.335,0.87,0.502,1.533,0.502
			c0.615,0,1.206-0.162,1.773-0.487c0.567-0.324,1.016-0.777,1.344-1.358S441.947,225.414,442.132,224.34z"/>
		<path fill="#231F20" d="M445.782,229.857l2.276-10.89h1.682l-0.399,1.897c0.73-0.745,1.414-1.289,2.051-1.63
			c0.635-0.342,1.284-0.513,1.947-0.513c0.883,0,1.574,0.239,2.077,0.718c0.502,0.479,0.753,1.118,0.753,1.917
			c0,0.403-0.089,1.039-0.266,1.907l-1.385,6.593h-1.855l1.445-6.901c0.144-0.67,0.215-1.166,0.215-1.487
			c0-0.362-0.124-0.656-0.374-0.882c-0.249-0.226-0.61-0.338-1.081-0.338c-0.951,0-1.797,0.342-2.538,1.025
			c-0.742,0.684-1.287,1.856-1.636,3.517l-1.057,5.065H445.782z"/>
		<path fill="#231F20" d="M464.977,225.889l1.856,0.195c-0.465,1.36-1.126,2.371-1.984,3.03c-0.857,0.66-1.834,0.989-2.927,0.989
			c-1.184,0-2.142-0.383-2.877-1.148c-0.734-0.766-1.102-1.835-1.102-3.209c0-1.189,0.235-2.358,0.707-3.507s1.146-2.021,2.025-2.62
			c0.878-0.598,1.881-0.897,3.01-0.897c1.168,0,2.095,0.33,2.778,0.989c0.684,0.66,1.025,1.533,1.025,2.62l-1.825,0.123
			c-0.007-0.69-0.207-1.23-0.6-1.62c-0.394-0.39-0.911-0.584-1.554-0.584c-0.745,0-1.392,0.236-1.938,0.708
			s-0.976,1.188-1.286,2.148c-0.312,0.96-0.467,1.885-0.467,2.773c0,0.93,0.205,1.627,0.615,2.092s0.916,0.697,1.518,0.697
			s1.178-0.229,1.728-0.687C464.231,227.522,464.663,226.825,464.977,225.889z"/>
		<path fill="#231F20" d="M475.959,226.155l1.805,0.185c-0.26,0.896-0.856,1.747-1.789,2.553c-0.934,0.807-2.046,1.21-3.338,1.21
			c-0.807,0-1.547-0.187-2.22-0.559c-0.674-0.373-1.187-0.915-1.538-1.625c-0.353-0.711-0.528-1.521-0.528-2.43
			c0-1.189,0.275-2.343,0.825-3.461c0.551-1.117,1.263-1.948,2.139-2.491c0.874-0.544,1.821-0.815,2.84-0.815
			c1.299,0,2.336,0.403,3.112,1.21c0.775,0.807,1.163,1.907,1.163,3.302c0,0.533-0.048,1.08-0.143,1.641h-8.02
			c-0.027,0.212-0.041,0.403-0.041,0.574c0,1.019,0.234,1.796,0.703,2.333c0.468,0.537,1.041,0.805,1.717,0.805
			c0.637,0,1.262-0.208,1.877-0.625S475.618,226.941,475.959,226.155z M470.566,223.458h6.111c0.007-0.191,0.011-0.328,0.011-0.41
			c0-0.93-0.233-1.642-0.697-2.138c-0.466-0.496-1.063-0.744-1.795-0.744c-0.793,0-1.516,0.273-2.169,0.82
			C471.375,221.534,470.887,222.358,470.566,223.458z"/>
	</g>
	<g>
       inkscape:collect="always"
       xlink:href="#linearGradient4210"
       id="linearGradient4216"
       x1="32.261719"
       y1="719.68437"
       x2="599.57812"
       y2="719.68437"
		<path fill="#E6E7E8" d="M299.974,228.348c0,5.657-4.585,10.243-10.243,10.243h-6.004c-5.656,0-10.242-4.586-10.242-10.243v-6.004
			c0-5.657,4.586-10.244,10.242-10.244h6.004c5.658,0,10.243,4.586,10.243,10.244V228.348z"/>
		<path fill="#58595B" d="M300.174,228.358c0,0-0.021,0.344-0.061,0.99c-0.086,0.658-0.235,1.625-0.679,2.771
			c-0.44,1.141-1.159,2.485-2.347,3.745c-1.187,1.247-2.846,2.434-4.966,3.041c-1.036,0.299-2.258,0.43-3.34,0.461
			c-1.116,0.061-2.271,0.121-3.457,0.162c-0.616,0.017-1.144,0.062-1.854,0.057c-0.309-0.011-0.6-0.006-0.929-0.03
			c-0.353-0.044-0.707-0.089-1.063-0.134c-1.356-0.245-2.7-0.745-3.929-1.499c-2.46-1.492-4.43-4.048-5.16-7.06
			c-0.18-0.75-0.291-1.521-0.326-2.299c-0.038-0.736-0.043-1.385-0.066-2.084c-0.037-1.402-0.073-2.81-0.11-4.217l0.02-1.036
			l0.154-1.272l0.269-1.175c0.127-0.38,0.25-0.765,0.389-1.142c0.598-1.495,1.492-2.869,2.614-4.019
			c2.214-2.329,5.475-3.629,8.532-3.601c1.294,0.011,2.567-0.003,3.813,0.037c0.623,0.014,1.239,0.028,1.848,0.042l0.329,0.009
			l0.226,0.021l0.451,0.041c0.266,0.013,0.665,0.081,1.042,0.15c2.884,0.548,5.103,2.154,6.566,4.005
			c1.468,1.865,2.125,3.943,2.337,5.733c0.038,0.452,0.07,0.888,0.072,1.305c-0.02,0.416-0.028,0.83-0.059,1.191
			c-0.052,0.728-0.101,1.397-0.144,2c-0.088,1.208-0.121,2.157-0.141,2.805c-0.02,0.647-0.031,0.992-0.031,0.992L300.174,228.358z
			 M299.774,228.348c0,0-0.011-0.345-0.031-0.992c-0.02-0.647-0.053-1.597-0.141-2.805c-0.112-1.208-0.081-2.718-0.583-4.188
			c-0.509-1.483-1.469-2.994-2.886-4.127c-0.696-0.577-1.506-1.037-2.355-1.419c-0.846-0.355-1.845-0.582-2.71-0.662
			c-0.208-0.022-0.398-0.058-0.736-0.05l-0.453-0.005l-0.228-0.002c-0.1-0.002,0.104,0.003,0.073,0.002l-0.028,0.001l-0.057,0.001
			l-0.114,0.003c-0.609,0.014-1.225,0.028-1.848,0.042c-1.246,0.04-2.519,0.025-3.813,0.037c-2.12-0.035-4.235,0.659-5.934,2.134
			c-0.839,0.731-1.544,1.646-2.032,2.681l-0.329,0.793l-0.247,0.827l-0.156,0.774l-0.084,1.032c-0.037,1.354-0.074,2.707-0.11,4.056
			c-0.015,0.676-0.047,1.4-0.047,2.031c-0.005,0.591,0.046,1.179,0.15,1.757c0.425,2.318,1.836,4.41,3.731,5.707
			c0.944,0.654,2.001,1.117,3.086,1.375l0.774,0.146c0.282,0.038,0.605,0.052,0.904,0.079c0.506,0.037,1.182,0.051,1.752,0.078
			c1.187,0.041,2.341,0.101,3.457,0.162c1.15,0.075,2.094,0.098,3.082-0.056c1.941-0.3,3.615-1.204,4.835-2.293
			c1.225-1.099,1.973-2.376,2.411-3.474c0.467-1.102,0.543-2.046,0.626-2.664c0.025-0.646,0.039-0.992,0.039-0.992L299.774,228.348z
			"/>
       gradientUnits="userSpaceOnUse" />
  </defs>
	</g>
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="0.7"
     inkscape:cx="263.11623"
     inkscape:cy="534.40312"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="1527"
     inkscape:window-height="1016"
     inkscape:window-x="215"
     inkscape:window-y="35"
     inkscape:window-maximized="0" />
  <metadata
     id="metadata7">
	<g>
		<path fill="#231F20" d="M359.441,264.852l3.148-15.032h6.306c1.244,0,2.188,0.104,2.83,0.313c0.643,0.209,1.146,0.6,1.513,1.174
			c0.365,0.574,0.548,1.299,0.548,2.174c0,1.224-0.399,2.239-1.2,3.045c-0.799,0.807-2.091,1.33-3.875,1.569
			c0.547,0.403,0.96,0.8,1.241,1.189c0.629,0.882,1.135,1.794,1.518,2.738l1.148,2.83h-2.246l-1.077-2.799
			c-0.39-1.012-0.834-1.887-1.333-2.625c-0.342-0.513-0.69-0.849-1.046-1.01c-0.355-0.16-0.933-0.241-1.733-0.241h-2.338
			l-1.395,6.675H359.441z M363.184,256.546h2.779c1.285,0,2.123-0.017,2.512-0.051c0.759-0.075,1.381-0.246,1.866-0.513
			s0.861-0.625,1.128-1.077s0.4-0.937,0.4-1.456c0-0.438-0.099-0.818-0.297-1.144c-0.198-0.324-0.458-0.545-0.779-0.661
			s-0.868-0.174-1.641-0.174h-4.901L363.184,256.546z"/>
		<path fill="#231F20" d="M382.318,261.15l1.805,0.185c-0.26,0.896-0.856,1.747-1.789,2.553c-0.934,0.807-2.046,1.21-3.338,1.21
			c-0.807,0-1.547-0.187-2.22-0.559c-0.674-0.373-1.187-0.915-1.538-1.625c-0.353-0.711-0.528-1.521-0.528-2.43
			c0-1.189,0.275-2.343,0.825-3.461c0.55-1.117,1.263-1.948,2.138-2.491c0.875-0.544,1.822-0.815,2.841-0.815
			c1.299,0,2.336,0.403,3.112,1.21c0.775,0.807,1.163,1.907,1.163,3.302c0,0.533-0.048,1.08-0.143,1.641h-8.019
			c-0.027,0.212-0.041,0.403-0.041,0.574c0,1.019,0.233,1.796,0.702,2.333c0.468,0.537,1.04,0.805,1.718,0.805
			c0.635,0,1.261-0.208,1.876-0.625S381.976,261.937,382.318,261.15z M376.924,258.454h6.111c0.007-0.191,0.011-0.328,0.011-0.41
			c0-0.93-0.233-1.642-0.698-2.138s-1.063-0.744-1.794-0.744c-0.793,0-1.517,0.273-2.169,0.82S377.246,257.353,376.924,258.454z"/>
		<path fill="#231F20" d="M385.896,265.836l1.876,0.174c-0.014,0.424,0.038,0.742,0.154,0.954s0.301,0.376,0.554,0.492
			c0.335,0.15,0.769,0.226,1.302,0.226c1.121,0,1.928-0.291,2.42-0.872c0.321-0.39,0.619-1.237,0.893-2.543l0.185-0.882
			c-0.964,0.978-1.989,1.466-3.076,1.466c-1.101,0-2.021-0.405-2.764-1.215c-0.741-0.811-1.112-1.957-1.112-3.44
			c0-1.224,0.292-2.348,0.877-3.374c0.584-1.025,1.279-1.799,2.086-2.323c0.807-0.522,1.638-0.784,2.492-0.784
			c1.429,0,2.529,0.677,3.302,2.03l0.369-1.784h1.702l-2.194,10.51c-0.239,1.155-0.554,2.056-0.943,2.702
			c-0.39,0.646-0.932,1.147-1.625,1.502c-0.694,0.355-1.496,0.533-2.405,0.533c-0.875,0-1.628-0.113-2.261-0.338
			c-0.632-0.226-1.104-0.556-1.415-0.989c-0.311-0.435-0.467-0.932-0.467-1.492C385.844,266.219,385.862,266.035,385.896,265.836z
			 M388.213,260.033c0,0.745,0.072,1.306,0.215,1.682c0.205,0.526,0.498,0.928,0.877,1.205c0.38,0.276,0.802,0.415,1.267,0.415
			c0.608,0,1.213-0.213,1.815-0.641c0.601-0.427,1.088-1.089,1.461-1.984c0.372-0.896,0.559-1.75,0.559-2.563
			c0-0.896-0.248-1.608-0.743-2.138c-0.496-0.53-1.109-0.795-1.841-0.795c-0.451,0-0.889,0.122-1.313,0.364
			s-0.818,0.612-1.185,1.107c-0.365,0.496-0.643,1.088-0.83,1.779C388.307,259.154,388.213,259.677,388.213,260.033z"/>
		<path fill="#231F20" d="M397.678,264.852l2.276-10.89h1.641l-0.462,2.225c0.561-0.841,1.109-1.463,1.646-1.866
			c0.536-0.403,1.085-0.605,1.646-0.605c0.369,0,0.823,0.133,1.364,0.4l-0.76,1.723c-0.321-0.232-0.673-0.349-1.056-0.349
			c-0.649,0-1.316,0.362-1.999,1.087c-0.685,0.725-1.221,2.027-1.61,3.907l-0.923,4.368H397.678z"/>
		<path fill="#231F20" d="M412.669,261.15l1.805,0.185c-0.26,0.896-0.856,1.747-1.789,2.553c-0.934,0.807-2.046,1.21-3.338,1.21
			c-0.807,0-1.547-0.187-2.22-0.559c-0.674-0.373-1.187-0.915-1.538-1.625c-0.353-0.711-0.528-1.521-0.528-2.43
			c0-1.189,0.275-2.343,0.825-3.461c0.551-1.117,1.263-1.948,2.139-2.491c0.874-0.544,1.821-0.815,2.84-0.815
			c1.299,0,2.336,0.403,3.112,1.21c0.775,0.807,1.163,1.907,1.163,3.302c0,0.533-0.048,1.08-0.143,1.641h-8.02
			c-0.027,0.212-0.041,0.403-0.041,0.574c0,1.019,0.234,1.796,0.703,2.333c0.468,0.537,1.041,0.805,1.717,0.805
			c0.637,0,1.262-0.208,1.877-0.625S412.328,261.937,412.669,261.15z M407.276,258.454h6.111c0.007-0.191,0.011-0.328,0.011-0.41
			c0-0.93-0.233-1.642-0.697-2.138c-0.466-0.496-1.063-0.744-1.795-0.744c-0.793,0-1.516,0.273-2.169,0.82
			C408.084,256.529,407.597,257.353,407.276,258.454z"/>
		<path fill="#231F20" d="M416.524,261.13l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
			c-1.258,0-2.328-0.311-3.209-0.933C416.893,263.543,416.476,262.531,416.524,261.13z"/>
		<path fill="#231F20" d="M427.024,261.13l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
			c-1.258,0-2.328-0.311-3.209-0.933C427.393,263.543,426.976,262.531,427.024,261.13z"/>
		<path fill="#231F20" d="M437.278,264.852l2.277-10.89h1.855l-2.276,10.89H437.278z M439.985,251.922l0.441-2.102h1.846
			l-0.441,2.102H439.985z"/>
		<path fill="#231F20" d="M442.344,260.72c0-2.126,0.625-3.886,1.877-5.281c1.031-1.148,2.385-1.723,4.061-1.723
			c1.313,0,2.37,0.41,3.173,1.23c0.804,0.82,1.205,1.928,1.205,3.322c0,1.251-0.253,2.415-0.759,3.491
			c-0.506,1.077-1.226,1.902-2.158,2.477c-0.934,0.574-1.916,0.861-2.948,0.861c-0.848,0-1.618-0.181-2.313-0.543
			c-0.693-0.362-1.224-0.875-1.589-1.538C442.527,262.354,442.344,261.588,442.344,260.72z M444.2,260.535
			c0,1.025,0.246,1.803,0.738,2.333c0.492,0.53,1.118,0.795,1.877,0.795c0.396,0,0.789-0.08,1.18-0.241
			c0.389-0.16,0.751-0.405,1.086-0.733s0.621-0.703,0.856-1.123c0.236-0.421,0.426-0.874,0.569-1.359
			c0.212-0.677,0.318-1.326,0.318-1.948c0-0.984-0.248-1.749-0.744-2.292c-0.495-0.544-1.119-0.815-1.871-0.815
			c-0.581,0-1.111,0.139-1.59,0.415c-0.479,0.277-0.91,0.682-1.297,1.215c-0.386,0.533-0.67,1.154-0.851,1.861
			C444.291,259.351,444.2,259.981,444.2,260.535z"/>
		<path fill="#231F20" d="M453.696,264.852l2.276-10.89h1.682l-0.399,1.897c0.73-0.745,1.414-1.289,2.051-1.63
			c0.635-0.342,1.284-0.513,1.947-0.513c0.883,0,1.574,0.239,2.077,0.718c0.502,0.479,0.753,1.118,0.753,1.917
			c0,0.403-0.089,1.039-0.266,1.907l-1.385,6.593h-1.855l1.445-6.901c0.144-0.67,0.215-1.166,0.215-1.487
			c0-0.362-0.124-0.656-0.374-0.882c-0.249-0.226-0.61-0.338-1.081-0.338c-0.951,0-1.797,0.342-2.538,1.025
			c-0.742,0.684-1.287,1.856-1.636,3.517l-1.057,5.065H453.696z"/>
		<path fill="#231F20" d="M475.28,264.852l2.779-13.32h-4.932l0.358-1.712h11.833l-0.359,1.712h-4.891l-2.779,13.32H475.28z"/>
		<path fill="#231F20" d="M490.108,261.15l1.805,0.185c-0.26,0.896-0.856,1.747-1.789,2.553c-0.934,0.807-2.046,1.21-3.338,1.21
			c-0.807,0-1.547-0.187-2.22-0.559c-0.674-0.373-1.187-0.915-1.538-1.625c-0.353-0.711-0.528-1.521-0.528-2.43
			c0-1.189,0.275-2.343,0.825-3.461c0.551-1.117,1.263-1.948,2.139-2.491c0.874-0.544,1.821-0.815,2.84-0.815
			c1.299,0,2.336,0.403,3.112,1.21c0.775,0.807,1.163,1.907,1.163,3.302c0,0.533-0.048,1.08-0.143,1.641h-8.02
			c-0.027,0.212-0.041,0.403-0.041,0.574c0,1.019,0.234,1.796,0.703,2.333c0.468,0.537,1.041,0.805,1.717,0.805
			c0.637,0,1.262-0.208,1.877-0.625S489.766,261.937,490.108,261.15z M484.714,258.454h6.111c0.007-0.191,0.011-0.328,0.011-0.41
			c0-0.93-0.233-1.642-0.697-2.138c-0.466-0.496-1.063-0.744-1.795-0.744c-0.793,0-1.516,0.273-2.169,0.82
			C485.523,256.529,485.036,257.353,484.714,258.454z"/>
		<path fill="#231F20" d="M493.963,261.13l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
			c-1.258,0-2.328-0.311-3.209-0.933C494.333,263.543,493.916,262.531,493.963,261.13z"/>
		<path fill="#231F20" d="M508.627,263.345l-0.309,1.518c-0.444,0.116-0.875,0.174-1.291,0.174c-0.738,0-1.327-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.088-0.79,0.266-1.651l1.323-6.327h-1.466l0.297-1.436h1.467l0.563-2.676
			l2.122-1.282l-0.83,3.958h1.825l-0.308,1.436h-1.814l-1.262,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C507.94,263.468,508.305,263.427,508.627,263.345z"/>
		<path fill="#231F20" d="M510.051,264.852l2.277-10.89h1.855l-2.276,10.89H510.051z M512.758,251.922l0.441-2.102h1.846
			l-0.441,2.102H512.758z"/>
		<path fill="#231F20" d="M514.79,264.852l2.276-10.89h1.682l-0.399,1.897c0.73-0.745,1.414-1.289,2.051-1.63
			c0.635-0.342,1.284-0.513,1.947-0.513c0.883,0,1.574,0.239,2.077,0.718c0.502,0.479,0.753,1.118,0.753,1.917
			c0,0.403-0.089,1.039-0.266,1.907l-1.385,6.593h-1.855l1.445-6.901c0.144-0.67,0.215-1.166,0.215-1.487
			c0-0.362-0.124-0.656-0.374-0.882c-0.249-0.226-0.61-0.338-1.081-0.338c-0.951,0-1.797,0.342-2.538,1.025
			c-0.742,0.684-1.287,1.856-1.636,3.517l-1.057,5.065H514.79z"/>
		<path fill="#231F20" d="M526.367,265.836l1.876,0.174c-0.014,0.424,0.038,0.742,0.154,0.954s0.301,0.376,0.554,0.492
			c0.335,0.15,0.769,0.226,1.302,0.226c1.121,0,1.928-0.291,2.42-0.872c0.321-0.39,0.619-1.237,0.893-2.543l0.185-0.882
			c-0.964,0.978-1.989,1.466-3.076,1.466c-1.101,0-2.021-0.405-2.764-1.215c-0.741-0.811-1.112-1.957-1.112-3.44
			c0-1.224,0.292-2.348,0.877-3.374c0.584-1.025,1.279-1.799,2.086-2.323c0.807-0.522,1.638-0.784,2.492-0.784
			c1.429,0,2.529,0.677,3.302,2.03l0.369-1.784h1.702l-2.194,10.51c-0.239,1.155-0.554,2.056-0.943,2.702
			c-0.39,0.646-0.932,1.147-1.625,1.502c-0.694,0.355-1.496,0.533-2.405,0.533c-0.875,0-1.628-0.113-2.261-0.338
			c-0.632-0.226-1.104-0.556-1.415-0.989c-0.311-0.435-0.467-0.932-0.467-1.492C526.315,266.219,526.333,266.035,526.367,265.836z
			 M528.684,260.033c0,0.745,0.072,1.306,0.215,1.682c0.205,0.526,0.498,0.928,0.877,1.205c0.38,0.276,0.802,0.415,1.267,0.415
			c0.608,0,1.213-0.213,1.815-0.641c0.601-0.427,1.088-1.089,1.461-1.984c0.372-0.896,0.559-1.75,0.559-2.563
			c0-0.896-0.248-1.608-0.743-2.138c-0.496-0.53-1.109-0.795-1.841-0.795c-0.451,0-0.889,0.122-1.313,0.364
			s-0.818,0.612-1.185,1.107c-0.365,0.496-0.643,1.088-0.83,1.779C528.778,259.154,528.684,259.677,528.684,260.033z"/>
	</g>
	<g>
		<path fill="#E6E7E8" d="M350.837,263.056c0,5.656-4.587,10.243-10.244,10.243h-6.004c-5.658,0-10.243-4.586-10.243-10.243v-6.004
			c0-5.657,4.585-10.243,10.243-10.243h6.004c5.656,0,10.244,4.585,10.244,10.243V263.056z"/>
		<path fill="#58595B" d="M351.037,263.066c0,0-0.021,0.344-0.061,0.99c-0.086,0.658-0.235,1.626-0.68,2.771
			c-0.44,1.141-1.16,2.484-2.348,3.745c-1.186,1.247-2.846,2.433-4.966,3.041c-1.036,0.3-2.258,0.43-3.34,0.461
			c-1.117,0.061-2.271,0.121-3.457,0.162c-0.616,0.017-1.144,0.062-1.854,0.057c-0.309-0.011-0.6-0.006-0.929-0.029
			c-0.353-0.044-0.707-0.089-1.063-0.134c-1.356-0.244-2.7-0.744-3.929-1.499c-2.461-1.492-4.431-4.048-5.16-7.06
			c-0.18-0.75-0.291-1.52-0.326-2.299c-0.038-0.736-0.043-1.385-0.066-2.084c-0.037-1.402-0.073-2.81-0.11-4.217l0.02-1.036
			l0.154-1.273l0.269-1.175c0.127-0.381,0.25-0.765,0.389-1.143c0.598-1.495,1.492-2.869,2.614-4.019
			c2.215-2.329,5.476-3.628,8.533-3.6c1.294,0.011,2.567-0.003,3.813,0.037c0.623,0.014,1.239,0.028,1.848,0.042l0.329,0.009
			l0.227,0.021l0.451,0.041c0.266,0.013,0.665,0.081,1.043,0.15c2.884,0.548,5.103,2.154,6.566,4.005
			c1.468,1.864,2.126,3.943,2.338,5.733c0.038,0.452,0.07,0.888,0.072,1.305c-0.02,0.415-0.028,0.83-0.059,1.191
			c-0.052,0.728-0.101,1.396-0.144,2c-0.088,1.208-0.121,2.157-0.141,2.805c-0.02,0.647-0.031,0.992-0.031,0.992L351.037,263.066z
			 M350.637,263.056c0,0-0.011-0.345-0.031-0.992c-0.02-0.647-0.053-1.597-0.141-2.805c-0.112-1.208-0.081-2.718-0.583-4.188
			c-0.509-1.483-1.469-2.994-2.887-4.127c-0.696-0.577-1.506-1.036-2.355-1.419c-0.846-0.355-1.845-0.582-2.711-0.662
			c-0.208-0.022-0.398-0.058-0.735-0.05l-0.453-0.005l-0.228-0.002c-0.1-0.002,0.104,0.003,0.073,0.002l-0.028,0.001l-0.057,0.001
			l-0.114,0.003c-0.608,0.014-1.225,0.028-1.848,0.042c-1.246,0.04-2.519,0.025-3.813,0.037c-2.12-0.035-4.236,0.659-5.934,2.133
			c-0.839,0.73-1.544,1.646-2.032,2.68l-0.329,0.793l-0.247,0.827l-0.156,0.774l-0.084,1.032c-0.037,1.354-0.074,2.708-0.11,4.056
			c-0.015,0.676-0.047,1.4-0.047,2.032c-0.005,0.591,0.046,1.179,0.15,1.757c0.425,2.318,1.836,4.41,3.731,5.707
			c0.944,0.654,2.002,1.117,3.086,1.375l0.774,0.146c0.282,0.038,0.605,0.052,0.903,0.079c0.507,0.037,1.182,0.051,1.752,0.078
			c1.187,0.041,2.34,0.101,3.457,0.162c1.15,0.076,2.094,0.098,3.082-0.056c1.941-0.3,3.615-1.204,4.835-2.292
			c1.226-1.099,1.974-2.377,2.412-3.474c0.467-1.102,0.543-2.046,0.627-2.664c0.025-0.646,0.039-0.992,0.039-0.992L350.637,263.056z
			"/>
	</g>
	<g>
		<path fill="#231F20" d="M437.269,294.982l1.969-0.185l-0.021,0.523c0,0.581,0.134,1.113,0.399,1.594
			c0.268,0.482,0.708,0.855,1.323,1.118s1.347,0.395,2.194,0.395c1.203,0,2.121-0.263,2.753-0.79
			c0.633-0.526,0.948-1.128,0.948-1.805c0-0.472-0.167-0.902-0.502-1.292c-0.342-0.383-1.275-0.902-2.799-1.559
			c-1.184-0.513-1.99-0.906-2.42-1.179c-0.678-0.444-1.177-0.928-1.498-1.451c-0.321-0.522-0.481-1.119-0.481-1.789
			c0-0.772,0.212-1.47,0.636-2.092s1.044-1.097,1.861-1.425c0.816-0.328,1.738-0.492,2.764-0.492c1.223,0,2.256,0.205,3.096,0.615
			c0.842,0.41,1.451,0.957,1.831,1.641c0.379,0.684,0.569,1.336,0.569,1.958c0,0.062-0.004,0.164-0.011,0.308l-1.938,0.154
			c0-0.424-0.037-0.755-0.112-0.995c-0.137-0.417-0.349-0.769-0.636-1.056s-0.682-0.518-1.185-0.692
			c-0.502-0.175-1.064-0.262-1.687-0.262c-1.094,0-1.945,0.246-2.553,0.738c-0.466,0.376-0.697,0.875-0.697,1.497
			c0,0.369,0.095,0.699,0.287,0.989c0.19,0.291,0.536,0.576,1.035,0.856c0.355,0.198,1.199,0.591,2.533,1.179
			c1.079,0.479,1.824,0.854,2.234,1.128c0.547,0.362,0.968,0.802,1.262,1.318s0.441,1.102,0.441,1.758
			c0,0.813-0.248,1.564-0.744,2.25c-0.495,0.688-1.181,1.219-2.056,1.595s-1.876,0.564-3.005,0.564
			c-1.701,0-3.091-0.371-4.168-1.113C437.818,298.245,437.276,296.91,437.269,294.982z"/>
		<path fill="#231F20" d="M449.799,304.046l0.113-1.743c0.382,0.109,0.755,0.164,1.117,0.164c0.376,0,0.68-0.085,0.912-0.256
			c0.301-0.226,0.629-0.649,0.984-1.271l0.596-1.066l-1.815-10.92h1.825l0.82,5.506c0.164,1.087,0.304,2.174,0.42,3.261l4.871-8.767
			h1.938l-6.941,12.335c-0.67,1.203-1.265,2-1.784,2.389s-1.118,0.584-1.794,0.584C450.629,304.262,450.209,304.19,449.799,304.046z
			"/>
    <rdf:RDF>
      <cc:Work
         rdf:about="">
		<path fill="#231F20" d="M461.17,296.12l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
			c-1.258,0-2.328-0.311-3.209-0.933C461.54,298.533,461.123,297.521,461.17,296.12z"/>
		<path fill="#231F20" d="M475.834,298.335l-0.309,1.518c-0.444,0.116-0.875,0.174-1.291,0.174c-0.738,0-1.327-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.088-0.79,0.266-1.651l1.323-6.327h-1.466l0.297-1.436h1.467l0.563-2.676
			l2.122-1.282l-0.83,3.958h1.825l-0.308,1.436h-1.814l-1.262,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C475.147,298.458,475.512,298.417,475.834,298.335z"/>
		<path fill="#231F20" d="M485.329,296.141l1.805,0.185c-0.26,0.896-0.856,1.747-1.789,2.553c-0.934,0.807-2.046,1.21-3.338,1.21
			c-0.807,0-1.547-0.187-2.22-0.559c-0.674-0.373-1.187-0.915-1.538-1.625c-0.353-0.711-0.528-1.521-0.528-2.43
			c0-1.189,0.275-2.343,0.825-3.461c0.551-1.117,1.263-1.948,2.139-2.491c0.874-0.544,1.821-0.815,2.84-0.815
			c1.299,0,2.336,0.403,3.112,1.21c0.775,0.807,1.163,1.907,1.163,3.302c0,0.533-0.048,1.08-0.143,1.641h-8.02
			c-0.027,0.212-0.041,0.403-0.041,0.574c0,1.019,0.234,1.796,0.703,2.333c0.468,0.537,1.041,0.805,1.717,0.805
			c0.637,0,1.262-0.208,1.877-0.625S484.987,296.927,485.329,296.141z M479.935,293.444h6.111c0.007-0.191,0.011-0.328,0.011-0.41
			c0-0.93-0.233-1.642-0.697-2.138c-0.466-0.496-1.063-0.744-1.795-0.744c-0.793,0-1.516,0.273-2.169,0.82
			C480.744,291.52,480.256,292.343,479.935,293.444z"/>
		<path fill="#231F20" d="M489,299.842l2.275-10.89h1.856l-0.38,1.794c0.69-0.772,1.308-1.306,1.852-1.6
			c0.543-0.294,1.133-0.441,1.769-0.441c0.677,0,1.242,0.18,1.697,0.538c0.454,0.359,0.753,0.86,0.897,1.502
			c0.553-0.684,1.136-1.195,1.748-1.533c0.611-0.339,1.256-0.508,1.933-0.508c0.909,0,1.591,0.215,2.046,0.646
			c0.454,0.431,0.682,1.036,0.682,1.815c0,0.335-0.079,0.889-0.236,1.661l-1.466,7.014h-1.856l1.498-7.198
			c0.129-0.588,0.194-1.008,0.194-1.261c0-0.355-0.112-0.636-0.339-0.841c-0.225-0.205-0.543-0.308-0.953-0.308
			c-0.554,0-1.117,0.167-1.691,0.502s-1.021,0.774-1.339,1.317c-0.317,0.544-0.597,1.379-0.835,2.507l-1.107,5.281h-1.856
			l1.538-7.352c0.109-0.499,0.164-0.854,0.164-1.066c0-0.355-0.111-0.643-0.333-0.861c-0.223-0.219-0.512-0.328-0.866-0.328
			c-0.527,0-1.079,0.167-1.656,0.502c-0.578,0.335-1.048,0.802-1.41,1.399c-0.362,0.599-0.66,1.451-0.893,2.559l-1.076,5.147H489z"
			/>
		<path fill="#231F20" d="M510.442,299.842l8.521-15.032h2.368l2.482,15.032h-1.949l-0.728-4.327h-6.081l-2.409,4.327H510.442z
			 M515.917,293.967h4.974l-0.585-3.773c-0.225-1.497-0.365-2.745-0.42-3.743c-0.342,0.861-0.841,1.883-1.497,3.066L515.917,293.967
			z"/>
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
		<path fill="#231F20" d="M532.908,298.263c-1.06,1.217-2.167,1.825-3.322,1.825c-1.032,0-1.892-0.381-2.579-1.144
			c-0.687-0.762-1.03-1.868-1.03-3.317c0-1.326,0.271-2.538,0.815-3.635c0.543-1.097,1.224-1.919,2.04-2.466
			c0.817-0.547,1.636-0.82,2.456-0.82c1.354,0,2.375,0.653,3.065,1.958l1.23-5.855h1.846l-3.137,15.032h-1.713L532.908,298.263z
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1">
    <rect
			 M527.822,295.279c0,0.759,0.075,1.357,0.226,1.794s0.406,0.802,0.769,1.092c0.362,0.291,0.797,0.436,1.303,0.436
			c0.841,0,1.603-0.438,2.287-1.313c0.915-1.162,1.373-2.598,1.373-4.307c0-0.861-0.225-1.535-0.676-2.02s-1.02-0.728-1.703-0.728
			c-0.444,0-0.849,0.099-1.215,0.297c-0.365,0.198-0.728,0.535-1.087,1.01c-0.358,0.476-0.661,1.079-0.907,1.81
			S527.822,294.726,527.822,295.279z"/>
		<path fill="#231F20" d="M537.235,299.842l2.275-10.89h1.856l-0.38,1.794c0.69-0.772,1.308-1.306,1.852-1.6
			c0.543-0.294,1.133-0.441,1.769-0.441c0.677,0,1.242,0.18,1.697,0.538c0.454,0.359,0.753,0.86,0.897,1.502
			c0.553-0.684,1.136-1.195,1.748-1.533c0.611-0.339,1.256-0.508,1.933-0.508c0.909,0,1.591,0.215,2.046,0.646
			c0.454,0.431,0.682,1.036,0.682,1.815c0,0.335-0.079,0.889-0.236,1.661l-1.466,7.014h-1.856l1.498-7.198
			c0.129-0.588,0.194-1.008,0.194-1.261c0-0.355-0.112-0.636-0.339-0.841c-0.225-0.205-0.543-0.308-0.953-0.308
			c-0.554,0-1.117,0.167-1.691,0.502s-1.021,0.774-1.339,1.317c-0.317,0.544-0.597,1.379-0.835,2.507l-1.107,5.281h-1.856
			l1.538-7.352c0.109-0.499,0.164-0.854,0.164-1.066c0-0.355-0.111-0.643-0.333-0.861c-0.223-0.219-0.512-0.328-0.866-0.328
			c-0.527,0-1.079,0.167-1.656,0.502c-0.578,0.335-1.048,0.802-1.41,1.399c-0.362,0.599-0.66,1.451-0.893,2.559l-1.076,5.147
			H537.235z"/>
		<path fill="#231F20" d="M554.666,299.842l2.277-10.89h1.855l-2.276,10.89H554.666z M557.373,286.912l0.441-2.102h1.846
			l-0.441,2.102H557.373z"/>
		<path fill="#231F20" d="M559.403,299.842l2.276-10.89h1.682l-0.399,1.897c0.73-0.745,1.414-1.289,2.051-1.63
			c0.635-0.342,1.284-0.513,1.947-0.513c0.883,0,1.574,0.239,2.077,0.718c0.502,0.479,0.753,1.118,0.753,1.917
			c0,0.403-0.089,1.039-0.266,1.907l-1.385,6.593h-1.855l1.445-6.901c0.144-0.67,0.215-1.166,0.215-1.487
			c0-0.362-0.124-0.656-0.374-0.882c-0.249-0.226-0.61-0.338-1.081-0.338c-0.951,0-1.797,0.342-2.538,1.025
			c-0.742,0.684-1.287,1.856-1.636,3.517l-1.057,5.065H559.403z"/>
		<path fill="#231F20" d="M571.01,299.842l2.277-10.89h1.855l-2.276,10.89H571.01z M573.717,286.912l0.441-2.102h1.846l-0.441,2.102
			H573.717z"/>
		<path fill="#231F20" d="M575.922,296.12l1.856-0.113c0,0.533,0.082,0.988,0.246,1.364s0.467,0.684,0.907,0.923
			c0.441,0.239,0.955,0.359,1.543,0.359c0.82,0,1.436-0.164,1.846-0.492s0.615-0.714,0.615-1.159c0-0.321-0.123-0.625-0.369-0.913
			c-0.253-0.287-0.869-0.641-1.851-1.062c-0.98-0.42-1.608-0.716-1.882-0.887c-0.458-0.28-0.803-0.61-1.035-0.989
			c-0.232-0.38-0.349-0.815-0.349-1.308c0-0.861,0.342-1.6,1.025-2.215s1.641-0.923,2.871-0.923c1.367,0,2.408,0.316,3.122,0.948
			c0.715,0.633,1.085,1.465,1.113,2.497l-1.815,0.123c-0.027-0.656-0.26-1.176-0.697-1.559s-1.056-0.574-1.856-0.574
			c-0.643,0-1.142,0.147-1.496,0.441c-0.356,0.294-0.533,0.612-0.533,0.954s0.153,0.643,0.461,0.902
			c0.205,0.178,0.734,0.451,1.59,0.82c1.421,0.615,2.316,1.101,2.686,1.456c0.588,0.567,0.883,1.258,0.883,2.071
			c0,0.54-0.166,1.07-0.498,1.589c-0.331,0.52-0.837,0.935-1.518,1.246c-0.68,0.311-1.481,0.467-2.404,0.467
			c-1.258,0-2.328-0.311-3.209-0.933C576.292,298.533,575.875,297.521,575.922,296.12z"/>
		<path fill="#231F20" d="M590.586,298.335l-0.309,1.518c-0.444,0.116-0.875,0.174-1.291,0.174c-0.738,0-1.327-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.088-0.79,0.266-1.651l1.323-6.327h-1.466l0.297-1.436h1.467l0.563-2.676
			l2.122-1.282l-0.83,3.958h1.825l-0.308,1.436h-1.814l-1.262,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C589.899,298.458,590.264,298.417,590.586,298.335z"/>
		<path fill="#231F20" d="M592.083,299.842l2.276-10.89H596l-0.462,2.225c0.561-0.841,1.109-1.463,1.646-1.866
			c0.536-0.403,1.085-0.605,1.646-0.605c0.369,0,0.823,0.133,1.364,0.4l-0.76,1.723c-0.321-0.232-0.673-0.349-1.056-0.349
			c-0.649,0-1.316,0.362-1.999,1.087c-0.685,0.725-1.221,2.027-1.61,3.907l-0.923,4.368H592.083z"/>
		<path fill="#231F20" d="M606.417,298.489c-0.643,0.554-1.262,0.959-1.855,1.215c-0.596,0.257-1.23,0.385-1.908,0.385
			c-1.004,0-1.814-0.295-2.43-0.887s-0.923-1.349-0.923-2.271c0-0.608,0.139-1.146,0.415-1.615c0.277-0.468,0.645-0.844,1.103-1.128
			c0.458-0.283,1.019-0.487,1.682-0.61c0.417-0.082,1.208-0.147,2.374-0.195c1.165-0.048,2.001-0.171,2.507-0.369
			c0.144-0.506,0.216-0.926,0.216-1.261c0-0.431-0.158-0.769-0.473-1.015c-0.43-0.342-1.06-0.513-1.887-0.513
			c-0.779,0-1.416,0.173-1.912,0.518c-0.495,0.346-0.855,0.836-1.082,1.472l-1.876-0.164c0.383-1.08,0.989-1.907,1.82-2.481
			c0.83-0.574,1.878-0.861,3.143-0.861c1.347,0,2.413,0.321,3.199,0.964c0.602,0.479,0.902,1.101,0.902,1.866
			c0,0.581-0.086,1.254-0.257,2.02l-0.604,2.707c-0.191,0.861-0.287,1.562-0.287,2.102c0,0.342,0.075,0.834,0.226,1.477h-1.877
			C606.531,299.487,606.458,299.036,606.417,298.489z M607.105,294.326c-0.261,0.103-0.539,0.181-0.836,0.236
			c-0.298,0.055-0.795,0.113-1.492,0.174c-1.08,0.096-1.843,0.217-2.287,0.364s-0.779,0.381-1.004,0.702
			c-0.227,0.321-0.339,0.677-0.339,1.066c0,0.52,0.18,0.947,0.538,1.282c0.359,0.335,0.87,0.502,1.533,0.502
			c0.615,0,1.206-0.162,1.773-0.487c0.567-0.324,1.016-0.777,1.344-1.358S606.919,295.399,607.105,294.326z"/>
		<path fill="#231F20" d="M615.092,298.335l-0.309,1.518c-0.444,0.116-0.875,0.174-1.291,0.174c-0.738,0-1.327-0.181-1.764-0.543
			c-0.328-0.273-0.492-0.646-0.492-1.118c0-0.239,0.088-0.79,0.266-1.651l1.323-6.327h-1.466l0.297-1.436h1.467l0.563-2.676
			l2.122-1.282l-0.83,3.958h1.825l-0.308,1.436h-1.814l-1.262,6.019c-0.157,0.766-0.236,1.224-0.236,1.374
			c0,0.219,0.063,0.386,0.19,0.502c0.126,0.116,0.333,0.174,0.62,0.174C614.405,298.458,614.77,298.417,615.092,298.335z"/>
		<path fill="#231F20" d="M616.516,299.842l2.277-10.89h1.855l-2.276,10.89H616.516z M619.223,286.912l0.441-2.102h1.846
			l-0.441,2.102H619.223z"/>
		<path fill="#231F20" d="M621.583,295.71c0-2.126,0.625-3.886,1.877-5.281c1.031-1.148,2.385-1.723,4.061-1.723
			c1.313,0,2.37,0.41,3.173,1.23c0.804,0.82,1.205,1.928,1.205,3.322c0,1.251-0.253,2.415-0.759,3.491
			c-0.506,1.077-1.226,1.902-2.158,2.477c-0.934,0.574-1.916,0.861-2.948,0.861c-0.848,0-1.618-0.181-2.313-0.543
			c-0.693-0.362-1.224-0.875-1.589-1.538C621.765,297.344,621.583,296.578,621.583,295.71z M623.438,295.525
			c0,1.025,0.246,1.803,0.738,2.333c0.492,0.53,1.118,0.795,1.877,0.795c0.396,0,0.789-0.08,1.18-0.241
			c0.389-0.16,0.751-0.405,1.086-0.733s0.621-0.703,0.856-1.123c0.236-0.421,0.426-0.874,0.569-1.359
			c0.212-0.677,0.318-1.326,0.318-1.948c0-0.984-0.248-1.749-0.744-2.292c-0.495-0.544-1.119-0.815-1.871-0.815
			c-0.581,0-1.111,0.139-1.59,0.415c-0.479,0.277-0.91,0.682-1.297,1.215c-0.386,0.533-0.67,1.154-0.851,1.861
			C623.529,294.341,623.438,294.972,623.438,295.525z"/>
		<path fill="#231F20" d="M632.934,299.842l2.276-10.89h1.682l-0.399,1.897c0.73-0.745,1.414-1.289,2.051-1.63
			c0.635-0.342,1.284-0.513,1.947-0.513c0.883,0,1.574,0.239,2.077,0.718c0.502,0.479,0.753,1.118,0.753,1.917
			c0,0.403-0.089,1.039-0.266,1.907l-1.385,6.593h-1.855l1.445-6.901c0.144-0.67,0.215-1.166,0.215-1.487
			c0-0.362-0.124-0.656-0.374-0.882c-0.249-0.226-0.61-0.338-1.081-0.338c-0.951,0-1.797,0.342-2.538,1.025
			c-0.742,0.684-1.287,1.856-1.636,3.517l-1.057,5.065H632.934z"/>
	</g>
       style="opacity:0.78378378000000004;fill:#d6d6d6;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect4442"
       width="651.42859"
       height="675.71442"
	<g>
       x="32.857143"
       y="330.93362" />
    <flowRoot
       xml:space="preserve"
       id="flowRoot2985"
       style="fill:black;stroke:none;stroke-opacity:1;stroke-width:1px;stroke-linejoin:miter;stroke-linecap:butt;fill-opacity:1;font-family:Sans;font-style:normal;font-weight:normal;font-size:72px;line-height:125%;letter-spacing:0px;word-spacing:0px"><flowRegion
         id="flowRegion2987"><rect
           id="rect2989"
           width="628.57141"
           height="104.28571"
           x="55.714287"
		<path fill="#E6E7E8" d="M425.018,297.764c0,5.657-4.583,10.243-10.24,10.243h-6.006c-5.656,0-10.241-4.586-10.241-10.243v-6.005
			c0-5.657,4.585-10.243,10.241-10.243h6.006c5.657,0,10.24,4.586,10.24,10.243V297.764z"/>
		<path fill="#58595B" d="M425.218,297.774c0,0-0.021,0.344-0.062,0.99c-0.086,0.658-0.234,1.625-0.68,2.771
			c-0.439,1.141-1.158,2.485-2.347,3.745c-1.186,1.248-2.846,2.434-4.966,3.041c-1.035,0.299-2.258,0.43-3.34,0.461
			c-1.116,0.061-2.27,0.121-3.456,0.162c-0.616,0.017-1.145,0.062-1.854,0.057c-0.309-0.011-0.6-0.006-0.93-0.029
			c-0.352-0.044-0.706-0.089-1.063-0.134c-1.356-0.245-2.7-0.745-3.929-1.499c-2.461-1.492-4.431-4.048-5.159-7.061
			c-0.18-0.75-0.29-1.521-0.325-2.299c-0.038-0.736-0.043-1.385-0.065-2.084c-0.037-1.402-0.074-2.81-0.11-4.217l0.02-1.036
			l0.153-1.272l0.27-1.175c0.127-0.38,0.25-0.765,0.389-1.142c0.598-1.495,1.492-2.869,2.613-4.019
			c2.215-2.329,5.476-3.628,8.532-3.601c1.295,0.011,2.567-0.003,3.813,0.037c0.622,0.014,1.238,0.028,1.848,0.042l0.328,0.009
			l0.227,0.021l0.451,0.041c0.266,0.013,0.664,0.081,1.042,0.15c2.885,0.547,5.104,2.154,6.566,4.006
			c1.468,1.865,2.125,3.943,2.336,5.733c0.038,0.452,0.07,0.888,0.072,1.305c-0.02,0.415-0.027,0.83-0.059,1.19
			c-0.053,0.728-0.102,1.397-0.145,2.001c-0.088,1.208-0.121,2.157-0.142,2.804c-0.02,0.647-0.03,0.992-0.03,0.992V297.774z
			 M424.818,297.764c0,0-0.011-0.345-0.03-0.992c-0.021-0.647-0.054-1.596-0.142-2.804c-0.112-1.209-0.081-2.718-0.583-4.188
			c-0.509-1.483-1.468-2.995-2.885-4.128c-0.696-0.577-1.505-1.037-2.354-1.419c-0.846-0.355-1.846-0.582-2.711-0.662
			c-0.208-0.022-0.398-0.058-0.735-0.05l-0.453-0.005l-0.228-0.002c-0.1-0.002,0.104,0.003,0.073,0.002l-0.028,0.001l-0.058,0.001
			l-0.113,0.003c-0.609,0.014-1.226,0.028-1.848,0.042c-1.246,0.04-2.519,0.025-3.813,0.037c-2.119-0.035-4.235,0.659-5.934,2.133
			c-0.839,0.73-1.544,1.646-2.031,2.681l-0.329,0.793l-0.246,0.827l-0.156,0.773l-0.085,1.033c-0.036,1.354-0.073,2.707-0.11,4.055
			c-0.014,0.676-0.046,1.4-0.046,2.032c-0.006,0.591,0.046,1.179,0.149,1.758c0.425,2.318,1.836,4.41,3.73,5.707
			c0.944,0.654,2.002,1.117,3.086,1.375l0.774,0.146c0.282,0.038,0.605,0.052,0.903,0.079c0.507,0.037,1.183,0.051,1.753,0.078
			c1.187,0.041,2.34,0.101,3.456,0.162c1.15,0.075,2.095,0.098,3.082-0.055c1.941-0.3,3.615-1.204,4.835-2.292
			c1.226-1.099,1.974-2.377,2.411-3.474c0.467-1.102,0.543-2.046,0.626-2.664c0.026-0.646,0.039-0.992,0.039-0.992V297.764z"/>
	</g>
	<path fill="#00A551" d="M202.714,201.958c0,8.508-6.896,15.404-15.404,15.404h-57.722c-8.508,0-15.404-6.896-15.404-15.404v-7.553
		c0-8.508,6.896-15.404,15.404-15.404h57.722c8.509,0,15.404,6.896,15.404,15.404V201.958z"/>
	<g>
		<path fill="#FFFFFF" d="M128.408,206.238v-17.18h5.566c2.109,0,3.484,0.086,4.125,0.258c0.984,0.258,1.809,0.818,2.473,1.682
			s0.996,1.979,0.996,3.346c0,1.055-0.191,1.941-0.574,2.66s-0.869,1.283-1.459,1.693s-1.189,0.682-1.799,0.814
			c-0.828,0.164-2.027,0.246-3.598,0.246h-2.262v6.48H128.408z M131.877,191.964v4.875h1.898c1.367,0,2.281-0.09,2.742-0.27
			s0.822-0.461,1.084-0.844s0.393-0.828,0.393-1.336c0-0.625-0.184-1.141-0.551-1.547s-0.832-0.66-1.395-0.762
			c-0.414-0.078-1.246-0.117-2.496-0.117H131.877z"/>
		<path fill="#FFFFFF" d="M158.127,206.238h-3.773l-1.5-3.902h-6.867l-1.418,3.902h-3.68l6.691-17.18h3.668L158.127,206.238z
			 M151.74,199.441l-2.367-6.375l-2.32,6.375H151.74z"/>
		<path fill="#FFFFFF" d="M159.088,200.648l3.375-0.328c0.203,1.133,0.615,1.965,1.236,2.496s1.459,0.797,2.514,0.797
			c1.117,0,1.959-0.236,2.525-0.709s0.85-1.025,0.85-1.658c0-0.406-0.119-0.752-0.357-1.037s-0.654-0.533-1.248-0.744
			c-0.406-0.141-1.332-0.391-2.777-0.75c-1.859-0.461-3.164-1.027-3.914-1.699c-1.055-0.945-1.582-2.098-1.582-3.457
			c0-0.875,0.248-1.693,0.744-2.455s1.211-1.342,2.145-1.74s2.061-0.598,3.381-0.598c2.156,0,3.779,0.473,4.869,1.418
			s1.662,2.207,1.717,3.785l-3.469,0.152c-0.148-0.883-0.467-1.518-0.955-1.904s-1.221-0.58-2.197-0.58
			c-1.008,0-1.797,0.207-2.367,0.621c-0.367,0.266-0.551,0.621-0.551,1.066c0,0.406,0.172,0.754,0.516,1.043
			c0.438,0.367,1.5,0.75,3.188,1.148s2.936,0.811,3.744,1.236s1.441,1.008,1.898,1.746s0.686,1.65,0.686,2.736
			c0,0.984-0.273,1.906-0.82,2.766s-1.32,1.498-2.32,1.916s-2.246,0.627-3.738,0.627c-2.172,0-3.84-0.502-5.004-1.506
			S159.314,202.57,159.088,200.648z"/>
		<path fill="#FFFFFF" d="M175.096,200.648l3.375-0.328c0.203,1.133,0.615,1.965,1.236,2.496s1.459,0.797,2.514,0.797
			c1.117,0,1.959-0.236,2.525-0.709s0.85-1.025,0.85-1.658c0-0.406-0.119-0.752-0.357-1.037s-0.654-0.533-1.248-0.744
			c-0.406-0.141-1.332-0.391-2.777-0.75c-1.859-0.461-3.164-1.027-3.914-1.699c-1.055-0.945-1.582-2.098-1.582-3.457
			c0-0.875,0.248-1.693,0.744-2.455s1.211-1.342,2.145-1.74s2.061-0.598,3.381-0.598c2.156,0,3.779,0.473,4.869,1.418
			s1.662,2.207,1.717,3.785l-3.469,0.152c-0.148-0.883-0.467-1.518-0.955-1.904s-1.221-0.58-2.197-0.58
			c-1.008,0-1.797,0.207-2.367,0.621c-0.367,0.266-0.551,0.621-0.551,1.066c0,0.406,0.172,0.754,0.516,1.043
			c0.438,0.367,1.5,0.75,3.188,1.148s2.936,0.811,3.744,1.236s1.441,1.008,1.898,1.746s0.686,1.65,0.686,2.736
			c0,0.984-0.273,1.906-0.82,2.766s-1.32,1.498-2.32,1.916s-2.246,0.627-3.738,0.627c-2.172,0-3.84-0.502-5.004-1.506
			S175.322,202.57,175.096,200.648z"/>
	</g>
	<path fill="#EC1C24" d="M202.714,247.065c0,8.508-6.896,15.404-15.404,15.404h-57.722c-8.508,0-15.404-6.896-15.404-15.404v-7.554
		c0-8.506,6.896-15.404,15.404-15.404h57.722c8.509,0,15.404,6.897,15.404,15.404V247.065z"/>
	<g>
		<path fill="#FFFFFF" d="M134.438,251.347v-17.18h11.777v2.906h-8.309v4.066h7.172v2.906h-7.172v7.301H134.438z"/>
		<path fill="#FFFFFF" d="M163.242,251.347h-3.773l-1.5-3.902h-6.867l-1.418,3.902h-3.68l6.691-17.18h3.668L163.242,251.347z
			 M156.855,244.55l-2.367-6.375l-2.32,6.375H156.855z"/>
		<path fill="#FFFFFF" d="M164.977,251.347v-17.18h3.469v17.18H164.977z"/>
		<path fill="#FFFFFF" d="M171.844,251.347v-17.039h3.469v14.145h8.625v2.895H171.844z"/>
	</g>
	<path fill="#FFDD15" d="M202.714,292.171c0,8.509-6.896,15.405-15.404,15.405h-57.722c-8.508,0-15.404-6.896-15.404-15.405v-7.553
		c0-8.508,6.896-15.405,15.404-15.405h57.722c8.509,0,15.404,6.897,15.404,15.405V292.171z"/>
	<g>
		<path fill="#FFFFFF" d="M125.971,296.452l-4.102-17.18h3.551l2.59,11.801l3.141-11.801h4.125l3.012,12l2.637-12h3.492
			l-4.172,17.18h-3.68l-3.422-12.844l-3.41,12.844H125.971z"/>
		<path fill="#FFFFFF" d="M160.354,296.452h-3.773l-1.5-3.902h-6.867l-1.418,3.902h-3.68l6.691-17.18h3.668L160.354,296.452z
			 M153.967,289.655l-2.367-6.375l-2.32,6.375H153.967z"/>
		<path fill="#FFFFFF" d="M162.205,296.452v-17.18h7.301c1.836,0,3.17,0.154,4.002,0.463s1.498,0.857,1.998,1.646
			s0.75,1.691,0.75,2.707c0,1.289-0.379,2.354-1.137,3.193s-1.891,1.369-3.398,1.588c0.75,0.438,1.369,0.918,1.857,1.441
			s1.146,1.453,1.975,2.789l2.098,3.352h-4.148l-2.508-3.738c-0.891-1.336-1.5-2.178-1.828-2.525s-0.676-0.586-1.043-0.715
			s-0.949-0.193-1.746-0.193h-0.703v7.172H162.205z M165.674,286.538h2.566c1.664,0,2.703-0.07,3.117-0.211s0.738-0.383,0.973-0.727
			s0.352-0.773,0.352-1.289c0-0.578-0.154-1.045-0.463-1.4s-0.744-0.58-1.307-0.674c-0.281-0.039-1.125-0.059-2.531-0.059h-2.707
			V286.538z"/>
		<path fill="#FFFFFF" d="M179.561,296.452v-17.18h3.375l7.031,11.473v-11.473h3.223v17.18h-3.48l-6.926-11.203v11.203H179.561z"/>
           y="40.933609"
           style="font-size:72px" /></flowRegion><flowPara
         id="flowPara2991"></flowPara></flowRoot>    <text
       xml:space="preserve"
       style="font-size:22px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="187.14285"
       y="58.076473"
       id="text2993"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan2995"
         x="187.14285"
         y="58.076473"
         style="font-size:64px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Sans;-inkscape-font-specification:Sans Bold">Megatest</tspan></text>
	</g>
	<g>
		<rect x="149.475" y="375.648" fill="none" width="479.086" height="606.257"/>
		<path d="M153.72,390.685l-3.989-15.032h2.041l2.287,9.854c0.246,1.032,0.458,2.058,0.636,3.076
			c0.383-1.606,0.608-2.533,0.677-2.779l2.861-10.151h2.399l2.153,7.608c0.54,1.887,0.93,3.661,1.169,5.322
			c0.191-0.95,0.441-2.041,0.749-3.271l2.358-9.659h2l-4.122,15.032h-1.917l-3.168-11.454c-0.267-0.957-0.424-1.545-0.472-1.764
			c-0.157,0.69-0.304,1.278-0.441,1.764l-3.189,11.454H153.72z"/>
		<path d="M170.28,390.685v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H170.28z"/>
		<path d="M177.304,377.775v-2.123h1.846v2.123H177.304z M177.304,390.685v-10.89h1.846v10.89H177.304z"/>
		<path d="M185.989,389.034l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354v-1.436h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856
			v6.368c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C185.384,389.105,185.654,389.082,185.989,389.034z"/>
		<path d="M195.249,387.178l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S194.968,387.957,195.249,387.178z
			 M189.188,384.194h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S189.25,383.244,189.188,384.194z"/>
		<path d="M204.621,385.24c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.427-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.466C205.09,388.487,204.621,387.079,204.621,385.24z M206.518,385.24
			c0,1.395,0.304,2.439,0.913,3.132c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046s0.913-1.76,0.913-3.189
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S206.518,383.845,206.518,385.24z"/>
		<path d="M216.987,390.685v-10.89h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687s-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333c-0.786,0-1.465,0.25-2.036,0.749
			s-0.856,1.446-0.856,2.84v5.947H216.987z"/>
		<path d="M236.121,387.178l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S235.84,387.957,236.121,387.178z
			 M230.061,384.194h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S230.122,383.244,230.061,384.194z"/>
		<path d="M250.209,389.034l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354v-1.436h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856
			v6.368c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C249.604,389.105,249.875,389.082,250.209,389.034z"/>
		<path d="M259.12,389.341c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.092,0.882,0.092,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C259.298,390.302,259.175,389.854,259.12,389.341z M258.966,385.219c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V385.219z"
			/>
		<path d="M262.955,387.434l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C263.633,389.461,263.16,388.589,262.955,387.434z"/>
		<path d="M274.204,390.685v-15.032h1.846v8.572l4.368-4.43h2.389l-4.163,4.04l4.583,6.85h-2.276l-3.599-5.568l-1.302,1.251v4.317
			H274.204z"/>
		<path d="M289.841,385.24c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.427-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.466C290.311,388.487,289.841,387.079,289.841,385.24z M291.738,385.24
			c0,1.395,0.304,2.439,0.913,3.132c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046s0.913-1.76,0.913-3.189
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S291.738,383.845,291.738,385.24z"/>
		<path d="M302.187,390.685v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H302.187z"/>
		<path d="M319.064,389.034l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354v-1.436h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856
			v6.368c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C318.459,389.105,318.729,389.082,319.064,389.034z"/>
		<path d="M328.324,387.178l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S328.043,387.957,328.324,387.178z
			 M322.264,384.194h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S322.325,383.244,322.264,384.194z"/>
		<path d="M331.81,387.434l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C332.488,389.461,332.015,388.589,331.81,387.434z"/>
		<path d="M347.078,389.034l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354v-1.436h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856
			v6.368c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C346.473,389.105,346.743,389.082,347.078,389.034z"/>
		<path d="M361.823,389.341c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
    <text
       xml:space="preserve"
       style="font-size:22px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="195.71429"
       y="100.93362"
       id="text2997"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan2999"
         x="195.71429"
         y="100.93362">Simple - but not TOO simple!</tspan></text>
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.092,0.882,0.092,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C362.001,390.302,361.878,389.854,361.823,389.341z M361.669,385.219c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V385.219z"
			/>
		<path d="M366.396,390.685v-10.89h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696H373.4v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.446-0.856,2.84v5.947H366.396z"/>
		<path d="M385.141,390.685v-1.374c-0.691,1.08-1.706,1.62-3.046,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.293-1.146-1.693-2.005c-0.398-0.857-0.6-1.844-0.6-2.958c0-1.087,0.182-2.073,0.544-2.958s0.905-1.564,1.63-2.036
			s1.535-0.708,2.431-0.708c0.656,0,1.241,0.139,1.753,0.415c0.514,0.277,0.93,0.638,1.252,1.082v-5.394h1.835v15.032H385.141z
			 M379.306,385.25c0,1.395,0.294,2.437,0.882,3.127s1.281,1.036,2.082,1.036c0.807,0,1.492-0.33,2.055-0.989
			c0.564-0.66,0.847-1.667,0.847-3.02c0-1.49-0.287-2.584-0.861-3.281s-1.282-1.046-2.122-1.046c-0.82,0-1.506,0.335-2.057,1.005
			S379.306,383.808,379.306,385.25z"/>
		<path d="M395.6,377.775v-2.123h1.846v2.123H395.6z M395.6,390.685v-10.89h1.846v10.89H395.6z"/>
		<path d="M404.285,389.034l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354v-1.436h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856
			v6.368c0,0.526,0.033,0.865,0.098,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.631,0.133
			C403.68,389.105,403.95,389.082,404.285,389.034z"/>
		<path d="M413.544,387.178l1.906,0.236c-0.301,1.114-0.857,1.979-1.672,2.594c-0.813,0.615-1.852,0.923-3.116,0.923
			c-1.593,0-2.855-0.49-3.789-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.385,2.386,1.385,4.184c0,0.109-0.004,0.273-0.012,0.492h-8.12
			c0.068,1.196,0.406,2.112,1.016,2.748c0.607,0.636,1.367,0.954,2.276,0.954c0.676,0,1.254-0.178,1.732-0.533
			S413.263,387.957,413.544,387.178z M407.484,384.194h6.08c-0.082-0.916-0.314-1.603-0.697-2.061
			c-0.588-0.711-1.35-1.066-2.286-1.066c-0.848,0-1.561,0.284-2.139,0.851C407.865,382.485,407.545,383.244,407.484,384.194z"/>
		<path d="M417.748,390.685v-10.89h1.662v1.651c0.423-0.772,0.814-1.282,1.174-1.528c0.358-0.246,0.754-0.369,1.184-0.369
			c0.622,0,1.255,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.551,0.579-0.687,1.01c-0.205,0.656-0.309,1.374-0.309,2.153v5.701H417.748z"/>
		<path d="M431.867,389.341c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062c0.394-0.267,0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.414,0.011-0.482c0-0.752-0.175-1.282-0.522-1.589
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.152-1.923,0.457c-0.413,0.304-0.72,0.842-0.918,1.615l-1.805-0.246
			c0.164-0.772,0.435-1.396,0.811-1.872c0.376-0.475,0.919-0.841,1.631-1.097c0.71-0.257,1.534-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.093,0.882,0.093,1.702v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C432.044,390.302,431.921,389.854,431.867,389.341z M431.712,385.219c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.558,0.337-0.728,0.6c-0.172,0.263-0.257,0.555-0.257,0.876
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.155,1.896-0.466
			c0.555-0.311,0.961-0.737,1.221-1.277c0.198-0.417,0.297-1.032,0.297-1.846V385.219z"/>
		<path d="M440.47,389.034l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354v-1.436h1.354v-2.697l1.836-1.107v3.804h1.855v1.436h-1.855
			v6.368c0,0.526,0.032,0.865,0.097,1.015c0.065,0.15,0.171,0.27,0.318,0.359c0.146,0.089,0.356,0.133,0.63,0.133
			C439.865,389.105,440.135,389.082,440.47,389.034z"/>
		<path d="M449.729,387.178l1.907,0.236c-0.301,1.114-0.858,1.979-1.672,2.594s-1.853,0.923-3.117,0.923
    <image
       y="7.3621907"
       x="4.3571429"
       id="image3139"
       xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIkAAABGCAYAAAD4mreoAAAABHNCSVQICAgIfAhkiAAAIABJREFU
eJzlnXlcVNX7x98zwwwwgGyCiiuuWaYlaiq5b6m5p6aJ+S1NzbVyV9zKLbdEzQy3rIxMcV/ScM3S
cKtMUElFEVBW2QYYmPv7484dL+MMDAou/T6v133NPfes997PnPOc53nOuQpBEPhPQ4ECUAMa42Fv
DCvNDpXxF8Bg4cg3HjnGIxfIReA//gBB8Z8iiUgILeAEOPKAEIpSqlEA9IikyQYygSwEDKVU31PB
800SBUoekEJrPEqLELZCAHRABg9I8xw/5OeRJGJv4QK4Gn+VhWd46hAQyZICpD2PhHk+SCISwwmR
GGUQ5YcSwUhGtj7L2dFS2BffbVvZGlJS5ZshH7gPpCKQVUp1lDiebZIosAM8jIddaVTRnOZfp5Pe
TAqrUcec4UwXNepCH8z/+F/nCCL6VaTi0S50OfI+78cUs+ocIBWRMPpHaPoTw7NJEgX2gCfgjhUZ
Q4dO6YjjYwmIm9jks5SlB83raE/7YctZfrqwvC1osTSV1I5S2B77KG+8jzShybHpTL9UFMnMkAEk
IJBZrBt4Qni2SKLACSiLKGs8hLWsrbKXvZ0TSWySSWYDQLDDLtkb70NjGLOxK12Ti1NdV7qOvsWt
4ebX3XE/dIITn1jLp0evaEazXTnk+FqKt8MuwQOPY3Wpe2QSk/6oQpVcG5uUAdxFQGdj+ieCZ4Mk
Ys9RAXC2FB1KqFcQQR8nkdQFK4KqEmVGb3oPm8WsS7ZUmUaashWtDueR5w3ghtvhVFI7iM1R5C1g
QbuiSPcpn754mtNt73K3XQ45Na20K6sMZU754nt0DGOONqZxhg3Nuw/cQyDHlnspbTzdmYECFQoq
ADWxQpD5zK/7KZ+GJJH0JoW014DBeSc7V53ilMVeyBxTmNJCIogSZcZCFs5SoUoDEBDs1rGuR1Fl
BBJ4eR/7Vp3lbK9qVFttpV3aVFI7XODC/AMcqFpUmcM079VHFNBroqAiCtS23E9p4umQRIECBZ5A
bUTZw6LcEU648za2BUkvEzB44bXtLd4aEExws570fMce+ygALdqLAxk4zB//dFua8Bd/9ZHOPfE8
5I9/uieeB6Vrt7jVR4/eZp1LIomNpHMt2gt++E12x/2gEmUGgB1296Yy9XJhZXSt2qHjqTK/tzQG
FYgyWW0UlDfqhJ4KSmXGUCgUOAKVELWhhWIKUz7Woy8vZlPkdKPb0HnMuyjFN6XpX8MY1n8hC5ut
YMUJW4XFUEK90kiTXgaNabwboDnNd+1kZz+AXHKrTmVq4yUs+aOo8k5wokwmmSaSVKLS4U1s2g/s
v8c9uwUsaHSf+26W2hdOuHM00dobTlGaE1mnxl9I/KunWRIFopxWBgW3n4a88uRkEvE/6QV4Y4NW
9Ba3NN3o9qsBgyNAbWov3s72zUXlCyXU6zjHa61gxW/W0vSgx9DrXB8HoEZ95wxnOksv0A+/vbnk
VgXwwOPAcY5PKqrOd3m363nOL5TC4xnf2dYpcUc6To4nvvfNitfyG9s1WRQWfXxXIckFIAFxJvTE
hMkn04WJ46ovUA4b1ebLWOYnEQRgOMP3WEubTLJqOMPbvs7rK2cz+/Axji25wQ2LPZUevSKGmN5S
uAIV9sr/4RWpaHpJKaS0CyPMrai23uBGW+ncHvsoWwmymMW14okfkFA7VmvvonFJjc4YOo5xzQvJ
okD8k/miQGNLHSWB0h9uFLgCPhRTS5pEkiSHoEJ1vyMdU8zTrGBF9QMc6BVPfPd88j2k6wKCy1zm
tt3IxgPmeaYwpUkuuZWlcBxxXZvQpCXiv9RgwKCVlaNZzeru7WhntQe7xS3Nfe77S2FvvI/aeo/b
2T79fvlklaF6Dh6Hfcglt9oRjqxtQYuw93n/8yEMibWSVYso2MYh8NBzKWmUXk8iCqcVgcqYEWQ+
8+vakD1fOjdgcL7EJUd5fCSRDhvYEHKHO0PkBJFwhSvmYzsAZznbRx7Wo6+kQ1dXh+5FHbp6OeRU
l8ff4tZbhbVzMYubGDA4SeEmNLGJJEMY0iXJIdHPrm8W6igtjvmO96W4VFLbLWPZ7jd5c6S1HhHx
3VVEQRUUJWemsFZRyUNsdDVE6dyEW9zStKb1vBBCfviIj5oWVkRZyiZI5wKCaj3rG8jjX+CFbA88
fharU+S6437QHfdDUnw66U1DCCknzxNGmFsKKe2Kcys55PhOYUpDa/GXudxGOrfDLmE604vU05zn
vNN5zk/I7pBMfoIC9yjvlCCCutSn/kwVqhQAAcE+mugP+9Bn1whGtCmkuDKIw0+pjQolTxJxrKyO
aJAzYR/7PPrSd30SSd0FBNURjiwrbLwfyciLChQmTeWf/NnJPE072m2pQ52FQQS1PcGJiW/zdpAs
WrmFLQV0HV/yZTcBQSM2U5G7mtX+f/P3y+bHPvb5qVCZ/tmnOd3XUhv16BXJJLeWwu64H7dlhjWN
aSMSXo3xKv+xA0KYI6/wypKWtEz7nu93rGZ11/KU34Lo6IQefcVTnApqTvM1wQRXtlKkA1DDqJQs
cZQsSRRoEQlSoLGLWVwrkMAfssh6RUymyG1AgwXtaJdqraha1MpxxjlcCieQ0HsVq6rJ08xgRsQ2
tn3fmtb3AZxx1itQZEvxccR1kKePJtoksLrierwlLdMs1V2FKrleeO2VwskkdzjBiTLm6eYxr55M
h0Nd6hY51KxgRfVL1S4Orr5Zy53AbMonVLz4Ld/uluL98U8/zOEFAQT0dcLpvHQ9nfTmccQ91AYZ
1EB1o4qhRFFyJFFQBnGIKdDtjWRk6+/47js9eh8AO+ySutP9vc1stjpbkdCc5hvkbd3ClmmxxFrU
QJ7mtHMQQasFBAfpmi++odJ5IIH15arzl3ip0Po70MGUV0CwDyKou3maP/jDNAwoUeomMOFMUff0
peeqpR4zUKb9qkd7zh0duhe70nV0JJEO8nSTmHT1NKff9cNvsh1297zxDp3JzH+KKF6FOPTYpHW2
FSWjJxEJUhmz6W0vev0viqjxGMnogMOVcYwbM4hBcfJ0evQKa910M5oFZ5Bhkl+ccDobSOAncrvK
cIa3DSd8qqR4AyhL2V2HOBQolduXvgNuc7sjgBJlzk52jvbGO6+w22pFq0XZZFcy1vvvEY7MlMc3
otEOiXhuuIWd5OT4wsrrquk8IGJw+DTfFc5ENsnA458Kpjg16vhXeXXxetYfMs/3J39qdeiUTWlq
i90HxJnaHQSs9tTFweOTRGRtFWQEiSVW/Q7vzEok0SQTuOJ65Cu+mlKPeiaNoR69ogc9RuvQeR/l
aKCl4vexzyOQwB+knsgIgyOOkSpU6Tp0tcxnN954b93L3nmP60pQGIIJrhxE0H4p3IAGM77jO6uK
sIMcdH2/1cCjL4a5qm+MzcDhy3JJlai0K5bYAAHB1Ds643ymH/0WfMRH/5ZAM+MQSHrcQh5vuBFN
+wUIcpCD7r3pvU5OkEpUWneUo+PlBIkk0qEtbZfd5vYHiST27EnP9yxV0ZWuye/y7kh77K/L261D
92IGGa/JCaJEmf4Kr8wII+zT0iQIgAGDwguvHXbYJQGGwQw+UVj64fWHfFvrR2e1LjqP7N0qGtJw
yUEOLh/BiF4uuJyS0mWQ8dpGNm7vSMeJ4YRbNHoWAxWMeqrHwqP3JKKQWg0zojWn+dp00k1aQw88
9h/n+GR5mhBCyi1l6cpssiV9iaEudRduZesP1qq7xjX7sYz98C53u8iHFcRe5Up5yh8OJPAHG03x
JQY9esVKVtb4mI+jrKVpWPulT1SrU4a4t7fn8hv3qfBzjYvhhAfI0xiHzMnyHrM61VfsYtc6S2Xq
0CmHMrRHHHH1NWjS61DntBVThADceBx3yUcjiQIHRDX7Q0qcL/my6lrW/mDAIAlPhla0GrWKVb8C
zGRm/T3sWZFHXlkQzfStaDUhiKBT5mVZw3KW10gm2UmBgk50umGr5fdp4L0K7zb8beSB4CqBTpqk
XdkkD9YIH6SN6DeVqZHmaa9xzX4844fe5vb/7LBL3M72Hr74PuRTspzlNUIImZtFVn35dQccIgYw
YJoFwuYD/yJgq/NTARSfJKKirCZY93P4iI+ahhH2lYCgApEIQxk68Bzn6p7n/FwBwR5Ag+b2YAaP
Hse46+ZlFCbMPi/YwQ63j/oP+6l2iEt5IU/gn9fS8DpfOase9RZsYtMua/e3nvWVbnDD8zM++9M8
7h737DrTeUcuudUs5VWgyG5N6/EW/nS5iETJt5SvMBSPJKLkUQ0rDkJy9KPf2xFETJfCKlSp+eSb
lGdOOJ2bx7zxlnQls5n98j72zbI0E3pekEmmsl6r6sHV9zk2UTkpiJ6VITDPQ6HJF+1yjjj+3ZWu
8231pJMQQED3i1ycJ4W98f5Jg+Z+LLFvGzA4g+gN15e+Q2YwI+KhZsHN4lqQiyu4lsMGggBsZWtI
OcqZZAw5Qbzw2rGb3UMtEWQIQ7qEEroxm+w6K1ix+k/+1JqnKQI+QGdEdTVAQ0CurW0LvGw8tzem
7UhBtAEay8ryksX5Gq85G8vqLDtqGNN07P9SzzWV1qobqZwU6BPzMexxPOSd731YKkSH7uVtbNvS
lrZzDnKwgPmiMKSSapJZ1Kjjwwibe4ADK1ayspMrrkdB9IbbzvYvze1diFrwirbWJcF2koi6EK8i
08mwla2LXHD5XX7NEcfLRzgy01xHoUev6ErX0ec4t0gajpQodTHEFFAy2QBX4HOglTE8B1iCOAtz
A75AJABAO2PapYB8fJ8BDDOeLwLekcVNACYCWcBs4DNgsvFoDhDivmXR/QnRzR3rqJUAOWPdcrZd
2LPqJCc/bk/7YbKZmiKBhN6TmbzvLd56J5nkIg11csOnHr33Slb6ArSkZdpMZs6SbD955JVdxCJz
8gO4oaBsUfXIYRtJRHtMAQZ2pOPk7nT/QIfOahkeeOQvZvEnGjQ3pWs6dC+aT3eN0+Glcs91Dzz2
hRDyXnE94IEriF7njRANjFWAaOBV46EAJO+2HkAU4vqXbhbKigX+ALrwwJ3QH9gHpvW+p4HWxuPb
edp5VVf3W6hyHCIupckMz8sfePh9+wY0+AhgOctP72d/n1rUWqJEmQlgwOByhStTOtJx22Qm+8kb
8Bmf1U0jzfSMW9DimCxa+SM/mhR4HemY4o67aSp+gxvtrTyjcsWx8xRNEnH1XAFz/0hGto4jbtAN
boxpQ5uNm9nsYy27P/7pH/DBKLnB7F/+HTeSka1BnA4HELBZ8lQHhOpUX3Gc41MsSfY2wIBIAj+g
AfAvcNwYfhVRgLuE6LzTFNgDHEYcLiwJ47sQPfn9gDeMz0GuNGsKHAOOJZLYPrjNF587rE436Y3u
zMz+Z1Ti2Gs86L3wxjsvlNBv5jL3TU889yBOU8khp+YNbtSS0kUS6bCd7Ws60tH0jCcy8VoZyvwq
pbnP/bbTmPaqLGxyo1SgsLboS4HoZmATbOlJPOGB0SiUUK/f+X2uFM4ks+FSlm4fwpAu1goYzvBb
7Wn/sayrVP7GbwsDCOixiEUhkr5EiTLLH/9x1nQDxcA5oCrQAThvDDdEfNGXEYnSDfH+pbW6roi9
gTl+QRxa3jQeEYi9j4QoYC4wt3WTpr2qbXR8UWH8O93dqEttd+7NIAWKsoi9WwH0oEfiMY5N60a3
dx1wiHDAIeIbvtkqxU9net888jwzyWy4jGU/nee8E8AgBi2UE+AXfpmsR6/QoVM642wShJ1wul3I
M9KCbcNO4SQR3Q5NVk49esUSlszLJ7+AoGXA4HyOc4ta03qBNS3hEpb88SIvzpPlcbrIxc8kfYka
dew7vBPwFV/Z7NlVCM4Zf7sCF4xHFeAl4zlAT8QX1xuRHDlYHnJ0wCFjWfWB3WbxeUB6v9o9W7ks
1TXVeIkMyc8UcFldMWZ9wsb+iMPUDmuNnc/8Cyc48fZUpo6Sa4oTSawnnTvh9FdDGmYCjGRkdBWq
mP5IOnQvDWFID0ccDSc4MaEGNZarUKWNYcw3hTwjAG9b3CCL6kl85GniiFPnkScngaBEaVK1J5H0
5nCGb5/O9FcsFRZCyE/lKf+9+XUt2guf8umASUy6WlSDbcQlxJeuQiRFCnBdFq6POJUPQiRGN+BH
oAVmjlJG7ET02chHlEfkqH9Se3JD7OCrvV1e15geuH6CKz+d21sFkZwLgLWFNdgRR0NveifIr+WS
azI5uOFWwAL8NV8HS8tJAC5zebz0B93Jzg3zmNfNXJ5LJlnVgQ5TZJ6BkndbobBOEoVpawcTqlAl
dwpTxtlhd1dKpUX7lzPOJhO5Hr3PbnZ/05WuoyxJ69vZ/rkLLqYxtSxld+1gx/uPIKAWBj2i4Poy
ovAJYs/xMnAU+Mt4LjcDLEaUWVIQZz0fyOLOGdO/YoyX0HIb21oO6dP7unb6g5UOuuv5htRfszdU
oII/8BZgciIqDrRoTQ7VGWRUksf54KNvSUuTh34eeZ4b2GCSR8yfZzjhzm/y5pp44t/5iZ9WbWWr
NEI4IYoUVmGZJKJWtYKlqN70TuhL3zGSc08GGa+VpezZmtRcJhsnlbe4NaIznTevZ32BmytDGcMy
lk20xz6qFrWWHOXoDB98nulV9daQSaZyYutRS6t95VTALzZmku7qnkuHVj1u+c1otlM6TyGl/Rzm
1JPHz2NeuBJlliyNVRWFG256aRTII897MYtXyfQo5QpbKWitJ/GiEE/6aUyLeI3XpmKUym9y80N3
3OP60e8d+XQ3i6z6QQRtCyCggMNOU5pm7GZ3v1BCixozn2k0blR/WsWvNX4q7YP+Onl/TlbdP+qv
r0rVxyb+Z3z2pyuuR0B0fNrBji/HMOZ1KX4Sk5rLvftzybXqlVaLWjmBBI5Ro44DyCa77ghGfG5U
YSiRyZ7meJgkD/YEKRTBBP/ii+9KKddZzn6WQ476e77v6433NimdUUCd15KWi+XrdJ/X3kNCx9qt
ujtOyuqsrWVneoZCnkDi5/l/778ddrCwvMXBRjZOcsTxb4B88t2PcWxNYxpva0SjHcc4tkaW1NCe
9scLK6sb3ZIGMGCUpJ+5z/3WPegxwRjtZq03sdSTeErXd7GrrB9++9vSdvZUpj7kMb6b3cGeeO4F
kel72LPyNKc9wgib44//WBUqk9o9hZQ3xjAmNJTQYmltHxdztHOqta3+eu+iUxajTJc51W71jBzl
2dehgM9p7JKse++GD5tnLd+joBa1cmYxa7QWrTQrI5vsOua7GFSm8roP+TC6qPImMvFaferPl8Jx
xAX0p39/RN2JxXdT0MAnyiJ1AKUevaIVrdakk25aeKRBc8sHn9196btnMINjQVwm0Ze+G7LIagDi
CrZVrApoStOMUEK9lrBknrSTkBtuv5zk5Ee2PJySwBztnGqbeq9cae+j1IwLCnx3ZPaY+Mct82/+
tu/eve23NXc411XI/mK5CfnEvaEMvXL+5qzHrcMSkklWBRAwMoaYAPkQo0CRX5nK63ayc7UtVvPP
+bx2CCGrzX1yWtN61EpWngSumu+8ZE6SchjZ1Ic+g69ydaKVugRnnMNrUnPXZCYfjibaMZDAED36
CgAuuPy2l70feuCRr0ev6E//gJvcHLCMZW9Lnu2lDYkgNTe5VBPyBa53zjlz/Ujc0Mctt2azil9U
3q1qpy5bcOJ2/b2M6xs3hg5sQYtS3a3oGMdcN7HJP4mkKlq0Kb3odext3r5bdE4YzegWJzm5RE4y
CUqUGYMZHPAJn/yBQIGVgw9IIutFFrKwzha2bJHWqADYYZeYR54HZkOUEmWWBx6HPfGMuMa1cdL6
XW+8t4YR9qmULpZY9ZOSQ+QEkbSf6Wf1uYYh3qvO/HN+46OW2+jl+sPt1iYNK9NMU8DukX5WnysM
rPDF6Wvh3z5ey0sPfek7MJLIycjeXxnKHBcQNFJPr0YdF0jggF70OoWAyQArf+EmWaQSldK0aAv4
OeST71aOcj9Wo9pqNeo70nUDBm0iiT2ucGWKfIH3Pe7160OfwVK4MIJ82fjLqn7D/fb4Dffb0/iD
xls7BXSasKbJmqoAwY2CK/sN99vTaHijXYdqHDIpuiZ0mtDE/33/1a+OePVYo+GNdg3uPbgbQJeW
Xd5Z33fFT3KCALg0Umvud4vpv9p+hcWpfVEY7DOoSc7Qe2+bEwQgfnpuxO/XNK+B354HR3ejnuWd
nmK4xbIHOTZUFK8NMC4hfW0ztC2VYSqNNGUHOkyLJHIqsvddgQrf/cIvY1ew4mNJKadHX2EBC1ad
4ESBRWBiJnEGZ/L3GMSguKMc/Z8vvisle4uAYHeXuwMSSGg6nvHvtaf9MHfcD8pX2ZnjKlc/Gc3o
163FS8i0z9TkqnKrueS6XPJN8Q2963y317f1v50OsLPOzh56pb5CjiqnWnCj4M5SnmNVj00FlP63
/We8kPDCBnW+OueG+w3785rfJ9RZ7+qgsGB0rzRHW3FJ8/mfPhxTOH7kR/dTnQ7NqDDW8SFbx931
upQ25zovU5BTCQQN1PxWPOoZF5Zdexv05SG1A6ytYrxjDeRWA51R8M2tAtnlzct+XJznvFNnOq+O
J36A7LKhLnXnHeLQIkccDY1pnDGWsaOMDt0YMDjFEFNg2ajELCcoqMN3xNGwm91f96HPIA2aW9L1
TDL9lrJ0233uu53gxMTlLG9Xm9qfy1XEDwpX5rzACzZvXemR5RGxbu+6rZo8zS2dna6mTq1TxjnH
dXPLcTvunOt8NrpMdHcAvVqvMCgNTjl2OT53ne9WeSPqjT/W71p/KM0+TaV1dTUk/5JtUbup1Cgo
/7n61SZ1X7XomW8JqaQqJ7cdu9x3tfahTfTyMwxkrlOd3ZD0zfmHc5ZNh2U1QfcS1AoCRS7sfmiB
V2nhO76rMJzh36aRZvqTKlFmtKHNh+b71A5mcGxPeo52xfXoKlYNHMjAezxw2jKRxKpn1CxmXdrA
hr5eeJkMVAYMLuGEL25N63nuuOu3s/3bs5zt1YMeg7zw2iHZc+pRb8FoRt+09caue1wf3nJIy5PZ
6uwXfFN9v5nRdkZjvUrvUzeh7j7fVN/9OrXupeVNl9dQ69VCp6hOU9T56oQrnlcmLXp90cHuA7t/
0CC+QdYb2V0+vrs6L0vQWxb0XRqpNWndY/t/Yb/EqnuDHM0bvRpY+Wv7V5WODxs4YmbpYmadXiib
8uZ5wvV+4nGpBhzqIZJj4g5wPQFx3SjGFluPijnMqbeUpVuyyTa5HahRxw5mcIA1h/NZzLr0K7+O
lS0AMy3FUBr34ipsjSkNaJB1hCMzm9L0Y7lfSBJJ3YcydFsggfVB1BAe4cjMjWxs44//2O/53qrl
0xLcde5HW0a3nLRp16bXQ0NCvzlX4VwPgLM+ZydEekZ+AHCo5qHuAL0jel/9fd3vQ9fsXdPCUe94
+Y7Lne73XO7ZTfxt4ulRYeP631mUlWitnkpzHX1WNFv8WVHtaV+nZQ/HaTmdHGuoHtIn6aLyDQ4/
exwMIEC2+MnhGoS/JR5fHIa7bwIKGPUDpPuB3gem+5mXVZIYytCO29m+SbKuA2jR/jWHOQM/4ROr
yz4swEkacuwQGWOTh1owwYe3svXP5Syfn0HGayDu77GLXZsvcvGr7/n+6zKUMTSkYeajmPzdde5X
g/aLTD9f8bxTsmNyhzI5ZX6tnVR7N0CEV8Tb8c7xb+rUuhVDuw89XCanzO8qg0qXY5dTo1xGue2/
VP+l7OfNPt/qmuN6WverOjPnTn5Z+4oPCydKjYLyi9UNGg9uMDQ84k+LviuzXGb5xvS+8mGVXlqL
62pvT8q+8ts/py3uuChi6uuQVxYqrYPyRuv2+dkQ3gMqb3g4fdbL0NQ486p4FBu2/jLHUIZ2PMOZ
JcgWy7njfmg966fVotajOHC5Akmq2cz2oZDlEeZ4iZcy3+XdPWGE6VJIaYTxOzGppDYJIaSpGvWZ
V3ilWOtgUu1TueZ5LfvlhJfD295oexdgZ92dPvec7mV2+rfTlsWHF5/pGdkzKtot+nqmOjPTI8fj
31xV7p+ZmkxHBQrhhcQXtkw+NXl7w/iGaRFlI27r1Dqtm73nnZtHYsp69tZYfMn2PipVwq2UKrln
haPN8guu27nABYepXcZ+6bvWqbrCwuCQvCc3w3fdy8tGpI269uDqL4DnP/CWcYfFA5WBW7AiGN6L
hJ5R8Hs8qHTwxl9wJVsUbtvFw8+AcyRoY8Wj0lXoWqT21ByVqBR/kIOt88jzBKhM5eADHPjMC69C
1zwXAhWzSVEICM6Iw40LxSALiDsWhRK6SL4zcjWqrd7Dnq8esVElik7V23VJXhMx272jvUXDlyFX
IKpT1rmrx2L+p0FjEmJq+PsEVdmlbqP2fLiDFfQCUe2zf79xIv6DhyKfAWxms89ylm9+iZdWFrY2
uRi4Yq5xdUQkSxlEJ5siEUmkwyhGTbrHvb6OOF46yMFBHngUewFQaaF6mwrBNX62b6pQW5YX08/q
c3MDPNaei/zrawC/+vVHar5Oft/lNbVFR+GY+Vn3+s8b/v6srLk3S6/Vj4drXLN/xOHFEuKtL84S
LYJSD+NEEbsmjmBEmwY0uD6SkcXuJksTi7TzK2+atmJT5elaq6bwm5MzYoet+OT9C+UuVP570vEF
FUY5WnTCyb2XT/wbqm2RF27MKb0WP3PQ2baCT1TZS8OSMyX4vZkngXp+Nad67sodYF9RZZHohlyB
K20yL9q/iFv1YOdq1sr5d0jGv999s3tgM5o9N9+qeURIX//KBDIeZS2w9IEiaVh66nufF4UoojSd
BjYPqfG9Uy1raTIj9YJjNTuF0sHKsHRGn6MY5LP8t6g/HvLR/Y8gmwefhMuUf0ewJDaxceDBsFTi
+3WVFN6o0a5L0qqIWe5v2Bd32SgIcLVT5sWrh2MGywXc5xw5GHsKRFJYlSMff880gWwE7iHwL+Lq
uVhjxc/Uwzz4b9j+pMXCn9Y0sYXhbrAupcPZN5c+5wTRI65UjAGuIHDMvDIRAAACvUlEQVQNgVgE
0oraaaBkd18U0COQjMBNxEVMt40NeyZmOyPPjJt7Z5HOJt8LCfkZBjI32IUHp2y4WHTqZwp5iN/N
iUV0JLqCQAxC8T/n9mQ+QPDge73SsPTE9kU3x8t+taa478we6FDJziYbys2PMm/P/uKLQQMZWJJL
PkoDBuTDB2SXVF/+dL6cJcoxkuD7ROWYKKI0nQY0/6HGFqfaRaXNupZnyOjpvO7i5YiVRaV9CpCW
p0rEyC6tL1c8nQ/tiHJMglGOiUTsEtN5AnJMTWrm1jndIDjlYE6R09g7E7Ov7L8ctqaodE8IAuKa
5ATgBnAZgZvG56grzU+bPBvf4JMgWqTlZoJS08fUaFt+bfWDDs2taWKTd+VkVBhVb+aeO4cOW0zw
ZGB1Wvok8Wx9nVvAYJS2YxB7mBtAIjzahnCFYcSZ8Z/eWWhZiBX0AklLDX89BYLkAMnALSACgSgE
4hFIf1oEgWeNJHIICAhkGh/SVeAacBdK5svcEzOnxCh3uh7Kjsl7qCuNWai7N/SPD+dbylfCeORp
6ZPEszXc2ArRGUYSfJ14RLJHE61uM7DxDzW/d6ojXcuNzye+s91PkRevzy0s7yMiD7mw+YhbZj5p
PLs9SWEQyEMgBYFoxGEpGnG1f7H8JqpSVf/C768EJx94IMTenqSL+vbij4tLqKUGRIE8DnGzm0gE
bht1Sc8FQeB57UmsQZRBtTzoZWzaF6xG2wpf+R6w9884p89RDaq09NT1M1Z3pi4C8mlpJpTurONJ
4b9FEnOIu/hIMyUtVtwdvrBf4vPVtMWbs08KcTd/uRdgKY0VFLCWAln/BVKY479NEjlEdweph3HG
bKh9sXatiS0TWv/8VUrwX0WU9ExMS58k/v+QRA7RTODMA9IU9v06m62l/1X8/ySJHOIA5EhBBZ6c
FM/1Piolgf8Do6DT7EsG7IgAAAAASUVORK5CYII=
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.016,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533
			C449.069,388.524,449.449,387.957,449.729,387.178z M443.669,384.194h6.08c-0.082-0.916-0.314-1.603-0.697-2.061
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C444.05,382.485,443.73,383.244,443.669,384.194z"/>
		<path d="M454.477,390.685v-2.102h2.103v2.102H454.477z"/>
		<path d="M151.095,418.989v-15.032h5.178c1.169,0,2.061,0.072,2.676,0.215c0.861,0.198,1.596,0.557,2.205,1.077
			c0.793,0.67,1.386,1.526,1.779,2.568c0.393,1.043,0.59,2.234,0.59,3.574c0,1.142-0.133,2.153-0.4,3.035s-0.608,1.612-1.025,2.189
			c-0.417,0.578-0.874,1.033-1.369,1.364c-0.496,0.332-1.094,0.583-1.795,0.753s-1.505,0.256-2.415,0.256H151.095z M153.084,417.215
			h3.209c0.991,0,1.769-0.092,2.333-0.277c0.564-0.185,1.014-0.444,1.349-0.779c0.472-0.472,0.839-1.105,1.103-1.902
			c0.263-0.796,0.395-1.762,0.395-2.896c0-1.572-0.258-2.78-0.774-3.625c-0.516-0.844-1.143-1.41-1.881-1.697
			c-0.533-0.205-1.391-0.308-2.574-0.308h-3.158V417.215z"/>
		<path d="M166.035,406.08v-2.123h1.846v2.123H166.035z M166.035,418.989V408.1h1.846v10.89H166.035z"/>
		<path d="M169.952,415.739l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C170.63,417.766,170.157,416.894,169.952,415.739z"/>
		<path d="M185.22,417.338l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354V408.1h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856v6.368
			c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C184.615,417.41,184.885,417.386,185.22,417.338z"/>
		<path d="M187.004,418.989V408.1h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H187.004z"/>
		<path d="M194.028,406.08v-2.123h1.846v2.123H194.028z M194.028,418.989V408.1h1.846v10.89H194.028z"/>
		<path d="M200.386,418.989h-1.712v-15.032h1.846v5.363c0.779-0.978,1.774-1.466,2.984-1.466c0.67,0,1.304,0.135,1.902,0.405
			s1.09,0.649,1.477,1.138c0.386,0.489,0.689,1.079,0.908,1.769s0.328,1.429,0.328,2.215c0,1.866-0.461,3.309-1.384,4.327
			s-2.03,1.528-3.322,1.528c-1.285,0-2.293-0.537-3.025-1.61V418.989z M200.365,413.462c0,1.306,0.178,2.249,0.533,2.83
			c0.581,0.95,1.367,1.425,2.358,1.425c0.807,0,1.504-0.35,2.092-1.051s0.882-1.745,0.882-3.133c0-1.422-0.282-2.471-0.846-3.148
			c-0.563-0.677-1.246-1.015-2.045-1.015c-0.807,0-1.504,0.351-2.092,1.051C200.659,411.123,200.365,412.136,200.365,413.462z"/>
		<path d="M217.5,418.989v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.555-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723V408.1h1.846v6.04c0,0.964,0.038,1.613,0.113,1.948
			c0.116,0.485,0.362,0.867,0.738,1.143c0.376,0.277,0.841,0.416,1.395,0.416s1.073-0.142,1.559-0.425s0.829-0.67,1.03-1.159
			c0.202-0.488,0.303-1.198,0.303-2.127V408.1h1.846v10.89H217.5z"/>
		<path d="M226.072,417.338l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354V408.1h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856v6.368
			c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C225.467,417.41,225.737,417.386,226.072,417.338z"/>
		<path d="M235.331,415.482l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S235.051,416.262,235.331,415.482z
			 M229.271,412.499h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S229.333,411.548,229.271,412.499z"/>
		<path d="M249.42,417.338l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354V408.1h1.354v-2.697l1.835-1.107v3.804h1.856v1.436h-1.856v6.368
			c0,0.526,0.032,0.865,0.097,1.015s0.171,0.27,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C248.815,417.41,249.085,417.386,249.42,417.338z"/>
		<path d="M258.331,417.646c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.092,0.882,0.092,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308H258.7
			C258.508,418.606,258.385,418.159,258.331,417.646z M258.177,413.524c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V413.524z"
			/>
		<path d="M262.166,415.739l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C262.844,417.766,262.371,416.894,262.166,415.739z"/>
		<path d="M273.414,418.989v-15.032h1.846v8.572l4.368-4.43h2.389l-4.163,4.04l4.583,6.85h-2.276l-3.599-5.568l-1.302,1.251v4.317
			H273.414z"/>
		<path d="M283.166,415.739l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C283.844,417.766,283.371,416.894,283.166,415.739z"/>
		<path d="M299.551,413.544c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.427-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.466C300.021,416.792,299.551,415.383,299.551,413.544z M301.448,413.544
			c0,1.395,0.304,2.439,0.913,3.132c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046s0.913-1.76,0.913-3.189
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S301.448,412.15,301.448,413.544z"/>
		<path d="M314.942,418.989L310.8,408.1h1.948l2.338,6.521c0.253,0.704,0.485,1.436,0.697,2.194
			c0.164-0.574,0.393-1.265,0.687-2.071l2.42-6.645h1.897l-4.122,10.89H314.942z"/>
		<path d="M329.872,415.482l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S329.592,416.262,329.872,415.482z
			 M323.812,412.499h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S323.874,411.548,323.812,412.499z"/>
		<path d="M334.076,418.989V408.1h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H334.076z"/>
		<path d="M346.237,413.544c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.427-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.466C346.707,416.792,346.237,415.383,346.237,413.544z M348.134,413.544
			c0,1.395,0.304,2.439,0.913,3.132c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046s0.913-1.76,0.913-3.189
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S348.134,412.15,348.134,413.544z"/>
		<path d="M358.604,418.989V408.1h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687s-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333c-0.786,0-1.465,0.25-2.036,0.749
			s-0.856,1.446-0.856,2.84v5.947H358.604z"/>
		<path d="M377.737,415.482l1.908,0.236c-0.301,1.114-0.858,1.979-1.672,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.016,2.748c0.607,0.636,1.367,0.954,2.275,0.954c0.678,0,1.255-0.178,1.733-0.533
			S377.458,416.262,377.737,415.482z M371.677,412.499h6.081c-0.082-0.916-0.314-1.603-0.697-2.061
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.139,0.851C372.058,410.79,371.739,411.548,371.677,412.499z"/>
		<path d="M387.11,413.544c0-2.017,0.561-3.51,1.682-4.481c0.936-0.807,2.078-1.21,3.424-1.21c1.498,0,2.721,0.491,3.672,1.472
			c0.949,0.981,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.422,0.804-1.033,1.427-1.836,1.872
			c-0.804,0.444-1.68,0.667-2.631,0.667c-1.523,0-2.756-0.489-3.695-1.466C387.579,416.792,387.11,415.383,387.11,413.544z
			 M389.006,413.544c0,1.395,0.305,2.439,0.912,3.132c0.609,0.694,1.375,1.041,2.297,1.041c0.916,0,1.679-0.349,2.287-1.046
			s0.912-1.76,0.912-3.189c0-1.347-0.306-2.367-0.918-3.061c-0.611-0.693-1.371-1.041-2.281-1.041c-0.922,0-1.688,0.345-2.297,1.036
			C389.311,411.107,389.006,412.15,389.006,413.544z"/>
		<path d="M399.456,418.989V408.1h1.66v1.651c0.424-0.772,0.815-1.282,1.175-1.528c0.358-0.246,0.753-0.369,1.185-0.369
			c0.621,0,1.254,0.198,1.896,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.551,0.579-0.688,1.01c-0.205,0.656-0.307,1.374-0.307,2.153v5.701H399.456z"/>
		<path d="M412.304,418.989V408.1h1.65v1.528c0.342-0.533,0.796-0.962,1.363-1.287s1.214-0.487,1.938-0.487
			c0.807,0,1.468,0.167,1.984,0.502c0.516,0.335,0.88,0.803,1.092,1.405c0.861-1.271,1.982-1.907,3.363-1.907
			c1.08,0,1.91,0.299,2.491,0.897s0.872,1.519,0.872,2.763v7.475h-1.835v-6.86c0-0.738-0.061-1.27-0.18-1.594
			c-0.12-0.325-0.337-0.586-0.651-0.785s-0.684-0.297-1.107-0.297c-0.766,0-1.401,0.255-1.907,0.764
			c-0.506,0.51-0.759,1.325-0.759,2.446v6.327h-1.846v-7.075c0-0.82-0.15-1.436-0.451-1.846s-0.793-0.615-1.477-0.615
			c-0.52,0-1,0.137-1.44,0.41c-0.441,0.273-0.761,0.673-0.959,1.2s-0.297,1.285-0.297,2.276v5.65H412.304z"/>
		<path d="M436.903,417.646c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062c0.394-0.267,0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.414,0.011-0.482c0-0.752-0.175-1.282-0.522-1.589
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.152-1.923,0.457c-0.413,0.304-0.72,0.842-0.918,1.615l-1.805-0.246
			c0.164-0.772,0.435-1.396,0.811-1.872c0.376-0.475,0.919-0.841,1.631-1.097c0.71-0.257,1.534-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.093,0.882,0.093,1.702v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C437.081,418.606,436.958,418.159,436.903,417.646z M436.749,413.524c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.558,0.337-0.728,0.6c-0.172,0.263-0.257,0.555-0.257,0.876
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.155,1.896-0.466
			c0.555-0.311,0.961-0.737,1.221-1.277c0.198-0.417,0.297-1.032,0.297-1.846V413.524z"/>
		<path d="M441.476,418.989V408.1h1.66v1.548c0.801-1.196,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.446-0.855,2.84v5.947H441.476z"/>
		<path d="M453.074,423.183l-0.205-1.733c0.402,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.447-0.328,0.604-0.574c0.116-0.185,0.305-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.133-10.91h1.99
			l2.266,6.306c0.294,0.8,0.557,1.641,0.789,2.522c0.212-0.848,0.465-1.675,0.76-2.481l2.327-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.02-1.036,2.471c-0.328,0.608-0.704,1.054-1.127,1.338c-0.425,0.283-0.931,0.425-1.518,0.425
			C453.907,423.409,453.51,423.333,453.074,423.183z"/>
		<path d="M469.49,418.989v-15.032h1.846v5.394c0.861-0.998,1.947-1.497,3.26-1.497c0.807,0,1.508,0.159,2.103,0.477
			c0.595,0.318,1.021,0.757,1.276,1.318c0.257,0.561,0.385,1.374,0.385,2.44v6.901h-1.846v-6.901c0-0.923-0.2-1.594-0.6-2.015
			c-0.4-0.42-0.966-0.63-1.697-0.63c-0.547,0-1.062,0.142-1.543,0.425c-0.482,0.284-0.826,0.668-1.031,1.154
			s-0.307,1.155-0.307,2.01v5.958H469.49z"/>
		<path d="M480.482,413.544c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.427-1.836,1.872
			c-0.803,0.444-1.68,0.667-2.63,0.667c-1.524,0-2.757-0.489-3.696-1.466C480.952,416.792,480.482,415.383,480.482,413.544z
			 M482.378,413.544c0,1.395,0.305,2.439,0.913,3.132c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.189c0-1.347-0.306-2.367-0.918-3.061c-0.611-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S482.378,412.15,482.378,413.544z"/>
		<path d="M492.111,415.739l1.824-0.287c0.104,0.731,0.389,1.292,0.856,1.682c0.469,0.39,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984c-0.254-0.164-0.883-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.679-0.391,1.174-0.538
			c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.122,0.579,1.431,1
			c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313c-0.394-0.314-0.948-0.472-1.667-0.472
			c-0.848,0-1.452,0.14-1.814,0.42s-0.543,0.608-0.543,0.984c0,0.239,0.074,0.455,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738c-0.358,0.543-0.876,0.964-1.554,1.261
			c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882C492.789,417.766,492.316,416.894,492.111,415.739z"/>
		<path d="M507.378,417.338l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.318
			s-0.629-0.49-0.779-0.835s-0.226-1.072-0.226-2.179v-6.265h-1.354V408.1h1.354v-2.697l1.836-1.107v3.804h1.855v1.436h-1.855v6.368
			c0,0.526,0.032,0.865,0.097,1.015c0.065,0.15,0.171,0.27,0.318,0.359c0.146,0.089,0.356,0.133,0.63,0.133
			C506.773,417.41,507.043,417.386,507.378,417.338z"/>
		<path d="M508.445,415.739l1.824-0.287c0.104,0.731,0.389,1.292,0.856,1.682c0.469,0.39,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984c-0.254-0.164-0.883-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.679-0.391,1.174-0.538
			c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.122,0.579,1.431,1
			c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313c-0.394-0.314-0.948-0.472-1.667-0.472
			c-0.848,0-1.452,0.14-1.814,0.42s-0.543,0.608-0.543,0.984c0,0.239,0.074,0.455,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738c-0.358,0.543-0.876,0.964-1.554,1.261
			c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882C509.123,417.766,508.65,416.894,508.445,415.739z"/>
		<path d="M520.206,418.989v-2.102h2.103v2.102H520.206z"/>
		<path d="M150.49,468.277c0-2.495,0.67-4.448,2.01-5.86c1.34-1.411,3.069-2.117,5.188-2.117c1.388,0,2.639,0.332,3.753,0.995
			s1.963,1.588,2.548,2.774c0.584,1.186,0.876,2.531,0.876,4.035c0,1.524-0.308,2.888-0.923,4.091s-1.487,2.114-2.615,2.732
			c-1.128,0.619-2.345,0.928-3.65,0.928c-1.415,0-2.68-0.342-3.794-1.025s-1.958-1.617-2.533-2.799S150.49,469.597,150.49,468.277z
			 M152.541,468.308c0,1.812,0.487,3.239,1.461,4.281c0.974,1.043,2.196,1.564,3.666,1.564c1.497,0,2.729-0.526,3.697-1.579
			c0.967-1.053,1.451-2.546,1.451-4.481c0-1.224-0.207-2.292-0.621-3.204c-0.414-0.913-1.019-1.62-1.814-2.123
			c-0.797-0.502-1.69-0.753-2.682-0.753c-1.408,0-2.62,0.484-3.635,1.451C153.048,464.431,152.541,466.045,152.541,468.308z"/>
		<path d="M167.173,475.599v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H167.173z"/>
		<path d="M173.849,476.501l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.166,0.133-2.369
			c-0.807,0.95-1.812,1.425-3.015,1.425c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.876
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.266-1.641,1.676c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.292-3.148-0.876C174.208,478.557,173.821,477.677,173.849,476.501z M175.376,469.959
			c0,1.429,0.284,2.471,0.851,3.127s1.278,0.984,2.133,0.984c0.848,0,1.559-0.326,2.133-0.979s0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,1
			C175.664,467.657,175.376,468.646,175.376,469.959z"/>
		<path d="M192.972,474.255c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.092,0.882,0.092,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C193.15,475.216,193.027,474.768,192.972,474.255z M192.818,470.133c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V470.133z"
			/>
		<path d="M197.545,475.599v-10.89h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687s-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333c-0.786,0-1.465,0.25-2.036,0.749
			s-0.856,1.446-0.856,2.84v5.947H197.545z"/>
		<path d="M209.235,462.689v-2.123h1.846v2.123H209.235z M209.235,475.599v-10.89h1.846v10.89H209.235z"/>
		<path d="M212.916,475.599v-1.497l6.932-7.957c-0.786,0.041-1.48,0.062-2.082,0.062h-4.44v-1.497h8.9v1.22l-5.896,6.911
			l-1.138,1.261c0.827-0.062,1.603-0.092,2.328-0.092h5.035v1.589H212.916z"/>
		<path d="M231.845,472.092l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S231.564,472.871,231.845,472.092z
			 M225.785,469.108h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S225.846,468.158,225.785,469.108z"/>
		<path d="M241.883,475.599v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H241.883z"/>
		<path d="M256.034,475.599v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.555-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.964,0.038,1.613,0.113,1.948
			c0.116,0.485,0.362,0.867,0.738,1.143c0.376,0.277,0.841,0.416,1.395,0.416s1.073-0.142,1.559-0.425s0.829-0.67,1.03-1.159
			c0.202-0.488,0.303-1.198,0.303-2.127v-5.834h1.846v10.89H256.034z"/>
		<path d="M260.576,475.599v-10.89h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687s-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333c-0.786,0-1.465,0.25-2.036,0.749
			s-0.856,1.446-0.856,2.84v5.947H260.576z"/>
		<path d="M271.517,472.348l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C272.195,474.375,271.722,473.503,271.517,472.348z"/>
		<path d="M290.292,475.599h-1.712v-15.032h1.846v5.363c0.779-0.978,1.774-1.466,2.984-1.466c0.67,0,1.304,0.135,1.902,0.405
			s1.09,0.649,1.477,1.138c0.386,0.489,0.689,1.079,0.908,1.769s0.328,1.429,0.328,2.215c0,1.866-0.461,3.309-1.384,4.327
			s-2.03,1.528-3.322,1.528c-1.285,0-2.293-0.537-3.025-1.61V475.599z M290.271,470.072c0,1.306,0.178,2.249,0.533,2.83
			c0.581,0.95,1.367,1.425,2.358,1.425c0.807,0,1.504-0.35,2.092-1.051s0.882-1.745,0.882-3.133c0-1.422-0.282-2.471-0.846-3.148
			c-0.563-0.677-1.246-1.015-2.045-1.015c-0.807,0-1.504,0.351-2.092,1.051C290.565,467.732,290.271,468.746,290.271,470.072z"/>
		<path d="M300.187,479.792l-0.205-1.733c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.132-10.91h1.989
			l2.266,6.306c0.294,0.8,0.557,1.641,0.79,2.522c0.212-0.848,0.465-1.675,0.759-2.481l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.02-1.036,2.471c-0.328,0.608-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.425-1.518,0.425
			C301.021,480.018,300.625,479.943,300.187,479.792z"/>
		<path d="M323.709,474.255c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.092,0.882,0.092,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C323.887,475.216,323.764,474.768,323.709,474.255z M323.556,470.133c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V470.133z"
			/>
		<path d="M328.283,475.599v-10.89h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687s-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333c-0.786,0-1.465,0.25-2.036,0.749
			s-0.856,1.446-0.856,2.84v5.947H328.283z"/>
		<path d="M339.88,479.792l-0.205-1.733c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.132-10.91h1.989
			l2.266,6.306c0.294,0.8,0.557,1.641,0.79,2.522c0.212-0.848,0.465-1.675,0.759-2.481l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.02-1.036,2.471c-0.328,0.608-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.425-1.518,0.425
			C340.714,480.018,340.317,479.943,339.88,479.792z"/>
		<path d="M359.321,475.599l-4.143-10.89h1.948l2.338,6.521c0.253,0.704,0.485,1.436,0.697,2.194
			c0.164-0.574,0.393-1.265,0.687-2.071l2.42-6.645h1.897l-4.122,10.89H359.321z"/>
		<path d="M373.903,474.255c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.522-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.281,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.063,0.314,0.093,0.882,0.093,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.078,0.455,0.234,0.891,0.467,1.308h-1.928
			C374.081,475.216,373.958,474.768,373.903,474.255z M373.749,470.133c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.961-0.737,1.221-1.277c0.197-0.417,0.297-1.032,0.297-1.846V470.133z
			"/>
		<path d="M378.456,475.599v-10.89h1.66v1.651c0.424-0.772,0.815-1.282,1.175-1.528c0.358-0.246,0.753-0.369,1.185-0.369
			c0.621,0,1.254,0.198,1.896,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.551,0.579-0.688,1.01c-0.205,0.656-0.307,1.374-0.307,2.153v5.701H378.456z"/>
		<path d="M385.479,462.689v-2.123h1.846v2.123H385.479z M385.479,475.599v-10.89h1.846v10.89H385.479z"/>
		<path d="M397.241,474.255c-0.684,0.581-1.342,0.991-1.975,1.23s-1.311,0.359-2.035,0.359c-1.196,0-2.115-0.292-2.758-0.877
			c-0.643-0.584-0.965-1.331-0.965-2.24c0-0.533,0.121-1.021,0.365-1.461c0.242-0.441,0.56-0.795,0.953-1.062
			c0.393-0.267,0.836-0.468,1.328-0.605c0.361-0.096,0.908-0.188,1.641-0.277c1.49-0.178,2.587-0.39,3.291-0.636
			c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.522-1.589c-0.472-0.417-1.173-0.625-2.103-0.625
			c-0.867,0-1.509,0.152-1.922,0.457c-0.414,0.304-0.72,0.842-0.918,1.615l-1.805-0.246c0.164-0.772,0.434-1.396,0.811-1.872
			c0.375-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.534-0.385,2.472-0.385c0.93,0,1.685,0.109,2.266,0.328
			s1.008,0.494,1.281,0.825c0.273,0.332,0.465,0.75,0.574,1.256c0.063,0.314,0.093,0.882,0.093,1.702v2.461
			c0,1.716,0.039,2.801,0.118,3.255c0.078,0.455,0.234,0.891,0.467,1.308h-1.928C397.418,475.216,397.295,474.768,397.241,474.255z
			 M397.086,470.133c-0.67,0.273-1.675,0.506-3.015,0.697c-0.759,0.109-1.296,0.232-1.61,0.369s-0.557,0.337-0.728,0.6
			s-0.257,0.555-0.257,0.876c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.637,0.492c0.711,0,1.343-0.155,1.896-0.466
			s0.961-0.737,1.221-1.277c0.197-0.417,0.297-1.032,0.297-1.846V470.133z"/>
		<path d="M403.516,475.599h-1.713v-15.032h1.846v5.363c0.779-0.978,1.773-1.466,2.984-1.466c0.67,0,1.303,0.135,1.901,0.405
			s1.091,0.649,1.477,1.138c0.386,0.489,0.689,1.079,0.908,1.769s0.328,1.429,0.328,2.215c0,1.866-0.462,3.309-1.385,4.327
			s-2.03,1.528-3.322,1.528c-1.285,0-2.294-0.537-3.024-1.61V475.599z M403.495,470.072c0,1.306,0.178,2.249,0.533,2.83
			c0.582,0.95,1.367,1.425,2.359,1.425c0.807,0,1.504-0.35,2.092-1.051s0.881-1.745,0.881-3.133c0-1.422-0.281-2.471-0.846-3.148
			c-0.563-0.677-1.246-1.015-2.045-1.015c-0.807,0-1.504,0.351-2.092,1.051C403.79,467.732,403.495,468.746,403.495,470.072z"/>
		<path d="M413.453,475.599v-15.032h1.846v15.032H413.453z"/>
		<path d="M425.614,472.092l1.907,0.236c-0.301,1.114-0.858,1.979-1.672,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.016,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533
			C424.954,473.438,425.333,472.871,425.614,472.092z M419.554,469.108h6.08c-0.082-0.916-0.314-1.603-0.697-2.061
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C419.935,467.399,419.615,468.158,419.554,469.108z"/>
		<path d="M429.101,472.348l1.824-0.287c0.104,0.731,0.389,1.292,0.856,1.682c0.469,0.39,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984c-0.254-0.164-0.883-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.679-0.391,1.174-0.538
			c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.122,0.579,1.431,1
			c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313c-0.394-0.314-0.948-0.472-1.667-0.472
			c-0.848,0-1.452,0.14-1.814,0.42s-0.543,0.608-0.543,0.984c0,0.239,0.074,0.455,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738c-0.358,0.543-0.876,0.964-1.554,1.261
			c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882C429.779,474.375,429.306,473.503,429.101,472.348z"/>
		<path d="M440.821,475.599v-2.102h2.103v2.102c0,0.772-0.138,1.396-0.41,1.871c-0.274,0.475-0.708,0.843-1.303,1.103l-0.513-0.79
			c0.39-0.171,0.677-0.422,0.861-0.753c0.185-0.332,0.287-0.809,0.308-1.431H440.821z"/>
		<path d="M459.461,472.092l1.907,0.236c-0.301,1.114-0.858,1.979-1.672,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.016,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533
			C458.801,473.438,459.181,472.871,459.461,472.092z M453.402,469.108h6.08c-0.082-0.916-0.314-1.603-0.697-2.061
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C453.783,467.399,453.462,468.158,453.402,469.108z"/>
		<path d="M464.209,475.599v-2.102h2.103v2.102H464.209z"/>
		<path d="M469.182,476.501l1.794,0.267c0.075,0.554,0.284,0.957,0.626,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.515-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.166,0.134-2.369
			c-0.808,0.95-1.813,1.425-3.016,1.425c-1.496,0-2.655-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.563-2.876
			c0.376-0.878,0.922-1.557,1.636-2.035c0.715-0.479,1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.266-1.641,1.676c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.349-0.292-3.147-0.876C469.541,478.557,469.155,477.677,469.182,476.501z M470.71,469.959
			c0,1.429,0.283,2.471,0.851,3.127s1.278,0.984,2.133,0.984c0.848,0,1.559-0.326,2.133-0.979s0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.305-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,1
			C470.998,467.657,470.71,468.646,470.71,469.959z"/>
		<path d="M481.712,466.811v-2.102h2.103v2.102H481.712z M481.712,475.599v-2.102h2.103v2.102H481.712z"/>
		<path d="M174.177,503.903v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H174.177z"/>
		<path d="M188.645,500.396l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S188.365,501.176,188.645,500.396z
			 M182.585,497.413h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S182.646,496.462,182.585,497.413z"/>
		<path d="M192.829,503.903v-15.032h1.846v15.032H192.829z"/>
		<path d="M204.99,500.396l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S204.709,501.176,204.99,500.396z
			 M198.93,497.413h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S198.991,496.462,198.93,497.413z"/>
		<path d="M216.32,502.56c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.605c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246
			c0.164-0.772,0.434-1.396,0.81-1.872c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256
			c0.062,0.314,0.092,0.882,0.092,1.702v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C216.498,503.521,216.375,503.073,216.32,502.56z M216.167,498.438c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.6s-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23
			s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466s0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V498.438z"
			/>
		<path d="M220.155,500.653l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.172,1.887-0.518s0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984c-0.253-0.164-0.882-0.373-1.887-0.625
			c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036c-0.27-0.44-0.405-0.928-0.405-1.461
			c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03c0.287-0.212,0.678-0.391,1.174-0.538
			s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687
			l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.14-1.815,0.42
			s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969
			s0.441,0.95,0.441,1.579c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261
			c-0.677,0.298-1.442,0.446-2.297,0.446c-1.415,0-2.494-0.294-3.235-0.882C220.833,502.68,220.36,501.808,220.155,500.653z"/>
		<path d="M238.848,500.396l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S238.568,501.176,238.848,500.396z
			 M232.788,497.413h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S232.85,496.462,232.788,497.413z"/>
		<path d="M173.859,533.111l1.794,0.266c0.075,0.555,0.284,0.957,0.625,1.211c0.458,0.342,1.083,0.512,1.876,0.512
			c0.854,0,1.514-0.17,1.979-0.512s0.779-0.82,0.943-1.436c0.096-0.377,0.14-1.166,0.133-2.369c-0.807,0.95-1.812,1.426-3.015,1.426
			c-1.497,0-2.656-0.541-3.476-1.621s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.876c0.376-0.878,0.921-1.557,1.635-2.035
			s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.414c0,1.695-0.173,2.896-0.518,3.604
			c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615c-1.299,0-2.348-0.292-3.148-0.876
			C174.218,535.166,173.832,534.287,173.859,533.111z M175.387,526.568c0,1.429,0.284,2.471,0.851,3.127s1.278,0.984,2.133,0.984
			c0.848,0,1.559-0.326,2.133-0.979c0.574-0.652,0.861-1.676,0.861-3.071c0-1.333-0.296-2.338-0.887-3.015
			c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,1C175.674,524.267,175.387,525.256,175.387,526.568z"/>
		<path d="M185.887,519.298v-2.123h1.846v2.123H185.887z M185.887,532.208v-10.89h1.846v10.89H185.887z"/>
		<path d="M194.572,530.557l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.105-1.559-0.317
			s-0.629-0.49-0.779-0.835c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.697l1.835-1.107v3.804h1.856v1.436
			h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.359c0.146,0.089,0.357,0.133,0.63,0.133
			C193.967,530.628,194.237,530.605,194.572,530.557z"/>
		<path d="M201.524,526.763c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.402-0.21,2.503-0.63,3.306c-0.421,0.805-1.033,1.428-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.467C201.994,530.01,201.524,528.602,201.524,526.763z M203.421,526.763
			c0,1.395,0.304,2.439,0.913,3.133s1.374,1.041,2.297,1.041c0.916,0,1.678-0.35,2.287-1.047s0.913-1.76,0.913-3.188
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S203.421,525.369,203.421,526.763z"/>
		<path d="M213.87,532.208v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.712c-0.451-0.267-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.122-1.087,0.364
			s-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.702H213.87z"/>
		<path d="M227.159,532.208v-9.455h-1.63v-1.436h1.63v-1.159c0-0.731,0.065-1.275,0.195-1.63c0.178-0.479,0.49-0.866,0.938-1.164
			c0.448-0.297,1.075-0.446,1.882-0.446c0.52,0,1.094,0.062,1.723,0.185l-0.277,1.61c-0.383-0.068-0.745-0.103-1.087-0.103
			c-0.561,0-0.957,0.12-1.189,0.359s-0.349,0.687-0.349,1.343v1.005h2.123v1.436h-2.123v9.455H227.159z"/>
		<path d="M231.865,526.763c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.402-0.21,2.503-0.63,3.306c-0.421,0.805-1.033,1.428-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.467C232.335,530.01,231.865,528.602,231.865,526.763z M233.762,526.763
			c0,1.395,0.304,2.439,0.913,3.133s1.374,1.041,2.297,1.041c0.916,0,1.678-0.35,2.287-1.047s0.913-1.76,0.913-3.188
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S233.762,525.369,233.762,526.763z"/>
		<path d="M243.493,528.958l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.585,1.964,0.585
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.751,0.615-1.216c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.372-1.887-0.626c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.249-0.919-0.594-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.391,1.174-0.538s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1
			c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472
			c-0.848,0-1.453,0.14-1.815,0.42s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.544,1.215,0.968
			s0.441,0.951,0.441,1.58c0,0.615-0.179,1.193-0.539,1.738c-0.358,0.543-0.876,0.963-1.553,1.26
			c-0.677,0.299-1.442,0.447-2.297,0.447c-1.415,0-2.494-0.295-3.235-0.883C244.171,530.984,243.698,530.113,243.493,528.958z"/>
		<path d="M253.993,528.958l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.585,1.964,0.585
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.751,0.615-1.216c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.372-1.887-0.626c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.249-0.919-0.594-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.391,1.174-0.538s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1
			c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472
			c-0.848,0-1.453,0.14-1.815,0.42s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.544,1.215,0.968
			s0.441,0.951,0.441,1.58c0,0.615-0.179,1.193-0.539,1.738c-0.358,0.543-0.876,0.963-1.553,1.26
			c-0.677,0.299-1.442,0.447-2.297,0.447c-1.415,0-2.494-0.295-3.235-0.883C254.671,530.984,254.198,530.113,253.993,528.958z"/>
		<path d="M265.242,519.298v-2.123h1.846v2.123H265.242z M265.242,532.208v-10.89h1.846v10.89H265.242z"/>
		<path d="M269.856,532.208v-15.033h1.846v15.033H269.856z"/>
		<path d="M280.397,532.208v-10.89h1.661v1.548c0.8-1.196,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.545,1.235,0.928s0.465,0.837,0.574,1.364c0.068,0.342,0.103,0.94,0.103,1.794v6.696H287.4v-6.625
			c0-0.752-0.072-1.314-0.215-1.687s-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333c-0.786,0-1.465,0.25-2.036,0.749
			s-0.856,1.446-0.856,2.84v5.948H280.397z"/>
		<path d="M291.389,526.763c0-2.017,0.561-3.51,1.682-4.481c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.491,3.671,1.472
			s1.425,2.336,1.425,4.065c0,1.402-0.21,2.503-0.63,3.306c-0.421,0.805-1.033,1.428-1.836,1.872s-1.68,0.667-2.63,0.667
			c-1.524,0-2.757-0.489-3.696-1.467C291.859,530.01,291.389,528.602,291.389,526.763z M293.286,526.763
			c0,1.395,0.304,2.439,0.913,3.133s1.374,1.041,2.297,1.041c0.916,0,1.678-0.35,2.287-1.047s0.913-1.76,0.913-3.188
			c0-1.347-0.306-2.367-0.918-3.061c-0.612-0.693-1.372-1.041-2.281-1.041c-0.923,0-1.688,0.345-2.297,1.036
			S293.286,525.369,293.286,526.763z"/>
		<path d="M310.82,532.208v-1.375c-0.69,1.08-1.706,1.621-3.045,1.621c-0.868,0-1.667-0.24-2.394-0.719
			c-0.729-0.479-1.292-1.146-1.692-2.004c-0.399-0.857-0.6-1.844-0.6-2.959c0-1.086,0.181-2.072,0.543-2.958s0.906-1.564,1.63-2.036
			s1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.033H310.82z
			 M304.986,526.773c0,1.395,0.294,2.438,0.882,3.128s1.282,1.036,2.082,1.036c0.807,0,1.492-0.33,2.056-0.99
			c0.564-0.659,0.846-1.666,0.846-3.02c0-1.49-0.287-2.584-0.861-3.281s-1.282-1.046-2.123-1.046c-0.82,0-1.506,0.335-2.056,1.005
			C305.261,524.275,304.986,525.331,304.986,526.773z"/>
		<path d="M322.889,528.701l1.907,0.236c-0.301,1.114-0.858,1.979-1.671,2.594s-1.853,0.924-3.117,0.924
			c-1.593,0-2.856-0.49-3.789-1.473c-0.934-0.98-1.4-2.355-1.4-4.127c0-1.832,0.472-3.253,1.415-4.265s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.112,1.015,2.748s1.367,0.954,2.276,0.954c0.677,0,1.254-0.178,1.733-0.533S322.609,529.48,322.889,528.701z
			 M316.829,525.717h6.081c-0.082-0.916-0.314-1.603-0.697-2.061c-0.588-0.711-1.35-1.066-2.287-1.066
			c-0.848,0-1.561,0.284-2.138,0.851S316.891,524.767,316.829,525.717z"/>
		<path d="M332.948,532.208v-15.033h1.846v5.394c0.861-0.998,1.948-1.497,3.261-1.497c0.807,0,1.507,0.159,2.102,0.477
			c0.595,0.318,1.021,0.757,1.276,1.318c0.257,0.561,0.385,1.374,0.385,2.44v6.901h-1.846v-6.901c0-0.923-0.2-1.594-0.6-2.015
			c-0.4-0.42-0.966-0.63-1.697-0.63c-0.547,0-1.062,0.142-1.543,0.425c-0.482,0.284-0.826,0.668-1.031,1.154
			s-0.308,1.155-0.308,2.01v5.958H332.948z"/>
		<path d="M351.733,530.865c-0.684,0.581-1.342,0.991-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.293-2.758-0.877s-0.964-1.332-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461c0.242-0.441,0.56-0.795,0.953-1.063
			c0.393-0.266,0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277c1.49-0.178,2.587-0.39,3.292-0.636
			c0.007-0.253,0.01-0.414,0.01-0.482c0-0.752-0.174-1.282-0.523-1.589c-0.472-0.417-1.172-0.625-2.102-0.625
			c-0.868,0-1.509,0.152-1.923,0.457s-0.719,0.842-0.917,1.615l-1.805-0.246c0.164-0.772,0.434-1.396,0.81-1.872
			c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385c0.93,0,1.685,0.109,2.266,0.328
			s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.75,0.574,1.256c0.062,0.314,0.092,0.882,0.092,1.702v2.461
			c0,1.716,0.039,2.802,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.309h-1.928C351.911,531.826,351.788,531.377,351.733,530.865z
			 M351.58,526.743c-0.67,0.273-1.675,0.506-3.015,0.697c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.337-0.728,0.601
			c-0.171,0.263-0.256,0.555-0.256,0.876c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.155,1.897-0.466
			c0.554-0.312,0.96-0.737,1.22-1.277c0.198-0.417,0.297-1.032,0.297-1.846V526.743z"/>
		<path d="M355.568,528.958l1.825-0.287c0.103,0.731,0.388,1.292,0.856,1.682s1.123,0.585,1.964,0.585
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.751,0.615-1.216c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.372-1.887-0.626c-1.354-0.342-2.292-0.637-2.815-0.887c-0.522-0.249-0.919-0.594-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.391,1.174-0.538s1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369c0.646,0.246,1.123,0.579,1.43,1
			c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313c-0.394-0.314-0.949-0.472-1.667-0.472
			c-0.848,0-1.453,0.14-1.815,0.42s-0.543,0.608-0.543,0.984c0,0.239,0.075,0.455,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492
			c0.185,0.068,0.728,0.226,1.63,0.472c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.544,1.215,0.968
			s0.441,0.951,0.441,1.58c0,0.615-0.179,1.193-0.539,1.738c-0.358,0.543-0.876,0.963-1.553,1.26
			c-0.677,0.299-1.442,0.447-2.297,0.447c-1.415,0-2.494-0.295-3.235-0.883C356.247,530.984,355.773,530.113,355.568,528.958z"/>
		<path d="M366.807,532.208v-15.033h1.846v5.394c0.861-0.998,1.948-1.497,3.261-1.497c0.806,0,1.507,0.159,2.102,0.477
			c0.595,0.318,1.021,0.757,1.276,1.318c0.257,0.561,0.385,1.374,0.385,2.44v6.901h-1.846v-6.901c0-0.923-0.2-1.594-0.6-2.015
			c-0.4-0.42-0.966-0.63-1.697-0.63c-0.547,0-1.062,0.142-1.543,0.425c-0.482,0.284-0.826,0.668-1.031,1.154
			s-0.308,1.155-0.308,2.01v5.958H366.807z"/>
		<path d="M181.334,560.512v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H181.334z"/>
		<path d="M185.876,560.512v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H185.876z"/>
		<path d="M197.566,547.602v-2.122h1.846v2.122H197.566z M197.566,560.512v-10.89h1.846v10.89H197.566z"/>
		<path d="M206.251,558.862l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C205.646,558.933,205.916,558.91,206.251,558.862z"/>
		<path d="M213.203,555.067c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C213.673,558.315,213.203,556.907,213.203,555.067z
			 M215.1,555.067c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S215.1,553.672,215.1,555.067z"/>
		<path d="M225.549,560.512v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H225.549z"/>
		<path d="M238.397,564.686v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H238.397z M240.068,555.129c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C240.371,552.66,240.068,553.728,240.068,555.129z"/>
		<path d="M257.182,559.168c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C257.36,560.129,257.237,559.682,257.182,559.168z M257.028,555.047c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V555.047z"/>
		<path d="M261.735,560.512v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H261.735z"/>
		<path d="M272.778,558.862l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C272.173,558.933,272.443,558.91,272.778,558.862z"/>
		<path d="M274.593,547.602v-2.122h1.846v2.122H274.593z M274.593,560.512v-10.89h1.846v10.89H274.593z"/>
		<path d="M283.278,558.862l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C282.673,558.933,282.943,558.91,283.278,558.862z"/>
		<path d="M285.093,547.602v-2.122h1.846v2.122H285.093z M285.093,560.512v-10.89h1.846v10.89H285.093z"/>
		<path d="M289.062,555.067c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C289.531,558.315,289.062,556.907,289.062,555.067z
			 M290.958,555.067c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S290.958,553.672,290.958,555.067z"/>
		<path d="M301.428,560.512v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H301.428z"/>
		<path d="M154.92,617.122v-13.258h-4.953v-1.774h11.915v1.774h-4.973v13.258H154.92z"/>
		<path d="M168.465,615.778c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C168.643,616.739,168.52,616.292,168.465,615.778z M168.312,611.657c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V611.657z"/>
		<path d="M172.3,613.872l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C172.979,615.898,172.505,615.027,172.3,613.872z"/>
		<path d="M183.549,617.122v-15.032h1.846v8.572l4.368-4.43h2.389l-4.163,4.04l4.583,6.85h-2.276l-3.599-5.568l-1.302,1.252v4.316
			H183.549z"/>
		<path d="M193.3,613.872l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C193.979,615.898,193.505,615.027,193.3,613.872z"/>
		<path d="M209.686,611.676c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C210.156,614.924,209.686,613.516,209.686,611.676z
			 M211.583,611.676c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S211.583,610.282,211.583,611.676z"/>
		<path d="M222.032,617.122v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H222.032z"/>
		<path d="M238.91,615.471l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C238.305,615.542,238.575,615.519,238.91,615.471z"/>
		<path d="M248.169,613.615l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S247.889,614.394,248.169,613.615z M242.109,610.631h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C242.49,608.922,242.17,609.681,242.109,610.631z"/>
		<path d="M251.655,613.872l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C252.333,615.898,251.86,615.027,251.655,613.872z"/>
		<path d="M266.923,615.471l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C266.318,615.542,266.588,615.519,266.923,615.471z"/>
		<path d="M267.99,613.872l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C268.668,615.898,268.195,615.027,267.99,613.872z"/>
		<path d="M285.063,617.122v-10.89h1.651v1.528c0.342-0.533,0.796-0.963,1.364-1.287c0.567-0.325,1.213-0.487,1.938-0.487
			c0.807,0,1.468,0.168,1.984,0.503c0.516,0.335,0.88,0.803,1.092,1.404c0.861-1.271,1.982-1.907,3.363-1.907
			c1.08,0,1.911,0.299,2.492,0.897c0.581,0.598,0.872,1.52,0.872,2.764v7.475h-1.835v-6.859c0-0.738-0.06-1.271-0.179-1.595
			c-0.12-0.325-0.337-0.586-0.651-0.784s-0.684-0.298-1.107-0.298c-0.766,0-1.401,0.255-1.907,0.764
			c-0.506,0.51-0.759,1.325-0.759,2.446v6.326h-1.846v-7.075c0-0.82-0.15-1.436-0.451-1.846s-0.793-0.615-1.477-0.615
			c-0.52,0-1,0.137-1.44,0.41c-0.441,0.273-0.761,0.674-0.959,1.2s-0.297,1.285-0.297,2.275v5.65H285.063z"/>
		<path d="M309.662,615.778c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C309.839,616.739,309.716,616.292,309.662,615.778z M309.508,611.657c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V611.657z"/>
		<path d="M314.153,621.315l-0.205-1.732c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.132-10.91h1.989
			l2.266,6.306c0.294,0.801,0.557,1.641,0.79,2.523c0.212-0.848,0.465-1.675,0.759-2.482l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.021-1.036,2.472c-0.328,0.607-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.426-1.518,0.426
			C314.987,621.542,314.59,621.465,314.153,621.315z"/>
		<path d="M337.634,617.122v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H337.634z M331.8,611.687c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C332.075,609.189,331.8,610.245,331.8,611.687z"/>
		<path d="M349.703,613.615l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S349.423,614.394,349.703,613.615z M343.643,610.631h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C344.024,608.922,343.705,609.681,343.643,610.631z"/>
		<path d="M353.928,621.295v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H353.928z M355.599,611.739c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C355.902,609.269,355.599,610.337,355.599,611.739z"/>
		<path d="M373.061,613.615l1.908,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S372.782,614.394,373.061,613.615z M367.001,610.631h6.081c-0.082-0.916-0.314-1.604-0.698-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C367.382,608.922,367.063,609.681,367.001,610.631z"/>
		<path d="M377.286,617.122v-10.89h1.662v1.548c0.799-1.195,1.955-1.794,3.465-1.794c0.656,0,1.26,0.118,1.811,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.145-0.373-0.398-0.67-0.765-0.893c-0.366-0.222-0.794-0.333-1.286-0.333
			c-0.787,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H377.286z"/>
		<path d="M396.03,617.122v-1.374c-0.689,1.08-1.705,1.62-3.045,1.62c-0.868,0-1.666-0.239-2.395-0.718s-1.291-1.146-1.691-2.005
			c-0.4-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958c0.362-0.886,0.906-1.564,1.631-2.035
			c0.725-0.473,1.534-0.708,2.43-0.708c0.656,0,1.24,0.139,1.754,0.415c0.512,0.277,0.93,0.638,1.25,1.082v-5.394h1.836v15.032
			H396.03z M390.196,611.687c0,1.395,0.294,2.438,0.882,3.128s1.282,1.035,2.081,1.035c0.807,0,1.492-0.33,2.057-0.989
			c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281s-1.281-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.055,1.004
			C390.471,609.189,390.196,610.245,390.196,611.687z"/>
		<path d="M405.792,611.676c0-2.016,0.561-3.51,1.682-4.48c0.938-0.807,2.078-1.21,3.425-1.21c1.498,0,2.721,0.49,3.672,1.472
			c0.949,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.422,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.631,0.666c-1.524,0-2.757-0.488-3.696-1.467C406.262,614.924,405.792,613.516,405.792,611.676z
			 M407.689,611.676c0,1.395,0.304,2.439,0.913,3.133c0.607,0.694,1.373,1.041,2.296,1.041c0.916,0,1.678-0.349,2.287-1.046
			c0.607-0.697,0.912-1.76,0.912-3.188c0-1.347-0.305-2.367-0.918-3.062c-0.611-0.693-1.371-1.04-2.281-1.04
			c-0.923,0-1.688,0.345-2.296,1.035C407.993,609.24,407.689,610.282,407.689,611.676z"/>
		<path d="M418.158,617.122v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H418.158z"/>
		<path d="M434.984,611.676c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C435.454,614.924,434.984,613.516,434.984,611.676z
			 M436.88,611.676c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.611-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S436.88,610.282,436.88,611.676z"/>
		<path d="M451.38,615.471l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.836-1.107v3.804
			h1.855v1.436h-1.855v6.368c0,0.526,0.032,0.864,0.097,1.015c0.065,0.15,0.171,0.271,0.318,0.358
			c0.146,0.09,0.356,0.134,0.63,0.134C450.775,615.542,451.045,615.519,451.38,615.471z"/>
		<path d="M453.185,617.122v-15.032h1.846v5.394c0.861-0.998,1.947-1.497,3.26-1.497c0.807,0,1.508,0.159,2.103,0.477
			c0.595,0.318,1.021,0.758,1.276,1.317c0.257,0.562,0.385,1.375,0.385,2.441v6.9h-1.846v-6.9c0-0.924-0.2-1.595-0.6-2.016
			c-0.4-0.42-0.966-0.631-1.697-0.631c-0.547,0-1.062,0.143-1.543,0.426c-0.482,0.284-0.826,0.669-1.031,1.154
			s-0.307,1.155-0.307,2.01v5.957H453.185z"/>
		<path d="M472.319,613.615l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C471.659,614.961,472.039,614.394,472.319,613.615z M466.259,610.631h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C466.64,608.922,466.32,609.681,466.259,610.631z"/>
		<path d="M476.523,617.122v-10.89h1.662v1.651c0.423-0.772,0.814-1.282,1.174-1.528c0.358-0.246,0.754-0.369,1.184-0.369
			c0.622,0,1.255,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.551,0.579-0.687,1.01c-0.205,0.656-0.309,1.374-0.309,2.153v5.701H476.523z"/>
		<path d="M482.8,613.872l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C483.478,615.898,483.005,615.027,482.8,613.872z"/>
		<path d="M494.561,617.122v-2.102h2.103v2.102H494.561z"/>
		<path d="M151.136,645.426v-15.032h10.869v1.774h-8.88v4.604h8.316v1.764h-8.316v5.117h9.229v1.773H151.136z"/>
		<path d="M171.972,644.083c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C172.15,645.043,172.027,644.596,171.972,644.083z M171.818,639.961c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V639.961z"/>
		<path d="M183.651,641.438l1.815,0.235c-0.198,1.251-0.706,2.23-1.523,2.938c-0.817,0.708-1.82,1.062-3.009,1.062
			c-1.49,0-2.688-0.487-3.594-1.461c-0.906-0.975-1.358-2.37-1.358-4.189c0-1.175,0.195-2.204,0.584-3.086s0.982-1.543,1.779-1.984
			c0.796-0.44,1.663-0.661,2.6-0.661c1.183,0,2.15,0.299,2.902,0.897c0.752,0.598,1.234,1.447,1.446,2.548l-1.794,0.276
			c-0.171-0.73-0.474-1.281-0.908-1.65s-0.958-0.554-1.574-0.554c-0.93,0-1.685,0.333-2.266,1c-0.581,0.666-0.872,1.721-0.872,3.163
			c0,1.463,0.28,2.526,0.841,3.189s1.292,0.994,2.194,0.994c0.725,0,1.33-0.222,1.815-0.666S183.521,642.36,183.651,641.438z"/>
		<path d="M187.045,645.426v-15.032h1.846v5.394c0.861-0.998,1.948-1.497,3.261-1.497c0.807,0,1.507,0.159,2.102,0.477
			c0.595,0.318,1.021,0.758,1.276,1.317c0.257,0.562,0.385,1.375,0.385,2.441v6.9h-1.846v-6.9c0-0.924-0.2-1.595-0.6-2.016
			c-0.4-0.42-0.966-0.631-1.697-0.631c-0.547,0-1.062,0.143-1.543,0.426c-0.482,0.284-0.826,0.669-1.031,1.154
			s-0.308,1.155-0.308,2.01v5.957H187.045z"/>
		<path d="M208.589,643.776l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C207.984,643.847,208.254,643.824,208.589,643.776z"/>
		<path d="M217.5,644.083c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C217.677,645.043,217.554,644.596,217.5,644.083z M217.346,639.961c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V639.961z"/>
		<path d="M221.334,642.176l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C222.013,644.203,221.54,643.332,221.334,642.176z"/>
		<path d="M232.583,645.426v-15.032h1.846v8.572l4.368-4.43h2.389l-4.163,4.04l4.583,6.85h-2.276l-3.599-5.568l-1.302,1.252v4.316
			H232.583z"/>
		<path d="M248.22,639.981c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C248.69,643.229,248.22,641.821,248.22,639.981z
			 M250.117,639.981c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S250.117,638.586,250.117,639.981z"/>
		<path d="M260.566,645.426v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H260.566z"/>
		<path d="M277.444,643.776l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C276.839,643.847,277.109,643.824,277.444,643.776z"/>
		<path d="M286.703,641.919l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S286.423,642.699,286.703,641.919z M280.643,638.936h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C281.024,637.227,280.705,637.986,280.643,638.936z"/>
		<path d="M290.189,642.176l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C290.868,644.203,290.395,643.332,290.189,642.176z"/>
		<path d="M305.458,643.776l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C304.853,643.847,305.123,643.824,305.458,643.776z"/>
		<path d="M313.076,645.426v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H313.076z"/>
		<path d="M327.227,645.426v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H327.227z"/>
		<path d="M331.769,645.426v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H331.769z"/>
		<path d="M342.71,642.176l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C343.388,644.203,342.915,643.332,342.71,642.176z"/>
		<path d="M359.793,632.516v-2.122h1.846v2.122H359.793z M359.793,645.426v-10.89h1.846v10.89H359.793z"/>
		<path d="M364.448,645.426v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H364.448z"/>
		<path d="M389.068,641.438l1.815,0.235c-0.199,1.251-0.707,2.23-1.523,2.938c-0.816,0.708-1.82,1.062-3.01,1.062
			c-1.49,0-2.688-0.487-3.594-1.461c-0.906-0.975-1.358-2.37-1.358-4.189c0-1.175,0.194-2.204,0.585-3.086
			c0.389-0.882,0.982-1.543,1.778-1.984c0.796-0.44,1.663-0.661,2.6-0.661c1.183,0,2.149,0.299,2.901,0.897
			c0.752,0.598,1.234,1.447,1.446,2.548l-1.794,0.276c-0.172-0.73-0.475-1.281-0.908-1.65s-0.959-0.554-1.574-0.554
			c-0.93,0-1.685,0.333-2.266,1c-0.581,0.666-0.871,1.721-0.871,3.163c0,1.463,0.279,2.526,0.84,3.189s1.293,0.994,2.195,0.994
			c0.725,0,1.329-0.222,1.814-0.666S388.938,642.36,389.068,641.438z"/>
		<path d="M392.42,645.426v-15.032h1.846v15.032H392.42z"/>
		<path d="M404.583,641.919l1.906,0.235c-0.301,1.115-0.857,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.788-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.385,2.386,1.385,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.609,0.635,1.367,0.953,2.277,0.953c0.676,0,1.254-0.178,1.732-0.533
			S404.301,642.699,404.583,641.919z M398.522,638.936h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.286-1.066c-0.848,0-1.561,0.284-2.138,0.851C398.903,637.227,398.583,637.986,398.522,638.936z"/>
		<path d="M415.913,644.083c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.413,0.011-0.481c0-0.752-0.175-1.282-0.522-1.59
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.413,0.304-0.72,0.843-0.918,1.614l-1.805-0.246
			c0.164-0.771,0.435-1.396,0.811-1.871c0.376-0.475,0.92-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.472-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.093,0.883,0.093,1.703v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C416.09,645.043,415.967,644.596,415.913,644.083z M415.758,639.961c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.172,0.263-0.257,0.556-0.257,0.877
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.156,1.896-0.467
			c0.555-0.312,0.961-0.736,1.221-1.277c0.198-0.416,0.297-1.031,0.297-1.846V639.961z"/>
		<path d="M420.486,645.426v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H420.486z"/>
		<path d="M445.105,644.083c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062c0.394-0.267,0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.413,0.011-0.481c0-0.752-0.175-1.282-0.522-1.59
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.413,0.304-0.72,0.843-0.918,1.614l-1.805-0.246
			c0.164-0.771,0.435-1.396,0.811-1.871c0.376-0.475,0.919-0.841,1.631-1.097c0.71-0.257,1.534-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.093,0.883,0.093,1.703v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C445.283,645.043,445.16,644.596,445.105,644.083z M444.951,639.961c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.558,0.336-0.728,0.6c-0.172,0.263-0.257,0.556-0.257,0.877
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.156,1.896-0.467
			c0.555-0.312,0.961-0.736,1.221-1.277c0.198-0.416,0.297-1.031,0.297-1.846V639.961z"/>
		<path d="M449.658,645.426v-10.89h1.662v1.651c0.423-0.772,0.814-1.282,1.174-1.528c0.358-0.246,0.754-0.369,1.184-0.369
			c0.622,0,1.255,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.551,0.579-0.687,1.01c-0.205,0.656-0.309,1.374-0.309,2.153v5.701H449.658z"/>
		<path d="M464.126,641.919l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C463.466,643.266,463.846,642.699,464.126,641.919z M458.067,638.936h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C458.448,637.227,458.127,637.986,458.067,638.936z"/>
		<path d="M475.457,644.083c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062c0.394-0.267,0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.413,0.011-0.481c0-0.752-0.175-1.282-0.522-1.59
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.413,0.304-0.72,0.843-0.918,1.614l-1.805-0.246
			c0.164-0.771,0.435-1.396,0.811-1.871c0.376-0.475,0.919-0.841,1.631-1.097c0.71-0.257,1.534-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.093,0.883,0.093,1.703v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C475.634,645.043,475.511,644.596,475.457,644.083z M475.302,639.961c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.558,0.336-0.728,0.6c-0.172,0.263-0.257,0.556-0.257,0.877
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.156,1.896-0.467
			c0.555-0.312,0.961-0.736,1.221-1.277c0.198-0.416,0.297-1.031,0.297-1.846V639.961z"/>
		<path d="M480.553,645.426v-2.102h2.103v2.102H480.553z"/>
		<path d="M149.444,673.731l5.773-15.032h2.143l6.152,15.032h-2.266l-1.753-4.553h-6.286l-1.651,4.553H149.444z M153.782,667.558
			h5.096l-1.569-4.163c-0.479-1.265-0.834-2.304-1.066-3.117c-0.191,0.964-0.461,1.921-0.81,2.871L153.782,667.558z"/>
		<path d="M171.931,673.731v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H171.931z M166.097,668.296c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C166.372,665.798,166.097,666.854,166.097,668.296z"/>
		<path d="M183.61,673.731v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H183.61z M177.776,668.296c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C178.051,665.798,177.776,666.854,177.776,668.296z"/>
		<path d="M201.124,673.731v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H201.124z M195.29,668.296c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C195.564,665.798,195.29,666.854,195.29,668.296z"/>
		<path d="M205.749,660.821v-2.122h1.846v2.122H205.749z M205.749,673.731v-10.89h1.846v10.89H205.749z"/>
		<path d="M209.666,670.481l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C210.344,672.507,209.871,671.636,209.666,670.481z"/>
		<path d="M220.914,673.731v-15.032h1.846v8.572l4.368-4.43h2.389l-4.163,4.04l4.583,6.85h-2.276l-3.599-5.568l-1.302,1.252v4.316
			H220.914z"/>
		<path d="M236.5,670.481l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C237.178,672.507,236.705,671.636,236.5,670.481z"/>
		<path d="M247.738,677.905v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H247.738z M249.41,668.348c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C249.712,665.878,249.41,666.947,249.41,668.348z"/>
		<path d="M266.523,672.387c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C266.701,673.348,266.578,672.901,266.523,672.387z M266.37,668.266c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V668.266z"/>
		<path d="M278.203,669.743l1.815,0.235c-0.198,1.251-0.706,2.23-1.523,2.938c-0.817,0.708-1.82,1.062-3.009,1.062
			c-1.49,0-2.688-0.487-3.594-1.461c-0.906-0.975-1.358-2.37-1.358-4.189c0-1.175,0.195-2.204,0.584-3.086s0.982-1.543,1.779-1.984
			c0.796-0.44,1.663-0.661,2.6-0.661c1.183,0,2.15,0.299,2.902,0.897c0.752,0.598,1.234,1.447,1.446,2.548l-1.794,0.276
			c-0.171-0.73-0.474-1.281-0.908-1.65s-0.958-0.554-1.574-0.554c-0.93,0-1.685,0.333-2.266,1c-0.581,0.666-0.872,1.721-0.872,3.163
			c0,1.463,0.28,2.526,0.841,3.189s1.292,0.994,2.194,0.994c0.725,0,1.33-0.222,1.815-0.666S278.073,670.665,278.203,669.743z"/>
		<path d="M289.051,670.224l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S288.771,671.003,289.051,670.224z M282.991,667.241h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C283.372,665.532,283.053,666.291,282.991,667.241z"/>
		<path d="M298.423,668.286c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C298.893,671.534,298.423,670.125,298.423,668.286z
			 M300.32,668.286c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S300.32,666.891,300.32,668.286z"/>
		<path d="M310.769,673.731v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H310.769z"/>
		<path d="M323.617,677.905v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H323.617z M325.289,668.348c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C325.591,665.878,325.289,666.947,325.289,668.348z"/>
		<path d="M342.402,672.387c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
"
       height="70"
       width="137" />
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C342.58,673.348,342.457,672.901,342.402,672.387z M342.249,668.266c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V668.266z"/>
		<path d="M346.955,673.731v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H346.955z"/>
		<path d="M357.999,672.081l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C357.394,672.152,357.664,672.128,357.999,672.081z"/>
		<path d="M359.813,660.821v-2.122h1.846v2.122H359.813z M359.813,673.731v-10.89h1.846v10.89H359.813z"/>
		<path d="M368.499,672.081l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C367.894,672.152,368.164,672.128,368.499,672.081z"/>
		<path d="M370.313,660.821v-2.122h1.846v2.122H370.313z M370.313,673.731v-10.89h1.846v10.89H370.313z"/>
		<path d="M374.282,668.286c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C374.751,671.534,374.282,670.125,374.282,668.286z
			 M376.178,668.286c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.679-0.349,2.286-1.046
			c0.609-0.697,0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04
			c-0.923,0-1.688,0.345-2.297,1.035S376.178,666.891,376.178,668.286z"/>
		<path d="M386.648,673.731v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.551,0.236,0.963,0.546,1.236,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.102,0.94,0.102,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.035,0.749c-0.571,0.499-0.856,1.445-0.856,2.84v5.947H386.648z"/>
		<path d="M397.588,670.481l1.826-0.287c0.102,0.731,0.387,1.291,0.855,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.544-0.984
			c-0.252-0.164-0.881-0.373-1.887-0.626c-1.354-0.342-2.291-0.638-2.814-0.887c-0.522-0.25-0.92-0.595-1.189-1.036
			c-0.27-0.44-0.404-0.928-0.404-1.461c0-0.485,0.11-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.309,0.42,0.52,0.982,0.637,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.713-1.313
			c-0.394-0.314-0.949-0.472-1.666-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.544,0.608-0.544,0.984
			c0,0.239,0.076,0.454,0.227,0.646c0.15,0.198,0.386,0.362,0.707,0.492c0.185,0.068,0.729,0.226,1.631,0.472
			c1.305,0.349,2.216,0.634,2.732,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.18,1.194-0.539,1.738c-0.358,0.543-0.877,0.964-1.553,1.261c-0.678,0.298-1.443,0.446-2.297,0.446
			c-1.416,0-2.494-0.294-3.235-0.882C398.267,672.507,397.793,671.636,397.588,670.481z"/>
		<path d="M421.767,672.387c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062c0.394-0.267,0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.413,0.011-0.481c0-0.752-0.175-1.282-0.522-1.59
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.413,0.304-0.72,0.843-0.918,1.614l-1.805-0.246
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="78.571426"
       y="139.50505"
       id="text3142"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan3144"
         x="78.571426"
         y="139.50505">Automation</tspan></text>
			c0.164-0.771,0.435-1.396,0.811-1.871c0.376-0.475,0.919-0.841,1.631-1.097c0.71-0.257,1.534-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.093,0.883,0.093,1.703v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C421.945,673.348,421.822,672.901,421.767,672.387z M421.613,668.266c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.558,0.336-0.728,0.6c-0.172,0.263-0.257,0.556-0.257,0.877
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.156,1.896-0.467
			c0.555-0.312,0.961-0.736,1.221-1.277c0.198-0.416,0.297-1.031,0.297-1.846V668.266z"/>
		<path d="M425.603,670.481l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C426.281,672.507,425.808,671.636,425.603,670.481z"/>
		<path d="M442.675,673.731v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H442.675z"/>
		<path d="M461.809,670.224l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C461.149,671.571,461.529,671.003,461.809,670.224z M455.75,667.241h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C456.13,665.532,455.81,666.291,455.75,667.241z"/>
		<path d="M473.489,670.224l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C472.829,671.571,473.208,671.003,473.489,670.224z M467.429,667.241h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C467.81,665.532,467.49,666.291,467.429,667.241z"/>
		<path d="M484.779,673.731v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.869,0-1.667-0.239-2.395-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.544-2.958
			c0.361-0.886,0.905-1.564,1.63-2.035c0.725-0.473,1.534-0.708,2.431-0.708c0.656,0,1.24,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.836v15.032H484.779z M478.945,668.296c0,1.395,0.293,2.438,0.881,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.847-1.667,0.847-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C479.219,665.798,478.945,666.854,478.945,668.296z"/>
		<path d="M496.848,670.224l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C496.188,671.571,496.568,671.003,496.848,670.224z M490.789,667.241h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C491.169,665.532,490.849,666.291,490.789,667.241z"/>
		<path d="M508.138,673.731v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.869,0-1.667-0.239-2.395-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.544-2.958
			c0.361-0.886,0.905-1.564,1.63-2.035c0.725-0.473,1.534-0.708,2.431-0.708c0.656,0,1.24,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.836v15.032H508.138z M502.304,668.296c0,1.395,0.293,2.438,0.881,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.847-1.667,0.847-3.021c0-1.489-0.287-2.584-0.861-3.281
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="208.57144"
       y="185.21931"
       id="text3146"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan3148"
         x="208.57144"
         y="185.21931">Quality Assurance</tspan></text>
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C502.579,665.798,502.304,666.854,502.304,668.296z"/>
		<path d="M513.276,673.731v-2.102h2.103v2.102H513.276z"/>
		<path d="M151.126,702.036v-15.032h6.665c1.34,0,2.358,0.135,3.056,0.405c0.697,0.27,1.254,0.747,1.671,1.43
			c0.417,0.685,0.625,1.439,0.625,2.267c0,1.066-0.345,1.966-1.036,2.696c-0.69,0.732-1.757,1.197-3.199,1.395
			c0.526,0.254,0.926,0.503,1.2,0.749c0.581,0.533,1.131,1.2,1.651,1.999l2.615,4.092h-2.502l-1.989-3.127
			c-0.581-0.902-1.06-1.593-1.436-2.072c-0.376-0.478-0.712-0.813-1.01-1.004c-0.297-0.191-0.6-0.325-0.907-0.4
			c-0.226-0.048-0.595-0.072-1.107-0.072h-2.307v6.676H151.126z M153.115,693.637h4.276c0.909,0,1.62-0.094,2.133-0.281
			c0.513-0.188,0.902-0.489,1.169-0.902c0.267-0.414,0.4-0.863,0.4-1.349c0-0.711-0.258-1.295-0.774-1.753
			c-0.517-0.458-1.332-0.688-2.446-0.688h-4.758V693.637z"/>
		<path d="M166.035,689.125v-2.122h1.846v2.122H166.035z M166.035,702.036v-10.89h1.846v10.89H166.035z"/>
		<path d="M170.352,702.938l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.133-2.369
			c-0.807,0.951-1.812,1.426-3.015,1.426c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.877
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.293-3.148-0.877C170.711,704.994,170.325,704.114,170.352,702.938z M171.88,696.396
			c0,1.429,0.284,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C172.167,694.094,171.88,695.083,171.88,696.396z"/>
		<path d="M181.683,696.59c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C182.152,699.838,181.683,698.43,181.683,696.59z
			 M183.58,696.59c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S183.58,695.196,183.58,696.59z"/>
		<path d="M194.028,702.036v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H194.028z"/>
		<path d="M200.355,696.59c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C200.825,699.838,200.355,698.43,200.355,696.59z
			 M202.252,696.59c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S202.252,695.196,202.252,696.59z"/>
		<path d="M219.858,702.036v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H219.858z"/>
		<path d="M223.662,698.786l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C224.34,700.812,223.867,699.941,223.662,698.786z"/>
		<path d="M240.714,702.036v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H240.714z"/>
		<path d="M255.183,698.529l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="310"
       y="230.93361"
       id="text3150"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan3152"
         x="310"
         y="230.93361">Regression Testing</tspan></text>
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S254.902,699.308,255.183,698.529z M249.123,695.545h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C249.503,693.836,249.184,694.595,249.123,695.545z"/>
		<path d="M258.669,698.786l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C259.347,700.812,258.874,699.941,258.669,698.786z"/>
		<path d="M277.044,702.036v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H277.044z"/>
		<path d="M281.545,702.036v-15.032h1.846v15.032H281.545z"/>
		<path d="M290.282,700.385l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C289.677,700.457,289.947,700.433,290.282,700.385z"/>
		<path d="M291.348,698.786l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C292.026,700.812,291.553,699.941,291.348,698.786z"/>
		<path d="M303.099,693.249v-2.103h2.102v2.103H303.099z M303.099,702.036v-2.102h2.102v2.102H303.099z"/>
		<path fill="#EC1C24" d="M326.222,697.626h-8.367c0.075,0.67,0.256,1.169,0.543,1.497c0.403,0.472,0.93,0.707,1.579,0.707
			c0.41,0,0.8-0.102,1.169-0.307c0.226-0.13,0.468-0.359,0.728-0.688l4.112,0.379c-0.629,1.095-1.388,1.879-2.276,2.354
			c-0.889,0.476-2.164,0.713-3.825,0.713c-1.442,0-2.577-0.203-3.404-0.61c-0.827-0.406-1.513-1.053-2.056-1.938
			c-0.544-0.886-0.815-1.926-0.815-3.122c0-1.703,0.545-3.08,1.636-4.133c1.09-1.053,2.596-1.579,4.517-1.579
			c1.559,0,2.789,0.235,3.691,0.708c0.902,0.471,1.589,1.155,2.061,2.051s0.708,2.061,0.708,3.496V697.626z M321.977,695.627
			c-0.082-0.807-0.299-1.385-0.651-1.733s-0.815-0.522-1.389-0.522c-0.663,0-1.193,0.263-1.589,0.789
			c-0.253,0.328-0.414,0.817-0.482,1.467H321.977z"/>
		<path fill="#EC1C24" d="M328.18,691.146h3.907v1.784c0.376-0.772,0.764-1.304,1.164-1.595c0.399-0.29,0.894-0.436,1.481-0.436
			c0.615,0,1.289,0.191,2.02,0.574l-1.292,2.974c-0.492-0.205-0.882-0.308-1.169-0.308c-0.547,0-0.971,0.226-1.271,0.677
			c-0.431,0.636-0.646,1.825-0.646,3.568v3.65h-4.194V691.146z"/>
		<path fill="#EC1C24" d="M338.383,691.146h3.907v1.784c0.376-0.772,0.764-1.304,1.164-1.595c0.399-0.29,0.894-0.436,1.481-0.436
			c0.615,0,1.289,0.191,2.02,0.574l-1.292,2.974c-0.492-0.205-0.882-0.308-1.169-0.308c-0.547,0-0.971,0.226-1.271,0.677
			c-0.431,0.636-0.646,1.825-0.646,3.568v3.65h-4.194V691.146z"/>
		<path fill="#EC1C24" d="M347.488,696.622c0-1.661,0.561-3.03,1.682-4.106c1.121-1.077,2.635-1.615,4.542-1.615
			c2.181,0,3.828,0.633,4.942,1.897c0.896,1.019,1.343,2.272,1.343,3.763c0,1.675-0.556,3.047-1.667,4.117
			c-1.111,1.069-2.647,1.604-4.609,1.604c-1.75,0-3.165-0.444-4.245-1.333C348.151,699.848,347.488,698.406,347.488,696.622z
			 M351.672,696.612c0,0.971,0.196,1.688,0.589,2.152c0.393,0.466,0.887,0.697,1.482,0.697c0.602,0,1.095-0.229,1.482-0.687
			c0.386-0.458,0.579-1.192,0.579-2.204c0-0.943-0.195-1.646-0.584-2.107c-0.39-0.462-0.872-0.692-1.446-0.692
			c-0.608,0-1.111,0.234-1.507,0.702C351.87,694.942,351.672,695.655,351.672,696.612z"/>
		<path fill="#EC1C24" d="M362.049,691.146h3.907v1.784c0.376-0.772,0.764-1.304,1.164-1.595c0.399-0.29,0.894-0.436,1.481-0.436
			c0.615,0,1.289,0.191,2.02,0.574l-1.292,2.974c-0.492-0.205-0.882-0.308-1.169-0.308c-0.547,0-0.971,0.226-1.271,0.677
			c-0.431,0.636-0.646,1.825-0.646,3.568v3.65h-4.194V691.146z"/>
		<path d="M371.934,702.036v-2.102h2.102v2.102c0,0.772-0.137,1.396-0.41,1.871c-0.273,0.476-0.707,0.843-1.302,1.103l-0.513-0.79
			c0.39-0.171,0.677-0.422,0.862-0.753c0.184-0.332,0.287-0.809,0.307-1.431H371.934z"/>
		<path fill="#00A551" d="M383.018,706.178v-15.032h3.906v1.61c0.541-0.678,1.036-1.135,1.487-1.375
			c0.608-0.32,1.282-0.481,2.021-0.481c1.455,0,2.582,0.558,3.379,1.671c0.795,1.115,1.193,2.492,1.193,4.133
			c0,1.812-0.434,3.194-1.302,4.147c-0.868,0.954-1.966,1.431-3.292,1.431c-0.643,0-1.229-0.109-1.758-0.328
			c-0.53-0.219-1.004-0.543-1.42-0.975v5.199H383.018z M387.202,696.622c0,0.861,0.182,1.501,0.543,1.918
			c0.363,0.417,0.82,0.625,1.375,0.625c0.484,0,0.892-0.2,1.22-0.6c0.328-0.4,0.492-1.078,0.492-2.035
			c0-0.883-0.171-1.53-0.513-1.943c-0.342-0.414-0.759-0.621-1.251-0.621c-0.533,0-0.978,0.209-1.333,0.626
			S387.202,695.685,387.202,696.622z"/>
		<path fill="#00A551" d="M400.809,694.673l-3.989-0.421c0.15-0.697,0.367-1.245,0.651-1.646c0.283-0.399,0.691-0.746,1.225-1.04
			c0.383-0.212,0.91-0.376,1.58-0.492s1.395-0.175,2.174-0.175c1.25,0,2.256,0.07,3.014,0.21c0.76,0.141,1.392,0.433,1.897,0.877
			c0.355,0.308,0.636,0.743,0.841,1.308c0.205,0.563,0.308,1.103,0.308,1.614v4.81c0,0.513,0.032,0.914,0.097,1.205
			c0.065,0.29,0.207,0.661,0.426,1.112h-3.916c-0.158-0.28-0.26-0.494-0.309-0.641c-0.047-0.147-0.096-0.378-0.143-0.692
			c-0.547,0.526-1.091,0.902-1.631,1.128c-0.738,0.301-1.596,0.451-2.574,0.451c-1.299,0-2.285-0.301-2.957-0.902
			c-0.674-0.602-1.011-1.344-1.011-2.225c0-0.827,0.243-1.508,0.728-2.041c0.486-0.533,1.381-0.93,2.688-1.189
			c1.564-0.314,2.58-0.535,3.045-0.661c0.465-0.127,0.957-0.292,1.477-0.497c0-0.514-0.105-0.872-0.318-1.077
			c-0.211-0.205-0.584-0.308-1.117-0.308c-0.684,0-1.196,0.109-1.538,0.328C401.188,693.88,400.973,694.202,400.809,694.673z
			 M404.428,696.868c-0.574,0.205-1.172,0.387-1.795,0.543c-0.848,0.227-1.384,0.448-1.609,0.667
			c-0.232,0.226-0.349,0.481-0.349,0.769c0,0.328,0.114,0.597,0.343,0.806c0.229,0.208,0.566,0.313,1.011,0.313
			c0.465,0,0.897-0.112,1.298-0.339c0.398-0.225,0.683-0.5,0.85-0.825c0.168-0.324,0.252-0.746,0.252-1.267V696.868z"/>
		<path fill="#00A551" d="M410.273,699.01l4.143-0.389c0.17,0.492,0.41,0.844,0.717,1.056c0.309,0.212,0.719,0.317,1.23,0.317
			c0.561,0,0.996-0.119,1.303-0.358c0.24-0.177,0.359-0.398,0.359-0.665c0-0.3-0.158-0.532-0.473-0.696
			c-0.225-0.116-0.822-0.259-1.793-0.43c-1.449-0.253-2.457-0.486-3.02-0.702c-0.564-0.215-1.039-0.578-1.426-1.091
			c-0.387-0.512-0.58-1.096-0.58-1.751c0-0.718,0.209-1.336,0.625-1.854c0.418-0.52,0.992-0.906,1.723-1.163
			c0.732-0.256,1.713-0.384,2.943-0.384c1.299,0,2.258,0.1,2.877,0.298s1.135,0.506,1.549,0.922
			c0.412,0.418,0.756,0.981,1.029,1.692l-3.957,0.39c-0.104-0.349-0.273-0.605-0.514-0.77c-0.328-0.218-0.725-0.328-1.189-0.328
			c-0.471,0-0.814,0.084-1.029,0.251c-0.217,0.168-0.324,0.371-0.324,0.609c0,0.267,0.137,0.468,0.41,0.604
			c0.273,0.136,0.869,0.259,1.785,0.368c1.387,0.157,2.42,0.376,3.096,0.656c0.678,0.279,1.195,0.679,1.555,1.198
			c0.357,0.519,0.537,1.089,0.537,1.71c0,0.629-0.189,1.24-0.568,1.834s-0.979,1.067-1.795,1.419s-1.93,0.527-3.338,0.527
			c-1.988,0-3.406-0.283-4.25-0.852C411.054,700.864,410.512,700.057,410.273,699.01z"/>
		<path fill="#00A551" d="M423.101,699.01l4.143-0.389c0.17,0.492,0.41,0.844,0.717,1.056c0.309,0.212,0.719,0.317,1.23,0.317
			c0.561,0,0.995-0.119,1.303-0.358c0.239-0.177,0.359-0.398,0.359-0.665c0-0.3-0.158-0.532-0.473-0.696
			c-0.225-0.116-0.823-0.259-1.794-0.43c-1.449-0.253-2.456-0.486-3.02-0.702c-0.564-0.215-1.039-0.578-1.426-1.091
			c-0.386-0.512-0.579-1.096-0.579-1.751c0-0.718,0.208-1.336,0.625-1.854c0.417-0.52,0.991-0.906,1.723-1.163
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="401.42856"
			c0.731-0.256,1.713-0.384,2.943-0.384c1.299,0,2.258,0.1,2.876,0.298c0.619,0.198,1.135,0.506,1.549,0.922
			c0.413,0.418,0.757,0.981,1.03,1.692l-3.958,0.39c-0.103-0.349-0.273-0.605-0.513-0.77c-0.328-0.218-0.725-0.328-1.189-0.328
			c-0.472,0-0.815,0.084-1.03,0.251c-0.216,0.168-0.323,0.371-0.323,0.609c0,0.267,0.137,0.468,0.41,0.604
			c0.273,0.136,0.868,0.259,1.784,0.368c1.388,0.157,2.42,0.376,3.097,0.656c0.677,0.279,1.194,0.679,1.554,1.198
			c0.358,0.519,0.538,1.089,0.538,1.71c0,0.629-0.189,1.24-0.569,1.834c-0.379,0.594-0.978,1.067-1.794,1.419
			c-0.817,0.352-1.93,0.527-3.338,0.527c-1.989,0-3.406-0.283-4.25-0.852C423.881,700.864,423.339,700.057,423.101,699.01z"/>
		<path d="M437.272,702.036v-2.102h2.103v2.102c0,0.772-0.138,1.396-0.41,1.871c-0.274,0.476-0.708,0.843-1.303,1.103l-0.513-0.79
			c0.39-0.171,0.677-0.422,0.861-0.753c0.185-0.332,0.287-0.809,0.308-1.431H437.272z"/>
		<path fill="#F7931E" d="M447.115,691.146h4.035l1.746,6.856l2.209-6.856h3.771l2.303,6.873l1.756-6.873h4.011l-4.012,10.89h-3.714
			l-2.205-6.553l-2.132,6.553h-3.73L447.115,691.146z"/>
		<path fill="#F7931E" d="M471.723,694.673l-3.989-0.421c0.15-0.697,0.368-1.245,0.651-1.646c0.284-0.399,0.692-0.746,1.226-1.04
			c0.383-0.212,0.909-0.376,1.579-0.492s1.395-0.175,2.174-0.175c1.251,0,2.256,0.07,3.015,0.21
			c0.759,0.141,1.391,0.433,1.896,0.877c0.355,0.308,0.637,0.743,0.842,1.308c0.205,0.563,0.307,1.103,0.307,1.614v4.81
			c0,0.513,0.033,0.914,0.098,1.205c0.065,0.29,0.207,0.661,0.426,1.112h-3.917c-0.157-0.28-0.26-0.494-0.308-0.641
			c-0.048-0.147-0.096-0.378-0.144-0.692c-0.547,0.526-1.091,0.902-1.63,1.128c-0.738,0.301-1.597,0.451-2.574,0.451
			c-1.299,0-2.285-0.301-2.958-0.902c-0.674-0.602-1.011-1.344-1.011-2.225c0-0.827,0.243-1.508,0.729-2.041s1.381-0.93,2.687-1.189
			c1.565-0.314,2.58-0.535,3.046-0.661c0.464-0.127,0.956-0.292,1.477-0.497c0-0.514-0.106-0.872-0.318-1.077
			s-0.584-0.308-1.117-0.308c-0.685,0-1.197,0.109-1.539,0.328C472.103,693.88,471.887,694.202,471.723,694.673z M475.343,696.868
			c-0.574,0.205-1.173,0.387-1.795,0.543c-0.848,0.227-1.385,0.448-1.609,0.667c-0.233,0.226-0.35,0.481-0.35,0.769
			c0,0.328,0.115,0.597,0.344,0.806c0.229,0.208,0.565,0.313,1.01,0.313c0.465,0,0.897-0.112,1.298-0.339
			c0.399-0.225,0.684-0.5,0.851-0.825c0.168-0.324,0.252-0.746,0.252-1.267V696.868z"/>
		<path fill="#F7931E" d="M481.968,691.146h3.906v1.784c0.376-0.772,0.764-1.304,1.164-1.595c0.399-0.29,0.894-0.436,1.481-0.436
			c0.615,0,1.288,0.191,2.021,0.574l-1.293,2.974c-0.492-0.205-0.881-0.308-1.168-0.308c-0.548,0-0.972,0.226-1.271,0.677
			c-0.432,0.636-0.646,1.825-0.646,3.568v3.65h-4.193V691.146z"/>
		<path fill="#F7931E" d="M492.294,691.146h3.886v1.774c0.581-0.725,1.169-1.243,1.764-1.554c0.595-0.312,1.319-0.467,2.174-0.467
			c1.155,0,2.06,0.344,2.712,1.03c0.653,0.688,0.979,1.748,0.979,3.184v6.922h-4.194v-5.988c0-0.684-0.126-1.167-0.379-1.451
			c-0.253-0.283-0.608-0.426-1.066-0.426c-0.506,0-0.916,0.192-1.23,0.574c-0.314,0.384-0.472,1.07-0.472,2.062v5.229h-4.173
			V691.146z"/>
       y="283.79074"
       id="text3154"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan3156"
         x="401.42856"
         y="283.79074">System Administration</tspan></text>
    <rect
       style="opacity:0.84942082;fill:#000000;fill-opacity:0.05608335;stroke:#2b0000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect3158"
       width="40"
       height="41.42857"
       x="24.285707"
       y="110.93362" />
    <rect
       style="opacity:0.84942082;fill:#000000;fill-opacity:0.05608335;stroke:#2b0000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect3158-5"
       width="40"
       height="41.42857"
       x="147.14287"
       y="155.93361" />
    <rect
       style="opacity:0.84942082;fill:#000000;fill-opacity:0.05608335;stroke:#2b0000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect3158-9"
       width="40"
       height="41.42857"
       x="258.57141"
       y="201.64792" />
    <rect
       style="opacity:0.84942082;fill:#000000;fill-opacity:0.05608335;stroke:#2b0000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect3158-50"
       width="40"
       height="41.42857"
       x="347.14282"
       y="253.07646" />
    <rect
       style="opacity:0.84942082;fill:#000000;fill-opacity:0.05608335;stroke:#2b0000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect3402"
       width="0"
       height="0"
       x="687.14282"
       y="729.50494" />
		<path d="M506.905,702.036v-2.102h2.103v2.102c0,0.772-0.138,1.396-0.41,1.871c-0.274,0.476-0.708,0.843-1.303,1.103l-0.513-0.79
			c0.39-0.171,0.677-0.422,0.861-0.753c0.185-0.332,0.287-0.809,0.308-1.431H506.905z"/>
		<path d="M525.545,698.529l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C524.885,699.875,525.265,699.308,525.545,698.529z M519.486,695.545h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C519.867,693.836,519.546,694.595,519.486,695.545z"/>
		<path d="M533.8,700.385l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.836-1.107v3.804
			h1.855v1.436h-1.855v6.368c0,0.526,0.032,0.864,0.097,1.015c0.065,0.15,0.171,0.271,0.318,0.358
			c0.146,0.09,0.356,0.134,0.63,0.134C533.195,700.457,533.465,700.433,533.8,700.385z"/>
		<path d="M542.71,698.047l1.814,0.235c-0.198,1.251-0.705,2.23-1.522,2.938c-0.816,0.708-1.819,1.062-3.009,1.062
			c-1.491,0-2.688-0.487-3.595-1.461c-0.905-0.975-1.358-2.37-1.358-4.189c0-1.175,0.195-2.204,0.584-3.086
			c0.391-0.882,0.983-1.543,1.779-1.984c0.797-0.44,1.663-0.661,2.6-0.661c1.183,0,2.149,0.299,2.902,0.897
			c0.751,0.598,1.233,1.447,1.445,2.548l-1.795,0.276c-0.171-0.73-0.473-1.281-0.907-1.65c-0.434-0.369-0.958-0.554-1.573-0.554
			c-0.931,0-1.686,0.333-2.267,1c-0.581,0.666-0.872,1.721-0.872,3.163c0,1.463,0.28,2.526,0.842,3.189
			c0.56,0.663,1.291,0.994,2.193,0.994c0.725,0,1.33-0.222,1.815-0.666S542.581,698.969,542.71,698.047z"/>
		<path d="M546.627,702.036v-2.102h2.103v2.102H546.627z"/>
		<path d="M552.461,702.036v-2.102h2.103v2.102H552.461z"/>
		<path d="M558.295,702.036v-2.102h2.103v2.102H558.295z"/>
		<path d="M564.129,702.036v-2.102h2.103v2.102H564.129z"/>
		<path d="M161.821,725.07l1.989,0.503c-0.417,1.634-1.167,2.879-2.251,3.737c-1.083,0.857-2.408,1.286-3.973,1.286
			c-1.62,0-2.938-0.329-3.953-0.989c-1.016-0.659-1.788-1.614-2.317-2.866c-0.53-1.25-0.795-2.594-0.795-4.029
			c0-1.565,0.299-2.931,0.897-4.097c0.598-1.165,1.449-2.051,2.553-2.655c1.104-0.605,2.319-0.908,3.646-0.908
			c1.504,0,2.769,0.384,3.794,1.148c1.025,0.767,1.74,1.843,2.143,3.23l-1.958,0.461c-0.349-1.093-0.854-1.89-1.518-2.389
			s-1.497-0.748-2.502-0.748c-1.155,0-2.121,0.276-2.896,0.83c-0.776,0.554-1.321,1.297-1.636,2.23
			c-0.314,0.933-0.472,1.896-0.472,2.887c0,1.278,0.186,2.394,0.559,3.348c0.373,0.953,0.952,1.666,1.738,2.138
			s1.637,0.708,2.553,0.708c1.114,0,2.058-0.321,2.83-0.965C161.024,727.289,161.547,726.334,161.821,725.07z"/>
		<path d="M166.004,730.34v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H166.004z"/>
		<path d="M172.331,724.895c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C172.801,728.143,172.331,726.735,172.331,724.895z
			 M174.228,724.895c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S174.228,723.5,174.228,724.895z"/>
		<path d="M184.697,730.34v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H184.697z"/>
		<path d="M200.406,728.69l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C199.801,728.761,200.071,728.738,200.406,728.69z"/>
		<path d="M209.317,728.997c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C209.495,729.958,209.372,729.51,209.317,728.997z M209.163,724.875c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V724.875z"/>
		<path d="M215.592,730.34h-1.712v-15.032h1.846v5.362c0.779-0.977,1.774-1.466,2.984-1.466c0.67,0,1.304,0.135,1.902,0.405
			c0.598,0.27,1.09,0.649,1.477,1.138c0.386,0.489,0.689,1.079,0.908,1.769c0.219,0.691,0.328,1.43,0.328,2.215
			c0,1.867-0.461,3.31-1.384,4.328s-2.03,1.527-3.322,1.527c-1.285,0-2.293-0.536-3.025-1.609V730.34z M215.572,724.813
			c0,1.307,0.178,2.25,0.533,2.83c0.581,0.951,1.367,1.426,2.358,1.426c0.807,0,1.504-0.351,2.092-1.051
			c0.588-0.701,0.882-1.745,0.882-3.133c0-1.422-0.282-2.471-0.846-3.148c-0.563-0.676-1.246-1.015-2.045-1.015
			c-0.807,0-1.504,0.351-2.092,1.051C215.866,722.474,215.572,723.488,215.572,724.813z"/>
		<path d="M231.845,730.34v-9.454h-1.63v-1.436h1.63v-1.159c0-0.73,0.065-1.274,0.195-1.63c0.178-0.479,0.49-0.866,0.938-1.164
			c0.448-0.297,1.075-0.446,1.882-0.446c0.52,0,1.094,0.063,1.723,0.186l-0.277,1.609c-0.383-0.068-0.745-0.103-1.087-0.103
			c-0.561,0-0.957,0.12-1.189,0.358c-0.232,0.24-0.349,0.688-0.349,1.344v1.005h2.123v1.436h-2.123v9.454H231.845z"/>
		<path d="M237.218,730.34v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H237.218z"/>
		<path d="M244.242,717.43v-2.122h1.846v2.122H244.242z M244.242,730.34v-10.89h1.846v10.89H244.242z"/>
		<path d="M256.352,726.833l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S256.071,727.613,256.352,726.833z M250.292,723.85h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C250.672,722.141,250.353,722.9,250.292,723.85z"/>
		<path d="M260.576,730.34v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H260.576z"/>
		<path d="M279.32,730.34v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H279.32z M273.486,724.906c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C273.761,722.408,273.486,723.463,273.486,724.906z"/>
		<path d="M283.894,730.34v-15.032h1.846v15.032H283.894z"/>
		<path d="M288.518,734.534l-0.205-1.732c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.132-10.91h1.989
			l2.266,6.306c0.294,0.801,0.557,1.641,0.79,2.523c0.212-0.848,0.465-1.675,0.759-2.482l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.021-1.036,2.472c-0.328,0.607-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.426-1.518,0.426
			C289.352,734.76,288.956,734.684,288.518,734.534z"/>
		<path d="M304.914,730.34v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H304.914z"/>
		<path d="M319.064,730.34v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H319.064z"/>
		<path d="M323.607,730.34v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H323.607z"/>
		<path d="M334.548,727.09l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C335.226,729.117,334.753,728.246,334.548,727.09z"/>
		<path d="M355.148,734.76c-1.019-1.286-1.88-2.789-2.584-4.512s-1.056-3.508-1.056-5.354c0-1.626,0.263-3.185,0.79-4.676
			c0.615-1.729,1.565-3.451,2.851-5.168h1.323c-0.827,1.423-1.374,2.438-1.641,3.046c-0.417,0.943-0.745,1.928-0.984,2.953
			c-0.294,1.278-0.441,2.563-0.441,3.855c0,3.288,1.022,6.573,3.066,9.854H355.148z"/>
		<path d="M357.875,727.09l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C358.554,729.117,358.081,728.246,357.875,727.09z"/>
		<path d="M369.124,730.34v-15.032h1.846v8.572l4.369-4.43h2.389l-4.163,4.04l4.583,6.85h-2.275l-3.6-5.568l-1.302,1.252v4.316
			H369.124z"/>
		<path d="M379.624,717.43v-2.122h1.846v2.122H379.624z M379.624,730.34v-10.89h1.846v10.89H379.624z"/>
		<path d="M384.28,734.514v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.247,1.153,1.609,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.199,2.118-0.6,3.01
			c-0.399,0.893-0.98,1.576-1.743,2.051c-0.763,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.204-0.984v5.302H384.28z M385.951,724.958c0,1.401,0.284,2.437,0.851,3.106c0.568,0.67,1.255,1.005,2.062,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.285-2.427-0.855-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C386.253,722.488,385.951,723.556,385.951,724.958z"/>
		<path d="M401.803,717.43v-2.122h1.846v2.122H401.803z M401.803,730.34v-10.89h1.846v10.89H401.803z"/>
		<path d="M406.899,730.34v-9.454h-1.63v-1.436h1.63v-1.159c0-0.73,0.065-1.274,0.195-1.63c0.178-0.479,0.49-0.866,0.938-1.164
			c0.448-0.297,1.076-0.446,1.883-0.446c0.52,0,1.093,0.063,1.722,0.186l-0.277,1.609c-0.382-0.068-0.744-0.103-1.086-0.103
			c-0.561,0-0.957,0.12-1.189,0.358c-0.232,0.24-0.349,0.688-0.349,1.344v1.005h2.122v1.436h-2.122v9.454H406.899z"/>
		<path d="M418.107,730.34v-10.89h1.662v1.651c0.423-0.772,0.814-1.282,1.174-1.528c0.358-0.246,0.754-0.369,1.184-0.369
			c0.622,0,1.255,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.551,0.579-0.687,1.01c-0.205,0.656-0.309,1.374-0.309,2.153v5.701H418.107z"/>
		<path d="M432.258,730.34v-1.6c-0.849,1.23-2,1.846-3.456,1.846c-0.643,0-1.242-0.123-1.8-0.369
			c-0.557-0.246-0.971-0.556-1.24-0.928c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.112-0.937-0.112-1.723v-6.747h1.846
			v6.04c0,0.963,0.037,1.613,0.112,1.947c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415
			s1.073-0.142,1.559-0.425c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H432.258z"/>
		<path d="M436.8,730.34v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H436.8z"/>
		<path d="M448.48,730.34v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H448.48z"/>
		<path d="M460.169,717.43v-2.122h1.846v2.122H460.169z M460.169,730.34v-10.89h1.846v10.89H460.169z"/>
		<path d="M464.826,730.34v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H464.826z"/>
		<path d="M476.167,731.243l1.794,0.267c0.075,0.554,0.284,0.957,0.626,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.515-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.134-2.369
			c-0.808,0.951-1.813,1.426-3.016,1.426c-1.496,0-2.655-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.563-2.877
			c0.376-0.878,0.922-1.557,1.636-2.035c0.715-0.479,1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.349-0.293-3.147-0.877C476.525,733.298,476.139,732.418,476.167,731.243z M477.695,724.701
			c0,1.429,0.283,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.305-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C477.982,722.399,477.695,723.388,477.695,724.701z"/>
		<path d="M489.394,734.76h-1.322c2.044-3.281,3.066-6.566,3.066-9.854c0-1.285-0.147-2.56-0.441-3.825
			c-0.232-1.025-0.558-2.01-0.975-2.953c-0.266-0.615-0.816-1.641-1.65-3.076h1.322c1.285,1.717,2.236,3.439,2.852,5.168
			c0.525,1.491,0.789,3.05,0.789,4.676c0,1.846-0.354,3.631-1.062,5.354C491.266,731.971,490.406,733.474,489.394,734.76z"/>
		<path d="M495.701,730.34v-2.102h2.103v2.102H495.701z"/>
		<path d="M151.136,786.95v-15.032h10.869v1.774h-8.88v4.604h8.316v1.764h-8.316v5.117h9.229v1.773H151.136z"/>
		<path d="M171.972,785.606c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C172.15,786.567,172.027,786.12,171.972,785.606z M171.818,781.485c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V781.485z"/>
		<path d="M175.807,783.7l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C176.485,785.726,176.012,784.855,175.807,783.7z"/>
		<path d="M186.963,791.143l-0.205-1.732c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451L186,776.06h1.989l2.266,6.306
			c0.294,0.801,0.557,1.641,0.79,2.523c0.212-0.848,0.465-1.675,0.759-2.482l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.021-1.036,2.472c-0.328,0.607-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.426-1.518,0.426
			C187.797,791.37,187.401,791.293,186.963,791.143z"/>
		<path d="M210.445,786.95v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H210.445z M204.61,781.515c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C204.885,779.017,204.61,780.073,204.61,781.515z"/>
		<path d="M222.514,783.443l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S222.233,784.222,222.514,783.443z M216.454,780.459h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C216.834,778.75,216.515,779.509,216.454,780.459z"/>
		<path d="M228.44,786.95h-1.712v-15.032h1.846v5.362c0.779-0.977,1.774-1.466,2.984-1.466c0.67,0,1.304,0.135,1.902,0.405
			c0.598,0.27,1.09,0.649,1.477,1.138c0.386,0.489,0.689,1.079,0.908,1.769c0.219,0.691,0.328,1.43,0.328,2.215
			c0,1.867-0.461,3.31-1.384,4.328s-2.03,1.527-3.322,1.527c-1.285,0-2.293-0.536-3.025-1.609V786.95z M228.42,781.422
			c0,1.307,0.178,2.25,0.533,2.83c0.581,0.951,1.367,1.426,2.358,1.426c0.807,0,1.504-0.351,2.092-1.051
			c0.588-0.701,0.882-1.745,0.882-3.133c0-1.422-0.282-2.471-0.846-3.148c-0.563-0.676-1.246-1.015-2.045-1.015
			c-0.807,0-1.504,0.351-2.092,1.051C228.714,779.083,228.42,780.097,228.42,781.422z"/>
		<path d="M245.554,786.95v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H245.554z"/>
		<path d="M249.758,787.852l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.133-2.369
			c-0.807,0.951-1.812,1.426-3.015,1.426c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.877
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.293-3.148-0.877C250.117,789.908,249.731,789.028,249.758,787.852z M251.286,781.31
			c0,1.429,0.284,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C251.573,779.008,251.286,779.998,251.286,781.31z"/>
		<path d="M261.438,787.852l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.133-2.369
			c-0.807,0.951-1.812,1.426-3.015,1.426c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.877
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.293-3.148-0.877C261.796,789.908,261.41,789.028,261.438,787.852z M262.965,781.31
			c0,1.429,0.284,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C263.252,779.008,262.965,779.998,262.965,781.31z"/>
		<path d="M273.465,774.04v-2.122h1.846v2.122H273.465z M273.465,786.95v-10.89h1.846v10.89H273.465z"/>
		<path d="M278.121,786.95v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H278.121z"/>
		<path d="M289.461,787.852l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.133-2.369
			c-0.807,0.951-1.812,1.426-3.015,1.426c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.877
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.293-3.148-0.877C289.82,789.908,289.434,789.028,289.461,787.852z M290.989,781.31
			c0,1.429,0.284,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C291.276,779.008,290.989,779.998,290.989,781.31z"/>
		<path d="M301.992,778.163v-2.103h2.102v2.103H301.992z M301.992,786.95v-2.102h2.102v2.102H301.992z"/>
		<path d="M181.652,811.748l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="81.428574"
       y="390.93362"
       id="text4402"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan4404"
         x="81.428574"
         y="390.93362">Write one task or test and iterate</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="425.93362"
         id="tspan4406">Distribute tasks over one or many hosts</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="460.93362"
         id="tspan4408">Organize runs by any variables you wish</tspan><tspan
			S181.372,812.527,181.652,811.748z M175.592,808.764h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C175.973,807.055,175.653,807.814,175.592,808.764z"/>
		<path d="M192.982,813.911c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C193.16,814.872,193.037,814.424,192.982,813.911z M192.829,809.79c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V809.79z"/>
		<path d="M196.817,812.004l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C197.496,814.031,197.022,813.16,196.817,812.004z"/>
		<path d="M207.974,819.448l-0.205-1.732c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.132-10.91h1.989
			l2.266,6.306c0.294,0.801,0.557,1.641,0.79,2.523c0.212-0.848,0.465-1.675,0.759-2.482l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.021-1.036,2.472c-0.328,0.607-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.426-1.518,0.426
			C208.808,819.674,208.411,819.598,207.974,819.448z"/>
		<path d="M228.42,813.604l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18V805.8h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C227.815,813.675,228.085,813.652,228.42,813.604z"/>
		<path d="M229.538,809.809c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C230.007,813.057,229.538,811.649,229.538,809.809z
			 M231.435,809.809c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S231.435,808.415,231.435,809.809z"/>
		<path d="M247.718,815.254v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H247.718z"/>
		<path d="M262.186,811.748l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S261.906,812.527,262.186,811.748z M256.126,808.764h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C256.507,807.055,256.188,807.814,256.126,808.764z"/>
		<path d="M273.517,811.266l1.815,0.235c-0.198,1.251-0.706,2.23-1.523,2.938c-0.817,0.708-1.82,1.062-3.009,1.062
			c-1.49,0-2.688-0.487-3.594-1.461c-0.906-0.975-1.358-2.37-1.358-4.189c0-1.175,0.195-2.204,0.584-3.086s0.982-1.543,1.779-1.984
			c0.796-0.44,1.663-0.661,2.6-0.661c1.183,0,2.15,0.299,2.902,0.897c0.752,0.598,1.234,1.447,1.446,2.548l-1.794,0.276
			c-0.171-0.73-0.474-1.281-0.908-1.65s-0.958-0.554-1.574-0.554c-0.93,0-1.685,0.333-2.266,1c-0.581,0.666-0.872,1.721-0.872,3.163
			c0,1.463,0.28,2.526,0.841,3.189s1.292,0.994,2.194,0.994c0.725,0,1.33-0.222,1.815-0.666S273.387,812.188,273.517,811.266z"/>
		<path d="M276.89,815.254v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H276.89z"/>
		<path d="M291.358,811.748l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S291.078,812.527,291.358,811.748z M285.298,808.764h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C285.679,807.055,285.36,807.814,285.298,808.764z"/>
		<path d="M302.689,813.911c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C302.867,814.872,302.744,814.424,302.689,813.911z M302.535,809.79c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V809.79z"/>
		<path d="M311.292,813.604l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18V805.8h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C310.687,813.675,310.957,813.652,311.292,813.604z"/>
		<path d="M320.551,811.748l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S320.271,812.527,320.551,811.748z M314.491,808.764h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C314.872,807.055,314.553,807.814,314.491,808.764z"/>
		<path d="M338.065,811.748l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S337.785,812.527,338.065,811.748z M332.005,808.764h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C332.386,807.055,332.066,807.814,332.005,808.764z"/>
		<path d="M342.29,815.254v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H342.29z"/>
		<path d="M356.994,815.254l-4.143-10.89h1.948l2.338,6.521c0.253,0.704,0.485,1.436,0.697,2.194
			c0.164-0.574,0.393-1.265,0.687-2.071l2.42-6.645h1.897l-4.122,10.89H356.994z"/>
		<path d="M364.479,802.344v-2.122h1.846v2.122H364.479z M364.479,815.254v-10.89h1.846v10.89H364.479z"/>
		<path d="M369.114,815.254v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.896,0.595l-0.635,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.404,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H369.114z"/>
		<path d="M375.44,809.809c0-2.016,0.561-3.51,1.682-4.48c0.938-0.807,2.078-1.21,3.426-1.21c1.496,0,2.721,0.49,3.67,1.472
			c0.951,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.42,0.804-1.032,1.428-1.836,1.872
         sodipodi:role="line"
         x="81.428574"
         y="495.93362"
         id="tspan4410"> - release</tspan><tspan
			c-0.803,0.443-1.68,0.666-2.629,0.666c-1.525,0-2.758-0.488-3.697-1.467C375.911,813.057,375.44,811.649,375.44,809.809z
			 M377.337,809.809c0,1.395,0.304,2.439,0.913,3.133c0.607,0.694,1.373,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.307-2.367-0.918-3.062c-0.612-0.693-1.373-1.04-2.281-1.04c-0.924,0-1.689,0.345-2.297,1.035
			C377.641,807.373,377.337,808.415,377.337,809.809z"/>
		<path d="M387.807,815.254v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.398-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.785,0-1.465,0.25-2.035,0.749s-0.855,1.445-0.855,2.84v5.947H387.807z"/>
		<path d="M399.486,815.254v-10.89h1.651v1.528c0.342-0.533,0.796-0.963,1.363-1.287c0.567-0.325,1.213-0.487,1.938-0.487
			c0.807,0,1.469,0.168,1.984,0.503s0.881,0.803,1.092,1.404c0.861-1.271,1.982-1.907,3.364-1.907c1.08,0,1.91,0.299,2.49,0.897
			c0.582,0.598,0.873,1.52,0.873,2.764v7.475h-1.836v-6.859c0-0.738-0.061-1.271-0.18-1.595c-0.119-0.325-0.336-0.586-0.65-0.784
			s-0.684-0.298-1.108-0.298c-0.766,0-1.4,0.255-1.906,0.764c-0.506,0.51-0.76,1.325-0.76,2.446v6.326h-1.846v-7.075
			c0-0.82-0.15-1.436-0.451-1.846s-0.793-0.615-1.477-0.615c-0.52,0-1,0.137-1.439,0.41c-0.441,0.273-0.762,0.674-0.959,1.2
			c-0.199,0.526-0.298,1.285-0.298,2.275v5.65H399.486z"/>
		<path d="M424.434,811.748l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C423.774,813.094,424.154,812.527,424.434,811.748z M418.375,808.764h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C418.755,807.055,418.435,807.814,418.375,808.764z"/>
		<path d="M428.66,815.254v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H428.66z"/>
		<path d="M444.369,813.604l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18V805.8h-1.354v-1.436h1.354v-2.696l1.836-1.107v3.804
			h1.855v1.436h-1.855v6.368c0,0.526,0.032,0.864,0.097,1.015c0.065,0.15,0.171,0.271,0.318,0.358
			c0.146,0.09,0.356,0.134,0.63,0.134C443.763,813.675,444.034,813.652,444.369,813.604z"/>
		<path d="M452.448,815.254V805.8h-1.63v-1.436h1.63v-1.159c0-0.73,0.064-1.274,0.194-1.63c0.178-0.479,0.491-0.866,0.938-1.164
			c0.448-0.297,1.075-0.446,1.882-0.446c0.52,0,1.094,0.063,1.723,0.186l-0.277,1.609c-0.383-0.068-0.745-0.103-1.086-0.103
			c-0.562,0-0.958,0.12-1.189,0.358c-0.233,0.24-0.35,0.688-0.35,1.344v1.005h2.123v1.436h-2.123v9.454H452.448z"/>
		<path d="M457.154,809.809c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C457.624,813.057,457.154,811.649,457.154,809.809z
			 M459.05,809.809c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.611-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S459.05,808.415,459.05,809.809z"/>
		<path d="M469.5,815.254v-10.89h1.662v1.651c0.423-0.772,0.814-1.282,1.174-1.528c0.358-0.246,0.754-0.369,1.184-0.369
			c0.622,0,1.255,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.551,0.579-0.687,1.01c-0.205,0.656-0.309,1.374-0.309,2.153v5.701H469.5z"/>
		<path d="M486.378,813.604l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18V805.8h-1.354v-1.436h1.354v-2.696l1.836-1.107v3.804
			h1.855v1.436h-1.855v6.368c0,0.526,0.032,0.864,0.097,1.015c0.065,0.15,0.171,0.271,0.318,0.358
			c0.146,0.09,0.356,0.134,0.63,0.134C485.773,813.675,486.043,813.652,486.378,813.604z"/>
		<path d="M495.289,813.911c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.312,0.359-2.036,0.359
         sodipodi:role="line"
         x="81.428574"
         y="530.93359"
			c-1.196,0-2.115-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.561-0.795,0.953-1.062c0.394-0.267,0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.291-0.636c0.007-0.253,0.011-0.413,0.011-0.481c0-0.752-0.175-1.282-0.522-1.59
			c-0.473-0.417-1.173-0.625-2.103-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.413,0.304-0.72,0.843-0.918,1.614l-1.805-0.246
			c0.164-0.771,0.435-1.396,0.811-1.871c0.376-0.475,0.919-0.841,1.631-1.097c0.71-0.257,1.534-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.009,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.093,0.883,0.093,1.703v2.461c0,1.716,0.039,2.801,0.117,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C495.466,814.872,495.343,814.424,495.289,813.911z M495.134,809.79c-0.67,0.273-1.675,0.506-3.014,0.697
			c-0.76,0.109-1.296,0.232-1.61,0.369s-0.558,0.336-0.728,0.6c-0.172,0.263-0.257,0.556-0.257,0.877
			c0,0.492,0.187,0.902,0.559,1.23c0.373,0.328,0.918,0.492,1.636,0.492c0.711,0,1.344-0.156,1.896-0.467
			c0.555-0.312,0.961-0.736,1.221-1.277c0.198-0.416,0.297-1.031,0.297-1.846V809.79z"/>
		<path d="M499.125,812.004l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C499.802,814.031,499.33,813.16,499.125,812.004z"/>
		<path d="M510.373,815.254v-15.032h1.846v8.572l4.368-4.43h2.39l-4.164,4.04l4.584,6.85h-2.276l-3.599-5.568l-1.303,1.252v4.316
			H510.373z"/>
         id="tspan4412"> - architecture</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="565.93359"
         id="tspan4414"> - unit or partition</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="600.93359"
         id="tspan4416">Tasks or tests may depend on others</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="635.93359"
         id="tspan4418">Each task or test runs in clean area</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="670.93359"
         id="tspan4420">Add disk space or partitions as needed</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="705.93359"
         id="tspan4422">Rigorous results; error, pass, warn etc.</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="740.93359"
         id="tspan4424">Crontab friendly runs (skip if running)</tspan><tspan
		<path d="M521.385,815.254v-2.102h2.103v2.102H521.385z"/>
		<path d="M181.303,842.215c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C181.481,843.176,181.358,842.729,181.303,842.215z M181.149,838.094c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V838.094z"/>
		<path d="M185.876,843.559v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H185.876z"/>
		<path d="M197.556,843.559v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H197.556z"/>
		<path d="M208.548,838.114c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C209.018,841.362,208.548,839.954,208.548,838.114z
			 M210.445,838.114c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S210.445,836.719,210.445,838.114z"/>
		<path d="M224.944,841.909l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C224.339,841.98,224.609,841.957,224.944,841.909z"/>
		<path d="M233.854,842.215c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C234.032,843.176,233.909,842.729,233.854,842.215z M233.701,838.094c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V838.094z"/>
		<path d="M242.458,841.909l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C241.853,841.98,242.123,841.957,242.458,841.909z"/>
		<path d="M251.717,840.052l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S251.437,840.832,251.717,840.052z M245.657,837.069h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C246.038,835.36,245.718,836.119,245.657,837.069z"/>
		<path d="M263.006,843.559v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H263.006z M257.172,838.125c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C257.447,835.626,257.172,836.682,257.172,838.125z"/>
		<path d="M273.752,843.559v-15.032h1.989v6.173h7.813v-6.173h1.989v15.032h-1.989v-7.086h-7.813v7.086H273.752z"/>
		<path d="M292.681,843.559v-13.258h-4.953v-1.774h11.915v1.774h-4.973v13.258H292.681z"/>
		<path d="M301.623,843.559v-15.032h2.994l3.558,10.644c0.328,0.991,0.567,1.732,0.718,2.225c0.171-0.546,0.438-1.35,0.8-2.409
			l3.599-10.459h2.676v15.032h-1.917v-12.582l-4.368,12.582h-1.794l-4.348-12.797v12.797H301.623z"/>
		<path d="M319.095,843.559v-15.032h1.989v13.259h7.403v1.773H319.095z"/>
		<path d="M335.635,843.559v-15.032h1.846v15.032H335.635z"/>
		<path d="M339.654,838.114c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C340.124,841.362,339.654,839.954,339.654,838.114z
			 M341.551,838.114c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S341.551,836.719,341.551,838.114z"/>
		<path d="M351.682,844.461l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.133-2.369
			c-0.807,0.951-1.812,1.426-3.015,1.426c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.877
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.293-3.148-0.877C352.041,846.517,351.655,845.637,351.682,844.461z M353.21,837.919
			c0,1.429,0.284,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C353.497,835.618,353.21,836.607,353.21,837.919z"/>
		<path d="M362.961,840.309l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C363.64,842.335,363.167,841.464,362.961,840.309z"/>
		<path d="M380.034,843.559v-15.032h1.846v5.394c0.861-0.998,1.949-1.497,3.262-1.497c0.807,0,1.507,0.159,2.102,0.477
			c0.595,0.318,1.021,0.758,1.276,1.317c0.257,0.562,0.385,1.375,0.385,2.441v6.9h-1.846v-6.9c0-0.924-0.2-1.595-0.6-2.016
			c-0.4-0.42-0.966-0.631-1.697-0.631c-0.547,0-1.062,0.143-1.543,0.426c-0.482,0.284-0.825,0.669-1.03,1.154
			s-0.309,1.155-0.309,2.01v5.957H380.034z"/>
		<path d="M399.168,840.052l1.906,0.235c-0.301,1.115-0.857,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.788-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.385,2.386,1.385,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.609,0.635,1.367,0.953,2.277,0.953c0.676,0,1.254-0.178,1.732-0.533
			S398.887,840.832,399.168,840.052z M393.108,837.069h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.286-1.066c-0.848,0-1.561,0.284-2.138,0.851C393.489,835.36,393.169,836.119,393.108,837.069z"/>
		<path d="M403.352,843.559v-15.032h1.846v15.032H403.352z"/>
		<path d="M408.058,847.733v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.344-1.246c0.498-0.276,1.104-0.415,1.814-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.609,2.025c0.363,0.871,0.543,1.827,0.543,2.865c0,1.115-0.199,2.118-0.6,3.01
			c-0.398,0.893-0.98,1.576-1.742,2.051c-0.762,0.476-1.564,0.713-2.404,0.713c-0.615,0-1.168-0.13-1.656-0.39
			c-0.489-0.26-0.891-0.588-1.205-0.984v5.302H408.058z M409.729,838.176c0,1.401,0.284,2.437,0.852,3.106s1.255,1.005,2.062,1.005
			c0.82,0,1.521-0.347,2.107-1.041c0.584-0.693,0.875-1.769,0.875-3.225c0-1.388-0.285-2.427-0.855-3.117s-1.252-1.035-2.045-1.035
			c-0.787,0-1.482,0.367-2.088,1.102C410.032,835.707,409.729,836.775,409.729,838.176z"/>
		<path d="M426.012,843.559v-9.454h-1.63v-1.436h1.63v-1.159c0-0.73,0.064-1.274,0.194-1.63c0.178-0.479,0.491-0.866,0.938-1.164
			c0.448-0.297,1.075-0.446,1.882-0.446c0.52,0,1.094,0.063,1.723,0.186l-0.277,1.609c-0.383-0.068-0.745-0.103-1.086-0.103
			c-0.562,0-0.958,0.12-1.189,0.358c-0.233,0.24-0.35,0.688-0.35,1.344v1.005h2.123v1.436h-2.123v9.454H426.012z"/>
		<path d="M431.416,830.649v-2.122h1.846v2.122H431.416z M431.416,843.559v-10.89h1.846v10.89H431.416z"/>
		<path d="M436.072,843.559v-10.89h1.66v1.548c0.801-1.195,1.955-1.794,3.467-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.071-1.314-0.216-1.687c-0.143-0.373-0.397-0.67-0.764-0.893c-0.365-0.222-0.795-0.333-1.287-0.333
			c-0.786,0-1.464,0.25-2.035,0.749c-0.57,0.499-0.855,1.445-0.855,2.84v5.947H436.072z"/>
		<path d="M454.816,843.559v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.869,0-1.667-0.239-2.395-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.544-2.958
			c0.361-0.886,0.905-1.564,1.63-2.035c0.725-0.473,1.534-0.708,2.431-0.708c0.656,0,1.24,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.836v15.032H454.816z M448.982,838.125c0,1.395,0.293,2.438,0.881,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.847-1.667,0.847-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C449.256,835.626,448.982,836.682,448.982,838.125z"/>
		<path d="M465.275,830.649v-2.122h1.846v2.122H465.275z M465.275,843.559v-10.89h1.846v10.89H465.275z"/>
		<path d="M469.193,840.309l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
         sodipodi:role="line"
         x="81.428574"
         y="775.93359"
         id="tspan4426">Easy debugging</tspan><tspan
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C469.871,842.335,469.398,841.464,469.193,840.309z"/>
		<path d="M479.693,840.309l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C480.371,842.335,479.898,841.464,479.693,840.309z"/>
		<path d="M498.068,843.559v-1.6c-0.849,1.23-2,1.846-3.456,1.846c-0.643,0-1.242-0.123-1.8-0.369
			c-0.557-0.246-0.971-0.556-1.24-0.928c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.112-0.937-0.112-1.723v-6.747h1.846
			v6.04c0,0.963,0.037,1.613,0.112,1.947c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415
			s1.073-0.142,1.559-0.425c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H498.068z"/>
		<path d="M510.065,840.052l1.907,0.235c-0.301,1.115-0.858,1.979-1.672,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.004,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			C509.405,841.399,509.785,840.832,510.065,840.052z M504.005,837.069h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.351-1.066-2.287-1.066c-0.848,0-1.56,0.284-2.138,0.851C504.386,835.36,504.066,836.119,504.005,837.069z"/>
		<path d="M513.552,840.309l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C514.23,842.335,513.757,841.464,513.552,840.309z"/>
		<path d="M525.313,843.559v-2.102h2.103v2.102H525.313z"/>
		<path d="M150.418,895.338l1.876-0.164c0.089,0.753,0.295,1.369,0.621,1.852c0.324,0.481,0.829,0.871,1.512,1.169
			c0.684,0.297,1.453,0.446,2.307,0.446c0.759,0,1.429-0.113,2.01-0.339s1.013-0.535,1.297-0.928
			c0.284-0.394,0.426-0.822,0.426-1.287c0-0.472-0.137-0.884-0.41-1.235c-0.273-0.353-0.725-0.647-1.354-0.887
			c-0.403-0.157-1.295-0.402-2.676-0.733c-1.381-0.332-2.348-0.645-2.902-0.938c-0.718-0.376-1.253-0.843-1.604-1.399
         sodipodi:role="line"
         x="81.428574"
         y="810.93359"
         id="tspan4428"> - easy to recreate environment for task</tspan><tspan
			c-0.353-0.558-0.528-1.181-0.528-1.872c0-0.758,0.215-1.468,0.646-2.127c0.431-0.66,1.06-1.16,1.887-1.502
			s1.747-0.514,2.758-0.514c1.114,0,2.097,0.18,2.948,0.539c0.851,0.358,1.505,0.887,1.963,1.584s0.704,1.486,0.738,2.369
			l-1.907,0.143c-0.103-0.949-0.45-1.667-1.041-2.152c-0.592-0.485-1.465-0.729-2.62-0.729c-1.203,0-2.08,0.221-2.63,0.661
			c-0.551,0.441-0.826,0.973-0.826,1.595c0,0.54,0.195,0.984,0.584,1.333c0.383,0.349,1.382,0.706,2.999,1.071
         sodipodi:role="line"
         x="81.428574"
         y="845.93359"
         id="tspan4430"> - annotated HTML logs help find issues</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="880.93353"
         id="tspan4432">Simplify scripts</tspan><tspan
         sodipodi:role="line"
         x="81.428574"
         y="915.93353"
         id="tspan4434"> - eliminate for-each or while loops</tspan><tspan
			c1.617,0.366,2.726,0.686,3.328,0.959c0.875,0.403,1.521,0.914,1.938,1.533c0.417,0.618,0.625,1.331,0.625,2.138
			c0,0.8-0.229,1.554-0.687,2.261c-0.458,0.708-1.116,1.258-1.974,1.651c-0.858,0.393-1.824,0.589-2.897,0.589
			c-1.36,0-2.5-0.198-3.419-0.594c-0.92-0.396-1.641-0.993-2.164-1.79C150.721,897.245,150.446,896.344,150.418,895.338z"/>
		<path d="M164.876,887.258v-2.122h1.846v2.122H164.876z M164.876,900.168v-10.89h1.846v10.89H164.876z"/>
		<path d="M169.532,900.168v-10.89h1.651v1.528c0.342-0.533,0.796-0.963,1.364-1.287c0.567-0.325,1.213-0.487,1.938-0.487
			c0.807,0,1.468,0.168,1.984,0.503c0.516,0.335,0.88,0.803,1.092,1.404c0.861-1.271,1.982-1.907,3.363-1.907
			c1.08,0,1.911,0.299,2.492,0.897c0.581,0.598,0.872,1.52,0.872,2.764v7.475h-1.835v-6.859c0-0.738-0.06-1.271-0.179-1.595
			c-0.12-0.325-0.337-0.586-0.651-0.784s-0.684-0.298-1.107-0.298c-0.766,0-1.401,0.255-1.907,0.764
			c-0.506,0.51-0.759,1.325-0.759,2.446v6.326h-1.846v-7.075c0-0.82-0.15-1.436-0.451-1.846s-0.793-0.615-1.477-0.615
			c-0.52,0-1,0.137-1.44,0.41c-0.441,0.273-0.761,0.674-0.959,1.2s-0.297,1.285-0.297,2.275v5.65H169.532z"/>
		<path d="M187.025,904.342v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H187.025z M188.696,894.786c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C188.999,892.316,188.696,893.384,188.696,894.786z"/>
		<path d="M198.663,900.168v-15.032h1.846v15.032H198.663z"/>
		<path d="M203.38,887.258v-2.122h1.846v2.122H203.38z M203.38,900.168v-10.89h1.846v10.89H203.38z"/>
		<path d="M208.476,900.168v-9.454h-1.63v-1.436h1.63v-1.159c0-0.73,0.065-1.274,0.195-1.63c0.178-0.479,0.49-0.866,0.938-1.164
			c0.448-0.297,1.075-0.446,1.882-0.446c0.52,0,1.094,0.063,1.723,0.186l-0.277,1.609c-0.383-0.068-0.745-0.103-1.087-0.103
			c-0.561,0-0.957,0.12-1.189,0.358c-0.232,0.24-0.349,0.688-0.349,1.344v1.005h2.123v1.436h-2.123v9.454H208.476z"/>
		<path d="M213.788,904.362l-0.205-1.732c0.403,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.448-0.328,0.605-0.574c0.116-0.185,0.304-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.132-10.91h1.989
			l2.266,6.306c0.294,0.801,0.557,1.641,0.79,2.523c0.212-0.848,0.465-1.675,0.759-2.482l2.328-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.021-1.036,2.472c-0.328,0.607-0.704,1.054-1.128,1.338c-0.424,0.283-0.93,0.426-1.518,0.426
			C214.622,904.588,214.225,904.512,213.788,904.362z"/>
		<path d="M229.466,896.918l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C230.144,898.945,229.671,898.074,229.466,896.918z"/>
		<path d="M247.81,896.18l1.815,0.235c-0.198,1.251-0.706,2.23-1.523,2.938c-0.817,0.708-1.82,1.062-3.009,1.062
			c-1.49,0-2.688-0.487-3.594-1.461c-0.906-0.975-1.358-2.37-1.358-4.189c0-1.175,0.195-2.204,0.584-3.086s0.982-1.543,1.779-1.984
			c0.796-0.44,1.663-0.661,2.6-0.661c1.183,0,2.15,0.299,2.902,0.897c0.752,0.598,1.234,1.447,1.446,2.548l-1.794,0.276
			c-0.171-0.73-0.474-1.281-0.908-1.65s-0.958-0.554-1.574-0.554c-0.93,0-1.685,0.333-2.266,1c-0.581,0.666-0.872,1.721-0.872,3.163
			c0,1.463,0.28,2.526,0.841,3.189s1.292,0.994,2.194,0.994c0.725,0,1.33-0.222,1.815-0.666S247.68,897.102,247.81,896.18z"/>
		<path d="M251.184,900.168v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H251.184z"/>
		<path d="M258.208,887.258v-2.122h1.846v2.122H258.208z M258.208,900.168v-10.89h1.846v10.89H258.208z"/>
		<path d="M262.863,904.342v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H262.863z M264.534,894.786c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C264.837,892.316,264.534,893.384,264.534,894.786z"/>
		<path d="M278.572,898.518l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C277.967,898.589,278.237,898.566,278.572,898.518z"/>
		<path d="M279.638,896.918l1.825-0.287c0.103,0.731,0.388,1.291,0.856,1.682c0.468,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.181-0.745-0.543-0.984
			c-0.253-0.164-0.882-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.333-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.678-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.123,0.579,1.43,1c0.308,0.42,0.52,0.982,0.636,1.687l-1.805,0.246c-0.082-0.561-0.32-0.998-0.712-1.313
			c-0.394-0.314-0.949-0.472-1.667-0.472c-0.848,0-1.453,0.141-1.815,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.075,0.454,0.226,0.646c0.15,0.198,0.386,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.216,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.441,0.95,0.441,1.579
			c0,0.615-0.179,1.194-0.539,1.738c-0.358,0.543-0.876,0.964-1.553,1.261c-0.677,0.298-1.442,0.446-2.297,0.446
			c-1.415,0-2.494-0.294-3.235-0.882C280.316,898.945,279.843,898.074,279.638,896.918z"/>
		<path d="M291.389,891.381v-2.103h2.102v2.103H291.389z M291.389,900.168v-2.102h2.102v2.102H291.389z"/>
		<path d="M181.652,924.966l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S181.372,925.746,181.652,924.966z M175.592,921.983h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C175.973,920.274,175.653,921.033,175.592,921.983z"/>
		<path d="M185.835,928.473v-15.032h1.846v15.032H185.835z"/>
		<path d="M190.552,915.563v-2.122h1.846v2.122H190.552z M190.552,928.473v-10.89h1.846v10.89H190.552z"/>
		<path d="M195.208,928.473v-10.89h1.651v1.528c0.342-0.533,0.796-0.963,1.364-1.287c0.567-0.325,1.213-0.487,1.938-0.487
			c0.807,0,1.468,0.168,1.984,0.503c0.516,0.335,0.88,0.803,1.092,1.404c0.861-1.271,1.982-1.907,3.363-1.907
			c1.08,0,1.911,0.299,2.492,0.897c0.581,0.598,0.872,1.52,0.872,2.764v7.475h-1.835v-6.859c0-0.738-0.06-1.271-0.179-1.595
			c-0.12-0.325-0.337-0.586-0.651-0.784s-0.684-0.298-1.107-0.298c-0.766,0-1.401,0.255-1.907,0.764
			c-0.506,0.51-0.759,1.325-0.759,2.446v6.326h-1.846v-7.075c0-0.82-0.15-1.436-0.451-1.846s-0.793-0.615-1.477-0.615
			c-0.52,0-1,0.137-1.44,0.41c-0.441,0.273-0.761,0.674-0.959,1.2s-0.297,1.285-0.297,2.275v5.65H195.208z"/>
		<path d="M212.711,915.563v-2.122h1.846v2.122H212.711z M212.711,928.473v-10.89h1.846v10.89H212.711z"/>
		<path d="M217.366,928.473v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H217.366z"/>
		<path d="M236.151,927.129c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
         sodipodi:role="line"
         x="81.428574"
         y="950.93353"
         id="tspan4436"> - parallel running handled by tool</tspan></text>
    <rect
       style="opacity:0.7837838;fill:#e81c1c;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect4444"
       width="95.714287"
       height="38.57143"
       x="17.142857"
       y="223.79076" />
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C236.329,928.09,236.206,927.643,236.151,927.129z M235.998,923.008c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V923.008z"/>
		<path d="M244.754,926.823l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.835-1.107v3.804
			h1.856v1.436h-1.856v6.368c0,0.526,0.032,0.864,0.097,1.015s0.171,0.271,0.318,0.358c0.146,0.09,0.357,0.134,0.63,0.134
			C244.149,926.894,244.419,926.871,244.754,926.823z"/>
		<path d="M254.014,924.966l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S253.733,925.746,254.014,924.966z M247.954,921.983h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C248.334,920.274,248.015,921.033,247.954,921.983z"/>
		<path d="M264.514,928.473v-9.454h-1.63v-1.436h1.63v-1.159c0-0.73,0.065-1.274,0.195-1.63c0.178-0.479,0.49-0.866,0.938-1.164
			c0.448-0.297,1.075-0.446,1.882-0.446c0.52,0,1.094,0.063,1.723,0.186l-0.277,1.609c-0.383-0.068-0.745-0.103-1.087-0.103
			c-0.561,0-0.957,0.12-1.189,0.358c-0.232,0.24-0.349,0.688-0.349,1.344v1.005h2.123v1.436h-2.123v9.454H264.514z"/>
		<path d="M269.22,923.028c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C269.69,926.276,269.22,924.868,269.22,923.028z
			 M271.117,923.028c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S271.117,921.633,271.117,923.028z"/>
		<path d="M281.566,928.473v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H281.566z"/>
		<path d="M287.862,923.961v-1.855h5.67v1.855H287.862z"/>
		<path d="M303.027,924.966l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S302.747,925.746,303.027,924.966z M296.967,921.983h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C297.348,920.274,297.029,921.033,296.967,921.983z"/>
		<path d="M314.358,927.129c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C314.536,928.09,314.413,927.643,314.358,927.129z M314.204,923.008c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V923.008z"/>
		<path d="M326.037,924.485l1.815,0.235c-0.198,1.251-0.706,2.23-1.523,2.938c-0.817,0.708-1.82,1.062-3.009,1.062
			c-1.49,0-2.688-0.487-3.594-1.461c-0.906-0.975-1.358-2.37-1.358-4.189c0-1.175,0.195-2.204,0.584-3.086s0.982-1.543,1.779-1.984
			c0.796-0.44,1.663-0.661,2.6-0.661c1.183,0,2.15,0.299,2.902,0.897c0.752,0.598,1.234,1.447,1.446,2.548l-1.794,0.276
			c-0.171-0.73-0.474-1.281-0.908-1.65s-0.958-0.554-1.574-0.554c-0.93,0-1.685,0.333-2.266,1c-0.581,0.666-0.872,1.721-0.872,3.163
			c0,1.463,0.28,2.526,0.841,3.189s1.292,0.994,2.194,0.994c0.725,0,1.33-0.222,1.815-0.666S325.907,925.407,326.037,924.485z"/>
		<path d="M329.431,928.473v-15.032h1.846v5.394c0.861-0.998,1.948-1.497,3.261-1.497c0.807,0,1.507,0.159,2.102,0.477
			c0.595,0.318,1.021,0.758,1.276,1.317c0.257,0.562,0.385,1.375,0.385,2.441v6.9h-1.846v-6.9c0-0.924-0.2-1.595-0.6-2.016
			c-0.4-0.42-0.966-0.631-1.697-0.631c-0.547,0-1.062,0.143-1.543,0.426c-0.482,0.284-0.826,0.669-1.031,1.154
			s-0.308,1.155-0.308,2.01v5.957H329.431z"/>
		<path d="M346.258,923.028c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.425,2.336,1.425,4.065c0,1.401-0.21,2.504-0.63,3.307c-0.421,0.804-1.033,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C346.728,926.276,346.258,924.868,346.258,923.028z
			 M348.155,923.028c0,1.395,0.304,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.287-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.612-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S348.155,921.633,348.155,923.028z"/>
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="31.428562"
       y="253.79076"
       id="text4446"
       sodipodi:linespacing="125%"><tspan
		<path d="M358.604,928.473v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H358.604z"/>
		<path d="M373.461,928.473l-3.333-10.89h1.907l1.733,6.286l0.646,2.338c0.027-0.116,0.216-0.865,0.564-2.246l1.732-6.378h1.897
			l1.63,6.316l0.544,2.081l0.626-2.102l1.865-6.296h1.795l-3.404,10.89h-1.918l-1.732-6.521l-0.42-1.855l-2.205,8.377H373.461z"/>
		<path d="M386.618,928.473v-15.032h1.846v5.394c0.861-0.998,1.947-1.497,3.26-1.497c0.807,0,1.508,0.159,2.103,0.477
			c0.595,0.318,1.021,0.758,1.276,1.317c0.257,0.562,0.385,1.375,0.385,2.441v6.9h-1.846v-6.9c0-0.924-0.2-1.595-0.6-2.016
			c-0.4-0.42-0.966-0.631-1.697-0.631c-0.547,0-1.062,0.143-1.543,0.426c-0.482,0.284-0.826,0.669-1.031,1.154
			s-0.307,1.155-0.307,2.01v5.957H386.618z"/>
		<path d="M398.307,915.563v-2.122h1.846v2.122H398.307z M398.307,928.473v-10.89h1.846v10.89H398.307z"/>
		<path d="M402.92,928.473v-15.032h1.846v15.032H402.92z"/>
		<path d="M415.082,924.966l1.908,0.235c-0.301,1.115-0.859,1.979-1.672,2.595c-0.814,0.615-1.854,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.788-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.383,2.386,1.383,4.184c0,0.109-0.004,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.368,0.953,2.276,0.953c0.678,0,1.254-0.178,1.734-0.533
			C414.421,926.313,414.802,925.746,415.082,924.966z M409.022,921.983h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.352-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C409.403,920.274,409.083,921.033,409.022,921.983z"/>
		<path d="M425.101,928.473v-15.032h1.846v15.032H425.101z"/>
		<path d="M429.121,923.028c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C429.59,926.276,429.121,924.868,429.121,923.028z
			 M431.017,923.028c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.611-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S431.017,921.633,431.017,923.028z"/>
		<path d="M440.8,923.028c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C441.27,926.276,440.8,924.868,440.8,923.028z
			 M442.697,923.028c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.611-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S442.697,921.633,442.697,923.028z"/>
		<path d="M453.167,932.647v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.929,0,1.749,0.239,2.461,0.718c0.71,0.479,1.247,1.153,1.609,2.025c0.362,0.871,0.543,1.827,0.543,2.865
			c0,1.115-0.199,2.118-0.6,3.01c-0.399,0.893-0.98,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713
			c-0.615,0-1.167-0.13-1.656-0.39c-0.488-0.26-0.891-0.588-1.204-0.984v5.302H453.167z M454.838,923.09
			c0,1.401,0.283,2.437,0.851,3.106s1.255,1.005,2.062,1.005c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225
			c0-1.388-0.285-2.427-0.855-3.117c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102
			C455.141,920.621,454.838,921.689,454.838,923.09z"/>
		<path d="M464.109,925.223l1.824-0.287c0.104,0.731,0.389,1.291,0.856,1.682c0.469,0.389,1.123,0.584,1.964,0.584
			c0.848,0,1.477-0.173,1.887-0.518c0.41-0.346,0.615-0.75,0.615-1.215c0-0.417-0.182-0.745-0.543-0.984
         sodipodi:role="line"
         id="tspan4448"
         x="31.428562"
         y="253.79076">FAIL</tspan></text>
    <rect
       style="opacity:0.7837838;fill:#1ac92c;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect4444-6"
       width="92.85714"
       height="40"
       x="19.285711"
       y="177.36217" />
			c-0.254-0.164-0.883-0.373-1.887-0.626c-1.354-0.342-2.292-0.638-2.815-0.887c-0.522-0.25-0.919-0.595-1.189-1.036
			c-0.27-0.44-0.405-0.928-0.405-1.461c0-0.485,0.111-0.935,0.334-1.349c0.222-0.413,0.524-0.757,0.907-1.03
			c0.287-0.212,0.679-0.392,1.174-0.538c0.496-0.147,1.027-0.221,1.595-0.221c0.854,0,1.604,0.123,2.251,0.369
			c0.646,0.246,1.122,0.579,1.431,1c0.307,0.42,0.519,0.982,0.635,1.687l-1.805,0.246c-0.082-0.561-0.319-0.998-0.712-1.313
			c-0.394-0.314-0.948-0.472-1.667-0.472c-0.848,0-1.452,0.141-1.814,0.421s-0.543,0.608-0.543,0.984
			c0,0.239,0.074,0.454,0.225,0.646c0.15,0.198,0.387,0.362,0.708,0.492c0.185,0.068,0.728,0.226,1.63,0.472
			c1.306,0.349,2.217,0.634,2.733,0.856c0.516,0.222,0.921,0.545,1.215,0.969s0.44,0.95,0.44,1.579c0,0.615-0.179,1.194-0.538,1.738
			c-0.358,0.543-0.876,0.964-1.554,1.261c-0.676,0.298-1.442,0.446-2.297,0.446c-1.414,0-2.493-0.294-3.234-0.882
			C464.787,927.25,464.314,926.378,464.109,925.223z"/>
		<path d="M475.87,928.473v-2.102h2.103v2.102H475.87z"/>
		<path d="M174.197,960.952v-15.063h1.682v1.415c0.396-0.554,0.844-0.969,1.343-1.246c0.499-0.276,1.104-0.415,1.815-0.415
			c0.93,0,1.75,0.239,2.461,0.718s1.248,1.153,1.61,2.025c0.362,0.871,0.543,1.827,0.543,2.865c0,1.115-0.2,2.118-0.6,3.01
			c-0.399,0.893-0.981,1.576-1.743,2.051c-0.762,0.476-1.563,0.713-2.404,0.713c-0.615,0-1.167-0.13-1.656-0.39
			s-0.89-0.588-1.205-0.984v5.302H174.197z M175.869,951.395c0,1.401,0.284,2.437,0.851,3.106s1.254,1.005,2.061,1.005
			c0.82,0,1.522-0.347,2.107-1.041c0.584-0.693,0.876-1.769,0.876-3.225c0-1.388-0.286-2.427-0.856-3.117
			c-0.571-0.69-1.253-1.035-2.046-1.035c-0.786,0-1.481,0.367-2.087,1.102C176.171,948.925,175.869,949.994,175.869,951.395z"/>
		<path d="M192.982,955.434c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C193.16,956.395,193.037,955.948,192.982,955.434z M192.829,951.313c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V951.313z"/>
		<path d="M197.535,956.778v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H197.535z"/>
		<path d="M211.655,955.434c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
			C211.833,956.395,211.709,955.948,211.655,955.434z M211.501,951.313c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V951.313z"/>
		<path d="M216.187,956.778v-15.032h1.846v15.032H216.187z"/>
		<path d="M220.853,956.778v-15.032h1.846v15.032H220.853z"/>
		<path d="M233.014,953.271l1.907,0.235c-0.301,1.115-0.858,1.979-1.671,2.595s-1.853,0.923-3.117,0.923
			c-1.593,0-2.856-0.49-3.789-1.472c-0.934-0.98-1.4-2.356-1.4-4.127c0-1.832,0.472-3.254,1.415-4.266s2.167-1.518,3.671-1.518
			c1.456,0,2.646,0.496,3.568,1.487s1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.01,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.015,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.254-0.178,1.733-0.533
			S232.733,954.05,233.014,953.271z M226.954,950.288h6.081c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C227.334,948.579,227.015,949.337,226.954,950.288z"/>
		<path d="M237.197,956.778v-15.032h1.846v15.032H237.197z"/>
		<path d="M247.718,956.778v-10.89h1.661v1.651c0.424-0.772,0.815-1.282,1.174-1.528c0.358-0.246,0.753-0.369,1.184-0.369
			c0.622,0,1.254,0.198,1.897,0.595l-0.636,1.713c-0.451-0.268-0.902-0.4-1.354-0.4c-0.403,0-0.766,0.121-1.087,0.364
			c-0.321,0.242-0.55,0.579-0.687,1.01c-0.205,0.656-0.308,1.374-0.308,2.153v5.701H247.718z"/>
		<path d="M261.868,956.778v-1.6c-0.848,1.23-2,1.846-3.456,1.846c-0.643,0-1.243-0.123-1.8-0.369s-0.971-0.556-1.24-0.928
			c-0.271-0.373-0.46-0.829-0.569-1.369c-0.075-0.362-0.113-0.937-0.113-1.723v-6.747h1.846v6.04c0,0.963,0.038,1.613,0.113,1.947
			c0.116,0.486,0.362,0.867,0.738,1.144c0.376,0.277,0.841,0.415,1.395,0.415s1.073-0.142,1.559-0.425
			c0.485-0.284,0.829-0.67,1.03-1.159c0.202-0.488,0.303-1.197,0.303-2.127v-5.835h1.846v10.89H261.868z"/>
		<path d="M266.411,956.778v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H266.411z"/>
		<path d="M278.09,956.778v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H278.09z"/>
		<path d="M289.779,943.868v-2.122h1.846v2.122H289.779z M289.779,956.778v-10.89h1.846v10.89H289.779z"/>
		<path d="M294.435,956.778v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H294.435z"/>
		<path d="M305.775,957.68l1.794,0.267c0.075,0.554,0.284,0.957,0.625,1.21c0.458,0.342,1.083,0.513,1.876,0.513
			c0.854,0,1.514-0.171,1.979-0.513s0.779-0.82,0.943-1.436c0.096-0.376,0.14-1.165,0.133-2.369
			c-0.807,0.951-1.812,1.426-3.015,1.426c-1.497,0-2.656-0.54-3.476-1.62s-1.23-2.375-1.23-3.886c0-1.039,0.188-1.998,0.564-2.877
			c0.376-0.878,0.921-1.557,1.635-2.035s1.554-0.718,2.518-0.718c1.285,0,2.345,0.52,3.179,1.559v-1.313h1.702v9.413
			c0,1.695-0.173,2.896-0.518,3.604c-0.346,0.707-0.893,1.267-1.641,1.677c-0.749,0.41-1.67,0.615-2.764,0.615
			c-1.299,0-2.348-0.293-3.148-0.877C306.134,959.736,305.748,958.856,305.775,957.68z M307.303,951.138
			c0,1.429,0.284,2.472,0.851,3.128s1.278,0.984,2.133,0.984c0.848,0,1.559-0.327,2.133-0.979c0.574-0.653,0.861-1.677,0.861-3.071
			c0-1.333-0.296-2.338-0.887-3.015c-0.592-0.677-1.304-1.015-2.138-1.015c-0.82,0-1.518,0.333-2.092,0.999
			C307.59,948.836,307.303,949.826,307.303,951.138z"/>
		<path d="M323.627,956.778v-15.032h1.846v5.394c0.861-0.998,1.948-1.497,3.261-1.497c0.807,0,1.507,0.159,2.102,0.477
			c0.595,0.318,1.021,0.758,1.276,1.317c0.257,0.562,0.385,1.375,0.385,2.441v6.9h-1.846v-6.9c0-0.924-0.2-1.595-0.6-2.016
			c-0.4-0.42-0.966-0.631-1.697-0.631c-0.547,0-1.062,0.143-1.543,0.426c-0.482,0.284-0.826,0.669-1.031,1.154
			s-0.308,1.155-0.308,2.01v5.957H323.627z"/>
		<path d="M342.413,955.434c-0.684,0.582-1.342,0.992-1.974,1.23c-0.633,0.239-1.311,0.359-2.036,0.359
			c-1.196,0-2.116-0.292-2.758-0.877c-0.643-0.584-0.964-1.331-0.964-2.24c0-0.533,0.121-1.021,0.364-1.461
			c0.242-0.441,0.56-0.795,0.953-1.062s0.836-0.468,1.328-0.604c0.362-0.096,0.909-0.188,1.641-0.277
			c1.49-0.178,2.587-0.39,3.292-0.636c0.007-0.253,0.01-0.413,0.01-0.481c0-0.752-0.174-1.282-0.523-1.59
			c-0.472-0.417-1.172-0.625-2.102-0.625c-0.868,0-1.509,0.151-1.923,0.456c-0.414,0.304-0.719,0.843-0.917,1.614l-1.805-0.246
			c0.164-0.771,0.434-1.396,0.81-1.871c0.376-0.475,0.919-0.841,1.63-1.097c0.711-0.257,1.535-0.385,2.471-0.385
			c0.93,0,1.685,0.109,2.266,0.328s1.008,0.494,1.282,0.825c0.273,0.332,0.465,0.751,0.574,1.256
			c0.062,0.315,0.092,0.883,0.092,1.703v2.461c0,1.716,0.039,2.801,0.118,3.255c0.079,0.455,0.234,0.891,0.467,1.308h-1.928
    <text
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="29.285706"
       y="208.79076"
       id="text4446-1"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan4448-6"
         x="29.285706"
         y="208.79076">PASS</tspan></text>
    <rect
			C342.59,956.395,342.467,955.948,342.413,955.434z M342.259,951.313c-0.67,0.273-1.675,0.506-3.015,0.697
			c-0.759,0.109-1.295,0.232-1.61,0.369s-0.557,0.336-0.728,0.6c-0.171,0.263-0.256,0.556-0.256,0.877
			c0,0.492,0.186,0.902,0.559,1.23s0.918,0.492,1.636,0.492c0.711,0,1.343-0.156,1.897-0.467c0.554-0.312,0.96-0.736,1.22-1.277
			c0.198-0.416,0.297-1.031,0.297-1.846V951.313z"/>
		<path d="M346.986,956.778v-10.89h1.661v1.548c0.8-1.195,1.955-1.794,3.466-1.794c0.656,0,1.259,0.118,1.81,0.354
			c0.55,0.236,0.962,0.546,1.235,0.929s0.465,0.837,0.574,1.363c0.068,0.342,0.103,0.94,0.103,1.795v6.695h-1.846v-6.624
			c0-0.752-0.072-1.314-0.215-1.687c-0.144-0.373-0.398-0.67-0.764-0.893c-0.366-0.222-0.794-0.333-1.287-0.333
			c-0.786,0-1.465,0.25-2.036,0.749s-0.856,1.445-0.856,2.84v5.947H346.986z"/>
		<path d="M365.73,956.778v-1.374c-0.69,1.08-1.706,1.62-3.045,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.292-1.146-1.692-2.005c-0.399-0.857-0.6-1.844-0.6-2.958c0-1.087,0.181-2.073,0.543-2.958
			c0.362-0.886,0.906-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.43-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.513,0.277,0.93,0.638,1.251,1.082v-5.394h1.835v15.032H365.73z M359.896,951.343c0,1.395,0.294,2.438,0.882,3.128
			s1.282,1.035,2.082,1.035c0.807,0,1.492-0.33,2.056-0.989c0.564-0.66,0.846-1.667,0.846-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.123-1.045c-0.82,0-1.506,0.335-2.056,1.004C360.17,948.845,359.896,949.901,359.896,951.343z"/>
		<path d="M370.303,956.778v-15.032h1.846v15.032H370.303z"/>
		<path d="M382.464,953.271l1.907,0.235c-0.301,1.115-0.857,1.979-1.672,2.595c-0.813,0.615-1.852,0.923-3.117,0.923
			c-1.592,0-2.855-0.49-3.788-1.472c-0.934-0.98-1.399-2.356-1.399-4.127c0-1.832,0.471-3.254,1.414-4.266s2.168-1.518,3.672-1.518
			c1.455,0,2.645,0.496,3.568,1.487c0.922,0.991,1.384,2.386,1.384,4.184c0,0.109-0.003,0.273-0.011,0.492h-8.121
			c0.068,1.196,0.407,2.111,1.016,2.748c0.608,0.635,1.367,0.953,2.276,0.953c0.677,0,1.255-0.178,1.733-0.533
			S382.184,954.05,382.464,953.271z M376.405,950.288h6.08c-0.082-0.916-0.314-1.604-0.697-2.062
			c-0.588-0.711-1.35-1.066-2.287-1.066c-0.848,0-1.561,0.284-2.138,0.851C376.786,948.579,376.465,949.337,376.405,950.288z"/>
		<path d="M393.754,956.778v-1.374c-0.691,1.08-1.706,1.62-3.046,1.62c-0.868,0-1.667-0.239-2.394-0.718
			c-0.729-0.479-1.293-1.146-1.693-2.005c-0.398-0.857-0.6-1.844-0.6-2.958c0-1.087,0.182-2.073,0.544-2.958
			c0.362-0.886,0.905-1.564,1.63-2.035c0.725-0.473,1.535-0.708,2.431-0.708c0.656,0,1.241,0.139,1.753,0.415
			c0.514,0.277,0.93,0.638,1.252,1.082v-5.394h1.835v15.032H393.754z M387.919,951.343c0,1.395,0.294,2.438,0.882,3.128
			s1.281,1.035,2.082,1.035c0.807,0,1.492-0.33,2.055-0.989c0.564-0.66,0.847-1.667,0.847-3.021c0-1.489-0.287-2.584-0.861-3.281
			s-1.282-1.045-2.122-1.045c-0.82,0-1.506,0.335-2.057,1.004C388.194,948.845,387.919,949.901,387.919,951.343z"/>
		<path d="M405.905,956.778h-1.713v-15.032h1.846v5.362c0.779-0.977,1.774-1.466,2.984-1.466c0.67,0,1.304,0.135,1.901,0.405
			c0.6,0.27,1.092,0.649,1.477,1.138c0.387,0.489,0.689,1.079,0.908,1.769c0.219,0.691,0.328,1.43,0.328,2.215
			c0,1.867-0.461,3.31-1.385,4.328c-0.922,1.019-2.03,1.527-3.321,1.527c-1.285,0-2.294-0.536-3.025-1.609V956.778z M405.884,951.25
			c0,1.307,0.178,2.25,0.533,2.83c0.581,0.951,1.367,1.426,2.358,1.426c0.807,0,1.504-0.351,2.091-1.051
			c0.588-0.701,0.883-1.745,0.883-3.133c0-1.422-0.281-2.471-0.846-3.148c-0.563-0.676-1.246-1.015-2.046-1.015
			c-0.807,0-1.504,0.351-2.092,1.051C406.178,948.912,405.884,949.925,405.884,951.25z"/>
		<path d="M415.8,960.971l-0.205-1.732c0.402,0.109,0.755,0.164,1.056,0.164c0.41,0,0.738-0.068,0.984-0.205
			s0.447-0.328,0.604-0.574c0.116-0.185,0.305-0.643,0.564-1.374c0.034-0.103,0.089-0.253,0.164-0.451l-4.133-10.91h1.99
			l2.266,6.306c0.294,0.801,0.557,1.641,0.789,2.523c0.212-0.848,0.465-1.675,0.76-2.482l2.327-6.347h1.846l-4.143,11.074
			c-0.444,1.196-0.79,2.021-1.036,2.472c-0.328,0.607-0.704,1.054-1.127,1.338c-0.425,0.283-0.931,0.426-1.518,0.426
			C416.633,961.198,416.237,961.122,415.8,960.971z"/>
		<path d="M436.246,955.127l0.267,1.63c-0.52,0.109-0.984,0.164-1.395,0.164c-0.67,0-1.189-0.106-1.559-0.317
			c-0.369-0.212-0.629-0.491-0.779-0.836c-0.15-0.346-0.226-1.072-0.226-2.18v-6.265h-1.354v-1.436h1.354v-2.696l1.836-1.107v3.804
			h1.855v1.436h-1.855v6.368c0,0.526,0.032,0.864,0.097,1.015c0.065,0.15,0.171,0.271,0.318,0.358
			c0.146,0.09,0.356,0.134,0.63,0.134C435.64,955.199,435.911,955.175,436.246,955.127z"/>
		<path d="M437.363,951.333c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C437.833,954.581,437.363,953.172,437.363,951.333z
			 M439.259,951.333c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.611-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S439.259,949.938,439.259,951.333z"/>
		<path d="M449.042,951.333c0-2.016,0.561-3.51,1.682-4.48c0.937-0.807,2.078-1.21,3.425-1.21c1.497,0,2.721,0.49,3.671,1.472
			c0.95,0.98,1.426,2.336,1.426,4.065c0,1.401-0.211,2.504-0.631,3.307c-0.421,0.804-1.032,1.428-1.836,1.872
			c-0.803,0.443-1.68,0.666-2.63,0.666c-1.524,0-2.757-0.488-3.696-1.467C449.512,954.581,449.042,953.172,449.042,951.333z
			 M450.939,951.333c0,1.395,0.305,2.439,0.913,3.133c0.608,0.694,1.374,1.041,2.297,1.041c0.916,0,1.678-0.349,2.286-1.046
			s0.913-1.76,0.913-3.188c0-1.347-0.306-2.367-0.918-3.062c-0.611-0.693-1.372-1.04-2.281-1.04c-0.923,0-1.688,0.345-2.297,1.035
			S450.939,949.938,450.939,951.333z"/>
		<path d="M461.369,956.778v-15.032h1.846v15.032H461.369z"/>
		<path d="M466.598,956.778v-2.102h2.103v2.102H466.598z"/>
	</g>
	<g>
       style="opacity:0.7837838;fill:#ffbf02;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       id="rect4444-9"
       width="95.714287"
       height="38.57143"
       x="17.857157"
       y="268.79077" />
    <text
		<path d="M165.739,811.468c0,0.25-0.113,0.432-0.339,0.543L155.21,818.5c-0.363,0-0.543-0.146-0.543-0.441v-1.189
			c0-0.316,0.147-0.531,0.441-0.645l2.388-5.627l-2.388-5.549c-0.294-0.113-0.441-0.328-0.441-0.645v-1.189
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.193l0.412,0.262c0.226,0.111,0.339,0.293,0.339,0.543V811.468z"/>
	</g>
	<g>
		<path d="M165.739,838.83c0,0.25-0.113,0.432-0.339,0.543l-10.189,6.488c-0.363,0-0.543-0.146-0.543-0.441v-1.189
			c0-0.316,0.147-0.531,0.441-0.645l2.388-5.627l-2.388-5.549c-0.294-0.113-0.441-0.328-0.441-0.645v-1.189
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.193l0.412,0.262c0.226,0.111,0.339,0.293,0.339,0.543V838.83z"/>
	</g>
	<g>
		<path d="M165.739,925.695c0,0.25-0.113,0.432-0.339,0.543l-10.189,6.488c-0.363,0-0.543-0.146-0.543-0.441v-1.189
			c0-0.316,0.147-0.531,0.441-0.645l2.388-5.627l-2.388-5.549c-0.294-0.113-0.441-0.328-0.441-0.645v-1.189
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.193l0.412,0.262c0.226,0.111,0.339,0.293,0.339,0.543V925.695z"/>
	</g>
	<g>
		<path d="M165.739,953.056c0,0.25-0.113,0.432-0.339,0.543l-10.189,6.488c-0.363,0-0.543-0.146-0.543-0.441v-1.189
			c0-0.316,0.147-0.531,0.441-0.645l2.388-5.627l-2.388-5.549c-0.294-0.113-0.441-0.328-0.441-0.645v-1.189
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.193l0.412,0.262c0.226,0.111,0.339,0.293,0.339,0.543V953.056z"/>
	</g>
	<g>
		<path d="M165.739,553.697c0,0.25-0.113,0.432-0.339,0.543l-10.189,6.488c-0.363,0-0.543-0.146-0.543-0.441v-1.189
			c0-0.316,0.147-0.533,0.441-0.645l2.388-5.629l-2.388-5.547c-0.294-0.113-0.441-0.328-0.441-0.646v-1.188
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.191l0.412,0.262c0.226,0.113,0.339,0.295,0.339,0.543V553.697z"/>
	</g>
	<g>
		<path d="M165.739,525.392c0,0.25-0.113,0.432-0.339,0.543l-10.189,6.489c-0.363,0-0.543-0.146-0.543-0.441v-1.189
			c0-0.316,0.147-0.531,0.441-0.645l2.388-5.627l-2.388-5.548c-0.294-0.114-0.441-0.328-0.441-0.646v-1.188
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.193l0.412,0.262c0.226,0.111,0.339,0.293,0.339,0.542V525.392z"/>
	</g>
	<g>
		<path d="M165.739,497.087c0,0.25-0.113,0.431-0.339,0.544l-10.189,6.487c-0.363,0-0.543-0.146-0.543-0.441v-1.188
			c0-0.317,0.147-0.533,0.441-0.645l2.388-5.628l-2.388-5.547c-0.294-0.113-0.441-0.328-0.441-0.646v-1.188
			c0-0.293,0.181-0.441,0.543-0.441l9.778,6.192l0.412,0.262c0.226,0.112,0.339,0.294,0.339,0.542V497.087z"/>
	</g>
	<circle cx="134.852" cy="386.027" r="3.184"/>
	<circle cx="134.852" cy="412.444" r="3.184"/>
	<circle cx="134.852" cy="610.931" r="3.184"/>
	<circle cx="134.852" cy="639.148" r="3.184"/>
	<circle cx="134.852" cy="667.363" r="3.184"/>
	<circle cx="134.852" cy="695.58" r="3.184"/>
	<circle cx="135.796" cy="723.796" r="3.184"/>
	<circle cx="135.796" cy="894.164" r="3.184"/>
	<circle cx="135.796" cy="781.304" r="3.184"/>
</g>
       xml:space="preserve"
       style="font-size:28px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="22.142862"
       y="295.93362"
       id="text4446-3"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan4448-9"
         x="22.142862"
         y="295.93362">WARN</tspan></text>
  </g>
<g id="Layer_2">
	<g>
		<g>
			<path d="M77.952,102.496c-6.091-3.731-9.14-5.6-15.23-9.332c1.76-2.872,2.69-4.252,4.636-6.894
				c5.082,1.319,7.567,2.107,12.396,3.906c-2.699-4.399-3.96-6.681-6.281-11.38c2.152-2.372,3.27-3.5,5.574-5.64
				c4.846,5.26,7.271,7.891,12.116,13.15c-1.155,1.073-1.72,1.626-2.829,2.771c-4.024-3.934-6.04-5.901-10.064-9.836
				c2.634,5.371,4.081,7.972,7.2,12.965c-1.095,1.265-1.631,1.917-2.669,3.259c-5.491-2.094-8.324-3-14.129-4.486
				c4.625,3.2,6.94,4.801,11.565,8C79.294,100.349,78.836,101.053,77.952,102.496z"/>
			<path d="M94.314,83.543c-4.549-5.52-6.827-8.279-11.376-13.8c5.868-4.863,9.024-6.949,15.582-10.424
				c0.568,1.068,0.853,1.602,1.422,2.67c-4.618,2.447-6.862,3.85-11.143,7.008c0.94,1.278,1.411,1.917,2.351,3.194
				c3.809-2.811,5.798-4.068,9.889-6.29c0.577,1.058,0.865,1.587,1.442,2.646c-3.949,2.145-5.869,3.359-9.546,6.072
				c1.154,1.568,1.731,2.353,2.885,3.921c3.854-2.843,5.876-4.099,10.043-6.28c0.561,1.067,0.842,1.599,1.402,2.666
				C101.809,77.783,99.185,79.506,94.314,83.543z"/>
			<path d="M117.017,63.741c-0.374-1.146-0.563-1.718-0.937-2.863c3.731-1.203,5.63-1.695,9.457-2.462
				c0.568,2.79,0.854,4.185,1.422,6.975c-0.706,0.887-1.786,1.773-3.212,2.705c-1.426,0.931-2.896,1.638-4.457,2.138
				c-1.983,0.635-3.814,0.898-5.575,0.761c-1.761-0.138-3.321-0.669-4.688-1.648c-1.368-0.979-2.449-2.22-3.192-3.767
				c-0.806-1.679-1.076-3.388-0.731-5.136c0.344-1.747,1.327-3.397,2.966-4.877c1.25-1.129,3.014-2.107,5.267-2.835
				c2.928-0.946,5.386-1.101,7.259-0.594c1.872,0.506,3.191,1.553,3.981,3.067c-1.777,0.636-2.654,0.976-4.385,1.701
				c-0.539-0.767-1.32-1.281-2.347-1.519c-1.028-0.238-2.222-0.152-3.549,0.277c-2.013,0.651-3.431,1.711-4.217,3.086
				s-0.769,2.979-0.017,4.797c0.812,1.961,1.958,3.204,3.388,3.79s2.95,0.591,4.635,0.045c0.834-0.27,1.628-0.667,2.396-1.197
				s1.409-1.073,1.925-1.642c-0.228-0.878-0.342-1.316-0.57-2.194C119.894,62.846,118.93,63.125,117.017,63.741z"/>
			<path d="M148.957,66.569c-1.739-0.145-2.611-0.192-4.355-0.238c-0.65-1.64-0.993-2.458-1.717-4.084
				c-3.344-0.013-5.02,0.066-8.35,0.397c-0.524,1.683-0.768,2.527-1.22,4.217c-1.69,0.205-2.533,0.331-4.211,0.629
				c1.782-7.575,3.042-11.369,6.311-18.779c2.09-0.157,3.137-0.208,5.231-0.25C144.719,55.523,146.386,59.187,148.957,66.569z
				 M141.488,59.244c-1.231-2.636-1.894-3.942-3.314-6.528c-1.135,2.709-1.653,4.073-2.598,6.813
				C137.937,59.332,139.12,59.274,141.488,59.244z"/>
			<path d="M153.468,67.078c0.851-5.875,1.278-8.815,2.132-14.69c-2.793-0.398-4.198-0.543-7.011-0.727
				c0.081-1.206,0.121-1.81,0.202-3.015c7.784,0.508,11.676,1.16,19.229,3.262c-0.329,1.163-0.495,1.746-0.823,2.909
				c-2.723-0.757-4.097-1.083-6.863-1.627c-1.165,5.822-1.746,8.737-2.906,14.559C155.85,67.438,155.057,67.304,153.468,67.078z"/>
			<path d="M165.661,69.848c2.173-6.808,3.26-10.218,5.441-17.024c6.986,2.205,10.41,3.654,16.918,7.247
				c-0.587,1.058-0.882,1.587-1.469,2.646c-4.583-2.53-6.957-3.618-11.802-5.437c-0.563,1.482-0.844,2.223-1.406,3.705
				c4.311,1.619,6.427,2.575,10.523,4.783c-0.574,1.06-0.861,1.591-1.435,2.651c-3.955-2.131-5.996-3.055-10.158-4.617
				c-0.69,1.82-1.035,2.731-1.725,4.551c4.361,1.638,6.498,2.622,10.614,4.922c-0.589,1.051-0.885,1.577-1.474,2.628
				C174.299,72.89,171.46,71.677,165.661,69.848z"/>
			<path d="M184.807,72.147c1.546,0.772,2.313,1.181,3.831,2.046c-0.445,1.123-0.504,2.13-0.188,3.032
				c0.315,0.901,0.993,1.733,2.035,2.537c1.103,0.851,2.069,1.33,2.934,1.414c0.865,0.083,1.515-0.112,1.943-0.612
				c0.275-0.321,0.393-0.696,0.347-1.126c-0.046-0.43-0.299-0.985-0.768-1.649c-0.321-0.453-1.104-1.434-2.415-2.878
				c-1.688-1.858-2.805-3.301-3.265-4.437c-0.647-1.597-0.643-2.994,0.101-4.198c0.479-0.775,1.222-1.319,2.248-1.608
				c1.026-0.289,2.229-0.234,3.597,0.197c1.367,0.431,2.857,1.23,4.421,2.427c2.553,1.955,4.087,3.951,4.637,5.769
				c0.55,1.818,0.245,3.355-0.826,4.604c-1.483-1.324-2.24-1.961-3.777-3.184c0.433-0.838,0.511-1.64,0.222-2.399
				c-0.289-0.759-0.99-1.588-2.11-2.444c-1.156-0.884-2.207-1.373-3.119-1.489c-0.587-0.076-1.011,0.083-1.274,0.464
				c-0.241,0.348-0.248,0.782-0.03,1.304c0.277,0.663,1.253,1.831,2.833,3.598s2.602,3.229,3.14,4.3
				c0.538,1.072,0.763,2.109,0.687,3.095c-0.076,0.986-0.516,1.884-1.298,2.699c-0.709,0.739-1.629,1.179-2.743,1.359
				s-2.263,0.021-3.468-0.453c-1.205-0.474-2.492-1.27-3.909-2.361c-2.062-1.589-3.398-3.117-4.011-4.76
				C183.969,75.75,184.021,74.009,184.807,72.147z"/>
			<path d="M200.825,93.555c4.562-3.8,6.843-5.703,11.406-9.505c-1.956-2.368-2.973-3.498-5.079-5.65
				c0.861-0.85,1.292-1.274,2.153-2.123c5.826,5.958,8.498,9.336,13.127,16.888c-1.03,0.631-1.545,0.946-2.576,1.578
				c-1.669-2.723-2.551-4.03-4.392-6.539c-4.774,3.53-7.161,5.297-11.936,8.826C202.479,95.598,201.938,94.902,200.825,93.555z"/>
		</g>
	</g>
	<polygon fill="#00A551" points="120.909,94.217 134.005,82.577 145.647,105.132 201.063,36.532 201.726,49.118 142.736,130.597 	
		"/>
	<g>
		<path fill="#58595B" d="M74.947,128.281l1.414,5.408l-1.523,0.922l-7.32-6.722l2.163-1.309l3.652,3.7l-1.285-5.133l1.469-0.889
			l3.995,3.529l-1.573-4.995l2.176-1.317l2.559,9.603l-1.523,0.922L74.947,128.281z"/>
		<path fill="#58595B" d="M90.875,124.905l-2.122,1.284l-1.392-1.164l-3.128,1.894l0.386,1.773l-2.122,1.284l-1.825-10.047
			l2.149-1.301L90.875,124.905z M83.824,125.046l2.067-1.251L83.03,121.4L83.824,125.046z"/>
		<path fill="#58595B" d="M93.568,123.275l-1.973,1.194l-4.939-8.162l1.973-1.194L93.568,123.275z"/>
		<path fill="#58595B" d="M89.35,114.677l2.122-1.284l5.73,4.801l-1.596-7.304l2.122-1.284l1.825,10.047l-2.149,1.301L89.35,114.677
			z"/>
		<path fill="#58595B" d="M106.647,110.77l-3.319,2.009l1.004,1.659l3.958-2.396l1.029,1.7l-5.931,3.589l-4.939-8.162l5.931-3.589
			l1.029,1.7l-3.958,2.396l0.938,1.551l3.319-2.009L106.647,110.77z"/>
		<path fill="#58595B" d="M113.781,111.042l-3.143,1.902l-4.939-8.162l3.143-1.902c2.625-1.589,5.338-0.852,6.754,1.488
			S116.406,109.453,113.781,111.042z M108.7,105.288l2.882,4.762l1.02-0.617c1.319-0.799,1.859-2.334,0.954-3.83
			c-0.955-1.578-2.516-1.73-3.835-0.932L108.7,105.288z"/>
	</g>
	<g>
		<path fill="#00A551" d="M99.726,127.786c1.013,1.673,0.391,3.5-1.487,4.636l-1.632,0.988l1.622,2.68l-1.972,1.193l-4.94-8.162
			l3.604-2.181C96.784,125.812,98.763,126.194,99.726,127.786z M95.813,128.722l-1.496,0.906l1.276,2.108l1.51-0.914
			c0.693-0.419,1.002-1.108,0.582-1.801C97.257,128.313,96.535,128.286,95.813,128.722z"/>
		<path fill="#00A551" d="M110.946,128.393l-2.122,1.284l-1.393-1.164l-3.128,1.894l0.386,1.773l-2.122,1.284l-1.825-10.047
			l2.149-1.301L110.946,128.393z M103.896,128.534l2.067-1.251l-2.861-2.395L103.896,128.534z"/>
		<path fill="#00A551" d="M110.759,125.197c0,0,1.647,0.081,2.749-0.585c0.612-0.371,0.733-0.815,0.486-1.224
			c-0.256-0.422-0.646-0.482-1.993-0.13c-2.019,0.534-3.401,0.46-4.217-0.887c-0.897-1.483-0.524-3.14,1.625-4.44
			c2.217-1.342,3.601-0.99,3.601-0.99l-0.09,2.247c0,0-1.269-0.161-2.425,0.539c-0.666,0.403-0.728,0.793-0.521,1.133
			c0.247,0.409,0.699,0.358,1.803,0.063c2.113-0.592,3.575-0.511,4.398,0.85c0.897,1.482,0.646,3.308-1.504,4.609
			c-2.258,1.366-4.073,0.977-4.073,0.977L110.759,125.197z"/>
		<path fill="#00A551" d="M118.009,120.809c0,0,1.647,0.081,2.749-0.585c0.612-0.371,0.733-0.815,0.486-1.224
			c-0.255-0.422-0.645-0.482-1.993-0.13c-2.019,0.534-3.401,0.46-4.216-0.887c-0.898-1.483-0.524-3.139,1.625-4.44
			c2.217-1.342,3.601-0.99,3.601-0.99l-0.09,2.247c0,0-1.269-0.161-2.425,0.539c-0.667,0.403-0.728,0.793-0.522,1.133
			c0.247,0.409,0.7,0.358,1.803,0.063c2.113-0.592,3.575-0.511,4.398,0.85c0.897,1.482,0.646,3.308-1.504,4.609
			c-2.258,1.367-4.073,0.977-4.073,0.977L118.009,120.809z"/>
	</g>
	<g>
		<path fill="#EC1C24" d="M111.273,138.926l-3.319,2.009l2.025,3.347l-1.972,1.193l-4.939-8.162l5.984-3.622l1.029,1.7l-4.013,2.429
			l0.947,1.564l3.318-2.009L111.273,138.926z"/>
		<path fill="#EC1C24" d="M121.936,137.045l-2.122,1.284l-1.393-1.164l-3.129,1.894l0.386,1.773l-2.122,1.284l-1.825-10.047
			l2.149-1.301L121.936,137.045z M114.885,137.187l2.068-1.251l-2.862-2.395L114.885,137.187z"/>
		<path fill="#EC1C24" d="M124.628,135.416l-1.972,1.194l-4.939-8.162l1.972-1.194L124.628,135.416z"/>
		<path fill="#EC1C24" d="M126.315,134.395l-4.939-8.162l1.973-1.194l3.91,6.462l3.646-2.206l1.029,1.7L126.315,134.395z"/>
	</g>
</g>
</svg>

Added docs/waiton-analysis.gnumeric version [3f09f77a41].

cannot compute difference between binary files

Added env.scm version [88e7c2b715].




















































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
;;======================================================================
;; Copyright 2006-2013, Matthew Welland.
;; 
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;; 
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.
;;======================================================================

(declare (unit env))

(use sql-de-lite) ;; srfi-1 posix regex regex-case srfi-69 nanomsg srfi-18 call-with-environment-variables)

(define (env:open-db fname)
  (let* ((db-exists (file-exists? fname))
	 (db        (open-database fname)))
    (if (not db-exists)
	(begin
	  (exec (sql db "CREATE TABLE envvars (
                    id INTEGER PRIMARY KEY,
                    context TEXT NOT NULL,
                    var TEXT NOT NULL,
                    val TEXT NOT NULL,
                       CONSTRAINT envvars_constraint UNIQUE (context,var))"))))
    (set-busy-handler! db (busy-timeout 10000))
    db))

;; save vars in given context, this is NOT incremental by default
;;
(define (env:save-env-vars db context #!key (incremental #f)(vardat #f))
  (with-transaction
   db
   (lambda ()
     ;; first clear out any vars for this context
     (if (not incremental)(exec (sql db "DELETE FROM envvars WHERE context=?") context))
     (for-each
      (lambda (varval)
	(let ((var (car varval))
	      (val (cdr varval)))
	  (if incremental (exec (sql db "DELETE FROM envvars WHERE context=? AND var=?") context var))
	  (exec (sql db "INSERT INTO envvars (context,var,val) VALUES (?,?,?)") context var val)))
	(if vardat
	    (hash-table->alist vardat)
	    (get-environment-variables))))))

;; merge contexts in the order given
;;  - each context is applied in the given order
;;  - variables in the paths list are split on the separator and the components
;;    merged using simple delta addition
;;    returns a hash of the merged vars
;;
(define (env:merge-contexts db basecontext contexts paths)
  (let ((result (make-hash-table)))
    (for-each
     (lambda (context)
       (query
	(for-each-row
	 (lambda (row)
	   (let ((var  (car row))
		 (val  (cadr row)))
	     (hash-table-set! result var 
			      (if (and (hash-table-ref/default results var #f)
				       (assoc var paths)) ;; this var is a path and there is a previous path
				  (let ((sep (cadr (assoc var paths))))
				    (env:merge-path-envvar sep (hash-table-ref results var) valb))
				  valb)))))
	(sql db "SELECT var,val FROM envvars WHERE context=?")
	context))
     contexts)
    result))

;;  get list of removed variables between two contexts
;;
(define (env:get-removed db contexta contextb)
  (let ((result (make-hash-table)))
    (query
     (for-each-row
      (lambda (row)
	(let ((var  (car row))
	      (val  (cadr row)))
	  (hash-table-set! result var val))))
     (sql db "SELECT var,val FROM envvars WHERE context=? AND var NOT IN (SELECT var FROM envvars WHERE context=?)")
     contexta contextb)
    result))

;;  get list of variables added to contextb from contexta
;;
(define (env:get-added db contexta contextb)
  (let ((result (make-hash-table)))
    (query
     (for-each-row
      (lambda (row)
	(let ((var  (car row))
	      (val  (cadr row)))
	  (hash-table-set! result var val))))
     (sql db "SELECT var,val FROM envvars WHERE context=? AND var NOT IN (SELECT var FROM envvars WHERE context=?)")
     contextb contexta)
    result))

;;  get list of variables in both contexta and contexb that have been changed
;;
(define (env:get-changed db contexta contextb)
  (let ((result (make-hash-table)))
    (query
     (for-each-row
      (lambda (row)
	(let ((var  (car row))
	      (val  (cadr row)))
	  (hash-table-set! result var val))))
     (sql db "SELECT var,val FROM envvars AS a WHERE context=? AND val != (SELECT val FROM envvars WHERE var=a.var AND context=?)")
     contexta contextb)
    result))

;;
(define (env:blind-merge l1 l2)
  (if (null? l1) l2
      (if (null? l2) l1
	  (cons (car l1) (cons (car l2) (env:blind-merge (cdr l1) (cdr l2)))))))

;; given a before and an after envvar calculate a new merged path
;;
(define (env:merge-path-envvar separator patha pathb)
  (let* ((patha-parts  (string-split patha separator))
	 (pathb-parts  (string-split pathb separator))
	 (common-parts (lset-intersection equal? patha-parts pathb-parts))
	 (final        (delete-duplicates ;; env:blind-merge 
			(append pathb-parts common-parts patha-parts))))
;;     (print "BEFORE:   " (string-intersperse patha-parts  "\n       "))
;;     (print "AFTER:    " (string-intersperse pathb-parts  "\n       "))
;;     (print "COMMON:   " (string-intersperse common-parts "\n       "))
    (string-intersperse final separator)))

(define (env:process-path-envvar varname separator patha pathb)
  (let ((newpath (env:merge-path-envvar separator patha pathb)))
    (setenv varname newpath)))

(define (env:have-context db context)
  (> (query fetch-value (sql db "SELECT count(id) FROM envvars WHERE context=?") context)
     0))

;; this is so the calling block does not need to import sql-de-lite
(define (env:close-database db)
  (close-database db))

(define (env:lazy-hash-table->alist indat)
  (if (hash-table? indat)
      (let ((dat (hash-table->alist indat)))
	(if (null? dat)
	    #f 
	    dat))
      #f))

(define (env:inc-path path)
  (print "PATH "
	 (conc "#{scheme (env:min-path \"" path "\" \"#{getenv PATH}\")}")))
;; 	 (conc
;; 	  "#{scheme (string-intersperse "
;; 	  "(delete-duplicates "
;; 	  "(append (string-split \"" path "\" \":\") "
;; 	  "(string-split \"#{getenv PATH}\" \":\")))"
;; 	  " \":\")}")))

(define (env:min-path path1 path2)
  (string-intersperse
   (delete-duplicates
    (append
     (string-split path1 ":")
     (string-split path2 ":")))
   ":"))

;; inc path will set a PATH that is incrementally modified when read - config mode only
;;
(define (env:print added removed changed #!key (inc-path #t))
  (let ((a  (env:lazy-hash-table->alist added))
	(r  (env:lazy-hash-table->alist removed))
	(c  (env:lazy-hash-table->alist changed)))
    (case (if (args:get-arg "-dumpmode")
	      (string->symbol (args:get-arg "-dumpmode"))
	      'bash)
      ((bash)
       (if a
	   (begin
	     (print "# Added vars")
	     (map (lambda (dat)(print "export " (car dat) "=" (cdr dat)))
		  (hash-table->alist added))))
       (if r
	   (begin
	     (print "# Removed vars")
	     (map (lambda (dat)(print "unset " (car dat)))
		  (hash-table->alist removed))))
       (if c
	   (begin
	     (print "# Changed vars")
	     (map (lambda (dat)(print "export " (car dat) "=" (cdr dat)))
		  (hash-table->alist changed)))))
      ((csh)
       (if a
	   (begin
	     (print "# Added vars")
	     (map (lambda (dat)(print "setenv " (car dat) " " (cdr dat)))
		  (hash-table->alist added))))
       (if r
	   (begin
	     (print "# Removed vars")
	     (map (lambda (dat)(print "unsetenv " (car dat)))
		  (hash-table->alist removed))))
       (if c
	   (begin
	     (print "# Changed vars")
	     (map (lambda (dat)(print "setenv " (car dat) " " (cdr dat)))
		  (hash-table->alist changed)))))
      ((config ini)
       (if a
	   (begin
	     (print "# Added vars")
	     (map (lambda (dat)
		    (let ((var (car dat))
			  (val (cdr dat)))
		      (if (and inc-path
			       (equal? var "PATH"))
			  (env:inc-path val)
			  (print var " " val))))
		  (hash-table->alist added))))
       (if r
	   (begin
	     (print "# Removed vars")
	     (map (lambda (dat)(print "#{scheme (unsetenv \"" (car dat) "\")}"))
		  (hash-table->alist removed))))
       (if c
	   (begin
	     (print "# Changed vars")
	     (map (lambda (dat)
		    (let ((var (car dat))
			  (val (cdr dat)))
		      (if (and inc-path
			       (equal? var "PATH"))
			  (env:inc-path val)
			  (print var " " val))))
		  (hash-table->alist changed)))))
      (else
       (debug:print-error 0 *default-log-port* "No dumpmode specified, use -dumpmode [bash|csh|config]")))))

Modified ezsteps.scm from [34aa5d7cf5] to [7217a3d835].

39
40
41
42
43
44
45
46

47
48
49

50
51
52
53
54
55
56
39
40
41
42
43
44
45

46
47
48

49
50
51
52
53
54
55
56







-
+


-
+







	 (test-name     (dbr:test-testname testdat))
	 (kill-job      #f)) ;; for future use (on re-factoring with launch.scm code
    (let loop ((count 5))
      (if (file-exists? test-run-dir)
	  (push-directory test-run-dir)
	  (if (> count 0)
	      (begin
		(debug:print 0 "WARNING: ezsteps attempting to run but test run directory " test-run-dir " is not there. Waiting and trying again " count " more times")
		(debug:print 0 *default-log-port* "WARNING: ezsteps attempting to run but test run directory " test-run-dir " is not there. Waiting and trying again " count " more times")
		(sleep 3)
		(loop (- count 1))))))
    (debug:print-info 0 "Running in directory " test-run-dir)
    (debug:print-info 0 *default-log-port* "Running in directory " test-run-dir)
    (if (not (file-exists? ".ezsteps"))(create-directory ".ezsteps"))
    ;; if ezsteps was defined then we are sure to have at least one step but check anyway
    (if (not (> (length ezstepslst) 0))
	(message-window "ERROR: You can only re-run steps defined via ezsteps")
	(begin
	  (let loop ((ezstep   (car ezstepslst))
		     (tal      (cdr ezstepslst))
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92







-
+







-
+







		  (if (and start-step-name
			   (not runflag))
		      (if (equal? stepname start-step-name)
			  (set! runflag #t) ;; and continue
			  (if (not (null? tal))
			      (loop (car tal)(cdr tal) stepname #f))))

		  (debug:print 4 "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts
		  (debug:print 4 *default-log-port* "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts
			       " stepparms: " stepparms " stepcmd: " stepcmd)
		  
		  (if (file-exists? (conc stepname ".logpro"))(set! logpro-used #t))
		  
		  ;; call the command using mt_ezstep
		  (set! script (conc "mt_ezstep " stepname " " (if prevstep prevstep "-") " " stepcmd))
		  
		  (debug:print 4 "script: " script)
		  (debug:print 4 *default-log-port* "script: " script)
		  (rmt:teststep-set-status! run-id test-id stepname "start" "-" #f #f)
		  ;; now launch
		  (let ((pid (process-run script)))
		    (let processloop ((i 0))
		      (let-values (((pid-val exit-status exit-code)(process-wait pid #t)))
				  (mutex-lock! run-mutex)
				  (vector-set! exit-info 0 pid)
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
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







-
+



















-
+







					      ((eq? rollup-status 0) 'pass)
					      (else 'fail)))
			   (next-status      (cond 
					      ((eq? overall-status 'pass) this-step-status)
					      ((eq? overall-status 'warn)
					       (if (eq? this-step-status 'fail) 'fail 'warn))
					      (else 'fail))))
		      (debug:print 4 "Exit value received: " (vector-ref exit-info 2) " logpro-used: " logpro-used 
		      (debug:print 4 *default-log-port* "Exit value received: " (vector-ref exit-info 2) " logpro-used: " logpro-used 
				   " this-step-status: " this-step-status " overall-status: " overall-status 
				   " next-status: " next-status " rollup-status: " rollup-status)
		      (case next-status
			((warn)
			 (set! rollup-status 2)
			 ;; NB// test-set-status! does rdb calls under the hood
			 (tests:test-set-status! test-id "RUNNING" "WARN" 
						 (if (eq? this-step-status 'warn) "Logpro warning found" #f)
						 #f))
			((pass)
			 (tests:test-set-status! test-id "RUNNING" "PASS" #f #f))
			(else ;; 'fail
			 (set! rollup-status 1) ;; force fail
			 (tests:test-set-status! test-id "RUNNING" "FAIL" (conc "Failed at step " stepname) #f)
			 ))))
		  (if (and (steprun-good? logpro-used (vector-ref exit-info 2))
			   (not (null? tal)))
		      (if (not run-one) ;; if we got here we completed the step, if run-one is true, stop
			  (loop (car tal) (cdr tal) stepname runflag))))
		(debug:print 4 "WARNING: a prior step failed, stopping at " ezstep)))
		(debug:print 4 *default-log-port* "WARNING: a prior step failed, stopping at " ezstep)))
	  
	  ;; Once done with step/steps update the test record
	  ;;
	  (let* ((item-path (dbr:test-item-path testdat)) ;; (item-list->path itemdat))
		 (testinfo  (rmt:get-testinfo-by-id run-id test-id))) ;; refresh the testdat, call it iteminfo in case need prev/curr
	    ;; Am I completed?
	    (if (equal? (dbr:test-state testinfo) "RUNNING") ;; (not (equal? (dbr:test-state testinfo) "COMPLETED"))
155
156
157
158
159
160
161
162


163
164
165
166
167
168
169
170
171
172
173
174
175
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176







-
+
+













				    ;; if the current status is AUTO the defer to the calculated value (i.e. leave this AUTO)
				    (if (equal? (dbr:test-status testinfo) "AUTO") "AUTO" "PASS"))
				   ((eq? rollup-status 1) "FAIL")
				   ((eq? rollup-status 2)
				    ;; if the current status is AUTO the defer to the calculated value but qualify (i.e. make this AUTO-WARN)
				    (if (equal? (dbr:test-status testinfo) "AUTO") "AUTO-WARN" "WARN"))
				   (else "FAIL")))) ;; (dbr:test-status testinfo)))
		  (debug:print-info 2 "Test NOT logged as COMPLETED, (state=" (dbr:test-state testinfo) "), updating result, rollup-status is " rollup-status)
		  ;; (debug:print-info 2 "Test NOT logged as COMPLETED, (state=" (dbr:test-state testinfo) "), updating result, rollup-status is " rollup-status)
		  (debug:print-info 2 *default-log-port* "Test NOT logged as COMPLETED, (state=" (db:test-state testinfo) "), updating result, rollup-status is " rollup-status)
		  (tests:test-set-status! test-id 
					  new-state
					  new-status
					  (args:get-arg "-m") #f)
		  ;; need to update the top test record if PASS or FAIL and this is a subtest
		  (if (not (equal? item-path ""))
		      (cdb:roll-up-pass-fail-counts *runremote* run-id test-name item-path new-status))))
	    ;; for automated creation of the rollup html file this is a good place...
	    (if (not (equal? item-path ""))
		(tests:summarize-items #f run-id test-id test-name #f)) ;; don't force - just update if no
	    )))
    (pop-directory)
    rollup-status))

Modified fs-transport.scm from [d187681c70] to [59920959a9].

35
36
37
38
39
40
41
42

43
44
35
36
37
38
39
40
41

42
43
44







-
+


;; There is no "server" per se but a convience routine to make it non
;; necessary to be reopening the db over and over again.
;;

(define (fs:process-queue-item packet)
  (if (not *megatest-db*) ;; we will require that (setup-for-run) has already been called
      (set! *megatest-db* (open-db)))
  (debug:print-info 11 "fs:process-queue-item called with packet=" packet)
  (debug:print-info 11 *default-log-port* "fs:process-queue-item called with packet=" packet)
  (db:process-queue-item *megatest-db* packet))
      

Added fsl-rebase.scm version [d4dd53982d].






































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
;; given branch and baseline commit generate list of commands to cherry pick commits
;;
;;
;; Usage: fsl-rebase basecommit branch
;;         

(use regex posix)

(let* ((basecommit (cadr (argv)))
       (branch     (caddr (argv)))
       (cmd        (conc "fossil timeline after " basecommit " -n 1000000 -W 0"))
       (theregex   (conc ;; "^[^\\]]+"
			 "\\[([a-z0-9]+)\\]\\s+"
			 "(.*)"
			 "\\s+\\(.*tags:\\s+" branch 
			 ;; ".*\\)"
			 )))
  (print "basecommit: " basecommit ", branch: " branch ", theregex: " theregex ", cmd: \"" cmd "\"")
  (with-input-from-pipe
   cmd
   (lambda ()
     (let loop ((inl (read-line))
		(res '()))
       (if (not (eof-object? inl))
	   (let ((have-match (string-search theregex inl)))
	     (if have-match
		 (loop (read-line)
		       (cons (conc "fossil merge --cherrypick " (cadr have-match)
				   "\nfossil commit -m \"Cherry pick from " (cadr have-match)
				   ": " (caddr have-match) "\"")
			     res))
		 (loop (read-line) res)))
	   (map print res))))))

;; (print "match: " inl "\n   $1: " (cadr have-match) " $2: " (caddr have-match))
;; (print "no match: " theregex " " inl))
;; (loop (read-line))))))))

Added gen-data-for-graph.scm version [6dacda5542].
























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
(use foof-loop sql-de-lite posix)

(define beginning-2016 1451636435.0)
(define now (current-seconds))
(define one-year-ago (- now (* 365 24 60 60)))

(define db (open-database "example.db"))

(exec (sql db "CREATE TABLE IF NOT EXISTS alldat (event_time,var,val)"))
 
;; sin(time)
(with-transaction
 db
 (lambda ()
   (loop ((for m (up-from (/ one-year-ago 60) (to (/ now 60))))) ;; days of the year
	 (let ((thetime (* m 60))
	       (thehour (round (/ m 60))))
	   (let loop ((lastsec -1)
		      (sec     (random 60))
		      (count   0))
	     (if (> sec lastsec)
		 (exec (sql db "INSERT INTO alldat (event_time,var,val) VALUES (?,?,?)")
		       (+ thetime sec) ;; (* sec 60))
		       "stuff" 
		       (if (even? thehour)
			   (random 1000)
			   (random 6))))
	     (if (< count 20)
		 (loop (max sec lastsec)(random 60)(+ count 1))))))))

(close-database db)


;; (with-transaction
;;  db
;;  (lambda ()
;;    (loop ((for d (up-from 0 (to 365)))) ;; days of the year
;; 	 (print "Day: " d)
;; 	 (loop ((for h (up-from 1 (to 24))))
;; 	     (loop ((for m (up-from 1 (to 60))))
;; 		   (let ((thetime (+ beginning-2016 (* 365 24 60 60)(* h 60 60)(* m 60))))
;; 		     (let loop ((lastsec -1)
;; 				(sec     (random 60))
;; 				(count   0))
;; 		       (if (> sec lastsec)
;; 			   (exec (sql db "INSERT INTO alldat (event_time,var,val) VALUES (?,?,?)")
;; 				 (+ thetime sec) ;; (* sec 60))
;; 				 "stuff" 
;; 				 (if (even? h)
;; 				     (random 100)
;; 				     (random 6))))
;; 		       (if (< count 20)
;; 			   (loop (max sec lastsec)(random 60)(+ count 1))))))))))
;; 
;; (close-database db)

Modified http-transport.scm from [d387fec12a] to [13883e3b0d].

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
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







-
+










-
+








;; Call this to start the actual server
;;

(define *db:process-queue-mutex* (make-mutex))

(define (http-transport:run hostn run-id server-id)
  (debug:print 2 "Attempting to start the server ...")
  (debug:print 2 *default-log-port* "Attempting to start the server ...")
  (let* ((db              #f) ;;        (open-db)) ;; we don't want the server to be opening and closing the db unnecesarily
	 (hostname        (get-host-name))
	 (ipaddrstr       (let ((ipstr (if (string=? "-" hostn)
					   ;; (string-intersperse (map number->string (u8vector->list (hostname->ip hostname))) ".")
					   (server:get-best-guess-address hostname)
					   #f)))
			    (if ipstr ipstr hostn))) ;; hostname))) 
	 (start-port      (portlogger:open-run-close portlogger:find-port))
	 (link-tree-path  (configf:lookup *configdat* "setup" "linktree")))
    ;; (set! db *inmemdb*)
    (debug:print-info 0 "portlogger recommended port: " start-port)
    (debug:print-info 0 *default-log-port* "portlogger recommended port: " start-port)
    (root-path     (if link-tree-path 
		       link-tree-path
		       (current-directory))) ;; WARNING: SECURITY HOLE. FIX ASAP!
    (handle-directory spiffy-directory-listing)
    (handle-exception (lambda (exn chain)
			(signal (make-composite-condition
				 (make-property-condition 
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
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







+
+
+


















-
+






-
-
-
+
+
+

-
+
















-
+










-
+







				   (mutex-lock! *heartbeat-mutex*)
				   (set! *last-db-access* (current-seconds))
				   (mutex-unlock! *heartbeat-mutex*))
				  ((equal? (uri-path (request-uri (current-request))) 
					   '(/ ""))
				   (send-response body: (http-transport:main-page)))
				  ((equal? (uri-path (request-uri (current-request))) 
					   '(/ "json_api"))
				   (send-response body: (http-transport:main-page)))
				  ((equal? (uri-path (request-uri (current-request))) 
					   '(/ "runs"))
				   (send-response body: (http-transport:main-page)))
				  ((equal? (uri-path (request-uri (current-request))) 
					   '(/ any))
				   (send-response body: "hey there!\n"
						  headers: '((content-type text/plain))))
				  ((equal? (uri-path (request-uri (current-request))) 
					   '(/ "hey"))
				   (send-response body: "hey there!\n"
						  headers: '((content-type text/plain))))
				  (else (continue))))))))
    (http-transport:try-start-server run-id ipaddrstr start-port server-id)))

;; This is recursively run by http-transport:run until sucessful
;;
(define (http-transport:try-start-server run-id ipaddrstr portnum server-id)
  (let ((config-hostname (configf:lookup *configdat* "server" "hostname"))
	(tdbdat          (tasks:open-db)))
    (debug:print-info 0 "http-transport:try-start-server run-id=" run-id " ipaddrsstr=" ipaddrstr " portnum=" portnum " server-id=" server-id " config-hostname=" config-hostname)
    (debug:print-info 0 *default-log-port* "http-transport:try-start-server run-id=" run-id " ipaddrsstr=" ipaddrstr " portnum=" portnum " server-id=" server-id " config-hostname=" config-hostname)
    (handle-exceptions
     exn
     (begin
       (print-error-message exn)
       (if (< portnum 64000)
	   (begin 
	     (debug:print 0 "WARNING: attempt to start server failed. Trying again ...")
	     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 "exn=" (condition->list exn))
	     (debug:print 0 *default-log-port* "WARNING: attempt to start server failed. Trying again ...")
	     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 *default-log-port* "exn=" (condition->list exn))
	     (portlogger:open-run-close portlogger:set-failed portnum)
	     (debug:print 0 "WARNING: failed to start on portnum: " portnum ", trying next port")
	     (debug:print 0 *default-log-port* "WARNING: failed to start on portnum: " portnum ", trying next port")
	     (thread-sleep! 0.1)

	     ;; get_next_port goes here
	     (http-transport:try-start-server run-id
					      ipaddrstr
					      (portlogger:open-run-close portlogger:find-port)
					      server-id))
	   (begin
	     (tasks:server-force-clean-run-record (db:delay-if-busy tdbdat) run-id ipaddrstr portnum " http-transport:try-start-server")
	     (print "ERROR: Tried and tried but could not start the server"))))
     ;; any error in following steps will result in a retry
     (set! *server-info* (list ipaddrstr portnum))
     (tasks:server-set-interface-port 
		     (db:delay-if-busy tdbdat)
		     server-id 
		     ipaddrstr portnum)
     (debug:print 0 "INFO: Trying to start server on " ipaddrstr ":" portnum)
     (debug:print 0 *default-log-port* "INFO: Trying to start server on " ipaddrstr ":" portnum)
     ;; This starts the spiffy server
     ;; NEED WAY TO SET IP TO #f TO BIND ALL
     ;; (start-server bind-address: ipaddrstr port: portnum)
     (if config-hostname ;; this is a hint to bind directly
	 (start-server port: portnum bind-address: (if (equal? config-hostname "-")
						       ipaddrstr
						       config-hostname))
	 (start-server port: portnum))
     ;;  (portlogger:open-run-close portlogger:set-port portnum "released")
     (tasks:server-force-clean-run-record (db:delay-if-busy tdbdat) run-id ipaddrstr portnum " http-transport:try-start-server")
     (debug:print 1 "INFO: server has been stopped"))))
     (debug:print 1 *default-log-port* "INFO: server has been stopped"))))

;;======================================================================
;; S E R V E R   U T I L I T I E S 
;;======================================================================

;;======================================================================
;; C L I E N T S
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
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







-
+

















-
+














-
+













-
+

-
+






-
+



















-
-
+
+








(define (http-transport:inc-requests-count)
  (mutex-lock! *http-mutex*)
  (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*))
  ;; Use this opportunity to slow things down iff there are too many requests in flight
  (if (> *http-requests-in-progress* 5)
      (begin
	(debug:print-info 0 "Whoa there buddy, ease up...")
	(debug:print-info 0 *default-log-port* "Whoa there buddy, ease up...")
	(thread-sleep! 1)))
  (mutex-unlock! *http-mutex*))

(define (http-transport:dec-requests-count proc) 
  (mutex-lock! *http-mutex*)
  (proc)
  (set! *http-requests-in-progress* (- *http-requests-in-progress* 1))
  (mutex-unlock! *http-mutex*))

(define (http-transport:dec-requests-count-and-close-all-connections)
  (set! *http-requests-in-progress* (- *http-requests-in-progress* 1))
  (let loop ((etime (+ (current-seconds) 5))) ;; give up in five seconds
    (if (> *http-requests-in-progress* 0)
	(if (> etime (current-seconds))
	    (begin
	      (thread-sleep! 0.05)
	      (loop etime))
	    (debug:print 0 "ERROR: requests still in progress after 5 seconds of waiting. I'm going to pass on cleaning up http connections"))
	    (debug:print-error 0 *default-log-port* "requests still in progress after 5 seconds of waiting. I'm going to pass on cleaning up http connections"))
	(close-all-connections!)))
  (set! *http-connections-next-cleanup* (+ (current-seconds) 10))
  (mutex-unlock! *http-mutex*))

(define (http-transport:inc-requests-and-prep-to-close-all-connections)
  (mutex-lock! *http-mutex*)
  (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*)))

;; Send "cmd" with json payload "params" to serverdat and receive result
;;
(define (http-transport:client-api-send-receive run-id serverdat cmd params #!key (numretries 3))
  (let* ((fullurl    (if (vector? serverdat)
			 (http-transport:server-dat-get-api-req serverdat)
			 (begin
			   (debug:print 0 "FATAL ERROR: http-transport:client-api-send-receive called with no server info")
			   (debug:print 0 *default-log-port* "FATAL ERROR: http-transport:client-api-send-receive called with no server info")
			   (exit 1))))
	 (res        #f)
	 (success    #t)
	 (sparams    (db:obj->string params transport: 'http)))
;;    (condition-case
;;     handle-exceptions
;;     exn
;;     (if (> numretries 0)
;;	 (begin
;;	   (mutex-unlock! *http-mutex*)
;;	   (thread-sleep! 1)
;;	   (handle-exceptions
;;	    exn
;;	    (debug:print 0 "WARNING: closing connections failed. Server at " fullurl " almost certainly dead")
;;	    (debug:print 0 *default-log-port* "WARNING: closing connections failed. Server at " fullurl " almost certainly dead")
;;	    (close-all-connections!))
;;	   (debug:print 0 "WARNING: Failed to communicate with server, trying again, numretries left: " numretries)
;;	   (debug:print 0 *default-log-port* "WARNING: Failed to communicate with server, trying again, numretries left: " numretries)
;;	   (http-transport:client-api-send-receive run-id serverdat cmd sparams numretries: (- numretries 1)))
;;	 (begin
;;	   (mutex-unlock! *http-mutex*)
;;	   (tasks:kill-server-run-id run-id)
;;	   #f))
;;     (begin
       (debug:print-info 11 "fullurl=" fullurl ", cmd=" cmd ", params=" params ", run-id=" run-id "\n")
       (debug:print-info 11 *default-log-port* "fullurl=" fullurl ", cmd=" cmd ", params=" params ", run-id=" run-id "\n")
       ;; set up the http-client here
       (max-retry-attempts 1)
       ;; consider all requests indempotent
       (retry-request? (lambda (request)
			 #f))
       ;; send the data and get the response
       ;; extract the needed info from the http data and 
       ;; process and return it.
       (let* ((send-recieve (lambda ()
			      (mutex-lock! *http-mutex*)
			      ;; (condition-case (with-input-from-request "http://localhost"; #f read-lines)
			      ;;					       ((exn http client-error) e (print e)))
			      (set! res (vector
					 success
					 (db:string->obj 
					  (handle-exceptions
					   exn
					   (begin
					     (set! success #f)
					     (debug:print 0 "WARNING: failure in with-input-from-request to " fullurl ".")
					     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
					     (debug:print 0 *default-log-port* "WARNING: failure in with-input-from-request to " fullurl ".")
					     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
					     (hash-table-delete! *runremote* run-id)
					     ;; Killing associated server to allow clean retry.")
					     ;; (tasks:kill-server-run-id run-id)  ;; better to kill the server in the logic that called this routine?
					     (mutex-unlock! *http-mutex*)
					     ;;; (signal (make-composite-condition
					     ;;;          (make-property-condition 'commfail 'message "failed to connect to server")))
					     ;;; "communications failed"
284
285
286
287
288
289
290
291

292
293
294
295
296
297


298
299

300
301
302
303
304
305
306
287
288
289
290
291
292
293

294
295
296
297
298


299
300
301

302
303
304
305
306
307
308
309







-
+




-
-
+
+

-
+







			      #f))
	      (th1 (make-thread send-recieve "with-input-from-request"))
	      (th2 (make-thread time-out     "time out")))
	 (thread-start! th1)
	 (thread-start! th2)
	 (thread-join! th1)
	 (thread-terminate! th2)
	 (debug:print-info 11 "got res=" res)
	 (debug:print-info 11 *default-log-port* "got res=" res)
	 (if (vector? res)
	     (if (vector-ref res 0)
		 res
		 (begin ;; note: this code also called in nmsg-transport - consider consolidating it
		   (debug:print 0 "ERROR: error occured at server, info=" (vector-ref res 2))
		   (debug:print 0 " client call chain:")
		   (debug:print-error 0 *default-log-port* "error occured at server, info=" (vector-ref res 2))
		   (debug:print 0 *default-log-port* " client call chain:")
		   (print-call-chain (current-error-port))
		   (debug:print 0 " server call chain:")
		   (debug:print 0 *default-log-port* " server call chain:")
		   (pp (vector-ref res 1) (current-error-port))
		   (signal (vector-ref result 0))))
	     (signal (make-composite-condition
		      (make-property-condition 
		       'timeout
		       'message "nmsg-transport:client-api-send-receive-raw timed out talking to server")))))))

334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
350
351
352
353
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
380
381

382
383
384
385
386
387
388
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351
352
353
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

380
381
382
383

384
385
386
387
388
389
390
391







-
+


















-
+







-
+








-
+



-
+







      #f))

(define (http-transport:server-dat-update-last-access vec)
  (if (vector? vec)
      (vector-set! vec 5 (current-seconds))
      (begin
	(print-call-chain (current-error-port))
	(debug:print 0 "ERROR: call to http-transport:server-dat-update-last-access with non-vector!!"))))
	(debug:print-error 0 *default-log-port* "call to http-transport:server-dat-update-last-access with non-vector!!"))))

;;
;; connect
;;
(define (http-transport:client-connect iface port)
  (let* ((api-url      (conc "http://" iface ":" port "/api"))
	 (api-uri      (uri-reference (conc "http://" iface ":" port "/api")))
	 (api-req      (make-request method: 'POST uri: api-uri))
	 (server-dat   (vector iface port api-uri api-url api-req (current-seconds))))
    server-dat))

;; run http-transport:keep-running in a parallel thread to monitor that the db is being 
;; used and to shutdown after sometime if it is not.
;;
(define (http-transport:keep-running server-id run-id)
  ;; if none running or if > 20 seconds since 
  ;; server last used then start shutdown
  ;; This thread waits for the server to come alive
  (debug:print-info 0 "Starting the sync-back, keep alive thread in server for run-id=" run-id)
  (debug:print-info 0 *default-log-port* "Starting the sync-back, keep alive thread in server for run-id=" run-id)
  (let* ((tdbdat      (tasks:open-db))
	 (server-start-time (current-seconds))
	 (server-info (let loop ((start-time (current-seconds))
				 (changed    #t)
				 (last-sdat  "not this"))
                        (let ((sdat #f))
			  (thread-sleep! 0.01)
			  (debug:print-info 0 "Waiting for server alive signature")
			  (debug:print-info 0 *default-log-port* "Waiting for server alive signature")
                          (mutex-lock! *heartbeat-mutex*)
                          (set! sdat *server-info*)
                          (mutex-unlock! *heartbeat-mutex*)
                          (if (and sdat
				   (not changed)
				   (> (- (current-seconds) start-time) 2))
			      sdat
                              (begin
				(debug:print-info 0 "Still waiting, last-sdat=" last-sdat)
				(debug:print-info 0 *default-log-port* "Still waiting, last-sdat=" last-sdat)
                                (sleep 4)
				(if (> (- (current-seconds) start-time) 120) ;; been waiting for two minutes
				    (begin
				      (debug:print 0 "ERROR: transport appears to have died, exiting server " server-id " for run " run-id)
				      (debug:print-error 0 *default-log-port* "transport appears to have died, exiting server " server-id " for run " run-id)
				      (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id "failed to start, never received server alive signature")
				      (exit))
				    (loop start-time
					  (equal? sdat last-sdat)
					  sdat)))))))
         (iface       (car server-info))
         (port        (cadr server-info))
403
404
405
406
407
408
409
410

411
412
413
414
415

416
417
418
419
420
421
422
406
407
408
409
410
411
412

413
414
415
416
417

418
419
420
421
422
423
424
425







-
+




-
+







	     ((sync-failed)(cond
			    ((> bad-sync-count 10) ;; time to give up
			     (http-transport:server-shutdown server-id port))
			    (else ;; (> bad-sync-count 0)  ;; we've had a fail or two, delay and loop
			     (thread-sleep! 5)
			     (loop count server-state (+ bad-sync-count 1)))))
	     ((exn)
	      (debug:print 0 "ERROR: error from sync code other than 'sync-failed. Attempting to gracefully shutdown the server")
	      (debug:print-error 0 *default-log-port* "error from sync code other than 'sync-failed. Attempting to gracefully shutdown the server")
	      (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id " http-transport:keep-running crashed")
	      (exit)))
	    (set! sync-time  (- (current-milliseconds) start-time))
	    (set! rem-time (quotient (- 4000 sync-time) 1000))
	    (debug:print 4 "SYNC: time= " sync-time ", rem-time=" rem-time)
	    (debug:print 4 *default-log-port* "SYNC: time= " sync-time ", rem-time=" rem-time)
	    
	    (if (and (<= rem-time 4)
		     (> rem-time 0))
		(thread-sleep! rem-time)
		(thread-sleep! 4))) ;; fallback for if the math is changed ...

	  ;;
444
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477

478
479
480
481
482
483
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498
499
500
501
502



503
504
505
506
507
508
509


510
511
512
513
514
515

516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
543
544
545
546
547

548
549
550
551

552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
462

463
464
465
466
467
468
469
470
471
472
473

474
475
476
477
478
479

480
481
482
483
484
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500
501
502



503
504
505
506
507
508
509
510


511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553

554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569







-
+








-
+










-
+





-
+












-
+









-
-
-
+
+
+





-
-
+
+





-
+



















-
+











-
+



-
+







-
+







      (mutex-lock! *heartbeat-mutex*)
      (set! sdat *server-info*)
      (mutex-unlock! *heartbeat-mutex*)
      
      (if (or (not (equal? sdat (list iface port)))
	      (not server-id))
	  (begin 
	    (debug:print-info 0 "interface changed, refreshing iface and port info")
	    (debug:print-info 0 *default-log-port* "interface changed, refreshing iface and port info")
	    (set! iface (car sdat))
	    (set! port  (cadr sdat))))
      
      ;; Transfer *last-db-access* to last-access to use in checking that we are still alive
      (mutex-lock! *heartbeat-mutex*)
      (set! last-access *last-db-access*)
      (mutex-unlock! *heartbeat-mutex*)

      ;; (debug:print 11 "last-access=" last-access ", server-timeout=" server-timeout)
      ;; (debug:print 11 *default-log-port* "last-access=" last-access ", server-timeout=" server-timeout)
      ;;
      ;; no_traffic, no running tests, if server 0, no running servers
      ;;
      ;; (let ((wait-on-running (configf:lookup *configdat* "server" b"wait-on-running"))) ;; wait on running tasks (if not true then exit on time out)
      ;;
      (let* ((hrs-since-start  (/ (- (current-seconds) server-start-time) 3600))
	     (adjusted-timeout (if (> hrs-since-start 1)
				   (- server-timeout (inexact->exact (round (* hrs-since-start 60))))  ;; subtract 60 seconds per hour
				   server-timeout)))
	(if (common:low-noise-print 120 "server timeout")
	    (debug:print-info 0 "Adjusted server timeout: " adjusted-timeout))
	    (debug:print-info 0 *default-log-port* "Adjusted server timeout: " adjusted-timeout))
	(if (and *server-run*
		 (> (+ last-access server-timeout)
		    (current-seconds)))
	    (begin
	      (if (common:low-noise-print 120 "server continuing")
		  (debug:print-info 0 "Server continuing, seconds since last db access: " (- (current-seconds) last-access)))
		  (debug:print-info 0 *default-log-port* "Server continuing, seconds since last db access: " (- (current-seconds) last-access)))
	      ;;
	      ;; Consider implementing some smarts here to re-insert the record or kill self is
	      ;; the db indicates so
	      ;;
	      ;; (if (tasks:server-am-i-the-server? tdb run-id)
	      ;;     (tasks:server-set-state! tdb server-id "running"))
	      ;;
	      (loop 0 server-state bad-sync-count))
	    (http-transport:server-shutdown server-id port))))))
  
(define (http-transport:server-shutdown server-id port)
  (let ((tdbdat (tasks:open-db)))
    (debug:print-info 0 "Starting to shutdown the server.")
    (debug:print-info 0 *default-log-port* "Starting to shutdown the server.")
    ;; need to delete only *my* server entry (future use)
    (set! *time-to-exit* #t)
    (if *inmemdb* (db:sync-touched *inmemdb* *run-id* force-sync: #t))
    ;;
    ;; start_shutdown
    ;;
    (tasks:server-set-state! (db:delay-if-busy tdbdat) server-id "shutting-down")
    (portlogger:open-run-close portlogger:set-port port "released")
    (thread-sleep! 5)
    (debug:print-info 0 "Max cached queries was    " *max-cache-size*)
    (debug:print-info 0 "Number of cached writes   " *number-of-writes*)
    (debug:print-info 0 "Average cached write time "
    (debug:print-info 0 *default-log-port* "Max cached queries was    " *max-cache-size*)
    (debug:print-info 0 *default-log-port* "Number of cached writes   " *number-of-writes*)
    (debug:print-info 0 *default-log-port* "Average cached write time "
		      (if (eq? *number-of-writes* 0)
			  "n/a (no writes)"
			  (/ *writes-total-delay*
			     *number-of-writes*))
		      " ms")
    (debug:print-info 0 "Number non-cached queries "  *number-non-write-queries*)
    (debug:print-info 0 "Average non-cached time   "
    (debug:print-info 0 *default-log-port* "Number non-cached queries "  *number-non-write-queries*)
    (debug:print-info 0 *default-log-port* "Average non-cached time   "
		      (if (eq? *number-non-write-queries* 0)
			  "n/a (no queries)"
			  (/ *total-non-write-delay* 
			     *number-non-write-queries*))
		      " ms")
    (debug:print-info 0 "Server shutdown complete. Exiting")
    (debug:print-info 0 *default-log-port* "Server shutdown complete. Exiting")
    (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id " http-transport:keep-running complete")
    (exit)))

;; all routes though here end in exit ...
;;
;; start_server? 
;;
(define (http-transport:launch run-id)
  (let* ((tdbdat (tasks:open-db)))
    (set! *run-id*   run-id)
    (if (args:get-arg "-daemonize")
	(begin
	  (daemon:ize)
	  (if *alt-log-file* ;; we should re-connect to this port, I think daemon:ize disrupts it
	      (begin
		(current-error-port *alt-log-file*)
		(current-output-port *alt-log-file*)))))
    (if (server:check-if-running run-id)
	(begin
	  (debug:print 0 "INFO: Server for run-id " run-id " already running")
	  (debug:print 0 *default-log-port* "INFO: Server for run-id " run-id " already running")
	  (exit 0)))
    (let loop ((server-id (tasks:server-lock-slot (db:delay-if-busy tdbdat) run-id))
	       (remtries  4))
      (if (not server-id)
	  (if (> remtries 0)
	      (begin
		(thread-sleep! 2)
		(loop (tasks:server-lock-slot (db:delay-if-busy tdbdat) run-id)
		      (- remtries 1)))
	      (begin
		;; since we didn't get the server lock we are going to clean up and bail out
		(debug:print-info 2 "INFO: server pid=" (current-process-id) ", hostname=" (get-host-name) " not starting due to other candidates ahead in start queue")
		(debug:print-info 2 *default-log-port* "INFO: server pid=" (current-process-id) ", hostname=" (get-host-name) " not starting due to other candidates ahead in start queue")
		(tasks:server-delete-records-for-this-pid (db:delay-if-busy tdbdat) " http-transport:launch")
		))
	  (let* ((th2 (make-thread (lambda ()
				     (debug:print-info 0 "Server run thread started")
				     (debug:print-info 0 *default-log-port* "Server run thread started")
				     (http-transport:run 
				      (if (args:get-arg "-server")
					  (args:get-arg "-server")
					  "-")
				      run-id
				      server-id)) "Server run"))
		 (th3 (make-thread (lambda ()
				     (debug:print-info 0 "Server monitor thread started")
				     (debug:print-info 0 *default-log-port* "Server monitor thread started")
				     (http-transport:keep-running server-id run-id))
				   "Keep running")))
	    (thread-start! th2)
	    (thread-sleep! 0.25) ;; give the server time to settle before starting the keep-running monitor.
	    (thread-start! th3)
	    (set! *didsomething* #t)
	    (thread-join! th2)
578
579
580
581
582
583
584
585

586
587
588
589
590

591
592

593
594
595
596
597
598
599
581
582
583
584
585
586
587

588
589
590
591
592

593
594

595
596
597
598
599
600
601
602







-
+




-
+

-
+







	  (print "LOGIN_FAILED")
	  (exit 1)))))

(define (http-transport:server-signal-handler signum)
  (signal-mask! signum)
  (handle-exceptions
   exn
   (debug:print " ... exiting ...")
   (debug:print 0 *default-log-port* " ... exiting ...")
   (let ((th1 (make-thread (lambda ()
			     (thread-sleep! 1))
			   "eat response"))
	 (th2 (make-thread (lambda ()
			     (debug:print 0 "ERROR: Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
			     (debug:print-error 0 *default-log-port* "Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
			     (thread-sleep! 3) ;; give the flush three seconds to do it's stuff
			     (debug:print 0 "       Done.")
			     (debug:print 0 *default-log-port* "       Done.")
			     (exit 4))
			   "exit on ^C timer")))
     (thread-start! th2)
     (thread-start! th1)
     (thread-join! th2))))

;;======================================================================

Added inteldate.scm version [a6b831c59f].





















































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
(use srfi-19)
(use test)
(use format)
(use regex)
(declare (unit inteldate))
;; utility procedures to convert among
;; different ways to express date (inteldate, seconds since epoch, isodate)
;;
;; samples:
;; isodate   -> "2016-01-01"
;; inteldate -> "16ww01.5"
;; seconds   -> 1451631600

;; procedures provided:
;; ====================
;; seconds->isodate
;; seconds->inteldate
;;
;; isodate->seconds
;; isodate->inteldate
;;
;; inteldate->seconds
;; inteldate->isodate

;; srfi-19 used extensively; this doc is better tha the eggref:
;; http://srfi.schemers.org/srfi-19/srfi-19.html

;; Author: brandon.j.barclay@intel.com 16ww18.6

(define (date->seconds date)
  (inexact->exact
   (string->number
    (date->string date "~s"))))

(define (seconds->isodate seconds)
  (let* ((date (seconds->date seconds))
         (result (date->string date "~Y-~m-~d")))
    result))

(define (isodate->seconds isodate)
  "Takes a string input of the form 'YY-MM-DD' or 'YYYY-MM-DD' and returns epoch time; for YY, assume after Y2K"
  (let* ((numlist (map string->number (string-split isodate "-")))
        (raw-year (car numlist))
        (year (if (< raw-year 100) (+ raw-year 2000) raw-year))
        (month (list-ref numlist 1))
        (day (list-ref numlist 2))
        (date (make-date 0 0 0 0 day month year))
        (seconds (date->seconds date)))

    seconds))

;; adapted from perl Intel::WorkWeek perl module
;; intel year consists of numbered weeks starting from week 1
;;   week 1 is the week containing jan 1 of the year
;;   days of week are numbered starting from 0 on sunday
;;   intel year does not match calendar year in workweek 1
;;     before jan1.
(define (seconds->inteldate-values seconds)
  (define (date-difference->seconds d1 d2)
    (- (date->seconds d1) (date->seconds d2)))

  (let* ((thisdate (seconds->date seconds))
         (thisdow (string->number (date->string thisdate "~w")))

         (year (date-year thisdate))
         ;; intel workweek 1 begins on sunday of week containing jan1
         (jan1 (make-date 0 0 0 0 1 1 year))
         (jan1dow (date-week-day jan1))
         (ww01 (date-subtract-duration jan1 (seconds->time (* 60 60 24 jan1dow))))

         (ww01_delta_seconds (date-difference->seconds thisdate ww01))
         (wwnum_initial (inexact->exact (add1 (floor (/ ww01_delta_seconds 24 3600 7) ))))
         
         ;; we could be in ww1 of next year
         (this-saturday (seconds->date
                         (+ seconds
                            (* 60 60 24 (- 6 thisdow)))))
         (this-week-ends-next-year?
          (> (date-year this-saturday) year))
         (intelyear
          (if this-week-ends-next-year?
              (add1 year)
              year))
         (intelweek
          (if this-week-ends-next-year?
              1
              wwnum_initial)))
   (values intelyear intelweek thisdow)))

(define (seconds->inteldate seconds)
  (define (string-leftpad in width pad-char)
    (let* ((unpadded-str (->string in))
           (padlen_temp (- width (string-length unpadded-str)))
           (padlen (if (< padlen_temp 0) 0 padlen_temp))
           (padding
            (fold conc ""
                  (map (lambda (x) (->string pad-char)) (iota padlen)))))
      (conc padding unpadded-str)))
  (define (zeropad num width)
    (string-leftpad num width #:0))

  (let-values (((intelyear intelweek day-of-week-num)
                (seconds->inteldate-values seconds)))
    (let ((intelyear-str
           (zeropad
            (->string
             (if (> intelyear 1999)
                 (- intelyear 2000) intelyear))
            2))
          (intelweek-str
           (zeropad (->string intelweek) 2))
          (dow-str (->string day-of-week-num)))
      (conc intelyear-str "ww" intelweek-str "." dow-str))))

(define (isodate->inteldate isodate)
  (seconds->inteldate
   (isodate->seconds isodate)))

(define (inteldate->seconds inteldate)
  (let ((match (string-match "^(\\d+)ww(\\d+).(\\d)$" inteldate)))
    (if
     (not match)
     #f
     (let* (
            (intelyear-raw (string->number (list-ref match 1)))
            (intelyear (if (< intelyear-raw 100)
                           (+ intelyear-raw 2000)
                           intelyear-raw))
            (intelww (string->number (list-ref match 2)))
            (dayofweek (string->number (list-ref match 3)))

            (day-of-seconds (* 60 60 24 ))
            (week-of-seconds (* day-of-seconds 7))
            

            ;; get seconds at ww1.0
            (new-years-date (make-date 0 0 0 0 1 1 intelyear))
            (new-years-seconds
             (date->seconds new-years-date))
            (new-years-dayofweek (date-week-day new-years-date))
            (ww1.0_seconds (- new-years-seconds
                              (* day-of-seconds
                                 new-years-dayofweek)))
            (workweek-adjustment (* week-of-seconds (sub1 intelww)))
            (weekday-adjustment (* dayofweek day-of-seconds))

            (result (+ ww1.0_seconds workweek-adjustment weekday-adjustment)))
       result))))

(define (inteldate->isodate inteldate)
  (seconds->isodate (inteldate->seconds inteldate)))

(define (inteldate-tests)
  (test-group
   "date conversion tests"
   (let ((test-table
          '(("16ww01.5" . "2016-01-01")
            ("16ww18.5" . "2016-04-29")
            ("1999ww33.5" . "1999-08-13")
            ("16ww18.4" . "2016-04-28")
            ("16ww18.3" . "2016-04-27")
            ("13ww01.0" . "2012-12-30")
            ("13ww52.6" . "2013-12-28")
            ("16ww53.3" . "2016-12-28"))))
     (for-each
      (lambda (test-pair)
        (let ((inteldate (car test-pair))
              (isodate (cdr test-pair)))
          (test
           (conc "(isodate->inteldate "isodate ") => "inteldate)
           inteldate
           (isodate->inteldate isodate))
          
          (test
           (conc "(inteldate->isodate "inteldate ")   => "isodate)
           isodate
           (inteldate->isodate inteldate))))
      test-table))))

;(inteldate-tests)

Modified items.scm from [c5fa10b153] to [0624dd0189].

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
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







-
+


-
+







-
+



-
+







;;       (("ANIMAL" "Lion")     ("SEASON" "Spring"))
;;       (("ANIMAL" "Lion")     ("SEASON" "Fall")))
(define (item-assoc->item-list itemsdat)
  (if (and itemsdat (not (null? itemsdat)))
      (let ((itemlst (filter (lambda (x)
			       (list? x))
			     (map (lambda (x)
				    (debug:print 6 "item-assoc->item-list x: " x)
				    (debug:print 6 *default-log-port* "item-assoc->item-list x: " x)
				    (if (< (length x) 2)
					(begin
					  (debug:print 0 "ERROR: malformed items spec " (string-intersperse x " "))
					  (debug:print-error 0 *default-log-port* "malformed items spec " (string-intersperse x " "))
					  (list (car x)'()))
					(let* ((name (car x))
					       (items (cadr x))
					       (ilist (list name (if (string? items)
								     (string-split items)
								     '()))))
					  (if (null? ilist)
					      (debug:print 0 "ERROR: No items specified for " name))
					      (debug:print-error 0 *default-log-port* "No items specified for " name))
					  ilist)))
				  itemsdat))))
	(let ((debuglevel 5))
	  (debug:print 5 "item-assoc->item-list: itemsdat => itemlst ")
	  (debug:print 5 *default-log-port* "item-assoc->item-list: itemsdat => itemlst ")
	  (if (debug:debug-mode 5)
	      (begin
		(pp itemsdat)
		(print " => ")
		(pp itemlst))))
	(if (> (length itemlst) 0)
	    (process-itemlist #f '() itemlst)
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105







-
+







      (for-each (lambda (row)
		  (let ((rowname (car row))
			(rowdat  (cadr row)))
		    (set! item (append item 
				       (list 
					(if (< indx (length rowdat))
					    (let ((new (list rowname (list-ref rowdat indx))))
					      ;; (debug:print 0 "New: " new)
					      ;; (debug:print 0 *default-log-port* "New: " new)
					      (set! elflag #t)
					      new
					      ) ;; i.e. had at least on legit value to use
					    (list rowname "-")))))))
		newlst)
      (if elflag
	  (begin
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
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







-
+


-
+




-
+


-
-
+
+









	item)))

(define (items:get-items-from-config tconfig)
  (let* ((have-items  (hash-table-ref/default tconfig "items"      #f))
	 (have-itable (hash-table-ref/default tconfig "itemstable" #f))
	 (items       (hash-table-ref/default tconfig "items"      '()))
	 (itemstable  (hash-table-ref/default tconfig "itemstable" '())))
    (debug:print 5 "items: " items " itemstable: " itemstable)
    (debug:print 5 *default-log-port* "items: " items " itemstable: " itemstable)
    (set! items (map (lambda (item)
		       (if (procedure? (cadr item))
			   (list (car item)((cadr item)))
			   (list (car item)((cadr item)))  ;; evaluate the proc
			   item))
		     items))
    (set! itemstable (map (lambda (item)
			    (if (procedure? (cadr item))
				(list (car item)((cadr item)))
				(list (car item)((cadr item)))  ;; evaluate the proc
				item))
			  itemstable))
    (if (and have-items  (null? items))     (debug:print 0 "ERROR: [items] section in testconfig but no entries defined"))
    (if (and have-itable (null? itemstable))(debug:print 0 "ERROR: [itemstable] section in testconfig but no entries defined"))
    (if (and have-items  (null? items))     (debug:print-error 0 *default-log-port* "[items] section in testconfig but no entries defined"))
    (if (and have-itable (null? itemstable))(debug:print-error 0 *default-log-port* "[itemstable] section in testconfig but no entries defined"))
    (if (or (not (null? items))(not (null? itemstable)))
	(append (item-assoc->item-list items)
		(item-table->item-list itemstable))
	'(()))))

;; (pp (item-assoc->item-list itemdat))


	

Modified keys.scm from [b0a1fb8bc8] to [d7ceb127bd].

41
42
43
44
45
46
47
48

49
50

51
52
53
54
55
56
57
41
42
43
44
45
46
47

48
49

50
51
52
53
54
55
56
57







-
+

-
+







      (let ((vals (string-split target "/")))
	(if (eq? (length vals)(length keys))
	    (for-each (lambda (key val)
			(setenv key val)
			(if ht (hash-table-set! ht (conc ":" key) val)))
		      keys
		      vals)
	    (debug:print 0 "ERROR: wrong number of values in " target ", should match " keys))
	    (debug:print-error 0 *default-log-port* "wrong number of values in " target ", should match " keys))
	vals)
      (debug:print 4 "ERROR: keys:target-set-args called with no target.")))
      (debug:print 4 *default-log-port* "ERROR: keys:target-set-args called with no target.")))

;; given the keys (a list of vectors <key field> or a list of keys) and a target return a keyval list
;; keyval list ( (key1 val1) (key2 val2) ...)
(define (keys:target->keyval keys target)
  (let* ((targlist (string-split target "/"))
	 (numkeys  (length keys))
	 (numtarg  (length targlist))

Modified launch.scm from [644354e9c7] to [fee5119e46].

9
10
11
12
13
14
15
16
17


18
19
20
21
22
23
24
9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24







-
-
+
+







;;  PURPOSE.

;;======================================================================
;; launch a task - this runs on the originating host, tests themselves
;;
;;======================================================================

(use regex regex-case base64 sqlite3 srfi-18 directory-utils posix-extras z3 call-with-environment-variables)
(use defstruct)
(use regex regex-case base64 sqlite3 srfi-18 directory-utils posix-extras z3 call-with-environment-variables csv)
(use defstruct pathname-expand)

(import (prefix base64 base64:))
(import (prefix sqlite3 sqlite3:))

(declare (unit launch))
(declare (uses common))
(declare (uses configf))
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
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
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397







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










+














-
+











-
+




















-
+















-
+


-
-
-
-
+
+
+
+
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+
+















-
+
-
-
+















+
+
+
+
+
+

-
+




+
+
+
+
+
+








+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  (let ((enccmd (if encoded-cmd encoded-cmd (getenv "MT_CMDINFO"))))
    (if enccmd
	(common:read-encoded-string enccmd)
	'())))

;;                       0           1              2              3
(defstruct launch:einf (pid #t)(exit-status #t)(exit-code #t)(rollup-status 0))

;; return (conc status ": " comment) from the final section so that
;;   the comment can be set in the step record in launch.scm
;;
(define (launch:load-logpro-dat run-id test-id stepname)
  (let ((cname (conc stepname ".dat")))
    (if (file-exists? cname)
	(let* ((dat  (read-config cname #f #f))
	       (csvr (db:logpro-dat->csv dat stepname))
	       (csvt (let-values (( (fmt-cell fmt-record fmt-csv) (make-format ",")))
				 (fmt-csv (map list->csv-record csvr))))
	       (status (configf:lookup dat "final" "exit-status"))
	       (msg     (configf:lookup dat "final" "message")))
	  (rmt:csv->test-data run-id test-id csvt)
	  (cond
	   ((equal? status "PASS") "PASS") ;; skip the message part if status is pass
	   (status (conc (configf:lookup dat "final" "exit-status") ": " (if msg msg "no message")))
	   (else #f)))
	#f)))

(define (launch:runstep ezstep run-id test-id exit-info m tal testconfig)
  (let* ((stepname       (car ezstep))  ;; do stuff to run the step
	 (stepinfo       (cadr ezstep))
	 (stepparts      (string-match (regexp "^(\\{([^\\}]*)\\}\\s*|)(.*)$") stepinfo))
	 (stepparms      (list-ref stepparts 2)) ;; for future use, {VAR=1,2,3}, run step for each 
	 (stepcmd        (list-ref stepparts 3))
	 (script         "") ; "#!/bin/bash\n") ;; yep, we depend on bin/bash FIXME!!!\
	 (logpro-file    (conc stepname ".logpro"))
	 (html-file      (conc stepname ".html"))
	 (dat-file       (conc stepname ".dat"))
	 (tconfig-logpro (configf:lookup testconfig "logpro" stepname))
	 (logpro-used    (file-exists? logpro-file)))

    (if (and tconfig-logpro
	     (not logpro-used)) ;; no logpro file found but have a defn in the testconfig
	(begin
	  (with-output-to-file logpro-file
	    (lambda ()
	      (print ";; logpro file extracted from testconfig\n"
		     ";;")
	      (print tconfig-logpro)))
	  (set! logpro-used #t)))
    
    ;; NB// can safely assume we are in test-area directory
    (debug:print 4 "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts
    (debug:print 4 *default-log-port* "ezsteps:\n stepname: " stepname " stepinfo: " stepinfo " stepparts: " stepparts
		 " stepparms: " stepparms " stepcmd: " stepcmd)
    
    ;; ;; first source the previous environment
    ;; (let ((prev-env (conc ".ezsteps/" prevstep (if (string-search (regexp "csh") 
    ;;      							 (get-environment-variable "SHELL")) ".csh" ".sh"))))
    ;;   (if (and prevstep (file-exists? prev-env))
    ;;       (set! script (conc script "source " prev-env))))
    
    ;; call the command using mt_ezstep
    ;; (set! script (conc "mt_ezstep " stepname " " (if prevstep prevstep "x") " " stepcmd))
    
    (debug:print 4 "script: " script)
    (debug:print 4 *default-log-port* "script: " script)
    (rmt:teststep-set-status! run-id test-id stepname "start" "-" #f #f)
    ;; now launch the actual process
    (call-with-environment-variables 
     (list (cons "PATH" (conc (get-environment-variable "PATH") ":.")))
     (lambda () ;; (process-run "/bin/bash" "-c" "exec ls -l /tmp/foobar > /tmp/delme-more.log 2>&1")
       (let* ((cmd (conc stepcmd " > " stepname ".log 2>&1")) ;; >outfile 2>&1 
	      (pid (process-run "/bin/bash" (list "-c" cmd))))
	 (rmt:test-set-top-process-pid run-id test-id pid)
	 (let processloop ((i 0))
	   (let-values (((pid-val exit-status exit-code)(process-wait pid #t)))
		       (mutex-lock! m)
		       (launch:einf-pid-set!         exit-info pid)         ;; (vector-set! exit-info 0 pid)
		       (launch:einf-exit-status-set! exit-info exit-status) ;; (vector-set! exit-info 1 exit-status)
		       (launch:einf-exit-code-set!   exit-info exit-code)   ;; (vector-set! exit-info 2 exit-code)
		       (mutex-unlock! m)
		       (if (eq? pid-val 0)
			   (begin
			     (thread-sleep! 2)
			     (processloop (+ i 1))))
		       )))))
    (debug:print-info 0 "step " stepname " completed with exit code " (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
    (debug:print-info 0 *default-log-port* "step " stepname " completed with exit code " (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
    ;; now run logpro if needed
    (if logpro-used
	(let ((pid (process-run (conc "logpro " logpro-file " " (conc stepname ".html") " < " stepname ".log"))))
	  (let processloop ((i 0))
	    (let-values (((pid-val exit-status exit-code)(process-wait pid #t)))
			(mutex-lock! m)
			;; (make-launch:einf pid: pid exit-status: exit-status exit-code: exit-code)
			(launch:einf-pid-set!         exit-info pid)         ;; (vector-set! exit-info 0 pid)
			(launch:einf-exit-status-set! exit-info exit-status) ;; (vector-set! exit-info 1 exit-status)
			(launch:einf-exit-code-set!   exit-info exit-code)   ;; (vector-set! exit-info 2 exit-code)
			(mutex-unlock! m)
			(if (eq? pid-val 0)
			    (begin
			      (thread-sleep! 2)
			      (processloop (+ i 1)))))
	    (debug:print-info 0 "logpro for step " stepname " exited with code " (launch:einf-exit-code exit-info))))) ;; (vector-ref exit-info 2)))))
	    (debug:print-info 0 *default-log-port* "logpro for step " stepname " exited with code " (launch:einf-exit-code exit-info))))) ;; (vector-ref exit-info 2)))))
    
    (let ((exinfo (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
	  (logfna (if logpro-used (conc stepname ".html") "")))
      (rmt:teststep-set-status! run-id test-id stepname "end" exinfo #f logfna))
    (if logpro-used
	(rmt:test-set-log! run-id test-id (conc stepname ".html")))
	  (logfna (if logpro-used (conc stepname ".html") ""))
	  (comment #f))
      (if logpro-used
	  (let ((datfile (conc stepname ".dat")))
	    ;; load the .dat file into the test_data table if it exists
	    (if (file-exists? datfile)
		(set! comment (launch:load-logpro-dat run-id test-id stepname)))
	    (rmt:test-set-log! run-id test-id (conc stepname ".html"))))
      (rmt:teststep-set-status! run-id test-id stepname "end" exinfo comment logfna))
    ;; set the test final status
    (let* ((process-exit-status (launch:einf-exit-code exit-info)) ;; (vector-ref exit-info 2))
	   (this-step-status (cond
			      ((and (eq? process-exit-status 2) logpro-used) 'warn)  ;; logpro 2 = warnings
			      ((and (eq? process-exit-status 3) logpro-used) 'check) ;; logpro 3 = check
			      ((and (eq? process-exit-status 4) logpro-used) 'waived) ;; logpro 4 = abort			      
			      ((and (eq? process-exit-status 5) logpro-used) 'abort) ;; logpro 4 = abort
			      ((eq? process-exit-status 0)                   'pass)  ;; logpro 0 = pass
			      ((and (eq? process-exit-status 2) logpro-used) 'warn)   ;; logpro 2 = warnings
			      ((and (eq? process-exit-status 3) logpro-used) 'check)  ;; logpro 3 = check
			      ((and (eq? process-exit-status 4) logpro-used) 'waived) ;; logpro 4 = waived
			      ((and (eq? process-exit-status 5) logpro-used) 'abort)  ;; logpro 5 = abort
			      ((and (eq? process-exit-status 6) logpro-used) 'skip)   ;; logpro 6 = skip
			      ((eq? process-exit-status 0)                   'pass)   ;; logpro 0 = pass
			      (else 'fail)))
	   (overall-status   (cond
			      ((eq? (launch:einf-rollup-status exit-info) 2) 'warn) ;; rollup-status (vector-ref exit-info 3)
			      ((eq? (launch:einf-rollup-status exit-info) 0) 'pass) ;; (vector-ref exit-info 3)
			      (else 'fail)))
	   (next-status      (cond 
			      ((eq? overall-status 'pass) this-step-status)
			      ((eq? overall-status 'warn)
			       (if (eq? this-step-status 'fail) 'fail 'warn))
			      ((eq? overall-status 'abort) 'abort)
			      (else 'fail)))
	   (next-state       ;; "RUNNING") ;; WHY WAS THIS CHANGED TO NOT USE (null? tal) ??
	    (cond
	     ((null? tal) ;; more to run?
	      "COMPLETED")
	     (else "RUNNING")))
	     (else "RUNNING"))))
	   )
      (debug:print 4 "Exit value received: " (launch:einf-exit-code exit-info) " logpro-used: " logpro-used 
      (debug:print 4 *default-log-port* "Exit value received: " (launch:einf-exit-code exit-info) " logpro-used: " logpro-used 
		   " this-step-status: " this-step-status " overall-status: " overall-status 
		   " next-status: " next-status " rollup-status: "  (launch:einf-rollup-status exit-info)) ;; (vector-ref exit-info 3))
      (case next-status
	((warn)
	 (launch:einf-rollup-status-set! exit-info 2) ;; (vector-set! exit-info 3 2) ;; rollup-status
	 ;; NB// test-set-status! does rdb calls under the hood
	 (tests:test-set-status! run-id test-id next-state "WARN" 
				 (if (eq? this-step-status 'warn) "Logpro warning found" #f)
				 #f))
	((check)
	 (launch:einf-rollup-status-set! exit-info 3) ;; (vector-set! exit-info 3 3) ;; rollup-status
	 ;; NB// test-set-status! does rdb calls under the hood
	 (tests:test-set-status! run-id test-id next-state "CHECK" 
				 (if (eq? this-step-status 'check) "Logpro check found" #f)
				 #f))
	((waived)
	 (launch:einf-rollup-status-set! exit-info 4) ;; (vector-set! exit-info 3 3) ;; rollup-status
	 ;; NB// test-set-status! does rdb calls under the hood
	 (tests:test-set-status! run-id test-id next-state "WAIVED" 
				 (if (eq? this-step-status 'check) "Logpro waived found" #f)
				 #f))
	((abort)
	 (launch:einf-rollup-status-set! exit-info 4) ;; (vector-set! exit-info 3 4) ;; rollup-status
	 (launch:einf-rollup-status-set! exit-info 5) ;; (vector-set! exit-info 3 4) ;; rollup-status
	 ;; NB// test-set-status! does rdb calls under the hood
	 (tests:test-set-status! run-id test-id next-state "ABORT" 
				 (if (eq? this-step-status 'abort) "Logpro abort found" #f)
				 #f))
	((skip)
	 (launch:einf-rollup-status-set! exit-info 6) ;; (vector-set! exit-info 3 4) ;; rollup-status
	 ;; NB// test-set-status! does rdb calls under the hood
	 (tests:test-set-status! run-id test-id next-state "SKIP" 
				 (if (eq? this-step-status 'skip) "Logpro skip found" #f)
				 #f))
	((pass)
	 (tests:test-set-status! run-id test-id next-state "PASS" #f #f))
	(else ;; 'fail
	 (launch:einf-rollup-status-set! exit-info 1) ;; (vector-set! exit-info 3 1) ;; force fail, this used to be next-state but that doesn't make sense. should always be "COMPLETED" 
	 (tests:test-set-status! run-id test-id "COMPLETED" "FAIL" (conc "Failed at step " stepname) #f)
	 )))
    logpro-used))

(define (launch:manage-steps run-id test-id item-path fullrunscript ezsteps test-name tconfigreg exit-info m)
  ;; (let-values
  ;;  (((pid exit-status exit-code)
  ;;    (run-n-wait fullrunscript)))
  ;; (tests:test-set-status! test-id "RUNNING" "n/a" #f #f)
  ;; Since we should have a clean slate at this time there is no need to do 
  ;; any of the other stuff that tests:test-set-status! does. Let's just 
  ;; force RUNNING/n/a
(define (launch:execute encoded-cmd)
  
   (let* ((cmdinfo    (common:read-encoded-string encoded-cmd))

  ;; (thread-sleep! 0.3)
  (tests:test-force-state-status! run-id test-id "RUNNING" "n/a")
  (rmt:roll-up-pass-fail-counts run-id test-name item-path #f "RUNNING")
  ;; (thread-sleep! 0.3) ;; NFS slowness has caused grief here

  ;; if there is a runscript do it first
  (if fullrunscript
      (let ((pid (process-run fullrunscript)))
	(rmt:test-set-top-process-pid run-id test-id pid)
	(let loop ((i 0))
	  (let-values
	   (((pid-val exit-status exit-code) (process-wait pid #t)))
	   (mutex-lock! m)
	   (launch:einf-pid-set!           exit-info  pid)         ;; (vector-set! exit-info 0 pid)
	   (launch:einf-exit-status-set!   exit-info  exit-status) ;; (vector-set! exit-info 1 exit-status)
	   (launch:einf-exit-code-set!     exit-info  exit-code)   ;; (vector-set! exit-info 2 exit-code)
	   (launch:einf-rollup-status-set! exit-info  exit-code)   ;; (vector-set! exit-info 3 exit-code)  ;; rollup status
	   (mutex-unlock! m)
	   (if (eq? pid-val 0)
	       (begin
		 (thread-sleep! 2)
		 (loop (+ i 1)))
	       )))))
  ;; then, if runscript ran ok (or did not get called)
  ;; do all the ezsteps (if any)
  (if ezsteps
      (let* ((testconfig ;; (read-config (conc work-area "/testconfig") #f #t environ-patt: "pre-launch-env-vars")) ;; FIXME??? is allow-system ok here?
	      ;; NOTE: it is tempting to turn off force-create of testconfig but dynamic
	      ;;       ezstep names need a full re-eval here.
	      (tests:get-testconfig test-name tconfigreg #t force-create: #t)) ;; 'return-procs)))
	     (ezstepslst (if (hash-table? testconfig)
			     (hash-table-ref/default testconfig "ezsteps" '())
			     #f)))
	(if testconfig
	    (hash-table-set! *testconfigs* test-name testconfig) ;; cached for lazy reads later ...
	    (begin
	      (launch:setup)
	      (debug:print 0 *default-log-port* "WARNING: no testconfig found for " test-name " in search path:\n  "
			   (string-intersperse (tests:get-tests-search-path *configdat*) "\n  "))))
	;; after all that, still no testconfig? Time to abort
	(if (not testconfig)
	    (begin
	      (debug:print-error 0 *default-log-port* "Failed to resolve megatest.config, runconfigs.config and testconfig issues. Giving up now")
	      (exit 1)))
	(if (not (file-exists? ".ezsteps"))(create-directory ".ezsteps"))
	;; if ezsteps was defined then we are sure to have at least one step but check anyway
	(if (not (> (length ezstepslst) 0))
	    (debug:print-error 0 *default-log-port* "ezsteps defined but ezstepslst is zero length")
	    (let loop ((ezstep (car ezstepslst))
		       (tal    (cdr ezstepslst))
		       (prevstep #f))
	      ;; check exit-info (vector-ref exit-info 1)
	      (if (launch:einf-exit-status exit-info) ;; (vector-ref exit-info 1)
		  (let ((logpro-used (launch:runstep ezstep run-id test-id exit-info m tal testconfig))
			(stepname    (car ezstep)))
		    ;; if logpro-used read in the stepname.dat file
		    (if (and logpro-used (file-exists? (conc stepname ".dat")))
			(launch:load-logpro-dat run-id test-id stepname))
		    (if (steprun-good? logpro-used (launch:einf-exit-code exit-info))
			(if (not (null? tal))
			    (loop (car tal) (cdr tal) stepname))
			(debug:print 4 *default-log-port* "WARNING: step " (car ezstep) " failed. Stopping")))
		  (debug:print 4 *default-log-port* "WARNING: a prior step failed, stopping at " ezstep)))))))

(define (launch:monitor-job run-id test-id item-path fullrunscript ezsteps test-name tconfigreg exit-info m work-area runtlim misc-flags)
  (let* ((start-seconds (current-seconds))
	 (calc-minutes  (lambda ()
			  (inexact->exact 
			   (round 
			    (- 
			     (current-seconds) 
			     start-seconds)))))
	 (kill-tries 0))
    ;; (tests:set-full-meta-info #f test-id run-id (calc-minutes) work-area)
    ;; (tests:set-full-meta-info test-id run-id (calc-minutes) work-area)
    (tests:set-full-meta-info #f test-id run-id (calc-minutes) work-area 10)
    (let loop ((minutes   (calc-minutes))
	       (cpu-load  (get-cpu-load))
	       (disk-free (get-df (current-directory))))
      (let ((new-cpu-load (let* ((load  (get-cpu-load))
				 (delta (abs (- load cpu-load))))
			    (if (> delta 0.6) ;; don't bother updating with small changes
				load
				#f)))
	    (new-disk-free (let* ((df    (get-df (current-directory)))
				  (delta (abs (- df disk-free))))
			     (if (> delta 200) ;; ignore changes under 200 Meg
				 df
				 #f))))
	(set! kill-job? (or (test-get-kill-request run-id test-id) ;; run-id test-name itemdat))
			    (and runtlim (let* ((run-seconds   (- (current-seconds) start-seconds))
						(time-exceeded (> run-seconds runtlim)))
					   (if time-exceeded
					       (begin
						 (debug:print-info 0 *default-log-port* "KILLING TEST DUE TO TIME LIMIT EXCEEDED! Runtime=" run-seconds " seconds, limit=" runtlim)
						 #t)
					       #f)))))
	(tests:update-central-meta-info run-id test-id new-cpu-load new-disk-free (calc-minutes) #f #f)
	(if kill-job? 
	    (begin
	      (mutex-lock! m)
	      ;; NOTE: The pid can change as different steps are run. Do we need handshaking between this
	      ;;       section and the runit section? Or add a loop that tries three times with a 1/4 second
	      ;;       between tries?
	      (let* ((pid1 (launch:einf-pid exit-info)) ;; (vector-ref exit-info 0))
		     (pid2 (rmt:test-get-top-process-pid run-id test-id))
		     (pids (delete-duplicates (filter number? (list pid1 pid2)))))
		(if (not (null? pids))
		    (begin
		      (for-each
		       (lambda (pid)
			 (handle-exceptions
			  exn
			  (begin
			    (debug:print-info 0 *default-log-port* "Unable to kill process with pid " pid ", possibly already killed.")
			    (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn)))
			  (debug:print 0 *default-log-port* "WARNING: Request received to kill job " pid) ;;  " (attempt # " kill-tries ")")
			  (debug:print-info 0 *default-log-port* "Signal mask=" (signal-mask))
			  ;; (if (process:alive? pid)
			  ;;     (begin
			  (map (lambda (pid-num)
				 (process-signal pid-num signal/term))
			       (process:get-sub-pids pid))
			  (thread-sleep! 5)
			  ;; (if (process:process-alive? pid)
			  (map (lambda (pid-num)
				 (handle-exceptions
				  exn
				  #f
				  (process-signal pid-num signal/kill)))
			       (process:get-sub-pids pid))))
		       ;;    (debug:print-info 0 *default-log-port* "not killing process " pid " as it is not alive"))))
		       pids)
		      (tests:test-set-status! run-id test-id "KILLED"  "KILLED" (args:get-arg "-m") #f))
		    (begin
		      (debug:print-error 0 *default-log-port* "Nothing to kill, pid1=" pid1 ", pid2=" pid2)
		      (tests:test-set-status! run-id test-id "KILLED"  "FAILED TO KILL" (args:get-arg "-m") #f)
		      )))
	      (mutex-unlock! m)
	      ;; no point in sticking around. Exit now.
	      (exit)))
	(if (hash-table-ref/default misc-flags 'keep-going #f)
	    (begin
	      (thread-sleep! 3) ;; (+ 3 (random 6))) ;; add some jitter to the call home time to spread out the db accesses
	      (if (hash-table-ref/default misc-flags 'keep-going #f)  ;; keep originals for cpu-load and disk-free unless they change more than the allowed delta
		  (loop (calc-minutes) (or new-cpu-load cpu-load) (or new-disk-free disk-free)))))))
    (tests:update-central-meta-info run-id test-id (get-cpu-load) (get-df (current-directory))(calc-minutes) #f #f))) ;; NOTE: Checking twice for keep-going is intentional

(define (launch:execute encoded-cmd)
     (let* ((cmdinfo    (common:read-encoded-string encoded-cmd))
	  (tconfigreg (tests:get-all)))
    (setenv "MT_CMDINFO" encoded-cmd)
    (if (list? cmdinfo) ;; ((testpath /tmp/mrwellan/jazzmind/src/example_run/tests/sqlitespeed)
	;; (test-name sqlitespeed) (runscript runscript.rb) (db-host localhost) (run-id 1))
	(let* ((testpath  (assoc/default 'testpath  cmdinfo))  ;; testpath is the test spec area
	       (top-path  (assoc/default 'toppath   cmdinfo))
	       (work-area (assoc/default 'work-area cmdinfo))  ;; work-area is the test run area
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
295
296
297
298
299
300

301
302
303
304
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338

339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
420
421
422
423
424
425
426

427

428
429
430
431
432
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

459
460


461
462
463

464
465
466
467
468

469
470
471
472
473
474
475
476
477

478
479
480
481

482
483
484
485

486
487

488
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518

519
520
521
522
523
524
525
526
527
528

529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544

545
546
547
548
549
550
551
552







-
+
-







-
+






-
+









-
+






-
+

-
-



-
+
+
+


-
+


+
+
+
+


-
+
+


-
+



-
+

-
+








-
+











-
+









-
+









-
+





-
+









-
+







                                  (if (substring-index "/" runscript)
                                      runscript ;; use unadultered if contains slashes
                                      (let ((fulln (conc testpath "/" runscript)))
	                                  (if (and (file-exists? fulln)
                                                   (file-execute-access? fulln))
                                              fulln
                                              runscript))))) ;; assume it is on the path
	       ;; (rollup-status 0)
	       ) ;; (rollup-status 0)
	       )

	  ;; NFS might not have propagated the directory meta data to the run host - give it time if needed
	  (let loop ((count 0))
	    (if (or (file-exists? top-path)
		    (> count 10))
		(change-directory top-path)
		(begin
		  (debug:print 0 "INFO: Not starting job yet - directory " top-path " not found")
		  (debug:print 0 *default-log-port* "INFO: Not starting job yet - directory " top-path " not found")
		  (thread-sleep! 10)
		  (loop (+ count 1)))))

	  (let ((sighand (lambda (signum)
			   ;; (signal-mask! signum) ;; to mask or not? seems to cause issues in exiting
			   (if (eq? signum signal/stop)
			 (debug:print 0 "ERROR: attempt to STOP process. Exiting."))
			       (debug:print-error 0 *default-log-port* "attempt to STOP process. Exiting."))
			   (set! *time-to-exit* #t)
			   (print "Received signal " signum ", cleaning up before exit. Please wait...")
			   (let ((th1 (make-thread (lambda ()
						     (tests:test-force-state-status! run-id test-id "INCOMPLETE" "KILLED")
						     (print "Killed by signal " signum ". Exiting")
						     (thread-sleep! 1)
						     (exit 1))))
				 (th2 (make-thread (lambda ()
						     (thread-sleep! 2)
						     (debug:print 0 "Done")
						     (debug:print 0 *default-log-port* "Done")
						     (exit 4)))))
			     (thread-start! th2)
			     (thread-start! th1)
			     (thread-join! th2)))))
	    (set-signal-handler! signal/int sighand)
	    (set-signal-handler! signal/term sighand)
	    (set-signal-handler! signal/stop sighand))
	    ) ;; (set-signal-handler! signal/stop sighand)
	  
	  ;; (set-signal-handler! signal/int (lambda ()
					    
	  ;; Do not run the test if it is REMOVING, RUNNING, KILLREQ or REMOTEHOSTSTART,
	  ;; Mark the test as REMOTEHOSTSTART *IMMEDIATELY*
	  ;;
	  (let ((test-info (rmt:get-testinfo-state-status run-id test-id)))
	  (let* ((test-info (rmt:get-test-info-by-id run-id test-id))
		 (test-host (db:test-get-host        test-info))
		 (test-pid  (db:test-get-process_id  test-info)))
	    (cond
	     ((member (dbr:test-state test-info) '("INCOMPLETE" "KILLED" "UNKNOWN" "KILLREQ" "STUCK")) ;; prior run of this test didn't complete, go ahead and try to rerun
	      (debug:print 0 "INFO: test is INCOMPLETE or KILLED, treat this execute call as a rerun request")
	      (debug:print 0 *default-log-port* "INFO: test is INCOMPLETE or KILLED, treat this execute call as a rerun request")
	      (tests:test-force-state-status! run-id test-id "REMOTEHOSTSTART" "n/a")) ;; prime it for running
	     ((not (member (dbr:test-state test-info) '("REMOVING" "REMOTEHOSTSTART" "RUNNING" "KILLREQ")))
	     ;; ((member (db:test-get-state test-info) '("RUNNING" "REMOTEHOSTSTART"))
	      (if (process:alive-on-host? test-host test-pid)
		  (debug:print-error 0 *default-log-port* "test state is "  (db:test-get-state test-info) " and process " test-pid " is still running on host " test-host ", cannot proceed")
		  (tests:test-force-state-status! run-id test-id "REMOTEHOSTSTART" "n/a")))
	      (tests:test-force-state-status! run-id test-id "REMOTEHOSTSTART" "n/a"))
	     (else ;; (member (dbr:test-state test-info) '("REMOVING" "REMOTEHOSTSTART" "RUNNING" "KILLREQ"))
	      (debug:print 0 "ERROR: test state is " (dbr:test-state test-info) ", cannot proceed")
	      ;; (debug:print 0 "ERROR: test state is " (dbr:test-state test-info) ", cannot proceed")
	      (debug:print-error 0 *default-log-port* "test state is " (db:test-state test-info) ", cannot proceed")
	      (exit))))
	  
	  (debug:print 2 "Exectuing " test-name " (id: " test-id ") on " (get-host-name))
	  (debug:print 2 *default-log-port* "Exectuing " test-name " (id: " test-id ") on " (get-host-name))
	  (set! keys       (rmt:get-keys))
	  ;; (runs:set-megatest-env-vars run-id inkeys: keys inkeyvals: keyvals) ;; these may be needed by the launching process
	  ;; one of these is defunct/redundant ...
	  (if (not (launch:setup-for-run force: #t))
	  (if (not (launch:setup force: #t))
	      (begin
		(debug:print 0 "Failed to setup, exiting") 
		(debug:print 0 *default-log-port* "Failed to setup, exiting") 
		;; (sqlite3:finalize! db)
		;; (sqlite3:finalize! tdb)
		(exit 1)))
	  (change-directory *toppath*) 

	  ;; NOTE: Current order is to process runconfigs *before* setting the MT_ vars. This 
	  ;;       seems non-ideal but could well break stuff
	  ;;    BUG? BUG? BUG?

	  
	  (let ((rconfig (full-runconfigs-read))) ;; (read-config (conc  *toppath* "/runconfigs.config") #f #t sections: (list "default" target))))
	    ;; (setup-env-defaults (conc *toppath* "/runconfigs.config") run-id (make-hash-table) keyvals target)
	    ;; (set-run-config-vars run-id keyvals target) ;; (db:get-target db run-id))
	    ;; Now have runconfigs data loaded, set environment vars
	    (for-each (lambda (section)
			(for-each (lambda (varval)
				    (let ((var (car varval))
					  (val (cadr varval)))
				      (if (and (string? var)(string? val))
					  (begin
					    (setenv var (config:eval-string-in-environment val))) ;; val)
					  (debug:print 0 "ERROR: bad variable spec, " var "=" val))))
					  (debug:print-error 0 *default-log-port* "bad variable spec, " var "=" val))))
				  (configf:get-section rconfig section)))
		      (list "default" target)))

	  ;; NFS might not have propagated the directory meta data to the run host - give it time if needed
	  (let loop ((count 0))
	    (if (or (file-exists? work-area)
		    (> count 10))
		(change-directory work-area)
		(begin
		  (debug:print 0 "INFO: Not starting job yet - directory " work-area " not found")
		  (debug:print 0 *default-log-port* "INFO: Not starting job yet - directory " work-area " not found")
		  (thread-sleep! 10)
		  (loop (+ count 1)))))

	  ;; (change-directory work-area) 
	  (set! keyvals    (keys:target->keyval keys target))
	  ;; apply pre-overrides before other variables. The pre-override vars must not
	  ;; clobbers things from the official sources such as megatest.config and runconfigs.config
	  (if (string? set-vars)
	      (let ((varpairs (string-split set-vars ",")))
		(debug:print 4 "varpairs: " varpairs)
		(debug:print 4 *default-log-port* "varpairs: " varpairs)
		(map (lambda (varpair)
		       (let ((varval (string-split varpair "=")))
			 (if (eq? (length varval) 2)
			     (let ((var (car varval))
				   (val (cadr varval)))
			       (debug:print 1 "Adding pre-var/val " var " = " val " to the environment")
			       (debug:print 1 *default-log-port* "Adding pre-var/val " var " = " val " to the environment")
			       (setenv var val)))))
		     varpairs)))
	  (for-each
	   (lambda (varval)
	     (let ((var (car varval))
		   (val (cadr varval)))
	       (if val
		   (setenv var val)
		   (begin
		     (debug:print 0 "ERROR: required variable " var " does not have a valid value. Exiting")
		     (debug:print-error 0 *default-log-port* "required variable " var " does not have a valid value. Exiting")
		     (exit)))))
	     (list 
	      (list  "MT_TEST_RUN_DIR" work-area)
	      (list  "MT_TEST_NAME" test-name)
	      (list  "MT_ITEM_INFO" (conc itemdat))
	      (list  "MT_ITEMPATH"  item-path)
	      (list  "MT_RUNNAME"   runname)
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395

396
397
398
399
400
401
402
403
404
405


406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
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
459
460
461
462
463

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542


543
544
545
546
547
548
549
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586

587
588
589
590
591

592










593
594























595















596




597




598











599







































































600
601
602
603
604
605


606
607
608
609
610
611
612
613
614







-
+












-
+




-
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
+
+







	  (set-item-env-vars itemdat)
	  (save-environment-as-files "megatest")
	  ;; open-run-close not needed for test-set-meta-info
	  ;; (tests:set-full-meta-info #f test-id run-id 0 work-area)
	  ;; (tests:set-full-meta-info test-id run-id 0 work-area)
	  (tests:set-full-meta-info #f test-id run-id 0 work-area 10)

	  (thread-sleep! 0.3) ;; NFS slowness has caused grief here
	  ;; (thread-sleep! 0.3) ;; NFS slowness has caused grief here

	  (if (args:get-arg "-xterm")
	      (set! fullrunscript "xterm")
	      (if (and fullrunscript 
		       (file-exists? fullrunscript)
		       (not (file-execute-access? fullrunscript)))
		  (system (conc "chmod ug+x " fullrunscript))))

	  ;; We are about to actually kick off the test
	  ;; so this is a good place to remove the records for 
	  ;; any previous runs
	  ;; (db:test-remove-steps db run-id testname itemdat)
	  
	  ;; 
	  (let* ((m            (make-mutex))
		 (kill-job?    #f)
		 (exit-info    (make-launch:einf pid: #t exit-status: #t exit-code: #t rollup-status: 0)) ;; pid exit-status exit-code (i.e. process was successfully run) rollup-status
		 (job-thread   #f)
		 (keep-going   #t)
		 ;; (keep-going   #t)
		 (runit        (lambda ()
				 ;; (let-values
				 ;;  (((pid exit-status exit-code)
				 ;;    (run-n-wait fullrunscript)))
				 ;; (tests:test-set-status! test-id "RUNNING" "n/a" #f #f)
				 ;; Since we should have a clean slate at this time there is no need to do 
				 ;; any of the other stuff that tests:test-set-status! does. Let's just 
				 ;; force RUNNING/n/a
				 

		 (misc-flags   (let ((ht (make-hash-table)))
				 (hash-table-set! ht 'keep-going #t)
				 ;; (thread-sleep! 0.3)
				 (tests:test-force-state-status! run-id test-id "RUNNING" "n/a")
				 (rmt:roll-up-pass-fail-counts run-id test-name item-path #f "RUNNING")
				 ;; (thread-sleep! 0.3) ;; NFS slowness has caused grief here

				 ;; if there is a runscript do it first
				 (if fullrunscript
				     (let ((pid (process-run fullrunscript)))
				       (rmt:test-set-top-process-pid run-id test-id pid)
				       (let loop ((i 0))
					 (let-values
					  (((pid-val exit-status exit-code) (process-wait pid #t)))
					  (mutex-lock! m)
					  (launch:einf-pid-set!           exit-info  pid)         ;; (vector-set! exit-info 0 pid)
					  (launch:einf-exit-status-set!   exit-info  exit-status) ;; (vector-set! exit-info 1 exit-status)
					  (launch:einf-exit-code-set!     exit-info  exit-code)   ;; (vector-set! exit-info 2 exit-code)
					  (launch:einf-rollup-status-set! exit-info  exit-code)   ;; (vector-set! exit-info 3 exit-code)  ;; rollup status
					  (mutex-unlock! m)
					  (if (eq? pid-val 0)
					      (begin
						(thread-sleep! 2)
						(loop (+ i 1)))
					      )))))
				 ht))
				 ;; then, if runscript ran ok (or did not get called)
				 ;; do all the ezsteps (if any)
				 (if ezsteps
				     (let* ((testconfig ;; (read-config (conc work-area "/testconfig") #f #t environ-patt: "pre-launch-env-vars")) ;; FIXME??? is allow-system ok here?
					     ;; NOTE: it is tempting to turn off force-create of testconfig but dynamic
					     ;;       ezstep names need a full re-eval here.
					     (tests:get-testconfig test-name tconfigreg #t force-create: #t)) ;; 'return-procs)))
					    (ezstepslst (hash-table-ref/default testconfig "ezsteps" '())))
				       (hash-table-set! *testconfigs* test-name testconfig) ;; cached for lazy reads later ...
				       (if (not (file-exists? ".ezsteps"))(create-directory ".ezsteps"))
				       ;; if ezsteps was defined then we are sure to have at least one step but check anyway
				       (if (not (> (length ezstepslst) 0))
					   (debug:print 0 "ERROR: ezsteps defined but ezstepslst is zero length")
					   (let loop ((ezstep (car ezstepslst))
						      (tal    (cdr ezstepslst))
		 (runit        (lambda ()
						      (prevstep #f))
					     ;; check exit-info (vector-ref exit-info 1)
					     (if (launch:einf-exit-status exit-info) ;; (vector-ref exit-info 1)
						 (let ((logpro-used (launch:runstep ezstep run-id test-id exit-info m tal testconfig)))
				 (launch:manage-steps run-id test-id item-path fullrunscript ezsteps test-name tconfigreg exit-info m)))
						   (if (and (steprun-good? logpro-used (launch:einf-exit-code exit-info))
							    (not (null? tal)))
						       (loop (car tal) (cdr tal) stepname)))
						 (debug:print 4 "WARNING: a prior step failed, stopping at " ezstep))))))))
		 (monitorjob   (lambda ()
				 (let* ((start-seconds (current-seconds))
					(calc-minutes  (lambda ()
							 (inexact->exact 
							  (round 
							   (- 
							    (current-seconds) 
							    start-seconds)))))
					(kill-tries 0))
				   ;; (tests:set-full-meta-info #f test-id run-id (calc-minutes) work-area)
				   ;; (tests:set-full-meta-info test-id run-id (calc-minutes) work-area)
				   (tests:set-full-meta-info #f test-id run-id (calc-minutes) work-area 10)
				 (launch:monitor-job  run-id test-id item-path fullrunscript ezsteps test-name tconfigreg exit-info m work-area runtlim misc-flags)))
				   (let loop ((minutes   (calc-minutes))
					      (cpu-load  (get-cpu-load))
					      (disk-free (get-df (current-directory))))
				     (let ((new-cpu-load (let* ((load  (get-cpu-load))
								(delta (abs (- load cpu-load))))
							   (if (> delta 0.6) ;; don't bother updating with small changes
							       load
							       #f)))
					   (new-disk-free (let* ((df    (get-df (current-directory)))
								 (delta (abs (- df disk-free))))
							    (if (> delta 200) ;; ignore changes under 200 Meg
								df
								#f))))
				       (set! kill-job? (or (test-get-kill-request run-id test-id) ;; run-id test-name itemdat))
							   (and runtlim (let* ((run-seconds   (- (current-seconds) start-seconds))
									       (time-exceeded (> run-seconds runtlim)))
									  (if time-exceeded
									      (begin
										(debug:print-info 0 "KILLING TEST DUE TO TIME LIMIT EXCEEDED! Runtime=" run-seconds " seconds, limit=" runtlim)
										#t)
									      #f)))))
				       (tests:update-central-meta-info run-id test-id new-cpu-load new-disk-free (calc-minutes) #f #f)
				       (if kill-job? 
					   (begin
					     (mutex-lock! m)
					     ;; NOTE: The pid can change as different steps are run. Do we need handshaking between this
					     ;;       section and the runit section? Or add a loop that tries three times with a 1/4 second
					     ;;       between tries?
					     (let* ((pid1 (launch:einf-pid exit-info)) ;; (vector-ref exit-info 0))
						    (pid2 (rmt:test-get-top-process-pid run-id test-id))
						    (pids (delete-duplicates (filter number? (list pid1 pid2)))))
					       (if (not (null? pids))
						   (begin
						     (for-each
						      (lambda (pid)
							(handle-exceptions
							 exn
							 (begin
							   (debug:print-info 0 "Unable to kill process with pid " pid ", possibly already killed.")
							   (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn)))
							 (debug:print 0 "WARNING: Request received to kill job " pid) ;;  " (attempt # " kill-tries ")")
							 (debug:print-info 0 "Signal mask=" (signal-mask))
							 ;; (if (process:alive? pid)
							 ;;     (begin
							 (map (lambda (pid-num)
								(process-signal pid-num signal/term))
							      (process:get-sub-pids pid))
							 (thread-sleep! 5)
							 ;; (if (process:process-alive? pid)
							 (map (lambda (pid-num)
								(handle-exceptions
								 exn
								 #f
								 (process-signal pid-num signal/kill)))
							      (process:get-sub-pids pid))))
							 ;;    (debug:print-info 0 "not killing process " pid " as it is not alive"))))
						      pids)
						     (tests:test-set-status! run-id test-id "KILLED"  "KILLED" (args:get-arg "-m") #f))
						   (begin
						     (debug:print 0 "ERROR: Nothing to kill, pid1=" pid1 ", pid2=" pid2)
						     (tests:test-set-status! run-id test-id "KILLED"  "FAILED TO KILL" (args:get-arg "-m") #f)
						     )))
					     (mutex-unlock! m)
					     ;; no point in sticking around. Exit now.
					     (exit)))
				       (if keep-going
					   (begin
					     (thread-sleep! 3) ;; (+ 3 (random 6))) ;; add some jitter to the call home time to spread out the db accesses
					     (if keep-going    ;; keep originals for cpu-load and disk-free unless they change more than the allowed delta
						 (loop (calc-minutes) (or new-cpu-load cpu-load) (or new-disk-free disk-free)))))))
				   (tests:update-central-meta-info run-id test-id (get-cpu-load) (get-df (current-directory))(calc-minutes) #f #f)))) ;; NOTE: Checking twice for keep-going is intentional
		 (th1          (make-thread monitorjob "monitor job"))
		 (th2          (make-thread runit "run job")))
	    (set! job-thread th2)
	    (thread-start! th1)
	    (thread-start! th2)
	    (thread-join! th2)
	    (debug:print-info 0 "Megatest exectute of test " test-name ", item path " item-path " complete. Notifying the db ...")
	    (set! keep-going #f)
	    (debug:print-info 0 *default-log-port* "Megatest exectute of test " test-name ", item path " item-path " complete. Notifying the db ...")
	    (hash-table-set! misc-flags 'keep-going #f)
	    (thread-join! th1)
	    (thread-sleep! 1)       ;; givbe thread th1 a chance to be done TODO: Verify this is needed. At 0.1 I was getting fail to stop, increased to total of 1.1 sec.
	    (mutex-lock! m)
	    (let* ((item-path (item-list->path itemdat))
		   ;; only state and status needed - use lazy routine
		   (testinfo  (rmt:get-testinfo-state-status run-id test-id)))
	      ;; Am I completed?
557
558
559
560
561
562
563
564
565





566
567
568
569
570
571
572
573
574
575
576
577
578

579
580

581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659


660
661
662
663


664
665
666
667
668

669

670
671
672
673
674
675
676
677
678
679
680



























































































































































681
682
683
684
685
686
687
688
689
690
691
692
693


694
695
696
697
698
699
700
622
623
624
625
626
627
628


629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

646
647

648
649
650
651
652





































































653
654
655
656
657

658
659
660
661
662

663
664
665
666
667


668
669
670
671
672
673
674
675
676





677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842


843
844
845
846
847
848
849
850
851







-
-
+
+
+
+
+












-
+

-
+




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





-
+
+



-
+
+



-
-
+

+






-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-
-
+
+







				     ((eq? (launch:einf-rollup-status exit-info) 0)     ;; (vector-ref exit-info 3)
				      ;; if the current status is AUTO then defer to the calculated value (i.e. leave this AUTO)
				      (if (equal? (dbr:test-status testinfo) "AUTO") "AUTO" "PASS"))
				     ((eq? (launch:einf-rollup-status exit-info) 1) "FAIL")  ;; (vector-ref exit-info 3)
				     ((eq? (launch:einf-rollup-status exit-info) 2)	     ;;	(vector-ref exit-info 3)
				      ;; if the current status is AUTO the defer to the calculated value but qualify (i.e. make this AUTO-WARN)
				      (if (equal? (dbr:test-status testinfo) "AUTO") "AUTO-WARN" "WARN"))
				     (else "FAIL")))) ;; (dbr:test-status testinfo)))
		    (debug:print-info 1 "Test exited in state=" (dbr:test-state testinfo) ", setting state/status based on exit code of " (launch:einf-exit-status exit-info) " and rollup-status of " (launch:einf-rollup-status exit-info))
				     ((eq? (launch:einf-rollup-status exit-info) 3) "CHECK")
				     ((eq? (launch:einf-rollup-status exit-info) 4) "WAIVED")
				     ((eq? (launch:einf-rollup-status exit-info) 5) "ABORT")
				     ((eq? (launch:einf-rollup-status exit-info) 6) "SKIP"))))
		    (debug:print-info 1 *default-log-port* "Test exited in state=" (db:test-state testinfo) ", setting state/status based on exit code of " (launch:einf-exit-status exit-info) " and rollup-status of " (launch:einf-rollup-status exit-info))
		    (tests:test-set-status! run-id 
					    test-id 
					    new-state
					    new-status
					    (args:get-arg "-m") #f)
		    ;; need to update the top test record if PASS or FAIL and this is a subtest
		    ;; NO NEED TO CALL roll-up-pass-fail-counts HERE, THIS IS DONE IN roll-up-pass-fail-counts called by tests:test-set-status!
		    ))
	      ;; for automated creation of the rollup html file this is a good place...
	      (if (not (equal? item-path ""))
		  (tests:summarize-items run-id test-id test-name #f))
	      (tests:summarize-test run-id test-id)  ;; don't force - just update if no
	      )
	      (rmt:update-run-stats run-id (rmt:get-raw-run-stats run-id)))
	    (mutex-unlock! m)
	    (debug:print 2 "Output from running " fullrunscript ", pid " (launch:einf-pid exit-info) " in work area " 
	    (debug:print 2 *default-log-port* "Output from running " fullrunscript ", pid " (launch:einf-pid exit-info) " in work area " 
			 work-area ":\n====\n exit code " (launch:einf-exit-code exit-info) "\n" "====\n")
	    (if (not (launch:einf-exit-status exit-info))
		(exit 4)))))))

;; set up the very basics needed for doing anything here.
(define (launch:setup-for-run #!key (force #f))
  ;; would set values for KEYS in the environment here for better support of env-override but 
  ;; have chicken/egg scenario. need to read megatest.config then read it again. Going to 
  ;; pass on that idea for now
  ;; special case
  (if (or force (not (hash-table? *configdat*)))  ;; no need to re-open on every call
      (begin
	(set! *configinfo* (or (if (get-environment-variable "MT_CMDINFO") ;; we are inside a test - do not reprocess configs
				   (let ((alistconfig (conc (get-environment-variable "MT_LINKTREE") "/"
							    (get-environment-variable "MT_TARGET")   "/"
							    (get-environment-variable "MT_RUNNAME")  "/"
							    ".megatest.cfg-"  megatest-version "-" megatest-fossil-hash)))
				     (if (file-exists? alistconfig)
					 (list (configf:read-alist alistconfig)
					       (get-environment-variable "MT_RUN_AREA_HOME"))
					 #f))
				   #f) ;; no config cached - give up
			       (let ((runname (or (args:get-arg "-runname")(args:get-arg ":runname"))))
				 (if runname (setenv "MT_RUNNAME" runname))
				 (find-and-read-config 
				  (if (args:get-arg "-config")(args:get-arg "-config") "megatest.config")
				  environ-patt: "env-override"
				  given-toppath: (get-environment-variable "MT_RUN_AREA_HOME")
				  pathenvvar: "MT_RUN_AREA_HOME"))))
	(set! *configdat*  (if (car *configinfo*)(car *configinfo*) #f))
	(set! *toppath*    (if (car *configinfo*)(cadr *configinfo*) #f))
	(let* ((tmptransport (configf:lookup *configdat* "server" "transport"))
	       (transport    (if tmptransport (string->symbol tmptransport) 'http)))
	  (if (member transport '(http rpc nmsg))
	      (set! *transport-type* transport)
	      (begin
		(debug:print 0 "ERROR: Unrecognised transport " transport)
		(exit))))
	(let ((linktree (configf:lookup *configdat* "setup" "linktree"))) ;; link tree is critical
	  (if linktree
	      (if (not (file-exists? linktree))
		  (begin
		    (handle-exceptions
		     exn
		     (begin
		       (debug:print 0 "ERROR: Something went wrong when trying to create linktree dir at " linktree)
		       (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
		       (exit 1))
		     (create-directory linktree #t))))
	      (begin
		(debug:print 0 "ERROR: linktree not defined in [setup] section of megatest.config")
		(exit 1)))
	  (if linktree
	      (let ((dbdir (conc linktree "/.db")))
		(handle-exceptions
		 exn
		 (begin
		   (debug:print 0 "ERROR: failed to create the " dbdir " area for your database files")
		   (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn)))
		 (if (not (directory-exists? dbdir))(create-directory dbdir)))
		(setenv "MT_LINKTREE" linktree))
	      (begin
		(debug:print 0 "ERROR: linktree is required in your megatest.config [setup] section")
		(exit 1)))
	  (if (and *toppath*
		   (directory-exists? *toppath*))
	      (setenv "MT_RUN_AREA_HOME" *toppath*)
	      (begin
		(debug:print 0 "ERROR: failed to find the top path to your Megatest area.")
		(exit 1)))
	  )))
  *toppath*)

(define (launch:cache-config)
  ;; if we have a linktree and -runtests and -target and the directory exists dump the config
  ;; to megatest-(current-seconds).cfg and symlink it to megatest.cfg
  (if (and *configdat* 
	   (or (args:get-arg "-run")
	       (args:get-arg "-runtests")))
	       (args:get-arg "-runtests")
	       (args:get-arg "-execute")))
      (let* ((linktree (get-environment-variable "MT_LINKTREE"))
	     (target   (common:args-get-target))
	     (runname  (or (args:get-arg "-runname")
			   (args:get-arg ":runname")))
			   (args:get-arg ":runname")
			   (getenv "MT_RUNNAME")))
	     (fulldir  (conc linktree "/"
			     target "/"
			     runname)))
	(debug:print-info 0 "Have -runtests with target=" target ", runname=" runname ", fulldir=" fulldir ", testpatt=" (or (args:get-arg "-testpatt") "%"))
	(if (file-exists? linktree) ;; can't proceed without linktree
	(if (and linktree (file-exists? linktree)) ;; can't proceed without linktree
	    (begin
	      (debug:print-info 0 *default-log-port* "Have -run with target=" target ", runname=" runname ", fulldir=" fulldir ", testpatt=" (or (args:get-arg "-testpatt") "%"))
	      (if (not (file-exists? fulldir))
		  (create-directory fulldir #t)) ;; need to protect with exception handler 
	      (if (and target
		       runname
		       (file-exists? fulldir))
		  (let ((tmpfile  (conc fulldir "/.megatest.cfg." (current-seconds)))
			(targfile (conc fulldir "/.megatest.cfg-"  megatest-version "-" megatest-fossil-hash)))
		    (debug:print-info 0 "Caching megatest.config in " fulldir "/.megatest.cfg")
		    (configf:write-alist *configdat* tmpfile)
		    (system (conc "ln -sf " tmpfile " " targfile))
		    )))))))
			(targfile (conc fulldir "/.megatest.cfg-"  megatest-version "-" megatest-fossil-hash))
			(rconfig  (conc fulldir "/.runconfig." megatest-version "-" megatest-fossil-hash)))
		    (if (file-exists? rconfig) ;; only cache megatest.config AFTER runconfigs has been cached
			(begin
			  (debug:print-info 0 *default-log-port* "Caching megatest.config in " tmpfile)
			  (configf:write-alist *configdat* tmpfile)
			  (system (conc "ln -sf " tmpfile " " targfile))))
		    )))
	    (debug:print-info 1 *default-log-port* "No linktree yet, no caching configs.")))))


;; gather available information, if legit read configs in this order:
;;
;;   if have cache;
;;      read it a return it
;;   else
;;     megatest.config     (do not cache)
;;     runconfigs.config   (cache if all vars avail)
;;     megatest.config     (cache if all vars avail)
;;   returns:
;;     *toppath*
;;   side effects:
;;     sets; *configdat*    (megatest.config info)
;;           *runconfigdat* (runconfigs.config info)
;;           *configstatus* (status of the read data)
;;
(define (launch:setup-new #!key (force #f))
  (let* ((toppath  (or *toppath* (getenv "MT_RUN_AREA_HOME"))) ;; preserve toppath
	 (runname  (common:args-get-runname))
	 (target   (common:args-get-target))
	 (linktree (common:get-linktree))
	 (sections (if target (list "default" target) #f)) ;; for runconfigs
	 (mtconfig (or (args:get-arg "-config") "megatest.config")) ;; allow overriding megatest.config 
	 (rundir   (if (and runname target linktree)(conc linktree "/" target "/" runname) #f))
	 (mtcachef (and rundir (conc rundir "/" ".megatest.cfg-"  megatest-version "-" megatest-fossil-hash)))
	 (rccachef (and rundir (conc rundir "/" ".runconfigs.cfg-"  megatest-version "-" megatest-fossil-hash)))
	 (cancreate (and rundir (file-exists? rundir)(file-write-access? rundir))))
    ;; (print "runname: " runname " target: " target " mtcachef: " mtcachef " rccachef: " rccachef)
    (set! *toppath* toppath) ;; This is needed when we are running as a test using CMDINFO as a datasource
    (cond
     ;; data was read and cached and available in *configstatus*, toppath has already been set
     ((eq? *configstatus* 'fulldata)
      *toppath*)
     ;; if mtcachef exists just read it, however we need to assume toppath is available in $MT_RUN_AREA_HOME
     ((and mtcachef (file-exists? mtcachef) (get-environment-variable "MT_RUN_AREA_HOME"))
      (set! *configdat*    (configf:read-alist mtcachef))
      (set! *runconfigdat* (configf:read-alist rccachef))
      (set! *configinfo*   (list *configdat*  (get-environment-variable "MT_RUN_AREA_HOME")))
      (set! *configstatus* 'fulldata)
      (set! *toppath*      (get-environment-variable "MT_RUN_AREA_HOME"))
      *toppath*)
     ;; we have all the info needed to fully process runconfigs and megatest.config
     (mtcachef              
      (let* ((first-pass    (find-and-read-config        ;; NB// sets MT_RUN_AREA_HOME as side effect
			             mtconfig
				     environ-patt: "env-override"
				     given-toppath: toppath
				     pathenvvar: "MT_RUN_AREA_HOME"))
	     (first-rundat  (let ((toppath (if toppath 
					       toppath
					       (car first-pass))))
			      (read-config ;; (conc toppath "/runconfigs.config")
			       (conc (if (string? toppath)
					 toppath
					 (get-environment-variable "MT_RUN_AREA_HOME"))
				     "/runconfigs.config")
			       *runconfigdat* #t 
			       sections: sections))))
	(set! *runconfigdat* first-rundat)
	(if first-pass  ;; 
	    (begin
	      (set! *configdat*  (car first-pass))
	      (set! *configinfo* first-pass)
	      (set! *toppath*    (or toppath (cadr first-pass))) ;; use the gathered data unless already have it
	      (set! toppath      *toppath*)
	      (if (not *toppath*)
		  (begin
		    (debug:print-error 0 *default-log-port* "you are not in a megatest area!")
		    (exit 1)))
	      (setenv "MT_RUN_AREA_HOME" *toppath*)
	      ;; the seed read is done, now read runconfigs, cache it then read megatest.config one more time and cache it
	      (let* ((keys         (rmt:get-keys))
		     (key-vals     (keys:target->keyval keys target))
		     (linktree     (or (getenv "MT_LINKTREE")
				       (if *configdat* (configf:lookup *configdat* "setup" "linktree") #f)))
		     (second-pass  (find-and-read-config
				    mtconfig
				    environ-patt: "env-override"
				    given-toppath: toppath
				    pathenvvar: "MT_RUN_AREA_HOME"))
		     (runconfigdat (begin     ;; this read of the runconfigs will see any adjustments made by re-reading megatest.config
				     (for-each (lambda (kt)
						 (setenv (car kt) (cadr kt)))
					       key-vals)
				     (read-config (conc toppath "/runconfigs.config") *runconfigdat* #t 
						  sections: sections))))
		(if cancreate (configf:write-alist runconfigdat rccachef))
		(set! *runconfigdat* runconfigdat)
		(if cancreate (configf:write-alist *configdat* mtcachef))
		(if cancreate (set! *configstatus* 'fulldata))))
	    ;; no configs found? should not happen but let's try to recover gracefully, return an empty hash-table
	    (set! *configdat* (make-hash-table))
	    )))
     ;; else read what you can and set the flag accordingly
     (else
      (let* ((cfgdat   (find-and-read-config 
			(or (args:get-arg "-config") "megatest.config")
			environ-patt: "env-override"
			given-toppath: (get-environment-variable "MT_RUN_AREA_HOME")
			pathenvvar: "MT_RUN_AREA_HOME")))
	(if cfgdat
	    (let* ((toppath  (or (get-environment-variable "MT_RUN_AREA_HOME")(cadr cfgdat)))
		   (rdat     (read-config (conc toppath
						"/runconfigs.config") *runconfigdat* #t sections: sections)))
	      (set! *configinfo*   cfgdat)
	      (set! *configdat*    (car cfgdat))
	      (set! *runconfigdat* rdat)
	      (set! *toppath*      toppath)
	      (set! *configstatus* 'partial))
	    (begin
	      (debug:print-error 0 *default-log-port* "No " mtconfig " file found. Giving up.")
	      (exit 2))))))
    ;; additional house keeping
    (let* ((linktree (or (getenv "MT_LINKTREE")
			 (if *configdat* (configf:lookup *configdat* "setup" "linktree") #f))))
      (if linktree
	  (begin
	    (if (not (file-exists? linktree))
		(begin
		  (handle-exceptions
		   exn
		   (begin
		     (debug:print-error 0 *default-log-port* "Something went wrong when trying to create linktree dir at " linktree)
		     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
		     (exit 1))
		   (create-directory linktree #t))))
	    (handle-exceptions
	     exn
	     (begin
	       (debug:print-error 0 *default-log-port* "Something went wrong when trying to create link to linktree at " *toppath*)
	       (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn)))
	     (let ((tlink (conc *toppath* "/lt")))
	       (if (not (file-exists? tlink))
		   (create-symbolic-link linktree tlink)))))
	  (begin
	    (debug:print-error 0 *default-log-port* "linktree not defined in [setup] section of megatest.config")
	    )))
    (if (and *toppath*
	     (directory-exists? *toppath*))
	(setenv "MT_RUN_AREA_HOME" *toppath*)
	(begin
	  (debug:print-error 0 *default-log-port* "failed to find the top path to your Megatest area.")))
    *toppath*))

(define launch:setup launch:setup-new)

(define (get-best-disk confdat testconfig)
  (let* ((disks   (or (and testconfig (hash-table-ref/default testconfig "disks" #f))
		      (hash-table-ref/default confdat "disks" #f)))
	 (minspace (let ((m (configf:lookup confdat "setup" "minspace")))
		     (string->number (or m "10000")))))
    (if disks 
	(let ((res (common:get-disk-with-most-free-space disks minspace))) ;; min size of 1000, seems tad dumb
	  (if res
	      (cdr res)
	      (begin
		(if (common:low-noise-print 20 "no valid disks")
		    (debug:print 0 "ERROR: No valid disks found in megatest.config. Please add some to your [disks] section and ensure the directory exists!"))
		(if (common:low-noise-print 20 "No valid disks or no disk with enough space")
		    (debug:print-error 0 *default-log-port* "No valid disks found in megatest.config. Please add some to your [disks] section and ensure the directory exists and has enough space!\n    You can change minspace in the [setup] section of megatest.config. Current setting is: " minspace))
		(exit 1)))))))

;; Desired directory structure:
;;
;;  <linkdir> - <target> - <testname> -.
;;                                     |
;;                                     v
737
738
739
740
741
742
743
744

745
746
747

748
749
750
751
752
753
754
755

756
757
758
759
760
761
762
763
764
765
766
767
768
769
770

771
772
773
774

775
776
777
778
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
816
817
818
819

820
821
822
823
824
825
826
827
828
829
830
831


832
833
834
835

836
837
838

839
840
841
842
843
844
845
846

847
848
849
850
851
852
853
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
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







-
+


-
+







-
+














-
+



-
+







-
+








-
+




















-
+
+






-
+










-
-
+
+



-
+


-
+







-
+







	 (lnkpathf  (conc lnkpath (if not-iterated "" "/") item-path))
	 (lnktarget (conc lnkpath "/" item-path)))

    ;; Update the rundir path in the test record for all, rundir=physical, shortdir=logical
    ;;                                                 rundir   shortdir
    (rmt:general-call 'test-set-rundir-shortdir run-id lnkpathf test-path testname item-path)

    (debug:print 2 "INFO:\n       lnkbase=" lnkbase "\n       lnkpath=" lnkpath "\n  toptest-path=" toptest-path "\n     test-path=" test-path)
    (debug:print 2 *default-log-port* "INFO:\n       lnkbase=" lnkbase "\n       lnkpath=" lnkpath "\n  toptest-path=" toptest-path "\n     test-path=" test-path)
    (if (not (file-exists? linktree))
	(begin
	  (debug:print 0 "WARNING: linktree did not exist! Creating it now at " linktree)
	  (debug:print 0 *default-log-port* "WARNING: linktree did not exist! Creating it now at " linktree)
	  (create-directory linktree #t))) ;; (system (conc "mkdir -p " linktree))))
    ;; create the directory for the tests dir links, this is needed no matter what...
    (if (and (not (directory-exists? lnkbase))
	     (not (file-exists? lnkbase)))
	(handle-exceptions
	 exn
	 (begin
	   (debug:print "ERROR: Problem creating linktree base at " lnkbase)
	   (debug:print-error 0 *default-log-port* "Problem creating linktree base at " lnkbase)
	   (print-error-message exn (current-error-port)))
	 (create-directory lnkbase #t)))
    
    ;; update the toptest record with its location rundir, cache the path
    ;; This wass highly inefficient, one db write for every subtest, potentially
    ;; thousands of unnecessary updates, cache the fact it was set and don't set it 
    ;; again. 

    ;; Now create the link from the test path to the link tree, however
    ;; if the test is iterated it is necessary to create the parent path
    ;; to the iteration. use pathname-directory to trim the path by one
    ;; level
    (if (not not-iterated) ;; i.e. iterated
	(let ((iterated-parent  (pathname-directory (conc lnkpath "/" item-path))))
	  (debug:print-info 2 "Creating iterated parent " iterated-parent)
	  (debug:print-info 2 *default-log-port* "Creating iterated parent " iterated-parent)
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 0 "ERROR:  Failed to create directory " iterated-parent ((condition-property-accessor 'exn 'message) exn) ", exiting")
	     (debug:print-error 0 *default-log-port* " Failed to create directory " iterated-parent ((condition-property-accessor 'exn 'message) exn) ", exiting")
	     (exit 1))
	   (create-directory iterated-parent #t))))

    (if (symbolic-link? lnkpath) 
	(handle-exceptions
	 exn
	 (begin
	   (debug:print 0 "ERROR:  Failed to remove symlink " lnkpath ((condition-property-accessor 'exn 'message) exn) ", exiting")
	   (debug:print-error 0 *default-log-port* " Failed to remove symlink " lnkpath ((condition-property-accessor 'exn 'message) exn) ", exiting")
	   (exit 1))
	 (delete-file lnkpath)))

    (if (not (or (file-exists? lnkpath)
		 (symbolic-link? lnkpath)))
	(handle-exceptions
	 exn
	 (begin
	   (debug:print 0 "ERROR:  Failed to create symlink " lnkpath ((condition-property-accessor 'exn 'message) exn) ", exiting")
	   (debug:print-error 0 *default-log-port* " Failed to create symlink " lnkpath ((condition-property-accessor 'exn 'message) exn) ", exiting")
	   (exit 1))
	 (create-symbolic-link toptest-path lnkpath)))
    
    ;; NB - This was not working right - some top tests are not getting the path set!!!
    ;;
    ;; Do the setting of this record after the paths are created so that the shortdir can 
    ;; be set to the real directory location. This is safer for future clean up if the link
    ;; tree is damaged or lost.
    ;; 
    (if (not (hash-table-ref/default *toptest-paths* testname #f))
	(let* ((testinfo       (rmt:get-test-info-by-id run-id test-id)) ;;  run-id testname item-path))
	       (curr-test-path (if testinfo ;; (filedb:get-path *fdb*
							     ;; (db:get-path dbstruct
				   ;; (rmt:sdb-qry 'getstr 
				   (dbr:test-rundir testinfo) ;; ) ;; )
				   #f)))
	  (hash-table-set! *toptest-paths* testname curr-test-path)
	  ;; NB// Was this for the test or for the parent in an iterated test?
	  (rmt:general-call 'test-set-rundir-shortdir run-id lnkpath 
			    (if (file-exists? lnkpath)
				(resolve-pathname lnkpath)
				;; (resolve-pathname lnkpath)
				(common:nice-path lnkpath)
				lnkpath)
			    testname "")
	  ;; (rmt:general-call 'test-set-rundir run-id lnkpath testname "") ;; toptest-path)
	  (if (or (not curr-test-path)
		  (not (directory-exists? toptest-path)))
	      (begin
		(debug:print-info 2 "Creating " toptest-path " and link " lnkpath)
		(debug:print-info 2 *default-log-port* "Creating " toptest-path " and link " lnkpath)
		(handle-exceptions
		 exn
		 #f ;; don't care to catch and deal with errors here for now.
		 (create-directory toptest-path #t))
		(hash-table-set! *toptest-paths* testname toptest-path)))))

    ;; The toptest path has been created, the link to the test in the linktree has
    ;; been created. Now, if this is an iterated test the real test dir must be created
    (if (not not-iterated) ;; this is an iterated test
	(begin ;; (let ((lnktarget (conc lnkpath "/" item-path)))
	  (debug:print 2 "Setting up sub test run area")
	  (debug:print 2 " - creating run area in " test-path)
	  (debug:print 2 *default-log-port* "Setting up sub test run area")
	  (debug:print 2 *default-log-port* " - creating run area in " test-path)
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 0 "ERROR:  Failed to create directory " test-path ((condition-property-accessor 'exn 'message) exn) ", exiting")
	     (debug:print-error 0 *default-log-port* " Failed to create directory " test-path ((condition-property-accessor 'exn 'message) exn) ", exiting")
	     (exit 1))
	   (create-directory test-path #t))
	  (debug:print 2 
	  (debug:print 2 *default-log-port* 
		       " - creating link from: " test-path "\n"
		       "                   to: " lnktarget)

	  ;; If there is already a symlink delete it and recreate it.
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 0 "ERROR:  Failed to re-create link " lnktarget ((condition-property-accessor 'exn 'message) exn) ", exiting")
	     (debug:print-error 0 *default-log-port* " Failed to re-create link " lnktarget ((condition-property-accessor 'exn 'message) exn) ", exiting")
	     (exit))
	   (if (symbolic-link? lnktarget)     (delete-file lnktarget))
	   (if (not (file-exists? lnktarget)) (create-symbolic-link test-path lnktarget)))))

    (if (not (directory? test-path))
	(create-directory test-path #t)) ;; this is a hack, I don't know why out of the blue this path does not exist sometimes

861
862
863
864
865
866
867
868

869
870
871
872

873
874
875
876
877
878
879
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
1031







-
+



-
+







			       #f)))
		 (cmd    (if ovrcmd 
			     ovrcmd
			     (conc "rsync -av" (if (debug:debug-mode 1) "" "q") " " test-src-path "/ " test-path "/"
				   " >> " test-path "/mt_launch.log 2>> " test-path "/mt_launch.log")))
		 (status (system cmd)))
	    (if (not (eq? status 0))
		(debug:print 2 "ERROR: problem with running \"" cmd "\"")))
		(debug:print 2 *default-log-port* "ERROR: problem with running \"" cmd "\"")))
	  (list lnkpathf lnkpath ))
	(if (and test-src-path (> remtries 0))
	    (begin
	      (debug:print 0 "ERROR: Failed to create work area at " test-path " with link at " lnktarget ", remaining attempts " remtries)
	      (debug:print-error 0 *default-log-port* "Failed to create work area at " test-path " with link at " lnktarget ", remaining attempts " remtries)
	      ;; 
	      (create-work-area run-id run-info keyvals test-id test-src-path disk-path testname itemdat remtries: (- remtries 1)))
	    (list #f #f)))))

;; 1. look though disks list for disk with most space
;; 2. create run dir on disk, path name is meaningful
;; 3. create link from run dir to megatest runs area 
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
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114

1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1126







-
+
+











-
+



-
+







    (if (not remote-megatest)(set! remote-megatest local-megatest)) ;; "megatest"))
    (set! mt-bindir-path (pathname-directory remote-megatest))
    (if launcher (set! launcher (string-split launcher)))
    ;; set up the run work area for this test
    (if (and (args:get-arg "-preclean") ;; user has requested to preclean for this run
	     (not (member (dbr:test-rundir testinfo)(list "n/a" "/tmp/badname")))) ;; n/a is a placeholder and thus not a read dir
	(begin
	  (debug:print-info 0 "attempting to preclean directory " (dbr:test-rundir testinfo) " for test " test-name "/" item-path)
	  ;; (debug:print-info 0 "attempting to preclean directory " (dbr:test-rundir testinfo) " for test " test-name "/" item-path)
	  (debug:print-info 0 *default-log-port* "attempting to preclean directory " (dbr:test-rundir testinfo) " for test " test-name "/" item-path)
	  (runs:remove-test-directory testinfo 'remove-data-only))) ;; remove data only, do not perturb the record

    ;; prevent overlapping actions - set to LAUNCHED as early as possible
    ;;
    (tests:test-set-status! run-id test-id "LAUNCHED" "n/a" #f #f) ;; (if launch-results launch-results "FAILED"))
    (rmt:roll-up-pass-fail-counts run-id test-name item-path #f "LAUNCHED")
    (set! diskpath (get-best-disk *configdat* tconfig))
    (if diskpath
	(let ((dat  (create-work-area run-id run-info keyvals test-id test-path diskpath test-name itemdat)))
	  (set! work-area (car dat))
	  (set! toptest-work-area (cadr dat))
	  (debug:print-info 2 "Using work area " work-area))
	  (debug:print-info 2 *default-log-port* "Using work area " work-area))
	(begin
	  (set! work-area (conc test-path "/tmp_run"))
	  (create-directory work-area #t)
	  (debug:print 0 "WARNING: No disk work area specified - running in the test directory under tmp_run")))
	  (debug:print 0 *default-log-port* "WARNING: No disk work area specified - running in the test directory under tmp_run")))
    (set! cmdparms (base64:base64-encode 
		    (z3:encode-buffer 
		     (with-output-to-string
		       (lambda () ;; (list 'hosts     hosts)
			 (write (list (list 'testpath  test-path)
				      (list 'transport (conc *transport-type*))
				      ;; (list 'serverinf *server-info*)
997
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008

1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048


1049
1050
1051
1052
1053
1054
1055
1150
1151
1152
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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199


1200
1201
1202
1203
1204
1205
1206
1207
1208







-
+



-
+

-
+
















-
+



















-
-
+
+







     ((and launcher hosts) ;; must be using ssh hostname
      (set! fullcmd (append launcher (car hosts)(list remote-megatest "-m" test-sig "-execute" cmdparms) debug-param)))
     ;; (set! fullcmd (append launcher (car hosts)(list remote-megatest test-sig "-execute" cmdparms))))
     (launcher
      (set! fullcmd (append launcher (list remote-megatest "-m" test-sig "-execute" cmdparms) debug-param)))
     ;; (set! fullcmd (append launcher (list remote-megatest test-sig "-execute" cmdparms))))
     (else
      (if (not useshell)(debug:print 0 "WARNING: internal launching will not work well without \"useshell yes\" in your [jobtools] section"))
      (if (not useshell)(debug:print 0 *default-log-port* "WARNING: internal launching will not work well without \"useshell yes\" in your [jobtools] section"))
      (set! fullcmd (append (list remote-megatest "-m" test-sig "-execute" cmdparms) debug-param (list (if useshell "&" ""))))))
    ;; (set! fullcmd (list remote-megatest test-sig "-execute" cmdparms (if useshell "&" "")))))
    (if (args:get-arg "-xterm")(set! fullcmd (append fullcmd (list "-xterm"))))
    (debug:print 1 "Launching " work-area)
    (debug:print 1 *default-log-port* "Launching " work-area)
    ;; set pre-launch-env-vars before launching, keep the vars in prevvals and put the envionment back when done
    (debug:print 4 "fullcmd: " fullcmd)
    (debug:print 4 *default-log-port* "fullcmd: " fullcmd)
    (let* ((commonprevvals (alist->env-vars
			    (hash-table-ref/default *configdat* "env-override" '())))
	   (testprevvals   (alist->env-vars
			    (hash-table-ref/default tconfig "pre-launch-env-overrides" '())))
	   (miscprevvals   (alist->env-vars ;; consolidate this code with the code in megatest.scm for "-execute"
			    (append (list (list "MT_TEST_RUN_DIR" work-area)
					  (list "MT_TEST_NAME" test-name)
					  (list "MT_ITEM_INFO" (conc itemdat)) 
					  (list "MT_RUNNAME"   runname)
					  (list "MT_TARGET"    mt_target)
					  (list "MT_ITEMPATH"  item-path)
					  )
				    itemdat)))
	   ;; Launchwait defaults to true, must override it to turn off wait
	   (launchwait     (if (equal? (configf:lookup *configdat* "setup" "launchwait") "no") #f #t))
	   (launch-results (apply (if launchwait
				      cmd-run-with-stderr->list
				      process:cmd-run-with-stderr->list
				      process-run)
				  (if useshell
				      (let ((cmdstr (string-intersperse fullcmd " ")))
					(if launchwait
					    cmdstr
					    (conc cmdstr " >> mt_launch.log 2>&1")))
				      (car fullcmd))
				  (if useshell
				      '()
				      (cdr fullcmd)))))
      (if (not launchwait) ;; give the OS a little time to allow the process to start
	  (thread-sleep! 0.01))
      (with-output-to-file "mt_launch.log"
	(lambda ()
	  (print "LAUNCHCMD: " (string-intersperse fullcmd " "))
	  (if (list? launch-results)
	      (apply print launch-results)
	      (print "NOTE: launched \"" fullcmd "\"\n  but did not wait for it to proceed. Add the following to megatest.config \n[setup]\nlaunchwait yes\n  if you have problems with this"))
	  #:append))
      (debug:print 2 "Launching completed, updating db")
      (debug:print 2 "Launch results: " launch-results)
      (debug:print 2 *default-log-port* "Launching completed, updating db")
      (debug:print 2 *default-log-port* "Launch results: " launch-results)
      (if (not launch-results)
          (begin
            (print "ERROR: Failed to run " (string-intersperse fullcmd " ") ", exiting now")
            ;; (sqlite3:finalize! db)
            ;; good ole "exit" seems not to work
            ;; (_exit 9)
            ;; but this hack will work! Thanks go to Alan Post of the Chicken email list

Modified lock-queue.scm from [1e70529cd9] to [9c528b71c8].

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
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







-
-
+
+



-
+












-
-
+
+




-
+








(define (lock-queue:set-state dbdat test-id newstate #!key (remtries 10))
  (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200)
  (handle-exceptions
   exn
   (if (> remtries 0)
       (begin
	 (debug:print 0 "WARNING: exception on lock-queue:set-state. Trying again in 30 seconds.")
	 (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	 (debug:print 0 *default-log-port* "WARNING: exception on lock-queue:set-state. Trying again in 30 seconds.")
	 (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	 (thread-sleep! 30)
	 (lock-queue:set-state dbdat test-id newstate remtries: (- remtries 1)))
       (begin
	 (debug:print 0 "ERROR:  Failed to set lock state for test with id " test-id ", error: " ((condition-property-accessor 'exn 'message) exn) ", giving up.")
	 (debug:print-error 0 *default-log-port* " Failed to set lock state for test with id " test-id ", error: " ((condition-property-accessor 'exn 'message) exn) ", giving up.")
	 #f))
   (sqlite3:execute (lock-queue:db-dat-get-db dbdat) "UPDATE queue SET state=? WHERE test_id=?;"
		    newstate
		    test-id)))

(define (lock-queue:any-younger? dbdat mystart test-id #!key (remtries 10))
  ;; no need to wait on journal on read only queries
  ;; (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200)
  (handle-exceptions
   exn
   (if (> remtries 0)
       (begin
	 (debug:print 0 "WARNING: exception on lock-queue:any-younger. Removing lockdb and trying again in 5 seconds.")
	 (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	 (debug:print 0 *default-log-port* "WARNING: exception on lock-queue:any-younger. Removing lockdb and trying again in 5 seconds.")
	 (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	 (thread-sleep! 5)
         (lock-queue:delete-lock-db dbdat)
	 (lock-queue:any-younger? dbdat mystart test-id remtries: (- remtries 1)))
       (begin
	 (debug:print 0 "ERROR:  Failed to find younger locks for test with id " test-id ", error: " ((condition-property-accessor 'exn 'message) exn) ", giving up.")
	 (debug:print-error 0 *default-log-port* " Failed to find younger locks for test with id " test-id ", error: " ((condition-property-accessor 'exn 'message) exn) ", giving up.")
	 #f))
   (let ((res #f))
     (sqlite3:for-each-row
      (lambda (tid)
	;; Actually this should not be needed as mystart cannot be simultaneously less than and test-id same as 
	(if (not (equal? tid test-id)) 
	    (set! res tid)))
117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132
117
118
119
120
121
122
123


124
125
126
127
128
129
130
131
132







-
-
+
+







	 (db        (lock-queue:db-dat-get-db dbdat))
	 (lckqry    (sqlite3:prepare db "SELECT test_id,run_lock FROM runlocks WHERE run_lock='locked';"))
	 (mklckqry  (sqlite3:prepare db "INSERT INTO runlocks (test_id,run_lock) VALUES (?,'locked');")))
    (let ((result 
	   (handle-exceptions
	    exn
	    (begin
	      (debug:print 0 "WARNING: failed to get queue lock. Removing lock db and returning fail") ;; Will try again in a few seconds")
	      (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	      (debug:print 0 *default-log-port* "WARNING: failed to get queue lock. Removing lock db and returning fail") ;; Will try again in a few seconds")
	      (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	      (thread-sleep! 10)
	      ;; (if (> count 0)	
	      ;;  #f ;; (lock-queue:get-lock dbdat test-id count: (- count 1)) - give up on retries 
	      ;; (begin ;; never recovered, remote the lock file and return #f, no lock obtained
	      (lock-queue:delete-lock-db dbdat)
	      #f)
	    (sqlite3:with-transaction
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
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







-
-
+
+


















-
+




-
-
+
+



















-
-
+
+







-
+








(define (lock-queue:release-lock fname test-id #!key (count 10))
  (let* ((dbdat (lock-queue:open-db fname)))
    (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 "lock-queue:release-lock; waiting on journal")
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "WARNING: Failed to release queue lock. Will try again in few seconds")
       (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 *default-log-port* "WARNING: Failed to release queue lock. Will try again in few seconds")
       (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
       (thread-sleep! (/ count 10))
       (if (> count 0)
	   (begin
	     (sqlite3:finalize! (lock-queue:db-dat-get-db dbdat))
	     (lock-queue:release-lock fname test-id count: (- count 1)))
	   (let ((journal (conc fname "-journal")))
	     ;; If we've tried ten times and failed there is a serious problem
	     ;; try to remove the lock db and allow it to be recreated
	     (handle-exceptions
	      exn
	      #f
	      (if (file-exists? journal)(delete-file journal))
	      (if (file-exists? fname)  (delete-file fname))
	      #f))))
     (sqlite3:execute (lock-queue:db-dat-get-db dbdat) "DELETE FROM runlocks WHERE test_id=?;" test-id)
     (sqlite3:finalize! (lock-queue:db-dat-get-db dbdat)))))

(define (lock-queue:steal-lock dbdat test-id #!key (count 10))
  (debug:print-info 0 "Attempting to steal lock at " (lock-queue:db-dat-get-path dbdat))
  (debug:print-info 0 *default-log-port* "Attempting to steal lock at " (lock-queue:db-dat-get-path dbdat))
  (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 "lock-queue:steal-lock; waiting on journal")
  (handle-exceptions
   exn
   (begin
     (tadebug:print 0 "WARNING: Failed to steal queue lock. Will try again in few seconds")
     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 *default-log-port* "WARNING: Failed to steal queue lock. Will try again in few seconds")
     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
     (thread-sleep! 10)
     (if (> count 0)
	 (lock-queue:steal-lock dbdat test-id count: (- count 1))
	 #f))
   (sqlite3:execute (lock-queue:db-dat-get-db dbdat) "DELETE FROM runlocks WHERE run_lock='locked';"))
  (lock-queue:get-lock dbdat test-it))

;; returns #f if ok to skip the task
;; returns #t if ok to proceed with task
;; otherwise waits
;;
(define (lock-queue:wait-turn fname test-id #!key (count 10)(waiting-msg #f))
  (let* ((dbdat   (lock-queue:open-db fname))
	 (mystart (current-seconds))
	 (db      (lock-queue:db-dat-get-db dbdat)))
    ;; (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 waiting-msg: "lock-queue:wait-turn; waiting on journal file")
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "WARNING: Failed to find out if it is ok to skip the wait queue. Will try again in few seconds")
       (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 *default-log-port* "WARNING: Failed to find out if it is ok to skip the wait queue. Will try again in few seconds")
       (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
       (print-call-chain (current-error-port))
       (thread-sleep! 10)
       (if (> count 0)
	   (begin
	     (sqlite3:finalize! db)
	     (lock-queue:wait-turn fname test-id count: (- count 1)))
	   (begin
	     (debug:print 0 "Giving up calls to lock-queue:wait-turn for test-id " test-id " at path " fname ", printing call chain")
	     (debug:print 0 *default-log-port* "Giving up calls to lock-queue:wait-turn for test-id " test-id " at path " fname ", printing call chain")
	     (print-call-chain (current-error-port))
	     #f)))
     ;; wait 10 seconds and then check to see if someone is already updating the html
     (thread-sleep! 10)
     (if (not (lock-queue:any-younger? dbdat mystart test-id)) ;; no processing in flight, must try to start processing
	 (begin
	   (tasks:wait-on-journal (lock-queue:db-dat-get-path dbdat) 1200 waiting-msg: "lock-queue:wait-turn; waiting on journal file")

Modified margs.scm from [5bb81571cb] to [c9007a2ca1].

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







;; Copyright 2007-2010, Matthew Welland.
;;
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;;
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.

(declare (unit margs))
(declare (uses common))
;; (declare (uses common))

(define args:arg-hash (make-hash-table))

(define (args:get-arg arg . default)
  (if (null? default)
      (hash-table-ref/default args:arg-hash arg #f)
      (hash-table-ref/default args:arg-hash arg (car default))))

Modified megatest-version.scm from [85e378264e] to [1eea1a53bb].

1
2

3
4
5
6

7
1

2
3
4
5

6
7

-
+



-
+

;; Always use two or four digit decimal
;; 1.01, 1.02...1.10,1.11,1,1101 ... 1.99,2.00..
;; 1.01, 1.02...1.10,1.11,1.1101 ... 1.99,2.00..

(declare (unit megatest-version))

(define megatest-version 1.6028)
(define megatest-version 1.6104)

Modified megatest.scm from [1bdeda4f7c] to [dd6c0301b8].

34
35
36
37
38
39
40

41
42
43
44
45

46
47
48
49
50
51
52
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54







+





+







(declare (uses launch))
(declare (uses server))
(declare (uses client))
(declare (uses tests))
(declare (uses genexample))
(declare (uses daemon))
(declare (uses db))
;; (declare (uses dcommon))

(declare (uses tdb))
(declare (uses mt))
(declare (uses api))
(declare (uses tasks)) ;; only used for debugging.
(declare (uses env))

(define *db* #f) ;; this is only for the repl, do not use in general!!!!

(include "common_records.scm")
(include "key_records.scm")
(include "db_records.scm")
(include "run_records.scm")
73
74
75
76
77
78
79

80
81
82
83
84
85

86
87
88
89
90
91
92
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96







+






+







  -runall                 : run all tests or as specified by -testpatt
  -remove-runs            : remove the data for a run, requires -runname and -testpatt
                            Optionally use :state and :status
  -set-state-status X,Y   : set state to X and status to Y, requires controls per -remove-runs
  -rerun FAIL,WARN...     : force re-run for tests with specificed status(s)
  -rerun-clean            : set all tests not COMPLETED+PASS,WARN,WAIVED to NOT_STARTED,n/a
                            and then run the specified testpatt with -preclean
  -rerun-all              : set all tests to NOT_STARTED,n/a and run with -preclean
  -lock                   : lock run specified by target and runname
  -unlock                 : unlock run specified by target and runname
  -set-run-status status  : sets status for run to status, requires -target and -runname
  -get-run-status         : gets status for run specified by target and runname
  -run-wait               : wait on run specified by target and runname
  -preclean               : remove the existing test directory before running the test
  -clean-cache            : remove the cached megatest.config and runconfig.config files

Selectors (e.g. use for -runtests, -remove-runs, -set-state-status, -list-runs etc.)
  -target key1/key2/...   : run for key1, key2, etc.
  -reqtarg key1/key2/...  : run for key1, key2, etc. but key1/key2 must be in runconfig
  -testpatt patt1/patt2,patt3/...  : % is wildcard
  -runname                : required, name for this particular test run
  -state                  : Applies to runs, tests or steps depending on context
154
155
156
157
158
159
160

161
162
163
164
165
166
167
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172







+







  -load file.scm          : load and run file.scm
  -mark-incompletes       : find and mark incomplete tests
  -ping run-id|host:port  : ping server, exit with 0 if found
  -debug N|N,M,O...       : enable debug 0-N or N and M and O ...

Utilities
  -env2file fname         : write the environment to fname.csh and fname.sh
  -envcap fname=context   : save current variables labeled as context in file fname
  -refdb2dat refdb        : convert refdb to sexp or to format specified by -dumpmode
                            formats: perl, ruby, sqlite3, csv (for csv the -o param
                            will substitute %s for the sheet name in generating 
                            multiple sheets)
  -o                      : output file for refdb2dat (defaults to stdout)
  -archive cmd            : archive runs specified by selectors to one of disks specified
                            in the [archive-disks] section.
228
229
230
231
232
233
234


235
236
237
238
239
240
241
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248







+
+







			"-stop-server"
			"-transport"
			"-kill-server"
			"-port"
			"-extract-ods"
			"-pathmod"
			"-env2file"
			"-envcap"
			"-envdelta"
			"-setvars"
			"-set-state-status"
			"-set-run-status"
			"-debug" ;; for *verbosity* > 2
			"-gen-megatest-test"
			"-override-timeout"
			"-test-files"  ;; -test-paths is for listing all
264
265
266
267
268
269
270


271
272
273
274
275
276
277
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286







+
+







			"-set-values"
			"-load-test-data"
			"-summarize-items"
		        "-gui"
			"-daemonize"
			"-preclean"
			"-rerun-clean"
			"-rerun-all"
			"-clean-cache"

			;; misc
			"-repl"
			"-lock"
			"-unlock"
			"-list-servers"
                        "-run-wait"      ;; wait on a run to complete (i.e. no RUNNING)
307
308
309
310
311
312
313


314
315
316
317




318
319

320
321
322
323
324
325
326
316
317
318
319
320
321
322
323
324
325
326


327
328
329
330
331

332
333
334
335
336
337
338
339







+
+


-
-
+
+
+
+

-
+







			"-logging"
			"-v" ;; verbose 2, more than normal (normal is 1)
			"-q" ;; quiet 0, errors/warnings only
		       )
		 args:arg-hash
		 0))

;; Add args that use remargs here
;;
(if (and (not (null? remargs))
	 (not (or
	       (args:get-arg "-runstep"))
	      ;; add more args that use remargs here
	       (args:get-arg "-runstep")
	       (args:get-arg "-envcap")
	       (args:get-arg "-envdelta")
	       )
	      ))
    (debug:print 0 "ERROR: Unrecognised arguments: " (string-intersperse (if (list? remargs) remargs (argv))  " ")))
    (debug:print-error 0 *default-log-port* "Unrecognised arguments: " (string-intersperse (if (list? remargs) remargs (argv))  " ")))

;; immediately set MT_TARGET if -reqtarg or -target are available
;;
(let ((targ (or (args:get-arg "-reqtarg")(args:get-arg "-target"))))
  (if targ (setenv "MT_TARGET" targ)))

;; The watchdog is to keep an eye on things like db sync etc.
344
345
346
347
348
349
350
351

352
353

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
380
381

382
383
384
385
386


387
388
389
390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405

406
407
408
409
410
411
412
357
358
359
360
361
362
363

364
365

366
367
368

369
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398


399
400

401
402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417

418
419
420
421
422
423
424
425







-
+

-
+


-
+








-
+












-
+



+



-
-
+
+
-












-
+




-
+







		  (mutex-lock! *db-multi-sync-mutex*)
		  (if (and legacy-sync 
			   (hash-table-ref/default *db-local-sync* run-id #f))
		      ;; (if (> (- start-time last-write) 5) ;; every five seconds
		      (begin ;; let ((sync-time (- (current-seconds) start-time)))
			(db:multi-db-sync (list run-id) 'new2old)
			(let ((sync-time (- (current-seconds) start-time)))
			  (debug:print-info 3 "Sync of newdb to olddb for run-id " run-id " completed in " sync-time " seconds")
			  (debug:print-info 3 *default-log-port* "Sync of newdb to olddb for run-id " run-id " completed in " sync-time " seconds")
			  (if (common:low-noise-print 30 "sync new to old")
			      (debug:print-info 0 "Sync of newdb to olddb for run-id " run-id " completed in " sync-time " seconds")))
			      (debug:print-info 0 *default-log-port* "Sync of newdb to olddb for run-id " run-id " completed in " sync-time " seconds")))
			;; (if (> sync-time 10) ;; took more than ten seconds, start a server for this run
			;;     (begin
			;;       (debug:print-info 0 "Sync is taking a long time, start up a server to assist for run " run-id)
			;;       (debug:print-info 0 *default-log-port* "Sync is taking a long time, start up a server to assist for run " run-id)
			;;       (server:kind-run run-id)))))
			(hash-table-delete! *db-local-sync* run-id)))
		  (mutex-unlock! *db-multi-sync-mutex*))
		(hash-table-keys *db-local-sync*))
	       (if (and debug-mode
			(> (- start-time last-time) 60))
		   (begin
		     (set! last-time start-time)
		     (debug:print-info 4 "timestamp -> " (seconds->time-string (current-seconds)) ", time since start -> " (seconds->hr-min-sec (- (current-seconds) *time-zero*))))))
		     (debug:print-info 4 *default-log-port* "timestamp -> " (seconds->time-string (current-seconds)) ", time since start -> " (seconds->hr-min-sec (- (current-seconds) *time-zero*))))))
	     
	     ;; keep going unless time to exit
	     ;;
	     (if (not *time-to-exit*)
		 (let delay-loop ((count 0))
		   (if (and (not *time-to-exit*)
			    (< count 11)) ;; aprox 5-6 seconds
		       (begin
			 (thread-sleep! 1)
			 (delay-loop (+ count 1))))
		   (loop)))
	     (if (common:low-noise-print 30)
		 (debug:print-info 0 "Exiting watchdog timer, *time-to-exit* = " *time-to-exit*)))))
		 (debug:print-info 0 *default-log-port* "Exiting watchdog timer, *time-to-exit* = " *time-to-exit*)))))
     "Watchdog thread")))

(thread-start! *watchdog*)


(if (args:get-arg "-log")
    (let ((oup (open-output-file (args:get-arg "-log"))))
      (debug:print-info 0 "Sending log output to " (args:get-arg "-log"))
      (current-error-port oup)
      (debug:print-info 0 *default-log-port* "Sending log output to " (args:get-arg "-log"))
      (set! *default-log-port* oup)))
      (current-output-port oup)))

(if (or (args:get-arg "-h")
	(args:get-arg "-help")
	(args:get-arg "--help"))
    (begin
      (print help)
      (exit)))

(if (args:get-arg "-start-dir")
    (if (file-exists? (args:get-arg "-start-dir"))
	(change-directory (args:get-arg "-start-dir"))
	(begin
	  (debug:print 0 "ERROR: non-existant start dir " (args:get-arg "-start-dir") " specified, exiting.")
	  (debug:print-error 0 *default-log-port* "non-existant start dir " (args:get-arg "-start-dir") " specified, exiting.")
	  (exit 1))))

(if (args:get-arg "-version")
    (begin
      (print megatest-version)
      (print (common:version-signature)) ;; (print megatest-version)
      (exit)))

(define *didsomething* #f)

;; Overall exit handling setup immediately
;;
(if (or (args:get-arg "-process-reap"))
440
441
442
443
444
445
446
447

448
449
450
451


452
453
454
455
456
457
458





























459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
453
454
455
456
457
458
459

460
461
462
463

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515
516
517
518























519
520
521
522
523
524
525







-
+



-
+
+







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






-
+










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







(if (args:get-arg "-logging")(set! *logging* #t))

(if (debug:debug-mode 3) ;; we are obviously debugging
    (set! open-run-close open-run-close-no-exception-handling))

(if (args:get-arg "-itempatt")
    (let ((newval (conc (args:get-arg "-testpatt") "/" (args:get-arg "-itempatt"))))
      (debug:print 0 "WARNING: -itempatt has been deprecated, please use -testpatt testpatt/itempatt method, new testpatt is "newval)
      (debug:print 0 *default-log-port* "WARNING: -itempatt has been deprecated, please use -testpatt testpatt/itempatt method, new testpatt is "newval)
      (hash-table-set! args:arg-hash "-testpatt" newval)
      (hash-table-delete! args:arg-hash "-itempatt")))


(if (args:get-arg "-runtests")
    (debug:print 0 *default-log-port* "WARNING: \"-runtests\" is deprecated. Use \"-run\" with \"-testpatt\" instead"))

(on-exit std-exit-procedure)

;;======================================================================
;; Misc general calls
;;======================================================================

;; 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
	  (if (args:get-arg "-runname")
	      (let* ((toppath  (launch:setup))
		     (linktree (if toppath (configf:lookup *configdat* "setup" "linktree")))
		     (runtop   (conc linktree "/" (getenv "MT_TARGET") "/" (args:get-arg "-runname")))
		     (files    (if (file-exists? runtop)
				   (append (glob (conc runtop "/.megatest*"))
					   (glob (conc runtop "/.runconfig*")))
				   '())))
		(if (null? files)
		    (debug:print-info 0 *default-log-port* "No cached megatest or runconfigs files found. None removed.")
		    (begin
		      (debug:print-info 0 *default-log-port* "Removing cached files:\n    " (string-intersperse files "\n    "))
		      (for-each 
		       (lambda (f)
			 (handle-exceptions
			     exn
			     (debug:print 0 *default-log-port* "WARNING: Failed to remove file " f)
			   (delete-file f)))
		       files))))
	      (debug:print-error 0 *default-log-port* "-clean-cache requires -runname."))
	  (debug:print-error 0 *default-log-port* "-clean-cache requires -target or -reqtarg"))))
	    
	  
(if (args:get-arg "-env2file")
    (begin
      (save-environment-as-files (args:get-arg "-env2file"))
      (set! *didsomething* #t)))

(if (args:get-arg "-list-disks")
    (let ((toppath (launch:setup-for-run)))
    (let ((toppath (launch:setup)))
      (print 
       (string-intersperse 
	(map (lambda (x)
	       (string-intersperse 
		x
		" => "))
	     (common:get-disks *configdat*))
	"\n"))
      (set! *didsomething* #t)))

(define (make-sparse-array)
  (let ((a (make-sparse-vector)))
    (sparse-vector-set! a 0 (make-sparse-vector))
    a))

(define (sparse-array? a)
  (and (sparse-vector? a)
       (sparse-vector? (sparse-vector-ref a 0))))

(define (sparse-array-ref a x y)
  (let ((row (sparse-vector-ref a x)))
    (if row
	(sparse-vector-ref row y)
	#f)))

(define (sparse-array-set! a x y val)
  (let ((row (sparse-vector-ref a x)))
    (if row
	(sparse-vector-set! row y val)
	(let ((new-row (make-sparse-vector)))
	  (sparse-vector-set! a x new-row)
	  (sparse-vector-set! new-row y val)))))

(defstruct refdb:csv svec rows cols maxrow maxcol)

;; csv processing record
(define (actual-make-refdb:csv)
  (make-refdb:csv 
   (make-sparse-array)
   (make-hash-table)
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
552
553
554
555
556
557
558

559
560
561
562
563
564
565
566







-
+







			      (not (member out-fmt '("sqlite3" "csv"))))
			 (open-output-file out-file)
			 (current-output-port)))
	   (res-data (configf:read-refdb input-db))
	   (data     (car res-data))
	   (msg      (cadr res-data)))
      (if (not data)
	  (debug:print 0 "Bad input? data=" data) ;; some error occurred
	  (debug:print 0 *default-log-port* "Bad input? data=" data) ;; some error occurred
	  (with-output-to-port out-port
	    (lambda ()
	      (case (string->symbol out-fmt)
		((scheme)(pp data))
		((perl)
		 ;; (print "%hash = (")
		 ;;        key1 => 'value1',
653
654
655
656
657
658
659



660
661
662
663































664
665
666






667
668
669
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693
694
695
696
697








698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714
715
716
717

718
719
720
721
722
723
724
673
674
675
676
677
678
679
680
681
682




683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713



714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736

737
738
739
740
741
742








743
744
745
746
747
748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769

770
771
772
773
774
775
776
777







+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+










-
+






-
+





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+






-
+












-
+







      ))

(if (args:get-arg "-ping")
    (let* ((run-id        (string->number (args:get-arg "-run-id")))
	   (host:port     (args:get-arg "-ping")))
      (server:ping run-id host:port)))

;;======================================================================
;; Capture, save and manipulate environments
;;======================================================================
;;       (set! *did-something* #t)
;; 	      (begin
;; 		(print ((rpc:procedure 'testing (car host-port)(cadr host-port))))
;; 		(case (server:get-transport)

;; NOTE: Keep these above the section where the server or client code is setup

(let ((envcap (args:get-arg "-envcap")))
  (if envcap
      (let* ((db      (env:open-db (if (null? remargs) "envdat.db" (car remargs)))))
	(env:save-env-vars db envcap)
	(env:close-database db)
	(set! *didsomething* #t))))

;; delta "language" will eventually be res=a+b-c but for now it is just res=a-b 
;;
(let ((envdelta (args:get-arg "-envdelta")))
  (if envdelta
      (let ((match (string-split envdelta "-")));; (string-match "([a-z0-9_]+)=([a-z0-9_\\-,]+)" envdelta)))
	(if (not (null? match))
	    (let* ((db        (env:open-db (if (null? remargs) "envdat.db" (car remargs))))
		   ;; (resctx    (cadr match))
		   ;; (equn      (caddr match))
		   (parts     match) ;; (string-split equn "-"))
		   (minuend   (car parts))
		   (subtraend (cadr parts))
		   (added     (env:get-added   db minuend subtraend))
		   (removed   (env:get-removed db minuend subtraend))
		   (changed   (env:get-changed db minuend subtraend)))
	      ;; (pp (hash-table->alist added))
	      ;; (pp (hash-table->alist removed))
	      ;; (pp (hash-table->alist changed))
	      (if (args:get-arg "-o")
		  (with-output-to-file
		      (args:get-arg "-o")
;; 		  ((http)(http:ping run-id host-port))
;; 		  ((rpc) (rpc:procedure 'server:login (car host-port)(cadr host-port));;  *toppath*)) ;; (rpc-transport:ping  run-id (car host-port)(cadr host-port)))
;; 		  (else  (debug:print 0 "ERROR: No transport set")(exit)))))
		    (lambda ()
		      (env:print added removed changed)))
		  (env:print added removed changed))
	      (env:close-database db)
	      (set! *didsomething* #t))
	    (debug:print-error 0 *default-log-port* "Parameter to -envdelta should be new=star-end")))))

;;======================================================================
;; Start the server - can be done in conjunction with -runall or -runtests (one day...)
;;   we start the server if not running else start the client thread
;;======================================================================

(if (args:get-arg "-server")

    ;; Server? Start up here.
    ;;
    (let ((tl        (launch:setup-for-run))
    (let ((tl        (launch:setup))
	  (run-id    (and (args:get-arg "-run-id")
			  (string->number (args:get-arg "-run-id")))))
      (if run-id
	  (begin
	    (server:launch run-id)
	    (set! *didsomething* #t))
	  (debug:print 0 "ERROR: server requires run-id be specified with -run-id")))
	  (debug:print-error 0 *default-log-port* "server requires run-id be specified with -run-id")))

    ;; Not a server? This section will decide how to communicate
    ;;
    ;;  Setup client for all expect listed here
    (if (null? (lset-intersection 
		     equal?
		     (hash-table-keys args:arg-hash)
		     '("-list-servers"
		       "-stop-server"
		       "-show-cmdinfo"
		       "-list-runs"
		       "-ping")))
	(if (launch:setup-for-run)
		equal?
		(hash-table-keys args:arg-hash)
		'("-list-servers"
		  "-stop-server"
		  "-show-cmdinfo"
		  "-list-runs"
		  "-ping")))
	(if (launch:setup)
	    (let ((run-id    (and (args:get-arg "-run-id")
				  (string->number (args:get-arg "-run-id")))))
	      ;; (set! *fdb*   (filedb:open-db (conc *toppath* "/db/paths.db")))
	      ;; if not list or kill then start a client (if appropriate)
	      (if (or (args-defined? "-h" "-version" "-gen-megatest-area" "-gen-megatest-test")
		      (eq? (length (hash-table-keys args:arg-hash)) 0))
		  (debug:print-info 1 "Server connection not needed")
		  (debug:print-info 1 *default-log-port* "Server connection not needed")
		  (begin
		    ;; (if run-id 
		    ;;     (client:launch run-id) 
		    ;;     (client:launch 0)      ;; without run-id we'll start a server for "0"
		    #t
		    ))))))

;; MAY STILL NEED THIS
;;		       (set! *megatest-db* (make-dbr:dbstruct path: *toppath* local: #t))))))))))

(if (or (args:get-arg "-list-servers")
	(args:get-arg "-stop-server"))
    (let ((tl (launch:setup-for-run)))
    (let ((tl (launch:setup)))
      (if tl 
	  (let* ((tdbdat  (tasks:open-db))
		 (servers (tasks:get-all-servers (db:delay-if-busy tdbdat)))
		 (fmtstr  "~5a~12a~8a~20a~24a~10a~10a~10a~10a\n")
		 (servers-to-kill '())
		 (killinfo   (args:get-arg "-stop-server"))
		 (khost-port (if killinfo (if (substring-index ":" killinfo)(string-split ":") #f) #f))
750
751
752
753
754
755
756
757

758
759
760

761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
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
816
817

818
819
820
821
822

823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

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
803
804
805
806
807
808
809

810
811
812

813
814
815
816
817
818
819
820
821
822
823

824
825
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
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
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







-
+


-
+










-
+









-
+


+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-

-
+
















-
+




-
+


















-
+










-
+












-
+



-
+


-
+




-
+


+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+







		     (if (> last-update 20)        ;; Mark as dead if not updated in last 20 seconds
			 (tasks:server-deregister (db:delay-if-busy tdbdat) hostname pullport: pullport pid: pid)))
		 (format #t fmtstr id mt-ver pid hostname (conc interface ":" pullport) pubport last-update
			 (if status "alive" "dead") transport)
		 (if (or (equal? id sid)
			 (equal? sid 0)) ;; kill all/any
		     (begin
		       (debug:print-info 0 "Attempting to stop server with pid " pid)
		       (debug:print-info 0 *default-log-port* "Attempting to stop server with pid " pid)
		       (tasks:kill-server status hostname pullport pid transport)))))
	     servers)
	    (debug:print-info 1 "Done with listservers")
	    (debug:print-info 1 *default-log-port* "Done with listservers")
	    (set! *didsomething* #t)
	    (exit)) ;; must do, would have to add checks to many/all calls below
	  (exit))))

;;======================================================================
;; Weird special calls that need to run *after* the server has started?
;;======================================================================

(if (args:get-arg "-list-targets")
    (let ((targets (common:get-runconfig-targets)))
      (debug:print 1 "Found "(length targets) " targets")
      (debug:print 1 *default-log-port* "Found "(length targets) " targets")
      (case (string->symbol (or (args:get-arg "-dumpmode") "alist"))
	((alist)
	 (for-each (lambda (x)
		     ;; (print "[" x "]"))
		     (print x))
		   targets))
	((json)
	 (json-write targets))
	(else
	 (debug:print 0 "ERROR: dump output format " (args:get-arg "-dumpmode") " not supported for -list-targets")))
	 (debug:print-error 0 *default-log-port* "dump output format " (args:get-arg "-dumpmode") " not supported for -list-targets")))
      (set! *didsomething* #t)))

;; cache the runconfigs in $MT_LINKTREE/$MT_TARGET/$MT_RUNNAME/.runconfig
;;
(define (full-runconfigs-read)
;; in the envprocessing branch the below code replaces the further below code
;;  (if (eq? *configstatus* 'fulldata)
;;      *runconfigdat*
;;      (begin
;;	(launch:setup)
;;	*runconfigdat*)))

  (let* ((rundir (if (and (getenv "MT_LINKTREE")(getenv "MT_TARGET")(getenv "MT_RUNNAME"))
		     (conc (getenv "MT_LINKTREE") "/" (getenv "MT_TARGET") "/" (getenv "MT_RUNNAME"))
		     #f))
	 (cfgf   (if rundir (conc rundir "/.runconfig." megatest-version "-" megatest-fossil-hash) #f)))
    (if (and cfgf
	     (file-exists? cfgf)
	     (file-write-access? cfgf))
	(configf:read-alist cfgf)
  (let* ((keys   (rmt:get-keys))
	 (target (common:args-get-target))
	 (key-vals (if target (keys:target->keyval keys target) #f))
	 (sections (if target (list "default" target) #f))
	 (data     (begin
		     (setenv "MT_RUN_AREA_HOME" *toppath*)
		     (if key-vals
			 (for-each (lambda (kt)
				     (setenv (car kt) (cadr kt)))
				   key-vals))
		     (read-config (conc *toppath* "/runconfigs.config") #f #t sections: sections))))
    data))
	(let* ((keys   (rmt:get-keys))
	       (target (common:args-get-target))
	       (key-vals (if target (keys:target->keyval keys target) #f))
	       (sections (if target (list "default" target) #f))
	       (data     (begin
			   (setenv "MT_RUN_AREA_HOME" *toppath*)
			   (if key-vals
			       (for-each (lambda (kt)
					   (setenv (car kt) (cadr kt)))
					 key-vals))
			   (read-config (conc *toppath* "/runconfigs.config") #f #t sections: sections))))
	  (if (and rundir ;; have all needed variabless
		   (directory-exists? rundir)
		   (file-write-access? rundir))
	      (begin
		(configf:write-alist data cfgf)
		;; force re-read of megatest.config - this resolves circular references between megatest.config
		(launch:setup force: #t)
		(launch:cache-config))) ;; we can safely cache megatest.config since we have a valid runconfig
	  data))))


(if (args:get-arg "-show-runconfig")
    (let ((tl (launch:setup-for-run)))
    (let ((tl (launch:setup)))
      (push-directory *toppath*)
      (let ((data (full-runconfigs-read)))
	;; keep this one local
	(cond
	 ((and (args:get-arg "-section")
	       (args:get-arg "-var"))
	  (let ((val (or (configf:lookup data (args:get-arg "-section")(args:get-arg "-var"))
			 (configf:lookup data "default" (args:get-arg "-var")))))
	    (if val (print val))))
	 ((not (args:get-arg "-dumpmode"))
	  (pp (hash-table->alist data)))
	 ((string=? (args:get-arg "-dumpmode") "json")
	  (json-write data))
	 ((string=? (args:get-arg "-dumpmode") "ini")
	  (configf:config->ini data))
	 (else
	  (debug:print 0 "ERROR: -dumpmode of " (args:get-arg "-dumpmode") " not recognised")))
	  (debug:print-error 0 *default-log-port* "-dumpmode of " (args:get-arg "-dumpmode") " not recognised")))
	(set! *didsomething* #t))
      (pop-directory)))

(if (args:get-arg "-show-config")
    (let ((tl   (launch:setup-for-run))
    (let ((tl   (launch:setup))
	  (data *configdat*)) ;; (read-config "megatest.config" #f #t)))
      (push-directory *toppath*)
      ;; keep this one local
      (cond 
       ((and (args:get-arg "-section")
	     (args:get-arg "-var"))
	(let ((val (configf:lookup data (args:get-arg "-section")(args:get-arg "-var"))))
	  (if val (print val))))

       ;; print just a section if only -section

       ((not (args:get-arg "-dumpmode"))
	(pp (hash-table->alist data)))
       ((string=? (args:get-arg "-dumpmode") "json")
	(json-write data))
       ((string=? (args:get-arg "-dumpmode") "ini")
	(configf:config->ini data))
       (else
	(debug:print 0 "ERROR: -dumpmode of " (args:get-arg "-dumpmode") " not recognised")))
	(debug:print-error 0 *default-log-port* "-dumpmode of " (args:get-arg "-dumpmode") " not recognised")))
      (set! *didsomething* #t)
      (pop-directory)))

(if (args:get-arg "-show-cmdinfo")
    (if (or (args:get-arg ":value")(getenv "MT_CMDINFO"))
	(let ((data (common:read-encoded-string (or (args:get-arg ":value")(getenv "MT_CMDINFO")))))
	  (if (equal? (args:get-arg "-dumpmode") "json")
	      (json-write data)
	      (pp data))
	  (set! *didsomething* #t))
	(debug:print-info 0 "environment variable MT_CMDINFO is not set")))
	(debug:print-info 0 *default-log-port* "environment variable MT_CMDINFO is not set")))

;;======================================================================
;; Remove old run(s)
;;======================================================================

;; since several actions can be specified on the command line the removal
;; is done first
(define (operate-on action)
  (let* ((runrec (runs:runrec-make-record))
	 (target (common:args-get-target)))
    (cond
     ((not target)
      (debug:print 0 "ERROR: Missing required parameter for " action ", you must specify -target or -reqtarg")
      (debug:print-error 0 *default-log-port* "Missing required parameter for " action ", you must specify -target or -reqtarg")
      (exit 1))
     ((not (or (args:get-arg ":runname")
	       (args:get-arg "-runname")))
      (debug:print 0 "ERROR: Missing required parameter for " action ", you must specify the run name pattern with -runname patt")
      (debug:print-error 0 *default-log-port* "Missing required parameter for " action ", you must specify the run name pattern with -runname patt")
      (exit 2))
     ((not (args:get-arg "-testpatt"))
      (debug:print 0 "ERROR: Missing required parameter for " action ", you must specify the test pattern with -testpatt")
      (debug:print-error 0 *default-log-port* "Missing required parameter for " action ", you must specify the test pattern with -testpatt")
      (exit 3))
     (else
      (if (not (car *configinfo*))
	  (begin
	    (debug:print 0 "ERROR: Attempted " action "on test(s) but run area config file not found")
	    (debug:print-error 0 *default-log-port* "Attempted " action "on test(s) but run area config file not found")
	    (exit 1))
	  ;; put test parameters into convenient variables
	  (begin
	    ;; check for correct version, exit with message if not correct
	    (common:exit-on-version-changed)
	  (runs:operate-on  action
			    target
			    (common:args-get-runname)  ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
			    (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
			    state: (common:args-get-state)
			    status: (common:args-get-status)
			    new-state-status: (args:get-arg "-set-state-status")))
	    (runs:operate-on  action
			      target
			      (common:args-get-runname)  ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
			      (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
			      state: (common:args-get-state)
			      status: (common:args-get-status)
			      new-state-status: (args:get-arg "-set-state-status"))))
      (set! *didsomething* #t)))))
	  

(if (args:get-arg "-remove-runs")
    (general-run-call 
     "-remove-runs"
     "remove runs"
     (lambda (target runname keys keyvals)
       (operate-on 'remove-runs))))

909
910
911
912
913
914
915
916

917
918
919
920
921
922
923
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003







-
+







       (let* ((runsdat  (rmt:get-runs-by-patt keys runname 
					(common:args-get-target)
					#f #f #f))
	      (header   (vector-ref runsdat 0))
	      (rows     (vector-ref runsdat 1)))
	 (if (null? rows)
	     (begin
	       (debug:print-info 0 "No matching run found.")
	       (debug:print-info 0 *default-log-port* "No matching run found.")
	       (exit 1))
	     (let* ((row      (car (vector-ref runsdat 1)))
		    (run-id   (db:get-value-by-header row header "id")))
	       (if (args:get-arg "-set-run-status")
		   (rmt:set-run-status run-id (args:get-arg "-set-run-status") msg: (args:get-arg "-m"))
		   (print (rmt:get-run-status run-id))
		   )))))))
952
953
954
955
956
957
958
959

960
961
962
963
964
965
966
1032
1033
1034
1035
1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1046







-
+








;; NOTE: list-runs and list-db-targets operate on local db!!!
;;
;; IDEA: megatest list -runname blah% ...
;;
(if (or (args:get-arg "-list-runs")
	(args:get-arg "-list-db-targets"))
    (if (launch:setup-for-run)
    (if (launch:setup)
	(let* (;; (dbstruct    (make-dbr:dbstruct path: *toppath* local: (args:get-arg "-local")))
	       (runpatt     (args:get-arg "-list-runs"))
	       (testpatt    (common:args-get-testpatt #f))
	       ;; (if (args:get-arg "-testpatt") 
	       ;;  	        (args:get-arg "-testpatt") 
	       ;;  	        "%"))
	       (keys        (rmt:get-keys)) ;; (db:get-keys dbstruct))
1009
1010
1011
1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022
1023
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098
1099
1100
1101
1102
1103







-
+







		    ;; generate the lookup map test-field-name => index-number
		    (let loop ((hed (car adj-tests-spec))
			       (tal (cdr adj-tests-spec))
			       (idx 0))
		      (hash-table-set! test-field-index hed idx)
		      (if (not (null? tal))(loop (car tal)(cdr tal)(+ idx 1))))
		    (begin
		      (debug:print 0 "ERROR: Invalid test fields specified: " (string-intersperse invalid-tests-spec ", "))
		      (debug:print-error 0 *default-log-port* "Invalid test fields specified: " (string-intersperse invalid-tests-spec ", "))
		      (exit)))))

	  ;; Each run
	  (for-each 
	   (lambda (run)
	     (let ((targetstr (string-intersperse (map (lambda (x)
							 (db:get-value-by-header run header x))
1037
1038
1039
1040
1041
1042
1043
1044



1045
1046
1047
1048
1049
1050
1051
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130
1131
1132
1133







-
+
+
+







			  (statuses (string-split (or (args:get-arg "-status") "") ","))
			  (tests   (if tests-spec
				       (rmt:get-tests-for-run run-id testpatt states statuses #f #f #f 'testname 'asc ;; (db:get-tests-for-run dbstruct run-id testpatt '() '() #f #f #f 'testname 'asc 
							     ;; use qryvals if test-spec provided
							     (if tests-spec
								 (string-intersperse adj-tests-spec ",")
								 ;; db:test-record-fields
								 #f))
								 #f)
							     #f
							     'normal)
				       '())))
		     (case dmode
		       ((json ods)
			(if runs-spec
			    (for-each 
			     (lambda (field-name)
			       (mutils:hierhash-set! data (conc (db:get-value-by-header run header field-name)) targetstr runname "meta" field-name))
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085

1086
1087
1088
1089
1090
1091
1092
1158
1159
1160
1161
1162
1163
1164

1165
1166

1167
1168
1169
1170
1171
1172
1173
1174







-
+

-
+







			      (newline)))))
		       
		     (for-each 
		      (lambda (test)
		      	(handle-exceptions
			 exn
			 (begin
			   (debug:print 0 "ERROR: Bad data in test record? " test)
			   (debug:print-error 0 *default-log-port* "Bad data in test record? " test)
			   (print "exn=" (condition->list exn))
			   (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
			   (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
			   (print-call-chain (current-error-port)))
			 (let* ((test-id      (if (member "id"           tests-spec)(get-value-by-fieldname test test-field-index "id"          ) #f)) ;; (dbr:test-id         test))
				(testname     (if (member "testname"     tests-spec)(get-value-by-fieldname test test-field-index "testname"    ) #f)) ;; (dbr:test-testname   test))
				(itempath     (if (member "item_path"    tests-spec)(get-value-by-fieldname test test-field-index "item_path"   ) #f)) ;; (dbr:test-item-path  test))
				(comment      (if (member "comment"      tests-spec)(get-value-by-fieldname test test-field-index "comment"     ) #f)) ;; (dbr:test-comment    test))
				(tstate       (if (member "state"        tests-spec)(get-value-by-fieldname test test-field-index "state"       ) #f)) ;; (dbr:test-state      test))
				(tstatus      (if (member "status"       tests-spec)(get-value-by-fieldname test test-field-index "status"      ) #f)) ;; (dbr:test-status     test))
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1304
1305
1306
1307
1308
1309
1310

1311
1312
1313
1314
1315
1316
1317
1318







-
+







					    ;; (print "runname: " runname "\n\nrundat: " )(pp rundat)(print "\n\nmetadat: ")(pp metadat)
					    (if metadat
						(map (lambda (field)
						       (let ((tmp (assoc field metadat)))
							 (if tmp (cdr tmp) "")))
						     metadat-fields)
						(begin
						  (debug:print 0 "WARNING: meta data for run " runname " not found")
						  (debug:print 0 *default-log-port* "WARNING: meta data for run " runname " not found")
						  '()))))
					allrundat)))
		 ;; '( ( "target" ( "runname" ( "data" ( "runid" ( "id . "37" ) ( ... ))))
		 (run-pages      (map (lambda (targdat)
					(let* ((target  (car targdat))
					       (runsdat (cdr targdat)))
					  (if runsdat
1251
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1333
1334
1335
1336
1337
1338
1339

1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360

1361
1362
1363
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377
1378







-
+




















-
+









-
+







							     ;; (print "Target: " target "/" runname " tests:")
							     ;; (pp tests)
							     (cons (conc target "/" runname)
								   (cons (list (conc target "/" runname))
									 (cons '()
									       (cons run-fields tests)))))
							   (begin
							     (debug:print 0 "WARNING: run " target "/" runname " appears to have no data")
							     (debug:print 0 *default-log-port* "WARNING: run " target "/" runname " appears to have no data")
							     ;; (pp rundat)
							     '()))))
						   runsdat)
					      '())))
				      newdat)) ;; we use newdat to get target
		 (sheets         (filter (lambda (x)
					   (not (null? x)))
					 (cons runs (map car run-pages)))))
	    ;; (print "allrundat:")
	    ;; (pp allrundat)
	    ;; (print "runs:")
	    ;; (pp runs)
	    ;(print "sheets: ")
	    ;; (pp sheets)
	    (if (eq? dmode 'ods)
		(let* ((tempdir    (conc "/tmp/" (current-user-name) "/" (random 10000) "_" (current-process-id)))
		       (outputfile (or (args:get-arg "-o") "out.ods"))
		       (ouf        (if (string-match (regexp "^[/~]+.*") outputfile) ;; full path?
				       outputfile
				       (begin
					 (debug:print 0 "WARNING: path given, " outputfile " is relative, prefixing with current directory")
					 (debug:print 0 *default-log-port* "WARNING: path given, " outputfile " is relative, prefixing with current directory")
					 (conc (current-directory) "/" outputfile)))))
		  (create-directory tempdir #t)
		  (ods:list->ods tempdir ouf sheets))))
	  ;; (system (conc "rm -rf " tempdir))
	  (set! *didsomething* #t))))

;; Don't think I need this. Incorporated into -list-runs instead
;;
;; (if (and (args:get-arg "-since")
;; 	 (launch:setup-for-run))
;; 	 (launch:setup))
;;     (let* ((since-time (string->number (args:get-arg "-since")))
;; 	   (run-ids    (db:get-changed-run-ids since-time)))
;;       ;; (rmt:get-tests-for-runs-mindata run-ids testpatt states status not-in)
;;       (print (sort run-ids <))
;;       (set! *didsomething* #t)))
      
      
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323
1324
1325
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408







+







;; if still ok to run tasks
;;   process deferred tasks per above steps

;; run all tests are are Not COMPLETED and PASS or CHECK
(if (or (args:get-arg "-runall")
	(args:get-arg "-run")
	(args:get-arg "-rerun-clean")
	(args:get-arg "-rerun-all")
	(args:get-arg "-runtests"))
    (general-run-call 
     "-runall"
     "run all tests"
     (lambda (target runname keys keyvals)
       (if (args:get-arg "-rerun-clean") ;; first set states/statuses correct
	   (let ((states   (or (configf:lookup *configdat* "validvalues" "cleanrerun-states")
1336
1337
1338
1339
1340
1341
1342


















1343
1344
1345
1346
1347
1348
1349
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450







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







			      new-state-status: "NOT_STARTED,n/a")
	     (runs:operate-on 'set-state-status
			      target
			      (common:args-get-runname)  ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
			      "%" ;; (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
			      ;; state:  states
			      status: statuses
			      new-state-status: "NOT_STARTED,n/a")))
       ;; RERUN ALL
       (if (args:get-arg "-rerun-all") ;; first set states/statuses correct
	   (begin
	     (hash-table-set! args:arg-hash "-preclean" #t)
	     (runs:operate-on 'set-state-status
			      target
			      (common:args-get-runname)  ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
			      "%" ;; (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
			      state:  #f
			      ;; status: statuses
			      new-state-status: "NOT_STARTED,n/a")
	     (runs:operate-on 'set-state-status
			      target
			      (common:args-get-runname)  ;; (or (args:get-arg "-runname")(args:get-arg ":runname"))
			      "%" ;; (common:args-get-testpatt #f) ;; (args:get-arg "-testpatt")
			      ;; state:  states
			      status: #f
			      new-state-status: "NOT_STARTED,n/a")))
       (runs:run-tests target
		       runname
		       #f ;; (common:args-get-testpatt #f)
		       ;; (or (args:get-arg "-testpatt")
		       ;;     "%")
		       user
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447

1448
1449

1450
1451
1452
1453
1454
1455
1456
1539
1540
1541
1542
1543
1544
1545

1546
1547

1548
1549

1550
1551
1552
1553
1554
1555
1556
1557







-
+

-
+

-
+







	       (state     (args:get-arg ":state"))
	       (status    (args:get-arg ":status"))
	       (target    (args:get-arg "-target"))
	       (toppath   (assoc/default 'toppath   cmdinfo)))
	  (change-directory toppath)
	  (if (not target)
	      (begin
		(debug:print 0 "ERROR: -target is required.")
		(debug:print-error 0 *default-log-port* "-target is required.")
		(exit 1)))
	  (if (not (launch:setup-for-run))
	  (if (not (launch:setup))
	      (begin
		(debug:print 0 "Failed to setup, giving up on -test-paths or -test-files, exiting")
		(debug:print 0 *default-log-port* "Failed to setup, giving up on -test-paths or -test-files, exiting")
		(exit 1)))
	  (let* ((keys     (rmt:get-keys))
		 ;; db:test-get-paths must not be run remote
		 (paths    (tests:test-get-paths-matching keys target (args:get-arg "-test-files"))))
	    (set! *didsomething* #t)
	    (for-each (lambda (path)
			(print path))
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1590
1591
1592
1593
1594
1595
1596

1597
1598
1599
1600
1601
1602
1603
1604







-
+







     "Make ods spreadsheet"
     (lambda (target runname keys keyvals)
       (let ((dbstruct   (make-dbr:dbstruct path: *toppath* local: #t))
	     (outputfile (args:get-arg "-extract-ods"))
	     (runspatt   (or (args:get-arg "-runname")(args:get-arg ":runname")))
	     (pathmod    (args:get-arg "-pathmod")))
	     ;; (keyvalalist (keys->alist keys "%")))
	 (debug:print 2 "Extract ods, outputfile: " outputfile " runspatt: " runspatt " keyvals: " keyvals)
	 (debug:print 2 *default-log-port* "Extract ods, outputfile: " outputfile " runspatt: " runspatt " keyvals: " keyvals)
	 (db:extract-ods-file dbstruct outputfile keyvals (if runspatt runspatt "%") pathmod)
	 (db:close-all dbstruct)
	 (set! *didsomething* #t)))))

;;======================================================================
;; execute the test
;;    - gets called on remote host
1522
1523
1524
1525
1526
1527
1528
1529

1530
1531
1532
1533
1534
1535
1536
1537
1538
1539

1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553

1554
1555

1556
1557


1558

1559
1560

1561
1562
1563
1564
1565
1566
1567
1623
1624
1625
1626
1627
1628
1629

1630
1631
1632
1633
1634
1635
1636
1637
1638
1639

1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653

1654
1655

1656
1657
1658
1659
1660

1661
1662

1663
1664
1665
1666
1667
1668
1669
1670







-
+









-
+













-
+

-
+


+
+
-
+

-
+







	  (let ((run-id (string->number (car params)))
		(test-id (string->number (cadr params))))
	    (if (and run-id test-id)
		(begin
		  (launch:recover-test run-id test-id)
		  (set! *didsomething* #t))
		(begin
		  (debug:print 0 "ERROR: bad run-id or test-id, must be integers")
		  (debug:print-error 0 *default-log-port* "bad run-id or test-id, must be integers")
		  (exit 1)))))))

;;======================================================================
;; Test commands (i.e. for use inside tests)
;;======================================================================

(define (megatest:step step state status logfile msg)
  (if (not (getenv "MT_CMDINFO"))
      (begin
	(debug:print 0 "ERROR: MT_CMDINFO env var not set, -step must be called *inside* a megatest invoked environment!")
	(debug:print-error 0 *default-log-port* "MT_CMDINFO env var not set, -step must be called *inside* a megatest invoked environment!")
	(exit 5))
      (let* ((cmdinfo   (common:read-encoded-string (getenv "MT_CMDINFO")))
	     (transport (assoc/default 'transport cmdinfo))
	     (testpath  (assoc/default 'testpath  cmdinfo))
	     (test-name (assoc/default 'test-name cmdinfo))
	     (runscript (assoc/default 'runscript cmdinfo))
	     (db-host   (assoc/default 'db-host   cmdinfo))
	     (run-id    (assoc/default 'run-id    cmdinfo))
	     (test-id   (assoc/default 'test-id   cmdinfo))
	     (itemdat   (assoc/default 'itemdat   cmdinfo))
	     (work-area (assoc/default 'work-area cmdinfo))
	     (db        #f))
	(change-directory testpath)
	(if (not (launch:setup-for-run))
	(if (not (launch:setup))
	    (begin
	      (debug:print 0 "Failed to setup, exiting")
	      (debug:print 0 *default-log-port* "Failed to setup, exiting")
	      (exit 1)))
	(if (and state status)
	    (let ((comment (launch:load-logpro-dat run-id test-id step)))
	      ;; (rmt:test-set-log! run-id test-id (conc stepname ".html"))))
	    (rmt:teststep-set-status! run-id test-id step state status msg logfile)
	      (rmt:teststep-set-status! run-id test-id step state status (or comment msg) logfile))
	    (begin
	      (debug:print 0 "ERROR: You must specify :state and :status with every call to -step")
	      (debug:print-error 0 *default-log-port* "You must specify :state and :status with every call to -step")
	      (exit 6))))))

(if (args:get-arg "-step")
    (begin
      (megatest:step 
       (args:get-arg "-step")
       (or (args:get-arg "-state")(args:get-arg ":state"))
1578
1579
1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601



1602
1603

1604
1605
1606

1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627

1628
1629
1630
1631
1632
1633
1634
1681
1682
1683
1684
1685
1686
1687

1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702


1703
1704
1705
1706

1707
1708
1709

1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730

1731
1732
1733
1734
1735
1736
1737
1738







-
+














-
-
+
+
+

-
+


-
+




















-
+







	(args:get-arg "-test-status")
	(args:get-arg "-set-values")
	(args:get-arg "-load-test-data")
	(args:get-arg "-runstep")
	(args:get-arg "-summarize-items"))
    (if (not (getenv "MT_CMDINFO"))
	(begin
	  (debug:print 0 "ERROR: MT_CMDINFO env var not set, commands -test-status, -runstep and -setlog must be called *inside* a megatest environment!")
	  (debug:print-error 0 *default-log-port* "MT_CMDINFO env var not set, commands -test-status, -runstep and -setlog must be called *inside* a megatest environment!")
	  (exit 5))
	(let* ((startingdir (current-directory))
	       (cmdinfo   (common:read-encoded-string (getenv "MT_CMDINFO")))
	       (transport (assoc/default 'transport cmdinfo))
	       (testpath  (assoc/default 'testpath  cmdinfo))
	       (test-name (assoc/default 'test-name cmdinfo))
	       (runscript (assoc/default 'runscript cmdinfo))
	       (db-host   (assoc/default 'db-host   cmdinfo))
	       (run-id    (assoc/default 'run-id    cmdinfo))
	       (test-id   (assoc/default 'test-id   cmdinfo))
	       (itemdat   (assoc/default 'itemdat   cmdinfo))
	       (work-area (assoc/default 'work-area cmdinfo))
	       (db        #f) ;; (open-db))
	       (state     (args:get-arg ":state"))
	       (status    (args:get-arg ":status")))
	  (if (not (launch:setup-for-run))
	       (status    (args:get-arg ":status"))
	       (stepname  (args:get-arg "-step")))
	  (if (not (launch:setup))
	      (begin
		(debug:print 0 "Failed to setup, exiting")
		(debug:print 0 *default-log-port* "Failed to setup, exiting")
		(exit 1)))

	  (if (args:get-arg "-runstep")(debug:print-info 1 "Running -runstep, first change to directory " work-area))
	  (if (args:get-arg "-runstep")(debug:print-info 1 *default-log-port* "Running -runstep, first change to directory " work-area))
	  (change-directory work-area)
	  ;; can setup as client for server mode now
	  ;; (client:setup)

	  (if (args:get-arg "-load-test-data")
	      ;; has sub commands that are rdb:
	      ;; DO NOT put this one into either rmt: or open-run-close
	      (tdb:load-test-data run-id test-id))
	  (if (args:get-arg "-setlog")
	      (let ((logfname (args:get-arg "-setlog")))
		(rmt:test-set-log! run-id test-id logfname)))
	  (if (args:get-arg "-set-toplog")
	      ;; DO NOT run remote
	      (tests:test-set-toplog! run-id test-name (args:get-arg "-set-toplog")))
	  (if (args:get-arg "-summarize-items")
	      ;; DO NOT run remote
	      (tests:summarize-items run-id test-id test-name #t)) ;; do force here
	  (if (args:get-arg "-runstep")
	      (if (null? remargs)
		  (begin
		    (debug:print 0 "ERROR: nothing specified to run!")
		    (debug:print-error 0 *default-log-port* "nothing specified to run!")
		    (if db (sqlite3:finalize! db))
		    (exit 6))
		  (let* ((stepname   (args:get-arg "-runstep"))
			 (logprofile (args:get-arg "-logpro"))
			 (logfile    (conc stepname ".log"))
			 (cmd        (if (null? remargs) #f (car remargs)))
			 (params     (if cmd (cdr remargs) '()))
1643
1644
1645
1646
1647
1648
1649
1650

1651
1652
1653
1654
1655
1656
1657
1658
1659
1660

1661
1662
1663
1664
1665
1666
1667
1747
1748
1749
1750
1751
1752
1753

1754
1755
1756
1757
1758
1759
1760
1761
1762
1763

1764
1765
1766
1767
1768
1769
1770
1771







-
+









-
+







				       (else ">&")))
			 (fullcmd    (conc "(" (string-intersperse 
						(cons cmd params) " ")
					   ") " redir " " logfile)))
		    ;; mark the start of the test
		    (rmt:teststep-set-status! run-id test-id stepname "start" "n/a" (args:get-arg "-m") logfile)
		    ;; run the test step
		    (debug:print-info 2 "Running \"" fullcmd "\" in directory \"" startingdir)
		    (debug:print-info 2 *default-log-port* "Running \"" fullcmd "\" in directory \"" startingdir)
		    (change-directory startingdir)
		    (set! exitstat (system fullcmd))
		    (set! *globalexitstatus* exitstat)
		    ;; (change-directory testpath)
		    ;; run logpro if applicable ;; (process-run "ls" (list "/foo" "2>&1" "blah.log"))
		    (if logprofile
			(let* ((htmllogfile (conc stepname ".html"))
			       (oldexitstat exitstat)
			       (cmd         (string-intersperse (list "logpro" logprofile htmllogfile "<" logfile ">" (conc stepname "_logpro.log")) " ")))
			  (debug:print-info 2 "running \"" cmd "\"")
			  (debug:print-info 2 *default-log-port* "running \"" cmd "\"")
			  (change-directory startingdir)
			  (set! exitstat (system cmd))
			  (set! *globalexitstatus* exitstat) ;; no necessary
			  (change-directory testpath)
			  (rmt:test-set-log! run-id test-id htmllogfile)))
		    (let ((msg (args:get-arg "-m")))
		      (rmt:teststep-set-status! run-id test-id stepname "end" exitstat msg logfile))
1681
1682
1683
1684
1685
1686
1687
1688

1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706

1707
1708

1709
1710
1711

1712
1713
1714
1715
1716
1717

1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737

1738
1739

1740
1741
1742
1743
1744
1745
1746
1747

1748
1749

1750
1751
1752

1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766

1767
1768

1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779

1780
1781

1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793

1794

1795
1796

1797
1798














1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
























1818
1819
1820
1821
1822
1823
1824
1825
1826
1827

1828
1829

1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842

1843
1844
1845
1846
1847
1848

1849
1850
1851
1852
1853
1854
1855

1856
1857
1858
1859
1860
1861
1862
1785
1786
1787
1788
1789
1790
1791

1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809

1810
1811

1812
1813
1814

1815
1816
1817
1818
1819
1820

1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840

1841
1842

1843
1844
1845
1846
1847
1848
1849
1850

1851
1852

1853
1854


1855









1856
1857
1858
1859

1860
1861

1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872

1873
1874

1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888

1889
1890

1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907



















1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940

1941
1942

1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955

1956
1957
1958
1959
1960
1961

1962
1963
1964
1965
1966
1967
1968

1969
1970
1971
1972
1973
1974
1975
1976







-
+

















-
+

-
+


-
+





-
+



















-
+

-
+







-
+

-
+

-
-
+
-
-
-
-
-
-
-
-
-




-
+

-
+










-
+

-
+












+
-
+

-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
+

-
+












-
+





-
+






-
+







						 (hash-table-set! res key (args:get-arg key))))
					   (list ":value" ":tol" ":expected" ":first_err" ":first_warn" ":units" ":category" ":variable"))
				 res)))
		(if (and (args:get-arg "-test-status")
			 (or (not state)
			     (not status)))
		    (begin
		      (debug:print 0 "ERROR: You must specify :state and :status with every call to -test-status\n" help)
		      (debug:print-error 0 *default-log-port* "You must specify :state and :status with every call to -test-status\n" help)
		      (if (sqlite3:database? db)(sqlite3:finalize! db))
		      (exit 6)))
		(let* ((msg    (args:get-arg "-m"))
		       (numoth (length (hash-table-keys otherdata))))
		  ;; Convert to rpc inside the tests:test-set-status! call, not here
		  (tests:test-set-status! run-id test-id state newstatus msg otherdata work-area: work-area))))
	  (if (sqlite3:database? db)(sqlite3:finalize! db))
	  (set! *didsomething* #t))))

;;======================================================================
;; Various helper commands can go below here
;;======================================================================

(if (or (args:get-arg "-showkeys")
        (args:get-arg "-show-keys"))
    (let ((db #f)
	  (keys #f))
      (if (not (launch:setup-for-run))
      (if (not (launch:setup))
	  (begin
	    (debug:print 0 "Failed to setup, exiting")
	    (debug:print 0 *default-log-port* "Failed to setup, exiting")
	    (exit 1)))
      (set! keys (rmt:get-keys)) ;;  db))
      (debug:print 1 "Keys: " (string-intersperse keys ", "))
      (debug:print 1 *default-log-port* "Keys: " (string-intersperse keys ", "))
      (if (sqlite3:database? db)(sqlite3:finalize! db))
      (set! *didsomething* #t)))

(if (args:get-arg "-gui")
    (begin
      (debug:print 0 "Look at the dashboard for now")
      (debug:print 0 *default-log-port* "Look at the dashboard for now")
      ;; (megatest-gui)
      (set! *didsomething* #t)))

(if (args:get-arg "-gen-megatest-area")
    (begin
      (genexample:mk-megatest.config)
      (set! *didsomething* #t)))

(if (args:get-arg "-gen-megatest-test")
    (let ((testname (args:get-arg "-gen-megatest-test")))
      (genexample:mk-megatest-test testname)
      (set! *didsomething* #t)))

;;======================================================================
;; Update the database schema, clean up the db
;;======================================================================

(if (args:get-arg "-rebuild-db")
    (begin
      (if (not (launch:setup-for-run))
      (if (not (launch:setup))
	  (begin
	    (debug:print 0 "Failed to setup, exiting") 
	    (debug:print 0 *default-log-port* "Failed to setup, exiting") 
	    (exit 1)))
      ;; keep this one local
      (open-run-close patch-db #f)
      (set! *didsomething* #t)))

(if (args:get-arg "-cleanup-db")
    (begin
      (if (not (launch:setup-for-run))
      (if (not (launch:setup))
	  (begin
	    (debug:print 0 "Failed to setup, exiting") 
	    (debug:print 0 *default-log-port* "Failed to setup, exiting") 
	    (exit 1)))
      ;; keep this one local
      ;; (open-run-close db:clean-up #f)
      (common:cleanup-db)
      (db:multi-db-sync 
       #f ;; do all run-ids
       ;; 'new2old
       'killservers
       'dejunk
       ;; 'adj-testids
       ;; 'old2new
       'new2old
       )
      (set! *didsomething* #t)))

(if (args:get-arg "-mark-incompletes")
    (begin
      (if (not (launch:setup-for-run))
      (if (not (launch:setup))
	  (begin
	    (debug:print 0 "Failed to setup, exiting") b
	    (debug:print 0 *default-log-port* "Failed to setup, exiting")
	    (exit 1)))
      (open-run-close db:find-and-mark-incomplete #f)
      (set! *didsomething* #t)))

;;======================================================================
;; Update the tests meta data from the testconfig files
;;======================================================================

(if (args:get-arg "-update-meta")
    (begin
      (if (not (launch:setup-for-run))
      (if (not (launch:setup))
	  (begin
	    (debug:print 0 "Failed to setup, exiting") 
	    (debug:print 0 *default-log-port* "Failed to setup, exiting") 
	    (exit 1)))
      ;; now can find our db
      ;; keep this one local
      (open-run-close runs:update-all-test_meta #f)
      (set! *didsomething* #t)))

;;======================================================================
;; Start a repl
;;======================================================================

;; fakeout readline

(if (or (getenv "MT_RUNSCRIPT")
(if (or (args:get-arg "-repl")
	(args:get-arg "-repl")
	(args:get-arg "-load"))
    (let* ((toppath (launch:setup-for-run))
    (let* ((toppath (launch:setup))
	   (dbstruct (if toppath (make-dbr:dbstruct path: toppath local: (args:get-arg "-local")) #f)))
      (if dbstruct
	  (cond
	   ((getenv "MT_RUNSCRIPT")
	    ;; How to run megatest scripts
	    ;;
	    ;; #!/bin/bash
	    ;;
	    ;; export MT_RUNSCRIPT=yes
	    ;; megatest << EOF
	    ;; (print "Hello world")
	    ;; (exit)
	    ;; EOF

	    (repl))
	   (else
	  (begin
	    (set! *db* dbstruct)
	    (set! *client-non-blocking-mode* #t)
	    (import extras) ;; might not be needed
	    ;; (import csi)
	    (import readline)
	    (import apropos)
	    ;; (import (prefix sqlite3 sqlite3:)) ;; doesn't work ...
	    (include "readline-fix.scm")
	    (gnu-history-install-file-manager
	     (string-append
	      (or (get-environment-variable "HOME") ".") "/.megatest_history"))
	    (current-input-port (make-gnu-readline-port "megatest> "))
	    (if (args:get-arg "-repl")
		(repl)
		(load (args:get-arg "-load")))
	    (db:close-all dbstruct))
	  (exit))
      (set! *didsomething* #t)))
	    (begin
	      (set! *db* dbstruct)
	      (set! *client-non-blocking-mode* #t)
	      (import extras) ;; might not be needed
	      ;; (import csi)
	      (import readline)
	      (import apropos)
	      ;; (import (prefix sqlite3 sqlite3:)) ;; doesn't work ...
	      (include "readline-fix.scm")
	      (if *use-new-readline*
		  (begin
		    (install-history-file (get-environment-variable "HOME") ".megatest_history") ;;  [homedir] [filename] [nlines])
		    (current-input-port (make-readline-port "megatest> ")))
		  (begin
		    (gnu-history-install-file-manager
		     (string-append
		      (or (get-environment-variable "HOME") ".") "/.megatest_history"))
		    (current-input-port (make-gnu-readline-port "megatest> "))))
	      (if (args:get-arg "-repl")
		  (repl)
		  (load (args:get-arg "-load")))
	      (db:close-all dbstruct))
	    (exit)))
	  (set! *didsomething* #t))))

;;======================================================================
;; Wait on a run to complete
;;======================================================================

(if (and (args:get-arg "-run-wait")
	 (not (or (args:get-arg "-run")
		  (args:get-arg "-runtests")))) ;; run-wait is built into runtests now
    (begin
      (if (not (launch:setup-for-run))
      (if (not (launch:setup))
	  (begin
	    (debug:print 0 "Failed to setup, exiting") 
	    (debug:print 0 *default-log-port* "Failed to setup, exiting") 
	    (exit 1)))
      (operate-on 'run-wait)
      (set! *didsomething* #t)))

;; ;; ;; redo me ;; Not converted to use dbstruct yet
;; ;; ;; redo me ;;
;; ;; ;; redo me (if (args:get-arg "-convert-to-norm")
;; ;; ;; redo me     (let* ((toppath (setup-for-run))
;; ;; ;; redo me 	   (dbstruct (if toppath (make-dbr:dbstruct path: toppath local: #t))))
;; ;; ;; redo me       (for-each 
;; ;; ;; redo me        (lambda (field)
;; ;; ;; redo me 	 (let ((dat '()))
;; ;; ;; redo me 	   (debug:print-info 0 "Getting data for field " field)
;; ;; ;; redo me 	   (debug:print-info 0 *default-log-port* "Getting data for field " field)
;; ;; ;; redo me 	   (sqlite3:for-each-row
;; ;; ;; redo me 	    (lambda (id val)
;; ;; ;; redo me 	      (set! dat (cons (list id val) dat)))
;; ;; ;; redo me 	    (db:get-db db run-id)
;; ;; ;; redo me 	    (conc "SELECT id," field " FROM tests;"))
;; ;; ;; redo me 	   (debug:print-info 0 "found " (length dat) " items for field " field)
;; ;; ;; redo me 	   (debug:print-info 0 *default-log-port* "found " (length dat) " items for field " field)
;; ;; ;; redo me 	   (let ((qry (sqlite3:prepare db (conc "UPDATE tests SET " field "=? WHERE id=?;"))))
;; ;; ;; redo me 	     (for-each
;; ;; ;; redo me 	      (lambda (item)
;; ;; ;; redo me 		(let ((newval ;; (sdb:qry 'getid 
;; ;; ;; redo me 		       (cadr item))) ;; )
;; ;; ;; redo me 		  (if (not (equal? newval (cadr item)))
;; ;; ;; redo me 		      (debug:print-info 0 "Converting " (cadr item) " to " newval " for test #" (car item)))
;; ;; ;; redo me 		      (debug:print-info 0 *default-log-port* "Converting " (cadr item) " to " newval " for test #" (car item)))
;; ;; ;; redo me 		  (sqlite3:execute qry newval (car item))))
;; ;; ;; redo me 	      dat)
;; ;; ;; redo me 	     (sqlite3:finalize! qry))))
;; ;; ;; redo me        (db:close-all dbstruct)
;; ;; ;; redo me        (list "uname" "rundir" "final_logf" "comment"))
;; ;; ;; redo me       (set! *didsomething* #t)))

1883
1884
1885
1886
1887
1888
1889
1890

1891
1892
1893
1894
1895
1896
1897
1898

1899
1900
1901
1902
1903
1904
1997
1998
1999
2000
2001
2002
2003

2004
2005
2006
2007
2008
2009
2010
2011

2012
2013
2014
2015
2016
2017
2018







-
+







-
+






;;======================================================================
;; Exit and clean up
;;======================================================================

(if *runremote* (close-all-connections!))

(if (not *didsomething*)
    (debug:print 0 help))
    (debug:print 0 *default-log-port* help))

(set! *time-to-exit* #t)
(thread-join! *watchdog*)

(if (not (eq? *globalexitstatus* 0))
    (if (or (args:get-arg "-run")(args:get-arg "-runtests")(args:get-arg "-runall"))
        (begin
           (debug:print 0 "NOTE: Subprocesses with non-zero exit code detected: " *globalexitstatus*)
           (debug:print 0 *default-log-port* "NOTE: Subprocesses with non-zero exit code detected: " *globalexitstatus*)
           (exit 0))
        (case *globalexitstatus*
         ((0)(exit 0))
         ((1)(exit 1))
         ((2)(exit 2))
         (else (exit 3)))))

Modified mt.scm from [44b2cf6841] to [6528ed8e20].

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
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
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
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







-
+



-
-
+
+










-
-
+
+







-
-
+
+














-
+













-
+














-
+
















+
-
+

















-
+
















-
+







	     (offset   0)
	     (limit    500))
    ;; (print "runsdat: " runsdat)
    (let* ((header    (vector-ref runsdat 0))
	   (runslst   (vector-ref runsdat 1))
	   (full-list (append res runslst))
	   (have-more (eq? (length runslst) limit)))
      ;; (debug:print 0 "header: " header " runslst: " runslst " have-more: " have-more)
      ;; (debug:print 0 *default-log-port* "header: " header " runslst: " runslst " have-more: " have-more)
      (if have-more 
	  (let ((new-offset (+ offset limit))
		(next-batch (rmt:get-runs-by-patt keys runnamepatt targpatt offset limit #f)))
	    (debug:print-info 4 "More than " limit " runs, have " (length full-list) " runs so far.")
	    (debug:print-info 0 "next-batch: " next-batch)
	    (debug:print-info 4 *default-log-port* "More than " limit " runs, have " (length full-list) " runs so far.")
	    (debug:print-info 0 *default-log-port* "next-batch: " next-batch)
	    (loop next-batch
		  full-list
		  new-offset
		  limit))
	 (vector header full-list)))))

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

(define (mt:get-tests-for-run run-id testpatt states status #!key (not-in #t) (sort-by 'event_time) (sort-order "ASC") (qryvals #f))
  (let loop ((testsdat (rmt:get-tests-for-run run-id testpatt states status 0 500 not-in sort-by sort-order qryvals))
(define (mt:get-tests-for-run run-id testpatt states status #!key (not-in #t) (sort-by 'event_time) (sort-order "ASC") (qryvals #f)(last-update #f))
  (let loop ((testsdat (rmt:get-tests-for-run run-id testpatt states status 0 500 not-in sort-by sort-order qryvals last-update 'normal))
	     (res      '())
	     (offset   0)
	     (limit    500))
    (let* ((full-list (append res testsdat))
	   (have-more (eq? (length testsdat) limit)))
      (if have-more 
	  (let ((new-offset (+ offset limit)))
	    (debug:print-info 4 "More than " limit " tests, have " (length full-list) " tests so far.")
	    (loop (rmt:get-tests-for-run run-id testpatt states status new-offset limit not-in sort-by sort-order qryvals)
	    (debug:print-info 4 *default-log-port* "More than " limit " tests, have " (length full-list) " tests so far.")
	    (loop (rmt:get-tests-for-run run-id testpatt states status new-offset limit not-in sort-by sort-order qryvals last-update 'normal)
		  full-list
		  new-offset
		  limit))
	  full-list))))

(define (mt:lazy-get-prereqs-not-met run-id waitons ref-item-path #!key (mode '(normal))(itemmaps #f) )
  (let* ((key    (list run-id waitons ref-item-path mode))
	 (res    (hash-table-ref/default *pre-reqs-met-cache* key #f))
	 (useres (let ((last-time (if (vector? res) (vector-ref res 0) #f)))
		   (if last-time
		       (< (current-seconds)(+ last-time 5))
		       #f))))
    (if useres
	(let ((result (vector-ref res 1)))
	  (debug:print 4 "Using lazy value res: " result)
	  (debug:print 4 *default-log-port* "Using lazy value res: " result)
	  result)
	(let ((newres (rmt:get-prereqs-not-met run-id waitons ref-item-path mode: mode itemmaps: itemmaps)))
	  (hash-table-set! *pre-reqs-met-cache* key (vector (current-seconds) newres))
	  newres))))

(define (mt:get-run-stats dbstruct run-id)
;;  Get run stats from local access, move this ... but where?
  (db:get-run-stats dbstruct run-id))

(define (mt:discard-blocked-tests run-id failed-test tests test-records)
  (if (null? tests)
      tests
      (begin
	(debug:print-info 1 "Discarding tests from " tests " that are waiting on " failed-test)
	(debug:print-info 1 *default-log-port* "Discarding tests from " tests " that are waiting on " failed-test)
	(let loop ((testn (car tests))
		   (remt  (cdr tests))
		   (res   '()))
	  (let* ((test-dat (hash-table-ref/default test-records testn (vector #f #f '())))
		 (waitons  (vector-ref test-dat 2)))
	    ;; (print "mt:discard-blocked-tests run-id: " run-id " failed-test: " failed-test " testn: " testn " with waitons: " waitons)
	    (if (null? remt)
		(let ((new-res (reverse res)))
		  ;; (print "       new-res: " new-res)
		  new-res)
		(loop (car remt)
		      (cdr remt)
		      (if (member failed-test waitons)
			  (begin
			    (debug:print 0 "Discarding test " testn "(" test-dat ") due to " failed-test)
			    (debug:print 0 *default-log-port* "Discarding test " testn "(" test-dat ") due to " failed-test)
			    res)
			  (cons testn res)))))))))

;;======================================================================
;;  T R I G G E R S
;;======================================================================

(define (mt:process-triggers run-id test-id newstate newstatus)
  (let* ((test-dat      (rmt:get-test-info-by-id run-id test-id)))
    (if test-dat
	(let* ((test-rundir   ;; (rmt:sdb-qry 'getstr ;; (filedb:get-path *fdb*
		(dbr:test-rundir test-dat)) ;; ) ;; )
	       (test-name     (dbr:test-testname test-dat))
	       (tconfig       #f)
	       (state         (if newstate  newstate  (dbr:test-state  test-dat)))
	       (status        (if newstatus newstatus (dbr:test-status test-dat))))
	  (if (and test-name
	  (if (and test-rundir   ;; #f means no dir set yet
		   test-rundir   ;; #f means no dir set yet
		   (file-exists? test-rundir)
		   (directory? test-rundir))
	      (call-with-environment-variables
	       (list (cons "MT_TEST_NAME" test-name)
		     (cons "MT_TEST_RUN_DIR" test-rundir)
		     (cons "MT_ITEMPATH"     (dbr:test-item-path test-dat)))
	       (lambda ()
		 (push-directory test-rundir)
		 (set! tconfig (mt:lazy-read-test-config test-name))
		 (for-each (lambda (trigger)
			     (let ((cmd  (configf:lookup tconfig "triggers" trigger))
				   (logf (conc  test-rundir "/last-trigger.log")))
			       (if cmd
				   ;; Putting the commandline into ( )'s means no control over the shell. 
				   ;; stdout and stderr will be caught in the NBFAKE or mt_launch.log files
				   ;; or equivalent. No need to do this. Just run it?
				   (let ((fullcmd (conc cmd " " test-id " " test-rundir " " trigger "&")))
				     (debug:print-info 0 "TRIGGERED on " trigger ", running command " fullcmd)
				     (debug:print-info 0 *default-log-port* "TRIGGERED on " trigger ", running command " fullcmd)
				     (process-run fullcmd)))))
			   (list
			    (conc state "/" status)
			    (conc state "/")
			    (conc "/" status)))
		 (pop-directory))
	       ))))))

;;======================================================================
;;  S T A T E   A N D   S T A T U S   F O R   T E S T S 
;;======================================================================

;; speed up for common cases with a little logic
(define (mt:test-set-state-status-by-id run-id test-id newstate newstatus newcomment)
  (if (not (and run-id test-id))
      (begin
	(debug:print 0 "ERROR: bad data handed to mt:test-set-state-status-by-id, run-id=" run-id ", test-id=" test-id ", newstate=" newstate)
	(debug:print-error 0 *default-log-port* "bad data handed to mt:test-set-state-status-by-id, run-id=" run-id ", test-id=" test-id ", newstate=" newstate)
	(print-call-chain (current-error-port))
	#f)
      (begin
	(cond
	 ((and newstate newstatus newcomment)
	  (rmt:general-call 'state-status-msg run-id newstate newstatus newcomment test-id))
	 ((and newstate newstatus)
212
213
214
215
216
217
218
219

220
221
222
213
214
215
216
217
218
219

220
221
222
223







-
+



		      (hash-table-set! *testconfigs* test-name newtcfg)
		      (if old-link-tree 
			  (setenv "MT_LINKTREE" old-link-tree)
			  (unsetenv "MT_LINKTREE"))
		      newtcfg))
		  (if (null? tal)
		      (begin
			(debug:print 0 "ERROR: No readable testconfig found for " test-name)
			(debug:print-error 0 *default-log-port* "No readable testconfig found for " test-name)
			#f)
		      (loop (car tal)(cdr tal))))))))))

Modified multi-dboard.scm from [e9e822b1ad] to [604c83dc90].

210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224







-
+







			((-1) "monitor.db")
			((0) "main.db")
			(else (conc run-id ".db")))
		      #f)))
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "ERROR: Couldn't create path to " dbdir)
       (debug:print-error 0 *default-log-port* "Couldn't create path to " dbdir)
       (exit 1))
     (if (not (directory? dbdir))(create-directory dbdir #t)))
    (if fname
	(conc dbdir "/" fname)
	dbdir)))

;; -1 => monitor.db
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
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







-
+













+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







			     #f)))))
    (if db
	db ;; merely return the already opened db
	(let* ((dbfile (areadb:dbfile-path areadat run-id)) ;; not already opened, so open it
	       (db     (if (file-exists? dbfile)
			   (open-database dbfile)
			   (begin
			     (debug:print 0 "ERROR: I was asked to open " dbfile ", but file does not exist or is not readable.")
			     (debug:print-error 0 *default-log-port* "I was asked to open " dbfile ", but file does not exist or is not readable.")
			     #f))))
	  (case run-id
	    ((-1)(areadat-monitordb-set! areadat db))
	    ((0) (areadat-maindb-set!    areadat db))
	    (else (rundat-db-set!        rundat  db)))
	  db))))

;; populate the areadat tests info, does NOT fill the tests data itself unless asked
;;
(define (areadb:populate-run-info areadat)
  (let* ((runs   (or (areadat-runs areadat) (make-hash-table)))
	 (keys   (areadat-run-keys areadat))
	 (maindb (areadb:open areadat 0)))
    (if maindb
    (query (for-each-row (lambda (row)
			   (let ((id  (list-ref row 0))
				 (dat (apply make-rundat (append row (list #f #f))))) ;; add placeholders for tests and db
			     (print row)
			     (hash-table-set! runs id dat))))
	   (sql maindb (conc "SELECT id,"
			     (string-intersperse keys "||'/'||")
			     ",runname,state,status,event_time FROM runs WHERE state != 'deleted';")))
	(query (for-each-row (lambda (row)
			       (let ((id  (list-ref row 0))
				     (dat (apply make-rundat (append row (list #f #f))))) ;; add placeholders for tests and db
				 (print row)
				 (hash-table-set! runs id dat))))
	       (sql maindb (conc "SELECT id,"
				 (string-intersperse keys "||'/'||")
				 ",runname,state,status,event_time FROM runs WHERE state != 'deleted';")))
	(debug:print-error 0 *default-log-port* "no main.db found at "  (areadb:dbfile-path areadat 0)))
    areadat))

;; given an areadat and target/runname patt fill up runs data
;;
;; ?????/

;; given a list of run-ids refresh/retrieve runs data into areadat
319
320
321
322
323
324
325
326

327
328
329
330

331
332
333
334
335
336
337
321
322
323
324
325
326
327

328
329
330
331

332
333
334
335
336
337
338
339







-
+



-
+







				"Areas"
				(string-intersperse (tree:node->path current-tree current-node) "/")))
	    (current-matrix (if (null? tab-ids) #f (tab-matrix current-tab)))
	    (seen-nodes     (make-hash-table))
	    (path-changed   (if current-tab
				(equal? current-path (tab-view-path current-tab))
				#t)))
       ;; (debug:print-info 0 "Current path: " current-path)
       ;; (debug:print-info 0 *default-log-port* "Current path: " current-path)
       ;; now for each area in the window gather the data
       (if path-changed
	   (begin
	     (debug:print-info 0 "clearing matrix - path changed")
	     (debug:print-info 0 *default-log-port* "clearing matrix - path changed")
	     (dboard:clear-matrix current-tab)))
       (for-each
	(lambda (area-name)
	  ;; (print "Processing for area-name " area-name)
	  (let* ((area-dat  (hash-table-ref areas area-name))
		 (area-path (areadat-path   area-dat))
		 (runs      (areadat-runs   area-dat)))
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399

400
401
402
403
404
405
406
387
388
389
390
391
392
393

394
395
396
397
398
399
400

401
402
403
404
405
406
407
408







-
+






-
+







		     ;; (print "obj: " obj ", id: " id ", state: " state)
		     (let* ((tree-path (tree:node->path obj id))
			    (area      (car tree-path))
			    (areadat-path (cdr tree-path)))
		       #f
		       ;; (test-id  (tree-path->test-id (cdr run-path))))
		       ;; (if test-id
		       ;;    (hash-table-set! (dboard:data-get-curr-test-ids *data*)
		       ;;    (hash-table-set! (dboard:data-curr-test-ids *data*)
		       ;;		     window-id test-id))
		       ;; (print "path: " (tree:node->path obj id) " test-id: " test-id))))))
		       )))))
    ;; (iup:attribute-set! tb "VALUE" "0")
    ;; (iup:attribute-set! tb "NAME" "Runs")
    ;; (iup:attribute-set! tb "ADDEXPANDED" "NO")
    ;; (dboard:data-set-tests-tree! *data* tb)
    ;; (dboard:data-tests-tree-set! *data* tb)
    tb))

;;======================================================================
;; M A I N   M A T R I X
;;======================================================================

;; General displayer
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
420
421
422
423
424
425
426

427
428
429
430
431
432
433
434







-
+







			   #:numcol-visible 3
			   #:numlin-visible 20
			   #:click-cb (lambda (obj lin col status)
					(print "obj: " obj " lin: " lin " col: " col " status: " status " value: " (iup:attribute obj "VALUE"))))))
    
    ;; (iup:attribute-set! view-matrix "RESIZEMATRIX" "YES")
    (iup:attribute-set! view-matrix "WIDTH0" "100")
    ;; (dboard:data-set-runs-matrix! *data* runs-matrix)
    ;; (dboard:data-runs-matrix-set! *data* runs-matrix)
    ;; (iup:hbox
    ;;  (iup:frame 
    ;;   #:title "Runs browser"
    ;;   (iup:vbox
    view-matrix))

;;======================================================================
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515







-
+

















-
+







	 (rows      (tab-rows      tab-dat))
	 (used-cols (hash-table-values headers))
	 (used-rows (hash-table-values rows))
	 (touched   (make-hash-table)) ;; (vector row col) ==> true, touched cell
	 (view-type (dboard:get-view-type keys current-path))
	 (changed   #f)
	 (state-statuses  (list "PASS" "FAIL" "WARN" "CHECK" "SKIP" "RUNNING" "LAUNCHED")))
    (debug:print 0 "current-matrix=" current-matrix)
    ;; (debug:print 0 *default-log-port* "current-matrix=" current-matrix)
    (case view-type
      ((areas) ;; find row for this area, if not found, create new entry
       (let* ((curr-rownum (hash-table-ref/default rows area-name #f))
	      (next-rownum (+ (apply max (cons 0 used-rows)) 1))
	      (rownum      (or curr-rownum next-rownum))
	      (coord       (conc rownum ":0")))
	 (if (not curr-rownum)(hash-table-set! rows area-name rownum))
	 (if (not (equal? (iup:attribute current-matrix coord) area-name))
	     (begin
	       (let loop ((hed  (car state-statuses))
			  (tal  (cdr state-statuses))
			  (count 1))
		 (if (not (equal? (iup:attribute current-matrix (conc "0:" count)) hed))
		     (iup:attribute-set! current-matrix (conc "0:" count) hed))
		 (iup:attribute-set! current-matrix (conc rownum ":" count) "0")
		 (if (not (null? tal))
		     (loop (car tal)(cdr tal)(+ count 1))))
	       (debug:print-info 0 "view-type=" view-type ", rownum=" rownum ", curr-rownum=" curr-rownum ", next-rownum=" next-rownum ", coord=" coord ", area-name=" area-name)
	       (debug:print-info 0 *default-log-port* "view-type=" view-type ", rownum=" rownum ", curr-rownum=" curr-rownum ", next-rownum=" next-rownum ", coord=" coord ", area-name=" area-name)
	       (iup:attribute-set! current-matrix coord area-name)
	       (set! changed #t))))))
    (if changed (iup:attribute-set! current-matrix "REDRAW" "ALL"))))
	     

       
   ;; (dboard:clear-matrix current-matrix used-cols used-rows touched) ;; clear all
569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
571
572
573
574
575
576
577

578
579
580
581
582
583
584
585







-
+







			       area-panels))
	   (tabs     (data-tabs data)))
      (if (not (null? area-names))
	  (let loop ((index 0)
		     (hed   (car area-names))
		     (tal   (cdr area-names)))
	    ;; (hash-table-set! tabs index hed)
	    (debug:print 0 "Adding area " hed " with index " index " to dashboard")
	    (debug:print 0 *default-log-port* "Adding area " hed " with index " index " to dashboard")
	    (iup:attribute-set! tabtop (conc "TABTITLE" index) hed)
	    (if (not (null? tal))
		(loop (+ index 1)(car tal)(cdr tal)))))
      tabtop))))


;;======================================================================
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741
742
743

744
745
746
747
748
749
750
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744

745
746
747
748
749
750
751
752







-
+









-
+







	  (file-name     (pathname-strip-directory fname))
	  (curr-mtcfgdat (find-config "megatest.config"
				      toppath: (or (get-environment-variable "MT_RUN_AREA_HOME")(current-directory))))
	  (curr-mtcfg    (if (and curr-mtcfgdat (not (null? curr-mtcfgdat)))(cadr curr-mtcfgdat) #f))
	  (curr-mtpath   (if curr-mtcfg (car curr-mtcfgdat) #f)))
     (if curr-mtpath
	 (begin
	   (debug:print-info 0 "Creating config file " fname)
	   (debug:print-info 0 *default-log-port* "Creating config file " fname)
	   (if (not (file-exists? dirname))
	       (create-directory dirname #t))
	   (with-output-to-file fname
	     (lambda ()
	       (let ((aname (pathname-strip-directory curr-mtpath)))
		 (print "[" aname "]")
		 (print  "path " curr-mtpath))))
	   #t)
	 (begin
	   (debug:print-info 0 "Need to create a config but no megatest.config found: " curr-mtcfgdat)
	   (debug:print-info 0 *default-log-port* "Need to create a config but no megatest.config found: " curr-mtcfgdat)
	   #f))))
;; )

(define (dboard:read-mtconf apath)
  (let* ((mtconffile  (conc apath "/megatest.config")))
    (call-with-environment-variables
     (list (cons "MT_RUN_AREA_HOME" apath))

Modified newdashboard.scm from [4d9a3810fc] to [21f36bb36f].

65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+







		 0))

(if (args:get-arg "-h")
    (begin
      (print help)
      (exit)))

(if (not (launch:setup-for-run))
(if (not (launch:setup))
    (begin
      (print "Failed to find megatest.config, exiting") 
      (exit 1)))

;; (if (args:get-arg "-host")
;;     (begin
;;       (set! *runremote* (string-split (args:get-arg "-host" ":")))
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273







-
+








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

(define (tree-path->test-id path)
  (if (not (null? path))
      (hash-table-ref/default (dboard:data-get-path-test-ids *data*) path #f)
      (hash-table-ref/default (dboard:data-path-test-ids *data*) path #f)
      #f))

(define (test-panel window-id)
  (let* ((curr-row-num 0)
	 (viewlog    (lambda (x)
		       (if (file-exists? logfile)
					;(system (conc "firefox " logfile "&"))
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357







-
+







			    #:numlin 50
			    #:numcol-visible 8
			    #:numlin-visible 8))
	 (updater          (lambda (testdat)
			     (test-update window-id testdat run-info-matrix test-info-matrix test-run-matrix meta-dat-matrix steps-matrix data-matrix))))

    ;; Set the updater in updaters
    (hash-table-set! (dboard:data-get-updaters *data*) window-id updater)
    (hash-table-set! (dboard:data-updaters *data*) window-id updater)
    ;; 
    (for-each
     (lambda (mat)
       ;; (iup:attribute-set! mat "0:1" "Value")
       ;; (iup:attribute-set! mat "0:0" "Var")
       (iup:attribute-set! mat "HEIGHT0" 0)
       (iup:attribute-set! mat "ALIGNMENT1" "ALEFT")
445
446
447
448
449
450
451
452

453
454
455
456
457
458

459
460
461
462
463
464
465
466
467

468
469
470

471
472
473
474
475
476
477
445
446
447
448
449
450
451

452
453
454
455
456
457

458
459
460
461
462
463
464
465
466

467
468
469

470
471
472
473
474
475
476
477







-
+





-
+








-
+


-
+







   (let* ((tb      (iup:treebox
		    #:selection-cb
		    (lambda (obj id state)
		      ;; (print "obj: " obj ", id: " id ", state: " state)
		      (let* ((run-path (tree:node->path obj id))
			     (test-id  (tree-path->test-id (cdr run-path))))
			(if test-id
			    (hash-table-set! (dboard:data-get-curr-test-ids *data*)
			    (hash-table-set! (dboard:data-curr-test-ids *data*)
					     window-id test-id))
			(print "path: " (tree:node->path obj id) " test-id: " test-id))))))
     (iup:attribute-set! tb "VALUE" "0")
     (iup:attribute-set! tb "NAME" "Runs")
     ;;(iup:attribute-set! tb "ADDEXPANDED" "NO")
     (dboard:data-set-tests-tree! *data* tb)
     (dboard:data-tests-tree-set! *data* tb)
     tb)
   (test-panel window-id)))

;; The function to update the fields in the test view panel
(define (test-update window-id testdat run-info-matrix test-info-matrix test-run-matrix meta-dat-matrix steps-matrix data-matrix)
  ;; get test-id
  ;; then get test record
  (if testdat
      (let* ((test-id      (hash-table-ref/default (dboard:data-get-curr-test-ids *data*) window-id #f))
      (let* ((test-id      (hash-table-ref/default (dboard:data-curr-test-ids *data*) window-id #f))
	     (test-data    (hash-table-ref/default testdat test-id #f))
	     (run-id       (dbr:test-run_id test-data))
	     (targ/runname (hash-table-ref/default (dboard:data-get-run-keys *data*) 
	     (targ/runname (hash-table-ref/default (dboard:data-run-keys *data*) 
						   run-id
						   '()))
	     (target       (if (null? targ/runname) "" (string-intersperse (reverse (cdr (reverse targ/runname))) "/")))
	     (runname      (if (null? targ/runname) "" (car (cdr targ/runname))))
	     (steps-dat    (tests:get-compressed-steps *dbstruct-local* run-id test-id)))
				
	(if test-data
560
561
562
563
564
565
566
567

568
569
570
571
572
573
574
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574







-
+







			   #:numlin-visible 7
			   #:click-cb (lambda (obj lin col status)
					(print "obj: " obj " lin: " lin " col: " col " status: " status)))))

    (iup:attribute-set! runs-matrix "RESIZEMATRIX" "YES")
    (iup:attribute-set! runs-matrix "WIDTH0" "100")

    (dboard:data-set-runs-matrix! *data* runs-matrix)
    (dboard:data-runs-matrix-set! *data* runs-matrix)
    (iup:hbox
     (iup:frame 
      #:title "Runs browser"
      (iup:vbox
       runs-matrix)))))

;; Browse and control a single run
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626
627
628
629
630
631


632
633

634
635
609
610
611
612
613
614
615

616
617
618
619
620
621
622
623
624
625
626
627
628
629


630
631
632

633
634
635







-
+













-
-
+
+

-
+


	 (testpatt "%")
	 (keypatts (map (lambda (k)(list k "%")) keys))
	 (states   '())
	 (statuses '())
	 (nextmintime (current-milliseconds))
	 (my-window-id *current-window-id*))
    (set! *current-window-id* (+ 1 *current-window-id*))
    (dboard:data-set-runs! *data* data) ;; make this data available to the rest of the application
    (dboard:data-runs-set! *data* data) ;; make this data available to the rest of the application
    (iup:show (main-panel my-window-id))
    ;; Yes, running iup:show will pop up a new panel
    ;; (iup:show (main-panel my-window-id))
    (iup:callback-set! *tim*
		       "ACTION_CB"
		       (lambda (x)
			 ;; Want to dedicate no more than 50% of the time to this so skip if
			 ;; 2x delta time has not passed since last query
			 (if (< nextmintime (current-milliseconds))
			     (let* ((starttime (current-milliseconds))
				    (changes   (dcommon:run-update keys data runname keypatts testpatt states statuses 'full my-window-id))
				    (endtime   (current-milliseconds)))
			       (set! nextmintime (+ endtime (* 2 (- endtime starttime))))
			       (debug:print 11 "CHANGE(S): " (car changes) "..."))
			     (debug:print-info 11 "Server overloaded"))))))
			       (debug:print 11 *default-log-port* "CHANGE(S): " (car changes) "..."))
			     (debug:print-info 11 *default-log-port* "Server overloaded"))))))

(dboard:data-set-updaters! *data* (make-hash-table))
(dboard:data-updaters-set! *data* (make-hash-table))
(newdashboard *dbstruct-local*)    
(iup:main-loop)

Modified nmsg-transport.scm from [c28712df60] to [b30844cb1a].

60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74







-
+







(define *heartbeat-mutex* (make-mutex))

;;======================================================================
;; S E R V E R
;;======================================================================

(define (nmsg-transport:run dbstruct hostn run-id server-id #!key (retrynum 1000))
  (debug:print 2 "Attempting to start the server ...")
  (debug:print 2 *default-log-port* "Attempting to start the server ...")
  (let* ((start-port      (portlogger:open-run-close portlogger:find-port))
	 (server-thread   (make-thread (lambda ()
					 (nmsg-transport:try-start-server dbstruct run-id start-port server-id))
				       "server thread"))
	 (tdbdat          (tasks:open-db)))
    (thread-start! server-thread)
    (thread-sleep! 0.1)
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
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







-
+




-
+







-
+

-
+







	  (tasks:server-set-state! (db:delay-if-busy tdbdat) server-id "running")
	  (thread-start! (make-thread
			  (lambda ()(nmsg-transport:keep-running server-id run-id))
			  "keep running"))
	  (thread-join! server-thread))
	(if (> retrynum 0)
	    (begin
	      (debug:print 0 "WARNING: Failed to connect to server (self) on host " hostn ":" start-port ", trying again.")
	      (debug:print 0 *default-log-port* "WARNING: Failed to connect to server (self) on host " hostn ":" start-port ", trying again.")
	      (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id "failed to start, never received server alive signature")
	      (portlogger:open-run-close portlogger:set-failed start-port)
	      (nmsg-transport:run dbstruct hostn run-id server-id))
	    (begin
	      (debug:print 0 "ERROR: could not find an open port to start server on. Giving up")
	      (debug:print-error 0 *default-log-port* "could not find an open port to start server on. Giving up")
	      (exit 1))))))

(define (nmsg-transport:try-start-server dbstruct run-id portnum server-id)
  (let ((repsoc (nn-socket 'rep)))
    (nn-bind repsoc (conc "tcp://*:" portnum))
    (let loop ((msg-in (nn-recv repsoc)))
      (let* ((dat    (db:string->obj msg-in transport: 'nmsg)))
	(debug:print 0 "server, received: " dat)
	(debug:print 0 *default-log-port* "server, received: " dat)
	(let ((result (api:execute-requests dbstruct dat)))
	  (debug:print 0 "server, sending: " result)
	  (debug:print 0 *default-log-port* "server, sending: " result)
	  (nn-send repsoc (db:obj->string result  transport: 'nmsg)))
	(loop (nn-recv repsoc))))))

;; all routes though here end in exit ...
;;
(define (nmsg-transport:launch run-id)
  (let* ((tdbdat   (tasks:open-db))
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
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







-
+











-
+



-
+







    ;;       (daemon:ize)
    ;;       (if *alt-log-file* ;; we should re-connect to this port, I think daemon:ize disrupts it
    ;;           (begin
    ;;     	(current-error-port *alt-log-file*)
    ;;     	(current-output-port *alt-log-file*)))))
    (if (server:check-if-running run-id)
	(begin
	  (debug:print-info 0 "Server for run-id " run-id " already running")
	  (debug:print-info 0 *default-log-port* "Server for run-id " run-id " already running")
	  (exit 0)))
    (let loop ((server-id (tasks:server-lock-slot (db:delay-if-busy tdbdat) run-id))
	       (remtries  4))
      (if (not server-id)
	  (if (> remtries 0)
	      (begin
		(thread-sleep! 2)
		(if (not (server:check-if-running run-id))
		    (loop (tasks:server-lock-slot (db:delay-if-busy tdbdat) run-id)
			  (- remtries 1))
		    (begin
		      (debug:print-info 0 "Another server took the slot, exiting")
		      (debug:print-info 0 *default-log-port* "Another server took the slot, exiting")
		      (exit 0))))
	      (begin
		;; since we didn't get the server lock we are going to clean up and bail out
		(debug:print-info 2 "INFO: server pid=" (current-process-id) ", hostname=" (get-host-name) " not starting due to other candidates ahead in start queue")
		(debug:print-info 2 *default-log-port* "INFO: server pid=" (current-process-id) ", hostname=" (get-host-name) " not starting due to other candidates ahead in start queue")
		(tasks:server-delete-records-for-this-pid (db:delay-if-busy tdbdat) " http-transport:launch")
		))
	  ;; locked in a server id, try to start up
	  (nmsg-transport:run dbstruct hostn run-id server-id))
      (set! *didsomething* #t)
      (exit))))

182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196







-
+







	 (dat     (vector "ping" our-key))
	 (result  (condition-case 
		   (nmsg-transport:client-api-send-receive-raw req dat timeout: timeout)
		   ((timeout)(set! success #f) #f)))
	 (key     (if success 
		      (vector-ref result 1)
		      #f)))
    (debug:print 0 "success=" success ", key=" key ", expected-key=" expected-key ", equal? " (equal? key expected-key))
    (debug:print 0 *default-log-port* "success=" success ", key=" key ", expected-key=" expected-key ", equal? " (equal? key expected-key))
    (if (and success
	     (or (not expected-key) ;; just getting a reply is good enough then
		 (equal? key expected-key)))
	(if return-socket
	    req
	    (begin
	      (if (not socket)(nn-close req)) ;; don't want a side effect of closing socket if handed it
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230







-
+







			   (set! success #t)
			   (set! result (db:string->obj res transport: 'nmsg))))
		       "send-recv"))
	 (timeout     (make-thread
		       (lambda ()
			 (let loop ((count 0))
			   (thread-sleep! 1)
			   (debug:print-info 1 "send-receive-raw, still waiting after " count " seconds...")
			   (debug:print-info 1 *default-log-port* "send-receive-raw, still waiting after " count " seconds...")
			   (if (and keepwaiting (< count timeout)) ;; yes, this is very aproximate
			       (loop (+ count 1))))
			 (if keepwaiting
			     (begin
			       (print "timeout waiting for ping")
			       (thread-terminate! send-recv))))
		       "timeout")))
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
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







-
-
+
+

-
+



















-
+







     (if success (thread-terminate! timeout)))
    ;; raise timeout error if timed out
    (if success
	(if (and (vector? result)
		 (vector-ref result 0)) ;; did it fail at the server?
	    result                ;; nope, all good
	    (begin
	      (debug:print 0 "ERROR: error occured at server, info=" (vector-ref result 2))
	      (debug:print 0 " client call chain:")
	      (debug:print-error 0 *default-log-port* "error occured at server, info=" (vector-ref result 2))
	      (debug:print 0 *default-log-port* " client call chain:")
	      (print-call-chain (current-error-port))
	      (debug:print 0 " server call chain:")
	      (debug:print 0 *default-log-port* " server call chain:")
	      (pp (vector-ref result 1) (current-error-port))
	      (signal (vector-ref result 0))))
	(signal (make-composite-condition
		 (make-property-condition 'timeout 'message "nmsg-transport:client-api-send-receive-raw timed out talking to server"))))))

;; run nmsg-transport:keep-running in a parallel thread to monitor that the db is being 
;; used and to shutdown after sometime if it is not.
;;
(define (nmsg-transport:keep-running server-id run-id)
  ;; if none running or if > 20 seconds since 
  ;; server last used then start shutdown
  ;; This thread waits for the server to come alive
  (let* ((server-info (let loop ()
                        (let ((sdat #f))
                          (mutex-lock! *heartbeat-mutex*)
                          (set! sdat *server-info*)
                          (mutex-unlock! *heartbeat-mutex*)
                          (if sdat 
			      (begin
				(debug:print-info 0 "keep-running got sdat=" sdat)
				(debug:print-info 0 *default-log-port* "keep-running got sdat=" sdat)
				sdat)
                              (begin
                                (thread-sleep! 0.5)
                                (loop))))))
         (iface       (car server-info))
         (port        (cadr server-info))
         (last-access 0)
295
296
297
298
299
300
301
302

303
304
305

306
307
308
309

310
311
312
313
314
315
316
295
296
297
298
299
300
301

302
303
304

305
306
307
308

309
310
311
312
313
314
315
316







-
+


-
+



-
+







        (set! last-access *last-db-access*)
        (mutex-unlock! *heartbeat-mutex*)
	(db:sync-touched *inmemdb* run-id force-sync: #t)
        (if (and *server-run*
	       (> (+ last-access server-timeout)
		  (current-seconds)))
            (begin
              (debug:print-info 0 "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
              (debug:print-info 0 *default-log-port* "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
              (loop 0))
            (begin
              (debug:print-info 0 "Starting to shutdown the server.")
              (debug:print-info 0 *default-log-port* "Starting to shutdown the server.")
              (set! *time-to-exit* #t)
	      (db:sync-touched *inmemdb* run-id force-sync: #t)
              (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id " http-transport:keep-running")
              (debug:print-info 0 "Server shutdown complete. Exiting")
              (debug:print-info 0 *default-log-port* "Server shutdown complete. Exiting")
              (exit)
	      ))))))

;;======================================================================
;; C L I E N T S
;;======================================================================

337
338
339
340
341
342
343
344

345
346
347
348
349
350

351
352

353
354
355
356
357
358
337
338
339
340
341
342
343

344
345
346
347
348
349

350
351

352
353
354
355
356
357
358







-
+





-
+

-
+






;;======================================================================

;; DO NOT USE
;;
(define (nmsg-transport:client-signal-handler signum)
  (handle-exceptions
   exn
   (debug:print " ... exiting ...")
   (debug:print 0 *default-log-port* " ... exiting ...")
   (let ((th1 (make-thread (lambda ()
			     (if (not *received-response*)
				 (receive-message* *runremote*))) ;; flush out last call if applicable
			   "eat response"))
	 (th2 (make-thread (lambda ()
			     (debug:print 0 "ERROR: Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
			     (debug:print-error 0 *default-log-port* "Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
			     (thread-sleep! 3) ;; give the flush three seconds to do it's stuff
			     (debug:print 0 "       Done.")
			     (debug:print 0 *default-log-port* "       Done.")
			     (exit 4))
			   "exit on ^C timer")))
     (thread-start! th2)
     (thread-start! th1)
     (thread-join! th2))))

Added portlogger-example.scm version [bd21f0d600].





1
2
3
4
+
+
+
+

(declare (uses portlogger))

(print (apply portlogger:main (cdr (argv))))

Modified portlogger.scm from [f3f2be6883] to [fd5d390b65].

52
53
54
55
56
57
58
59
60
61



62
63
64
65
66
67
68
52
53
54
55
56
57
58



59
60
61
62
63
64
65
66
67
68







-
-
-
+
+
+







(define (portlogger:open-run-close proc . params)
  (let* ((fname  (conc "/tmp/." (current-user-name) "-portlogger.db"))
	 (avail  (tasks:wait-on-journal fname 10))) ;; wait up to about 10 seconds for the journal to go away
    (handle-exceptions
     exn
     (begin
       ;; (release-dot-lock fname)
       (debug:print 0 "ERROR: portlogger:open-run-close failed. " proc " " params)
       (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 "exn=" (condition->list exn))
       (debug:print-error 0 *default-log-port* "portlogger:open-run-close failed. " proc " " params)
       (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 *default-log-port* "exn=" (condition->list exn))
       (if (file-exists? fname)(delete-file fname)) ;; brutally get rid of it
       (print-call-chain (current-error-port)))
     (let* (;; (lock   (obtain-dot-lock fname 2 9 10))
	    (db     (portlogger:open-db fname))
	    (res    (apply proc db params)))
       (sqlite3:finalize! db)
       ;; (release-dot-lock fname)
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
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







-
-
-
+
+
+

-
+




















-
-
-
+
+
+

-
+







    (sqlite3:finalize! qry3)
    res))

(define (portlogger:get-prev-used-port db)
  (handle-exceptions
   exn
   (begin
     (debug:print 0 "EXCEPTION: portlogger database probably overloaded or unreadable. If you see this message again remove /tmp/.$USER-portlogger.db")
     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 "exn=" (condition->list exn))
     (debug:print 0 *default-log-port* "EXCEPTION: portlogger database probably overloaded or unreadable. If you see this message again remove /tmp/.$USER-portlogger.db")
     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 *default-log-port* "exn=" (condition->list exn))
     (print-call-chain (current-error-port))
     (debug:print 0 "Continuing anyway.")
     (debug:print 0 *default-log-port* "Continuing anyway.")
     #f)
   (sqlite3:fold-row
    (lambda (var curr)
      (or curr var curr))
    #f
    db
    "SELECT (port) FROM ports WHERE state='released' LIMIT 1;")))

(define (portlogger:find-port db)
  (let* ((lowport (let ((val (configf:lookup *configdat* "server" "lowport")))
		    (if (and val 
			     (string->number val))
			(string->number val)
			32768)))
	 (portnum (or (portlogger:get-prev-used-port db)
		      (+ lowport ;; top of registered ports is 49152 but lets use ports in the registered range
			 (random (- 64000 lowport))))))
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "EXCEPTION: portlogger database probably overloaded or unreadable. If you see this message again remove /tmp/.$USER-portlogger.db")
       (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 "exn=" (condition->list exn))
       (debug:print 0 *default-log-port* "EXCEPTION: portlogger database probably overloaded or unreadable. If you see this message again remove /tmp/.$USER-portlogger.db")
       (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 *default-log-port* "exn=" (condition->list exn))
       (print-call-chain (current-error-port))
       (debug:print 0 "Continuing anyway."))
       (debug:print 0 *default-log-port* "Continuing anyway."))
     (portlogger:take-port db portnum))
    portnum))

;; set port to "released", "failed" etc.
;; 
(define (portlogger:set-port db portnum value)
  (sqlite3:execute db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;" value portnum))
154
155
156
157
158
159
160
161
162


163
164

165
166
167
168
169
170
171
154
155
156
157
158
159
160


161
162
163

164
165
166
167
168
169
170
171







-
-
+
+

-
+







  (let* ((dbfname (conc "/tmp/." (current-user-name) "-portlogger.db"))
	 (db      (portlogger:open-db dbfname))
	 (numargs (length args))
	 (result  
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 0 "EXCEPTION: portlogger database at " dbfname " probably overloaded or unreadable. Try removing it.")
	     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 *default-log-port* "EXCEPTION: portlogger database at " dbfname " probably overloaded or unreadable. Try removing it.")
	     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	     (print "exn=" (condition->list exn))
	     (debug:print 0 " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
	     (debug:print 0 *default-log-port* " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
	     (print-call-chain (current-error-port))
	     #f)
	   (case (string->symbol (car args)) ;; commands with two or more params
	     ((take)(portlogger:take-port db (string->number (cadr args))))
	     ((find)(portlogger:find-port db))
	     ((set) (let ((port  (cadr  args))
			  (state (caddr args)))

Modified process.scm from [785bc2c6db] to [1851bdf789].

11
12
13
14
15
16
17
18

19
20

21
22
23
24
25
26


27
28
29
30
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
11
12
13
14
15
16
17

18
19

20
21
22
23
24


25
26
27
28
29
30
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







-
+

-
+




-
-
+
+












-
+











-
+





-
+
















-
+





-
+








;;======================================================================
;; Process convience utils
;;======================================================================

(use regex)
(declare (unit process))
(declare (uses common))
;;(declare (uses common))

(define (conservative-read port)
(define (process:conservative-read port)
  (let loop ((res ""))
    (if (not (eof-object? (peek-char port)))
	(loop (conc res (read-char port)))
	res)))
    
(define (cmd-run-with-stderr->list cmd . params)

(define (process:cmd-run-with-stderr->list cmd . params)
  ;; (print "Called with cmd=" cmd ", proc=" proc ", params=" params)
;;  (handle-exceptions
;;   exn
;;   (begin
;;     (print "ERROR:  Failed to run command: " cmd " " (string-intersperse params " "))
;;     (print "       " ((condition-property-accessor 'exn 'message) exn))
;;     #f)
   (let-values (((fh fho pid fhe) (if (null? params)
				      (process* cmd)
				      (process* cmd params))))
       (let loop ((curr (read-line fh))
		  (result  '()))
	 (let ((errstr (conservative-read fhe)))
	 (let ((errstr (process:conservative-read fhe)))
	   (if (not (string=? errstr ""))
	       (set! result (append result (list errstr)))))
       (if (not (eof-object? curr))
	   (loop (read-line fh)
		 (append result (list curr)))
	   (begin
	     (close-input-port fh)
	     (close-input-port fhe)
	     (close-output-port fho)
	     result))))) ;; )

(define (cmd-run-proc-each-line cmd proc . params)
(define (process:cmd-run-proc-each-line cmd proc . params)
  ;; (print "Called with cmd=" cmd ", proc=" proc ", params=" params)
  (handle-exceptions
   exn
   (begin
     (print "ERROR:  Failed to run command: " cmd " " (string-intersperse params " "))
     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
     (print "exn=" (condition->list exn))
     #f)
   (let-values (((fh fho pid) (if (null? params)
				  (process cmd)
				  (process cmd params))))
       (let loop ((curr (read-line fh))
		(result  '()))
       (if (not (eof-object? curr))
	   (loop (read-line fh)
		 (append result (list (proc curr))))
	   (begin
	     (close-input-port fh)
	     (close-input-port fhe)
	     (close-output-port fho)
	     result))))))

(define (cmd-run-proc-each-line-alt cmd proc)
(define (process:cmd-run-proc-each-line-alt cmd proc)
  (let* ((fh (open-input-pipe cmd))
         (res (port-proc->list fh proc))
         (status (close-input-pipe fh)))
    (if (eq? status 0) res #f)))

(define (cmd-run->list cmd)
(define (process:cmd-run->list cmd)
  (let* ((fh (open-input-pipe cmd))
         (res (port->list fh))
         (status (close-input-pipe fh)))
    (list res status)))

(define (port->list fh)
  (if (eof-object? fh) #f
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116







-
+







                  (append result (list curr)))
            result))))

;; here is an example line where the shell is sh or bash
;; "find / -print 2&>1 > findall.log"
(define (run-n-wait cmdline #!key (params #f)(print-cmd #f))
  (if print-cmd 
      (debug:print 0 
      (debug:print 0 *default-log-port* 
		   (if (string? print-cmd)
		       print-cmd
		       "")
		   cmdline
		   (if params
		       (string-intersperse params " ")
		       "")))
145
146
147
148
149
150
151
152

















153
154
155
156
157
158
159
160
161
162
163
164
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







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












  (handle-exceptions
   exn
   ;; possibly pid is a process not a child, look in /proc to see if it is running still
   (file-exists? (conc "/proc/" pid))
   (let-values (((rpid exit-type exit-signal)(process-wait pid #t)))
       (and (number? rpid)
	    (equal? rpid pid)))))
	 

(define (process:alive-on-host? host pid)
  (let ((cmd (conc "ssh " host " ps -o pid= -p " pid)))
    (handle-exceptions
     exn
     #f ;; anything goes wrong - assume the process in NOT running.
     (with-input-from-pipe 
      cmd
      (lambda ()
	(let loop ((inl (read-line)))
	  (if (eof-object? inl)
	      #f
	      (let* ((clean-str (string-substitute "^[^\\d]*([0-9]+)[^\\d]*$" "\\1" inl))
		     (innum     (string->number clean-str)))
		(and innum
		     (eq? pid innum))))))))))

(define (process:get-sub-pids pid)
  (with-input-from-pipe
   (conc "pstree -A -p " pid) ;; | tr 'a-z\\-+`()\\.' ' ' " pid)
   (lambda ()
     (let loop ((inl (read-line))
		(res '()))
       (if (eof-object? inl)
	   (reverse res)
	   (let ((nums (map string->number
			    (string-split-fields "\\d+" inl))))
	     (loop (read-line)
		   (append res nums))))))))

Added records-vs-vectors-vs-coops.scm version [93fa590917].






























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
;; (include "vg.scm")

;; (declare (uses vg))

(use foof-loop defstruct coops)

(defstruct obj     type fill-color angle)

(define (make-vg:obj)(make-vector 3))
(define-inline (vg:obj-get-type         vec)    (vector-ref  vec 0))
(define-inline (vg:obj-get-fill-color   vec)    (vector-ref  vec 1))
(define-inline (vg:obj-get-angle        vec)    (vector-ref  vec 2))
(define-inline (vg:obj-set-type!        vec val)(vector-set! vec 0 val))
(define-inline (vg:obj-set-fill-color!  vec val)(vector-set! vec 1 val))
(define-inline (vg:obj-set-angle!       vec val)(vector-set! vec 2 val))

(use simple-exceptions)
(define vgs:obj-exn (make-exception "wrong record type, expected vgs:obj." 'assert))
(define (make-vgs:obj)(let ((v (make-vector 4)))(vector-set! v 0 'vgs:obj) v))
(define-inline (vgs:obj-type             vec)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-ref  vec 1)(raise (vgs:obj-exn 'vgs:obj-type 'xpr))))
(define-inline (vgs:obj-fill-color       vec)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-ref  vec 2)(raise (vgs:obj-exn 'vgs:obj-fill-color 'xpr))))
(define-inline (vgs:obj-angle            vec)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-ref  vec 3)(raise (vgs:obj-exn 'vgs:obj-angle 'xpr))))
(define-inline (vgs:obj-type-set!        vec val)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-set! vec 1 val)(raise (vgs:obj-exn 'type))))
(define-inline (vgs:obj-fill-color-set!  vec val)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-set! vec 2 val)(raise (vgs:obj-exn 'fill-color))))
(define-inline (vgs:obj-angle-set!       vec val)(if (eq? (vector-ref vec 0) 'vgs:obj)(vector-set! vec 3 val)(raise (vgs:obj-exn 'angle))))

(define-class <vgc> ()
  ((type)
   (fill-color)
   (angle)))


;; first use raw vectors
(print "Using vectors")
(time
 (loop ((for r (up-from 0 (to 255))))
       (loop ((for g (up-from 0 (to 255))))
	     (loop ((for b (up-from 0 (to 255))))
		   (let ((obj (make-vg:obj)))
		     (vg:obj-set-type! obj 'abc)
		     (vg:obj-set-fill-color! obj "green")
		     (vg:obj-set-angle! obj 135)
		     (let ((a (vg:obj-get-type obj))
			   (b (vg:obj-get-fill-color obj))
			   (c (vg:obj-get-angle obj)))
		       obj))))))

;; first use raw vectors with safe mode
(print "Using vectors (safe mode)")
(time
 (loop ((for r (up-from 0 (to 255))))
       (loop ((for g (up-from 0 (to 255))))
	     (loop ((for b (up-from 0 (to 255))))
		   (let ((obj (make-vgs:obj)))
		     ;; (badobj (make-vector 20)))
		     (vgs:obj-type-set! obj 'abc)
		     (vgs:obj-fill-color-set! obj "green")
		     (vgs:obj-angle-set! obj 135)
		     (let ((a (vgs:obj-type obj))
			   (b (vgs:obj-fill-color obj))
			   (c (vgs:obj-angle obj)))
		       obj))))))

;; first use defstruct
(print "Using defstruct")
(time
 (loop ((for r (up-from 0 (to 255))))
       (loop ((for g (up-from 0 (to 255))))
	     (loop ((for b (up-from 0 (to 255))))
		   (let ((obj (make-obj)))
		     (obj-type-set! obj 'abc)
		     (obj-fill-color-set! obj "green")
		     (obj-angle-set! obj 135)
		     (let ((a (obj-type obj))
			   (b (obj-fill-color obj))
			   (c (obj-angle obj)))
		       obj))))))
		   

;; first use defstruct
(print "Using coops")
(time
 (loop ((for r (up-from 0 (to 255))))
       (loop ((for g (up-from 0 (to 255))))
	     (loop ((for b (up-from 0 (to 255))))
		   (let ((obj (make <vgc>)))
		     (set! (slot-value obj 'type) 'abc)
		     (set! (slot-value obj 'fill-color) "green")
		     (set! (slot-value obj 'angle) 135)
		     (let ((a (slot-value obj 'type))
			   (b (slot-value obj 'fill-color))
			   (c (slot-value obj 'angle)))
		       obj))))))

Added records.sh version [97305b1392].



















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#! /bin/bash

# extents caches extents calculated on draw
# proc is called on draw and takes the obj itself as a parameter
# attrib is an alist of parameters
# libs: hash of name->lib, insts: hash of instname->inst
#
# Add -safe when doing development
#
export MODE='-safe'
(echo ";; Created by records.sh. DO NOT EDIT THIS FILE. Edit records.sh instead"
make-vector-record $MODE vg lib     comps
make-vector-record $MODE vg comp    objs name file
make-vector-record $MODE vg obj     type pts fill-color text line-color call-back angle font attrib extents proc
make-vector-record $MODE vg inst    libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache
make-vector-record $MODE vg drawing libs insts scalex scaley xoff yoff cnv cache
) > vg_records.scm

Modified rmt.scm from [58033889c8] to [f100192880].

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
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







-
-
-
-
-
-
-
-
-
-
















-
+



















-
+







-
+






-
+







;;  grep define ../rmt.scm | grep rmt: |perl -pi -e 's/\(define\s+\((\S+)\W.*$/\1/'|sort -u


;;======================================================================
;;  S U P P O R T   F U N C T I O N S
;;======================================================================

;; NOT USED?
;;
;; (define (rmt:call-transport run-id connection-info cmd jparams)
;;   (case (server:get-transport)
;;     ((rpc)  ( rpc-transport:client-api-send-receive run-id connection-info cmd jparams))
;;     ((http) (http-transport:client-api-send-receive run-id connection-info cmd jparams))
;;     ((fs)   ( fs-transport:client-api-send-receive run-id connection-info cmd jparams))
;;     ((zmq)  (zmq-transport:client-api-send-receive run-id connection-info cmd jparams))
;;     (else   ( rpc-transport:client-api-send-receive run-id connection-info cmd jparams))))

;;
(define (rmt:write-frequency-over-limit? cmd run-id)
  (and (not (member cmd api:read-only-queries))
       (let* ((tmprec (hash-table-ref/default *write-frequency* run-id #f))
	      (record (if tmprec tmprec 
			  (let ((v (vector (current-seconds) 0)))
			    (hash-table-set! *write-frequency* run-id v)
			    v)))
	      (count  (+ 1 (vector-ref record 1)))
	      (start  (vector-ref record 0))
	      (queries-per-second (/ (* count 1.0)
				     (max (- (current-seconds) start) 1))))
	 (vector-set! record 1 count)
	 (if (and (> count 10)
		  (> queries-per-second 10))
	     (begin
	       (debug:print-info 1 "db write rate too high, starting a server, count=" count " start=" start " run-id=" run-id " queries-per-second=" queries-per-second)
	       (debug:print-info 1 *default-log-port* "db write rate too high, starting a server, count=" count " start=" start " run-id=" run-id " queries-per-second=" queries-per-second)
	       #t)
	     #f))))

;; if a server is either running or in the process of starting call client:setup
;; else return #f to let the calling proc know that there is no server available
;;
(define (rmt:get-connection-info run-id)
  (let ((cinfo (hash-table-ref/default *runremote* run-id #f)))
    (if cinfo
	cinfo
	;; NB// can cache the answer for server running for 10 seconds ...
	;;  ;; (and (not (rmt:write-frequency-over-limit? cmd run-id))
	(if (tasks:server-running-or-starting? (db:delay-if-busy (tasks:open-db)) run-id)
	    (client:setup run-id)
	    #f))))

(define *send-receive-mutex* (make-mutex)) ;; should have separate mutex per run-id
(define (rmt:send-receive cmd rid params #!key (attemptnum 1)) ;; start attemptnum at 1 so the modulo below works as expected
  ;; clean out old connections
  (mutex-lock! *db-multi-sync-mutex*)
  ;; (mutex-lock! *db-multi-sync-mutex*)
  (let ((expire-time (- (current-seconds) (server:get-timeout) 10))) ;; don't forget the 10 second margin
    (for-each 
     (lambda (run-id)
       (let ((connection (hash-table-ref/default *runremote* run-id #f)))
         (if (and (vector? connection)
        	  (< (http-transport:server-dat-get-last-access connection) expire-time))
             (begin
               (debug:print-info 0 "Discarding connection to server for run-id " run-id ", too long between accesses")
               (debug:print-info 0 *default-log-port* "Discarding connection to server for run-id " run-id ", too long between accesses")
               ;; SHOULD CLOSE THE CONNECTION HERE
	       (case *transport-type*
		 ((nmsg)(nn-close (http-transport:server-dat-get-socket 
				   (hash-table-ref *runremote* run-id)))))
               (hash-table-delete! *runremote* run-id)))))
     (hash-table-keys *runremote*)))
  (mutex-unlock! *db-multi-sync-mutex*)
  ;; (mutex-unlock! *db-multi-sync-mutex*)
  ;; (mutex-lock! *send-receive-mutex*)
  (let* ((run-id          (if rid rid 0))
	 (connection-info (rmt:get-connection-info run-id)))
    ;; the nmsg method does the encoding under the hood (the http method should be changed to do this also)
    (if connection-info
	;; use the server if have connection info
	(let* ((dat     (case *transport-type*
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126







-
+







	  (if success
	      (begin
		;; (mutex-unlock! *send-receive-mutex*)
		(case *transport-type* 
		  ((http) res) ;; (db:string->obj res))
		  ((nmsg) res))) ;; (vector-ref res 1)))
	      (begin ;; let ((new-connection-info (client:setup run-id)))
		(debug:print 0 "WARNING: Communication failed, trying call to rmt:send-receive again.")
		(debug:print 0 *default-log-port* "WARNING: Communication failed, trying call to rmt:send-receive again.")
		;; (case *transport-type*
		;;   ((nmsg)(nn-close (http-transport:server-dat-get-socket connection-info))))
		(hash-table-delete! *runremote* run-id) ;; don't keep using the same connection
		;; NOTE: killing server causes this process to block forever. No idea why. Dec 2. 
		;; (if (eq? (modulo attemptnum 5) 0)
		;;     (tasks:kill-server-run-id run-id tag: "api-send-receive-failed"))
		;; (mutex-unlock! *send-receive-mutex*) ;; close the mutex here to allow other threads access to communications
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
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







-
+





-
+










-
-
+
+















-
-
+
+


-
+







		  (let ((start-time (current-milliseconds))
			(max-query  (string->number (or (configf:lookup *configdat* "server" "server-query-threshold")
							"300")))
			(newres     (rmt:open-qry-close-locally cmd run-id params)))
		    (let ((delta (- (current-milliseconds) start-time)))
		      (if (> delta max-query)
			  (begin
			    (debug:print-info 0 "Starting server as query time " delta " is over the limit of " max-query)
			    (debug:print-info 0 *default-log-port* "Starting server as query time " delta " is over the limit of " max-query)
			    (server:kind-run run-id)))
		      ;; return the result!
		      newres)
		    )))
	    (begin
	      ;; (debug:print 0 "ERROR: Communication failed!")
	      ;; (debug:print-error 0 *default-log-port* "Communication failed!")
	      ;; (mutex-unlock! *send-receive-mutex*)
	      ;; (exit)
	      (rmt:open-qry-close-locally cmd run-id params)
	      )))))

(define (rmt:update-db-stats run-id rawcmd params duration)
  (mutex-lock! *db-stats-mutex*)
  (handle-exceptions
   exn
   (begin
     (debug:print 0 "WARNING: stats collection failed in update-db-stats")
     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
     (debug:print 0 *default-log-port* "WARNING: stats collection failed in update-db-stats")
     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
     (print "exn=" (condition->list exn))
     #f) ;; if this fails we don't care, it is just stats
   (let* ((cmd      (conc "run-id=" run-id " " (if (eq? rawcmd 'general-call) (car params) rawcmd)))
	  (stat-vec (hash-table-ref/default *db-stats* cmd #f)))
     (if (not (vector? stat-vec))
	 (let ((newvec (vector 0 0)))
	   (hash-table-set! *db-stats* cmd newvec)
	   (set! stat-vec newvec)))
     (vector-set! stat-vec 0 (+ (vector-ref stat-vec 0) 1))
     (vector-set! stat-vec 1 (+ (vector-ref stat-vec 1) duration))))
  (mutex-unlock! *db-stats-mutex*))


(define (rmt:print-db-stats)
  (let ((fmtstr "~40a~7-d~9-d~20,2-f")) ;; "~20,2-f"
    (debug:print 18 "DB Stats\n========")
    (debug:print 18 (format #f "~40a~8a~10a~10a" "Cmd" "Count" "TotTime" "Avg"))
    (debug:print 18 *default-log-port* "DB Stats\n========")
    (debug:print 18 *default-log-port* (format #f "~40a~8a~10a~10a" "Cmd" "Count" "TotTime" "Avg"))
    (for-each (lambda (cmd)
		(let ((cmd-dat (hash-table-ref *db-stats* cmd)))
		  (debug:print 18 (format #f fmtstr cmd (vector-ref cmd-dat 0) (vector-ref cmd-dat 1) (/ (vector-ref cmd-dat 1)(vector-ref cmd-dat 0))))))
		  (debug:print 18 *default-log-port* (format #f fmtstr cmd (vector-ref cmd-dat 0) (vector-ref cmd-dat 1) (/ (vector-ref cmd-dat 1)(vector-ref cmd-dat 0))))))
	      (sort (hash-table-keys *db-stats*)
		    (lambda (a b)
		      (> (vector-ref (hash-table-ref *db-stats* a) 0)
			 (vector-ref (hash-table-ref *db-stats* b) 0)))))))

(define (rmt:get-max-query-average run-id)
  (mutex-lock! *db-stats-mutex*)
247
248
249
250
251
252
253
254

255
256
257
258

259
260
261
262
263
264
265
237
238
239
240
241
242
243

244
245
246
247

248
249
250
251
252
253
254
255







-
+



-
+







	 (resdat         (api:execute-requests dbstruct-local (vector (symbol->string cmd) params)))
	 (success        (vector-ref resdat 0))
	 (res            (vector-ref resdat 1))
	 (duration       (- (current-milliseconds) start)))
    (if (not success)
	(if (> remretries 0)
	    (begin
	      (debug:print 0 "ERROR: local query failed. Trying again.")
	      (debug:print-error 0 *default-log-port* "local query failed. Trying again.")
	      (thread-sleep! (/ (random 5000) 1000)) ;; some random delay 
	      (rmt:open-qry-close-locally cmd run-id params remretries: (- remretries 1)))
	    (begin
	      (debug:print 0 "ERROR: too many retries in rmt:open-qry-close-locally, giving up")
	      (debug:print-error 0 *default-log-port* "too many retries in rmt:open-qry-close-locally, giving up")
	      #f))
	(begin
	  ;; (rmt:update-db-stats run-id cmd params duration)
	  ;; mark this run as dirty if this was a write
	  (if (not (member cmd api:read-only-queries))
	      (let ((start-time (current-seconds)))
		(mutex-lock! *db-multi-sync-mutex*)
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282







-
+







		    (http-transport:client-api-send-receive run-id connection-info cmd params))))
;;		    ((commfail) (vector #f "communications fail")))))
    (if (and res (vector-ref res 0))
	(vector-ref res 1) ;;; YES!! THIS IS CORRECT!! CHANGE IT HERE, THEN CHANGE rmt:send-receive ALSO!!!
	#f)))
;; 	(db:string->obj (vector-ref dat 1))
;; 	(begin
;; 	  (debug:print 0 "ERROR: rmt:send-receive-no-auto-client-setup failed, attempting to continue. Got " dat)
;; 	  (debug:print-error 0 *default-log-port* "rmt:send-receive-no-auto-client-setup failed, attempting to continue. Got " dat)
;; 	  dat))))

;; Wrap json library for strings (why the ports crap in the first place?)
(define (rmt:dat->json-str dat)
  (with-output-to-string 
    (lambda ()
      (json-write dat))))
358
359
360
361
362
363
364



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401

402
403

404
405

406
407
408
409
410
411
412
348
349
350
351
352
353
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
380
381
382
383

384
385
386
387
388
389
390
391
392
393

394
395

396
397

398
399
400
401
402
403
404
405







+
+
+















-
+










-
+









-
+

-
+

-
+








(define (rmt:get-key-vals run-id)
  (rmt:send-receive 'get-key-vals #f (list run-id)))

(define (rmt:get-targets)
  (rmt:send-receive 'get-targets #f '()))

(define (rmt:get-target run-id)
  (rmt:send-receive 'get-target run-id (list run-id)))

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

;; Just some syntatic sugar
(define (rmt:register-test run-id test-name item-path)
  (rmt:general-call 'register-test run-id run-id test-name item-path))

(define (rmt:get-test-id run-id testname item-path)
  (rmt:send-receive 'get-test-id run-id (list run-id testname item-path)))

(define (rmt:get-test-info-by-id run-id test-id)
  (if (and (number? run-id)(number? test-id))
      (rmt:send-receive 'get-test-info-by-id run-id (list run-id test-id))
      (begin
	(debug:print 0 "WARNING: Bad data handed to rmt:get-test-info-by-id run-id=" run-id ", test-id=" test-id)
	(debug:print 0 *default-log-port* "WARNING: Bad data handed to rmt:get-test-info-by-id run-id=" run-id ", test-id=" test-id)
	(print-call-chain (current-error-port))
	#f)))

(define (rmt:test-get-rundir-from-test-id run-id test-id)
  (rmt:send-receive 'test-get-rundir-from-test-id run-id (list run-id test-id)))

(define (rmt:open-test-db-by-test-id run-id test-id #!key (work-area #f))
  (let* ((test-path (if (string? work-area)
			work-area
			(rmt:test-get-rundir-from-test-id run-id test-id))))
    (debug:print 3 "TEST PATH: " test-path)
    (debug:print 3 *default-log-port* "TEST PATH: " test-path)
    (open-test-db test-path)))

;; WARNING: This currently bypasses the transaction wrapped writes system
(define (rmt:test-set-state-status-by-id run-id test-id newstate newstatus newcomment)
  (rmt:send-receive 'test-set-state-status-by-id run-id (list run-id test-id newstate newstatus newcomment)))

(define (rmt:set-tests-state-status run-id testnames currstate currstatus newstate newstatus)
  (rmt:send-receive 'set-tests-state-status run-id (list run-id testnames currstate currstatus newstate newstatus)))

(define (rmt:get-tests-for-run run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals)
(define (rmt:get-tests-for-run run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals last-update mode)
  (if (number? run-id)
      (rmt:send-receive 'get-tests-for-run run-id (list run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals))
      (rmt:send-receive 'get-tests-for-run run-id (list run-id testpatt states statuses offset limit not-in sort-by sort-order qryvals last-update mode))
      (begin
	(debug:print "ERROR: rmt:get-tests-for-run called with bad run-id=" run-id)
	(debug:print-error 0 *default-log-port* "rmt:get-tests-for-run called with bad run-id=" run-id)
	(print-call-chain (current-error-port))
	'())))

;; get stuff via synchash 
(define (rmt:synchash-get run-id proc synckey keynum params)
  (rmt:send-receive 'synchash-get run-id (list run-id proc synckey keynum params)))

429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436







-
+







				 (lambda ()
				   (let ((res (rmt:send-receive 'get-tests-for-run-mindata hed (list hed testpatt states status not-in))))
				     (if (list? res)
					 (begin
					   (mutex-lock! multi-run-mutex)
					   (set! result (append result res))
					   (mutex-unlock! multi-run-mutex))
					 (debug:print 0 "ERROR: get-tests-for-run-mindata failed for run-id " hed ", testpatt " testpatt ", states " states ", status " status ", not-in " not-in))))
					 (debug:print-error 0 *default-log-port* "get-tests-for-run-mindata failed for run-id " hed ", testpatt " testpatt ", states " states ", status " status ", not-in " not-in))))
				 (conc "multi-run-thread for run-id " hed)))
		     (newthreads (cons newthread threads)))
		(thread-start! newthread)
		(thread-sleep! 0.05) ;; give that thread some time to start
		(if (null? tal)
		    newthreads
		    (loop (car tal)(cdr tal) newthreads))))))
530
531
532
533
534
535
536



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556



557
558
559
560
561
562
563
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562







+
+
+




















+
+
+








(define (rmt:update-pass-fail-counts run-id test-name)
  (rmt:general-call 'update-pass-fail-counts run-id test-name test-name test-name))

(define (rmt:top-test-set-per-pf-counts run-id test-name)
  (rmt:send-receive 'top-test-set-per-pf-counts run-id (list run-id test-name)))

(define (rmt:get-raw-run-stats run-id)
  (rmt:send-receive 'get-raw-run-stats run-id (list run-id)))

;;======================================================================
;;  R U N S
;;======================================================================

(define (rmt:get-run-info run-id)
  (rmt:send-receive 'get-run-info run-id (list run-id)))

(define (rmt:get-num-runs runpatt)
  (rmt:send-receive 'get-num-runs #f (list runpatt)))

;; Use the special run-id == #f scenario here since there is no run yet
(define (rmt:register-run keyvals runname state status user)
  (rmt:send-receive 'register-run #f (list keyvals runname state status user)))
    
(define (rmt:get-run-name-from-id run-id)
  (rmt:send-receive 'get-run-name-from-id run-id (list run-id)))

(define (rmt:delete-run run-id)
  (rmt:send-receive 'delete-run run-id (list run-id)))

(define (rmt:update-run-stats run-id stats)
  (rmt:send-receive 'update-run-stats #f (list run-id stats)))

(define (rmt:delete-old-deleted-test-records)
  (rmt:send-receive 'delete-old-deleted-test-records #f '()))

(define (rmt:get-runs runpatt count offset keypatts)
  (rmt:send-receive 'get-runs #f (list runpatt count offset keypatts)))

(define (rmt:get-all-run-ids)
582
583
584
585
586
587
588









589
590
591
592
593
594
595
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603







+
+
+
+
+
+
+
+
+







(define (rmt:get-runs-by-patt  keys runnamepatt targpatt offset limit fields) ;; fields of #f uses default
  (rmt:send-receive 'get-runs-by-patt #f (list keys runnamepatt targpatt offset limit fields)))

(define (rmt:find-and-mark-incomplete run-id ovr-deadtime)
  (if (rmt:send-receive 'have-incompletes? run-id (list run-id ovr-deadtime))
      (rmt:send-receive 'mark-incomplete run-id (list run-id ovr-deadtime))))

(define (rmt:get-main-run-stats run-id)
  (rmt:send-receive 'get-main-run-stats #f (list run-id)))

(define (rmt:get-var varname)
  (rmt:send-receive 'get-var #f (list varname)))

(define (rmt:set-var varname value)
  (rmt:send-receive 'set-var #f (list varname value)))

;;======================================================================
;; M U L T I R U N   Q U E R I E S
;;======================================================================

;; Need to move this to multi-run section and make associated changes
(define (rmt:find-and-mark-incomplete-all-runs #!key (ovr-deadtime #f))
  (let ((run-ids (rmt:get-all-run-ids)))
608
609
610
611
612
613
614
615

616
617
618
619
620




621
622
623
624
625
626



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
655
656
657
658

659
660
661
662




663
664
665
666
667
668
669
616
617
618
619
620
621
622

623
624
625
626


627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
671
672




673
674
675
676
677
678
679
680
681
682
683







-
+



-
-
+
+
+
+






+
+
+




















-
+











+
-
-
-
-
+
+
+
+







	 (selstr  (string-intersperse  keys ","))
	 (qrystr  (string-intersperse (map (lambda (x)(conc x "=?")) keys) " AND ")))
    (if (not keyvals)
	#f
	(let ((prev-run-ids (rmt:get-prev-run-ids run-id)))
	  ;; for each run starting with the most recent look to see if there is a matching test
	  ;; if found then return that matching test record
	  (debug:print 4 "selstr: " selstr ", qrystr: " qrystr ", keyvals: " keyvals ", previous run ids found: " prev-run-ids)
	  (debug:print 4 *default-log-port* "selstr: " selstr ", qrystr: " qrystr ", keyvals: " keyvals ", previous run ids found: " prev-run-ids)
	  (if (null? prev-run-ids) #f
	      (let loop ((hed (car prev-run-ids))
			 (tal (cdr prev-run-ids)))
		(let ((results (rmt:get-tests-for-run hed (conc test-name "/" item-path) '() '() #f #f #f #f #f #f)))
		  (debug:print 4 "Got tests for run-id " run-id ", test-name " test-name ", item-path " item-path ": " results)
		(let ((results (rmt:get-tests-for-run hed (conc test-name "/" item-path) '() '() ;; run-id testpatt states statuses
						      #f #f #f               ;; offset limit not-in hide/not-hide
						      #f #f #f #f 'normal))) ;; sort-by sort-order qryvals last-update mode
		  (debug:print 4 *default-log-port* "Got tests for run-id " run-id ", test-name " test-name ", item-path " item-path ": " results)
		  (if (and (null? results)
			   (not (null? tal)))
		      (loop (car tal)(cdr tal))
		      (if (null? results) #f
			  (car results))))))))))

(define (rmt:get-run-stats)
  (rmt:send-receive 'get-run-stats #f '()))

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

;; Getting steps is more complicated.
;;
;; If given work area 
;;  1. Find the testdat.db file
;;  2. Open the testdat.db file and do the query
;; If not given the work area
;;  1. Do a remote call to get the test path
;;  2. Continue as above
;; 
;;(define (rmt:get-steps-for-test run-id test-id)
;;  (rmt:send-receive 'get-steps-data run-id (list test-id)))

(define (rmt:teststep-set-status! run-id test-id teststep-name state-in status-in comment logfile)
  (let* ((state     (items:check-valid-items "state" state-in))
	 (status    (items:check-valid-items "status" status-in)))
    (if (or (not state)(not status))
	(debug:print 3 "WARNING: Invalid " (if status "status" "state")
	(debug:print 3 *default-log-port* "WARNING: Invalid " (if status "status" "state")
		     " value \"" (if status state-in status-in) "\", update your validvalues section in megatest.config"))
    (rmt:send-receive 'teststep-set-status! run-id (list run-id test-id teststep-name state-in status-in comment logfile))))

(define (rmt:get-steps-for-test run-id test-id)
  (rmt:send-receive 'get-steps-for-test run-id (list run-id test-id)))

;;======================================================================
;;  T E S T   D A T A 
;;======================================================================

(define (rmt:read-test-data run-id test-id categorypatt #!key (work-area #f)) 
  (rmt:send-receive 'read-test-data run-id (list run-id test-id categorypatt)))
  (let ((tdb  (rmt:open-test-db-by-test-id run-id test-id work-area: work-area)))
    (if tdb
	(tdb:read-test-data tdb test-id categorypatt)
	'())))
;;   (let ((tdb  (rmt:open-test-db-by-test-id run-id test-id work-area: work-area)))
;;     (if tdb
;; 	(tdb:read-test-data tdb test-id categorypatt)
;; 	'())))

(define (rmt:testmeta-add-record testname)
  (rmt:send-receive 'testmeta-add-record #f (list testname)))

(define (rmt:testmeta-get-record testname)
  (rmt:send-receive 'testmeta-get-record #f (list testname)))

685
686
687
688
689
690
691



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715







+
+
+








(define (rmt:tasks-add action owner target runname testpatt params)
  (rmt:send-receive 'tasks-add #f (list action owner target runname testpatt params)))

(define (rmt:tasks-set-state-given-param-key param-key new-state)
  (rmt:send-receive 'tasks-set-state-given-param-key #f (list  param-key new-state)))

(define (rmt:tasks-get-last target runname)
  (rmt:send-receive 'tasks-get-last #f (list target runname)))

;;======================================================================
;; A R C H I V E S
;;======================================================================

(define (rmt:archive-get-allocations  testname itempath dneeded)
  (rmt:send-receive 'archive-get-allocations #f (list testname itempath dneeded)))

Modified rpc-transport.scm from [1e1f685d67] to [7e38f4f2de].

25
26
27
28
29
30
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
25
26
27
28
29
30
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







-
+















-
+











-
+






-
+







(include "db_records.scm")

;; procstr is the name of the procedure to be called as a string
(define (rpc-transport:autoremote procstr params)
  (handle-exceptions
   exn
   (begin
     (debug:print 1 "Remote failed for " proc " " params)
     (debug:print 1 *default-log-port* "Remote failed for " proc " " params)
     (apply (eval (string->symbol procstr)) params))
   ;; (if *runremote*
   ;;    (apply (eval (string->symbol (conc "remote:" procstr))) params)
   (apply (eval (string->symbol procstr)) params)))

;; all routes though here end in exit ...
;;
;; start_server? 
;;
(define (rpc-transport:launch run-id)
  (set! *run-id*   run-id)
  (if (args:get-arg "-daemonize")
      (daemon:ize))
  (if (server:check-if-running run-id)
      (begin
	(debug:print 0 "INFO: Server for run-id " run-id " already running")
	(debug:print 0 *default-log-port* "INFO: Server for run-id " run-id " already running")
	(exit 0)))
  (let loop ((server-id (open-run-close tasks:server-lock-slot tasks:open-db run-id))
	     (remtries  4))
    (if (not server-id)
	(if (> remtries 0)
	    (begin
	      (thread-sleep! 2)
	      (loop (open-run-close tasks:server-lock-slot tasks:open-db run-id)
		    (- remtries 1)))
	    (begin
	      ;; since we didn't get the server lock we are going to clean up and bail out
	      (debug:print-info 2 "INFO: server pid=" (current-process-id) ", hostname=" (get-host-name) " not starting due to other candidates ahead in start queue")
	      (debug:print-info 2 *default-log-port* "INFO: server pid=" (current-process-id) ", hostname=" (get-host-name) " not starting due to other candidates ahead in start queue")
	      (open-run-close tasks:server-delete-records-for-this-pid tasks:open-db " rpc-transport:launch")))
	(begin
	  (rpc-transport:run (if (args:get-arg "-server")(args:get-arg "-server") "-") run-id server-id)
	  (exit)))))

(define (rpc-transport:run hostn run-id server-id)
  (debug:print 2 "Attempting to start the rpc server ...")
  (debug:print 2 *default-log-port* "Attempting to start the rpc server ...")
   ;; (trace rpc:publish-procedure!)

  (rpc:publish-procedure! 'server:login server:login)
  (rpc:publish-procedure! 'testing (lambda () "Just testing"))

  (let* ((db              #f)
	 (hostname        (get-host-name))
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111







-
+







	 (tdb             (tasks:open-db)))
    (thread-start! th1)
    (set! db *inmemdb*)
    (open-run-close tasks:server-set-interface-port 
		    tasks:open-db 
		    server-id 
		    ipaddrstr portnum)
    (debug:print 0 "Server started on " host:port)
    (debug:print 0 *default-log-port* "Server started on " host:port)
    
    ;; (trace rpc:publish-procedure!)
    ;; (rpc:publish-procedure! 'server:login server:login)
    ;; (rpc:publish-procedure! 'testing (lambda () "Just testing"))

    ;;======================================================================
    ;;	  ;; end of publish-procedure section
121
122
123
124
125
126
127
128

129
130
131

132
133
134
135


136
137
138
139
140
141
142
121
122
123
124
125
126
127

128
129
130

131
132
133


134
135
136
137
138
139
140
141
142







-
+


-
+


-
-
+
+







    ;; server last used then start shutdown
    (let loop ((count 0))
      (thread-sleep! 5) ;; no need to do this very often
      (let ((numrunning -1)) ;; (db:get-count-tests-running db)))
	(if (or (> numrunning 0)
		(> (+ *last-db-access* 60)(current-seconds)))
	    (begin
	      (debug:print-info 0 "Server continuing, tests running: " numrunning ", seconds since last db access: " (- (current-seconds) *last-db-access*))
	      (debug:print-info 0 *default-log-port* "Server continuing, tests running: " numrunning ", seconds since last db access: " (- (current-seconds) *last-db-access*))
	      (loop (+ 1 count)))
	    (begin
	      (debug:print-info 0 "Starting to shutdown the server side")
	      (debug:print-info 0 *default-log-port* "Starting to shutdown the server side")
	      (open-run-close tasks:server-delete-record tasks:open-db server-id " rpc-transport:try-start-server stop")
	      (thread-sleep! 10)
	      (debug:print-info 0 "Max cached queries was " *max-cache-size*)
	      (debug:print-info 0 "Server shutdown complete. Exiting")
	      (debug:print-info 0 *default-log-port* "Max cached queries was " *max-cache-size*)
	      (debug:print-info 0 *default-log-port* "Server shutdown complete. Exiting")
	      ))))))

(define (rpc-transport:find-free-port-and-open port)
  (handle-exceptions
   exn
	  (begin
     (print "Failed to bind to port " (rpc:default-server-port) ", trying next port")
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
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







-
+















-
+







	 (begin
	   (print "LOGIN_FAILED")
	   (exit 1))))))

(define (rpc-transport:client-setup run-id #!key (remtries 10))
  (if *runremote*
      (begin
	(debug:print 0 "ERROR: Attempt to connect to server but already connected")
	(debug:print-error 0 *default-log-port* "Attempt to connect to server but already connected")
	#f)
      (let* ((host-info (hash-table-ref/default *runremote* run-id #f))) ;; (open-run-close db:get-var #f "SERVER"))
	(if host-info
	    (let ((iface    (car host-info))
		  (port     (cadr host-info))
		  (ping-res ((rpc:procedure 'server:login host port) *toppath*)))
	      (if ping-res
		  (let ((server-dat (list iface port #f #f #f)))
		    (hash-table-set! *runremote* run-id server-dat)
		    server-dat)
		  (begin
		    (server:try-running run-id)
		    (thread-sleep! 2)
		    (rpc-transport:client-setup run-id (- remtries 1)))))
 	    (let* ((server-db-info (open-run-close tasks:get-server tasks:open-db run-id)))
 	      (debug:print-info 0 "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
 	      (debug:print-info 0 *default-log-port* "client:setup server-dat=" server-dat ", remaining-tries=" remaining-tries)
	      (if server-db-info
 		  (let* ((iface     (tasks:hostinfo-get-interface server-db-info))
 			 (port      (tasks:hostinfo-get-port      server-db-info))
			 (server-dat (list iface port #f #f #f))
 			 (ping-res  ((rpc:procedure 'server:login host port) *toppath*)))
 		    (if start-res
 			(begin
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
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







-
+



-
-
+
+








-
+


-
+

-
+

		    (thread-sleep! 2)
		    (rpc-transport:client-setup run-id (- remtries 1)))))))))
;; 
;; 	     (port     (if (and hostinfo (> (length hostdat) 1))(cadr hostdat) #f)))
;; 	(if (and port
;; 		 (string->number port))
;; 	    (let ((portn (string->number port)))
;; 	      (debug:print-info 2 "Setting up to connect to host " host ":" port)
;; 	      (debug:print-info 2 *default-log-port* "Setting up to connect to host " host ":" port)
;; 	      (handle-exceptions
;; 	       exn
;; 	       (begin
;; 		 (debug:print 0 "ERROR: Failed to open a connection to the server at host: " host " port: " port)
;; 		 (debug:print 0 "   EXCEPTION: " ((condition-property-accessor 'exn 'message) exn))
;; 		 (debug:print-error 0 *default-log-port* "Failed to open a connection to the server at host: " host " port: " port)
;; 		 (debug:print 0 *default-log-port* "   EXCEPTION: " ((condition-property-accessor 'exn 'message) exn))
;; 		 ;; (open-run-close 
;; 		 ;;  (lambda (db . param) 
;; 		 ;;    (sqlite3:execute db "DELETE FROM metadat WHERE var='SERVER'"))
;; 		 ;;  #f)
;; 		 (set! *runremote* #f))
;; 	       (if (and (not (args:get-arg "-server")) ;; no point in the server using the server using the server
;; 			((rpc:procedure 'server:login host portn) *toppath*))
;; 		   (begin
;; 		     (debug:print-info 2 "Logged in and connected to " host ":" port)
;; 		     (debug:print-info 2 *default-log-port* "Logged in and connected to " host ":" port)
;; 		     (set! *runremote* (vector host portn)))
;; 		   (begin
;; 		     (debug:print-info 2 "Failed to login or connect to " host ":" port)
;; 		     (debug:print-info 2 *default-log-port* "Failed to login or connect to " host ":" port)
;; 		     (set! *runremote* #f)))))
;; 	    (debug:print-info 2 "no server available")))))
;; 	    (debug:print-info 2 *default-log-port* "no server available")))))

Added run-eff.sql version [a9003b4b84].















1
2
3
4
5
6
7
8
9
10
11
12
13
14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
.mode col
.head on
select runs.runname,num_items,printf("%.2f",wall_runtime) AS runtime,printf("%.2f",max_duration) AS duration,ratio,testname from
   (select run_id,
          count(id) AS num_items,
          (max(event_time+run_duration)-min(event_time))/3600.0 AS wall_runtime,
          max(run_duration)/3600.0 AS max_duration,
          (max(event_time+run_duration)-min(event_time))/max(run_duration) AS ratio,
          testname from tests where item_path != '' AND state != 'DELETED'
          group by run_id
          order by ratio DESC) AS dat
    join runs on dat.run_id=runs.id
WHERE ratio > 0
AND runs.state != 'deleted';

Modified runconfig.scm from [7fa3564888] to [42efb3636c].

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38







-
+








-
+







(define (setup-env-defaults fname run-id already-seen keyvals #!key (environ-patt #f)(change-env #t))
  (let* ((keys    (map car keyvals))
	 (thekey  (if keyvals 
		      (string-intersperse (map (lambda (x)(if x x "-na-")) (map cadr keyvals)) "/")
		      (or (common:args-get-target)
			  (get-environment-variable "MT_TARGET")
			  (begin
			    (debug:print 0 "ERROR: setup-env-defaults called with no run-id or -target or -reqtarg")
			    (debug:print-error 0 *default-log-port* "setup-env-defaults called with no run-id or -target or -reqtarg")
			    "nothing matches this I hope"))))
	 ;; Why was system disallowed in the reading of the runconfigs file?
	 ;; NOTE: Should be setting env vars based on (target|default)
	 (confdat (read-config fname #f #t environ-patt: environ-patt sections: (list "default" thekey)))
	 (whatfound (make-hash-table))
	 (finaldat  (make-hash-table))
	 (sections (list "default" thekey)))
    (if (not *target*)(set! *target* thekey)) ;; may save a db access or two but repeats db:get-target code
    (debug:print 4 "Using key=\"" thekey "\"")
    (debug:print 4 *default-log-port* "Using key=\"" thekey "\"")

    (if change-env
	(for-each ;; NB// This can be simplified with new content of keyvals having all that is needed.
	 (lambda (keyval)
	   (safe-setenv (car keyval)(cadr keyval)))
	 keyvals))
	
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
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







-
+

-
+

-
+


















-
+

			 change-env)
		    (safe-setenv envvar val))
		(hash-table-set! finaldat envvar val)))
	      (map car section-dat)))))
     sections)
    (if already-seen
	(begin
	  (debug:print 2 "Key settings found in runconfig.config:")
	  (debug:print 2 *default-log-port* "Key settings found in runconfig.config:")
	  (for-each (lambda (fullkey)
		      (debug:print 2 (format #f "~20a ~a\n" fullkey (hash-table-ref/default whatfound fullkey 0))))
		      (debug:print 2 *default-log-port* (format #f "~20a ~a\n" fullkey (hash-table-ref/default whatfound fullkey 0))))
		    sections)
	  (debug:print 2 "---")
	  (debug:print 2 *default-log-port* "---")
	  (set! *already-seen-runconfig-info* #t)))
    ;; finaldat ;; was returning this "finaldat" which would be good but conflicts with other uses
    confdat
    ))

(define (set-run-config-vars run-id keyvals targ-from-db)
  (push-directory *toppath*) ;; the push/pop doesn't appear to do anything ...
  (let ((runconfigf (conc  *toppath* "/runconfigs.config"))
	(targ       (or (common:args-get-target)
			targ-from-db
			(get-environment-variable "MT_TARGET"))))
    (pop-directory)
    (if (file-exists? runconfigf)
	(setup-env-defaults runconfigf run-id #t keyvals
			    environ-patt: (conc "(default"
						(if targ
						    (conc "|" targ ")")
						    ")")))
	(debug:print 0 "WARNING: You do not have a run config file: " runconfigf))))
	(debug:print 0 *default-log-port* "WARNING: You do not have a run config file: " runconfigf))))
 

Modified runs.scm from [b521780e15] to [19cae9951d].

1
2

3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316




317
318
319
320
321
322
323
1

2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298

-
+










-
+
+


















+
+




-

-
-
-
+

-
+
-
-
+
-
-
-
+
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+














-
+












-
+







-
+












-
+
-



-
+








-
-
-
+
+
+
+
+
+
+
+
+
+













+
+
+
+
+
+









-
+
+
+
+
+

-
-
+
+
-









-
+


-
+





-
+


-
+







-
+










-
+



-
+





-
+






+
+
+
+









-
-










-
+





-
+
-





-
+

+
+
+





-
-
-

-
+



















-
-
-
-
+
+
+
+








;; Copyright 2006-2013, Matthew Welland.
;; Copyright 2006-2016, Matthew Welland.
;; 
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;; 
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.

;;  strftime('%m/%d/%Y %H:%M:%S','now','localtime')

(use sqlite3 srfi-1 posix regex regex-case srfi-69 dot-locking (srfi 18) posix-extras directory-utils)
(use sqlite3 srfi-1 posix regex regex-case srfi-69 dot-locking (srfi 18) 
     posix-extras directory-utils pathname-expand typed-records format)
(import (prefix sqlite3 sqlite3:))

(declare (unit runs))
(declare (uses db))
(declare (uses common))
(declare (uses items))
(declare (uses runconfig))
(declare (uses tests))
(declare (uses server))
(declare (uses mt))
(declare (uses archive))
;; (declare (uses filedb))

(include "common_records.scm")
(include "key_records.scm")
(include "db_records.scm")
(include "run_records.scm")
(include "test_records.scm")

;; (include "debugger.scm")

(define (runs:test-get-full-path test)
  (let* ((testname (dbr:test-testname   test))
	 (itempath (dbr:test-item-path test)))
    (conc testname (if (equal? itempath "") "" (conc "(" itempath ")")))))

;; This is the *new* methodology. One record to inform them and in the chaos, organise them.
;;
;; NOT YET UTILIZED
;; use this struct to facilitate refactoring
;;
(define (runs:create-run-record)

  (let* ((mconfig      (if *configdat*
		           *configdat*
(defstruct runs:dat
		           (if (launch:setup-for-run)
		               *configdat*
		               (begin
  reglen regfull
		                 (debug:print 0 "ERROR: Called setup in a non-megatest area, exiting")
		                 (exit 1)))))
	  (runrec      (runs:runrec-make-record))
	  (target      (common:args-get-target))
	  (runname     (common:args-get-runname))
	  (testpatt    (common:args-get-testpatt #f))
  runname max-concurrent-jobs run-id
  test-patts required-tests test-registry
	  (keys        (keys:config-get-fields mconfig))
	  (keyvals     (keys:target->keyval keys target))
  registry-mutex flags keyvals run-info all-tests-registry
	  (toppath     *toppath*)
	  (envdat      keyvals) ;; initial values start with keyvals
	  (runconfig   #f)
	  (serverdat   (if (args:get-arg "-server")
			   *runremote*
  can-run-more-tests
			   #f)) ;; to be used later
	  (transport   (or (args:get-arg "-transport") 'http))
	  (run-id      #f))
  ((can-run-more-tests-count 0) : fixnum))
    ;; Set all the environment vars we know so far, start with keys
    (for-each (lambda (keyval)
		(setenv (car keyval)(cadr keyval)))
	      keyvals)
    ;; Set up various and sundry known vars here
    (setenv "MT_RUN_AREA_HOME" toppath)
    (setenv "MT_RUNNAME" runname)
    (setenv "MT_TARGET"  target)
    (setenv "MT_TESTSUITENAME" (common:get-testsuite-name))
    (set! envdat (append 
		  envdat
		  (list (list "MT_RUN_AREA_HOME" toppath)
			(list "MT_RUNNAME"       runname)
			(list "MT_TARGET"        target))))
    ;; Now can read the runconfigs file
    ;; 
    (set! runconfig (read-config (conc  *toppath* "/runconfigs.config") #f #t sections: (list "default" target)))
    (if (not (hash-table-ref/default runconfig (args:get-arg "-reqtarg") #f))
	(begin
	  (debug:print 0 "ERROR: [" (args:get-arg "-reqtarg") "] not found in " runconfigf)
	  (if db (sqlite3:finalize! db))
	  (exit 1)))
    ;; Now have runconfigs data loaded, set environment vars

(defstruct runs:testdat
  hed tal reg reruns  test-record
    ;; Only now can we calculate the testpatt
    (set! testpatt (common:args-get-testpatt runconfig))
    
  test-name item-path jobgroup
  waitons testmode  newtal itemmaps prereqs-not-met)

    (for-each (lambda (section)
		(for-each (lambda (varval)
			    (set! envdat (append envdat (list varval)))
			    (safe-setenv (car varval)(cadr varval)))
			  (configf:get-section runconfig section)))
	      (list "default" target))
    (vector target runname testpatt keys keyvals envdat mconfig runconfig serverdat transport db toppath run-id)))

;; set up needed environment variables given a run-id and optionally a target, itempath etc.
;;
(define (runs:set-megatest-env-vars run-id #!key (inkeys #f)(inrunname #f)(inkeyvals #f)(intarget #f)(testname #f)(itempath #f))
  (let* ((target    (or intarget 
			(common:args-get-target)
			(get-environment-variable "MT_TARGET")))
	 (keys      (if inkeys    inkeys    (rmt:get-keys)))
	 (keyvals   (if inkeyvals inkeyvals (keys:target->keyval keys target)))
	 (vals      (hash-table-ref/default *env-vars-by-run-id* run-id #f))
	 (link-tree (configf:lookup *configdat* "setup" "linktree")))
    (if testname (setenv "MT_TEST_NAME" testname))
    (if itempath (setenv "MT_ITEMPATH"  itempath))

    ;; get the info from the db and put it in the cache
    (if link-tree
	(setenv "MT_LINKTREE" link-tree)
	(debug:print 0 "ERROR: linktree not set, should be set in megatest.config in [setup] section."))
	(debug:print-error 0 *default-log-port* "linktree not set, should be set in megatest.config in [setup] section."))
    (if (not vals)
	(let ((ht (make-hash-table)))
	  (hash-table-set! *env-vars-by-run-id* run-id ht)
	  (set! vals ht)
	  (for-each
	   (lambda (key)
	     (hash-table-set! vals (car key) (cadr key)))
	   keyvals)))
    ;; from the cached data set the vars
    (hash-table-for-each
     vals
     (lambda (key val)
       (debug:print 2 "setenv " key " " val)
       (debug:print 2 *default-log-port* "setenv " key " " val)
       (safe-setenv key val)))
    (if (not (get-environment-variable "MT_TARGET"))(setenv "MT_TARGET" target))
    (alist->env-vars (hash-table-ref/default *configdat* "env-override" '()))
    ;; Lets use this as an opportunity to put MT_RUNNAME in the environment
    (let ((runname  (if inrunname inrunname (rmt:get-run-name-from-id run-id))))
      (if runname
	  (setenv "MT_RUNNAME" runname)
	  (debug:print 0 "ERROR: no value for runname for id " run-id)))
	  (debug:print-error 0 *default-log-port* "no value for runname for id " run-id)))
    (setenv "MT_RUN_AREA_HOME" *toppath*)
    ;; if a testname and itempath are available set the remaining appropriate variables
    (if testname (setenv "MT_TEST_NAME" testname))
    (if itempath (setenv "MT_ITEMPATH"  itempath))
    (if (and testname link-tree)
	(setenv "MT_TEST_RUN_DIR" (conc (getenv "MT_LINKTREE")  "/"
					(getenv "MT_TARGET")    "/"
					(getenv "MT_RUNNAME")   "/"
					(getenv "MT_TEST_NAME")
					(if (and itempath
						 (not (equal? itempath "")))
					    (conc "/" itempath)
					    ""))))
					    ""))))))
    ))

(define (set-item-env-vars itemdat)
  (for-each (lambda (item)
	      (debug:print 2 "setenv " (car item) " " (cadr item))
	      (debug:print 2 *default-log-port* "setenv " (car item) " " (cadr item))
	      (setenv (car item) (cadr item)))
	    itemdat))

;; Every time can-run-more-tests is called increment the delay
;;
;; NOTE: We run this server-side!! Do not use this global except in the runs:can-run-more-tests routine
;;
(define *last-num-running-tests* 0)
(define *runs:can-run-more-tests-count* 0)
(define (runs:shrink-can-run-more-tests-count)
  (set! *runs:can-run-more-tests-count* 0)) ;; (/ *runs:can-run-more-tests-count* 2)))
;; (define *runs:can-run-more-tests-count* 0)
(define (runs:shrink-can-run-more-tests-count runsdat)
  (runs:dat-can-run-more-tests-count-set! runsdat 0))

(define (runs:inc-can-run-more-tests-count runsdat)
  (runs:dat-can-run-more-tests-count-set!
   runsdat
   (+ (runs:dat-can-run-more-tests-count runsdat) 1)))

;;  (set! *runs:can-run-more-tests-count* 0)) ;; (/ *runs:can-run-more-tests-count* 2)))

;; Temporary globals. Move these into the logic or into common
;;
(define *seen-cant-run-tests* (make-hash-table)) ;; use to track tests that we suspect cannot be run
(define (runs:inc-cant-run-tests testname)
  (hash-table-set! *seen-cant-run-tests* testname
		   (+ (hash-table-ref/default *seen-cant-run-tests* testname 0) 1)))

(define (runs:can-keep-running? testname n)
  (< (hash-table-ref/default *seen-cant-run-tests* testname 0) n))

(define *runs:denoise* (make-hash-table)) ;; key => last-time-ran

;; mechanism to limit printing info to the screen that is repetitive.
;;
;; Example: 
;; (if (runs:lownoise "waiting on tasks" 60)
;;     (debug:print-info 2 *default-log-port* "waiting for tasks to complete, sleeping briefly ..."))
;;
(define (runs:lownoise key waitval)
  (let ((lasttime (hash-table-ref/default *runs:denoise* key 0))
	(currtime (current-seconds)))
    (if (> (- currtime lasttime) waitval)
	(begin
	  (hash-table-set! *runs:denoise* key currtime)
	  #t)
	#f)))

(define (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs)
(define (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs)
  ;; Take advantage of a good place to exit if running the one-pass methodology
  (if (and (> (runs:dat-can-run-more-tests-count runsdat) 20)
	   (args:get-arg "-one-pass"))
      (exit 0))
  (thread-sleep! (cond
        	  ((> *runs:can-run-more-tests-count* 20)
		   (if (runs:lownoise "waiting on tasks" 60)
        	  ((> (runs:dat-can-run-more-tests-count runsdat) 20)
		   (if (runs:lownoise "waiting on tasks" 60)(debug:print-info 2 *default-log-port* "waiting for tasks to complete, sleeping briefly ..."))
		       (debug:print-info 2 "waiting for tasks to complete, sleeping briefly ..."))
		   2);; obviously haven't had any work to do for a while
        	  (else 0)))
  (let* ((num-running             (rmt:get-count-tests-running run-id))
	 (num-running-in-jobgroup (rmt:get-count-tests-running-in-jobgroup run-id jobgroup))
	 (job-group-limit         (let ((jobg-count (config-lookup *configdat* "jobgroups" jobgroup)))
				    (if (string? jobg-count)
					(string->number jobg-count)
					jobg-count))))
    (if (> (+ num-running num-running-in-jobgroup) 0)
	(set! *runs:can-run-more-tests-count* (+ *runs:can-run-more-tests-count* 1)))
	(runs:inc-can-run-more-tests-count runsdat)) ;; (set! *runs:can-run-more-tests-count* (+ *runs:can-run-more-tests-count* 1)))
    (if (not (eq? *last-num-running-tests* num-running))
	(begin
	  (debug:print 2 "max-concurrent-jobs: " max-concurrent-jobs ", num-running: " num-running)
	  (debug:print 2 *default-log-port* "max-concurrent-jobs: " max-concurrent-jobs ", num-running: " num-running)
	  (set! *last-num-running-tests* num-running)))
    (if (not (eq? 0 *globalexitstatus*))
	(list #f num-running num-running-in-jobgroup max-concurrent-jobs job-group-limit)
	(let ((can-not-run-more (cond
				 ;; if max-concurrent-jobs is set and the number running is greater 
				 ;; than it than cannot run more jobs
				 ;; than it then cannot run more jobs
				 ((and max-concurrent-jobs (>= num-running max-concurrent-jobs))
				  (if (runs:lownoise "mcj msg" 60)
				      (debug:print 0 "WARNING: Max running jobs exceeded, current number running: " num-running 
				      (debug:print 0 *default-log-port* "WARNING: Max running jobs exceeded, current number running: " num-running 
						   ", max_concurrent_jobs: " max-concurrent-jobs))
				  #t)
				 ;; if job-group-limit is set and number of jobs in the group is greater
				 ;; than the limit then cannot run more jobs of this kind
				 ((and job-group-limit
				       (>= num-running-in-jobgroup job-group-limit))
				  (if (runs:lownoise (conc "maxjobgroup " jobgroup) 60)
				      (debug:print 1 "WARNING: number of jobs " num-running-in-jobgroup 
				      (debug:print 1 *default-log-port* "WARNING: number of jobs " num-running-in-jobgroup 
						   " in jobgroup \"" jobgroup "\" exceeds limit of " job-group-limit))
				  #t)
				 (else #f))))
	  (list (not can-not-run-more) num-running num-running-in-jobgroup max-concurrent-jobs job-group-limit)))))


;;  test-names: Comma separated patterns same as test-patts but used in selection 
;;              of tests to run. The item portions are not respected.
;;              FIXME: error out if /patt specified
;;            
(define (runs:run-tests target runname test-patts user flags #!key (run-count 3)) ;; test-names
(define (runs:run-tests target runname test-patts user flags #!key (run-count 1)) ;; test-names
  (let* ((keys               (keys:config-get-fields *configdat*))
	 (keyvals            (keys:target->keyval keys target))
	 (run-id             (rmt:register-run keyvals runname "new" "n/a" user))  ;;  test-name)))
	 (deferred          '()) ;; delay running these since they have a waiton clause
	 ;; (deferred          '()) ;; delay running these since they have a waiton clause
	 (runconfigf         (conc  *toppath* "/runconfigs.config"))
	 (test-records       (make-hash-table))
	 ;; need to process runconfigs before generating these lists
	 (all-tests-registry #f)  ;; (tests:get-all)) ;; (tests:get-valid-tests (make-hash-table) test-search-path)) ;; all valid tests to check waiton names
	 (all-test-names     #f)  ;; (hash-table-keys all-tests-registry))
	 (test-names         #f)  ;; (tests:filter-test-names all-test-names test-patts))
	 (test-names         #f)  ;; Generated by a call to (tests:filter-test-names all-test-names test-patts))
	 (required-tests     #f)  ;; Put fully qualified test/testpath names in this list to be done
	 (task-key           (conc (hash-table->alist flags) " " (get-host-name) " " (current-process-id)))
	 (tdbdat             (tasks:open-db))
	 (config-reruns      (let ((x (configf:lookup *configdat* "setup" "reruns")))
			       (if x (string->number x) #f))))

    ;; per user request. If less than 100Meg space on dbdir partition, bail out with error
    ;; this will reduce issues in database corruption
    (common:check-db-dir-and-exit-if-insufficient)
    
    ;; override the number of reruns from the configs
    (if (and config-reruns
	     (> run-count config-reruns))
	(set! run-count config-reruns))
    
    (if (tasks:need-server run-id)(tasks:start-and-wait-for-server tdbdat run-id 10))

    (let ((sighand (lambda (signum)
		     ;; (signal-mask! signum) ;; to mask or not? seems to cause issues in exiting
		     (if (eq? signum signal/stop)
			 (debug:print 0 "ERROR: attempt to STOP process. Exiting."))
		     (set! *time-to-exit* #t)
		     (print "Received signal " signum ", cleaning up before exit. Please wait...")
		     (let ((th1 (make-thread (lambda ()
					       (let ((tdbdat (tasks:open-db)))
						 (rmt:tasks-set-state-given-param-key task-key "killed"))
					       (print "Killed by signal " signum ". Exiting")
					       (thread-sleep! 3)
					       (exit))))
			   (th2 (make-thread (lambda ()
					       (thread-sleep! 5)
					       (debug:print 0 "Done")
					       (debug:print 0 *default-log-port* "Done")
					       (exit 4)))))
		       (thread-start! th2)
		       (thread-start! th1)
		       (thread-join! th2)))))
      (set-signal-handler! signal/int sighand)
      (set-signal-handler! signal/term sighand)
      (set-signal-handler! signal/term sighand))
      (set-signal-handler! signal/stop sighand))

    (runs:set-megatest-env-vars run-id inkeys: keys inrunname: runname) ;; these may be needed by the launching process
    (set! runconf (if (file-exists? runconfigf)
		      (setup-env-defaults runconfigf run-id *already-seen-runconfig-info* keyvals target)
		      (begin
			(debug:print 0 "WARNING: You do not have a run config file: " runconfigf)
			(debug:print 0 *default-log-port* "WARNING: You do not have a run config file: " runconfigf)
			#f)))

    (if (not test-patts) ;; first time in - adjust testpatt
	(set! test-patts (common:args-get-testpatt runconf)))

    ;; register this run in monitor.db
    (rmt:tasks-add "run-tests" user target runname test-patts task-key) ;; params)
    (rmt:tasks-set-state-given-param-key task-key "running")

    (if (not test-patts) ;; first time in - adjust testpatt
	(set! test-patts (common:args-get-testpatt runconf)))

    ;; Now generate all the tests lists
    (set! all-tests-registry (tests:get-all))
    (set! all-tests-registry (tests:get-all))   ;; hash of testname => path-to-test
    (set! all-test-names     (hash-table-keys all-tests-registry))
    (set! test-names         (tests:filter-test-names all-test-names test-patts))

    ;; I think seeding required-tests with all test-names makes sense but lack analysis to back that up.

    ;; NEW STRATEGY HERE:
    ;; 1. fill required tests with test-patts
    ;; 2. scan testconfigs and if waitons, itemwait, itempatt calc prior test test-patt
    ;; 3. repeat until all deps propagated
    
    ;; any tests with direct mention in test-patts can be added to required
    ;;
    (set! required-tests     (lset-intersection equal? (string-split test-patts ",") all-test-names))
    ;; (set! required-tests     (lset-intersection equal? test-names all-test-names))
    
    ;; look up all tests matching the comma separated list of globs in
    ;; test-patts (using % as wildcard)

    ;; (set! test-names (delete-duplicates (tests:get-valid-tests *toppath* test-patts)))
    (debug:print-info 0 "tests search path: " (string-intersperse (tests:get-tests-search-path *configdat*) " "))
    (debug:print-info 0 "all tests:         " (string-intersperse (sort all-test-names string<) " "))
    (debug:print-info 0 "test names:        " (string-intersperse (sort test-names string<) " "))
    (debug:print-info 0 "required tests:    " (string-intersperse (sort required-tests string<) " "))
    (debug:print-info 0 *default-log-port* "tests search path: " (string-intersperse (tests:get-tests-search-path *configdat*) " "))
    (debug:print-info 0 *default-log-port* "all tests:         " (string-intersperse (sort all-test-names string<) " "))
    (debug:print-info 0 *default-log-port* "test names:        " (string-intersperse (sort test-names string<) " "))
    (debug:print-info 0 *default-log-port* "required tests:    " (string-intersperse (sort required-tests string<) " "))

    ;; on the first pass or call to run-tests set FAILS to NOT_STARTED if
    ;; -keepgoing is specified
    (if (eq? *passnum* 0)
	(begin
	  ;; Is this still necessary? I think not. Unreachable tests are marked as such and 
	  ;; should not cause problems here.
343
344
345
346
347
348
349
350

351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431

432
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
459

460
461
462
463
464
465
466
467
468
469










470
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497


498
499
500
501
502
503
504
318
319
320
321
322
323
324

325
326
327
328
329

330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346























347

348
349
350
351
352
353
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
380
381
382

383
384
385
386

387
388
389
390
391
392
393
394
395
396
397
398
399

400
401
402
403

404
405

406
407
408
409
410
411
412










413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430

431
432
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







-
+




-
+





-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-












-
+

-
+
















-
+



-
+



-
+












-
+



-
+

-
+





+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+








-
+

















-
-
+
+







    ;; refactoring this block into tests:get-full-data
    ;;
    ;; What happended, this code is now duplicated in tests!?
    ;;
    ;;======================================================================
    
    (if (not (null? test-names))
	(let loop ((hed (car test-names))
	(let loop ((hed (car test-names))   ;; NOTE: This is the main loop that iterates over the test-names
		   (tal (cdr test-names)))         ;; 'return-procs tells the config reader to prep running system but return a proc
	  (change-directory *toppath*) ;; PLEASE OPTIMIZE ME!!! I think this should be a no-op but there are several places where change-directories could be happening.
	  (setenv "MT_TEST_NAME" hed) ;; 
	  (let*-values (((waitons waitors config)(tests:get-waitons hed all-tests-registry)))
	    (debug:print-info 8 "waitons: " waitons)
	    (debug:print-info 8 *default-log-port* "waitons: " waitons)
	    ;; check for hed in waitons => this would be circular, remove it and issue an
	    ;; error
	    (if (or (member hed waitons)
		    (member hed waitors))
		(begin
		  (debug:print 0 "ERROR: test " hed " has listed itself as a waiton or waitor, please correct this!")
		  (debug:print-error 0 *default-log-port* "test " hed " has listed itself as a waiton or waitor, please correct this!")
		  (set! waitons (filter (lambda (x)(not (equal? x hed))) waitons))
		  (set! waitors (filter (lambda (x)(not (equal? x hed))) waitors))))
	    
	    ;; (items   (items:get-items-from-config config)))
	    (if (not (hash-table-ref/default test-records hed #f))
		(hash-table-set! test-records
				 hed (vector hed     ;; 0
					     config  ;; 1
					     waitons ;; 2
					     (config-lookup config "requirements" "priority")     ;; priority 3
					     (let ((items      (hash-table-ref/default config "items" #f)) ;; items 4
						   (itemstable (hash-table-ref/default config "itemstable" #f))) 
					       ;; if either items or items table is a proc return it so test running
					       ;; process can know to call items:get-items-from-config
					       ;; if either is a list and none is a proc go ahead and call get-items
					       ;; otherwise return #f - this is not an iterated test
					       (cond
						((procedure? items)      
						 (debug:print-info 4 "items is a procedure, will calc later")
						 items)            ;; calc later
						((procedure? itemstable)
						 (debug:print-info 4 "itemstable is a procedure, will calc later")
						 itemstable)       ;; calc later
						((filter (lambda (x)
							   (let ((val (car x)))
							     (if (procedure? val) val #f)))
							 (append (if (list? items) items '())
								 (if (list? itemstable) itemstable '())))
						 'have-procedure)
						((or (list? items)(list? itemstable)) ;; calc now
						 (debug:print-info 4 "items and itemstable are lists, calc now\n"
								   "    items: " items " itemstable: " itemstable)
						 (items:get-items-from-config config))
					     (tests:get-items config) ;; expand the [items] and or [itemstable] into explict items
						(else #f)))                           ;; not iterated
					     #f      ;; itemsdat 5
					     #f      ;; spare - used for item-path
					     waitors ;; 
					     )))
	    (for-each 
	     (lambda (waiton)
	       (if (and waiton (not (member waiton test-names)))
		   (let* ((waiton-record   (hash-table-ref/default test-records waiton #f))
			  (waiton-tconfig  (if waiton-record (vector-ref waiton-record 1) #f))
			  (waiton-itemized (and waiton-tconfig
						(or (hash-table-ref/default waiton-tconfig "items" #f)
						    (hash-table-ref/default waiton-tconfig "itemstable" #f))))
			  (itemmaps        (tests:get-itemmaps config));; (configf:lookup config "requirements" "itemmap"))
			  (itemmaps        (tests:get-itemmaps config))  ;; (configf:lookup config "requirements" "itemmap"))
			  (new-test-patts  (tests:extend-test-patts test-patts hed waiton itemmaps)))
		     (debug:print-info 0 "Test " waiton " has " (if waiton-record "a" "no") " waiton-record and" (if waiton-itemized " " " no ") "items")
		     (debug:print-info 0 *default-log-port* "Test " waiton " has " (if waiton-record "a" "no") " waiton-record and" (if waiton-itemized " " " no ") "items")
		     ;; need to account for test-patt here, if I am test "a", selected with a test-patt of "hed/b%"
		     ;; and we are waiting on "waiton" we need to add "waiton/,waiton/b%" to test-patt
		     ;; is this satisfied by merely appending "/" to the waiton name added to the list?
		     ;;
		     ;; This approach causes all of the items in an upstream test to be run 

		     ;; if we have this waiton already processed once we can analzye it for extending
		     ;; tests to be run, since we can't properly process waitons unless they have been
		     ;; initially added we add them again to be processed on second round AND add the hed
		     ;; back in to also be processed on second round
		     ;;
		     (if waiton-tconfig
			 (begin
			   (set! test-names (cons waiton test-names)) ;; need to process this one, only add once the waiton tconfig read
			   (if waiton-itemized
			       (begin
				 (debug:print-info 0 "New test patts: " new-test-patts ", prev test patts: " test-patts)
				 (debug:print-info 0 *default-log-port* "New test patts: " new-test-patts ", prev test patts: " test-patts)
				 (set! required-tests (cons (conc waiton "/") required-tests))
				 (set! test-patts new-test-patts))
			       (begin
				 (debug:print-info 0 "Adding non-itemized test " waiton " to required-tests")
				 (debug:print-info 0 *default-log-port* "Adding non-itemized test " waiton " to required-tests")
				 (set! required-tests (cons waiton required-tests))
				 (set! test-patts new-test-patts))))
			 (begin
			   (debug:print-info 0 "No testconfig info yet for " waiton ", setting up to re-process it")
			   (debug:print-info 0 *default-log-port* "No testconfig info yet for " waiton ", setting up to re-process it")
			   (set! tal (append (cons waiton tal)(list hed))))) ;; (cons (conc waiton "/") required-tests))
			 
		     ;; NOPE: didn't work. required needs to be plain test names. Try tacking on to test-patts
		     ;;  - doesn't work
		     ;; (set! test-patts (conc test-patts "," waiton "/"))
		     
		     ;; (set! test-names (cons waiton test-names))))) ;; was an append, now a cons
		     )))
	     (delete-duplicates (append waitons waitors)))
	    (let ((remtests (delete-duplicates (append waitons tal))))
	      (if (not (null? remtests))
		  (begin
		    ;; (debug:print-info 0 "Preprocessing continues for " (string-intersperse remtests ", "))
		    ;; (debug:print-info 0 *default-log-port* "Preprocessing continues for " (string-intersperse remtests ", "))
		    (loop (car remtests)(cdr remtests))))))))

    (if (not (null? required-tests))
	(debug:print-info 1 "Adding \"" (string-intersperse required-tests " ") "\" to the run queue"))
	(debug:print-info 1 *default-log-port* "Adding \"" (string-intersperse required-tests " ") "\" to the run queue"))
    ;; NOTE: these are all parent tests, items are not expanded yet.
    (debug:print-info 4 "test-records=" (hash-table->alist test-records))
    (debug:print-info 4 *default-log-port* "test-records=" (hash-table->alist test-records))
    (let ((reglen (configf:lookup *configdat* "setup" "runqueue")))
      (if (> (length (hash-table-keys test-records)) 0)
	  (let* ((keep-going        #t)
		 (run-queue-retries 5)
		 (th1        (make-thread (lambda ()
					    (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests (any->number reglen) all-tests-registry))
					    (handle-exceptions
					     exn
					     (begin
					       (print-call-chain (current-error-port))
					       (debug:print 0 "ERROR: failure in runs:run-tests-queue thread, error: " ((condition-property-accessor 'exn 'message) exn))
					       (if (> run-queue-retries 0)
						   (begin
						     (set! run-queue-retries (- run-queue-retries 1))
						     (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests (any->number reglen) all-tests-registry))))
					     (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests (any->number reglen) all-tests-registry)))
					    ;; (handle-exceptions
					    ;;  exn
					    ;;  (begin
					    ;;    (print-call-chain (current-error-port))
					    ;;    (debug:print-error 0 *default-log-port* "failure in runs:run-tests-queue thread, error: " ((condition-property-accessor 'exn 'message) exn))
					    ;;    (if (> run-queue-retries 0)
					    ;; 	   (begin
					    ;; 	     (set! run-queue-retries (- run-queue-retries 1))
					    ;; 	     (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests (any->number reglen) all-tests-registry))))
					    ;;  (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests (any->number reglen) all-tests-registry)))
					  "runs:run-tests-queue"))
		 (th2        (make-thread (lambda ()				    
					    ;; (rmt:find-and-mark-incomplete-all-runs))))) CAN'T INTERRUPT IT ...
					    (let ((run-ids (rmt:get-all-run-ids)))
					      (for-each (lambda (run-id)
							  (if keep-going
							      (handle-exceptions
							       exn
							       (debug:print 0 "error in calling find-and-mark-incomplete for run-id " run-id)
							       (debug:print 0 *default-log-port* "error in calling find-and-mark-incomplete for run-id " run-id)
							       (rmt:find-and-mark-incomplete run-id #f)))) ;; ovr-deadtime)))
							run-ids)))
					  "runs: mark-incompletes")))
	    (thread-start! th1)
	    (thread-start! th2)
	    (thread-join! th1)
	    (set! keep-going #f)
	    (thread-join! th2)
	    ;; if run-count > 0 call, set -preclean and -rerun STUCK/DEAD
	    (if (> run-count 0) ;; handle reruns
		(begin
		  (if (not (hash-table-ref/default flags "-preclean" #f))
		      (hash-table-set! flags "-preclean" #t))
		  (if (not (hash-table-ref/default flags "-rerun" #f))
		      (hash-table-set! flags "-rerun" "STUCK/DEAD,n/a,ZERO_ITEMS"))
		  ;; recursive call to self
		  (runs:run-tests target runname test-patts user flags run-count: (- run-count 1)))))
	  (debug:print-info 0 "No tests to run")))
    (debug:print-info 4 "All done by here")
	  (debug:print-info 0 *default-log-port* "No tests to run")))
    (debug:print-info 4 *default-log-port* "All done by here")
    (rmt:tasks-set-state-given-param-key task-key "done")
    ;; (sqlite3:finalize! tasks-db)
    ))


;; loop logic. These are used in runs:run-tests-queue to make it a bit more readable.
;;
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546








547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573

574
575
576
577
578
579
580
581

582
583
584
585
586
587

588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605
606





607
608
609
610

611
612
613
614
615
616
617
465
466
467
468
469
470
471









472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523

524
525
526
527
528
529
530
531

532
533
534
535
536
537

538
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
554
555


556
557
558
559
560
561
562
563

564
565
566
567
568
569
570
571







-
-
-
-
-
-
-
-
-


















-
+
+
+
+
+
+
+
+





-
+













-
+






-
+







-
+





-
+








-
+








-
-
+
+
+
+
+



-
+







(define (runs:queue-next-hed tal reg n regfull)
  (if regfull
      (car reg)
      (if (null? tal) ;; tal is used up, pop from reg
	  (car reg)
	  (car tal))))

;;   (cond
;;    ((and regfull (null? reg)(not (null? tal)))      (car tal))
;;    ((and regfull (not (null? reg)))                 (car reg))
;;    ((and (not regfull)(null? tal)(not (null? reg))) (car reg))
;;    ((and (not regfull)(not (null? tal)))            (car tal))
;;    (else
;;     (debug:print 0 "ERROR: runs:queue-next-hed, tal=" tal ", reg=" reg ", n=" n ", regfull=" regfull)
;;     #f)))

(define (runs:queue-next-tal tal reg n regfull)
  (if regfull
      tal
      (if (null? tal) ;; must transfer from reg
	  (cdr reg)
	  (cdr tal))))

(define (runs:queue-next-reg tal reg n regfull)
  (if regfull
      (cdr reg)
      (if (null? tal) ;; if tal is null and reg not full then '() as reg contents moved to tal
	  '()
	  reg)))

(define runs:nothing-left-in-queue-count 0)

(define (runs:expand-items hed tal reg reruns regfull newtal jobgroup max-concurrent-jobs run-id waitons item-path testmode test-record can-run-more items runname tconfig reglen test-registry test-records itemmaps)
  (let* ((loop-list       (list hed tal reg reruns))
	 (prereqs-not-met (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps))
	 (prereqs-not-met (let ((res (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps)))
			    (if (list? res)
				res
				(begin
				  (debug:print 0 *default-log-port*
					       "ERROR: rmt:get-prereqs-not-met returned non-list!\n"
					       "  res=" res " run-id=" run-id " waitons=" waitons " hed=" hed " item-path=" item-path " testmode=" testmode " itemmaps=" itemmaps)
				  '()))))
	 ;; (prereqs-not-met (mt:lazy-get-prereqs-not-met run-id waitons item-path mode: testmode itemmap: itemmap))
	 (fails           (runs:calc-fails prereqs-not-met))
	 (prereq-fails    (runs:calc-prereq-fail prereqs-not-met))
	 (non-completed   (runs:calc-not-completed prereqs-not-met))
	 (runnables       (runs:calc-runnable prereqs-not-met)))
    (debug:print-info 4 "START OF INNER COND #2 "
    (debug:print-info 4 *default-log-port* "START OF INNER COND #2 "
		      "\n can-run-more:    " can-run-more
		      "\n testname:        " hed
		      "\n prereqs-not-met: " (runs:pretty-string prereqs-not-met)
		      "\n non-completed:   " (runs:pretty-string non-completed) 
		      "\n prereq-fails:    " (runs:pretty-string prereq-fails)
		      "\n fails:           " (runs:pretty-string fails)
		      "\n testmode:        " testmode
		      "\n (member 'toplevel testmode): " (member 'toplevel testmode)
		      "\n (null? non-completed):    " (null? non-completed)
		      "\n reruns:          " reruns
		      "\n items:           " items
		      "\n can-run-more:    " can-run-more)

    (cond
   (cond
     ;; all prereqs met, fire off the test
     ;; or, if it is a 'toplevel test and all prereqs not met are COMPLETED then launch

     ((and (not (member 'toplevel testmode))
	   (member (hash-table-ref/default test-registry (db:test-make-full-name hed item-path) 'n/a)
		   '(DONOTRUN removed CANNOTRUN))) ;; *common:cant-run-states-sym*) ;; '(COMPLETED KILLED WAIVED UNKNOWN INCOMPLETE)) ;; try to catch repeat processing of COMPLETED tests here
      (debug:print-info 1 "Test " hed " set to \"" (hash-table-ref test-registry (db:test-make-full-name hed item-path)) "\". Removing it from the queue")
      (debug:print-info 1 *default-log-port* "Test " hed " set to \"" (hash-table-ref test-registry (db:test-make-full-name hed item-path)) "\". Removing it from the queue")
      (if (or (not (null? tal))
	      (not (null? reg)))
	  (list (runs:queue-next-hed tal reg reglen regfull)
		(runs:queue-next-tal tal reg reglen regfull)
		(runs:queue-next-reg tal reg reglen regfull)
		reruns)
	  (begin
	    (debug:print-info 0 "Nothing left in the queue!")
	    (debug:print-info 0 *default-log-port* "Nothing left in the queue!")
	    ;; If get here twice then we know we've tried to expand all items
	    ;; since there must be a logic issue with the handling of loops in the 
	    ;; items expand phase we will brute force an exit here.
	    (if (> runs:nothing-left-in-queue-count 2)
		(begin
		  (debug:print 0 "WARNING: this condition is triggered when there were no items to expand and nothing to run. Please check your run for completeness")
		  (debug:print 0 *default-log-port* "WARNING: this condition is triggered when there were no items to expand and nothing to run. Please check your run for completeness")
		  (exit 0))
		(set! runs:nothing-left-in-queue-count (+ runs:nothing-left-in-queue-count 1)))
	    #f)))

     ;; 
     ((or (null? prereqs-not-met)
	  (and (member 'toplevel testmode)
	       (null? non-completed)))
      (debug:print-info 4 "runs:expand-items: (or (null? prereqs-not-met) (and (member 'toplevel testmode)(null? non-completed)))")
      (debug:print-info 4 *default-log-port* "runs:expand-items: (or (null? prereqs-not-met) (and (member 'toplevel testmode)(null? non-completed)))")
      (let ((test-name (tests:testqueue-get-testname test-record)))
	(setenv "MT_TEST_NAME" test-name) ;; 
	(setenv "MT_RUNNAME"   runname)
	(runs:set-megatest-env-vars run-id inrunname: runname) ;; these may be needed by the launching process
	(let ((items-list (items:get-items-from-config tconfig)))
	  (if (list? items-list)
	      (begin
		(if (null? items-list)
		    (let ((test-id (rmt:get-test-id run-id test-name "")))
		      (if test-id (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "ZERO_ITEMS" "Failed to run due to failed prerequisites"))))
		    (let ((test-id   (rmt:get-test-id run-id test-name ""))
			  (num-items (rmt:test-toplevel-num-items run-id test-name)))
		      (if (and test-id
			       (not (> num-items 0)))
			  (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "ZERO_ITEMS" "Failed to run due to failed prerequisites"))))
		(tests:testqueue-set-items! test-record items-list)
		(list hed tal reg reruns))
	      (begin
		(debug:print 0 "ERROR: The proc from reading the items table did not yield a list - please report this")
		(debug:print-error 0 *default-log-port* "The proc from reading the items table did not yield a list - please report this")
		(exit 1))))))

     ((and (null? fails)
	   (null? prereq-fails)
	   (not (null? non-completed)))
      (let* ((allinqueue (map (lambda (x)(if (string? x) x (dbr:test-testname x)))
        		      (append newtal reruns)))
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661

662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678
679
680

681
682
683
684
685
686
687
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621

622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637
638
639
640
641







-
+



















-
+






-
+











-
+







			    (set! give-up #t)))
		      prereqstrs))

	(if (and give-up
		 (not (and (null? tal)(null? reg))))
	    (let ((trimmed-tal (mt:discard-blocked-tests run-id hed tal test-records))
		  (trimmed-reg (mt:discard-blocked-tests run-id hed reg test-records)))
	      (debug:print 1 "WARNING: test " hed " has discarded prerequisites, removing it from the queue")
	      (debug:print 1 *default-log-port* "WARNING: test " hed " has discarded prerequisites, removing it from the queue")

	      (let ((test-id (rmt:get-test-id run-id hed "")))
		(if test-id (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "PREQ_DISCARDED" "Failed to run due to discarded prerequisites")))
	      
	      (if (and (null? trimmed-tal)
		       (null? trimmed-reg))
		  #f
		  (list (runs:queue-next-hed trimmed-tal trimmed-reg reglen regfull)
			(runs:queue-next-tal trimmed-tal trimmed-reg reglen regfull)
			(runs:queue-next-reg trimmed-tal trimmed-reg reglen regfull)
			reruns)))
	      (list (car newtal)(append (cdr newtal) reg) '() reruns))))

     ((and (null? fails)
	   (null? prereq-fails)
	   (null? non-completed))
      (if  (runs:can-keep-running? hed 20)
	  (begin
	    (runs:inc-cant-run-tests hed)
	    (debug:print-info 1 "no fails in prerequisites for " hed " but also none running, keeping " hed " for now. Try count: " (hash-table-ref/default *seen-cant-run-tests* hed 0))
	    (debug:print-info 1 *default-log-port* "no fails in prerequisites for " hed " but also none running, keeping " hed " for now. Try count: " (hash-table-ref/default *seen-cant-run-tests* hed 0))
	    ;; getting here likely means the system is way overloaded, kill a full minute before continuing
	    (thread-sleep! 60)
	    ;; num-retries code was here
	    ;; we use this opportunity to move contents of reg to tal
	    (list (car newtal)(append (cdr newtal) reg) '() reruns)) ;; an issue with prereqs not yet met?
	  (begin
	    (debug:print-info 1 "no fails in prerequisites for " hed " but nothing seen running in a while, dropping test " hed " from the run queue")
	    (debug:print-info 1 *default-log-port* "no fails in prerequisites for " hed " but nothing seen running in a while, dropping test " hed " from the run queue")
	    (let ((test-id (rmt:get-test-id run-id hed "")))
	      (if test-id (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "TIMED_OUT" "Nothing seen running in a while.")))
	    (list (runs:queue-next-hed tal reg reglen regfull)
		  (runs:queue-next-tal tal reg reglen regfull)
		  (runs:queue-next-reg tal reg reglen regfull)
		  reruns))))

     ((and 
       (or (not (null? fails))
	   (not (null? prereq-fails)))
       (member 'normal testmode))
      (debug:print-info 1 "test "  hed " (mode=" testmode ") has failed prerequisite(s); "
      (debug:print-info 1 *default-log-port* "test "  hed " (mode=" testmode ") has failed prerequisite(s); "
			(string-intersperse (map (lambda (t)(conc (dbr:test-testname t) ":" (dbr:test-state t)"/"(dbr:test-status t))) fails) ", ")
			", removing it from to-do list")
      (let ((test-id (rmt:get-test-id run-id hed "")))
	(if test-id
	    (if (not (null? prereq-fails))
		(mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "PREQ_DISCARDED" "Failed to run due to prior failed prerequisites")
		(mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "PREQ_FAIL"      "Failed to run due to failed prerequisites"))))
696
697
698
699
700
701
702
703

704
705
706
707
708
709
710
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664







-
+








     ((and (not (null? fails))(member 'toplevel testmode))
      (if (or (not (null? reg))(not (null? tal)))
	   (list (car newtal)(append (cdr newtal) reg) '() reruns)
	  #f)) 
     ((null? runnables) #f) ;; if we get here and non-completed is null the it's all over.
     (else
      (debug:print 0 "WARNING: FAILS or incomplete tests maybe preventing completion of this run. Watch for issues with test " hed ", continuing for now")
      (debug:print 0 *default-log-port* "WARNING: FAILS or incomplete tests maybe preventing completion of this run. Watch for issues with test " hed ", continuing for now")
      ;; (list (runs:queue-next-hed tal reg reglen regfull)
      ;;   	(runs:queue-next-tal tal reg reglen regfull)
      ;;   	(runs:queue-next-reg tal reg reglen regfull)
      ;;   	reruns)
      (list (car newtal)(cdr newtal) reg reruns)))))

(define (runs:mixed-list-testname-and-testrec->list-of-strings inlst)
720
721
722
723
724
725
726

727
728
729
730
731
732
733
734







































735

736




737
738
739
740
741
742
743
744
745

746
747
748
749
750
751
752
753
754
755
756
757
758
759

760
761
762
763

764
765
766
767
768
769
770
771
772

773
774
775
776
777
778
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

816
817
818
819
820
821
822
823
824
825
826
827
828

829
830
831
832
833
834
835
674
675
676
677
678
679
680
681








682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722

723
724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744
745
746
747
748

749
750
751
752

753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769
770
771
772

773
774
775
776
777
778
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
816
817

818
819
820
821
822
823
824
825







+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
+
+
+
+








-
+













-
+



-
+








-
+










-
+









-
+





-
+















-
+












-
+







		 (conc test-name (if (equal? item-path "") "" "/") item-path ":" test-state "/" test-status)))
	      ((string? t)
	       t)
	      (else 
	       (conc t))))
	   inlst)))


(define (runs:process-expanded-tests hed tal reg reruns reglen regfull test-record runname test-name item-path jobgroup max-concurrent-jobs run-id waitons item-path testmode test-patts required-tests test-registry registry-mutex flags keyvals run-info newtal all-tests-registry itemmaps)
  (let* ((run-limits-info         (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs)) ;; look at the test jobgroup and tot jobs running
	 (have-resources          (car run-limits-info))
	 (num-running             (list-ref run-limits-info 1))
	 (num-running-in-jobgroup (list-ref run-limits-info 2)) 
	 (max-concurrent-jobs     (list-ref run-limits-info 3))
	 (job-group-limit         (list-ref run-limits-info 4))
	 (prereqs-not-met         (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps))
;;  hed tal reg reruns reglen regfull test-record runname test-name item-path jobgroup max-concurrent-jobs run-id waitons item-path testmode test-patts required-tests test-registry registry-mutex flags keyvals run-info newtal all-tests-registry itemmaps)
(define (runs:process-expanded-tests runsdat testdat)
  ;; unroll the contents of runsdat and testdat (due to ongoing refactoring).
  (let* ((hed                    (runs:testdat-hed testdat))
	 (tal                    (runs:testdat-tal testdat))
	 (reg                    (runs:testdat-reg testdat))
	 (reruns                 (runs:testdat-reruns testdat))
	 (test-name              (runs:testdat-test-name testdat))
	 (item-path              (runs:testdat-item-path testdat))
	 (jobgroup               (runs:testdat-jobgroup testdat))
	 (waitons                (runs:testdat-waitons testdat))
	 (item-path              (runs:testdat-item-path testdat))
	 (testmode               (runs:testdat-testmode testdat))
	 (newtal                 (runs:testdat-newtal testdat))
	 (itemmaps               (runs:testdat-itemmaps testdat))
	 (test-record            (runs:testdat-test-record testdat))
	 (prereqs-not-met        (runs:testdat-prereqs-not-met testdat))

	 (reglen                 (runs:dat-reglen runsdat))
	 (regfull                (runs:dat-regfull runsdat))
	 (runname                (runs:dat-runname runsdat))
	 (max-concurrent-jobs    (runs:dat-max-concurrent-jobs runsdat))
	 (run-id                 (runs:dat-run-id runsdat))
	 (test-patts             (runs:dat-test-patts runsdat))
	 (required-tests         (runs:dat-required-tests runsdat))
	 (test-registry          (runs:dat-test-registry runsdat))
	 (registry-mutex         (runs:dat-registry-mutex runsdat))
	 (flags                  (runs:dat-flags runsdat))
	 (keyvals                (runs:dat-keyvals runsdat))
	 (run-info               (runs:dat-run-info runsdat))
	 (all-tests-registry     (runs:dat-all-tests-registry runsdat))
	 (run-limits-info        (runs:dat-can-run-more-tests runsdat))
	 ;; (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs)) ;; look at the test jobgroup and tot jobs running
	 (have-resources         (car run-limits-info))
	 (num-running            (list-ref run-limits-info 1))
	 (num-running-in-jobgroup(list-ref run-limits-info 2)) 
	 (max-concurrent-jobs    (list-ref run-limits-info 3))
	 (job-group-limit        (list-ref run-limits-info 4))
	 ;; (prereqs-not-met        (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps))
	 ;; (prereqs-not-met         (mt:lazy-get-prereqs-not-met run-id waitons item-path mode: testmode itemmap: itemmap))
	 (fails                  (if (list? prereqs-not-met)
	 (fails                   (runs:calc-fails prereqs-not-met))
				      (runs:calc-fails prereqs-not-met)
				      (begin
					(debug:print-error 0 *default-log-port* "prereqs-not-met is not a list! " prereqs-not-met)
					'())))
	 (non-completed           (filter (lambda (x)             ;; remove hed from not completed list, duh, of course it is not completed!
					    (not (equal? x hed)))
					  (runs:calc-not-completed prereqs-not-met)))
	 (loop-list               (list hed tal reg reruns))
	 ;; configure the load runner
	 (numcpus                 (common:get-num-cpus))
	 (maxload                 (string->number (or (configf:lookup *configdat* "jobtools" "maxload") "3")))
	 (waitdelay               (string->number (or (configf:lookup *configdat* "jobtools" "waitdelay") "60"))))
    (debug:print-info 4 "have-resources: " have-resources " prereqs-not-met: (" 
    (debug:print-info 4 *default-log-port* "have-resources: " have-resources " prereqs-not-met: (" 
		      (string-intersperse 
		       (map (lambda (t)
			      (if (vector? t)
				  (conc (dbr:test-state t) "/" (dbr:test-status t))
				  (conc " WARNING: t is not a vector=" t )))
			    prereqs-not-met)
		       ", ") ") fails: " fails
		       "\nregistered? " (hash-table-ref/default test-registry (db:test-make-full-name test-name item-path) #f))
			    

    
    (if (and (not (null? prereqs-not-met))
	     (runs:lownoise (conc "waiting on tests " prereqs-not-met hed) 60))
	(debug:print-info 2 "waiting on tests; " (string-intersperse (runs:mixed-list-testname-and-testrec->list-of-strings prereqs-not-met) ", ")))
	(debug:print-info 2 *default-log-port* "waiting on tests; " (string-intersperse (runs:mixed-list-testname-and-testrec->list-of-strings prereqs-not-met) ", ")))

    ;; Don't know at this time if the test have been launched at some time in the past
    ;; i.e. is this a re-launch?
    (debug:print-info 4 "run-limits-info = " run-limits-info)
    (debug:print-info 4 *default-log-port* "run-limits-info = " run-limits-info)
    
    (cond
     
     ;; Check item path against item-patts, 
     ;;
     ((not (tests:match test-patts (tests:testqueue-get-testname test-record) item-path required: required-tests)) ;; This test/itempath is not to be run
      ;; else the run is stuck, temporarily or permanently
      ;; but should check if it is due to lack of resources vs. prerequisites
      (debug:print-info 1 "Skipping " (tests:testqueue-get-testname test-record) " " item-path " as it doesn't match " test-patts)
      (debug:print-info 1 *default-log-port* "Skipping " (tests:testqueue-get-testname test-record) " " item-path " as it doesn't match " test-patts)
      (if (or (not (null? tal))(not (null? reg)))
	  (list (runs:queue-next-hed tal reg reglen regfull)
		(runs:queue-next-tal tal reg reglen regfull)
		(runs:queue-next-reg tal reg reglen regfull)
		reruns)
	  #f))
     
     ;; Register tests 
     ;;
     ((not (hash-table-ref/default test-registry (db:test-make-full-name test-name item-path) #f))
      (debug:print-info 4 "Pre-registering test " test-name "/" item-path " to create placeholder" )
      (debug:print-info 4 *default-log-port* "Pre-registering test " test-name "/" item-path " to create placeholder" )
      ;; always do firm registration now in v1.60 and greater ;; (eq? *transport-type* 'fs) ;; no point in parallel registration if use fs
      (let register-loop ((numtries 15))
	(rmt:register-test run-id test-name item-path)
	(if (rmt:get-test-id run-id test-name item-path)
	    (hash-table-set! test-registry (db:test-make-full-name test-name item-path) 'done)
	    (if (> numtries 0)
		(begin
		  (thread-sleep! 0.5)
		  (register-loop (- numtries 1)))
		(debug:print 0 "ERROR: failed to register test " (db:test-make-full-name test-name item-path)))))
		(debug:print-error 0 *default-log-port* "failed to register test " (db:test-make-full-name test-name item-path)))))
      (if (not (eq? (hash-table-ref/default test-registry (db:test-make-full-name test-name "") #f) 'done))
	  (begin
	    (rmt:register-test run-id test-name "")
	    (if (rmt:get-test-id run-id test-name "")
		(hash-table-set! test-registry (db:test-make-full-name test-name "") 'done))))
      (runs:shrink-can-run-more-tests-count)   ;; DELAY TWEAKER (still needed?)
      (runs:shrink-can-run-more-tests-count runsdat)   ;; DELAY TWEAKER (still needed?)
      (if (and (null? tal)(null? reg))
	  (list hed tal (append reg (list hed)) reruns)
	  (list (runs:queue-next-hed tal reg reglen regfull)
		(runs:queue-next-tal tal reg reglen regfull)
		;; NB// Here we are building reg as we register tests
		;; if regfull we must pop the front item off reg
		(if regfull
		    (append (cdr reg) (list hed))
		    (append reg (list hed)))
		reruns)))
     
     ;; At this point hed test registration must be completed.
     ;;
     ((eq? (hash-table-ref/default test-registry (db:test-make-full-name test-name item-path) #f)
	   'start)
      (debug:print-info 0 "Waiting on test registration(s): "
      (debug:print-info 0 *default-log-port* "Waiting on test registration(s): "
			(string-intersperse 
			 (filter (lambda (x)
				   (eq? (hash-table-ref/default test-registry x #f) 'start))
				 (hash-table-keys test-registry))
			 ", "))
      (thread-sleep! 0.051)
      (list hed tal reg reruns))
     
     ;; If no resources are available just kill time and loop again
     ;;
     ((not have-resources) ;; simply try again after waiting a second
      (if (runs:lownoise "no resources" 60)
	  (debug:print-info 1 "no resources to run new tests, waiting ..."))
	  (debug:print-info 1 *default-log-port* "no resources to run new tests, waiting ..."))
      ;; Have gone back and forth on this but db starvation is an issue.
      ;; wait one second before looking again to run jobs.
      (thread-sleep! 1)
      ;; could have done hed tal here but doing car/cdr of newtal to rotate tests
      (list (car newtal)(cdr newtal) reg reruns))
     
     ;; This is the final stage, everything is in place so launch the test
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
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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024


1025

1026
1027
1028
1029
1030
1031
1032
833
834
835
836
837
838
839
840
841

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


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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115

1116
1117
1118
1119
1120
1121
1122
1123







+

-
+











-
+





-
+







-
+






-
+



-
+













-
+












-
+

-
+














-
+








-
-
+
+


















+
















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









-
+





-
+













-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


















+
+
-
+







      ;; this means they will increment only when nothing can be run
      (set! *max-tries-hash* (make-hash-table))
      ;; well, first lets see if cpu load throttling is enabled. If so wait around until the
      ;; average cpu load is under the threshold before continuing
      (if (configf:lookup *configdat* "jobtools" "maxload") ;; only gate if maxload is specified
	  (common:wait-for-cpuload maxload numcpus waitdelay))
      (run:test run-id run-info keyvals runname test-record flags #f test-registry all-tests-registry)
      (runs:incremental-print-results run-id)
      (hash-table-set! test-registry (db:test-make-full-name test-name item-path) 'running)
      (runs:shrink-can-run-more-tests-count)  ;; DELAY TWEAKER (still needed?)
      (runs:shrink-can-run-more-tests-count runsdat)  ;; DELAY TWEAKER (still needed?)
      ;; (thread-sleep! *global-delta*)
      (if (or (not (null? tal))(not (null? reg)))
	  (list (runs:queue-next-hed tal reg reglen regfull)
		(runs:queue-next-tal tal reg reglen regfull)
		(runs:queue-next-reg tal reg reglen regfull)
		reruns)
	  #f))
     
     ;; must be we have unmet prerequisites
     ;;
     (else
      (debug:print 4 "FAILS: " fails)
      (debug:print 4 *default-log-port* "FAILS: " fails)
      ;; If one or more of the prereqs-not-met are FAIL then we can issue
      ;; a message and drop hed from the items to be processed.
      ;; (runs:mixed-list-testname-and-testrec->list-of-strings prereqs-not-met)
      (if (and (not (null? prereqs-not-met))
	       (runs:lownoise (conc "waiting on tests " prereqs-not-met hed) 60))
	  (debug:print-info 1 "waiting on tests; " (string-intersperse 
	  (debug:print-info 1 *default-log-port* "waiting on tests; " (string-intersperse 
						    (runs:mixed-list-testname-and-testrec->list-of-strings 
						     prereqs-not-met) ", ")))
      (if (or (null? fails)
	      (member 'toplevel testmode))
	  (begin
	    ;; couldn't run, take a breather
	    (if  (runs:lownoise "Waiting for more work to do..." 60)
		 (debug:print-info 0 "Waiting for more work to do..."))
		 (debug:print-info 0 *default-log-port* "Waiting for more work to do..."))
	    (thread-sleep! 1)
	    (list (car newtal)(cdr newtal) reg reruns))
	  ;; the waiton is FAIL so no point in trying to run hed ever again
	  (if (or (not (null? reg))(not (null? tal)))
	      (if (vector? hed)
		  (begin
		    (debug:print 1 "WARNING: Dropping test " test-name "/" item-path
		    (debug:print 1 *default-log-port* "WARNING: Dropping test " test-name "/" item-path
				 " from the launch list as it has prerequistes that are FAIL")
		    (let ((test-id (rmt:get-test-id run-id hed "")))
		      (if test-id (mt:test-set-state-status-by-id run-id test-id "NOT_STARTED" "PREQ_FAIL" "Failed to run due to failed prerequisites")))
		    (runs:shrink-can-run-more-tests-count) ;; DELAY TWEAKER (still needed?)
		    (runs:shrink-can-run-more-tests-count runsdat) ;; DELAY TWEAKER (still needed?)
		    ;; (thread-sleep! *global-delta*)
		    ;; This next is for the items
		    (mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "BLOCKED" #f)
		    (hash-table-set! test-registry (db:test-make-full-name test-name item-path) 'removed)
		    (list (runs:queue-next-hed tal reg reglen regfull)
			  (runs:queue-next-tal tal reg reglen regfull)
			  (runs:queue-next-reg tal reg reglen regfull)
			  reruns ;; WAS: (cons hed reruns) ;; but that makes no sense?
			  ))
		  (let ((nth-try (hash-table-ref/default test-registry hed 0)))
		    (cond
		     ((member "RUNNING" (map dbr:test-state prereqs-not-met))
		      (if (runs:lownoise (conc "possible RUNNING prerequistes " hed) 60)
			  (debug:print 0 "WARNING: test " hed " has possible RUNNING prerequisites, don't give up on it yet."))
			  (debug:print 0 *default-log-port* "WARNING: test " hed " has possible RUNNING prerequisites, don't give up on it yet."))
		      (thread-sleep! 4)
		      (list (runs:queue-next-hed newtal reg reglen regfull)
			    (runs:queue-next-tal newtal reg reglen regfull)
			    (runs:queue-next-reg newtal reg reglen regfull)
			    reruns))
		     ((or (not nth-try)
			  (and (number? nth-try)
			       (< nth-try 10)))
		      (hash-table-set! test-registry hed (if (number? nth-try)
							     (+ nth-try 1)
							     0))
		      (if (runs:lownoise (conc "not removing test " hed) 60)
			  (debug:print 1 "WARNING: not removing test " hed " from queue although it may not be runnable due to FAILED prerequisites"))
			  (debug:print 1 *default-log-port* "WARNING: not removing test " hed " from queue although it may not be runnable due to FAILED prerequisites"))
		      ;; may not have processed correctly. Could be a race condition in your test implementation? Dropping test " hed) ;;  " as it has prerequistes that are FAIL. (NOTE: hed is not a vector)")
		      (runs:shrink-can-run-more-tests-count) ;; DELAY TWEAKER (still needed?)
		      (runs:shrink-can-run-more-tests-count runsdat) ;; DELAY TWEAKER (still needed?)
		      ;; (list hed tal reg reruns)
		      ;; (list (car newtal)(cdr newtal) reg reruns)
		      ;; (hash-table-set! test-registry hed 'removed)
		      (list (runs:queue-next-hed newtal reg reglen regfull)
			    (runs:queue-next-tal newtal reg reglen regfull)
			    (runs:queue-next-reg newtal reg reglen regfull)
			    reruns))
		     ((symbol? nth-try)
		      (if (eq? nth-try 'removed) ;; removed is removed - drop it NOW
			  (if (null? tal)
			      #f ;; yes, really
			      (list (car tal)(cdr tal) reg reruns))
			  (begin
			    (if (runs:lownoise (conc "FAILED prerequisites or other issue" hed) 60)
				(debug:print 0 "WARNING: test " hed " has FAILED prerequisites or other issue. Internal state " nth-try " will be overridden and we'll retry."))
				(debug:print 0 *default-log-port* "WARNING: test " hed " has FAILED prerequisites or other issue. Internal state " nth-try " will be overridden and we'll retry."))
			    (mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "KEEP_TRYING" #f)
			    (hash-table-set! test-registry hed 0)
			    (list (runs:queue-next-hed newtal reg reglen regfull)
				  (runs:queue-next-tal newtal reg reglen regfull)
				  (runs:queue-next-reg newtal reg reglen regfull)
				  reruns))))
		     (else
		      (if (runs:lownoise (conc "FAILED prerequitests and we tried" hed) 60)
			  (debug:print 0 "WARNING: test " hed " has FAILED prerequitests and we've tried at least 10 times to run it. Giving up now."))
		      ;; (debug:print 0 "         prereqs: " prereqs-not-met)
			  (debug:print 0 *default-log-port* "WARNING: test " hed " has FAILED prerequitests and we've tried at least 10 times to run it. Giving up now."))
		      ;; (debug:print 0 *default-log-port* "         prereqs: " prereqs-not-met)
		      (hash-table-set! test-registry hed 'removed)
		      (mt:test-set-state-status-by-testname run-id test-name item-path "NOT_STARTED" "TEN_STRIKES" #f)
		      ;; I'm unclear on if this roll up is needed - it may be the root cause of the "all set to FAIL" bug.
		      (rmt:roll-up-pass-fail-counts run-id test-name item-path #f "FAIL") ;; treat as FAIL
		      (list (if (null? tal)(car newtal)(car tal))
			    tal
			    reg
			    reruns)))))
	      ;; can't drop this - maybe running? Just keep trying
	      (let ((runable-tests (runs:runable-tests prereqs-not-met)))
		(if (null? runable-tests)
		    #f   ;; I think we are truly done here
		    (list (runs:queue-next-hed newtal reg reglen regfull)
			    (runs:queue-next-tal newtal reg reglen regfull)
			    (runs:queue-next-reg newtal reg reglen regfull)
			    reruns)))))))))

;; scan a list of tests looking to see if any are potentially runnable
;;
(define (runs:runable-tests tests)
  (filter (lambda (t)
	    (if (not (vector? t))
		t
		(let ((state  (dbr:test-state t))
		      (status (dbr:test-status t)))
		  (case (string->symbol state)
		    ((COMPLETED INCOMPLETE) #f)
		    ((NOT_STARTED)
		     (if (member status '("TEN_STRIKES" "BLOCKED" "PREQ_FAIL" "ZERO_ITEMS" "PREQ_DISCARDED" "TIMED_OUT" ))
			 #f
			 t))
		    ((DELETED) #f)
		    (else t)))))
	  tests))

;; move all the miscellanea into this struct
;;
(defstruct runs:gendat inc-results inc-results-last-update inc-results-fmt run-info runname target)

(define *runs:general-data* 
  (make-runs:gendat
   inc-results: (make-hash-table)
   inc-results-last-update: 0
   inc-results-fmt: "~12a~12a~20a~12a~40a\n" ;; state status time duration test-name item-path
   run-info: #f
   runname: #f
   target: #f
   )
)

(define (runs:incremental-print-results run-id)
  (let ((curr-sec (current-seconds)))
    (if (> (- curr-sec (runs:gendat-inc-results-last-update *runs:general-data*)) 5) ;; at least five seconds since last update
	(let* ((run-dat  (or (runs:gendat-run-info *runs:general-data*)(rmt:get-run-info run-id)))
	       (runname  (or (runs:gendat-runname *runs:general-data*)
			     (db:get-value-by-header (db:get-rows run-dat)
						     (db:get-header run-dat) "runname")))
	       (target   (or (runs:gendat-target *runs:general-data*)(rmt:get-target run-id)))
	       (testsdat (rmt:get-tests-for-run run-id "%" '() '() ;; run-id testpatt states statuses
						#f #f ;; offset limit
						#f ;; not-in
						#f ;; sort-by
						#f ;; sort-order
						#f ;; get full data (not 'shortlist)
						(runs:gendat-inc-results-last-update *runs:general-data*) ;; last update time
						'dashboard)))
	  (if (not (runs:gendat-run-info *runs:general-data*))
	      (runs:gendat-run-info-set! *runs:general-data* run-dat))
	  (if (not (runs:gendat-runname  *runs:general-data*))
	      (runs:gendat-runname-set! *runs:general-data* runname))
	  (if (not (runs:gendat-target *runs:general-data*))
	      (runs:gendat-target-set! *runs:general-data* target))
	  (for-each
	   (lambda (testdat)
	     (let* ((test-id    (db:test-get-id           testdat))
		    (prevdat    (hash-table-ref/default   (runs:gendat-inc-results *runs:general-data*)
							  (conc run-id "," test-id) #f))
		    (test-name  (db:test-get-testname     testdat))
		    (item-path  (db:test-get-item-path    testdat))
		    (state      (db:test-get-state        testdat))
		    (status     (db:test-get-status       testdat))
		    (event-time (db:test-get-event_time   testdat))
		    (duration   (db:test-get-run_duration testdat)))
	       (if (and (not (member state '("DELETED" "REMOTEHOSTSTART" "RUNNING" "LAUNCHED""NOT_STARTED")))
			(not (and prevdat
				  (equal? state  (db:test-get-state  prevdat))
				  (equal? status (db:test-get-status prevdat)))))
		   (let ((fmt   (runs:gendat-inc-results-fmt *runs:general-data*))
			 (dtime (seconds->year-work-week/day-time event-time))) 
		     (if (runs:lownoise "inc-print" 600)
			 (format #t fmt "State" "Status" "Start Time" "Duration" "Test path"))
		     ;; (debug:print 0 *default-log-port* "fmt: " fmt " state: " state " status: " status " test-name: " test-name " item-path: " item-path " dtime: " dtime)
		     ;; (debug:print 0 #f "event-time: " event-time " duration: " duration)
		     (format #t fmt
			     state
			     status
			     dtime
			     (seconds->hr-min-sec duration)
			     (conc "lt/" target "/" runname "/" test-name (if (string-null? item-path) "" (conc "/" item-path))))
		     (hash-table-set! (runs:gendat-inc-results *runs:general-data*) (conc run-id "," test-id) testdat)))))
	   testsdat)))
    (runs:gendat-inc-results-last-update-set! *runs:general-data* (- curr-sec 10))))

;; every time though the loop increment the test/itempatt val.
;; when the min is > max-allowed and none running then force exit
;;
(define *max-tries-hash* (make-hash-table))

;; test-records is a hash table testname:item_path => vector < testname testconfig waitons priority items-info ... >
(define (runs:run-tests-queue run-id runname test-records keyvals flags test-patts required-tests reglen-in all-tests-registry)
  ;; At this point the list of parent tests is expanded 
  ;; NB// Should expand items here and then insert into the run queue.
  (debug:print 5 "test-records: " test-records ", flags: " (hash-table->alist flags))
  (debug:print 5 *default-log-port* "test-records: " test-records ", flags: " (hash-table->alist flags))

  ;; Do mark-and-find clean up of db before starting runing of quue
  ;;
  ;; (rmt:find-and-mark-incomplete)

  (let ((run-info              (rmt:get-run-info run-id))
  (let* ((run-info              (rmt:get-run-info run-id))
	(tests-info            (mt:get-tests-for-run run-id #f '() '())) ;;  qryvals: "id,testname,item_path"))
	(sorted-test-names     (tests:sort-by-priority-and-waiton test-records))
	(test-registry         (make-hash-table))
	(registry-mutex        (make-mutex))
	(num-retries           0)
	(max-retries           (config-lookup *configdat* "setup" "maxretries"))
	(max-concurrent-jobs   (let ((mcj (config-lookup *configdat* "setup"     "max_concurrent_jobs")))
				 (if (and mcj (string->number mcj))
				     (string->number mcj)
				     1))) ;; length of the register queue ahead
	(reglen                (if (number? reglen-in) reglen-in 1))
	(last-time-incomplete  (- (current-seconds) 900)) ;; force at least one clean up cycle
	(last-time-some-running (current-seconds))
	(tdbdat                (tasks:open-db)))
	(tdbdat                (tasks:open-db))
	(runsdat (make-runs:dat
		  ;; hed: hed
		  ;; tal: tal
		  ;; reg: reg
		  ;; reruns: reruns
		  reglen: reglen
		  regfull: #f ;; regfull
		  ;; test-record: test-record
		  runname: runname
		  ;; test-name: test-name
		  ;; item-path: item-path
		  ;; jobgroup: jobgroup
		  max-concurrent-jobs: max-concurrent-jobs
		  run-id: run-id
		  ;; waitons: waitons
		  ;; testmode: testmode
		  test-patts: test-patts
		  required-tests: required-tests
		  test-registry: test-registry
		  registry-mutex: registry-mutex
		  flags: flags
		  keyvals: keyvals
		  run-info: run-info
		  ;; newtal: newtal
		  all-tests-registry: all-tests-registry
		  ;; itemmaps: itemmaps
		  ;; prereqs-not-met: (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps)
		  ;; can-run-more-tests: (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs) ;; look at the test jobgroup and tot jobs running
		  )))

    ;; Initialize the test-registery hash with tests that already have a record
    ;; convert state to symbol and use that as the hash value
    (for-each (lambda (trec)
		(let ((id (dbr:test-id        trec))
		      (tn (dbr:test-testname  trec))
		      (ip (dbr:test-item-path trec))
		      (st (dbr:test-state     trec)))
		  (if (not (equal? st "DELETED"))
		      (hash-table-set! test-registry (db:test-make-full-name tn ip) (string->symbol st)))))
	      tests-info)
    (set! max-retries (if (and max-retries (string->number max-retries))(string->number max-retries) 100))

    (let loop ((hed         (car sorted-test-names))
	       (tal         (cdr sorted-test-names))
	       (reg         '()) ;; registered, put these at the head of tal 
	       (reruns      '()))

      (runs:incremental-print-results run-id)

      (if (not (null? reruns))(debug:print-info 4 "reruns=" reruns))
      (if (not (null? reruns))(debug:print-info 4 *default-log-port* "reruns=" reruns))

      ;; Here we mark any old defunct tests as incomplete. Do this every fifteen minutes
      ;; moving this to a parallel thread and just run it once.
      ;;
      (if (> (current-seconds)(+ last-time-incomplete 900))
          (begin
            (set! last-time-incomplete (current-seconds))
1045
1046
1047
1048
1049
1050
1051
1052
1053

















1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086

1087

1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107

1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131

1132
1133
1134


1135
1136


1137
1138
1139
1140
1141
1142

1143
1144
1145
1146
1147
1148
1149

1150
1151
1152
1153
1154
1155
1156
1136
1137
1138
1139
1140
1141
1142


1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
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
1184

1185
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213

1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242
1243


1244
1245
1246
1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257

1258
1259
1260
1261
1262
1263
1264
1265







-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










-
+














-
+







+
-
+



















-
+

















-
+





-
+



+
+
-
-
+
+





-
+






-
+







	     (priority    (tests:testqueue-get-priority   test-record))
	     (itemdat     (tests:testqueue-get-itemdat    test-record)) ;; itemdat can be a string, list or #f
	     (items       (tests:testqueue-get-items      test-record))
	     (item-path   (item-list->path itemdat))
	     (tfullname   (db:test-make-full-name test-name item-path))
	     (newtal      (append tal (list hed)))
	     (regfull     (>= (length reg) reglen))
	     (num-running (rmt:get-count-tests-running-for-run-id run-id)))

	     (num-running (rmt:get-count-tests-running-for-run-id run-id))
	     (testdat     (make-runs:testdat
			   hed: hed
			   tal: tal
			   reg: reg
			   reruns: reruns
			   test-record: test-record
			   test-name:   test-name
			   item-path:   item-path
			   jobgroup:    jobgroup
			   waitons:     waitons
			   testmode:    testmode
			   newtal:      newtal
			   itemmaps:    itemmaps
			   ;; prereqs-not-met: prereqs-not-met
			   )))
	(runs:dat-regfull-set! runsdat regfull)
	;; every couple minutes verify the server is there for this run
	(if (and (common:low-noise-print 60 "try start server"  run-id)
		 (tasks:need-server run-id))
	    (tasks:start-and-wait-for-server tdbdat run-id 10)) ;; NOTE: delay and wait is done under the hood
	
	(if (> num-running 0)
	  (set! last-time-some-running (current-seconds)))

      (if (> (current-seconds)(+ last-time-some-running (or (configf:lookup *configdat* "setup" "give-up-waiting") 36000)))
	  (hash-table-set! *max-tries-hash* tfullname (+ (hash-table-ref/default *max-tries-hash* tfullname 0) 1)))
	;; (debug:print 0 "max-tries-hash: " (hash-table->alist *max-tries-hash*))
	;; (debug:print 0 *default-log-port* "max-tries-hash: " (hash-table->alist *max-tries-hash*))

	;; Ensure all top level tests get registered. This way they show up as "NOT_STARTED" on the dashboard
	;; and it is clear they *should* have run but did not.
	(if (not (hash-table-ref/default test-registry (db:test-make-full-name test-name "") #f))
	    (begin
	      (rmt:register-test run-id test-name "")
	      (hash-table-set! test-registry (db:test-make-full-name test-name "") 'done)))
	
	;; Fast skip of tests that are already "COMPLETED" - NO! Cannot do that as the items may not have been expanded yet :(
	;;
	(if (member (hash-table-ref/default test-registry tfullname #f) 
		    '(DONOTRUN removed)) ;; *common:cant-run-states-sym*) ;; '(COMPLETED KILLED WAIVED UNKNOWN INCOMPLETE))
	    (begin
	      (if (runs:lownoise (conc "been marked do not run " tfullname) 60)
		  (debug:print-info 0 "Skipping test " tfullname " as it has been marked do not run due to being completed or not runnable"))
		  (debug:print-info 0 *default-log-port* "Skipping test " tfullname " as it has been marked do not run due to being completed or not runnable"))
	      (if (or (not (null? tal))(not (null? reg)))
		  (loop (runs:queue-next-hed tal reg reglen regfull)
			(runs:queue-next-tal tal reg reglen regfull)
			(runs:queue-next-reg tal reg reglen regfull)
			reruns))))
		  ;; (loop (car tal)(cdr tal) reg reruns))))

	(runs:incremental-print-results run-id)
	(debug:print 4 "TOP OF LOOP => "
	(debug:print 4 *default-log-port* "TOP OF LOOP => "
		     "test-name: " test-name
		     "\n  test-record  " test-record
		     "\n  hed:         " hed
		     "\n  itemdat:     " itemdat
		     "\n  items:       " items
		     "\n  item-path:   " item-path
		     "\n  waitons:     " waitons
		     "\n  num-retries: " num-retries
		     "\n  tal:         " tal
		     "\n  reruns:      " reruns
		     "\n  regfull:     " regfull
		     "\n  reglen:      " reglen
		     "\n  length reg:  " (length reg)
		     "\n  reg:         " reg)

	;; check for hed in waitons => this would be circular, remove it and issue an
	;; error
	(if (member test-name waitons)
	    (begin
	      (debug:print 0 "ERROR: test " test-name " has listed itself as a waiton, please correct this!")
	      (debug:print-error 0 *default-log-port* "test " test-name " has listed itself as a waiton, please correct this!")
	      (set! waiton (filter (lambda (x)(not (equal? x hed))) waitons))))

	(cond 
	 
	 ;; We want to catch tests that have waitons that are NOT in the queue and discard them IFF 
	 ;; they have been through the wringer 10 or more times
	 ((and (list? waitons)
	       (not (null? waitons))
	       (> (hash-table-ref/default *max-tries-hash* tfullname 0) 10)
	       (not (null? (filter
			    number?
			    (map (lambda (waiton)
				   (if (and (not (member waiton tal))            ;; this waiton is not in the list to be tried to run
					    (not (member waiton reruns)))
				       1
				       #f))
				 waitons))))) ;; could do this more elegantly with a marker....
	  (debug:print 0 "WARNING: Marking test " tfullname " as not runnable. It is waiting on tests that cannot be run. Giving up now.")
	  (debug:print 0 *default-log-port* "WARNING: Marking test " tfullname " as not runnable. It is waiting on tests that cannot be run. Giving up now.")
	  (hash-table-set! test-registry tfullname 'removed))

	 ;; items is #f then the test is ok to be handed off to launch (but not before)
	 ;; 
	 ((not items)
	  (debug:print-info 4 "OUTER COND: (not items)")
	  (debug:print-info 4 *default-log-port* "OUTER COND: (not items)")
	  (if (and (not (tests:match test-patts (tests:testqueue-get-testname test-record) item-path required: required-tests))
		   (not (null? tal)))
	      (loop (car tal)(cdr tal) reg reruns))
	  (runs:testdat-prereqs-not-met-set! testdat (rmt:get-prereqs-not-met run-id waitons hed item-path mode: testmode itemmaps: itemmaps))
	  (runs:dat-can-run-more-tests-set! runsdat (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs)) ;; look at the test jobgroup and tot jobs running
	  (let ((loop-list (runs:process-expanded-tests hed tal reg reruns reglen regfull test-record runname test-name item-path jobgroup max-concurrent-jobs run-id waitons item-path testmode test-patts required-tests test-registry registry-mutex flags keyvals run-info newtal all-tests-registry itemmaps)))
	    (if loop-list (apply loop loop-list))))
	  (let ((loop-list (runs:process-expanded-tests runsdat testdat)))
	      (if loop-list (apply loop loop-list))))

	 ;; items processed into a list but not came in as a list been processed
	 ;;
	 ((and (list? items)     ;; thus we know our items are already calculated
	       (not   itemdat))  ;; and not yet expanded into the list of things to be done
	  (debug:print-info 4 "OUTER COND: (and (list? items)(not itemdat))")
	  (debug:print-info 4 *default-log-port* "OUTER COND: (and (list? items)(not itemdat))")
	  ;; Must determine if the items list is valid. Discard the test if it is not.
	  (if (and (list? items)
		   (> (length items) 0)
		   (and (list? (car items))
			(> (length (car items)) 0))
		   (debug:debug-mode 1))
	      (debug:print 2 (map (lambda (row)
	      (debug:print 2 *default-log-port* (map (lambda (row)
				    (conc (string-intersperse
					   (map (lambda (varval)
						  (string-intersperse varval "="))
						row)
					   " ")
					  "\n"))
				  items)))
1165
1166
1167
1168
1169
1170
1171
1172

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187

1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211
1212

1213
1214

1215
1216
1217

1218
1219
1220
1221
1222
1223
1224

1225
1226
1227
1228
1229
1230

1231
1232
1233

1234
1235
1236
1237

1238
1239
1240
1241
1242
1243

1244
1245
1246
1247
1248
1249
1250
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311

1312
1313
1314
1315
1316
1317
1318
1319
1320

1321
1322

1323
1324
1325

1326
1327
1328
1329
1330
1331
1332

1333
1334
1335
1336
1337
1338

1339
1340
1341

1342
1343
1344
1345

1346
1347
1348
1349
1350
1351

1352
1353
1354
1355
1356
1357
1358
1359







-
+














-
+










-
+




-
+








-
+

-
+


-
+






-
+





-
+


-
+



-
+





-
+







		     (tests:testqueue-set-items!     new-test-record #f)
		     (tests:testqueue-set-itemdat!   new-test-record my-itemdat)
		     (tests:testqueue-set-item_path! new-test-record my-item-path)
		     (hash-table-set! test-records newtestname new-test-record)
		     (set! tal (append tal (list newtestname))))))) ;; since these are itemized create new test names testname/itempath
	   items)

	  ;; (debug:print-info 0 "Test " (tests:testqueue-get-testname test-record) " is itemized but has no items")
	  ;; (debug:print-info 0 *default-log-port* "Test " (tests:testqueue-get-testname test-record) " is itemized but has no items")

	  ;; At this point we have possibly added items to tal but all must be handed off to 
	  ;; INNER COND logic. I think loop without rotating the queue 
	  ;; (loop hed tal reg reruns))
	  ;; (let ((newtal (append tal (list hed))))  ;; We should discard hed as it has been expanded into it's items? Yes, but only if this *is* an itemized test
	  ;; (loop (car newtal)(cdr newtal) reg reruns)
	  (if (null? tal)
	      #f
	      (loop (car tal)(cdr tal) reg reruns)))
	    
	 ;; if items is a proc then need to run items:get-items-from-config, get the list and loop 
	 ;;    - but only do that if resources exist to kick off the job
	 ;; EXPAND ITEMS
	 ((or (procedure? items)(eq? items 'have-procedure))
	  (let ((can-run-more    (runs:can-run-more-tests run-id jobgroup max-concurrent-jobs)))
	  (let ((can-run-more    (runs:can-run-more-tests runsdat run-id jobgroup max-concurrent-jobs)))
	    (if (and (list? can-run-more)
		     (car can-run-more))
		(let ((loop-list (runs:expand-items hed tal reg reruns regfull newtal jobgroup max-concurrent-jobs run-id waitons item-path testmode test-record can-run-more items runname tconfig reglen test-registry test-records itemmaps)))
		  (if loop-list
		      (apply loop loop-list)))
		;; if can't run more just loop with next possible test
		(loop (car newtal)(cdr newtal) reg reruns))))
	    
	 ;; this case should not happen, added to help catch any bugs
	 ((and (list? items) itemdat)
	  (debug:print 0 "ERROR: Should not have a list of items in a test and the itemspath set - please report this")
	  (debug:print-error 0 *default-log-port* "Should not have a list of items in a test and the itemspath set - please report this")
	  (exit 1))
	 ((not (null? reruns))
	  (let* ((newlst (tests:filter-non-runnable run-id tal test-records)) ;; i.e. not FAIL, WAIVED, INCOMPLETE, PASS, KILLED,
		 (junked (lset-difference equal? tal newlst)))
	    (debug:print-info 4 "full drop through, if reruns is less than 100 we will force retry them, reruns=" reruns ", tal=" tal)
	    (debug:print-info 4 *default-log-port* "full drop through, if reruns is less than 100 we will force retry them, reruns=" reruns ", tal=" tal)
	    (if (< num-retries max-retries)
		(set! newlst (append reruns newlst)))
	    (set! num-retries (+ num-retries 1))
	    ;; (thread-sleep! (+ 1 *global-delta*))
	    (if (not (null? newlst))
		;; since reruns have been tacked on to newlst create new reruns from junked
		(loop (car newlst)(cdr newlst) reg (delete-duplicates junked)))))
	 ((not (null? tal))
	  (debug:print-info 4 "I'm pretty sure I shouldn't get here."))
	  (debug:print-info 4 *default-log-port* "I'm pretty sure I shouldn't get here."))
	 ((not (null? reg)) ;; could we get here with leftovers?
	  (debug:print-info 0 "Have leftovers!")
	  (debug:print-info 0 *default-log-port* "Have leftovers!")
	  (loop (car reg)(cdr reg) '() reruns))
	 (else
	  (debug:print-info 4 "Exiting loop with...\n  hed=" hed "\n  tal=" tal "\n  reruns=" reruns))
	  (debug:print-info 4 *default-log-port* "Exiting loop with...\n  hed=" hed "\n  tal=" tal "\n  reruns=" reruns))
	 )))
    ;; now *if* -run-wait we wait for all tests to be done
    ;; Now wait for any RUNNING tests to complete (if in run-wait mode)
    (thread-sleep! 5) ;; I think there is a race condition here. Let states/statuses settle
    (let wait-loop ((num-running      (rmt:get-count-tests-running-for-run-id run-id))
		    (prev-num-running 0))
      ;; (debug:print 0 "num-running=" num-running ", prev-num-running=" prev-num-running)
      ;; (debug:print 0 *default-log-port* "num-running=" num-running ", prev-num-running=" prev-num-running)
      (if (and (or (args:get-arg "-run-wait")
		   (equal? (configf:lookup *configdat* "setup" "run-wait") "yes"))
	       (> num-running 0))
	  (begin
	    ;; Here we mark any old defunct tests as incomplete. Do this every fifteen minutes
	    ;; (debug:print 0 "Got here eh! num-running=" num-running " (> num-running 0) " (> num-running 0))
	    ;; (debug:print 0 *default-log-port* "Got here eh! num-running=" num-running " (> num-running 0) " (> num-running 0))
	    (if (> (current-seconds)(+ last-time-incomplete 900))
		(begin
		  (debug:print-info 0 "Marking stuck tests as INCOMPLETE while waiting for run " run-id ". Running as pid " (current-process-id) " on " (get-host-name))
		  (debug:print-info 0 *default-log-port* "Marking stuck tests as INCOMPLETE while waiting for run " run-id ". Running as pid " (current-process-id) " on " (get-host-name))
		  (set! last-time-incomplete (current-seconds))
		  (rmt:find-and-mark-incomplete run-id #f)))
	    (if (not (eq? num-running prev-num-running))
		(debug:print-info 0 "run-wait specified, waiting on " num-running " tests in RUNNING, REMOTEHOSTSTART or LAUNCHED state at " (time->string (seconds->local-time (current-seconds)))))
		(debug:print-info 0 *default-log-port* "run-wait specified, waiting on " num-running " tests in RUNNING, REMOTEHOSTSTART or LAUNCHED state at " (time->string (seconds->local-time (current-seconds)))))
	    (thread-sleep! 5)
	    ;; (wait-loop (rmt:get-count-tests-running-for-run-id run-id) num-running))))
	    (wait-loop (rmt:get-count-tests-running-for-run-id run-id) num-running))))
    ;; LET* ((test-record
    ;; we get here on "drop through". All done!
    (debug:print-info 1 "All tests launched")))
    (debug:print-info 1 *default-log-port* "All tests launched")))

(define (runs:calc-fails prereqs-not-met)
  (filter (lambda (test)
	    (and (vector? test) ;; not (string? test))
		 (member (dbr:test-state test) '("INCOMPLETE" "COMPLETED"))
		 (not (member (dbr:test-status test)
			      '("PASS" "WARN" "CHECK" "WAIVED" "SKIP")))))
1285
1286
1287
1288
1289
1290
1291

1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314
1315
1316

1317
1318
1319
1320
1321
1322
1323
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432
1433







+



















-
+




-
+







  (map (lambda (t)
	 (if (not (vector? t))
	     (conc t)
	     (conc (dbr:test-testname t) ":" (dbr:test-state t) "/" (dbr:test-status t))))
       lst))

;; parent-test is there as a placeholder for when parent-tests can be run as a setup step
;;
(define (run:test run-id run-info keyvals runname test-record flags parent-test test-registry all-tests-registry)
  ;; All these vars might be referenced by the testconfig file reader
  (let* ((test-name    (tests:testqueue-get-testname   test-record))
	 (test-waitons (tests:testqueue-get-waitons    test-record))
	 (test-conf    (tests:testqueue-get-testconfig test-record))
	 (itemdat      (tests:testqueue-get-itemdat    test-record))
	 (test-path    (hash-table-ref all-tests-registry test-name)) ;; (conc *toppath* "/tests/" test-name)) ;; could use tests:get-testconfig here ...
	 (force        (hash-table-ref/default flags "-force" #f))
	 (rerun        (hash-table-ref/default flags "-rerun" #f))
	 (keepgoing    (hash-table-ref/default flags "-keepgoing" #f))
	 (incomplete-timeout (string->number (or (configf:lookup *configdat* "setup" "incomplete-timeout") "x")))
	 (item-path     "")
	 (db           #f)
	 (full-test-name #f))

    ;; setting itemdat to a list if it is #f
    (if (not itemdat)(set! itemdat '()))
    (set! item-path (item-list->path itemdat))
    (set! full-test-name (db:test-make-full-name test-name item-path))
    (debug:print-info 4
    (debug:print-info 4 *default-log-port*
		      "\nTESTNAME: " full-test-name 
		      "\n   test-config: " (hash-table->alist test-conf)
		      "\n   itemdat: " itemdat
		      )
    (debug:print 2 "Attempting to launch test " full-test-name)
    (debug:print 2 *default-log-port* "Attempting to launch test " full-test-name)
    ;; (setenv "MT_TEST_NAME" test-name) ;; 
    ;; (setenv "MT_ITEMPATH"  item-path)
    ;; (setenv "MT_RUNNAME"   runname)
    (runs:set-megatest-env-vars run-id inrunname: runname testname: test-name itempath: item-path) ;; these may be needed by the launching process
    (change-directory *toppath*)

    ;; Here is where the test_meta table is best updated
1345
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355

1356
1357
1358
1359

1360
1361
1362
1363

1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397

1398
1399

1400
1401
1402
1403
1404
1405
1406
1407
1408
1409

1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464

1465
1466
1467
1468

1469
1470
1471
1472

1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485

1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506

1507
1508

1509
1510
1511
1512
1513
1514
1515
1516
1517
1518

1519
1520
1521
1522

1523
1524
1525
1526
1527
1528
1529
1530







-
+


-
+



-
+



-
+




-
+







-
+













-
+






-
+

-
+









-
+



-
+







	    ;; (open-run-close tests:register-test db run-id test-name item-path)
	    ;;
	    ;; NB// for the above line. I want the test to be registered long before this routine gets called!
	    ;;
	    (if (not test-id)(set! test-id (rmt:get-test-id run-id test-name item-path)))
	    (if (not test-id)
		(begin
		  (debug:print 2 "WARN: Test not pre-created? test-name=" test-name ", item-path=" item-path ", run-id=" run-id)
		  (debug:print 2 *default-log-port* "WARN: Test not pre-created? test-name=" test-name ", item-path=" item-path ", run-id=" run-id)
		  (rmt:register-test run-id test-name item-path)
		  (set! test-id (rmt:get-test-id run-id test-name item-path))))
	    (debug:print-info 4 "test-id=" test-id ", run-id=" run-id ", test-name=" test-name ", item-path=\"" item-path "\"")
	    (debug:print-info 4 *default-log-port* "test-id=" test-id ", run-id=" run-id ", test-name=" test-name ", item-path=\"" item-path "\"")
	    (set! testdat (rmt:get-test-info-by-id run-id test-id))
	    (if (not testdat)
		(begin
		  (debug:print-info 0 "WARNING: server is overloaded, trying again in one second")
		  (debug:print-info 0 *default-log-port* "WARNING: server is overloaded, trying again in one second")
		  (thread-sleep! 1)
		  (loop)))))
      (if (not testdat) ;; should NOT happen
	  (debug:print 0 "ERROR: failed to get test record for test-id " test-id))
	  (debug:print-error 0 *default-log-port* "failed to get test record for test-id " test-id))
      (set! test-id (dbr:test-id testdat))
      (if (file-exists? test-path)
	  (change-directory test-path)
	  (begin
	    (debug:print "ERROR: test run path not created before attempting to run the test. Perhaps you are running -remove-runs at the same time?")
	    (debug:print-error 0 *default-log-port* "test run path not created before attempting to run the test. Perhaps you are running -remove-runs at the same time?")
	    (change-directory *toppath*)))
      (case (if force ;; (args:get-arg "-force")
		'NOT_STARTED
		(if testdat
		    (string->symbol (test:get-state testdat))
		    'failed-to-insert))
	((failed-to-insert)
	 (debug:print 0 "ERROR: Failed to insert the record into the db"))
	 (debug:print-error 0 *default-log-port* "Failed to insert the record into the db"))
	((NOT_STARTED COMPLETED DELETED INCOMPLETE)
	 (let ((runflag #f))
	   (cond
	    ;; -force, run no matter what
	    (force (set! runflag #t))
	    ;; NOT_STARTED, run no matter what
	    ((member (test:get-state testdat) '("DELETED" "NOT_STARTED" "INCOMPLETE"))(set! runflag #t))
	    ;; not -rerun and PASS, WARN or CHECK, do no run
	    ((and (or (not rerun)
		      keepgoing)
		  ;; Require to force re-run for COMPLETED or *anything* + PASS,WARN or CHECK
		  (or (member (test:get-status testdat) '("PASS" "WARN" "CHECK" "SKIP" "WAIVED"))
		      (member (test:get-state  testdat) '("COMPLETED")))) 
	     (debug:print-info 2 "running test " test-name "/" item-path " suppressed as it is " (test:get-state testdat) " and " (test:get-status testdat))
	     (debug:print-info 2 *default-log-port* "running test " test-name "/" item-path " suppressed as it is " (test:get-state testdat) " and " (test:get-status testdat))
	     (hash-table-set! test-registry full-test-name 'DONOTRUN) ;; COMPLETED)
	     (set! runflag #f))
	    ;; -rerun and status is one of the specifed, run it
	    ((and rerun
		  (let* ((rerunlst   (string-split rerun ","))
			 (must-rerun (member (test:get-status testdat) rerunlst)))
		    (debug:print-info 3 "-rerun list: " rerun ", test-status: " (test:get-status testdat)", must-rerun: " must-rerun)
		    (debug:print-info 3 *default-log-port* "-rerun list: " rerun ", test-status: " (test:get-status testdat)", must-rerun: " must-rerun)
		    must-rerun))
	     (debug:print-info 2 "Rerun forced for test " test-name "/" item-path)
	     (debug:print-info 2 *default-log-port* "Rerun forced for test " test-name "/" item-path)
	     (set! runflag #t))
	    ;; -keepgoing, do not rerun FAIL
	    ((and keepgoing
		  (member (test:get-status testdat) '("FAIL")))
	     (set! runflag #f))
	    ((and (not rerun)
		  (member (test:get-status testdat) '("FAIL" "n/a")))
	     (set! runflag #t))
	    (else (set! runflag #f)))
	   (debug:print 4 "RUNNING => runflag: " runflag " STATE: " (test:get-state testdat) " STATUS: " (test:get-status testdat))
	   (debug:print 4 *default-log-port* "RUNNING => runflag: " runflag " STATE: " (test:get-state testdat) " STATUS: " (test:get-status testdat))
	   (if (not runflag)
	       (if (not parent-test)
		   (if (runs:lownoise (conc "not starting test" full-test-name) 60)
		       (debug:print 1 "NOTE: Not starting test " full-test-name " as it is state \"" (test:get-state testdat) 
		       (debug:print 1 *default-log-port* "NOTE: Not starting test " full-test-name " as it is state \"" (test:get-state testdat) 
				    "\" and status \"" (test:get-status testdat) "\", use -rerun \"" (test:get-status testdat)
				    "\" or -force to override")))
	       ;; NOTE: No longer be checking prerequisites here! Will never get here unless prereqs are
	       ;;       already met.
	       ;; This would be a great place to do the process-fork
	       ;; 
	       (let ((skip-test   #f)
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458

1459
1460
1461

1462
1463
1464
1465
1466
1467

1468
1469
1470

1471
1472

1473
1474
1475
1476
1477
1478
1479
1554
1555
1556
1557
1558
1559
1560

1561
1562
1563
1564
1565
1566
1567

1568
1569
1570

1571
1572
1573
1574
1575
1576

1577
1578
1579

1580
1581

1582
1583
1584
1585
1586
1587
1588
1589







-
+






-
+


-
+





-
+


-
+

-
+







		     (if (or (not (null? running-tests)) ;; have to skip if test is running
			     (> numseconds time-since-last))
			 (set! skip-test (conc "Skipping due to previous test run less than " (configf:lookup test-conf "skip" "rundelay") " ago"))))))
		 
		 (if skip-test
		     (begin
		       (mt:test-set-state-status-by-id run-id test-id "COMPLETED" "SKIP" skip-test)
		       (debug:print-info 1 "SKIPPING Test " full-test-name " due to " skip-test))
		       (debug:print-info 1 *default-log-port* "SKIPPING Test " full-test-name " due to " skip-test))
		     (if (not (launch-test test-id run-id run-info keyvals runname test-conf test-name test-path itemdat flags))
			 (begin
			   (print "ERROR: Failed to launch the test. Exiting as soon as possible")
			   (set! *globalexitstatus* 1) ;; 
			   (process-signal (current-process-id) signal/kill))))))))
	((KILLED) 
	 (debug:print 1 "NOTE: " full-test-name " is already running or was explictly killed, use -force to launch it.")
	 (debug:print 1 *default-log-port* "NOTE: " full-test-name " is already running or was explictly killed, use -force to launch it.")
	 (hash-table-set! test-registry (db:test-make-full-name test-name test-path) 'DONOTRUN)) ;; KILLED))
	((LAUNCHED REMOTEHOSTSTART RUNNING)  
	 (debug:print 2 "NOTE: " test-name " is already running"))
	 (debug:print 2 *default-log-port* "NOTE: " test-name " is already running"))
	;; (if (> (- (current-seconds)(+ (dbr:test-event_time testdat)
	;; 			       (dbr:test-run_duration testdat)))
	;; 	(or incomplete-timeout
	;; 	    6000)) ;; i.e. no update for more than 6000 seconds
	;;      (begin
	;;        (debug:print 0 "WARNING: Test " test-name " appears to be dead. Forcing it to state INCOMPLETE and status STUCK/DEAD")
	;;        (debug:print 0 *default-log-port* "WARNING: Test " test-name " appears to be dead. Forcing it to state INCOMPLETE and status STUCK/DEAD")
	;;        (tests:test-set-status! run-id test-id "INCOMPLETE" "STUCK/DEAD" "" #f))
	;;        ;; (tests:test-set-status! test-id "INCOMPLETE" "STUCK/DEAD" "" #f))
	;;      (debug:print 2 "NOTE: " test-name " is already running")))
	;;      (debug:print 2 *default-log-port* "NOTE: " test-name " is already running")))
	(else      
	 (debug:print 0 "ERROR: Failed to launch test " full-test-name ". Unrecognised state " (test:get-state testdat))
	 (debug:print-error 0 *default-log-port* "Failed to launch test " full-test-name ". Unrecognised state " (test:get-state testdat))
	 (case (string->symbol (test:get-state testdat)) 
	   ((COMPLETED INCOMPLETE)
	    (hash-table-set! test-registry (db:test-make-full-name test-name test-path) 'DONOTRUN))
	   (else
	    (hash-table-set! test-registry (db:test-make-full-name test-name test-path) 'DONOTRUN))))))))

;;======================================================================
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1599
1600
1601
1602
1603
1604
1605

1606
1607
1608
1609
1610
1611
1612
1613







-
+








(define (runs:recursive-delete-with-error-msg real-dir)
  (if (> (system (conc "rm -rf " real-dir)) 0)
      (begin
	;; FAILED, possibly due to permissions, do chmod a+rwx then try one more time
	(system (conc "chmod -R a+rwx " real-dir))
	(if (> (system (conc "rm -rf " real-dir)) 0)
	    (debug:print 0 "ERROR: There was a problem removing " real-dir " with rm -f")))))
	    (debug:print-error 0 *default-log-port* "There was a problem removing " real-dir " with rm -f")))))

(define (runs:safe-delete-test-dir real-dir)
  ;; first delete all sub-directories
  (directory-fold 
   (lambda (f x)
     (let ((fullname (conc real-dir "/" f)))
       (if (directory? fullname)(runs:recursive-delete-with-error-msg fullname)))
1531
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541

1542
1543
1544
1545
1546
1547
1548
1641
1642
1643
1644
1645
1646
1647

1648
1649
1650

1651
1652
1653
1654
1655
1656
1657
1658







-
+


-
+







	 (header       (vector-ref rundat 0))
	 (runs         (vector-ref rundat 1))
	 (states       (if state  (string-split state  ",") '()))
	 (statuses     (if status (string-split status ",") '()))
	 (state-status (if (string? new-state-status) (string-split new-state-status ",") '(#f #f)))
	 (rp-mutex     (make-mutex))
	 (bup-mutex    (make-mutex)))
    (debug:print-info 4 "runs:operate-on => Header: " header " action: " action " new-state-status: " new-state-status)
    (debug:print-info 4 *default-log-port* "runs:operate-on => Header: " header " action: " action " new-state-status: " new-state-status)
    (if (> 2 (length state-status))
	(begin
	  (debug:print 0 "ERROR: the parameter to -set-state-status is a comma delimited string. E.g. COMPLETED,FAIL")
	  (debug:print-error 0 *default-log-port* "the parameter to -set-state-status is a comma delimited string. E.g. COMPLETED,FAIL")
	  (exit)))
    (for-each
     (lambda (run)
       (let ((runkey (string-intersperse (map (lambda (k)
						(db:get-value-by-header run header k)) keys) "/"))
	     (dirs-to-remove (make-hash-table))
	     (proc-get-tests (lambda (run-id)
1556
1557
1558
1559
1560
1561
1562
1563

1564
1565
1566
1567
1568
1569
1570
1571
1572
1573


1574
1575
1576

1577
1578

1579
1580
1581

1582
1583

1584
1585
1586
1587
1588
1589

1590
1591
1592
1593
1594

1595
1596
1597
1598
1599
1600
1601
1666
1667
1668
1669
1670
1671
1672

1673
1674
1675
1676
1677
1678
1679
1680
1681


1682
1683
1684
1685

1686
1687

1688
1689
1690

1691
1692

1693
1694
1695
1696
1697
1698

1699
1700
1701
1702
1703

1704
1705
1706
1707
1708
1709
1710
1711







-
+








-
-
+
+


-
+

-
+


-
+

-
+





-
+




-
+







		(run-state (db:get-value-by-header run header "state"))
		(run-name  (db:get-value-by-header run header "runname"))
		(tests     (if (not (equal? run-state "locked"))
			       (proc-get-tests run-id)
			       '()))
		(lasttpath "/does/not/exist/I/hope")
		(worker-thread #f))
	   (debug:print-info 4 "runs:operate-on run=" run ", header=" header)
	   (debug:print-info 4 *default-log-port* "runs:operate-on run=" run ", header=" header)
	   (if (not (null? tests))
	       (begin
		 (case action
		   ((remove-runs)
		    (if (tasks:need-server run-id)(tasks:start-and-wait-for-server tdbdat run-id 10))
		    ;; seek and kill in flight -runtests with % as testpatt here
		    ;; (if (equal? testpatt "%")
		    (tasks:kill-runner target run-name testpatt)
		    ;; (debug:print 0 "not attempting to kill any run launcher processes as testpatt is " testpatt))
		    (debug:print 1 "Removing tests for run: " runkey " " (db:get-value-by-header run header "runname")))
		    ;; (debug:print 0 *default-log-port* "not attempting to kill any run launcher processes as testpatt is " testpatt))
		    (debug:print 1 *default-log-port* "Removing tests for run: " runkey " " (db:get-value-by-header run header "runname")))
		   ((set-state-status)
		    (if (tasks:need-server run-id)(tasks:start-and-wait-for-server tdbdat run-id 10))
		    (debug:print 1 "Modifying state and staus for tests for run: " runkey " " (db:get-value-by-header run header "runname")))
		    (debug:print 1 *default-log-port* "Modifying state and staus for tests for run: " runkey " " (db:get-value-by-header run header "runname")))
		   ((print-run)
		    (debug:print 1 "Printing info for run " runkey ", run=" run ", tests=" tests ", header=" header)
		    (debug:print 1 *default-log-port* "Printing info for run " runkey ", run=" run ", tests=" tests ", header=" header)
		    action)
		   ((run-wait)
		    (debug:print 1 "Waiting for run " runkey ", run=" runnamepatt " to complete"))
		    (debug:print 1 *default-log-port* "Waiting for run " runkey ", run=" runnamepatt " to complete"))
		   ((archive)
		    (debug:print 1 "Archiving/restoring (" (args:get-arg "-archive") ") data for run: " runkey " " (db:get-value-by-header run header "runname"))
		    (debug:print 1 *default-log-port* "Archiving/restoring (" (args:get-arg "-archive") ") data for run: " runkey " " (db:get-value-by-header run header "runname"))
		    (set! worker-thread (make-thread (lambda ()
						       (case (string->symbol (args:get-arg "-archive"))
							 ((save save-remove keep-html)(archive:run-bup (args:get-arg "-archive") run-id run-name tests rp-mutex bup-mutex))
							 ((restore)(archive:bup-restore (args:get-arg "-archive") run-id run-name tests rp-mutex bup-mutex))
							 (else 
							  (debug:print 0 "ERROR: unrecognised sub command to -archive. Run \"megatest\" to see help")
							  (debug:print-error 0 *default-log-port* "unrecognised sub command to -archive. Run \"megatest\" to see help")
							  (exit))))
						     "archive-bup-thread"))
		    (thread-start! worker-thread))
		   (else
		    (debug:print-info 0 "action not recognised " action)))
		    (debug:print-info 0 *default-log-port* "action not recognised " action)))
		 
		 ;; actions that operate on one test at a time can be handled below
		 ;;
		 (let ((sorted-tests     (filter 
					  vector?
					  (sort tests (lambda (a b)(let ((dira ;; (rmt:sdb-qry 'getstr 
									  (dbr:test-rundir a)) ;; )  ;; (filedb:get-path *fdb* (dbr:test-rundir a)))
1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667


1668
1669

1670
1671
1672
1673
1674

1675
1676
1677
1678

1679
1680
1681
1682
1683
1684
1685
1686

1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700

1701
1702
1703
1704
1705
1706
1707

1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719


1720
1721
1722
1723
1724
1725

1726
1727
1728
1729
1730

1731
1732
1733

1734
1735
1736


1737
1738
1739

1740
1741
1742

1743
1744
1745
1746

1747
1748
1749

1750
1751
1752
1753
1754


1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773

1774
1775
1776

1777
1778
1779
1780
1781
1782




1783
1784

1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795

1796
1797
1798
1799
1800
1801
1802
1803

1804
1805
1806
1807
1808
1809
1810
1719
1720
1721
1722
1723
1724
1725

1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743

1744
1745
1746
1747
1748
1749
1750
1751

1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763

1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776

1777
1778
1779

1780
1781
1782
1783
1784

1785
1786
1787
1788

1789
1790
1791
1792
1793
1794
1795
1796

1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810

1811
1812
1813
1814
1815
1816
1817

1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829

1830
1831
1832
1833
1834
1835
1836

1837
1838
1839
1840
1841

1842
1843
1844

1845
1846


1847
1848
1849
1850

1851
1852
1853

1854
1855
1856
1857

1858
1859
1860

1861
1862
1863
1864


1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884

1885
1886
1887

1888
1889
1890
1891
1892


1893
1894
1895
1896
1897

1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908

1909
1910
1911
1912
1913
1914
1915
1916

1917
1918
1919
1920
1921
1922
1923
1924







-
+

















-
+







-
+











-
+












-
+
+

-
+




-
+



-
+







-
+













-
+






-
+











-
+
+





-
+




-
+


-
+

-
-
+
+


-
+


-
+



-
+


-
+



-
-
+
+


















-
+


-
+




-
-
+
+
+
+

-
+










-
+







-
+







		       (allow-run-time   10)) ;; seconds to allow for killing tests before just brutally killing 'em
		   (let loop ((test (car sorted-tests))
			      (tal  (cdr sorted-tests)))
		     (let* ((test-id       (dbr:test-id test))
			    (new-test-dat  (rmt:get-test-info-by-id run-id test-id)))
		       (if (not new-test-dat)
			   (begin
			     (debug:print 0 "ERROR: We have a test-id of " test-id " but no record was found. NOTE: No locking of records is done between processes, do not simultaneously remove the same run from two processes!")
			     (debug:print-error 0 *default-log-port* "We have a test-id of " test-id " but no record was found. NOTE: No locking of records is done between processes, do not simultaneously remove the same run from two processes!")
			     (if (not (null? tal))
				 (loop (car tal)(cdr tal))))
			   (let* ((item-path     (dbr:test-item-path new-test-dat))
				  (test-name     (dbr:test-testname new-test-dat))
				  (run-dir       ;;(filedb:get-path *fdb*
				   ;; (rmt:sdb-qry 'getid 
				   (dbr:test-rundir new-test-dat)) ;; )    ;; run dir is from the link tree
				  (test-state    (dbr:test-state new-test-dat))
				  (test-fulln    (dbr:test-fullname new-test-dat))
				  (uname         (dbr:test-uname    new-test-dat))
				  (toplevel-with-children (and (db:test-is-toplevel test)
							       (> (rmt:test-toplevel-num-items run-id test-name) 0))))
			     (case action
			       ((remove-runs)
				;; if the test is a toplevel-with-children issue an error and do not remove
				(if toplevel-with-children
				    (begin
				      (debug:print 0 "WARNING: skipping removal of " test-fulln " with run-id " run-id " as it has sub tests")
				      (debug:print 0 *default-log-port* "WARNING: skipping removal of " test-fulln " with run-id " run-id " as it has sub tests")
				      (hash-table-set! toplevel-retries test-fulln (+ (hash-table-ref/default toplevel-retries test-fulln 0) 1))
				      (if (> (hash-table-ref toplevel-retries test-fulln) 3)
					  (if (not (null? tal))
					      (loop (car tal)(cdr tal))) ;; no else clause - drop it if no more in queue and > 3 tries
					  (let ((newtal (append tal (list test))))
					    (loop (car newtal)(cdr newtal))))) ;; loop with test still in queue
				    (begin
				      (debug:print-info 0 "test: " test-name " itest-state: " test-state)
				      (debug:print-info 0 *default-log-port* "test: " test-name " itest-state: " test-state)
				      (if (member test-state (list "RUNNING" "LAUNCHED" "REMOTEHOSTSTART" "KILLREQ"))
					  (begin
					    (if (not (hash-table-ref/default test-retry-time test-fulln #f))
						(begin
						  ;; want to set to REMOVING BUT CANNOT do it here?
						  (hash-table-set! test-retry-time test-fulln (current-seconds))))
					    (if (> (- (current-seconds)(hash-table-ref test-retry-time test-fulln)) allow-run-time)
						;; This test is not in a correct state for cleaning up. Let's try some graceful shutdown steps first
						;; Set the test to "KILLREQ" and wait five seconds then try again. Repeat up to five times then give
						;; up and blow it away.
						(begin
						  (debug:print 0 "WARNING: could not gracefully remove test " test-fulln ", tried to kill it to no avail. Forcing state to FAILEDKILL and continuing")
						  (debug:print 0 *default-log-port* "WARNING: could not gracefully remove test " test-fulln ", tried to kill it to no avail. Forcing state to FAILEDKILL and continuing")
					    (mt:test-set-state-status-by-id run-id (dbr:test-id test) "FAILEDKILL" "n/a" #f)
						  (thread-sleep! 1))
						(begin
					    (mt:test-set-state-status-by-id run-id (dbr:test-id test) "KILLREQ" "n/a" #f)
						  (thread-sleep! 1)))
					    ;; NOTE: This is suboptimal as the testdata will be used later and the state/status may have changed ...
					    (if (null? tal)
						(loop new-test-dat tal)
						(loop (car tal)(append tal (list new-test-dat)))))
					  (begin
					    (runs:remove-test-directory new-test-dat mode) ;; 'remove-all)
					    (if (not (null? tal))
						(loop (car tal)(cdr tal))))))))
						(loop (car tal)(cdr tal)))))))
				(rmt:update-run-stats run-id (rmt:get-raw-run-stats run-id)))
			       ((set-state-status)
				(debug:print-info 2 "new state " (car state-status) ", new status " (cadr state-status))
				(debug:print-info 2 *default-log-port* "new state " (car state-status) ", new status " (cadr state-status))
				(mt:test-set-state-status-by-id run-id (dbr:test-id test) (car state-status)(cadr state-status) #f)
				(if (not (null? tal))
				    (loop (car tal)(cdr tal))))
			       ((run-wait)
				(debug:print-info 2 "still waiting, " (length tests) " tests still running")
				(debug:print-info 2 *default-log-port* "still waiting, " (length tests) " tests still running")
				(thread-sleep! 10)
				(let ((new-tests (proc-get-tests run-id)))
				  (if (null? new-tests)
				      (debug:print-info 1 "Run completed according to zero tests matching provided criteria.")
				      (debug:print-info 1 *default-log-port* "Run completed according to zero tests matching provided criteria.")
				      (loop (car new-tests)(cdr new-tests)))))
			       ((archive)
				(if (and run-dir (not toplevel-with-children))
				    (let ((ddir (conc run-dir "/")))
				      (case (string->symbol (args:get-arg "-archive"))
					((save save-remove keep-html)
					 (if (file-exists? ddir)
					     (debug:print-info 0 "Estimating disk space usage for " test-fulln ": " (common:get-disk-space-used ddir)))))))
					     (debug:print-info 0 *default-log-port* "Estimating disk space usage for " test-fulln ": " (common:get-disk-space-used ddir)))))))
				(if (not (null? tal))
				    (loop (car tal)(cdr tal))))
			       )))
		       )
		     (if worker-thread (thread-join! worker-thread))))))
	   ;; remove the run if zero tests remain
	   (if (eq? action 'remove-runs)
	       (let ((remtests (mt:get-tests-for-run (db:get-value-by-header run header "id") #f '("DELETED") '("n/a") not-in: #t)))
		 (if (null? remtests) ;; no more tests remaining
		     (let* ((dparts  (string-split lasttpath "/"))
			    (runpath (conc "/" (string-intersperse 
						(take dparts (- (length dparts) 1))
						"/"))))
		       (debug:print 1 "Removing run: " runkey " " (db:get-value-by-header run header "runname") " and related record")
		       (debug:print 1 *default-log-port* "Removing run: " runkey " " (db:get-value-by-header run header "runname") " and related record")
		       (rmt:delete-run run-id)
		       (rmt:delete-old-deleted-test-records)
		       ;; (rmt:set-var "DELETED_TESTS" (current-seconds))
		       ;; need to figure out the path to the run dir and remove it if empty
		       ;;    (if (null? (glob (conc runpath "/*")))
		       ;;        (begin
		       ;; 	 (debug:print 1 "Removing run dir " runpath)
		       ;; 	 (debug:print 1 *default-log-port* "Removing run dir " runpath)
		       ;; 	 (system (conc "rmdir -p " runpath))))
		       )))))
	 ))
     runs)
    ;; (sqlite3:finalize! (db:delay-if-busy tdbdat))
    )
  #t)

(define (runs:remove-test-directory test mode) ;; remove-data-only)
  (let* ((run-dir       (dbr:test-rundir test))    ;; run dir is from the link tree
	 (real-dir      (if (file-exists? run-dir)
			    (resolve-pathname run-dir)
			    ;; (resolve-pathname run-dir)
			    (common:nice-path run-dir)
			    #f)))
    (case mode
      ((remove-data-only)(mt:test-set-state-status-by-id (dbr:test-run_id test)(dbr:test-id test) "CLEANING" "LOCKED" #f))
      ((remove-all)      (mt:test-set-state-status-by-id (dbr:test-run_id test)(dbr:test-id test) "REMOVING" "LOCKED" #f))
      ((archive-remove)  (mt:test-set-state-status-by-id (dbr:test-run_id test)(dbr:test-id test) "ARCHIVE_REMOVING" #f #f)))
    (debug:print-info 1 "Attempting to remove " (if real-dir (conc " dir " real-dir " and ") "") " link " run-dir)
    (debug:print-info 1 *default-log-port* "Attempting to remove " (if real-dir (conc " dir " real-dir " and ") "") " link " run-dir)
    (if (and real-dir 
	     (> (string-length real-dir) 5)
	     (file-exists? real-dir)) ;; bad heuristic but should prevent /tmp /home etc.
	(begin ;; let* ((realpath (resolve-pathname run-dir)))
	  (debug:print-info 1 "Recursively removing " real-dir)
	  (debug:print-info 1 *default-log-port* "Recursively removing " real-dir)
	  (if (file-exists? real-dir)
	      (runs:safe-delete-test-dir real-dir)
	      (debug:print 0 "WARNING: test dir " real-dir " appears to not exist or is not readable")))
	      (debug:print 0 *default-log-port* "WARNING: test dir " real-dir " appears to not exist or is not readable")))
	(if real-dir 
	    (debug:print 0 "WARNING: directory " real-dir " does not exist")
	    (debug:print 0 "WARNING: no real directory corrosponding to link " run-dir ", nothing done")))
	    (debug:print 0 *default-log-port* "WARNING: directory " real-dir " does not exist")
	    (debug:print 0 *default-log-port* "WARNING: no real directory corrosponding to link " run-dir ", nothing done")))
    (if (symbolic-link? run-dir)
	(begin
	  (debug:print-info 1 "Removing symlink " run-dir)
	  (debug:print-info 1 *default-log-port* "Removing symlink " run-dir)
	  (handle-exceptions
	   exn
	   (debug:print 0 "ERROR:  Failed to remove symlink " run-dir ((condition-property-accessor 'exn 'message) exn) ", attempting to continue")
	   (debug:print-error 0 *default-log-port* " Failed to remove symlink " run-dir ((condition-property-accessor 'exn 'message) exn) ", attempting to continue")
	   (delete-file run-dir)))
	(if (directory? run-dir)
	    (if (> (directory-fold (lambda (f x)(+ 1 x)) 0 run-dir) 0)
		(debug:print 0 "WARNING: refusing to remove " run-dir " as it is not empty")
		(debug:print 0 *default-log-port* "WARNING: refusing to remove " run-dir " as it is not empty")
		(handle-exceptions
		 exn
		 (debug:print 0 "ERROR:  Failed to remove directory " run-dir ((condition-property-accessor 'exn 'message) exn) ", attempting to continue")
		 (debug:print-error 0 *default-log-port* " Failed to remove directory " run-dir ((condition-property-accessor 'exn 'message) exn) ", attempting to continue")
		 (delete-directory run-dir)))
	    (if (and run-dir
		     (not (member run-dir (list "n/a" "/tmp/badname"))))
		(debug:print 0 "WARNING: not removing " run-dir " as it either doesn't exist or is not a symlink")
		(debug:print 0 "NOTE: the run dir for this test is undefined. Test may have already been deleted."))
		(debug:print 0 *default-log-port* "WARNING: not removing " run-dir " as it either doesn't exist or is not a symlink")
		(debug:print 0 *default-log-port* "NOTE: the run dir for this test is undefined. Test may have already been deleted."))
	    ))
    ;; Only delete the records *after* removing the directory. If things fail we have a record 
    (case mode
      ((remove-data-only)(mt:test-set-state-status-by-id (dbr:test-run_id test)(dbr:test-id test) "NOT_STARTED" "n/a" #f))
      ((archive-remove)  (mt:test-set-state-status-by-id (dbr:test-run_id test)(dbr:test-id test) "ARCHIVED" #f #f))
      (else (rmt:delete-test-records (dbr:test-run_id test) (dbr:test-id test))))))

;;======================================================================
;; Routines for manipulating runs
;;======================================================================

;; Since many calls to a run require pretty much the same setup 
;; this wrapper is used to reduce the replication of code
(define (general-run-call switchname action-desc proc)
  (let ((runname (or (args:get-arg "-runname")(args:get-arg ":runname")))
	(target  (common:args-get-target)))
    (cond
     ((not target)
      (debug:print 0 "ERROR: Missing required parameter for " switchname ", you must specify the target with -target")
      (debug:print-error 0 *default-log-port* "Missing required parameter for " switchname ", you must specify the target with -target")
      (exit 3))
     ((not runname)
      (debug:print 0 "ERROR: Missing required parameter for " switchname ", you must specify the run name with -runname runname")
      (debug:print-error 0 *default-log-port* "Missing required parameter for " switchname ", you must specify the run name with -runname runname")
      (exit 3))
     (else
      (let (;; (db   #f)
	    (keys #f))
	(if (launch:setup-for-run)
	    (launch:cache-config)
	(if (launch:setup)
	    (begin
	      (full-runconfigs-read) ;; cache the run config
	      (launch:cache-config)) ;; do not cache here - need to be sure runconfigs is processed
	    (begin 
	      (debug:print 0 "Failed to setup, exiting")
	      (debug:print 0 *default-log-port* "Failed to setup, exiting")
	      (exit 1)))
	(set! keys (keys:config-get-fields *configdat*))
	;; have enough to process -target or -reqtarg here
	(if (args:get-arg "-reqtarg")
	    (let* ((runconfigf (conc  *toppath* "/runconfigs.config")) ;; DO NOT EVALUATE ALL 
		   (runconfig  (read-config runconfigf #f #t environ-patt: #f)))
	      (if (hash-table-ref/default runconfig (args:get-arg "-reqtarg") #f)
		  (keys:target-set-args keys (args:get-arg "-reqtarg") args:arg-hash)
		    
		  (begin
		    (debug:print 0 "ERROR: [" (args:get-arg "-reqtarg") "] not found in " runconfigf)
		    (debug:print-error 0 *default-log-port* "[" (args:get-arg "-reqtarg") "] not found in " runconfigf)
		    ;; (if db (sqlite3:finalize! db))
		    (exit 1)
		    )))
	    (if (args:get-arg "-target")
		(keys:target-set-args keys (args:get-arg "-target" args:arg-hash) args:arg-hash)))
	(if (not (car *configinfo*))
	    (begin
	      (debug:print 0 "ERROR: Attempted to " action-desc " but run area config file not found")
	      (debug:print-error 0 *default-log-port* "Attempted to " action-desc " but run area config file not found")
	      (exit 1))
	    ;; Extract out stuff needed in most or many calls
	    ;; here then call proc
	    (let* ((keyvals    (keys:target->keyval keys target)))
	      (proc target runname keys keyvals)))
	;; (if db (sqlite3:finalize! db))
	(set! *didsomething* #t))))))
1822
1823
1824
1825
1826
1827
1828
1829

1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847

1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867

1868
1869
1870
1871
1872
1873
1874
1936
1937
1938
1939
1940
1941
1942

1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960

1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980

1981
1982
1983
1984
1985
1986
1987
1988







-
+

















-
+



















-
+







		(let ((run-id (db:get-value-by-header run header "id")))
		  (if (or lock
			  (and unlock
			       (begin
				 (print "Do you really wish to unlock run " run-id "?\n   y/n: ")
				 (equal? "y" (read-line)))))
		      (rmt:lock/unlock-run run-id lock unlock user)
		      (debug:print-info 0 "Skipping lock/unlock on " run-id))))
		      (debug:print-info 0 *default-log-port* "Skipping lock/unlock on " run-id))))
	      runs)))
;;======================================================================
;; Rollup runs
;;======================================================================

;; Update the test_meta table for this test
(define (runs:update-test_meta test-name test-conf)
  (let ((currrecord (rmt:testmeta-get-record test-name)))
    (if (not currrecord)
	(begin
	  (set! currrecord (make-vector 11 #f))
	  (rmt:testmeta-add-record test-name)))
    (for-each 
     (lambda (key)
       (let* ((idx (cadr key))
	      (fld (car  key))
	      (val (config-lookup test-conf "test_meta" fld)))
	 ;; (debug:print 5 "idx: " idx " fld: " fld " val: " val)
	 ;; (debug:print 5 *default-log-port* "idx: " idx " fld: " fld " val: " val)
	 (if (and val (not (equal? (vector-ref currrecord idx) val)))
	     (begin
	       (print "Updating " test-name " " fld " to " val)
	       (rmt:testmeta-update-field test-name fld val)))))
     '(("author" 2)("owner" 3)("description" 4)("reviewed" 5)("tags" 9)("jobgroup" 10)))))

;; Update test_meta for all tests
(define (runs:update-all-test_meta db)
  (let ((test-names (tests:get-all))) ;; (tests:get-valid-tests)))
    (for-each 
     (lambda (test-name)
       (let* ((test-conf    (mt:lazy-read-test-config test-name)))
	 (if test-conf (runs:update-test_meta test-name test-conf))))
     (hash-table-keys test-names))))

;; This could probably be refactored into one complex query ...
;; NOT PORTED - DO NOT USE YET
;;
(define (runs:rollup-run keys runname user keyvals)
  (debug:print 4 "runs:rollup-run, keys: " keys " -runname " runname " user: " user)
  (debug:print 4 *default-log-port* "runs:rollup-run, keys: " keys " -runname " runname " user: " user)
  (let* ((db              #f)
	 ;; register run operates on the main db
	 (new-run-id      (rmt:register-run keyvals runname "new" "n/a" user))
	 (prev-tests      (rmt:get-matching-previous-test-run-records new-run-id "%" "%"))
	 (curr-tests      (mt:get-tests-for-run new-run-id "%/%" '() '()))
	 (curr-tests-hash (make-hash-table)))
    (rmt:update-run-event_time new-run-id)
1896
1897
1898
1899
1900
1901
1902
1903


1904
1905
1906
1907
1908
1909
1910
1911
1912


1913
1914
1915
1916
1917
1918
1919
1920
1921
2010
2011
2012
2013
2014
2015
2016

2017
2018
2019
2020
2021
2022
2023
2024
2025
2026

2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037







-
+
+








-
+
+









		db 
		(conc "INSERT OR REPLACE INTO tests (run_id,testname,state,status,event_time,host,cpuload,diskfree,uname,rundir,item_path,run_duration,final_logf,comment) "
		      "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);")
		new-run-id (cddr (vector->list testdat)))
	 (set! new-testdat (car (mt:get-tests-for-run new-run-id (conc testname "/" item-path) '() '())))
	 (hash-table-set! curr-tests-hash full-name new-testdat) ;; this could be confusing, which record should go into the lookup table?
	 ;; Now duplicate the test steps
	 (debug:print 4 "Copying records in test_steps from test_id=" (dbr:test-id testdat) " to " (dbr:test-id new-testdat))
	 ;; (debug:print 4 "Copying records in test_steps from test_id=" (dbr:test-id testdat) " to " (dbr:test-id new-testdat))
	 (debug:print 4 *default-log-port* "Copying records in test_steps from test_id=" (dbr:test-id testdat) " to " (dbr:test-id new-testdat))
	 (cdb:remote-run ;; to be replaced, note: this routine is not used currently
	  (lambda ()
	    (sqlite3:execute 
	     db 
	     (conc "INSERT OR REPLACE INTO test_steps (test_id,stepname,state,status,event_time,comment) "
		   "SELECT " (dbr:test-id new-testdat) ",stepname,state,status,event_time,comment FROM test_steps WHERE test_id=?;")
	     (dbr:test-id testdat))
	    ;; Now duplicate the test data
	    (debug:print 4 "Copying records in test_data from test_id=" (dbr:test-id testdat) " to " (dbr:test-id new-testdat))
	    ;; (debug:print 4 "Copying records in test_data from test_id=" (dbr:test-id testdat) " to " (dbr:test-id new-testdat))
	    (debug:print 4 *default-log-port* "Copying records in test_data from test_id=" (dbr:test-id testdat) " to " (dbr:test-id new-testdat))
	    (sqlite3:execute 
	     db 
	     (conc "INSERT OR REPLACE INTO test_data (test_id,category,variable,value,expected,tol,units,comment) "
		   "SELECT " (dbr:test-id new-testdat) ",category,variable,value,expected,tol,units,comment FROM test_data WHERE test_id=?;")
	     (dbr:test-id testdat))))
	 ))
     prev-tests)))
	 
     

Modified server.scm from [7b411d8eb3] to [1952897710].

50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65







-
-
+
+







;; start_server
;;
(define (server:launch run-id)
  (case *transport-type*
    ((http)(http-transport:launch run-id))
    ((nmsg)(nmsg-transport:launch run-id))
    ((rpc)  (rpc-transport:launch run-id))
    (else (debug:print 0 "ERROR: unknown server type " *transport-type*))))
;;       (else   (debug:print 0 "ERROR: No known transport set, transport=" transport ", using rpc")
    (else (debug:print-error 0 *default-log-port* "unknown server type " *transport-type*))))
;;       (else   (debug:print-error 0 *default-log-port* "No known transport set, transport=" transport ", using rpc")
;; 	      (rpc-transport:launch run-id)))))

;;======================================================================
;; S E R V E R   U T I L I T I E S 
;;======================================================================

;; Get the transport
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
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







-
+











-
+

















-
+











-
+

-
+











-
+







			     (write (list (current-directory)
					  (argv)))))))

;; When using zmq this would send the message back (two step process)
;; with spiffy or rpc this simply returns the return data to be returned
;; 
(define (server:reply return-addr query-sig success/fail result)
  (debug:print-info 11 "server:reply return-addr=" return-addr ", result=" result)
  (debug:print-info 11 *default-log-port* "server:reply return-addr=" return-addr ", result=" result)
  ;; (send-message pubsock target send-more: #t)
  ;; (send-message pubsock 
  (case (server:get-transport)
    ((rpc)  (db:obj->string (vector success/fail query-sig result)))
    ((http) (db:obj->string (vector success/fail query-sig result)))
    ((zmq)
     (let ((pub-socket (vector-ref *runremote* 1)))
       (send-message pub-socket return-addr send-more: #t)
       (send-message pub-socket (db:obj->string (vector success/fail query-sig result)))))
    ((fs)   result)
    (else 
     (debug:print 0 "ERROR: unrecognised transport type: " *transport-type*)
     (debug:print-error 0 *default-log-port* "unrecognised transport type: " *transport-type*)
     result)))

;; Given a run id start a server process    ### NOTE ### > file 2>&1 
;; if the run-id is zero and the target-host is set 
;; try running on that host
;;
(define  (server:run run-id)
  (let* ((curr-host   (get-host-name))
	 (curr-ip     (server:get-best-guess-address curr-host))
	 (target-host (configf:lookup *configdat* "server" "homehost" ))
	 (testsuite   (common:get-testsuite-name))
	 (logfile     (conc *toppath* "/logs/" run-id ".log"))
	 (cmdln (conc (common:get-megatest-exe)
		      " -server " (or target-host "-") " -run-id " run-id (if (equal? (configf:lookup *configdat* "server" "daemonize") "yes")
									      (conc " -daemonize -log " logfile)
									      "")
		      " -m testsuite:" testsuite))) ;; (conc " >> " logfile " 2>&1 &")))))
    (debug:print 0 "INFO: Starting server (" cmdln ") as none running ...")
    (debug:print 0 *default-log-port* "INFO: Starting server (" cmdln ") as none running ...")
    (push-directory *toppath*)
    (if (not (directory-exists? "logs"))(create-directory "logs"))
    ;; Rotate logs, logic: 
    ;;                 if > 500k and older than 1 week, remove previous compressed log and compress this log
    (directory-fold 
     (lambda (file rem)
       (if (and (string-match "^.*.log" file)
		(> (file-size (conc "logs/" file)) 200000))
	   (let ((gzfile (conc "logs/" file ".gz")))
	     (if (file-exists? gzfile)
		 (begin
		   (debug:print-info 0 "removing " gzfile)
		   (debug:print-info 0 *default-log-port* "removing " gzfile)
		   (delete-file gzfile)))
	     (debug:print-info 0 "compressing " file)
	     (debug:print-info 0 *default-log-port* "compressing " file)
	     (system (conc "gzip logs/" file)))))
     '()
     "logs")
    
    ;; host.domain.tld match host?
    (if (and target-host 
	     ;; look at target host, is it host.domain.tld or ip address and does it 
	     ;; match current ip or hostname
	     (not (string-match (conc "("curr-host "|" curr-host"\\..*)") target-host))
	     (not (equal? curr-ip target-host)))
	(begin
	  (debug:print-info 0 "Starting server on " target-host ", logfile is " logfile)
	  (debug:print-info 0 *default-log-port* "Starting server on " target-host ", logfile is " logfile)
	  (setenv "TARGETHOST" target-host)))
    (setenv "TARGETHOST_LOGF" logfile)
    (common:wait-for-normalized-load 4 " delaying server start due to load") ;; do not try starting servers on an already overloaded machine, just wait forever
    (system (conc "nbfake " cmdln))
    (unsetenv "TARGETHOST_LOGF")
    (if (get-environment-variable "TARGETHOST")(unsetenv "TARGETHOST"))
    ;; (system cmdln)
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
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







-
+













-
+



-
+







		     ((nmsg)(nmsg-transport:ping (tasks:hostinfo-get-interface server)
						 (tasks:hostinfo-get-port      server)
						 timeout: 2)))))
	  ;; if the server didn't respond we must remove the record
	  (if res
	      #t
	      (begin
		(debug:print-info 0 "server at " server " not responding, removing record")
		(debug:print-info 0 *default-log-port* "server at " server " not responding, removing record")
		(tasks:server-force-clean-running-records-for-run-id (db:delay-if-busy tdbdat) run-id 
				" server:check-if-running")
		res)))
	#f))))

;; called in megatest.scm, host-port is string hostname:port
;;
(define (server:ping run-id host:port)
  (let ((tdbdat (tasks:open-db)))
    (let* ((host-port (let ((slst (string-split   host:port ":")))
			(if (eq? (length slst) 2)
			    (list (car slst)(string->number (cadr slst)))
			    #f)))
	   (toppath       (launch:setup-for-run))
	   (toppath       (launch:setup))
	   (server-db-dat (if (not host-port)(tasks:get-server (db:delay-if-busy tdbdat) run-id) #f)))
      (if (not run-id)
	  (begin
	    (debug:print 0 "ERROR: must specify run-id when doing ping, -run-id n")
	    (debug:print-error 0 *default-log-port* "must specify run-id when doing ping, -run-id n")
	    (print "ERROR: No run-id")
	    (exit 1))
	  (if (and (not host-port)
		   (not server-db-dat))
	      (begin
		(print "ERROR: bad host:port")
		(exit 1))
250
251
252
253
254
255
256
257

258
259
260

261
262
263
264
265
266
267
268
269
270
271
272
250
251
252
253
254
255
256

257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272







-
+


-
+












	   (loop (read-line) inl))))))

(define (server:login toppath)
  (lambda (toppath)
    (set! *last-db-access* (current-seconds))
    (if (equal? *toppath* toppath)
	(begin
	  ;; (debug:print-info 2 "login successful")
	  ;; (debug:print-info 2 *default-log-port* "login successful")
	  #t)
	(begin
	  ;; (debug:print-info 2 "login failed")
	  ;; (debug:print-info 2 *default-log-port* "login failed")
	  #f))))

(define (server:get-timeout)
  (let ((tmo (configf:lookup  *configdat* "server" "timeout")))
    (if (and (string? tmo)
	     (string->number tmo))
	(* 60 60 (string->number tmo))
	;; (* 3 24 60 60) ;; default to three days
	(* 60 1)         ;; default to one minute
	;; (* 60 60 25)      ;; default to 25 hours
	)))

Modified sharedat.scm from [2c59e32b03] to [aee689d39a].

113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127







-
+







	     (file-read-access? path))
	(let* ((dbpath    (conc path "/spublish.db"))
	       (writeable (file-write-access? dbpath))
	       (dbexists  (file-exists? dbpath)))
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 2 "ERROR: problem accessing db " dbpath
	     (debug:print 2 *default-log-port* "ERROR: problem accessing db " dbpath
			  ((condition-property-accessor 'exn 'message) exn))
	     (exit 1))
	   (call-with-database
            dbpath
	    (lambda (db)
	      ;; (print "calling proc " proc " on db " db)
	      (set-busy-handler! db (busy-timeout 10000)) ;; 10 sec timeout

Modified spublish.scm from [18240ec105] to [238d94c641].

18
19
20
21
22
23
24
25
26


27
28
29
30
31
32
33
18
19
20
21
22
23
24


25
26
27
28
29
30
31
32
33







-
-
+
+







;; (use regex-case)
;; (use posix)
;; (use json)
;; (use csv)
(use srfi-18)
(use format)

(require-library ini-file)
(import (prefix ini-file ini:))
;; (require-library ini-file)
;; (import (prefix ini-file ini:))

(use sql-de-lite srfi-1 posix regex regex-case srfi-69)
;; (import (prefix sqlite3 sqlite3:))
;; 
(declare (uses configf))
;; (declare (uses tree))
(declare (uses margs))
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127







-
+







	     (file-read-access? path))
	(let* ((dbpath    (conc path "/spublish.db"))
	       (writeable (file-write-access? dbpath))
	       (dbexists  (file-exists? dbpath)))
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 2 "ERROR: problem accessing db " dbpath
	     (debug:print 2 *default-log-port* "ERROR: problem accessing db " dbpath
			  ((condition-property-accessor 'exn 'message) exn))
	     (exit 1))
	   (call-with-database
            dbpath
	    (lambda (db)
	      ;; (print "calling proc " proc " on db " db)
	      (set-busy-handler! db (busy-timeout 10000)) ;; 10 sec timeout
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150







-
+







        (targ-path (conc target-dir "/" dest-dir "/" targ-file)))
    (if (file-exists? targ-path)
	(begin
	  (print "ERROR: target file already exists, remove it before re-publishing")
	  (exit 1)))
       (if (not(file-exists? dest-dir-path))
	(begin
	  (print "ERROR: target directory "  target-dir " does not exists." )
	  (print "ERROR: target directory " dest-dir-path " does not exists." )
	  (exit 1)))

    (spublish:db-do
     configdat
     (lambda (db)
       (spublish:register-action db "cp" submitter source-path comment)))
    (let* (;; (target-path (configf:lookup "settings" "target-path"))
163
164
165
166
167
168
169





















170
171
172
173
174
175
176
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







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







			     (flush-output)
			     (loop)))
			 "action is happening thread")))
      (thread-start! th1)
      (thread-start! th2)
      (thread-join! th1))
    (cons #t "Successfully saved data")))

;; copy directory to dest, validation is done BEFORE calling this
;;

(define (spublish:tar configdat submitter target-dir dest-dir comment)
  (let ((dest-dir-path (conc target-dir "/" dest-dir)))
       (if (not(file-exists? dest-dir-path))
	(begin
	  (print "ERROR: target directory " dest-dir-path " does not exists." )
	  (exit 1)))
    ;;(print dest-dir-path )
    (spublish:db-do
     configdat
     (lambda (db)
       (spublish:register-action db "tar" submitter dest-dir-path comment)))
       (change-directory dest-dir-path)
       (process-wait (process-run "/bin/tar" (list "xf" "-")))
       (print "Data copied to " dest-dir-path) 

        (cons #t "Successfully saved data")))


(define (spublish:validate target-dir targ-mk)
  (let* ((normal-path (normalize-pathname targ-mk))
        (targ-path (conc target-dir "/" normal-path)))
    (if (string-contains   normal-path "..")
    (begin
      (print "ERROR: Path  " targ-mk " resolved outside target area "  target-dir )
327
328
329
330
331
332
333
334
335


336
337
338
339
340
341
342
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362
363







-
-
+
+








;;======================================================================
;; MAIN
;;======================================================================

(define (spublish:load-config exe-dir exe-name)
  (let* ((fname   (conc exe-dir "/." exe-name ".config")))
    (ini:property-separator-patt " *  *")
    (ini:property-separator #\space)
    ;; (ini:property-separator-patt " *  *")
    ;; (ini:property-separator #\space)
    (if (file-exists? fname)
	;; (ini:read-ini fname)
	(read-config fname #f #t)
	(make-hash-table))))

(define (spublish:process-action configdat action . args)
  (let* ((target-dir    (configf:lookup configdat "settings" "target-dir"))
373
374
375
376
377
378
379
380

381
382
383
384













385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405

406
407
408
409
410






411
412
413
414
415
416
417
394
395
396
397
398
399
400

401
402



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435

436
437
438



439
440
441
442
443
444
445
446
447
448
449
450
451







-
+

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
+


-
-
-
+
+
+
+
+
+







	      (targ-file   (pathname-strip-directory src-path)))
	 (if (not (file-read-access? src-path))
	     (begin
	       (print "ERROR: source file not readable: " src-path)
	       (exit 1)))
	 (if (directory? src-path)
	     (begin
	       (print "ERROR: source file is a directory, this is not supported yet.")
              (print "ERROR: source file is a directory, this is not supported yet.")
	       (exit 1)))
	 (print "publishing " src-path-in " to " target-dir)
         (spublish:validate     target-dir dest-dir)
	 (spublish:cp configdat user src-path target-dir targ-file dest-dir msg)))
	     (print "publishing " src-path-in " to " target-dir)
             (spublish:validate     target-dir dest-dir)
	     (spublish:cp configdat user src-path target-dir targ-file dest-dir msg)))
      ((tar)
        (if (< (length args) 1)
          (begin 
	     (print "ERROR: Missing arguments; " (string-intersperse args ", "))
	     (exit 1)))
        (let* ((dst-dir (car args))
               (msg         (or (args:get-arg "-m") "")))
               (spublish:validate     target-dir  dst-dir)
               (spublish:tar configdat user target-dir dst-dir msg)))
 
      ((mkdir)
        (if (< (length args) 1)
          (begin 
	     (print "ERROR: Missing arguments; " (string-intersperse args ", "))
	     (exit 1)))
        (let* ((targ-mk (car args))
               (msg         (or (args:get-arg "-m") ""))) 
               (print "attempting to create directory " targ-mk " in " target-dir)
               (spublish:validate     target-dir targ-mk)
               (spublish:mkdir configdat user target-dir targ-mk msg)))

      ((ln) 
        (if (< (length args) 2)
          (begin 
	     (print "ERROR: Missing arguments; " (string-intersperse args ", "))
	     (exit 1)))
        (let* ((targ-link (car args))
               (link-name (cadr args))  
               (sub-path (string-reverse (string-join (cdr (string-split (string-reverse link-name) "/")) "/"))) 
               (msg         (or (args:get-arg "-m") "")))
               (if(not (equal? sub-path link-name))
               (if (> (string-length(string-trim sub-path)) 0)
                (begin 
                  (print "attempting to create directory " sub-path " in " target-dir)
                    (spublish:validate     target-dir sub-path)
 
                  (spublish:mkdir configdat user target-dir sub-path msg)))
                  (spublish:validate     target-dir sub-path)
                  (print (conc target-dir "/" sub-path ) )
                  (print (directory-exists?(conc target-dir "/" sub-path )))
                  (if (directory-exists?(conc target-dir "/" sub-path ))
                   (print "Target Directory " (conc target-dir sub-path ) " exist!!")
                  (spublish:mkdir configdat user target-dir sub-path msg))))

               (print "attempting to create link " link-name " in " target-dir)
               (spublish:ln configdat user target-dir targ-link link-name msg)))

      ((rm)
       (if (< (length args) 1)
	   (begin 
499
500
501
502
503
504
505
506

507
508
533
534
535
536
537
538
539

540
541
542







-
+


					    (sql db "SELECT * FROM actions")))))
	(else
	 (print "ERROR: Unrecognised command. Try \"spublish help\""))))
     ;; multi-word commands
     ((null? rema)(print spublish:help))
     ((>= (length rema) 2)
      (apply spublish:process-action configdat (car rema)(cdr rema)))
     (else (print "ERROR: Unrecognised command. Try \"spublish help\"")))))
     (else (print "ERROR: Unrecognised command2. Try \"spublish help\"")))))

(main)

Modified sretrieve.scm from [d298262aee] to [f347600c92].

15
16
17
18
19
20
21
22

23
24
25
26
27


28
29
30
31
32
33
34
15
16
17
18
19
20
21

22
23
24
25


26
27
28
29
30
31
32
33
34







-
+



-
-
+
+







;; (use sxml-modifications)
;; (use regex)
;; (use srfi-69)
;; (use regex-case)
;; (use posix)
;; (use json)
;; (use csv)
(use directory-utils)
;; (use directory-utils)
(use srfi-18)
(use format)

(require-library ini-file)
(import (prefix ini-file ini:))
;; (require-library ini-file)
;; (import (prefix ini-file ini:))

(use sql-de-lite srfi-1 posix regex regex-case srfi-69)
;; (import (prefix sqlite3 sqlite3:))
;; 
(declare (uses configf))
;; (declare (uses tree))
(declare (uses margs))
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
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







+
+
+


-
+


-
+
-

-
+

+














+









-
+







;; (declare (uses tbd))

(include "megatest-fossil-hash.scm")

;;
;; GLOBALS
;;
(define *verbosity* 1)
(define *logging* #f)
(define *exe-name* (pathname-file (car (argv))))
(define *sretrieve:current-tab-number* 0)
(define *args-hash* (make-hash-table))
(define sretrieve:help (conc "Usage: sretrieve [action [params ...]]
(define sretrieve:help (conc "Usage: " *exe-name* " [action [params ...]]

  ls                     : list contents of target area
  get <version>          : retrieve data for <version>
  get <relversion>       : retrieve data for release <version>
    -i iteration_num       get specific iteration
    -m \"message\"       : why retrieved?

  cp <relative path>     : copy file to current directory 
  log                    : get listing of recent downloads
  shell                  : start a shell-like interface

Part of the Megatest tool suite.
Learn more at http://www.kiatoa.com/fossils/megatest

Version: " megatest-fossil-hash)) ;; "

;;======================================================================
;; RECORDS
;;======================================================================

;;======================================================================
;; DB
;;======================================================================

;; replace (strftime('%s','now')), with datetime('now'))
(define (sretrieve:initialize-db db)
  (for-each
   (lambda (qry)
     (exec (sql db qry)))
   (list 
    "CREATE TABLE IF NOT EXISTS actions
         (id           INTEGER PRIMARY KEY,
          action       TEXT NOT NULL,
          retriever    TEXT NOT NULL,
          datetime     TIMESTAMP DEFAULT (strftime('%s','now')),
          datetime     TIMESTAMP DEFAULT (datetime('now','localtime')),
          srcpath      TEXT NOT NULL,
          comment      TEXT DEFAULT '' NOT NULL,
          state        TEXT DEFAULT 'new');"
    "CREATE TABLE IF NOT EXISTS bundles
         (id           INTEGER PRIMARY KEY,
          bundle       TEXT NOT NULL,
          release      TEXT NOT NULL,
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311

312
313
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329







+



-
+




-
+





-
+


+



-
+



-
+

-
+

-
+
-
-
-
-
+
+



-
+

+


-
+






+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

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





-
+




-
+

-
+









-
+








-
+




















-
+



-
+









-
+







;; (call-with-database
;;  (lambda (db)
;;   (set-busy-handler! db (busy-timeout 10000)) ; 10 second timeout
;;   ...))

;; Create the sqlite db
(define (sretrieve:db-do configdat proc) 

  (let ((path (configf:lookup configdat "database" "location")))
    (if (not path)
	(begin
	  (debug:print 0 "[database]\nlocation /some/path\n\n Is missing from the config file!")
	  (debug:print 0 *default-log-port* "[database]\nlocation /some/path\n\n Is missing from the config file!")
	  (exit 1)))
    (if (and path
	     (directory? path)
	     (file-read-access? path))
	(let* ((dbpath    (conc path "/sretrieve.db"))
	(let* ((dbpath    (conc path "/" *exe-name* ".db"))
	       (writeable (file-write-access? dbpath))
	       (dbexists  (file-exists? dbpath)))
	  (handle-exceptions
	   exn
	   (begin
	     (debug:print 2 "ERROR: problem accessing db " dbpath
	     (debug:print 2 *default-log-port* "ERROR: problem accessing db " dbpath
			  ((condition-property-accessor 'exn 'message) exn))
	     (exit 1))
            ;;(debug:print 0 *default-log-port* "calling proc " proc "db path " dbpath )
	   (call-with-database
            dbpath
	    (lambda (db)
	      ;; (debug:print 0 "calling proc " proc " on db " db)
	       ;;(debug:print 0 *default-log-port* "calling proc " proc " on db " db)
	      (set-busy-handler! db (busy-timeout 10000)) ;; 10 sec timeout
	      (if (not dbexists)(sretrieve:initialize-db db))
	      (proc db)))))
	(debug:print 0 "ERROR: invalid path for storing database: " path))))
	(debug:print-error 0 *default-log-port* "invalid path for storing database: " path))))

;; copy in file to dest, validation is done BEFORE calling this
;; copy in directory to dest, validation is done BEFORE calling this
;;
(define (sretrieve:get configdat reldat retriever area version iter comment)
(define (sretrieve:get configdat retriever version comment)
  (let* ((iteration (or iter
			(configf:lookup reldat version "iteration")))
	 (base-dir  (configf:lookup configdat "settings" "base-dir"))
	 (datadir   (conc base-dir "/" area "/" version "/" iteration)))
  (let* ((base-dir  (configf:lookup configdat "settings" "base-dir"))
	 (datadir   (conc base-dir "/" version)))
    (if (or (not base-dir)
	    (not (file-exists? base-dir)))
	(begin
	  (debug:print 0 "ERROR: Bad configuration! base-dir " base-dir " not found")
	  (debug:print-error 0 *default-log-port* "Bad configuration! base-dir " base-dir " not found")
	  (exit 1)))
    (print datadir)
    (if (not (file-exists? datadir))
	(begin
	  (debug:print 0 "ERROR: Bad version (" version ") or iteration (" iteration "), no data found at " datadir "." )
	  (debug:print-error 0 *default-log-port* "Bad version (" version "), no data found at " datadir "." )
	  (exit 1)))
    
    (sretrieve:db-do
     configdat
     (lambda (db)
       (sretrieve:register-action db "get" retriever datadir comment)))
      (sretrieve:do-as-calling-user
       (lambda ()
         (if (directory? datadir)
	   (begin
    (change-directory datadir)
    (process-execute "tar" (append (list "chfv" "-")(filter (lambda (x)
							     (not (member x '("." ".."))))
							   (glob "*" ".*"))))))
  	    (change-directory datadir)
	    (let ((files (filter (lambda (x)
				(not (member x '("." ".."))))
			      (glob "*" ".*"))))
	     (print "files: " files)
	     (process-execute "/bin/tar" (append (append (list  "chfv" "-") files) (list "--ignore-failed-read")))))
             (begin
               (let* ((parent-dir (pathname-directory datadir) )
                      (filename  (conc(pathname-file datadir) "." (pathname-extension datadir))))
                  (change-directory parent-dir)  
                  (process-execute "/bin/tar" (list "chfv" "-" filename))
             )))
))
))


;; copy in file to dest, validation is done BEFORE calling this
;;
(define (sretrieve:cp configdat retriever file comment)
  (let* ((base-dir  (configf:lookup configdat "settings" "base-dir"))
         (allowed-sub-paths (configf:lookup configdat "settings" "allowed-sub-paths"))    
	 (datadir   (conc base-dir "/" file))
         (filename  (conc(pathname-file datadir) "." (pathname-extension datadir))))
    (if (or (not base-dir)
	    (not (file-exists? base-dir)))
	(begin
	  (debug:print-error 0 *default-log-port* "Bad configuration! base-dir " base-dir " not found")
	  (exit 1)))
    (print datadir)
    (if (not (file-exists? datadir))
	(begin
	  (debug:print-error 0 *default-log-port* "File  (" file "), not found at " base-dir "." )
	  (exit 1)))
    (if (directory? datadir)
	(begin
	  (debug:print-error 0 *default-log-port* "(" file ") is a dirctory!! cp cmd works only on files ." )
	  (exit 1)))
    (if(not (string-match (regexp  allowed-sub-paths) file))
        (begin
	  (debug:print-error 0 *default-log-port* "Access denied to file (" file ")!! " )
	  (exit 1)))
     
     (sretrieve:db-do
     configdat
     (lambda (db)
       (sretrieve:register-action db "cp" retriever datadir comment)))
      (sretrieve:do-as-calling-user
      ;;  (debug:print 0 *default-log-port* "ph:  "(pathname-directory datadir)  "!! " )
       (change-directory (pathname-directory datadir))  
       ;;(debug:print 0 *default-log-port* "ph: /bin/tar" (list "chfv" "-" filename) )
      (process-execute "/bin/tar" (list "chfv" "-" filename)))
      ))

;; ls in file to dest, validation is done BEFORE calling this
;;
(define (sretrieve:ls configdat retriever file comment)
  (let* ((base-dir  (configf:lookup configdat "settings" "base-dir"))
         (allowed-sub-paths (configf:lookup configdat "settings" "allowed-sub-paths"))    
	 (datadir   (conc base-dir "/" file))
         (filename  (conc(pathname-file datadir) "." (pathname-extension datadir))))
    (if (or (not base-dir)
	    (not (file-exists? base-dir)))
	(begin
	  (debug:print-error 0 *default-log-port* "Bad configuration! base-dir " base-dir " not found")
	  (exit 1)))
    (print datadir)
    (if (not (file-exists? datadir))
	(begin
	  (debug:print-error 0 *default-log-port* "File  (" file "), not found at " base-dir "." )
	  (exit 1)))
      (if(not (string-match (regexp  allowed-sub-paths) file))
        (begin
	  (debug:print-error 0 *default-log-port* "Access denied to file (" file ")!! " )
	  (exit 1)))
   
        (sretrieve:do-as-calling-user
        (lambda ()
	 ;;(change-directory datadir)
         ;; (debug:print 0 *default-log-port*  "/usr/bin/find" (list datadir "-ls" "|" "grep" "-E" "'"allowed-file-patt"'"))
         ;; (status (with-input-from-pipe "find " datadir " -ls | grep -E '" allowed-file-patt "'" (lambda () (read-line))))
         ;; (debug:print 0 *default-log-port* status) 
	  (process-execute "/bin/ls" (list "-ls"  "-lrt" datadir ))
 ))))



;;(filter (lambda (x)
;;							     (not (member x '("." ".."))))
;;							   (glob "*" ".*"))))))))

(define (sretrieve:validate target-dir targ-mk)
  (let* ((normal-path (normalize-pathname targ-mk))
        (targ-path (conc target-dir "/" normal-path)))
    (if (string-contains   normal-path "..")
    (begin
      (debug:print 0 "ERROR: Path  " targ-mk " resolved outside target area "  target-dir )
      (debug:print-error 0 *default-log-port* "Path  " targ-mk " resolved outside target area "  target-dir )
      (exit 1)))

    (if (not (string-contains targ-path target-dir))
    (begin
      (debug:print 0 "ERROR: You cannot update data outside " target-dir ".")
      (debug:print-error 0 *default-log-port* "You cannot update data outside " target-dir ".")
      (exit 1)))
    (debug:print 0 "Path " targ-mk " is valid.")   
    (debug:print 0 *default-log-port* "Path " targ-mk " is valid.")   
 ))
;; make directory in dest
;;

(define (sretrieve:mkdir configdat submitter target-dir targ-mk comment)
  (let ((targ-path (conc target-dir "/" targ-mk)))
    
    (if (file-exists? targ-path)
	(begin
	  (debug:print 0 "ERROR: target Directory " targ-path " already exist!!")
	  (debug:print-error 0 *default-log-port* "target Directory " targ-path " already exist!!")
	  (exit 1)))
    (sretrieve:db-do
     configdat
     (lambda (db)
       (sretrieve:register-action db "mkdir" submitter targ-mk comment)))
    (let* ((th1         (make-thread
			 (lambda ()
			   (create-directory targ-path #t)
			   (debug:print 0 " ... dir " targ-path " created"))
			   (debug:print 0 *default-log-port* " ... dir " targ-path " created"))
			 "mkdir thread"))
	   (th2         (make-thread
			 (lambda ()
			   (let loop ()
			     (thread-sleep! 15)
			     (display ".")
			     (flush-output)
			     (loop)))
			 "action is happening thread")))
      (thread-start! th1)
      (thread-start! th2)
      (thread-join! th1))
    (cons #t "Successfully saved data")))

;; create a symlink in dest
;;
(define (sretrieve:ln configdat submitter target-dir targ-link link-name comment)
  (let ((targ-path (conc target-dir "/" link-name)))
    (if (file-exists? targ-path)
	(begin
	  (debug:print 0 "ERROR: target file " targ-path " already exist!!")
	  (debug:print-error 0 *default-log-port* "target file " targ-path " already exist!!")
	  (exit 1)))
     (if (not (file-exists? targ-link ))
	(begin
	  (debug:print 0 "ERROR: target file " targ-link " does not exist!!")
	  (debug:print-error 0 *default-log-port* "target file " targ-link " does not exist!!")
	  (exit 1)))
 
    (sretrieve:db-do
     configdat
     (lambda (db)
       (sretrieve:register-action db "ln" submitter link-name comment)))
    (let* ((th1         (make-thread
			 (lambda ()
			   (create-symbolic-link targ-link targ-path  )
			   (debug:print 0 " ... link " targ-path " created"))
			   (debug:print 0 *default-log-port* " ... link " targ-path " created"))
			 "symlink thread"))
	   (th2         (make-thread
			 (lambda ()
			   (let loop ()
			     (thread-sleep! 15)
			     (display ".")
			     (flush-output)
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360







-
+








-
+








;; remove copy of file in dest
;;
(define (sretrieve:rm configdat submitter target-dir targ-file comment)
  (let ((targ-path (conc target-dir "/" targ-file)))
    (if (not (file-exists? targ-path))
	(begin
	  (debug:print 0 "ERROR: target file " targ-path " not found, nothing to remove.")
	  (debug:print-error 0 *default-log-port* "target file " targ-path " not found, nothing to remove.")
	  (exit 1)))
    (sretrieve:db-do
     configdat
     (lambda (db)
       (sretrieve:register-action db "rm" submitter targ-file comment)))
    (let* ((th1         (make-thread
			 (lambda ()
			   (delete-file targ-path)
			   (debug:print 0 " ... file " targ-path " removed"))
			   (debug:print 0 *default-log-port* " ... file " targ-path " removed"))
			 "rm thread"))
	   (th2         (make-thread
			 (lambda ()
			   (let loop ()
			     (thread-sleep! 15)
			     (display ".")
			     (flush-output)
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322













































323
324
325
326
327
328
329
330
331


332
333
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382

383
384
385
386

387
388
389
390
391
392

393
394
395
396
397
398
399
400
401


402
403
404
405


























406
407
408
409
410
411
412
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
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
459
460
461
462
463
464
465
466
467
468


469
470
471
472
473
474
475
476
477
478
479

480

481
482
483
484
485
486
487
488
489
490
491

492
493
494




495
496
497
498
499
500

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

518
519
520
521

522
523
524
525

526
527
528
529
530
531

532
533
534
535
536

537
538


539
540
541



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574







-
+



















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







-
-
+
+









-
+
-











-
+


-
-
-
-
+
+
+
+


-
+








+




+


-
+



-
+



-
+





-
+




-


-
-
+
+

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







;;======================================================================

(define (sretrieve:do-as-calling-user proc)
  (let ((eid (current-effective-user-id))
        (cid (current-user-id)))
    (if (not (eq? eid cid)) ;; running suid
            (set! (current-effective-user-id) cid))
    ;; (debug:print 0 "running as " (current-effective-user-id))
    ;; (debug:print 0 *default-log-port* "running as " (current-effective-user-id))
    (proc)
    (if (not (eq? eid cid))
        (set! (current-effective-user-id) eid))))

(define (sretrieve:find name paths)
  (if (null? paths)
      #f
      (let loop ((hed (car paths))
		 (tal (cdr paths)))
	(if (file-exists? (conc hed "/" name))
	    hed
	    (if (null? tal)
		#f
		(loop (car tal)(cdr tal)))))))

(define (sretrieve:stderr-print . args)
  (with-output-to-port (current-error-port)
    (lambda ()
      (apply print args))))

;;======================================================================
;; SHELL
;;======================================================================

(define (toplevel-command . args) #f)
(define (sretrieve:shell)
  (use readline)
  (let* ((path      '())
	 (prompt    "> ")
	 (top-areas '("mrwellan" "pjhatwal" "bjbarcla" "ritikaag" "jmoon18"))
	 (iport     (make-readline-port prompt)))
    (install-history-file) ;;  [homedir] [filename] [nlines])
    (with-input-from-port iport
      (lambda ()
	(let loop ((inl (read-line)))
	  (if (not (or (eof-object? inl)
		       (equal? inl "exit")))
	      (let* ((parts (string-split inl))
		     (cmd   (if (null? parts) #f (car parts))))
		(if (not cmd)
		    (loop (read-line))
		    (case (string->symbol cmd)
		      ((cd)
		       (if (> (length parts) 1) ;; have a parameter
			   (set! path (append path (string-split (cadr parts)))) ;; not correct for relative paths
			   (set! path '())))
		      ((ls)
		       (let* ((thepath (if (> (length parts) 1) ;; have a parameter
					   (cdr parts)
					   path))
			      (plen    (length thepath)))
			 (cond
			  ((null? thepath)
			   (print (string-intersperse top-areas " ")))
			  ((and (< plen 2)
				(member (car thepath) top-areas))
			   (system (conc "ls /p/fdk/gwa/" (car thepath))))
			  (else ;; have a long path
			   ;; check for access rights here
			   (system (conc "ls /p/fdk/gwa/" (string-intersperse thepath "/")))))))
		      (else 
		       (print "Got command: " inl))))
		(loop (read-line)))))))))
    

;;======================================================================
;; MAIN
;;======================================================================

(define (sretrieve:load-config exe-dir exe-name)
  (let* ((fname   (conc exe-dir "/." exe-name ".config")))
    (ini:property-separator-patt " *  *")
    (ini:property-separator #\space)
    ;; (ini:property-separator-patt " *  *")
    ;; (ini:property-separator #\space)
    (if (file-exists? fname)
	;; (ini:read-ini fname)
	(read-config fname #f #t)
	(make-hash-table))))

;; package-type is "megatest", "builds", "kits" etc.
;;
(define (sretrieve:load-packages configdat exe-dir package-type)
  (push-directory exe-dir)
  (let* ((packages-metadir  (or (configf:lookup configdat "settings" "packages-metadir")
  (let* ((packages-metadir  (configf:lookup configdat "settings" "packages-metadir"))
				".")) ;; exe-dir))
	 (conversion-script (configf:lookup configdat "settings" "conversion-script"))
	 (upstream-file     (configf:lookup configdat "settings" "upstream-file"))
	 (package-config    (conc packages-metadir "/" package-type ".config")))
    ;; this section here does a timestamp based rebuild of the
    ;;   <packages-metadir>/<package-type>.config file using
    ;;   <upstream-file> as an input
    (if (file-exists? upstream-file)
	(if (or (not (file-exists? package-config)) ;; if not created call the updater, otherwise call only if upstream newer
		(> (file-modification-time upstream-file)(file-modification-time package-config)))
	    (handle-exceptions
	     exn
	     (debug:print 0 "ERROR: failed to run script " conversion-script " with params " upstream-file " " package-config)
	     (debug:print-error 0 *default-log-port* "failed to run script " conversion-script " with params " upstream-file " " package-config)
	     (let ((pid (process-run conversion-script (list upstream-file package-config))))
	       (process-wait pid)))
	    (debug:print 0 "Skipping update of " package-config " from " upstream-file))
	(debug:print 0 "Skipping update of " package-config " as " upstream-file " not found"))
    (ini:property-separator-patt " *  *")
    (ini:property-separator #\space)
	    (debug:print 0 *default-log-port* "Skipping update of " package-config " from " upstream-file))
	(debug:print 0 *default-log-port* "Skipping update of " package-config " as " upstream-file " not found"))
    ;; (ini:property-separator-patt " *  *")
    ;; (ini:property-separator #\space)
    (let ((res (if (file-exists? package-config)
		   (begin
		     (debug:print 0 "Reading package config " package-config)
		     (debug:print 0 *default-log-port* "Reading package config " package-config)
		     (read-config package-config #f #t))
		   (make-hash-table))))
      (pop-directory)
      res)))

(define (sretrieve:process-action configdat action . args)
  (let* ((base-dir      (configf:lookup configdat "settings" "base-dir"))
	 (user          (current-user-name))
         (allowed-sub-paths (configf:lookup configdat "settings" "allowed-sub-paths")) 
	 (allowed-users (string-split
			 (or (configf:lookup configdat "settings" "allowed-users")
			     "")))
	 (default-area  (configf:lookup configdat "settings" "default-area"))) ;; otherwise known as the package
    
    (if (not base-dir)
	(begin
	  (debug:print 0 "[settings]\nbase-dir /some/path\n\n Is MISSING from the config file!")
	  (debug:print 0 *default-log-port* "[settings]\nbase-dir /some/path\n\n Is MISSING from the config file!")
	  (exit)))
    (if (null? allowed-users)
	(begin
	  (debug:print 0 "[setings]\nallowed-users user1 user2 ...\n\n Is MISSING from the config file!")
	  (debug:print 0 *default-log-port* "[setings]\nallowed-users user1 user2 ...\n\n Is MISSING from the config file!")
	  (exit)))
    (if (not (member user allowed-users))
	(begin
	  (debug:print 0 "User \"" (current-user-name) "\" does not have access. Exiting")
	  (debug:print 0 *default-log-port* "User \"" (current-user-name) "\" does not have access. Exiting")
	  (exit 1)))
    (case (string->symbol action)
      ((get)
       (if (< (length args) 1)
	   (begin 
	     (debug:print 0 "ERROR: Missing arguments; " (string-intersperse args ", "))
	     (debug:print-error 0 *default-log-port* "Missing arguments; " (string-intersperse args ", "))
	     (exit 1)))
       (let* ((remargs     (args:get-args args '("-m" "-i" "-package") '() args:arg-hash 0))
              (version     (car args))
	      (msg         (or (args:get-arg "-m") ""))
	      (iteration   (args:get-arg "-i"))
	      (package-type (or (args:get-arg "-package")
				default-area))
	      (exe-dir     (configf:lookup configdat "exe-info" "exe-dir"))
	      (relconfig   (sretrieve:load-packages configdat exe-dir package-type)))
	      (exe-dir     (configf:lookup configdat "exe-info" "exe-dir")))
;;	      (relconfig   (sretrieve:load-packages configdat exe-dir package-type)))

	 (debug:print 0 "retrieving " version " of " package-type " as tar data on stdout")
	 (sretrieve:get configdat relconfig user package-type version iteration msg)))
      (else (debug:print 0 "Unrecognised command " action)))))
	 (debug:print 0 *default-log-port* "retrieving " version " of " package-type " as tar data on stdout")
	 (sretrieve:get configdat user version msg)))
         ((cp)
            (if (< (length args) 1)
             (begin 
	     (debug:print-error 0 *default-log-port* "Missing arguments; " (string-intersperse args ", "))
	     (exit 1)))
          (let* ((remargs     (args:get-args args '("-m" "-i" "-package") '() args:arg-hash 0))
              (file     (car args))
	      (msg         (or (args:get-arg "-m") "")) )

	 (debug:print 0 *default-log-port* "copinging " file " to current directory " )
	 (sretrieve:cp configdat user file msg)))
      ((ls)
            (if (< (length args) 1)
             (begin 
	     (debug:print-error 0 *default-log-port* "Missing arguments; " (string-intersperse args ", "))
	     (exit 1)))
          (let* ((remargs     (args:get-args args '("-m" "-i" "-package") '() args:arg-hash 0))
              (dir     (car args))
	      (msg         (or (args:get-arg "-m") "")) )

	 (debug:print 0 *default-log-port* "Listing files in " )
	 (sretrieve:ls configdat user dir msg)))
 
      (else (debug:print 0 *default-log-port* "Unrecognised command " action)))))
  
;; ease debugging by loading ~/.dashboardrc - REMOVE FROM PRODUCTION!
;; (let ((debugcontrolf (conc (get-environment-variable "HOME") "/.sretrieverc")))
;;   (if (file-exists? debugcontrolf)
;;       (load debugcontrolf)))

(define (main)
425
426
427
428
429
430
431
432
433
434








435
436
437

438
439
440
441


442
443
444
445
446
447
448

449
450
587
588
589
590
591
592
593



594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619







-
-
-
+
+
+
+
+
+
+
+


-
+




+
+






-
+


     ((eq? (length rema) 1)
      (case (string->symbol (car rema))
	((help -h -help --h --help)
	 (print sretrieve:help))
	((list-vars) ;; print out the ini file
	 (map print (sretrieve:get-areas configdat)))
	((ls)
	 (let ((target-dir (configf:lookup configdat "settings" "target-dir")))
	   (print "Files in " target-dir)
	   (system (conc "ls " target-dir))))
	 (let* ((base-dir (configf:lookup configdat "settings" "base-dir")))
	   (if base-dir
	       (begin
		 (print "Files in " base-dir)
                 (sretrieve:do-as-calling-user
                    (lambda ()
		 (process-execute "/bin/ls" (list "-lrt" base-dir)))))
	       (print "ERROR: No base dir specified!"))))
	((log)
	 (sretrieve:db-do configdat (lambda (db)
				     (print "Listing actions")
				     (print "Logs : ")
				     (query (for-each-row
					     (lambda (row)
					       (apply print (intersperse row " | "))))
					    (sql db "SELECT * FROM actions")))))
	((shell)
	 (sretrieve:shell))
	(else
	 (print "ERROR: Unrecognised command. Try \"sretrieve help\""))))
     ;; multi-word commands
     ((null? rema)(print sretrieve:help))
     ((>= (length rema) 2)
      (apply sretrieve:process-action configdat (car rema)(cdr rema)))
     (else (debug:print 0 "ERROR: Unrecognised command. Try \"sretrieve help\"")))))
     (else (debug:print-error 0 *default-log-port* "Unrecognised command. Try \"sretrieve help\"")))))

(main)

Modified synchash.scm from [1596fbcb93] to [748a7632da].

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
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







-
+













-
+

















-
+


-
+



-
+

-
+







	(begin
	  (set! myhash (make-hash-table))
	  (hash-table-set! synchash synckey myhash)))
    (for-each 
     (lambda (item)
       (let ((id  (car item))
	     (dat (cadr item)))
	 ;; (debug:print-info 2 "Processing item: " item)
	 ;; (debug:print-info 2 *default-log-port* "Processing item: " item)
	 (hash-table-set! myhash id dat)))
     newdat)
    (for-each
     (lambda (id)
       (hash-table-delete! myhash id))
     removs)
    ;; WHICH ONE!?
    ;; data)) ;; return the changed and deleted list
    (list newdat removs))) ;; synchash))

(define *synchashes* (make-hash-table))

(define (synchash:server-get dbstruct run-id proc synckey keynum params)
  ;; (debug:print-info 2 "synckey: " synckey ", keynum: " keynum ", params: " params)
  ;; (debug:print-info 2 *default-log-port* "synckey: " synckey ", keynum: " keynum ", params: " params)
  (let* ((dbdat     (db:get-db dbstruct run-id))
	 (db        (db:dbdat-get-db dbdat))
	 (synchash  (hash-table-ref/default *synchashes* synckey #f))
	 (newdat    (apply (case proc
			     ((db:get-runs)                   db:get-runs)
			     ((db:get-tests-for-run-mindata)  db:get-tests-for-run-mindata)
			     ((db:get-test-info-by-ids)       db:get-test-info-by-ids)
			     (else
			      (print "ERROR: sync for hash " proc " not setup! Edits needed in synchash.scm")
			      print))
			   db params))
	 (postdat  #f)
	 (make-indexed (lambda (x)
			 (list (vector-ref x keynum) x))))
    ;; Now process newdat based on the query type
    (set! postdat (case proc
		    ((db:get-runs)
		     ;; (debug:print-info 2 "Get runs call")
		     ;; (debug:print-info 2 *default-log-port* "Get runs call")
		     (let ((header (vector-ref newdat 0))
			   (data   (vector-ref newdat 1)))
		       ;; (debug:print-info 2 "header: " header ", data: " data)
		       ;; (debug:print-info 2 *default-log-port* "header: " header ", data: " data)
		       (cons (list "header" header)         ;; add the header keyed by the word "header"
			     (map make-indexed data))))        ;; add each element keyed by the keynum'th val
		    (else 
		     ;; (debug:print-info 2 "Non-get runs call")
		     ;; (debug:print-info 2 *default-log-port* "Non-get runs call")
		     (map make-indexed newdat))))
    ;; (debug:print-info 2 "postdat: " postdat)
    ;; (debug:print-info 2 *default-log-port* "postdat: " postdat)
    ;; (if (not indb)(sqlite3:finalize! db))
    (if (not synchash)
	(begin
	  (set! synchash (make-hash-table))
	  (hash-table-set! *synchashes* synckey synchash)))
    (synchash:get-delta postdat synchash)))

Modified task_records.scm from [8f450896f9] to [9c8b281be4].

13
14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28







-
-
+
+







(define (make-tasks:task)(make-vector 11))
(define-inline (tasks:task-get-id               vec)    (vector-ref  vec 0))
(define-inline (tasks:task-get-action           vec)    (vector-ref  vec 1))
(define-inline (tasks:task-get-owner            vec)    (vector-ref  vec 2))
(define-inline (tasks:task-get-state            vec)    (vector-ref  vec 3))
(define-inline (tasks:task-get-target           vec)    (vector-ref  vec 4))
(define-inline (tasks:task-get-name             vec)    (vector-ref  vec 5))
(define-inline (tasks:task-get-test             vec)    (vector-ref  vec 6))
(define-inline (tasks:task-get-item             vec)    (vector-ref  vec 7))
(define-inline (tasks:task-get-testpatt         vec)    (vector-ref  vec 6))
(define-inline (tasks:task-get-keylock          vec)    (vector-ref  vec 7))
(define-inline (tasks:task-get-params           vec)    (vector-ref  vec 8))
(define-inline (tasks:task-get-creation_time    vec)    (vector-ref  vec 9))
(define-inline (tasks:task-get-execution_time   vec)    (vector-ref  vec 10))

(define-inline (tasks:task-set-state!  vec val)(vector-set! vec 3 val))


Modified tasks.scm from [2559bee69c] to [7aab5e9e48].

23
24
25
26
27
28
29
30

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
23
24
25
26
27
28
29

30
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







-
+





-
-
-
+
+
+







-
+

















-
+







;; Tasks db
;;======================================================================

;; wait up to aprox n seconds for a journal to go away
;;
(define (tasks:wait-on-journal path n #!key (remove #f)(waiting-msg #f))
  (if (not (string? path))
      (debug:print 0 "ERROR: Called tasks:wait-on-journal with path=" path " (not a string)")
      (debug:print-error 0 *default-log-port* "Called tasks:wait-on-journal with path=" path " (not a string)")
      (let ((fullpath (conc path "-journal")))
	(handle-exceptions
	 exn
	 (begin
	   (print-call-chain (current-error-port))
	   (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	   (debug:print 0 " exn=" (condition->list exn))
	   (debug:print 0 "tasks:wait-on-journal failed. Continuing on, you can ignore this call-chain")
	   (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	   (debug:print 0 *default-log-port* " exn=" (condition->list exn))
	   (debug:print 0 *default-log-port* "tasks:wait-on-journal failed. Continuing on, you can ignore this call-chain")
	   #t) ;; if stuff goes wrong just allow it to move on
	 (let loop ((journal-exists (file-exists? fullpath))
		    (count          n)) ;; wait ten times ...
	   (if journal-exists
	       (begin
		 (if (and waiting-msg
			  (eq? (modulo n 30) 0))
		     (debug:print 0 waiting-msg))
		     (debug:print 0 *default-log-port* waiting-msg))
		 (if (> count 0)
		     (begin
		       (thread-sleep! 1)
		       (loop (file-exists? fullpath)
			     (- count 1)))
		     (begin
		       (if remove (system (conc "rm -rf " fullpath)))
		       #f)))
	       #t))))))

(define (tasks:get-task-db-path)
  (let ((dbdir  (or (configf:lookup *configdat* "setup" "monitordir")
		    (configf:lookup *configdat* "setup" "dbdir")
		    (conc (configf:lookup *configdat* "setup" "linktree") "/.db"))))
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "ERROR: Couldn't create path to " dbdir)
       (debug:print-error 0 *default-log-port* "Couldn't create path to " dbdir)
       (exit 1))
     (if (not (directory? dbdir))(create-directory dbdir #t)))
    dbdir))

;; If file exists AND
;;    file readable
;;         ==> open it
79
80
81
82
83
84
85
86
87


88
89
90
91
92
93


94
95
96
97
98
99
100
79
80
81
82
83
84
85


86
87
88
89
90
91


92
93
94
95
96
97
98
99
100







-
-
+
+




-
-
+
+







  (if *task-db*
      *task-db*
      (handle-exceptions
       exn
       (if (> numretries 0)
	   (begin
	     (print-call-chain (current-error-port))
	     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 " exn=" (condition->list exn))
	     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 *default-log-port* " exn=" (condition->list exn))
	     (thread-sleep! 1)
	     (tasks:open-db numretries (- numretries 1)))
	   (begin
	     (print-call-chain (current-error-port))
	     (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 " exn=" (condition->list exn))))
	     (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	     (debug:print 0 *default-log-port* " exn=" (condition->list exn))))
       (let* ((dbpath       (tasks:get-task-db-path))
	      (dbfile       (conc dbpath "/monitor.db"))
	      (avail        (tasks:wait-on-journal dbpath 10)) ;; wait up to about 10 seconds for the journal to go away
	      (exists       (file-exists? dbpath))
	      (write-access (file-write-access? dbpath))
	      (mdb          (cond ;; what the hek is *toppath* doing here?
			     ((and (string? *toppath*)(file-write-access? *toppath*))
284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308







-
+









-
+







		(loop (get-rand-port)(- remtries 1))
		(get-rand-port))
	    port))))))

(define (tasks:server-am-i-the-server? mdb run-id)
  (let* ((all    (tasks:server-get-servers-vying-for-run-id mdb run-id))
	 (first  (if (null? all)
		     #f;; (begin (debug:print 0 "ERROR: no servers listed, should be at least one by now.") 
		     #f;; (begin (debug:print-error 0 *default-log-port* "no servers listed, should be at least one by now.") 
		       ;;      (sqlite3:finalize! mdb)
		       ;;      (exit 1))
		     (car (db:get-rows all)))))
    (if first
	(let* ((header   (db:get-header all))
	       (id       (db:get-value-by-header first header "id"))
	       (hostname (db:get-value-by-header first header "hostname"))
	       (pid      (db:get-value-by-header first header "pid"))
	       (priority (db:get-value-by-header first header "priority")))
	  ;; (debug:print 0 "INFO: am-i-the-server got record " first)
	  ;; (debug:print 0 *default-log-port* "INFO: am-i-the-server got record " first)
	  ;; for now a basic check. add tiebreaking by priority later
	  (if (and (equal? hostname (get-host-name))
		   (equal? pid      (current-process-id)))
	      id
	      #f))
	#f)))
	     
324
325
326
327
328
329
330
331
332
333



334
335
336
337

338
339
340

341
342
343
344
345
346
347
324
325
326
327
328
329
330



331
332
333
334
335
336

337
338
339

340
341
342
343
344
345
346
347







-
-
-
+
+
+



-
+


-
+







(define (tasks:get-server mdb run-id #!key (retries 10))
  (let ((res  #f)
	(best #f))
    (handle-exceptions
     exn
     (begin
       (print-call-chain (current-error-port))
       (debug:print 0 "WARNING: tasks:get-server db access error.")
       (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 " for run " run-id)
       (debug:print 0 *default-log-port* "WARNING: tasks:get-server db access error.")
       (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
       (debug:print 0 *default-log-port* " for run " run-id)
       (print-call-chain (current-error-port))
       (if (> retries 0)
	   (begin
	     (debug:print 0 " trying call to tasks:get-server again in 10 seconds")
	     (debug:print 0 *default-log-port* " trying call to tasks:get-server again in 10 seconds")
	     (thread-sleep! 10)
	     (tasks:get-server mdb run-id retries: (- retries 0)))
	   (debug:print 0 "10 tries of tasks:get-server all crashed and burned. Giving up and returning \"no server found\"")))
	   (debug:print 0 *default-log-port* "10 tries of tasks:get-server all crashed and burned. Giving up and returning \"no server found\"")))
     (sqlite3:for-each-row
      (lambda (id interface port pubport transport pid hostname)
	(set! res (vector id interface port pubport transport pid hostname)))
      mdb
      ;; removed:
      ;; strftime('%s','now')-heartbeat < 10 AND mt_version = ?
      "SELECT id,interface,port,pubport,transport,pid,hostname FROM servers
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378

379
380
381
382

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
364
365
366
367
368
369
370

371
372
373
374
375
376
377

378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404







-
+






-
+



-
+














-
+







     (lambda (id)
       (set! res id))
     mdb ;; NEEDS dbprep ADDED
     "SELECT id FROM servers WHERE run_id=? AND state = 'running';" run-id)
    res))

(define (tasks:need-server run-id)
  (configf:lookup *configdat* "server" "required"))
  (equal? (configf:lookup *configdat* "server" "required") "yes"))

;; 	(maxqry (cdr (rmt:get-max-query-average run-id)))
;; 	(threshold   (string->number (or (configf:lookup *configdat* "server" "server-query-threshold") "10"))))
;;     (cond
;;      (forced 
;;       (if (common:low-noise-print 60 run-id "server required is set")
;; 	  (debug:print-info 0 "Server required is set, starting server for run-id " run-id "."))
;; 	  (debug:print-info 0 *default-log-port* "Server required is set, starting server for run-id " run-id "."))
;;       #t)
;;      ((> maxqry threshold)
;;       (if (common:low-noise-print 60 run-id "Max query time execeeded")
;; 	  (debug:print-info 0 "Max avg query time of " maxqry "ms exceeds limit of " threshold "ms, server needed for run-id " run-id "."))
;; 	  (debug:print-info 0 *default-log-port* "Max avg query time of " maxqry "ms exceeds limit of " threshold "ms, server needed for run-id " run-id "."))
;;       #t)
;;      (else
;;       #f))))

;; try to start a server and wait for it to be available
;;
(define (tasks:start-and-wait-for-server tdbdat run-id delay-max-tries)
  ;; ensure a server is running for this run
  (let loop ((server-dat (tasks:get-server (db:delay-if-busy tdbdat) run-id))
	     (delay-time 0))
      (if (and (not server-dat)
	       (< delay-time delay-max-tries))
	  (begin
	    (if (common:low-noise-print 60 "tasks:start-and-wait-for-server" run-id)
		(debug:print 0 "Try starting server for run-id " run-id))
		(debug:print 0 *default-log-port* "Try starting server for run-id " run-id))
	    (thread-sleep! (/ (random 2000) 1000))
	    (server:kind-run run-id)
	    (thread-sleep! (min delay-time 1))
	    (loop (tasks:get-server (db:delay-if-busy tdbdat) run-id)(+ delay-time 1))))))

(define (tasks:get-all-servers mdb)
  (let ((res '()))
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446

447
448
449

450
451
452
453
454
455
456
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448

449
450
451
452
453
454
455
456







-
+
















-
+


-
+







        FROM servers WHERE run_id=? AND state NOT LIKE 'defunct%' ORDER BY start_time DESC;"
     run-id)
    (reverse res)))

;; no elegance here ...
;;
(define (tasks:kill-server hostname pid)
  (debug:print-info 0 "Attempting to kill server process " pid " on host " hostname)
  (debug:print-info 0 *default-log-port* "Attempting to kill server process " pid " on host " hostname)
  (setenv "TARGETHOST" hostname)
  (setenv "TARGETHOST_LOGF" "server-kills.log")
  (system (conc "nbfake kill " pid))
  (unsetenv "TARGETHOST_LOGF")
  (unsetenv "TARGETHOST"))
 
;; look up a server by run-id and send it a kill, also delete the record for that server
;;
(define (tasks:kill-server-run-id run-id #!key (tag "default"))
  (let* ((tdbdat  (tasks:open-db))
	 (sdat    (tasks:get-server (db:delay-if-busy tdbdat) run-id)))
    (if sdat
	(let ((hostname (vector-ref sdat 6))
	      (pid      (vector-ref sdat 5))
	      (server-id (vector-ref sdat 0)))
	  (tasks:server-set-state! (db:delay-if-busy tdbdat) server-id "killed")
	  (debug:print-info 0 "Killing server " server-id " for run-id " run-id " on host " hostname " with pid " pid)
	  (debug:print-info 0 *default-log-port* "Killing server " server-id " for run-id " run-id " on host " hostname " with pid " pid)
	  (tasks:kill-server hostname pid)
	  (tasks:server-delete-record (db:delay-if-busy tdbdat) server-id tag) )
	(debug:print-info 0 "No server found for run-id " run-id ", nothing to kill"))
	(debug:print-info 0 *default-log-port* "No server found for run-id " run-id ", nothing to kill"))
    ;; (sqlite3:finalize! tdb)
    ))
    
;;======================================================================
;; M O N I T O R S
;;======================================================================

517
518
519
520
521
522
523
524

525
526
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552











553
554
555
556
557
558
559
517
518
519
520
521
522
523

524
525
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570







-
+









-
+


















+
+
+
+
+
+
+
+
+
+
+







     "SELECT count(id) FROM monitors WHERE last_update < (strftime('%s','now') - 300) AND username=?;"
     (car (user-information (current-user-id))))
    res))

;; 
(define (tasks:start-monitor db mdb)
  (if (> (tasks:get-num-alive-monitors mdb) 2) ;; have two running, no need for more
      (debug:print-info 1 "Not starting monitor, already have more than two running")
      (debug:print-info 1 *default-log-port* "Not starting monitor, already have more than two running")
      (let* ((megatestdb     (conc *toppath* "/megatest.db"))
	     (monitordbf     (conc (db:dbfile-path #f) "/monitor.db"))
	     (last-db-update 0)) ;; (file-modification-time megatestdb)))
	(task:register-monitor mdb)
	(let loop ((count      0)
		   (next-touch 0)) ;; next-touch is the time where we need to update last_update
	  ;; if the db has been modified we'd best look at the task queue
	  (let ((modtime (file-modification-time megatestdbpath )))
	    (if (> modtime last-db-update)
		(tasks:process-queue db mdb last-db-update megatestdb next-touch))
		(tasks:process-queue db)) ;; BROKEN. mdb last-db-update megatestdb next-touch))
	    ;; WARNING: Possible race conditon here!!
	    ;; should this update be immediately after the task-get-action call above?
	    (if (> (current-seconds) next-touch)
		(begin
		  (tasks:monitors-update mdb)
		  (loop (+ count 1)(+ (current-seconds) 240)))
		(loop (+ count 1) next-touch)))))))
      
;;======================================================================
;; T A S K S   Q U E U E
;;
;;   NOTE:: These operate on task_queue which is in main.db
;;
;;======================================================================

;; NOTE: It might be good to add one more layer of checking to ensure
;;       that no task gets run in parallel.

;; id INTEGER PRIMARY KEY,
;; action TEXT DEFAULT '',
;; owner TEXT,
;; state TEXT DEFAULT 'new',
;; target TEXT DEFAULT '',
;; name TEXT DEFAULT '',
;; testpatt TEXT DEFAULT '',
;; keylock TEXT,
;; params TEXT,
;; creation_time TIMESTAMP DEFAULT (strftime('%s','now')),
;; execution_time TIMESTAMP);


;; register a task
(define (tasks:add dbstruct action owner target runname testpatt params)
  (db:with-db 
   dbstruct #f #t
   (lambda (db)
643
644
645
646
647
648
649

















650
651
652
653
654
655
656
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684







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







	(conc "SELECT id,action,owner,state,target,name,test,item,params,creation_time,execution_time 
                  FROM tasks_queue "
	      ;; WHERE  
	      ;;   state IN " statesstr " AND 
	      ;;   action IN " actionsstr 
	      " ORDER BY creation_time DESC;"))
       res))))

(define (tasks:get-last dbstruct target runname)
  (let ((res #f))
    (db:with-db
     dbstruct #f #f
     (lambda (db)
       (sqlite3:for-each-row
	(lambda (id . rem)
	  (set! res (apply vector id rem)))
	db
	(conc "SELECT id,action,owner,state,target,name,testpatt,keylock,params,creation_time,execution_time 
                  FROM tasks_queue 
 	       WHERE  
	        target = ? AND name =?
	       ORDER BY creation_time DESC LIMIT 1;")
	target runname)
       res))))

;; remove tasks given by a string of numbers comma separated
(define (tasks:remove-queue-entries dbstruct task-ids)
  (db:with-db
   dbstruct #f #t
   (lambda (db)
     (sqlite3:execute db (conc "DELETE FROM tasks_queue WHERE id IN (" task-ids ");")))))
745
746
747
748
749
750
751
752
753


754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769


770
771
772
773
774
775
776
777
778
779
780
781
782
783

784
785
786
787
788
789
790
773
774
775
776
777
778
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
816
817
818







-
-
+
+







-
+






-
-
+
+













-
+







;; 
;; do a remote call to get the task queue info but do the killing as self here.
;;
(define (tasks:kill-runner target run-name testpatt)
  (let ((records    (rmt:tasks-find-task-queue-records target run-name testpatt "running" "run-tests"))
	(hostpid-rx (regexp "\\s+(\\w+)\\s+(\\d+)$"))) ;; host pid is at end of param string
    (if (null? records)
	(debug:print 0 "No run launching processes found for " target " / " run-name " with testpatt " (or testpatt "* no testpatt specified! *"))
	(debug:print 0 "Found " (length records) " run(s) to kill."))
	(debug:print 0 *default-log-port* "No run launching processes found for " target " / " run-name " with testpatt " (or testpatt "* no testpatt specified! *"))
	(debug:print 0 *default-log-port* "Found " (length records) " run(s) to kill."))
    (for-each 
     (lambda (record)
       (let* ((param-key (list-ref record 8))
	      (match-dat (string-search hostpid-rx param-key)))
	 (if match-dat
	     (let ((hostname  (cadr match-dat))
		   (pid       (string->number (caddr match-dat))))
	       (debug:print 0 "Sending SIGINT to process " pid " on host " hostname)
	       (debug:print 0 *default-log-port* "Sending SIGINT to process " pid " on host " hostname)
	       (if (equal? (get-host-name) hostname)
		   (if (process:alive? pid)
		       (begin
			 (handle-exceptions
			  exn
			  (begin
			    (debug:print 0 "Kill of process " pid " on host " hostname " failed.")
			    (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
			    (debug:print 0 *default-log-port* "Kill of process " pid " on host " hostname " failed.")
			    (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
			    #t)
			  (process-signal pid signal/int)
			  (thread-sleep! 5)
			  (if (process:alive? pid)
			      (process-signal pid signal/kill)))))
		   ;;  (call-with-environment-variables
		   (let ((old-targethost (getenv "TARGETHOST")))
		     (setenv "TARGETHOST" hostname)
		     (setenv "TARGETHOST_LOGF" "server-kills.log")
		     (system (conc "nbfake kill " pid))
		     (if old-targethost (setenv "TARGETHOST" old-targethost))
		     (unsetenv "TARGETHOST")
		     (unsetenv "TARGETHOST_LOGF"))))
	     (debug:print 0 "ERROR: no record or improper record for " target "/" run-name " in tasks_queue in main.db"))))
	     (debug:print-error 0 *default-log-port* "no record or improper record for " target "/" run-name " in tasks_queue in main.db"))))
     records)))

;; (define (tasks:start-run dbstruct mdb task)
;;   (let ((flags (make-hash-table)))
;;     (hash-table-set! flags "-rerun" "NOT_STARTED")
;;     (if (not (string=? (tasks:task-get-params task) ""))
;; 	(hash-table-set! flags "-setvars" (tasks:task-get-params task)))

Modified tdb.scm from [9506a565ad] to [03ea2dc1b8].

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
124
125
126
127
128
129
130

131
132
133
134
135
136
137
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
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+










-
+



















-
+


-
+





-
+









-
+









-
+







-
+











-
+








;; Create the sqlite db for the individual test(s)
;;
;; Moved these tables into <runid>.db
;; THIS CODE TO BE REMOVED
;;
(define (open-test-db work-area) 
  (debug:print-info 11 "open-test-db " work-area)
  (debug:print-info 11 *default-log-port* "open-test-db " work-area)
  (if (and work-area 
	   (directory? work-area)
	   (file-read-access? work-area))
      (let* ((dbpath              (conc work-area "/testdat.db"))
	     (dbexists            (file-exists? dbpath))
	     (work-area-writeable (file-write-access? work-area))
	     (db                  (handle-exceptions  ;; open the db if area writeable or db pre-existing. open in-mem otherwise. if exception, open in-mem
				   exn
				   (begin
				     (print-call-chain (current-error-port))
				     (debug:print 2 "ERROR: problem accessing test db " work-area ", you probably should clean and re-run this test"
				     (debug:print 2 *default-log-port* "ERROR: problem accessing test db " work-area ", you probably should clean and re-run this test"
						  ((condition-property-accessor 'exn 'message) exn))
				     (set! dbexists #f) ;; must force re-creation of tables, more tom-foolery
				     (sqlite3:open-database ":memory:")) ;; open an in-memory db to allow readonly access 
				   (if (or work-area-writeable
					   dbexists)
				       (sqlite3:open-database dbpath)
				       (sqlite3:open-database ":memory:"))))
	     (tdb-writeable       (and (file-write-access? work-area)
				       (file-write-access? dbpath)))
	     (handler   (make-busy-timeout (if (args:get-arg "-override-timeout")
					       (string->number (args:get-arg "-override-timeout"))
					       136000))))
	
	(if (and tdb-writeable
		 *db-write-access*)
	    (sqlite3:set-busy-handler! db handler))
	(if (not dbexists)
	    (begin
	      (db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = FULL;")
	      (debug:print-info 11 "Initialized test database " dbpath)
	      (debug:print-info 11 *default-log-port* "Initialized test database " dbpath)
	      (tdb:testdb-initialize db)))
	;; (sqlite3:execute db "PRAGMA synchronous = 0;")
	(debug:print-info 11 "open-test-db END (sucessful)" work-area)
	(debug:print-info 11 *default-log-port* "open-test-db END (sucessful)" work-area)
	;; now let's test that everything is correct
	(handle-exceptions
	 exn
	 (begin
	   (print-call-chain (current-error-port))
	   (debug:print 0 "ERROR: problem accessing test db " work-area ", you probably should clean and re-run this test or remove the file " 
	   (debug:print-error 0 *default-log-port* "problem accessing test db " work-area ", you probably should clean and re-run this test or remove the file " 
			dbpath ".\n  "
			((condition-property-accessor 'exn 'message) exn))
	   #f)
	 ;; Is there a cheaper single line operation that will check for existance of a table
	 ;; and raise an exception ?
	 (sqlite3:execute db "SELECT id FROM test_data LIMIT 1;"))
	db)
      ;; no work-area or not readable - create a placeholder to fake rest of world out
      (let ((baddb (sqlite3:open-database ":memory:")))
 	(debug:print-info 11 "open-test-db END (unsucessful)" work-area)
 	(debug:print-info 11 *default-log-port* "open-test-db END (unsucessful)" work-area)
 	;; provide an in-mem db (this is dangerous!)
 	(tdb:testdb-initialize baddb)
 	baddb)))

;; find and open the testdat.db file for an existing test
(define (tdb:open-test-db-by-test-id test-id #!key (work-area #f))
  (let* ((test-path (if work-area
			work-area
			(rmt:test-get-rundir-from-test-id test-id))))
    (debug:print 3 "TEST PATH: " test-path)
    (debug:print 3 *default-log-port* "TEST PATH: " test-path)
    (open-test-db test-path)))

;; find and open the testdat.db file for an existing test
(define (tdb:open-test-db-by-test-id-local dbstruct run-id test-id #!key (work-area #f))
  (let* ((test-path (if work-area
			work-area
			(db:test-get-rundir-from-test-id dbstruct run-id test-id))))
    (debug:print 3 "TEST PATH: " test-path)
    (debug:print 3 *default-log-port* "TEST PATH: " test-path)
    (open-test-db test-path)))

;; find and open the testdat.db file for an existing test
(define (tdb:open-run-close-db-by-test-id-local dbstruct run-id test-id work-area proc . params)
  (let* ((test-path (if work-area
			work-area
			(db:test-get-rundir-from-test-id dbstruct run-id test-id)))
	 (tdb        (open-test-db test-path)))
    (apply proc tdb params)))

(define (tdb:testdb-initialize db)
  (debug:print 11 "db:testdb-initialize START")
  (debug:print 11 *default-log-port* "db:testdb-initialize START")
  (sqlite3:with-transaction
   db
   (lambda ()
     (for-each
      (lambda (sqlcmd)
	(sqlite3:execute db sqlcmd))
      (list "CREATE TABLE IF NOT EXISTS test_rundat (
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183







-
+







	    ;;      the ackstate is set to 1 once the command has been completed
	    "CREATE TABLE IF NOT EXISTS test_meta (
              id INTEGER PRIMARY KEY,
              var TEXT,
              val TEXT,
              ackstate INTEGER DEFAULT 0,
              CONSTRAINT metadat_constraint UNIQUE (var));"))))
  (debug:print 11 "db:testdb-initialize END"))
  (debug:print 11 *default-log-port* "db:testdb-initialize END"))

;; This routine moved to db:read-test-data
;;
(define (tdb:read-test-data tdb test-id categorypatt)
  (let ((res '()))
    (sqlite3:for-each-row 
     (lambda (id test_id category variable value expected tol units comment status type)
206
207
208
209
210
211
212
213













214
215
216
217
218
219
220
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







-
+
+
+
+
+
+
+
+
+
+
+
+
+







;; 	'())))

;; NOTE: Run this local with #f for db !!!
(define (tdb:load-test-data run-id test-id)
  (let loop ((lin (read-line)))
    (if (not (eof-object? lin))
	(begin
	  (debug:print 4 lin)
	  (debug:print 4 *default-log-port* lin)
	  (rmt:csv->test-data run-id test-id lin)
	  (loop (read-line)))))
  ;; roll up the current results.
  ;; FIXME: Add the status too 
  (rmt:test-data-rollup run-id test-id #f))

;; NOTE: Run this local with #f for db !!!
(define (tdb:load-logpro-data run-id test-id)
  (let loop ((lin (read-line)))
    (if (not (eof-object? lin))
	(begin
	  (debug:print 4 *default-log-port* lin)
	  (rmt:csv->test-data run-id test-id lin)
	  (loop (read-line)))))
  ;; roll up the current results.
  ;; FIXME: Add the status too 
  (rmt:test-data-rollup run-id test-id #f))

(define (tdb:get-prev-tol-for-test tdb test-id category variable)
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
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
295







-
+





-
+

















-
+












-
+







;; 
;; NOT USED, WILL BE REMOVED
;;
(define (tdb:get-steps-table steps);; organise the steps for better readability
  (let ((res (make-hash-table)))
    (for-each 
     (lambda (step)
       (debug:print 6 "step=" step)
       (debug:print 6 *default-log-port* "step=" step)
       (let ((record (hash-table-ref/default 
		      res 
		      (tdb:step-get-stepname step) 
		      ;;        stepname                start end status Duration  Logfile 
		      (vector (tdb:step-get-stepname step) ""   "" ""     ""        ""))))
	 (debug:print 6 "record(before) = " record 
	 (debug:print 6 *default-log-port* "record(before) = " record 
		      "\nid:       " (tdb:step-get-id step)
		      "\nstepname: " (tdb:step-get-stepname step)
		      "\nstate:    " (tdb:step-get-state step)
		      "\nstatus:   " (tdb:step-get-status step)
		      "\ntime:     " (tdb:step-get-event_time step))
	 (case (string->symbol (tdb:step-get-state step))
	   ((start)(vector-set! record 1 (tdb:step-get-event_time step))
	    (vector-set! record 3 (if (equal? (vector-ref record 3) "")
				      (tdb:step-get-status step)))
	    (if (> (string-length (tdb:step-get-logfile step))
		   0)
		(vector-set! record 5 (tdb:step-get-logfile step))))
	   ((end)  
	    (vector-set! record 2 (any->number (tdb:step-get-event_time step)))
	    (vector-set! record 3 (tdb:step-get-status step))
	    (vector-set! record 4 (let ((startt (any->number (vector-ref record 1)))
					(endt   (any->number (vector-ref record 2))))
				    (debug:print 4 "record[1]=" (vector-ref record 1) 
				    (debug:print 4 *default-log-port* "record[1]=" (vector-ref record 1) 
						 ", startt=" startt ", endt=" endt
						 ", get-status: " (tdb:step-get-status step))
				    (if (and (number? startt)(number? endt))
					(seconds->hr-min-sec (- endt startt)) "-1")))
	    (if (> (string-length (tdb:step-get-logfile step))
		   0)
		(vector-set! record 5 (tdb:step-get-logfile step))))
	   (else
	    (vector-set! record 2 (tdb:step-get-state step))
	    (vector-set! record 3 (tdb:step-get-status step))
	    (vector-set! record 4 (tdb:step-get-event_time step))))
	 (hash-table-set! res (tdb:step-get-stepname step) record)
	 (debug:print 6 "record(after)  = " record 
	 (debug:print 6 *default-log-port* "record(after)  = " record 
		      "\nid:       " (tdb:step-get-id step)
		      "\nstepname: " (tdb:step-get-stepname step)
		      "\nstate:    " (tdb:step-get-state step)
		      "\nstatus:   " (tdb:step-get-status step)
		      "\ntime:     " (tdb:step-get-event_time step))))
     ;; (else   (vector-set! record 1 (tdb:step-get-event_time step)))
     (sort steps (lambda (a b)
293
294
295
296
297
298
299
300

301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
305
306
307
308
309
310
311

312
313
314
315
316
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+





-
+

















-
+












-
+







;; get a pretty table to summarize steps
;;
(define (tdb:get-steps-table-list steps)
  ;; organise the steps for better readability
  (let ((res (make-hash-table)))
    (for-each 
     (lambda (step)
       (debug:print 6 "step=" step)
       (debug:print 6 *default-log-port* "step=" step)
       (let ((record (hash-table-ref/default 
		      res 
		      (tdb:step-get-stepname step) 
		      ;;        stepname                start end status    
		      (vector (tdb:step-get-stepname step) ""   "" ""     "" ""))))
	 (debug:print 6 "record(before) = " record 
	 (debug:print 6 *default-log-port* "record(before) = " record 
		      "\nid:       " (tdb:step-get-id step)
		      "\nstepname: " (tdb:step-get-stepname step)
		      "\nstate:    " (tdb:step-get-state step)
		      "\nstatus:   " (tdb:step-get-status step)
		      "\ntime:     " (tdb:step-get-event_time step))
	 (case (string->symbol (tdb:step-get-state step))
	   ((start)(vector-set! record 1 (tdb:step-get-event_time step))
	    (vector-set! record 3 (if (equal? (vector-ref record 3) "")
				      (tdb:step-get-status step)))
	    (if (> (string-length (tdb:step-get-logfile step))
		   0)
		(vector-set! record 5 (tdb:step-get-logfile step))))
	   ((end)  
	    (vector-set! record 2 (any->number (tdb:step-get-event_time step)))
	    (vector-set! record 3 (tdb:step-get-status step))
	    (vector-set! record 4 (let ((startt (any->number (vector-ref record 1)))
					(endt   (any->number (vector-ref record 2))))
				    (debug:print 4 "record[1]=" (vector-ref record 1) 
				    (debug:print 4 *default-log-port* "record[1]=" (vector-ref record 1) 
						 ", startt=" startt ", endt=" endt
						 ", get-status: " (tdb:step-get-status step))
				    (if (and (number? startt)(number? endt))
					(seconds->hr-min-sec (- endt startt)) "-1")))
	    (if (> (string-length (tdb:step-get-logfile step))
		   0)
		(vector-set! record 5 (tdb:step-get-logfile step))))
	   (else
	    (vector-set! record 2 (tdb:step-get-state step))
	    (vector-set! record 3 (tdb:step-get-status step))
	    (vector-set! record 4 (tdb:step-get-event_time step))))
	 (hash-table-set! res (tdb:step-get-stepname step) record)
	 (debug:print 6 "record(after)  = " record 
	 (debug:print 6 *default-log-port* "record(after)  = " record 
		      "\nid:       " (tdb:step-get-id step)
		      "\nstepname: " (tdb:step-get-stepname step)
		      "\nstate:    " (tdb:step-get-state step)
		      "\nstatus:   " (tdb:step-get-status step)
		      "\ntime:     " (tdb:step-get-event_time step))))
     ;; (else   (vector-set! record 1 (tdb:step-get-event_time step)))
     (sort steps (lambda (a b)
381
382
383
384
385
386
387
388

389
393
394
395
396
397
398
399

400
401







-
+

(define (tdb:remote-update-testdat-meta-info run-id test-id work-area cpuload diskfree minutes)
  (let ((tdb         (rmt:open-test-db-by-test-id run-id test-id work-area: work-area)))
    (if (sqlite3:database? tdb)
	(begin
	  (sqlite3:execute tdb "INSERT INTO test_rundat (update_time,cpuload,diskfree,run_duration) VALUES (strftime('%s','now'),?,?,?);"
			   cpuload diskfree minutes)
	  (sqlite3:finalize! tdb))
	(debug:print 2 "Can't update testdat.db for test " test-id " read-only or non-existant"))))
	(debug:print 2 *default-log-port* "Can't update testdat.db for test " test-id " read-only or non-existant"))))
    

Modified tests.scm from [782c758c23] to [e84888f213].

45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59







-
+







(define (tests:get-tests-search-path cfgdat)
  (let ((paths (map cadr (configf:get-section cfgdat "tests-paths"))))
    (filter (lambda (d)
	      (if (directory-exists? d)
		  d
		  (begin
		    (if (common:low-noise-print 60 "tests:get-tests-search-path" d)
			(debug:print 0 "WARNING: problem with directory " d ", dropping it from tests path"))
			(debug:print 0 *default-log-port* "WARNING: problem with directory " d ", dropping it from tests path"))
		    #f)))
	    (append paths (list (conc *toppath* "/tests"))))))

(define (tests:get-valid-tests test-registry tests-paths)
  (if (null? tests-paths) 
      test-registry
      (let loop ((hed (car tests-paths))
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
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







-
+






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








-
+




-
+


-
+

-
+



-
+





-
+



-
+







-
+






-
+







(define (tests:lookup-itemmap itemmaps testname)
  (let ((best-matches (filter (lambda (itemmap)
				(tests:match (car itemmap) testname #f))
			      itemmaps)))
    (if (null? best-matches)
	#f
	(let ((res (car best-matches)))
	  ;; (debug:print 0 "res=" res)
	  ;; (debug:print 0 *default-log-port* "res=" res)
	  (cond
	   ((string? res) res) ;;; FIX THE ROOT CAUSE HERE ....
	   ((null? res)   #f)
	   ((string? (cdr res)) (cdr res))  ;; it is a pair
	   ((string? (cadr res))(cadr res)) ;; it is a list
	   (else cadr res))))))

;; return items given config
;;
(define (tests:get-items tconfig)
  (let ((items      (hash-table-ref/default tconfig "items" #f)) ;; items 4
	(itemstable (hash-table-ref/default tconfig "itemstable" #f))) 
    ;; if either items or items table is a proc return it so test running
    ;; process can know to call items:get-items-from-config
    ;; if either is a list and none is a proc go ahead and call get-items
    ;; otherwise return #f - this is not an iterated test
    (cond
     ((procedure? items)      
      (debug:print-info 4 *default-log-port* "items is a procedure, will calc later")
      items)            ;; calc later
     ((procedure? itemstable)
      (debug:print-info 4 *default-log-port* "itemstable is a procedure, will calc later")
      itemstable)       ;; calc later
     ((filter (lambda (x)
		(let ((val (car x)))
		  (if (procedure? val) val #f)))
	      (append (if (list? items) items '())
		      (if (list? itemstable) itemstable '())))
      'have-procedure)
     ((or (list? items)(list? itemstable)) ;; calc now
      (debug:print-info 4 *default-log-port* "items and itemstable are lists, calc now\n"
			"    items: " items " itemstable: " itemstable)
      (items:get-items-from-config tconfig))
     (else #f))))                           ;; not iterated


;; returns waitons waitors tconfigdat
;;
(define (tests:get-waitons test-name all-tests-registry)
   (let* ((config  (tests:get-testconfig test-name all-tests-registry 'return-procs)))
     (let ((instr (if config 
		      (config-lookup config "requirements" "waiton")
		      (begin ;; No config means this is a non-existant test
			(debug:print 0 "ERROR: non-existent required test \"" test-name "\"")
			(debug:print-error 0 *default-log-port* "non-existent required test \"" test-name "\"")
			(exit 1))))
	   (instr2 (if config
		       (config-lookup config "requirements" "waitor")
		       "")))
       (debug:print-info 8 "waitons string is " instr ", waitors string is " instr2)
       (debug:print-info 8 *default-log-port* "waitons string is " instr ", waitors string is " instr2)
       (let ((newwaitons
	      (string-split (cond
			     ((procedure? instr)
			     ((procedure? instr) ;; here 
			      (let ((res (instr)))
				(debug:print-info 8 "waiton procedure results in string " res " for test " test-name)
				(debug:print-info 8 *default-log-port* "waiton procedure results in string " res " for test " test-name)
				res))
			     ((string? instr)     instr)
			     (else 
			      ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print 0 "ERROR: something went wrong in processing waitons for test " test-name)
			      ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print-error 0 *default-log-port* "something went wrong in processing waitons for test " test-name)
			      ""))))
	     (newwaitors
	      (string-split (cond
			     ((procedure? instr2)
			      (let ((res (instr2)))
				(debug:print-info 8 "waitor procedure results in string " res " for test " test-name)
				(debug:print-info 8 *default-log-port* "waitor procedure results in string " res " for test " test-name)
				res))
			     ((string? instr2)     instr2)
			     (else 
			      ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print 0 "ERROR: something went wrong in processing waitons for test " test-name)
			      ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print-error 0 *default-log-port* "something went wrong in processing waitons for test " test-name)
			      "")))))
	 (values
	  ;; the waitons
	  (filter (lambda (x)
		    (if (hash-table-ref/default all-tests-registry x #f)
			#t
			(begin
			  (debug:print 0 "ERROR: test " test-name " has unrecognised waiton testname " x)
			  (debug:print-error 0 *default-log-port* "test " test-name " has unrecognised waiton testname " x)
			  #f)))
		  newwaitons)
	  (filter (lambda (x)
		    (if (hash-table-ref/default all-tests-registry x #f)
			#t
			(begin
			  (debug:print 0 "ERROR: test " test-name " has unrecognised waiton testname " x)
			  (debug:print-error 0 *default-log-port* "test " test-name " has unrecognised waiton testname " x)
			  #f)))
		  newwaitors)
	  config)))))
					     
;; given waiting-test that is waiting on waiton-test extend test-patt appropriately
;;
;;  genlib/testconfig               sim/testconfig
186
187
188
189
190
191
192


193
194
195
196
197
198
199
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230







+
+







				(filter (lambda (x)
					  (eq? (substring-index (conc waiting-test "/") x) 0)) ;; is this patt pertinent to the waiting test
					patts))))
    (string-intersperse (delete-duplicates (append patts (if (null? patts-waiton)
							     (list (conc waiton-test "/%")) ;; really shouldn't add the waiton forcefully like this
							     patts-waiton)))
			",")))


  
;; tests:glob-like-match 
(define (tests:glob-like-match patt str) 
  (let ((like (substring-index "%" patt)))
    (let* ((notpatt  (equal? (substring-index "~" patt) 0))
	   (newpatt  (if notpatt (substring patt 1) patt))
	   (finpatt  (if like
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
308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354







-
+







-
+









-
+











-
+









-
+







	  (dbr:test-rundir prev-testdat)) ;; )
	 (waivers     (if testconfig (configf:section-vars testconfig "waivers") '()))
	 (waiver-rx   (regexp "^(\\S+)\\s+(.*)$"))
	 (diff-rule   "diff %file1% %file2%")
	 (logpro-rule "diff %file1% %file2% | logpro %waivername%.logpro %waivername%.html"))
    (if (not (file-exists? test-rundir))
	(begin
	  (debug:print 0 "ERROR: test run directory is gone, cannot propagate waiver")
	  (debug:print-error 0 *default-log-port* "test run directory is gone, cannot propagate waiver")
	  #f)
	(begin
	  (push-directory test-rundir)
	  (let ((result (if (null? waivers)
			    #f
			    (let loop ((hed (car waivers))
				       (tal (cdr waivers)))
			      (debug:print 0 "INFO: Applying waiver rule \"" hed "\"")
			      (debug:print 0 *default-log-port* "INFO: Applying waiver rule \"" hed "\"")
			      (let* ((waiver      (configf:lookup testconfig "waivers" hed))
				     (wparts      (if waiver (string-match waiver-rx waiver) #f))
				     (waiver-rule (if wparts (cadr wparts)  #f))
				     (waiver-glob (if wparts (caddr wparts) #f))
				     (logpro-file (if waiver
						      (let ((fname (conc hed ".logpro")))
							(if (file-exists? fname)
							    fname 
							    (begin
							      (debug:print 0 "INFO: No logpro file " fname " falling back to diff")
							      (debug:print 0 *default-log-port* "INFO: No logpro file " fname " falling back to diff")
							      #f)))
						      #f))
				     ;; if rule by name of waiver-rule is found in testconfig - use it
				     ;; else if waivername.logpro exists use logpro-rule
				     ;; else default to diff-rule
				     (rule-string (let ((rule (configf:lookup testconfig "waiver_rules" waiver-rule)))
						    (if rule
							rule
							(if logpro-file
							    logpro-rule
							    (begin
							      (debug:print 0 "INFO: No logpro file " logpro-file " found, using diff rule")
							      (debug:print 0 *default-log-port* "INFO: No logpro file " logpro-file " found, using diff rule")
							      diff-rule)))))
				     ;; (string-substitute "%file1%" "foofoo.txt" "This is %file1% and so is this %file1%." #t)
				     (processed-cmd (string-substitute 
						     "%file1%" (conc test-rundir "/" waiver-glob)
						     (string-substitute
						      "%file2%" (conc prev-rundir "/" waiver-glob)
						      (string-substitute
						       "%waivername%" hed rule-string #t) #t) #t))
				     (res            #f))
				(debug:print 0 "INFO: waiver command is \"" processed-cmd "\"")
				(debug:print 0 *default-log-port* "INFO: waiver command is \"" processed-cmd "\"")
				(if (eq? (system processed-cmd) 0)
				    (if (null? tal)
					#t
					(loop (car tal)(cdr tal)))
				    #f))))))
	    (pop-directory)
	    result)))))
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402







-
+












-
+







			  (rmt:get-previous-test-run-record run-id test-name item-path)
			  #f))
	 (waived   (if prev-test
		       (if prev-test ;; true if we found a previous test in this run series
			   (let ((prev-status  (dbr:test-status  prev-test))
				 (prev-state   (dbr:test-state   prev-test))
				 (prev-comment (dbr:test-comment prev-test)))
			     (debug:print 4 "prev-status " prev-status ", prev-state " prev-state ", prev-comment " prev-comment)
			     (debug:print 4 *default-log-port* "prev-status " prev-status ", prev-state " prev-state ", prev-comment " prev-comment)
			     (if (and (equal? prev-state  "COMPLETED")
				      (equal? prev-status "WAIVED"))
				 (if comment
				     comment
				     prev-comment) ;; waived is either the comment or #f
				 #f))
			   #f)
		       #f)))
    (if (and waived 
	     (tests:check-waiver-eligibility testdat prev-test))
	(set! real-status "WAIVED"))

    (debug:print 4 "real-status " real-status ", waived " waived ", status " status)
    (debug:print 4 *default-log-port* "real-status " real-status ", waived " waived ", status " status)

    ;; update the primary record IF state AND status are defined
    (if (and state status)
	(begin
	  (rmt:test-set-status-state run-id test-id real-status state (if waived waived comment))
	  (mt:process-triggers run-id test-id state real-status)))
    
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435







-
+







	  (variable (hash-table-ref/default otherdat ":variable" ""))
	  (value    (hash-table-ref/default otherdat ":value"    #f))
	  (expected (hash-table-ref/default otherdat ":expected" #f))
	  (tol      (hash-table-ref/default otherdat ":tol"      #f))
	  (units    (hash-table-ref/default otherdat ":units"    ""))
	  (type     (hash-table-ref/default otherdat ":type"     ""))
	  (dcomment (hash-table-ref/default otherdat ":comment"  "")))
      (debug:print 4 
      (debug:print 4 *default-log-port* 
		   "category: " category ", variable: " variable ", value: " value
		   ", expected: " expected ", tol: " tol ", units: " units)
      (if (and value expected tol) ;; all three required
	  (let ((dat (conc category ","
			   variable ","
			   value    ","
			   expected ","
432
433
434
435
436
437
438
439

440
441
442
443


444
445
446
447
448
449
450
463
464
465
466
467
468
469

470
471
472


473
474
475
476
477
478
479
480
481







-
+


-
-
+
+







	 (logf-info      (rmt:test-get-logfile-info run-id test-name))
	 (logf           (if logf-info (cadr logf-info) #f))
	 (path           (if logf-info (car  logf-info) #f)))
    ;; This query finds the path and changes the directory to it for the test
    (if (and (string? path)
	     (directory? path)) ;; can get #f here under some wierd conditions. why, unknown ...
	(begin
	  (debug:print 4 "Found path: " path)
	  (debug:print 4 *default-log-port* "Found path: " path)
	  (change-directory path))
	;; (set! outputfilename (conc path "/" outputfilename)))
	(debug:print 0 "ERROR: summarize-items for run-id=" run-id ", test-name=" test-name ", no such path: " path))
    (debug:print 4 "summarize-items with logf " logf ", outputfilename " outputfilename " and force " force)
	(debug:print-error 0 *default-log-port* "summarize-items for run-id=" run-id ", test-name=" test-name ", no such path: " path))
    (debug:print 4 *default-log-port* "summarize-items with logf " logf ", outputfilename " outputfilename " and force " force)
    (if (or (equal? logf "logs/final.log")
	    (equal? logf outputfilename)
	    force)
	(let ((my-start-time (current-seconds))
	      (lockf         (conc outputfilename ".lock")))
	  (let loop ((have-lock  (common:simple-file-lock lockf)))
	    (if have-lock
461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477





478
479
480
481
482
483
484
492
493
494
495
496
497
498

499
500
501
502
503





504
505
506
507
508
509
510
511
512
513
514
515







-
+




-
-
-
-
-
+
+
+
+
+







		  ;; NB// tests:test-set-toplog! is remote internal...
		  (tests:test-set-toplog! run-id test-name outputfilename))
		;; didn't get the lock, check to see if current update started later than this 
		;; update, if so we can exit without doing any work
		(if (> my-start-time (file-modification-time lockf))
		    ;; we started since current re-gen in flight, delay a little and try again
		    (begin
		      (debug:print-info 1 "Waiting to update " outputfilename ", another test currently updating it")
		      (debug:print-info 1 *default-log-port* "Waiting to update " outputfilename ", another test currently updating it")
		      (thread-sleep! (+ 5 (random 5))) ;; delay between 5 and 10 seconds
		      (loop (common:simple-file-lock lockf))))))))))

(define (tests:generate-html-summary-for-iterated-test run-id test-id test-name outputfilename)
  (let ((counts (make-hash-table))
	(statecounts (make-hash-table))
	(outtxt "")
	(tot    0)
	(testdat (rmt:test-get-records-for-index-file run-id test-name)))
  (let ((counts              (make-hash-table))
	(statecounts         (make-hash-table))
	(outtxt              "")
	(tot                 0)
	(testdat             (rmt:test-get-records-for-index-file run-id test-name)))
    (with-output-to-file outputfilename
      (lambda ()
	(set! outtxt (conc outtxt "<html><title>Summary: " test-name 
			   "</title><body><h2>Summary for " test-name "</h2>"))
	(for-each
	 (lambda (testrecord)
	   (let ((id             (vector-ref testrecord 0))
527
528
529
530
531
532
533






534
535
536
537
538
539
540
541
542
543
544
545
546
547

548
549
550
551
552
553



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578




579
580
581
582


583
584

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

600
601
602

603
604
605

606
607
608
609
610
611
612
613
614
615
616

617

618
619
620
621
622
623
624
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583

584
585
586
587



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

608
609
610
611
612
613
614

615
616
617
618
619
620
621

622
623
624

625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

640

641

642



643
644
645
646
647
648
649
650
651
652
653
654
655

656
657
658
659
660
661
662
663







+
+
+
+
+
+













-
+



-
-
-
+
+
+

















-
+






-
+
+
+
+



-
+
+

-
+














-
+
-

-
+
-
-
-
+











+
-
+







	(print "<tr><td>Total</td><td>" tot "</td></tr></table>")
	(print "</td></td></tr></table>")
	
	(print "<table cellspacing=\"0\" border=\"1\">" 
	       "<tr><td>Item</td><td>State</td><td>Status</td><td>Comment</td>"
	       outtxt "</table></body></html>")
	;; (release-dot-lock outputfilename)
	;;(rmt:update-run-stats 
	;; run-id
	;; (hash-table-map
	;;  state-status-counts
	;;  (lambda (key val)
	;;	(append key (list val)))))
	))))

;; CHECK - WAS THIS ADDED OR REMOVED? MANUAL MERGE WITH API STUFF!!!
;;
;; get a pretty table to summarize steps
;;
;; (define (dcommon:process-steps-table steps);; db test-id #!key (work-area #f))
(define (tests:process-steps-table steps);; db test-id #!key (work-area #f))
;;  (let ((steps   (db:get-steps-for-test db test-id work-area: work-area)))
    ;; organise the steps for better readability
    (let ((res (make-hash-table)))
      (for-each 
       (lambda (step)
	 (debug:print 6 "step=" step)
	 (debug:print 6 *default-log-port* "step=" step)
	 (let ((record (hash-table-ref/default 
			res 
			(tdb:step-get-stepname step) 
			;;        stepname                start end status Duration  Logfile 
			(vector (tdb:step-get-stepname step) ""   "" ""     ""        ""))))
	   (debug:print 6 "record(before) = " record 
			;;        stepname                start end status Duration  Logfile Comment
			(vector (tdb:step-get-stepname step) ""   "" ""     ""        ""     ""))))
	   (debug:print 6 *default-log-port* "record(before) = " record 
			"\nid:       " (tdb:step-get-id step)
			"\nstepname: " (tdb:step-get-stepname step)
			"\nstate:    " (tdb:step-get-state step)
			"\nstatus:   " (tdb:step-get-status step)
			"\ntime:     " (tdb:step-get-event_time step))
	   (case (string->symbol (tdb:step-get-state step))
	     ((start)(vector-set! record 1 (tdb:step-get-event_time step))
	      (vector-set! record 3 (if (equal? (vector-ref record 3) "")
					(tdb:step-get-status step)))
	      (if (> (string-length (tdb:step-get-logfile step))
		     0)
		  (vector-set! record 5 (tdb:step-get-logfile step))))
	     ((end)  
	      (vector-set! record 2 (any->number (tdb:step-get-event_time step)))
	      (vector-set! record 3 (tdb:step-get-status step))
	      (vector-set! record 4 (let ((startt (any->number (vector-ref record 1)))
					  (endt   (any->number (vector-ref record 2))))
				      (debug:print 4 "record[1]=" (vector-ref record 1) 
				      (debug:print 4 *default-log-port* "record[1]=" (vector-ref record 1) 
						   ", startt=" startt ", endt=" endt
						   ", get-status: " (tdb:step-get-status step))
				      (if (and (number? startt)(number? endt))
					  (seconds->hr-min-sec (- endt startt)) "-1")))
	      (if (> (string-length (tdb:step-get-logfile step))
		     0)
		  (vector-set! record 5 (tdb:step-get-logfile step))))
		  (vector-set! record 5 (tdb:step-get-logfile step)))
	      (if (> (string-length (tdb:step-get-comment step))
		     0)
		  (vector-set! record 6 (tdb:step-get-comment step))))
	     (else
	      (vector-set! record 2 (tdb:step-get-state step))
	      (vector-set! record 3 (tdb:step-get-status step))
	      (vector-set! record 4 (tdb:step-get-event_time step))))
	      (vector-set! record 4 (tdb:step-get-event_time step))
	      (vector-set! record 6 (tdb:step-get-comment step))))
	   (hash-table-set! res (tdb:step-get-stepname step) record)
	   (debug:print 6 "record(after)  = " record 
	   (debug:print 6 *default-log-port* "record(after)  = " record 
			"\nid:       " (tdb:step-get-id step)
			"\nstepname: " (tdb:step-get-stepname step)
			"\nstate:    " (tdb:step-get-state step)
			"\nstatus:   " (tdb:step-get-status step)
			"\ntime:     " (tdb:step-get-event_time step))))
       ;; (else   (vector-set! record 1 (tdb:step-get-event_time step)))
       (sort steps (lambda (a b)
		     (cond
		      ((<   (tdb:step-get-event_time a)(tdb:step-get-event_time b)) #t)
		      ((eq? (tdb:step-get-event_time a)(tdb:step-get-event_time b)) 
		       (<   (tdb:step-get-id a)        (tdb:step-get-id b)))
		      (else #f)))))
      res))


;; 
;; temporarily passing in dbstruct to support direct access (i.e. bypassing servers)
;;
(define (tests:get-compressed-steps dbstruct run-id test-id)
(define (tests:get-compressed-steps run-id test-id)
  (let* ((steps-data  (if dbstruct 
			  (db:get-steps-for-test dbstruct run-id test-id)
			  (rmt:get-steps-for-test run-id test-id))) 
  (let* ((steps-data  (rmt:get-steps-for-test run-id test-id))
	 (comprsteps  (tests:process-steps-table steps-data))) ;; (open-run-close db:get-steps-table #f test-id work-area: work-area)))
    (map (lambda (x)
	   ;; take advantage of the \n on time->string
	   (vector
	    (vector-ref x 0)
	    (let ((s (vector-ref x 1)))
	      (if (number? s)(seconds->time-string s) s))
	    (let ((s (vector-ref x 2)))
	      (if (number? s)(seconds->time-string s) s))
	    (vector-ref x 3)    ;; status
	    (vector-ref x 4)
	    (vector-ref x 5)  ;; time delta
	    (vector-ref x 5)))  ;; time delta
	    (vector-ref x 6)))
	 (sort (hash-table-values comprsteps)
	       (lambda (a b)
		 (let ((time-a (vector-ref a 1))
		       (time-b (vector-ref b 1)))
		   (if (and (number? time-a)(number? time-b))
		       (if (< time-a time-b)
			   #t
636
637
638
639
640
641
642
643

644
645
646
647
648
649
650
675
676
677
678
679
680
681

682
683
684
685
686
687
688
689







-
+







	 (test-name (dbr:test-testname test-dat))
	 (item-path (dbr:test-item-path test-dat))
	 (full-name (db:test-make-full-name test-name item-path))
	 (oup       (open-output-file (conc (dbr:test-rundir test-dat) "/test-summary.html")))
	 (status    (dbr:test-status   test-dat))
	 (color     (common:get-color-from-status status))
	 (logf      (dbr:test-final_logf test-dat))
	 (steps-dat (tests:get-compressed-steps #f run-id test-id)))
	 (steps-dat (tests:get-compressed-steps run-id test-id)))
    ;; (dcommon:get-compressed-steps #f 1 30045)
    ;; (#("wasting_time" "23:36:13" "23:36:21" "0" "8.0s" "wasting_time.log"))

    (s:output-new
     oup
     (s:html
      (s:title "Summary for " full-name)
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732













733





734
735
736
737
738
739
740
741
742
743



744
745

746
747
748
749
750
751




752
753
754
755
756
757
758
759
760
761
762


























763
764
765
766
767
768





769
770
771
772
773
774
775
776

777
778
779
780
781
782
783
753
754
755
756
757
758
759












760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
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
816
817
818
819
820
821
822
823
824
825
826

827
828
829
830
831
832
833
834







-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+

-
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+







-
+







;;      (filter (lambda (testname)
;; 	       (tests:match test-patts testname #f))
;; 	     (map (lambda (testp)
;; 		    (last (string-split testp "/")))
;; 		  tests)))))

(define (tests:get-test-path-from-environment)
  (and (getenv "MT_LINKTREE")
       (getenv "MT_TARGET")
       (getenv "MT_RUNNAME")
       (getenv "MT_TEST_NAME")
       (getenv "MT_ITEMPATH")
       (conc (getenv "MT_LINKTREE")  "/"
	     (getenv "MT_TARGET")    "/"
	     (getenv "MT_RUNNAME")   "/"
	     (getenv "MT_TEST_NAME") "/"
	     (if (or (getenv "MT_ITEMPATH")
		     (not (string=? "" (getenv "MT_ITEMPATH"))))
		 (conc "/" (getenv "MT_ITEMPATH"))))))
  (if (and (getenv "MT_LINKTREE")
	   (getenv "MT_TARGET")
	   (getenv "MT_RUNNAME")
	   (getenv "MT_TEST_NAME")
	   (getenv "MT_ITEMPATH"))
      (conc (getenv "MT_LINKTREE")  "/"
	    (getenv "MT_TARGET")    "/"
	    (getenv "MT_RUNNAME")   "/"
	    (getenv "MT_TEST_NAME") "/"
	    (if (or (getenv "MT_ITEMPATH")
		    (not (string=? "" (getenv "MT_ITEMPATH"))))
		(conc "/" (getenv "MT_ITEMPATH"))))
      #f))

;; if .testconfig exists in test directory read and return it
;; else if have cached copy in *testconfigs* return it IFF there is a section "have fulldata"
;; else read the testconfig file
;;   if have path to test directory save the config as .testconfig and return it
;;
(define (tests:get-testconfig test-name test-registry system-allowed #!key (force-create #f))
  (let* ((treg              (or test-registry
				(tests:get-all)))
	 (test-path         (hash-table-ref/default 
			     treg test-name 
			     (conc *toppath* "/tests/" test-name)))
	 (test-configf (conc test-path "/testconfig"))
	 (testexists   (and (file-exists? test-configf)(file-read-access? test-configf)))
	 (cache-path   (tests:get-test-path-from-environment))
	 (cache-exists (and cache-path 
  (let* ((cache-path   (tests:get-test-path-from-environment))
	 (cache-file   (and cache-path (conc cache-path "/.testconfig")))
	 (cache-exists (and cache-file
			    (not force-create)  ;; if force-create then pretend there is no cache to read
			    (file-exists? (conc cache-path "/.testconfig"))))
			    (file-exists? cache-file)))
	 (cache-file   (conc cache-path "/.testconfig"))
	 (tcfg         (if testexists
			   (or (and (not force-create)
				    cache-exists
				    (handle-exceptions
				     exn
	 (cached-dat   (if (and (not force-create)
				cache-exists)
			   (handle-exceptions
			    exn
				     (begin
				       (debug:print 0 "WARNING: Failed to read " cache-file) 
				       (make-hash-table)) ;; better to return a hash and keep going - I think
				     (configf:read-alist cache-file)))
			       (read-config test-configf #f system-allowed environ-patt: (if system-allowed
											     "pre-launch-env-vars"
											     #f)))
			   #f)))
    (hash-table-set! *testconfigs* test-name tcfg)
    (if (and testexists
	     cache-path
			    #f ;; any issues, just give up with the cached version and re-read
			    (configf:read-alist cache-file))
			   #f)))
    (if cached-dat
	cached-dat
	(let ((dat (hash-table-ref/default *testconfigs* test-name #f)))
	  (if (and  dat ;; have a locally cached version
		    (hash-table-ref/default dat "have fulldata" #f)) ;; marked as good data?
	      dat
	      ;; no cached data available
	      (let* ((treg         (or test-registry
				       (tests:get-all)))
		     (test-path    (or (hash-table-ref/default treg test-name #f)
				       (conc *toppath* "/tests/" test-name)))
		     (test-configf (conc test-path "/testconfig"))
		     (testexists   (and (file-exists? test-configf)(file-read-access? test-configf)))
		     (tcfg         (if testexists
				       (read-config test-configf #f system-allowed
						    environ-patt: (if system-allowed
								      "pre-launch-env-vars"
								      #f))
				       #f)))
		(if (and tcfg cache-file) (hash-table-set! tcfg "have fulldata" #t)) ;; mark this as fully read data
		(if tcfg (hash-table-set! *testconfigs* test-name tcfg))
		(if (and testexists
			 cache-file
	     (not cache-exists)
	     (file-write-access? cache-path))
	(let ((tpath (conc cache-path "/.testconfig")))
	  (debug:print-info 1 "Caching testconfig for " test-name " in " tpath)
	  (configf:write-alist tcfg tpath)))
    tcfg))
			 (file-write-access? cache-path))
		    (let ((tpath (conc cache-path "/.testconfig")))
		      (debug:print-info 1 *default-log-port* "Caching testconfig for " test-name " in " tpath)
		      (configf:write-alist tcfg tpath)))
		tcfg))))))
  
;; sort tests by priority and waiton
;; Move test specific stuff to a test unit FIXME one of these days
(define (tests:sort-by-priority-and-waiton test-records)
  (let* ((mungepriority (lambda (priority)
			  (if priority
			      (let ((tmp (any->number priority)))
				(if tmp tmp (begin (debug:print 0 "ERROR: bad priority value " priority ", using 0") 0)))
				(if tmp tmp (begin (debug:print-error 0 *default-log-port* "bad priority value " priority ", using 0") 0)))
			      0)))
	 (all-tests      (hash-table-keys test-records))
	 (all-waited-on  (let loop ((hed (car all-tests))
				    (tal (cdr all-tests))
				    (res '()))
			   (let* ((trec    (hash-table-ref test-records hed))
				  (waitons (or (tests:testqueue-get-waitons trec) '())))
794
795
796
797
798
799
800
801

802
803
804
805

806
807
808

809
810
811
812

813
814
815
816

817
818
819
820

821
822
823
824
825

826
827
828
829
830
831
832
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







-
+



-
+


-
+



-
+



-
+



-
+




-
+







		   (b-config   (tests:testqueue-get-testconfig  b-record))
		   (a-raw-pri  (config-lookup a-config "requirements" "priority"))
		   (b-raw-pri  (config-lookup b-config "requirements" "priority"))
		   (a-priority (mungepriority a-raw-pri))
		   (b-priority (mungepriority b-raw-pri)))
	      (tests:testqueue-set-priority! a-record a-priority)
	      (tests:testqueue-set-priority! b-record b-priority)
	      ;; (debug:print 0 "a=" a ", b=" b ", a-waitons=" a-waitons ", b-waitons=" b-waitons)
	      ;; (debug:print 0 *default-log-port* "a=" a ", b=" b ", a-waitons=" a-waitons ", b-waitons=" b-waitons)
	      (cond
	       ;; is 
	       ((member a b-waitons)          ;; is b waiting on a?
		;; (debug:print 0 "case1")
		;; (debug:print 0 *default-log-port* "case1")
		#t)
	       ((member b a-waitons)          ;; is a waiting on b?
		;; (debug:print 0 "case2")
		;; (debug:print 0 *default-log-port* "case2")
		#f)
	       ((and (not (null? a-waitons))  ;; both have waitons - do not disturb
		     (not (null? b-waitons)))
		;; (debug:print 0 "case2.1")
		;; (debug:print 0 *default-log-port* "case2.1")
		#t)
	       ((and (null? a-waitons)        ;; no waitons for a but b has waitons
		     (not (null? b-waitons)))
		;; (debug:print 0 "case3")
		;; (debug:print 0 *default-log-port* "case3")
		#f)
	       ((and (not (null? a-waitons))  ;; a has waitons but b does not
		     (null? b-waitons)) 
		;; (debug:print 0 "case4")
		;; (debug:print 0 *default-log-port* "case4")
		#t)
	       ((not (eq? a-priority b-priority)) ;; use
		(> a-priority b-priority))
	       (else
		;; (debug:print 0 "case5")
		;; (debug:print 0 *default-log-port* "case5")
		(string>? a b))))))
	 
	 (sort-fn2
	  (lambda (a b)
	    (> (mungepriority (tests:testqueue-get-priority (hash-table-ref test-records a)))
	       (mungepriority (tests:testqueue-get-priority (hash-table-ref test-records b)))))))
    ;; (let ((dot-res (tests:run-dot (tests:tests->dot test-records) "plain")))
841
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
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
932
933
934
935
936
937
938

939
940

941
942
943
944
945
946
947
948







+



















-
+



-
+

-
+





-
+
+
+
+




-
+

-
+








(define (tests:easy-dot test-records outtype)
  (let-values (((fd temp-path) (file-mkstemp (conc "/tmp/" (current-user-name) ".XXXXXX"))))
    (let ((all-testnames (hash-table-keys test-records))
	  (temp-port     (open-output-file* fd)))
      ;; (format temp-port "This file is ~A.~%" temp-path)
      (format temp-port "digraph tests {\n")
      (format temp-port "  size=4,8\n")
      ;; (format temp-port "   splines=none\n")
      (for-each
       (lambda (testname)
	 (let* ((testrec (hash-table-ref test-records testname))
		(waitons (or (tests:testqueue-get-waitons testrec) '())))
	   (for-each
	    (lambda (waiton)
	      (format temp-port (conc "   " waiton " -> " testname " [splines=ortho]\n")))
	    waitons)))
       all-testnames)
      (format temp-port "}\n")
      (close-output-port temp-port)
      (with-input-from-pipe
       (conc "env -i PATH=$PATH dot -T" outtype " < " temp-path)
       (lambda ()
	 (let ((res (read-lines)))
	   ;; (delete-file temp-path)
	   res))))))

(define (tests:write-dot-file test-records fname)
(define (tests:write-dot-file test-records fname sizex sizey)
  (if (file-write-access? (pathname-directory fname))
      (with-output-to-file fname
	(lambda ()
	  (map print (tests:tests->dot test-records))))))
	  (map print (tests:tests->dot test-records sizex sizey))))))

(define (tests:tests->dot test-records)
(define (tests:tests->dot test-records sizex sizey)
  (let ((all-testnames (hash-table-keys test-records)))
    (if (null? all-testnames)
	'()
	(let loop ((hed (car all-testnames))
		   (tal (cdr all-testnames))
		   (res (list "digraph tests {")))
		   (res (list "digraph tests {"
			      (conc " size=\"" (or sizex 11) "," (or sizey 11) "\";")
			      " ratio=0.95;"
			      )))
	  (let* ((testrec (hash-table-ref test-records hed))
		 (waitons (or (tests:testqueue-get-waitons testrec) '()))
		 (newres  (append res
				  (if (null? waitons)
				      (list (conc "   \"" hed "\";"))
				      (list (conc "   \"" hed "\" [shape=box];"))
				      (map (lambda (waiton)
					     (conc "   \"" waiton "\" -> \"" hed "\";"))
					     (conc "   \"" waiton "\" -> \"" hed "\" [shape=box];"))
					   waitons)
				      ))))
	    (if (null? tal)
		(append newres (list "}"))
		(loop (car tal)(cdr tal) newres)
		))))))

904
905
906
907
908
909
910
911

912
913
914

915
916
917
918
919
920
921
959
960
961
962
963
964
965

966
967
968

969
970
971
972
973
974
975
976







-
+


-
+







		   (read-lines)))))
      (close-input-port inp)
      res)))

;; read data from tmp file or create if not exists
;; if exists regen in background
;;
(define (tests:lazy-dot testrecords  outtype)
(define (tests:lazy-dot testrecords  outtype sizex sizey)
  (let ((dfile (conc "/tmp/." (current-user-name) "-" (server:mk-signature) ".dot"))
	(fname (conc "/tmp/." (current-user-name) "-" (server:mk-signature) ".dotdat")))
    (tests:write-dot-file testrecords dfile)
    (tests:write-dot-file testrecords dfile sizex sizey)
    (if (file-exists? fname)
	(let ((res (with-input-from-file fname
		     (lambda ()
		       (read-lines)))))
	  (system (conc "env -i PATH=$PATH dot -T " outtype " < " dfile " > " fname "&"))
	  res)
	(begin
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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1030
1031
1032
1033
1034
1035
1036

1037
1038
1039
1040
1041

1042
1043

1044
1045
1046
1047

1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101







-
+




-
+

-
+



-
+



-
+






-
+




-
+

















-
+


-
+








-
+







;;======================================================================
;; hed is the test name
;; test-records is a hash of test-name => test record
(define (tests:get-full-data test-names test-records required-tests all-tests-registry)
  (if (not (null? test-names))
      (let loop ((hed (car test-names))
		 (tal (cdr test-names)))         ;; 'return-procs tells the config reader to prep running system but return a proc
	(debug:print-info 4 "hed=" hed " at top of loop")
	(debug:print-info 4 *default-log-port* "hed=" hed " at top of loop")
	(let* ((config  (tests:get-testconfig hed all-tests-registry 'return-procs))
	       (waitons (let ((instr (if config 
					 (config-lookup config "requirements" "waiton")
					 (begin ;; No config means this is a non-existant test
					   (debug:print 0 "ERROR: non-existent required test \"" hed "\", grep through your testconfigs to find and remove or create the test. Discarding and continuing.")
					   (debug:print-error 0 *default-log-port* "non-existent required test \"" hed "\", grep through your testconfigs to find and remove or create the test. Discarding and continuing.")
					     ""))))
			  (debug:print-info 8 "waitons string is " instr)
			  (debug:print-info 8 *default-log-port* "waitons string is " instr)
			  (string-split (cond
					 ((procedure? instr)
					  (let ((res (instr)))
					    (debug:print-info 8 "waiton procedure results in string " res " for test " hed)
					    (debug:print-info 8 *default-log-port* "waiton procedure results in string " res " for test " hed)
					    res))
					 ((string? instr)     instr)
					 (else 
					  ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print 0 "ERROR: something went wrong in processing waitons for test " hed)
					  ;; NOTE: This is actually the case of *no* waitons! ;; (debug:print-error 0 *default-log-port* "something went wrong in processing waitons for test " hed)
					  ""))))))
	  (if (not config) ;; this is a non-existant test called in a waiton. 
	      (if (null? tal)
		  test-records
		  (loop (car tal)(cdr tal)))
	      (begin
		(debug:print-info 8 "waitons: " waitons)
		(debug:print-info 8 *default-log-port* "waitons: " waitons)
		;; check for hed in waitons => this would be circular, remove it and issue an
		;; error
		(if (member hed waitons)
		    (begin
		      (debug:print 0 "ERROR: test " hed " has listed itself as a waiton, please correct this!")
		      (debug:print-error 0 *default-log-port* "test " hed " has listed itself as a waiton, please correct this!")
		      (set! waitons (filter (lambda (x)(not (equal? x hed))) waitons))))
		
		;; (items   (items:get-items-from-config config)))
		(if (not (hash-table-ref/default test-records hed #f))
		    (hash-table-set! test-records
				     hed (vector hed     ;; 0
						 config  ;; 1
						 waitons ;; 2
						 (config-lookup config "requirements" "priority")     ;; priority 3
						 (let ((items      (hash-table-ref/default config "items" #f)) ;; items 4
						       (itemstable (hash-table-ref/default config "itemstable" #f))) 
						   ;; if either items or items table is a proc return it so test running
						   ;; process can know to call items:get-items-from-config
						   ;; if either is a list and none is a proc go ahead and call get-items
						   ;; otherwise return #f - this is not an iterated test
						   (cond
						    ((procedure? items)      
						     (debug:print-info 4 "items is a procedure, will calc later")
						     (debug:print-info 4 *default-log-port* "items is a procedure, will calc later")
						     items)            ;; calc later
						    ((procedure? itemstable)
						     (debug:print-info 4 "itemstable is a procedure, will calc later")
						     (debug:print-info 4 *default-log-port* "itemstable is a procedure, will calc later")
						     itemstable)       ;; calc later
						    ((filter (lambda (x)
							       (let ((val (car x)))
								 (if (procedure? val) val #f)))
							     (append (if (list? items) items '())
								     (if (list? itemstable) itemstable '())))
						     'have-procedure)
						    ((or (list? items)(list? itemstable)) ;; calc now
						     (debug:print-info 4 "items and itemstable are lists, calc now\n"
						     (debug:print-info 4 *default-log-port* "items and itemstable are lists, calc now\n"
								       "    items: " items " itemstable: " itemstable)
						     (items:get-items-from-config config))
						    (else #f)))                           ;; not iterated
						 #f      ;; itemsdat 5
						 #f      ;; spare - used for item-path
						 )))
		(for-each 
1101
1102
1103
1104
1105
1106
1107
1108

1109
1110
1111
1112
1113
1114
1115



1116
1117

1118
1119
1120
1121
1122
1123
1124
1156
1157
1158
1159
1160
1161
1162

1163
1164
1165
1166
1167



1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1179







-
+




-
-
-
+
+
+

-
+







	 (diskfree (get-df (current-directory)))
	 (remtries 10))
    (handle-exceptions
     exn
     (if (> remtries 0)
	 (begin
	   (print-call-chain (current-error-port))
	   (debug:print-info 0 "WARNING: failed to set meta info. Will try " remtries " more times")
	   (debug:print-info 0 *default-log-port* "WARNING: failed to set meta info. Will try " remtries " more times")
	   (set! remtries (- remtries 1))
	   (thread-sleep! 10)
	   (tests:set-full-meta-info db test-id run-id minutes work-area (- remtries 1)))
	 (let ((err-status ((condition-property-accessor 'sqlite3 'status #f) exn)))
	   (debug:print 0 "ERROR: tried for over a minute to update meta info and failed. Giving up")
	   (debug:print 0 "EXCEPTION: database probably overloaded or unreadable.")
	   (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
	   (debug:print-error 0 *default-log-port* "tried for over a minute to update meta info and failed. Giving up")
	   (debug:print 0 *default-log-port* "EXCEPTION: database probably overloaded or unreadable.")
	   (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn))
	   (print "exn=" (condition->list exn))
	   (debug:print 0 " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
	   (debug:print 0 *default-log-port* " status:  " ((condition-property-accessor 'sqlite3 'status) exn))
	   (print-call-chain (current-error-port))))
     (tests:update-testdat-meta-info db test-id work-area cpuload diskfree minutes)
  )))
	 
;;======================================================================
;; A R C H I V I N G
;;======================================================================

Modified tests/Makefile from [0ec8867fd3] to [cf65e1af4f].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33












-
+












-
+







#
# run some tests

BINPATH   = $(shell readlink -m $(PWD)/../bin)
MEGATEST  = $(BINPATH)/megatest
DASHBOARD = $(BINPATH)/dashboard
PATH     := $(BINPATH):$(PATH)
RUNNAME  := $(shell date +w%V.%u.%H.%M)
IPADDR   := "-"
RUNID    := 1
SERVER    = 
DEBUG     = 1
LOGGING   = 
LOGGING   = -log logs/$(RUNNAME)
ROWS      = 20

OS  = $(shell grep ID /etc/*-release|cut -d= -f2)
FS  = $(shell df -T .|tail -1|awk '{print $$2}')
VER = $(shell fsl info|grep checkout|awk '{print $$2}'|cut -c 1-5)

# The NEWTARGET causes some tests to fail. Do not use until this is fixed.
NEWTARGET  = "$(OS)/$(FS)/$(VER)"
TARGET     = "ubuntu/nfs/none"

all : build unit test1 test2 test3 test4 test5 test6 test7 test8 test9

unit : basicserver.log runs.log misc.log
unit : basicserver.log runs.log misc.log tests.log

rel : 
	cd release;dashboard -rows 25 &

## basicserver.log : unittests/basicserver.scm
## 	script -c "./rununittest.sh basicserver $(DEBUG)" basicserver.log

178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192







-
+







	touch cleanprep

fullprep : cleanprep
	cd fullrun;$(MEGATEST) -remove-runs :runname $(RUNNAME)% -target %/%/% -testpatt %/%
	cd fullrun;$(BINPATH)/dashboard -rows 15 &

dashboard : cleanprep
	cd fullrun && $(BINPATH)/dashboard -rows $(ROWS) &
	cd fullrun && $(BINPATH)/dashboard -skip-version-check -rows $(ROWS) &

newdashboard : cleanprep
	cd fullrun && $(BINPATH)/newdashboard &

mdboard : cleanprep
	cd fullrun && $(BINPATH)/mdboard &

Modified tests/fullrun/configs/mt_include_2.config from [e4edd5bbcd] to [e3be724bae].

1
2

1

2

-
+
[disks]
disk0 #{getenv MT_RUN_AREA_HOME}/tmp/mt_runs
disk0 #{scheme (create-directory "#{getenv MT_RUN_AREA_HOME}/tmp/mt_runs" #t)}

Modified tests/fullrun/megatest.config from [007216e935] to [73b1295a6b].

1
2
3
4
5



6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15





+
+
+







[fields]
sysname TEXT
fsname TEXT
datapath TEXT

[graph]
g1 sqlite3:../../example.db alldat event_time var val stuff

# refareas can be searched to find previous runs
# the path points to where megatest.db exists
[refareas]
area1 /tmp/oldarea/megatest

[include ./configs/mt_include_1.config]

Modified tests/fullrun/multi-dboard.sh from [f73dd06f1d] to [b641343611].

1



























2
3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

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


#!/bin/bash

if [[ ! -e "$HOME/.megatest" ]];then
   mkdir -p "$HOME/.megatest"
fi
# if [[ ! -e "$HOME/.megatest/areas.dat" ]];then
#    echo "Creating some placeholder files in ~/.megatest"
#    cat > "$HOME/.megatest/areas.dat" << EOF
# [default]
# mfstest /mfs/matt/data/megatest/tests/fullrun
# mfsbig /mfs/matt/data/megatest/tests/fdktestqa/testqa
# [local]
# localtest /home/matt/data/megatest/tests/fullrun
# EOF
# fi
if [[ ! -e "$HOME/.megatest/default.dat" ]];then
   cat > "$HOME/.megatest/default.dat" << EOF
[fullrun]
path /mfs/matt/data/megatest/tests/fullrun
order 1
# [bigrun]
# path /mfs/matt/data/megatest/tests/fdktestqa/testqa
# order 2
# [local_fullrun]
# path /home/matt/data/megatest/tests/fullrun
# order 3
EOF
fi

csi -I ../.. multi-dboard-load-all.scm

Modified tests/fullrun/runconfigs.config from [7bda90c9cb] to [6612b4b8e1].

1
2


3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10
11


+
+







[default]
SOMEVAR This should show up in SOMEVAR3
VARNOVAL
VARNOVAL_WITHSPACE 

# target based getting of config file, look at afs.config and nfs.config
[include #{getenv fsname}.config]

[include #{getenv MT_RUN_AREA_HOME}/common_runconfigs.config]

# #{system echo 'VACKYVAR #{shell pwd}' > $MT_RUN_AREA_HOME/configs/$USER.config}

Modified tests/fullrun/tests/all_toplevel/testconfig from [deabaf2573] to [3fb72f4d55].

1
2





3
4
5
6
7
8
1
2
3
4
5
6
7
8
9
10
11
12
13


+
+
+
+
+






[ezsteps]
calcresults megatest -list-runs $MT_RUNNAME -target $MT_TARGET
check_triggers  cat $MT_RUN_AREA_HOME/triggers_$MT_RUN_NAME.dat

[logpro]
check_triggers ;;
  (expect:error in "LogFileBody" = 0 "No errors" #/error/i)

[requirements]
waiton  #{getenv ALL_TOPLEVEL_TESTS}

# This is a "toplevel" test, it does not require waitons to be non-FAIL to run
mode toplevel

Modified tests/fullrun/tests/exit_0/testconfig from [5010ef5eb6] to [63e30e301e].

1
2
3
4
5
6
7
8
9
10
11
12
13
14




15
1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17












-
-
+
+
+
+

[setup]
runscript main.sh

[test_meta]
author matt
owner  bob
description This test checks that a multi-lineitem test with mix of pass and non-fail rolls up a PASS

tags first,single
reviewed 09/10/2011, by Matt

[triggers]
NOT_STARTED/ xterm -e bash -s -- 
RUNNING/ xterm -e bash -s -- 
# NOT_STARTED/ xterm -e bash -s -- 
NOT_STARTED/   echo "trigger: exit_0, NOT_STARTED/" > $MT_RUN_AREA_HOME/triggers_$MT_RUN_NAME.dat
RUNNING/       echo "trigger: exit_0, RUNNING/" >> $MT_RUN_AREA_HOME/triggers_$MT_RUN_NAME.dat


Modified tests/fullrun/tests/ez_fail_quick/testconfig from [84fb49b4c8] to [99e2edd3f4].

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







[requirements]
priority 10

[ezsteps]
# should fail on next step
lookitnada  ls /nada

[triggers]
# run like this: cmd test-id test-rundir trigger
COMPLETED/FAIL xterm;echo
COMPLETED/FAIL   echo "trigger: ez_fail_quick, COMPLETED/FAIL" >> $MT_RUN_AREA_HOME/triggers_$MT_RUN_NAME.dat

[test_meta]
author matt
owner  bob
description This test runs a single ezstep which fails immediately.

tags first,single

Modified tests/fullrun/tests/priority_1/testconfig from [5fb118212f] to [9d6a3629ba].

10
11
12
13
14
15
16
17

10
11
12
13
14
15
16

17







-
+
owner  bob
description This test checks that a multi-lineitem test with mix of pass and non-fail rolls up a PASS

tags first,single
reviewed 09/10/2011, by Matt

[triggers]
COMPLETED/ echo $MT_TEST_NAME > $MT_RUN_AREA_HOME/foo
COMPLETED/   echo "trigger: priority_1, COMPLETED/" >> $MT_RUN_AREA_HOME/triggers_$MT_RUN_NAME.dat

Modified tests/fullrun/tests/test_mt_vars/testconfig from [0d7c3216f9] to [0083ae639f].

20
21
22
23
24
25
26




27
28
29
30
31
32
33














34
35
36
37
38
39
40
20
21
22
23
24
25
26
27
28
29
30
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







+
+
+
+







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








# test-path and test-file
test-path test-path-file.sh

# verify that vars with $ signs get expanded
varwithdollar eval_vars.sh

emptyvars bash -c 'if [[ $VARNOVAL == "" ]];then echo HAVE_VARNOVAL;else echo "ERROR: VARNOVAL not found";fi'
emptyvar_withspace bash -c 'if [[ $VARNOVAL_WITHSPACE == "" ]];then echo HAVE_VARNOVAL_WITHSPACE;else echo "ERROR: VARNOVAL_WITHSPACE not found";fi'
emptyvar_megatest.sh egrep VARNO megatest.sh

[requirements]
waiton runfirst
priority 0

[items]
NUMNUM [system cat $MT_RUN_AREA_HOME/tmp/$USER/$sysname/$fsname/$datapath/$MT_RUNNAME/$PREDICTABLE]

[logpro]
emptyvars ;;
  (expect:error in "LogFileBody" = 0 "VARNOVAL not found" #/ERROR: VARNOVAL not found/)
  (expect:required in "LogFileBody" = 1 "HAVE_VARNOVAL"   #/HAVE_VARNOVAL/)

emptyvar_withspace ;;
  (expect:error in "LogFileBody" = 0 "VARNOVAL_WITHSPACE not found" #/ERROR: VARNOVAL_WITHSPACE not found/)
  (expect:required in "LogFileBody" = 1 "HAVE_VARNOVAL_WITHSPACE"   #/HAVE_VARNOVAL_WITHSPACE/)

emptyvar_megatest.sh ;;
  (expect:error in "LogFileBody" = 0 "No errors expected" #/ERR/i)
  (expect:required in "LogFileBody" = 1 "VARNOVAL_WITHSPACE"  #/VARNOVAL_WITHSPACE/)
  (expect:required in "LogFileBody" = 1 "VARNOVAL"            #/VARNOVAL/)

[test_meta]
author matt
owner  bob
description This test runs a single ezstep which is expected to pass, no logpro file.

tags first,single
reviewed 09/10/2011, by Matt

Modified tests/rununittest.sh from [1c13c943af] to [751af2da02].

11
12
13
14
15
16
17

18
19
20
11
12
13
14
15
16
17
18
19
20
21







+



# Clean setup
#
dbdir=$(cd simplerun;megatest -show-config -section setup -var linktree)/.db
rm -f simplerun/megatest.db simplerun/monitor.db simplerun/db/monitor.db $dbdir/*.db
rm -rf simplelinks/ simpleruns/ simplerun/db/ $dbdir
mkdir -p simplelinks simpleruns
(cd simplerun;cp ../../*_records.scm .;perl -pi.bak -e 's/define-inline/define/' *_records.scm)
(cd simplerun;cp ../../altdb.scm .)

# Run the test $1 is the unit test to run
cd simplerun;echo '(load "../tests.scm")' | ../../bin/megatest -repl -debug $2 $1

Modified tests/unittests/basicserver.scm from [f2f7d0aa9d] to [85fa769c5b].

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19











-
+







;;======================================================================
;; S E R V E R
;;======================================================================

;; Run like this:
;;
;;  ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0)

(delete-file* "logs/1.log")
(define run-id 1)

(test "setup for run" #t (begin (launch:setup-for-run)
(test "setup for run" #t (begin (launch:setup)
 				(string? (getenv "MT_RUN_AREA_HOME"))))

;; NON Server tests go here

(test #f #f (db:dbdat-get-path *db*))
(test #f #f (db:get-run-name-from-id *db* run-id))
;; (test #f '("SYSTEM" "RELEASE") (rmt:get-keys))
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191







-
+







;; 
;; ;; Not sure how the following should work, replacing it with system of megatest -server
;; ;; (test "launch server" #t (let ((pid (process-fork (lambda ()
;; ;; 						    ;; (daemon:ize)
;; ;; 						    (server:launch 'http)))))
;; ;; 			   (set! server-pid pid)
;; ;; 			   (number? pid)))
;; (system "../../bin/megatest -server - -debug 22 > server.log 2> server.log &")
;; (system "../../bin/megatest -server - -debugbcom 22 > server.log 2> server.log &")
;; 
;; (let loop ((n 10))
;;   (thread-sleep! 1) ;; need to wait for server to start.
;;   (let ((res (open-run-close tasks:get-best-server tasks:open-db)))
;;     (print "tasks:get-best-server returned " res)
;;     (if (and (not res)
;; 	     (> n 0))

Modified tests/unittests/misc.scm from [6b0f595ffe] to [dd44f991b6].

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







(use sqlite3)

;;======================================================================
;; P R O C E S S E S
;;======================================================================

(test "cmd-run-with-stderr->list" '("No such file or directory")
      (let ((reslst (cmd-run-with-stderr->list "ls" "/tmp/ihadbetternotexist")))
(test "process:cmd-run-with-stderr->list" '("No such file or directory")
      (let ((reslst (process:cmd-run-with-stderr->list "ls" "/tmp/ihadbetternotexist")))
	(string-search (regexp "No such file or directory")(car reslst))))

;;======================================================================
;; T E S T   M A T C H I N G
;;======================================================================

;; tests:glob-like-match

Modified tests/unittests/tests.scm from [15fd3688ae] to [eb49f922eb].

1
2
3
4
5
6
7
8
9
10
11
12
13





























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
;;======================================================================
;; itemwait, itemmatch

(db:compare-itempaths ref-item-path item-path itemmap)

;; prereqs-not-met

(rmt:get-prereqs-not-met run-id waitons item-path mode: testmode itemmap: itemmap))

	 (fails           (runs:calc-fails prereqs-not-met))
	 (prereq-fails    (runs:calc-prereq-fail prereqs-not-met))
	 (non-completed   (runs:calc-not-completed prereqs-not-met))
	 (runnables       (runs:calc-runnable prereqs-not-met)))
;; ;;======================================================================
;; ;; itemwait, itemmatch
;; 
;; (db:compare-itempaths ref-item-path item-path itemmap)
;; 
;; ;; prereqs-not-met
;; 
;; (rmt:get-prereqs-not-met run-id waitons item-path mode: testmode itemmap: itemmap))
;; 
;; 	 (fails           (runs:calc-fails prereqs-not-met))
;; 	 (prereq-fails    (runs:calc-prereq-fail prereqs-not-met))
;; 	 (non-completed   (runs:calc-not-completed prereqs-not-met))
;; 	 (runnables       (runs:calc-runnable prereqs-not-met)))
;; 
;; 
;; 

(define user    (current-user-name))
(define runname "mytestrun")
(define keys    (rmt:get-keys))
(define runinfo #f)
(define keyvals '(("SYSTEM" "abc")("RELEASE" "def")))
(define header  (list "SYSTEM" "RELEASE" "id" "runname" "state" "status" "owner" "event_time"))
(define run-id  1)

;; Create a run
(test #f 1 (rmt:register-run keyvals runname "new" "n/a" user))
(test #f #t (rmt:general-call 'register-test run-id run-id "test-one"   ""))
(test #f #t (rmt:general-call 'register-test run-id run-id "test-two"   ""))
(test #f #t (rmt:general-call 'register-test run-id run-id "test-three" ""))
(test #f #t (rmt:general-call 'register-test run-id run-id "test-four"  ""))

(rmt:test-set-state-status-by-id run-id (rmt:get-test-id run-id "test-one"   "") "COMPLETED" "FAIL" "")
(rmt:test-set-state-status-by-id run-id (rmt:get-test-id run-id "test-two"   "") "COMPLETED" "PASS" "")
(rmt:test-set-state-status-by-id run-id (rmt:get-test-id run-id "test-three" "") "RUNNING"   "n/a"  "")
(rmt:test-set-state-status-by-id run-id (rmt:get-test-id run-id "test-four"  "") "COMPLETED" "WARN" "")

(print "MODE=not in")
(test #f '()
      (filter
       (lambda (y)
	 (equal? y "FAIL")) ;; any FAIL in the output list?
       (map 
	(lambda (x)(vector-ref x 4))
	(rmt:get-tests-for-run run-id "%/%" '() '("FAIL") #f #f #t 'event_time "DESC" 'shortlist 0 'dashboard))))

(print "MODE=in")
(test #f '("FAIL")
      (map 
       (lambda (x)(vector-ref x 4))
       (rmt:get-tests-for-run run-id "%/%" '() '("FAIL") #f #f #f 'event_time "DESC" 'shortlist 0 'dashboard)))
(set! *verbosity* 1)

(print "MODE=in, state in RUNNING")
;; (set! *verbosity* 8)
(test #f '("RUNNING")
      (map 
       (lambda (x)(vector-ref x 3))
       (rmt:get-tests-for-run run-id "%/%" '("RUNNING") '() #f #f #f 'event_time "DESC" 'shortlist 0 'dashboard)))
(set! *verbosity* 1)

(print "MODE=in, state in RUNNING and status IN WARN")
;; (set! *verbosity* 8)
(test #f '(("RUNNING" . "n/a") ("COMPLETED" . "WARN"))
      (map 
       (lambda (x)
	 (cons (vector-ref x 3)(vector-ref x 4)))
       (rmt:get-tests-for-run run-id "%/%" '("RUNNING") '("WARN") #f #f #f 'event_time "DESC" 'shortlist 0 'dashboard)))
(set! *verbosity* 1)

(print "MODE=not in, state in RUNNING and status IN WARN")
(set! *verbosity* 8)
(test #f '(("DELETED" . "n/a") ("COMPLETED" . "PASS") ("COMPLETED" . "FAIL"))
      (map 
       (lambda (x)
	 (cons (vector-ref x 3)(vector-ref x 4)))
       (rmt:get-tests-for-run run-id "%/%" '("RUNNING") '("WARN") #f #f #t 'event_time "DESC" 'shortlist 0 'dashboard)))
(set! *verbosity* 1)

(exit)

Modified tree.scm from [1c5a9172b0] to [5c27bcda2b].

133
134
135
136
137
138
139
140

141
142
143
144
133
134
135
136
137
138
139

140
141
142
143
144







-
+




                   #:selection-cb
                   (lambda (obj id state)
                     ;; (print "obj: " obj ", id: " id ", state: " state)
                     (let* ((run-path (tree:node->path obj id))
                            (run-id   (tree-path->run-id (cdr run-path))))
                       (if run-id
                           (begin
                             (dboard:data-set-curr-run-id! *data* run-id)
                             (dboard:data-curr-run-id-set! *data* run-id)
                             (dashboard:update-run-summary-tab)))
                       ;; (print "path: " (tree:node->path obj id) " run-id: " run-id)
                       ))))
|#

Added utils/Makefile.git.installall version [d3a2bd23c6].















































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

# Copyright 2013-2015 Matthew Welland.
# 
#  This program is made available under the GNU GPL version 2.0 or
#  greater. See the accompanying file COPYING for details.
# 
#  This program is distributed WITHOUT ANY WARRANTY; without even the
#  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.

help :
	@echo You may need to do the following setup first:
	@echo
	@echo sudo apt-get install libreadline-dev
	@echo sudo apt-get install libwebkitgtk-dev libfreetype6-dev libx11-dev libxpm-dev libxmu-dev \
	           libxft-dev libgtk2.0-dev libgl1-mesa-dev libglu1-mesa-dev libpangox-1.0-dev bison \
                   libwebkitgtk-3.0-dev
	@echo   -- nb// adding monodevelop gets more packages of which some might be needed...
	@echo sudo apt-get install libmotif3
	@echo
	@echo Set up your PATH, setting it in the Makefile does not work as expected
	@echo export PATH=$(PREFIX)/bin:\$$PATH
	@echo
	@echo For IUP set IUPBRANCH, currently $(IUPBRANCH)
	@echo         set IUPCONFIG, currently $(IUPCONFIG) - look in https://www.kiatoa.com/fossils/iuplib for .inc files
	@echo You are using PREFIX=$(PREFIX)
	@echo You are using PRODCHICKEN=$(PRODCHICKEN)
	@echo You are using PROXY="$(PROXY)"
	@echo If needed set PROXY to host.dom:port
	@echo   http_proxy=$(http_proxy)
	@echo 
	@echo To make all do: make all
	@echo   make minimal: make nogui
	@echo 
	@echo Note: If compiling on amd64 do CSC_OPTIONS=\'-C "-fPIC"\' make all IUPCONFIG=

FPIC=-C "-fPIC"

# Put the installation here
ifeq ($(PREFIX),)
PREFIX=$(PWD)/target
endif
ifeq ($(PRODCHICKEN),)
PRODCHICKEN=$(PREFIX)/prod-chicken/
endif
# Set this on the command line of your make call if needed: make PROXY=host.com:1234
PROXY=

# http://code.call-cc.org/dev-snapshots/2015/06/07/chicken-4.10.0rc1.tar.gz
# http://code.call-cc.org/releases/4.10.0/chicken-4.10.0.tar.gz
# Select version of chicken, sqlite3 etc
CHICKEN_VERSION=4.10.1
SQLITE3_VERSION=3090200
# http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
# http://www.sqlite.org/2015/sqlite-autoconf-3081101.tar.gz
# Override IUPBRANCH to use other than trunk
IUPBRANCH=trunk
IUPCONFIG=ubuntu-15.04.inc
# iup-3.15

# Eggs to install (straightforward ones)
EGGS=matchable readline apropos base64 regex-literals format regex-case test coops trace csv \
     dot-locking posix-utils posix-extras directory-utils hostinfo tcp-server rpc csv-xml fmt \
     json md5 awful http-client spiffy uri-common intarweb spiffy-request-vars \
     spiffy-directory-listing ssax sxml-serializer sxml-modifications sql-de-lite \
     srfi-19 refdb ini-file sparse-vectors z3 call-with-environment-variables hahn linenoise \
     crypt parley

#
# Derived variables
#

ifeq ($(PROXY),)
PROX:=
else
http_proxy:=http://$(PROXY)
PROX:=-proxy $(PROXY)
endif

BUILDHOME=$(PWD)
PATH:=$(PREFIX)/bin:$(PATH)
LIBPATH=$(PREFIX)/lib$(ADDITIONAL_LIBPATH)
LD_LIBRARY_PATH=$(LIBPATH)
CHICKEN_INSTALL=$(PREFIX)/bin/chicken-install
CHICKEN_EGG_DIR=$(PREFIX)/lib/chicken/7

VPATH=$(CHICKEN_EGG_DIR):$(PWD)/eggflags

vpath %.so $(CHICKEN_EGG_DIR)
vpath %.flag eggflags

EGGSOFILES=$(addprefix $(CHICKEN_EGG_DIR)/,$(addsuffix .so,$(EGGS)))
EGGFLAGS=$(addprefix eggflags/,$(addsuffix .flag,$(EGGS)))

# Stuff needed for IUP
ISARCHX86_64=$(shell uname -a | grep x86_64)
ifeq ($(ISARCHX86_64),)
ARCHSIZE=
else
ARCHSIZE=64_
endif

CSCLIBS=$(shell echo $(LD_LIBRARY_PATH) | sed 's/:/ -L/g')
CSC_OPTIONS="-I$(PREFIX)/include -L$(CSCLIBS) -C \"-fPIC\""
# CSC_OPTIONS=-I $(PREFIX)/include -L $(CSCLIBS)

nogui : base mutils

#all : nogui libiup $(PREFIX)/lib/sqlite3.so
all : nogui libiup

base : chkn eggs 

# stuff needed for Kiatoa and Megatest from matts miscellaneous stash
#   NOTE TO SELF: eggifying these would be great...
mutils : base logprobin $(PREFIX)/bin/hs \
        $(PREFIX)/lib/chicken/7/mutils.so \
        $(PREFIX)/lib/chicken/7/dbi.so \
        $(PREFIX)/lib/chicken/7/stml.so \
        $(PREFIX)/lib/chicken/7/margs.so

chkn : $(CHICKEN_INSTALL)

eggs : $(EGGSOFILES)

# libiup : $(PREFIX)/lib/libavcall.a 
libiup : $(CHICKEN_EGG_DIR)/iup.so $(CHICKEN_EGG_DIR)/canvas-draw.so

logprobin : $(PREFIX)/bin/logpro

$(PREFIX)/bin/logpro : $(CHICKEN_EGG_DIR)/regex-literals.so
	$(CHICKEN_INSTALL) logpro

# Silly rule to make installing eggs more makeish, I don't understand why I need the basename
$(CHICKEN_EGG_DIR)/%.so : eggflags/%.flag
	$(CHICKEN_INSTALL) $(PROX) -keep-installed $(shell basename $*)

$(EGGFLAGS) : # $(CHICKEN_INSTALL)
	mkdir -p eggflags
	touch $(EGGFLAGS)

# some setup stuff
#
$(PREFIX)/setup-chicken4x.sh : $(EGGFLAGS)
	mkdir -p $(PREFIX)
	(echo 'export PATH=$(PREFIX)/bin:$$PATH' > $(PREFIX)/setup-chicken4x.sh)
	(echo "export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" >> $(PREFIX)/setup-chicken4x.sh)

$(PREFIX)/setup-chicken4x.csh : $(EGGFLAGS)
	mkdir -p $(PREFIX)
	(echo "setenv PATH $(PREFIX):'$$'PATH" > $(PREFIX)/setup-chicken4x.csh)
	(echo "setenv LD_LIBRARY_PATH $(LD_LIBRARY_PATH)" >> $(PREFIX)/setup-chicken4x.csh)

chicken-core/chicken.scm : chicken-$(CHICKEN_VERSION).tar.gz
	#tar xf chicken-$(CHICKEN_VERSION).tar.gz
	#ln -sf chicken-$(CHICKEN_VERSION) chicken-core
	echo "Hello from chicken"

chicken-4.9.0rc1.tar.gz : 
	wget http://code.call-cc.org/dev-snapshots/2014/04/17/chicken-4.9.0rc1.tar.gz

chicken-4.9.0.1.tar.gz :
	wget http://code.call-cc.org/releases/4.9.0/chicken-4.9.0.1.tar.gz

chicken-4.10.0rc1.tar.gz :
	wget http://code.call-cc.org/dev-snapshots/2015/06/07/chicken-4.10.0rc1.tar.gz

chicken-4.10.0.tar.gz :
	wget http://code.call-cc.org/releases/4.10.0/chicken-4.10.0.tar.gz

chicken-4.10.1.tar.gz :
	fossil clone https://www.kiatoa.com/fossils/chicken-core chicken-scheme.fossil
	mkdir -p chicken-core
	cd chicken-core; pwd
	cd chicken-core; fossil open ../chicken-scheme.fossil
	cd chicken-core; fossil up 337f5be
#	wget http://code.call-cc.org/dev-snapshots/2015/08/29/chicken-4.10.1.tar.gz

# git clone git://code.call-cc.org/chicken-core
# git clone http://code.call-cc.org/git/chicken-core.git

$(PRODCHICKEN)/bin/chicken :
	wget http://code.call-cc.org/dev-snapshots/2015/08/29/chicken-4.10.1.tar.gz
	tar -xzvf chicken-4.10.1.tar.gz
	cd chicken-4.10.1/; make PLATFORM=linux PREFIX=$(PRODCHICKEN)
	cd chicken-4.10.1/; make PLATFORM=linux PREFIX=$(PRODCHICKEN) install
	rm -rfv chicken-4.10.1/ 

$(CHICKEN_INSTALL) : chicken-core/chicken.scm $(PREFIX)/setup-chicken4x.sh $(PREFIX)/setup-chicken4x.csh $(PRODCHICKEN)/bin/chicken
	cd chicken-core; LD_LIBRARY_PATH=$(PRODCHICKEN) make PLATFORM=linux CHICKEN=$(PRODCHICKEN)/bin/chicken  PREFIX=$(PREFIX)
	cd chicken-core; LD_LIBRARY_PATH=$(PRODCHICKEN) make PLATFORM=linux CHICKEN=$(PRODCHICKEN)/bin/chicken  PREFIX=$(PREFIX) install

#======================================================================
# S Q L I T E 3
#======================================================================
# https://www.sqlite.org/2015/sqlite-autoconf-3090200.tar.gz
sqlite-autoconf-$(SQLITE3_VERSION).tar.gz :
	wget  http://www.sqlite.org/2015/sqlite-autoconf-$(SQLITE3_VERSION).tar.gz

sqlite-autoconf-$(SQLITE3_VERSION)/config.log : sqlite-autoconf-$(SQLITE3_VERSION).tar.gz
	tar xf  sqlite-autoconf-$(SQLITE3_VERSION).tar.gz

$(PREFIX)/bin/sqlite3 : sqlite-autoconf-$(SQLITE3_VERSION)/config.log
	cd sqlite-autoconf-$(SQLITE3_VERSION);./configure --prefix=$(PREFIX);make;make install

$(CHICKEN_EGG_DIR)/sqlite3.so : $(PREFIX)/bin/sqlite3
	CSC_OPTIONS="-I$(PREFIX)/include -L$(PREFIX)/lib" $(CHICKEN_INSTALL) $(PROX) sqlite3

#======================================================================
# N  A N O M S G
#======================================================================

# https://github.com/nanomsg/nanomsg/releases/download/0.6-beta/nanomsg-0.6-beta.tar.gz
# https://github.com/nanomsg/nanomsg/releases/download/0.8-beta/nanomsg-0.8-beta.tar.gz

nanomsg-0.6-beta.tar.gz :
	wget http://download.nanomsg.org/nanomsg-0.6-beta.tar.gz

nanomsg-0.6-beta/COPYING : nanomsg-0.6-beta.tar.gz
	tar xf nanomsg-0.6-beta.tar.gz

$(PREFIX)/bin/nanocat : nanomsg-0.6-beta/COPYING
	cd nanomsg-0.6-beta;./configure --prefix=$(PREFIX);make;make install

$(PREFIX)/lib/nanomsg.so : $(PREFIX)/bin/nanocat
	CSC_OPTIONS="-I$(PREFIX)/include -L$(PREFIX)/lib" $(CHICKEN_INSTALL) $(PROX) nanomsg

# LD_LIBRARY_PATH=/mfs/pkgs/chicken/4.10.0-amd64/lib CSC_OPTIONS="-I/mfs/pkgs/chicken/4.10.0-amd64/include -L/mfs/pkgs/chicken/4.10.0-amd64/lib -C \"-fPIC\"" /mfs/pkgs/chicken/4.10.0-amd64/bin/chicken-install  -D no-library-checks nanomsg

#======================================================================
# M A T T S   U T I L S
#======================================================================

# opensrc

opensrc.fossil :
	fossil clone http://www.kiatoa.com/fossils/opensrc opensrc.fossil

opensrc/histstore/histstore.scm : opensrc.fossil
	mkdir -p opensrc
	cd opensrc;if [ -e .fslckout ];then fossil update; else fossil open ../opensrc.fossil; fi

$(PREFIX)/lib/chicken/7/mutils.so : opensrc/histstore/histstore.scm
	cd opensrc/mutils;chicken-install

$(PREFIX)/lib/chicken/7/dbi.so : opensrc/dbi/dbi.scm
	cd opensrc/dbi; sed -i -e 's/.*postgres.*/;;commented out/g' dbi.scm; chicken-install

$(PREFIX)/lib/chicken/7/margs.so : opensrc/margs/margs.scm
	cd opensrc/margs;chicken-install

opensrc/histstore/hs : opensrc/histstore/histstore.scm chkn eggs $(CHICKEN_EGG_DIR)/sqlite3.so 
	cd opensrc/histstore;$(PREFIX)/bin/csc histstore.scm -o hs

$(PREFIX)/bin/hs : opensrc/histstore/hs 
	cp -f opensrc/histstore/hs $(PREFIX)/bin/hs

# stml
stml.fossil :
	fossil clone http://www.kiatoa.com/fossils/stml stml.fossil

# open touches the .fossil :(
stml/requirements.scm.template : stml.fossil
	mkdir -p stml
	cd stml;if [ -e .fslckout ];then fossil update; else fossil open ../stml.fossil;fi

stml/requirements.scm : stml/requirements.scm.template
	cp stml/install.cfg.template      stml/install.cfg
	cp stml/requirements.scm.template stml/requirements.scm

$(PREFIX)/lib/chicken/7/stml.so : stml/requirements.scm
	cd stml; sed -i -e "s#.*TARGDIR.*#TARGDIR=$(PREFIX)/bin#g" install.cfg 
	cd stml;CSC_OPTIONS='-C "-fPIC"' make

#======================================================================
# F F C A L L (Used by IUP)
#======================================================================

ffcall.fossil :
	fossil clone http://www.kiatoa.com/fossils/ffcall ffcall.fossil

ffcall/README : ffcall.fossil
	mkdir -p ffcall
	cd ffcall && if [ -e README ];then fossil update; else fossil open ../ffcall.fossil; fi

# NOTE: This worked fine *without* the enable-shared
#
$(PREFIX)/lib/libavcall.a : ffcall/README
	cd ffcall;./configure --prefix=$(PREFIX) --enable-shared && make CC="gcc -fPIC" && make install

#======================================================================
# I U P 
#======================================================================

iuplib.fossil :
	#fossil clone http://www.kiatoa.com/fossils/iuplib iuplib.fossil
	touch iuplib.fossil
iup/installall.sh : iuplib.fossil $(PREFIX)/lib/libiup.so
	mkdir -p iup
	pwd
	wget -c --no-check-certificate http://sourceforge.net/projects/canvasdraw/files/5.9/Linux%20Libraries/cd-5.9_Linux26g4_64_lib.tar.gz/download
	wget -c --no-check-certificate http://sourceforge.net/projects/iup/files/3.17/Linux%20Libraries/iup-3.17_Linux26g4_64_lib.tar.gz/download
	wget -c --no-check-certificate http://sourceforge.net/projects/imtoolkit/files/3.10/Linux%20Libraries/im-3.10_Linux26g4_64_lib.tar.gz/download
	#wget -c http://sourceforge.net/projects/luabinaries/files/5.3.2/Linux%20Libraries/lua-5.3.2_Linux26g4_64_lib.tar.gz/download
	tar -xzvf cd-5.9_Linux26g4_64_lib.tar.gz -C iup/
	tar -xzvf im-3.10_Linux26g4_64_lib.tar.gz -C iup/
	tar -xzvf iup-3.17_Linux26g4_64_lib.tar.gz -C iup/
	mkdir -p $(PREFIX)/include/ $(PREFIX)/lib/
	cp iup/include/* $(PREFIX)/include/
	cp iup/*.so $(PREFIX)/lib/
	cp iup/*.a $(PREFIX)/lib/

#	cd iup && if [ -e makeall.sh ];then fossil update $(IUPBRANCH); else fossil open ../iuplib.fossil;fossil update $(IUPBRANCH); fi

#iup/alldone : iup/makeall.sh $(PREFIX)/include/iup.h $(PREFIX)/lib/libiup.so
#	cd iup && ./makeall.sh $(IUPCONFIG)

$(PREFIX)/lib/libiup.so $(PREFIX)/include/iup.h : iup/installall.sh
#	cd iup && ./makeall.sh $(IUPCONFIG)

# $(PREFIX)/lib/libiup.so : iup/iup/alldone
#	touch -c $(PREFIX)/lib/libiup.so

$(CHICKEN_EGG_DIR)/iup.so : $(PREFIX)/lib/libiup.so  $(PREFIX)/lib/libavcall.a 
	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks -feature disable-iup-web iup

# -feature disable-iup-web

$(CHICKEN_EGG_DIR)/canvas-draw.so :  $(PREFIX)/lib/libiup.so  $(PREFIX)/lib/libavcall.a 
	CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks canvas-draw


clean :
	rm -rf chicken-4.8.0 eggflags ffcall sqlite-autoconf-$(SQLITE3_VERSION)

Modified utils/Makefile.installall from [57f74dddf7] to [981091d91c].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22



23

24
25
26
27
28
29
30
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
1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
124
125










-
-










+
+
+

+








-
+














-
+
+




-
+
+
+




-
+


-
+

















-
+



















-
+



-
+
+






-
-
-
-
+
+
+
+








# Copyright 2013-2015 Matthew Welland.
# 
#  This program is made available under the GNU GPL version 2.0 or
#  greater. See the accompanying file COPYING for details.
# 
#  This program is distributed WITHOUT ANY WARRANTY; without even the
#  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.

# make PREFIX=/mfs/pkgs/chicken/chicken-core all

help :
	@echo You may need to do the following setup first:
	@echo
	@echo sudo apt-get install libreadline-dev
	@echo sudo apt-get install libwebkitgtk-dev libfreetype6-dev libx11-dev libxpm-dev libxmu-dev \
	           libxft-dev libgtk2.0-dev libgl1-mesa-dev libglu1-mesa-dev libpangox-1.0-dev bison \
                   libwebkitgtk-3.0-dev
	@echo   -- nb// adding monodevelop gets more packages of which some might be needed...
	@echo sudo apt-get install libmotif3
	@echo
	@echo Set up your PATH, setting it in the Makefile does not work as expected
	@echo export PATH=$(PREFIX)/bin:\$$PATH
	@echo
	@echo For IUP set IUPBRANCH, currently $(IUPBRANCH)
	@echo         set IUPCONFIG, currently $(IUPCONFIG) - look in https://www.kiatoa.com/fossils/iuplib for .inc files
	@echo You are using PREFIX=$(PREFIX)
	@echo You are using PROXY="$(PROXY)"
	@echo If needed set PROXY to host.dom:port
	@echo   http_proxy=$(http_proxy)
	@echo 
	@echo To make all do: make all
	@echo   make minimal: make nogui
	@echo 
	@echo Note: might need to do CSC_OPTIONS='-C "-fPIC"' make
	@echo Note: If compiling on amd64 do CSC_OPTIONS=\'-C "-fPIC"\' make all IUPCONFIG=

FPIC=-C "-fPIC"

# Put the installation here
ifeq ($(PREFIX),)
PREFIX=$(PWD)/target
endif

# Set this on the command line of your make call if needed: make PROXY=host.com:1234
PROXY=

# http://code.call-cc.org/dev-snapshots/2015/06/07/chicken-4.10.0rc1.tar.gz
# http://code.call-cc.org/releases/4.10.0/chicken-4.10.0.tar.gz
# Select version of chicken, sqlite3 etc
CHICKEN_VERSION=4.10.0
# CHICKEN_VERSION=4.10.0
CHICKEN_VERSION=4.11.0rc2
SQLITE3_VERSION=3090200
# http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
# http://www.sqlite.org/2015/sqlite-autoconf-3081101.tar.gz
# Override IUPBRANCH to use other than trunk
IUPBRANCH=iup-3.15
IUPBRANCH=trunk
IUPCONFIG=ubuntu-15.04.inc
# iup-3.15

# Eggs to install (straightforward ones)
EGGS=matchable readline apropos base64 regex-literals format regex-case test coops trace csv \
     dot-locking posix-utils posix-extras directory-utils hostinfo tcp-server rpc csv-xml fmt \
     json md5 awful http-client spiffy uri-common intarweb spiffy-request-vars \
     json md5 awful http-client spiffy uri-common intarweb spiffy-request-vars pathname-expand \
     spiffy-directory-listing ssax sxml-serializer sxml-modifications sql-de-lite \
     srfi-19 refdb ini-file sparse-vectors z3 call-with-environment-variables hahn linenoise \
     crypt
     crypt parley

#
# Derived variables
#

ifeq ($(PROXY),)
PROX:=
else
http_proxy:=http://$(PROXY)
PROX:=-proxy $(PROXY)
endif

BUILDHOME=$(PWD)
PATH:=$(PREFIX)/bin:$(PATH)
LIBPATH=$(PREFIX)/lib$(ADDITIONAL_LIBPATH)
LD_LIBRARY_PATH=$(LIBPATH)
CHICKEN_INSTALL=$(PREFIX)/bin/chicken-install
CHICKEN_EGG_DIR=$(PREFIX)/lib/chicken/6
CHICKEN_EGG_DIR=$(PREFIX)/lib/chicken/8

VPATH=$(CHICKEN_EGG_DIR):$(PWD)/eggflags

vpath %.so $(CHICKEN_EGG_DIR)
vpath %.flag eggflags

EGGSOFILES=$(addprefix $(CHICKEN_EGG_DIR)/,$(addsuffix .so,$(EGGS)))
EGGFLAGS=$(addprefix eggflags/,$(addsuffix .flag,$(EGGS)))

# Stuff needed for IUP
ISARCHX86_64=$(shell uname -a | grep x86_64)
ifeq ($(ISARCHX86_64),)
ARCHSIZE=
else
ARCHSIZE=64_
endif

CSCLIBS=$(shell echo $(LD_LIBRARY_PATH) | sed 's/:/ -L/g')
CSC_OPTIONS="-I$(PREFIX)/include -L$(CSCLIBS) -C \"-fPIC\""
# CSC_OPTIONS=-I$(PREFIX)/include -L$(CSCLIBS)
# CSC_OPTIONS=-I $(PREFIX)/include -L $(CSCLIBS)

nogui : base mutils

all : nogui libiup $(PREFIX)/lib/sqlite3.so
#all : nogui libiup $(PREFIX)/lib/sqlite3.so
all : nogui libiup

base : chkn eggs 

# stuff needed for Kiatoa and Megatest from matts miscellaneous stash
#   NOTE TO SELF: eggifying these would be great...
mutils : base logprobin $(PREFIX)/bin/hs \
        $(PREFIX)/lib/chicken/7/mutils.so \
        $(PREFIX)/lib/chicken/7/dbi.so \
        $(PREFIX)/lib/chicken/7/stml.so \
        $(PREFIX)/lib/chicken/7/margs.so
        $(PREFIX)/lib/chicken/8/mutils.so \
        $(PREFIX)/lib/chicken/8/dbi.so \
        $(PREFIX)/lib/chicken/8/stml.so \
        $(PREFIX)/lib/chicken/8/margs.so

chkn : $(CHICKEN_INSTALL)

eggs : $(EGGSOFILES)

# libiup : $(PREFIX)/lib/libavcall.a 
libiup : $(CHICKEN_EGG_DIR)/iup.so $(CHICKEN_EGG_DIR)/canvas-draw.so
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
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







+



-
+













+
+
+




















-
+







+
+







	(echo "export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" >> $(PREFIX)/setup-chicken4x.sh)

$(PREFIX)/setup-chicken4x.csh : $(EGGFLAGS)
	mkdir -p $(PREFIX)
	(echo "setenv PATH $(PREFIX):'$$'PATH" > $(PREFIX)/setup-chicken4x.csh)
	(echo "setenv LD_LIBRARY_PATH $(LD_LIBRARY_PATH)" >> $(PREFIX)/setup-chicken4x.csh)

# NOTE: the touch chicken-core/chicken.scm compensates for the time stamp from the tar file
chicken-core/chicken.scm : chicken-$(CHICKEN_VERSION).tar.gz
	tar xf chicken-$(CHICKEN_VERSION).tar.gz
	ln -sf chicken-$(CHICKEN_VERSION) chicken-core

	if [[ -e chicken-core/chicken.scm ]];then touch chicken-core/chicken.scm;fi

chicken-4.9.0rc1.tar.gz : 
	wget http://code.call-cc.org/dev-snapshots/2014/04/17/chicken-4.9.0rc1.tar.gz

chicken-4.9.0.1.tar.gz :
	wget http://code.call-cc.org/releases/4.9.0/chicken-4.9.0.1.tar.gz

chicken-4.10.0rc1.tar.gz :
	wget http://code.call-cc.org/dev-snapshots/2015/06/07/chicken-4.10.0rc1.tar.gz

chicken-4.10.0.tar.gz :
	wget http://code.call-cc.org/releases/4.10.0/chicken-4.10.0.tar.gz

chicken-4.11.0rc2.tar.gz : 
	wget http://code.call-cc.org/dev-snapshots/2016/04/28/chicken-4.11.0rc2.tar.gz

# git clone git://code.call-cc.org/chicken-core
# git clone http://code.call-cc.org/git/chicken-core.git

$(CHICKEN_INSTALL) : chicken-core/chicken.scm $(PREFIX)/setup-chicken4x.sh $(PREFIX)/setup-chicken4x.csh
	cd chicken-core;make PLATFORM=linux PREFIX=$(PREFIX)
	cd chicken-core;make PLATFORM=linux PREFIX=$(PREFIX) install

#======================================================================
# S Q L I T E 3
#======================================================================
# https://www.sqlite.org/2015/sqlite-autoconf-3090200.tar.gz
sqlite-autoconf-$(SQLITE3_VERSION).tar.gz :
	wget  http://www.sqlite.org/2015/sqlite-autoconf-$(SQLITE3_VERSION).tar.gz

sqlite-autoconf-$(SQLITE3_VERSION)/config.log : sqlite-autoconf-$(SQLITE3_VERSION).tar.gz
	tar xf  sqlite-autoconf-$(SQLITE3_VERSION).tar.gz

$(PREFIX)/bin/sqlite3 : sqlite-autoconf-$(SQLITE3_VERSION)/config.log
	cd sqlite-autoconf-$(SQLITE3_VERSION);./configure --prefix=$(PREFIX);make;make install

$(PREFIX)/lib/sqlite3.so : $(PREFIX)/bin/sqlite3
$(CHICKEN_EGG_DIR)/sqlite3.so : $(PREFIX)/bin/sqlite3
	CSC_OPTIONS="-I$(PREFIX)/include -L$(PREFIX)/lib" $(CHICKEN_INSTALL) $(PROX) sqlite3

#======================================================================
# N  A N O M S G
#======================================================================

# https://github.com/nanomsg/nanomsg/releases/download/0.6-beta/nanomsg-0.6-beta.tar.gz
# https://github.com/nanomsg/nanomsg/releases/download/0.8-beta/nanomsg-0.8-beta.tar.gz

nanomsg-0.6-beta.tar.gz :
	wget http://download.nanomsg.org/nanomsg-0.6-beta.tar.gz

nanomsg-0.6-beta/COPYING : nanomsg-0.6-beta.tar.gz
	tar xf nanomsg-0.6-beta.tar.gz

$(PREFIX)/bin/nanocat : nanomsg-0.6-beta/COPYING
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
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
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316


317
318
319
320

321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336







-
+


-
+


-
+


-
+


















-
+



-
+














+
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+

+
+
+
+
+
+
+
+
+
-
+

-
-
+
+


-
+





-
+









opensrc.fossil :
	fossil clone http://www.kiatoa.com/fossils/opensrc opensrc.fossil

opensrc/histstore/histstore.scm : opensrc.fossil
	mkdir -p opensrc
	cd opensrc;if [ -e .fslckout ];then fossil update; else fossil open ../opensrc.fossil; fi

$(PREFIX)/lib/chicken/7/mutils.so : opensrc/histstore/histstore.scm
$(PREFIX)/lib/chicken/8/mutils.so : opensrc/histstore/histstore.scm
	cd opensrc/mutils;chicken-install

$(PREFIX)/lib/chicken/7/dbi.so : opensrc/dbi/dbi.scm
$(PREFIX)/lib/chicken/8/dbi.so : opensrc/dbi/dbi.scm
	cd opensrc/dbi;chicken-install

$(PREFIX)/lib/chicken/7/margs.so : opensrc/margs/margs.scm
$(PREFIX)/lib/chicken/8/margs.so : opensrc/margs/margs.scm
	cd opensrc/margs;chicken-install

opensrc/histstore/hs : opensrc/histstore/histstore.scm chkn eggs $(PREFIX)/lib/sqlite3.so 
opensrc/histstore/hs : opensrc/histstore/histstore.scm chkn eggs $(CHICKEN_EGG_DIR)/sqlite3.so 
	cd opensrc/histstore;$(PREFIX)/bin/csc histstore.scm -o hs

$(PREFIX)/bin/hs : opensrc/histstore/hs 
	cp -f opensrc/histstore/hs $(PREFIX)/bin/hs

# stml
stml.fossil :
	fossil clone http://www.kiatoa.com/fossils/stml stml.fossil

# open touches the .fossil :(
stml/requirements.scm.template : stml.fossil
	mkdir -p stml
	cd stml;if [ -e .fslckout ];then fossil update; else fossil open ../stml.fossil;fi

stml/requirements.scm : stml/requirements.scm.template
	cp stml/install.cfg.template      stml/install.cfg
	cp stml/requirements.scm.template stml/requirements.scm

$(PREFIX)/lib/chicken/7/stml.so : stml/requirements.scm
$(PREFIX)/lib/chicken/8/stml.so : stml/requirements.scm
	cd stml;make

#======================================================================
# I U P 
# F F C A L L (Used by IUP)
#======================================================================

ffcall.fossil :
	fossil clone http://www.kiatoa.com/fossils/ffcall ffcall.fossil

ffcall/README : ffcall.fossil
	mkdir -p ffcall
	cd ffcall && if [ -e README ];then fossil update; else fossil open ../ffcall.fossil; fi

# NOTE: This worked fine *without* the enable-shared
#
$(PREFIX)/lib/libavcall.a : ffcall/README
	cd ffcall;./configure --prefix=$(PREFIX) --enable-shared && make CC="gcc -fPIC" && make install

#======================================================================
# I U P 
#======================================================================

iuplib.fossil :
	fossil clone http://www.kiatoa.com/fossils/iuplib iuplib.fossil

cd-5.9_Linux26g4_64_lib.tar.gz :
	wget -c http://sourceforge.net/projects/canvasdraw/files/5.9/Linux%20Libraries/cd-5.9_Linux26g4_64_lib.tar.gz/download
	mv download cd-5.9_Linux26g4_64_lib.tar.gz

iup-3.17_Linux26g4_64_lib.tar.gz :
	wget -c http://sourceforge.net/projects/iup/files/3.17/Linux%20Libraries/iup-3.17_Linux26g4_64_lib.tar.gz/download
	mv download iup-3.17_Linux26g4_64_lib.tar.gz

im-3.10_Linux26g4_64_lib.tar.gz :
	wget -c http://sourceforge.net/projects/imtoolkit/files/3.10/Linux%20Libraries/im-3.10_Linux26g4_64_lib.tar.gz/download
	mv download im-3.10_Linux26g4_64_lib.tar.gz

lua-5.3.2_Linux26g4_64_lib.tar.gz :
	wget -c http://sourceforge.net/projects/luabinaries/files/5.3.2/Linux%20Libraries/lua-5.3.2_Linux26g4_64_lib.tar.gz/download
	mv download lua-5.3.2_Linux26g4_64_lib.tar.gz

iup/installall.sh : iuplib.fossil
iup/installall.sh : $(PREFIX)/lib/libiup.so \
                       cd-5.9_Linux26g4_64_lib.tar.gz \
                       iup-3.17_Linux26g4_64_lib.tar.gz \
                       im-3.10_Linux26g4_64_lib.tar.gz \
		       lua-5.3.2_Linux26g4_64_lib.tar.gz	# iuplib.fossil
	mkdir -p iup
	pwd
	tar -xzvf cd-5.9_Linux26g4_64_lib.tar.gz -C iup/
	tar -xzvf im-3.10_Linux26g4_64_lib.tar.gz -C iup/
	tar -xzvf iup-3.17_Linux26g4_64_lib.tar.gz -C iup/
	mkdir -p $(PREFIX)/include/ $(PREFIX)/lib/
	cp iup/include/* $(PREFIX)/include/
	cp iup/*.so $(PREFIX)/lib/
	cp iup/*.a $(PREFIX)/lib/

	cd iup && if [ -e installall.sh ];then fossil update $(IUPBRANCH); else fossil open ../iuplib.fossil;fossil update $(IUPBRANCH); fi
#	cd iup && if [ -e makeall.sh ];then fossil update $(IUPBRANCH); else fossil open ../iuplib.fossil;fossil update $(IUPBRANCH); fi

iup/alldone : iup/installall.sh $(PREFIX)/include/iup.h $(PREFIX)/lib/libiup.so
	cd iup && ./makeall.sh
iup/alldone :  $(PREFIX)/include/iup.h $(PREFIX)/lib/libiup.so # iup/makeall.sh
#	cd iup && ./makeall.sh $(IUPCONFIG)

$(PREFIX)/lib/libiup.so $(PREFIX)/include/iup.h : iup/installall.sh iup/alldone
	cd iup && ./installall.sh
#	cd iup && ./makeall.sh $(IUPCONFIG)

# $(PREFIX)/lib/libiup.so : iup/iup/alldone
#	touch -c $(PREFIX)/lib/libiup.so

$(CHICKEN_EGG_DIR)/iup.so : $(PREFIX)/lib/libiup.so  $(PREFIX)/lib/libavcall.a 
	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks iup
	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks -feature disable-iup-web iup

# -feature disable-iup-web

$(CHICKEN_EGG_DIR)/canvas-draw.so :  $(PREFIX)/lib/libiup.so  $(PREFIX)/lib/libavcall.a 
	CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks canvas-draw


clean :
	rm -rf chicken-4.8.0 eggflags ffcall sqlite-autoconf-$(SQLITE3_VERSION)

Added utils/Makefile.latest.installall version [149911e2cc].

































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

# Copyright 2013-2015 Matthew Welland.
# 
#  This program is made available under the GNU GPL version 2.0 or
#  greater. See the accompanying file COPYING for details.
# 
#  This program is distributed WITHOUT ANY WARRANTY; without even the
#  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.

help :
	@echo You may need to do the following setup first:
	@echo
	@echo sudo apt-get install libreadline-dev
	@echo sudo apt-get install libwebkitgtk-dev libfreetype6-dev libx11-dev libxpm-dev libxmu-dev \
	           libxft-dev libgtk2.0-dev libgl1-mesa-dev libglu1-mesa-dev libpangox-1.0-dev bison \
                   libwebkitgtk-3.0-dev
	@echo   -- nb// adding monodevelop gets more packages of which some might be needed...
	@echo sudo apt-get install libmotif3
	@echo
	@echo Set up your PATH, setting it in the Makefile does not work as expected
	@echo export PATH=$(PREFIX)/bin:\$$PATH
	@echo
	@echo For IUP set IUPBRANCH, currently $(IUPBRANCH)
	@echo         set IUPCONFIG, currently $(IUPCONFIG) - look in https://www.kiatoa.com/fossils/iuplib for .inc files
	@echo You are using PREFIX=$(PREFIX)
	@echo You are using PROXY="$(PROXY)"
	@echo If needed set PROXY to host.dom:port
	@echo   http_proxy=$(http_proxy)
	@echo 
	@echo To make all do: make all
	@echo   make minimal: make nogui
	@echo 
	@echo Note: If compiling on amd64 do CSC_OPTIONS=\'-C "-fPIC"\' make all IUPCONFIG=

FPIC=-C "-fPIC"

# Put the installation here
ifeq ($(PREFIX),)
PREFIX=$(PWD)/target
endif

# Set this on the command line of your make call if needed: make PROXY=host.com:1234
PROXY=

# http://code.call-cc.org/dev-snapshots/2015/06/07/chicken-4.10.0rc1.tar.gz
# http://code.call-cc.org/releases/4.10.0/chicken-4.10.0.tar.gz
# Select version of chicken, sqlite3 etc
CHICKEN_VERSION=4.10.1
SQLITE3_VERSION=3090200
# http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
# http://www.sqlite.org/2015/sqlite-autoconf-3081101.tar.gz
# Override IUPBRANCH to use other than trunk
IUPBRANCH=trunk
IUPCONFIG=ubuntu-15.04.inc
# iup-3.15

# Eggs to install (straightforward ones)
EGGS=matchable readline apropos base64 regex-literals format regex-case test coops trace csv \
     dot-locking posix-utils posix-extras directory-utils hostinfo tcp-server rpc csv-xml fmt \
     json md5 awful http-client spiffy uri-common intarweb spiffy-request-vars \
     spiffy-directory-listing ssax sxml-serializer sxml-modifications sql-de-lite \
     srfi-19 refdb ini-file sparse-vectors z3 call-with-environment-variables hahn linenoise \
     crypt parley zlib shell udp loops foof-loop lazy-seq ansi-escape-sequences rfc3339 slice \
     slice-utf8 scsh-process functional-lists srfi-101 uuid-lib filepath srfi-78 srfi-42 sexp-diff \
     low-level-macros symbol-utils expand-full chicken-doc irc silex lalr lalr-driver sha1 refdb

#
# Derived variables
#

ifeq ($(PROXY),)
PROX:=
else
http_proxy:=http://$(PROXY)
PROX:=-proxy $(PROXY)
endif

BUILDHOME=$(PWD)
PATH:=$(PREFIX)/bin:$(PATH)
LIBPATH=$(PREFIX)/lib$(ADDITIONAL_LIBPATH)
LD_LIBRARY_PATH=$(LIBPATH)
CHICKEN_INSTALL=$(PREFIX)/bin/chicken-install
CHICKEN_EGG_DIR=$(PREFIX)/lib/chicken/7

VPATH=$(CHICKEN_EGG_DIR):$(PWD)/eggflags

vpath %.so $(CHICKEN_EGG_DIR)
vpath %.flag eggflags

EGGSOFILES=$(addprefix $(CHICKEN_EGG_DIR)/,$(addsuffix .so,$(EGGS)))
EGGFLAGS=$(addprefix eggflags/,$(addsuffix .flag,$(EGGS)))

# Stuff needed for IUP
ISARCHX86_64=$(shell uname -a | grep x86_64)
ifeq ($(ISARCHX86_64),)
ARCHSIZE=
else
ARCHSIZE=64_
endif

CSCLIBS=$(shell echo $(LD_LIBRARY_PATH) | sed 's/:/ -L/g')
CSC_OPTIONS="-I$(PREFIX)/include -L$(CSCLIBS) -C \"-fPIC\""
# CSC_OPTIONS=-I $(PREFIX)/include -L $(CSCLIBS)

nogui : base mutils

#all : nogui libiup $(PREFIX)/lib/sqlite3.so
all : nogui libiup

base : chkn eggs 

# stuff needed for Kiatoa and Megatest from matts miscellaneous stash
#   NOTE TO SELF: eggifying these would be great...
mutils : base logprobin $(PREFIX)/bin/hs \
        $(PREFIX)/lib/chicken/7/mutils.so \
        $(PREFIX)/lib/chicken/7/dbi.so \
        $(PREFIX)/lib/chicken/7/stml.so \
        $(PREFIX)/lib/chicken/7/margs.so

chkn : $(CHICKEN_INSTALL)

eggs : $(EGGSOFILES)

# libiup : $(PREFIX)/lib/libavcall.a 
libiup : $(CHICKEN_EGG_DIR)/iup.so $(CHICKEN_EGG_DIR)/canvas-draw.so

logprobin : $(PREFIX)/bin/logpro

$(PREFIX)/bin/logpro : $(CHICKEN_EGG_DIR)/regex-literals.so
	$(CHICKEN_INSTALL) logpro

# Silly rule to make installing eggs more makeish, I don't understand why I need the basename
$(CHICKEN_EGG_DIR)/%.so : eggflags/%.flag
	$(CHICKEN_INSTALL) $(PROX) -keep-installed $(shell basename $*)

$(EGGFLAGS) : # $(CHICKEN_INSTALL)
	mkdir -p eggflags
	touch $(EGGFLAGS)

# some setup stuff
#
$(PREFIX)/setup-chicken4x.sh : $(EGGFLAGS)
	mkdir -p $(PREFIX)
	(echo 'export PATH=$(PREFIX)/bin:$$PATH' > $(PREFIX)/setup-chicken4x.sh)
	(echo "export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" >> $(PREFIX)/setup-chicken4x.sh)

$(PREFIX)/setup-chicken4x.csh : $(EGGFLAGS)
	mkdir -p $(PREFIX)
	(echo "setenv PATH $(PREFIX):'$$'PATH" > $(PREFIX)/setup-chicken4x.csh)
	(echo "setenv LD_LIBRARY_PATH $(LD_LIBRARY_PATH)" >> $(PREFIX)/setup-chicken4x.csh)

chicken-core/chicken.scm : chicken-$(CHICKEN_VERSION).tar.gz
	tar xf chicken-$(CHICKEN_VERSION).tar.gz
	ln -sf chicken-$(CHICKEN_VERSION) chicken-core


chicken-4.9.0rc1.tar.gz : 
	wget http://code.call-cc.org/dev-snapshots/2014/04/17/chicken-4.9.0rc1.tar.gz

chicken-4.9.0.1.tar.gz :
	wget http://code.call-cc.org/releases/4.9.0/chicken-4.9.0.1.tar.gz

chicken-4.10.0rc1.tar.gz :
	wget http://code.call-cc.org/dev-snapshots/2015/06/07/chicken-4.10.0rc1.tar.gz

chicken-4.10.0.tar.gz :
	wget http://code.call-cc.org/releases/4.10.0/chicken-4.10.0.tar.gz

chicken-4.10.1.tar.gz :
	wget http://code.call-cc.org/dev-snapshots/2015/08/29/chicken-4.10.1.tar.gz

# git clone git://code.call-cc.org/chicken-core
# git clone http://code.call-cc.org/git/chicken-core.git

$(CHICKEN_INSTALL) : chicken-core/chicken.scm $(PREFIX)/setup-chicken4x.sh $(PREFIX)/setup-chicken4x.csh
	cd chicken-core;make PLATFORM=linux PREFIX=$(PREFIX)
	cd chicken-core;make PLATFORM=linux PREFIX=$(PREFIX) install

#======================================================================
# S Q L I T E 3
#======================================================================
# https://www.sqlite.org/2015/sqlite-autoconf-3090200.tar.gz
sqlite-autoconf-$(SQLITE3_VERSION).tar.gz :
	wget  http://www.sqlite.org/2015/sqlite-autoconf-$(SQLITE3_VERSION).tar.gz

sqlite-autoconf-$(SQLITE3_VERSION)/config.log : sqlite-autoconf-$(SQLITE3_VERSION).tar.gz
	tar xf  sqlite-autoconf-$(SQLITE3_VERSION).tar.gz

$(PREFIX)/bin/sqlite3 : sqlite-autoconf-$(SQLITE3_VERSION)/config.log
	cd sqlite-autoconf-$(SQLITE3_VERSION);./configure --prefix=$(PREFIX);make;make install

$(CHICKEN_EGG_DIR)/sqlite3.so : $(PREFIX)/bin/sqlite3
	CSC_OPTIONS="-I$(PREFIX)/include -L$(PREFIX)/lib" $(CHICKEN_INSTALL) $(PROX) sqlite3

#======================================================================
# N  A N O M S G
#======================================================================

# https://github.com/nanomsg/nanomsg/releases/download/0.6-beta/nanomsg-0.6-beta.tar.gz
# https://github.com/nanomsg/nanomsg/releases/download/0.8-beta/nanomsg-0.8-beta.tar.gz

nanomsg-0.6-beta.tar.gz :
	wget http://download.nanomsg.org/nanomsg-0.6-beta.tar.gz

nanomsg-0.6-beta/COPYING : nanomsg-0.6-beta.tar.gz
	tar xf nanomsg-0.6-beta.tar.gz

$(PREFIX)/bin/nanocat : nanomsg-0.6-beta/COPYING
	cd nanomsg-0.6-beta;./configure --prefix=$(PREFIX);make;make install

$(PREFIX)/lib/nanomsg.so : $(PREFIX)/bin/nanocat
	CSC_OPTIONS="-I$(PREFIX)/include -L$(PREFIX)/lib" $(CHICKEN_INSTALL) $(PROX) nanomsg

# LD_LIBRARY_PATH=/mfs/pkgs/chicken/4.10.0-amd64/lib CSC_OPTIONS="-I/mfs/pkgs/chicken/4.10.0-amd64/include -L/mfs/pkgs/chicken/4.10.0-amd64/lib -C \"-fPIC\"" /mfs/pkgs/chicken/4.10.0-amd64/bin/chicken-install  -D no-library-checks nanomsg

#======================================================================
# M A T T S   U T I L S
#======================================================================

# opensrc

opensrc.fossil :
	fossil clone http://www.kiatoa.com/fossils/opensrc opensrc.fossil

opensrc/histstore/histstore.scm : opensrc.fossil
	mkdir -p opensrc
	cd opensrc;if [ -e .fslckout ];then fossil update; else fossil open ../opensrc.fossil; fi

$(PREFIX)/lib/chicken/7/mutils.so : opensrc/histstore/histstore.scm
	cd opensrc/mutils;chicken-install

$(PREFIX)/lib/chicken/7/dbi.so : opensrc/dbi/dbi.scm
	cd opensrc/dbi;chicken-install

$(PREFIX)/lib/chicken/7/margs.so : opensrc/margs/margs.scm
	cd opensrc/margs;chicken-install

opensrc/histstore/hs : opensrc/histstore/histstore.scm chkn eggs $(CHICKEN_EGG_DIR)/sqlite3.so 
	cd opensrc/histstore;$(PREFIX)/bin/csc histstore.scm -o hs

$(PREFIX)/bin/hs : opensrc/histstore/hs 
	cp -f opensrc/histstore/hs $(PREFIX)/bin/hs

# stml
stml.fossil :
	fossil clone http://www.kiatoa.com/fossils/stml stml.fossil

# open touches the .fossil :(
stml/requirements.scm.template : stml.fossil
	mkdir -p stml
	cd stml;if [ -e .fslckout ];then fossil update; else fossil open ../stml.fossil;fi

stml/requirements.scm : stml/requirements.scm.template
	cp stml/install.cfg.template      stml/install.cfg
	cp stml/requirements.scm.template stml/requirements.scm

$(PREFIX)/lib/chicken/7/stml.so : stml/requirements.scm
	cd stml;make

#======================================================================
# F F C A L L (Used by IUP)
#======================================================================

ffcall.fossil :
	fossil clone http://www.kiatoa.com/fossils/ffcall ffcall.fossil

ffcall/README : ffcall.fossil
	mkdir -p ffcall
	cd ffcall && if [ -e README ];then fossil update; else fossil open ../ffcall.fossil; fi

# NOTE: This worked fine *without* the enable-shared
#
$(PREFIX)/lib/libavcall.a : ffcall/README
	cd ffcall;./configure --prefix=$(PREFIX) --enable-shared && make CC="gcc -fPIC" && make install

#======================================================================
# I U P 
#======================================================================

iuplib.fossil :
	#fossil clone http://www.kiatoa.com/fossils/iuplib iuplib.fossil
	touch iuplib.fossil
iup/installall.sh : iuplib.fossil $(PREFIX)/lib/libiup.so
	mkdir -p iup
	pwd
	#wget -c http://sourceforge.net/projects/canvasdraw/files/5.9/Linux%20Libraries/cd-5.9_Linux26g4_64_lib.tar.gz/download
	#wget -c http://sourceforge.net/projects/iup/files/3.17/Linux%20Libraries/iup-3.17_Linux26g4_64_lib.tar.gz/download
	#wget -c http://sourceforge.net/projects/imtoolkit/files/3.10/Linux%20Libraries/im-3.10_Linux26g4_64_lib.tar.gz/download
	#wget -c http://sourceforge.net/projects/luabinaries/files/5.3.2/Linux%20Libraries/lua-5.3.2_Linux26g4_64_lib.tar.gz/download
	tar -xzvf cd-5.9_Linux26g4_64_lib.tar.gz -C iup/
	tar -xzvf im-3.10_Linux26g4_64_lib.tar.gz -C iup/
	tar -xzvf iup-3.17_Linux26g4_64_lib.tar.gz -C iup/
	mkdir -p $(PREFIX)/include/ $(PREFIX)/lib/
	cp iup/include/* $(PREFIX)/include/
	cp iup/*.so $(PREFIX)/lib/
	cp iup/*.a $(PREFIX)/lib/

#	cd iup && if [ -e makeall.sh ];then fossil update $(IUPBRANCH); else fossil open ../iuplib.fossil;fossil update $(IUPBRANCH); fi

#iup/alldone : iup/makeall.sh $(PREFIX)/include/iup.h $(PREFIX)/lib/libiup.so
#	cd iup && ./makeall.sh $(IUPCONFIG)

$(PREFIX)/lib/libiup.so $(PREFIX)/include/iup.h : iup/installall.sh
#	cd iup && ./makeall.sh $(IUPCONFIG)

# $(PREFIX)/lib/libiup.so : iup/iup/alldone
#	touch -c $(PREFIX)/lib/libiup.so

$(CHICKEN_EGG_DIR)/iup.so : $(PREFIX)/lib/libiup.so  $(PREFIX)/lib/libavcall.a 
	LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks -feature disable-iup-web iup

# -feature disable-iup-web

$(CHICKEN_EGG_DIR)/canvas-draw.so :  $(PREFIX)/lib/libiup.so  $(PREFIX)/lib/libavcall.a 
	CSC_OPTIONS=$(CSC_OPTIONS) $(CHICKEN_INSTALL) $(PROX) -D no-library-checks canvas-draw


clean :
	rm -rf chicken-4.8.0 eggflags ffcall sqlite-autoconf-$(SQLITE3_VERSION)

Modified utils/mk_wrapper from [a9a7628aaa] to [4b9a0dffa4].

22
23
24
25
26
27
28





















29
30
31
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52







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




# echo "#!/bin/bash" > $target
# if [ "$LD_LIBRARY_PATH" != "" ];then
#   echo "source $prefix/bin/.\$(lsb_release -sr)/cfg.sh" >> $target
# fi
# echo "exec $prefix/bin/.\$(lsb_release -sr)/$cmd \"\$@\"" >> $target
echo "#!/bin/bash" > $target

if [[ $cmd =~ dboard ]]; then
    cat >> $target <<'EOF'

# check that $DISPLAY is set
if [[ -z $DISPLAY ]]; then
   echo 'ERROR: $DISPLAY environment variable is not set; megatest dashboard requires X display address to be set in $DISPLAY.'
   exit 1
fi

# check that $DISPLAY is proper
if [[ -x $(which xdpyinfo  2>/dev/null) ]]; then
  if ! xdpyinfo -display "$DISPLAY" &>/dev/null; then
    echo 'ERROR: megatest dashboard cannot open display "'$DISPLAY'".  Please check $DISPLAY environment variable.'
    exit 1
  fi
fi
EOF

fi

echo "lsbr=\$(lsb_release -sr)" >> $target
echo "if [[ -e \$lsbr ]];then source \$lsbr;fi" >> $target
echo "exec $prefix/bin/.\$lsbr/$cmd \"\$@\"" >> $target

Added vg-test.scm version [3a58c56b03].







































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
(use canvas-draw iup foof-loop)
(import canvas-draw-iup)

(load "vg.scm")

(define numtorun 1000)
;; (if (> (length (argv)) 1)
;; 		     (string->number (cadr (argv)))
;; 		     1000))

 (use trace)
 ;; (trace 
 ;;  ;; vg:draw-rect
 ;;  ;; vg:grow-rect
 ;;  vg:get-extents-for-objs
 ;;  vg:components-get-extents
 ;;  vg:instances-get-extents
 ;;  vg:get-extents-for-two-rects
 ;;  canvas-line!)

(define d1 (vg:drawing-new))
(define l1 (vg:lib-new))
(define c1 (vg:comp-new))
(define c2 (vg:comp-new))
(define bt1 (vg:make-rect-obj 10 40 20 50 text: "A long piece of text" font: "Helvetica, -10"))

(let ((r1 (vg:make-rect-obj 20 20 30 30 text: "r1" font: "Helvetica, -20"))
      (r2 (vg:make-rect-obj 30 30 60 60 text: "r2" font: "Helvetica, -10"))
      (t1 (vg:make-text-obj 60 60 "The middle" font: "Helvetica, -10")))
  (vg:add-objs-to-comp c1 r1 r2 t1 bt1))

(loop ((for x (up-from 0 (to 20))))
       (loop ((for y (up-from 0 (to 20))))
	     (vg:add-objs-to-comp c1 (vg:make-rect-obj x y (+ x 5)(+ y 5)))))
      
(let ((start (current-seconds)))
  (let loop ((i 0))
    (vg:add-obj-to-comp c1 (vg:make-rect-obj 0 0 100 100))
    (if (< i numtorun)(loop (+ i 1))))
  (print "Run time: " (- (current-seconds) start)))

(vg:add-obj-to-comp c1 (vg:make-line-obj 0 0 100 100))

;; add the c1 component to lib l1 with name firstcomp
(vg:add-comp-to-lib l1 "firstcomp" c1)
(vg:add-comp-to-lib l1 "secondcomp" c2)

;; add the l1 lib to drawing with name firstlib
(vg:add-lib d1 "firstlib" l1)

;; instantiate firstlib/firstcomp as inst1 in drawing d1 at 0,0
(vg:instantiate d1 "firstlib" "firstcomp" "inst1" 0 0)
(vg:instantiate d1 "firstlib" "firstcomp" "inst2" 200 200)


;; (vg:drawing-scalex-set! d1 1.1)
;; (vg:drawing-scaley-set! d1 0.5)

;; (define xtnts (vg:scale-offset-xy 
;; 	       (vg:component-get-extents c1)
;; 	       1.1 1.1 -2 -2))

;; get extents of c1 and put a rectange around it
;;
(define xtnts (apply vg:grow-rect 10 10 (vg:components-get-extents d1 c1)))
(vg:add-objs-to-comp c1 (apply vg:make-rect-obj xtnts))

(define bt1xt (vg:obj-get-extents d1 bt1))
(print "bt1xt: " bt1xt)
(vg:add-objs-to-comp c1 (apply vg:make-rect-obj bt1xt))

;; get extents of all objects and put rectangle around it
;;
(define big-xtnts (vg:instances-get-extents d1))
(vg:add-objs-to-comp c2 (apply vg:make-rect-obj big-xtnts))
(vg:instantiate d1 "firstlib" "secondcomp" "inst3" 0 0)

(vg:drawing-scalex-set! d1 1.5)
(vg:drawing-scaley-set! d1 1.5)

(define cnv #f)
(define the-cnv (canvas 
		 #:size "500x400"
		 #:expand "YES"
		 #:scrollbar "YES"
		 #:posx "0.5"
		 #:posy "0.5"
		 #:action (make-canvas-action
			   (lambda (c xadj yadj)
			     (set! cnv c)))))

(show
 (dialog
  (vbox
   the-cnv)))

(vg:drawing-cnv-set! d1 cnv)
(vg:draw d1 #t)

;; (canvas-rectangle! cnv  10 100 10 80)

(main-loop)

Added vg.scm version [4b3f71521e].











































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
;;
;; Copyright 2016  Matthew Welland.
;; 
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;; 
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.

;;  strftime('%m/%d/%Y %H:%M:%S','now','localtime')

(use typed-records srfi-1)

(declare (unit vg))
(use canvas-draw iup)
(import canvas-draw-iup)

(include "vg_records.scm")

;; ;; structs
;; ;;
;; (defstruct vg:lib     comps)
;; (defstruct vg:comp    objs name file)
;; ;; extents caches extents calculated on draw
;; ;; proc is called on draw and takes the obj itself as a parameter
;; ;; attrib is an alist of parameters
;; (defstruct vg:obj     type pts fill-color text line-color call-back angle font attrib extents proc)
;; (defstruct vg:inst    libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache)
;; (defstruct vg:drawing libs insts scalex scaley xoff yoff cnv cache) ;; libs: hash of name->lib, insts: hash of instname->inst

;; inits
;;
(define (vg:comp-new)
  (make-vg:comp objs: '() name: #f file: #f))

(define (vg:lib-new)
  (make-vg:lib comps: (make-hash-table)))

(define (vg:drawing-new)
  (make-vg:drawing scalex: 1 
		   scaley: 1 
		   xoff: 0 
		   yoff: 0 
		   libs: (make-hash-table) 
		   insts: (make-hash-table)
		   cache: '()))

;;======================================================================
;; scaling and offsets
;;======================================================================

(define-inline (vg:scale-offset val s o)
  (+ o (* val s)))
  ;; (* (+ o val) s))

;; apply scale and offset to a list of x y values
;;
(define (vg:scale-offset-xy lstxy sx sy ox oy)
  (if (> (length lstxy) 1) ;; have at least one xy pair
      (let loop ((x   (car lstxy))
		 (y   (cadr lstxy))
		 (tal (cddr lstxy))
		 (res '()))
	(let ((newres (cons (vg:scale-offset y sy oy)
			    (cons (vg:scale-offset x sx ox)
				  res))))
	  (if (> (length tal) 1)
	      (loop (car tal)(cadr tal)(cddr tal) newres)
	      (reverse newres))))
      '()))

;; apply drawing offset and scaling to the points in lstxy
;;
(define (vg:drawing-apply-scale drawing lstxy)
  (vg:scale-offset-xy 
   lstxy
   (vg:drawing-scalex drawing)
   (vg:drawing-scaley drawing)
   (vg:drawing-xoff   drawing)
   (vg:drawing-yoff   drawing)))

;; apply instance offset and scaling to the points in lstxy
;;
(define (vg:inst-apply-scale inst lstxy)
  (vg:scale-offset-xy 
   lstxy
   (vg:inst-scalex inst)
   (vg:inst-scaley inst)
   (vg:inst-xoff   inst)
   (vg:inst-yoff   inst)))

;; apply both drawing and instance scaling to a list of xy points
;; 
(define (vg:drawing-inst-apply-scale-offset drawing inst lstxy)
  (vg:drawing-apply-scale 
   drawing
   (vg:inst-apply-scale inst lstxy)))

;;======================================================================
;; objects
;;======================================================================

;;   (vg:inst-apply-scale 
;;    inst
;;    (vg:drawing-apply-scale drawing lstxy)))

;; make a rectangle obj
;;
(define (vg:make-rect-obj x1 y1 x2 y2 #!key (line-color #f)(fill-color #f)(text #f)(font #f)(extents #f))
  (make-vg:obj type: 'r pts: (list x1 y1 x2 y2) text: text font: font line-color: line-color fill-color: fill-color extents: extents))

;; make a rectangle obj
;; 
(define (vg:make-line-obj x1 y1 x2 y2 #!key (line-color #f)(fill-color #f)(text #f)(font #f)(extents #f))
  (make-vg:obj type: 'l pts: (list x1 y1 x2 y2) text: text font: font line-color: line-color extents: extents))

;; make a text obj
;;
(define (vg:make-text-obj x1 y1 text #!key (line-color #f)(fill-color #f)
		      (angle #f)(scale-with-zoom #f)(font #f)
		      (font-size #f))
  (make-vg:obj type: 't pts: (list x1 y1) text: text 
	       line-color: line-color fill-color: fill-color
	       angle: angle font: font extents: #f
	       attributes: (vg:make-attrib 'font-size font-size)))

;; proc takes startnum and endnum and yields scalef, per-grad and unitname
;;
(define (vg:make-xaxis-obj x1 y1 x2 y2 #!key (line-color #f)(fill-color #f)(text #f)(font #f)(proc #f))
  (make-vg:obj type: 'x pts: (list x1 y1 x2 y2) text: text font: font line-color: line-color fill-color: fill-color extents: #f proc: proc))

;;======================================================================
;; obj modifiers and queries
;;======================================================================

;; get extents, use knowledge of type ...
;;
(define (vg:obj-get-extents drawing obj)
  (let ((type (vg:obj-type obj)))
    (case type
      ((l)(vg:rect-get-extents obj))
      ((r)(vg:rect-get-extents obj))
      ((t)(vg:draw-text drawing obj draw: #f))
      (else #f))))

(define (vg:rect-get-extents obj)
  (vg:obj-pts obj)) ;; extents are just the points for a rectangle

(define (vg:grow-rect borderx bordery x1 y1 x2 y2)
  (list
   (- x1 borderx)
   (- y1 bordery)
   (+ x2 borderx)
   (+ y2 bordery)))

(define (vg:make-attrib . attrib-list)
  #f)

;;======================================================================
;; components
;;======================================================================

;; add obj to comp
;;
(define (vg:add-objs-to-comp comp . objs)
  (vg:comp-objs-set! comp (append (vg:comp-objs comp) objs)))

(define (vg:add-obj-to-comp comp obj)
  (vg:comp-objs-set! comp (cons obj (vg:comp-objs comp))))

;; use the struct. leave this here to remind of this!
;;
;; (define (vg:comp-get-objs comp)
;;   (vg:comp-objs comp))

;; add comp to lib
;;
(define (vg:add-comp-to-lib lib compname comp)
  (hash-table-set! (vg:lib-comps lib) compname comp))

;; instanciate component in drawing
;;
(define (vg:instantiate drawing libname compname instname xoff yoff #!key (theta 0)(scalex 1)(scaley 1)(mirrx #f)(mirry #f))
  (let ((inst (make-vg:inst libname: libname compname: compname xoff: xoff yoff: yoff theta: theta scalex: scalex scaley: scaley mirrx: mirrx mirry: mirry)) )
    (hash-table-set! (vg:drawing-insts drawing) instname inst)))

(define (vg:instance-move drawing instname newx newy)
  (let ((inst (hash-table-ref (vg:drawing-insts drawing) instname)))
    (vg:inst-xoff-set! inst newx)
    (vg:inst-yoff-set! inst newy)))

;; get component from drawing (look in apropriate lib) given libname and compname
(define (vg:get-component drawing libname compname)
  (let* ((lib  (hash-table-ref (vg:drawing-libs drawing) libname))
	 (inst (hash-table-ref (vg:lib-comps lib) compname)))
    inst))

(define (vg:get-extents-for-objs drawing objs)
  (if (or (not objs)
	  (null? objs))
      #f
      (let loop ((hed     (car objs))
		 (tal     (cdr objs))
		 (extents (vg:obj-get-extents drawing (car objs))))
	(let ((newextents
	       (vg:get-extents-for-two-rects
		extents
		(vg:obj-get-extents drawing hed))))
	  (if (null? tal)
	      extents
	      (loop (car tal)(cdr tal) newextents))))))

;;   (let ((extents #f))
;;     (for-each
;;      (lambda (obj)
;;        (set! extents
;; 	 (vg:get-extents-for-two-rects
;; 	  extents
;; 	  (vg:obj-get-extents drawing obj))))
;;      objs)
;;     extents))

;; given rectangles r1 and r2, return the box that bounds both
;;
(define (vg:get-extents-for-two-rects r1 r2)
  (if (not r1)
      r2
      (if (not r2)
	  r1 ;; #f ;; no extents from #f #f
	  (list (min (car r1)(car r2))           ;; llx
		(min (cadr r1)(cadr r2))         ;; lly
		(max (caddr r1)(caddr r2))       ;; ulx
		(max (cadddr r1)(cadddr r2)))))) ;; uly

(define (vg:components-get-extents drawing . comps)
  (if (null? comps)
      #f
      (let loop ((hed  (car comps))
		 (tal  (cdr comps))
		 (extents #f))
	(let* ((objs  (vg:comp-objs hed))
	       (newextents (if extents
			       (vg:get-extents-for-two-rects
				extents
				(vg:get-extents-for-objs drawing objs))
			       (vg:get-extents-for-objs drawing objs))))
	  (if (null? tal)
	      newextents
	      (loop (car tal)(cdr tal) newextents))))))

;;======================================================================
;; libraries
;;======================================================================

;; register lib with drawing

;;
(define (vg:add-lib drawing libname lib)
  (hash-table-set! (vg:drawing-libs drawing) libname lib))

(define (vg:get-lib drawing libname)
  (hash-table-ref/default (vg:drawing-libs drawing) libname #f))

(define (vg:get/create-lib drawing libname)
  (let ((lib (vg:get-lib drawing libname)))
    (if lib
	lib
	(let ((newlib (vg:lib-new)))
	  (vg:add-lib drawing libname newlib)
	  newlib))))

;;======================================================================
;; map objects given offset, scale and mirror, resulting obj is displayed
;;======================================================================

;; dispatch the drawing of obj off to the correct drawing routine
;;
(define (vg:map-obj drawing inst obj)
  (case (vg:obj-type obj)
    ((l)(vg:map-line   drawing inst obj))
    ((r)(vg:map-rect   drawing inst obj))
    ((t)(vg:map-text   drawing inst obj))
    ((x)(vg:map-xaxis  drawing inst obj))
    (else #f)))

;; given a drawing and a inst map a rectangle to it screen coordinates
;;
(define (vg:map-rect drawing inst obj)
  (let ((res (make-vg:obj type:       'r ;; is there a defstruct copy?
			  fill-color: (vg:obj-fill-color obj)
			  text:       (vg:obj-text       obj)
			  line-color: (vg:obj-line-color obj)
			  font:       (vg:obj-font       obj)))
	(pts (vg:obj-pts obj)))
    (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
    (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) ))
    res))

;; given a drawing and a inst map a line to it screen coordinates
;;
(define (vg:map-line drawing inst obj)
  (let ((res (make-vg:obj type:       'l ;; is there a defstruct copy?
			  line-color: (vg:obj-line-color obj)
			  font:       (vg:obj-font       obj)))
	(pts (vg:obj-pts obj)))
    (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
    (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) ))
    res))

;; given a drawing and a inst map a text to it screen coordinates
;;
(define (vg:map-text drawing inst obj)
  (let ((res (make-vg:obj type:       't
			  fill-color: (vg:obj-fill-color obj)
			  text:       (vg:obj-text       obj)
			  line-color: (vg:obj-line-color obj)
			  font:       (vg:obj-font       obj)
			  angle:      (vg:obj-angle      obj)
			  attrib:     (vg:obj-attrib     obj)))
	(pts (vg:obj-pts obj)))
    (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
    (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing)))
    res))

;; given a drawing and a inst map a line to it screen coordinates
;;
(define (vg:map-xaxis drawing inst obj)
  (let ((res (make-vg:obj type:      'x ;; is there a defstruct copy?
			  line-color: (vg:obj-line-color obj)
			  font:       (vg:obj-font       obj)))
	(pts (vg:obj-pts obj)))
    (vg:obj-pts-set! res (vg:drawing-inst-apply-scale-offset drawing inst pts))
    (vg:drawing-cache-set! drawing (cons res (vg:drawing-cache drawing) ))
    res))

;;======================================================================
;; instances
;;======================================================================

(define (vg:instances-get-extents drawing . instance-names)
  (let ((xtnt-lst (vg:draw drawing #f)))
    (if (null? xtnt-lst)
	#f
	(let loop ((extents (car xtnt-lst))
		   (tal     (cdr xtnt-lst))
		   (llx     #f)
		   (lly     #f)
		   (ulx     #f)
		   (uly     #f))
	  (let ((nllx      (if llx (min llx (list-ref extents 0))(list-ref extents 0)))
		(nlly      (if lly (min lly (list-ref extents 1))(list-ref extents 1)))
		(nulx      (if ulx (max ulx (list-ref extents 2))(list-ref extents 2)))
		(nuly      (if uly (max uly (list-ref extents 3))(list-ref extents 3))))
	    (if (null? tal)
		(list llx lly ulx uly)
		(loop (car tal)(cdr tal) nllx nlly nulx nuly)))))))

(define (vg:lib-get-component lib instname)
  (hash-table-ref/default  (vg:lib-comps lib) instname #f))

;;======================================================================
;; color
;;======================================================================

(define (vg:rgb->number r g b #!key (a 0))
  (bitwise-ior
    (arithmetic-shift a 24)
    (arithmetic-shift r 16)
    (arithmetic-shift g 8)
    b))

(define (vg:generate-color)
  (vg:rgb->number (random 255)
                  (random 255)
                  (random 255)))
  ;;(vg:rgb->number 0 0 0))

(define (vg:iup-color->number iup-color)
  (apply vg:rgb->number (map string->number (string-split iup-color))))

;;======================================================================
;; graphing
;;======================================================================

(define (vg:make-xaxis drawing component x1 y1 x2 y2 startnum endnum scaleproc)
  (let ((obj (vg:make-xaxis-obj x1 y1 x2 y2)))
    #f))

;;======================================================================
;; Unravel and draw the objects
;;======================================================================

;; with get-extents = #t return the extents
;; with draw = #f don't actually draw the object
;;
(define (vg:draw-obj drawing obj #!key (draw #t))
  ;; (print "obj type: " (vg:obj-type obj))
  (case (vg:obj-type obj)
    ((l)(vg:draw-line drawing obj draw: draw))
    ((r)(vg:draw-rect drawing obj draw: draw))
    ((t)(vg:draw-text drawing obj draw: draw))))

;; given a rect obj draw it on the canvas applying first the drawing
;; scale and offset
;;
(define (vg:draw-rect drawing obj #!key (draw #t))
  (let* ((cnv (vg:drawing-cnv drawing))
	 (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
	 (fill-color (vg:obj-fill-color obj))
	 (line-color (vg:obj-line-color obj))
	 (text       (vg:obj-text obj))
	 (font       (vg:obj-font obj))
	 (llx        (car pts))
	 (lly        (cadr pts))
	 (ulx        (caddr pts))
	 (uly        (cadddr pts))
	 (w          (- ulx llx))
	 (h          (- uly lly))
	 (text-xmax  #f)
	 (text-ymax  #f))
    (if draw 
	(let ((prev-background-color (canvas-background cnv))
	      (prev-foreground-color (canvas-foreground cnv)))
	  (if fill-color
	      (begin
		(canvas-foreground-set! cnv fill-color)
		(canvas-box! cnv llx ulx lly uly))) ;; docs are all over the place on this one.;; w h)
	  (if line-color
	      (canvas-foreground-set! cnv line-color)
	      (if fill-color
		  (canvas-foreground-set! cnv prev-foreground-color)))
	  (canvas-rectangle! cnv llx ulx lly uly)
	  (canvas-foreground-set! cnv prev-foreground-color)
	  (if text 
	      (let* ((prev-font    (canvas-font cnv))
		     (font-changed (and font (not (equal? font prev-font)))))
		(if font-changed (canvas-font-set! cnv font))
		(canvas-text! cnv (+ 2 llx)(+ 2 lly) text)
		(if (eq? draw 'get-extents)
		    (let-values (((xmax ymax)(canvas-text-size cnv text)))
				(set! text-xmax xmax)(set! text-ymax ymax)))
		(if font-changed (canvas-font-set! cnv prev-font))))))
    ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax)
    (if (vg:obj-extents obj)
	(vg:obj-extents obj)
	(if (not text)
	    pts ;; no text
	    (if (and text-xmax text-ymax) ;; have text
		(let ((xt (list llx lly
				(max ulx (+ llx text-xmax))
				(max uly (+ lly text-ymax)))))
		  (vg:obj-extents-set! obj xt)
		  xt)
		(if cnv
		    (if (eq? draw 'get-extents)
			(let-values (((xmax ymax)(canvas-text-size cnv text)))
				    (let ((xt (list llx lly
						    (max ulx (+ llx xmax))
						    (max uly (+ lly ymax)))))
				      (vg:obj-extents-set! obj xt)
				      xt))
			pts)
		    pts)))))) ;; return extents 

;; given a rect obj draw it on the canvas applying first the drawing
;; scale and offset
;;
(define (vg:draw-line drawing obj #!key (draw #t))
  (let* ((cnv (vg:drawing-cnv drawing))
	 (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
	 ;; (fill-color (vg:obj-fill-color obj))
	 (line-color (vg:obj-line-color obj))
	 (text       (vg:obj-text obj))
	 (font       (vg:obj-font obj))
	 (llx        (car pts))
	 (lly        (cadr pts))
	 (ulx        (caddr pts))
	 (uly        (cadddr pts))
	 (w          (- ulx llx))
	 (h          (- uly lly))
	 (text-xmax  #f)
	 (text-ymax  #f))
    (if draw 
	(let ((prev-background-color (canvas-background cnv))
	      (prev-foreground-color (canvas-foreground cnv)))
	;; (if fill-color
	;;     (begin
	;; 	(canvas-foreground-set! cnv fill-color)
	;; 	(canvas-box! cnv llx ulx lly uly))) ;; docs are all over the place on this one.;; w h)
	  (if line-color
	      (canvas-foreground-set! cnv line-color))
	     ;; (if fill-color
	     ;;  (canvas-foreground-set! cnv prev-foreground-color)))
	  (canvas-line! cnv llx lly ulx uly)
	  (canvas-foreground-set! cnv prev-foreground-color)
	  (if text 
	      (let* ((prev-font    (canvas-font cnv))
		     (font-changed (and font (not (equal? font prev-font)))))
		(if font-changed (canvas-font-set! cnv font))
		(canvas-text! cnv (+ 2 llx)(+ 2 lly) text)
		(let-values (((xmax ymax)(canvas-text-size cnv text)))
		  (set! text-xmax xmax)(set! text-ymax ymax))
		(if font-changed (canvas-font-set! cnv prev-font))))))
    ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax)
    (if (vg:obj-extents obj)
	(vg:obj-extents obj)
	(if (not text)
	    pts
	    (if (and text-xmax text-ymax)
		(let ((xt (list llx lly
				(max ulx (+ llx text-xmax))
				(max uly (+ lly text-ymax)))))
		  (vg:obj-extents-set! obj xt)
		  xt)
		(if cnv
		    (let-values (((xmax ymax)(canvas-text-size cnv text)))
		      (let ((xt (list llx lly
				      (max ulx (+ llx xmax))
				      (max uly (+ lly ymax)))))
			(vg:obj-extents-set! obj xt)
			xt))
		    pts)))))) ;; return extents 

;; given a rect obj draw it on the canvas applying first the drawing
;; scale and offset
;;
(define (vg:draw-xaxis drawing obj #!key (draw #t))
  (let* ((cnv (vg:drawing-cnv drawing))
	 (pts (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
	 ;; (fill-color (vg:obj-fill-color obj))
	 (line-color (vg:obj-line-color obj))
	 (text       (vg:obj-text obj))
	 (font       (vg:obj-font obj))
	 (llx        (car pts))
	 (lly        (cadr pts))
	 (ulx        (caddr pts))
	 (uly        (cadddr pts))
	 (w          (- ulx llx))
	 (h          (- uly lly))
	 (text-xmax  #f)
	 (text-ymax  #f))
    (if draw 
	(let ((prev-background-color (canvas-background cnv))
	      (prev-foreground-color (canvas-foreground cnv)))
	;; (if fill-color
	;;     (begin
	;; 	(canvas-foreground-set! cnv fill-color)
	;; 	(canvas-box! cnv llx ulx lly uly))) ;; docs are all over the place on this one.;; w h)
	  (if line-color
	      (canvas-foreground-set! cnv line-color)
	      (if fill-color
		  (canvas-foreground-set! cnv prev-foreground-color)))
	  (canvas-line! cnv llx ulx lly uly)
	  (canvas-foreground-set! cnv prev-foreground-color)
	  (if text 
	      (let* ((prev-font    (canvas-font cnv))
		     (font-changed (and font (not (equal? font prev-font)))))
		(if font-changed (canvas-font-set! cnv font))
		(canvas-text! cnv (+ 2 llx)(+ 2 lly) text)
		(let-values (((xmax ymax)(canvas-text-size cnv text)))
		  (set! text-xmax xmax)(set! text-ymax ymax))
		(if font-changed (canvas-font-set! cnv prev-font))))))
    ;; (print "text-xmax: " text-xmax " text-ymax: " text-ymax)
    (if (vg:obj-extents obj)
	(vg:obj-extents obj)
	(if (not text)
	    pts
	    (if (and text-xmax text-ymax)
		(let ((xt (list llx lly
				(max ulx (+ llx text-xmax))
				(max uly (+ lly text-ymax)))))
		  (vg:obj-extents-set! obj xt)
		  xt)
		(if cnv
		    (let-values (((xmax ymax)(canvas-text-size cnv text)))
		      (let ((xt (list llx lly
				      (max ulx (+ llx xmax))
				      (max uly (+ lly ymax)))))
			(vg:obj-extents-set! obj xt)
			xt))
		    pts)))))) ;; return extents 

;; given a rect obj draw it on the canvas applying first the drawing
;; scale and offset
;;
(define (vg:draw-text drawing obj #!key (draw #t))
  (let* ((cnv        (vg:drawing-cnv drawing))
	 (pts        (vg:drawing-apply-scale drawing (vg:obj-pts obj)))
	 (text       (vg:obj-text obj))
	 (font       (vg:obj-font obj))
	 (fill-color (vg:obj-fill-color obj))
	 (line-color (vg:obj-line-color obj))
	 (llx        (car pts)) 
	 (lly        (cadr pts)))
    (if draw 
	(let* ((prev-background-color (canvas-background cnv))
	       (prev-foreground-color (canvas-foreground cnv))
	       (prev-font             (canvas-font       cnv))
	       (font-changed    (and font (not (equal? font prev-font)))))
	  (if line-color
	      (canvas-foreground-set! cnv line-color)
	      (if fill-color
		  (canvas-foreground-set! cnv prev-foreground-color)))
	  (if font-changed (canvas-font-set! cnv font))
	  (canvas-text! cnv llx lly text)
	  ;; NOTE: we do not set the font back!!
	  (canvas-foreground-set! cnv prev-foreground-color)))
    (if cnv
	(if (eq? draw 'get-extents)
	    (let-values (((xmax ymax)(canvas-text-size cnv text)))
			(append pts (list (+ llx xmax)(+ lly ymax)))) ;; will be wrong if text is rotated?
	    (append pts pts))
	(append pts pts))))

(define (vg:draw-inst drawing inst #!key (draw-mode #t)(prev-extents '()))
  (let* ((libname  (vg:inst-libname inst))
	 (compname (vg:inst-compname inst))
	 (comp     (vg:get-component drawing libname compname))
	 (objs     (vg:comp-objs comp)))
    ;; (print "comp: " comp)
    (if (null? objs)
	prev-extents
	(let loop ((obj (car objs))
		   (tal (cdr objs))
		   (res prev-extents))
	  (let* ((obj-xfrmd (vg:map-obj drawing inst obj))
		 (newres    (cons (vg:draw-obj drawing obj-xfrmd draw: draw-mode) res)))
	    (if (null? tal)
		newres
		(loop (car tal)(cdr tal) newres)))))))

(define (vg:draw drawing draw-mode . instnames)
  (let* ((insts (vg:drawing-insts drawing))
	 (all-inst-names (hash-table-keys insts))
	 (master-list    (if (null? instnames)
			     all-inst-names
			     instnames)))
    (if (null? master-list)
	'()
	(let loop ((instname (car master-list))
		   (tal      (cdr master-list))
		   (res      '()))
	  (let* ((inst     (hash-table-ref/default insts instname #f))
		 (newres   (if inst
			       (vg:draw-inst drawing inst draw-mode: draw-mode prev-extents: res)
			       res)))
	    (if (null? tal)
		newres
		(loop (car tal)(cdr tal) newres)))))))

Added vg_records.scm version [c48b950cb7].


























































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
;; Created by records.sh. DO NOT EDIT THIS FILE. Edit records.sh instead
;; Generated using make-vector-record -safe vg lib comps

(use simple-exceptions)
(define vg:lib-exn (make-exception "wrong record type, expected vg:lib." 'assert))
(define (pmake-vg:lib . params)(let ((v (if (null? params)(make-vector 2)(apply vector 'vg:lib params)))) v))
(define (make-vg:lib #!key 
              (comps #f)
         )
    (vector 'vg:lib comps))

(define-inline (vg:lib-comps       vec)(if (eq? (vector-ref vec 0) 'vg:lib)(vector-ref  vec 1)(raise (vg:lib-exn 'vg:lib-comps 'xpr))))

(define-inline (vg:lib-comps-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:lib)(vector-set! vec 1 val)(raise (vg:lib-exn 'comps))))
;; Generated using make-vector-record -safe vg comp objs name file

(use simple-exceptions)
(define vg:comp-exn (make-exception "wrong record type, expected vg:comp." 'assert))
(define (pmake-vg:comp . params)(let ((v (if (null? params)(make-vector 4)(apply vector 'vg:comp params)))) v))
(define (make-vg:comp #!key 
              (objs #f)
              (name #f)
              (file #f)
         )
    (vector 'vg:comp objs name file))

(define-inline (vg:comp-objs       vec)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-ref  vec 1)(raise (vg:comp-exn 'vg:comp-objs 'xpr))))
(define-inline (vg:comp-name       vec)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-ref  vec 2)(raise (vg:comp-exn 'vg:comp-name 'xpr))))
(define-inline (vg:comp-file       vec)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-ref  vec 3)(raise (vg:comp-exn 'vg:comp-file 'xpr))))

(define-inline (vg:comp-objs-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-set! vec 1 val)(raise (vg:comp-exn 'objs))))
(define-inline (vg:comp-name-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-set! vec 2 val)(raise (vg:comp-exn 'name))))
(define-inline (vg:comp-file-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:comp)(vector-set! vec 3 val)(raise (vg:comp-exn 'file))))
;; Generated using make-vector-record -safe vg obj type pts fill-color text line-color call-back angle font attrib extents proc

(use simple-exceptions)
(define vg:obj-exn (make-exception "wrong record type, expected vg:obj." 'assert))
(define (pmake-vg:obj . params)(let ((v (if (null? params)(make-vector 12)(apply vector 'vg:obj params)))) v))
(define (make-vg:obj #!key 
              (type #f)
              (pts #f)
              (fill-color #f)
              (text #f)
              (line-color #f)
              (call-back #f)
              (angle #f)
              (font #f)
              (attrib #f)
              (extents #f)
              (proc #f)
         )
    (vector 'vg:obj type pts fill-color text line-color call-back angle font attrib extents proc))

(define-inline (vg:obj-type             vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 1)(raise (vg:obj-exn 'vg:obj-type 'xpr))))
(define-inline (vg:obj-pts              vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 2)(raise (vg:obj-exn 'vg:obj-pts 'xpr))))
(define-inline (vg:obj-fill-color       vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 3)(raise (vg:obj-exn 'vg:obj-fill-color 'xpr))))
(define-inline (vg:obj-text             vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 4)(raise (vg:obj-exn 'vg:obj-text 'xpr))))
(define-inline (vg:obj-line-color       vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 5)(raise (vg:obj-exn 'vg:obj-line-color 'xpr))))
(define-inline (vg:obj-call-back        vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 6)(raise (vg:obj-exn 'vg:obj-call-back 'xpr))))
(define-inline (vg:obj-angle            vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 7)(raise (vg:obj-exn 'vg:obj-angle 'xpr))))
(define-inline (vg:obj-font             vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 8)(raise (vg:obj-exn 'vg:obj-font 'xpr))))
(define-inline (vg:obj-attrib           vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 9)(raise (vg:obj-exn 'vg:obj-attrib 'xpr))))
(define-inline (vg:obj-extents          vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 10)(raise (vg:obj-exn 'vg:obj-extents 'xpr))))
(define-inline (vg:obj-proc             vec)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-ref  vec 11)(raise (vg:obj-exn 'vg:obj-proc 'xpr))))

(define-inline (vg:obj-type-set!        vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 1 val)(raise (vg:obj-exn 'type))))
(define-inline (vg:obj-pts-set!         vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 2 val)(raise (vg:obj-exn 'pts))))
(define-inline (vg:obj-fill-color-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 3 val)(raise (vg:obj-exn 'fill-color))))
(define-inline (vg:obj-text-set!        vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 4 val)(raise (vg:obj-exn 'text))))
(define-inline (vg:obj-line-color-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 5 val)(raise (vg:obj-exn 'line-color))))
(define-inline (vg:obj-call-back-set!   vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 6 val)(raise (vg:obj-exn 'call-back))))
(define-inline (vg:obj-angle-set!       vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 7 val)(raise (vg:obj-exn 'angle))))
(define-inline (vg:obj-font-set!        vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 8 val)(raise (vg:obj-exn 'font))))
(define-inline (vg:obj-attrib-set!      vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 9 val)(raise (vg:obj-exn 'attrib))))
(define-inline (vg:obj-extents-set!     vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 10 val)(raise (vg:obj-exn 'extents))))
(define-inline (vg:obj-proc-set!        vec val)(if (eq? (vector-ref vec 0) 'vg:obj)(vector-set! vec 11 val)(raise (vg:obj-exn 'proc))))
;; Generated using make-vector-record -safe vg inst libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache

(use simple-exceptions)
(define vg:inst-exn (make-exception "wrong record type, expected vg:inst." 'assert))
(define (pmake-vg:inst . params)(let ((v (if (null? params)(make-vector 12)(apply vector 'vg:inst params)))) v))
(define (make-vg:inst #!key 
              (libname #f)
              (compname #f)
              (theta #f)
              (xoff #f)
              (yoff #f)
              (scalex #f)
              (scaley #f)
              (mirrx #f)
              (mirry #f)
              (call-back #f)
              (cache #f)
         )
    (vector 'vg:inst libname compname theta xoff yoff scalex scaley mirrx mirry call-back cache))

(define-inline (vg:inst-libname         vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 1)(raise (vg:inst-exn 'vg:inst-libname 'xpr))))
(define-inline (vg:inst-compname        vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 2)(raise (vg:inst-exn 'vg:inst-compname 'xpr))))
(define-inline (vg:inst-theta           vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 3)(raise (vg:inst-exn 'vg:inst-theta 'xpr))))
(define-inline (vg:inst-xoff            vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 4)(raise (vg:inst-exn 'vg:inst-xoff 'xpr))))
(define-inline (vg:inst-yoff            vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 5)(raise (vg:inst-exn 'vg:inst-yoff 'xpr))))
(define-inline (vg:inst-scalex          vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 6)(raise (vg:inst-exn 'vg:inst-scalex 'xpr))))
(define-inline (vg:inst-scaley          vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 7)(raise (vg:inst-exn 'vg:inst-scaley 'xpr))))
(define-inline (vg:inst-mirrx           vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 8)(raise (vg:inst-exn 'vg:inst-mirrx 'xpr))))
(define-inline (vg:inst-mirry           vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 9)(raise (vg:inst-exn 'vg:inst-mirry 'xpr))))
(define-inline (vg:inst-call-back       vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 10)(raise (vg:inst-exn 'vg:inst-call-back 'xpr))))
(define-inline (vg:inst-cache           vec)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-ref  vec 11)(raise (vg:inst-exn 'vg:inst-cache 'xpr))))

(define-inline (vg:inst-libname-set!    vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 1 val)(raise (vg:inst-exn 'libname))))
(define-inline (vg:inst-compname-set!   vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 2 val)(raise (vg:inst-exn 'compname))))
(define-inline (vg:inst-theta-set!      vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 3 val)(raise (vg:inst-exn 'theta))))
(define-inline (vg:inst-xoff-set!       vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 4 val)(raise (vg:inst-exn 'xoff))))
(define-inline (vg:inst-yoff-set!       vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 5 val)(raise (vg:inst-exn 'yoff))))
(define-inline (vg:inst-scalex-set!     vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 6 val)(raise (vg:inst-exn 'scalex))))
(define-inline (vg:inst-scaley-set!     vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 7 val)(raise (vg:inst-exn 'scaley))))
(define-inline (vg:inst-mirrx-set!      vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 8 val)(raise (vg:inst-exn 'mirrx))))
(define-inline (vg:inst-mirry-set!      vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 9 val)(raise (vg:inst-exn 'mirry))))
(define-inline (vg:inst-call-back-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 10 val)(raise (vg:inst-exn 'call-back))))
(define-inline (vg:inst-cache-set!      vec val)(if (eq? (vector-ref vec 0) 'vg:inst)(vector-set! vec 11 val)(raise (vg:inst-exn 'cache))))
;; Generated using make-vector-record -safe vg drawing libs insts scalex scaley xoff yoff cnv cache

(use simple-exceptions)
(define vg:drawing-exn (make-exception "wrong record type, expected vg:drawing." 'assert))
(define (pmake-vg:drawing . params)(let ((v (if (null? params)(make-vector 9)(apply vector 'vg:drawing params)))) v))
(define (make-vg:drawing #!key 
              (libs #f)
              (insts #f)
              (scalex #f)
              (scaley #f)
              (xoff #f)
              (yoff #f)
              (cnv #f)
              (cache #f)
         )
    (vector 'vg:drawing libs insts scalex scaley xoff yoff cnv cache))

(define-inline (vg:drawing-libs         vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 1)(raise (vg:drawing-exn 'vg:drawing-libs 'xpr))))
(define-inline (vg:drawing-insts        vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 2)(raise (vg:drawing-exn 'vg:drawing-insts 'xpr))))
(define-inline (vg:drawing-scalex       vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 3)(raise (vg:drawing-exn 'vg:drawing-scalex 'xpr))))
(define-inline (vg:drawing-scaley       vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 4)(raise (vg:drawing-exn 'vg:drawing-scaley 'xpr))))
(define-inline (vg:drawing-xoff         vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 5)(raise (vg:drawing-exn 'vg:drawing-xoff 'xpr))))
(define-inline (vg:drawing-yoff         vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 6)(raise (vg:drawing-exn 'vg:drawing-yoff 'xpr))))
(define-inline (vg:drawing-cnv          vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 7)(raise (vg:drawing-exn 'vg:drawing-cnv 'xpr))))
(define-inline (vg:drawing-cache        vec)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-ref  vec 8)(raise (vg:drawing-exn 'vg:drawing-cache 'xpr))))

(define-inline (vg:drawing-libs-set!    vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 1 val)(raise (vg:drawing-exn 'libs))))
(define-inline (vg:drawing-insts-set!   vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 2 val)(raise (vg:drawing-exn 'insts))))
(define-inline (vg:drawing-scalex-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 3 val)(raise (vg:drawing-exn 'scalex))))
(define-inline (vg:drawing-scaley-set!  vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 4 val)(raise (vg:drawing-exn 'scaley))))
(define-inline (vg:drawing-xoff-set!    vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 5 val)(raise (vg:drawing-exn 'xoff))))
(define-inline (vg:drawing-yoff-set!    vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 6 val)(raise (vg:drawing-exn 'yoff))))
(define-inline (vg:drawing-cnv-set!     vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 7 val)(raise (vg:drawing-exn 'cnv))))
(define-inline (vg:drawing-cache-set!   vec val)(if (eq? (vector-ref vec 0) 'vg:drawing)(vector-set! vec 8 val)(raise (vg:drawing-exn 'cache))))

Deleted zmq-transport.scm version [e1f3152a02].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493













































































































































































































































































































































































































































































































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

;; Copyright 2006-2012, Matthew Welland.
;; 
;;  This program is made available under the GNU GPL version 2.0 or
;;  greater. See the accompanying file COPYING for details.
;; 
;;  This program is distributed WITHOUT ANY WARRANTY; without even the
;;  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;  PURPOSE.

(require-extension (srfi 18) extras tcp s11n)

(use sqlite3 srfi-1 posix regex regex-case srfi-69 hostinfo md5 message-digest)
(import (prefix sqlite3 sqlite3:))

(use zmq)

(declare (unit zmq-transport))

(declare (uses common))
(declare (uses db))
(declare (uses tests))
(declare (uses tasks)) ;; tasks are where stuff is maintained about what is running.
(declare (uses server))

(include "common_records.scm")
(include "db_records.scm")

;; Transition to pub --> sub with pull <-- push
;;
;;   1. client sends request to server via push to the pull port
;;   2. server puts request in queue or processes immediately as appropriate
;;   3. server puts responses from completed requests into pub port 
;;
;; TODO
;;
;; Done Tested
;; [x]  [ ]    1. Add columns pullport pubport to servers table
;; [x]  [ ]    2. Add rm of monitor.db if older than 11/12/2012 
;; [x]  [ ]    3. Add create of pullport and pubport with finding of available ports
;; [x]  [ ]    4. Add client compose of request
;; [x]  [ ]        - name of client: testname/itempath-test_id-hostname 
;; [x]  [ ]        - name of request: callname, params
;; [x]  [ ]        - request key: f(clientname, callname, params)
;; [x]  [ ]    5. Add processing of subscription hits
;; [x]  [ ]        - done when get key 
;; [x]  [ ]        - return results
;; [x]  [ ]    6. Add timeout processing
;; [x]  [ ]        - after 60 seconds
;; [ ]  [ ]            i. check server alive, connect to new if necessary
;; [ ]  [ ]           ii. resend request
;; [ ]  [ ]    7. Turn self ping back on

(define (zmq-transport:make-server-url hostport)
  (if (not hostport)
      #f
      (conc "tcp://" (car hostport) ":" (cadr hostport))))

(define  *server-loop-heart-beat* (current-seconds))
(define *heartbeat-mutex* (make-mutex))

;;======================================================================
;; S E R V E R
;;======================================================================

(define-inline (zmqsock:get-pub  dat)(vector-ref dat 0))
(define-inline (zmqsock:get-pull dat)(vector-ref dat 1))
(define-inline (zmqsock:set-pub! dat s)(vector-set! dat s 0))
(define-inline (zmqsock:set-pull! dat s)(vector-set! dat s 0))

(define (zmq-transport:run hostn)
  (debug:print 2 "Attempting to start the server ...")
  (if (not *toppath*)
      (if (not (setup-for-run))
	  (begin
	    (debug:print 0 "ERROR: cannot find megatest.config, cannot start server, exiting")
	    (exit))))
  (let* ((db              (open-db)) ;; here we *do not* want to be opening and closing the db
	 (zmq-sdat1       #f)
	 (zmq-sdat2       #f)
	 (pull-socket     #f)
	 (pub-socket      #f)
	 (p1              #f)
	 (p2              #f)
	 (zmq-sockets-dat #f)
	 (iface           (if (string=? "-" hostn)
			      "*" ;; (get-host-name) 
			      hostn))
	 (hostname        (get-host-name))
	 (ipaddrstr       (let ((ipstr (if (string=? "-" hostn)
					   (string-intersperse (map number->string (u8vector->list (hostname->ip hostname))) ".")
					   #f)))
			    (if ipstr ipstr hostname)))
	 (last-run       0))
    (set! zmq-sockets-dat (zmq-transport:setup-ports ipaddrstr (if (args:get-arg "-port")
			    (string->number (args:get-arg "-port"))
							    (+ 5000 (random 1001)))))

    (set! zmq-sdat1    (car   zmq-sockets-dat))
    (set! pull-socket  (cadr  zmq-sdat1)) ;; (iface s  port)
    (set! p1           (caddr zmq-sdat1))
    
    (set! zmq-sdat2    (cadr  zmq-sockets-dat))
    (set! pub-socket   (cadr  zmq-sdat2))
    (set! p2           (caddr zmq-sdat2))

    (set! *cache-on* #t)

    (set! *runremote* (vector pull-socket pub-socket)) ;; overloading the use of *runremote* BUG!?

    ;; what to do when we quit
    ;;
;;     (on-exit (lambda ()
;; 	       (if (and *toppath* *server-info*)
;; 		   (open-run-close tasks:server-deregister-self tasks:open-db (car *server-info*))
;; 		   (let loop () 
;; 		     (let ((queue-len 0))
;; 		       (thread-sleep! (random 5))
;; 		       (mutex-lock! *incoming-mutex*)
;; 		       (set! queue-len (length *incoming-data*))
;; 		       (mutex-unlock! *incoming-mutex*)
;; 		       (if (> queue-len 0)
;; 			   (begin
;; 			     (debug:print-info 0 "Queue not flushed, waiting ...")
;; 			     (loop))))))))

    ;; The heavy lifting
    ;;
    ;; make-vector-record cdb packet client-sig qtype immediate query-sig params qtime
    ;;
    (debug:print-info 11 "Server setup complete, start listening for messages")
    (let loop ((queue-lst '()))
      (let* ((rawmsg (receive-message* pull-socket))
	     (packet (db:string->obj rawmsg))
	     (qtype  (cdb:packet-get-qtype packet)))
	(debug:print-info 12 "server=> received packet=" packet)
	(if (not (member qtype '(sync ping)))
	    (begin
	      (mutex-lock! *heartbeat-mutex*)
	      (set! *last-db-access* (current-seconds))
	      (mutex-unlock! *heartbeat-mutex*)))
	(if #t ;; (cdb:packet-get-immediate packet) ;; process immediately or put in queue
	    (begin
	      (db:process-queue-item db packet)
	      ;; (open-run-close db:process-queue #f pub-socket (cons packet queue-lst))
	      
	      (loop '()))
	    (loop (cons packet queue-lst)))))))

;; run zmq-transport:keep-running in a parallel thread to monitor that the db is being 
;; used and to shutdown after sometime if it is not.
;;
(define (zmq-transport:keep-running)
  ;; if none running or if > 20 seconds since 
  ;; server last used then start shutdown
  ;; This thread waits for the server to come alive
  (let* ((server-info (let loop ()
			(let ((sdat #f))
			  (mutex-lock! *heartbeat-mutex*)
			  (set! sdat *server-info*)
			  (mutex-unlock! *heartbeat-mutex*)
			  (if sdat sdat
			      (begin
				(debug:print 12 "WARNING: server not started yet, waiting few seconds before trying again")
				(sleep 4)
				(loop))))))
	 (iface       (cadr server-info))
	 (pullport    (caddr server-info))
	 (pubport     (cadddr server-info)) ;; id interface pullport pubport)
	 ;; (zmq-sockets (zmq-transport:client-connect iface pullport pubport))
	 (last-access 0))
    (debug:print-info 11 "heartbeat started for zmq server on " iface " " pullport " " pubport)
    (let loop ((count 0))
      (thread-sleep! 4) ;; no need to do this very often
      ;; NB// sync currently does NOT return queue-length
      ;; GET REAL QUEUE LENGTH FROM THE VARIABLE
      (let ((queue-len 0)) ;; FOR NOW DO NOT DO THIS (cdb:client-call zmq-sockets 'sync #t 1)))
      ;; (print "Server running, count is " count)
	(if (< count 1) ;; 3x3 = 9 secs aprox
	    (loop (+ count 1)))

	;; NOTE: Get rid of this mechanism! It really is not needed...
	(open-run-close tasks:server-update-heartbeat tasks:open-db (car server-info))

	;; (if ;; (or (> numrunning 0) ;; stay alive for two days after last access
	(mutex-lock! *heartbeat-mutex*)
	(set! last-access *last-db-access*)
	(mutex-unlock! *heartbeat-mutex*)
	(if (> (+ last-access
		  ;; (* 50 60 60)    ;; 48 hrs
		  ;; 60              ;; one minute
		  ;; (* 60 60)       ;; one hour
		  (* 45 60)          ;; 45 minutes, until the db deletion bug is fixed.
		  )
	       (current-seconds))
	    (begin
	      (debug:print-info 2 "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
	      (loop 0))
	    (begin
	      (debug:print-info 0 "Starting to shutdown the server.")
	      ;; need to delete only *my* server entry (future use)
	      (set! *time-to-exit* #t)
	      (open-run-close tasks:server-deregister-self tasks:open-db (get-host-name))
	      (thread-sleep! 1)
	      (debug:print-info 0 "Max cached queries was " *max-cache-size*)
	      (debug:print-info 0 "Server shutdown complete. Exiting")
	      (exit)))))))

(define (zmq-transport:find-free-port-and-open iface s port stype #!key (trynum 50))
  (let ((s (if s s (make-socket stype)))
        (p (if (number? port) port 5555))
        (old-handler (current-exception-handler)))
    (handle-exceptions
     exn
     (begin
       (debug:print 0 "Failed to bind to port " p ", trying next port")
       (debug:print 0 "   EXCEPTION: " ((condition-property-accessor 'exn 'message) exn))
       ;; (old-handler)
       ;; (print-call-chain)
       (if (> trynum 0)
           (zmq-transport:find-free-port-and-open iface s (+ p 1) trynum: (- trynum 1))
           (debug:print-info 0 "Tried ports up to " p 
                             " but all were in use. Please try a different port range by starting the server with parameter \" -port N\" where N is the starting port number to use"))
       (exit)) ;; To exit or not? That is the question.
     (let ((zmq-url (conc "tcp://" iface ":" p)))
       (debug:print 2 "Trying to start server on " zmq-url)
       (bind-socket s zmq-url)
       (list iface s port)))))

(define (zmq-transport:setup-ports ipaddrstr startport)
  (let* ((s1 (zmq-transport:find-free-port-and-open ipaddrstr #f startport 'pull))
         (p1 (caddr s1))
         (s2 (zmq-transport:find-free-port-and-open ipaddrstr #f (+ 1 (if p1 p1 (+ startport 1))) 'pub))
         (p2 (caddr s2)))
    (set! *runremote* #f)
    (debug:print 0 "Server started on " ipaddrstr " ports " p1 " and " p2)
    (mutex-lock! *heartbeat-mutex*)
    (set! *server-info* (open-run-close tasks:server-register 
					tasks:open-db 
					(current-process-id) 
					ipaddrstr p1 
					0 
					'live
					'zmq
					pubport: p2))
    (debug:print-info 11 "*server-info* set to " *server-info*)
    (mutex-unlock! *heartbeat-mutex*)
    (list s1 s2)))

(define (zmq-transport:mk-signature)
  (message-digest-string (md5-primitive) 
			 (with-output-to-string
			   (lambda ()
			     (write (list (current-directory)
					  (argv)))))))

;;======================================================================
;; S E R V E R   U T I L I T I E S 
;;======================================================================

;;======================================================================
;; C L I E N T S
;;======================================================================

;; 
(define (zmq-transport:client-socket-connect iface port #!key (context #f)(type 'req)(subscriptions '()))
  (debug:print-info 3 "client-connect " iface ":" port ", type=" type ", subscriptions=" subscriptions)
  (let ((connect-ok #f)
	(zmq-socket (if context 
			(make-socket type context)
			(make-socket type)))
	(conurl     (zmq-transport:make-server-url (list iface port))))
    (if (socket? zmq-socket)
     (begin
	  ;; first apply subscriptions
	  (for-each (lambda (subscription)
		      (debug:print 2 "Subscribing to " subscription)
		      (socket-option-set! zmq-socket 'subscribe subscription))
		    subscriptions)
	  (connect-socket zmq-socket conurl)
	  zmq-socket)
	(begin
	  (debug:print 0 "ERROR: Failed to open socket to " conurl)
	  #f))))

(define (zmq-transport:client-connect iface pullport pubport)
  (let* ((push-socket (zmq-transport:client-socket-connect iface pullport type: 'push))
	 (sub-socket  (zmq-transport:client-socket-connect iface pubport
						    type: 'sub
						    subscriptions: (list (server:get-client-signature) "all")))
	 (zmq-sockets (vector push-socket sub-socket))
	 (login-res   #f))
    (debug:print-info 11 "zmq-transport:client-connect started. Next is login")
    (set! login-res (server:client-login zmq-sockets))
    (if (and (not (null? login-res))
	     (car login-res))
	(begin
	  (debug:print-info 2 "Logged in and connected to " iface ":" pullport "/" pubport ".")
	  (set! *runremote* zmq-sockets)
	  zmq-sockets)
	(begin
	  (debug:print-info 2 "Failed to login or connect to " conurl)
	  (set! *runremote* #f)
	  #f))))

;; run zmq-transport:keep-running in a parallel thread to monitor that the db is being 
;; used and to shutdown after sometime if it is not.
;;
(define (zmq-transport:keep-running)
  ;; if none running or if > 20 seconds since 
  ;; server last used then start shutdown
  ;; This thread waits for the server to come alive
  (let* ((server-info (let loop ()
                        (let ((sdat #f))
                          (mutex-lock! *heartbeat-mutex*)
                          (set! sdat *runremote*)
                          (mutex-unlock! *heartbeat-mutex*)
                          (if sdat sdat
                              (begin
                                (sleep 4)
                                (loop))))))
         (iface       (car server-info))
         (port        (cadr server-info))
         (last-access 0)
	 (tdb         (tasks:open-db))
	 (spid        (tasks:server-get-server-id tdb #f iface port #f)))
    (print "Keep-running got server pid " spid ", using iface " iface " and port " port)
    (let loop ((count 0))
      (thread-sleep! 4) ;; no need to do this very often
      ;; NB// sync currently does NOT return queue-length
      (let () ;; (queue-len (cdb:client-call server-info 'sync #t 1)))
      ;; (print "Server running, count is " count)
        (if (< count 1) ;; 3x3 = 9 secs aprox
            (loop (+ count 1)))
        
        ;; NOTE: Get rid of this mechanism! It really is not needed...
        (tasks:server-update-heartbeat tdb spid)
      
        ;; (if ;; (or (> numrunning 0) ;; stay alive for two days after last access
        (mutex-lock! *heartbeat-mutex*)
        (set! last-access *last-db-access*)
        (mutex-unlock! *heartbeat-mutex*)
        (if (> (+ last-access
                  ;; (* 50 60 60)    ;; 48 hrs
                  ;; 60              ;; one minute
                  ;; (* 60 60)       ;; one hour
                  (* 45 60)          ;; 45 minutes, until the db deletion bug is fixed.
                  )
               (current-seconds))
            (begin
              (debug:print-info 2 "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
              (loop 0))
            (begin
              (debug:print-info 0 "Starting to shutdown the server.")
              ;; need to delete only *my* server entry (future use)
              (set! *time-to-exit* #t)
              (tasks:server-deregister-self tdb (get-host-name))
              (thread-sleep! 1)
              (debug:print-info 0 "Max cached queries was " *max-cache-size*)
              (debug:print-info 0 "Server shutdown complete. Exiting")
              (exit)))))))

;; all routes though here end in exit ...
(define (zmq-transport:launch)
  (if (not *toppath*)
      (if (not (setup-for-run))
	  (begin
	    (debug:print 0 "ERROR: cannot find megatest.config, exiting")
	    (exit))))
  (debug:print-info 2 "Starting zmq server")
  (if *toppath* 
      (let* (;; (th1 (make-thread (lambda ()
	     ;;      	       (let ((server-info #f))
	     ;;      		 ;; wait for the server to be online and available
	     ;;      		 (let loop ()
	     ;;			   (debug:print-info 2 "Waiting for the server to come online before starting heartbeat")
	     ;;      		   (thread-sleep! 2)
	     ;;      		   (mutex-lock! *heartbeat-mutex*)
	     ;;      		   (set! server-info *server-info* )
	     ;;      		   (mutex-unlock! *heartbeat-mutex*)
	     ;;      		   (if (not server-info)(loop)))
	     ;;			 (debug:print 2 "Server alive, starting self-ping")
	     ;;      		 (zmq-transport:self-ping server-info)
	     ;;      		 ))
	     ;;      	     "Self ping"))
	     (th2 (make-thread (lambda ()
				 (zmq-transport:run 
				  (if (args:get-arg "-server")
				      (args:get-arg "-server")
				      "-"))) "Server run"))
	     ;; (th3 (make-thread (lambda ()(zmq-transport:keep-running)) "Keep running"))
	     )
	(set! *client-non-blocking-mode* #t)
	;; (thread-start! th1)
	(thread-start! th2)
	;; (thread-start! th3)
	(set! *didsomething* #t)
	;; (thread-join! th3)
	(thread-join! th2)
	)
      (debug:print 0 "ERROR: Failed to setup for megatest")))

(define (zmq-transport:client-signal-handler signum)
  (handle-exceptions
   exn
   (debug:print " ... exiting ...")
   (let ((th1 (make-thread (lambda ()
			     (if (not *received-response*)
				 (receive-message* *runremote*))) ;; flush out last call if applicable
			   "eat response"))
	 (th2 (make-thread (lambda ()
			     (debug:print 0 "ERROR: Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
			     (thread-sleep! 3) ;; give the flush three seconds to do it's stuff
			     (debug:print 0 "       Done.")
			     (exit 4))
			   "exit on ^C timer")))
     (thread-start! th2)
     (thread-start! th1)
     (thread-join! th2))))

(define (zmq-transport:client-launch)
  (set-signal-handler! signal/int zmq-transport:client-signal-handler)
   (if (zmq-transport:client-setup)
       (debug:print-info 2 "connected as client")
       (begin
	 (debug:print 0 "ERROR: Failed to connect as client")
	 (exit))))

;;======================================================================
;; Defunct functions
;;======================================================================

;; ping a server and return number of clients or #f (if no response)
;; NOT IN USE!
(define (zmq-transport:ping host port #!key (secs 10)(return-socket #f))
  (cdb:use-non-blocking-mode
   (lambda ()
     (let* ((res #f)
	    (th1 (make-thread
		  (lambda ()
		    (let* ((zmq-context (make-context 1))
			   (zmq-socket  (zmq-transport:client-connect host port context: zmq-context)))
		      (if zmq-socket
			  (if (zmq-transport:client-login zmq-socket)
			      (let ((numclients (cdb:num-clients zmq-socket)))
				(if (not return-socket)
				    (begin
				      (zmq-transport:client-logout zmq-socket)
				      (close-socket  zmq-socket)))
				(set! res (list #t numclients (if return-socket zmq-socket #f))))
			      (begin
				;; (close-socket zmq-socket)
				(set! res (list #f "CAN'T LOGIN" #f))))
			  (set! res (list #f "CAN'T CONNECT" #f)))))
		  "Ping: th1"))
	    (th2 (make-thread
		  (lambda ()
		    (let loop ((count 1))
		      (debug:print-info 1 "Ping " count " server on " host " at port " port)
		      (thread-sleep! 2)
		      (if (< count (/ secs 2))
			  (loop (+ count 1))))
		    ;; (thread-terminate! th1)
		    (set! res (list #f "TIMED OUT" #f)))
		  "Ping: th2")))
       (thread-start! th2)
       (thread-start! th1)
       (handle-exceptions
	exn
	(set! res (list #f "TIMED OUT" #f))
	(thread-join! th1 secs))
       res))))

;; (define (zmq-transport:self-ping server-info)
;;   ;; server-info: server-id interface pullport pubport
;;   (let ((iface    (list-ref server-info 1))
;; 	(pullport (list-ref server-info 2))
;; 	(pubport  (list-ref server-info 3)))
;;     (zmq-transport:client-connect iface pullport pubport)
;;     (let loop ()
;;       (thread-sleep! 2)
;;       (cdb:client-call *runremote* 'ping #t)
;;       (debug:print 4 "zmq-transport:self-ping - I'm alive on " iface ":" pullport "/" pubport "!")
;;       (mutex-lock! *heartbeat-mutex*)
;;       (set! *server-loop-heart-beat* (current-seconds))
;;       (mutex-unlock! *heartbeat-mutex*)
;;       (loop))))
    
(define (zmq-transport:reply pubsock target query-sig success/fail result)
  (debug:print-info 11 "zmq-transport:reply target=" target ", result=" result)
  (send-message pubsock target send-more: #t)
  (send-message pubsock (db:obj->string (vector success/fail query-sig result))))