/ Check-in [6a64109d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a couple of coverage tests. (CVS 6149)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6a64109d1f9b63ac8b29ea2c77da02506387b4a1
User & Date: danielk1977 2009-01-09 10:49:14
Context
2009-01-09
14:11
Simplifications to btree.c to improve test coverage. (CVS 6150) check-in: ac84f106 user: drh tags: trunk
10:49
Add a couple of coverage tests. (CVS 6149) check-in: 6a64109d user: danielk1977 tags: trunk
02:49
More coverage improvements. (CVS 6148) check-in: 6e171c0a user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/crash8.test.

8
9
10
11
12
13
14



15
16
17
18
19
20
21
22
...
104
105
106
107
108
109
110
111





112





















































































































































































#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This test verifies a couple of specific potential data corruption 
# scenarios involving crashes or power failures.
#



# $Id: crash8.test,v 1.1 2009/01/08 17:50:46 danielk1977 Exp $


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

ifcapable !crashtest {
  finish_test
................................................................................
  }
} {1 {child process exited abnormally}}

do_test crash8-2.3 {
  execsql {PRAGMA integrity_check}
} {ok}

finish_test


































































































































































































>
>
>
|







 







|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This test verifies a couple of specific potential data corruption 
# scenarios involving crashes or power failures.
#
# Later: Also, some other specific scenarios required for coverage
# testing that do not lead to corruption.
#
# $Id: crash8.test,v 1.2 2009/01/09 10:49:14 danielk1977 Exp $


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

ifcapable !crashtest {
  finish_test
................................................................................
  }
} {1 {child process exited abnormally}}

do_test crash8-2.3 {
  execsql {PRAGMA integrity_check}
} {ok}

proc read_file {zFile} {
  set fd [open $zFile]
  fconfigure $fd -translation binary 
  set zData [read $fd]
  close $fd
  return $zData
}

# The following tests check that SQLite will not roll back a hot-journal
# file if the sector-size field in the first journal file header is
# suspect. Definition of suspect:
# 
#    a) Not a power of 2, or
#    b) Greater than 0x1000000 (16MB).
#
do_test crash8-3.1 {
  list [file exists test.db-joural] [file exists test.db]
} {0 1}
do_test crash8-3.2 {
  execsql {
    PRAGMA synchronous = off;
    BEGIN;
    DELETE FROM t1;
    SELECT count(*) FROM t1;
  }
} {0}
do_test crash8-3.3 {
  set zJournal [read_file test.db-journal]
  execsql { 
    COMMIT;
    SELECT count(*) FROM t1;
  }
} {0}
do_test crash8-3.4 {
  binary scan [string range $zJournal 20 23] I nSector
  set nSector
} {512}
do_test crash8-3.5 {
  set zJournal2 [
    string replace $zJournal 20 23 [binary format I 511]
  ]
  set fd [open test.db-journal w]
  fconfigure $fd -translation binary 
  puts -nonewline $fd $zJournal2
  close $fd
  
  execsql { 
    SELECT count(*) FROM t1;
    PRAGMA integrity_check
  }
} {0 ok}
do_test crash8-3.6 {
  set zJournal2 [
    string replace $zJournal 20 23 [binary format I [expr 0x2000000]]
  ]
  set fd [open test.db-journal w]
  fconfigure $fd -translation binary 
  puts -nonewline $fd $zJournal2
  close $fd
  execsql { 
    SELECT count(*) FROM t1;
    PRAGMA integrity_check
  }
} {0 ok}
do_test crash8-3.7 {
  set fd [open test.db-journal w]
  fconfigure $fd -translation binary 
  puts -nonewline $fd $zJournal
  close $fd
  execsql { 
    SELECT count(*) FROM t1;
    PRAGMA integrity_check
  }
} {6 ok}


