/ Check-in [cbf42365]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Various fixes for the wapptest.tcl script.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wapptest
Files: files | file ages | folders
SHA3-256: cbf423656047f0cb5200be6981a205e0ae206eef8263aa686f4a3621fb07fb57
User & Date: dan 2019-04-10 18:56:30
Context
2019-04-10
19:45
Have wapptest.tcl display the name, OS and architecture of the host. check-in: c47e53b4 user: dan tags: wapptest
18:56
Various fixes for the wapptest.tcl script. check-in: cbf42365 user: dan tags: wapptest
2019-04-09
19:53
Add test/wapptest.tcl, a wapp alternative to releasetest.tcl. check-in: a4af0c2f user: dan tags: wapptest
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to test/wapptest.tcl.

1
2
3
4
5

6

7

8
9
10
11
12
13
14
..
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
...
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
...
211
212
213
214
215
216
217

218
219
220
221
222
223
224
...
236
237
238
239
240
241
242













243
244
245
246
247

248
249
250
251
252
253
254
...
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
...
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
...
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
#!/bin/sh 
# \
exec wapptclsh "$0" ${1+"$@"}

#

#

#


# Variables set by the "control" form:
#
#   G(platform) - User selected platform.
#   G(test)     - Set to "Normal", "Veryquick", "Smoketest" or "Build-Only".
#   G(keep)     - Boolean. True to delete no files after each test.
#   G(msvc)     - Boolean. True to use MSVC as the compiler.
................................................................................
set G(platform) $::tcl_platform(os)-$::tcl_platform(machine)
set G(test)     Normal
set G(keep)     0
set G(msvc)     0
set G(tcl)      ""
set G(jobs)     3

set G(sqlite_version) unknown


# The root of the SQLite source tree.




#

set G(srcdir)   [file dirname [file dirname [info script]]]

# Either "config", "running", "stopped":
#
set G(state) "config"

# releasetest.tcl script
#
set G(releaseTest) [file join [file dirname [info script]] releasetest.tcl]

set G(cnt) 0

# package required wapp
source [file join [file dirname [info script]] wapp.tcl]

# Read the data from the releasetest_data.tcl script.
#
source [file join [file dirname [info script]] releasetest_data.tcl]

# Check to see if there are uncommitted changes in the SQLite source
# directory. Return true if there are, or false otherwise.
#
proc check_uncommitted {} {
  global G
  set ret 0
................................................................................
    set G(test.$name.errmsg) "Test did not complete"
    if {[file readable core]} {
      append G(test.$name.errmsg) " - core file exists"
    }
  }
}

proc slave_fileevent {name} {
  global G
  set fd $G(test.$name.channel)

  if {[eof $fd]} {
    fconfigure $fd -blocking 1
    set rc [catch { close $fd }]
    unset G(test.$name.channel)
    set G(test.$name.done) [clock seconds]
    set G(test.$name.nError) 0
    set G(test.$name.nTest) 0
    set G(test.$name.errmsg) ""
    if {$rc} {
      incr G(test.$name.nError)
    }
    if {[file exists $G(test.$name.log)]} {
      count_tests_and_errors $name $G(test.$name.log)
    }











  } else {
    set line [gets $fd]
    if {[string trim $line] != ""} { puts "Trace   : $name - \"$line\"" }
  }

  do_some_stuff
}
................................................................................
      incr nTest $G(test.$name.nTest)
      incr nConfig 
    }
    set G(result) "$nError errors from $nTest tests in $nConfig configurations."
    catch {
      append G(result) " SQLite version $G(sqlite_version)"
    }

  } else {
    set nLaunch [expr $G(jobs) - $nRunning]
    foreach j $G(test_array) {
      if {$nLaunch<=0} break
      set name [dict get $j config]
      if { ![info exists G(test.$name.channel)]
        && ![info exists G(test.$name.done)]
................................................................................
        flush $fd
        set G(test.$name.log) [file join [lindex $L 1] test.log]
        incr nLaunch -1
      }
    }
  }
}














