Add tests so that the "coverage-sorter" test permutation covers all branches in vdbesort.c. Fix a few minor problems in the same file.

FossilOrigin-Name: bde28b702dabd02269e333535cc41481351c5efc
This commit is contained in:
dan 2014-05-05 09:08:54 +00:00
parent f7f425d600
commit d94d4ee7bd
7 changed files with 178 additions and 53 deletions

View File

@ -312,6 +312,7 @@ TESTSRC2 = \
$(TOP)/src/pcache.c \
$(TOP)/src/pcache1.c \
$(TOP)/src/select.c \
$(TOP)/src/threads.c \
$(TOP)/src/tokenize.c \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \

View File

@ -1,5 +1,5 @@
C Add\san\sextra\sfault-injection\stest\sto\ssortfault.test.\sRemove\san\sunreachable\sbranch\sfrom\svdbesort.c.
D 2014-05-03T20:43:13.986
C Add\stests\sso\sthat\sthe\s"coverage-sorter"\stest\spermutation\scovers\sall\sbranches\sin\svdbesort.c.\sFix\sa\sfew\sminor\sproblems\sin\sthe\ssame\sfile.
D 2014-05-05T09:08:54.007
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in ad0921c4b2780d01868cf69b419a4f102308d125
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -144,7 +144,7 @@ F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt f439556c5ce01ced70987e5ee86549a45165d9ff
F main.mk 97673939d94f210b7218a8236df6c8799d4a0da6
F main.mk f51f401a87fd07be255bcecae8b03105ca2024e8
F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea
F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
@ -273,7 +273,7 @@ F src/test_thread.c 1e133a40b50e9c035b00174035b846e7eef481cb
F src/test_vfs.c e72f555ef7a59080f898fcf1a233deb9eb704ea9
F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c e35de159f9ced746266ff4b2129b7a828e59119c
F src/threads.c b9daffcb6ae3a9c080da37b905e790d45a8f99db
F src/tokenize.c 6da2de6e12218ccb0aea5184b56727d011f4bee7
F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb
F src/update.c 5b3e74a03b3811e586b4f2b4cbd7c49f01c93115
@ -287,7 +287,7 @@ F src/vdbeapi.c 0ed6053f947edd0b30f64ce5aeb811872a3450a4
F src/vdbeaux.c 44d4d1f5711f71eaf0d624de5c3e4976fe4e180b
F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac
F src/vdbemem.c 6fc77594c60f6155404f3f8d71bf36d1fdeb4447
F src/vdbesort.c db67b5b54c476163f3068a194a734c394ecb675e
F src/vdbesort.c af752fa4c125ab2bfeee1c4e0b50504e79aa7051
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8
@ -821,10 +821,10 @@ F test/skipscan1.test bed8cbe9d554c8c27afb6c88500f704c86a9196f
F test/skipscan2.test d77f79cdbba25f0f6f35298136cff21a7d7a553a
F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24
F test/sort.test 2af626b7963eddb8c93b6c87babf81396c379ef5
F test/sort.test 688468cef8c9a66fcc1d54235de8e4deac745690
F test/sort2.test c5e25eb674689e291d06b5209fe8d337ae0ec010
F test/sort3.test 6178ade30810ac9166fcdf14b7065e49c0f534e2
F test/sortfault.test f2f94227d97f7efb6351aff29e77498e877d6216
F test/sortfault.test 1a12b6e27d475f50658a8164aaa34f0080a86b36
F test/speed1.test f2974a91d79f58507ada01864c0e323093065452
F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
F test/speed1p.test b180e98609c7677382cf618c0ec9b69f789033a8
@ -1170,7 +1170,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 32ccf3ae18531682dfd039fa8df6ad9a907ac455
R 5ede29f57c1094d89ff6cfb82c23c871
P a33a366ba8a0da81ddd895d552a348441ef8529a
R 48fa4af9d614a9372c1dc3ff956ba091
U dan
Z 83a8a7f60269415a80d26ca6a02bda49
Z 1076615c7d8998a9f1b953b2c0f517bb

