os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/crash2.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/crash2.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,133 @@
     1.4 +# 2001 September 15
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.
    1.15 +#
    1.16 +# The focus of this file is testing the ability of the database to
    1.17 +# uses its rollback journal to recover intact (no database corruption)
    1.18 +# from a power failure during the middle of a COMMIT. Even more
    1.19 +# specifically, the tests in this file verify this functionality
    1.20 +# for storage mediums with various sector sizes.
    1.21 +#
    1.22 +# $Id: crash2.test,v 1.6 2008/08/25 07:12:29 danielk1977 Exp $
    1.23 +
    1.24 +set testdir [file dirname $argv0]
    1.25 +source $testdir/tester.tcl
    1.26 +
    1.27 +ifcapable !crashtest {
    1.28 +  finish_test
    1.29 +  return
    1.30 +}
    1.31 +
    1.32 +db close
    1.33 +
    1.34 +# This test is designed to check that the crash-test infrastructure
    1.35 +# can create files that do not consist of an integer number of
    1.36 +# simulated disk blocks (i.e. 3KB file using 2KB disk blocks).
    1.37 +#
    1.38 +do_test crash2-1.1 {
    1.39 +  crashsql -delay 500 -file test.db -blocksize 2048 {
    1.40 +    PRAGMA auto_vacuum=OFF;
    1.41 +    PRAGMA page_size=1024;
    1.42 +    BEGIN;
    1.43 +    CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
    1.44 +    CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
    1.45 +    COMMIT;
    1.46 +  }
    1.47 +  file size test.db
    1.48 +} {3072}
    1.49 +
    1.50 +for {set ii 0} {$ii < 5} {incr ii} {
    1.51 +
    1.52 +  # Simple test using the database created above: Create a new
    1.53 +  # table so that page 1 and page 4 are modified. Using a
    1.54 +  # block-size of 2048 and page-size of 1024, this means
    1.55 +  # pages 2 and 3 must also be saved in the journal to avoid
    1.56 +  # risking corruption.
    1.57 +  #
    1.58 +  # The loop is so that this test can be run with a couple
    1.59 +  # of different seeds for the random number generator.
    1.60 +  #
    1.61 +  do_test crash2-1.2.$ii {
    1.62 +    crashsql -file test.db -blocksize 2048 [subst {
    1.63 +      [string repeat {SELECT random();} $ii]
    1.64 +      CREATE TABLE hij(h, i, j);
    1.65 +    }]
    1.66 +    sqlite3 db test.db
    1.67 +    db eval {PRAGMA integrity_check}
    1.68 +  } {ok}
    1.69 +}
    1.70 +
    1.71 +proc signature {} {
    1.72 +  return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
    1.73 +}
    1.74 +
    1.75 +# Test case for crashing during journal sync with simulated
    1.76 +# sector-size values from 1024 to 8192.
    1.77 +#
    1.78 +do_test crash2-2.0 {
    1.79 +  execsql BEGIN
    1.80 +  for {set n 0} {$n < 1000} {incr n} {
    1.81 +    execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
    1.82 +  }
    1.83 +  execsql {
    1.84 +    INSERT INTO abc SELECT * FROM abc;
    1.85 +    INSERT INTO abc SELECT * FROM abc;
    1.86 +    INSERT INTO abc SELECT * FROM abc;
    1.87 +    INSERT INTO abc SELECT * FROM abc;
    1.88 +    INSERT INTO abc SELECT * FROM abc;
    1.89 +  }
    1.90 +  execsql COMMIT
    1.91 +  expr ([file size test.db] / 1024) > 450
    1.92 +} {1}
    1.93 +for {set i 1} {$i < 30} {incr i} {
    1.94 +  set sig [signature]
    1.95 +  set sector [expr 1024 * 1<<($i%4)]
    1.96 +  db close
    1.97 +  do_test crash2-2.$i.1 {
    1.98 +     crashsql -blocksize $sector -delay [expr $i%5 + 1] -file test.db-journal "
    1.99 +       PRAGMA temp_store = memory;
   1.100 +       BEGIN;
   1.101 +       SELECT random() FROM abc LIMIT $i;
   1.102 +       INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
   1.103 +       DELETE FROM abc WHERE random()%2!=0;
   1.104 +       COMMIT;
   1.105 +     "
   1.106 +  } {1 {child process exited abnormally}}
   1.107 +  do_test crash2-2.$i.2 {
   1.108 +    sqlite3 db test.db
   1.109 +    signature
   1.110 +  } $sig
   1.111 +} 
   1.112 +
   1.113 +
   1.114 +# Test case for crashing during database sync with simulated
   1.115 +# sector-size values from 1024 to 8192.
   1.116 +#
   1.117 +for {set i 1} {$i < 10} {incr i} {
   1.118 +  set sig [signature]
   1.119 +  set sector [expr 1024 * 1<<($i%4)]
   1.120 +  db close
   1.121 +  do_test crash2-3.$i.1 {
   1.122 +     crashsql -blocksize $sector -file test.db "
   1.123 +       BEGIN;
   1.124 +       SELECT random() FROM abc LIMIT $i;
   1.125 +       INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
   1.126 +       DELETE FROM abc WHERE random()%2!=0;
   1.127 +       COMMIT;
   1.128 +     "
   1.129 +  } {1 {child process exited abnormally}}
   1.130 +  do_test crash2-3.$i.2 {
   1.131 +    sqlite3 db test.db
   1.132 +    signature
   1.133 +  } $sig
   1.134 +} 
   1.135 +
   1.136 +finish_test