# If a connection running in persistent-journal mode is part of a 
# multi-file transaction, it must ensure that the master-journal name
# appended to the journal file contents during the commit is located
# at the end of the physical journal file. If there was already a
# large journal file allocated at the start of the transaction, this
# may mean truncating the file so that the master journal name really
# is at the physical end of the file.
#
# This block of tests test that SQLite correctly truncates such
# journal files, and that the results behave correctly if a hot-journal
# rollback occurs.
#
ifcapable pragma {
  reset_db
  file delete -force test2.db

  do_test crash8-4.1 {
    execsql {
      PRAGMA journal_mode = persist;
      CREATE TABLE ab(a, b);
      INSERT INTO ab VALUES(0, 'abc');
      INSERT INTO ab VALUES(1, NULL);
      INSERT INTO ab VALUES(2, NULL);
      INSERT INTO ab VALUES(3, NULL);
      INSERT INTO ab VALUES(4, NULL);
      INSERT INTO ab VALUES(5, NULL);
      INSERT INTO ab VALUES(6, NULL);
      UPDATE ab SET b = randstr(1000,1000);
      ATTACH 'test2.db' AS aux;
      CREATE TABLE aux.ab(a, b);
      INSERT INTO aux.ab SELECT * FROM main.ab;

      UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1;
      UPDATE ab SET b = randstr(1000,1000) WHERE a>=1;
    }
    list [file exists test.db-journal] [file exists test2.db-journal]
  } {1 1}

  do_test crash8-4.2 {
    execsql {
      BEGIN;
        UPDATE aux.ab SET b = 'def' WHERE a = 0;
        UPDATE main.ab SET b = 'def' WHERE a = 0;
      COMMIT;
    }
  } {}

  do_test crash8-4.3 {
    execsql {
      UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1;
      UPDATE ab SET b = randstr(1000,1000) WHERE a>=1;
    }
  } {}

  set contents_main [db eval {SELECT b FROM main.ab WHERE a = 1}]
  set contents_aux  [db eval {SELECT b FROM  aux.ab WHERE a = 1}]

  do_test crash8-4.4 {
    crashsql -file test2.db -delay 1 {
      ATTACH 'test2.db' AS aux;
      BEGIN;
        UPDATE aux.ab SET b = 'ghi' WHERE a = 0;
        UPDATE main.ab SET b = 'ghi' WHERE a = 0;
      COMMIT;
    }
  } {1 {child process exited abnormally}}

  do_test crash8-4.5 {
    list [file exists test.db-journal] [file exists test2.db-journal]
  } {1 1}

  do_test crash8-4.6 {
    execsql {
      SELECT b FROM main.ab WHERE a = 0;
      SELECT b FROM aux.ab WHERE a = 0;
    }
  } {def def}

  do_test crash8-4.7 {
    crashsql -file test2.db -delay 1 {
      ATTACH 'test2.db' AS aux;
      BEGIN;
        UPDATE aux.ab SET b = 'jkl' WHERE a = 0;
        UPDATE main.ab SET b = 'jkl' WHERE a = 0;
      COMMIT;
    }
  } {1 {child process exited abnormally}}

  do_test crash8-4.8 {
    set fd [open test.db-journal]
    fconfigure $fd -translation binary
    seek $fd -16 end
    binary scan [read $fd 4] I len

    seek $fd [expr {-1 * ($len + 16)}] end
    set zMasterJournal [read $fd $len]
    close $fd

    file exists $zMasterJournal
  } {1}

  do_test crash8-4.9 {
    execsql { SELECT b FROM aux.ab WHERE a = 0 }
  } {def}

  do_test crash8-4.10 {
    file delete $zMasterJournal
    execsql { SELECT b FROM main.ab WHERE a = 0 }
  } {jkl}
}

finish_test

Changes to test/jrnlmode.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
416
417
418
419
420
421
422
423








































424

#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The focus
# of these tests is the journal mode pragma.
#
# $Id: jrnlmode.test,v 1.9 2008/12/22 11:43:36 danielk1977 Exp $

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

