⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tester.tcl

📁 最新的sqlite3.6.2源代码
💻 TCL
📖 第 1 页 / 共 2 页
字号:
# 2001 September 15## The author disclaims copyright to this source code.  In place of# a legal notice, here is a blessing:##    May you do good and not evil.#    May you find forgiveness for yourself and forgive others.#    May you share freely, never taking more than you give.##***********************************************************************# This file implements some common TCL routines used for regression# testing the SQLite library## $Id: tester.tcl,v 1.134 2008/08/05 17:53:24 drh Exp $## What for user input before continuing.  This gives an opportunity# to connect profiling tools to the process.#for {set i 0} {$i<[llength $argv]} {incr i} {  if {[regexp {^-+pause$} [lindex $argv $i] all value]} {    puts -nonewline "Press RETURN to begin..."    flush stdout    gets stdin    set argv [lreplace $argv $i $i]  }}set tcl_precision 15set sqlite_pending_byte 0x0010000# # Check the command-line arguments for a default soft-heap-limit.# Store this default value in the global variable ::soft_limit and# update the soft-heap-limit each time this script is run.  In that# way if an individual test file changes the soft-heap-limit, it# will be reset at the start of the next test file.#if {![info exists soft_limit]} {  set soft_limit 0  for {set i 0} {$i<[llength $argv]} {incr i} {    if {[regexp {^--soft-heap-limit=(.+)$} [lindex $argv $i] all value]} {      if {$value!="off"} {        set soft_limit $value      }      set argv [lreplace $argv $i $i]    }  }}sqlite3_soft_heap_limit $soft_limit# # Check the command-line arguments to set the memory debugger# backtrace depth.## See the sqlite3_memdebug_backtrace() function in mem2.c or# test_malloc.c for additional information.#for {set i 0} {$i<[llength $argv]} {incr i} {  if {[lindex $argv $i] eq "--malloctrace"} {    set argv [lreplace $argv $i $i]    sqlite3_memdebug_backtrace 10    sqlite3_memdebug_log start    set tester_do_malloctrace 1  }}for {set i 0} {$i<[llength $argv]} {incr i} {  if {[regexp {^--backtrace=(\d+)$} [lindex $argv $i] all value]} {    sqlite3_memdebug_backtrace $value    set argv [lreplace $argv $i $i]  }}proc ostrace_call {zCall nClick zFile i32 i64} {  set s "INSERT INTO ostrace VALUES('$zCall', $nClick, '$zFile', $i32, $i64);"  puts $::ostrace_fd $s}for {set i 0} {$i<[llength $argv]} {incr i} {  if {[lindex $argv $i] eq "--ossummary" || [lindex $argv $i] eq "--ostrace"} {    sqlite3_instvfs create -default ostrace    set tester_do_ostrace 1    set ostrace_fd [open ostrace.sql w]    puts $ostrace_fd "BEGIN;"    if {[lindex $argv $i] eq "--ostrace"} {      set    s "CREATE TABLE ostrace"      append s "(method TEXT, clicks INT, file TEXT, i32 INT, i64 INT);"      puts $ostrace_fd $s      sqlite3_instvfs configure ostrace ostrace_call      sqlite3_instvfs configure ostrace ostrace_call    }    set argv [lreplace $argv $i $i]  }  if {[lindex $argv $i] eq "--binarylog"} {    set tester_do_binarylog 1    set argv [lreplace $argv $i $i]  }}# # Check the command-line arguments to set the maximum number of# errors tolerated before halting.#if {![info exists maxErr]} {  set maxErr 1000}for {set i 0} {$i<[llength $argv]} {incr i} {  if {[regexp {^--maxerror=(\d+)$} [lindex $argv $i] all maxErr]} {    set argv [lreplace $argv $i $i]  }}#puts "Max error = $maxErr"# Use the pager codec if it is available#if {[sqlite3 -has-codec] && [info command sqlite_orig]==""} {  rename sqlite3 sqlite_orig  proc sqlite3 {args} {    if {[llength $args]==2 && [string index [lindex $args 0] 0]!="-"} {      lappend args -key {xyzzy}    }    uplevel 1 sqlite_orig $args  }}# Create a test database#if {![info exists nTest]} {  sqlite3_shutdown   install_malloc_faultsim 1   sqlite3_initialize  if {[info exists tester_do_binarylog]} {    sqlite3_instvfs binarylog -default binarylog ostrace.bin    sqlite3_instvfs marker binarylog "$argv0 $argv"  }}catch {db close}file delete -force test.dbfile delete -force test.db-journalsqlite3 db ./test.dbset ::DB [sqlite3_connection_pointer db]if {[info exists ::SETUP_SQL]} {  db eval $::SETUP_SQL}# Abort early if this script has been run before.#if {[info exists nTest]} return# Set the test counters to zero#set nErr 0set nTest 0set skip_test 0set failList {}set omitList {}if {![info exists speedTest]} {  set speedTest 0}# Record the fact that a sequence of tests were omitted.#proc omit_test {name reason} {  global omitList  lappend omitList [list $name $reason]}# Invoke the do_test procedure to run a single test #proc do_test {name cmd expected} {  global argv nErr nTest skip_test maxErr  sqlite3_memdebug_settitle $name  if {[info exists ::tester_do_binarylog]} {    sqlite3_instvfs marker binarylog "Start of $name"  }  if {$skip_test} {    set skip_test 0    return  }  if {[llength $argv]==0} {     set go 1  } else {    set go 0    foreach pattern $argv {      if {[string match $pattern $name]} {        set go 1        break      }    }  }  if {!$go} return  incr nTest  puts -nonewline $name...  flush stdout  if {[catch {uplevel #0 "$cmd;\n"} result]} {    puts "\nError: $result"    incr nErr    lappend ::failList $name    if {$nErr>$maxErr} {puts "*** Giving up..."; finalize_testing}  } elseif {[string compare $result $expected]} {    puts "\nExpected: \[$expected\]\n     Got: \[$result\]"    incr nErr    lappend ::failList $name    if {$nErr>=$maxErr} {puts "*** Giving up..."; finalize_testing}  } else {    puts " Ok"  }  flush stdout  if {[info exists ::tester_do_binarylog]} {    sqlite3_instvfs marker binarylog "End of $name"  }}# Run an SQL script.  # Return the number of microseconds per statement.#proc speed_trial {name numstmt units sql} {  puts -nonewline [format {%-21.21s } $name...]  flush stdout  set speed [time {sqlite3_exec_nr db $sql}]  set tm [lindex $speed 0]  if {$tm == 0} {    set rate [format %20s "many"]  } else {    set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]  }  set u2 $units/s  puts [format {%12d uS %s %s} $tm $rate $u2]  global total_time  set total_time [expr {$total_time+$tm}]}proc speed_trial_tcl {name numstmt units script} {  puts -nonewline [format {%-21.21s } $name...]  flush stdout  set speed [time {eval $script}]  set tm [lindex $speed 0]  if {$tm == 0} {    set rate [format %20s "many"]  } else {    set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]  }  set u2 $units/s  puts [format {%12d uS %s %s} $tm $rate $u2]  global total_time  set total_time [expr {$total_time+$tm}]}proc speed_trial_init {name} {  global total_time  set total_time 0}proc speed_trial_summary {name} {  global total_time  puts [format {%-21.21s %12d uS TOTAL} $name $total_time]}# Run this routine last#proc finish_test {} {  finalize_testing}proc finalize_testing {} {  global nTest nErr sqlite_open_file_count omitList  catch {db close}  catch {db2 close}  catch {db3 close}  vfs_unlink_test  sqlite3 db {}  # sqlite3_clear_tsd_memdebug  db close  sqlite3_reset_auto_extension  set heaplimit [sqlite3_soft_heap_limit]  if {$heaplimit!=$::soft_limit} {    puts "soft-heap-limit changed by this script\          from $::soft_limit to $heaplimit"  } elseif {$heaplimit!="" && $heaplimit>0} {    puts "soft-heap-limit set to $heaplimit"  }  sqlite3_soft_heap_limit 0  incr nTest  puts "$nErr errors out of $nTest tests"  if {$nErr>0} {    puts "Failures on these tests: $::failList"  }  if {[llength $omitList]>0} {    puts "Omitted test cases:"    set prec {}    foreach {rec} [lsort $omitList] {      if {$rec==$prec} continue      set prec $rec      puts [format {  %-12s %s} [lindex $rec 0] [lindex $rec 1]]    }  }  if {$nErr>0 && ![working_64bit_int]} {    puts "******************************************************************"    puts "N.B.:  The version of TCL that you used to build this test harness"    puts "is defective in that it does not support 64-bit integers.  Some or"    puts "all of the test failures above might be a result from this defect"    puts "in your TCL build."    puts "******************************************************************"  }  if {[info exists ::tester_do_binarylog]} {    sqlite3_instvfs destroy binarylog  }  if {$sqlite_open_file_count} {    puts "$sqlite_open_file_count files were left open"    incr nErr  }  if {[info exists ::tester_do_ostrace]} {    puts "Writing ostrace.sql..."    set fd $::ostrace_fd    puts -nonewline $fd "CREATE TABLE ossummary"    puts $fd "(method TEXT, clicks INTEGER, count INTEGER);"    foreach row [sqlite3_instvfs report ostrace] {      foreach {method count clicks} $row break      puts $fd "INSERT INTO ossummary VALUES('$method', $clicks, $count);"    }    puts $fd "COMMIT;"    close $fd    sqlite3_instvfs destroy ostrace  }  if {[sqlite3_memory_used]>0} {    puts "Unfreed memory: [sqlite3_memory_used] bytes"    incr nErr    ifcapable memdebug||mem5||(mem3&&debug) {      puts "Writing unfreed memory log to \"./memleak.txt\""      sqlite3_memdebug_dump ./memleak.txt    }  } else {    puts "All memory allocations freed - no leaks"    ifcapable memdebug||mem5 {      sqlite3_memdebug_dump ./memusage.txt    }  }  show_memstats  puts "Maximum memory usage: [sqlite3_memory_highwater 1] bytes"  puts "Current memory usage: [sqlite3_memory_highwater] bytes"  if {[info commands sqlite3_memdebug_malloc_count] ne ""} {    puts "Number of malloc()  : [sqlite3_memdebug_malloc_count] calls"  }  if {[info exists ::tester_do_malloctrace]} {    puts "Writing mallocs.sql..."    memdebug_log_sql    sqlite3_memdebug_log stop    sqlite3_memdebug_log clear    if {[sqlite3_memory_used]>0} {      puts "Writing leaks.sql..."      sqlite3_memdebug_log sync      memdebug_log_sql leaks.sql    }  }  foreach f [glob -nocomplain test.db-*-journal] {    file delete -force $f  }  foreach f [glob -nocomplain test.db-mj*] {    file delete -force $f  }  exit [expr {$nErr>0}]}# Display memory statistics for analysis and debugging purposes.#proc show_memstats {} {  set x [sqlite3_status SQLITE_STATUS_MEMORY_USED 0]  set y [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0]  set val [format {now %10d  max %10d  max-size %10d} \              [lindex $x 1] [lindex $x 2] [lindex $y 2]]  puts "Memory used:          $val"  set x [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0]  set y [sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 0]  set val [format {now %10d  max %10d  max-size %10d} \              [lindex $x 1] [lindex $x 2] [lindex $y 2]]  puts "Page-cache used:      $val"  set x [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0]  set val [format {now %10d  max %10d} [lindex $x 1] [lindex $x 2]]  puts "Page-cache overflow:  $val"  set x [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0]  set val [format {now %10d  max %10d} [lindex $x 1] [lindex $x 2]]  puts "Scratch memory used:  $val"  set x [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0]  set y [sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 0]  set val [format {now %10d  max %10d  max-size %10d} \               [lindex $x 1] [lindex $x 2] [lindex $y 2]]  puts "Scratch overflow:     $val"  ifcapable yytrackmaxstackdepth {    set x [sqlite3_status SQLITE_STATUS_PARSER_STACK 0]    set val [format {               max %10d} [lindex $x 2]]    puts "Parser stack depth:    $val"  }}# A procedure to execute SQL#proc execsql {sql {db db}} {  # puts "SQL = $sql"  uplevel [list $db eval $sql]}# Execute SQL and catch exceptions.#proc catchsql {sql {db db}} {  # puts "SQL = $sql"  set r [catch {$db eval $sql} msg]  lappend r $msg  return $r}# Do an VDBE code dump on the SQL given#proc explain {sql {db db}} {  puts ""  puts "addr  opcode        p1      p2      p3      p4               p5  #"  puts "----  ------------  ------  ------  ------  ---------------  --  -"  $db eval "explain $sql" {} {    puts [format {%-4d  %-12.12s  %-6d  %-6d  %-6d  % -17s %s  %s} \      $addr $opcode $p1 $p2 $p3 $p4 $p5 $comment    ]  }}# Show the VDBE program for an SQL statement but omit the Trace# opcode at the beginning.  This procedure can be used to prove# that different SQL statements generate exactly the same VDBE code.#proc explain_no_trace {sql} {  set tr [db eval "EXPLAIN $sql"]  return [lrange $tr 7 end]}# Another procedure to execute SQL.  This one includes the field# names in the returned list.#proc execsql2 {sql} {  set result {}  db eval $sql data {    foreach f $data(*) {      lappend result $f $data($f)    }  }  return $result}# Use the non-callback API to execute multiple SQL statements#proc stepsql {dbptr sql} {  set sql [string trim $sql]  set r 0  while {[string length $sql]>0} {    if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} {      return [list 1 $vm]    }    set sql [string trim $sqltail]#    while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} {#      foreach v $VAL {lappend r $v}#    }    while {[sqlite3_step $vm]=="SQLITE_ROW"} {      for {set i 0} {$i<[sqlite3_data_count $vm]} {incr i} {        lappend r [sqlite3_column_text $vm $i]      }    }    if {[catch {sqlite3_finalize $vm} errmsg]} {      return [list 1 $errmsg]    }  }  return $r

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -