/ Check-in [0e3d5119]
Login

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

Overview
Comment:Modify various test cases so that they work if the file is extended in units of the system page-size.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | two-mappings
Files: files | file ages | folders
SHA1: 0e3d5119273fd8e3512b3aa4272a873847e7ca40
User & Date: dan 2013-03-27 19:53:55
Context
2013-03-29
11:24
Avoid assuming the page-size is 4096 bytes in os_unix.c. check-in: 3b7ec8d7 user: dan tags: two-mappings
2013-03-27
19:53
Modify various test cases so that they work if the file is extended in units of the system page-size. check-in: 0e3d5119 user: dan tags: two-mappings
2013-03-26
20:32
Change os_unix.c to use either one or two mappings internally. check-in: e7698cba user: dan tags: two-mappings
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   317    317   */
   318    318   #if SQLITE_THREADSAFE
   319    319   #define threadid pthread_self()
   320    320   #else
   321    321   #define threadid 0
   322    322   #endif
   323    323   
          324  +#if !defined(HAVE_MREMAP)
   324    325   #if defined(__linux__) && defined(_GNU_SOURCE)
   325         -# define HAVE_MREMAP
          326  +# define HAVE_MREMAP 1
          327  +#else
          328  +# define HAVE_MREMAP 0
          329  +#endif
   326    330   #endif
   327    331   
   328    332   /*
   329    333   ** Different Unix systems declare open() in different ways.  Same use
   330    334   ** open(const char*,int,mode_t).  Others use open(const char*,int,...).
   331    335   ** The difference is important when using a pointer to the function.
   332    336   **
................................................................................
   458    462   
   459    463     { "mmap",       (sqlite3_syscall_ptr)mmap,     0 },
   460    464   #define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[21].pCurrent)
   461    465   
   462    466     { "munmap",       (sqlite3_syscall_ptr)munmap,          0 },
   463    467   #define osMunmap ((void*(*)(void*,size_t))aSyscall[22].pCurrent)
   464    468   
   465         -#if defined(HAVE_MREMAP)
          469  +#if HAVE_MREMAP
   466    470     { "mremap",       (sqlite3_syscall_ptr)mremap,          0 },
   467    471   #else
   468    472     { "mremap",       (sqlite3_syscall_ptr)0,               0 },
   469    473   #endif
   470    474   #define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[23].pCurrent)
   471    475   
   472    476   }; /* End of the overrideable system calls */
................................................................................
  4598   4602       nMap = pFd->mmapLimit;
  4599   4603     }
  4600   4604   
  4601   4605     if( nMap!=(pFd->aMmap[0].mmapSize + pFd->aMmap[1].mmapSize) ){
  4602   4606       void *pNew = 0;
  4603   4607   
  4604   4608       /* If the request is for a mapping zero bytes in size, or there are 
  4605         -     ** currently already two mapping regions, or there is already a mapping
  4606         -     ** region that is not a multiple of the page-size in size, unmap
  4607         -     ** everything.  */
         4609  +    ** currently already two mapping regions, or there is already a mapping
         4610  +    ** region that is not a multiple of the page-size in size, unmap
         4611  +    ** everything.  */
  4608   4612       if( nMap==0 
  4609         -#ifndef HAVE_MREMAP
  4610         -        || (pFd->aMmap[0].pMapRegion && pFd->aMmap[1].pMapRegion) 
  4611         -        || (pFd->aMmap[0].mmapSize % pFd->szSyspage)
         4613  +#if !HAVE_MREMAP
         4614  +     || (pFd->aMmap[0].pMapRegion && pFd->aMmap[1].pMapRegion) 
         4615  +     || (pFd->aMmap[0].mmapSize % pFd->szSyspage)
  4612   4616   #endif
  4613         -      ){
         4617  +    ){
  4614   4618         unixUnmapfile(pFd);
  4615   4619       }
  4616   4620       assert( pFd->aMmap[1].pMapRegion==0 );
  4617   4621   
  4618   4622       if( nMap>0 ){
  4619   4623         int flags = PROT_READ;
  4620   4624         if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
................................................................................
  4625   4629           if( pNew==MAP_FAILED ){
  4626   4630             return SQLITE_IOERR_MMAP;
  4627   4631           }
  4628   4632           pFd->aMmap[0].pMapRegion = pNew;
  4629   4633           pFd->aMmap[0].mmapSize = nMap;
  4630   4634           pFd->aMmap[0].mmapOrigsize = nMap;
  4631   4635         }
  4632         -#ifdef HAVE_MREMAP
         4636  +#if HAVE_MREMAP
  4633   4637         /* If we have an mremap() call, resize the existing mapping. */
  4634   4638         else{
  4635   4639           unixMapping *pMap = &pFd->aMmap[0];
  4636   4640           pNew = osMremap(
  4637   4641               pMap->pMapRegion, pMap->mmapOrigsize, nMap, MREMAP_MAYMOVE
  4638   4642               );
  4639   4643           if( pNew==MAP_FAILED ){

Changes to src/wal.c.

  1204   1204       /* If more than one frame was recovered from the log file, report an
  1205   1205       ** event via sqlite3_log(). This is to help with identifying performance
  1206   1206       ** problems caused by applications routinely shutting down without
  1207   1207       ** checkpointing the log file.
  1208   1208       */
  1209   1209       if( pWal->hdr.nPage ){
  1210   1210         sqlite3_log(SQLITE_OK, "Recovered %d frames from WAL file %s",
  1211         -          pWal->hdr.nPage, pWal->zWalName
         1211  +          pWal->hdr.mxFrame, pWal->zWalName
  1212   1212         );
  1213   1213       }
  1214   1214     }
  1215   1215   
  1216   1216   recovery_error:
  1217   1217     WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok"));
  1218   1218     walUnlockExclusive(pWal, iLock, nLock);

Changes to test/autovacuum.test.

    28     28   proc make_str {char len} {
    29     29     set str [string repeat $char. $len]
    30     30     return [string range $str 0 [expr $len-1]]
    31     31   }
    32     32   
    33     33   # Return the number of pages in the file test.db by looking at the file system.
    34     34   proc file_pages {} {
    35         -  return [expr [file size test.db] / 1024]
           35  +  file_page_count test.db
    36     36   }
    37     37   
    38     38   #-------------------------------------------------------------------------
    39     39   # Test cases autovacuum-1.* work as follows:
    40     40   #
    41     41   # 1. A table with a single indexed field is created.
    42     42   # 2. Approximately 20 rows are inserted into the table. Each row is long 
................................................................................
   610    610       INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
   611    611       INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 4
   612    612       INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 8
   613    613       INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 16
   614    614       INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 32
   615    615     }
   616    616   
   617         -  expr {[file size test.db] / 1024}
          617  +  file_page_count test.db
   618    618   } {73}
   619    619   
   620    620   do_test autovacuum-7.2 {
   621    621     execsql {
   622    622       CREATE TABLE t2(a, b, PRIMARY KEY(a, b));
   623    623       INSERT INTO t2 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
   624    624       CREATE TABLE t3(a, b, PRIMARY KEY(a, b));
   625    625       INSERT INTO t3 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
   626    626       CREATE TABLE t4(a, b, PRIMARY KEY(a, b));
   627    627       INSERT INTO t4 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
   628    628       CREATE TABLE t5(a, b, PRIMARY KEY(a, b));
   629    629       INSERT INTO t5 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
   630    630     }
   631         -  expr {[file size test.db] / 1024}
          631  +  file_page_count test.db
   632    632   } {354}
   633    633   
   634    634   do_test autovacuum-7.3 {
   635    635     db close
   636    636     sqlite3 db test.db
   637    637     execsql {
   638    638       BEGIN;
   639    639       DELETE FROM t4;
   640    640       COMMIT;
   641    641       SELECT count(*) FROM t1;
   642    642     }
   643         -  expr {[file size test.db] / 1024}
          643  +  file_page_count test.db
   644    644   } {286}
   645    645   
   646    646   #------------------------------------------------------------------------
   647    647   # Additional tests.
   648    648   #
   649    649   # Try to determine the autovacuum setting for a database that is locked.
   650    650   #

