From 03ba3fa02c41bc584e32d0e6dec568efc0d8f82b Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Fri, 9 Jan 2009 10:49:14 +0000 Subject: [PATCH] Add a couple of coverage tests. (CVS 6149) FossilOrigin-Name: 6a64109d1f9b63ac8b29ea2c77da02506387b4a1 --- manifest | 18 ++--- manifest.uuid | 2 +- test/crash8.test | 193 ++++++++++++++++++++++++++++++++++++++++++++- test/jrnlmode.test | 43 +++++++++- test/tester.tcl | 20 +++-- 5 files changed, 255 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index d336667d58..dd2d7ecb8a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\scoverage\simprovements.\s(CVS\s6148) -D 2009-01-09T02:49:32 +C Add\sa\scouple\sof\scoverage\stests.\s(CVS\s6149) +D 2009-01-09T10:49:14 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 05461a9b5803d5ad10c79f989801e9fd2cc3e592 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -288,7 +288,7 @@ F test/crash4.test 02ff4f15c149ca1e88a5c299b4896c84d9450c3b F test/crash5.test 80a2f7073381837fc082435c97df52a830abcd80 F test/crash6.test 9c730cf06335003cb1f5cfceddacd044155336e0 F test/crash7.test e20a7b9ee1d16eaef7c94a4cb7ed2191b4d05970 -F test/crash8.test 8a7134b3b51e6914054ecd47115a62d9be6726da +F test/crash8.test 2ee8ecfed37eea4b987148fe36d6b56175c7d049 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/createtab.test 199cf68f44e5d9e87a0b8afc7130fdeb4def3272 F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c @@ -413,7 +413,7 @@ F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 F test/join5.test 86675fc2919269aa923c84dd00ee4249b97990fe F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19 -F test/jrnlmode.test 513b495624bfe54da24ae1208125421d8167953d +F test/jrnlmode.test e004a5ed138e06464d74dbd6bead01908f264c52 F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200 F test/like.test e55cbbc21729f577b74ec333c753a2d6eda03f9f @@ -545,7 +545,7 @@ F test/tableapi.test 505031f15b18a750184d967d2c896cf88fcc969c F test/tclsqlite.test 30636c3151ccc2d553aa09020b885054141a1963 F test/tempdb.test b88ac8a19823cf771d742bf61eef93ef337c06b1 F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125 -F test/tester.tcl 66c41fc4d8a7f185d9abb21d68821c1f05e41f53 +F test/tester.tcl 57b8ad3e60bd14e93c88c9b8f1106221e677d17e F test/thread001.test dda1d39cea954d7d43f520891d77a93d3325ab58 F test/thread002.test 84c03a9fc4f7a5f92eefe551266afa840c2eb6ae F test/thread003.test e17754799649c2b732c295620dca041c32f01e16 @@ -696,7 +696,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 45bb5703d7ef5e835b43a6fa7ee2a2d96db76939 -R 9c598b92693d243d4089a75e467bcfdb -U drh -Z 54fe2b39d55a9e6d88ce90f4b7ea9f31 +P 6e171c0a64850013b26a223189d5bebcc0a01a8b +R 89004f1f2d745e64659a2282676eb561 +U danielk1977 +Z 92cdcba9e0727e6498f46c2592efcecb diff --git a/manifest.uuid b/manifest.uuid index 280f52a263..e34a36aa4b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6e171c0a64850013b26a223189d5bebcc0a01a8b \ No newline at end of file +6a64109d1f9b63ac8b29ea2c77da02506387b4a1 \ No newline at end of file diff --git a/test/crash8.test b/test/crash8.test index 97706ab8f6..3f6c2f35fd 100644 --- a/test/crash8.test +++ b/test/crash8.test @@ -12,7 +12,10 @@ # This test verifies a couple of specific potential data corruption # scenarios involving crashes or power failures. # -# $Id: crash8.test,v 1.1 2009/01/08 17:50:46 danielk1977 Exp $ +# Later: Also, some other specific scenarios required for coverage +# testing that do not lead to corruption. +# +# $Id: crash8.test,v 1.2 2009/01/09 10:49:14 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -108,5 +111,191 @@ do_test crash8-2.3 { execsql {PRAGMA integrity_check} } {ok} -finish_test +proc read_file {zFile} { + set fd [open $zFile] + fconfigure $fd -translation binary + set zData [read $fd] + close $fd + return $zData +} +# The following tests check that SQLite will not roll back a hot-journal +# file if the sector-size field in the first journal file header is +# suspect. Definition of suspect: +# +# a) Not a power of 2, or +# b) Greater than 0x1000000 (16MB). +# +do_test crash8-3.1 { + list [file exists test.db-joural] [file exists test.db] +} {0 1} +do_test crash8-3.2 { + execsql { + PRAGMA synchronous = off; + BEGIN; + DELETE FROM t1; + SELECT count(*) FROM t1; + } +} {0} +do_test crash8-3.3 { + set zJournal [read_file test.db-journal] + execsql { + COMMIT; + SELECT count(*) FROM t1; + } +} {0} +do_test crash8-3.4 { + binary scan [string range $zJournal 20 23] I nSector + set nSector +} {512} +do_test crash8-3.5 { + set zJournal2 [ + string replace $zJournal 20 23 [binary format I 511] + ] + set fd [open test.db-journal w] + fconfigure $fd -translation binary + puts -nonewline $fd $zJournal2 + close $fd + + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.6 { + set zJournal2 [ + string replace $zJournal 20 23 [binary format I [expr 0x2000000]] + ] + set fd [open test.db-journal w] + fconfigure $fd -translation binary + puts -nonewline $fd $zJournal2 + close $fd + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.7 { + set fd [open test.db-journal w] + fconfigure $fd -translation binary + puts -nonewline $fd $zJournal + close $fd + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {6 ok} + + +# If a connection running in persistent-journal mode is part of a +# multi-file transaction, it must ensure that the master-journal name +# appended to the journal file contents during the commit is located +# at the end of the physical journal file. If there was already a +# large journal file allocated at the start of the transaction, this +# may mean truncating the file so that the master journal name really +# is at the physical end of the file. +# +# This block of tests test that SQLite correctly truncates such +# journal files, and that the results behave correctly if a hot-journal +# rollback occurs. +# +ifcapable pragma { + reset_db + file delete -force test2.db + + do_test crash8-4.1 { + execsql { + PRAGMA journal_mode = persist; + CREATE TABLE ab(a, b); + INSERT INTO ab VALUES(0, 'abc'); + INSERT INTO ab VALUES(1, NULL); + INSERT INTO ab VALUES(2, NULL); + INSERT INTO ab VALUES(3, NULL); + INSERT INTO ab VALUES(4, NULL); + INSERT INTO ab VALUES(5, NULL); + INSERT INTO ab VALUES(6, NULL); + UPDATE ab SET b = randstr(1000,1000); + ATTACH 'test2.db' AS aux; + CREATE TABLE aux.ab(a, b); + INSERT INTO aux.ab SELECT * FROM main.ab; + + UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1; + UPDATE ab SET b = randstr(1000,1000) WHERE a>=1; + } + list [file exists test.db-journal] [file exists test2.db-journal] + } {1 1} + + do_test crash8-4.2 { + execsql { + BEGIN; + UPDATE aux.ab SET b = 'def' WHERE a = 0; + UPDATE main.ab SET b = 'def' WHERE a = 0; + COMMIT; + } + } {} + + do_test crash8-4.3 { + execsql { + UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1; + UPDATE ab SET b = randstr(1000,1000) WHERE a>=1; + } + } {} + + set contents_main [db eval {SELECT b FROM main.ab WHERE a = 1}] + set contents_aux [db eval {SELECT b FROM aux.ab WHERE a = 1}] + + do_test crash8-4.4 { + crashsql -file test2.db -delay 1 { + ATTACH 'test2.db' AS aux; + BEGIN; + UPDATE aux.ab SET b = 'ghi' WHERE a = 0; + UPDATE main.ab SET b = 'ghi' WHERE a = 0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_test crash8-4.5 { + list [file exists test.db-journal] [file exists test2.db-journal] + } {1 1} + + do_test crash8-4.6 { + execsql { + SELECT b FROM main.ab WHERE a = 0; + SELECT b FROM aux.ab WHERE a = 0; + } + } {def def} + + do_test crash8-4.7 { + crashsql -file test2.db -delay 1 { + ATTACH 'test2.db' AS aux; + BEGIN; + UPDATE aux.ab SET b = 'jkl' WHERE a = 0; + UPDATE main.ab SET b = 'jkl' WHERE a = 0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_test crash8-4.8 { + set fd [open test.db-journal] + fconfigure $fd -translation binary + seek $fd -16 end + binary scan [read $fd 4] I len + + seek $fd [expr {-1 * ($len + 16)}] end + set zMasterJournal [read $fd $len] + close $fd + + file exists $zMasterJournal + } {1} + + do_test crash8-4.9 { + execsql { SELECT b FROM aux.ab WHERE a = 0 } + } {def} + + do_test crash8-4.10 { + file delete $zMasterJournal + execsql { SELECT b FROM main.ab WHERE a = 0 } + } {jkl} +} + +finish_test diff --git a/test/jrnlmode.test b/test/jrnlmode.test index 313078f1a5..7b230e03fc 100644 --- a/test/jrnlmode.test +++ b/test/jrnlmode.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The focus # of these tests is the journal mode pragma. # -# $Id: jrnlmode.test,v 1.9 2008/12/22 11:43:36 danielk1977 Exp $ +# $Id: jrnlmode.test,v 1.10 2009/01/09 10:49:14 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -421,4 +421,45 @@ ifcapable pragma { } {1} } +ifcapable pragma { + do_test jrnlmode-6.1 { + execsql { + PRAGMA journal_mode = truncate; + CREATE TABLE t4(a, b); + BEGIN; + INSERT INTO t4 VALUES(1, 2); + PRAGMA journal_mode = memory; + } + } {truncate memory} + do_test jrnlmode-6.2 { + file exists test.db-journal + } {1} + do_test jrnlmode-6.3 { + execsql { + COMMIT; + SELECT * FROM t4; + } + } {1 2} + do_test jrnlmode-6.4 { + file exists test.db-journal + } {0} + do_test jrnlmode-6.5 { + execsql { + BEGIN; + INSERT INTO t4 VALUES(3, 4); + } + file exists test.db-journal + } {0} + do_test jrnlmode-6.7 { + execsql { + COMMIT; + SELECT * FROM t4; + } + } {1 2 3 4} + do_test jrnlmode-6.8 { + file exists test.db-journal + } {0} +} + finish_test + diff --git a/test/tester.tcl b/test/tester.tcl index e6530a3316..2e222d5215 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -11,7 +11,7 @@ # This file implements some common TCL routines used for regression # testing the SQLite library # -# $Id: tester.tcl,v 1.135 2008/11/21 00:10:35 aswift Exp $ +# $Id: tester.tcl,v 1.136 2009/01/09 10:49:14 danielk1977 Exp $ # # What for user input before continuing. This gives an opportunity @@ -137,14 +137,18 @@ if {![info exists nTest]} { sqlite3_instvfs marker binarylog "$argv0 $argv" } } -catch {db close} -file delete -force test.db -file delete -force test.db-journal -sqlite3 db ./test.db -set ::DB [sqlite3_connection_pointer db] -if {[info exists ::SETUP_SQL]} { - db eval $::SETUP_SQL + +proc reset_db {} { + catch {db close} + file delete -force test.db + file delete -force test.db-journal + sqlite3 db ./test.db + set ::DB [sqlite3_connection_pointer db] + if {[info exists ::SETUP_SQL]} { + db eval $::SETUP_SQL + } } +reset_db # Abort early if this script has been run before. #