/ Check-in [cc9ddae6]
Login

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

Overview
Comment:Add test cases to pager1.test and pager2.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cc9ddae6d72b214f52b8949e644b91f4ab340a28
User & Date: dan 2010-06-21 18:29:41
Context
2010-06-21
20:19
Fix comment inside the pager_unlock() routine. Always close the master journal file before trying to delete it. check-in: f820b815 user: drh tags: trunk
18:29
Add test cases to pager1.test and pager2.test. check-in: cc9ddae6 user: dan tags: trunk
12:47
Merge the experimental UNDELETABLE_WHEN_OPEN optimization into the trunk. check-in: ee0acef1 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/test_vfs.c.

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
903
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918
919
920
921
922


923
924
925
926
927
928
929
930
#define TESTVFS_DELETE_MASK     0x00000400
#define TESTVFS_CLOSE_MASK      0x00000800
#define TESTVFS_WRITE_MASK      0x00001000
#define TESTVFS_TRUNCATE_MASK   0x00002000
#define TESTVFS_ALL_MASK        0x00003FFF


#define TESTVFS_MAX_PAGES 256

/*
** A shared-memory buffer. There is one of these objects for each shared
** memory region opened by clients. If two clients open the same file,
** there are two TestvfsFile structures but only one TestvfsBuffer structure.
*/
struct TestvfsBuffer {
................................................................................
      if( !pBuffer ){
        Tcl_AppendResult(interp, "no such file: ", Tcl_GetString(objv[2]), 0);
        return TCL_ERROR;
      }
      if( objc==4 ){
        int n;
        u8 *a = Tcl_GetByteArrayFromObj(objv[3], &n);
        assert( pBuffer->pgsz==0 || pBuffer->pgsz==32768 );

        for(i=0; i*32768<n; i++){
          int nByte = 32768;
          tvfsAllocPage(pBuffer, i, 32768);
          if( n-i*32768<32768 ){
            nByte = n;
          }
          memcpy(pBuffer->aPage[i], &a[i*32768], nByte);
        }
      }

      pObj = Tcl_NewObj();
      for(i=0; pBuffer->aPage[i]; i++){


        Tcl_AppendObjToObj(pObj, Tcl_NewByteArrayObj(pBuffer->aPage[i], 32768));
      }
      Tcl_SetObjResult(interp, pObj);
      break;
    }

    case CMD_FILTER: {
      static struct VfsMethod {







|







 







|
>
|
|
|
|


|





>
>
|







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
#define TESTVFS_DELETE_MASK     0x00000400
#define TESTVFS_CLOSE_MASK      0x00000800
#define TESTVFS_WRITE_MASK      0x00001000
#define TESTVFS_TRUNCATE_MASK   0x00002000
#define TESTVFS_ALL_MASK        0x00003FFF


#define TESTVFS_MAX_PAGES 1024

/*
** A shared-memory buffer. There is one of these objects for each shared
** memory region opened by clients. If two clients open the same file,
** there are two TestvfsFile structures but only one TestvfsBuffer structure.
*/
struct TestvfsBuffer {
................................................................................
      if( !pBuffer ){
        Tcl_AppendResult(interp, "no such file: ", Tcl_GetString(objv[2]), 0);
        return TCL_ERROR;
      }
      if( objc==4 ){
        int n;
        u8 *a = Tcl_GetByteArrayFromObj(objv[3], &n);
        int pgsz = pBuffer->pgsz;
        if( pgsz==0 ) pgsz = 32768;
        for(i=0; i*pgsz<n; i++){
          int nByte = pgsz;
          tvfsAllocPage(pBuffer, i, pgsz);
          if( n-i*pgsz<pgsz ){
            nByte = n;
          }
          memcpy(pBuffer->aPage[i], &a[i*pgsz], nByte);
        }
      }

      pObj = Tcl_NewObj();
      for(i=0; pBuffer->aPage[i]; i++){
        int pgsz = pBuffer->pgsz;
        if( pgsz==0 ) pgsz = 32768;
        Tcl_AppendObjToObj(pObj, Tcl_NewByteArrayObj(pBuffer->aPage[i], pgsz));
      }
      Tcl_SetObjResult(interp, pObj);
      break;
    }

    case CMD_FILTER: {
      static struct VfsMethod {

Changes to test/pager1.test.

27
28
29
30
31
32
33


34
35
36
37
38
39
40
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
496
497
498
499
500
501
502





































































503
504
505
506
507
508
509
...
720
721
722
723
724
725
726




727
728
729
730
731
732
733
734
735
736
737
738

739
740
741
742
743
744








745
746
#
# pager1-5.*: Cases related to multi-file commits.
#
# pager1-6.*: Cases related to "PRAGMA max_page_count"
#
# pager1-7.*: Cases specific to "PRAGMA journal_mode=TRUNCATE"
#



set a_string_counter 1
proc a_string {n} {
  global a_string_counter
  incr a_string_counter
  string range [string repeat "${a_string_counter}." $n] 1 $n
}
................................................................................
  do_test pager1-$tn.27 { sql2 { SELECT * FROM t1 } } {21 one 22 two 23 three}
  do_test pager1-$tn.28 { sql3 { SELECT * FROM t1 } } {21 one 22 two 23 three}
}

#-------------------------------------------------------------------------
# Savepoint related test cases.
# 
do_test pager1-3.1 {
  faultsim_delete_and_reopen
  execsql {
    CREATE TABLE t1(a PRIMARY KEY, b);
    CREATE TABLE counter(
      i CHECK (i<5), 
      u CHECK (u<10)
    );
................................................................................
    CREATE TRIGGER tr2 AFTER UPDATE ON t1 BEGIN
      UPDATE counter SET u = u+1;
    END;
  }
  execsql { SELECT * FROM counter }
} {0 0}

do_execsql_test pager1-3.2 {
  BEGIN;
    INSERT INTO t1 VALUES(1, randomblob(1500));
    INSERT INTO t1 VALUES(2, randomblob(1500));
    INSERT INTO t1 VALUES(3, randomblob(1500));
    SELECT * FROM counter;
} {3 0}
do_catchsql_test pager1-3.3 {
    INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1
} {1 {constraint failed}}
do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0}
do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3}
do_execsql_test pager1-3.6 { COMMIT } {}

#-------------------------------------------------------------------------
................................................................................
    } {won too free double-you why zed}
  }

  cd $pwd
}
db close
tv delete






































