Changes to test/backup.test.

   657    657       INSERT INTO t1 VALUES(3, randstr(1000,1000));
   658    658       INSERT INTO t1 VALUES(4, randstr(1000,1000));
   659    659       INSERT INTO t1 VALUES(5, randstr(1000,1000));
   660    660       COMMIT;
   661    661     }
   662    662   } {}
   663    663   do_test backup-6.2 {
   664         -  set nTotal [expr {[file size test.db]/1024}]
          664  +  set nTotal [file_page_count test.db]
   665    665     sqlite3_backup B db2 main db main
   666    666     B step 1
   667    667   } {SQLITE_OK}
   668    668   do_test backup-6.3 {
   669    669     B pagecount
   670    670   } $nTotal
   671    671   do_test backup-6.4 {

Changes to test/backup4.test.

    59     59   # Test that if the source is zero bytes, the destination database 
    60     60   # consists of a single page only.
    61     61   #
    62     62   do_execsql_test 2.1 {
    63     63     CREATE TABLE t1(a, b);
    64     64     CREATE INDEX i1 ON t1(a, b);
    65     65   }
    66         -do_test 2.2 { file size test.db } [expr $AUTOVACUUM ? 4096 : 3072]
           66  +do_test 2.2 { file_page_count test.db } [expr $AUTOVACUUM ? 4 : 3]
    67     67   
    68     68   do_test 2.3 {
    69     69     sqlite3 db1 test.db2
    70     70     db1 backup test.db
    71     71     db1 close
    72     72     file size test.db
    73     73   } {1024}

Changes to test/corrupt2.test.

   330    330       PRAGMA page_size = 1024;
   331    331       CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
   332    332       INSERT INTO t1 VALUES(1, randomblob(2500));
   333    333       INSERT INTO t1 VALUES(2, randomblob(2500));
   334    334       INSERT INTO t1 VALUES(3, randomblob(2500));
   335    335       DELETE FROM t1 WHERE a = 1;
   336    336     } -corrupt {
   337         -    set nPage [expr [file size corrupt.db] / 1024]
          337  +    set nPage [file_page_count corrupt.db]
   338    338       hexio_write corrupt.db [expr 1024 + ($nPage-3)*5] 010000000
   339    339     } -test {
   340    340       do_test corrupt2-6.3 {
   341    341         catchsql " $::presql pragma incremental_vacuum = 1 "
   342    342       } {1 {database disk image is malformed}}
   343    343     }
   344    344   

Changes to test/corrupt3.test.

    36     36     set bigstring [string repeat 0123456789 200]
    37     37     execsql {
    38     38       PRAGMA auto_vacuum=OFF;
    39     39       PRAGMA page_size=1024;
    40     40       CREATE TABLE t1(x);
    41     41       INSERT INTO t1 VALUES($bigstring);
    42     42     }
    43         -  file size test.db
    44         -} [expr {1024*3}]
           43  +  list [file_page_count test.db] [file_page_size test.db]
           44  +} {3 1024}
    45     45   
    46     46   # Verify that the file format is as we expect.  The page size
    47     47   # should be 1024 bytes.  The only record should have a single
    48     48   # overflow page.  The overflow page is page 3.  The pointer to
    49     49   # the overflow page is on the last 4 bytes of page 2.
    50     50   #
    51     51   do_test corrupt3-1.2 {

Changes to test/corrupt6.test.

    37     37     execsql {
    38     38       PRAGMA auto_vacuum=OFF;
    39     39       PRAGMA page_size=1024;
    40     40       CREATE TABLE t1(x);
    41     41       INSERT INTO t1(x) VALUES('varint32-01234567890123456789012345678901234567890123456789');
    42     42       INSERT INTO t1(x) VALUES('varint32-01234567890123456789012345678901234567890123456789');
    43     43     }
    44         -  file size test.db
    45         -} [expr {1024*2}]
           44  +  file_page_count test.db
           45  +} {2}
    46     46   
    47     47   # Verify that the file format is as we expect.  The page size
    48     48   # should be 1024 bytes.
    49     49   #
    50     50   do_test corrupt6-1.2 {
    51     51     hexio_get_int [hexio_read test.db 16 2]
    52     52   } 1024   ;# The page size is 1024

Changes to test/corrupt7.test.

    40     40       CREATE TABLE t1(x);
    41     41       INSERT INTO t1(x) VALUES(1);
    42     42       INSERT INTO t1(x) VALUES(2);
    43     43       INSERT INTO t1(x) SELECT x+2 FROM t1;
    44     44       INSERT INTO t1(x) SELECT x+4 FROM t1;
    45     45       INSERT INTO t1(x) SELECT x+8 FROM t1;
    46     46     }
    47         -  file size test.db
    48         -} [expr {1024*2}]
           47  +  file_page_count test.db
           48  +} {2}
    49     49   
    50     50   # Verify that the file format is as we expect.  The page size
    51     51   # should be 1024 bytes.
    52     52   #
    53     53   do_test corrupt7-1.2 {
    54     54     hexio_get_int [hexio_read test.db 16 2]
    55     55   } 1024   ;# The page size is 1024

Changes to test/corruptF.test.

    52     52   }
    53     53   
    54     54   do_test 1.1 { create_test_db } {}
    55     55   
    56     56   # Check the db is as we expect. 6 pages in total, with 3 and 4 on the free
    57     57   # list. Page 3 is the free list trunk and page 4 is a leaf.
    58     58   #
    59         -do_test 1.2 { file size test.db } [expr 6*1024]
           59  +do_test 1.2 { file_page_count test.db } 6
    60     60   do_test 1.3 { hexio_read test.db 32 4 } 00000003
    61     61   do_test 1.4 { hexio_read test.db [expr 2*1024] 12 } 000000000000000100000004
    62     62   
    63     63   # Change the free-list entry to page 6 and reopen the db file.
    64     64   do_test 1.5 { 
    65     65     hexio_write test.db [expr 2*1024 + 8] 00000006 
    66     66     sqlite3 db test.db
................................................................................
   105    105       }
   106    106       set res
   107    107     } {}
   108    108   }
   109    109   }
   110    110   
   111    111   do_test 2.1 { create_test_db } {}
   112         -do_test 2.2 { file size test.db } [expr 6*1024]
          112  +do_test 2.2 { file_page_count test.db } 6
   113    113   do_test 2.3 { hexio_read test.db 32 4 } 00000003
   114    114   do_test 2.4 { hexio_read test.db [expr 2*1024] 12 } 000000000000000100000004
   115    115   
   116    116   # Change the free-list entry to page 5 and reopen the db file.
   117    117   do_test 2.5 { 
   118    118     hexio_write test.db [expr 2*1024 + 8] 00000005 
   119    119     sqlite3 db test.db

Changes to test/createtab.test.

    48     48   
    49     49     set isUtf16 0
    50     50     ifcapable utf16 { 
    51     51       set isUtf16 [expr {[execsql {PRAGMA encoding}] != "UTF-8"}]
    52     52     }
    53     53   
    54     54     do_test createtab-$av.2 {
    55         -    file size test.db
    56         -  } [expr {1024*(4+($av!=0)+(${isUtf16}*2))}]
           55  +    file_page_count test.db
           56  +  } [expr {4+($av!=0)+(${isUtf16}*2)}]
    57     57     
    58     58     # Start reading the table
    59     59     #
    60     60     do_test createtab-$av.3 {
    61     61       set STMT [sqlite3_prepare db {SELECT x FROM t1} -1 TAIL]
    62     62       sqlite3_step $STMT
    63     63     } {SQLITE_ROW}

Changes to test/dbstatus2.test.

    16     16   source $testdir/tester.tcl
    17     17   
    18     18   set ::testprefix dbstatus2
    19     19   
    20     20   do_execsql_test 1.0 {
    21     21     PRAGMA page_size = 1024;
    22     22     PRAGMA auto_vacuum = 0;
           23  +  PRAGMA mmap_limit = 0;
    23     24   
    24     25     CREATE TABLE t1(a PRIMARY KEY, b);
    25     26     INSERT INTO t1 VALUES(1, randomblob(600));
    26     27     INSERT INTO t1 VALUES(2, randomblob(600));
    27     28     INSERT INTO t1 VALUES(3, randomblob(600));
    28     29   }
    29     30   

Changes to test/e_vacuum.test.

    38     38         INSERT INTO t1 SELECT a+64, randomblob(400) FROM t1;
    39     39   
    40     40         CREATE TABLE t2(a PRIMARY KEY, b UNIQUE);
    41     41         INSERT INTO t2 SELECT * FROM t1;
    42     42       }
    43     43     }
    44     44   
    45         -  return [expr {[file size test.db] / 1024}]
           45  +  return [file_page_count test.db]
    46     46   }
    47     47   
    48     48   # This proc returns the number of contiguous blocks of pages that make up
    49     49   # the table or index named by the only argument. For example, if the table
    50     50   # occupies database pages 3, 4, 8 and 9, then this command returns 2 (there
    51     51   # are 2 fragments - one consisting of pages 3 and 4, the other of fragments
    52     52   # 8 and 9).

