configure: Use pkg-config if possible
[jimtcl.git] / tests / lock.test
blob92778d18c50300d49d524c6c8dc2b3f12ad80687
1 # This test file covers POSIX file locking
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # for errors.  No output means no errors were found.
7 # Copyright (c) 2003-2009 Donal K. Fellows
8 # See the file "license.terms" for information on usage and redistribution of
9 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 source [file dirname [info script]]/testing.tcl
13 needs constraint jim
14 # Really we want to check if locking is supported, but there
15 # is no easy way to do that, so use the existence of os.wait as a proxy
16 needs cmd os.wait
18 set fh [open locktest.file w]
20 test lock-1.1 {grab lock} {
21         $fh lock
22 } 1
24 test lock-1.2 {grab lock again} {
25         $fh lock
26 } 1
28 test lock-1.j {release lock} {
29         $fh unlock
30 } 1
32 test lock-1.4 {release lock again} {
33         $fh unlock
34 } 1
36 test lock-1.5 {grab lock from sub-process} {
37         # Run a child process that grabs the lock for 0.5 seconds
38         set pid [exec [info nameofexecutable] -e {set fh [open locktest.file r+]; $fh lock; sleep 0.5} >/dev/null &]
39         sleep 0.1
40         # Try to grab the lock - should fail
41         set stat [$fh lock]
42         sleep 0.5
43         set stat
44 } 0
46 $fh close
47 file delete locktest.file
49 testreport