1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add OOM tests for the recovery extension.

FossilOrigin-Name: 9b6b4c7162439a889144edb561356afc66436db921a867c20871f0c556716502
This commit is contained in:
dan
2022-09-13 20:40:57 +00:00
parent a3a6d63b40
commit 322967df59
4 changed files with 142 additions and 7 deletions

View File

@ -167,6 +167,32 @@ ifcapable fts5 {
do_recover_test 9
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 10.1 {
CREATE TABLE x1(a PRIMARY KEY, str TEXT) WITHOUT ROWID;
INSERT INTO x1 VALUES(1, '
\nhello\012world(\n0)(\n1)
');
INSERT INTO x1 VALUES(2, '
\nhello
');
}
do_execsql_test 10.2 "
INSERT INTO x1 VALUES(3, '\012hello there\015world');
INSERT INTO x1 VALUES(4, '\015hello there\015world');
"
do_recover_test 10
#-------------------------------------------------------------------------
reset_db
do_execsql_test 11.1 {
PRAGMA encoding='utf16';
CREATE TABLE u1(u, v);
INSERT INTO u1 VALUES('edvin marton', 'bond');
INSERT INTO u1 VALUES(1, 4.0);
}
do_recover_test 11

View File

@ -0,0 +1,108 @@
# 2022 August 28
#
# 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.
#
#***********************************************************************
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] recover_common.tcl]
source $testdir/tester.tcl
set testprefix recoverfault2
#--------------------------------------------------------------------------
proc compare_result {db1 db2 sql} {
set r1 [$db1 eval $sql]
set r2 [$db2 eval $sql]
if {$r1 != $r2} {
puts "r1: $r1"
puts "r2: $r2"
error "mismatch for $sql"
}
return ""
}
proc compare_dbs {db1 db2} {
compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
compare_result $db1 $db2 "SELECT * FROM $tbl"
}
}
#--------------------------------------------------------------------------
do_execsql_test 1.0 "
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
"
faultsim_save_and_close
proc my_sql_hook {sql} {
lappend ::lSql $sql
return 0
}
do_faultsim_test 1 -faults oom* -prep {
catch { db2 close }
faultsim_restore_and_reopen
set ::lSql [list]
} -body {
set R [sqlite3_recover_init_sql db main my_sql_hook]
$R run
$R finish
} -test {
faultsim_test_result {0 {}} {1 {}}
if {$testrc==0} {
sqlite3 db2 ""
db2 eval [join $::lSql ";"]
compare_dbs db db2
db2 close
}
}
ifcapable utf16 {
reset_db
do_execsql_test 2.0 "
PRAGMA encoding='utf-16';
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
"
faultsim_save_and_close
proc my_sql_hook {sql} {
puts "HOOK $sql"
lappend ::lSql $sql
return 0
}
do_faultsim_test 2 -faults oom-t* -prep {
catch { db2 close }
faultsim_restore_and_reopen
set ::lSql [list]
} -body {
set R [sqlite3_recover_init_sql db main my_sql_hook]
$R run
$R finish
} -test {
faultsim_test_result {0 {}} {1 {}}
if {$testrc==0} {
sqlite3 db2 ""
db2 eval [join $::lSql ";"]
compare_dbs db db2
db2 close
}
}
}
finish_test