1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2003,2008 Oracle.  All rights reserved.
4#
5# $Id: fopscript.tcl,v 12.7 2008/01/08 20:58:53 bostic Exp $
6#
7# Fop006 script - test of fileops in multiple transactions
8# Usage: fopscript
9# omethod: access method for database
10# op: file operation to perform
11# end: how to end the transaction (abort or commit)
12# result: expected result of the transaction
13# names: name(s) of files to operate on
14# args: additional args to do_op
15
16source ./include.tcl
17source $test_path/test.tcl
18source $test_path/testutils.tcl
19
20set usage "fopscript operator omethod op end result names args"
21
22# Verify usage
23if { $argc < 6 } {
24	puts stderr "FAIL:[timestamp] Usage: $usage"
25	exit
26}
27
28# Initialize arguments
29set operator [ lindex $argv 0 ]
30set omethod [ lindex $argv 1 ]
31set op [ lindex $argv 2 ]
32set end [ lindex $argv 3 ]
33set result [ lindex $argv 4 ]
34set names [ lindex $argv 5 ]
35set args [lindex [lrange $argv 6 end] 0]
36
37# Join the env
38set dbenv [eval berkdb_env -home $testdir]
39error_check_good envopen [is_valid_env $dbenv] TRUE
40
41# Start transaction
42puts "\tFopscript.a: begin 2nd transaction (will block)"
43set txn2 [$dbenv txn]
44error_check_good txn2_begin [is_valid_txn $txn2 $dbenv] TRUE
45
46# Execute op2
47set op2result [$operator $omethod $op $names $txn2 $dbenv $args]
48
49# End txn2
50error_check_good txn2_end [$txn2 $end] 0
51if {$result == 0} {
52	error_check_good op2_should_succeed $op2result $result
53} else {
54	set error [extract_error $op2result]
55	error_check_good op2_wrong_failure $error $result
56}
57
58# Close any open db handles.  We had to wait until now
59# because you can't close a database inside a transaction.
60set handles [berkdb handles]
61foreach handle $handles {
62	if {[string range $handle 0 1] == "db" } {
63		error_check_good db_close [$handle close] 0
64	}
65}
66
67# Close the env
68error_check_good dbenv_close [$dbenv close] 0
69puts "\tFopscript completed successfully"
70
71