Add extra tests to threadtest3.

FossilOrigin-Name: f6bf86f907cbff31bed3cbfc922c10c973575498
This commit is contained in:
dan 2014-12-12 16:39:38 +00:00
parent ef15c6e9e6
commit 0420954606
7 changed files with 288 additions and 25 deletions

12
main.mk
View File

@ -625,9 +625,15 @@ test: testfixture$(EXE) sqlite3$(EXE)
# threadtest runs a few thread-safety tests that are implemented in C. This
# target is invoked by the releasetest.tcl script.
#
threadtest3$(EXE): sqlite3.o $(TOP)/test/threadtest3.c $(TOP)/test/tt3_checkpoint.c
$(TCCX) -O2 sqlite3.o $(TOP)/test/threadtest3.c \
-o threadtest3$(EXE) $(THREADLIB)
THREADTEST3_SRC = $(TOP)/test/threadtest3.c \
$(TOP)/test/tt3_checkpoint.c \
$(TOP)/test/tt3_index.c \
$(TOP)/test/tt3_vacuum.c \
$(TOP)/test/tt3_stress.c \
$(TOP)/test/tt3_lookaside1.c
threadtest3$(EXE): sqlite3.o $(THREADTEST3_SRC)
$(TCCX) $(TOP)/test/threadtest3.c sqlite3.o -o $@ $(THREADLIB)
threadtest: threadtest3$(EXE)
./threadtest3$(EXE)

View File

@ -1,5 +1,5 @@
C Add\snew\stests\sto\sthe\sthreadtest4.c\sprogram.\s\sFix\sa\slong-standing\sdata\srace\nin\sWAL\smode\sfor\sshared-cache.
D 2014-12-12T01:27:17.213
C Add\sextra\stests\sto\sthreadtest3.
D 2014-12-12T16:39:38.824
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 6c4f961fa91d0b4fa121946a19f9e5eac2f2f809
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -152,7 +152,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
F main.mk 084976077a4aa3bd985154b5423e7aed88e4a2e9
F main.mk 9f8c54fe62b60e0a24a2e65cfc8d2add063dda07
F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea
F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
@ -912,7 +912,7 @@ F test/thread2.test f35d2106452b77523b3a2b7d1dcde2e5ee8f9e46
F test/thread_common.tcl 334639cadcb9f912bf82aa73f49efd5282e6cadd
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9
F test/threadtest3.c 2b6e07e915c383c250a5b531cf6ef163a3047d7e
F test/threadtest3.c bef2bde18b4e638b6cf4b119aa2076123ffdc425
F test/threadtest4.c 1678c340387c19ae28b18e4d8f71d4a989297e46
F test/tkt-02a8e81d44.test 6c80d9c7514e2a42d4918bf87bf6bc54f379110c
F test/tkt-26ff0c2d1e.test 888324e751512972c6e0d1a09df740d8f5aaf660
@ -1077,8 +1077,10 @@ F test/triggerC.test a68980c5955d62ee24be6f97129d824f199f9a4c
F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650
F test/triggerE.test 355e9c5cbaed5cd039a60baad1fb2197caeb8e52
F test/tt3_checkpoint.c 415eccce672d681b297485fc20f44cdf0eac93af
F test/tt3_index.c 14f4b0cc3f4c05353e25778cf531c9d6e3b0d27f
F test/tt3_index.c 652630e6b6fc7a48adf2ead60de1ef48e1a34569
F test/tt3_lookaside1.c 0b5b79ba37f21a1eb849cd4a54eed367f4d4aaaf
F test/tt3_stress.c e003a8486ba990c43dc9b8298f4b266cd10eb1c1
F test/tt3_vacuum.c 6a66e52e2b39fc0cccb71db5a302411f34d09736
F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a
@ -1229,7 +1231,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 03c443eaf24413d6faaa91a33575d9dfd3528b5c
R 7d057661252570fbf3877a000bcb607e
U drh
Z 24d2ddd2be9b77d0c401fa6e4cbdad23
P d8d3e6d04cbb9e3033ad8613e3dbd4ad0b01765a
R 2ae2d517339c22d48400a669b2098fec
U dan
Z 951a78f63dc9b91d226749536e3eb614

View File

@ -1 +1 @@
d8d3e6d04cbb9e3033ad8613e3dbd4ad0b01765a
f6bf86f907cbff31bed3cbfc922c10c973575498

