From: drh Date: Wed, 19 Feb 2014 19:14:34 +0000 (+0000) Subject: Add the VdbeCoverageNeverTaken() macro, and comments that better describe how X-Git-Tag: version-3.8.4~57 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5655c549aa202c957cf3610d9faa99aac5996475;p=thirdparty%2Fsqlite.git Add the VdbeCoverageNeverTaken() macro, and comments that better describe how the VDBE branch coverage measurement works. Add some tags to provide 100% VDBE branch coverage. FossilOrigin-Name: c1e94169dd8eb80b4d18c73be9f81585330d11ad --- diff --git a/manifest b/manifest index 9293877a3f..2b91bf1936 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_NOTNULL\sP5\scode\sfor\scomparison\soperations\s-\sreally\sa\scomposite\nof\sSQLITE_NULLEQ\sand\sSQLITE_JUMPIFNULL.\s\sThis\sflag\sindicates\sthat\sNULL\soperands\nare\snot\spossible\sand\sraises\sand\sassert()\sif\sNULL\soperands\sare\sseen.\nAlso\somit\san\sunnecessary\sscan\sof\sthe\ssqlite_sequence\stable\swhen\swriting\ninto\san\sAUTOINCREMENT\stable. -D 2014-02-19T14:20:49.685 +C Add\sthe\sVdbeCoverageNeverTaken()\smacro,\sand\scomments\sthat\sbetter\sdescribe\show\nthe\sVDBE\sbranch\scoverage\smeasurement\sworks.\s\sAdd\ssome\stags\sto\sprovide\s100%\nVDBE\sbranch\scoverage. +D 2014-02-19T19:14:34.983 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -210,7 +210,7 @@ F src/parse.y 2613ca5d609c2f3d71dd297351f010bcec16e1e0 F src/pcache.c d8eafac28290d4bb80332005435db44991d07fc2 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c 102e6f5a2fbc646154463eb856d1fd716867b64c -F src/pragma.c 2635d6bf8b54003ebefd773df2f50258cece2bec +F src/pragma.c a46ee83671f5c95f53d2ceeb5e1a818d7b1df99a F src/prepare.c 677521ab7132615a8a26107a1d1c3132f44ae337 F src/printf.c 85d07756e45d7496d19439dcae3e6e9e0090f269 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece @@ -273,12 +273,12 @@ F src/test_vfstrace.c 3a0ab304682fecbceb689e7d9b904211fde11d78 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/tokenize.c 6da2de6e12218ccb0aea5184b56727d011f4bee7 F src/trigger.c a80036fcbd992729adc7cd34a875d59a71fa10cc -F src/update.c 16d6555a32298da18ce6e2a00637c462d9e3ac97 +F src/update.c 5b3e74a03b3811e586b4f2b4cbd7c49f01c93115 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c c46c90459ef9bdc0c6c73803cf4c55425b4771cf F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 16c220ae23bbd6755f66bb32eb4c8c0fadda6c8f -F src/vdbe.h f429f5e5e14b02acbdffb2b2e8ba6e865e66e320 +F src/vdbe.c b82ffb8ca4a7b163f0d4450dce353259cbb12240 +F src/vdbe.h 6c703ccef97f4504bd0d79cc09180185a60ae8ad F src/vdbeInt.h 5286af9067cabdb8ba57b87c0c988a931be6c6c8 F src/vdbeapi.c 5bc41aaea448a7fc250902c418f1795859be3820 F src/vdbeaux.c 0e01d6fda149c689039caadb8c89b20abb58e21d @@ -1151,7 +1151,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 85b355cfb40e8dbeb171980204ffad897184063f -R 6054409536840db43eb58dd38378a2df +P d2c047f304848e49864ed8c216b48fd671fa3916 +R 290109175fc6aecf9e37def55ff4d8d1 U drh -Z 59cedb1de1bf2e430d47d82062cddf85 +Z 8351cefc3ed205778666dc9ef6e2430a diff --git a/manifest.uuid b/manifest.uuid index 30fa60d6f1..a6ed2e8a06 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d2c047f304848e49864ed8c216b48fd671fa3916 \ No newline at end of file +c1e94169dd8eb80b4d18c73be9f81585330d11ad \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index a586370b8d..a211633f23 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1942,6 +1942,7 @@ void sqlite3Pragma( sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v); + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT); sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); diff --git a/src/update.c b/src/update.c index 4c45a4b40d..4138749f80 100644 --- a/src/update.c +++ b/src/update.c @@ -434,7 +434,7 @@ void sqlite3Update( if( aToOpen[iDataCur-iBaseCur] ){ assert( pPk!=0 ); sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey); - VdbeCoverage(v); + VdbeCoverageNeverTaken(v); } labelContinue = labelBreak; sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak); @@ -577,11 +577,10 @@ void sqlite3Update( if( bReplace || chngKey ){ if( pPk ){ j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey); - VdbeCoverage(v); }else{ j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid); - VdbeCoverage(v); } + VdbeCoverageNeverTaken(v); } sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx); diff --git a/src/vdbe.c b/src/vdbe.c index 1e9e31116f..2b3396223c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -108,15 +108,31 @@ int sqlite3_found_count = 0; #endif /* -** Invoke the VDBE coverage callback, if defined +** Invoke the VDBE coverage callback, if that callback is defined. This +** feature is used for test suite validation only and does not appear an +** production builds. +** +** M is an integer, 2 or 3, that indices how many different ways the +** branch can go. It is usually 2. "I" is the direction the branch +** goes. 0 means falls through. 1 means branch is taken. 2 means the +** second alternative branch is taken. */ #if !defined(SQLITE_VDBE_COVERAGE) # define VdbeBranchTaken(I,M) #else -# define VdbeBranchTaken(I,M) \ - if( sqlite3GlobalConfig.xVdbeBranch!=0 ){ \ - sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg, \ - pOp->iSrcLine,(I),(M)); } +# define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M) + static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){ + if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){ + M = iSrcLine; + /* Assert the truth of VdbeCoverageAlwaysTaken() and + ** VdbeCoverageNeverTaken() */ + assert( (M & I)==I ); + }else{ + if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/ + sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg, + iSrcLine,I,M); + } + } #endif /* diff --git a/src/vdbe.h b/src/vdbe.h index f1f28cb1b5..44cd9123aa 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -241,14 +241,39 @@ void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *); # define VdbeModuleComment(X) #endif -/* Set the Opcode.iSrcline field of the previous opcode */ +/* +** The VdbeCoverage macros are used to set a coverage testing point +** for VDBE branch instructions. The coverage testing points are line +** numbers in the sqlite3.c source file. VDBE branch coverage testing +** only works with an amalagmation build. That's ok since a VDBE branch +** coverage build designed for testing the test suite only. No application +** should ever ship with VDBE branch coverage measuring turned on. +** +** VdbeCoverage(v) // Mark the previously coded instruction +** // as a branch +** +** VdbeCoverageIf(v, conditional) // Mark previous if conditional true +** +** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken +** +** VdbeCoverageNeverTaken(v) // Previous branch is never taken +** +** Every VDBE branch operation must be tagged with one of the macros above. +** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and +** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch() +** routine in vdbe.c, alerting the developer to the missed tag. +*/ #ifdef SQLITE_VDBE_COVERAGE void sqlite3VdbeSetLineNumber(Vdbe*,int); # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__) # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__) +# define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2); +# define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1); #else # define VdbeCoverage(v) # define VdbeCoverageIf(v,x) +# define VdbeCoverageAlwaysTaken(v) +# define VdbeCoverageNeverTaken(v) #endif #endif