diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt
index a5d04f79a6c74dcb9d514bfc22d5dd6b8f03198a..1b2fe37c71f26486ba847006ecf3aa373b5f55c1 100644
--- a/tests/script/jenkins/basic.txt
+++ b/tests/script/jenkins/basic.txt
@@ -57,8 +57,8 @@ cd ../../../debug; make
./test.sh -f general/db/delete_reuse2.sim
./test.sh -f general/db/delete_reusevnode.sim
./test.sh -f general/db/delete_reusevnode2.sim
-#./test.sh -f general/db/delete_writing1.sim
-#./test.sh -f general/db/delete_writing2.sim
+./test.sh -f general/db/delete_writing1.sim
+./test.sh -f general/db/delete_writing2.sim
./test.sh -f general/db/delete.sim
./test.sh -f general/db/len.sim
./test.sh -f general/db/repeat.sim
diff --git a/tests/tsim/inc/sim.h b/tests/tsim/inc/sim.h
index 58e58a442cedca564864578604faa6cea28ede68..01e5016557f2987741fdec6c6fd54facd885ea8a 100644
--- a/tests/tsim/inc/sim.h
+++ b/tests/tsim/inc/sim.h
@@ -100,7 +100,7 @@ typedef struct _cmd_t {
int16_t cmdno;
int16_t nlen;
char name[MAX_SIM_CMD_NAME_LEN];
- bool (*parseCmd)(char *, struct _cmd_t *, int);
+ bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
bool (*executeCmd)(struct _script_t *script, char *option);
struct _cmd_t *next;
} SCommand;
@@ -111,7 +111,7 @@ typedef struct {
int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
int16_t lineNum; // correspodning line number in original file
- int optionOffset; // relative option offset
+ int32_t optionOffset;// relative option offset
} SCmdLine;
typedef struct _var_t {
@@ -121,59 +121,56 @@ typedef struct _var_t {
} SVariable;
typedef struct _script_t {
- int type;
- bool killed;
-
- void *taos;
- char rows[12]; // number of rows data retrieved
- char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM]
- [MAX_QUERY_VALUE_LEN]; // query results
- char system_exit_code[12];
- char system_ret_content[MAX_SYSTEM_RESULT_LEN];
-
- int varLen;
- int linePos; // current cmd position
- int numOfLines; // number of lines in the script
- int bgScriptLen;
- char fileName[MAX_FILE_NAME_LEN]; // script file name
- char error[MAX_ERROR_LEN];
- char *optionBuffer;
+ int32_t type;
+ bool killed;
+ void * taos;
+ char rows[12]; // number of rows data retrieved
+ char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
+ char system_exit_code[12];
+ char system_ret_content[MAX_SYSTEM_RESULT_LEN];
+ int32_t varLen;
+ int32_t linePos; // current cmd position
+ int32_t numOfLines; // number of lines in the script
+ int32_t bgScriptLen;
+ char fileName[MAX_FILE_NAME_LEN]; // script file name
+ char error[MAX_ERROR_LEN];
+ char * optionBuffer;
SCmdLine *lines; // command list
SVariable variables[MAX_VAR_LEN];
+ pthread_t bgPid;
+ char auth[128];
struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM];
- char auth[128];
} SScript;
extern SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
extern SCommand simCmdList[];
-extern int simScriptPos;
-extern int simScriptSucced;
-extern int simDebugFlag;
-extern char tsScriptDir[];
-extern bool simAsyncQuery;
+extern int32_t simScriptPos;
+extern int32_t simScriptSucced;
+extern int32_t simDebugFlag;
+extern char tsScriptDir[];
+extern bool simAsyncQuery;
SScript *simParseScript(char *fileName);
-
SScript *simProcessCallOver(SScript *script);
-void *simExecuteScript(void *script);
-void simInitsimCmdList();
-bool simSystemInit();
-void simSystemCleanUp();
-char *simGetVariable(SScript *script, char *varName, int varLen);
-bool simExecuteExpCmd(SScript *script, char *option);
-bool simExecuteTestCmd(SScript *script, char *option);
-bool simExecuteGotoCmd(SScript *script, char *option);
-bool simExecuteRunCmd(SScript *script, char *option);
-bool simExecuteRunBackCmd(SScript *script, char *option);
-bool simExecuteSystemCmd(SScript *script, char *option);
-bool simExecuteSystemContentCmd(SScript *script, char *option);
-bool simExecutePrintCmd(SScript *script, char *option);
-bool simExecuteSleepCmd(SScript *script, char *option);
-bool simExecuteReturnCmd(SScript *script, char *option);
-bool simExecuteSqlCmd(SScript *script, char *option);
-bool simExecuteSqlErrorCmd(SScript *script, char *rest);
-bool simExecuteSqlSlowCmd(SScript *script, char *option);
-bool simExecuteRestfulCmd(SScript *script, char *rest);
-void simVisuallizeOption(SScript *script, char *src, char *dst);
+void * simExecuteScript(void *script);
+void simInitsimCmdList();
+bool simSystemInit();
+void simSystemCleanUp();
+char * simGetVariable(SScript *script, char *varName, int32_t varLen);
+bool simExecuteExpCmd(SScript *script, char *option);
+bool simExecuteTestCmd(SScript *script, char *option);
+bool simExecuteGotoCmd(SScript *script, char *option);
+bool simExecuteRunCmd(SScript *script, char *option);
+bool simExecuteRunBackCmd(SScript *script, char *option);
+bool simExecuteSystemCmd(SScript *script, char *option);
+bool simExecuteSystemContentCmd(SScript *script, char *option);
+bool simExecutePrintCmd(SScript *script, char *option);
+bool simExecuteSleepCmd(SScript *script, char *option);
+bool simExecuteReturnCmd(SScript *script, char *option);
+bool simExecuteSqlCmd(SScript *script, char *option);
+bool simExecuteSqlErrorCmd(SScript *script, char *rest);
+bool simExecuteSqlSlowCmd(SScript *script, char *option);
+bool simExecuteRestfulCmd(SScript *script, char *rest);
+void simVisuallizeOption(SScript *script, char *src, char *dst);
#endif
\ No newline at end of file
diff --git a/tests/tsim/inc/simParse.h b/tests/tsim/inc/simParse.h
index d3f92add71f3dc6ddb205c1810e1a3caace47e36..ef7d8e5ce72cc9bf0ae52380089d36576e84bd28 100644
--- a/tests/tsim/inc/simParse.h
+++ b/tests/tsim/inc/simParse.h
@@ -50,6 +50,6 @@ typedef struct {
char sexpLen[MAX_NUM_BLOCK]; /*switch expression length */
} SBlock;
-bool simParseExpression(char *token, int lineNum);
+bool simParseExpression(char *token, int32_t lineNum);
#endif
\ No newline at end of file
diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c
index 7f786dfaa9de5f6a93d3a181ddd53e37e8694310..2db750cdd302c63522e008e3ea324230dd87b6e5 100644
--- a/tests/tsim/src/simExe.c
+++ b/tests/tsim/src/simExe.c
@@ -13,6 +13,7 @@
* along with this program. If not, see .
*/
+#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "taos.h"
@@ -38,30 +39,28 @@ void simLogSql(char *sql, bool useSharp) {
} else {
fprintf(fp, "%s;\n", sql);
}
-
+
fflush(fp);
}
char *simParseArbitratorName(char *varName);
char *simParseHostName(char *varName);
-char *simGetVariable(SScript *script, char *varName, int varLen) {
+char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
if (strncmp(varName, "hostname", 8) == 0) {
return simParseHostName(varName);
}
if (strncmp(varName, "arbitrator", 10) == 0) {
- return simParseArbitratorName(varName);
+ return simParseArbitratorName(varName);
}
if (strncmp(varName, "error", varLen) == 0) return script->error;
if (strncmp(varName, "rows", varLen) == 0) return script->rows;
- if (strncmp(varName, "system_exit", varLen) == 0)
- return script->system_exit_code;
+ if (strncmp(varName, "system_exit", varLen) == 0) return script->system_exit_code;
- if (strncmp(varName, "system_content", varLen) == 0)
- return script->system_ret_content;
+ if (strncmp(varName, "system_content", varLen) == 0) return script->system_ret_content;
// variable like data2_192.168.0.1
if (strncmp(varName, "data", 4) == 0) {
@@ -70,16 +69,16 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
if (varName[5] == '_') {
- int col = varName[4] - '0';
+ int32_t col = varName[4] - '0';
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
return "null";
}
- char *keyName;
- int keyLen;
+ char * keyName;
+ int32_t keyLen;
paGetToken(varName + 6, &keyName, &keyLen);
- for (int i = 0; i < MAX_QUERY_ROW_NUM; ++i) {
+ for (int32_t i = 0; i < MAX_QUERY_ROW_NUM; ++i) {
if (strncmp(keyName, script->data[i][0], keyLen) == 0) {
simDebug("script:%s, keyName:%s, keyValue:%s", script->fileName, script->data[i][0], script->data[i][col]);
return script->data[i][col];
@@ -87,16 +86,16 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
return "null";
} else if (varName[6] == '_') {
- int col = (varName[4] - '0') * 10 + (varName[5] - '0');
+ int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0');
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
return "null";
}
- char *keyName;
- int keyLen;
+ char * keyName;
+ int32_t keyLen;
paGetToken(varName + 7, &keyName, &keyLen);
- for (int i = 0; i < MAX_QUERY_ROW_NUM; ++i) {
+ for (int32_t i = 0; i < MAX_QUERY_ROW_NUM; ++i) {
if (strncmp(keyName, script->data[i][0], keyLen) == 0) {
simTrace("script:%s, keyName:%s, keyValue:%s", script->fileName, script->data[i][0], script->data[i][col]);
return script->data[i][col];
@@ -104,8 +103,8 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
return "null";
} else {
- int row = varName[4] - '0';
- int col = varName[5] - '0';
+ int32_t row = varName[4] - '0';
+ int32_t col = varName[5] - '0';
if (row < 0 || row >= MAX_QUERY_ROW_NUM) {
return "null";
}
@@ -118,7 +117,7 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
}
- for (int i = 0; i < script->varLen; ++i) {
+ for (int32_t i = 0; i < script->varLen; ++i) {
SVariable *var = &script->variables[i];
if (var->varNameLen != varLen) {
continue;
@@ -144,11 +143,11 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
return var->varValue;
}
-int simExecuteExpression(SScript *script, char *exp) {
- char *op1, *op2, *var1, *var2, *var3, *rest;
- int op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1;
- char t0[512], t1[512], t2[512], t3[1024];
- int result;
+int32_t simExecuteExpression(SScript *script, char *exp) {
+ char * op1, *op2, *var1, *var2, *var3, *rest;
+ int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1;
+ char t0[512], t1[512], t2[512], t3[1024];
+ int32_t result;
rest = paGetToken(exp, &var1, &var1Len);
rest = paGetToken(rest, &op1, &op1Len);
@@ -234,7 +233,7 @@ bool simExecuteExpCmd(SScript *script, char *option) {
}
bool simExecuteTestCmd(SScript *script, char *option) {
- int result;
+ int32_t result;
result = simExecuteExpression(script, option);
if (result >= 0)
@@ -285,13 +284,12 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
sprintf(script->error, "lineNum:%d. parse file:%s error", script->lines[script->linePos].lineNum, fileName);
return false;
}
- simInfo("script:%s, start to execute in background", newScript->fileName);
newScript->type = SIM_SCRIPT_TYPE_BACKGROUND;
script->bgScripts[script->bgScriptLen++] = newScript;
+ simInfo("script:%s, start to execute in background,", newScript->fileName);
- pthread_t pid;
- if (pthread_create(&pid, NULL, simExecuteScript, (void *)newScript) != 0) {
+ if (pthread_create(&newScript->bgPid, NULL, simExecuteScript, (void *)newScript) != 0) {
sprintf(script->error, "lineNum:%d. create background thread failed", script->lines[script->linePos].lineNum);
return false;
}
@@ -307,13 +305,13 @@ bool simExecuteSystemCmd(SScript *script, char *option) {
simVisuallizeOption(script, option, buf + strlen(buf));
simLogSql(buf, true);
- int code = system(buf);
- int repeatTimes = 0;
+ int32_t code = system(buf);
+ int32_t repeatTimes = 0;
while (code < 0) {
- simError("script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d",
- script->fileName, buf, code, errno, strerror(errno), repeatTimes);
+ simError("script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d", script->fileName, buf, code,
+ errno, strerror(errno), repeatTimes);
taosMsleep(1000);
-#ifdef LINUX
+#ifdef LINUX
signal(SIGCHLD, SIG_DFL);
#endif
if (repeatTimes++ >= 10) {
@@ -368,8 +366,8 @@ bool simExecutePrintCmd(SScript *script, char *rest) {
}
bool simExecuteSleepCmd(SScript *script, char *option) {
- int delta;
- char buf[1024];
+ int32_t delta;
+ char buf[1024];
simVisuallizeOption(script, option, buf);
option = buf;
@@ -395,7 +393,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
simVisuallizeOption(script, option, buf);
option = buf;
- int ret = 1;
+ int32_t ret = 1;
if (option && option[0] != 0) ret = atoi(option);
if (ret < 0) {
@@ -411,8 +409,8 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
}
void simVisuallizeOption(SScript *script, char *src, char *dst) {
- char *var, *token, *value;
- int dstLen, srcLen, tokenLen;
+ char * var, *token, *value;
+ int32_t dstLen, srcLen, tokenLen;
dst[0] = 0, dstLen = 0;
@@ -420,14 +418,14 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
var = strchr(src, '$');
if (var == NULL) break;
if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') {
- srcLen = (int)(var - src - 1);
+ srcLen = (int32_t)(var - src - 1);
memcpy(dst + dstLen, src, srcLen);
dstLen += srcLen;
src = var;
break;
}
- srcLen = (int)(var - src);
+ srcLen = (int32_t)(var - src);
memcpy(dst + dstLen, src, srcLen);
dstLen += srcLen;
@@ -435,13 +433,13 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
value = simGetVariable(script, token, tokenLen);
strcpy(dst + dstLen, value);
- dstLen += (int)strlen(value);
+ dstLen += (int32_t)strlen(value);
}
strcpy(dst + dstLen, src);
}
-void simCloseRestFulConnect(SScript *script) {
+void simCloseRestFulConnect(SScript *script) {
memset(script->auth, 0, sizeof(script->auth));
}
@@ -465,7 +463,7 @@ void simCloseTaosdConnect(SScript *script) {
// {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}
// {"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}
// {"status":"succ","head":["ts","i"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10]],"rows":10}
-int simParseHttpCommandResult(SScript *script, char *command) {
+int32_t simParseHttpCommandResult(SScript *script, char *command) {
cJSON* root = cJSON_Parse(command);
if (root == NULL) {
simError("script:%s, failed to parse json, response:%s", script->fileName, command);
@@ -492,14 +490,15 @@ int simParseHttpCommandResult(SScript *script, char *command) {
cJSON_Delete(root);
return -1;
}
- int retcode = (int)code->valueint;
+ int32_t retcode = (int32_t)code->valueint;
if (retcode != 1017) {
- simError("script:%s, json:status:%s not equal to succ, response:%s", script->fileName, status->valuestring, command);
+ simError("script:%s, json:status:%s not equal to succ, response:%s", script->fileName, status->valuestring,
+ command);
cJSON_Delete(root);
return retcode;
} else {
simDebug("script:%s, json:status:%s not equal to succ, but code is %d, response:%s", script->fileName,
- status->valuestring, retcode, command);
+ status->valuestring, retcode, command);
cJSON_Delete(root);
return 0;
}
@@ -524,27 +523,27 @@ int simParseHttpCommandResult(SScript *script, char *command) {
return -1;
}
- int rowsize = cJSON_GetArraySize(data);
+ int32_t rowsize = cJSON_GetArraySize(data);
if (rowsize < 0) {
simError("script:%s, failed to parse json:data, data size %d, response:%s", script->fileName, rowsize, command);
cJSON_Delete(root);
return -1;
}
- int rowIndex = 0;
+ int32_t rowIndex = 0;
sprintf(script->rows, "%d", rowsize);
- for (int r = 0; r < rowsize; ++r) {
+ for (int32_t r = 0; r < rowsize; ++r) {
cJSON *row = cJSON_GetArrayItem(data, r);
if (row == NULL) continue;
if (rowIndex++ >= 10) break;
- int colsize = cJSON_GetArraySize(row);
+ int32_t colsize = cJSON_GetArraySize(row);
if (colsize < 0) {
break;
}
colsize = MIN(10, colsize);
- for (int c = 0; c < colsize; ++c) {
+ for (int32_t c = 0; c < colsize; ++c) {
cJSON *col = cJSON_GetArrayItem(row, c);
if (col->valuestring != NULL) {
strcpy(script->data[r][c], col->valuestring);
@@ -561,7 +560,7 @@ int simParseHttpCommandResult(SScript *script, char *command) {
return 0;
}
-int simExecuteRestFulCommand(SScript *script, char *command) {
+int32_t simExecuteRestFulCommand(SScript *script, char *command) {
char buf[5000] = {0};
sprintf(buf, "%s 2>/dev/null", command);
@@ -571,13 +570,13 @@ int simExecuteRestFulCommand(SScript *script, char *command) {
return -1;
}
- int mallocSize = 2000;
- int alreadyReadSize = 0;
- char* content = malloc(mallocSize);
+ int32_t mallocSize = 2000;
+ int32_t alreadyReadSize = 0;
+ char * content = malloc(mallocSize);
while (!feof(fp)) {
- int availSize = mallocSize - alreadyReadSize;
- int len = (int)fread(content + alreadyReadSize, 1, availSize, fp);
+ int32_t availSize = mallocSize - alreadyReadSize;
+ int32_t len = (int32_t)fread(content + alreadyReadSize, 1, availSize, fp);
if (len >= availSize) {
alreadyReadSize += len;
mallocSize *= 2;
@@ -595,10 +594,11 @@ bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
sprintf(command, "curl 127.0.0.1:6041/rest/login/%s/%s", user, pass);
bool success = false;
- for (int attempt = 0; attempt < 10; ++attempt) {
+ for (int32_t attempt = 0; attempt < 10; ++attempt) {
success = simExecuteRestFulCommand(script, command) == 0;
if (!success) {
- simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL), attempt);
+ simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
+ attempt);
taosMsleep(1000);
} else {
simDebug("script:%s, user:%s connect taosd successed, attempt:%d", script->fileName, user, attempt);
@@ -607,7 +607,8 @@ bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
}
if (!success) {
- sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum, taos_errstr(NULL));
+ sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum,
+ taos_errstr(NULL));
return false;
}
@@ -619,10 +620,11 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
simCloseTaosdConnect(script);
void *taos = NULL;
taosMsleep(2000);
- for (int attempt = 0; attempt < 10; ++attempt) {
+ for (int32_t attempt = 0; attempt < 10; ++attempt) {
taos = taos_connect(NULL, user, pass, NULL, tsDnodeShellPort);
if (taos == NULL) {
- simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL), attempt);
+ simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
+ attempt);
taosMsleep(1000);
} else {
simDebug("script:%s, user:%s connect taosd successed, attempt:%d", script->fileName, user, attempt);
@@ -631,7 +633,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
if (taos == NULL) {
- sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum, taos_errstr(NULL));
+ sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum,
+ taos_errstr(NULL));
return false;
}
@@ -642,9 +645,9 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
bool simCreateTaosdConnect(SScript *script, char *rest) {
- char *user = TSDB_DEFAULT_USER;
- char *token;
- int tokenLen;
+ char * user = TSDB_DEFAULT_USER;
+ char * token;
+ int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
rest = paGetToken(rest, &token, &tokenLen);
if (tokenLen != 0) {
@@ -659,26 +662,27 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
}
bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
- char timeStr[30] = {0};
- time_t tt;
+ char timeStr[30] = {0};
+ time_t tt;
struct tm *tp;
- SCmdLine *line = &script->lines[script->linePos];
- int ret = -1;
+ SCmdLine * line = &script->lines[script->linePos];
+ int32_t ret = -1;
+
+ TAOS_RES *pSql = NULL;
- TAOS_RES* pSql = NULL;
-
- for (int attempt = 0; attempt < 10; ++attempt) {
+ for (int32_t attempt = 0; attempt < 10; ++attempt) {
simLogSql(rest, false);
pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql);
-
+
if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
- simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF, tstrerror(ret));
+ simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
+ tstrerror(ret));
ret = 0;
break;
} else if (ret != 0) {
- simDebug("script:%s, taos:%p, %s failed, ret:%d:%s, error:%s",
- script->fileName, script->taos, rest, ret & 0XFFFF, tstrerror(ret), taos_errstr(pSql));
+ simDebug("script:%s, taos:%p, %s failed, ret:%d:%s, error:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
+ tstrerror(ret), taos_errstr(pSql));
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
@@ -689,7 +693,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
} else {
break;
}
-
+
taos_free_result(pSql);
}
@@ -698,8 +702,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
return false;
}
- int numOfRows = 0;
- int num_fields = taos_field_count(pSql);
+ 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);
@@ -717,9 +721,9 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
while ((row = taos_fetch_row(pSql))) {
if (numOfRows < MAX_QUERY_ROW_NUM) {
TAOS_FIELD *fields = taos_fetch_fields(pSql);
- int* length = taos_fetch_lengths(pSql);
-
- for (int i = 0; i < num_fields; i++) {
+ int32_t * length = taos_fetch_lengths(pSql);
+
+ for (int32_t i = 0; i < num_fields; i++) {
char *value = NULL;
if (i < MAX_QUERY_COL_NUM) {
value = script->data[numOfRows][i];
@@ -735,8 +739,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
switch (fields[i].type) {
case TSDB_DATA_TYPE_BOOL:
- sprintf(value, "%s",
- ((((int)(*((char *)row[i]))) == 1) ? "1" : "0"));
+ sprintf(value, "%s", ((((int32_t)(*((char *)row[i]))) == 1) ? "1" : "0"));
break;
case TSDB_DATA_TYPE_TINYINT:
sprintf(value, "%d", *((int8_t *)row[i]));
@@ -779,9 +782,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
tp = localtime(&tt);
strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", tp);
- sprintf(value, "%s.%03d", timeStr,
- (int)(*((int64_t *)row[i]) % 1000));
-
+ sprintf(value, "%s.%03d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000));
+
break;
default:
break;
@@ -814,17 +816,16 @@ bool simExecuteRestFulSqlCommand(SScript *script, char *rest) {
char command[4096];
sprintf(command, "curl -H 'Authorization: Taosd %s' -d \"%s\" 127.0.0.1:6041/rest/sql", script->auth, rest);
- int ret = -1;
- for (int attempt = 0; attempt < 10; ++attempt) {
+ int32_t ret = -1;
+ for (int32_t attempt = 0; attempt < 10; ++attempt) {
ret = simExecuteRestFulCommand(script, command);
- if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST ||
- ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
- simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF, tstrerror(ret));
+ if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
+ simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
+ tstrerror(ret));
ret = 0;
break;
} else if (ret != 0) {
- simDebug("script:%s, taos:%p, %s failed, ret:%d",
- script->fileName, script->taos, rest, ret);
+ simDebug("script:%s, taos:%p, %s failed, ret:%d", script->fileName, script->taos, rest, ret);
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
@@ -854,8 +855,8 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
simDebug("script:%s, exec:%s", script->fileName, rest);
strcpy(script->rows, "-1");
- for (int row = 0; row < MAX_QUERY_ROW_NUM; ++row) {
- for (int col = 0; col < MAX_QUERY_COL_NUM; ++col) {
+ for (int32_t row = 0; row < MAX_QUERY_ROW_NUM; ++row) {
+ for (int32_t col = 0; col < MAX_QUERY_COL_NUM; ++col) {
strcpy(script->data[row][col], "null");
}
}
@@ -903,23 +904,23 @@ bool simExecuteSqlSlowCmd(SScript *script, char *rest) {
bool simExecuteRestfulCmd(SScript *script, char *rest) {
FILE *fp = NULL;
- char filename[256];
- sprintf(filename, "%s/tmp.sql", tsScriptDir);
+ char filename[256];
+ sprintf(filename, "%s/tmp.sql", tsScriptDir);
fp = fopen(filename, "w");
if (fp == NULL) {
fprintf(stderr, "ERROR: failed to open file: %s\n", filename);
return false;
}
- char db[64] = {0};
- char tb[64] = {0};
- char gzip[32] = {0};
+ char db[64] = {0};
+ char tb[64] = {0};
+ char gzip[32] = {0};
int32_t ts;
int32_t times;
sscanf(rest, "%s %s %d %d %s", db, tb, &ts, ×, gzip);
-
+
fprintf(fp, "insert into %s.%s values ", db, tb);
- for (int i = 0; i < times; ++i) {
+ for (int32_t i = 0; i < times; ++i) {
fprintf(fp, "(%d000, %d)", ts + i, ts);
}
fprintf(fp, " \n");
@@ -951,8 +952,8 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
simDebug("script:%s, exec:%s", script->fileName, rest);
strcpy(script->rows, "-1");
- for (int row = 0; row < MAX_QUERY_ROW_NUM; ++row) {
- for (int col = 0; col < MAX_QUERY_COL_NUM; ++col) {
+ for (int32_t row = 0; row < MAX_QUERY_ROW_NUM; ++row) {
+ for (int32_t col = 0; col < MAX_QUERY_COL_NUM; ++col) {
strcpy(script->data[row][col], "null");
}
}
@@ -981,27 +982,27 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true;
}
- int ret;
- TAOS_RES* pSql = NULL;
+ int32_t ret;
+ TAOS_RES *pSql = NULL;
if (simAsyncQuery) {
char command[4096];
sprintf(command, "curl -H 'Authorization: Taosd %s' -d '%s' 127.0.0.1:6041/rest/sql", script->auth, rest);
ret = simExecuteRestFulCommand(script, command);
- }
- else {
+ } else {
pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql);
taos_free_result(pSql);
}
if (ret != TSDB_CODE_SUCCESS) {
- simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s",
- script->fileName, script->taos, rest, ret & 0XFFFF, tstrerror(ret));
+ simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s", script->fileName, script->taos,
+ rest, ret & 0XFFFF, tstrerror(ret));
script->linePos++;
return true;
}
-
- sprintf(script->error, "lineNum:%d. sql:%s expect failed, but success, ret:%d:%s", line->lineNum, rest, ret & 0XFFFF, tstrerror(ret));
+
+ sprintf(script->error, "lineNum:%d. sql:%s expect failed, but success, ret:%d:%s", line->lineNum, rest, ret & 0XFFFF,
+ tstrerror(ret));
return false;
}
diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c
index ef1a488f602959b740cbe863cc22654a24b2d41b..33fd24dd5823b8ec7bf818cec7c36ddac783bc24 100644
--- a/tests/tsim/src/simMain.c
+++ b/tests/tsim/src/simMain.c
@@ -13,6 +13,7 @@
* along with this program. If not, see .
*/
+#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "sim.h"
@@ -20,15 +21,15 @@
bool simAsyncQuery = false;
-void simHandleSignal(int signo) {
+void simHandleSignal(int32_t signo) {
simSystemCleanUp();
exit(1);
}
-int main(int argc, char *argv[]) {
+int32_t main(int32_t argc, char *argv[]) {
char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";
- for (int i = 1; i < argc; ++i) {
+ for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
tstrncpy(configDir, argv[++i], MAX_FILE_NAME_LEN);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
@@ -37,8 +38,7 @@ int main(int argc, char *argv[]) {
simAsyncQuery = true;
} else {
printf("usage: %s [options] \n", argv[0]);
- printf(" [-c config]: config directory, default is: %s\n",
- configDir);
+ printf(" [-c config]: config directory, default is: %s\n", configDir);
printf(" [-f script]: script filename\n");
exit(0);
}
diff --git a/tests/tsim/src/simParse.c b/tests/tsim/src/simParse.c
index 2e6121304f18022a74b9e4f09a8043b5b4beb909..b909f5bd8fc10bea09afd65dc504ae35d6de3505 100644
--- a/tests/tsim/src/simParse.c
+++ b/tests/tsim/src/simParse.c
@@ -57,6 +57,7 @@
*
*/
+#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "simParse.h"
@@ -64,16 +65,16 @@
#undef TAOS_MEM_CHECK
static SCommand *cmdHashList[MAX_NUM_CMD];
-static SCmdLine cmdLine[MAX_CMD_LINES];
-static char parseErr[MAX_ERROR_LEN];
-static char optionBuffer[MAX_OPTION_BUFFER];
-static int numOfLines, optionOffset;
-static SLabel label, dest;
-static SBlock block;
+static SCmdLine cmdLine[MAX_CMD_LINES];
+static char parseErr[MAX_ERROR_LEN];
+static char optionBuffer[MAX_OPTION_BUFFER];
+static int32_t numOfLines, optionOffset;
+static SLabel label, dest;
+static SBlock block;
-int simHashCmd(char *token, int tokenLen) {
- int i;
- int hash = 0;
+int32_t simHashCmd(char *token, int32_t tokenLen) {
+ int32_t i;
+ int32_t hash = 0;
for (i = 0; i < tokenLen; ++i) hash += token[i];
@@ -82,8 +83,8 @@ int simHashCmd(char *token, int tokenLen) {
return hash;
}
-SCommand *simCheckCmd(char *token, int tokenLen) {
- int hash;
+SCommand *simCheckCmd(char *token, int32_t tokenLen) {
+ int32_t hash;
SCommand *node;
hash = simHashCmd(token, tokenLen);
@@ -102,10 +103,10 @@ SCommand *simCheckCmd(char *token, int tokenLen) {
}
void simAddCmdIntoHash(SCommand *pCmd) {
- int hash;
+ int32_t hash;
SCommand *node;
- hash = simHashCmd(pCmd->name, (int)strlen(pCmd->name));
+ hash = simHashCmd(pCmd->name, (int32_t)strlen(pCmd->name));
node = cmdHashList[hash];
pCmd->next = node;
cmdHashList[hash] = pCmd;
@@ -122,7 +123,7 @@ void simResetParser() {
}
SScript *simBuildScriptObj(char *fileName) {
- int i, destPos;
+ int32_t i, destPos;
/* process labels */
@@ -176,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
}
SScript *simParseScript(char *fileName) {
- FILE *fd;
- int tokenLen, lineNum = 0;
- char buffer[MAX_LINE_LEN], name[128], *token, *rest;
+ FILE * fd;
+ int32_t tokenLen, lineNum = 0;
+ char buffer[MAX_LINE_LEN], name[128], *token, *rest;
SCommand *pCmd;
- SScript *script;
+ SScript * script;
if ((fileName[0] == '.') || (fileName[0] == '/')) {
strcpy(name, fileName);
@@ -199,12 +200,13 @@ SScript *simParseScript(char *fileName) {
if (fgets(buffer, sizeof(buffer), fd) == NULL) continue;
lineNum++;
- int cmdlen = (int)strlen(buffer);
- if (buffer[cmdlen - 1] == '\r' || buffer[cmdlen - 1] == '\n')
+ int32_t cmdlen = (int32_t)strlen(buffer);
+ if (buffer[cmdlen - 1] == '\r' || buffer[cmdlen - 1] == '\n') {
buffer[cmdlen - 1] = 0;
+ }
rest = buffer;
- for (int i = 0; i < cmdlen; ++i) {
+ for (int32_t i = 0; i < cmdlen; ++i) {
if (buffer[i] == '\r' || buffer[i] == '\n') {
buffer[i] = ' ';
}
@@ -249,9 +251,9 @@ SScript *simParseScript(char *fileName) {
return script;
}
-int simCheckExpression(char *exp) {
- char *op1, *op2, *op, *rest;
- int op1Len, op2Len, opLen;
+int32_t simCheckExpression(char *exp) {
+ char * op1, *op2, *op, *rest;
+ int32_t op1Len, op2Len, opLen;
rest = paGetToken(exp, &op1, &op1Len);
if (op1Len == 0) {
@@ -282,8 +284,7 @@ int simCheckExpression(char *exp) {
return -1;
}
} else if (opLen == 2) {
- if (op[1] != '=' ||
- (op[0] != '=' && op[0] != '<' && op[0] != '>' && op[0] != '!')) {
+ if (op[1] != '=' || (op[0] != '=' && op[0] != '<' && op[0] != '>' && op[0] != '!')) {
sprintf(parseErr, "left side of assignment must be variable");
return -1;
}
@@ -294,10 +295,10 @@ int simCheckExpression(char *exp) {
rest = paGetToken(rest, &op, &opLen);
- if (opLen == 0) return (int)(rest - exp);
+ if (opLen == 0) return (int32_t)(rest - exp);
/* if it is key word "then" */
- if (strncmp(op, "then", 4) == 0) return (int)(op - exp);
+ if (strncmp(op, "then", 4) == 0) return (int32_t)(op - exp);
rest = paGetToken(rest, &op2, &op2Len);
if (op2Len == 0) {
@@ -310,16 +311,15 @@ int simCheckExpression(char *exp) {
return -1;
}
- if (op[0] == '+' || op[0] == '-' || op[0] == '*' || op[0] == '/' ||
- op[0] == '.') {
- return (int)(rest - exp);
+ if (op[0] == '+' || op[0] == '-' || op[0] == '*' || op[0] == '/' || op[0] == '.') {
+ return (int32_t)(rest - exp);
}
return -1;
}
-bool simParseExpression(char *token, int lineNum) {
- int expLen;
+bool simParseExpression(char *token, int32_t lineNum) {
+ int32_t expLen;
expLen = simCheckExpression(token);
if (expLen <= 0) return -1;
@@ -335,9 +335,9 @@ bool simParseExpression(char *token, int lineNum) {
return true;
}
-bool simParseIfCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *ret;
- int expLen;
+bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * ret;
+ int32_t expLen;
expLen = simCheckExpression(rest);
@@ -364,8 +364,8 @@ bool simParseIfCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
- int expLen;
+bool simParseElifCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t expLen;
expLen = simCheckExpression(rest);
@@ -382,8 +382,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
}
cmdLine[numOfLines].cmdno = SIM_CMD_GOTO;
- block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] =
- &(cmdLine[numOfLines].jump);
+ block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = &(cmdLine[numOfLines].jump);
block.numJump[block.top - 1]++;
numOfLines++;
@@ -402,7 +401,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
+bool simParseElseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) {
sprintf(parseErr, "no matching if");
return false;
@@ -414,8 +413,7 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
}
cmdLine[numOfLines].cmdno = SIM_CMD_GOTO;
- block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] =
- &(cmdLine[numOfLines].jump);
+ block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = &(cmdLine[numOfLines].jump);
block.numJump[block.top - 1]++;
numOfLines++;
@@ -426,8 +424,8 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
- int i;
+bool simParseEndiCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t i;
if (block.top < 1) {
sprintf(parseErr, "no matching if");
@@ -441,8 +439,9 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
if (block.pos[block.top - 1]) *(block.pos[block.top - 1]) = numOfLines;
- for (i = 0; i < block.numJump[block.top - 1]; ++i)
+ for (i = 0; i < block.numJump[block.top - 1]; ++i) {
*(block.jump[block.top - 1][i]) = numOfLines;
+ }
block.numJump[block.top - 1] = 0;
block.top--;
@@ -450,8 +449,8 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseWhileCmd(char *rest, SCommand *pCmd, int lineNum) {
- int expLen;
+bool simParseWhileCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t expLen;
expLen = simCheckExpression(rest);
@@ -473,8 +472,8 @@ bool simParseWhileCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseEndwCmd(char *rest, SCommand *pCmd, int lineNum) {
- int i;
+bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t i;
if (block.top < 1) {
sprintf(parseErr, "no matching while");
@@ -493,17 +492,18 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int lineNum) {
*(block.pos[block.top - 1]) = numOfLines;
- for (i = 0; i < block.numJump[block.top - 1]; ++i)
+ for (i = 0; i < block.numJump[block.top - 1]; ++i) {
*(block.jump[block.top - 1][i]) = numOfLines;
+ }
block.top--;
return true;
}
-bool simParseSwitchCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *token;
- int tokenLen;
+bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * token;
+ int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
if (tokenLen == 0) {
@@ -524,9 +524,9 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *token;
- int tokenLen;
+bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * token;
+ int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
if (tokenLen == 0) {
@@ -544,16 +544,16 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
return false;
}
- if (block.pos[block.top - 1] != NULL)
+ if (block.pos[block.top - 1] != NULL) {
*(block.pos[block.top - 1]) = numOfLines;
+ }
block.pos[block.top - 1] = &(cmdLine[numOfLines].jump);
cmdLine[numOfLines].cmdno = SIM_CMD_TEST;
cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset;
- memcpy(optionBuffer + optionOffset, block.sexp[block.top - 1],
- block.sexpLen[block.top - 1]);
+ memcpy(optionBuffer + optionOffset, block.sexp[block.top - 1], block.sexpLen[block.top - 1]);
optionOffset += block.sexpLen[block.top - 1];
*(optionBuffer + optionOffset++) = ' ';
*(optionBuffer + optionOffset++) = '=';
@@ -567,20 +567,18 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseBreakCmd(char *rest, SCommand *pCmd, int lineNum) {
+bool simParseBreakCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) {
sprintf(parseErr, "no blcok exists");
return false;
}
- if (block.type[block.top - 1] != BLOCK_SWITCH &&
- block.type[block.top - 1] != BLOCK_WHILE) {
+ if (block.type[block.top - 1] != BLOCK_SWITCH && block.type[block.top - 1] != BLOCK_WHILE) {
sprintf(parseErr, "not in switch or while block");
return false;
}
- block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] =
- &(cmdLine[numOfLines].jump);
+ block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = &(cmdLine[numOfLines].jump);
block.numJump[block.top - 1]++;
cmdLine[numOfLines].cmdno = SIM_CMD_GOTO;
@@ -590,7 +588,7 @@ bool simParseBreakCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseDefaultCmd(char *rest, SCommand *pCmd, int lineNum) {
+bool simParseDefaultCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) {
sprintf(parseErr, "no matching switch");
return false;
@@ -601,14 +599,15 @@ bool simParseDefaultCmd(char *rest, SCommand *pCmd, int lineNum) {
return false;
}
- if (block.pos[block.top - 1] != NULL)
+ if (block.pos[block.top - 1] != NULL) {
*(block.pos[block.top - 1]) = numOfLines;
+ }
return true;
}
-bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
- int i;
+bool simParseEndsCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t i;
if (block.top < 1) {
sprintf(parseErr, "no matching switch");
@@ -620,8 +619,9 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
return false;
}
- for (i = 0; i < block.numJump[block.top - 1]; ++i)
+ for (i = 0; i < block.numJump[block.top - 1]; ++i) {
*(block.jump[block.top - 1][i]) = numOfLines;
+ }
block.numJump[block.top - 1] = 0;
block.top--;
@@ -629,7 +629,7 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseContinueCmd(char *rest, SCommand *pCmd, int lineNum) {
+bool simParseContinueCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) {
sprintf(parseErr, "no matching while");
return false;
@@ -648,14 +648,14 @@ bool simParseContinueCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParsePrintCmd(char *rest, SCommand *pCmd, int lineNum) {
- int expLen;
+bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t expLen;
rest++;
cmdLine[numOfLines].cmdno = SIM_CMD_PRINT;
cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset;
- expLen = (int)strlen(rest);
+ expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0;
@@ -665,8 +665,8 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int lineNum) {
}
void simCheckSqlOption(char *rest) {
- int valueLen;
- char *value, *xpos;
+ int32_t valueLen;
+ char * value, *xpos;
xpos = strstr(rest, " -x"); // need a blank
if (xpos) {
@@ -682,15 +682,15 @@ void simCheckSqlOption(char *rest) {
}
}
-bool simParseSqlCmd(char *rest, SCommand *pCmd, int lineNum) {
- int expLen;
+bool simParseSqlCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t expLen;
rest++;
simCheckSqlOption(rest);
cmdLine[numOfLines].cmdno = SIM_CMD_SQL;
cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset;
- expLen = (int)strlen(rest);
+ expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0;
@@ -699,14 +699,14 @@ bool simParseSqlCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int lineNum) {
- int expLen;
+bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t expLen;
rest++;
cmdLine[numOfLines].cmdno = SIM_CMD_SQL_ERROR;
cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset;
- expLen = (int)strlen(rest);
+ expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0;
@@ -715,26 +715,26 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int lineNum) {
+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, int lineNum) {
+bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSqlCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL;
return true;
}
-bool simParseSystemCmd(char *rest, SCommand *pCmd, int lineNum) {
- int expLen;
+bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ int32_t expLen;
rest++;
cmdLine[numOfLines].cmdno = SIM_CMD_SYSTEM;
cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset;
- expLen = (int)strlen(rest);
+ expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0;
@@ -743,15 +743,15 @@ bool simParseSystemCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int lineNum) {
+bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSystemCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SYSTEM_CONTENT;
return true;
}
-bool simParseSleepCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *token;
- int tokenLen;
+bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * token;
+ int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP;
cmdLine[numOfLines].lineNum = lineNum;
@@ -768,9 +768,9 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseReturnCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *token;
- int tokenLen;
+bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * token;
+ int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_RETURN;
cmdLine[numOfLines].lineNum = lineNum;
@@ -787,9 +787,9 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseGotoCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *token;
- int tokenLen;
+bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * token;
+ int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
@@ -810,9 +810,9 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseRunCmd(char *rest, SCommand *pCmd, int lineNum) {
- char *token;
- int tokenLen;
+bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
+ char * token;
+ int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
@@ -832,14 +832,14 @@ bool simParseRunCmd(char *rest, SCommand *pCmd, int lineNum) {
return true;
}
-bool simParseRunBackCmd(char *rest, SCommand *pCmd, int lineNum) {
+bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseRunCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RUN_BACK;
return true;
}
void simInitsimCmdList() {
- int cmdno;
+ int32_t cmdno;
memset(simCmdList, 0, SIM_CMD_END * sizeof(SCommand));
/* internal command */
diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c
index 17df7f306a47545f7283df1848f98ce18b87db79..30d0d247b8d67ff6b49551d646066d30c31d4ac8 100644
--- a/tests/tsim/src/simSystem.c
+++ b/tests/tsim/src/simSystem.c
@@ -13,6 +13,7 @@
* along with this program. If not, see .
*/
+#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "taos.h"
@@ -24,11 +25,11 @@
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
SCommand simCmdList[SIM_CMD_END];
-int simScriptPos = -1;
-int simScriptSucced = 0;
-int simDebugFlag = 135;
-void simCloseTaosdConnect(SScript *script);
-char simHostName[128];
+int32_t simScriptPos = -1;
+int32_t simScriptSucced = 0;
+int32_t simDebugFlag = 135;
+void simCloseTaosdConnect(SScript *script);
+char simHostName[128];
char *simParseArbitratorName(char *varName) {
static char hostName[140];
@@ -39,8 +40,8 @@ char *simParseArbitratorName(char *varName) {
char *simParseHostName(char *varName) {
static char hostName[140];
- int index = atoi(varName + 8);
- int port = 7100;
+ int32_t index = atoi(varName + 8);
+ int32_t port = 7100;
switch (index) {
case 1:
port = 7100;
@@ -70,9 +71,9 @@ char *simParseHostName(char *varName) {
port = 7900;
break;
}
-
+
sprintf(hostName, "'%s:%d'", simHostName, port);
- //simInfo("hostName:%s", hostName);
+ // simInfo("hostName:%s", hostName);
return hostName;
}
@@ -88,12 +89,19 @@ void simSystemCleanUp() {}
void simFreeScript(SScript *script) {
if (script->type == SIM_SCRIPT_TYPE_MAIN) {
- for (int i = 0; i < script->bgScriptLen; ++i) {
+ simInfo("script:%s, background script num:%d, stop them", script->fileName, script->bgScriptLen);
+
+ for (int32_t i = 0; i < script->bgScriptLen; ++i) {
SScript *bgScript = script->bgScripts[i];
+ simInfo("script:%s, set stop flag", script->fileName);
bgScript->killed = true;
+ if (taosCheckPthreadValid(bgScript->bgPid)) {
+ pthread_join(bgScript->bgPid, NULL);
+ }
}
}
+ simDebug("script:%s, is freed", script->fileName);
taos_close(script->taos);
taosTFree(script->lines);
taosTFree(script->optionBuffer);
@@ -103,25 +111,24 @@ void simFreeScript(SScript *script) {
SScript *simProcessCallOver(SScript *script) {
if (script->type == SIM_SCRIPT_TYPE_MAIN) {
if (script->killed) {
- simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX
- "failed" FAILED_POSTFIX ", error:%s",
- script->fileName, script->error);
+ simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s",
+ script->fileName, script->error);
exit(-1);
} else {
- simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX
- "success" SUCCESS_POSTFIX,
- script->fileName);
+ simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX,
+ script->fileName);
simCloseTaosdConnect(script);
simScriptSucced++;
simScriptPos--;
+
+ simFreeScript(script);
if (simScriptPos == -1) {
simInfo("----------------------------------------------------------------------");
simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced);
exit(0);
}
- simFreeScript(script);
- return simScriptList[simScriptPos];
+ return NULL;
}
} else {
simInfo("script:%s, is stopped by main script", script->fileName);
@@ -143,11 +150,11 @@ void *simExecuteScript(void *inputScript) {
if (script == NULL) break;
} else {
SCmdLine *line = &script->lines[script->linePos];
- char *option = script->optionBuffer + line->optionOffset;
+ char * option = script->optionBuffer + line->optionOffset;
simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
SCommand *cmd = &simCmdList[line->cmdno];
- int ret = (*(cmd->executeCmd))(script, option);
+ int32_t ret = (*(cmd->executeCmd))(script, option);
if (!ret) {
script->killed = true;
}