proc generate_main_page {{extra {}}} {
  global G
  set_test_array


  wapp-trim {
    <html>
    <head>
      <link rel="stylesheet" type="text/css" href="style.css"/>
    </head>
    <body>
  }
................................................................................
      </div>
    }
  }

  wapp-trim {
      <div class=div id=controls> 
        <form action="control" method="post" name="control">
        <label> Platform: </label>
        <select id="control_platform" name="control_platform">
  }


  foreach platform [array names ::Platforms] {
    set selected ""
    if {$platform==$G(platform)} { set selected " selected=1" }

    wapp-subst "<option $selected>$platform</option>"


  }

















  wapp-trim {
        </select>
        <label> Test: </label>
        <select id="control_test" name="control_test">




  }
  foreach test [list Normal Veryquick Smoketest Build-Only] {
    set selected ""
    if {$test==$G(test)} { set selected " selected=1" }
    wapp-subst "<option $selected>$test</option>"
  }
  wapp-trim [subst -nocommands {
        </select>

        <label> Tcl: </label>
        <input id="control_tcl" name="control_tcl"></input>

        <label> Keep files: </label>
        <input id="control_keep" name="control_keep" type=checkbox value=1>
        </input>
        <label> Use MSVC: </label>
        <input id="control_msvc" name="control_msvc" type=checkbox value=1>
        </input>
        <hr>
        <div class=right>
          <label> Jobs: </label>
          <select id="control_jobs" name="control_jobs">
  }]
  for {set i 1} {$i <= 8} {incr i} {
    if {$G(jobs)==$i} {

      wapp-trim {
        <option selected=1>%string($i)</option>

      }
    } else {
      wapp-trim {
        <option>%string($i)</option>


      }

    }
  }

  wapp-trim {
          </select>
          <input id=control_go name=control_go type=submit value="Run Tests!">
          </input>
        </div>
     </form>
      </div>
      <div class=div id=tests>    
      <table>



  }









  foreach t $G(test_array) {
    set config [dict get $t config]
    set target [dict get $t target]

    set class "testwait"
    set seconds ""

................................................................................
        <tr class=testfail>
        <td class=testfield>
        <td class=testfield colspan=3> %html($errmsg)
      }
    }
  }

  wapp-trim {
      </table>
      </div>
  }
  if {[info exists G(result)]} {
    set res $G(result)
    wapp-trim {
      <div class=div id=log> %string($res) </div>
    }
  }
  wapp-trim {
    <script src="script.js"></script>
    </body>
    </html>
  }
  incr G(cnt)
}


proc wapp-default {} {
  generate_main_page
}



proc wapp-page-control {} {
  global G


  foreach v {platform test tcl jobs keep msvc} {






    if {[wapp-param-exists control_$v]} {
      set G($v) [wapp-param control_$v]
    } else {
      set G($v) 0
    }
  }

  if {[wapp-param-exists control_go]} {
    # This is an actual "run test" command, not just a change of 
    # configuration!
    set_test_array
    set ::G(state) "running"
  }





















  if {$::G(state) == "running"} {
    do_some_stuff
  }

  wapp-redirect /
}





proc wapp-page-style.css {} {
  wapp-subst {
    .div {
      border: 3px groove #444444;
      margin: 1em;
      padding: 1em;
    }


















    .warning {
      text-align:center;
      color: red;
      font-size: 2em;
      font-weight: bold;
    }

    .right {
    }

    .testfield {
      padding-right: 10ex;

    }

    .testwait {}
    .testrunning { color: blue }
    .testdone { color: green }
    .testfail { color: red }



  }
}








proc wapp-page-script.js {} {


  set tcl $::G(tcl)
  set keep $::G(keep)
  set msvc $::G(msvc)
  
  wapp-subst {
    var lElem = \["control_platform", "control_test", "control_msvc", "control_jobs"\];


    lElem.forEach(function(e) {
      var elem = document.getElementById(e);
      elem.addEventListener("change", function() { control.submit() } );
    })

    elem = document.getElementById("control_tcl");
    elem.value = "%string($tcl)"
................................................................................
    elem = document.getElementById("control_keep");
    elem.checked = %string($keep);

    elem = document.getElementById("control_msvc");
    elem.checked = %string($msvc);
  }

  if {$::G(state)!="config"} {
    wapp-subst {
      var lElem = \["control_platform", "control_test", 
          "control_tcl", "control_keep", "control_msvc", "control_go"
      \];
      lElem.forEach(function(e) {
        var elem = document.getElementById(e);
        elem.disabled = true;
      })
    }
  }
}


























