summaryrefslogtreecommitdiffstats
path: root/test/crash7.test
blob: 482999cbfd9575921d5e6f5336f04e3143db101d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 2008 March 20
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# $Id: crash7.test,v 1.1 2008/04/03 14:36:26 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix crash7

ifcapable !crashtest {
  finish_test
  return
}

proc signature {} {
  return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
}

foreach f [list test.db test.db-journal] {
  for {set ii 1} {$ii < 64} {incr ii} {
    db close
    delete_file test.db
    sqlite3 db test.db
  
    set from_size [expr 1024 << ($ii&3)]
    set to_size   [expr 1024 << (($ii>>2)&3)]
  
    execsql "
      PRAGMA page_size = $from_size;
      BEGIN;
      CREATE TABLE abc(a PRIMARY KEY, b, c);
      INSERT INTO abc VALUES(randomblob(100), randomblob(200), randomblob(1000));
      INSERT INTO abc 
          SELECT randomblob(1000), randomblob(200), randomblob(100)
          FROM abc;
      INSERT INTO abc 
          SELECT randomblob(100), randomblob(200), randomblob(1000)
          FROM abc;
      INSERT INTO abc 
          SELECT randomblob(100), randomblob(200), randomblob(1000)
          FROM abc;
      INSERT INTO abc 
          SELECT randomblob(100), randomblob(200), randomblob(1000)
          FROM abc;
      INSERT INTO abc 
          SELECT randomblob(100), randomblob(200), randomblob(1000)
          FROM abc WHERE [expr $ii&16];
      INSERT INTO abc 
          SELECT randomblob(25), randomblob(45), randomblob(9456)
          FROM abc WHERE [expr $ii&32];
      INSERT INTO abc 
          SELECT randomblob(100), randomblob(200), randomblob(1000)
          FROM abc WHERE [expr $ii&8];
      INSERT INTO abc 
          SELECT randomblob(25), randomblob(45), randomblob(9456)
          FROM abc WHERE [expr $ii&4];
      COMMIT;
    "
  
    set sig [signature]
    db close
  
    do_test crash7-1.$ii.crash {
       crashsql -file $f "
         PRAGMA page_size = $to_size;
         VACUUM;
       "
    } {1 {child process exited abnormally}}
  
    sqlite3 db test.db
    integrity_check crash7-1.$ii.integrity
  } 
}

db close
forcedelete test.db
sqlite3 db test.db
do_execsql_test 2.0 {
  CREATE TABLE t1(a, b, UNIQUE(a, b));
  INSERT INTO t1 VALUES(randomblob(100), randomblob(100));
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM t1;
  DELETE FROM t1 WHERE rowid%2;
}
db_save_and_close

for {set i 0} {$i < 20} {incr i} {
  db_restore_and_reopen
  do_test 2.[expr $i+1].1 {
    crashsql -file test.db -seed $i {VACUUM}
  } {1 {child process exited abnormally}}
  do_execsql_test 2.[expr $i+1].2 { PRAGMA integrity_check } {ok}
}


finish_test