/ Check-in [1ca3b8cc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Futher improvements to the .testctrl interface in the shell.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1ca3b8cce93e83fabe35c22cb726b8ce0883e0448afa3301ad0b53073055fa8d
User & Date: drh 2017-11-15 19:14:08
Context
2017-11-16
19:04
Add a missing "finish_test" to the end of the stmtvtab1.test script. check-in: e0b5c058 user: drh tags: trunk
2017-11-15
19:14
Futher improvements to the .testctrl interface in the shell. check-in: 1ca3b8cc user: drh tags: trunk
17:07
UI improvements on the .testctrl dot-command in the shell. check-in: 5d66219c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  5922   5922     }else
  5923   5923   
  5924   5924   #ifndef SQLITE_UNTESTABLE
  5925   5925     if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
  5926   5926       static const struct {
  5927   5927          const char *zCtrlName;   /* Name of a test-control option */
  5928   5928          int ctrlCode;            /* Integer code for that option */
         5929  +       const char *zUsage;      /* Usage notes */
  5929   5930       } aCtrl[] = {
  5930         -      { "always",                SQLITE_TESTCTRL_ALWAYS                 },
  5931         -      { "assert",                SQLITE_TESTCTRL_ASSERT                 },
  5932         -      { "benign_malloc_hooks",   SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS    },
  5933         -      { "bitvec_test",           SQLITE_TESTCTRL_BITVEC_TEST            },
  5934         -      { "byteorder",             SQLITE_TESTCTRL_BYTEORDER              },
  5935         -      { "fault_install",         SQLITE_TESTCTRL_FAULT_INSTALL          },
  5936         -      { "imposter",              SQLITE_TESTCTRL_IMPOSTER               },
  5937         -      { "iskeyword",             SQLITE_TESTCTRL_ISKEYWORD              },
  5938         -      { "never_corrupt",         SQLITE_TESTCTRL_NEVER_CORRUPT          },
  5939         -      { "optimizations",         SQLITE_TESTCTRL_OPTIMIZATIONS          },
  5940         -      { "pending_byte",          SQLITE_TESTCTRL_PENDING_BYTE           },
  5941         -      { "prng_reset",            SQLITE_TESTCTRL_PRNG_RESET             },
  5942         -      { "prng_restore",          SQLITE_TESTCTRL_PRNG_RESTORE           },
  5943         -      { "prng_save",             SQLITE_TESTCTRL_PRNG_SAVE              },
  5944         -      { "reserve",               SQLITE_TESTCTRL_RESERVE                },
         5931  +      { "always",             SQLITE_TESTCTRL_ALWAYS,        "BOOLEAN"            },
         5932  +      { "assert",             SQLITE_TESTCTRL_ASSERT,        "BOOLEAN"            },
         5933  +    /*{ "benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, ""          },*/
         5934  +    /*{ "bitvec_test",        SQLITE_TESTCTRL_BITVEC_TEST,   ""                },*/
         5935  +      { "byteorder",          SQLITE_TESTCTRL_BYTEORDER,     ""                   },
         5936  +    /*{ "fault_install",      SQLITE_TESTCTRL_FAULT_INSTALL, ""                }, */
         5937  +      { "imposter",           SQLITE_TESTCTRL_IMPOSTER,   "SCHEMA ON/OFF ROOTPAGE"},
         5938  +#ifdef SQLITE_N_KEYWORD
         5939  +      { "iskeyword",          SQLITE_TESTCTRL_ISKEYWORD,     "IDENTIFIER"         },
         5940  +#endif
         5941  +      { "localtime_fault",    SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN"           },
         5942  +      { "never_corrupt",      SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN"            },
         5943  +      { "optimizations",      SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK"       },
         5944  +      { "pending_byte",       SQLITE_TESTCTRL_PENDING_BYTE,  "OFFSET  "           },
         5945  +      { "prng_reset",         SQLITE_TESTCTRL_PRNG_RESET,    ""                   },
         5946  +      { "prng_restore",       SQLITE_TESTCTRL_PRNG_RESTORE,  ""                   },
         5947  +      { "prng_save",          SQLITE_TESTCTRL_PRNG_SAVE,     ""                   },
         5948  +      { "reserve",            SQLITE_TESTCTRL_RESERVE,       "BYTES-OF-RESERVE"   },
  5945   5949       };
  5946   5950       int testctrl = -1;
  5947         -    int rc2 = 0;
         5951  +    int iCtrl = -1;
         5952  +    int rc2 = 0;    /* 0: usage.  1: %d  2: %x  3: no-output */
         5953  +    int isOk = 0;
  5948   5954       int i, n2;
  5949   5955       open_db(p, 0);
  5950   5956       const char *zCmd = nArg>=2 ? azArg[1] : "help";
  5951   5957   
  5952   5958       /* The argument can optionally begin with "-" or "--" */
  5953   5959       if( zCmd[0]=='-' && zCmd[1] ){
  5954   5960         zCmd++;
................................................................................
  5955   5961         if( zCmd[0]=='-' && zCmd[1] ) zCmd++;
  5956   5962       }
  5957   5963   
  5958   5964       /* --help lists all test-controls */
  5959   5965       if( strcmp(zCmd,"help")==0 ){
  5960   5966         utf8_printf(p->out, "Available test-controls:\n");
  5961   5967         for(i=0; i<ArraySize(aCtrl); i++){
  5962         -        utf8_printf(p->out, "  .testctrl %s\n", aCtrl[i].zCtrlName);
         5968  +        utf8_printf(p->out, "  .testctrl %s %s\n",
         5969  +                    aCtrl[i].zCtrlName, aCtrl[i].zUsage);
  5963   5970         }
  5964   5971         rc = 1;
  5965   5972         goto meta_command_exit;
  5966   5973       }
  5967   5974   
  5968   5975       /* convert testctrl text option to value. allow any unique prefix
  5969   5976       ** of the option name, or a numerical value. */
  5970   5977       n2 = strlen30(zCmd);
  5971   5978       for(i=0; i<ArraySize(aCtrl); i++){
  5972   5979         if( strncmp(zCmd, aCtrl[i].zCtrlName, n2)==0 ){
  5973   5980           if( testctrl<0 ){
  5974   5981             testctrl = aCtrl[i].ctrlCode;
         5982  +          iCtrl = i;
  5975   5983           }else{
  5976   5984             utf8_printf(stderr, "Error: ambiguous test-control: \"%s\"\n"
  5977   5985                                 "Use \".testctrl --help\" for help\n", zCmd);
  5978   5986             rc = 1;
  5979   5987             goto meta_command_exit;
  5980   5988           }
  5981   5989         }
  5982   5990       }
  5983         -    if( testctrl<0 ) testctrl = (int)integerValue(zCmd);
  5984         -    if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
         5991  +    if( testctrl<0 ){
  5985   5992         utf8_printf(stderr,"Error: unknown test-control: %s\n"
  5986   5993                            "Use \".testctrl --help\" for help\n", zCmd);
  5987   5994       }else{
  5988   5995         switch(testctrl){
  5989   5996   
  5990   5997           /* sqlite3_test_control(int, db, int) */
  5991   5998           case SQLITE_TESTCTRL_OPTIMIZATIONS:
  5992   5999           case SQLITE_TESTCTRL_RESERVE:
  5993   6000             if( nArg==3 ){
  5994   6001               int opt = (int)strtol(azArg[2], 0, 0);
  5995   6002               rc2 = sqlite3_test_control(testctrl, p->db, opt);
  5996         -            raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
  5997         -          } else {
  5998         -            utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
  5999         -                    azArg[1]);
         6003  +            isOk = 3;
  6000   6004             }
  6001   6005             break;
  6002   6006   
  6003   6007           /* sqlite3_test_control(int) */
  6004   6008           case SQLITE_TESTCTRL_PRNG_SAVE:
  6005   6009           case SQLITE_TESTCTRL_PRNG_RESTORE:
  6006   6010           case SQLITE_TESTCTRL_PRNG_RESET:
  6007   6011           case SQLITE_TESTCTRL_BYTEORDER:
  6008   6012             if( nArg==2 ){
  6009   6013               rc2 = sqlite3_test_control(testctrl);
  6010         -            raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
  6011         -          } else {
  6012         -            utf8_printf(stderr,"Error: testctrl %s takes no options\n",
  6013         -                        azArg[1]);
         6014  +            isOk = testctrl==SQLITE_TESTCTRL_BYTEORDER ? 1 : 3;
  6014   6015             }
  6015   6016             break;
  6016   6017   
  6017   6018           /* sqlite3_test_control(int, uint) */
  6018   6019           case SQLITE_TESTCTRL_PENDING_BYTE:
  6019   6020             if( nArg==3 ){
  6020   6021               unsigned int opt = (unsigned int)integerValue(azArg[2]);
  6021   6022               rc2 = sqlite3_test_control(testctrl, opt);
  6022         -            raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
  6023         -          } else {
  6024         -            utf8_printf(stderr,"Error: testctrl %s takes a single unsigned"
  6025         -                           " int option\n", azArg[1]);
         6023  +            isOk = 3;
  6026   6024             }
  6027   6025             break;
  6028   6026   
  6029   6027           /* sqlite3_test_control(int, int) */
  6030   6028           case SQLITE_TESTCTRL_ASSERT:
  6031   6029           case SQLITE_TESTCTRL_ALWAYS:
         6030  +          if( nArg==3 ){
         6031  +            int opt = booleanValue(azArg[2]);
         6032  +            rc2 = sqlite3_test_control(testctrl, opt);
         6033  +            isOk = 1;
         6034  +          }
         6035  +          break;
         6036  +
         6037  +        /* sqlite3_test_control(int, int) */
         6038  +        case SQLITE_TESTCTRL_LOCALTIME_FAULT:
  6032   6039           case SQLITE_TESTCTRL_NEVER_CORRUPT:
  6033   6040             if( nArg==3 ){
  6034   6041               int opt = booleanValue(azArg[2]);
  6035   6042               rc2 = sqlite3_test_control(testctrl, opt);
  6036         -            raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
  6037         -          } else {
  6038         -            utf8_printf(stderr,"Error: testctrl %s takes a single int option\n",
  6039         -                            azArg[1]);
         6043  +            isOk = 3;
  6040   6044             }
  6041   6045             break;
  6042   6046   
  6043   6047           /* sqlite3_test_control(int, char *) */
  6044   6048   #ifdef SQLITE_N_KEYWORD
  6045   6049           case SQLITE_TESTCTRL_ISKEYWORD:
  6046   6050             if( nArg==3 ){
  6047   6051               const char *opt = azArg[2];
  6048   6052               rc2 = sqlite3_test_control(testctrl, opt);
  6049         -            raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
  6050         -          } else {
  6051         -            utf8_printf(stderr,
  6052         -                        "Error: testctrl %s takes a single char * option\n",
  6053         -                        azArg[1]);
         6053  +            isOk = 1;
  6054   6054             }
  6055   6055             break;
  6056   6056   #endif
  6057   6057   
  6058   6058           case SQLITE_TESTCTRL_IMPOSTER:
  6059   6059             if( nArg==5 ){
  6060   6060               rc2 = sqlite3_test_control(testctrl, p->db,
  6061   6061                             azArg[2],
  6062   6062                             integerValue(azArg[3]),
  6063   6063                             integerValue(azArg[4]));
  6064         -            raw_printf(p->out, "%d (0x%08x)\n", rc2, rc2);
  6065         -          }else{
  6066         -            raw_printf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n");
         6064  +            isOk = 3;
  6067   6065             }
  6068   6066             break;
  6069         -
  6070         -        case SQLITE_TESTCTRL_BITVEC_TEST:
  6071         -        case SQLITE_TESTCTRL_FAULT_INSTALL:
  6072         -        case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
  6073         -        default:
  6074         -          utf8_printf(stderr,
  6075         -                      "Error: CLI support for testctrl %s not implemented\n",
  6076         -                      azArg[1]);
  6077         -          break;
  6078   6067         }
  6079   6068       }
         6069  +    if( isOk==0 && iCtrl>=0 ){
         6070  +      utf8_printf(p->out, "Usage: .testctrl %s %s\n", zCmd, aCtrl[iCtrl].zUsage);
         6071  +      rc = 1;
         6072  +    }else if( isOk==1 ){
         6073  +      raw_printf(p->out, "%d\n", rc2);
         6074  +    }else if( isOk==2 ){
         6075  +      raw_printf(p->out, "0x%08x\n", rc2);
         6076  +    }
  6080   6077     }else
  6081   6078   #endif /* !defined(SQLITE_UNTESTABLE) */
  6082   6079   
  6083   6080     if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 ){
  6084   6081       open_db(p, 0);
  6085   6082       sqlite3_busy_timeout(p->db, nArg>=2 ? (int)integerValue(azArg[1]) : 0);
  6086   6083     }else