1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/crash4.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,102 @@
1.4 +# 2008 January 8
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +#
1.15 +# This file contains additional tests to verify that SQLite database
1.16 +# file survive a power loss or OS crash.
1.17 +#
1.18 +# $Id: crash4.test,v 1.3 2008/01/16 17:46:38 drh Exp $
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +
1.23 +ifcapable !crashtest {
1.24 + finish_test
1.25 + return
1.26 +}
1.27 +
1.28 +
1.29 +# A sequence of SQL commands:
1.30 +#
1.31 +set sql_cmd_list {
1.32 + {CREATE TABLE a(id INTEGER, name CHAR(50))}
1.33 + {INSERT INTO a(id,name) VALUES(1,'one')}
1.34 + {INSERT INTO a(id,name) VALUES(2,'two')}
1.35 + {INSERT INTO a(id,name) VALUES(3,'three')}
1.36 + {INSERT INTO a(id,name) VALUES(4,'four')}
1.37 + {INSERT INTO a(id,name) VALUES(5,'five')}
1.38 + {INSERT INTO a(id,name) VALUES(6,'six')}
1.39 + {INSERT INTO a(id,name) VALUES(7,'seven')}
1.40 + {INSERT INTO a(id,name) VALUES(8,'eight')}
1.41 + {INSERT INTO a(id,name) VALUES(9,'nine')}
1.42 + {INSERT INTO a(id,name) VALUES(10,'ten')}
1.43 + {UPDATE A SET name='new text for row 3' WHERE id=3}
1.44 +}
1.45 +
1.46 +# Assume that a database is created by evaluating the SQL statements
1.47 +# in $sql_cmd_list. Compute a set of checksums that capture the state
1.48 +# of the database after each statement. Also include a checksum for
1.49 +# the state of the database prior to any of these statements.
1.50 +#
1.51 +set crash4_cksum_set {}
1.52 +lappend crash4_cksum_set [allcksum db]
1.53 +foreach cmd $sql_cmd_list {
1.54 + db eval $cmd
1.55 + lappend crash4_cksum_set [allcksum db]
1.56 +}
1.57 +
1.58 +# Run the sequence of SQL statements shown above repeatedly.
1.59 +# Close and reopen the database right before the UPDATE statement.
1.60 +# On each repetition, introduce database corruption typical of
1.61 +# what might be seen in a power loss or OS crash.
1.62 +#
1.63 +# Slowly increase the delay before the crash, repeating the test
1.64 +# over and over. Stop testing when the entire sequence of SQL
1.65 +# statements runs to completing without hitting the crash.
1.66 +#
1.67 +for {set cnt 1; set fin 0} {!$fin} {incr cnt} {
1.68 + db close
1.69 + file delete -force test.db test.db-journal
1.70 + do_test crash4-1.$cnt.1 {
1.71 + set seed [expr {int(abs(rand()*10000))}]
1.72 + set delay [expr {int($cnt/50)+1}]
1.73 + set file [expr {($cnt&1)?"test.db":"test.db-journal"}]
1.74 + set c [crashsql -delay $delay -file $file -seed $seed -tclbody {
1.75 + db eval {CREATE TABLE a(id INTEGER, name CHAR(50))}
1.76 + db eval {INSERT INTO a(id,name) VALUES(1,'one')}
1.77 + db eval {INSERT INTO a(id,name) VALUES(2,'two')}
1.78 + db eval {INSERT INTO a(id,name) VALUES(3,'three')}
1.79 + db eval {INSERT INTO a(id,name) VALUES(4,'four')}
1.80 + db eval {INSERT INTO a(id,name) VALUES(5,'five')}
1.81 + db eval {INSERT INTO a(id,name) VALUES(6,'six')}
1.82 + db eval {INSERT INTO a(id,name) VALUES(7,'seven')}
1.83 + db eval {INSERT INTO a(id,name) VALUES(8,'eight')}
1.84 + db eval {INSERT INTO a(id,name) VALUES(9,'nine')}
1.85 + db eval {INSERT INTO a(id,name) VALUES(10,'ten')}
1.86 + db close
1.87 + sqlite3 db test.db
1.88 + db eval {UPDATE A SET name='new text for row 3' WHERE id=3}
1.89 + db close
1.90 + } {}]
1.91 + if {$c==[list 0 {}]} {
1.92 + set ::fin 1
1.93 + set c [list 1 {child process exited abnormally}]
1.94 + }
1.95 + set c
1.96 + } {1 {child process exited abnormally}}
1.97 + sqlite3 db test.db
1.98 + integrity_check crash4-1.$cnt.2
1.99 + do_test crash4-1.$cnt.3 {
1.100 + set x [lsearch $::crash4_cksum_set [allcksum db]]
1.101 + expr {$x>=0}
1.102 + } {1}
1.103 +}
1.104 +
1.105 +finish_test