1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: lock003.tcl,v 11.19 2001/05/17 20:37:05 bostic Exp $
8
# Exercise multi-process aspects of lock. Generate a bunch of parallel
9
# testers that try to randomly obtain locks; make sure that the locks
10
# correctly protect corresponding objects.
11
proc lock003 { dir {iter 500} {max 1000} {procs 5} {ldegree 5} {objs 75} \
12
{reads 65} {wait 1} {conflicts { 3 0 0 0 0 0 1 0 1 1}} {seeds {}} } {
15
puts "Lock003: Multi-process random lock test"
17
# Clean up after previous runs
20
# Open/create the lock region
21
set e [berkdb env -create -lock -home $dir]
22
error_check_good env_open [is_substr $e env] 1
25
error_check_good env_close $ret 0
27
# Now spawn off processes
30
for { set i 0 } {$i < $procs} {incr i} {
31
if { [llength $seeds] == $procs } {
32
set s [lindex $seeds $i]
36
lockscript.tcl $dir/$i.lockout\
37
$dir $iter $objs $wait $ldegree $reads &"
38
set p [exec $tclsh_path $test_path/wrap.tcl \
39
lockscript.tcl $testdir/lock003.$i.out \
40
$dir $iter $objs $wait $ldegree $reads &]
44
puts "Lock003: $procs independent processes now running"
47
# Check for test failure
48
set e [eval findfail [glob $testdir/lock003.*.out]]
49
error_check_good "FAIL: error message(s) in log files" $e 0
52
for { set i 0 } {$i < $procs} {incr i} {
53
fileremove -f $dir/lock003.$i.out
57
# Create and destroy flag files to show we have an object locked, and
58
# verify that the correct files exist or don't exist given that we've
59
# just read or write locked a file.
60
proc lock003_create { rw obj } {
63
set pref $testdir/L3FLAG
64
set f [open $pref.$rw.[pid].$obj w]
68
proc lock003_destroy { obj } {
71
set pref $testdir/L3FLAG
72
set f [glob -nocomplain $pref.*.[pid].$obj]
73
error_check_good l3_destroy [llength $f] 1
77
proc lock003_vrfy { rw obj } {
80
set pref $testdir/L3FLAG
81
if { [string compare $rw "write"] == 0 } {
82
set fs [glob -nocomplain $pref.*.*.$obj]
83
error_check_good "number of other locks on $obj" [llength $fs] 0
85
set fs [glob -nocomplain $pref.write.*.$obj]
86
error_check_good "number of write locks on $obj" [llength $fs] 0