ifcapable {!pager_pragmas} {
  finish_test
  return
................................................................................
  } {1}
  do_test jrnlmode-5.19 {
    execsql COMMIT
    set sz [file size test.db-journal]
    expr {$sz>=$journalsize}
  } {1}
}









































finish_test








|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The focus
# of these tests is the journal mode pragma.
#
# $Id: jrnlmode.test,v 1.10 2009/01/09 10:49:14 danielk1977 Exp $

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

ifcapable {!pager_pragmas} {
  finish_test
  return
................................................................................
  } {1}
  do_test jrnlmode-5.19 {
    execsql COMMIT
    set sz [file size test.db-journal]
    expr {$sz>=$journalsize}
  } {1}
}

ifcapable pragma {
  do_test jrnlmode-6.1 {
    execsql {
      PRAGMA journal_mode = truncate;
      CREATE TABLE t4(a, b);
      BEGIN;
        INSERT INTO t4 VALUES(1, 2);
        PRAGMA journal_mode = memory;
    }
  } {truncate memory}
  do_test jrnlmode-6.2 {
    file exists test.db-journal
  } {1}
  do_test jrnlmode-6.3 {
    execsql {
      COMMIT;
      SELECT * FROM t4;
    }
  } {1 2}
  do_test jrnlmode-6.4 {
    file exists test.db-journal
  } {0}
  do_test jrnlmode-6.5 {
    execsql {
      BEGIN;
        INSERT INTO t4 VALUES(3, 4);
    }
    file exists test.db-journal
  } {0}
  do_test jrnlmode-6.7 {
    execsql {
      COMMIT;
      SELECT * FROM t4;
    }
  } {1 2 3 4}
  do_test jrnlmode-6.8 {
    file exists test.db-journal
  } {0}
}

finish_test

Changes to test/tester.tcl.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
133
134
135
136
137
138
139


140
141
142
143
144
145
146
147


148
149
150
151
152
153
154
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.135 2008/11/21 00:10:35 aswift Exp $

#
# What for user input before continuing.  This gives an opportunity
# to connect profiling tools to the process.
#
for {set i 0} {$i<[llength $argv]} {incr i} {
  if {[regexp {^-+pause$} [lindex $argv $i] all value]} {
................................................................................
  install_malloc_faultsim 1 
  sqlite3_initialize
  if {[info exists tester_do_binarylog]} {
    sqlite3_instvfs binarylog -default binarylog ostrace.bin
    sqlite3_instvfs marker binarylog "$argv0 $argv"
  }
}


catch {db close}
file delete -force test.db
file delete -force test.db-journal
sqlite3 db ./test.db
set ::DB [sqlite3_connection_pointer db]
if {[info exists ::SETUP_SQL]} {
  db eval $::SETUP_SQL
}



# Abort early if this script has been run before.
#
if {[info exists nTest]} return

# Set the test counters to zero
#







|







 







>
>
|
|
|
|
|
|
|
|
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.136 2009/01/09 10:49:14 danielk1977 Exp $

#
# What for user input before continuing.  This gives an opportunity
# to connect profiling tools to the process.
#
for {set i 0} {$i<[llength $argv]} {incr i} {
  if {[regexp {^-+pause$} [lindex $argv $i] all value]} {
................................................................................
  install_malloc_faultsim 1 
  sqlite3_initialize
  if {[info exists tester_do_binarylog]} {
    sqlite3_instvfs binarylog -default binarylog ostrace.bin
    sqlite3_instvfs marker binarylog "$argv0 $argv"
  }
}

proc reset_db {} {
  catch {db close}
  file delete -force test.db
  file delete -force test.db-journal
  sqlite3 db ./test.db
  set ::DB [sqlite3_connection_pointer db]
  if {[info exists ::SETUP_SQL]} {
    db eval $::SETUP_SQL
  }
}
reset_db

# Abort early if this script has been run before.
#
if {[info exists nTest]} return

# Set the test counters to zero
#