proc fop001 { method { inmem 0 } args } {
source ./include.tcl
set args [convert_args $method $args]
set omethod [convert_method $method]
if { $inmem == 0 } {
set tnum "001"
set string "regular named databases"
set operator do_op
} else {
set tnum "007"
set string "in-memory named databases"
set operator do_inmem_op
}
puts "\nFop$tnum: ($method)\
Two file system ops in one transaction for $string."
set exists {a b}
set noexist {foo bar}
set open {}
set cases {}
set ops {rename remove open open_create open_excl truncate}
foreach retval { 0 "file exists" "no such file" } {
foreach op1 {rename remove open open_excl \
open_create truncate} {
foreach op2 $ops {
append cases " " [create_tests $op1 $op2 \
$exists $noexist $open $retval]
}
}
}
foreach retval { 0 "file exists" "no such file" } {
foreach op1 { rename remove open open_excl } {
foreach op2 $ops {
append cases " " [create_badtests $op1 $op2 \
$exists $noexist $open $retval]
}
}
}
set testid 0
foreach case $cases {
env_cleanup $testdir
incr testid
set op1 [lindex [lindex $case 0] 0]
set names1 [lindex [lindex $case 0] 1]
set res1 [lindex [lindex $case 0] 2]
set op2 [lindex [lindex $case 1] 0]
set names2 [lindex [lindex $case 1] 1]
set res2 [lindex [lindex $case 1] 2]
puts "\tFop$tnum.$testid: $op1 ($names1), then $op2 ($names2)."
foreach when { before after } {
set env [berkdb_env -create -home $testdir -txn]
error_check_good is_valid_env [is_valid_env $env] TRUE
if { $inmem == 0 } {
set dba [eval {berkdb_open -create} $omethod \
$args -env $env -auto_commit a]
} else {
set dba [eval {berkdb_open -create} $omethod \
$args -env $env -auto_commit { "" a }]
}
error_check_good dba_open [is_valid_db $dba] TRUE
error_check_good dba_put [$dba put 1 a] 0
error_check_good dba_close [$dba close] 0
if { $inmem == 0 } {
set dbb [eval {berkdb_open -create} $omethod \
$args -env $env -auto_commit b]
} else {
set dbb [eval {berkdb_open -create} $omethod \
$args -env $env -auto_commit { "" b }]
}
error_check_good dbb_open [is_valid_db $dbb] TRUE
error_check_good dbb_put [$dbb put 1 b] 0
error_check_good dbb_close [$dbb close] 0
foreach end {abort commit} {
puts "\t\tFop$tnum.$testid:\
$end $when closing database."
set txn [$env txn]
set result1 [$operator \
$omethod $op1 $names1 $txn $env $args]
if { $res1 == 0 } {
error_check_good \
op1_should_succeed $result1 $res1
} else {
set error [extract_error $result1]
error_check_good \
op1_wrong_failure $error $res1
}
set result2 [$operator \
$omethod $op2 $names2 $txn $env $args]
if { $res2 == 0 } {
error_check_good \
op2_should_succeed $result2 $res2
} else {
set error [extract_error $result2]
error_check_good \
op2_wrong_failure $error $res2
}
if { $when == "before" } {
error_check_good txn_$end [$txn $end] 0
if { $end == "abort" } {
database_exists \
$inmem $testdir a
database_exists \
$inmem $testdir b
}
close_db_handles
} else {
close_db_handles
error_check_good txn_$end [$txn $end] 0
if { $end == "abort" } {
database_exists \
$inmem $testdir a
database_exists \
$inmem $testdir b
}
}
}
error_check_good env_close [$env close] 0
error_check_good envremove \
[berkdb envremove -home $testdir] 0
env_cleanup $testdir
}
}
}
proc database_exists { inmem testdir name } {
if { $inmem == 1 } {
error_check_good db_exists [inmem_exists $testdir $name] 1
} else {
error_check_good db_exists [file exists $testdir/$name] 1
}
}
proc inmem_exists { dir filename } {
set infile 0
set islive 0
set name ""
set s [exec ./db_stat -MA -h $dir]
foreach i $s {
if { $i == "File" } {
set infile 1
set islive 1
set name ""
} elseif { $i == "Flags" } {
set infile 0
if { $name != "" && $islive } {
return 1
}
} elseif { $infile != 0 } {
incr infile
}
if { $islive && $i == "deadfile" } {
set islive 0
}
if { $infile == 3 } {
if { $i == $filename } {
set name $filename
}
}
}
return 0
}