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