interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / mmapleak.test

81 lines · 1847 bytes Raw Blame History
1# 2026 October 13
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# This file tests that growing an mmap() mapping of a database file
13# whose page-size is not a multiple of the OS page size does not leak
14# mappings in HAVE_MREMAP=0 builds.
15#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19set testprefix mmapleak
20
21ifcapable !mmap {
22 finish_test
23 return
24}
25if {![file readable /proc/self/maps]} {
26 finish_test
27 return
28}
29
30# Return the number of entries in /proc/self/maps for test.db
31#
32proc n_db_mappings {} {
33 set path [file normalize test.db]
34 set fd [open /proc/self/maps]
35 set n 0
36 foreach line [split [read $fd] "\n"] {
37 if {[string match "*$path*" $line]} { incr n }
38 }
39 close $fd
40 return $n
41}
42
43do_execsql_test 1.0 {
44 PRAGMA page_size = 512;
45 PRAGMA mmap_size = 10000000;
46 CREATE TABLE t1(x);
47} {10000000}
48
49for {set ii 0} {$ii < 100} {incr ii} {
50 do_execsql_test 1.$ii.1 {
51 INSERT INTO t1 VALUES(randomblob(700));
52 SELECT count(*) FROM t1;
53 } [expr $ii+1]
54
55 do_test 1.$ii.2 { n_db_mappings } 1
56}
57
58reset_db
59do_execsql_test 2.0 {
60 PRAGMA page_size = 512;
61 PRAGMA auto_vacuum = full;
62 PRAGMA mmap_size = 10000000;
63 CREATE TABLE t1(x);
64} {10000000}
65
66for {set ii 0} {$ii < 10} {incr ii} {
67 do_execsql_test 2.$ii.1 {
68 WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<20)
69 INSERT INTO t1 SELECT randomblob(700) FROM s;
70 SELECT count(*) FROM t1;
71 } 20
72
73 do_execsql_test 2.$ii.2 {
74 DELETE FROM t1;
75 SELECT count(*) FROM t1;
76 } 0
77
78 do_test 2.$ii.3 { n_db_mappings } 1
79}
80
81finish_test