Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/test_malloc.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2007 August 15 2 ** 2007 August 15
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if( install ){ 204 if( install ){
205 rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memfault.m); 205 rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memfault.m);
206 assert(memfault.m.xMalloc); 206 assert(memfault.m.xMalloc);
207 if( rc==SQLITE_OK ){ 207 if( rc==SQLITE_OK ){
208 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &m); 208 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &m);
209 } 209 }
210 sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 210 sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,
211 faultsimBeginBenign, faultsimEndBenign 211 faultsimBeginBenign, faultsimEndBenign
212 ); 212 );
213 }else{ 213 }else{
214 sqlite3_mem_methods m; 214 sqlite3_mem_methods m2;
215 assert(memfault.m.xMalloc); 215 assert(memfault.m.xMalloc);
216 216
217 /* One should be able to reset the default memory allocator by storing 217 /* One should be able to reset the default memory allocator by storing
218 ** a zeroed allocator then calling GETMALLOC. */ 218 ** a zeroed allocator then calling GETMALLOC. */
219 memset(&m, 0, sizeof(m)); 219 memset(&m2, 0, sizeof(m2));
220 sqlite3_config(SQLITE_CONFIG_MALLOC, &m); 220 sqlite3_config(SQLITE_CONFIG_MALLOC, &m2);
221 sqlite3_config(SQLITE_CONFIG_GETMALLOC, &m); 221 sqlite3_config(SQLITE_CONFIG_GETMALLOC, &m2);
222 assert( memcmp(&m, &memfault.m, sizeof(m))==0 ); 222 assert( memcmp(&m2, &memfault.m, sizeof(m2))==0 );
223 223
224 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m); 224 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m);
225 sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 0, 0); 225 sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,
226 (void*)0, (void*)0);
226 } 227 }
227 228
228 if( rc==SQLITE_OK ){ 229 if( rc==SQLITE_OK ){
229 memfault.isInstalled = 1; 230 memfault.isInstalled = 1;
230 } 231 }
231 return rc; 232 return rc;
232 } 233 }
233 234
234 #ifdef SQLITE_TEST 235 #ifdef SQLITE_TEST
235 236
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 static char *buf = 0; 904 static char *buf = 0;
904 if( objc!=3 ){ 905 if( objc!=3 ){
905 Tcl_WrongNumArgs(interp, 1, objv, "SIZE N"); 906 Tcl_WrongNumArgs(interp, 1, objv, "SIZE N");
906 return TCL_ERROR; 907 return TCL_ERROR;
907 } 908 }
908 if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR; 909 if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR;
909 if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR; 910 if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR;
910 free(buf); 911 free(buf);
911 if( sz<0 ){ 912 if( sz<0 ){
912 buf = 0; 913 buf = 0;
913 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, 0, 0, 0); 914 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, (void*)0, 0, 0);
914 }else{ 915 }else{
915 buf = malloc( sz*N + 1 ); 916 buf = malloc( sz*N + 1 );
916 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, buf, sz, N); 917 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, buf, sz, N);
917 } 918 }
918 pResult = Tcl_NewObj(); 919 pResult = Tcl_NewObj();
919 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc)); 920 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
920 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N)); 921 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
921 Tcl_SetObjResult(interp, pResult); 922 Tcl_SetObjResult(interp, pResult);
922 return TCL_OK; 923 return TCL_OK;
923 } 924 }
924 925
925 /* 926 /*
926 ** Usage: sqlite3_config_pagecache SIZE N 927 ** Usage: sqlite3_config_pagecache SIZE N
927 ** 928 **
928 ** Set the page-cache memory buffer using SQLITE_CONFIG_PAGECACHE. 929 ** Set the page-cache memory buffer using SQLITE_CONFIG_PAGECACHE.
929 ** The buffer is static and is of limited size. N might be 930 ** The buffer is static and is of limited size. N might be
930 ** adjusted downward as needed to accommodate the requested size. 931 ** adjusted downward as needed to accommodate the requested size.
931 ** The revised value of N is returned. 932 ** The revised value of N is returned.
932 ** 933 **
933 ** A negative SIZE causes the buffer pointer to be NULL. 934 ** A negative SIZE causes the buffer pointer to be NULL.
934 */ 935 */
935 static int test_config_pagecache( 936 static int test_config_pagecache(
936 void * clientData, 937 void * clientData,
937 Tcl_Interp *interp, 938 Tcl_Interp *interp,
938 int objc, 939 int objc,
939 Tcl_Obj *CONST objv[] 940 Tcl_Obj *CONST objv[]
940 ){ 941 ){
941 int sz, N, rc; 942 int sz, N;
942 Tcl_Obj *pResult; 943 Tcl_Obj *pRes;
943 static char *buf = 0; 944 static char *buf = 0;
944 if( objc!=3 ){ 945 if( objc!=3 ){
945 Tcl_WrongNumArgs(interp, 1, objv, "SIZE N"); 946 Tcl_WrongNumArgs(interp, 1, objv, "SIZE N");
946 return TCL_ERROR; 947 return TCL_ERROR;
947 } 948 }
948 if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR; 949 if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR;
949 if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR; 950 if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR;
950 free(buf); 951 free(buf);
952 buf = 0;
953
954 /* Set the return value */
955 pRes = Tcl_NewObj();
956 Tcl_ListObjAppendElement(0, pRes, Tcl_NewIntObj(sqlite3GlobalConfig.szPage));
957 Tcl_ListObjAppendElement(0, pRes, Tcl_NewIntObj(sqlite3GlobalConfig.nPage));
958 Tcl_SetObjResult(interp, pRes);
959
951 if( sz<0 ){ 960 if( sz<0 ){
952 buf = 0; 961 sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, 0);
953 rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, 0);
954 }else{ 962 }else{
955 buf = malloc( sz*N ); 963 buf = malloc( sz*N );
956 rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, buf, sz, N); 964 sqlite3_config(SQLITE_CONFIG_PAGECACHE, buf, sz, N);
957 } 965 }
958 pResult = Tcl_NewObj();
959 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
960 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
961 Tcl_SetObjResult(interp, pResult);
962 return TCL_OK; 966 return TCL_OK;
963 } 967 }
964 968
965 /* 969 /*
966 ** Usage: sqlite3_config_alt_pcache INSTALL_FLAG DISCARD_CHANCE PRNG_SEED 970 ** Usage: sqlite3_config_alt_pcache INSTALL_FLAG DISCARD_CHANCE PRNG_SEED
967 ** 971 **
968 ** Set up the alternative test page cache. Install if INSTALL_FLAG is 972 ** Set up the alternative test page cache. Install if INSTALL_FLAG is
969 ** true and uninstall (reverting to the default page cache) if INSTALL_FLAG 973 ** true and uninstall (reverting to the default page cache) if INSTALL_FLAG
970 ** is false. DISCARD_CHANGE is an integer between 0 and 100 inclusive 974 ** is false. DISCARD_CHANGE is an integer between 0 and 100 inclusive
971 ** which determines the chance of discarding a page when unpinned. 100 975 ** which determines the chance of discarding a page when unpinned. 100
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 if( Tcl_GetBooleanFromObj(interp, objv[1], &bUseCis) ){ 1257 if( Tcl_GetBooleanFromObj(interp, objv[1], &bUseCis) ){
1254 return TCL_ERROR; 1258 return TCL_ERROR;
1255 } 1259 }
1256 1260
1257 rc = sqlite3_config(SQLITE_CONFIG_COVERING_INDEX_SCAN, bUseCis); 1261 rc = sqlite3_config(SQLITE_CONFIG_COVERING_INDEX_SCAN, bUseCis);
1258 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); 1262 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
1259 1263
1260 return TCL_OK; 1264 return TCL_OK;
1261 } 1265 }
1262 1266
1267 /*
1268 ** Usage: sqlite3_config_pmasz INTEGER
1269 **
1270 ** Set the minimum PMA size.
1271 */
1272 static int test_config_pmasz(
1273 void * clientData,
1274 Tcl_Interp *interp,
1275 int objc,
1276 Tcl_Obj *CONST objv[]
1277 ){
1278 int rc;
1279 int iPmaSz;
1280
1281 if( objc!=2 ){
1282 Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
1283 return TCL_ERROR;
1284 }
1285 if( Tcl_GetIntFromObj(interp, objv[1], &iPmaSz) ){
1286 return TCL_ERROR;
1287 }
1288
1289 rc = sqlite3_config(SQLITE_CONFIG_PMASZ, iPmaSz);
1290 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
1291
1292 return TCL_OK;
1293 }
1294
1263 1295
1264 /* 1296 /*
1265 ** Usage: sqlite3_dump_memsys3 FILENAME 1297 ** Usage: sqlite3_dump_memsys3 FILENAME
1266 ** sqlite3_dump_memsys5 FILENAME 1298 ** sqlite3_dump_memsys5 FILENAME
1267 ** 1299 **
1268 ** Write a summary of unfreed memsys3 allocations to FILENAME. 1300 ** Write a summary of unfreed memsys3 allocations to FILENAME.
1269 */ 1301 */
1270 static int test_dump_memsys3( 1302 static int test_dump_memsys3(
1271 void * clientData, 1303 void * clientData,
1272 Tcl_Interp *interp, 1304 Tcl_Interp *interp,
(...skipping 30 matching lines...) Expand all
1303 ** Return a list of three elements which are the sqlite3_status() return 1335 ** Return a list of three elements which are the sqlite3_status() return
1304 ** code, the current value, and the high-water mark value. 1336 ** code, the current value, and the high-water mark value.
1305 */ 1337 */
1306 static int test_status( 1338 static int test_status(
1307 void * clientData, 1339 void * clientData,
1308 Tcl_Interp *interp, 1340 Tcl_Interp *interp,
1309 int objc, 1341 int objc,
1310 Tcl_Obj *CONST objv[] 1342 Tcl_Obj *CONST objv[]
1311 ){ 1343 ){
1312 int rc, iValue, mxValue; 1344 int rc, iValue, mxValue;
1313 int i, op, resetFlag; 1345 int i, op = 0, resetFlag;
1314 const char *zOpName; 1346 const char *zOpName;
1315 static const struct { 1347 static const struct {
1316 const char *zName; 1348 const char *zName;
1317 int op; 1349 int op;
1318 } aOp[] = { 1350 } aOp[] = {
1319 { "SQLITE_STATUS_MEMORY_USED", SQLITE_STATUS_MEMORY_USED }, 1351 { "SQLITE_STATUS_MEMORY_USED", SQLITE_STATUS_MEMORY_USED },
1320 { "SQLITE_STATUS_MALLOC_SIZE", SQLITE_STATUS_MALLOC_SIZE }, 1352 { "SQLITE_STATUS_MALLOC_SIZE", SQLITE_STATUS_MALLOC_SIZE },
1321 { "SQLITE_STATUS_PAGECACHE_USED", SQLITE_STATUS_PAGECACHE_USED }, 1353 { "SQLITE_STATUS_PAGECACHE_USED", SQLITE_STATUS_PAGECACHE_USED },
1322 { "SQLITE_STATUS_PAGECACHE_OVERFLOW", SQLITE_STATUS_PAGECACHE_OVERFLOW }, 1354 { "SQLITE_STATUS_PAGECACHE_OVERFLOW", SQLITE_STATUS_PAGECACHE_OVERFLOW },
1323 { "SQLITE_STATUS_PAGECACHE_SIZE", SQLITE_STATUS_PAGECACHE_SIZE }, 1355 { "SQLITE_STATUS_PAGECACHE_SIZE", SQLITE_STATUS_PAGECACHE_SIZE },
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 ** Return a list of three elements which are the sqlite3_db_status() return 1392 ** Return a list of three elements which are the sqlite3_db_status() return
1361 ** code, the current value, and the high-water mark value. 1393 ** code, the current value, and the high-water mark value.
1362 */ 1394 */
1363 static int test_db_status( 1395 static int test_db_status(
1364 void * clientData, 1396 void * clientData,
1365 Tcl_Interp *interp, 1397 Tcl_Interp *interp,
1366 int objc, 1398 int objc,
1367 Tcl_Obj *CONST objv[] 1399 Tcl_Obj *CONST objv[]
1368 ){ 1400 ){
1369 int rc, iValue, mxValue; 1401 int rc, iValue, mxValue;
1370 int i, op, resetFlag; 1402 int i, op = 0, resetFlag;
1371 const char *zOpName; 1403 const char *zOpName;
1372 sqlite3 *db; 1404 sqlite3 *db;
1373 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); 1405 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
1374 static const struct { 1406 static const struct {
1375 const char *zName; 1407 const char *zName;
1376 int op; 1408 int op;
1377 } aOp[] = { 1409 } aOp[] = {
1378 { "LOOKASIDE_USED", SQLITE_DBSTATUS_LOOKASIDE_USED }, 1410 { "LOOKASIDE_USED", SQLITE_DBSTATUS_LOOKASIDE_USED },
1379 { "CACHE_USED", SQLITE_DBSTATUS_CACHE_USED }, 1411 { "CACHE_USED", SQLITE_DBSTATUS_CACHE_USED },
1380 { "SCHEMA_USED", SQLITE_DBSTATUS_SCHEMA_USED }, 1412 { "SCHEMA_USED", SQLITE_DBSTATUS_SCHEMA_USED },
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 { "sqlite3_status", test_status ,0 }, 1539 { "sqlite3_status", test_status ,0 },
1508 { "sqlite3_db_status", test_db_status ,0 }, 1540 { "sqlite3_db_status", test_db_status ,0 },
1509 { "install_malloc_faultsim", test_install_malloc_faultsim ,0 }, 1541 { "install_malloc_faultsim", test_install_malloc_faultsim ,0 },
1510 { "sqlite3_config_heap", test_config_heap ,0 }, 1542 { "sqlite3_config_heap", test_config_heap ,0 },
1511 { "sqlite3_config_heap_size", test_config_heap_size ,0 }, 1543 { "sqlite3_config_heap_size", test_config_heap_size ,0 },
1512 { "sqlite3_config_memstatus", test_config_memstatus ,0 }, 1544 { "sqlite3_config_memstatus", test_config_memstatus ,0 },
1513 { "sqlite3_config_lookaside", test_config_lookaside ,0 }, 1545 { "sqlite3_config_lookaside", test_config_lookaside ,0 },
1514 { "sqlite3_config_error", test_config_error ,0 }, 1546 { "sqlite3_config_error", test_config_error ,0 },
1515 { "sqlite3_config_uri", test_config_uri ,0 }, 1547 { "sqlite3_config_uri", test_config_uri ,0 },
1516 { "sqlite3_config_cis", test_config_cis ,0 }, 1548 { "sqlite3_config_cis", test_config_cis ,0 },
1549 { "sqlite3_config_pmasz", test_config_pmasz ,0 },
1517 { "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 }, 1550 { "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 },
1518 { "sqlite3_dump_memsys3", test_dump_memsys3 ,3 }, 1551 { "sqlite3_dump_memsys3", test_dump_memsys3 ,3 },
1519 { "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }, 1552 { "sqlite3_dump_memsys5", test_dump_memsys3 ,5 },
1520 { "sqlite3_install_memsys3", test_install_memsys3 ,0 }, 1553 { "sqlite3_install_memsys3", test_install_memsys3 ,0 },
1521 { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test ,0 }, 1554 { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test ,0 },
1522 }; 1555 };
1523 int i; 1556 int i;
1524 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ 1557 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
1525 ClientData c = (ClientData)SQLITE_INT_TO_PTR(aObjCmd[i].clientData); 1558 ClientData c = (ClientData)SQLITE_INT_TO_PTR(aObjCmd[i].clientData);
1526 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0); 1559 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0);
1527 } 1560 }
1528 return TCL_OK; 1561 return TCL_OK;
1529 } 1562 }
1530 #endif 1563 #endif
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/test_loadext.c ('k') | third_party/sqlite/sqlite-src-3100200/src/test_multiplex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698