Skip to content

Commit d10887d

Browse files
committed
Tests: Test for expected SQLite3 cache size
Signed-off-by: DL6ER <[email protected]>
1 parent 4ed7397 commit d10887d

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
2828
# SQLITE_DQS=0: This setting disables the double-quoted string literal misfeature.
2929
# SQLITE_ENABLE_DBPAGE_VTAB: Enables the SQLITE_DBPAGE virtual table. Warning: writing to the SQLITE_DBPAGE virtual table can very easily cause unrecoverably database corruption.
3030
# SQLITE_OMIT_DESERIALIZE: This option causes the the sqlite3_serialize() and sqlite3_deserialize() interfaces to be omitted from the build (was the default before 3.36.0)
31-
# HAVE_READLINE: Enable readline support to allow easy editing, history and auto-completion7
31+
# HAVE_READLINE: Enable readline support to allow easy editing, history and auto-completion
3232
# SQLITE_DEFAULT_CACHE_SIZE=-16384: Allow up to 16 MiB of cache to be used by SQLite3 (default is 2000 kiB)
3333
set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_OMIT_DESERIALIZE -DHAVE_READLINE -DSQLITE_DEFAULT_CACHE_SIZE=-16384")
3434

src/database/common.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ sqlite3* _dbopen(bool create, const char *func, const int line, const char *file
112112

113113
// Print database cache size when DEBUG_DATABASE is set
114114
if(config.debug & DEBUG_DATABASE)
115-
print_cache_size(db);
115+
print_cache_size("FTL", db);
116116

117117
return db;
118118
}
@@ -665,11 +665,11 @@ static int get_cache_size(sqlite3 *db)
665665
return result;
666666
}
667667

668-
void print_cache_size(sqlite3 *db)
668+
void print_cache_size(const char *name, sqlite3 *db)
669669
{
670670
const int cs = get_cache_size(db);
671671
if(cs < 0)
672-
logg("Gravity database cache size is %.1f MiB", -1.0*cs/1024);
672+
logg("%s database cache size is %.1f MiB", name, -1.0*cs/1024);
673673
else
674-
logg("Gravity database cache size is %d", cs);
675-
}
674+
logg("%s database cache size is %d", name, cs);
675+
}

src/database/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void SQLite3LogCallback(void *pArg, int iErrCode, const char *zMsg);
4343
long int get_max_query_ID(sqlite3 *db);
4444
bool db_update_counters(sqlite3 *db, const int total, const int blocked);
4545
const char *get_sqlite3_version(void);
46-
void print_cache_size(sqlite3 *db);
46+
void print_cache_size(const char *name, sqlite3 *db);
4747

4848
extern long int lastdbindex;
4949
extern bool DBdeleteoldqueries;

src/database/gravity-db.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool gravityDB_open(void)
144144

145145
// Print database cache size when DEBUG_DATABASE is set
146146
if(config.debug & DEBUG_DATABASE)
147-
print_cache_size(gravity_db);
147+
print_cache_size("Gravity", gravity_db);
148148

149149
// Prepare audit statement
150150
if(config.debug & DEBUG_DATABASE)

test/test_suite.bats

+7
Original file line numberDiff line numberDiff line change
@@ -1407,3 +1407,10 @@
14071407
[[ "$firstnum" == 7 ]]
14081408
[[ "$lastnum" == 7 ]]
14091409
}
1410+
1411+
@test "SQLite3 cache size as expected" {
1412+
# Get number of lines in the log before the test
1413+
cache_size_total_mentionings="$(grep -c "database cache size is" /var/log/pihole/FTL.log)"
1414+
cache_size_corect_mentionings="$(grep -c "database cache size is 16.0 MiB" /var/log/pihole/FTL.log)"
1415+
[[ "$cache_size_total_mentionings" == "$cache_size_corect_mentionings" ]]
1416+
}

0 commit comments

Comments
 (0)