View File

@ -1 +1 @@
a33a366ba8a0da81ddd895d552a348441ef8529a
bde28b702dabd02269e333535cc41481351c5efc

View File

@ -208,6 +208,7 @@ int sqlite3ThreadCreate(
/* Get the results of the thread */
int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
assert( ppOut!=0 );
if( p==0 ) return SQLITE_NOMEM;
if( p->xTask ){
@ -216,6 +217,15 @@ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
*ppOut = p->pResult;
}
sqlite3_free(p);
#if defined(SQLITE_TEST)
{
void *pTstAlloc = sqlite3Malloc(10);
if (!pTstAlloc) return SQLITE_NOMEM;
sqlite3_free(pTstAlloc);
}
#endif
return SQLITE_OK;
}

View File

@ -1251,11 +1251,10 @@ static int vdbeSorterSort(SortSubtask *pTask, SorterList *pList){
pList->pList = p;
sqlite3_free(aSlot);
if( pTask->pUnpacked->errCode ){
assert( pTask->pUnpacked->errCode==SQLITE_NOMEM );
return SQLITE_NOMEM;
}
return SQLITE_OK;
assert( pTask->pUnpacked->errCode==SQLITE_OK
|| pTask->pUnpacked->errCode==SQLITE_NOMEM
);
return pTask->pUnpacked->errCode;
}
/*
@ -1485,7 +1484,7 @@ static int vdbeSorterNext(
*pbEof = (pMerger->aIter[pMerger->aTree[1]].pFile==0);
}
return rc;
return (rc==SQLITE_OK ? pTask->pUnpacked->errCode : rc);
}
#if SQLITE_MAX_WORKER_THREADS>0
@ -1534,7 +1533,7 @@ static int vdbeSorterFlushPMA(VdbeSorter *pSorter){
if( pTask->bDone ){
rc = vdbeSorterJoinThread(pTask);
}
if( pTask->pThread==0 || rc!=SQLITE_OK ) break;
if( rc!=SQLITE_OK || pTask->pThread==0 ) break;
}
if( rc==SQLITE_OK ){
@ -1864,7 +1863,7 @@ static int vdbeIncrInitMerger(
rc = vdbeSorterDoCompare(pTask, pMerger, i);
}
return rc;
return (rc==SQLITE_OK ? pTask->pUnpacked->errCode : rc);
}
/*
@ -2074,9 +2073,10 @@ static int vdbeSorterAddToTree(
rc = vdbeIncrNew(pTask, pNew, &pIter->pIncr);
}
}
p = pIter->pIncr->pMerger;
nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
if( rc==SQLITE_OK ){
p = pIter->pIncr->pMerger;
nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
}
}
if( rc==SQLITE_OK ){
@ -2178,6 +2178,7 @@ static int vdbeSorterSetupMerge(VdbeSorter *pSorter){
rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
if( rc==SQLITE_OK ){
#if SQLITE_MAX_WORKER_THREADS
assert( pSorter->bUseThreads==0 || pSorter->nTask>1 );
if( pSorter->bUseThreads ){
int iTask;
PmaReader *pIter;
@ -2199,16 +2200,14 @@ static int vdbeSorterSetupMerge(VdbeSorter *pSorter){
assert( pIncr->pTask!=pLast );
}
}
if( pSorter->nTask>1 ){
for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
PmaReader *p = &pMain->aIter[iTask];
assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
if( p->pIncr ){
if( iTask==pSorter->nTask-1 ){
rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
}else{
rc = vdbePmaReaderBgIncrInit(p);
}
for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
PmaReader *p = &pMain->aIter[iTask];
assert( p->pIncr==0 || p->pIncr->pTask==&pSorter->aTask[iTask] );
if( p->pIncr ){
if( iTask==pSorter->nTask-1 ){
rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
}else{
rc = vdbePmaReaderBgIncrInit(p);
}
}
}
@ -2216,8 +2215,7 @@ static int vdbeSorterSetupMerge(VdbeSorter *pSorter){
pMain = 0;
}
if( rc==SQLITE_OK ){
int eMode = (pSorter->nTask>1 ? INCRINIT_ROOT : INCRINIT_NORMAL);
rc = vdbePmaReaderIncrInit(pIter, eMode);
rc = vdbePmaReaderIncrInit(pIter, INCRINIT_ROOT);
}
}else
#endif
@ -2259,10 +2257,12 @@ int sqlite3VdbeSorterRewind(const VdbeCursor *pCsr, int *pbEof){
return rc;
}
/* Write the current in-memory list to a PMA. */
if( pSorter->list.pList ){
rc = vdbeSorterFlushPMA(pSorter);
}
/* Write the current in-memory list to a PMA. When the VdbeSorterWrite()
** function flushes the contents of memory to disk, it immediately always
** creates a new list consisting of a single key immediately afterwards.
** So the list is never empty at this point. */
assert( pSorter->list.pList );
rc = vdbeSorterFlushPMA(pSorter);
/* Join all threads */
rc = vdbeSorterJoinAll(pSorter, rc);