Changes to test/filefmt.test.

    61     61     foreach pagesize {512 1024 2048 4096 8192 16384 32768} {
    62     62        if {[info exists SQLITE_MAX_PAGE_SIZE]
    63     63             && $pagesize>$SQLITE_MAX_PAGE_SIZE} continue
    64     64        do_test filefmt-1.5.$pagesize.1 {
    65     65          db close
    66     66          forcedelete test.db
    67     67          sqlite3 db test.db
           68  +       db eval "PRAGMA mmap_limit=0"
    68     69          db eval "PRAGMA auto_vacuum=OFF"
    69     70          db eval "PRAGMA page_size=$pagesize"
    70     71          db eval {CREATE TABLE t1(x)}
    71     72          file size test.db
    72     73        } [expr $pagesize*2]
    73     74        do_test filefmt-1.5.$pagesize.2 {
    74     75          hexio_get_int [hexio_read test.db 16 2]
................................................................................
   211    212   do_execsql_test filefmt-3.3 {
   212    213     SELECT * FROM sqlite_master;
   213    214     PRAGMA integrity_check;
   214    215   } {ok}
   215    216   
   216    217   reset_db
   217    218   do_execsql_test filefmt-4.1 {
          219  +  PRAGMA mmap_limit = 0;
   218    220     PRAGMA auto_vacuum = 1;
   219    221     CREATE TABLE t1(x, y);
   220    222     CREATE TABLE t2(x, y);
   221    223   
   222    224     INSERT INTO t1 VALUES(randomblob(100), randomblob(100));
   223    225     INSERT INTO t1 VALUES(randomblob(100), randomblob(100));
   224    226     INSERT INTO t1 VALUES(randomblob(100), randomblob(100));

Changes to test/format4.test.

    42     42       INSERT INTO t1 SELECT * FROM t1;
    43     43       INSERT INTO t1 SELECT * FROM t1;
    44     44       INSERT INTO t1 SELECT * FROM t1;
    45     45       INSERT INTO t1 SELECT * FROM t1;
    46     46       INSERT INTO t1 SELECT * FROM t1;
    47     47       INSERT INTO t1 SELECT * FROM t1;
    48     48     }
    49         -  file size test.db
           49  +  expr {1024 * [file_page_count test.db]}
    50     50   } $small
    51     51   do_test format4-1.2 {
    52     52     execsql {
    53     53       UPDATE t1 SET x0=1, x1=1, x2=1, x3=1, x4=1, x5=1, x6=1, x7=1, x8=1, x9=1
    54     54     }
    55         -  file size test.db
           55  +  expr {1024 * [file_page_count test.db]}
    56     56   } $small
    57     57   do_test format4-1.3 {
    58     58     execsql {
    59     59       UPDATE t1 SET x0=2, x1=2, x2=2, x3=2, x4=2, x5=2, x6=2, x7=2, x8=2, x9=2
    60     60     }
    61         -  file size test.db
           61  +  expr {1024 * [file_page_count test.db]}
    62     62   } $large
    63     63   
    64     64   
    65     65   finish_test

Changes to test/incrblob.test.

   615    615       INSERT INTO t2 VALUES(456, $::otherdata);
   616    616     }
   617    617     set ::b [db incrblob -readonly t2 b 456]
   618    618     fconfigure $::b -translation binary
   619    619     read $::b
   620    620   } $::otherdata
   621    621   do_test incrblob-7.3.2 {
   622         -  expr [file size test.db]/1024
          622  +  file_page_count test.db
   623    623   } 30
   624    624   do_test incrblob-7.3.3 {
   625    625     execsql {
   626    626       DELETE FROM t1 WHERE a = 123;
   627    627       PRAGMA INCREMENTAL_VACUUM(0);
   628    628     }
   629    629     seek $::b 0

Changes to test/incrvacuum.test.

   145    145     #
   146    146     #   1 -> database header
   147    147     #   2 -> first back-pointer page
   148    148     #   3 -> table abc
   149    149     #   4 -> table tbl2
   150    150     #   5 -> table tbl2 overflow page.
   151    151     #
   152         -  expr {[file size test.db] / 1024}
          152  +  file_page_count test.db
   153    153   } {5}
   154    154   do_test incrvacuum-3.3 {
   155    155     execsql {
   156    156       DROP TABLE abc;
   157    157       DELETE FROM tbl2;
   158    158     }
   159         -  expr {[file size test.db] / 1024}
          159  +  file_page_count test.db
   160    160   } {5}
   161    161   do_test incrvacuum-3.4 {
   162    162     execsql {
   163    163       PRAGMA auto_vacuum = 1;
   164    164       INSERT INTO tbl2 VALUES('hello world');
   165    165     }
   166         -  expr {[file size test.db] / 1024}
          166  +  file_page_count test.db
   167    167   } {3}
   168    168   
   169    169   #---------------------------------------------------------------------
   170    170   # Try to run a very simple incremental vacuum. Also verify that 
   171    171   # PRAGMA incremental_vacuum is a harmless no-op against a database that
   172    172   # does not support auto-vacuum.
   173    173   #
................................................................................
   174    174   do_test incrvacuum-4.1 {
   175    175     set ::str [string repeat 1234567890 110]
   176    176     execsql {
   177    177       PRAGMA auto_vacuum = 2;
   178    178       INSERT INTO tbl2 VALUES($::str);
   179    179       CREATE TABLE tbl1(a, b, c);
   180    180     }
   181         -  expr {[file size test.db] / 1024}
          181  +  file_page_count test.db
   182    182   } {5}
   183    183   do_test incrvacuum-4.2 {
   184    184     execsql {
   185    185       DELETE FROM tbl2;
   186    186       DROP TABLE tbl1;
   187    187     }
   188         -  expr {[file size test.db] / 1024}
          188  +  file_page_count test.db
   189    189   } {5}
   190    190   do_test incrvacuum-4.3 {
   191    191     set ::nStep 0
   192    192     db eval {pragma incremental_vacuum(10)} {
   193    193       incr ::nStep
   194    194     }
   195    195     list [expr {[file size test.db] / 1024}] $::nStep
................................................................................
   217    217     execsql {
   218    218       BEGIN;
   219    219       CREATE TABLE tbl1(a);
   220    220       INSERT INTO tbl1 VALUES($::str);
   221    221       PRAGMA incremental_vacuum;                 -- this is a no-op.
   222    222       COMMIT;
   223    223     }
   224         -  expr {[file size test.db] / 1024}
          224  +  file_page_count test.db
   225    225   } {4}
   226    226   do_test incrvacuum-5.2.2 {
   227    227     set ::str [string repeat abcdefghij 110]
   228    228     execsql {
   229    229       BEGIN;
   230    230       INSERT INTO tbl1 VALUES($::str);
   231    231       INSERT INTO tbl1 SELECT * FROM tbl1;
   232    232       DELETE FROM tbl1 WHERE oid%2;        -- Put 2 overflow pages on free-list.
   233    233       COMMIT;
   234    234     }
   235         -  expr {[file size test.db] / 1024}
          235  +  file_page_count test.db
   236    236   } {7}
   237    237   do_test incrvacuum-5.2.3 {
   238    238     execsql {
   239    239       BEGIN;
   240    240       PRAGMA incremental_vacuum;           -- Vacuum up the two pages.
   241    241       CREATE TABLE tbl2(b);                -- Use one free page as a table root.
   242    242       INSERT INTO tbl2 VALUES('a nice string');
   243    243       COMMIT;
   244    244     }
   245         -  expr {[file size test.db] / 1024}
          245  +  file_page_count test.db
   246    246   } {6}
   247    247   do_test incrvacuum-5.2.4 {
   248    248     execsql {
   249    249       SELECT * FROM tbl2;
   250    250     }
   251    251   } {{a nice string}}
   252    252   do_test incrvacuum-5.2.5 {
   253    253     execsql {
   254    254       DROP TABLE tbl1;
   255    255       DROP TABLE tbl2;
   256    256       PRAGMA incremental_vacuum;
   257    257     }
   258         -  expr {[file size test.db] / 1024}
          258  +  file_page_count test.db
   259    259   } {1}
   260    260   
   261    261   
   262    262   # Test cases incrvacuum-5.3.* use the following list as input data.
   263    263   # Two new databases are opened, one with incremental vacuum enabled,
   264    264   # the other with no auto-vacuum completely disabled. After executing
   265    265   # each element of the following list on both databases, test that
................................................................................
   523    523   # N pages are vacuumed.
   524    524   #
   525    525   do_test incrvacuum-10.1 {
   526    526     execsql {
   527    527       DROP TABLE t1;
   528    528       DROP TABLE t2;
   529    529     }
   530         -  expr [file size test.db] / 1024
          530  +  file_page_count test.db
   531    531   } {29}
   532    532   
   533    533   do_test incrvacuum-10.2 {
   534    534     execsql {
   535    535       PRAGMA incremental_vacuum(1);
   536    536     }
   537    537     expr [file size test.db] / 1024

Changes to test/io.test.

   414    414       # size may be a little less than that. So this test case just tests
   415    415       # that the file is now greater than 20000 bytes in size.
   416    416       list [expr [file size test.db]>20000] [nSync]
   417    417     } {1 0}
   418    418     do_test io-3.3 {
   419    419       # The COMMIT requires a single fsync() - to the database file.
   420    420       execsql { COMMIT }
   421         -    list [file size test.db] [nSync]
   422         -  } {39936 1}
          421  +    list [file_page_count test.db] [nSync]
          422  +  } {39 1}
   423    423   }
   424    424   
   425    425   #----------------------------------------------------------------------
   426    426   # Test cases io-4.* test the IOCAP_SAFE_APPEND optimization.
   427    427   #
   428    428   sqlite3_simulate_device -char safe_append
   429    429   