#-------------------------------------------------------------------------
# The following tests deal with multi-file commits.
#
# pager1-5.1.*: The case where a multi-file cannot be committed because
#               another connection is holding a SHARED lock on one of the
#               files. After the SHARED lock is removed, the COMMIT succeeds.
................................................................................
}] {
  do_execsql_test pager1-7.1.$tn.1 $sql $res
  catch { set J -1 ; set J [file size test.db-journal] }
  catch { set W -1 ; set W [file size test.db-wal] }
  do_test pager1-7.1.$tn.2 { list $J $W } [list $js $ws]
}





do_test pager1-8.1 {
  faultsim_delete_and_reopen
  db close
  sqlite3 db :memory:
  execsql {
    CREATE TABLE x1(x);
    INSERT INTO x1 VALUES('Charles');
    INSERT INTO x1 VALUES('James');
    INSERT INTO x1 VALUES('Mary');
    SELECT * FROM x1;
  }
} {Charles James Mary}

do_test pager1-8.2 {
  db close
  sqlite3 db :memory:
  catchsql { SELECT * FROM x1 }
} {1 {no such table: x1}}









finish_test








>
>







 







|







 







|






|







 







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







 







>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
>
|
<
|
|
|

>
>
>
>
>
>
>
>


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
...
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
#
# pager1-5.*: Cases related to multi-file commits.
#
# pager1-6.*: Cases related to "PRAGMA max_page_count"
#
# pager1-7.*: Cases specific to "PRAGMA journal_mode=TRUNCATE"
#
# pager1-8.*: Cases using temporary and in-memory databases.
#

set a_string_counter 1
proc a_string {n} {
  global a_string_counter
  incr a_string_counter
  string range [string repeat "${a_string_counter}." $n] 1 $n
}
................................................................................
  do_test pager1-$tn.27 { sql2 { SELECT * FROM t1 } } {21 one 22 two 23 three}
  do_test pager1-$tn.28 { sql3 { SELECT * FROM t1 } } {21 one 22 two 23 three}
}

#-------------------------------------------------------------------------
# Savepoint related test cases.
# 
do_test pager1-3.1.1 {
  faultsim_delete_and_reopen
  execsql {
    CREATE TABLE t1(a PRIMARY KEY, b);
    CREATE TABLE counter(
      i CHECK (i<5), 
      u CHECK (u<10)
    );
................................................................................
    CREATE TRIGGER tr2 AFTER UPDATE ON t1 BEGIN
      UPDATE counter SET u = u+1;
    END;
  }
  execsql { SELECT * FROM counter }
} {0 0}

do_execsql_test pager1-3.1.2 {
  BEGIN;
    INSERT INTO t1 VALUES(1, randomblob(1500));
    INSERT INTO t1 VALUES(2, randomblob(1500));
    INSERT INTO t1 VALUES(3, randomblob(1500));
    SELECT * FROM counter;
} {3 0}
do_catchsql_test pager1-3.1.3 {
    INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1
} {1 {constraint failed}}
do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0}
do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3}
do_execsql_test pager1-3.6 { COMMIT } {}

#-------------------------------------------------------------------------
................................................................................
    } {won too free double-you why zed}
  }

  cd $pwd
}
db close
tv delete
file delete -force $dirname


