New #ifdefs to omit code that is unused when SQLITE_USE_LONG DOUBLE is defined.
[sqlite.git] / src / test_vdbecov.c
blob283936aeb74f909607b6991972d5cdac78c17f6b
1 /*
2 ** 2019 April 02
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.
11 ******************************************************************************
14 #if SQLITE_TEST /* This file is used for testing only */
16 #include "sqlite3.h"
17 #include "sqliteInt.h"
18 #include "tclsqlite.h"
20 #ifdef SQLITE_VDBE_COVERAGE
22 static u8 aBranchArray[200000];
24 static void test_vdbe_branch(
25 void *pCtx,
26 unsigned int iSrc,
27 unsigned char iBranch,
28 unsigned char iType
30 if( iSrc<sizeof(aBranchArray) ){
31 aBranchArray[iSrc] |= iBranch;
35 static void appendToList(
36 Tcl_Obj *pList,
37 int iLine,
38 int iPath,
39 const char *zNever
41 Tcl_Obj *pNew = Tcl_NewObj();
42 Tcl_IncrRefCount(pNew);
43 Tcl_ListObjAppendElement(0, pNew, Tcl_NewIntObj(iLine));
44 Tcl_ListObjAppendElement(0, pNew, Tcl_NewIntObj(iPath));
45 Tcl_ListObjAppendElement(0, pNew, Tcl_NewStringObj(zNever, -1));
46 Tcl_ListObjAppendElement(0, pList, pNew);
47 Tcl_DecrRefCount(pNew);
51 static int SQLITE_TCLAPI test_vdbe_coverage(
52 ClientData cd,
53 Tcl_Interp *interp,
54 int objc,
55 Tcl_Obj *CONST objv[]
57 const char *aSub[] = { "start", "report", "stop", 0 };
58 int iSub = -1;
59 if( objc!=2 ){
60 Tcl_WrongNumArgs(interp, 1, objv, "sub-command");
61 return TCL_ERROR;
64 if( Tcl_GetIndexFromObj(interp, objv[1], aSub, "sub-command", 0, &iSub) ){
65 return TCL_ERROR;
68 Tcl_ResetResult(interp);
69 assert( iSub==0 || iSub==1 || iSub==2 );
70 switch( iSub ){
71 case 0: /* start */
72 memset(aBranchArray, 0, sizeof(aBranchArray));
73 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, test_vdbe_branch, 0);
74 break;
75 case 1: { /* report */
76 int i;
77 Tcl_Obj *pRes = Tcl_NewObj();
78 Tcl_IncrRefCount(pRes);
79 for(i=0; i<sizeof(aBranchArray); i++){
80 u8 b = aBranchArray[i];
81 int bFlag = ((b >> 4)==4);
82 if( b ){
83 if( (b & 0x01)==0 ){
84 appendToList(pRes, i, 0, bFlag ? "less than" : "falls through");
86 if( (b & 0x02)==0 ){
87 appendToList(pRes, i, 1, bFlag ? "equal" : "taken");
89 if( (b & 0x04)==0 ){
90 appendToList(pRes, i, 2, bFlag ? "greater-than" : "NULL");
94 Tcl_SetObjResult(interp, pRes);
95 Tcl_DecrRefCount(pRes);
96 break;
99 default: /* stop */
100 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, 0, 0);
101 break;
104 return TCL_OK;
107 #endif /* SQLITE_VDBE_COVERAGE */
109 int Sqlitetestvdbecov_Init(Tcl_Interp *interp){
110 #ifdef SQLITE_VDBE_COVERAGE
111 Tcl_CreateObjCommand(interp, "vdbe_coverage", test_vdbe_coverage, 0, 0);
112 #endif
113 return TCL_OK;
116 #endif