................................................................................
   484    484       INSERT INTO abc SELECT * FROM abc;
   485    485       INSERT INTO abc SELECT * FROM abc;
   486    486       INSERT INTO abc SELECT * FROM abc;
   487    487       INSERT INTO abc SELECT * FROM abc;
   488    488       INSERT INTO abc SELECT * FROM abc;
   489    489       INSERT INTO abc SELECT * FROM abc;
   490    490     }
   491         -  expr {[file size test.db]/1024}
          491  +  file_page_count test.db
   492    492   } {43}
   493    493   ifcapable pager_pragmas {
   494    494     do_test io-4.3.2 {
   495    495       execsql {
   496    496         PRAGMA synchronous = full;
   497    497         PRAGMA cache_size = 10;
   498    498         PRAGMA synchronous;
................................................................................
   558    558       if {[regexp {^atomic} $char]} continue
   559    559     }
   560    560     do_test io-5.$tn {
   561    561       execsql {
   562    562         CREATE TABLE abc(a, b, c);
   563    563       }
   564    564       expr {[file size test.db]/2}
   565         -  } $pgsize
          565  +
          566  +    list [file_page_count test.db] [file_page_size test.db]
          567  +  } [list 2 $pgsize]
   566    568   }
   567    569   
   568    570   sqlite3_simulate_device -char {} -sectorsize 0
   569    571   finish_test

Changes to test/jrnlmode.test.

   517    517         PRAGMA journal_mode = memory;
   518    518         PRAGMA auto_vacuum = 0;
   519    519         PRAGMA page_size = 1024;
   520    520         PRAGMA user_version = 5;
   521    521         PRAGMA user_version;
   522    522       }
   523    523     } {memory 5}
   524         -  do_test jrnlmode-7.2 { file size test.db } {1024}
          524  +  do_test jrnlmode-7.2 { 
          525  +    list [file_page_count test.db] [file_page_size test.db]
          526  +  } {1 1024}
   525    527   }
   526    528   
   527    529   do_execsql_test jrnlmode-8.1  { PRAGMA locking_mode=EXCLUSIVE } {exclusive}
   528    530   do_execsql_test jrnlmode-8.2  { CREATE TABLE t1(x) }            {}
   529    531   do_execsql_test jrnlmode-8.3  { INSERT INTO t1 VALUES(123) }    {}
   530    532   do_execsql_test jrnlmode-8.4  { SELECT * FROM t1 }              {123}
   531    533   do_execsql_test jrnlmode-8.5  { PRAGMA journal_mode=PERSIST }   {persist}

Changes to test/lock4.test.

    29     29     forcedelete test2.db test2.db-journal
    30     30     sqlite3 db2 test2.db
    31     31     db2 eval {
    32     32        PRAGMA auto_vacuum=OFF;
    33     33        CREATE TABLE t2(x)
    34     34     }
    35     35     db2 close
    36         -  list [file size test.db] [file size test2.db]
    37         -} {2048 2048}
           36  +  list [file_page_count test.db] [file_page_count test2.db]
           37  +} {2 2}
    38     38   
    39     39   # Create a script to drive a separate process that will
    40     40   #
    41     41   #     1.  Create a second database test2.db
    42     42   #     2.  Get an exclusive lock on test2.db
    43     43   #     3.  Add an entry to test.db in table t1, waiting as necessary.
    44     44   #     4.  Commit the change to test2.db.

Changes to test/pager1.test.

  1105   1105   
  1106   1106   #-------------------------------------------------------------------------
  1107   1107   # The following tests work with "PRAGMA max_page_count"
  1108   1108   #
  1109   1109   do_test pager1-6.1 {
  1110   1110     faultsim_delete_and_reopen
  1111   1111     execsql {
         1112  +    PRAGMA page_size = 4096;
  1112   1113       PRAGMA auto_vacuum = none;
  1113   1114       PRAGMA max_page_count = 10;
  1114   1115       CREATE TABLE t2(a, b);
  1115   1116       CREATE TABLE t3(a, b);
  1116   1117       CREATE TABLE t4(a, b);
  1117   1118       CREATE TABLE t5(a, b);
  1118   1119       CREATE TABLE t6(a, b);
................................................................................
  1353   1354     B step 30
  1354   1355     list [B step 10000] [B finish]
  1355   1356   } {SQLITE_DONE SQLITE_OK}
  1356   1357   do_test pager1-9.3.3 {
  1357   1358     db2 close
  1358   1359     db close
  1359   1360     tv delete
  1360         -  file size test.db2
  1361         -} [file size test.db]
         1361  +  file_page_count test.db2
         1362  +} [file_page_count test.db]
  1362   1363   
  1363   1364   do_test pager1-9.4.1 {
  1364   1365     faultsim_delete_and_reopen
  1365   1366     sqlite3 db2 test.db2
  1366   1367     execsql {
  1367   1368       PRAGMA page_size = 4096;
  1368   1369       CREATE TABLE t1(a, b);
................................................................................
  1467   1468     file size test.db
  1468   1469   } {32768}
  1469   1470   do_test pager1.10.x.2 {
  1470   1471     execsql {
  1471   1472       CREATE TABLE t2(x);
  1472   1473       DROP TABLE t2;
  1473   1474     }
  1474         -  file size test.db
  1475         -} {33792}
         1475  +  list [file_page_count test.db] [file_page_size test.db]
         1476  +} {33 1024}
  1476   1477   do_test pager1.10.x.3 {
  1477   1478     execsql {
  1478   1479       BEGIN;
  1479   1480       CREATE TABLE t2(x);
  1480   1481     }
  1481   1482     recursive_select 30 t1
  1482   1483     execsql {
................................................................................
  1548   1549   
  1549   1550     do_test pager1-12.$pagesize.1 {
  1550   1551       sqlite3 db2 test.db
  1551   1552       execsql "
  1552   1553         PRAGMA page_size = $pagesize;
  1553   1554         CREATE VIEW v AS SELECT * FROM sqlite_master;
  1554   1555       " db2
  1555         -    file size test.db
         1556  +    file_page_size test.db
  1556   1557     } $eff
  1557   1558     do_test pager1-12.$pagesize.2 {
  1558   1559       sqlite3 db2 test.db
  1559   1560       execsql { 
  1560   1561         SELECT count(*) FROM v;
  1561   1562         PRAGMA main.page_size;
  1562   1563       } db2
................................................................................
  2384   2385     execsql {
  2385   2386       PRAGMA page_size = 1024;
  2386   2387       PRAGMA auto_vacuum = full;
  2387   2388       PRAGMA locking_mode=exclusive;
  2388   2389       CREATE TABLE t1(a, b);
  2389   2390       INSERT INTO t1 VALUES(1, 2);
  2390   2391     }
  2391         -  file size test.db
  2392         -} [expr 1024*3]
         2392  +  list [file_page_count test.db] [file_page_size test.db]
         2393  +} {3 1024}
  2393   2394   do_test pager1-29.2 {
  2394   2395     execsql {
  2395   2396       PRAGMA page_size = 4096;
  2396   2397       VACUUM;
  2397   2398     }
  2398         -  file size test.db
  2399         -} [expr 4096*3]
         2399  +  list [file_page_count test.db] [file_page_size test.db]
         2400  +} {3 4096}
  2400   2401   
  2401   2402   #-------------------------------------------------------------------------
  2402   2403   # Test that if an empty database file (size 0 bytes) is opened in 
  2403   2404   # exclusive-locking mode, any journal file is deleted from the file-system
  2404   2405   # without being rolled back. And that the RESERVED lock obtained while
  2405   2406   # doing this is not released.
  2406   2407   #

