/ Hex Artifact Content
Login

Artifact 5f5f155393c5685b3842fef79b6fbafa55197d75:


0000: 23 20 32 30 30 31 20 53 65 70 74 65 6d 62 65 72  # 2001 September
0010: 20 31 35 0a 23 0a 23 20 54 68 65 20 61 75 74 68   15.#.# The auth
0020: 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70  or disclaims cop
0030: 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73  yright to this s
0040: 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20  ource code.  In 
0050: 70 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67  place of.# a leg
0060: 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20  al notice, here 
0070: 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23  is a blessing:.#
0080: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f  .#    May you do
0090: 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76   good and not ev
00a0: 69 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75  il..#    May you
00b0: 20 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73   find forgivenes
00c0: 73 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61  s for yourself a
00d0: 6e 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72  nd forgive other
00e0: 73 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20  s..#    May you 
00f0: 73 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65  share freely, ne
0100: 76 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20  ver taking more 
0110: 74 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23  than you give..#
0120: 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .#**************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20 54 68 69 73  *********.# This
0170: 20 66 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73   file implements
0180: 20 72 65 67 72 65 73 73 69 6f 6e 20 74 65 73 74   regression test
0190: 73 20 66 6f 72 20 53 51 4c 69 74 65 20 6c 69 62  s for SQLite lib
01a0: 72 61 72 79 2e 0a 23 0a 23 20 54 68 65 20 66 6f  rary..#.# The fo
01b0: 63 75 73 20 6f 66 20 74 68 69 73 20 66 69 6c 65  cus of this file
01c0: 20 69 73 20 74 65 73 74 69 6e 67 20 74 68 65 20   is testing the 
01d0: 61 62 69 6c 69 74 79 20 6f 66 20 74 68 65 20 64  ability of the d
01e0: 61 74 61 62 61 73 65 20 74 6f 0a 23 20 75 73 65  atabase to.# use
01f0: 73 20 69 74 73 20 72 6f 6c 6c 62 61 63 6b 20 6a  s its rollback j
0200: 6f 75 72 6e 61 6c 20 74 6f 20 72 65 63 6f 76 65  ournal to recove
0210: 72 20 69 6e 74 61 63 74 20 28 6e 6f 20 64 61 74  r intact (no dat
0220: 61 62 61 73 65 20 63 6f 72 72 75 70 74 69 6f 6e  abase corruption
0230: 29 0a 23 20 66 72 6f 6d 20 61 20 70 6f 77 65 72  ).# from a power
0240: 20 66 61 69 6c 75 72 65 20 64 75 72 69 6e 67 20   failure during 
0250: 74 68 65 20 6d 69 64 64 6c 65 20 6f 66 20 61 20  the middle of a 
0260: 43 4f 4d 4d 49 54 2e 20 20 54 68 65 20 4f 53 20  COMMIT.  The OS 
0270: 69 6e 74 65 72 66 61 63 65 0a 23 20 6d 6f 64 75  interface.# modu
0280: 6c 65 73 20 61 72 65 20 6f 76 65 72 6c 6f 61 64  les are overload
0290: 65 64 20 69 6e 20 61 20 73 65 70 61 72 61 74 65  ed in a separate
02a0: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 65 73   instance of tes
02b0: 74 66 69 78 74 75 72 65 20 75 73 69 6e 67 0a 23  tfixture using.#
02c0: 20 74 68 65 20 6d 6f 64 69 66 69 65 64 20 49 2f   the modified I/
02d0: 4f 20 72 6f 75 74 69 6e 65 73 20 66 6f 75 6e 64  O routines found
02e0: 20 69 6e 20 74 65 73 74 36 2e 63 2e 20 20 54 68   in test6.c.  Th
02f0: 65 73 65 20 72 6f 75 74 69 6e 65 73 20 61 6c 6c  ese routines all
0300: 6f 77 20 75 73 0a 23 20 74 6f 20 73 69 6d 75 6c  ow us.# to simul
0310: 61 74 65 20 74 68 65 20 6b 69 6e 64 20 6f 66 20  ate the kind of 
0320: 66 69 6c 65 20 64 61 6d 61 67 65 20 74 68 61 74  file damage that
0330: 20 6f 63 63 75 72 73 20 61 66 74 65 72 20 61 20   occurs after a 
0340: 70 6f 77 65 72 20 66 61 69 6c 75 72 65 2e 0a 23  power failure..#
0350: 0a 23 20 24 49 64 3a 20 63 72 61 73 68 2e 74 65  .# $Id: crash.te
0360: 73 74 2c 76 20 31 2e 32 31 20 32 30 30 36 2f 30  st,v 1.21 2006/0
0370: 31 2f 30 36 20 31 34 3a 33 32 3a 32 30 20 64 72  1/06 14:32:20 dr
0380: 68 20 45 78 70 20 24 0a 0a 73 65 74 20 74 65 73  h Exp $..set tes
0390: 74 64 69 72 20 5b 66 69 6c 65 20 64 69 72 6e 61  tdir [file dirna
03a0: 6d 65 20 24 61 72 67 76 30 5d 0a 73 6f 75 72 63  me $argv0].sourc
03b0: 65 20 24 74 65 73 74 64 69 72 2f 74 65 73 74 65  e $testdir/teste
03c0: 72 2e 74 63 6c 0a 0a 69 66 63 61 70 61 62 6c 65  r.tcl..ifcapable
03d0: 20 21 63 72 61 73 68 74 65 73 74 20 7b 0a 20 20   !crashtest {.  
03e0: 66 69 6e 69 73 68 5f 74 65 73 74 0a 20 20 72 65  finish_test.  re
03f0: 74 75 72 6e 0a 7d 0a 0a 23 20 73 65 74 20 72 65  turn.}..# set re
0400: 70 65 61 74 73 20 31 30 30 0a 73 65 74 20 72 65  peats 100.set re
0410: 70 65 61 74 73 20 31 30 0a 0a 23 20 54 68 69 73  peats 10..# This
0420: 20 70 72 6f 63 20 65 78 65 63 73 20 61 20 73 65   proc execs a se
0430: 70 65 72 61 74 65 20 70 72 6f 63 65 73 73 20 74  perate process t
0440: 68 61 74 20 63 72 61 73 68 65 73 20 6d 69 64 77  hat crashes midw
0450: 61 79 20 74 68 72 6f 75 67 68 20 65 78 65 63 75  ay through execu
0460: 74 69 6e 67 0a 23 20 74 68 65 20 53 51 4c 20 73  ting.# the SQL s
0470: 63 72 69 70 74 20 24 73 71 6c 20 6f 6e 20 64 61  cript $sql on da
0480: 74 61 62 61 73 65 20 74 65 73 74 2e 64 62 2e 0a  tabase test.db..
0490: 23 0a 23 20 54 68 65 20 63 72 61 73 68 20 6f 63  #.# The crash oc
04a0: 63 75 72 73 20 64 75 72 69 6e 67 20 61 20 73 79  curs during a sy
04b0: 6e 63 28 29 20 6f 66 20 66 69 6c 65 20 24 63 72  nc() of file $cr
04c0: 61 73 68 66 69 6c 65 2e 20 57 68 65 6e 20 74 68  ashfile. When th
04d0: 65 20 63 72 61 73 68 0a 23 20 6f 63 63 75 72 73  e crash.# occurs
04e0: 20 61 20 72 61 6e 64 6f 6d 20 73 75 62 73 65 74   a random subset
04f0: 20 6f 66 20 61 6c 6c 20 75 6e 73 79 6e 63 65 64   of all unsynced
0500: 20 77 72 69 74 65 73 20 6d 61 64 65 20 62 79 20   writes made by 
0510: 74 68 65 20 70 72 6f 63 65 73 73 20 61 72 65 0a  the process are.
0520: 23 20 77 72 69 74 74 65 6e 20 69 6e 74 6f 20 74  # written into t
0530: 68 65 20 66 69 6c 65 73 20 6f 6e 20 64 69 73 6b  he files on disk
0540: 2e 20 41 72 67 75 6d 65 6e 74 20 24 63 72 61 73  . Argument $cras
0550: 68 64 65 6c 61 79 20 69 6e 64 69 63 61 74 65 73  hdelay indicates
0560: 20 74 68 65 0a 23 20 6e 75 6d 62 65 72 20 6f 66   the.# number of
0570: 20 66 69 6c 65 20 73 79 6e 63 73 20 74 6f 20 77   file syncs to w
0580: 61 69 74 20 62 65 66 6f 72 65 20 63 72 61 73 68  ait before crash
0590: 69 6e 67 2e 0a 23 0a 23 20 54 68 65 20 72 65 74  ing..#.# The ret
05a0: 75 72 6e 20 76 61 6c 75 65 20 69 73 20 61 20 6c  urn value is a l
05b0: 69 73 74 20 6f 66 20 74 77 6f 20 65 6c 65 6d 65  ist of two eleme
05c0: 6e 74 73 2e 20 54 68 65 20 66 69 72 73 74 20 65  nts. The first e
05d0: 6c 65 6d 65 6e 74 20 69 73 20 61 0a 23 20 62 6f  lement is a.# bo
05e0: 6f 6c 65 61 6e 2c 20 69 6e 64 69 63 61 74 69 6e  olean, indicatin
05f0: 67 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74  g whether or not
0600: 20 74 68 65 20 70 72 6f 63 65 73 73 20 61 63 74   the process act
0610: 75 61 6c 6c 79 20 63 72 61 73 68 65 64 20 6f 72  ually crashed or
0620: 0a 23 20 72 65 70 6f 72 74 65 64 20 73 6f 6d 65  .# reported some
0630: 20 6f 74 68 65 72 20 65 72 72 6f 72 2e 20 54 68   other error. Th
0640: 65 20 73 65 63 6f 6e 64 20 65 6c 65 6d 65 6e 74  e second element
0650: 20 69 6e 20 74 68 65 20 72 65 74 75 72 6e 65 64   in the returned
0660: 20 6c 69 73 74 20 69 73 20 74 68 65 0a 23 20 65   list is the.# e
0670: 72 72 6f 72 20 6d 65 73 73 61 67 65 2e 20 54 68  rror message. Th
0680: 69 73 20 69 73 20 22 63 68 69 6c 64 20 70 72 6f  is is "child pro
0690: 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f  cess exited abno
06a0: 72 6d 61 6c 6c 79 22 20 69 66 20 74 68 65 20 63  rmally" if the c
06b0: 72 61 73 68 0a 23 20 6f 63 63 75 72 65 64 2e 0a  rash.# occured..
06c0: 70 72 6f 63 20 63 72 61 73 68 73 71 6c 20 7b 63  proc crashsql {c
06d0: 72 61 73 68 64 65 6c 61 79 20 63 72 61 73 68 66  rashdelay crashf
06e0: 69 6c 65 20 73 71 6c 7d 20 7b 0a 20 20 73 65 74  ile sql} {.  set
06f0: 20 63 66 69 6c 65 20 5b 66 69 6c 65 20 6a 6f 69   cfile [file joi
0700: 6e 20 5b 70 77 64 5d 20 24 63 72 61 73 68 66 69  n [pwd] $crashfi
0710: 6c 65 5d 0a 0a 20 20 73 65 74 20 66 20 5b 6f 70  le]..  set f [op
0720: 65 6e 20 63 72 61 73 68 2e 74 63 6c 20 77 5d 0a  en crash.tcl w].
0730: 20 20 70 75 74 73 20 24 66 20 22 73 71 6c 69 74    puts $f "sqlit
0740: 65 33 5f 63 72 61 73 68 70 61 72 61 6d 73 20 24  e3_crashparams $
0750: 63 72 61 73 68 64 65 6c 61 79 20 24 63 66 69 6c  crashdelay $cfil
0760: 65 22 0a 20 20 70 75 74 73 20 24 66 20 22 73 65  e".  puts $f "se
0770: 74 20 73 71 6c 69 74 65 5f 70 65 6e 64 69 6e 67  t sqlite_pending
0780: 5f 62 79 74 65 20 24 3a 3a 73 71 6c 69 74 65 5f  _byte $::sqlite_
0790: 70 65 6e 64 69 6e 67 5f 62 79 74 65 22 0a 20 20  pending_byte".  
07a0: 70 75 74 73 20 24 66 20 7b 73 71 6c 69 74 65 33  puts $f {sqlite3
07b0: 20 64 62 20 74 65 73 74 2e 64 62 7d 0a 0a 20 20   db test.db}..  
07c0: 23 20 54 68 69 73 20 62 6c 6f 63 6b 20 73 65 74  # This block set
07d0: 73 20 74 68 65 20 63 61 63 68 65 20 73 69 7a 65  s the cache size
07e0: 20 6f 66 20 74 68 65 20 6d 61 69 6e 20 64 61 74   of the main dat
07f0: 61 62 61 73 65 20 74 6f 20 31 30 0a 20 20 23 20  abase to 10.  # 
0800: 70 61 67 65 73 2e 20 54 68 69 73 20 69 73 20 64  pages. This is d
0810: 6f 6e 65 20 69 6e 20 63 61 73 65 20 74 68 65 20  one in case the 
0820: 62 75 69 6c 64 20 69 73 20 63 6f 6e 66 69 67 75  build is configu
0830: 72 65 64 20 74 6f 20 6f 6d 69 74 0a 20 20 23 20  red to omit.  # 
0840: 22 50 52 41 47 4d 41 20 63 61 63 68 65 5f 73 69  "PRAGMA cache_si
0850: 7a 65 22 2e 0a 20 20 70 75 74 73 20 24 66 20 7b  ze"..  puts $f {
0860: 64 62 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20  db eval {SELECT 
0870: 2a 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61  * FROM sqlite_ma
0880: 73 74 65 72 3b 7d 7d 0a 20 20 70 75 74 73 20 24  ster;}}.  puts $
0890: 66 20 7b 73 65 74 20 62 74 20 5b 62 74 72 65 65  f {set bt [btree
08a0: 5f 66 72 6f 6d 5f 64 62 20 64 62 5d 7d 0a 20 20  _from_db db]}.  
08b0: 70 75 74 73 20 24 66 20 7b 62 74 72 65 65 5f 73  puts $f {btree_s
08c0: 65 74 5f 63 61 63 68 65 5f 73 69 7a 65 20 24 62  et_cache_size $b
08d0: 74 20 31 30 7d 0a 0a 20 20 70 75 74 73 20 24 66  t 10}..  puts $f
08e0: 20 22 64 62 20 65 76 61 6c 20 7b 22 0a 20 20 70   "db eval {".  p
08f0: 75 74 73 20 24 66 20 20 20 22 24 73 71 6c 22 0a  uts $f   "$sql".
0900: 20 20 70 75 74 73 20 24 66 20 22 7d 22 0a 20 20    puts $f "}".  
0910: 63 6c 6f 73 65 20 24 66 0a 0a 20 20 73 65 74 20  close $f..  set 
0920: 72 20 5b 63 61 74 63 68 20 7b 0a 20 20 20 20 65  r [catch {.    e
0930: 78 65 63 20 5b 69 6e 66 6f 20 6e 61 6d 65 6f 66  xec [info nameof
0940: 65 78 65 63 5d 20 63 72 61 73 68 2e 74 63 6c 20  exec] crash.tcl 
0950: 3e 40 73 74 64 6f 75 74 0a 20 20 7d 20 6d 73 67  >@stdout.  } msg
0960: 5d 0a 20 20 6c 61 70 70 65 6e 64 20 72 20 24 6d  ].  lappend r $m
0970: 73 67 0a 7d 0a 0a 23 20 54 68 65 20 66 6f 6c 6c  sg.}..# The foll
0980: 6f 77 69 6e 67 20 70 72 6f 63 65 64 75 72 65 20  owing procedure 
0990: 63 6f 6d 70 75 74 65 73 20 61 20 22 73 69 67 6e  computes a "sign
09a0: 61 74 75 72 65 22 20 66 6f 72 20 74 61 62 6c 65  ature" for table
09b0: 20 22 61 62 63 22 2e 20 20 49 66 0a 23 20 61 62   "abc".  If.# ab
09c0: 63 20 63 68 61 6e 67 65 73 20 69 6e 20 61 6e 79  c changes in any
09d0: 20 77 61 79 2c 20 74 68 65 20 73 69 67 6e 61 74   way, the signat
09e0: 75 72 65 20 73 68 6f 75 6c 64 20 63 68 61 6e 67  ure should chang
09f0: 65 2e 20 20 0a 70 72 6f 63 20 73 69 67 6e 61 74  e.  .proc signat
0a00: 75 72 65 20 7b 7d 20 7b 0a 20 20 72 65 74 75 72  ure {} {.  retur
0a10: 6e 20 5b 64 62 20 65 76 61 6c 20 7b 53 45 4c 45  n [db eval {SELE
0a20: 43 54 20 63 6f 75 6e 74 28 2a 29 2c 20 6d 64 35  CT count(*), md5
0a30: 73 75 6d 28 61 29 2c 20 6d 64 35 73 75 6d 28 62  sum(a), md5sum(b
0a40: 29 2c 20 6d 64 35 73 75 6d 28 63 29 20 46 52 4f  ), md5sum(c) FRO
0a50: 4d 20 61 62 63 7d 5d 0a 7d 0a 70 72 6f 63 20 73  M abc}].}.proc s
0a60: 69 67 6e 61 74 75 72 65 32 20 7b 7d 20 7b 0a 20  ignature2 {} {. 
0a70: 20 72 65 74 75 72 6e 20 5b 64 62 20 65 76 61 6c   return [db eval
0a80: 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a   {SELECT count(*
0a90: 29 2c 20 6d 64 35 73 75 6d 28 61 29 2c 20 6d 64  ), md5sum(a), md
0aa0: 35 73 75 6d 28 62 29 2c 20 6d 64 35 73 75 6d 28  5sum(b), md5sum(
0ab0: 63 29 20 46 52 4f 4d 20 61 62 63 32 7d 5d 0a 7d  c) FROM abc2}].}
0ac0: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
0ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
0b10: 53 69 6d 70 6c 65 20 63 72 61 73 68 20 74 65 73  Simple crash tes
0b20: 74 3a 0a 23 0a 23 20 63 72 61 73 68 2d 31 2e 31  t:.#.# crash-1.1
0b30: 3a 20 43 72 65 61 74 65 20 61 20 64 61 74 61 62  : Create a datab
0b40: 61 73 65 20 77 69 74 68 20 61 20 74 61 62 6c 65  ase with a table
0b50: 20 77 69 74 68 20 74 77 6f 20 72 6f 77 73 2e 0a   with two rows..
0b60: 23 20 63 72 61 73 68 2d 31 2e 32 3a 20 52 75 6e  # crash-1.2: Run
0b70: 20 61 20 27 44 45 4c 45 54 45 20 46 52 4f 4d 20   a 'DELETE FROM 
0b80: 61 62 63 20 57 48 45 52 45 20 61 20 3d 20 31 27  abc WHERE a = 1'
0b90: 20 74 68 61 74 20 63 72 61 73 68 65 73 20 64 75   that crashes du
0ba0: 72 69 6e 67 0a 23 20 20 20 20 20 20 20 20 20 20  ring.#          
0bb0: 20 20 74 68 65 20 66 69 72 73 74 20 6a 6f 75 72    the first jour
0bc0: 6e 61 6c 2d 73 79 6e 63 2e 0a 23 20 63 72 61 73  nal-sync..# cras
0bd0: 68 2d 31 2e 33 3a 20 45 6e 73 75 72 65 20 74 68  h-1.3: Ensure th
0be0: 65 20 64 61 74 61 62 61 73 65 20 69 73 20 69 6e  e database is in
0bf0: 20 74 68 65 20 73 61 6d 65 20 73 74 61 74 65 20   the same state 
0c00: 61 73 20 61 66 74 65 72 20 63 72 61 73 68 2d 31  as after crash-1
0c10: 2e 31 2e 0a 23 20 63 72 61 73 68 2d 31 2e 34 3a  .1..# crash-1.4:
0c20: 20 52 75 6e 20 61 20 27 44 45 4c 45 54 45 20 46   Run a 'DELETE F
0c30: 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20 61 20  ROM abc WHERE a 
0c40: 3d 20 31 27 20 74 68 61 74 20 63 72 61 73 68 65  = 1' that crashe
0c50: 73 20 64 75 72 69 6e 67 0a 23 20 20 20 20 20 20  s during.#      
0c60: 20 20 20 20 20 20 74 68 65 20 66 69 72 73 74 20        the first 
0c70: 64 61 74 61 62 61 73 65 2d 73 79 6e 63 2e 0a 23  database-sync..#
0c80: 20 63 72 61 73 68 2d 31 2e 35 3a 20 45 6e 73 75   crash-1.5: Ensu
0c90: 72 65 20 74 68 65 20 64 61 74 61 62 61 73 65 20  re the database 
0ca0: 69 73 20 69 6e 20 74 68 65 20 73 61 6d 65 20 73  is in the same s
0cb0: 74 61 74 65 20 61 73 20 61 66 74 65 72 20 63 72  tate as after cr
0cc0: 61 73 68 2d 31 2e 31 2e 0a 23 20 63 72 61 73 68  ash-1.1..# crash
0cd0: 2d 31 2e 36 3a 20 52 75 6e 20 61 20 27 44 45 4c  -1.6: Run a 'DEL
0ce0: 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45  ETE FROM abc WHE
0cf0: 52 45 20 61 20 3d 20 31 27 20 74 68 61 74 20 63  RE a = 1' that c
0d00: 72 61 73 68 65 73 20 64 75 72 69 6e 67 0a 23 20  rashes during.# 
0d10: 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 73             the s
0d20: 65 63 6f 6e 64 20 6a 6f 75 72 6e 61 6c 2d 73 79  econd journal-sy
0d30: 6e 63 2e 0a 23 20 63 72 61 73 68 2d 31 2e 37 3a  nc..# crash-1.7:
0d40: 20 45 6e 73 75 72 65 20 74 68 65 20 64 61 74 61   Ensure the data
0d50: 62 61 73 65 20 69 73 20 69 6e 20 74 68 65 20 73  base is in the s
0d60: 61 6d 65 20 73 74 61 74 65 20 61 73 20 61 66 74  ame state as aft
0d70: 65 72 20 63 72 61 73 68 2d 31 2e 31 2e 0a 23 0a  er crash-1.1..#.
0d80: 23 20 54 65 73 74 73 20 31 2e 38 20 74 68 72 6f  # Tests 1.8 thro
0d90: 75 67 68 20 31 2e 31 31 20 74 65 73 74 20 66 6f  ugh 1.11 test fo
0da0: 72 20 63 72 61 73 68 65 73 20 6f 6e 20 74 68 65  r crashes on the
0db0: 20 74 68 69 72 64 20 6a 6f 75 72 6e 61 6c 20 73   third journal s
0dc0: 79 6e 63 20 61 6e 64 0a 23 20 73 65 63 6f 6e 64  ync and.# second
0dd0: 20 64 61 74 61 62 61 73 65 20 73 79 6e 63 2e 20   database sync. 
0de0: 20 4e 65 69 74 68 65 72 20 6f 66 20 74 68 65 73   Neither of thes
0df0: 65 20 69 73 20 72 65 71 75 69 72 65 64 20 69 6e  e is required in
0e00: 20 73 75 63 68 20 61 20 73 6d 61 6c 6c 20 74 65   such a small te
0e10: 73 74 0a 23 20 63 61 73 65 2c 20 73 6f 20 74 68  st.# case, so th
0e20: 65 73 65 20 74 65 73 74 73 20 61 72 65 20 6a 75  ese tests are ju
0e30: 73 74 20 74 6f 20 76 65 72 69 66 79 20 74 68 61  st to verify tha
0e40: 74 20 74 68 65 20 74 65 73 74 20 69 6e 66 72 61  t the test infra
0e50: 73 74 72 75 63 74 75 72 65 0a 23 20 6f 70 65 72  structure.# oper
0e60: 61 74 65 73 20 61 73 20 65 78 70 65 63 74 65 64  ates as expected
0e70: 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  ..#.do_test cras
0e80: 68 2d 31 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  h-1.1 {.  execsq
0e90: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54  l {.    CREATE T
0ea0: 41 42 4c 45 20 61 62 63 28 61 2c 20 62 2c 20 63  ABLE abc(a, b, c
0eb0: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
0ec0: 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 31 2c  TO abc VALUES(1,
0ed0: 20 32 2c 20 33 29 3b 0a 20 20 20 20 49 4e 53 45   2, 3);.    INSE
0ee0: 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55  RT INTO abc VALU
0ef0: 45 53 28 34 2c 20 35 2c 20 36 29 3b 0a 20 20 7d  ES(4, 5, 6);.  }
0f00: 0a 20 20 73 65 74 20 3a 3a 73 69 67 20 5b 73 69  .  set ::sig [si
0f10: 67 6e 61 74 75 72 65 5d 0a 20 20 65 78 70 72 20  gnature].  expr 
0f20: 30 0a 7d 20 7b 30 7d 0a 64 6f 5f 74 65 73 74 20  0.} {0}.do_test 
0f30: 63 72 61 73 68 2d 31 2e 32 20 7b 0a 20 20 63 72  crash-1.2 {.  cr
0f40: 61 73 68 73 71 6c 20 31 20 74 65 73 74 2e 64 62  ashsql 1 test.db
0f50: 2d 6a 6f 75 72 6e 61 6c 20 7b 0a 20 20 20 20 44  -journal {.    D
0f60: 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57  ELETE FROM abc W
0f70: 48 45 52 45 20 61 20 3d 20 31 3b 0a 20 20 7d 0a  HERE a = 1;.  }.
0f80: 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63  } {1 {child proc
0f90: 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72  ess exited abnor
0fa0: 6d 61 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73 74 20  mally}}.do_test 
0fb0: 63 72 61 73 68 2d 31 2e 33 20 7b 0a 20 20 73 69  crash-1.3 {.  si
0fc0: 67 6e 61 74 75 72 65 0a 7d 20 24 3a 3a 73 69 67  gnature.} $::sig
0fd0: 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 31  .do_test crash-1
0fe0: 2e 34 20 7b 0a 20 20 63 72 61 73 68 73 71 6c 20  .4 {.  crashsql 
0ff0: 31 20 74 65 73 74 2e 64 62 20 7b 0a 20 20 20 20  1 test.db {.    
1000: 44 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20  DELETE FROM abc 
1010: 57 48 45 52 45 20 61 20 3d 20 31 3b 0a 20 20 7d  WHERE a = 1;.  }
1020: 0a 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f  .} {1 {child pro
1030: 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f  cess exited abno
1040: 72 6d 61 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73 74  rmally}}.do_test
1050: 20 63 72 61 73 68 2d 31 2e 35 20 7b 0a 20 20 73   crash-1.5 {.  s
1060: 69 67 6e 61 74 75 72 65 0a 7d 20 24 3a 3a 73 69  ignature.} $::si
1070: 67 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d  g.do_test crash-
1080: 31 2e 36 20 7b 0a 20 20 63 72 61 73 68 73 71 6c  1.6 {.  crashsql
1090: 20 32 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e   2 test.db-journ
10a0: 61 6c 20 7b 0a 20 20 20 20 44 45 4c 45 54 45 20  al {.    DELETE 
10b0: 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20 61  FROM abc WHERE a
10c0: 20 3d 20 31 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b   = 1;.  }.} {1 {
10d0: 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78  child process ex
10e0: 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d  ited abnormally}
10f0: 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d  }.do_test crash-
1100: 31 2e 37 20 7b 0a 20 20 63 61 74 63 68 73 71 6c  1.7 {.  catchsql
1110: 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20   {.    SELECT * 
1120: 46 52 4f 4d 20 61 62 63 3b 0a 20 20 7d 0a 7d 20  FROM abc;.  }.} 
1130: 7b 30 20 7b 31 20 32 20 33 20 34 20 35 20 36 7d  {0 {1 2 3 4 5 6}
1140: 7d 0a 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68  }..do_test crash
1150: 2d 31 2e 38 20 7b 0a 20 20 63 72 61 73 68 73 71  -1.8 {.  crashsq
1160: 6c 20 33 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72  l 3 test.db-jour
1170: 6e 61 6c 20 7b 0a 20 20 20 20 44 45 4c 45 54 45  nal {.    DELETE
1180: 20 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20   FROM abc WHERE 
1190: 61 20 3d 20 31 3b 0a 20 20 7d 0a 7d 20 7b 30 20  a = 1;.  }.} {0 
11a0: 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  {}}.do_test cras
11b0: 68 2d 31 2e 39 20 7b 0a 20 20 63 61 74 63 68 73  h-1.9 {.  catchs
11c0: 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20  ql {.    SELECT 
11d0: 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 7d 0a  * FROM abc;.  }.
11e0: 7d 20 7b 30 20 7b 34 20 35 20 36 7d 7d 0a 64 6f  } {0 {4 5 6}}.do
11f0: 5f 74 65 73 74 20 63 72 61 73 68 2d 31 2e 31 30  _test crash-1.10
1200: 20 7b 0a 20 20 63 72 61 73 68 73 71 6c 20 32 20   {.  crashsql 2 
1210: 74 65 73 74 2e 64 62 20 7b 0a 20 20 20 20 44 45  test.db {.    DE
1220: 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48  LETE FROM abc WH
1230: 45 52 45 20 61 20 3d 20 34 3b 0a 20 20 7d 0a 7d  ERE a = 4;.  }.}
1240: 20 7b 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20   {0 {}}.do_test 
1250: 63 72 61 73 68 2d 31 2e 31 31 20 7b 0a 20 20 63  crash-1.11 {.  c
1260: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 53 45  atchsql {.    SE
1270: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b  LECT * FROM abc;
1280: 0a 20 20 7d 0a 7d 20 7b 30 20 7b 7d 7d 0a 0a 23  .  }.} {0 {}}..#
1290: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65  ----------.# The
12e0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 73   following tests
12f0: 20 74 65 73 74 20 72 65 63 6f 76 65 72 79 20 77   test recovery w
1300: 68 65 6e 20 62 6f 74 68 20 74 68 65 20 64 61 74  hen both the dat
1310: 61 62 61 73 65 20 66 69 6c 65 20 61 6e 64 20 74  abase file and t
1320: 68 65 20 74 68 65 0a 23 20 6a 6f 75 72 6e 61 6c  he the.# journal
1330: 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 20 63 6f   file contain co
1340: 72 72 75 70 74 20 64 61 74 61 2e 20 54 68 69 73  rrupt data. This
1350: 20 63 61 6e 20 68 61 70 70 65 6e 20 61 66 74 65   can happen afte
1360: 72 20 70 61 67 65 73 20 61 72 65 0a 23 20 77 72  r pages are.# wr
1370: 69 74 74 65 6e 20 74 6f 20 74 68 65 20 64 61 74  itten to the dat
1380: 61 62 61 73 65 20 66 69 6c 65 20 62 65 66 6f 72  abase file befor
1390: 65 20 61 20 74 72 61 6e 73 61 63 74 69 6f 6e 20  e a transaction 
13a0: 69 73 20 63 6f 6d 6d 69 74 74 65 64 20 64 75 65  is committed due
13b0: 20 74 6f 0a 23 20 63 61 63 68 65 2d 70 72 65 73   to.# cache-pres
13c0: 73 75 72 65 2e 0a 23 0a 23 20 63 72 61 73 68 2d  sure..#.# crash-
13d0: 32 2e 31 3a 20 49 6e 73 65 72 74 20 31 38 20 70  2.1: Insert 18 p
13e0: 61 67 65 73 20 6f 66 20 64 61 74 61 20 69 6e 74  ages of data int
13f0: 6f 20 74 68 65 20 64 61 74 61 62 61 73 65 2e 0a  o the database..
1400: 23 20 63 72 61 73 68 2d 32 2e 32 3a 20 43 68 65  # crash-2.2: Che
1410: 63 6b 20 74 68 65 20 64 61 74 61 62 61 73 65 20  ck the database 
1420: 66 69 6c 65 20 73 69 7a 65 20 6c 6f 6f 6b 73 20  file size looks 
1430: 6f 6b 2e 0a 23 20 63 72 61 73 68 2d 32 2e 33 3a  ok..# crash-2.3:
1440: 20 44 65 6c 65 74 65 20 31 35 20 6f 72 20 73 6f   Delete 15 or so
1450: 20 70 61 67 65 73 20 28 77 69 74 68 20 61 20 31   pages (with a 1
1460: 30 20 70 61 67 65 20 70 61 67 65 2d 63 61 63 68  0 page page-cach
1470: 65 29 2c 20 74 68 65 6e 20 63 72 61 73 68 2e 0a  e), then crash..
1480: 23 20 63 72 61 73 68 2d 32 2e 34 3a 20 45 6e 73  # crash-2.4: Ens
1490: 75 72 65 20 74 68 65 20 64 61 74 61 62 61 73 65  ure the database
14a0: 20 69 73 20 69 6e 20 74 68 65 20 73 61 6d 65 20   is in the same 
14b0: 73 74 61 74 65 20 61 73 20 61 66 74 65 72 20 63  state as after c
14c0: 72 61 73 68 2d 32 2e 31 2e 0a 23 0a 23 20 54 65  rash-2.1..#.# Te
14d0: 73 74 20 63 61 73 65 73 20 63 72 61 73 68 2d 32  st cases crash-2
14e0: 2e 35 20 61 6e 64 20 63 72 61 73 68 2d 32 2e 36  .5 and crash-2.6
14f0: 20 63 68 65 63 6b 20 74 68 61 74 20 74 68 65 20   check that the 
1500: 64 61 74 61 62 61 73 65 20 69 73 20 4f 4b 20 69  database is OK i
1510: 66 20 74 68 65 20 0a 23 20 63 72 61 73 68 20 6f  f the .# crash o
1520: 63 63 75 72 73 20 64 75 72 69 6e 67 20 74 68 65  ccurs during the
1530: 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 66   main database f
1540: 69 6c 65 20 73 79 6e 63 2e 20 42 75 74 20 74 68  ile sync. But th
1550: 69 73 20 69 73 6e 27 74 20 72 65 61 6c 6c 79 0a  is isn't really.
1560: 23 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d  # different from
1570: 20 74 68 65 20 63 72 61 73 68 2d 31 2e 2a 20 63   the crash-1.* c
1580: 61 73 65 73 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  ases..#.do_test 
1590: 63 72 61 73 68 2d 32 2e 31 20 7b 0a 20 20 65 78  crash-2.1 {.  ex
15a0: 65 63 73 71 6c 20 7b 20 42 45 47 49 4e 20 7d 0a  ecsql { BEGIN }.
15b0: 20 20 66 6f 72 20 7b 73 65 74 20 6e 20 30 7d 20    for {set n 0} 
15c0: 7b 24 6e 20 3c 20 31 30 30 30 7d 20 7b 69 6e 63  {$n < 1000} {inc
15d0: 72 20 6e 7d 20 7b 0a 20 20 20 20 65 78 65 63 73  r n} {.    execs
15e0: 71 6c 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20  ql "INSERT INTO 
15f0: 61 62 63 20 56 41 4c 55 45 53 28 24 6e 2c 20 5b  abc VALUES($n, [
1600: 65 78 70 72 20 32 2a 24 6e 5d 2c 20 5b 65 78 70  expr 2*$n], [exp
1610: 72 20 33 2a 24 6e 5d 29 22 0a 20 20 7d 0a 20 20  r 3*$n])".  }.  
1620: 65 78 65 63 73 71 6c 20 7b 20 43 4f 4d 4d 49 54  execsql { COMMIT
1630: 20 7d 0a 20 20 73 65 74 20 3a 3a 73 69 67 20 5b   }.  set ::sig [
1640: 73 69 67 6e 61 74 75 72 65 5d 0a 20 20 65 78 65  signature].  exe
1650: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 73 75  csql { SELECT su
1660: 6d 28 61 29 2c 20 73 75 6d 28 62 29 2c 20 73 75  m(a), sum(b), su
1670: 6d 28 63 29 20 66 72 6f 6d 20 61 62 63 20 7d 0a  m(c) from abc }.
1680: 7d 20 7b 34 39 39 35 30 30 20 39 39 39 30 30 30  } {499500 999000
1690: 20 31 34 39 38 35 30 30 7d 0a 64 6f 5f 74 65 73   1498500}.do_tes
16a0: 74 20 63 72 61 73 68 2d 32 2e 32 20 7b 0a 20 20  t crash-2.2 {.  
16b0: 65 78 70 72 20 28 5b 66 69 6c 65 20 73 69 7a 65  expr ([file size
16c0: 20 74 65 73 74 2e 64 62 5d 20 2f 20 31 30 32 34   test.db] / 1024
16d0: 29 3e 31 36 0a 7d 20 7b 31 7d 0a 64 6f 5f 74 65  )>16.} {1}.do_te
16e0: 73 74 20 63 72 61 73 68 2d 32 2e 33 20 7b 0a 20  st crash-2.3 {. 
16f0: 20 63 72 61 73 68 73 71 6c 20 32 20 74 65 73 74   crashsql 2 test
1700: 2e 64 62 2d 6a 6f 75 72 6e 61 6c 20 7b 0a 20 20  .db-journal {.  
1710: 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 61 62    DELETE FROM ab
1720: 63 20 57 48 45 52 45 20 61 20 3c 20 38 30 30 3b  c WHERE a < 800;
1730: 0a 20 20 7d 0a 7d 20 7b 31 20 7b 63 68 69 6c 64  .  }.} {1 {child
1740: 20 70 72 6f 63 65 73 73 20 65 78 69 74 65 64 20   process exited 
1750: 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a 64 6f 5f  abnormally}}.do_
1760: 74 65 73 74 20 63 72 61 73 68 2d 32 2e 34 20 7b  test crash-2.4 {
1770: 0a 20 20 73 69 67 6e 61 74 75 72 65 0a 7d 20 24  .  signature.} $
1780: 73 69 67 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  sig.do_test cras
1790: 68 2d 32 2e 35 20 7b 0a 20 20 63 72 61 73 68 73  h-2.5 {.  crashs
17a0: 71 6c 20 31 20 74 65 73 74 2e 64 62 20 7b 0a 20  ql 1 test.db {. 
17b0: 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 61     DELETE FROM a
17c0: 62 63 20 57 48 45 52 45 20 61 3c 38 30 30 3b 0a  bc WHERE a<800;.
17d0: 20 20 7d 0a 7d 20 7b 31 20 7b 63 68 69 6c 64 20    }.} {1 {child 
17e0: 70 72 6f 63 65 73 73 20 65 78 69 74 65 64 20 61  process exited a
17f0: 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a 64 6f 5f 74  bnormally}}.do_t
1800: 65 73 74 20 63 72 61 73 68 2d 32 2e 36 20 7b 0a  est crash-2.6 {.
1810: 20 20 73 69 67 6e 61 74 75 72 65 0a 7d 20 24 73    signature.} $s
1820: 69 67 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ig..#-----------
1830: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1840: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1870: 23 20 54 68 65 20 63 72 61 73 68 2d 33 2e 2a 20  # The crash-3.* 
1880: 74 65 73 74 20 63 61 73 65 73 20 61 72 65 20 65  test cases are e
1890: 73 73 65 6e 74 69 61 6c 6c 79 20 74 68 65 20 73  ssentially the s
18a0: 61 6d 65 20 74 65 73 74 20 61 73 20 74 65 73 74  ame test as test
18b0: 20 63 61 73 65 0a 23 20 63 72 61 73 68 2d 32 2e   case.# crash-2.
18c0: 2a 2c 20 62 75 74 20 77 69 74 68 20 61 20 6d 6f  *, but with a mo
18d0: 72 65 20 63 6f 6d 70 6c 69 63 61 74 65 64 20 64  re complicated d
18e0: 61 74 61 20 73 65 74 2e 20 0a 23 0a 23 20 54 68  ata set. .#.# Th
18f0: 65 20 74 65 73 74 20 69 73 20 72 65 70 65 61 74  e test is repeat
1900: 65 64 20 61 20 66 65 77 20 74 69 6d 65 73 20 77  ed a few times w
1910: 69 74 68 20 64 69 66 66 65 72 65 6e 74 20 73 65  ith different se
1920: 65 64 73 20 66 6f 72 20 74 68 65 20 72 61 6e 64  eds for the rand
1930: 6f 6d 0a 23 20 6e 75 6d 62 65 72 20 67 65 6e 65  om.# number gene
1940: 72 61 74 6f 72 20 69 6e 20 74 68 65 20 63 72 61  rator in the cra
1950: 73 68 69 6e 67 20 65 78 65 63 75 74 61 62 6c 65  shing executable
1960: 2e 20 42 65 63 61 75 73 65 20 74 68 65 72 65 20  . Because there 
1970: 69 73 20 6e 6f 20 77 61 79 20 74 6f 0a 23 20 73  is no way to.# s
1980: 65 65 64 20 74 68 65 20 72 61 6e 64 6f 6d 20 6e  eed the random n
1990: 75 6d 62 65 72 20 67 65 6e 65 72 61 74 6f 72 20  umber generator 
19a0: 64 69 72 65 63 74 6c 79 2c 20 73 6f 6d 65 20 53  directly, some S
19b0: 51 4c 20 69 73 20 61 64 64 65 64 20 74 6f 20 74  QL is added to t
19c0: 68 65 20 74 65 73 74 0a 23 20 63 61 73 65 20 74  he test.# case t
19d0: 6f 20 27 75 73 65 20 75 70 27 20 61 20 64 69 66  o 'use up' a dif
19e0: 66 65 72 65 6e 74 20 71 75 61 6e 74 69 74 79 20  ferent quantity 
19f0: 72 61 6e 64 6f 6d 20 6e 75 6d 62 65 72 73 20 62  random numbers b
1a00: 65 66 6f 72 65 20 74 68 65 20 74 65 73 74 20 53  efore the test S
1a10: 51 4c 0a 23 20 69 73 20 65 78 65 63 75 74 65 64  QL.# is executed
1a20: 2e 0a 23 0a 0a 23 20 4d 61 6b 65 20 73 75 72 65  ..#..# Make sure
1a30: 20 74 68 65 20 66 69 6c 65 20 69 73 20 6d 75 63   the file is muc
1a40: 68 20 62 69 67 67 65 72 20 74 68 61 6e 20 74 68  h bigger than th
1a50: 65 20 70 61 67 65 72 2d 63 61 63 68 65 20 28 31  e pager-cache (1
1a60: 30 20 70 61 67 65 73 29 2e 20 54 68 69 73 0a 23  0 pages). This.#
1a70: 20 65 6e 73 75 72 65 73 20 74 68 61 74 20 63 61   ensures that ca
1a80: 63 68 65 2d 73 70 69 6c 6c 73 20 68 61 70 70 65  che-spills happe
1a90: 6e 20 72 65 67 75 6c 61 72 6c 79 2e 0a 64 6f 5f  n regularly..do_
1aa0: 74 65 73 74 20 63 72 61 73 68 2d 33 2e 30 20 7b  test crash-3.0 {
1ab0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
1ac0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
1ad0: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61   SELECT * FROM a
1ae0: 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  bc;.    INSERT I
1af0: 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 2a  NTO abc SELECT *
1b00: 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49   FROM abc;.    I
1b10: 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53  NSERT INTO abc S
1b20: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63  ELECT * FROM abc
1b30: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
1b40: 4f 20 61 62 63 20 53 45 4c 45 43 54 20 2a 20 46  O abc SELECT * F
1b50: 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e 53  ROM abc;.    INS
1b60: 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c  ERT INTO abc SEL
1b70: 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a  ECT * FROM abc;.
1b80: 20 20 7d 0a 20 20 65 78 70 72 20 28 5b 66 69 6c    }.  expr ([fil
1b90: 65 20 73 69 7a 65 20 74 65 73 74 2e 64 62 5d 20  e size test.db] 
1ba0: 2f 20 31 30 32 34 29 20 3e 20 34 35 30 0a 7d 20  / 1024) > 450.} 
1bb0: 7b 31 7d 0a 66 6f 72 20 7b 73 65 74 20 69 20 31  {1}.for {set i 1
1bc0: 7d 20 7b 24 69 20 3c 20 24 72 65 70 65 61 74 73  } {$i < $repeats
1bd0: 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 73  } {incr i} {.  s
1be0: 65 74 20 73 69 67 20 5b 73 69 67 6e 61 74 75 72  et sig [signatur
1bf0: 65 5d 0a 20 20 64 6f 5f 74 65 73 74 20 63 72 61  e].  do_test cra
1c00: 73 68 2d 33 2e 24 69 2e 31 20 7b 0a 20 20 20 20  sh-3.$i.1 {.    
1c10: 20 63 72 61 73 68 73 71 6c 20 5b 65 78 70 72 20   crashsql [expr 
1c20: 24 69 25 35 20 2b 20 31 5d 20 74 65 73 74 2e 64  $i%5 + 1] test.d
1c30: 62 2d 6a 6f 75 72 6e 61 6c 20 22 0a 20 20 20 20  b-journal ".    
1c40: 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 20 20     BEGIN;.      
1c50: 20 53 45 4c 45 43 54 20 72 61 6e 64 6f 6d 28 29   SELECT random()
1c60: 20 46 52 4f 4d 20 61 62 63 20 4c 49 4d 49 54 20   FROM abc LIMIT 
1c70: 24 69 3b 0a 20 20 20 20 20 20 20 49 4e 53 45 52  $i;.       INSER
1c80: 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55 45  T INTO abc VALUE
1c90: 53 28 72 61 6e 64 73 74 72 28 31 30 2c 31 30 29  S(randstr(10,10)
1ca0: 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20 20  , 0, 0);.       
1cb0: 44 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20  DELETE FROM abc 
1cc0: 57 48 45 52 45 20 72 61 6e 64 6f 6d 28 29 25 31  WHERE random()%1
1cd0: 30 21 3d 30 3b 0a 20 20 20 20 20 20 20 43 4f 4d  0!=0;.       COM
1ce0: 4d 49 54 3b 0a 20 20 20 20 20 22 0a 20 20 7d 20  MIT;.     ".  } 
1cf0: 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73  {1 {child proces
1d00: 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61  s exited abnorma
1d10: 6c 6c 79 7d 7d 0a 20 20 64 6f 5f 74 65 73 74 20  lly}}.  do_test 
1d20: 63 72 61 73 68 2d 33 2e 24 69 2e 32 20 7b 0a 20  crash-3.$i.2 {. 
1d30: 20 20 20 73 69 67 6e 61 74 75 72 65 0a 20 20 7d     signature.  }
1d40: 20 24 73 69 67 0a 7d 20 0a 0a 23 2d 2d 2d 2d 2d   $sig.} ..#-----
1d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d90: 2d 2d 2d 2d 2d 0a 23 20 54 68 65 20 66 6f 6c 6c  -----.# The foll
1da0: 6f 77 69 6e 67 20 74 65 73 74 20 63 61 73 65 73  owing test cases
1db0: 20 2d 20 63 72 61 73 68 2d 34 2e 2a 20 2d 20 74   - crash-4.* - t
1dc0: 65 73 74 20 74 68 65 20 63 6f 72 72 65 63 74 20  est the correct 
1dd0: 72 65 63 6f 76 65 72 79 20 6f 66 20 74 68 65 0a  recovery of the.
1de0: 23 20 64 61 74 61 62 61 73 65 20 77 68 65 6e 20  # database when 
1df0: 61 20 63 72 61 73 68 20 6f 63 63 75 72 73 20 64  a crash occurs d
1e00: 75 72 69 6e 67 20 61 20 6d 75 6c 74 69 2d 66 69  uring a multi-fi
1e10: 6c 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e 0a  le transaction..
1e20: 23 0a 23 20 63 72 61 73 68 2d 34 2e 31 2e 2a 3a  #.# crash-4.1.*:
1e30: 20 54 65 73 74 20 72 65 63 6f 76 65 72 79 20 77   Test recovery w
1e40: 68 65 6e 20 63 72 61 73 68 20 6f 63 63 75 72 73  hen crash occurs
1e50: 20 64 75 72 69 6e 67 20 73 79 6e 63 28 29 20 6f   during sync() o
1e60: 66 20 74 68 65 20 0a 23 20 20 20 20 20 20 20 20  f the .#        
1e70: 20 20 20 20 20 20 6d 61 69 6e 20 64 61 74 61 62        main datab
1e80: 61 73 65 20 6a 6f 75 72 6e 61 6c 20 66 69 6c 65  ase journal file
1e90: 2e 0a 23 20 63 72 61 73 68 2d 34 2e 32 2e 2a 3a  ..# crash-4.2.*:
1ea0: 20 54 65 73 74 20 72 65 63 6f 76 65 72 79 20 77   Test recovery w
1eb0: 68 65 6e 20 63 72 61 73 68 20 6f 63 63 75 72 73  hen crash occurs
1ec0: 20 64 75 72 69 6e 67 20 73 79 6e 63 28 29 20 6f   during sync() o
1ed0: 66 20 61 6e 20 0a 23 20 20 20 20 20 20 20 20 20  f an .#         
1ee0: 20 20 20 20 20 61 74 74 61 63 68 65 64 20 64 61       attached da
1ef0: 74 61 62 61 73 65 20 6a 6f 75 72 6e 61 6c 20 66  tabase journal f
1f00: 69 6c 65 2e 0a 23 20 63 72 61 73 68 2d 34 2e 33  ile..# crash-4.3
1f10: 2e 2a 3a 20 54 65 73 74 20 72 65 63 6f 76 65 72  .*: Test recover
1f20: 79 20 77 68 65 6e 20 63 72 61 73 68 20 6f 63 63  y when crash occ
1f30: 75 72 73 20 64 75 72 69 6e 67 20 73 79 6e 63 28  urs during sync(
1f40: 29 20 6f 66 20 74 68 65 20 6d 61 73 74 65 72 0a  ) of the master.
1f50: 23 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6a  #              j
1f60: 6f 75 72 6e 61 6c 20 66 69 6c 65 2e 20 0a 23 0a  ournal file. .#.
1f70: 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34 2e  do_test crash-4.
1f80: 30 20 7b 0a 20 20 66 69 6c 65 20 64 65 6c 65 74  0 {.  file delet
1f90: 65 20 2d 66 6f 72 63 65 20 74 65 73 74 32 2e 64  e -force test2.d
1fa0: 62 0a 20 20 66 69 6c 65 20 64 65 6c 65 74 65 20  b.  file delete 
1fb0: 2d 66 6f 72 63 65 20 74 65 73 74 32 2e 64 62 2d  -force test2.db-
1fc0: 6a 6f 75 72 6e 61 6c 0a 20 20 65 78 65 63 73 71  journal.  execsq
1fd0: 6c 20 7b 0a 20 20 20 20 41 54 54 41 43 48 20 27  l {.    ATTACH '
1fe0: 74 65 73 74 32 2e 64 62 27 20 41 53 20 61 75 78  test2.db' AS aux
1ff0: 3b 0a 20 20 20 20 50 52 41 47 4d 41 20 61 75 78  ;.    PRAGMA aux
2000: 2e 64 65 66 61 75 6c 74 5f 63 61 63 68 65 5f 73  .default_cache_s
2010: 69 7a 65 20 3d 20 31 30 3b 0a 20 20 20 20 43 52  ize = 10;.    CR
2020: 45 41 54 45 20 54 41 42 4c 45 20 61 75 78 2e 61  EATE TABLE aux.a
2030: 62 63 32 20 41 53 20 53 45 4c 45 43 54 20 32 2a  bc2 AS SELECT 2*
2040: 61 20 61 73 20 61 2c 20 32 2a 62 20 61 73 20 62  a as a, 2*b as b
2050: 2c 20 32 2a 63 20 61 73 20 63 20 46 52 4f 4d 20  , 2*c as c FROM 
2060: 61 62 63 3b 0a 20 20 7d 0a 20 20 65 78 70 72 20  abc;.  }.  expr 
2070: 28 5b 66 69 6c 65 20 73 69 7a 65 20 74 65 73 74  ([file size test
2080: 32 2e 64 62 5d 20 2f 20 31 30 32 34 29 20 3e 20  2.db] / 1024) > 
2090: 34 35 30 0a 7d 20 7b 31 7d 0a 0a 66 6f 72 20 7b  450.} {1}..for {
20a0: 73 65 74 20 69 20 31 7d 20 7b 24 69 3c 24 72 65  set i 1} {$i<$re
20b0: 70 65 61 74 73 7d 20 7b 69 6e 63 72 20 69 7d 20  peats} {incr i} 
20c0: 7b 0a 20 20 73 65 74 20 73 69 67 20 5b 73 69 67  {.  set sig [sig
20d0: 6e 61 74 75 72 65 5d 0a 20 20 73 65 74 20 73 69  nature].  set si
20e0: 67 32 20 5b 73 69 67 6e 61 74 75 72 65 32 5d 0a  g2 [signature2].
20f0: 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d    do_test crash-
2100: 34 2e 31 2e 24 69 2e 31 20 7b 0a 20 20 20 20 20  4.1.$i.1 {.     
2110: 73 65 74 20 63 20 5b 63 72 61 73 68 73 71 6c 20  set c [crashsql 
2120: 24 69 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e  $i test.db-journ
2130: 61 6c 20 22 0a 20 20 20 20 20 20 20 41 54 54 41  al ".       ATTA
2140: 43 48 20 27 74 65 73 74 32 2e 64 62 27 20 41 53  CH 'test2.db' AS
2150: 20 61 75 78 3b 0a 20 20 20 20 20 20 20 42 45 47   aux;.       BEG
2160: 49 4e 3b 0a 20 20 20 20 20 20 20 53 45 4c 45 43  IN;.       SELEC
2170: 54 20 72 61 6e 64 6f 6d 28 29 20 46 52 4f 4d 20  T random() FROM 
2180: 61 62 63 20 4c 49 4d 49 54 20 24 69 3b 0a 20 20  abc LIMIT $i;.  
2190: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
21a0: 20 61 62 63 20 56 41 4c 55 45 53 28 72 61 6e 64   abc VALUES(rand
21b0: 73 74 72 28 31 30 2c 31 30 29 2c 20 30 2c 20 30  str(10,10), 0, 0
21c0: 29 3b 0a 20 20 20 20 20 20 20 44 45 4c 45 54 45  );.       DELETE
21d0: 20 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20   FROM abc WHERE 
21e0: 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d 30 3b 0a  random()%10!=0;.
21f0: 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e         INSERT IN
2200: 54 4f 20 61 62 63 32 20 56 41 4c 55 45 53 28 72  TO abc2 VALUES(r
2210: 61 6e 64 73 74 72 28 31 30 2c 31 30 29 2c 20 30  andstr(10,10), 0
2220: 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 44 45 4c  , 0);.       DEL
2230: 45 54 45 20 46 52 4f 4d 20 61 62 63 32 20 57 48  ETE FROM abc2 WH
2240: 45 52 45 20 72 61 6e 64 6f 6d 28 29 25 31 30 21  ERE random()%10!
2250: 3d 30 3b 0a 20 20 20 20 20 20 20 43 4f 4d 4d 49  =0;.       COMMI
2260: 54 3b 0a 20 20 20 20 20 22 5d 0a 20 20 20 20 20  T;.     "].     
2270: 73 65 74 20 63 0a 20 20 7d 20 7b 31 20 7b 63 68  set c.  } {1 {ch
2280: 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78 69 74  ild process exit
2290: 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a  ed abnormally}}.
22a0: 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d    do_test crash-
22b0: 34 2e 31 2e 24 69 2e 32 20 7b 0a 20 20 20 20 73  4.1.$i.2 {.    s
22c0: 69 67 6e 61 74 75 72 65 0a 20 20 7d 20 24 73 69  ignature.  } $si
22d0: 67 0a 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73  g.  do_test cras
22e0: 68 2d 34 2e 31 2e 24 69 2e 33 20 7b 0a 20 20 20  h-4.1.$i.3 {.   
22f0: 20 73 69 67 6e 61 74 75 72 65 32 0a 20 20 7d 20   signature2.  } 
2300: 24 73 69 67 32 0a 7d 20 0a 73 65 74 20 69 20 30  $sig2.} .set i 0
2310: 0a 77 68 69 6c 65 20 7b 5b 69 6e 63 72 20 69 5d  .while {[incr i]
2320: 7d 20 7b 0a 20 20 73 65 74 20 73 69 67 20 5b 73  } {.  set sig [s
2330: 69 67 6e 61 74 75 72 65 5d 0a 20 20 73 65 74 20  ignature].  set 
2340: 73 69 67 32 20 5b 73 69 67 6e 61 74 75 72 65 32  sig2 [signature2
2350: 5d 0a 20 20 73 65 74 20 3a 3a 66 69 6e 20 30 0a  ].  set ::fin 0.
2360: 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d    do_test crash-
2370: 34 2e 32 2e 24 69 2e 31 20 7b 0a 20 20 20 20 20  4.2.$i.1 {.     
2380: 73 65 74 20 63 20 5b 63 72 61 73 68 73 71 6c 20  set c [crashsql 
2390: 24 69 20 74 65 73 74 32 2e 64 62 2d 6a 6f 75 72  $i test2.db-jour
23a0: 6e 61 6c 20 22 0a 20 20 20 20 20 20 20 41 54 54  nal ".       ATT
23b0: 41 43 48 20 27 74 65 73 74 32 2e 64 62 27 20 41  ACH 'test2.db' A
23c0: 53 20 61 75 78 3b 0a 20 20 20 20 20 20 20 42 45  S aux;.       BE
23d0: 47 49 4e 3b 0a 20 20 20 20 20 20 20 53 45 4c 45  GIN;.       SELE
23e0: 43 54 20 72 61 6e 64 6f 6d 28 29 20 46 52 4f 4d  CT random() FROM
23f0: 20 61 62 63 20 4c 49 4d 49 54 20 24 69 3b 0a 20   abc LIMIT $i;. 
2400: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
2410: 4f 20 61 62 63 20 56 41 4c 55 45 53 28 72 61 6e  O abc VALUES(ran
2420: 64 73 74 72 28 31 30 2c 31 30 29 2c 20 30 2c 20  dstr(10,10), 0, 
2430: 30 29 3b 0a 20 20 20 20 20 20 20 44 45 4c 45 54  0);.       DELET
2440: 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45  E FROM abc WHERE
2450: 20 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d 30 3b   random()%10!=0;
2460: 0a 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  .       INSERT I
2470: 4e 54 4f 20 61 62 63 32 20 56 41 4c 55 45 53 28  NTO abc2 VALUES(
2480: 72 61 6e 64 73 74 72 28 31 30 2c 31 30 29 2c 20  randstr(10,10), 
2490: 30 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 44 45  0, 0);.       DE
24a0: 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 32 20 57  LETE FROM abc2 W
24b0: 48 45 52 45 20 72 61 6e 64 6f 6d 28 29 25 31 30  HERE random()%10
24c0: 21 3d 30 3b 0a 20 20 20 20 20 20 20 43 4f 4d 4d  !=0;.       COMM
24d0: 49 54 3b 0a 20 20 20 20 20 22 5d 0a 20 20 20 20  IT;.     "].    
24e0: 20 69 66 20 7b 20 24 63 20 3d 3d 20 7b 30 20 7b   if { $c == {0 {
24f0: 7d 7d 20 7d 20 7b 0a 20 20 20 20 20 20 20 73 65  }} } {.       se
2500: 74 20 3a 3a 66 69 6e 20 31 0a 20 20 20 20 20 20  t ::fin 1.      
2510: 20 73 65 74 20 63 20 7b 31 20 7b 63 68 69 6c 64   set c {1 {child
2520: 20 70 72 6f 63 65 73 73 20 65 78 69 74 65 64 20   process exited 
2530: 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a 20 20 20  abnormally}}.   
2540: 20 20 7d 0a 20 20 20 20 20 73 65 74 20 63 0a 20    }.     set c. 
2550: 20 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f   } {1 {child pro
2560: 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f  cess exited abno
2570: 72 6d 61 6c 6c 79 7d 7d 0a 20 20 69 66 20 7b 20  rmally}}.  if { 
2580: 24 3a 3a 66 69 6e 20 7d 20 62 72 65 61 6b 0a 20  $::fin } break. 
2590: 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34   do_test crash-4
25a0: 2e 32 2e 24 69 2e 32 20 7b 0a 20 20 20 20 73 69  .2.$i.2 {.    si
25b0: 67 6e 61 74 75 72 65 0a 20 20 7d 20 24 73 69 67  gnature.  } $sig
25c0: 0a 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68  .  do_test crash
25d0: 2d 34 2e 32 2e 24 69 2e 33 20 7b 0a 20 20 20 20  -4.2.$i.3 {.    
25e0: 73 69 67 6e 61 74 75 72 65 32 0a 20 20 7d 20 24  signature2.  } $
25f0: 73 69 67 32 0a 7d 20 0a 66 6f 72 20 7b 73 65 74  sig2.} .for {set
2600: 20 69 20 31 7d 20 7b 24 69 20 3c 20 35 7d 20 7b   i 1} {$i < 5} {
2610: 69 6e 63 72 20 69 7d 20 7b 0a 20 20 73 65 74 20  incr i} {.  set 
2620: 73 69 67 20 5b 73 69 67 6e 61 74 75 72 65 5d 0a  sig [signature].
2630: 20 20 73 65 74 20 73 69 67 32 20 5b 73 69 67 6e    set sig2 [sign
2640: 61 74 75 72 65 32 5d 0a 20 20 64 6f 5f 74 65 73  ature2].  do_tes
2650: 74 20 63 72 61 73 68 2d 34 2e 33 2e 24 69 2e 31  t crash-4.3.$i.1
2660: 20 7b 0a 20 20 20 20 20 63 72 61 73 68 73 71 6c   {.     crashsql
2670: 20 31 20 74 65 73 74 2e 64 62 2d 6d 6a 2a 20 22   1 test.db-mj* "
2680: 0a 20 20 20 20 20 20 20 41 54 54 41 43 48 20 27  .       ATTACH '
2690: 74 65 73 74 32 2e 64 62 27 20 41 53 20 61 75 78  test2.db' AS aux
26a0: 3b 0a 20 20 20 20 20 20 20 42 45 47 49 4e 3b 0a  ;.       BEGIN;.
26b0: 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 72 61         SELECT ra
26c0: 6e 64 6f 6d 28 29 20 46 52 4f 4d 20 61 62 63 20  ndom() FROM abc 
26d0: 4c 49 4d 49 54 20 24 69 3b 0a 20 20 20 20 20 20  LIMIT $i;.      
26e0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
26f0: 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28   VALUES(randstr(
2700: 31 30 2c 31 30 29 2c 20 30 2c 20 30 29 3b 0a 20  10,10), 0, 0);. 
2710: 20 20 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f        DELETE FRO
2720: 4d 20 61 62 63 20 57 48 45 52 45 20 72 61 6e 64  M abc WHERE rand
2730: 6f 6d 28 29 25 31 30 21 3d 30 3b 0a 20 20 20 20  om()%10!=0;.    
2740: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
2750: 62 63 32 20 56 41 4c 55 45 53 28 72 61 6e 64 73  bc2 VALUES(rands
2760: 74 72 28 31 30 2c 31 30 29 2c 20 30 2c 20 30 29  tr(10,10), 0, 0)
2770: 3b 0a 20 20 20 20 20 20 20 44 45 4c 45 54 45 20  ;.       DELETE 
2780: 46 52 4f 4d 20 61 62 63 32 20 57 48 45 52 45 20  FROM abc2 WHERE 
2790: 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d 30 3b 0a  random()%10!=0;.
27a0: 20 20 20 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20         COMMIT;. 
27b0: 20 20 20 20 22 0a 20 20 7d 20 7b 31 20 7b 63 68      ".  } {1 {ch
27c0: 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78 69 74  ild process exit
27d0: 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a  ed abnormally}}.
27e0: 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d    do_test crash-
27f0: 34 2e 33 2e 24 69 2e 32 20 7b 0a 20 20 20 20 73  4.3.$i.2 {.    s
2800: 69 67 6e 61 74 75 72 65 0a 20 20 7d 20 24 73 69  ignature.  } $si
2810: 67 0a 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73  g.  do_test cras
2820: 68 2d 34 2e 33 2e 24 69 2e 33 20 7b 0a 20 20 20  h-4.3.$i.3 {.   
2830: 20 73 69 67 6e 61 74 75 72 65 32 0a 20 20 7d 20   signature2.  } 
2840: 24 73 69 67 32 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  $sig2.}..#------
2850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2890: 2d 2d 2d 2d 0a 23 20 54 68 65 20 66 6f 6c 6c 6f  ----.# The follo
28a0: 77 69 6e 67 20 74 65 73 74 20 63 61 73 65 73 20  wing test cases 
28b0: 2d 20 63 72 61 73 68 2d 35 2e 2a 20 2d 20 65 78  - crash-5.* - ex
28c0: 70 6f 73 65 73 20 61 20 62 75 67 20 74 68 61 74  poses a bug that
28d0: 20 65 78 69 73 74 65 64 20 69 6e 20 74 68 65 0a   existed in the.
28e0: 23 20 73 71 6c 69 74 65 33 70 61 67 65 72 5f 6d  # sqlite3pager_m
28f0: 6f 76 65 70 61 67 65 28 29 20 41 50 49 20 75 73  ovepage() API us
2900: 65 64 20 62 79 20 61 75 74 6f 2d 76 61 63 75 75  ed by auto-vacuu
2910: 6d 20 64 61 74 61 62 61 73 65 73 2e 0a 23 20 64  m databases..# d
2920: 61 74 61 62 61 73 65 20 77 68 65 6e 20 61 20 63  atabase when a c
2930: 72 61 73 68 20 6f 63 63 75 72 73 20 64 75 72 69  rash occurs duri
2940: 6e 67 20 61 20 6d 75 6c 74 69 2d 66 69 6c 65 20  ng a multi-file 
2950: 74 72 61 6e 73 61 63 74 69 6f 6e 2e 20 53 65 65  transaction. See
2960: 20 63 6f 6d 6d 65 6e 74 73 0a 23 20 69 6e 20 74   comments.# in t
2970: 65 73 74 20 63 72 61 73 68 2d 35 2e 33 20 66 6f  est crash-5.3 fo
2980: 72 20 64 65 74 61 69 6c 73 2e 0a 23 0a 64 62 20  r details..#.db 
2990: 63 6c 6f 73 65 0a 66 69 6c 65 20 64 65 6c 65 74  close.file delet
29a0: 65 20 2d 66 6f 72 63 65 20 74 65 73 74 2e 64 62  e -force test.db
29b0: 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74  .sqlite3 db test
29c0: 2e 64 62 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  .db.do_test cras
29d0: 68 2d 35 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  h-5.1 {.  execsq
29e0: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54  l {.    CREATE T
29f0: 41 42 4c 45 20 61 62 63 28 61 2c 20 62 2c 20 63  ABLE abc(a, b, c
2a00: 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  );              
2a10: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 52              -- R
2a20: 6f 6f 74 20 70 61 67 65 20 33 0a 20 20 20 20 49  oot page 3.    I
2a30: 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56  NSERT INTO abc V
2a40: 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28 31 35  ALUES(randstr(15
2a50: 30 30 2c 31 35 30 30 29 2c 20 30 2c 20 30 29 3b  00,1500), 0, 0);
2a60: 20 20 20 2d 2d 20 4f 76 65 72 66 6c 6f 77 20 70     -- Overflow p
2a70: 61 67 65 20 34 0a 20 20 20 20 49 4e 53 45 52 54  age 4.    INSERT
2a80: 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54   INTO abc SELECT
2a90: 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20   * FROM abc;.   
2aa0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
2ab0: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61   SELECT * FROM a
2ac0: 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  bc;.    INSERT I
2ad0: 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 2a  NTO abc SELECT *
2ae0: 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 7d 0a 7d   FROM abc;.  }.}
2af0: 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73   {}.do_test cras
2b00: 68 2d 35 2e 32 20 7b 0a 20 20 65 78 70 72 20 5b  h-5.2 {.  expr [
2b10: 66 69 6c 65 20 73 69 7a 65 20 74 65 73 74 2e 64  file size test.d
2b20: 62 5d 20 2f 20 31 30 32 34 0a 7d 20 5b 65 78 70  b] / 1024.} [exp
2b30: 72 20 5b 73 74 72 69 6e 67 20 6d 61 74 63 68 20  r [string match 
2b40: 5b 65 78 65 63 73 71 6c 20 7b 70 72 61 67 6d 61  [execsql {pragma
2b50: 20 61 75 74 6f 5f 76 61 63 75 75 6d 7d 5d 20 31   auto_vacuum}] 1
2b60: 5d 20 3f 20 31 31 20 3a 20 31 30 5d 0a 73 65 74  ] ? 11 : 10].set
2b70: 20 73 69 67 20 5b 73 69 67 6e 61 74 75 72 65 5d   sig [signature]
2b80: 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 35  .do_test crash-5
2b90: 2e 33 20 7b 0a 23 20 54 68 65 20 53 51 4c 20 62  .3 {.# The SQL b
2ba0: 65 6c 6f 77 20 69 73 20 75 73 65 64 20 74 6f 20  elow is used to 
2bb0: 65 78 70 6f 73 65 20 61 20 62 75 67 20 74 68 61  expose a bug tha
2bc0: 74 20 65 78 69 73 74 65 64 20 69 6e 0a 23 20 73  t existed in.# s
2bd0: 71 6c 69 74 65 33 70 61 67 65 72 5f 6d 6f 76 65  qlite3pager_move
2be0: 70 61 67 65 28 29 20 64 75 72 69 6e 67 20 64 65  page() during de
2bf0: 76 65 6c 6f 70 6d 65 6e 74 20 6f 66 20 74 68 65  velopment of the
2c00: 20 61 75 74 6f 2d 76 61 63 75 75 6d 20 66 65 61   auto-vacuum fea
2c10: 74 75 72 65 2e 20 49 74 0a 23 20 66 75 6e 63 74  ture. It.# funct
2c20: 69 6f 6e 73 20 61 73 20 66 6f 6c 6c 6f 77 73 3a  ions as follows:
2c30: 0a 23 20 0a 23 20 31 3a 20 42 65 67 69 6e 20 61  .# .# 1: Begin a
2c40: 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e 0a 23 20   transaction..# 
2c50: 32 3a 20 50 75 74 20 70 61 67 65 20 34 20 6f 6e  2: Put page 4 on
2c60: 20 74 68 65 20 66 72 65 65 2d 6c 69 73 74 20 28   the free-list (
2c70: 77 61 73 20 74 68 65 20 6f 76 65 72 66 6c 6f 77  was the overflow
2c80: 20 70 61 67 65 20 66 6f 72 20 74 68 65 20 72 6f   page for the ro
2c90: 77 20 64 65 6c 65 74 65 64 29 2e 0a 23 20 33 3a  w deleted)..# 3:
2ca0: 20 57 72 69 74 65 20 64 61 74 61 20 74 6f 20 70   Write data to p
2cb0: 61 67 65 20 34 20 28 69 74 20 62 65 63 6f 6d 65  age 4 (it become
2cc0: 73 20 74 68 65 20 6f 76 65 72 66 6c 6f 77 20 70  s the overflow p
2cd0: 61 67 65 20 66 6f 72 20 74 68 65 20 72 6f 77 20  age for the row 
2ce0: 69 6e 73 65 72 74 65 64 29 2e 0a 23 20 20 20 20  inserted)..#    
2cf0: 54 68 65 20 6f 6c 64 20 70 61 67 65 20 34 20 64  The old page 4 d
2d00: 61 74 61 20 68 61 73 20 62 65 65 6e 20 77 72 69  ata has been wri
2d10: 74 74 65 6e 20 74 6f 20 74 68 65 20 6a 6f 75 72  tten to the jour
2d20: 6e 61 6c 20 66 69 6c 65 2c 20 62 75 74 20 74 68  nal file, but th
2d30: 65 0a 23 20 20 20 20 6a 6f 75 72 6e 61 6c 20 66  e.#    journal f
2d40: 69 6c 65 20 68 61 73 20 6e 6f 74 20 62 65 65 6e  ile has not been
2d50: 20 73 79 6e 63 28 29 68 72 6f 6e 69 7a 65 64 2e   sync()hronized.
2d60: 0a 23 20 34 3a 20 43 72 65 61 74 65 20 61 20 74  .# 4: Create a t
2d70: 61 62 6c 65 2c 20 77 68 69 63 68 20 63 61 6c 6c  able, which call
2d80: 73 20 73 71 6c 69 74 65 33 70 61 67 65 72 5f 6d  s sqlite3pager_m
2d90: 6f 76 65 70 61 67 65 28 29 20 74 6f 20 6d 6f 76  ovepage() to mov
2da0: 65 20 70 61 67 65 20 34 0a 23 20 20 20 20 74 6f  e page 4.#    to
2db0: 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20   the end of the 
2dc0: 64 61 74 61 62 61 73 65 20 28 70 61 67 65 20 31  database (page 1
2dd0: 32 29 20 74 6f 20 6d 61 6b 65 20 72 6f 6f 6d 20  2) to make room 
2de0: 66 6f 72 20 74 68 65 20 6e 65 77 20 72 6f 6f 74  for the new root
2df0: 2d 70 61 67 65 2e 0a 23 20 35 3a 20 50 75 74 20  -page..# 5: Put 
2e00: 70 72 65 73 73 75 72 65 20 6f 6e 20 74 68 65 20  pressure on the 
2e10: 70 61 67 65 72 2d 63 61 63 68 65 2e 20 54 68 69  pager-cache. Thi
2e20: 73 20 72 65 73 75 6c 74 73 20 69 6e 20 70 61 67  s results in pag
2e30: 65 20 34 20 62 65 69 6e 67 20 77 72 69 74 74 65  e 4 being writte
2e40: 6e 0a 23 20 20 20 20 74 6f 20 74 68 65 20 64 61  n.#    to the da
2e50: 74 61 62 61 73 65 20 66 69 6c 65 20 74 6f 20 6d  tabase file to m
2e60: 61 6b 65 20 73 70 61 63 65 20 69 6e 20 74 68 65  ake space in the
2e70: 20 63 61 63 68 65 20 74 6f 20 6c 6f 61 64 20 61   cache to load a
2e80: 20 6e 65 77 20 70 61 67 65 2e 20 54 68 65 0a 23   new page. The.#
2e90: 20 20 20 20 62 75 67 20 77 61 73 20 74 68 61 74      bug was that
2ea0: 20 70 61 67 65 20 34 20 77 61 73 20 77 72 69 74   page 4 was writ
2eb0: 74 65 6e 20 74 6f 20 74 68 65 20 64 61 74 61 62  ten to the datab
2ec0: 61 73 65 20 66 69 6c 65 20 62 65 66 6f 72 65 20  ase file before 
2ed0: 74 68 65 20 6a 6f 75 72 6e 61 6c 0a 23 20 20 20  the journal.#   
2ee0: 20 69 73 20 73 79 6e 63 28 29 68 72 6f 6e 69 7a   is sync()hroniz
2ef0: 65 64 2e 0a 23 20 36 3a 20 43 6f 6d 6d 69 74 2e  ed..# 6: Commit.
2f00: 20 41 20 63 72 61 73 68 20 6f 63 63 75 72 73 20   A crash occurs 
2f10: 64 75 72 69 6e 67 20 74 68 65 20 73 79 6e 63 20  during the sync 
2f20: 6f 66 20 74 68 65 20 6a 6f 75 72 6e 61 6c 20 66  of the journal f
2f30: 69 6c 65 2e 0a 23 0a 23 20 45 6e 64 20 72 65 73  ile..#.# End res
2f40: 75 6c 74 3a 20 42 65 66 6f 72 65 20 74 68 65 20  ult: Before the 
2f50: 62 75 67 20 77 61 73 20 66 69 78 65 64 2c 20 64  bug was fixed, d
2f60: 61 74 61 20 68 61 73 20 62 65 65 6e 20 77 72 69  ata has been wri
2f70: 74 74 65 6e 20 74 6f 20 70 61 67 65 20 34 20 6f  tten to page 4 o
2f80: 66 20 74 68 65 0a 23 20 64 61 74 61 62 61 73 65  f the.# database
2f90: 20 66 69 6c 65 20 61 6e 64 20 74 68 65 20 6a 6f   file and the jo
2fa0: 75 72 6e 61 6c 20 66 69 6c 65 20 64 6f 65 73 20  urnal file does 
2fb0: 6e 6f 74 20 63 6f 6e 74 61 69 6e 20 74 72 75 73  not contain trus
2fc0: 74 77 6f 72 74 68 79 20 72 6f 6c 6c 62 61 63 6b  tworthy rollback
2fd0: 0a 23 20 64 61 74 61 20 66 6f 72 20 74 68 69 73  .# data for this
2fe0: 20 70 61 67 65 2e 0a 23 0a 20 20 63 72 61 73 68   page..#.  crash
2ff0: 73 71 6c 20 31 20 74 65 73 74 2e 64 62 2d 6a 6f  sql 1 test.db-jo
3000: 75 72 6e 61 6c 20 7b 0a 20 20 20 20 42 45 47 49  urnal {.    BEGI
3010: 4e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  N;              
3020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3030: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
3040: 2d 20 31 0a 20 20 20 20 44 45 4c 45 54 45 20 46  - 1.    DELETE F
3050: 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20 6f 69  ROM abc WHERE oi
3060: 64 20 3d 20 31 3b 20 20 20 20 20 20 20 20 20 20  d = 1;          
3070: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 32 0a             -- 2.
3080: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
3090: 61 62 63 20 56 41 4c 55 45 53 28 72 61 6e 64 73  abc VALUES(rands
30a0: 74 72 28 31 35 30 30 2c 31 35 30 30 29 2c 20 30  tr(1500,1500), 0
30b0: 2c 20 30 29 3b 20 20 2d 2d 20 33 0a 20 20 20 20  , 0);  -- 3.    
30c0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 61 62 63  CREATE TABLE abc
30d0: 32 28 61 2c 20 62 2c 20 63 29 3b 20 20 20 20 20  2(a, b, c);     
30e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
30f0: 20 20 20 2d 2d 20 34 0a 20 20 20 20 53 45 4c 45     -- 4.    SELE
3100: 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 20 20  CT * FROM abc;  
3110: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3120: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
3130: 2d 20 35 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 20  - 5.    COMMIT; 
3140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3150: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3160: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 36 0a             -- 6.
3170: 20 20 7d 0a 7d 20 7b 31 20 7b 63 68 69 6c 64 20    }.} {1 {child 
3180: 70 72 6f 63 65 73 73 20 65 78 69 74 65 64 20 61  process exited a
3190: 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a 69 6e 74 65  bnormally}}.inte
31a0: 67 72 69 74 79 5f 63 68 65 63 6b 20 63 72 61 73  grity_check cras
31b0: 68 2d 35 2e 34 0a 64 6f 5f 74 65 73 74 20 63 72  h-5.4.do_test cr
31c0: 61 73 68 2d 35 2e 35 20 7b 0a 20 20 73 69 67 6e  ash-5.5 {.  sign
31d0: 61 74 75 72 65 0a 7d 20 24 73 69 67 0a 0a 23 2d  ature.} $sig..#-
31e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65 20  ---------.# The 
3230: 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 20 63  following test c
3240: 61 73 65 73 20 2d 20 63 72 61 73 68 2d 36 2e 2a  ases - crash-6.*
3250: 20 2d 20 74 65 73 74 20 74 68 61 74 20 61 20 44   - test that a D
3260: 52 4f 50 20 54 41 42 4c 45 20 6f 70 65 72 61 74  ROP TABLE operat
3270: 69 6f 6e 0a 23 20 69 73 20 63 6f 72 72 65 63 74  ion.# is correct
3280: 6c 79 20 72 6f 6c 6c 65 64 20 62 61 63 6b 20 69  ly rolled back i
3290: 6e 20 74 68 65 20 65 76 65 6e 74 20 6f 66 20 61  n the event of a
32a0: 20 63 72 61 73 68 20 77 68 69 6c 65 20 74 68 65   crash while the
32b0: 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 0a 23   database file.#
32c0: 20 69 73 20 62 65 69 6e 67 20 77 72 69 74 74 65   is being writte
32d0: 6e 2e 20 54 68 69 73 20 69 73 20 6d 61 69 6e 6c  n. This is mainl
32e0: 79 20 74 6f 20 74 65 73 74 20 74 68 61 74 20 61  y to test that a
32f0: 6c 6c 20 70 61 67 65 73 20 61 72 65 20 77 72 69  ll pages are wri
3300: 74 74 65 6e 20 74 6f 20 74 68 65 0a 23 20 6a 6f  tten to the.# jo
3310: 75 72 6e 61 6c 20 66 69 6c 65 20 62 65 66 6f 72  urnal file befor
3320: 65 20 74 72 75 6e 63 61 74 69 6f 6e 20 69 6e 20  e truncation in 
3330: 61 6e 20 61 75 74 6f 2d 76 61 63 75 75 6d 20 64  an auto-vacuum d
3340: 61 74 61 62 61 73 65 2e 0a 23 0a 64 6f 5f 74 65  atabase..#.do_te
3350: 73 74 20 63 72 61 73 68 2d 36 2e 31 20 7b 0a 20  st crash-6.1 {. 
3360: 20 63 72 61 73 68 73 71 6c 20 31 20 74 65 73 74   crashsql 1 test
3370: 2e 64 62 20 7b 0a 20 20 20 20 44 52 4f 50 20 54  .db {.    DROP T
3380: 41 42 4c 45 20 61 62 63 3b 0a 20 20 7d 0a 7d 20  ABLE abc;.  }.} 
3390: 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73  {1 {child proces
33a0: 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61  s exited abnorma
33b0: 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73 74 20 63 72  lly}}.do_test cr
33c0: 61 73 68 2d 36 2e 32 20 7b 0a 20 20 73 69 67 6e  ash-6.2 {.  sign
33d0: 61 74 75 72 65 0a 7d 20 24 73 69 67 0a 0a 23 2d  ature.} $sig..#-
33e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
33f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3410: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3420: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65 73  ---------.# Thes
3430: 65 20 74 65 73 74 20 63 61 73 65 73 20 74 65 73  e test cases tes
3440: 74 20 74 68 65 20 63 61 73 65 20 77 68 65 72 65  t the case where
3450: 20 74 68 65 20 6d 61 73 74 65 72 20 6a 6f 75 72   the master jour
3460: 6e 61 6c 20 66 69 6c 65 20 6e 61 6d 65 20 69 73  nal file name is
3470: 20 0a 23 20 63 6f 72 72 75 70 74 65 64 20 73 6c   .# corrupted sl
3480: 69 67 68 74 6c 79 20 73 6f 20 74 68 61 74 20 74  ightly so that t
3490: 68 65 20 63 6f 72 72 75 70 74 69 6f 6e 20 68 61  he corruption ha
34a0: 73 20 74 6f 20 62 65 20 64 65 74 65 63 74 65 64  s to be detected
34b0: 20 62 79 20 74 68 65 0a 23 20 63 68 65 63 6b 73   by the.# checks
34c0: 75 6d 2e 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  um..do_test cras
34d0: 68 2d 37 2e 31 20 7b 0a 20 20 63 72 61 73 68 73  h-7.1 {.  crashs
34e0: 71 6c 20 31 20 74 65 73 74 2e 64 62 20 7b 0a 20  ql 1 test.db {. 
34f0: 20 20 20 41 54 54 41 43 48 20 27 74 65 73 74 32     ATTACH 'test2
3500: 2e 64 62 27 20 41 53 20 61 75 78 3b 0a 20 20 20  .db' AS aux;.   
3510: 20 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45   BEGIN;.    INSE
3520: 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55  RT INTO abc VALU
3530: 45 53 28 72 61 6e 64 73 74 72 28 31 35 30 30 2c  ES(randstr(1500,
3540: 31 35 30 30 29 2c 20 30 2c 20 30 29 3b 0a 20 20  1500), 0, 0);.  
3550: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62    INSERT INTO ab
3560: 63 32 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74  c2 VALUES(randst
3570: 72 28 31 35 30 30 2c 31 35 30 30 29 2c 20 30 2c  r(1500,1500), 0,
3580: 20 30 29 3b 0a 20 20 20 20 43 4f 4d 4d 49 54 3b   0);.    COMMIT;
3590: 0a 20 20 7d 0a 0a 20 20 23 20 43 68 61 6e 67 65  .  }..  # Change
35a0: 20 74 68 65 20 63 68 65 63 6b 73 75 6d 20 76 61   the checksum va
35b0: 6c 75 65 20 66 6f 72 20 74 68 65 20 6d 61 73 74  lue for the mast
35c0: 65 72 20 6a 6f 75 72 6e 61 6c 20 6e 61 6d 65 2e  er journal name.
35d0: 0a 20 20 73 65 74 20 66 20 5b 6f 70 65 6e 20 74  .  set f [open t
35e0: 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c 20 61  est.db-journal a
35f0: 5d 0a 20 20 66 63 6f 6e 66 69 67 75 72 65 20 24  ].  fconfigure $
3600: 66 20 2d 65 6e 63 6f 64 69 6e 67 20 62 69 6e 61  f -encoding bina
3610: 72 79 0a 20 20 73 65 65 6b 20 24 66 20 5b 65 78  ry.  seek $f [ex
3620: 70 72 20 5b 66 69 6c 65 20 73 69 7a 65 20 74 65  pr [file size te
3630: 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c 5d 20 2d  st.db-journal] -
3640: 20 31 32 5d 0a 20 20 70 75 74 73 20 2d 6e 6f 6e   12].  puts -non
3650: 65 77 6c 69 6e 65 20 24 66 20 22 5c 30 30 5c 30  ewline $f "\00\0
3660: 30 5c 30 30 5c 30 30 22 0a 20 20 63 6c 6f 73 65  0\00\00".  close
3670: 20 24 66 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74   $f.} {}.do_test
3680: 20 63 72 61 73 68 2d 37 2e 32 20 7b 0a 20 20 73   crash-7.2 {.  s
3690: 69 67 6e 61 74 75 72 65 0a 7d 20 24 73 69 67 0a  ignature.} $sig.
36a0: 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a           .finish_test.