View File

@ -1399,6 +1399,8 @@ static void dynamic_triggers(int nMs){
#include "tt3_checkpoint.c"
#include "tt3_index.c"
#include "tt3_lookaside1.c"
#include "tt3_vacuum.c"
#include "tt3_stress.c"
int main(int argc, char **argv){
struct ThreadTest {
@ -1420,7 +1422,9 @@ int main(int argc, char **argv){
{ checkpoint_starvation_2, "checkpoint_starvation_2", 10000 },
{ create_drop_index_1, "create_drop_index_1", 10000 },
{ lookaside1, "lookaside1", 10000 },
{ lookaside1, "lookaside1", 10000 },
{ vacuum1, "vacuum1", 10000 },
{ stress1, "stress1", 10000 },
};
int i;

View File

@ -22,22 +22,22 @@ static char *create_drop_index_thread(int iTid, int iArg){
opendb(&err, &db, "test.db", 0);
sql_script(&err, &db,
"DROP INDEX IF EXISTS i1;"
"DROP INDEX IF EXISTS i2;"
"DROP INDEX IF EXISTS i3;"
"DROP INDEX IF EXISTS i4;"
"CREATE INDEX IF NOT EXISTS i1 ON t1(a);"
"CREATE INDEX IF NOT EXISTS i2 ON t1(b);"
"CREATE INDEX IF NOT EXISTS i3 ON t1(c);"
"CREATE INDEX IF NOT EXISTS i4 ON t1(d);"
"CREATE INDEX IF NOT EXISTS i1 ON t11(a);"
"CREATE INDEX IF NOT EXISTS i2 ON t11(b);"
"CREATE INDEX IF NOT EXISTS i3 ON t11(c);"
"CREATE INDEX IF NOT EXISTS i4 ON t11(d);"
"SELECT * FROM t1 ORDER BY a;"
"SELECT * FROM t1 ORDER BY b;"
"SELECT * FROM t1 ORDER BY c;"
"SELECT * FROM t1 ORDER BY d;"
"SELECT * FROM t11 ORDER BY a;"
"SELECT * FROM t11 ORDER BY b;"
"SELECT * FROM t11 ORDER BY c;"
"SELECT * FROM t11 ORDER BY d;"
);
clear_error(&err, SQLITE_LOCKED);
closedb(&err, &db);
}
@ -53,9 +53,9 @@ static void create_drop_index_1(int nMs){
opendb(&err, &db, "test.db", 1);
sql_script(&err, &db,
"CREATE TABLE t1(a, b, c, d);"
"CREATE TABLE t11(a, b, c, d);"
"WITH data(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM data WHERE x<100) "
"INSERT INTO t1 SELECT x,x,x,x FROM data;"
"INSERT INTO t11 SELECT x,x,x,x FROM data;"
);
closedb(&err, &db);

161
test/tt3_stress.c Normal file
View File

@ -0,0 +1,161 @@
/*
** 2014 December 9
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
**
*/
/*
** Thread 1. CREATE and DROP a table.
*/
static char *stress_thread_1(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0);
while( !timetostop(&err) ){
sql_script(&err, &db, "CREATE TABLE IF NOT EXISTS t1(a PRIMARY KEY, b)");
clear_error(&err, SQLITE_LOCKED);
sql_script(&err, &db, "DROP TABLE IF EXISTS t1");
clear_error(&err, SQLITE_LOCKED);
}
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
/*
** Thread 2. Open and close database connections.
*/
static char *stress_thread_2(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
while( !timetostop(&err) ){
opendb(&err, &db, "test.db", 0);
sql_script(&err, &db, "SELECT * FROM sqlite_master;");
clear_error(&err, SQLITE_LOCKED);
closedb(&err, &db);
}
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
/*
** Thread 3. Attempt many small SELECT statements.
*/
static char *stress_thread_3(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
int i1 = 0;
int i2 = 0;
opendb(&err, &db, "test.db", 0);
while( !timetostop(&err) ){
sql_script(&err, &db, "SELECT * FROM t1 ORDER BY a;");
i1++;
if( err.rc ) i2++;
clear_error(&err, SQLITE_LOCKED);
clear_error(&err, SQLITE_ERROR);
}
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("read t1 %d/%d attempts", i2, i1);
}
/*
** Thread 5. Attempt INSERT statements.
*/
static char *stress_thread_4(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
int i1 = 0;
int i2 = 0;
opendb(&err, &db, "test.db", 0);
while( !timetostop(&err) ){
if( iArg ){
closedb(&err, &db);
opendb(&err, &db, "test.db", 0);
}
sql_script(&err, &db,
"WITH loop(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM loop LIMIT 200) "
"INSERT INTO t1 VALUES(randomblob(60), randomblob(60));"
);
i1++;
if( err.rc ) i2++;
clear_error(&err, SQLITE_LOCKED);
clear_error(&err, SQLITE_ERROR);
}
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("wrote t1 %d/%d attempts", i2, i1);
}
/*
** Thread 6. Attempt DELETE operations.
*/
static char *stress_thread_5(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
int i1 = 0;
int i2 = 0;
opendb(&err, &db, "test.db", 0);
while( !timetostop(&err) ){
i64 i = (i1 % 4);
if( iArg ){
closedb(&err, &db);
opendb(&err, &db, "test.db", 0);
}
execsql(&err, &db, "DELETE FROM t1 WHERE (rowid % 4)==:i", &i);
i1++;
if( err.rc ) i2++;
clear_error(&err, SQLITE_LOCKED);
clear_error(&err, SQLITE_ERROR);
}
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("deleted from t1 %d/%d attempts", i2, i1);
}
static void stress1(int nMs){
Error err = {0};
Sqlite db = {0};
Threadset threads = {0};
setstoptime(&err, nMs);
sqlite3_enable_shared_cache(1);
launch_thread(&err, &threads, stress_thread_1, 0);
launch_thread(&err, &threads, stress_thread_1, 0);
launch_thread(&err, &threads, stress_thread_2, 0);
launch_thread(&err, &threads, stress_thread_2, 0);
launch_thread(&err, &threads, stress_thread_3, 0);
launch_thread(&err, &threads, stress_thread_3, 0);
launch_thread(&err, &threads, stress_thread_4, 0);
launch_thread(&err, &threads, stress_thread_4, 0);
launch_thread(&err, &threads, stress_thread_5, 0);
launch_thread(&err, &threads, stress_thread_5, 1);
join_all_threads(&err, &threads);
sqlite3_enable_shared_cache(0);
print_and_free_err(&err);
}

90
test/tt3_vacuum.c Normal file
View File

@ -0,0 +1,90 @@
/*
** 2014 December 9
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains multi-threaded tests that use shared-cache and
** the VACUUM command.
**
** Tests:
**
** vacuum1
**
*/
static char *vacuum1_thread_writer(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0);
i64 i = 0;
while( !timetostop(&err) ){
i++;
/* Insert lots of rows. Then delete some. */
execsql(&err, &db,
"WITH loop(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM loop WHERE i<100) "
"INSERT INTO t1 SELECT randomblob(50), randomblob(2500) FROM loop"
);
/* Delete lots of rows */
execsql(&err, &db, "DELETE FROM t1 WHERE rowid = :i", &i);
clear_error(&err, SQLITE_LOCKED);
/* Select the rows */
execsql(&err, &db, "SELECT * FROM t1 ORDER BY x");
clear_error(&err, SQLITE_LOCKED);
}
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
static char *vacuum1_thread_vacuumer(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0);
do{
sql_script(&err, &db, "VACUUM");
clear_error(&err, SQLITE_LOCKED);
}while( !timetostop(&err) );
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
static void vacuum1(int nMs){
Error err = {0};
Sqlite db = {0};
Threadset threads = {0};
opendb(&err, &db, "test.db", 1);
sql_script(&err, &db,
"CREATE TABLE t1(x PRIMARY KEY, y BLOB);"
"CREATE INDEX i1 ON t1(y);"
);
closedb(&err, &db);
setstoptime(&err, nMs);
sqlite3_enable_shared_cache(1);
launch_thread(&err, &threads, vacuum1_thread_writer, 0);
launch_thread(&err, &threads, vacuum1_thread_writer, 0);
launch_thread(&err, &threads, vacuum1_thread_writer, 0);
launch_thread(&err, &threads, vacuum1_thread_vacuumer, 0);
join_all_threads(&err, &threads);
sqlite3_enable_shared_cache(0);
print_and_free_err(&err);
}