Changes to test/pagesize.test.

   111    111       db close
   112    112       sqlite3 db test.db
   113    113       execsql {
   114    114         PRAGMA page_size
   115    115       }
   116    116     } $PGSZ
   117    117     do_test pagesize-2.$PGSZ.3 {
   118         -    file size test.db
   119         -  } [expr {$PGSZ*($AUTOVACUUM?3:2)}]
          118  +    list [file_page_count test.db] [file_page_size test.db]
          119  +  } [list [expr ($AUTOVACUUM?3:2)] $PGSZ]
   120    120     ifcapable {vacuum} {
   121    121       do_test pagesize-2.$PGSZ.4 {
   122    122         execsql {VACUUM}
   123    123       } {}
   124    124     }
   125    125     integrity_check pagesize-2.$PGSZ.5
   126    126     do_test pagesize-2.$PGSZ.6 {

Changes to test/pragma.test.

   258    258   # These tests won't work if the database is encrypted
   259    259   #
   260    260   do_test pragma-3.1 {
   261    261     db close
   262    262     forcedelete test.db test.db-journal
   263    263     sqlite3 db test.db
   264    264     execsql {
          265  +    PRAGMA mmap_limit=0;
   265    266       PRAGMA auto_vacuum=OFF;
   266    267       BEGIN;
   267    268       CREATE TABLE t2(a,b,c);
   268    269       CREATE INDEX i2 ON t2(a);
   269    270       INSERT INTO t2 VALUES(11,2,3);
   270    271       INSERT INTO t2 VALUES(22,3,4);
   271    272       COMMIT;
................................................................................
   280    281         # overwrite the header on the rootpage of the index in order to
   281    282         # make the index appear to be empty.
   282    283         #
   283    284         set offset [expr {$pgsz*($rootpage-1)}]
   284    285         hexio_write test.db $offset 0a00000000040000000000
   285    286         db close
   286    287         sqlite3 db test.db
          288  +      execsql {PRAGMA mmap_limit=0}
   287    289         execsql {PRAGMA integrity_check}
   288    290       } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   289    291       do_test pragma-3.3 {
   290    292         execsql {PRAGMA integrity_check=1}
   291    293       } {{rowid 1 missing from index i2}}
   292    294       do_test pragma-3.4 {
   293    295         execsql {
................................................................................
  1247   1249     } {3}
  1248   1250     do_test pragma-14.3uc {
  1249   1251       execsql {pragma PAGE_COUNT}
  1250   1252     } {3}
  1251   1253   
  1252   1254     do_test pragma-14.4 {
  1253   1255       set page_size [db one {pragma page_size}]
  1254         -    expr [file size test.db] / $page_size
  1255         -  } {2}
         1256  +    list [file_page_count test.db] $page_size
         1257  +  } [list 2 [file_page_size test.db]]
  1256   1258   
  1257   1259     do_test pragma-14.5 {
  1258   1260       execsql {
  1259   1261         ROLLBACK;
  1260   1262         PRAGMA page_count;
  1261   1263       }
  1262   1264     } {2}

Changes to test/pragma2.test.

    82     82       set ::val [string repeat 0123456789 1000]
    83     83       execsql {
    84     84         INSERT INTO aux.abc VALUES(1, 2, $::val);
    85     85         PRAGMA aux.freelist_count;
    86     86       }
    87     87     } {0}
    88     88     do_test pragma2-2.4 {
    89         -    expr {[file size test2.db] / 1024}
    90         -  } {11}
           89  +    list [file_page_count test2.db] [file_page_size test2.db]
           90  +  } {11 1024}
    91     91     do_test pragma2-2.5 {
    92     92       execsql {
    93     93         DELETE FROM aux.abc;
    94     94         PRAGMA aux.freelist_count;
    95     95       }
    96     96     } {9}
    97     97     

Changes to test/quota.test.

    67     67   
    68     68   do_test quota-2.1.1 {
    69     69     sqlite3_quota_set *test.db 4096 quota_check
    70     70   } {SQLITE_OK}
    71     71   do_test quota-2.1.2 {
    72     72     sqlite3 db test.db
    73     73     execsql {
           74  +    PRAGMA mmap_limit=0;
    74     75       PRAGMA page_size=1024;
    75     76       PRAGMA auto_vacuum=OFF;
    76     77       PRAGMA journal_mode=DELETE;
    77     78     }
    78     79     set ::quota [list]
    79     80     execsql {
    80     81       CREATE TABLE t1(a, b);
................................................................................
   139    140     forcedelete test.db
   140    141     sqlite3_quota_initialize "" 1
   141    142     sqlite3_quota_set *test.db 4096 quota_check
   142    143   } {SQLITE_OK}
   143    144   do_test quota-3.1.2 {
   144    145     sqlite3 db test.db
   145    146     execsql {
          147  +    PRAGMA mmap_limit = 0;
   146    148       PRAGMA page_size = 1024;
   147    149       PRAGMA journal_mode = delete;
   148    150       PRAGMA auto_vacuum = off;
   149    151       CREATE TABLE t1(a PRIMARY KEY, b);
   150    152       INSERT INTO t1 VALUES(1, 'one');
   151    153     }
   152    154     file size test.db
   153    155   } {3072}
   154    156   do_test quota-3.1.3 {
   155    157     sqlite3 db2 test.db
   156    158     set ::quota [list]
          159  +  execsql { PRAGMA mmap_limit=0 } db2
   157    160     execsql { CREATE TABLE t2(a, b) } db2
   158    161     set ::quota
   159    162   } {}
   160    163   do_test quota-3.1.4 {
   161    164     catchsql { CREATE TABLE t3(a, b) }
   162    165   } {1 {database or disk is full}}
   163    166   do_test quota-3.1.5 {
................................................................................
   175    178   
   176    179     sqlite3_quota_set * 4096 {}
   177    180     sqlite3 db1a test.db
   178    181     sqlite3 db2a test2.db
   179    182   
   180    183     foreach db {db1a db2a} {
   181    184       execsql {
          185  +      PRAGMA mmap_limit=0;
   182    186         PRAGMA page_size = 1024;
   183    187         PRAGMA journal_mode = delete;
   184    188         PRAGMA auto_vacuum = off;
   185    189         CREATE TABLE t1(a, b);
   186    190       } $db
   187    191     }
   188    192   

Changes to test/tester.tcl.

  1632   1632   # to the values they held before the SQL was executed. This simulates
  1633   1633   # a write by a pre-3.7.0 client.
  1634   1634   #
  1635   1635   proc sql36231 {sql} {
  1636   1636     set B [hexio_read test.db 92 8]
  1637   1637     set A [hexio_read test.db 28 4]
  1638   1638     sqlite3 db36231 test.db
         1639  +  db36231 eval { PRAGMA mmap_limit = 0 }
  1639   1640     catch { db36231 func a_string a_string }
  1640   1641     execsql $sql db36231
  1641   1642     db36231 close
  1642   1643     hexio_write test.db 28 $A
  1643   1644     hexio_write test.db 92 $B
  1644   1645     return ""
  1645   1646   }
................................................................................
  1669   1670     sqlite3 db $dbfile
  1670   1671   }
  1671   1672   proc db_delete_and_reopen {{file test.db}} {
  1672   1673     catch { db close }
  1673   1674     foreach f [glob -nocomplain test.db*] { forcedelete $f }
  1674   1675     sqlite3 db $file
  1675   1676   }
         1677  +
         1678  +# Return the number of pages in the database file $zFile, according to 
         1679  +# the database header.
         1680  +#
         1681  +proc file_page_count {zFile} {
         1682  +  set nPg [hexio_get_int [hexio_read $zFile 28 4]]
         1683  +  return $nPg
         1684  +}
         1685  +
         1686  +# Return the page size of database file $zFile, according to the database 
         1687  +# header.
         1688  +#
         1689  +proc file_page_size {zFile} {
         1690  +  set pgsz [hexio_get_int [hexio_read $zFile 16 2]]
         1691  +  if {$pgsz==1} {set pgsz 65536}
         1692  +  return $pgsz
         1693  +}
  1676   1694   
  1677   1695   # If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set
  1678   1696   # to non-zero, then set the global variable $AUTOVACUUM to 1.
  1679   1697   set AUTOVACUUM $sqlite_options(default_autovacuum)
  1680   1698   
  1681   1699   # Make sure the FTS enhanced query syntax is disabled.
  1682   1700   set sqlite_fts3_enable_parentheses 0
  1683   1701   
  1684   1702   source $testdir/thread_common.tcl
  1685   1703   source $testdir/malloc_common.tcl

Changes to test/tkt1512.test.

    31     31       CREATE TABLE t1(a,b);
    32     32       INSERT INTO t1 VALUES(1,2);
    33     33       INSERT INTO t1 VALUES(3,4);
    34     34       SELECT * FROM t1
    35     35     }
    36     36   } {1 2 3 4}
    37     37   do_test tkt1512-1.2 {
    38         -  file size test.db
    39         -} {2048}
           38  +  file_page_count test.db
           39  +} {2}
    40     40   do_test tkt1512-1.3 {
    41     41     execsql {
    42     42       DROP TABLE t1;
    43     43     }
    44         -  file size test.db
    45         -} {2048}
           44  +  file_page_count test.db
           45  +} {2}
    46     46   do_test tkt1512-1.4 {
    47     47     execsql {
    48     48       VACUUM;
    49     49     }
    50         -  file size test.db
    51         -} {1024}
           50  +  file_page_count test.db
           51  +} {1}
    52     52   
    53     53   
    54     54   finish_test

Changes to test/tkt2920.test.

    22     22   do_test tkt2920-1.1 {
    23     23     db eval {
    24     24       PRAGMA page_size=1024;
    25     25       PRAGMA max_page_count=40;
    26     26       PRAGMA auto_vacuum=0;
    27     27       CREATE TABLE filler (fill);
    28     28     }
    29         -  file size test.db
    30         -} {2048}
           29  +  list [file_page_count test.db] [file_page_size test.db]
           30  +} {2 1024}
    31     31   do_test tkt2920-1.2 {
    32     32     db eval BEGIN
    33     33     for {set i 0} {$i<34} {incr i} {
    34     34       db eval {INSERT INTO filler VALUES(randomblob(1024))}
    35     35     }
    36     36     db eval COMMIT
    37     37   }  {}

