interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / src / test_vdbecov.c

116 lines · 2907 bytes Raw Blame History
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.
10**
11******************************************************************************
12**
13*/
14#if SQLITE_TEST /* This file is used for testing only */
15
16#include "sqlite3.h"
17#include "sqliteInt.h"
18#include "tclsqlite.h"
19
20#ifdef SQLITE_VDBE_COVERAGE
21
22static u8 aBranchArray[200000];
23
24static void test_vdbe_branch(
25 void *pCtx,
26 unsigned int iSrc,
27 unsigned char iBranch,
28 unsigned char iType
29){
30 if( iSrc<sizeof(aBranchArray) ){
31 aBranchArray[iSrc] |= iBranch;
32 }
33}
34
35static void appendToList(
36 Tcl_Obj *pList,
37 int iLine,
38 int iPath,
39 const char *zNever
40){
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);
48}
49
50
51static int SQLITE_TCLAPI test_vdbe_coverage(
52 ClientData cd,
53 Tcl_Interp *interp,
54 int objc,
55 Tcl_Obj *CONST objv[]
56){
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;
62 }
63
64 if( Tcl_GetIndexFromObj(interp, objv[1], aSub, "sub-command", 0, &iSub) ){
65 return TCL_ERROR;
66 }
67
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");
85 }
86 if( (b & 0x02)==0 ){
87 appendToList(pRes, i, 1, bFlag ? "equal" : "taken");
88 }
89 if( (b & 0x04)==0 ){
90 appendToList(pRes, i, 2, bFlag ? "greater-than" : "NULL");
91 }
92 }
93 }
94 Tcl_SetObjResult(interp, pRes);
95 Tcl_DecrRefCount(pRes);
96 break;
97 };
98
99 default: /* stop */
100 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, 0, 0);
101 break;
102 }
103
104 return TCL_OK;
105}
106
107#endif /* SQLITE_VDBE_COVERAGE */
108
109int 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;
114}
115
116#endif