proc wapp-page-env {} {
  wapp-allow-xorigin-params
  wapp-trim {
    <h1>Wapp Environment</h1>\n<pre>
    <pre>%html([wapp-debug-env])</pre>
  }
}






proc wapp-page-log {} {
  set log [string range [wapp-param REQUEST_URI] 5 end]
  set fd [open $log]
  set data [read $fd]
  close $fd
  wapp-trim {
    <pre>
    %html($data)
    </pre>
  }
}


wapp-start $argv





|
>
|
>

>







 







|
>

<
>
>
>
>
|
>
|

<
<
<
<
|
<
|

|

|
|
|
<
<
<







 







|

<
<
<
<
<
<










>
>
>
>
>
>
>
>
>
>
>







 







>







 







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





>







 







<
<

>
>
|
|
<
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<
<
<
>
>
>
>

<
<
<
<
|
|
<
>


<






<
<
<
<
<
<
<
>
|
<
>
|
<
|
<
>
>
|
>
|
<
>

<
<
<
|
<
<
<
<
>
>
>

>
>
>
>
>
>
>
>
>







 







|
<
<
|



|


<
<
<
<
|
<
|
>
|
<
<
<
>
>
|


>
>
|
>
>
>
>
>
>


<
<



|
|
<



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




<



>
>
>
>







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








<
<
<


>






>
>
>



>
>
>
>
>
>
>
|
>






|
>
>







 







|


|







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








>
>
>
>
>












>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
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
...
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
...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
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
...
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
...
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
...
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
#!/bin/sh 
# \
exec wapptclsh "$0" ${1+"$@"}

# package required wapp
source [file join [file dirname [info script]] wapp.tcl]

# Read the data from the releasetest_data.tcl script.
#
source [file join [file dirname [info script]] releasetest_data.tcl]

# Variables set by the "control" form:
#
#   G(platform) - User selected platform.
#   G(test)     - Set to "Normal", "Veryquick", "Smoketest" or "Build-Only".
#   G(keep)     - Boolean. True to delete no files after each test.
#   G(msvc)     - Boolean. True to use MSVC as the compiler.
................................................................................
set G(platform) $::tcl_platform(os)-$::tcl_platform(machine)
set G(test)     Normal
set G(keep)     0
set G(msvc)     0
set G(tcl)      ""
set G(jobs)     3

proc wapptest_init {} {
  global G


  set lSave [list platform test keep msvc tcl jobs] 
  foreach k $lSave { set A($k) $G($k) }
  array unset G
  foreach k $lSave { set G($k) $A($k) }

  # The root of the SQLite source tree.
  set G(srcdir)   [file dirname [file dirname [info script]]]





  # releasetest.tcl script

  set G(releaseTest) [file join [file dirname [info script]] releasetest.tcl]

  set G(sqlite_version) "unknown"

  # Either "config", "running" or "stopped":
  set G(state) "config"
}




# Check to see if there are uncommitted changes in the SQLite source
# directory. Return true if there are, or false otherwise.
#
proc check_uncommitted {} {
  global G
  set ret 0
................................................................................
    set G(test.$name.errmsg) "Test did not complete"
    if {[file readable core]} {
      append G(test.$name.errmsg) " - core file exists"
    }
  }
}

proc slave_test_done {name rc} {
  global G






  set G(test.$name.done) [clock seconds]
  set G(test.$name.nError) 0
  set G(test.$name.nTest) 0
  set G(test.$name.errmsg) ""
  if {$rc} {
    incr G(test.$name.nError)
  }
  if {[file exists $G(test.$name.log)]} {
    count_tests_and_errors $name $G(test.$name.log)
  }
}

