1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Exercise multi-process aspects of lock. Generate a bunch of parallel
10
# TEST testers that try to randomly obtain locks; make sure that the locks
11
# TEST correctly protect corresponding objects.
12
proc lock003 { {iter 500} {max 1000} {procs 5} } {
21
set conflicts { 0 0 0 0 0 1 0 1 1}
24
puts "Lock003: Multi-process random lock test"
26
# Clean up after previous runs
29
# Open/create the lock region
30
puts "\tLock003.a: Create environment"
31
set e [berkdb_env -create -lock -home $testdir]
32
error_check_good env_open [is_substr $e env] 1
33
$e lock_id_set $lock_curid $lock_maxid
35
error_check_good env_close [$e close] 0
37
# Now spawn off processes
40
for { set i 0 } {$i < $procs} {incr i} {
41
if { [llength $seeds] == $procs } {
42
set s [lindex $seeds $i]
45
# $test_path/wrap.tcl \
46
# lockscript.tcl $testdir/$i.lockout\
47
# $testdir $iter $objs $wait $ldegree $reads &"
48
set p [exec $tclsh_path $test_path/wrap.tcl \
49
lockscript.tcl $testdir/lock003.$i.out \
50
$testdir $iter $objs $wait $ldegree $reads &]
54
puts "\tLock003.b: $procs independent processes now running"
55
watch_procs $pidlist 30 10800
57
# Check for test failure
58
set e [eval findfail [glob $testdir/lock003.*.out]]
59
error_check_good "FAIL: error message(s) in log files" $e 0
62
for { set i 0 } {$i < $procs} {incr i} {
63
fileremove -f $testdir/lock003.$i.out
67
# Create and destroy flag files to show we have an object locked, and
68
# verify that the correct files exist or don't exist given that we've
69
# just read or write locked a file.
70
proc lock003_create { rw obj } {
73
set pref $testdir/L3FLAG
74
set f [open $pref.$rw.[pid].$obj w]
78
proc lock003_destroy { obj } {
81
set pref $testdir/L3FLAG
82
set f [glob -nocomplain $pref.*.[pid].$obj]
83
error_check_good l3_destroy [llength $f] 1
87
proc lock003_vrfy { rw obj } {
90
set pref $testdir/L3FLAG
91
if { [string compare $rw "write"] == 0 } {
92
set fs [glob -nocomplain $pref.*.*.$obj]
93
error_check_good "number of other locks on $obj" [llength $fs] 0
95
set fs [glob -nocomplain $pref.write.*.$obj]
96
error_check_good "number of write locks on $obj" [llength $fs] 0