CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
btreefault.test107 linesDownload Raw Back to test
1# 2013 April 022#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#12# This file contains fault injection tests designed to test the btree.c 13# module.14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18source $testdir/malloc_common.tcl19set testprefix btreefault20 21# This test will not work with an in-memory journal, as the database will22# become corrupt if an error is injected into a transaction after it starts23# writing data out to the db file.24if {[permutation]=="inmemory_journal"} {25  finish_test26  return27}28 29do_test 1-pre1 {30  execsql {31    PRAGMA auto_vacuum = incremental;32    PRAGMA journal_mode = DELETE;33    CREATE TABLE t1(a PRIMARY KEY, b);34    INSERT INTO t1 VALUES(randomblob(1000), randomblob(100));35    INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;36    INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;37    INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;38    INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;39    DELETE FROM t1 WHERE rowid%2;40  }41  faultsim_save_and_close42} {}43 44do_faultsim_test 1 -prep {45  faultsim_restore_and_reopen46  set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY a" -1 DUMMY]47  sqlite3_step $::STMT48  sqlite3_step $::STMT49} -body {50  execsql { PRAGMA incremental_vacuum = 10 }51} -test {52  sqlite3_finalize $::STMT53  faultsim_test_result {0 {}} 54  faultsim_integrity_check55}56 57#-------------------------------------------------------------------------58# dbsqlfuzz crash-6ef3cd3b18ccc5de86120950a0498641acd90a33.txt59#60reset_db61 62do_execsql_test 2.0 {63  CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b);64  CREATE INDEX i1 ON t1(b);65  CREATE TABLE t2(x, y);66}67 68do_execsql_test 2.1 {69  INSERT INTO t1 VALUES(25, 25, 25);70  INSERT INTO t2 VALUES(25, 'a'), (25, 'b'), (25, 'c');71}72 73faultsim_save74do_test 2.2 {75  set res [list]76  db eval {77    SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b78  } {79    lappend res $x $y80    if {$y=="b"} {81      db eval { DELETE FROM t1 WHERE i=25 }82    }83  }84  set res85} {25 a 25 b}86 87do_faultsim_test 2 -faults oom-t* -prep {88  faultsim_restore_and_reopen89  db eval {SELECT * FROM sqlite_master}90} -body {91  set ::myres [list]92  db eval {93    SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b94  } {95    lappend ::myres $x $y96    if {$y=="b"} {97      db eval { DELETE FROM t1 WHERE i=25 }98    }99  }100  set ::myres101} -test {102  faultsim_test_result {0 {25 a 25 b}} 103}104 105 106finish_test107