SQLite4
Hex Artifact Content
Not logged in

Artifact becfe48e3ec22db21e0e9b1e4ae5c4626a0599f6:


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 20 74 68 65 0a 23 20 6a 6f 75 72 6e 61 6c  he the.# journal
0e60: 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 20 63 6f   file contain co
0e70: 72 72 75 70 74 20 64 61 74 61 2e 20 54 68 69 73  rrupt data. This
0e80: 20 63 61 6e 20 68 61 70 70 65 6e 20 61 66 74 65   can happen afte
0e90: 72 20 70 61 67 65 73 20 61 72 65 0a 23 20 77 72  r pages are.# wr
0ea0: 69 74 74 65 6e 20 74 6f 20 74 68 65 20 64 61 74  itten to the dat
0eb0: 61 62 61 73 65 20 66 69 6c 65 20 62 65 66 6f 72  abase file befor
0ec0: 65 20 61 20 74 72 61 6e 73 61 63 74 69 6f 6e 20  e a transaction 
0ed0: 69 73 20 63 6f 6d 6d 69 74 74 65 64 20 64 75 65  is committed due
0ee0: 20 74 6f 0a 23 20 63 61 63 68 65 2d 70 72 65 73   to.# cache-pres
0ef0: 73 75 72 65 2e 0a 23 0a 23 20 63 72 61 73 68 2d  sure..#.# crash-
0f00: 32 2e 31 3a 20 49 6e 73 65 72 74 20 31 38 20 70  2.1: Insert 18 p
0f10: 61 67 65 73 20 6f 66 20 64 61 74 61 20 69 6e 74  ages of data int
0f20: 6f 20 74 68 65 20 64 61 74 61 62 61 73 65 2e 0a  o the database..
0f30: 23 20 63 72 61 73 68 2d 32 2e 32 3a 20 43 68 65  # crash-2.2: Che
0f40: 63 6b 20 74 68 65 20 64 61 74 61 62 61 73 65 20  ck the database 
0f50: 66 69 6c 65 20 73 69 7a 65 20 6c 6f 6f 6b 73 20  file size looks 
0f60: 6f 6b 2e 0a 23 20 63 72 61 73 68 2d 32 2e 33 3a  ok..# crash-2.3:
0f70: 20 44 65 6c 65 74 65 20 31 35 20 6f 72 20 73 6f   Delete 15 or so
0f80: 20 70 61 67 65 73 20 28 77 69 74 68 20 61 20 31   pages (with a 1
0f90: 30 20 70 61 67 65 20 70 61 67 65 2d 63 61 63 68  0 page page-cach
0fa0: 65 29 2c 20 74 68 65 6e 20 63 72 61 73 68 2e 0a  e), then crash..
0fb0: 23 20 63 72 61 73 68 2d 32 2e 34 3a 20 45 6e 73  # crash-2.4: Ens
0fc0: 75 72 65 20 74 68 65 20 64 61 74 61 62 61 73 65  ure the database
0fd0: 20 69 73 20 69 6e 20 74 68 65 20 73 61 6d 65 20   is in the same 
0fe0: 73 74 61 74 65 20 61 73 20 61 66 74 65 72 20 63  state as after c
0ff0: 72 61 73 68 2d 32 2e 31 2e 0a 23 0a 23 20 54 65  rash-2.1..#.# Te
1000: 73 74 20 63 61 73 65 73 20 63 72 61 73 68 2d 32  st cases crash-2
1010: 2e 35 20 61 6e 64 20 63 72 61 73 68 2d 32 2e 36  .5 and crash-2.6
1020: 20 63 68 65 63 6b 20 74 68 61 74 20 74 68 65 20   check that the 
1030: 64 61 74 61 62 61 73 65 20 69 73 20 4f 4b 20 69  database is OK i
1040: 66 20 74 68 65 20 0a 23 20 63 72 61 73 68 20 6f  f the .# crash o
1050: 63 63 75 72 73 20 64 75 72 69 6e 67 20 74 68 65  ccurs during the
1060: 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 66   main database f
1070: 69 6c 65 20 73 79 6e 63 2e 20 42 75 74 20 74 68  ile sync. But th
1080: 69 73 20 69 73 6e 27 74 20 72 65 61 6c 6c 79 0a  is isn't really.
1090: 23 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d  # different from
10a0: 20 74 68 65 20 63 72 61 73 68 2d 31 2e 2a 20 63   the crash-1.* c
10b0: 61 73 65 73 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  ases..#.do_test 
10c0: 63 72 61 73 68 2d 32 2e 31 20 7b 0a 20 20 65 78  crash-2.1 {.  ex
10d0: 65 63 73 71 6c 20 7b 20 42 45 47 49 4e 20 7d 0a  ecsql { BEGIN }.
10e0: 20 20 66 6f 72 20 7b 73 65 74 20 6e 20 30 7d 20    for {set n 0} 
10f0: 7b 24 6e 20 3c 20 31 30 30 30 7d 20 7b 69 6e 63  {$n < 1000} {inc
1100: 72 20 6e 7d 20 7b 0a 20 20 20 20 65 78 65 63 73  r n} {.    execs
1110: 71 6c 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20  ql "INSERT INTO 
1120: 61 62 63 20 56 41 4c 55 45 53 28 24 6e 2c 20 5b  abc VALUES($n, [
1130: 65 78 70 72 20 32 2a 24 6e 5d 2c 20 5b 65 78 70  expr 2*$n], [exp
1140: 72 20 33 2a 24 6e 5d 29 22 0a 20 20 7d 0a 20 20  r 3*$n])".  }.  
1150: 65 78 65 63 73 71 6c 20 7b 20 43 4f 4d 4d 49 54  execsql { COMMIT
1160: 20 7d 0a 20 20 73 65 74 20 3a 3a 73 69 67 20 5b   }.  set ::sig [
1170: 73 69 67 6e 61 74 75 72 65 5d 0a 20 20 65 78 65  signature].  exe
1180: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 73 75  csql { SELECT su
1190: 6d 28 61 29 2c 20 73 75 6d 28 62 29 2c 20 73 75  m(a), sum(b), su
11a0: 6d 28 63 29 20 66 72 6f 6d 20 61 62 63 20 7d 0a  m(c) from abc }.
11b0: 7d 20 7b 34 39 39 35 30 30 20 39 39 39 30 30 30  } {499500 999000
11c0: 20 31 34 39 38 35 30 30 7d 0a 64 6f 5f 74 65 73   1498500}.do_tes
11d0: 74 20 63 72 61 73 68 2d 32 2e 32 20 7b 0a 20 20  t crash-2.2 {.  
11e0: 65 78 70 72 20 28 5b 66 69 6c 65 20 73 69 7a 65  expr ([file size
11f0: 20 74 65 73 74 2e 64 62 5d 20 2f 20 31 30 32 34   test.db] / 1024
1200: 29 3e 31 36 0a 7d 20 7b 31 7d 0a 64 6f 5f 74 65  )>16.} {1}.do_te
1210: 73 74 20 63 72 61 73 68 2d 32 2e 33 20 7b 0a 20  st crash-2.3 {. 
1220: 20 63 72 61 73 68 73 71 6c 20 2d 64 65 6c 61 79   crashsql -delay
1230: 20 32 20 2d 66 69 6c 65 20 74 65 73 74 2e 64 62   2 -file test.db
1240: 2d 6a 6f 75 72 6e 61 6c 20 7b 0a 20 20 20 20 44  -journal {.    D
1250: 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57  ELETE FROM abc W
1260: 48 45 52 45 20 61 20 3c 20 38 30 30 3b 0a 20 20  HERE a < 800;.  
1270: 7d 0a 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72  }.} {1 {child pr
1280: 6f 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e  ocess exited abn
1290: 6f 72 6d 61 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73  ormally}}.do_tes
12a0: 74 20 63 72 61 73 68 2d 32 2e 34 20 7b 0a 20 20  t crash-2.4 {.  
12b0: 73 69 67 6e 61 74 75 72 65 0a 7d 20 24 73 69 67  signature.} $sig
12c0: 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 32  .do_test crash-2
12d0: 2e 35 20 7b 0a 20 20 63 72 61 73 68 73 71 6c 20  .5 {.  crashsql 
12e0: 2d 64 65 6c 61 79 20 31 20 2d 66 69 6c 65 20 74  -delay 1 -file t
12f0: 65 73 74 2e 64 62 20 7b 0a 20 20 20 20 44 45 4c  est.db {.    DEL
1300: 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57 48 45  ETE FROM abc WHE
1310: 52 45 20 61 3c 38 30 30 3b 0a 20 20 7d 0a 7d 20  RE a<800;.  }.} 
1320: 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73  {1 {child proces
1330: 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61  s exited abnorma
1340: 6c 6c 79 7d 7d 0a 64 6f 5f 74 65 73 74 20 63 72  lly}}.do_test cr
1350: 61 73 68 2d 32 2e 36 20 7b 0a 20 20 73 69 67 6e  ash-2.6 {.  sign
1360: 61 74 75 72 65 0a 7d 20 24 73 69 67 0a 0a 23 2d  ature.} $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 2d 2d 2d 2d 0a 23 20 54 68 65 20  ---------.# The 
13c0: 63 72 61 73 68 2d 33 2e 2a 20 74 65 73 74 20 63  crash-3.* test c
13d0: 61 73 65 73 20 61 72 65 20 65 73 73 65 6e 74 69  ases are essenti
13e0: 61 6c 6c 79 20 74 68 65 20 73 61 6d 65 20 74 65  ally the same te
13f0: 73 74 20 61 73 20 74 65 73 74 20 63 61 73 65 0a  st as test case.
1400: 23 20 63 72 61 73 68 2d 32 2e 2a 2c 20 62 75 74  # crash-2.*, but
1410: 20 77 69 74 68 20 61 20 6d 6f 72 65 20 63 6f 6d   with a more com
1420: 70 6c 69 63 61 74 65 64 20 64 61 74 61 20 73 65  plicated data se
1430: 74 2e 20 0a 23 0a 23 20 54 68 65 20 74 65 73 74  t. .#.# The test
1440: 20 69 73 20 72 65 70 65 61 74 65 64 20 61 20 66   is repeated a f
1450: 65 77 20 74 69 6d 65 73 20 77 69 74 68 20 64 69  ew times with di
1460: 66 66 65 72 65 6e 74 20 73 65 65 64 73 20 66 6f  fferent seeds fo
1470: 72 20 74 68 65 20 72 61 6e 64 6f 6d 0a 23 20 6e  r the random.# n
1480: 75 6d 62 65 72 20 67 65 6e 65 72 61 74 6f 72 20  umber generator 
1490: 69 6e 20 74 68 65 20 63 72 61 73 68 69 6e 67 20  in the crashing 
14a0: 65 78 65 63 75 74 61 62 6c 65 2e 20 42 65 63 61  executable. Beca
14b0: 75 73 65 20 74 68 65 72 65 20 69 73 20 6e 6f 20  use there is no 
14c0: 77 61 79 20 74 6f 0a 23 20 73 65 65 64 20 74 68  way to.# seed th
14d0: 65 20 72 61 6e 64 6f 6d 20 6e 75 6d 62 65 72 20  e random number 
14e0: 67 65 6e 65 72 61 74 6f 72 20 64 69 72 65 63 74  generator direct
14f0: 6c 79 2c 20 73 6f 6d 65 20 53 51 4c 20 69 73 20  ly, some SQL is 
1500: 61 64 64 65 64 20 74 6f 20 74 68 65 20 74 65 73  added to the tes
1510: 74 0a 23 20 63 61 73 65 20 74 6f 20 27 75 73 65  t.# case to 'use
1520: 20 75 70 27 20 61 20 64 69 66 66 65 72 65 6e 74   up' a different
1530: 20 71 75 61 6e 74 69 74 79 20 72 61 6e 64 6f 6d   quantity random
1540: 20 6e 75 6d 62 65 72 73 20 62 65 66 6f 72 65 20   numbers before 
1550: 74 68 65 20 74 65 73 74 20 53 51 4c 0a 23 20 69  the test SQL.# i
1560: 73 20 65 78 65 63 75 74 65 64 2e 0a 23 0a 0a 23  s executed..#..#
1570: 20 4d 61 6b 65 20 73 75 72 65 20 74 68 65 20 66   Make sure the f
1580: 69 6c 65 20 69 73 20 6d 75 63 68 20 62 69 67 67  ile is much bigg
1590: 65 72 20 74 68 61 6e 20 74 68 65 20 70 61 67 65  er than the page
15a0: 72 2d 63 61 63 68 65 20 28 31 30 20 70 61 67 65  r-cache (10 page
15b0: 73 29 2e 20 54 68 69 73 0a 23 20 65 6e 73 75 72  s). This.# ensur
15c0: 65 73 20 74 68 61 74 20 63 61 63 68 65 2d 73 70  es that cache-sp
15d0: 69 6c 6c 73 20 68 61 70 70 65 6e 20 72 65 67 75  ills happen regu
15e0: 6c 61 72 6c 79 2e 0a 64 6f 5f 74 65 73 74 20 63  larly..do_test c
15f0: 72 61 73 68 2d 33 2e 30 20 7b 0a 20 20 65 78 65  rash-3.0 {.  exe
1600: 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45 52  csql {.    INSER
1610: 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43  T INTO abc SELEC
1620: 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20  T * FROM abc;.  
1630: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62    INSERT INTO ab
1640: 63 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20  c SELECT * FROM 
1650: 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20  abc;.    INSERT 
1660: 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20  INTO abc SELECT 
1670: 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20  * FROM abc;.    
1680: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20  INSERT INTO abc 
1690: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62  SELECT * FROM ab
16a0: 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  c;.    INSERT IN
16b0: 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 2a 20  TO abc SELECT * 
16c0: 46 52 4f 4d 20 61 62 63 3b 0a 20 20 7d 0a 20 20  FROM abc;.  }.  
16d0: 65 78 70 72 20 28 5b 66 69 6c 65 20 73 69 7a 65  expr ([file size
16e0: 20 74 65 73 74 2e 64 62 5d 20 2f 20 31 30 32 34   test.db] / 1024
16f0: 29 20 3e 20 34 35 30 0a 7d 20 7b 31 7d 0a 66 6f  ) > 450.} {1}.fo
1700: 72 20 7b 73 65 74 20 69 20 31 7d 20 7b 24 69 20  r {set i 1} {$i 
1710: 3c 20 24 72 65 70 65 61 74 73 7d 20 7b 69 6e 63  < $repeats} {inc
1720: 72 20 69 7d 20 7b 0a 20 20 73 65 74 20 73 69 67  r i} {.  set sig
1730: 20 5b 73 69 67 6e 61 74 75 72 65 5d 0a 20 20 64   [signature].  d
1740: 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 33 2e 24  o_test crash-3.$
1750: 69 2e 31 20 7b 0a 20 20 20 20 20 73 65 74 20 73  i.1 {.     set s
1760: 65 65 64 20 5b 65 78 70 72 20 7b 69 6e 74 28 61  eed [expr {int(a
1770: 62 73 28 72 61 6e 64 28 29 2a 31 30 30 30 30 29  bs(rand()*10000)
1780: 29 7d 5d 0a 20 20 20 20 20 63 72 61 73 68 73 71  )}].     crashsq
1790: 6c 20 2d 64 65 6c 61 79 20 5b 65 78 70 72 20 24  l -delay [expr $
17a0: 69 25 35 20 2b 20 31 5d 20 2d 66 69 6c 65 20 74  i%5 + 1] -file t
17b0: 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c 20 2d  est.db-journal -
17c0: 73 65 65 64 20 24 73 65 65 64 20 22 0a 20 20 20  seed $seed ".   
17d0: 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 20      BEGIN;.     
17e0: 20 20 53 45 4c 45 43 54 20 72 61 6e 64 6f 6d 28    SELECT random(
17f0: 29 20 46 52 4f 4d 20 61 62 63 20 4c 49 4d 49 54  ) FROM abc LIMIT
1800: 20 24 69 3b 0a 20 20 20 20 20 20 20 49 4e 53 45   $i;.       INSE
1810: 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55  RT INTO abc VALU
1820: 45 53 28 72 61 6e 64 73 74 72 28 31 30 2c 31 30  ES(randstr(10,10
1830: 29 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20  ), 0, 0);.      
1840: 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63   DELETE FROM abc
1850: 20 57 48 45 52 45 20 72 61 6e 64 6f 6d 28 29 25   WHERE random()%
1860: 31 30 21 3d 30 3b 0a 20 20 20 20 20 20 20 43 4f  10!=0;.       CO
1870: 4d 4d 49 54 3b 0a 20 20 20 20 20 22 0a 20 20 7d  MMIT;.     ".  }
1880: 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65   {1 {child proce
1890: 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d  ss exited abnorm
18a0: 61 6c 6c 79 7d 7d 0a 20 20 64 6f 5f 74 65 73 74  ally}}.  do_test
18b0: 20 63 72 61 73 68 2d 33 2e 24 69 2e 32 20 7b 0a   crash-3.$i.2 {.
18c0: 20 20 20 20 73 69 67 6e 61 74 75 72 65 0a 20 20      signature.  
18d0: 7d 20 24 73 69 67 0a 7d 20 0a 0a 23 2d 2d 2d 2d  } $sig.} ..#----
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 2d 2d 2d 2d 0a 23 20 54 68 65 20 66 6f 6c  ------.# The fol
1930: 6c 6f 77 69 6e 67 20 74 65 73 74 20 63 61 73 65  lowing test case
1940: 73 20 2d 20 63 72 61 73 68 2d 34 2e 2a 20 2d 20  s - crash-4.* - 
1950: 74 65 73 74 20 74 68 65 20 63 6f 72 72 65 63 74  test the correct
1960: 20 72 65 63 6f 76 65 72 79 20 6f 66 20 74 68 65   recovery of the
1970: 0a 23 20 64 61 74 61 62 61 73 65 20 77 68 65 6e  .# database when
1980: 20 61 20 63 72 61 73 68 20 6f 63 63 75 72 73 20   a crash occurs 
1990: 64 75 72 69 6e 67 20 61 20 6d 75 6c 74 69 2d 66  during a multi-f
19a0: 69 6c 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e  ile transaction.
19b0: 0a 23 0a 23 20 63 72 61 73 68 2d 34 2e 31 2e 2a  .#.# crash-4.1.*
19c0: 3a 20 54 65 73 74 20 72 65 63 6f 76 65 72 79 20  : Test recovery 
19d0: 77 68 65 6e 20 63 72 61 73 68 20 6f 63 63 75 72  when crash occur
19e0: 73 20 64 75 72 69 6e 67 20 73 79 6e 63 28 29 20  s during sync() 
19f0: 6f 66 20 74 68 65 20 0a 23 20 20 20 20 20 20 20  of the .#       
1a00: 20 20 20 20 20 20 20 6d 61 69 6e 20 64 61 74 61         main data
1a10: 62 61 73 65 20 6a 6f 75 72 6e 61 6c 20 66 69 6c  base journal fil
1a20: 65 2e 0a 23 20 63 72 61 73 68 2d 34 2e 32 2e 2a  e..# crash-4.2.*
1a30: 3a 20 54 65 73 74 20 72 65 63 6f 76 65 72 79 20  : Test recovery 
1a40: 77 68 65 6e 20 63 72 61 73 68 20 6f 63 63 75 72  when crash occur
1a50: 73 20 64 75 72 69 6e 67 20 73 79 6e 63 28 29 20  s during sync() 
1a60: 6f 66 20 61 6e 20 0a 23 20 20 20 20 20 20 20 20  of an .#        
1a70: 20 20 20 20 20 20 61 74 74 61 63 68 65 64 20 64        attached d
1a80: 61 74 61 62 61 73 65 20 6a 6f 75 72 6e 61 6c 20  atabase journal 
1a90: 66 69 6c 65 2e 0a 23 20 63 72 61 73 68 2d 34 2e  file..# crash-4.
1aa0: 33 2e 2a 3a 20 54 65 73 74 20 72 65 63 6f 76 65  3.*: Test recove
1ab0: 72 79 20 77 68 65 6e 20 63 72 61 73 68 20 6f 63  ry when crash oc
1ac0: 63 75 72 73 20 64 75 72 69 6e 67 20 73 79 6e 63  curs during sync
1ad0: 28 29 20 6f 66 20 74 68 65 20 6d 61 73 74 65 72  () of the master
1ae0: 0a 23 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .#              
1af0: 6a 6f 75 72 6e 61 6c 20 66 69 6c 65 2e 20 0a 23  journal file. .#
1b00: 0a 69 66 63 61 70 61 62 6c 65 20 61 74 74 61 63  .ifcapable attac
1b10: 68 20 7b 0a 20 20 64 6f 5f 74 65 73 74 20 63 72  h {.  do_test cr
1b20: 61 73 68 2d 34 2e 30 20 7b 0a 20 20 20 20 66 6f  ash-4.0 {.    fo
1b30: 72 63 65 64 65 6c 65 74 65 20 74 65 73 74 32 2e  rcedelete test2.
1b40: 64 62 0a 20 20 20 20 66 6f 72 63 65 64 65 6c 65  db.    forcedele
1b50: 74 65 20 74 65 73 74 32 2e 64 62 2d 6a 6f 75 72  te test2.db-jour
1b60: 6e 61 6c 0a 20 20 20 20 65 78 65 63 73 71 6c 20  nal.    execsql 
1b70: 7b 0a 20 20 20 20 20 20 41 54 54 41 43 48 20 27  {.      ATTACH '
1b80: 74 65 73 74 32 2e 64 62 27 20 41 53 20 61 75 78  test2.db' AS aux
1b90: 3b 0a 20 20 20 20 20 20 50 52 41 47 4d 41 20 61  ;.      PRAGMA a
1ba0: 75 78 2e 64 65 66 61 75 6c 74 5f 63 61 63 68 65  ux.default_cache
1bb0: 5f 73 69 7a 65 20 3d 20 31 30 3b 0a 20 20 20 20  _size = 10;.    
1bc0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 61    CREATE TABLE a
1bd0: 75 78 2e 61 62 63 32 20 41 53 20 53 45 4c 45 43  ux.abc2 AS SELEC
1be0: 54 20 32 2a 61 20 61 73 20 61 2c 20 32 2a 62 20  T 2*a as a, 2*b 
1bf0: 61 73 20 62 2c 20 32 2a 63 20 61 73 20 63 20 46  as b, 2*c as c F
1c00: 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 7d 0a 20  ROM abc;.    }. 
1c10: 20 20 20 65 78 70 72 20 28 5b 66 69 6c 65 20 73     expr ([file s
1c20: 69 7a 65 20 74 65 73 74 32 2e 64 62 5d 20 2f 20  ize test2.db] / 
1c30: 31 30 32 34 29 20 3e 20 34 35 30 0a 20 20 7d 20  1024) > 450.  } 
1c40: 7b 31 7d 0a 20 20 0a 20 20 73 65 74 20 66 69 6e  {1}.  .  set fin
1c50: 20 30 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20   0.  for {set i 
1c60: 31 7d 20 7b 24 69 3c 24 72 65 70 65 61 74 73 7d  1} {$i<$repeats}
1c70: 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20   {incr i} {.    
1c80: 73 65 74 20 73 65 65 64 20 5b 65 78 70 72 20 7b  set seed [expr {
1c90: 69 6e 74 28 61 62 73 28 72 61 6e 64 28 29 2a 31  int(abs(rand()*1
1ca0: 30 30 30 30 29 29 7d 5d 0a 20 20 20 20 73 65 74  0000))}].    set
1cb0: 20 73 69 67 20 5b 73 69 67 6e 61 74 75 72 65 5d   sig [signature]
1cc0: 0a 20 20 20 20 73 65 74 20 73 69 67 32 20 5b 73  .    set sig2 [s
1cd0: 69 67 6e 61 74 75 72 65 32 5d 0a 20 20 20 20 64  ignature2].    d
1ce0: 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34 2e 31  o_test crash-4.1
1cf0: 2e 24 69 2e 31 20 7b 0a 20 20 20 20 20 20 20 73  .$i.1 {.       s
1d00: 65 74 20 63 20 5b 63 72 61 73 68 73 71 6c 20 2d  et c [crashsql -
1d10: 64 65 6c 61 79 20 24 69 20 2d 66 69 6c 65 20 74  delay $i -file t
1d20: 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c 20 2d  est.db-journal -
1d30: 73 65 65 64 20 24 3a 3a 73 65 65 64 20 22 0a 20  seed $::seed ". 
1d40: 20 20 20 20 20 20 20 20 41 54 54 41 43 48 20 27          ATTACH '
1d50: 74 65 73 74 32 2e 64 62 27 20 41 53 20 61 75 78  test2.db' AS aux
1d60: 3b 0a 20 20 20 20 20 20 20 20 20 42 45 47 49 4e  ;.         BEGIN
1d70: 3b 0a 20 20 20 20 20 20 20 20 20 53 45 4c 45 43  ;.         SELEC
1d80: 54 20 72 61 6e 64 73 74 72 28 24 69 2c 24 69 29  T randstr($i,$i)
1d90: 20 46 52 4f 4d 20 61 62 63 20 4c 49 4d 49 54 20   FROM abc LIMIT 
1da0: 24 69 3b 0a 20 20 20 20 20 20 20 20 20 49 4e 53  $i;.         INS
1db0: 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c  ERT INTO abc VAL
1dc0: 55 45 53 28 72 61 6e 64 73 74 72 28 31 30 2c 31  UES(randstr(10,1
1dd0: 30 29 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20  0), 0, 0);.     
1de0: 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20      DELETE FROM 
1df0: 61 62 63 20 57 48 45 52 45 20 72 61 6e 64 6f 6d  abc WHERE random
1e00: 28 29 25 31 30 21 3d 30 3b 0a 20 20 20 20 20 20  ()%10!=0;.      
1e10: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
1e20: 62 63 32 20 56 41 4c 55 45 53 28 72 61 6e 64 73  bc2 VALUES(rands
1e30: 74 72 28 31 30 2c 31 30 29 2c 20 30 2c 20 30 29  tr(10,10), 0, 0)
1e40: 3b 0a 20 20 20 20 20 20 20 20 20 44 45 4c 45 54  ;.         DELET
1e50: 45 20 46 52 4f 4d 20 61 62 63 32 20 57 48 45 52  E FROM abc2 WHER
1e60: 45 20 72 61 6e 64 6f 6d 28 29 25 31 30 21 3d 30  E random()%10!=0
1e70: 3b 0a 20 20 20 20 20 20 20 20 20 43 4f 4d 4d 49  ;.         COMMI
1e80: 54 3b 0a 20 20 20 20 20 20 20 22 5d 0a 20 20 20  T;.       "].   
1e90: 20 20 20 20 69 66 20 7b 20 24 63 20 3d 3d 20 7b      if { $c == {
1ea0: 30 20 7b 7d 7d 20 7d 20 7b 0a 20 20 20 20 20 20  0 {}} } {.      
1eb0: 20 20 20 73 65 74 20 3a 3a 66 69 6e 20 31 0a 20     set ::fin 1. 
1ec0: 20 20 20 20 20 20 20 20 73 65 74 20 63 20 7b 31          set c {1
1ed0: 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20   {child process 
1ee0: 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c  exited abnormall
1ef0: 79 7d 7d 0a 20 20 20 20 20 20 20 7d 0a 20 20 20  y}}.       }.   
1f00: 20 20 20 20 73 65 74 20 63 0a 20 20 20 20 7d 20      set c.    } 
1f10: 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73  {1 {child proces
1f20: 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61  s exited abnorma
1f30: 6c 6c 79 7d 7d 0a 20 20 20 20 69 66 20 7b 24 3a  lly}}.    if {$:
1f40: 3a 66 69 6e 7d 20 62 72 65 61 6b 0a 20 20 20 20  :fin} break.    
1f50: 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34 2e  do_test crash-4.
1f60: 31 2e 24 69 2e 32 20 7b 0a 20 20 20 20 20 20 73  1.$i.2 {.      s
1f70: 69 67 6e 61 74 75 72 65 0a 20 20 20 20 7d 20 24  ignature.    } $
1f80: 73 69 67 0a 20 20 20 20 64 6f 5f 74 65 73 74 20  sig.    do_test 
1f90: 63 72 61 73 68 2d 34 2e 31 2e 24 69 2e 33 20 7b  crash-4.1.$i.3 {
1fa0: 0a 20 20 20 20 20 20 73 69 67 6e 61 74 75 72 65  .      signature
1fb0: 32 0a 20 20 20 20 7d 20 24 73 69 67 32 0a 20 20  2.    } $sig2.  
1fc0: 7d 20 0a 20 20 73 65 74 20 69 20 30 0a 20 20 73  } .  set i 0.  s
1fd0: 65 74 20 66 69 6e 20 30 0a 20 20 77 68 69 6c 65  et fin 0.  while
1fe0: 20 7b 5b 69 6e 63 72 20 69 5d 7d 20 7b 0a 20 20   {[incr i]} {.  
1ff0: 20 20 73 65 74 20 73 65 65 64 20 5b 65 78 70 72    set seed [expr
2000: 20 7b 69 6e 74 28 61 62 73 28 72 61 6e 64 28 29   {int(abs(rand()
2010: 2a 31 30 30 30 30 29 29 7d 5d 0a 20 20 20 20 73  *10000))}].    s
2020: 65 74 20 73 69 67 20 5b 73 69 67 6e 61 74 75 72  et sig [signatur
2030: 65 5d 0a 20 20 20 20 73 65 74 20 73 69 67 32 20  e].    set sig2 
2040: 5b 73 69 67 6e 61 74 75 72 65 32 5d 0a 20 20 20  [signature2].   
2050: 20 73 65 74 20 3a 3a 66 69 6e 20 30 0a 20 20 20   set ::fin 0.   
2060: 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34   do_test crash-4
2070: 2e 32 2e 24 69 2e 31 20 7b 0a 20 20 20 20 20 20  .2.$i.1 {.      
2080: 20 73 65 74 20 63 20 5b 63 72 61 73 68 73 71 6c   set c [crashsql
2090: 20 2d 64 65 6c 61 79 20 24 69 20 2d 66 69 6c 65   -delay $i -file
20a0: 20 74 65 73 74 32 2e 64 62 2d 6a 6f 75 72 6e 61   test2.db-journa
20b0: 6c 20 2d 73 65 65 64 20 24 3a 3a 73 65 65 64 20  l -seed $::seed 
20c0: 22 0a 20 20 20 20 20 20 20 20 20 41 54 54 41 43  ".         ATTAC
20d0: 48 20 27 74 65 73 74 32 2e 64 62 27 20 41 53 20  H 'test2.db' AS 
20e0: 61 75 78 3b 0a 20 20 20 20 20 20 20 20 20 42 45  aux;.         BE
20f0: 47 49 4e 3b 0a 20 20 20 20 20 20 20 20 20 53 45  GIN;.         SE
2100: 4c 45 43 54 20 72 61 6e 64 73 74 72 28 24 69 2c  LECT randstr($i,
2110: 24 69 29 20 46 52 4f 4d 20 61 62 63 20 4c 49 4d  $i) FROM abc LIM
2120: 49 54 20 24 69 3b 0a 20 20 20 20 20 20 20 20 20  IT $i;.         
2130: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20  INSERT INTO abc 
2140: 56 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28 31  VALUES(randstr(1
2150: 30 2c 31 30 29 2c 20 30 2c 20 30 29 3b 0a 20 20  0,10), 0, 0);.  
2160: 20 20 20 20 20 20 20 44 45 4c 45 54 45 20 46 52         DELETE FR
2170: 4f 4d 20 61 62 63 20 57 48 45 52 45 20 72 61 6e  OM abc WHERE ran
2180: 64 6f 6d 28 29 25 31 30 21 3d 30 3b 0a 20 20 20  dom()%10!=0;.   
2190: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
21a0: 4f 20 61 62 63 32 20 56 41 4c 55 45 53 28 72 61  O abc2 VALUES(ra
21b0: 6e 64 73 74 72 28 31 30 2c 31 30 29 2c 20 30 2c  ndstr(10,10), 0,
21c0: 20 30 29 3b 0a 20 20 20 20 20 20 20 20 20 44 45   0);.         DE
21d0: 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 32 20 57  LETE FROM abc2 W
21e0: 48 45 52 45 20 72 61 6e 64 6f 6d 28 29 25 31 30  HERE random()%10
21f0: 21 3d 30 3b 0a 20 20 20 20 20 20 20 20 20 43 4f  !=0;.         CO
2200: 4d 4d 49 54 3b 0a 20 20 20 20 20 20 20 22 5d 0a  MMIT;.       "].
2210: 20 20 20 20 20 20 20 69 66 20 7b 20 24 63 20 3d         if { $c =
2220: 3d 20 7b 30 20 7b 7d 7d 20 7d 20 7b 0a 20 20 20  = {0 {}} } {.   
2230: 20 20 20 20 20 20 73 65 74 20 3a 3a 66 69 6e 20        set ::fin 
2240: 31 0a 20 20 20 20 20 20 20 20 20 73 65 74 20 63  1.         set c
2250: 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f 63 65   {1 {child proce
2260: 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f 72 6d  ss exited abnorm
2270: 61 6c 6c 79 7d 7d 0a 20 20 20 20 20 20 20 7d 0a  ally}}.       }.
2280: 20 20 20 20 20 20 20 73 65 74 20 63 0a 20 20 20         set c.   
2290: 20 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70 72 6f   } {1 {child pro
22a0: 63 65 73 73 20 65 78 69 74 65 64 20 61 62 6e 6f  cess exited abno
22b0: 72 6d 61 6c 6c 79 7d 7d 0a 20 20 20 20 69 66 20  rmally}}.    if 
22c0: 7b 20 24 3a 3a 66 69 6e 20 7d 20 62 72 65 61 6b  { $::fin } break
22d0: 0a 20 20 20 20 64 6f 5f 74 65 73 74 20 63 72 61  .    do_test cra
22e0: 73 68 2d 34 2e 32 2e 24 69 2e 32 20 7b 0a 20 20  sh-4.2.$i.2 {.  
22f0: 20 20 20 20 73 69 67 6e 61 74 75 72 65 0a 20 20      signature.  
2300: 20 20 7d 20 24 73 69 67 0a 20 20 20 20 64 6f 5f    } $sig.    do_
2310: 74 65 73 74 20 63 72 61 73 68 2d 34 2e 32 2e 24  test crash-4.2.$
2320: 69 2e 33 20 7b 0a 20 20 20 20 20 20 73 69 67 6e  i.3 {.      sign
2330: 61 74 75 72 65 32 0a 20 20 20 20 7d 20 24 73 69  ature2.    } $si
2340: 67 32 0a 20 20 7d 20 0a 20 20 66 6f 72 20 7b 73  g2.  } .  for {s
2350: 65 74 20 69 20 31 7d 20 7b 24 69 20 3c 20 35 7d  et i 1} {$i < 5}
2360: 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20   {incr i} {.    
2370: 73 65 74 20 73 69 67 20 5b 73 69 67 6e 61 74 75  set sig [signatu
2380: 72 65 5d 0a 20 20 20 20 73 65 74 20 73 69 67 32  re].    set sig2
2390: 20 5b 73 69 67 6e 61 74 75 72 65 32 5d 0a 20 20   [signature2].  
23a0: 20 20 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d    do_test crash-
23b0: 34 2e 33 2e 24 69 2e 31 20 7b 0a 20 20 20 20 20  4.3.$i.1 {.     
23c0: 20 20 63 72 61 73 68 73 71 6c 20 2d 64 65 6c 61    crashsql -dela
23d0: 79 20 31 20 2d 66 69 6c 65 20 74 65 73 74 2e 64  y 1 -file test.d
23e0: 62 2d 6d 6a 2a 20 22 0a 20 20 20 20 20 20 20 20  b-mj* ".        
23f0: 20 41 54 54 41 43 48 20 27 74 65 73 74 32 2e 64   ATTACH 'test2.d
2400: 62 27 20 41 53 20 61 75 78 3b 0a 20 20 20 20 20  b' AS aux;.     
2410: 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 20      BEGIN;.     
2420: 20 20 20 20 53 45 4c 45 43 54 20 72 61 6e 64 6f      SELECT rando
2430: 6d 28 29 20 46 52 4f 4d 20 61 62 63 20 4c 49 4d  m() FROM abc LIM
2440: 49 54 20 24 69 3b 0a 20 20 20 20 20 20 20 20 20  IT $i;.         
2450: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20  INSERT INTO abc 
2460: 56 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28 31  VALUES(randstr(1
2470: 30 2c 31 30 29 2c 20 30 2c 20 30 29 3b 0a 20 20  0,10), 0, 0);.  
2480: 20 20 20 20 20 20 20 44 45 4c 45 54 45 20 46 52         DELETE FR
2490: 4f 4d 20 61 62 63 20 57 48 45 52 45 20 72 61 6e  OM abc WHERE ran
24a0: 64 6f 6d 28 29 25 31 30 21 3d 30 3b 0a 20 20 20  dom()%10!=0;.   
24b0: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
24c0: 4f 20 61 62 63 32 20 56 41 4c 55 45 53 28 72 61  O abc2 VALUES(ra
24d0: 6e 64 73 74 72 28 31 30 2c 31 30 29 2c 20 30 2c  ndstr(10,10), 0,
24e0: 20 30 29 3b 0a 20 20 20 20 20 20 20 20 20 44 45   0);.         DE
24f0: 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 32 20 57  LETE FROM abc2 W
2500: 48 45 52 45 20 72 61 6e 64 6f 6d 28 29 25 31 30  HERE random()%10
2510: 21 3d 30 3b 0a 20 20 20 20 20 20 20 20 20 43 4f  !=0;.         CO
2520: 4d 4d 49 54 3b 0a 20 20 20 20 20 20 20 22 0a 20  MMIT;.       ". 
2530: 20 20 20 7d 20 7b 31 20 7b 63 68 69 6c 64 20 70     } {1 {child p
2540: 72 6f 63 65 73 73 20 65 78 69 74 65 64 20 61 62  rocess exited ab
2550: 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a 20 20 20 20 64  normally}}.    d
2560: 6f 5f 74 65 73 74 20 63 72 61 73 68 2d 34 2e 33  o_test crash-4.3
2570: 2e 24 69 2e 32 20 7b 0a 20 20 20 20 20 20 73 69  .$i.2 {.      si
2580: 67 6e 61 74 75 72 65 0a 20 20 20 20 7d 20 24 73  gnature.    } $s
2590: 69 67 0a 20 20 20 20 64 6f 5f 74 65 73 74 20 63  ig.    do_test c
25a0: 72 61 73 68 2d 34 2e 33 2e 24 69 2e 33 20 7b 0a  rash-4.3.$i.3 {.
25b0: 20 20 20 20 20 20 73 69 67 6e 61 74 75 72 65 32        signature2
25c0: 0a 20 20 20 20 7d 20 24 73 69 67 32 0a 20 20 7d  .    } $sig2.  }
25d0: 0a 7d 0a 0a 23 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 2d 2d 2d 2d 0a  ---------------.
2620: 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20  # The following 
2630: 74 65 73 74 20 63 61 73 65 73 20 2d 20 63 72 61  test cases - cra
2640: 73 68 2d 35 2e 2a 20 2d 20 65 78 70 6f 73 65 73  sh-5.* - exposes
2650: 20 61 20 62 75 67 20 74 68 61 74 20 65 78 69 73   a bug that exis
2660: 74 65 64 20 69 6e 20 74 68 65 0a 23 20 73 71 6c  ted in the.# sql
2670: 69 74 65 34 70 61 67 65 72 5f 6d 6f 76 65 70 61  ite4pager_movepa
2680: 67 65 28 29 20 41 50 49 20 75 73 65 64 20 62 79  ge() API used by
2690: 20 61 75 74 6f 2d 76 61 63 75 75 6d 20 64 61 74   auto-vacuum dat
26a0: 61 62 61 73 65 73 2e 0a 23 20 64 61 74 61 62 61  abases..# databa
26b0: 73 65 20 77 68 65 6e 20 61 20 63 72 61 73 68 20  se when a crash 
26c0: 6f 63 63 75 72 73 20 64 75 72 69 6e 67 20 61 20  occurs during a 
26d0: 6d 75 6c 74 69 2d 66 69 6c 65 20 74 72 61 6e 73  multi-file trans
26e0: 61 63 74 69 6f 6e 2e 20 53 65 65 20 63 6f 6d 6d  action. See comm
26f0: 65 6e 74 73 0a 23 20 69 6e 20 74 65 73 74 20 63  ents.# in test c
2700: 72 61 73 68 2d 35 2e 33 20 66 6f 72 20 64 65 74  rash-5.3 for det
2710: 61 69 6c 73 2e 0a 23 0a 64 62 20 63 6c 6f 73 65  ails..#.db close
2720: 0a 66 6f 72 63 65 64 65 6c 65 74 65 20 74 65 73  .forcedelete tes
2730: 74 2e 64 62 0a 73 71 6c 69 74 65 34 20 64 62 20  t.db.sqlite4 db 
2740: 74 65 73 74 2e 64 62 0a 64 6f 5f 74 65 73 74 20  test.db.do_test 
2750: 63 72 61 73 68 2d 35 2e 31 20 7b 0a 20 20 65 78  crash-5.1 {.  ex
2760: 65 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41  ecsql {.    CREA
2770: 54 45 20 54 41 42 4c 45 20 61 62 63 28 61 2c 20  TE TABLE abc(a, 
2780: 62 2c 20 63 29 3b 20 20 20 20 20 20 20 20 20 20  b, c);          
2790: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
27a0: 2d 2d 20 52 6f 6f 74 20 70 61 67 65 20 33 0a 20  -- Root page 3. 
27b0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
27c0: 62 63 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74  bc VALUES(randst
27d0: 72 28 31 35 30 30 2c 31 35 30 30 29 2c 20 30 2c  r(1500,1500), 0,
27e0: 20 30 29 3b 20 20 20 2d 2d 20 4f 76 65 72 66 6c   0);   -- Overfl
27f0: 6f 77 20 70 61 67 65 20 34 0a 20 20 20 20 49 4e  ow page 4.    IN
2800: 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45  SERT INTO abc SE
2810: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b  LECT * FROM abc;
2820: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
2830: 20 61 62 63 20 53 45 4c 45 43 54 20 2a 20 46 52   abc SELECT * FR
2840: 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e 53 45  OM abc;.    INSE
2850: 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45  RT INTO abc SELE
2860: 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 0a 20  CT * FROM abc;. 
2870: 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20   }.} {}.do_test 
2880: 63 72 61 73 68 2d 35 2e 32 20 7b 0a 20 20 65 78  crash-5.2 {.  ex
2890: 70 72 20 5b 66 69 6c 65 20 73 69 7a 65 20 74 65  pr [file size te
28a0: 73 74 2e 64 62 5d 20 2f 20 31 30 32 34 0a 7d 20  st.db] / 1024.} 
28b0: 5b 65 78 70 72 20 5b 73 74 72 69 6e 67 20 6d 61  [expr [string ma
28c0: 74 63 68 20 5b 65 78 65 63 73 71 6c 20 7b 70 72  tch [execsql {pr
28d0: 61 67 6d 61 20 61 75 74 6f 5f 76 61 63 75 75 6d  agma auto_vacuum
28e0: 7d 5d 20 31 5d 20 3f 20 31 31 20 3a 20 31 30 5d  }] 1] ? 11 : 10]
28f0: 0a 73 65 74 20 73 69 67 20 5b 73 69 67 6e 61 74  .set sig [signat
2900: 75 72 65 5d 0a 64 6f 5f 74 65 73 74 20 63 72 61  ure].do_test cra
2910: 73 68 2d 35 2e 33 20 7b 0a 23 20 54 68 65 20 53  sh-5.3 {.# The S
2920: 51 4c 20 62 65 6c 6f 77 20 69 73 20 75 73 65 64  QL below is used
2930: 20 74 6f 20 65 78 70 6f 73 65 20 61 20 62 75 67   to expose a bug
2940: 20 74 68 61 74 20 65 78 69 73 74 65 64 20 69 6e   that existed in
2950: 0a 23 20 73 71 6c 69 74 65 34 70 61 67 65 72 5f  .# sqlite4pager_
2960: 6d 6f 76 65 70 61 67 65 28 29 20 64 75 72 69 6e  movepage() durin
2970: 67 20 64 65 76 65 6c 6f 70 6d 65 6e 74 20 6f 66  g development of
2980: 20 74 68 65 20 61 75 74 6f 2d 76 61 63 75 75 6d   the auto-vacuum
2990: 20 66 65 61 74 75 72 65 2e 20 49 74 0a 23 20 66   feature. It.# f
29a0: 75 6e 63 74 69 6f 6e 73 20 61 73 20 66 6f 6c 6c  unctions as foll
29b0: 6f 77 73 3a 0a 23 20 0a 23 20 31 3a 20 42 65 67  ows:.# .# 1: Beg
29c0: 69 6e 20 61 20 74 72 61 6e 73 61 63 74 69 6f 6e  in a transaction
29d0: 2e 0a 23 20 32 3a 20 50 75 74 20 70 61 67 65 20  ..# 2: Put page 
29e0: 34 20 6f 6e 20 74 68 65 20 66 72 65 65 2d 6c 69  4 on the free-li
29f0: 73 74 20 28 77 61 73 20 74 68 65 20 6f 76 65 72  st (was the over
2a00: 66 6c 6f 77 20 70 61 67 65 20 66 6f 72 20 74 68  flow page for th
2a10: 65 20 72 6f 77 20 64 65 6c 65 74 65 64 29 2e 0a  e row deleted)..
2a20: 23 20 33 3a 20 57 72 69 74 65 20 64 61 74 61 20  # 3: Write data 
2a30: 74 6f 20 70 61 67 65 20 34 20 28 69 74 20 62 65  to page 4 (it be
2a40: 63 6f 6d 65 73 20 74 68 65 20 6f 76 65 72 66 6c  comes the overfl
2a50: 6f 77 20 70 61 67 65 20 66 6f 72 20 74 68 65 20  ow page for the 
2a60: 72 6f 77 20 69 6e 73 65 72 74 65 64 29 2e 0a 23  row inserted)..#
2a70: 20 20 20 20 54 68 65 20 6f 6c 64 20 70 61 67 65      The old page
2a80: 20 34 20 64 61 74 61 20 68 61 73 20 62 65 65 6e   4 data has been
2a90: 20 77 72 69 74 74 65 6e 20 74 6f 20 74 68 65 20   written to the 
2aa0: 6a 6f 75 72 6e 61 6c 20 66 69 6c 65 2c 20 62 75  journal file, bu
2ab0: 74 20 74 68 65 0a 23 20 20 20 20 6a 6f 75 72 6e  t the.#    journ
2ac0: 61 6c 20 66 69 6c 65 20 68 61 73 20 6e 6f 74 20  al file has not 
2ad0: 62 65 65 6e 20 73 79 6e 63 28 29 68 72 6f 6e 69  been sync()hroni
2ae0: 7a 65 64 2e 0a 23 20 34 3a 20 43 72 65 61 74 65  zed..# 4: Create
2af0: 20 61 20 74 61 62 6c 65 2c 20 77 68 69 63 68 20   a table, which 
2b00: 63 61 6c 6c 73 20 73 71 6c 69 74 65 34 70 61 67  calls sqlite4pag
2b10: 65 72 5f 6d 6f 76 65 70 61 67 65 28 29 20 74 6f  er_movepage() to
2b20: 20 6d 6f 76 65 20 70 61 67 65 20 34 0a 23 20 20   move page 4.#  
2b30: 20 20 74 6f 20 74 68 65 20 65 6e 64 20 6f 66 20    to the end of 
2b40: 74 68 65 20 64 61 74 61 62 61 73 65 20 28 70 61  the database (pa
2b50: 67 65 20 31 32 29 20 74 6f 20 6d 61 6b 65 20 72  ge 12) to make r
2b60: 6f 6f 6d 20 66 6f 72 20 74 68 65 20 6e 65 77 20  oom for the new 
2b70: 72 6f 6f 74 2d 70 61 67 65 2e 0a 23 20 35 3a 20  root-page..# 5: 
2b80: 50 75 74 20 70 72 65 73 73 75 72 65 20 6f 6e 20  Put pressure on 
2b90: 74 68 65 20 70 61 67 65 72 2d 63 61 63 68 65 2e  the pager-cache.
2ba0: 20 54 68 69 73 20 72 65 73 75 6c 74 73 20 69 6e   This results in
2bb0: 20 70 61 67 65 20 34 20 62 65 69 6e 67 20 77 72   page 4 being wr
2bc0: 69 74 74 65 6e 0a 23 20 20 20 20 74 6f 20 74 68  itten.#    to th
2bd0: 65 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20  e database file 
2be0: 74 6f 20 6d 61 6b 65 20 73 70 61 63 65 20 69 6e  to make space in
2bf0: 20 74 68 65 20 63 61 63 68 65 20 74 6f 20 6c 6f   the cache to lo
2c00: 61 64 20 61 20 6e 65 77 20 70 61 67 65 2e 20 54  ad a new page. T
2c10: 68 65 0a 23 20 20 20 20 62 75 67 20 77 61 73 20  he.#    bug was 
2c20: 74 68 61 74 20 70 61 67 65 20 34 20 77 61 73 20  that page 4 was 
2c30: 77 72 69 74 74 65 6e 20 74 6f 20 74 68 65 20 64  written to the d
2c40: 61 74 61 62 61 73 65 20 66 69 6c 65 20 62 65 66  atabase file bef
2c50: 6f 72 65 20 74 68 65 20 6a 6f 75 72 6e 61 6c 0a  ore the journal.
2c60: 23 20 20 20 20 69 73 20 73 79 6e 63 28 29 68 72  #    is sync()hr
2c70: 6f 6e 69 7a 65 64 2e 0a 23 20 36 3a 20 43 6f 6d  onized..# 6: Com
2c80: 6d 69 74 2e 20 41 20 63 72 61 73 68 20 6f 63 63  mit. A crash occ
2c90: 75 72 73 20 64 75 72 69 6e 67 20 74 68 65 20 73  urs during the s
2ca0: 79 6e 63 20 6f 66 20 74 68 65 20 6a 6f 75 72 6e  ync of the journ
2cb0: 61 6c 20 66 69 6c 65 2e 0a 23 0a 23 20 45 6e 64  al file..#.# End
2cc0: 20 72 65 73 75 6c 74 3a 20 42 65 66 6f 72 65 20   result: Before 
2cd0: 74 68 65 20 62 75 67 20 77 61 73 20 66 69 78 65  the bug was fixe
2ce0: 64 2c 20 64 61 74 61 20 68 61 73 20 62 65 65 6e  d, data has been
2cf0: 20 77 72 69 74 74 65 6e 20 74 6f 20 70 61 67 65   written to page
2d00: 20 34 20 6f 66 20 74 68 65 0a 23 20 64 61 74 61   4 of the.# data
2d10: 62 61 73 65 20 66 69 6c 65 20 61 6e 64 20 74 68  base file and th
2d20: 65 20 6a 6f 75 72 6e 61 6c 20 66 69 6c 65 20 64  e journal file d
2d30: 6f 65 73 20 6e 6f 74 20 63 6f 6e 74 61 69 6e 20  oes not contain 
2d40: 74 72 75 73 74 77 6f 72 74 68 79 20 72 6f 6c 6c  trustworthy roll
2d50: 62 61 63 6b 0a 23 20 64 61 74 61 20 66 6f 72 20  back.# data for 
2d60: 74 68 69 73 20 70 61 67 65 2e 0a 23 0a 20 20 63  this page..#.  c
2d70: 72 61 73 68 73 71 6c 20 2d 64 65 6c 61 79 20 31  rashsql -delay 1
2d80: 20 2d 66 69 6c 65 20 74 65 73 74 2e 64 62 2d 6a   -file test.db-j
2d90: 6f 75 72 6e 61 6c 20 7b 0a 20 20 20 20 42 45 47  ournal {.    BEG
2da0: 49 4e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20  IN;             
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 20 20 20 20                  
2dd0: 2d 2d 20 31 0a 20 20 20 20 44 45 4c 45 54 45 20  -- 1.    DELETE 
2de0: 46 52 4f 4d 20 61 62 63 20 57 48 45 52 45 20 6f  FROM abc WHERE o
2df0: 69 64 20 3d 20 31 3b 20 20 20 20 20 20 20 20 20  id = 1;         
2e00: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 32              -- 2
2e10: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
2e20: 20 61 62 63 20 56 41 4c 55 45 53 28 72 61 6e 64   abc VALUES(rand
2e30: 73 74 72 28 31 35 30 30 2c 31 35 30 30 29 2c 20  str(1500,1500), 
2e40: 30 2c 20 30 29 3b 20 20 2d 2d 20 33 0a 20 20 20  0, 0);  -- 3.   
2e50: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 61 62   CREATE TABLE ab
2e60: 63 32 28 61 2c 20 62 2c 20 63 29 3b 20 20 20 20  c2(a, b, c);    
2e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2e80: 20 20 20 20 2d 2d 20 34 0a 20 20 20 20 53 45 4c      -- 4.    SEL
2e90: 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 3b 20  ECT * 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 20 20 20 20                  
2ec0: 2d 2d 20 35 0a 20 20 20 20 43 4f 4d 4d 49 54 3b  -- 5.    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 20 20 20 20 2d 2d 20 36              -- 6
2f00: 0a 20 20 7d 0a 7d 20 7b 31 20 7b 63 68 69 6c 64  .  }.} {1 {child
2f10: 20 70 72 6f 63 65 73 73 20 65 78 69 74 65 64 20   process exited 
2f20: 61 62 6e 6f 72 6d 61 6c 6c 79 7d 7d 0a 69 6e 74  abnormally}}.int
2f30: 65 67 72 69 74 79 5f 63 68 65 63 6b 20 63 72 61  egrity_check cra
2f40: 73 68 2d 35 2e 34 0a 64 6f 5f 74 65 73 74 20 63  sh-5.4.do_test c
2f50: 72 61 73 68 2d 35 2e 35 20 7b 0a 20 20 73 69 67  rash-5.5 {.  sig
2f60: 6e 61 74 75 72 65 0a 7d 20 24 73 69 67 0a 0a 23  nature.} $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 2d 2d 2d 2d 0a 23 20 54 68 65  ----------.# The
2fc0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 20   following test 
2fd0: 63 61 73 65 73 20 2d 20 63 72 61 73 68 2d 36 2e  cases - crash-6.
2fe0: 2a 20 2d 20 74 65 73 74 20 74 68 61 74 20 61 20  * - test that a 
2ff0: 44 52 4f 50 20 54 41 42 4c 45 20 6f 70 65 72 61  DROP TABLE opera
3000: 74 69 6f 6e 0a 23 20 69 73 20 63 6f 72 72 65 63  tion.# is correc
3010: 74 6c 79 20 72 6f 6c 6c 65 64 20 62 61 63 6b 20  tly rolled back 
3020: 69 6e 20 74 68 65 20 65 76 65 6e 74 20 6f 66 20  in the event of 
3030: 61 20 63 72 61 73 68 20 77 68 69 6c 65 20 74 68  a crash while th
3040: 65 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 0a  e database file.
3050: 23 20 69 73 20 62 65 69 6e 67 20 77 72 69 74 74  # is being writt
3060: 65 6e 2e 20 54 68 69 73 20 69 73 20 6d 61 69 6e  en. This is main
3070: 6c 79 20 74 6f 20 74 65 73 74 20 74 68 61 74 20  ly to test that 
3080: 61 6c 6c 20 70 61 67 65 73 20 61 72 65 20 77 72  all pages are wr
3090: 69 74 74 65 6e 20 74 6f 20 74 68 65 0a 23 20 6a  itten to the.# j
30a0: 6f 75 72 6e 61 6c 20 66 69 6c 65 20 62 65 66 6f  ournal file befo
30b0: 72 65 20 74 72 75 6e 63 61 74 69 6f 6e 20 69 6e  re truncation in
30c0: 20 61 6e 20 61 75 74 6f 2d 76 61 63 75 75 6d 20   an auto-vacuum 
30d0: 64 61 74 61 62 61 73 65 2e 0a 23 0a 64 6f 5f 74  database..#.do_t
30e0: 65 73 74 20 63 72 61 73 68 2d 36 2e 31 20 7b 0a  est crash-6.1 {.
30f0: 20 20 63 72 61 73 68 73 71 6c 20 2d 64 65 6c 61    crashsql -dela
3100: 79 20 31 20 2d 66 69 6c 65 20 74 65 73 74 2e 64  y 1 -file test.d
3110: 62 20 7b 0a 20 20 20 20 44 52 4f 50 20 54 41 42  b {.    DROP TAB
3120: 4c 45 20 61 62 63 3b 0a 20 20 7d 0a 7d 20 7b 31  LE abc;.  }.} {1
3130: 20 7b 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20   {child process 
3140: 65 78 69 74 65 64 20 61 62 6e 6f 72 6d 61 6c 6c  exited abnormall
3150: 79 7d 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73  y}}.do_test cras
3160: 68 2d 36 2e 32 20 7b 0a 20 20 73 69 67 6e 61 74  h-6.2 {.  signat
3170: 75 72 65 0a 7d 20 24 73 69 67 0a 0a 23 2d 2d 2d  ure.} $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 2d 2d 2d 2d 0a 23 20 54 68 65 73 65 20  -------.# These 
31d0: 74 65 73 74 20 63 61 73 65 73 20 74 65 73 74 20  test cases test 
31e0: 74 68 65 20 63 61 73 65 20 77 68 65 72 65 20 74  the case where t
31f0: 68 65 20 6d 61 73 74 65 72 20 6a 6f 75 72 6e 61  he master journa
3200: 6c 20 66 69 6c 65 20 6e 61 6d 65 20 69 73 20 0a  l file name is .
3210: 23 20 63 6f 72 72 75 70 74 65 64 20 73 6c 69 67  # corrupted slig
3220: 68 74 6c 79 20 73 6f 20 74 68 61 74 20 74 68 65  htly so that the
3230: 20 63 6f 72 72 75 70 74 69 6f 6e 20 68 61 73 20   corruption has 
3240: 74 6f 20 62 65 20 64 65 74 65 63 74 65 64 20 62  to be detected b
3250: 79 20 74 68 65 0a 23 20 63 68 65 63 6b 73 75 6d  y the.# checksum
3260: 2e 0a 64 6f 5f 74 65 73 74 20 63 72 61 73 68 2d  ..do_test crash-
3270: 37 2e 31 20 7b 0a 20 20 63 72 61 73 68 73 71 6c  7.1 {.  crashsql
3280: 20 2d 64 65 6c 61 79 20 31 20 2d 66 69 6c 65 20   -delay 1 -file 
3290: 74 65 73 74 2e 64 62 20 7b 0a 20 20 20 20 41 54  test.db {.    AT
32a0: 54 41 43 48 20 27 74 65 73 74 32 2e 64 62 27 20  TACH 'test2.db' 
32b0: 41 53 20 61 75 78 3b 0a 20 20 20 20 42 45 47 49  AS aux;.    BEGI
32c0: 4e 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  N;.    INSERT IN
32d0: 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 72 61  TO abc VALUES(ra
32e0: 6e 64 73 74 72 28 31 35 30 30 2c 31 35 30 30 29  ndstr(1500,1500)
32f0: 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 49 4e 53  , 0, 0);.    INS
3300: 45 52 54 20 49 4e 54 4f 20 61 62 63 32 20 56 41  ERT INTO abc2 VA
3310: 4c 55 45 53 28 72 61 6e 64 73 74 72 28 31 35 30  LUES(randstr(150
3320: 30 2c 31 35 30 30 29 2c 20 30 2c 20 30 29 3b 0a  0,1500), 0, 0);.
3330: 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20 20 7d 0a      COMMIT;.  }.
3340: 0a 20 20 23 20 43 68 61 6e 67 65 20 74 68 65 20  .  # Change the 
3350: 63 68 65 63 6b 73 75 6d 20 76 61 6c 75 65 20 66  checksum value f
3360: 6f 72 20 74 68 65 20 6d 61 73 74 65 72 20 6a 6f  or the master jo
3370: 75 72 6e 61 6c 20 6e 61 6d 65 2e 0a 20 20 73 65  urnal name..  se
3380: 74 20 66 20 5b 6f 70 65 6e 20 74 65 73 74 2e 64  t f [open test.d
3390: 62 2d 6a 6f 75 72 6e 61 6c 20 61 5d 0a 20 20 66  b-journal a].  f
33a0: 63 6f 6e 66 69 67 75 72 65 20 24 66 20 2d 65 6e  configure $f -en
33b0: 63 6f 64 69 6e 67 20 62 69 6e 61 72 79 0a 20 20  coding binary.  
33c0: 73 65 65 6b 20 24 66 20 5b 65 78 70 72 20 5b 66  seek $f [expr [f
33d0: 69 6c 65 20 73 69 7a 65 20 74 65 73 74 2e 64 62  ile size test.db
33e0: 2d 6a 6f 75 72 6e 61 6c 5d 20 2d 20 31 32 5d 0a  -journal] - 12].
33f0: 20 20 70 75 74 73 20 2d 6e 6f 6e 65 77 6c 69 6e    puts -nonewlin
3400: 65 20 24 66 20 22 5c 30 30 5c 30 30 5c 30 30 5c  e $f "\00\00\00\
3410: 30 30 22 0a 20 20 63 6c 6f 73 65 20 24 66 0a 7d  00".  close $f.}
3420: 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 63 72 61 73   {}.do_test cras
3430: 68 2d 37 2e 32 20 7b 0a 20 20 73 69 67 6e 61 74  h-7.2 {.  signat
3440: 75 72 65 0a 7d 20 24 73 69 67 0a 0a 66 69 6e 69  ure.} $sig..fini
3450: 73 68 5f 74 65 73 74 0a                          sh_test.