# Set up a VFS to make a copy of the file-system just before deleting a
# journal file to commit a transaction. The transaction modifies exactly
# two database pages (and page 1 - the change counter).
#
testvfs tv -default 1
tv sectorsize 512
tv script copy_on_journal_delete
tv filter xDelete
set ::mj_filename_length 0
proc copy_on_journal_delete {method filename args} {
  if {[string match *journal $filename]} faultsim_save 
  return SQLITE_OK
}
faultsim_delete_and_reopen
do_execsql_test pager1.4.5.1 {
  PRAGMA page_size = 1024;
  CREATE TABLE t1(a, b);
  CREATE TABLE t2(a, b);
  INSERT INTO t1 VALUES('I', 'II');
  INSERT INTO t2 VALUES('III', 'IV');
  BEGIN;
    INSERT INTO t1 VALUES(1, 2);
    INSERT INTO t2 VALUES(3, 4);
  COMMIT;
} {}
tv filter {}

# Check the transaction was committed:
#
do_execsql_test pager1.4.5.2 {
  SELECT * FROM t1;
  SELECT * FROM t2;
} {I II 1 2 III IV 3 4}

# Now try three tests:
#
#  pager1-4.5.3: Restore the file-system. Check that the whole transaction 
#                is rolled back.
#
#  pager1-4.5.4: Restore the file-system. Corrupt the first record in the
#                journal. Check the transaction is not rolled back.
#
#  pager1-4.5.5: Restore the file-system. Corrupt the second record in the
#                journal. Check that the first record in the transaction is 
#                played back, but not the second.
#
faultsim_restore_and_reopen
do_execsql_test pager1.4.5.3 {
  SELECT * FROM t1;
  SELECT * FROM t2;
} {I II III IV}
faultsim_restore_and_reopen
hexio_write test.db-journal [expr 512+4+1024 - 202] 0123456789ABCDEF
do_execsql_test pager1.4.5.4 {
  SELECT * FROM t1;
  SELECT * FROM t2;
} {I II 1 2 III IV 3 4}
faultsim_restore_and_reopen
hexio_write test.db-journal [expr 512+4+1024+4+4+1024 - 202] 0123456789ABCDEF
do_execsql_test pager1.4.5.5 {
  SELECT * FROM t1;
  SELECT * FROM t2;
} {I II III IV 3 4}

db close
tv delete

#-------------------------------------------------------------------------
# The following tests deal with multi-file commits.
#
# pager1-5.1.*: The case where a multi-file cannot be committed because
#               another connection is holding a SHARED lock on one of the
#               files. After the SHARED lock is removed, the COMMIT succeeds.
................................................................................
}] {
  do_execsql_test pager1-7.1.$tn.1 $sql $res
  catch { set J -1 ; set J [file size test.db-journal] }
  catch { set W -1 ; set W [file size test.db-wal] }
  do_test pager1-7.1.$tn.2 { list $J $W } [list $js $ws]
}

foreach {tn filename} {
  1 :memory:
  2 ""
} {
  do_test pager1-8.$tn.1 {
    faultsim_delete_and_reopen
    db close
    sqlite3 db $filename
    execsql {
      CREATE TABLE x1(x);
      INSERT INTO x1 VALUES('Charles');
      INSERT INTO x1 VALUES('James');
      INSERT INTO x1 VALUES('Mary');
      SELECT * FROM x1;
    }
  } {Charles James Mary}

  do_test pager1-8.$tn.2 {

    sqlite3 db2 $filename
    catchsql { SELECT * FROM x1 } db2
  } {1 {no such table: x1}}

  do_execsql_test pager1-8.$tn.3 {
    BEGIN;
      INSERT INTO x1 VALUES('William');
      INSERT INTO x1 VALUES('Anne');
    ROLLBACK;
  } {}
}

finish_test

Changes to test/pager2.test.

33
34
35
36
37
38
39



40
41
42
43
44
45
46
...
108
109
110
111
112
113
114
115
116
117
  tv devchar safe_append
} {
  set s 4096
} {
  set s 4096
  set sql { PRAGMA journal_mode = WAL }
} {



  set s 8192
  set sql { PRAGMA synchronous = off }
}] {

  incr otn
  set sql ""
  tv devchar {}
................................................................................
        PRAGMA integrity_check;
      } [list $x ok]
    }
  }
}
db close
tv delete


finish_test







>
>
>







 








<

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
111
112
113
114
115
116
117
118

119
  tv devchar safe_append
} {
  set s 4096
} {
  set s 4096
  set sql { PRAGMA journal_mode = WAL }
} {
  set s 4096
  set sql { PRAGMA auto_vacuum = 1 }
} {
  set s 8192
  set sql { PRAGMA synchronous = off }
}] {

  incr otn
  set sql ""
  tv devchar {}
................................................................................
        PRAGMA integrity_check;
      } [list $x ok]
    }
  }
}
db close
tv delete


finish_test