2004-06-22 17:12:51 +04:00
|
|
|
# 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 regression tests for SQLite library.
|
|
|
|
#
|
2004-06-23 05:05:26 +04:00
|
|
|
# $Id: crash.test,v 1.2 2004/06/23 01:05:27 danielk1977 Exp $
|
2004-06-22 17:12:51 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
2004-06-23 05:05:26 +04:00
|
|
|
# This proc execs a seperate process that crashes midway through executing
|
|
|
|
# the SQL script $sql on database test.db.
|
|
|
|
#
|
|
|
|
# Argument $crashdelay indicates the number of file closes or syncs to wait
|
|
|
|
# before crashing. When a crash occurs a random subset of unsynced writes
|
|
|
|
# are written into any open files.
|
|
|
|
proc crashsql {crashdelay sql} {
|
|
|
|
|
2004-06-22 17:12:51 +04:00
|
|
|
set f [open crash.tcl w]
|
2004-06-23 05:05:26 +04:00
|
|
|
puts $f "sqlite3_crashseed $crashdelay"
|
|
|
|
puts $f "sqlite3 db test.db"
|
|
|
|
puts $f "db eval {"
|
|
|
|
puts $f "$sql"
|
|
|
|
puts $f "}"
|
2004-06-22 17:12:51 +04:00
|
|
|
close $f
|
|
|
|
|
2004-06-23 05:05:26 +04:00
|
|
|
exec [file join . crashtest] crash.tcl
|
2004-06-22 17:12:51 +04:00
|
|
|
}
|
|
|
|
|
2004-06-23 05:05:26 +04:00
|
|
|
# Simple crash test:
|
|
|
|
#
|
|
|
|
# crash-1.1: Create a database with a table with two rows.
|
|
|
|
# crash-1.2: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
|
|
|
|
# journal-sync
|
|
|
|
# crash-1.3: Ensure the database is in the same state as after crash-1.1.
|
|
|
|
# crash-1.4: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
|
|
|
|
# database-sync
|
|
|
|
# crash-1.5: Ensure the database is in the same state as after crash-1.1.
|
|
|
|
#
|
2004-06-22 17:12:51 +04:00
|
|
|
do_test crash-1.1 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
INSERT INTO abc VALUES(1, 2, 3);
|
|
|
|
INSERT INTO abc VALUES(4, 5, 6);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
do_test crash-1.2 {
|
|
|
|
catch {
|
2004-06-23 05:05:26 +04:00
|
|
|
crashsql 1 {
|
|
|
|
DELETE FROM abc WHERE a = 1;
|
|
|
|
}
|
2004-06-22 17:12:51 +04:00
|
|
|
} msg
|
|
|
|
set msg
|
|
|
|
} {child process exited abnormally}
|
|
|
|
do_test crash-1.3 {
|
|
|
|
catchsql {
|
|
|
|
SELECT * FROM abc;
|
|
|
|
}
|
|
|
|
} {0 {1 2 3 4 5 6}}
|
|
|
|
do_test crash-1.4 {
|
|
|
|
catch {
|
2004-06-23 05:05:26 +04:00
|
|
|
crashsql 1 {
|
|
|
|
DELETE FROM abc WHERE a = 1;
|
|
|
|
}
|
2004-06-22 17:12:51 +04:00
|
|
|
} msg
|
|
|
|
set msg
|
|
|
|
} {child process exited abnormally}
|
|
|
|
do_test crash-1.5 {
|
2004-06-23 05:05:26 +04:00
|
|
|
catchsql {
|
2004-06-22 17:12:51 +04:00
|
|
|
SELECT * FROM abc;
|
|
|
|
}
|
2004-06-23 05:05:26 +04:00
|
|
|
} {0 {1 2 3 4 5 6}}
|
2004-06-22 17:12:51 +04:00
|
|
|
|
|
|
|
finish_test
|
|
|
|
|
|
|
|
|