From 5c928eac6a6242b81178c5f38d645e97c763cf87 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 20 Oct 2022 10:16:49 +0800 Subject: [PATCH] fix: improve test coverage --- tests/script/jenkins/basic.txt | 2 +- tests/script/tsim/insert/basic.sim | 33 ++++++-- tests/script/tsim/stream/basic0.sim | 2 +- utils/tsim/src/simExe.c | 126 +++++++--------------------- utils/tsim/src/simParse.c | 18 ---- 5 files changed, 61 insertions(+), 120 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index fc139a1533..e07ec54182 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -228,7 +228,7 @@ ./test.sh -f tsim/table/vgroup.sim # ---- stream -./test.sh -f tsim/stream/basic0.sim +./test.sh -f tsim/stream/basic0.sim -v ./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/drop_stream.sim diff --git a/tests/script/tsim/insert/basic.sim b/tests/script/tsim/insert/basic.sim index c926cbc8b0..ec8a61bb04 100644 --- a/tests/script/tsim/insert/basic.sim +++ b/tests/script/tsim/insert/basic.sim @@ -12,14 +12,14 @@ $tb = $tbPrefix . $i print =============== step1 sql drop database -x step1 step1: -sql create database $db vgroups 2 +sql create database $db vgroups 2 precision 'ns' sql use $db sql create table $tb (ts timestamp, speed int) $x = 0 -while $x < 10 +while $x < 110 $cc = $x * 60000 - $ms = 1601481600000 + $cc + $ms = 1601481600000000000 + $cc sql insert into $tb values ($ms , $x ) $x = $x + 1 @@ -27,9 +27,9 @@ endw print =============== step 2 $x = 0 -while $x < 5 +while $x < 110 $cc = $x * 60000 - $ms = 1551481600000 + $cc + $ms = 1551481600000000000 + $cc sql insert into $tb values ($ms , $x ) $x = $x + 1 @@ -38,8 +38,29 @@ endw sql select * from $tb print $rows points data are retrieved -if $rows != 15 then +if $rows != 220 then return -1 endi +# error +print $data1 +print $data[1000][1] +print $data[1][1000] +print $data[1000][1000] +$a1 = 0 +$a2 = 0 +$a3 = $a1 % $a2 +print $a3 + +$val = \\\1 +print ====> $val + +sql_slow select * from $tb + +sql close +sql connect +sql close +sql connect root + + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stream/basic0.sim b/tests/script/tsim/stream/basic0.sim index 6d05f69dcf..8e3e99978b 100644 --- a/tests/script/tsim/stream/basic0.sim +++ b/tests/script/tsim/stream/basic0.sim @@ -1,7 +1,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c debugflag -v 131 -system sh/exec.sh -n dnode1 -s start -v +system sh/exec.sh -n dnode1 -s start sql connect print =============== create database diff --git a/utils/tsim/src/simExe.c b/utils/tsim/src/simExe.c index 7218ea39f8..258c611557 100644 --- a/utils/tsim/src/simExe.c +++ b/utils/tsim/src/simExe.c @@ -21,35 +21,20 @@ void simLogSql(char *sql, bool useSharp) { char filename[256]; sprintf(filename, "%s/sim.sql", simScriptDir); if (pFile == NULL) { - // fp = fopen(filename, "w"); pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); - if (pFile == NULL) { - fprintf(stderr, "ERROR: failed to open file: %s\n", filename); - return; + } + + if (pFile != NULL) { + if (useSharp) { + taosFprintfFile(pFile, "# %s;\n", sql); + } else { + taosFprintfFile(pFile, "%s;\n", sql); } - } - if (useSharp) { - taosFprintfFile(pFile, "# %s;\n", sql); - } else { - taosFprintfFile(pFile, "%s;\n", sql); - } - taosFsyncFile(pFile); + taosFsyncFile(pFile); + } } -#if 0 -char *simParseArbitratorName(char *varName) { - static char hostName[140]; -#ifdef WINDOWS - taosGetFqdn(hostName); - sprintf(&hostName[strlen(hostName)], ":%d", 8000); -#else - sprintf(hostName, "%s:%d", "localhost", 8000); -#endif - return hostName; -} -#endif - char *simParseHostName(char *varName) { static char hostName[140]; #ifdef WINDOWS @@ -65,18 +50,18 @@ char *simParseHostName(char *varName) { } static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) { - if (beginLen <= 5) { - *num = 0; - } else { + *num = 0; + + if (beginLen > 5) { *num = atoi(begin + 5); } } static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) { + *num = 0; + const char *number = strstr(begin, "]["); - if (number == NULL) { - *num = 0; - } else { + if (number != NULL) { *num = atoi(number + 2); } } @@ -91,10 +76,10 @@ static void simFindFirstKeyVal(const char *begin, int32_t beginLen, char *key, i } static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) { + *num = 0; + const char *number = strstr(begin, ")["); - if (number == NULL) { - *num = 0; - } else { + if (number != NULL) { *num = atoi(number + 2); } } @@ -104,12 +89,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { return simParseHostName(varName); } -#if 0 - if (strncmp(varName, "arbitrator", 10) == 0) { - return simParseArbitratorName(varName); - } -#endif - if (strncmp(varName, "error", varLen) == 0) return script->error; if (strncmp(varName, "rows", varLen) == 0) return script->rows; @@ -153,9 +132,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { } else if (varName[5] == '_') { // data2_db int32_t col = varName[4] - '0'; - if (col < 0 || col >= MAX_QUERY_COL_NUM) { - return "null"; - } + col = col % MAX_QUERY_COL_NUM; char *keyName; int32_t keyLen; @@ -171,9 +148,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { } else if (varName[6] == '_') { // data21_db int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0'); - if (col < 0 || col >= MAX_QUERY_COL_NUM) { - return "null"; - } + col = col % MAX_QUERY_COL_NUM; char *keyName; int32_t keyLen; @@ -185,17 +160,12 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { return script->data[i][col]; } } - return "null"; } else { // $data00 int32_t row = varName[4] - '0'; int32_t col = varName[5] - '0'; - if (row < 0 || row >= MAX_QUERY_ROW_NUM) { - return "null"; - } - if (col < 0 || col >= MAX_QUERY_COL_NUM) { - return "null"; - } + row = row % MAX_QUERY_ROW_NUM; + col = col % MAX_QUERY_COL_NUM; simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]); return script->data[row][col]; @@ -253,9 +223,9 @@ int32_t simExecuteExpression(SScript *script, char *exp) { rest = paGetToken(rest, &op2, &op2Len); if (var1[0] == '$') - strcpy(t0, simGetVariable(script, var1 + 1, var1Len - 1)); + tstrncpy(t0, simGetVariable(script, var1 + 1, var1Len - 1), sizeof(t0)); else { - memcpy(t0, var1, var1Len); + tstrncpy(t0, var1, var1Len); t0[var1Len] = 0; } @@ -578,6 +548,8 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { while (1) { var = strchr(src, '$'); if (var == NULL) break; + +#if 0 if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') { srcLen = (int32_t)(var - src - 1); memcpy(dst + dstLen, src, srcLen); @@ -585,6 +557,7 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { src = var; break; } +#endif srcLen = (int32_t)(var - src); memcpy(dst + dstLen, src, srcLen); @@ -657,11 +630,11 @@ bool simCreateTaosdConnect(SScript *script, char *rest) { } bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { - char timeStr[80] = {0}; - time_t tt; - struct tm tp; - SCmdLine *line = &script->lines[script->linePos]; - int32_t ret = -1; + char timeStr[80] = {0}; + time_t tt; + struct tm tp; + SCmdLine *line = &script->lines[script->linePos]; + int32_t ret = -1; TAOS_RES *pSql = NULL; @@ -705,17 +678,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { int32_t numOfRows = 0; int32_t num_fields = taos_field_count(pSql); if (num_fields != 0) { - if (pSql == NULL) { - simDebug("script:%s, taos:%p, %s failed, result is null", script->fileName, script->taos, rest); - if (line->errorJump == SQL_JUMP_TRUE) { - script->linePos = line->jump; - return true; - } - - sprintf(script->error, "lineNum:%d. result set null, sql:%s", line->lineNum, rest); - return false; - } - TAOS_ROW row; while ((row = taos_fetch_row(pSql))) { @@ -942,30 +904,6 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { } } - if (strncmp(rest, "connect", 7) == 0) { - if (!simCreateTaosdConnect(script, rest)) { - return false; - } - script->linePos++; - return true; - } - - if (script->taos == NULL) { - if (!simCreateTaosdConnect(script, "connect root")) { - if (line->errorJump == SQL_JUMP_TRUE) { - script->linePos = line->jump; - return true; - } - return false; - } - } - - if (strncmp(rest, "close", 5) == 0) { - simCloseTaosdConnect(script); - script->linePos++; - return true; - } - TAOS_RES *pSql = taos_query(script->taos, rest); int32_t ret = taos_errno(pSql); taos_free_result(pSql); diff --git a/utils/tsim/src/simParse.c b/utils/tsim/src/simParse.c index ae523edfc4..cdd918ac00 100644 --- a/utils/tsim/src/simParse.c +++ b/utils/tsim/src/simParse.c @@ -717,20 +717,12 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) { return true; } -#if 0 bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) { simParseSqlCmd(rest, pCmd, lineNum); cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW; return true; } -bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) { - simParseSqlCmd(rest, pCmd, lineNum); - cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL; - return true; -} -#endif - bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) { int32_t expLen; @@ -1058,7 +1050,6 @@ void simInitsimCmdList() { simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd; simAddCmdIntoHash(&(simCmdList[cmdno])); -#if 0 cmdno = SIM_CMD_SQL_SLOW; simCmdList[cmdno].cmdno = cmdno; strcpy(simCmdList[cmdno].name, "sql_slow"); @@ -1067,15 +1058,6 @@ void simInitsimCmdList() { simCmdList[cmdno].executeCmd = simExecuteSqlSlowCmd; simAddCmdIntoHash(&(simCmdList[cmdno])); - cmdno = SIM_CMD_RESTFUL; - simCmdList[cmdno].cmdno = cmdno; - strcpy(simCmdList[cmdno].name, "restful"); - simCmdList[cmdno].nlen = (int16_t)strlen(simCmdList[cmdno].name); - simCmdList[cmdno].parseCmd = simParseRestfulCmd; - simCmdList[cmdno].executeCmd = simExecuteRestfulCmd; - simAddCmdIntoHash(&(simCmdList[cmdno])); -#endif - /* test is only an internal command */ cmdno = SIM_CMD_TEST; simCmdList[cmdno].cmdno = cmdno;