CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
oserror.test146 linesDownload Raw Back to test
1# 2011 February 192#3# The author disclaims copyright to this source code.  In place of4# a legal notice, here is a blessing:5#6#    May you do good and not evil.7#    May you find forgiveness for yourself and forgive others.8#    May you share freely, never taking more than you give.9#10#***********************************************************************11# This file implements regression tests for SQLite library.  The12# focus of this file is testing that error messages are logged via the13# sqlite3_log() mechanism when certain errors are encountered in the14# default unix or windows VFS modules.15#16 17set testdir [file dirname $argv0]18source $testdir/tester.tcl19if {[llength [info commands test_syscall]]==0} {20  finish_test21  return22} 23set ::testprefix oserror24 25db close26sqlite3_shutdown27test_sqlite3_log xLog28proc xLog {error_code msg} {29  if {[string match os_* $msg]} {30    lappend ::log $msg 31  }32}33 34proc do_re_test {tn script expression} {35  uplevel do_test $tn [list [subst -nocommands {36    set res [eval { $script }]37    if {[regexp {$expression} [set res]]} {38      set {} {$expression}39    } else {40      set res41    }42  }]] [list $expression]43  44}45 46#--------------------------------------------------------------------------47# Tests oserror-1.* test failures in the open() system call.48#49 50# Test a failure in open() due to too many files. 51#52# The xOpen() method of the unix VFS calls getcwd() as well as open().53# Although this does not appear to be documented in the man page, on OSX54# a call to getcwd() may fail if there are no free file descriptors. So55# an error may be reported for either open() or getcwd() here.56#57if {![clang_sanitize_address]} {58  unset -nocomplain rc59  unset -nocomplain nOpen60  set nOpen 2000061  do_test 1.1.1 {62    set ::log [list]63    set ::rc [catch {64      for {set i 0} {$i < $::nOpen} {incr i} { sqlite3 dbh_$i test.db -readonly 1 }65    } msg]66    if {$::rc==0} {67      # Some system (ex: Debian) are able to create 20000+ file descriptiors68      # such systems will not fail here69      set x ok70    } elseif {$::rc==1 && $msg=="unable to open database file"} {71      set x ok72    } else {73      set x [list $::rc $msg]74    }75  } {ok}76  do_test 1.1.2 {77    catch { for {set i 0} {$i < $::nOpen} {incr i} { dbh_$i close } }78  } $::rc79  if {$rc} {80    do_re_test 1.1.3 { 81      lindex $::log 0 82    } {^os_unix.c:\d+: \(\d+\) (open|getcwd)\(.*test.db\) - }83  }84}85 86 87# Test a failure in open() due to the path being a directory.88#89do_test 1.2.1 {90  file mkdir dir.db91  set ::log [list]92  list [catch { sqlite3 dbh dir.db } msg] $msg93} {1 {unable to open database file}}94 95do_re_test 1.2.2 { lindex $::log 0 } {^os_unix.c:\d+: \(\d+\) open\(.*dir.db\) - }96 97# Test a failure in open() due to the path not existing.98#99do_test 1.3.1 {100  set ::log [list]101  list [catch { sqlite3 dbh /x/y/z/test.db } msg] $msg102} {1 {unable to open database file}}103 104do_re_test 1.3.2 { lindex $::log 0 } {^os_unix.c:\d+: \(\d+\) open\(.*test.db\) - }105 106# Test a failure in open() due to the path not existing.107#108do_test 1.4.1 {109  set ::log [list]110  list [catch { sqlite3 dbh /root/test.db } msg] $msg111} {1 {unable to open database file}}112 113do_re_test 1.4.2 { 114  lindex $::log 0115} {^os_unix.c:\d*: \(\d+\) (open|readlink|lstat)\(.*test.db\) - }116 117#--------------------------------------------------------------------------118# Tests oserror-1.* test failures in the unlink() system call.119#120ifcapable wal {121  do_test 2.1.1 {122    set ::log [list]123    file mkdir test.db-wal124    forcedelete test.db125    list [catch {126      sqlite3 dbh test.db127      execsql { SELECT * FROM sqlite_master } dbh128    } msg] $msg129  } {1 {disk I/O error}}130  131  do_re_test 2.1.2 { 132    lindex $::log 0 133  } {^os_unix.c:\d+: \(\d+\) unlink\(.*test.db-wal\) - }134  do_test 2.1.3 { 135    catch { dbh close }136    forcedelete test.db-wal137  } {}138}139  140 141test_syscall reset142sqlite3_shutdown143test_sqlite3_log 144sqlite3_initialize145finish_test146