/ Hex Artifact Content
Login

Artifact fb9dc4a02dcba30d4aa5c2c226f98b220b2b959f:


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 75 73 69 6e 67 20 74 68 65 20 6d 6f 64  ed using the mod
02a0: 69 66 69 65 64 20 49 2f 4f 20 72 6f 75 74 69 6e  ified I/O routin
02b0: 65 73 20 66 6f 75 6e 64 20 69 6e 20 74 65 73 74  es found in test
02c0: 36 2e 63 2e 20 20 0a 23 20 54 68 65 73 65 20 72  6.c.  .# These r
02d0: 6f 75 74 69 6e 65 73 20 61 6c 6c 6f 77 20 75 73  outines allow us
02e0: 20 74 6f 20 73 69 6d 75 6c 61 74 65 20 74 68 65   to simulate the
02f0: 20 6b 69 6e 64 20 6f 66 20 66 69 6c 65 20 64 61   kind of file da
0300: 6d 61 67 65 20 74 68 61 74 20 0a 23 20 6f 63 63  mage that .# occ
0310: 75 72 73 20 61 66 74 65 72 20 61 20 70 6f 77 65  urs after a powe
0320: 72 20 66 61 69 6c 75 72 65 2e 0a 23 0a 23 20 24  r failure..#.# $
0330: 49 64 3a 20 63 72 61 73 68 2e 74 65 73 74 2c 76  Id: crash.test,v
0340: 20 31 2e 32 37 20 32 30 30 38 2f 30 31 2f 30 38   1.27 2008/01/08
0350: 20 31 35 3a 31 38 3a 35 32 20 64 72 68 20 45 78   15:18:52 drh Ex
0360: 70 20 24 0a 0a 73 65 74 20 74 65 73 74 64 69 72  p $..set testdir
0370: 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 24   [file dirname $
0380: 61 72 67 76 30 5d 0a 73 6f 75 72 63 65 20 24 74  argv0].source $t
0390: 65 73 74 64 69 72 2f 74 65 73 74 65 72 2e 74 63  estdir/tester.tc
03a0: 6c 0a 0a 69 66 63 61 70 61 62 6c 65 20 21 63 72  l..ifcapable !cr
03b0: 61 73 68 74 65 73 74 20 7b 0a 20 20 66 69 6e 69  ashtest {.  fini
03c0: 73 68 5f 74 65 73 74 0a 20 20 72 65 74 75 72 6e  sh_test.  return
03d0: 0a 7d 0a 0a 73 65 74 20 72 65 70 65 61 74 73 20  .}..set repeats 
03e0: 31 30 30 0a 23 73 65 74 20 72 65 70 65 61 74 73  100.#set repeats
03f0: 20 31 30 0a 0a 23 20 54 68 65 20 66 6f 6c 6c 6f   10..# The follo
0400: 77 69 6e 67 20 70 72 6f 63 65 64 75 72 65 20 63  wing procedure c
0410: 6f 6d 70 75 74 65 73 20 61 20 22 73 69 67 6e 61  omputes a "signa
0420: 74 75 72 65 22 20 66 6f 72 20 74 61 62 6c 65 20  ture" for table 
0430: 22 61 62 63 22 2e 20 20 49 66 0a 23 20 61 62 63  "abc".  If.# abc
0440: 20 63 68 61 6e 67 65 73 20 69 6e 20 61 6e 79 20   changes in any 
0450: 77 61 79 2c 20 74 68 65 20 73 69 67 6e 61 74 75  way, the signatu
0460: 72 65 20 73 68 6f 75 6c 64 20 63 68 61 6e 67 65  re should change
0470: 2e 20 20 0a 70 72 6f 63 20 73 69 67 6e 61 74 75  .  .proc signatu
0480: 72 65 20 7b 7d 20 7b 0a 20 20 72 65 74 75 72 6e  re {} {.  return
0490: 20 5b 64 62 20 65 76 61 6c 20 7b 53 45 4c 45 43   [db eval {SELEC
04a0: 54 20 63 6f 75 6e 74 28 2a 29 2c 20 6d 64 35 73  T count(*), md5s
04b0: 75 6d 28 61 29 2c 20 6d 64 35 73 75 6d 28 62 29  um(a), md5sum(b)
04c0: 2c 20 6d 64 35 73 75 6d 28 63 29 20 46 52 4f 4d  , md5sum(c) FROM
04d0: 20 61 62 63 7d 5d 0a 7d 0a 70 72 6f 63 20 73 69   abc}].}.proc si
04e0: 67 6e 61 74 75 72 65 32 20 7b 7d 20 7b 0a 20 20  gnature2 {} {.  
04f0: 72 65 74 75 72 6e 20 5b 64 62 20 65 76 61 6c 20  return [db eval 
0500: 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29  {SELECT count(*)
0510: 2c 20 6d 64 35 73 75 6d 28 61 29 2c 20 6d 64 35  , md5sum(a), md5
0520: 73 75 6d 28 62 29 2c 20 6d 64 35 73 75 6d 28 63  sum(b), md5sum(c
0530: 29 20 46 52 4f 4d 20 61 62 63 32 7d 5d 0a 7d 0a  ) FROM abc2}].}.
0540: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
0550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0580: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 53  ------------.# S
0590: 69 6d 70 6c 65 20 63 72 61 73 68 20 74 65 73 74  imple crash test
05a0: 3a 0a 23 0a 23 20 63 72 61 73 68 2d 31 2e 31 3a  :.#.# crash-1.1:
05b0: 20 43 72 65 61 74 65 20 61 20 64 61 74 61 62 61   Create a databa
05c0: 73 65 20 77 69 74 68 20 61 20 74 61 62 6c 65 20  se with a table 
05d0: 77 69 74 68 20 74 77 6f 20 72 6f 77 73 2e 0a 23  with two rows..#
05e0: 20 63 72 61 73 68 2d 31 2e 32 3a 20 52 75 6e 20   crash-1.2: Run 
05f0: 61 20 27 44 45 4c 45 54 45 20 46 52 4f 4d 20 61  a 'DELETE FROM a
0600: 62 63 20 57 48 45 52 45 20 61 20 3d 20 31 27 20  bc WHERE a = 1' 
0610: 74 68 61 74 20 63 72 61 73 68 65 73 20 64 75 72  that crashes dur
0620: 69 6e 67 0a 23 20 20 20 20 20 20 20 20 20 20 20  ing.#           
0630: 20 74 68 65 20 66 69 72 73 74 20 6a 6f 75 72 6e   the first journ
0640: 61 6c 2d 73 79 6e 63 2e 0a 23 20 63 72 61 73 68  al-sync..# crash
0650: 2d 31 2e 33 3a 20 45 6e 73 75 72 65 20 74 68 65  -1.3: Ensure the
0660: 20 64 61 74 61 62 61 73 65 20 69 73 20 69 6e 20   database is in 
0670: 74 68 65 20 73 61 6d 65 20 73 74 61 74 65 20 61  the same state a
0680: 73 20 61 66 74 65 72 20 63 72 61 73 68 2d 31 2e  s after crash-1.
0690: 31 2e 0a 23 20 63 72 61 73 68 2d 31 2e 34 3a 20  1..# crash-1.4: 
06a0: 52 75 6e 20 61 20 27 44 45 4c 45 54 45 20 46 52  Run a 'DELETE FR
06b0: 4f 4d 20 61 62 63 20 57 48 45 52 45 20 61 20 3d  OM abc WHERE a =
06c0: 20 31 27 20 74 68 61 74 20 63 72 61 73 68 65 73   1' that crashes
06d0: 20 64 75 72 69 6e 67 0a 23 20 20 20 20 20 20 20   during.#       
06e0: 20 20 20 20 20 74 68 65 20 66 69 72 73 74 20 64       the first d
06f0: 61 74 61 62 61 73 65 2d 73 79 6e 63 2e 0a 23 20  atabase-sync..# 
0700: 63 72 61 73 68 2d 31 2e 35 3a 20 45 6e 73 75 72  crash-1.5: Ensur
0710: 65 20 74 68 65 20 64 61 74 61 62 61 73 65 20 69  e the database i
0720: 73 20 69 6e 20 74 68 65 20 73 61 6d 65 20 73 74  s in the same st
0730: 61 74 65 20 61 73 20 61 66 74 65 72 20 63 72 61  ate as after cra
0740: 73 68 2d 31 2e 31 2e 0a 23 20 63 72 61 73 68 2d  sh-1.1..# crash-
0750: 31 2e 36 3a 20 52 75 6e 20 61 20 27 44 45 4c 45  1.6: Run a 'DELE
0760: 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45 52  TE FROM abc WHER
0770: 45 20 61 20 3d 20 31 27 20 74 68 61 74 20 63 72  E a = 1' that cr
0780: 61 73 68 65 73 20 64 75 72 69 6e 67 0a 23 20 20  ashes during.#  
0790: 20 20 20 20 20 20 20 20 20 20 74 68 65 20 73 65            the se
07a0: 63 6f 6e 64 20 6a 6f 75 72 6e 61 6c 2d 73 79 6e  cond journal-syn
07b0: 63 2e 0a 23 20 63 72 61 73 68 2d 31 2e 37 3a 20  c..# crash-1.7: 
07c0: 45 6e 73 75 72 65 20 74 68 65 20 64 61 74 61 62  Ensure the datab
07d0: 61 73 65 20 69 73 20 69 6e 20 74 68 65 20 73 61  ase is in the sa
07e0: 6d 65 20 73 74 61 74 65 20 61 73 20 61 66 74 65  me state as afte
07f0: 72 20 63 72 61 73 68 2d 31 2e 31 2e 0a 23 0a 23  r crash-1.1..#.#
0800: 20 54 65 73 74 73 20 31 2e 38 20 74 68 72 6f 75   Tests 1.8 throu
0810: 67 68 20 31 2e 31 31 20 74 65 73 74 20 66 6f 72  gh 1.11 test for
0820: 20 63 72 61 73 68 65 73 20 6f 6e 20 74 68 65 20   crashes on the 
0830: 74 68 69 72 64 20 6a 6f 75 72 6e 61 6c 20 73 79  third journal sy
0840: 6e 63 20 61 6e 64 0a 23 20 73 65 63 6f 6e 64 20  nc and.# second 
0850: 64 61 74 61 62 61 73 65 20 73 79 6e 63 2e 20 20  database sync.  
0860: 4e 65 69 74 68 65 72 20 6f 66 20 74 68 65 73 65  Neither of these
0870: 20 69 73 20 72 65 71 75 69 72 65 64 20 69 6e 20   is required in 
0880: 73 75 63 68 20 61 20 73 6d 61 6c 6c 20 74 65 73  such a small tes
0890: 74 0a 23 20 63 61 73 65 2c 20 73 6f 20 74 68 65  t.# case, so the
08a0: 73 65 20 74 65 73 74 73 20 61 72 65 20 6a 75 73  se tests are jus
08b0: 74 20 74 6f 20 76 65 72 69 66 79 20 74 68 61 74  t to verify that
08c0: 20 74 68 65 20 74 65 73 74 20 69 6e 66 72 61 73   the test infras
08d0: 74 72 75 63 74 75 72 65 0a 23 20 6f 70 65 72 61  tructure.# opera
08e0: 74 65 73 20 61 73 20 65 78 70 65 63 74 65 64 2e  tes as expected.
08f0: 0a 23 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68  .#.do_test crash
0900: 2d 31 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -1.1 {.  execsql
0910: 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41   {.    CREATE TA
0920: 42 4c 45 20 61 62 63 28 61 2c 20 62 2c 20 63 29  BLE abc(a, b, c)
0930: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
0940: 4f 20 61 62 63 20 56 41 4c 55 45 53 28 31 2c 20  O abc VALUES(1, 
0950: 32 2c 20 33 29 3b 0a 20 20 20 20 49 4e 53 45 52  2, 3);.    INSER
0960: 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55 45  T INTO abc VALUE
0970: 53 28 34 2c 20 35 2c 20 36 29 3b 0a 20 20 7d 0a  S(4, 5, 6);.  }.
0980: 20 20 73 65 74 20 3a 3a 73 69 67 20 5b 73 69 67    set ::sig [sig
0990: 6e 61 74 75 72 65 5d 0a 20 20 65 78 70 72 20 30  nature].  expr 0
09a0: 0a 7d 20 7b 30 7d 0a 66 6f 72 20 7b 73 65 74 20  .} {0}.for {set 
09b0: 69 20 30 7d 20 7b 24 69 3c 31 30 7d 20 7b 69 6e  i 0} {$i<10} {in
09c0: 63 72 20 69 7d 20 7b 0a 20 20 73 65 74 20 73 65  cr i} {.  set se
09d0: 65 64 20 5b 65 78 70 72 20 7b 69 6e 74 28 61 62  ed [expr {int(ab
09e0: 73 28 72 61 6e 64 28 29 2a 31 30 30 30 30 29 29  s(rand()*10000))
09f0: 7d 5d 0a 20 20 64 6f 5f 74 65 73 74 20 63 72 61  }].  do_test cra
0a00: 73 68 2d 31 2e 32 2e 24 69 20 7b 0a 20 20 20 20  sh-1.2.$i {.    
0a10: 63 72 61 73 68 73 71 6c 20 2d 64 65 6c 61 79 20  crashsql -delay 
0a20: 31 20 2d 66 69 6c 65 20 74 65 73 74 2e 64 62 2d  1 -file test.db-
0a30: 6a 6f 75 72 6e 61 6c 20 2d 73 65 65 64 20 24 73  journal -seed $s
0a40: 65 65 64 20 7b 0a 20 20 20 20 20 20 44 45 4c 45  eed {.      DELE
0a50: 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45 52  TE FROM abc WHER
0a60: 45 20 61 20 3d 20 31 3b 0a 20 20 20 20 7d 0a 20  E a = 1;.    }. 
0a70: 20 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f   } {1 {child pro
0a80: 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f  cess exited abno
0a90: 72 6d 61 6c 6c 79 7d 7d 0a 20 20 64 6f 5f 74 65  rmally}}.  do_te
0aa0: 73 74 20 63 72 61 73 68 2d 31 2e 33 2e 24 69 20  st crash-1.3.$i 
0ab0: 7b 0a 20 20 20 20 73 69 67 6e 61 74 75 72 65 0a  {.    signature.
0ac0: 20 20 7d 20 24 3a 3a 73 69 67 0a 7d 0a 64 6f 5f    } $::sig.}.do_
0ad0: 74 65 73 74 20 63 72 61 73 68 2d 31 2e 34 20 7b  test crash-1.4 {
0ae0: 0a 20 20 63 72 61 73 68 73 71 6c 20 2d 64 65 6c  .  crashsql -del
0af0: 61 79 20 31 20 2d 66 69 6c 65 20 74 65 73 74 2e  ay 1 -file test.
0b00: 64 62 20 7b 0a 20 20 20 20 44 45 4c 45 54 45 20  db {.    DELETE 
0b10: 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20 61  FROM abc WHERE a
0b20: 20 3d 20 31 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b   = 1;.  }.} {1 {
0b30: 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78  child process ex
0b40: 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d  ited abnormally}
0b50: 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d  }.do_test crash-
0b60: 31 2e 35 20 7b 0a 20 20 73 69 67 6e 61 74 75 72  1.5 {.  signatur
0b70: 65 0a 7d 20 24 3a 3a 73 69 67 0a 64 6f 5f 74 65  e.} $::sig.do_te
0b80: 73 74 20 63 72 61 73 68 2d 31 2e 36 20 7b 0a 20  st crash-1.6 {. 
0b90: 20 63 72 61 73 68 73 71 6c 20 2d 64 65 6c 61 79   crashsql -delay
0ba0: 20 32 20 2d 66 69 6c 65 20 74 65 73 74 2e 64 62   2 -file test.db
0bb0: 2d 6a 6f 75 72 6e 61 6c 20 7b 0a 20 20 20 20 44  -journal {.    D
0bc0: 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57  ELETE FROM abc W
0bd0: 48 45 52 45 20 61 20 3d 20 31 3b 0a 20 20 7d 0a  HERE a = 1;.  }.
0be0: 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63  } {1 {child proc
0bf0: 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72  ess exited abnor
0c00: 6d 61 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73 74 20  mally}}.do_test 
0c10: 63 72 61 73 68 2d 31 2e 37 20 7b 0a 20 20 63 61  crash-1.7 {.  ca
0c20: 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  tchsql {.    SEL
0c30: 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a  ECT * FROM abc;.
0c40: 20 20 7d 0a 7d 20 7b 30 20 7b 31 20 32 20 33 20    }.} {0 {1 2 3 
0c50: 34 20 35 20 36 7d 7d 0a 0a 64 6f 5f 74 65 73 74  4 5 6}}..do_test
0c60: 20 63 72 61 73 68 2d 31 2e 38 20 7b 0a 20 20 63   crash-1.8 {.  c
0c70: 72 61 73 68 73 71 6c 20 2d 64 65 6c 61 79 20 33  rashsql -delay 3
0c80: 20 2d 66 69 6c 65 20 74 65 73 74 2e 64 62 2d 6a   -file test.db-j
0c90: 6f 75 72 6e 61 6c 20 7b 0a 20 20 20 20 44 45 4c  ournal {.    DEL
0ca0: 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45  ETE FROM abc WHE
0cb0: 52 45 20 61 20 3d 20 31 3b 0a 20 20 7d 0a 7d 20  RE a = 1;.  }.} 
0cc0: 7b 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20 63  {0 {}}.do_test c
0cd0: 72 61 73 68 2d 31 2e 39 20 7b 0a 20 20 63 61 74  rash-1.9 {.  cat
0ce0: 63 68 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  chsql {.    SELE
0cf0: 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20  CT * FROM abc;. 
0d00: 20 7d 0a 7d 20 7b 30 20 7b 34 20 35 20 36 7d 7d   }.} {0 {4 5 6}}
0d10: 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 31  .do_test crash-1
0d20: 2e 31 30 20 7b 0a 20 20 63 72 61 73 68 73 71 6c  .10 {.  crashsql
0d30: 20 2d 64 65 6c 61 79 20 32 20 2d 66 69 6c 65 20   -delay 2 -file 
0d40: 74 65 73 74 2e 64 62 20 7b 0a 20 20 20 20 44 45  test.db {.    DE
0d50: 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48  LETE FROM abc WH
0d60: 45 52 45 20 61 20 3d 20 34 3b 0a 20 20 7d 0a 7d  ERE a = 4;.  }.}
0d70: 20 7b 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20   {0 {}}.do_test 
0d80: 63 72 61 73 68 2d 31 2e 31 31 20 7b 0a 20 20 63  crash-1.11 {.  c
0d90: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 53 45  atchsql {.    SE
0da0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b  LECT * FROM abc;
0db0: 0a 20 20 7d 0a 7d 20 7b 30 20 7b 7d 7d 0a 0a 23  .  }.} {0 {}}..#
0dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0de0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0df0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65  ----------.# The
0e10: 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 73   following tests
0e20: 20 74 65 73 74 20 72 65 63 6f 76 65 72 79 20 77   test recovery w
0e30: 68 65 6e 20 62 6f 74 68 20 74 68 65 20 64 61 74  hen both the dat
0e40: 61 62 61 73 65 20 66 69 6c 65 20 61 6e 64 20 74  abase file and t
0e50: 68 65 0a 23 20 6a 6f 75 72 6e 61 6c 20 66 69 6c  he.# journal fil
0e60: 65 20 63 6f 6e 74 61 69 6e 20 63 6f 72 72 75 70  e contain corrup
0e70: 74 20 64 61 74 61 2e 20 54 68 69 73 20 63 61 6e  t data. This can
0e80: 20 68 61 70 70 65 6e 20 61 66 74 65 72 20 70 61   happen after pa
0e90: 67 65 73 20 61 72 65 0a 23 20 77 72 69 74 74 65  ges are.# writte
0ea0: 6e 20 74 6f 20 74 68 65 20 64 61 74 61 62 61 73  n to the databas
0eb0: 65 20 66 69 6c 65 20 62 65 66 6f 72 65 20 61 20  e file before a 
0ec0: 74 72 61 6e 73 61 63 74 69 6f 6e 20 69 73 20 63  transaction is c
0ed0: 6f 6d 6d 69 74 74 65 64 20 64 75 65 20 74 6f 0a  ommitted due to.
0ee0: 23 20 63 61 63 68 65 2d 70 72 65 73 73 75 72 65  # cache-pressure
0ef0: 2e 0a 23 0a 23 20 63 72 61 73 68 2d 32 2e 31 3a  ..#.# crash-2.1:
0f00: 20 49 6e 73 65 72 74 20 31 38 20 70 61 67 65 73   Insert 18 pages
0f10: 20 6f 66 20 64 61 74 61 20 69 6e 74 6f 20 74 68   of data into th
0f20: 65 20 64 61 74 61 62 61 73 65 2e 0a 23 20 63 72  e database..# cr
0f30: 61 73 68 2d 32 2e 32 3a 20 43 68 65 63 6b 20 74  ash-2.2: Check t
0f40: 68 65 20 64 61 74 61 62 61 73 65 20 66 69 6c 65  he database file
0f50: 20 73 69 7a 65 20 6c 6f 6f 6b 73 20 6f 6b 2e 0a   size looks ok..
0f60: 23 20 63 72 61 73 68 2d 32 2e 33 3a 20 44 65 6c  # crash-2.3: Del
0f70: 65 74 65 20 31 35 20 6f 72 20 73 6f 20 70 61 67  ete 15 or so pag
0f80: 65 73 20 28 77 69 74 68 20 61 20 31 30 20 70 61  es (with a 10 pa
0f90: 67 65 20 70 61 67 65 2d 63 61 63 68 65 29 2c 20  ge page-cache), 
0fa0: 74 68 65 6e 20 63 72 61 73 68 2e 0a 23 20 63 72  then crash..# cr
0fb0: 61 73 68 2d 32 2e 34 3a 20 45 6e 73 75 72 65 20  ash-2.4: Ensure 
0fc0: 74 68 65 20 64 61 74 61 62 61 73 65 20 69 73 20  the database is 
0fd0: 69 6e 20 74 68 65 20 73 61 6d 65 20 73 74 61 74  in the same stat
0fe0: 65 20 61 73 20 61 66 74 65 72 20 63 72 61 73 68  e as after crash
0ff0: 2d 32 2e 31 2e 0a 23 0a 23 20 54 65 73 74 20 63  -2.1..#.# Test c
1000: 61 73 65 73 20 63 72 61 73 68 2d 32 2e 35 20 61  ases crash-2.5 a
1010: 6e 64 20 63 72 61 73 68 2d 32 2e 36 20 63 68 65  nd crash-2.6 che
1020: 63 6b 20 74 68 61 74 20 74 68 65 20 64 61 74 61  ck that the data
1030: 62 61 73 65 20 69 73 20 4f 4b 20 69 66 20 74 68  base is OK if th
1040: 65 20 0a 23 20 63 72 61 73 68 20 6f 63 63 75 72  e .# crash occur
1050: 73 20 64 75 72 69 6e 67 20 74 68 65 20 6d 61 69  s during the mai
1060: 6e 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20  n database file 
1070: 73 79 6e 63 2e 20 42 75 74 20 74 68 69 73 20 69  sync. But this i
1080: 73 6e 27 74 20 72 65 61 6c 6c 79 0a 23 20 64 69  sn't really.# di
1090: 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 74 68 65  fferent from the
10a0: 20 63 72 61 73 68 2d 31 2e 2a 20 63 61 73 65 73   crash-1.* cases
10b0: 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  ..#.do_test cras
10c0: 68 2d 32 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  h-2.1 {.  execsq
10d0: 6c 20 7b 20 42 45 47 49 4e 20 7d 0a 20 20 66 6f  l { BEGIN }.  fo
10e0: 72 20 7b 73 65 74 20 6e 20 30 7d 20 7b 24 6e 20  r {set n 0} {$n 
10f0: 3c 20 31 30 30 30 7d 20 7b 69 6e 63 72 20 6e 7d  < 1000} {incr n}
1100: 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 22   {.    execsql "
1110: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20  INSERT INTO abc 
1120: 56 41 4c 55 45 53 28 24 6e 2c 20 5b 65 78 70 72  VALUES($n, [expr
1130: 20 32 2a 24 6e 5d 2c 20 5b 65 78 70 72 20 33 2a   2*$n], [expr 3*
1140: 24 6e 5d 29 22 0a 20 20 7d 0a 20 20 65 78 65 63  $n])".  }.  exec
1150: 73 71 6c 20 7b 20 43 4f 4d 4d 49 54 20 7d 0a 20  sql { COMMIT }. 
1160: 20 73 65 74 20 3a 3a 73 69 67 20 5b 73 69 67 6e   set ::sig [sign
1170: 61 74 75 72 65 5d 0a 20 20 65 78 65 63 73 71 6c  ature].  execsql
1180: 20 7b 20 53 45 4c 45 43 54 20 73 75 6d 28 61 29   { SELECT sum(a)
1190: 2c 20 73 75 6d 28 62 29 2c 20 73 75 6d 28 63 29  , sum(b), sum(c)
11a0: 20 66 72 6f 6d 20 61 62 63 20 7d 0a 7d 20 7b 34   from abc }.} {4
11b0: 39 39 35 30 30 20 39 39 39 30 30 30 20 31 34 39  99500 999000 149
11c0: 38 35 30 30 7d 0a 64 6f 5f 74 65 73 74 20 63 72  8500}.do_test cr
11d0: 61 73 68 2d 32 2e 32 20 7b 0a 20 20 65 78 70 72  ash-2.2 {.  expr
11e0: 20 28 5b 66 69 6c 65 20 73 69 7a 65 20 74 65 73   ([file size tes
11f0: 74 2e 64 62 5d 20 2f 20 31 30 32 34 29 3e 31 36  t.db] / 1024)>16
1200: 0a 7d 20 7b 31 7d 0a 64 6f 5f 74 65 73 74 20 63  .} {1}.do_test c
1210: 72 61 73 68 2d 32 2e 33 20 7b 0a 20 20 63 72 61  rash-2.3 {.  cra
1220: 73 68 73 71 6c 20 2d 64 65 6c 61 79 20 32 20 2d  shsql -delay 2 -
1230: 66 69 6c 65 20 74 65 73 74 2e 64 62 2d 6a 6f 75  file test.db-jou
1240: 72 6e 61 6c 20 7b 0a 20 20 20 20 44 45 4c 45 54  rnal {.    DELET
1250: 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45  E FROM abc WHERE
1260: 20 61 20 3c 20 38 30 30 3b 0a 20 20 7d 0a 7d 20   a < 800;.  }.} 
1270: 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73  {1 {child proces
1280: 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61  s exited abnorma
1290: 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73 74 20 63 72  lly}}.do_test cr
12a0: 61 73 68 2d 32 2e 34 20 7b 0a 20 20 73 69 67 6e  ash-2.4 {.  sign
12b0: 61 74 75 72 65 0a 7d 20 24 73 69 67 0a 64 6f 5f  ature.} $sig.do_
12c0: 74 65 73 74 20 63 72 61 73 68 2d 32 2e 35 20 7b  test crash-2.5 {
12d0: 0a 20 20 63 72 61 73 68 73 71 6c 20 2d 64 65 6c  .  crashsql -del
12e0: 61 79 20 31 20 2d 66 69 6c 65 20 74 65 73 74 2e  ay 1 -file test.
12f0: 64 62 20 7b 0a 20 20 20 20 44 45 4c 45 54 45 20  db {.    DELETE 
1300: 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20 61  FROM abc WHERE a
1310: 3c 38 30 30 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b  <800;.  }.} {1 {
1320: 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78  child process ex
1330: 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d  ited abnormally}
1340: 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d  }.do_test crash-
1350: 32 2e 36 20 7b 0a 20 20 73 69 67 6e 61 74 75 72  2.6 {.  signatur
1360: 65 0a 7d 20 24 73 69 67 0a 0a 23 2d 2d 2d 2d 2d  e.} $sig..#-----
1370: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1380: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13b0: 2d 2d 2d 2d 2d 0a 23 20 54 68 65 20 63 72 61 73  -----.# The cras
13c0: 68 2d 33 2e 2a 20 74 65 73 74 20 63 61 73 65 73  h-3.* test cases
13d0: 20 61 72 65 20 65 73 73 65 6e 74 69 61 6c 6c 79   are essentially
13e0: 20 74 68 65 20 73 61 6d 65 20 74 65 73 74 20 61   the same test a
13f0: 73 20 74 65 73 74 20 63 61 73 65 0a 23 20 63 72  s test case.# cr
1400: 61 73 68 2d 32 2e 2a 2c 20 62 75 74 20 77 69 74  ash-2.*, but wit
1410: 68 20 61 20 6d 6f 72 65 20 63 6f 6d 70 6c 69 63  h a more complic
1420: 61 74 65 64 20 64 61 74 61 20 73 65 74 2e 20 0a  ated data set. .
1430: 23 0a 23 20 54 68 65 20 74 65 73 74 20 69 73 20  #.# The test is 
1440: 72 65 70 65 61 74 65 64 20 61 20 66 65 77 20 74  repeated a few t
1450: 69 6d 65 73 20 77 69 74 68 20 64 69 66 66 65 72  imes with differ
1460: 65 6e 74 20 73 65 65 64 73 20 66 6f 72 20 74 68  ent seeds for th
1470: 65 20 72 61 6e 64 6f 6d 0a 23 20 6e 75 6d 62 65  e random.# numbe
1480: 72 20 67 65 6e 65 72 61 74 6f 72 20 69 6e 20 74  r generator in t
1490: 68 65 20 63 72 61 73 68 69 6e 67 20 65 78 65 63  he crashing exec
14a0: 75 74 61 62 6c 65 2e 20 42 65 63 61 75 73 65 20  utable. Because 
14b0: 74 68 65 72 65 20 69 73 20 6e 6f 20 77 61 79 20  there is no way 
14c0: 74 6f 0a 23 20 73 65 65 64 20 74 68 65 20 72 61  to.# seed the ra
14d0: 6e 64 6f 6d 20 6e 75 6d 62 65 72 20 67 65 6e 65  ndom number gene
14e0: 72 61 74 6f 72 20 64 69 72 65 63 74 6c 79 2c 20  rator directly, 
14f0: 73 6f 6d 65 20 53 51 4c 20 69 73 20 61 64 64 65  some SQL is adde
1500: 64 20 74 6f 20 74 68 65 20 74 65 73 74 0a 23 20  d to the test.# 
1510: 63 61 73 65 20 74 6f 20 27 75 73 65 20 75 70 27  case to 'use up'
1520: 20 61 20 64 69 66 66 65 72 65 6e 74 20 71 75 61   a different qua
1530: 6e 74 69 74 79 20 72 61 6e 64 6f 6d 20 6e 75 6d  ntity random num
1540: 62 65 72 73 20 62 65 66 6f 72 65 20 74 68 65 20  bers before the 
1550: 74 65 73 74 20 53 51 4c 0a 23 20 69 73 20 65 78  test SQL.# is ex
1560: 65 63 75 74 65 64 2e 0a 23 0a 0a 23 20 4d 61 6b  ecuted..#..# Mak
1570: 65 20 73 75 72 65 20 74 68 65 20 66 69 6c 65 20  e sure the file 
1580: 69 73 20 6d 75 63 68 20 62 69 67 67 65 72 20 74  is much bigger t
1590: 68 61 6e 20 74 68 65 20 70 61 67 65 72 2d 63 61  han the pager-ca
15a0: 63 68 65 20 28 31 30 20 70 61 67 65 73 29 2e 20  che (10 pages). 
15b0: 54 68 69 73 0a 23 20 65 6e 73 75 72 65 73 20 74  This.# ensures t
15c0: 68 61 74 20 63 61 63 68 65 2d 73 70 69 6c 6c 73  hat cache-spills
15d0: 20 68 61 70 70 65 6e 20 72 65 67 75 6c 61 72 6c   happen regularl
15e0: 79 2e 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68  y..do_test crash
15f0: 2d 33 2e 30 20 7b 0a 20 20 65 78 65 63 73 71 6c  -3.0 {.  execsql
1600: 20 7b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e   {.    INSERT IN
1610: 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 2a 20  TO abc SELECT * 
1620: 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e  FROM abc;.    IN
1630: 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45  SERT INTO abc SE
1640: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b  LECT * FROM abc;
1650: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
1660: 20 61 62 63 20 53 45 4c 45 43 54 20 2a 20 46 52   abc SELECT * FR
1670: 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e 53 45  OM abc;.    INSE
1680: 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45  RT INTO abc SELE
1690: 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20  CT * FROM abc;. 
16a0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
16b0: 62 63 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d  bc SELECT * FROM
16c0: 20 61 62 63 3b 0a 20 20 7d 0a 20 20 65 78 70 72   abc;.  }.  expr
16d0: 20 28 5b 66 69 6c 65 20 73 69 7a 65 20 74 65 73   ([file size tes
16e0: 74 2e 64 62 5d 20 2f 20 31 30 32 34 29 20 3e 20  t.db] / 1024) > 
16f0: 34 35 30 0a 7d 20 7b 31 7d 0a 66 6f 72 20 7b 73  450.} {1}.for {s
1700: 65 74 20 69 20 31 7d 20 7b 24 69 20 3c 20 24 72  et i 1} {$i < $r
1710: 65 70 65 61 74 73 7d 20 7b 69 6e 63 72 20 69 7d  epeats} {incr i}
1720: 20 7b 0a 20 20 73 65 74 20 73 69 67 20 5b 73 69   {.  set sig [si
1730: 67 6e 61 74 75 72 65 5d 0a 20 20 64 6f 5f 74 65  gnature].  do_te
1740: 73 74 20 63 72 61 73 68 2d 33 2e 24 69 2e 31 20  st crash-3.$i.1 
1750: 7b 0a 20 20 20 20 20 73 65 74 20 73 65 65 64 20  {.     set seed 
1760: 5b 65 78 70 72 20 7b 69 6e 74 28 61 62 73 28 72  [expr {int(abs(r
1770: 61 6e 64 28 29 2a 31 30 30 30 30 29 29 7d 5d 0a  and()*10000))}].
1780: 20 20 20 20 20 63 72 61 73 68 73 71 6c 20 2d 64       crashsql -d
1790: 65 6c 61 79 20 5b 65 78 70 72 20 24 69 25 35 20  elay [expr $i%5 
17a0: 2b 20 31 5d 20 2d 66 69 6c 65 20 74 65 73 74 2e  + 1] -file test.
17b0: 64 62 2d 6a 6f 75 72 6e 61 6c 20 2d 73 65 65 64  db-journal -seed
17c0: 20 24 73 65 65 64 20 22 0a 20 20 20 20 20 20 20   $seed ".       
17d0: 42 45 47 49 4e 3b 0a 20 20 20 20 20 20 20 53 45  BEGIN;.       SE
17e0: 4c 45 43 54 20 72 61 6e 64 6f 6d 28 29 20 46 52  LECT random() FR
17f0: 4f 4d 20 61 62 63 20 4c 49 4d 49 54 20 24 69 3b  OM abc LIMIT $i;
1800: 0a 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  .       INSERT I
1810: 4e 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 72  NTO abc VALUES(r
1820: 61 6e 64 73 74 72 28 31 30 2c 31 30 29 2c 20 30  andstr(10,10), 0
1830: 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 44 45 4c  , 0);.       DEL
1840: 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45  ETE FROM abc WHE
1850: 52 45 20 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d  RE random()%10!=
1860: 30 3b 0a 20 20 20 20 20 20 20 43 4f 4d 4d 49 54  0;.       COMMIT
1870: 3b 0a 20 20 20 20 20 22 0a 20 20 7d 20 7b 31 20  ;.     ".  } {1 
1880: 7b 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 65  {child process e
1890: 78 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79  xited abnormally
18a0: 7d 7d 0a 20 20 64 6f 5f 74 65 73 74 20 63 72 61  }}.  do_test cra
18b0: 73 68 2d 33 2e 24 69 2e 32 20 7b 0a 20 20 20 20  sh-3.$i.2 {.    
18c0: 73 69 67 6e 61 74 75 72 65 0a 20 20 7d 20 24 73  signature.  } $s
18d0: 69 67 0a 7d 20 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  ig.} ..#--------
18e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
18f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1920: 2d 2d 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69  --.# The followi
1930: 6e 67 20 74 65 73 74 20 63 61 73 65 73 20 2d 20  ng test cases - 
1940: 63 72 61 73 68 2d 34 2e 2a 20 2d 20 74 65 73 74  crash-4.* - test
1950: 20 74 68 65 20 63 6f 72 72 65 63 74 20 72 65 63   the correct rec
1960: 6f 76 65 72 79 20 6f 66 20 74 68 65 0a 23 20 64  overy of the.# d
1970: 61 74 61 62 61 73 65 20 77 68 65 6e 20 61 20 63  atabase when a c
1980: 72 61 73 68 20 6f 63 63 75 72 73 20 64 75 72 69  rash occurs duri
1990: 6e 67 20 61 20 6d 75 6c 74 69 2d 66 69 6c 65 20  ng a multi-file 
19a0: 74 72 61 6e 73 61 63 74 69 6f 6e 2e 0a 23 0a 23  transaction..#.#
19b0: 20 63 72 61 73 68 2d 34 2e 31 2e 2a 3a 20 54 65   crash-4.1.*: Te
19c0: 73 74 20 72 65 63 6f 76 65 72 79 20 77 68 65 6e  st recovery when
19d0: 20 63 72 61 73 68 20 6f 63 63 75 72 73 20 64 75   crash occurs du
19e0: 72 69 6e 67 20 73 79 6e 63 28 29 20 6f 66 20 74  ring sync() of t
19f0: 68 65 20 0a 23 20 20 20 20 20 20 20 20 20 20 20  he .#           
1a00: 20 20 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65     main database
1a10: 20 6a 6f 75 72 6e 61 6c 20 66 69 6c 65 2e 0a 23   journal file..#
1a20: 20 63 72 61 73 68 2d 34 2e 32 2e 2a 3a 20 54 65   crash-4.2.*: Te
1a30: 73 74 20 72 65 63 6f 76 65 72 79 20 77 68 65 6e  st recovery when
1a40: 20 63 72 61 73 68 20 6f 63 63 75 72 73 20 64 75   crash occurs du
1a50: 72 69 6e 67 20 73 79 6e 63 28 29 20 6f 66 20 61  ring sync() of a
1a60: 6e 20 0a 23 20 20 20 20 20 20 20 20 20 20 20 20  n .#            
1a70: 20 20 61 74 74 61 63 68 65 64 20 64 61 74 61 62    attached datab
1a80: 61 73 65 20 6a 6f 75 72 6e 61 6c 20 66 69 6c 65  ase journal file
1a90: 2e 0a 23 20 63 72 61 73 68 2d 34 2e 33 2e 2a 3a  ..# crash-4.3.*:
1aa0: 20 54 65 73 74 20 72 65 63 6f 76 65 72 79 20 77   Test recovery w
1ab0: 68 65 6e 20 63 72 61 73 68 20 6f 63 63 75 72 73  hen crash occurs
1ac0: 20 64 75 72 69 6e 67 20 73 79 6e 63 28 29 20 6f   during sync() o
1ad0: 66 20 74 68 65 20 6d 61 73 74 65 72 0a 23 20 20  f the master.#  
1ae0: 20 20 20 20 20 20 20 20 20 20 20 20 6a 6f 75 72              jour
1af0: 6e 61 6c 20 66 69 6c 65 2e 20 0a 23 0a 69 66 63  nal file. .#.ifc
1b00: 61 70 61 62 6c 65 20 61 74 74 61 63 68 20 7b 0a  apable attach {.
1b10: 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d    do_test crash-
1b20: 34 2e 30 20 7b 0a 20 20 20 20 66 6f 72 63 65 64  4.0 {.    forced
1b30: 65 6c 65 74 65 20 74 65 73 74 32 2e 64 62 0a 20  elete test2.db. 
1b40: 20 20 20 66 6f 72 63 65 64 65 6c 65 74 65 20 74     forcedelete t
1b50: 65 73 74 32 2e 64 62 2d 6a 6f 75 72 6e 61 6c 0a  est2.db-journal.
1b60: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20      execsql {.  
1b70: 20 20 20 20 41 54 54 41 43 48 20 27 74 65 73 74      ATTACH 'test
1b80: 32 2e 64 62 27 20 41 53 20 61 75 78 3b 0a 20 20  2.db' AS aux;.  
1b90: 20 20 20 20 50 52 41 47 4d 41 20 61 75 78 2e 64      PRAGMA aux.d
1ba0: 65 66 61 75 6c 74 5f 63 61 63 68 65 5f 73 69 7a  efault_cache_siz
1bb0: 65 20 3d 20 31 30 3b 0a 20 20 20 20 20 20 43 52  e = 10;.      CR
1bc0: 45 41 54 45 20 54 41 42 4c 45 20 61 75 78 2e 61  EATE TABLE aux.a
1bd0: 62 63 32 20 41 53 20 53 45 4c 45 43 54 20 32 2a  bc2 AS SELECT 2*
1be0: 61 20 61 73 20 61 2c 20 32 2a 62 20 61 73 20 62  a as a, 2*b as b
1bf0: 2c 20 32 2a 63 20 61 73 20 63 20 46 52 4f 4d 20  , 2*c as c FROM 
1c00: 61 62 63 3b 0a 20 20 20 20 7d 0a 20 20 20 20 65  abc;.    }.    e
1c10: 78 70 72 20 28 5b 66 69 6c 65 20 73 69 7a 65 20  xpr ([file size 
1c20: 74 65 73 74 32 2e 64 62 5d 20 2f 20 31 30 32 34  test2.db] / 1024
1c30: 29 20 3e 20 34 35 30 0a 20 20 7d 20 7b 31 7d 0a  ) > 450.  } {1}.
1c40: 20 20 0a 20 20 73 65 74 20 66 69 6e 20 30 0a 20    .  set fin 0. 
1c50: 20 66 6f 72 20 7b 73 65 74 20 69 20 31 7d 20 7b   for {set i 1} {
1c60: 24 69 3c 24 72 65 70 65 61 74 73 7d 20 7b 69 6e  $i<$repeats} {in
1c70: 63 72 20 69 7d 20 7b 0a 20 20 20 20 73 65 74 20  cr i} {.    set 
1c80: 73 65 65 64 20 5b 65 78 70 72 20 7b 69 6e 74 28  seed [expr {int(
1c90: 61 62 73 28 72 61 6e 64 28 29 2a 31 30 30 30 30  abs(rand()*10000
1ca0: 29 29 7d 5d 0a 20 20 20 20 73 65 74 20 73 69 67  ))}].    set sig
1cb0: 20 5b 73 69 67 6e 61 74 75 72 65 5d 0a 20 20 20   [signature].   
1cc0: 20 73 65 74 20 73 69 67 32 20 5b 73 69 67 6e 61   set sig2 [signa
1cd0: 74 75 72 65 32 5d 0a 20 20 20 20 64 6f 5f 74 65  ture2].    do_te
1ce0: 73 74 20 63 72 61 73 68 2d 34 2e 31 2e 24 69 2e  st crash-4.1.$i.
1cf0: 31 20 7b 0a 20 20 20 20 20 20 20 73 65 74 20 63  1 {.       set c
1d00: 20 5b 63 72 61 73 68 73 71 6c 20 2d 64 65 6c 61   [crashsql -dela
1d10: 79 20 24 69 20 2d 66 69 6c 65 20 74 65 73 74 2e  y $i -file test.
1d20: 64 62 2d 6a 6f 75 72 6e 61 6c 20 2d 73 65 65 64  db-journal -seed
1d30: 20 24 3a 3a 73 65 65 64 20 22 0a 20 20 20 20 20   $::seed ".     
1d40: 20 20 20 20 41 54 54 41 43 48 20 27 74 65 73 74      ATTACH 'test
1d50: 32 2e 64 62 27 20 41 53 20 61 75 78 3b 0a 20 20  2.db' AS aux;.  
1d60: 20 20 20 20 20 20 20 42 45 47 49 4e 3b 0a 20 20         BEGIN;.  
1d70: 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 72 61         SELECT ra
1d80: 6e 64 73 74 72 28 24 69 2c 24 69 29 20 46 52 4f  ndstr($i,$i) FRO
1d90: 4d 20 61 62 63 20 4c 49 4d 49 54 20 24 69 3b 0a  M abc LIMIT $i;.
1da0: 20 20 20 20 20 20 20 20 20 49 4e 53 45 52 54 20           INSERT 
1db0: 49 4e 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28  INTO abc VALUES(
1dc0: 72 61 6e 64 73 74 72 28 31 30 2c 31 30 29 2c 20  randstr(10,10), 
1dd0: 30 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 20 20  0, 0);.         
1de0: 44 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20  DELETE FROM abc 
1df0: 57 48 45 52 45 20 72 61 6e 64 6f 6d 28 29 25 31  WHERE random()%1
1e00: 30 21 3d 30 3b 0a 20 20 20 20 20 20 20 20 20 49  0!=0;.         I
1e10: 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 32 20  NSERT INTO abc2 
1e20: 56 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28 31  VALUES(randstr(1
1e30: 30 2c 31 30 29 2c 20 30 2c 20 30 29 3b 0a 20 20  0,10), 0, 0);.  
1e40: 20 20 20 20 20 20 20 44 45 4c 45 54 45 20 46 52         DELETE FR
1e50: 4f 4d 20 61 62 63 32 20 57 48 45 52 45 20 72 61  OM abc2 WHERE ra
1e60: 6e 64 6f 6d 28 29 25 31 30 21 3d 30 3b 0a 20 20  ndom()%10!=0;.  
1e70: 20 20 20 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20         COMMIT;. 
1e80: 20 20 20 20 20 20 22 5d 0a 20 20 20 20 20 20 20        "].       
1e90: 69 66 20 7b 20 24 63 20 3d 3d 20 7b 30 20 7b 7d  if { $c == {0 {}
1ea0: 7d 20 7d 20 7b 0a 20 20 20 20 20 20 20 20 20 73  } } {.         s
1eb0: 65 74 20 3a 3a 66 69 6e 20 31 0a 20 20 20 20 20  et ::fin 1.     
1ec0: 20 20 20 20 73 65 74 20 63 20 7b 31 20 7b 63 68      set c {1 {ch
1ed0: 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78 69 74  ild process exit
1ee0: 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a  ed abnormally}}.
1ef0: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20         }.       
1f00: 73 65 74 20 63 0a 20 20 20 20 7d 20 7b 31 20 7b  set c.    } {1 {
1f10: 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78  child process ex
1f20: 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d  ited abnormally}
1f30: 7d 0a 20 20 20 20 69 66 20 7b 24 3a 3a 66 69 6e  }.    if {$::fin
1f40: 7d 20 62 72 65 61 6b 0a 20 20 20 20 64 6f 5f 74  } break.    do_t
1f50: 65 73 74 20 63 72 61 73 68 2d 34 2e 31 2e 24 69  est crash-4.1.$i
1f60: 2e 32 20 7b 0a 20 20 20 20 20 20 73 69 67 6e 61  .2 {.      signa
1f70: 74 75 72 65 0a 20 20 20 20 7d 20 24 73 69 67 0a  ture.    } $sig.
1f80: 20 20 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73      do_test cras
1f90: 68 2d 34 2e 31 2e 24 69 2e 33 20 7b 0a 20 20 20  h-4.1.$i.3 {.   
1fa0: 20 20 20 73 69 67 6e 61 74 75 72 65 32 0a 20 20     signature2.  
1fb0: 20 20 7d 20 24 73 69 67 32 0a 20 20 7d 20 0a 20    } $sig2.  } . 
1fc0: 20 73 65 74 20 69 20 30 0a 20 20 73 65 74 20 66   set i 0.  set f
1fd0: 69 6e 20 30 0a 20 20 77 68 69 6c 65 20 7b 5b 69  in 0.  while {[i
1fe0: 6e 63 72 20 69 5d 7d 20 7b 0a 20 20 20 20 73 65  ncr i]} {.    se
1ff0: 74 20 73 65 65 64 20 5b 65 78 70 72 20 7b 69 6e  t seed [expr {in
2000: 74 28 61 62 73 28 72 61 6e 64 28 29 2a 31 30 30  t(abs(rand()*100
2010: 30 30 29 29 7d 5d 0a 20 20 20 20 73 65 74 20 73  00))}].    set s
2020: 69 67 20 5b 73 69 67 6e 61 74 75 72 65 5d 0a 20  ig [signature]. 
2030: 20 20 20 73 65 74 20 73 69 67 32 20 5b 73 69 67     set sig2 [sig
2040: 6e 61 74 75 72 65 32 5d 0a 20 20 20 20 73 65 74  nature2].    set
2050: 20 3a 3a 66 69 6e 20 30 0a 20 20 20 20 64 6f 5f   ::fin 0.    do_
2060: 74 65 73 74 20 63 72 61 73 68 2d 34 2e 32 2e 24  test crash-4.2.$
2070: 69 2e 31 20 7b 0a 20 20 20 20 20 20 20 73 65 74  i.1 {.       set
2080: 20 63 20 5b 63 72 61 73 68 73 71 6c 20 2d 64 65   c [crashsql -de
2090: 6c 61 79 20 24 69 20 2d 66 69 6c 65 20 74 65 73  lay $i -file tes
20a0: 74 32 2e 64 62 2d 6a 6f 75 72 6e 61 6c 20 2d 73  t2.db-journal -s
20b0: 65 65 64 20 24 3a 3a 73 65 65 64 20 22 0a 20 20  eed $::seed ".  
20c0: 20 20 20 20 20 20 20 41 54 54 41 43 48 20 27 74         ATTACH 't
20d0: 65 73 74 32 2e 64 62 27 20 41 53 20 61 75 78 3b  est2.db' AS aux;
20e0: 0a 20 20 20 20 20 20 20 20 20 42 45 47 49 4e 3b  .         BEGIN;
20f0: 0a 20 20 20 20 20 20 20 20 20 53 45 4c 45 43 54  .         SELECT
2100: 20 72 61 6e 64 73 74 72 28 24 69 2c 24 69 29 20   randstr($i,$i) 
2110: 46 52 4f 4d 20 61 62 63 20 4c 49 4d 49 54 20 24  FROM abc LIMIT $
2120: 69 3b 0a 20 20 20 20 20 20 20 20 20 49 4e 53 45  i;.         INSE
2130: 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55  RT INTO abc VALU
2140: 45 53 28 72 61 6e 64 73 74 72 28 31 30 2c 31 30  ES(randstr(10,10
2150: 29 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20  ), 0, 0);.      
2160: 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 61     DELETE FROM a
2170: 62 63 20 57 48 45 52 45 20 72 61 6e 64 6f 6d 28  bc WHERE random(
2180: 29 25 31 30 21 3d 30 3b 0a 20 20 20 20 20 20 20  )%10!=0;.       
2190: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62    INSERT INTO ab
21a0: 63 32 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74  c2 VALUES(randst
21b0: 72 28 31 30 2c 31 30 29 2c 20 30 2c 20 30 29 3b  r(10,10), 0, 0);
21c0: 0a 20 20 20 20 20 20 20 20 20 44 45 4c 45 54 45  .         DELETE
21d0: 20 46 52 4f 4d 20 61 62 63 32 20 57 48 45 52 45   FROM abc2 WHERE
21e0: 20 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d 30 3b   random()%10!=0;
21f0: 0a 20 20 20 20 20 20 20 20 20 43 4f 4d 4d 49 54  .         COMMIT
2200: 3b 0a 20 20 20 20 20 20 20 22 5d 0a 20 20 20 20  ;.       "].    
2210: 20 20 20 69 66 20 7b 20 24 63 20 3d 3d 20 7b 30     if { $c == {0
2220: 20 7b 7d 7d 20 7d 20 7b 0a 20 20 20 20 20 20 20   {}} } {.       
2230: 20 20 73 65 74 20 3a 3a 66 69 6e 20 31 0a 20 20    set ::fin 1.  
2240: 20 20 20 20 20 20 20 73 65 74 20 63 20 7b 31 20         set c {1 
2250: 7b 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 65  {child process e
2260: 78 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79  xited abnormally
2270: 7d 7d 0a 20 20 20 20 20 20 20 7d 0a 20 20 20 20  }}.       }.    
2280: 20 20 20 73 65 74 20 63 0a 20 20 20 20 7d 20 7b     set c.    } {
2290: 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73 73  1 {child process
22a0: 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c   exited abnormal
22b0: 6c 79 7d 7d 0a 20 20 20 20 69 66 20 7b 20 24 3a  ly}}.    if { $:
22c0: 3a 66 69 6e 20 7d 20 62 72 65 61 6b 0a 20 20 20  :fin } break.   
22d0: 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34   do_test crash-4
22e0: 2e 32 2e 24 69 2e 32 20 7b 0a 20 20 20 20 20 20  .2.$i.2 {.      
22f0: 73 69 67 6e 61 74 75 72 65 0a 20 20 20 20 7d 20  signature.    } 
2300: 24 73 69 67 0a 20 20 20 20 64 6f 5f 74 65 73 74  $sig.    do_test
2310: 20 63 72 61 73 68 2d 34 2e 32 2e 24 69 2e 33 20   crash-4.2.$i.3 
2320: 7b 0a 20 20 20 20 20 20 73 69 67 6e 61 74 75 72  {.      signatur
2330: 65 32 0a 20 20 20 20 7d 20 24 73 69 67 32 0a 20  e2.    } $sig2. 
2340: 20 7d 20 0a 20 20 66 6f 72 20 7b 73 65 74 20 69   } .  for {set i
2350: 20 31 7d 20 7b 24 69 20 3c 20 35 7d 20 7b 69 6e   1} {$i < 5} {in
2360: 63 72 20 69 7d 20 7b 0a 20 20 20 20 73 65 74 20  cr i} {.    set 
2370: 73 69 67 20 5b 73 69 67 6e 61 74 75 72 65 5d 0a  sig [signature].
2380: 20 20 20 20 73 65 74 20 73 69 67 32 20 5b 73 69      set sig2 [si
2390: 67 6e 61 74 75 72 65 32 5d 0a 20 20 20 20 64 6f  gnature2].    do
23a0: 5f 74 65 73 74 20 63 72 61 73 68 2d 34 2e 33 2e  _test crash-4.3.
23b0: 24 69 2e 31 20 7b 0a 20 20 20 20 20 20 20 63 72  $i.1 {.       cr
23c0: 61 73 68 73 71 6c 20 2d 64 65 6c 61 79 20 31 20  ashsql -delay 1 
23d0: 2d 66 69 6c 65 20 74 65 73 74 2e 64 62 2d 6d 6a  -file test.db-mj
23e0: 2a 20 22 0a 20 20 20 20 20 20 20 20 20 41 54 54  * ".         ATT
23f0: 41 43 48 20 27 74 65 73 74 32 2e 64 62 27 20 41  ACH 'test2.db' A
2400: 53 20 61 75 78 3b 0a 20 20 20 20 20 20 20 20 20  S aux;.         
2410: 42 45 47 49 4e 3b 0a 20 20 20 20 20 20 20 20 20  BEGIN;.         
2420: 53 45 4c 45 43 54 20 72 61 6e 64 6f 6d 28 29 20  SELECT random() 
2430: 46 52 4f 4d 20 61 62 63 20 4c 49 4d 49 54 20 24  FROM abc LIMIT $
2440: 69 3b 0a 20 20 20 20 20 20 20 20 20 49 4e 53 45  i;.         INSE
2450: 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55  RT INTO abc VALU
2460: 45 53 28 72 61 6e 64 73 74 72 28 31 30 2c 31 30  ES(randstr(10,10
2470: 29 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20  ), 0, 0);.      
2480: 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 61     DELETE FROM a
2490: 62 63 20 57 48 45 52 45 20 72 61 6e 64 6f 6d 28  bc WHERE random(
24a0: 29 25 31 30 21 3d 30 3b 0a 20 20 20 20 20 20 20  )%10!=0;.       
24b0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62    INSERT INTO ab
24c0: 63 32 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74  c2 VALUES(randst
24d0: 72 28 31 30 2c 31 30 29 2c 20 30 2c 20 30 29 3b  r(10,10), 0, 0);
24e0: 0a 20 20 20 20 20 20 20 20 20 44 45 4c 45 54 45  .         DELETE
24f0: 20 46 52 4f 4d 20 61 62 63 32 20 57 48 45 52 45   FROM abc2 WHERE
2500: 20 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d 30 3b   random()%10!=0;
2510: 0a 20 20 20 20 20 20 20 20 20 43 4f 4d 4d 49 54  .         COMMIT
2520: 3b 0a 20 20 20 20 20 20 20 22 0a 20 20 20 20 7d  ;.       ".    }
2530: 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65   {1 {child proce
2540: 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d  ss exited abnorm
2550: 61 6c 6c 79 7d 7d 0a 20 20 20 20 64 6f 5f 74 65  ally}}.    do_te
2560: 73 74 20 63 72 61 73 68 2d 34 2e 33 2e 24 69 2e  st crash-4.3.$i.
2570: 32 20 7b 0a 20 20 20 20 20 20 73 69 67 6e 61 74  2 {.      signat
2580: 75 72 65 0a 20 20 20 20 7d 20 24 73 69 67 0a 20  ure.    } $sig. 
2590: 20 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68     do_test crash
25a0: 2d 34 2e 33 2e 24 69 2e 33 20 7b 0a 20 20 20 20  -4.3.$i.3 {.    
25b0: 20 20 73 69 67 6e 61 74 75 72 65 32 0a 20 20 20    signature2.   
25c0: 20 7d 20 24 73 69 67 32 0a 20 20 7d 0a 7d 0a 0a   } $sig2.  }.}..
25d0: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
25e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
25f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2610: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68  -----------.# Th
2620: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74  e following test
2630: 20 63 61 73 65 73 20 2d 20 63 72 61 73 68 2d 35   cases - crash-5
2640: 2e 2a 20 2d 20 65 78 70 6f 73 65 73 20 61 20 62  .* - exposes a b
2650: 75 67 20 74 68 61 74 20 65 78 69 73 74 65 64 20  ug that existed 
2660: 69 6e 20 74 68 65 0a 23 20 73 71 6c 69 74 65 33  in the.# sqlite3
2670: 70 61 67 65 72 5f 6d 6f 76 65 70 61 67 65 28 29  pager_movepage()
2680: 20 41 50 49 20 75 73 65 64 20 62 79 20 61 75 74   API used by aut
2690: 6f 2d 76 61 63 75 75 6d 20 64 61 74 61 62 61 73  o-vacuum databas
26a0: 65 73 2e 0a 23 20 64 61 74 61 62 61 73 65 20 77  es..# database w
26b0: 68 65 6e 20 61 20 63 72 61 73 68 20 6f 63 63 75  hen a crash occu
26c0: 72 73 20 64 75 72 69 6e 67 20 61 20 6d 75 6c 74  rs during a mult
26d0: 69 2d 66 69 6c 65 20 74 72 61 6e 73 61 63 74 69  i-file transacti
26e0: 6f 6e 2e 20 53 65 65 20 63 6f 6d 6d 65 6e 74 73  on. See comments
26f0: 0a 23 20 69 6e 20 74 65 73 74 20 63 72 61 73 68  .# in test crash
2700: 2d 35 2e 33 20 66 6f 72 20 64 65 74 61 69 6c 73  -5.3 for details
2710: 2e 0a 23 0a 64 62 20 63 6c 6f 73 65 0a 66 6f 72  ..#.db close.for
2720: 63 65 64 65 6c 65 74 65 20 74 65 73 74 2e 64 62  cedelete test.db
2730: 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74  .sqlite3 db test
2740: 2e 64 62 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  .db.do_test cras
2750: 68 2d 35 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  h-5.1 {.  execsq
2760: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54  l {.    CREATE T
2770: 41 42 4c 45 20 61 62 63 28 61 2c 20 62 2c 20 63  ABLE abc(a, b, c
2780: 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  );              
2790: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 52              -- R
27a0: 6f 6f 74 20 70 61 67 65 20 33 0a 20 20 20 20 49  oot page 3.    I
27b0: 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56  NSERT INTO abc V
27c0: 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28 31 35  ALUES(randstr(15
27d0: 30 30 2c 31 35 30 30 29 2c 20 30 2c 20 30 29 3b  00,1500), 0, 0);
27e0: 20 20 20 2d 2d 20 4f 76 65 72 66 6c 6f 77 20 70     -- Overflow p
27f0: 61 67 65 20 34 0a 20 20 20 20 49 4e 53 45 52 54  age 4.    INSERT
2800: 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54   INTO abc SELECT
2810: 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20   * FROM abc;.   
2820: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
2830: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61   SELECT * FROM a
2840: 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  bc;.    INSERT I
2850: 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 2a  NTO abc SELECT *
2860: 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 7d 0a 7d   FROM abc;.  }.}
2870: 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73   {}.do_test cras
2880: 68 2d 35 2e 32 20 7b 0a 20 20 65 78 70 72 20 5b  h-5.2 {.  expr [
2890: 66 69 6c 65 20 73 69 7a 65 20 74 65 73 74 2e 64  file size test.d
28a0: 62 5d 20 2f 20 31 30 32 34 0a 7d 20 5b 65 78 70  b] / 1024.} [exp
28b0: 72 20 5b 73 74 72 69 6e 67 20 6d 61 74 63 68 20  r [string match 
28c0: 5b 65 78 65 63 73 71 6c 20 7b 70 72 61 67 6d 61  [execsql {pragma
28d0: 20 61 75 74 6f 5f 76 61 63 75 75 6d 7d 5d 20 31   auto_vacuum}] 1
28e0: 5d 20 3f 20 31 31 20 3a 20 31 30 5d 0a 73 65 74  ] ? 11 : 10].set
28f0: 20 73 69 67 20 5b 73 69 67 6e 61 74 75 72 65 5d   sig [signature]
2900: 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 35  .do_test crash-5
2910: 2e 33 20 7b 0a 23 20 54 68 65 20 53 51 4c 20 62  .3 {.# The SQL b
2920: 65 6c 6f 77 20 69 73 20 75 73 65 64 20 74 6f 20  elow is used to 
2930: 65 78 70 6f 73 65 20 61 20 62 75 67 20 74 68 61  expose a bug tha
2940: 74 20 65 78 69 73 74 65 64 20 69 6e 0a 23 20 73  t existed in.# s
2950: 71 6c 69 74 65 33 70 61 67 65 72 5f 6d 6f 76 65  qlite3pager_move
2960: 70 61 67 65 28 29 20 64 75 72 69 6e 67 20 64 65  page() during de
2970: 76 65 6c 6f 70 6d 65 6e 74 20 6f 66 20 74 68 65  velopment of the
2980: 20 61 75 74 6f 2d 76 61 63 75 75 6d 20 66 65 61   auto-vacuum fea
2990: 74 75 72 65 2e 20 49 74 0a 23 20 66 75 6e 63 74  ture. It.# funct
29a0: 69 6f 6e 73 20 61 73 20 66 6f 6c 6c 6f 77 73 3a  ions as follows:
29b0: 0a 23 20 0a 23 20 31 3a 20 42 65 67 69 6e 20 61  .# .# 1: Begin a
29c0: 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e 0a 23 20   transaction..# 
29d0: 32 3a 20 50 75 74 20 70 61 67 65 20 34 20 6f 6e  2: Put page 4 on
29e0: 20 74 68 65 20 66 72 65 65 2d 6c 69 73 74 20 28   the free-list (
29f0: 77 61 73 20 74 68 65 20 6f 76 65 72 66 6c 6f 77  was the overflow
2a00: 20 70 61 67 65 20 66 6f 72 20 74 68 65 20 72 6f   page for the ro
2a10: 77 20 64 65 6c 65 74 65 64 29 2e 0a 23 20 33 3a  w deleted)..# 3:
2a20: 20 57 72 69 74 65 20 64 61 74 61 20 74 6f 20 70   Write data to p
2a30: 61 67 65 20 34 20 28 69 74 20 62 65 63 6f 6d 65  age 4 (it become
2a40: 73 20 74 68 65 20 6f 76 65 72 66 6c 6f 77 20 70  s the overflow p
2a50: 61 67 65 20 66 6f 72 20 74 68 65 20 72 6f 77 20  age for the row 
2a60: 69 6e 73 65 72 74 65 64 29 2e 0a 23 20 20 20 20  inserted)..#    
2a70: 54 68 65 20 6f 6c 64 20 70 61 67 65 20 34 20 64  The old page 4 d
2a80: 61 74 61 20 68 61 73 20 62 65 65 6e 20 77 72 69  ata has been wri
2a90: 74 74 65 6e 20 74 6f 20 74 68 65 20 6a 6f 75 72  tten to the jour
2aa0: 6e 61 6c 20 66 69 6c 65 2c 20 62 75 74 20 74 68  nal file, but th
2ab0: 65 0a 23 20 20 20 20 6a 6f 75 72 6e 61 6c 20 66  e.#    journal f
2ac0: 69 6c 65 20 68 61 73 20 6e 6f 74 20 62 65 65 6e  ile has not been
2ad0: 20 73 79 6e 63 28 29 68 72 6f 6e 69 7a 65 64 2e   sync()hronized.
2ae0: 0a 23 20 34 3a 20 43 72 65 61 74 65 20 61 20 74  .# 4: Create a t
2af0: 61 62 6c 65 2c 20 77 68 69 63 68 20 63 61 6c 6c  able, which call
2b00: 73 20 73 71 6c 69 74 65 33 70 61 67 65 72 5f 6d  s sqlite3pager_m
2b10: 6f 76 65 70 61 67 65 28 29 20 74 6f 20 6d 6f 76  ovepage() to mov
2b20: 65 20 70 61 67 65 20 34 0a 23 20 20 20 20 74 6f  e page 4.#    to
2b30: 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20   the end of the 
2b40: 64 61 74 61 62 61 73 65 20 28 70 61 67 65 20 31  database (page 1
2b50: 32 29 20 74 6f 20 6d 61 6b 65 20 72 6f 6f 6d 20  2) to make room 
2b60: 66 6f 72 20 74 68 65 20 6e 65 77 20 72 6f 6f 74  for the new root
2b70: 2d 70 61 67 65 2e 0a 23 20 35 3a 20 50 75 74 20  -page..# 5: Put 
2b80: 70 72 65 73 73 75 72 65 20 6f 6e 20 74 68 65 20  pressure on the 
2b90: 70 61 67 65 72 2d 63 61 63 68 65 2e 20 54 68 69  pager-cache. Thi
2ba0: 73 20 72 65 73 75 6c 74 73 20 69 6e 20 70 61 67  s results in pag
2bb0: 65 20 34 20 62 65 69 6e 67 20 77 72 69 74 74 65  e 4 being writte
2bc0: 6e 0a 23 20 20 20 20 74 6f 20 74 68 65 20 64 61  n.#    to the da
2bd0: 74 61 62 61 73 65 20 66 69 6c 65 20 74 6f 20 6d  tabase file to m
2be0: 61 6b 65 20 73 70 61 63 65 20 69 6e 20 74 68 65  ake space in the
2bf0: 20 63 61 63 68 65 20 74 6f 20 6c 6f 61 64 20 61   cache to load a
2c00: 20 6e 65 77 20 70 61 67 65 2e 20 54 68 65 0a 23   new page. The.#
2c10: 20 20 20 20 62 75 67 20 77 61 73 20 74 68 61 74      bug was that
2c20: 20 70 61 67 65 20 34 20 77 61 73 20 77 72 69 74   page 4 was writ
2c30: 74 65 6e 20 74 6f 20 74 68 65 20 64 61 74 61 62  ten to the datab
2c40: 61 73 65 20 66 69 6c 65 20 62 65 66 6f 72 65 20  ase file before 
2c50: 74 68 65 20 6a 6f 75 72 6e 61 6c 0a 23 20 20 20  the journal.#   
2c60: 20 69 73 20 73 79 6e 63 28 29 68 72 6f 6e 69 7a   is sync()hroniz
2c70: 65 64 2e 0a 23 20 36 3a 20 43 6f 6d 6d 69 74 2e  ed..# 6: Commit.
2c80: 20 41 20 63 72 61 73 68 20 6f 63 63 75 72 73 20   A crash occurs 
2c90: 64 75 72 69 6e 67 20 74 68 65 20 73 79 6e 63 20  during the sync 
2ca0: 6f 66 20 74 68 65 20 6a 6f 75 72 6e 61 6c 20 66  of the journal f
2cb0: 69 6c 65 2e 0a 23 0a 23 20 45 6e 64 20 72 65 73  ile..#.# End res
2cc0: 75 6c 74 3a 20 42 65 66 6f 72 65 20 74 68 65 20  ult: Before the 
2cd0: 62 75 67 20 77 61 73 20 66 69 78 65 64 2c 20 64  bug was fixed, d
2ce0: 61 74 61 20 68 61 73 20 62 65 65 6e 20 77 72 69  ata has been wri
2cf0: 74 74 65 6e 20 74 6f 20 70 61 67 65 20 34 20 6f  tten to page 4 o
2d00: 66 20 74 68 65 0a 23 20 64 61 74 61 62 61 73 65  f the.# database
2d10: 20 66 69 6c 65 20 61 6e 64 20 74 68 65 20 6a 6f   file and the jo
2d20: 75 72 6e 61 6c 20 66 69 6c 65 20 64 6f 65 73 20  urnal file does 
2d30: 6e 6f 74 20 63 6f 6e 74 61 69 6e 20 74 72 75 73  not contain trus
2d40: 74 77 6f 72 74 68 79 20 72 6f 6c 6c 62 61 63 6b  tworthy rollback
2d50: 0a 23 20 64 61 74 61 20 66 6f 72 20 74 68 69 73  .# data for this
2d60: 20 70 61 67 65 2e 0a 23 0a 20 20 63 72 61 73 68   page..#.  crash
2d70: 73 71 6c 20 2d 64 65 6c 61 79 20 31 20 2d 66 69  sql -delay 1 -fi
2d80: 6c 65 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e  le test.db-journ
2d90: 61 6c 20 7b 0a 20 20 20 20 42 45 47 49 4e 3b 20  al {.    BEGIN; 
2da0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2dc0: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 31              -- 1
2dd0: 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d  .    DELETE FROM
2de0: 20 61 62 63 20 57 48 45 52 45 20 6f 69 64 20 3d   abc WHERE oid =
2df0: 20 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 20   1;             
2e00: 20 20 20 20 20 20 20 20 2d 2d 20 32 0a 20 20 20          -- 2.   
2e10: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
2e20: 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28   VALUES(randstr(
2e30: 31 35 30 30 2c 31 35 30 30 29 2c 20 30 2c 20 30  1500,1500), 0, 0
2e40: 29 3b 20 20 2d 2d 20 33 0a 20 20 20 20 43 52 45  );  -- 3.    CRE
2e50: 41 54 45 20 54 41 42 4c 45 20 61 62 63 32 28 61  ATE TABLE abc2(a
2e60: 2c 20 62 2c 20 63 29 3b 20 20 20 20 20 20 20 20  , b, c);        
2e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2e80: 2d 2d 20 34 0a 20 20 20 20 53 45 4c 45 43 54 20  -- 4.    SELECT 
2e90: 2a 20 46 52 4f 4d 20 61 62 63 3b 20 20 20 20 20  * FROM abc;     
2ea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2eb0: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 35              -- 5
2ec0: 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 20 20 20 20  .    COMMIT;    
2ed0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2ee0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2ef0: 20 20 20 20 20 20 20 20 2d 2d 20 36 0a 20 20 7d          -- 6.  }
2f00: 0a 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f  .} {1 {child pro
2f10: 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f  cess exited abno
2f20: 72 6d 61 6c 6c 79 7d 7d 0a 69 6e 74 65 67 72 69  rmally}}.integri
2f30: 74 79 5f 63 68 65 63 6b 20 63 72 61 73 68 2d 35  ty_check crash-5
2f40: 2e 34 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68  .4.do_test crash
2f50: 2d 35 2e 35 20 7b 0a 20 20 73 69 67 6e 61 74 75  -5.5 {.  signatu
2f60: 72 65 0a 7d 20 24 73 69 67 0a 0a 23 2d 2d 2d 2d  re.} $sig..#----
2f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fb0: 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65 20 66 6f 6c  ------.# The fol
2fc0: 6c 6f 77 69 6e 67 20 74 65 73 74 20 63 61 73 65  lowing test case
2fd0: 73 20 2d 20 63 72 61 73 68 2d 36 2e 2a 20 2d 20  s - crash-6.* - 
2fe0: 74 65 73 74 20 74 68 61 74 20 61 20 44 52 4f 50  test that a DROP
2ff0: 20 54 41 42 4c 45 20 6f 70 65 72 61 74 69 6f 6e   TABLE operation
3000: 0a 23 20 69 73 20 63 6f 72 72 65 63 74 6c 79 20  .# is correctly 
3010: 72 6f 6c 6c 65 64 20 62 61 63 6b 20 69 6e 20 74  rolled back in t
3020: 68 65 20 65 76 65 6e 74 20 6f 66 20 61 20 63 72  he event of a cr
3030: 61 73 68 20 77 68 69 6c 65 20 74 68 65 20 64 61  ash while the da
3040: 74 61 62 61 73 65 20 66 69 6c 65 0a 23 20 69 73  tabase file.# is
3050: 20 62 65 69 6e 67 20 77 72 69 74 74 65 6e 2e 20   being written. 
3060: 54 68 69 73 20 69 73 20 6d 61 69 6e 6c 79 20 74  This is mainly t
3070: 6f 20 74 65 73 74 20 74 68 61 74 20 61 6c 6c 20  o test that all 
3080: 70 61 67 65 73 20 61 72 65 20 77 72 69 74 74 65  pages are writte
3090: 6e 20 74 6f 20 74 68 65 0a 23 20 6a 6f 75 72 6e  n to the.# journ
30a0: 61 6c 20 66 69 6c 65 20 62 65 66 6f 72 65 20 74  al file before t
30b0: 72 75 6e 63 61 74 69 6f 6e 20 69 6e 20 61 6e 20  runcation in an 
30c0: 61 75 74 6f 2d 76 61 63 75 75 6d 20 64 61 74 61  auto-vacuum data
30d0: 62 61 73 65 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  base..#.do_test 
30e0: 63 72 61 73 68 2d 36 2e 31 20 7b 0a 20 20 63 72  crash-6.1 {.  cr
30f0: 61 73 68 73 71 6c 20 2d 64 65 6c 61 79 20 31 20  ashsql -delay 1 
3100: 2d 66 69 6c 65 20 74 65 73 74 2e 64 62 20 7b 0a  -file test.db {.
3110: 20 20 20 20 44 52 4f 50 20 54 41 42 4c 45 20 61      DROP TABLE a
3120: 62 63 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b 63 68  bc;.  }.} {1 {ch
3130: 69 6c 64 20 70 72 6f 63 65 73 73 20 65 78 69 74  ild process exit
3140: 65 64 20 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a  ed abnormally}}.
3150: 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 36 2e  do_test crash-6.
3160: 32 20 7b 0a 20 20 73 69 67 6e 61 74 75 72 65 0a  2 {.  signature.
3170: 7d 20 24 73 69 67 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  } $sig..#-------
3180: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31c0: 2d 2d 2d 0a 23 20 54 68 65 73 65 20 74 65 73 74  ---.# These test
31d0: 20 63 61 73 65 73 20 74 65 73 74 20 74 68 65 20   cases test the 
31e0: 63 61 73 65 20 77 68 65 72 65 20 74 68 65 20 6d  case where the m
31f0: 61 73 74 65 72 20 6a 6f 75 72 6e 61 6c 20 66 69  aster journal fi
3200: 6c 65 20 6e 61 6d 65 20 69 73 20 0a 23 20 63 6f  le name is .# co
3210: 72 72 75 70 74 65 64 20 73 6c 69 67 68 74 6c 79  rrupted slightly
3220: 20 73 6f 20 74 68 61 74 20 74 68 65 20 63 6f 72   so that the cor
3230: 72 75 70 74 69 6f 6e 20 68 61 73 20 74 6f 20 62  ruption has to b
3240: 65 20 64 65 74 65 63 74 65 64 20 62 79 20 74 68  e detected by th
3250: 65 0a 23 20 63 68 65 63 6b 73 75 6d 2e 0a 64 6f  e.# checksum..do
3260: 5f 74 65 73 74 20 63 72 61 73 68 2d 37 2e 31 20  _test crash-7.1 
3270: 7b 0a 20 20 63 72 61 73 68 73 71 6c 20 2d 64 65  {.  crashsql -de
3280: 6c 61 79 20 31 20 2d 66 69 6c 65 20 74 65 73 74  lay 1 -file test
3290: 2e 64 62 20 7b 0a 20 20 20 20 41 54 54 41 43 48  .db {.    ATTACH
32a0: 20 27 74 65 73 74 32 2e 64 62 27 20 41 53 20 61   'test2.db' AS a
32b0: 75 78 3b 0a 20 20 20 20 42 45 47 49 4e 3b 0a 20  ux;.    BEGIN;. 
32c0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
32d0: 62 63 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74  bc VALUES(randst
32e0: 72 28 31 35 30 30 2c 31 35 30 30 29 2c 20 30 2c  r(1500,1500), 0,
32f0: 20 30 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20   0);.    INSERT 
3300: 49 4e 54 4f 20 61 62 63 32 20 56 41 4c 55 45 53  INTO abc2 VALUES
3310: 28 72 61 6e 64 73 74 72 28 31 35 30 30 2c 31 35  (randstr(1500,15
3320: 30 30 29 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20  00), 0, 0);.    
3330: 43 4f 4d 4d 49 54 3b 0a 20 20 7d 0a 0a 20 20 23  COMMIT;.  }..  #
3340: 20 43 68 61 6e 67 65 20 74 68 65 20 63 68 65 63   Change the chec
3350: 6b 73 75 6d 20 76 61 6c 75 65 20 66 6f 72 20 74  ksum value for t
3360: 68 65 20 6d 61 73 74 65 72 20 6a 6f 75 72 6e 61  he master journa
3370: 6c 20 6e 61 6d 65 2e 0a 20 20 73 65 74 20 66 20  l name..  set f 
3380: 5b 6f 70 65 6e 20 74 65 73 74 2e 64 62 2d 6a 6f  [open test.db-jo
3390: 75 72 6e 61 6c 20 61 5d 0a 20 20 66 63 6f 6e 66  urnal a].  fconf
33a0: 69 67 75 72 65 20 24 66 20 2d 65 6e 63 6f 64 69  igure $f -encodi
33b0: 6e 67 20 62 69 6e 61 72 79 0a 20 20 73 65 65 6b  ng binary.  seek
33c0: 20 24 66 20 5b 65 78 70 72 20 5b 66 69 6c 65 20   $f [expr [file 
33d0: 73 69 7a 65 20 74 65 73 74 2e 64 62 2d 6a 6f 75  size test.db-jou
33e0: 72 6e 61 6c 5d 20 2d 20 31 32 5d 0a 20 20 70 75  rnal] - 12].  pu
33f0: 74 73 20 2d 6e 6f 6e 65 77 6c 69 6e 65 20 24 66  ts -nonewline $f
3400: 20 22 5c 30 30 5c 30 30 5c 30 30 5c 30 30 22 0a   "\00\00\00\00".
3410: 20 20 63 6c 6f 73 65 20 24 66 0a 7d 20 7b 7d 0a    close $f.} {}.
3420: 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 37 2e  do_test crash-7.
3430: 32 20 7b 0a 20 20 73 69 67 6e 61 74 75 72 65 0a  2 {.  signature.
3440: 7d 20 24 73 69 67 0a 0a 66 69 6e 69 73 68 5f 74  } $sig..finish_t
3450: 65 73 74 0a                                      est.