/ Hex Artifact Content
Login

Artifact e039ac66c78d5561683cacde04097213cdad3b58e2b3f3fe1112862217bfd915:


0000: 23 20 32 30 31 30 20 4d 61 79 20 30 33 0a 23 0a  # 2010 May 03.#.
0010: 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73  # The author dis
0020: 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74  claims copyright
0030: 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20   to this source 
0040: 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20  code.  In place 
0050: 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74  of.# a legal not
0060: 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62  ice, here is a b
0070: 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20  lessing:.#.#    
0080: 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20  May you do good 
0090: 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20  and not evil..# 
00a0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20     May you find 
00b0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20  forgiveness for 
00c0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72  yourself and for
00d0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20  give others..#  
00e0: 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20    May you share 
00f0: 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61  freely, never ta
0100: 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79  king more than y
0110: 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a  ou give..#.#****
0120: 2a 2a 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 0a 23 20 54 68 69 73 20 66 69 6c 65 20  ***.# This file 
0170: 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67 72 65  implements regre
0180: 73 73 69 6f 6e 20 74 65 73 74 73 20 66 6f 72 20  ssion tests for 
0190: 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79 2e 20  SQLite library. 
01a0: 20 54 68 65 0a 23 20 66 6f 63 75 73 20 6f 66 20   The.# focus of 
01b0: 74 68 69 73 20 66 69 6c 65 20 69 73 20 74 65 73  this file is tes
01c0: 74 69 6e 67 20 74 68 65 20 6f 70 65 72 61 74 69  ting the operati
01d0: 6f 6e 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72  on of the librar
01e0: 79 20 69 6e 0a 23 20 22 50 52 41 47 4d 41 20 6a  y in.# "PRAGMA j
01f0: 6f 75 72 6e 61 6c 5f 6d 6f 64 65 3d 57 41 4c 22  ournal_mode=WAL"
0200: 20 6d 6f 64 65 2e 0a 23 0a 0a 73 65 74 20 74 65   mode..#..set te
0210: 73 74 64 69 72 20 5b 66 69 6c 65 20 64 69 72 6e  stdir [file dirn
0220: 61 6d 65 20 24 61 72 67 76 30 5d 0a 73 6f 75 72  ame $argv0].sour
0230: 63 65 20 24 74 65 73 74 64 69 72 2f 74 65 73 74  ce $testdir/test
0240: 65 72 2e 74 63 6c 0a 73 6f 75 72 63 65 20 24 74  er.tcl.source $t
0250: 65 73 74 64 69 72 2f 6d 61 6c 6c 6f 63 5f 63 6f  estdir/malloc_co
0260: 6d 6d 6f 6e 2e 74 63 6c 0a 73 6f 75 72 63 65 20  mmon.tcl.source 
0270: 24 74 65 73 74 64 69 72 2f 6c 6f 63 6b 5f 63 6f  $testdir/lock_co
0280: 6d 6d 6f 6e 2e 74 63 6c 0a 0a 69 66 63 61 70 61  mmon.tcl..ifcapa
0290: 62 6c 65 20 21 77 61 6c 20 7b 66 69 6e 69 73 68  ble !wal {finish
02a0: 5f 74 65 73 74 20 3b 20 72 65 74 75 72 6e 20 7d  _test ; return }
02b0: 0a 73 65 74 20 74 65 73 74 70 72 65 66 69 78 20  .set testprefix 
02c0: 77 61 6c 66 61 75 6c 74 32 0a 0a 23 2d 2d 2d 2d  walfault2..#----
02d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0310: 2d 2d 2d 2d 2d 0a 23 20 49 6e 6a 65 63 74 20 66  -----.# Inject f
0320: 61 75 6c 74 73 20 77 68 69 6c 65 20 74 72 75 6e  aults while trun
0330: 63 61 74 69 6e 67 20 74 68 65 20 77 61 6c 20 66  cating the wal f
0340: 69 6c 65 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71  ile..#.do_execsq
0350: 6c 5f 74 65 73 74 20 31 2e 30 20 7b 0a 20 20 50  l_test 1.0 {.  P
0360: 52 41 47 4d 41 20 61 75 74 6f 5f 76 61 63 75 75  RAGMA auto_vacuu
0370: 6d 20 3d 20 30 3b 0a 20 20 43 52 45 41 54 45 20  m = 0;.  CREATE 
0380: 54 41 42 4c 45 20 74 31 28 61 2c 20 62 29 3b 0a  TABLE t1(a, b);.
0390: 20 20 50 52 41 47 4d 41 20 6a 6f 75 72 6e 61 6c    PRAGMA journal
03a0: 5f 6d 6f 64 65 20 3d 20 77 61 6c 3b 0a 20 20 57  _mode = wal;.  W
03b0: 49 54 48 20 73 28 69 29 20 41 53 20 28 0a 20 20  ITH s(i) AS (.  
03c0: 20 20 53 45 4c 45 43 54 20 31 20 55 4e 49 4f 4e    SELECT 1 UNION
03d0: 20 41 4c 4c 20 53 45 4c 45 43 54 20 69 2b 31 20   ALL SELECT i+1 
03e0: 46 52 4f 4d 20 73 20 4c 49 4d 49 54 20 33 30 0a  FROM s LIMIT 30.
03f0: 20 20 29 0a 20 20 49 4e 53 45 52 54 20 49 4e 54    ).  INSERT INT
0400: 4f 20 74 31 20 53 45 4c 45 43 54 20 72 61 6e 64  O t1 SELECT rand
0410: 6f 6d 62 6c 6f 62 28 34 30 30 29 2c 20 72 61 6e  omblob(400), ran
0420: 64 6f 6d 62 6c 6f 62 28 34 30 30 29 20 46 52 4f  domblob(400) FRO
0430: 4d 20 73 3b 0a 7d 20 7b 77 61 6c 7d 0a 66 61 75  M s;.} {wal}.fau
0440: 6c 74 73 69 6d 5f 73 61 76 65 5f 61 6e 64 5f 63  ltsim_save_and_c
0450: 6c 6f 73 65 0a 0a 64 6f 5f 66 61 75 6c 74 73 69  lose..do_faultsi
0460: 6d 5f 74 65 73 74 20 31 20 2d 70 72 65 70 20 7b  m_test 1 -prep {
0470: 0a 20 20 63 61 74 63 68 20 7b 20 64 62 20 63 6c  .  catch { db cl
0480: 6f 73 65 20 7d 0a 20 20 66 61 75 6c 74 73 69 6d  ose }.  faultsim
0490: 5f 72 65 73 74 6f 72 65 0a 20 20 73 71 6c 69 74  _restore.  sqlit
04a0: 65 33 20 64 62 20 66 69 6c 65 3a 74 65 73 74 2e  e3 db file:test.
04b0: 64 62 3f 70 73 6f 77 3d 30 20 2d 75 72 69 20 31  db?psow=0 -uri 1
04c0: 0a 20 20 66 69 6c 65 5f 63 6f 6e 74 72 6f 6c 5f  .  file_control_
04d0: 70 6f 77 65 72 73 61 66 65 5f 6f 76 65 72 77 72  powersafe_overwr
04e0: 69 74 65 20 64 62 20 30 0a 20 20 65 78 65 63 73  ite db 0.  execs
04f0: 71 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d 41 20  ql {.    PRAGMA 
0500: 77 61 6c 5f 63 68 65 63 6b 70 6f 69 6e 74 3b 0a  wal_checkpoint;.
0510: 20 20 20 20 50 52 41 47 4d 41 20 6a 6f 75 72 6e      PRAGMA journ
0520: 61 6c 5f 73 69 7a 65 5f 6c 69 6d 69 74 20 3d 20  al_size_limit = 
0530: 31 30 30 30 30 3b 0a 20 20 20 20 50 52 41 47 4d  10000;.    PRAGM
0540: 41 20 73 79 6e 63 68 72 6f 6e 6f 75 73 20 3d 20  A synchronous = 
0550: 66 75 6c 6c 3b 0a 20 20 7d 0a 7d 20 2d 62 6f 64  full;.  }.} -bod
0560: 79 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  y {.  execsql { 
0570: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56  INSERT INTO t1 V
0580: 41 4c 55 45 53 28 31 2c 31 29 20 7d 0a 7d 20 2d  ALUES(1,1) }.} -
0590: 74 65 73 74 20 7b 0a 20 20 66 61 75 6c 74 73 69  test {.  faultsi
05a0: 6d 5f 74 65 73 74 5f 72 65 73 75 6c 74 20 7b 30  m_test_result {0
05b0: 20 7b 7d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d   {}}.}..#-------
05c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0600: 2d 2d 0a 23 20 49 6e 6a 65 63 74 20 66 61 75 6c  --.# Inject faul
0610: 74 73 20 77 68 69 6c 65 20 72 65 77 72 69 74 69  ts while rewriti
0620: 6e 67 20 63 68 65 63 6b 73 75 6d 73 2e 0a 23 0a  ng checksums..#.
0630: 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63  reset_db.do_exec
0640: 73 71 6c 5f 74 65 73 74 20 32 2e 30 20 7b 0a 20  sql_test 2.0 {. 
0650: 20 50 52 41 47 4d 41 20 61 75 74 6f 5f 76 61 63   PRAGMA auto_vac
0660: 75 75 6d 20 3d 20 30 3b 0a 20 20 43 52 45 41 54  uum = 0;.  CREAT
0670: 45 20 54 41 42 4c 45 20 74 31 28 61 2c 20 62 29  E TABLE t1(a, b)
0680: 3b 0a 20 20 50 52 41 47 4d 41 20 6a 6f 75 72 6e  ;.  PRAGMA journ
0690: 61 6c 5f 6d 6f 64 65 20 3d 20 77 61 6c 3b 0a 20  al_mode = wal;. 
06a0: 20 57 49 54 48 20 73 28 69 29 20 41 53 20 28 0a   WITH s(i) AS (.
06b0: 20 20 20 20 53 45 4c 45 43 54 20 31 20 55 4e 49      SELECT 1 UNI
06c0: 4f 4e 20 41 4c 4c 20 53 45 4c 45 43 54 20 69 2b  ON ALL SELECT i+
06d0: 31 20 46 52 4f 4d 20 73 20 4c 49 4d 49 54 20 33  1 FROM s LIMIT 3
06e0: 30 0a 20 20 29 0a 20 20 49 4e 53 45 52 54 20 49  0.  ).  INSERT I
06f0: 4e 54 4f 20 74 31 20 53 45 4c 45 43 54 20 72 61  NTO t1 SELECT ra
0700: 6e 64 6f 6d 62 6c 6f 62 28 34 30 30 29 2c 20 72  ndomblob(400), r
0710: 61 6e 64 6f 6d 62 6c 6f 62 28 34 30 30 29 20 46  andomblob(400) F
0720: 52 4f 4d 20 73 3b 0a 7d 20 7b 77 61 6c 7d 0a 66  ROM s;.} {wal}.f
0730: 61 75 6c 74 73 69 6d 5f 73 61 76 65 5f 61 6e 64  aultsim_save_and
0740: 5f 63 6c 6f 73 65 0a 0a 64 6f 5f 66 61 75 6c 74  _close..do_fault
0750: 73 69 6d 5f 74 65 73 74 20 32 20 2d 70 72 65 70  sim_test 2 -prep
0760: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 72 65   {.  faultsim_re
0770: 73 74 6f 72 65 5f 61 6e 64 5f 72 65 6f 70 65 6e  store_and_reopen
0780: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
0790: 20 50 52 41 47 4d 41 20 63 61 63 68 65 5f 73 69   PRAGMA cache_si
07a0: 7a 65 20 3d 20 32 3b 0a 20 20 20 20 42 45 47 49  ze = 2;.    BEGI
07b0: 4e 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74 31  N;.    UPDATE t1
07c0: 20 53 45 54 20 61 3d 72 61 6e 64 6f 6d 62 6c 6f   SET a=randomblo
07d0: 62 28 34 30 30 29 3b 0a 20 20 20 20 55 50 44 41  b(400);.    UPDA
07e0: 54 45 20 74 31 20 53 45 54 20 62 3d 72 61 6e 64  TE t1 SET b=rand
07f0: 6f 6d 62 6c 6f 62 28 34 30 30 29 3b 0a 20 20 20  omblob(400);.   
0800: 20 55 50 44 41 54 45 20 74 31 20 53 45 54 20 61   UPDATE t1 SET a
0810: 3d 72 61 6e 64 6f 6d 62 6c 6f 62 28 34 30 30 29  =randomblob(400)
0820: 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74 31 20  ;.    UPDATE t1 
0830: 53 45 54 20 62 3d 72 61 6e 64 6f 6d 62 6c 6f 62  SET b=randomblob
0840: 28 34 30 30 29 3b 0a 20 20 20 20 55 50 44 41 54  (400);.    UPDAT
0850: 45 20 74 31 20 53 45 54 20 61 3d 72 61 6e 64 6f  E t1 SET a=rando
0860: 6d 62 6c 6f 62 28 34 30 30 29 3b 0a 20 20 20 20  mblob(400);.    
0870: 55 50 44 41 54 45 20 74 31 20 53 45 54 20 62 3d  UPDATE t1 SET b=
0880: 72 61 6e 64 6f 6d 62 6c 6f 62 28 34 30 30 29 3b  randomblob(400);
0890: 0a 20 20 20 20 55 50 44 41 54 45 20 74 31 20 53  .    UPDATE t1 S
08a0: 45 54 20 61 3d 72 61 6e 64 6f 6d 62 6c 6f 62 28  ET a=randomblob(
08b0: 34 30 30 29 3b 0a 20 20 20 20 55 50 44 41 54 45  400);.    UPDATE
08c0: 20 74 31 20 53 45 54 20 62 3d 72 61 6e 64 6f 6d   t1 SET b=random
08d0: 62 6c 6f 62 28 34 30 30 29 3b 0a 20 20 7d 0a 7d  blob(400);.  }.}
08e0: 20 2d 62 6f 64 79 20 7b 0a 20 20 65 78 65 63 73   -body {.  execs
08f0: 71 6c 20 43 4f 4d 4d 49 54 0a 7d 20 2d 74 65 73  ql COMMIT.} -tes
0900: 74 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74  t {.  faultsim_t
0910: 65 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 7d  est_result {0 {}
0920: 7d 0a 7d 0a 0a 0a 0a 66 69 6e 69 73 68 5f 74 65  }.}....finish_te
0930: 73 74 0a                                         st.