1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996,2008 Oracle. All rights reserved. 4# 5# $Id: test045.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST test045 8# TEST Small random tester 9# TEST Runs a number of random add/delete/retrieve operations. 10# TEST Tests both successful conditions and error conditions. 11# TEST 12# TEST Run the random db tester on the specified access method. 13# 14# Options are: 15# -adds <maximum number of keys before you disable adds> 16# -cursors <number of cursors> 17# -dataavg <average data size> 18# -delete <minimum number of keys before you disable deletes> 19# -dups <allow duplicates in file> 20# -errpct <Induce errors errpct of the time> 21# -init <initial number of entries in database> 22# -keyavg <average key size> 23proc test045 { method {nops 10000} args } { 24 source ./include.tcl 25 global encrypt 26 27 # 28 # If we are using an env, then skip this test. It needs its own. 29 set eindex [lsearch -exact $args "-env"] 30 if { $eindex != -1 } { 31 incr eindex 32 set env [lindex $args $eindex] 33 puts "Test045 skipping for env $env" 34 return 35 } 36 set args [convert_args $method $args] 37 if { $encrypt != 0 } { 38 puts "Test045 skipping for security" 39 return 40 } 41 set omethod [convert_method $method] 42 43 puts "Test045: Random tester on $method for $nops operations" 44 45 # Set initial parameters 46 set adds [expr $nops * 10] 47 set cursors 5 48 set dataavg 40 49 set delete $nops 50 set dups 0 51 set errpct 0 52 set init 0 53 if { [is_record_based $method] == 1 } { 54 set keyavg 10 55 } else { 56 set keyavg 25 57 } 58 59 # Process arguments 60 set oargs "" 61 for { set i 0 } { $i < [llength $args] } {incr i} { 62 switch -regexp -- [lindex $args $i] { 63 -adds { incr i; set adds [lindex $args $i] } 64 -cursors { incr i; set cursors [lindex $args $i] } 65 -dataavg { incr i; set dataavg [lindex $args $i] } 66 -delete { incr i; set delete [lindex $args $i] } 67 -dups { incr i; set dups [lindex $args $i] } 68 -errpct { incr i; set errpct [lindex $args $i] } 69 -init { incr i; set init [lindex $args $i] } 70 -keyavg { incr i; set keyavg [lindex $args $i] } 71 -extent { incr i; 72 lappend oargs "-extent" "100" } 73 default { lappend oargs [lindex $args $i] } 74 } 75 } 76 77 # Create the database and and initialize it. 78 set root $testdir/test045 79 set f $root.db 80 env_cleanup $testdir 81 82 # Run the script with 3 times the number of initial elements to 83 # set it up. 84 set db [eval {berkdb_open \ 85 -create -mode 0644 $omethod} $oargs {$f}] 86 error_check_good dbopen:$f [is_valid_db $db] TRUE 87 88 set r [$db close] 89 error_check_good dbclose:$f $r 0 90 91 # We redirect standard out, but leave standard error here so we 92 # can see errors. 93 94 puts "\tTest045.a: Initializing database" 95 if { $init != 0 } { 96 set n [expr 3 * $init] 97 exec $tclsh_path \ 98 $test_path/dbscript.tcl $method $f $n \ 99 1 $init $n $keyavg $dataavg $dups 0 -1 \ 100 > $testdir/test045.init 101 } 102 # Check for test failure 103 set initerrs [findfail $testdir/test045.init] 104 foreach str $initerrs { 105 puts "FAIL: error message in .init file: $str" 106 } 107 108 puts "\tTest045.b: Now firing off berkdb rand dbscript, running: " 109 # Now the database is initialized, run a test 110 puts "$tclsh_path\ 111 $test_path/dbscript.tcl $method $f $nops $cursors $delete $adds \ 112 $keyavg $dataavg $dups $errpct > $testdir/test045.log" 113 114 exec $tclsh_path \ 115 $test_path/dbscript.tcl $method $f \ 116 $nops $cursors $delete $adds $keyavg \ 117 $dataavg $dups $errpct \ 118 > $testdir/test045.log 119 120 # Check for test failure 121 set logerrs [findfail $testdir/test045.log] 122 foreach str $logerrs { 123 puts "FAIL: error message in log file: $str" 124 } 125} 126