| OLD | NEW |
| 1 # 2004 August 30 | 1 # 2004 August 30 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| 11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
| 12 # | 12 # |
| 13 # This file implements tests to make sure SQLite does not crash or | 13 # This file implements tests to make sure SQLite does not crash or |
| 14 # segfault if it sees a corrupt database file. It creates a base | 14 # segfault if it sees a corrupt database file. It creates a base |
| 15 # data base file, then tests that single byte corruptions in | 15 # data base file, then tests that single byte corruptions in |
| 16 # increasingly larger quantities are handled gracefully. | 16 # increasingly larger quantities are handled gracefully. |
| 17 # | 17 # |
| 18 # $Id: corruptC.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $ | 18 # $Id: corruptC.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $ |
| 19 | 19 |
| 20 catch {file delete -force test.db test.db-journal test.bu} | 20 catch {file delete -force test.db test.db-journal test.bu} |
| 21 | 21 |
| 22 set testdir [file dirname $argv0] | 22 set testdir [file dirname $argv0] |
| 23 source $testdir/tester.tcl | 23 source $testdir/tester.tcl |
| 24 | 24 |
| 25 # Do not use a codec for tests in this file, as the database file is |
| 26 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 27 # |
| 28 do_not_use_codec |
| 29 |
| 25 # Construct a compact, dense database for testing. | 30 # Construct a compact, dense database for testing. |
| 26 # | 31 # |
| 27 do_test corruptC-1.1 { | 32 do_test corruptC-1.1 { |
| 28 execsql { | 33 execsql { |
| 29 PRAGMA auto_vacuum = 0; | 34 PRAGMA auto_vacuum = 0; |
| 30 PRAGMA legacy_file_format=1; | 35 PRAGMA legacy_file_format=1; |
| 31 BEGIN; | 36 BEGIN; |
| 32 CREATE TABLE t1(x,y); | 37 CREATE TABLE t1(x,y); |
| 33 INSERT INTO t1 VALUES(1,1); | 38 INSERT INTO t1 VALUES(1,1); |
| 34 INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; | 39 INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 60 } | 65 } |
| 61 | 66 |
| 62 # Setup for the tests. Make a backup copy of the good database in test.bu. | 67 # Setup for the tests. Make a backup copy of the good database in test.bu. |
| 63 # | 68 # |
| 64 db close | 69 db close |
| 65 copy_file test.db test.bu | 70 copy_file test.db test.bu |
| 66 sqlite3 db test.db | 71 sqlite3 db test.db |
| 67 set fsize [file size test.db] | 72 set fsize [file size test.db] |
| 68 | 73 |
| 69 # Set a quasi-random random seed. | 74 # Set a quasi-random random seed. |
| 70 if {[info exists SOAKTEST]} { | 75 if {[info exists ::G(issoak)]} { |
| 71 # If we are doing SOAK tests, we want a different | 76 # If we are doing SOAK tests, we want a different |
| 72 # random seed for each run. Ideally we would like | 77 # random seed for each run. Ideally we would like |
| 73 # to use [clock clicks] or something like that here. | 78 # to use [clock clicks] or something like that here. |
| 74 set qseed [file mtime test.db] | 79 set qseed [file mtime test.db] |
| 75 } else { | 80 } else { |
| 76 # If we are not doing soak tests, | 81 # If we are not doing soak tests, |
| 77 # make it repeatable. | 82 # make it repeatable. |
| 78 set qseed 0 | 83 set qseed 0 |
| 79 } | 84 } |
| 80 expr srand($qseed) | 85 expr srand($qseed) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 sqlite3 db test.db | 274 sqlite3 db test.db |
| 270 set blob [string repeat abcdefghij 10000] | 275 set blob [string repeat abcdefghij 10000] |
| 271 execsql { INSERT INTO t1 VALUES (1, $blob) } | 276 execsql { INSERT INTO t1 VALUES (1, $blob) } |
| 272 | 277 |
| 273 sqlite3 db test.db | 278 sqlite3 db test.db |
| 274 set filesize [file size test.db] | 279 set filesize [file size test.db] |
| 275 hexio_write test.db [expr $filesize-2048] 00000001 | 280 hexio_write test.db [expr $filesize-2048] 00000001 |
| 276 catchsql {DELETE FROM t1 WHERE rowid = (SELECT max(rowid) FROM t1)} | 281 catchsql {DELETE FROM t1 WHERE rowid = (SELECT max(rowid) FROM t1)} |
| 277 } {1 {database disk image is malformed}} | 282 } {1 {database disk image is malformed}} |
| 278 | 283 |
| 284 # At one point this particular corrupt database was causing a buffer |
| 285 # overread. Which caused a crash in a run of all.test once. |
| 286 # |
| 287 do_test corruptC-2.15 { |
| 288 db close |
| 289 copy_file test.bu test.db |
| 290 hexio_write test.db 986 b9 |
| 291 sqlite3 db test.db |
| 292 catchsql {SELECT count(*) FROM sqlite_master;} |
| 293 } {1 {malformed database schema (t1i1) - no such table: main.t1}} |
| 294 |
| 279 # | 295 # |
| 280 # Now test for a series of quasi-random seeds. | 296 # Now test for a series of quasi-random seeds. |
| 281 # We loop over the entire file size and touch | 297 # We loop over the entire file size and touch |
| 282 # each byte at least once. | 298 # each byte at least once. |
| 283 for {set tn 0} {$tn<$fsize} {incr tn 1} { | 299 for {set tn 0} {$tn<$fsize} {incr tn 1} { |
| 284 | 300 |
| 285 # setup for test | 301 # setup for test |
| 286 db close | 302 db close |
| 287 copy_file test.bu test.db | 303 copy_file test.bu test.db |
| 288 sqlite3 db test.db | 304 sqlite3 db test.db |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 set stats(ref) | 404 set stats(ref) |
| 389 } {0} | 405 } {0} |
| 390 } | 406 } |
| 391 } | 407 } |
| 392 # end for i | 408 # end for i |
| 393 | 409 |
| 394 } | 410 } |
| 395 # end for tn | 411 # end for tn |
| 396 | 412 |
| 397 finish_test | 413 finish_test |
| OLD | NEW |