7d74392642 2019-09-13 1: set file "//xvfs:/example/foo"
7d74392642 2019-09-13 2:
7d74392642 2019-09-13 3: set fd [open $file]
38bed7cee0 2019-09-13 4: seek $fd 0 end
38bed7cee0 2019-09-13 5: seek $fd -1 current
38bed7cee0 2019-09-13 6: set check [read $fd 1]
38bed7cee0 2019-09-13 7: if {$check != "\n"} {
38bed7cee0 2019-09-13 8: error "EXPECTED: (new line); GOT: [binary encode hex $check]"
38bed7cee0 2019-09-13 9: }
7d74392642 2019-09-13 10: close $fd
7d74392642 2019-09-13 11:
7d74392642 2019-09-13 12: set fd1 [open $file]
7d74392642 2019-09-13 13: set fd2 [open $file]
7d74392642 2019-09-13 14: set data1 [read $fd1]
7d74392642 2019-09-13 15: close $fd1
7d74392642 2019-09-13 16: set data2 [read $fd2]
7d74392642 2019-09-13 17: close $fd2
7d74392642 2019-09-13 18: if {$data1 != $data2} {
7d74392642 2019-09-13 19: error "EXPECTED match, differs"
7d74392642 2019-09-13 20: }
7d74392642 2019-09-13 21:
7d74392642 2019-09-13 22: set fd [open $file]
7d74392642 2019-09-13 23: seek $fd 0 end
7d74392642 2019-09-13 24: set size [tell $fd]
7d74392642 2019-09-13 25: close $fd
7d74392642 2019-09-13 26: set fd [open $file]
7d74392642 2019-09-13 27: set done false
7d74392642 2019-09-13 28: set calls 0
7d74392642 2019-09-13 29: set output ""
7d74392642 2019-09-13 30: fileevent $fd readable [list apply {{fd} {
7d74392642 2019-09-13 31: set pos [tell $fd]
7d74392642 2019-09-13 32: set x [read $fd 1]
7d74392642 2019-09-13 33: if {[string length $x] == 0} {
7d74392642 2019-09-13 34: set ::done true
7d74392642 2019-09-13 35: fileevent $fd readable ""
7d74392642 2019-09-13 36: }
7d74392642 2019-09-13 37:
7d74392642 2019-09-13 38: lappend ::output $pos
7d74392642 2019-09-13 39: incr ::calls
7d74392642 2019-09-13 40: }} $fd]
7d74392642 2019-09-13 41: vwait done
7d74392642 2019-09-13 42: if {$calls != ($size + 1)} {
7d74392642 2019-09-13 43: error "EXPECTED [expr {$size + 1}], got $calls"
7d74392642 2019-09-13 44: }
7d74392642 2019-09-13 45: if {[lsort -integer $output] != $output} {
7d74392642 2019-09-13 46: error "EXPECTED [lsort -integer $output], GOT $output"
7d74392642 2019-09-13 47: }
aa08a4a749 2019-09-14 48: close $fd
aa08a4a749 2019-09-14 49: update idle
38bed7cee0 2019-09-13 50:
38bed7cee0 2019-09-13 51: puts "ALL TESTS PASSED"