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

📄 tester.tcl

📁 嵌入式数据库,在嵌入式平台上实现数据库功能,没有数据引擎,符合sql92标准
💻 TCL
📖 第 1 页 / 共 2 页
字号:
# Evaluate a boolean expression of capabilities.  If true, execute the# code.  Omit the code if false.#proc ifcapable {expr code {else ""} {elsecode ""}} {  regsub -all {[a-z_0-9]+} $expr {$::sqlite_options(&)} e2  if ($e2) {    set c [catch {uplevel 1 $code} r]  } else {    set c [catch {uplevel 1 $elsecode} r]  }  return -code $c $r}# This proc execs a seperate process that crashes midway through executing# the SQL script $sql on database test.db.## The crash occurs during a sync() of file $crashfile. When the crash# occurs a random subset of all unsynced writes made by the process are# written into the files on disk. Argument $crashdelay indicates the# number of file syncs to wait before crashing.## The return value is a list of two elements. The first element is a# boolean, indicating whether or not the process actually crashed or# reported some other error. The second element in the returned list is the# error message. This is "child process exited abnormally" if the crash# occured.#proc crashsql {crashdelay crashfile sql} {  if {$::tcl_platform(platform)!="unix"} {    error "crashsql should only be used on unix"  }  set cfile [file join [pwd] $crashfile]  set f [open crash.tcl w]  puts $f "sqlite3_crashparams $crashdelay $cfile"  puts $f "sqlite3 db test.db"  puts $f "db eval {pragma cache_size = 10}"  puts $f "db eval {"  puts $f   "$sql"  puts $f "}"  close $f  set r [catch {    exec [info nameofexec] crash.tcl >@stdout  } msg]  lappend r $msg}# Usage: do_ioerr_test <test number> <options...>## This proc is used to implement test cases that check that IO errors# are correctly handled. The first argument, <test number>, is an integer # used to name the tests executed by this proc. Options are as follows:##     -tclprep          TCL script to run to prepare test.#     -sqlprep          SQL script to run to prepare test.#     -tclbody          TCL script to run with IO error simulation.#     -sqlbody          TCL script to run with IO error simulation.#     -exclude          List of 'N' values not to test.#     -erc              Use extended result codes#     -start            Value of 'N' to begin with (default 1)##     -cksum            Boolean. If true, test that the database does#                       not change during the execution of the test case.#proc do_ioerr_test {testname args} {  set ::ioerropts(-start) 1  set ::ioerropts(-cksum) 0  set ::ioerropts(-erc) 0  array set ::ioerropts $args  set ::go 1  for {set n $::ioerropts(-start)} {$::go} {incr n} {     # Skip this IO error if it was specified with the "-exclude" option.    if {[info exists ::ioerropts(-exclude)]} {      if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue    }    # Delete the files test.db and test2.db, then execute the TCL and     # SQL (in that order) to prepare for the test case.    do_test $testname.$n.1 {      set ::sqlite_io_error_pending 0      catch {db close}      catch {file delete -force test.db}      catch {file delete -force test.db-journal}      catch {file delete -force test2.db}      catch {file delete -force test2.db-journal}      set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]      sqlite3_extended_result_codes $::DB $::ioerropts(-erc)      if {[info exists ::ioerropts(-tclprep)]} {        eval $::ioerropts(-tclprep)      }      if {[info exists ::ioerropts(-sqlprep)]} {        execsql $::ioerropts(-sqlprep)      }      expr 0    } {0}    # Read the 'checksum' of the database.    if {$::ioerropts(-cksum)} {      set checksum [cksum]    }      # Set the Nth IO error to fail.    do_test $testname.$n.2 [subst {      set ::sqlite_io_error_pending $n    }] $n      # Create a single TCL script from the TCL and SQL specified    # as the body of the test.    set ::ioerrorbody {}    if {[info exists ::ioerropts(-tclbody)]} {      append ::ioerrorbody "$::ioerropts(-tclbody)\n"    }    if {[info exists ::ioerropts(-sqlbody)]} {      append ::ioerrorbody "db eval {$::ioerropts(-sqlbody)}"    }    # Execute the TCL Script created in the above block. If    # there are at least N IO operations performed by SQLite as    # a result of the script, the Nth will fail.    do_test $testname.$n.3 {      set r [catch $::ioerrorbody msg]      # puts rc=[sqlite3_errcode $::DB]      set rc [sqlite3_errcode $::DB]      if {$::ioerropts(-erc)} {        # In extended result mode, all IOERRs are qualified         if {[regexp {^SQLITE_IOERR} $rc] && ![regexp {IOERR\+\d} $rc]} {          return $rc        }      } else {        # Not in extended result mode, no errors are qualified        if {[regexp {\+\d} $rc]} {          return $rc        }      }      set ::go [expr {$::sqlite_io_error_pending<=0}]      set s [expr $::sqlite_io_error_hit==0]      set ::sqlite_io_error_hit 0      # puts "$::sqlite_io_error_pending $r $msg"      # puts "r=$r s=$s go=$::go msg=\"$msg\""      expr { ($s && !$r && !$::go) || (!$s && $r && $::go) }      # expr {$::sqlite_io_error_pending>0 || $r!=0}    } {1}    # If an IO error occured, then the checksum of the database should    # be the same as before the script that caused the IO error was run.    if {$::go && $::ioerropts(-cksum)} {      do_test $testname.$n.4 {        catch {db close}        set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]        cksum      } $checksum    }    set ::sqlite_io_error_pending 0    if {[info exists ::ioerropts(-cleanup)]} {      catch $::ioerropts(-cleanup)    }  }  set ::sqlite_io_error_pending 0  unset ::ioerropts}# Return a checksum based on the contents of database 'db'.#proc cksum {{db db}} {  set txt [$db eval {      SELECT name, type, sql FROM sqlite_master order by name  }]\n  foreach tbl [$db eval {      SELECT name FROM sqlite_master WHERE type='table' order by name  }] {    append txt [$db eval "SELECT * FROM $tbl"]\n  }  foreach prag {default_synchronous default_cache_size} {    append txt $prag-[$db eval "PRAGMA $prag"]\n  }  set cksum [string length $txt]-[md5 $txt]  # puts $cksum-[file size test.db]  return $cksum}# Copy file $from into $to. This is used because some versions of# TCL for windows (notably the 8.4.1 binary package shipped with the# current mingw release) have a broken "file copy" command.#proc copy_file {from to} {  if {$::tcl_platform(platform)=="unix"} {    file copy -force $from $to  } else {    set f [open $from]    fconfigure $f -translation binary    set t [open $to w]    fconfigure $t -translation binary    puts -nonewline $t [read $f [file size $from]]    close $t    close $f  }}# This command checks for outstanding calls to sqliteMalloc() from within# the current thread. A list is returned with one entry for each outstanding# malloc. Each list entry is itself a list of 5 items, as follows:##     { <number-bytes> <file-name> <line-number> <test-case> <stack-dump> }#proc check_for_leaks {} {  set ret [list]  set cnt 0  foreach alloc [sqlite_malloc_outstanding] {    foreach {nBytes file iLine userstring backtrace} $alloc {}    set stack [list]    set skip 0    # The first command in this block will probably fail on windows. This    # means there will be no stack dump available.    if {$cnt < 25 && $backtrace!=""} {      catch {        set stuff [eval "exec addr2line -e ./testfixture -f $backtrace"]        foreach {func line} $stuff {          if {$func != "??" || $line != "??:0"} {            regexp {.*/(.*)} $line dummy line            lappend stack "${func}() $line"          } else {            if {[lindex $stack end] != "..."} {              lappend stack "..."            }          }        }      }      incr cnt    }    if {!$skip} {      lappend ret [list $nBytes $file $iLine $userstring $stack]    }  }  return $ret}# Pretty print a report based on the return value of [check_for_leaks] to# stdout.proc pp_check_for_leaks {} {  set l [check_for_leaks]  set n 0  foreach leak $l {    foreach {nBytes file iLine userstring stack} $leak {}    puts "$nBytes bytes leaked at $file:$iLine ($userstring)"    foreach frame $stack {      puts "        $frame"    }    incr n $nBytes  }  puts "Memory leaked: $n bytes in [llength $l] allocations"  puts ""}# If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set# to non-zero, then set the global variable $AUTOVACUUM to 1.set AUTOVACUUM $sqlite_options(default_autovacuum)

⌨️ 快捷键说明

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