1c318f730Sdrh /*
2c318f730Sdrh ** 2017-10-13
3c318f730Sdrh **
4c318f730Sdrh ** The author disclaims copyright to this source code. In place of
5c318f730Sdrh ** a legal notice, here is a blessing:
6c318f730Sdrh **
7c318f730Sdrh ** May you do good and not evil.
8c318f730Sdrh ** May you find forgiveness for yourself and forgive others.
9c318f730Sdrh ** May you share freely, never taking more than you give.
10c318f730Sdrh **
11c318f730Sdrh *************************************************************************
12c318f730Sdrh **
13c318f730Sdrh ** This file contains extensions to the the "tclsqlite.c" module used for
14c318f730Sdrh ** testing. Basically, all of the other "test_*.c" modules are linked
15c318f730Sdrh ** into the enhanced tclsh used for testing (and named "testfixture" or
16c318f730Sdrh ** "testfixture.exe") using logic encoded by this file.
17c318f730Sdrh **
18c318f730Sdrh ** The code in this file used to be found in tclsqlite3.c, contained within
19c318f730Sdrh ** #if SQLITE_TEST ... #endif. It is factored out into this separate module
20c318f730Sdrh ** in an effort to keep the tclsqlite.c file pure.
21c318f730Sdrh */
22c318f730Sdrh #include "sqlite3.h"
23c318f730Sdrh #if defined(INCLUDE_SQLITE_TCL_H)
24c318f730Sdrh # include "sqlite_tcl.h"
25c318f730Sdrh #else
26c318f730Sdrh # include "tcl.h"
27c318f730Sdrh # ifndef SQLITE_TCLAPI
28c318f730Sdrh # define SQLITE_TCLAPI
29c318f730Sdrh # endif
30c318f730Sdrh #endif
31c318f730Sdrh
32c318f730Sdrh /* Needed for the setrlimit() system call on unix */
33c318f730Sdrh #if defined(unix)
34c318f730Sdrh #include <sys/resource.h>
35c318f730Sdrh #endif
36c318f730Sdrh
37c318f730Sdrh /* Forward declaration */
38c318f730Sdrh static int SQLITE_TCLAPI load_testfixture_extensions(
39c318f730Sdrh ClientData cd,
40c318f730Sdrh Tcl_Interp *interp,
41c318f730Sdrh int objc,
42c318f730Sdrh Tcl_Obj *CONST objv[]
43c318f730Sdrh );
44c318f730Sdrh
45c318f730Sdrh /*
46c318f730Sdrh ** This routine is the primary export of this file.
47c318f730Sdrh **
48c318f730Sdrh ** Configure the interpreter passed as the first argument to have access
49c318f730Sdrh ** to the commands and linked variables that make up:
50c318f730Sdrh **
51c318f730Sdrh ** * the [sqlite3] extension itself,
52c318f730Sdrh **
53c318f730Sdrh ** * If SQLITE_TCLMD5 or SQLITE_TEST is defined, the Md5 commands, and
54c318f730Sdrh **
55c318f730Sdrh ** * If SQLITE_TEST is set, the various test interfaces used by the Tcl
56c318f730Sdrh ** test suite.
57c318f730Sdrh */
sqlite3TestInit(Tcl_Interp * interp)5896a206faSdrh const char *sqlite3TestInit(Tcl_Interp *interp){
59c318f730Sdrh extern int Sqlite3_Init(Tcl_Interp*);
60c318f730Sdrh extern int Sqliteconfig_Init(Tcl_Interp*);
61c318f730Sdrh extern int Sqlitetest1_Init(Tcl_Interp*);
62c318f730Sdrh extern int Sqlitetest2_Init(Tcl_Interp*);
63c318f730Sdrh extern int Sqlitetest3_Init(Tcl_Interp*);
64c318f730Sdrh extern int Sqlitetest4_Init(Tcl_Interp*);
65c318f730Sdrh extern int Sqlitetest5_Init(Tcl_Interp*);
66c318f730Sdrh extern int Sqlitetest6_Init(Tcl_Interp*);
67c318f730Sdrh extern int Sqlitetest7_Init(Tcl_Interp*);
68c318f730Sdrh extern int Sqlitetest8_Init(Tcl_Interp*);
69c318f730Sdrh extern int Sqlitetest9_Init(Tcl_Interp*);
70c318f730Sdrh extern int Sqlitetestasync_Init(Tcl_Interp*);
71c318f730Sdrh extern int Sqlitetest_autoext_Init(Tcl_Interp*);
72c318f730Sdrh extern int Sqlitetest_blob_Init(Tcl_Interp*);
73c318f730Sdrh extern int Sqlitetest_demovfs_Init(Tcl_Interp *);
74c318f730Sdrh extern int Sqlitetest_func_Init(Tcl_Interp*);
75c318f730Sdrh extern int Sqlitetest_hexio_Init(Tcl_Interp*);
76c318f730Sdrh extern int Sqlitetest_init_Init(Tcl_Interp*);
77c318f730Sdrh extern int Sqlitetest_malloc_Init(Tcl_Interp*);
78c318f730Sdrh extern int Sqlitetest_mutex_Init(Tcl_Interp*);
79c318f730Sdrh extern int Sqlitetestschema_Init(Tcl_Interp*);
80c318f730Sdrh extern int Sqlitetestsse_Init(Tcl_Interp*);
81c318f730Sdrh extern int Sqlitetesttclvar_Init(Tcl_Interp*);
82c318f730Sdrh extern int Sqlitetestfs_Init(Tcl_Interp*);
83c318f730Sdrh extern int SqlitetestThread_Init(Tcl_Interp*);
84c318f730Sdrh extern int SqlitetestOnefile_Init();
85c318f730Sdrh extern int SqlitetestOsinst_Init(Tcl_Interp*);
86c318f730Sdrh extern int Sqlitetestbackup_Init(Tcl_Interp*);
87c318f730Sdrh extern int Sqlitetestintarray_Init(Tcl_Interp*);
88c318f730Sdrh extern int Sqlitetestvfs_Init(Tcl_Interp *);
89c318f730Sdrh extern int Sqlitetestrtree_Init(Tcl_Interp*);
9001ed72f2Sdan extern int Sqlitetestrtreedoc_Init(Tcl_Interp*);
91c318f730Sdrh extern int Sqlitequota_Init(Tcl_Interp*);
92c318f730Sdrh extern int Sqlitemultiplex_Init(Tcl_Interp*);
93c318f730Sdrh extern int SqliteSuperlock_Init(Tcl_Interp*);
94c318f730Sdrh extern int SqlitetestSyscall_Init(Tcl_Interp*);
95c318f730Sdrh #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
96c318f730Sdrh extern int TestSession_Init(Tcl_Interp*);
97c318f730Sdrh #endif
98c318f730Sdrh extern int Md5_Init(Tcl_Interp*);
99c318f730Sdrh extern int Fts5tcl_Init(Tcl_Interp *);
100c318f730Sdrh extern int SqliteRbu_Init(Tcl_Interp*);
101c318f730Sdrh extern int Sqlitetesttcl_Init(Tcl_Interp*);
102c318f730Sdrh #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
103c318f730Sdrh extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
104c318f730Sdrh #endif
105c318f730Sdrh #ifdef SQLITE_ENABLE_ZIPVFS
106c318f730Sdrh extern int Zipvfs_Init(Tcl_Interp*);
107c318f730Sdrh #endif
1083d9c7c3aSdan extern int TestExpert_Init(Tcl_Interp*);
109660af939Sdan extern int Sqlitetest_window_Init(Tcl_Interp *);
1101d07f1d8Sdan extern int Sqlitetestvdbecov_Init(Tcl_Interp *);
111*73b09b87Sdan extern int TestRecover_Init(Tcl_Interp*);
1123d9c7c3aSdan
11396a206faSdrh Tcl_CmdInfo cmdInfo;
114c318f730Sdrh
11596a206faSdrh /* Since the primary use case for this binary is testing of SQLite,
11696a206faSdrh ** be sure to generate core files if we crash */
11796a206faSdrh #if defined(unix)
11896a206faSdrh { struct rlimit x;
11996a206faSdrh getrlimit(RLIMIT_CORE, &x);
12096a206faSdrh x.rlim_cur = x.rlim_max;
12196a206faSdrh setrlimit(RLIMIT_CORE, &x);
12296a206faSdrh }
12396a206faSdrh #endif /* unix */
12496a206faSdrh
12596a206faSdrh if( Tcl_GetCommandInfo(interp, "sqlite3", &cmdInfo)==0 ){
126c318f730Sdrh Sqlite3_Init(interp);
12796a206faSdrh }
128c318f730Sdrh #ifdef SQLITE_ENABLE_ZIPVFS
129c318f730Sdrh Zipvfs_Init(interp);
130c318f730Sdrh #endif
131c318f730Sdrh Md5_Init(interp);
132c318f730Sdrh Sqliteconfig_Init(interp);
133c318f730Sdrh Sqlitetest1_Init(interp);
134c318f730Sdrh Sqlitetest2_Init(interp);
135c318f730Sdrh Sqlitetest3_Init(interp);
136c318f730Sdrh Sqlitetest4_Init(interp);
137c318f730Sdrh Sqlitetest5_Init(interp);
138c318f730Sdrh Sqlitetest6_Init(interp);
139c318f730Sdrh Sqlitetest7_Init(interp);
140c318f730Sdrh Sqlitetest8_Init(interp);
141c318f730Sdrh Sqlitetest9_Init(interp);
142c318f730Sdrh Sqlitetestasync_Init(interp);
143c318f730Sdrh Sqlitetest_autoext_Init(interp);
144c318f730Sdrh Sqlitetest_blob_Init(interp);
145c318f730Sdrh Sqlitetest_demovfs_Init(interp);
146c318f730Sdrh Sqlitetest_func_Init(interp);
147c318f730Sdrh Sqlitetest_hexio_Init(interp);
148c318f730Sdrh Sqlitetest_init_Init(interp);
149c318f730Sdrh Sqlitetest_malloc_Init(interp);
150c318f730Sdrh Sqlitetest_mutex_Init(interp);
151c318f730Sdrh Sqlitetestschema_Init(interp);
152c318f730Sdrh Sqlitetesttclvar_Init(interp);
153c318f730Sdrh Sqlitetestfs_Init(interp);
154c318f730Sdrh SqlitetestThread_Init(interp);
155c318f730Sdrh SqlitetestOnefile_Init();
156c318f730Sdrh SqlitetestOsinst_Init(interp);
157c318f730Sdrh Sqlitetestbackup_Init(interp);
158c318f730Sdrh Sqlitetestintarray_Init(interp);
159c318f730Sdrh Sqlitetestvfs_Init(interp);
160c318f730Sdrh Sqlitetestrtree_Init(interp);
16101ed72f2Sdan Sqlitetestrtreedoc_Init(interp);
162c318f730Sdrh Sqlitequota_Init(interp);
163c318f730Sdrh Sqlitemultiplex_Init(interp);
164c318f730Sdrh SqliteSuperlock_Init(interp);
165c318f730Sdrh SqlitetestSyscall_Init(interp);
166c318f730Sdrh #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
167c318f730Sdrh TestSession_Init(interp);
168c318f730Sdrh #endif
169c318f730Sdrh Fts5tcl_Init(interp);
170c318f730Sdrh SqliteRbu_Init(interp);
171c318f730Sdrh Sqlitetesttcl_Init(interp);
172c318f730Sdrh
173c318f730Sdrh #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
174c318f730Sdrh Sqlitetestfts3_Init(interp);
175c318f730Sdrh #endif
1763d9c7c3aSdan TestExpert_Init(interp);
177660af939Sdan Sqlitetest_window_Init(interp);
1781d07f1d8Sdan Sqlitetestvdbecov_Init(interp);
179*73b09b87Sdan TestRecover_Init(interp);
180c318f730Sdrh
181c318f730Sdrh Tcl_CreateObjCommand(
182c318f730Sdrh interp, "load_testfixture_extensions", load_testfixture_extensions,0,0
183c318f730Sdrh );
18496a206faSdrh return 0;
185c318f730Sdrh }
186c318f730Sdrh
187c318f730Sdrh /* tclcmd: load_testfixture_extensions
188c318f730Sdrh */
load_testfixture_extensions(ClientData cd,Tcl_Interp * interp,int objc,Tcl_Obj * CONST objv[])189c318f730Sdrh static int SQLITE_TCLAPI load_testfixture_extensions(
190c318f730Sdrh ClientData cd,
191c318f730Sdrh Tcl_Interp *interp,
192c318f730Sdrh int objc,
193c318f730Sdrh Tcl_Obj *CONST objv[]
194c318f730Sdrh ){
195c318f730Sdrh
196c318f730Sdrh Tcl_Interp *slave;
197c318f730Sdrh if( objc!=2 ){
198c318f730Sdrh Tcl_WrongNumArgs(interp, 1, objv, "SLAVE");
199c318f730Sdrh return TCL_ERROR;
200c318f730Sdrh }
201c318f730Sdrh
202c318f730Sdrh slave = Tcl_GetSlave(interp, Tcl_GetString(objv[1]));
203c318f730Sdrh if( !slave ){
204c318f730Sdrh return TCL_ERROR;
205c318f730Sdrh }
206c318f730Sdrh
20796a206faSdrh (void)sqlite3TestInit(slave);
208c318f730Sdrh return TCL_OK;
209c318f730Sdrh }
210