proc slave_fileevent {name} {
  global G
  set fd $G(test.$name.channel)

  if {[eof $fd]} {
    fconfigure $fd -blocking 1
    set rc [catch { close $fd }]
    unset G(test.$name.channel)
    slave_test_done $name $rc
  } else {
    set line [gets $fd]
    if {[string trim $line] != ""} { puts "Trace   : $name - \"$line\"" }
  }

  do_some_stuff
}
................................................................................
      incr nTest $G(test.$name.nTest)
      incr nConfig 
    }
    set G(result) "$nError errors from $nTest tests in $nConfig configurations."
    catch {
      append G(result) " SQLite version $G(sqlite_version)"
    }
    set G(state) "stopped"
  } else {
    set nLaunch [expr $G(jobs) - $nRunning]
    foreach j $G(test_array) {
      if {$nLaunch<=0} break
      set name [dict get $j config]
      if { ![info exists G(test.$name.channel)]
        && ![info exists G(test.$name.done)]
................................................................................
        flush $fd
        set G(test.$name.log) [file join [lindex $L 1] test.log]
        incr nLaunch -1
      }
    }
  }
}

proc generate_select_widget {label id lOpt opt} {
  wapp-trim {
    <label> %string($label) </label>
    <select id=%string($id) name=%string($id)>
  }
  foreach o $lOpt {
    set selected ""
    if {$o==$opt} { set selected " selected=1" }
    wapp-subst "<option $selected>$o</option>"
  }
  wapp-trim { </select> }
}

proc generate_main_page {{extra {}}} {
  global G
  set_test_array

  # <meta http-equiv="refresh" content="5; URL=/">
  wapp-trim {
    <html>
    <head>
      <link rel="stylesheet" type="text/css" href="style.css"/>
    </head>
    <body>
  }
................................................................................
      </div>
    }
  }

  wapp-trim {
      <div class=div id=controls> 
      <form action="control" method="post" name="control">


  }

  # Build the "platform" select widget. 
  set lOpt [array names ::Platforms]
  generate_select_widget Platform control_platform $lOpt $G(platform)


  # Build the "test" select widget. 
  set lOpt [list Normal Veryquick Smoketest Build-Only] 
  generate_select_widget Test control_test $lOpt $G(test)

  # Build the "jobs" select widget. Options are 1 to 8.
  generate_select_widget Jobs control_jobs {1 2 3 4 5 6 7 8} $G(jobs)

  switch $G(state) {
    config {
      set txt "Run Tests!"
      set id control_run
    }
    running {
      set txt "STOP Tests!"
      set id control_stop
    }
    stopped {
      set txt "Reset!"
      set id control_reset
    }
  }
  wapp-trim {



    <div class=right>
    <input id=%string($id) name=%string($id) type=submit value="%string($txt)">
    </input>
    </div>
  }





  wapp-trim {

  <br><br>
        <label> Tcl: </label>
        <input id="control_tcl" name="control_tcl"></input>

        <label> Keep files: </label>
        <input id="control_keep" name="control_keep" type=checkbox value=1>
        </input>
        <label> Use MSVC: </label>
        <input id="control_msvc" name="control_msvc" type=checkbox value=1>
        </input>







  }
  wapp-trim {

     </form>
  }

  wapp-trim {

     </div>
     <div class=div2 id=tests>
  }
  wapp-page-tests


  set script "script/$G(state).js"
  wapp-trim {



    </div>




      <script src=%string($script)></script>
    </body>
    </html>
  }
}

proc wapp-default {} {
  generate_main_page
}

proc wapp-page-tests {} {
  global G
  wapp-trim { <table> }
  foreach t $G(test_array) {
    set config [dict get $t config]
    set target [dict get $t target]

    set class "testwait"
    set seconds ""

................................................................................
        <tr class=testfail>
        <td class=testfield>
        <td class=testfield colspan=3> %html($errmsg)
      }
    }
  }

  wapp-trim { </table> }



  if {[info exists G(result)]} {
    set res $G(result)
    wapp-trim {
      <div class=border id=result> %string($res) </div>
    }
  }




}


# URI: /control
#