View File

@ -533,12 +533,14 @@ foreach {tn mmap_limit} {
#-------------------------------------------------------------------------
#
foreach {tn mmap_limit nWorker tmpstore coremutex fakeheap} {
1 0 3 file true false
2 0 3 file true true
3 0 0 file true false
4 1000000 3 file true false
5 0 0 memory false true
foreach {tn mmap_limit nWorker tmpstore coremutex fakeheap softheaplimit} {
1 0 3 file true false 0
2 0 3 file true true 0
3 0 0 file true false 0
4 1000000 3 file true false 0
5 0 0 memory false true 0
6 0 0 file false true 1000000
7 0 0 file false true 10000
} {
db close
sqlite3_shutdown
@ -550,6 +552,7 @@ foreach {tn mmap_limit nWorker tmpstore coremutex fakeheap} {
}
sqlite3_initialize
sorter_test_fakeheap $fakeheap
sqlite3_soft_heap_limit $softheaplimit
reset_db
sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $mmap_limit
@ -558,8 +561,13 @@ foreach {tn mmap_limit nWorker tmpstore coremutex fakeheap} {
set ten [string repeat X 10300]
set one [string repeat y 200]
if {$softheaplimit} {
execsql { PRAGMA cache_size = 20 };
} else {
execsql { PRAGMA cache_size = 5 };
}
do_execsql_test 15.$tn.1 {
PRAGMA cache_size = 5;
WITH rr AS (
SELECT 4, $ten UNION ALL
SELECT 2, $one UNION ALL
@ -582,7 +590,6 @@ foreach {tn mmap_limit nWorker tmpstore coremutex fakeheap} {
} {1 2 3 4 5 6}
do_execsql_test 15.$tn.3 {
PRAGMA cache_size = 5;
WITH rr AS (
SELECT 4, $ten UNION ALL
SELECT 2, $one
@ -601,6 +608,33 @@ set t(1) multithread
set t(2) serialized
sqlite3_config $t($sqlite_options(threadsafe))
sqlite3_initialize
sqlite3_soft_heap_limit 0
reset_db
do_catchsql_test 16.1 {
CREATE TABLE t1(a, b, c);
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(1, NULL, 3);
INSERT INTO t1 VALUES(NULL, 2, 3);
INSERT INTO t1 VALUES(1, 2, NULL);
INSERT INTO t1 VALUES(4, 5, 6);
CREATE UNIQUE INDEX i1 ON t1(b, a, c);
} {0 {}}
reset_db
do_catchsql_test 16.2 {
CREATE TABLE t1(a, b, c);
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(1, NULL, 3);
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(1, 2, NULL);
INSERT INTO t1 VALUES(4, 5, 6);
CREATE UNIQUE INDEX i1 ON t1(b, a, c);
} {1 {UNIQUE constraint failed: t1.b, t1.a, t1.c}}
reset_db
do_execsql_test 17.1 {
SELECT * FROM sqlite_master ORDER BY sql;
} {}
finish_test

View File

@ -18,24 +18,32 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix sortfault
do_execsql_test 1.0 {
PRAGMA cache_size = 5;
}
foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap} {
1 0 0 file multithread false
2 100000 0 file multithread false
3 100000 1 file multithread false
foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap lookaside} {
1 0 0 file multithread false false
2 100000 0 file multithread false false
3 100000 1 file multithread false false
4 2000000 0 file singlethread false true
} {
if {$sqlite_options(threadsafe)} { set threadsmode singlethread }
catch { db close }
sqlite3_shutdown
sqlite3_config_worker_threads $nWorker
sqlite3_config $threadsmode
if { $lookaside } {
sqlite3_config_lookaside 100 500
} else {
sqlite3_config_lookaside 0 0
}
sqlite3_initialize
sorter_test_fakeheap $fakeheap
set str [string repeat a 1000]
puts $threadsmode
do_faultsim_test 1.$tn -prep {
sqlite3 db test.db
@ -55,8 +63,7 @@ foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap} {
faultsim_test_result {0 {40 1000 40 1000 40 1000 40 1000 40 1000}}
}
do_faultsim_test 2.$tn -prep {
do_faultsim_test 2.$tn -faults oom* -prep {
sqlite3 db test.db
sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit
add_test_utf16bin_collate db
@ -75,6 +82,30 @@ foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap} {
faultsim_test_result {0 {20 1000 20 1000 20 1000 20 1000 20 1000}}
}
if {$mmap_limit > 1000000} {
set str2 [string repeat $str 10]
sqlite3_memdebug_vfs_oom_test 0
sqlite3 db test.db
sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit
execsql { PRAGMA cache_size = 5 }
do_faultsim_test 3.$tn -faults oom-trans* -body {
execsql {
WITH r(x,y) AS (
SELECT 300, $::str2
UNION ALL
SELECT x-1, $::str2 FROM r
LIMIT 300
)
SELECT count(x), length(y) FROM r GROUP BY y, (x%5)
}
} -test {
faultsim_test_result {0 {60 10000 60 10000 60 10000 60 10000 60 10000}}
}
sqlite3_memdebug_vfs_oom_test 1
}
}
catch { db close }
@ -84,6 +115,55 @@ set t(0) singlethread
set t(1) multithread
set t(2) serialized
sqlite3_config $t($sqlite_options(threadsafe))
sqlite3_config_lookaside 100 500
sqlite3_initialize
#-------------------------------------------------------------------------
#
reset_db
do_execsql_test 4.0 {
CREATE TABLE t1(a, b, c);
INSERT INTO t1 VALUES(1, 2, 3);
}
do_test 4.1 {
for {set i 0} {$i < 256} {incr i} {
execsql {
INSERT INTO t1 SELECT
((a<<3) + b) & 2147483647,
((b<<3) + c) & 2147483647,
((c<<3) + a) & 2147483647
FROM t1 ORDER BY rowid DESC LIMIT 1;
}
}
} {}
faultsim_save_and_close
do_faultsim_test 4.2 -faults oom* -prep {
faultsim_restore_and_reopen
} -body {
execsql { CREATE UNIQUE INDEX i1 ON t1(a,b,c) }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set a [string repeat a 500]
set b [string repeat b 500]
set c [string repeat c 500]
do_execsql_test 5.0 {
CREATE TABLE t1(a, b, c);
INSERT INTO t1 VALUES($a, $b, $c);
INSERT INTO t1 VALUES($c, $b, $a);
}
do_faultsim_test 5.1 -faults oom* -body {
execsql { SELECT * FROM t1 ORDER BY a }
} -test {
faultsim_test_result [list 0 [list $::a $::b $::c $::c $::b $::a]]
}
finish_test