Changes to test/wal.test.

    63     63   #
    64     64   do_test wal-0.1 {
    65     65     execsql { PRAGMA auto_vacuum = 0 }
    66     66     execsql { PRAGMA synchronous = normal }
    67     67     execsql { PRAGMA journal_mode = wal }
    68     68   } {wal}
    69     69   do_test wal-0.2 {
    70         -  file size test.db
    71         -} {1024}
           70  +  file_page_count test.db
           71  +} {1}
    72     72   
    73     73   do_test wal-1.0 {
    74     74     execsql { 
    75     75       BEGIN;
    76     76       CREATE TABLE t1(a, b); 
    77     77     }
    78     78     list [file exists test.db-journal] \
    79     79          [file exists test.db-wal]     \
    80         -       [file size test.db]
    81         -} {0 1 1024}
           80  +       [file_page_count test.db]
           81  +} {0 1 1}
    82     82   do_test wal-1.1 {
    83     83     execsql COMMIT
    84     84     list [file exists test.db-journal] [file exists test.db-wal]
    85     85   } {0 1}
    86     86   do_test wal-1.2 {
    87     87     # There are now two pages in the log.
    88     88     file size test.db-wal
................................................................................
   343    343           PRAGMA journal_mode = wal;
   344    344         "
   345    345         execsql "
   346    346           CREATE TABLE t1(a, b);
   347    347           INSERT INTO t1 VALUES(1, 2);
   348    348         "
   349    349         db close
   350         -      file size test.db
   351         -    } [expr $pgsz*2]
          350  +      list [file_page_count test.db] [file_page_size test.db]
          351  +    } [list 2 $pgsz]
   352    352     
   353    353       do_test wal-6.$sector.$pgsz.2 {
   354    354         log_deleted test.db-wal
   355    355       } {1}
   356    356     }
   357    357   }
   358    358   
................................................................................
   360    360     forcedelete test.db test.db-wal
   361    361     sqlite3_wal db test.db
   362    362     execsql {
   363    363       PRAGMA page_size = 1024;
   364    364       CREATE TABLE t1(a, b);
   365    365       INSERT INTO t1 VALUES(1, 2);
   366    366     }
   367         -  list [file size test.db] [file size test.db-wal]
   368         -} [list 1024 [wal_file_size 3 1024]]
          367  +  list [file_page_count test.db] \
          368  +       [file_page_size test.db]  \
          369  +       [file size test.db-wal]
          370  +} [list 1 1024 [wal_file_size 3 1024]]
   369    371   do_test wal-7.2 {
   370    372     execsql { PRAGMA wal_checkpoint }
   371         -  list [file size test.db] [file size test.db-wal]
   372         -} [list 2048 [wal_file_size 3 1024]]
          373  +  list [file_page_count test.db] \
          374  +       [file_page_size test.db]  \
          375  +       [file size test.db-wal]
          376  +} [list 2 1024 [wal_file_size 3 1024]]
   373    377   
   374    378   # Execute some transactions in auto-vacuum mode to test database file
   375    379   # truncation.
   376    380   #
   377    381   do_test wal-8.1 {
   378    382     reopen_db
   379    383     catch { db close }
................................................................................
   424    428       INSERT INTO t1 SELECT blob(900) FROM t1;       /*  8 */
   425    429       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 16 */
   426    430       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 32 */
   427    431       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 64 */
   428    432       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 128 */
   429    433       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 256 */
   430    434     }
   431         -  file size test.db
   432         -} 1024
          435  +  file_page_count test.db
          436  +} 1
   433    437   do_test wal-9.2 {
   434    438     sqlite3_wal db2 test.db
   435    439     execsql {PRAGMA integrity_check } db2
   436    440   } {ok}
   437    441   
   438    442   do_test wal-9.3 {
   439    443     forcedelete test2.db test2.db-wal
................................................................................
   677    681   do_test wal-11.1 {
   678    682     reopen_db
   679    683     execsql {
   680    684       PRAGMA cache_size = 10;
   681    685       PRAGMA page_size = 1024;
   682    686       CREATE TABLE t1(x PRIMARY KEY);
   683    687     }
   684         -  list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
          688  +  list [file_page_count test.db] [expr [file size test.db-wal]/1044]
   685    689   } {1 3}
   686    690   do_test wal-11.2 {
   687    691     execsql { PRAGMA wal_checkpoint }
   688         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          692  +  list [file_page_count test.db] [file size test.db-wal]
   689    693   } [list 3 [wal_file_size 3 1024]]
   690    694   do_test wal-11.3 {
   691    695     execsql { INSERT INTO t1 VALUES( blob(900) ) }
   692         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          696  +  list [file_page_count test.db] [file size test.db-wal]
   693    697   } [list 3 [wal_file_size 4 1024]]
   694    698   
   695    699   do_test wal-11.4 {
   696    700     execsql { 
   697    701       BEGIN;
   698    702         INSERT INTO t1 SELECT blob(900) FROM t1;   -- 2
   699    703         INSERT INTO t1 SELECT blob(900) FROM t1;   -- 4
   700    704         INSERT INTO t1 SELECT blob(900) FROM t1;   -- 8
   701    705         INSERT INTO t1 SELECT blob(900) FROM t1;   -- 16
   702    706     }
   703         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          707  +  list [file_page_count test.db] [file size test.db-wal]
   704    708   } [list 3 [wal_file_size 32 1024]]
   705    709   do_test wal-11.5 {
   706    710     execsql { 
   707    711       SELECT count(*) FROM t1;
   708    712       PRAGMA integrity_check;
   709    713     }
   710    714   } {16 ok}
   711    715   do_test wal-11.6 {
   712    716     execsql COMMIT
   713         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          717  +  list [file_page_count test.db] [file size test.db-wal]
   714    718   } [list 3 [wal_file_size 41 1024]]
   715    719   do_test wal-11.7 {
   716    720     execsql { 
   717    721       SELECT count(*) FROM t1;
   718    722       PRAGMA integrity_check;
   719    723     }
   720    724   } {16 ok}
   721    725   do_test wal-11.8 {
   722    726     execsql { PRAGMA wal_checkpoint }
   723         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          727  +  list [file_page_count test.db] [file size test.db-wal]
   724    728   } [list 37 [wal_file_size 41 1024]]
   725    729   do_test wal-11.9 {
   726    730     db close
   727         -  list [expr [file size test.db]/1024] [log_deleted test.db-wal]
          731  +  list [file_page_count test.db] [log_deleted test.db-wal]
   728    732   } {37 1}
   729    733   sqlite3_wal db test.db
   730    734   set nWal 39
   731    735   if {[permutation]=="nommap"} {set nWal 37}
   732    736   do_test wal-11.10 {
   733    737     execsql {
   734    738       PRAGMA cache_size = 10;
   735    739       BEGIN;
   736    740         INSERT INTO t1 SELECT blob(900) FROM t1;   -- 32
   737    741         SELECT count(*) FROM t1;
   738    742     }
   739         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          743  +  list [file_page_count test.db] [file size test.db-wal]
   740    744   } [list 37 [wal_file_size $nWal 1024]]
   741    745   do_test wal-11.11 {
   742    746     execsql {
   743    747         SELECT count(*) FROM t1;
   744    748       ROLLBACK;
   745    749       SELECT count(*) FROM t1;
   746    750     }
   747    751   } {32 16}
   748    752   do_test wal-11.12 {
   749         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          753  +  list [file_page_count test.db] [file size test.db-wal]
   750    754   } [list 37 [wal_file_size $nWal 1024]]
   751    755   do_test wal-11.13 {
   752    756     execsql {
   753    757       INSERT INTO t1 VALUES( blob(900) );
   754    758       SELECT count(*) FROM t1;
   755    759       PRAGMA integrity_check;
   756    760     }
   757    761   } {17 ok}
   758    762   do_test wal-11.14 {
   759         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          763  +  list [file_page_count test.db] [file size test.db-wal]
   760    764   } [list 37 [wal_file_size $nWal 1024]]
   761    765   
   762    766   
   763    767   #-------------------------------------------------------------------------
   764    768   # This block of tests, wal-12.*, tests the fix for a problem that 
   765    769   # could occur if a log that is a prefix of an older log is written 
   766    770   # into a reused log file.
................................................................................
   769    773   do_test wal-12.1 {
   770    774     execsql {
   771    775       PRAGMA page_size = 1024;
   772    776       CREATE TABLE t1(x, y);
   773    777       CREATE TABLE t2(x, y);
   774    778       INSERT INTO t1 VALUES('A', 1);
   775    779     }
   776         -  list [expr [file size test.db]/1024] [file size test.db-wal]
          780  +  list [file_page_count test.db] [file size test.db-wal]
   777    781   } [list 1 [wal_file_size 5 1024]]
   778    782   do_test wal-12.2 {
   779    783     db close
   780    784     sqlite3 db test.db
   781    785     execsql {
   782    786       PRAGMA synchronous = normal;
   783    787       UPDATE t1 SET y = 0 WHERE x = 'A';
   784    788     }
   785         -  list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
          789  +  list [file_page_count test.db] [expr [file size test.db-wal]/1044]
   786    790   } {3 1}
   787    791   do_test wal-12.3 {
   788    792     execsql { INSERT INTO t2 VALUES('B', 1) }
   789         -  list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
          793  +  list [file_page_count test.db] [expr [file size test.db-wal]/1044]
   790    794   } {3 2}
   791    795   do_test wal-12.4 {
   792    796     forcecopy test.db test2.db
   793    797     forcecopy test.db-wal test2.db-wal
   794    798     sqlite3_wal db2 test2.db
   795    799     execsql { SELECT * FROM t2 } db2
   796    800   } {B 1}
................................................................................
   847    851     set fd [open test.db-wal w]
   848    852     seek $fd [expr 200*1024*1024]
   849    853     puts $fd ""
   850    854     close $fd
   851    855     sqlite3 db test.db
   852    856     execsql { SELECT * FROM t2 }
   853    857   } {B 2}
   854         -breakpoint
   855    858   do_test wal-13.1.3 {
   856    859     db close
   857    860     file exists test.db-wal
   858    861   } {0}
   859    862   
   860    863   do_test wal-13.2.1 {
   861    864     sqlite3 db test.db
................................................................................
  1018   1021     execsql { COMMIT } db2
  1019   1022     sqlite3_wal_checkpoint db
  1020   1023   } {SQLITE_OK}
  1021   1024   do_test wal-15.4.5 {
  1022   1025     sqlite3_errmsg db
  1023   1026   } {not an error}
  1024   1027   do_test wal-15.4.6 {
  1025         -  file size test.db
  1026         -} [expr 1024*2]
         1028  +  list [file_page_count test.db] [file_page_size test.db]
         1029  +} {2 1024}
  1027   1030   
  1028   1031   catch { db2 close }
  1029   1032   catch { db close }
  1030   1033   
  1031   1034   #-------------------------------------------------------------------------
  1032   1035   # The following block of tests - wal-16.* - test that if a NULL pointer or
  1033   1036   # an empty string is passed as the second argument of the wal_checkpoint()