# Whenever the form at the top of the application page is submitted, it
# is submitted here.
#
proc wapp-page-control {} {
  global G
  catch { puts [wapp-param control_msvc] }
  if {$::G(state)=="config"} {
    set lControls [list platform test tcl jobs keep msvc]
    set G(msvc) 0
    set G(keep) 0
  } else {
    set lControls [list jobs]
  }
  foreach v $lControls {
    if {[wapp-param-exists control_$v]} {
      set G($v) [wapp-param control_$v]


    }
  }

  if {[wapp-param-exists control_run]} {
    # This is a "run test" command.

    set_test_array
    set ::G(state) "running"
  }

  if {[wapp-param-exists control_stop]} {
    # A "STOP tests" command.
    set G(state) "stopped"
    set G(result) "Test halted by user"
    foreach j $G(test_array) {
      set name [dict get $j config]
      if { [info exists G(test.$name.channel)] } {
        close $G(test.$name.channel)
        unset G(test.$name.channel)
        slave_test_done $name 1
      }
    }
  }

  if {[wapp-param-exists control_reset]} {
    # A "reset app" command.
    set G(state) "config"
    wapptest_init
  }

  if {$::G(state) == "running"} {
    do_some_stuff
  }

  wapp-redirect /
}

# URI: /style.css
#
# Return the stylesheet for the application main page.
#
proc wapp-page-style.css {} {
  wapp-subst {
    .div {
      border: 3px groove #444444;
      margin: 1em;
      padding: 1em;
    }

    .border {
      border: 3px groove #444444;
      padding: 1em;
      margin-top: 1em;
      margin-bottom: 1em;
    }

    .div2 {
      margin: 1em;
    }

    table {
      padding: 1em;
      width:100%;
      border: 3px groove #444444;
    }

    .warning {
      text-align:center;
      color: red;
      font-size: 2em;
      font-weight: bold;
    }




    .testfield {
      padding-right: 10ex;
      white-space: nowrap;
    }

    .testwait {}
    .testrunning { color: blue }
    .testdone { color: green }
    .testfail { color: red }

    .right { float: right; }

  }
}

# URI: /script/${state}.js
#
# The last part of this URI is always "config.js", "running.js" or 
# "stopped.js", depending on the state of the application. It returns
# the javascript part of the front-end for the requested state to the
# browser.
#
proc wapp-page-script {} {
  regexp {[^/]*$} [wapp-param REQUEST_URI] script

  set tcl $::G(tcl)
  set keep $::G(keep)
  set msvc $::G(msvc)
  
  wapp-subst {
    var lElem = \["control_platform", "control_test", "control_msvc", 
        "control_jobs"
    \];
    lElem.forEach(function(e) {
      var elem = document.getElementById(e);
      elem.addEventListener("change", function() { control.submit() } );
    })

    elem = document.getElementById("control_tcl");
    elem.value = "%string($tcl)"
................................................................................
    elem = document.getElementById("control_keep");
    elem.checked = %string($keep);

    elem = document.getElementById("control_msvc");
    elem.checked = %string($msvc);
  }

  if {$script != "config.js"} {
    wapp-subst {
      var lElem = \["control_platform", "control_test", 
          "control_tcl", "control_keep", "control_msvc"
      \];
      lElem.forEach(function(e) {
        var elem = document.getElementById(e);
        elem.disabled = true;
      })
    }
  }

  if {$script == "running.js"} {
    wapp-subst {
      function reload_tests() {
        fetch('tests')
          .then( data => data.text() )
          .then( data => {
            document.getElementById("tests").innerHTML = data;
          })
          .then( data => {
            if( document.getElementById("result") ){
              document.location = document.location;
            } else {
              setTimeout(reload_tests, 1000)
            }
          });
      }

      setTimeout(reload_tests, 1000)
    }
  }
}

# URI: /env
#
# This is for debugging only. Serves no other purpose.
#
proc wapp-page-env {} {
  wapp-allow-xorigin-params
  wapp-trim {
    <h1>Wapp Environment</h1>\n<pre>
    <pre>%html([wapp-debug-env])</pre>
  }
}

# URI: /log/dirname/test.log
#
# This URI reads file "dirname/test.log" from disk, wraps it in a <pre>
# block, and returns it to the browser. Use for viewing log files.
#
proc wapp-page-log {} {
  set log [string range [wapp-param REQUEST_URI] 5 end]
  set fd [open $log]
  set data [read $fd]
  close $fd
  wapp-trim {
    <pre>
    %html($data)
    </pre>
  }
}

wapptest_init
wapp-start $argv