os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/crash6.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2001 September 15
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file tests that rollback journals for databases that use a 
sl@0
    12
# page-size other than the default page-size can be rolled back Ok.
sl@0
    13
#
sl@0
    14
# $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $
sl@0
    15
sl@0
    16
set testdir [file dirname $argv0]
sl@0
    17
source $testdir/tester.tcl
sl@0
    18
sl@0
    19
ifcapable !crashtest {
sl@0
    20
  finish_test
sl@0
    21
  return
sl@0
    22
}
sl@0
    23
sl@0
    24
for {set ii 0} {$ii < 10} {incr ii} {
sl@0
    25
  catch {db close}
sl@0
    26
  file delete -force test.db test.db-journal
sl@0
    27
  crashsql -delay 2 -file test.db {
sl@0
    28
    PRAGMA auto_vacuum=OFF;
sl@0
    29
    PRAGMA page_size=4096;
sl@0
    30
    BEGIN;
sl@0
    31
    CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
sl@0
    32
    COMMIT;
sl@0
    33
    BEGIN;
sl@0
    34
    CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
sl@0
    35
    COMMIT;
sl@0
    36
  }
sl@0
    37
  sqlite3 db test.db
sl@0
    38
  integrity_check crash6-1.$ii
sl@0
    39
}
sl@0
    40
sl@0
    41
for {set ii 0} {$ii < 10} {incr ii} {
sl@0
    42
  catch {db close}
sl@0
    43
  file delete -force test.db test.db-journal
sl@0
    44
  sqlite3 db test.db
sl@0
    45
  execsql {
sl@0
    46
    PRAGMA auto_vacuum=OFF;
sl@0
    47
    PRAGMA page_size=2048;
sl@0
    48
    BEGIN;
sl@0
    49
    CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
sl@0
    50
    COMMIT;
sl@0
    51
  }
sl@0
    52
  db close
sl@0
    53
  crashsql -delay 1 -file test.db {
sl@0
    54
    INSERT INTO abc VALUES(5, 6, 7);
sl@0
    55
  }
sl@0
    56
  sqlite3 db test.db
sl@0
    57
  integrity_check crash6-2.$ii
sl@0
    58
}
sl@0
    59
sl@0
    60
proc signature {} {
sl@0
    61
  return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
sl@0
    62
}
sl@0
    63
sl@0
    64
# Test case for crashing during database sync with page-size values 
sl@0
    65
# from 1024 to 8192.
sl@0
    66
#
sl@0
    67
for {set ii 0} {$ii < 30} {incr ii} {
sl@0
    68
  db close
sl@0
    69
  file delete -force test.db
sl@0
    70
  sqlite3 db test.db
sl@0
    71
sl@0
    72
  set pagesize [expr 1024 << ($ii % 4)]
sl@0
    73
  if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} {
sl@0
    74
    set pagesize $::SQLITE_MAX_PAGE_SIZE
sl@0
    75
  }
sl@0
    76
  do_test crash6-3.$ii.0 {
sl@0
    77
    execsql "pragma page_size = $pagesize"
sl@0
    78
    execsql "pragma page_size"
sl@0
    79
  } $pagesize
sl@0
    80
sl@0
    81
  do_test crash6-3.$ii.1 {
sl@0
    82
  
sl@0
    83
    execsql BEGIN
sl@0
    84
    execsql {CREATE TABLE abc(a, b, c)}
sl@0
    85
    for {set n 0} {$n < 1000} {incr n} {
sl@0
    86
      execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
sl@0
    87
    }
sl@0
    88
    execsql {
sl@0
    89
      INSERT INTO abc SELECT * FROM abc;
sl@0
    90
      INSERT INTO abc SELECT * FROM abc;
sl@0
    91
      INSERT INTO abc SELECT * FROM abc;
sl@0
    92
      INSERT INTO abc SELECT * FROM abc;
sl@0
    93
      INSERT INTO abc SELECT * FROM abc;
sl@0
    94
    }
sl@0
    95
    execsql COMMIT
sl@0
    96
    expr ([file size test.db] / 1024) > 450
sl@0
    97
  } {1}
sl@0
    98
sl@0
    99
  set sig [signature]
sl@0
   100
  db close
sl@0
   101
sl@0
   102
  do_test crash6-3.$ii.2 {
sl@0
   103
     crashsql -file test.db "
sl@0
   104
       BEGIN;
sl@0
   105
       SELECT random() FROM abc LIMIT $ii;
sl@0
   106
       INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
sl@0
   107
       DELETE FROM abc WHERE random()%2!=0;
sl@0
   108
       COMMIT;
sl@0
   109
     "
sl@0
   110
  } {1 {child process exited abnormally}}
sl@0
   111
sl@0
   112
  do_test crash6-3.$ii.3 {
sl@0
   113
    sqlite3 db test.db
sl@0
   114
    signature
sl@0
   115
  } $sig
sl@0
   116
} 
sl@0
   117
sl@0
   118
finish_test