................................................................................
  1067   1070         CREATE TABLE aux.t2(a, b, PRIMARY KEY(a, b));
  1068   1071   
  1069   1072         INSERT INTO t2 VALUES(1, randomblob(1000));
  1070   1073         INSERT INTO t2 VALUES(2, randomblob(1000));
  1071   1074         INSERT INTO t1 SELECT * FROM t2;
  1072   1075       }
  1073   1076     
  1074         -    list [file size test.db] [file size test.db-wal]
  1075         -  } [list [expr 1*1024] [wal_file_size 10 1024]]
         1077  +    list [file_page_count test.db] [file size test.db-wal]
         1078  +  } [list 1 [wal_file_size 10 1024]]
  1076   1079     do_test wal-16.$tn.3 {
  1077         -    list [file size test2.db] [file size test2.db-wal]
  1078         -  } [list [expr 1*1024] [wal_file_size 13 1024]]
         1080  +    list [file_page_count test2.db] [file size test2.db-wal]
         1081  +  } [list 1 [wal_file_size 13 1024]]
  1079   1082     
  1080   1083     do_test wal-16.$tn.4 [list eval $ckpt_cmd] $ckpt_res
  1081   1084     
  1082   1085     do_test wal-16.$tn.5 {
  1083         -    list [file size test.db] [file size test.db-wal]
  1084         -  } [list [expr ($ckpt_main ? 7 : 1)*1024] [wal_file_size 10 1024]]
         1086  +    list [file_page_count test.db] [file size test.db-wal]
         1087  +  } [list [expr ($ckpt_main ? 7 : 1)] [wal_file_size 10 1024]]
  1085   1088   
  1086   1089     do_test wal-16.$tn.6 {
  1087         -    list [file size test2.db] [file size test2.db-wal]
  1088         -  } [list [expr ($ckpt_aux ? 7 : 1)*1024] [wal_file_size 13 1024]]
         1090  +    list [file_page_count test2.db] [file size test2.db-wal]
         1091  +  } [list [expr ($ckpt_aux ? 7 : 1)] [wal_file_size 13 1024]]
  1089   1092   
  1090   1093     catch { db close }
  1091   1094   }
  1092   1095   
  1093   1096   #-------------------------------------------------------------------------
  1094   1097   # The following tests - wal-17.* - attempt to verify that the correct
  1095   1098   # number of "padding" frames are appended to the log file when a transaction
................................................................................
  1141   1144       }
  1142   1145       execsql COMMIT
  1143   1146   
  1144   1147       file size test.db-wal
  1145   1148     } $logsize
  1146   1149   
  1147   1150     do_test wal-17.$tn.2 {
  1148         -    file size test.db
  1149         -  } 512
         1151  +    file_page_count test.db
         1152  +  } 1
  1150   1153   
  1151   1154     do_test wal-17.$tn.3 {
  1152   1155       db close
  1153         -    file size test.db
  1154         -  } [expr 512*171]
         1156  +    file_page_count test.db
         1157  +  } 171
  1155   1158   }
  1156   1159   sqlite3_test_control_pending_byte $old_pending_byte
  1157   1160   
  1158   1161   #-------------------------------------------------------------------------
  1159   1162   # This test - wal-18.* - verifies a couple of specific conditions that
  1160   1163   # may be encountered while recovering a log file are handled correctly:
  1161   1164   #
................................................................................
  1182   1185       INSERT INTO t1 VALUES(3, 4);          -- frames 3 and 4
  1183   1186       INSERT INTO t1 VALUES(5, 6);          -- frames 5 and 6
  1184   1187     }
  1185   1188   
  1186   1189     forcecopy test.db testX.db
  1187   1190     forcecopy test.db-wal testX.db-wal
  1188   1191     db close
  1189         -  list [file size testX.db] [file size testX.db-wal]
  1190         -} [list [expr 3*1024] [wal_file_size 6 1024]]
         1192  +  list [file_page_count testX.db] [file size testX.db-wal]
         1193  +} [list 3 [wal_file_size 6 1024]]
  1191   1194   
  1192   1195   unset -nocomplain nFrame result
  1193   1196   foreach {nFrame result} {
  1194   1197            0      {0 0}
  1195   1198            1      {0 0}
  1196   1199            2      {0 0 1 2}
  1197   1200            3      {0 0 1 2}
................................................................................
  1263   1266       forcedelete test.db-wal
  1264   1267     
  1265   1268       # Check that the database now exists and consists of three pages. And
  1266   1269       # that there is no associated wal file.
  1267   1270       #
  1268   1271       do_test wal-18.2.$tn.$pg.1 { file exists test.db-wal } 0
  1269   1272       do_test wal-18.2.$tn.$pg.2 { file exists test.db } 1
  1270         -    do_test wal-18.2.$tn.$pg.3 { file size test.db } [expr 1024*3]
         1273  +    do_test wal-18.2.$tn.$pg.3 { file_page_count test.db } 3
  1271   1274     
  1272   1275       do_test wal-18.2.$tn.$pg.4 {
  1273   1276   
  1274   1277         # Create a wal file that contains a single frame (database page
  1275   1278         # number $pg) with the commit flag set. The frame checksum is
  1276   1279         # correct, but the contents of the database page are corrupt.
  1277   1280         #
................................................................................
  1505   1508   } {1 2 3 4}
  1506   1509   do_test wal-23.2 { set ::log } {}
  1507   1510   
  1508   1511   do_test wal-23.3 {
  1509   1512     db close
  1510   1513     set ::log [list]
  1511   1514     faultsim_restore_and_reopen
  1512         -  execsql { SELECT * FROM t1 }
  1513         -} {1 2 3 4}
         1515  +  execsql { SELECT * FROM t1 ; PRAGMA page_size }
         1516  +} {1 2 3 4 1024}
  1514   1517   set nPage [expr 2+$AUTOVACUUM]
  1515   1518   do_test wal-23.4 { 
  1516   1519     set ::log 
  1517   1520   } [list SQLITE_OK "Recovered $nPage frames from WAL file $walfile"]
  1518   1521   
  1519   1522   
  1520   1523   ifcapable autovacuum {

Changes to test/wal5.test.

    17     17   source $testdir/tester.tcl
    18     18   source $testdir/lock_common.tcl
    19     19   source $testdir/wal_common.tcl
    20     20   ifcapable !wal {finish_test ; return }
    21     21   
    22     22   set testprefix wal5
    23     23   
    24         -proc db_page_count  {{file test.db}} { expr [file size $file] / 1024 }
           24  +proc db_page_count  {{file test.db}} { file_page_count $file }
    25     25   proc wal_page_count {{file test.db}} { wal_frame_count ${file}-wal 1024 }
    26     26   
    27     27   
    28     28   # A checkpoint may be requested either using the C API or by executing
    29     29   # an SQL PRAGMA command. To test both methods, all tests in this file are 
    30     30   # run twice - once using each method to request checkpoints.
    31     31   #
................................................................................
    97     97           PRAGMA auto_vacuum = 0;
    98     98           CREATE TABLE t1(x, y);
    99     99           PRAGMA journal_mode = WAL;
   100    100           INSERT INTO t1 VALUES(1, zeroblob(1200));
   101    101           INSERT INTO t1 VALUES(2, zeroblob(1200));
   102    102           INSERT INTO t1 VALUES(3, zeroblob(1200));
   103    103         }
   104         -      expr [file size test.db] / 1024
   105         -    } {2}
          104  +      list [file_page_count test.db] [file_page_size test.db]
          105  +    } {2 1024}
   106    106   
   107    107       # Have connection 2 grab a read-lock on the current snapshot.
   108    108       do_test 1.$tn.2 { sql2 { BEGIN; SELECT x FROM t1 } } {1 2 3}
   109    109   
   110    110       # Attempt a checkpoint.
   111    111       do_test 1.$tn.3 {
   112    112         code1 { do_wal_checkpoint db }

Changes to test/wal9.test.

    59     59   } {}
    60     60   
    61     61   # Check file sizes are as expected. The real requirement here is that 
    62     62   # the *shm file is now more than one chunk (>32KiB).
    63     63   #
    64     64   # The sizes of various files are slightly different in normal and 
    65     65   # auto-vacuum mode.
    66         -do_test 1.3 { file size test.db     } {1024}
           66  +do_test 1.3 { file_page_count test.db } {1}
    67     67   do_test 1.4 { expr {[file size test.db-wal]>(1500*1024)} } {1}
    68     68   do_test 1.5 { expr {[file size test.db-shm]>32768} }       {1}
    69     69   do_test 1.6 { 
    70     70     foreach {a b c} [db eval {PRAGMA wal_checkpoint}] break
    71     71     list [expr {$a==0}] [expr {$b>14500}] [expr {$c>14500}] [expr {$b==$c}]
    72     72   } {1 1 1 1}
    73     73   

Changes to test/walbak.test.

    46     46         INSERT INTO t1 VALUES('I', 'one');
    47     47       COMMIT;
    48     48     }
    49     49   } {wal}
    50     50   do_test walbak-1.1 {
    51     51     forcedelete bak.db bak.db-journal bak.db-wal
    52     52     db backup bak.db
    53         -  file size bak.db
    54         -} [expr 3*1024]
           53  +  file_page_count bak.db
           54  +} 3
    55     55   do_test walbak-1.2 {
    56     56     sqlite3 db2 bak.db
    57     57     execsql { 
    58     58       SELECT * FROM t1;
    59     59       PRAGMA main.journal_mode;
    60     60     } db2
    61     61   } {I one wal}
................................................................................
    69     69   do_test walbak-1.4 {
    70     70     execsql { 
    71     71       VACUUM;
    72     72       PRAGMA main.journal_mode;
    73     73     }
    74     74   } {wal}
    75     75   do_test walbak-1.5 {
    76         -  list [file size test.db] [file size test.db-wal]
    77         -} [list 1024 [wal_file_size 6 1024]]
           76  +  list [file_page_count test.db] [file size test.db-wal]
           77  +} [list 1 [wal_file_size 6 1024]]
    78     78   do_test walbak-1.6 {
    79     79     execsql { PRAGMA wal_checkpoint }
    80     80     list [file size test.db] [file size test.db-wal]
    81     81   } [list [expr 3*1024] [wal_file_size 6 1024]]
    82     82   do_test walbak-1.6.1 {
    83     83     hexio_read test.db 18 2
    84     84   } {0202}

Changes to test/walcksum.test.

   172    172         INSERT INTO t1 VALUES(21, 'twentyone');
   173    173       }
   174    174   
   175    175       forcecopy test.db test2.db
   176    176       forcecopy test.db-wal test2.db-wal
   177    177       db close
   178    178   
   179         -    list [file size test2.db] [file size test2.db-wal]
   180         -  } [list [expr 1024*3] [wal_file_size 6 1024]]
          179  +    list [file_page_count test2.db] [file size test2.db-wal]
          180  +  } [list 3 [wal_file_size 6 1024]]
   181    181   
   182    182     # Verify that the checksums are valid for all frames and that they
   183    183     # are calculated by interpreting data in native byte-order.
   184    184     #
   185    185     for {set f 1} {$f <= 6} {incr f} {
   186    186       do_test walcksum-1.$endian.2.$f {
   187    187         log_checksum_verify test2.db-wal $f $native
................................................................................
   209    209     # endianness as the existing frames. Check that this is the case.
   210    210     #
   211    211     do_test walcksum-1.$endian.5.0 {
   212    212       execsql { 
   213    213         PRAGMA synchronous = NORMAL;
   214    214         INSERT INTO t1 VALUES(34, 'thirtyfour');
   215    215       }
   216         -    list [file size test.db] [file size test.db-wal]
   217         -  } [list [expr 1024*3] [wal_file_size 8 1024]]
          216  +    list [file_page_count test.db] [file size test.db-wal]
          217  +  } [list 3 [wal_file_size 8 1024]]
   218    218     for {set f 1} {$f <= 8} {incr f} {
   219    219       do_test walcksum-1.$endian.5.$f {
   220    220         log_checksum_verify test.db-wal $f $endian
   221    221       } {1}
   222    222     }
   223    223   
   224    224     # Now connect a second connection to the database. Check that this one
................................................................................
   233    233       } db2
   234    234     } {ok 1 2 3 5 8 13 21 34}
   235    235     do_test walcksum-1.$endian.7.0 {
   236    236       execsql { 
   237    237         PRAGMA synchronous = NORMAL;
   238    238         INSERT INTO t1 VALUES(55, 'fiftyfive');
   239    239       } db2
   240         -    list [file size test.db] [file size test.db-wal]
   241         -  } [list [expr 1024*3] [wal_file_size 10 1024]]
          240  +    list [file_page_count test.db] [file size test.db-wal]
          241  +  } [list 3 [wal_file_size 10 1024]]
   242    242     for {set f 1} {$f <= 10} {incr f} {
   243    243       do_test walcksum-1.$endian.7.$f {
   244    244         log_checksum_verify test.db-wal $f $endian
   245    245       } {1}
   246    246     }
   247    247   
   248    248     # Now that both the recoverer and non-recoverer have added frames to the

Changes to test/walhook.test.

    45     45     set ::wal_hook [list]
    46     46     execsql { INSERT INTO t1 VALUES(1, 'one') }
    47     47     set ::wal_hook
    48     48   } {main 5}
    49     49   do_test walhook-1.3 {
    50     50     proc wal_hook {args} { db eval {PRAGMA wal_checkpoint}; return 0 }
    51     51     execsql { INSERT INTO t1 VALUES(2, 'two') }
    52         -  file size test.db
    53         -} [expr 3*1024]
           52  +  file_page_count test.db
           53  +} 3
    54     54   do_test walhook-1.4 {
    55     55     proc wal_hook {zDb nEntry} { 
    56     56       execsql { PRAGMA wal_checkpoint }
    57     57       return 0
    58     58     }
    59     59     execsql { CREATE TABLE t2(a, b) }
    60     60     file size test.db

Changes to test/walmode.test.

    38     38   
    39     39   do_test walmode-1.1 {
    40     40     set sqlite_sync_count 0
    41     41     execsql { PRAGMA page_size = 1024 }
    42     42     execsql { PRAGMA journal_mode = wal }
    43     43   } {wal}
    44     44   do_test walmode-1.2 {
    45         -  file size test.db
    46         -} {1024}
           45  +  file_page_count test.db
           46  +} {1}
    47     47   
    48     48   set expected_sync_count 3
    49     49   if {$::tcl_platform(platform)!="windows"} {
    50     50     ifcapable dirsync {
    51     51       incr expected_sync_count
    52     52     }
    53     53   }
................................................................................
    56     56   } $expected_sync_count
    57     57   
    58     58   do_test walmode-1.4 {
    59     59     file exists test.db-wal
    60     60   } {0}
    61     61   do_test walmode-1.5 {
    62     62     execsql { CREATE TABLE t1(a, b) }
    63         -  file size test.db
    64         -} {1024}
           63  +  file_page_count test.db
           64  +} {1}
    65     65   do_test walmode-1.6 {
    66     66     file exists test.db-wal
    67     67   } {1}
    68     68   do_test walmode-1.7 {
    69     69     db close
    70     70     file exists test.db-wal
    71     71   } {0}