提交 d6f527d8 编写于 作者: S Shengliang Guan

[TD-1952]<fix>: tsim crash while run background scripts

上级 855ecf59
...@@ -100,7 +100,7 @@ typedef struct _cmd_t { ...@@ -100,7 +100,7 @@ typedef struct _cmd_t {
int16_t cmdno; int16_t cmdno;
int16_t nlen; int16_t nlen;
char name[MAX_SIM_CMD_NAME_LEN]; 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); bool (*executeCmd)(struct _script_t *script, char *option);
struct _cmd_t *next; struct _cmd_t *next;
} SCommand; } SCommand;
...@@ -111,7 +111,7 @@ typedef struct { ...@@ -111,7 +111,7 @@ typedef struct {
int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */ // will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
int16_t lineNum; // correspodning line number in original file int16_t lineNum; // correspodning line number in original file
int optionOffset; // relative option offset int32_t optionOffset;// relative option offset
} SCmdLine; } SCmdLine;
typedef struct _var_t { typedef struct _var_t {
...@@ -121,59 +121,56 @@ typedef struct _var_t { ...@@ -121,59 +121,56 @@ typedef struct _var_t {
} SVariable; } SVariable;
typedef struct _script_t { typedef struct _script_t {
int type; int32_t type;
bool killed; bool killed;
void * taos;
void *taos; char rows[12]; // number of rows data retrieved
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 data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM] char system_exit_code[12];
[MAX_QUERY_VALUE_LEN]; // query results char system_ret_content[MAX_SYSTEM_RESULT_LEN];
char system_exit_code[12]; int32_t varLen;
char system_ret_content[MAX_SYSTEM_RESULT_LEN]; int32_t linePos; // current cmd position
int32_t numOfLines; // number of lines in the script
int varLen; int32_t bgScriptLen;
int linePos; // current cmd position char fileName[MAX_FILE_NAME_LEN]; // script file name
int numOfLines; // number of lines in the script char error[MAX_ERROR_LEN];
int bgScriptLen; char * optionBuffer;
char fileName[MAX_FILE_NAME_LEN]; // script file name
char error[MAX_ERROR_LEN];
char *optionBuffer;
SCmdLine *lines; // command list SCmdLine *lines; // command list
SVariable variables[MAX_VAR_LEN]; SVariable variables[MAX_VAR_LEN];
pthread_t bgPid;
char auth[128];
struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM]; struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM];
char auth[128];
} SScript; } SScript;
extern SScript *simScriptList[MAX_MAIN_SCRIPT_NUM]; extern SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
extern SCommand simCmdList[]; extern SCommand simCmdList[];
extern int simScriptPos; extern int32_t simScriptPos;
extern int simScriptSucced; extern int32_t simScriptSucced;
extern int simDebugFlag; extern int32_t simDebugFlag;
extern char tsScriptDir[]; extern char tsScriptDir[];
extern bool simAsyncQuery; extern bool simAsyncQuery;
SScript *simParseScript(char *fileName); SScript *simParseScript(char *fileName);
SScript *simProcessCallOver(SScript *script); SScript *simProcessCallOver(SScript *script);
void *simExecuteScript(void *script); void * simExecuteScript(void *script);
void simInitsimCmdList(); void simInitsimCmdList();
bool simSystemInit(); bool simSystemInit();
void simSystemCleanUp(); void simSystemCleanUp();
char *simGetVariable(SScript *script, char *varName, int varLen); char * simGetVariable(SScript *script, char *varName, int32_t varLen);
bool simExecuteExpCmd(SScript *script, char *option); bool simExecuteExpCmd(SScript *script, char *option);
bool simExecuteTestCmd(SScript *script, char *option); bool simExecuteTestCmd(SScript *script, char *option);
bool simExecuteGotoCmd(SScript *script, char *option); bool simExecuteGotoCmd(SScript *script, char *option);
bool simExecuteRunCmd(SScript *script, char *option); bool simExecuteRunCmd(SScript *script, char *option);
bool simExecuteRunBackCmd(SScript *script, char *option); bool simExecuteRunBackCmd(SScript *script, char *option);
bool simExecuteSystemCmd(SScript *script, char *option); bool simExecuteSystemCmd(SScript *script, char *option);
bool simExecuteSystemContentCmd(SScript *script, char *option); bool simExecuteSystemContentCmd(SScript *script, char *option);
bool simExecutePrintCmd(SScript *script, char *option); bool simExecutePrintCmd(SScript *script, char *option);
bool simExecuteSleepCmd(SScript *script, char *option); bool simExecuteSleepCmd(SScript *script, char *option);
bool simExecuteReturnCmd(SScript *script, char *option); bool simExecuteReturnCmd(SScript *script, char *option);
bool simExecuteSqlCmd(SScript *script, char *option); bool simExecuteSqlCmd(SScript *script, char *option);
bool simExecuteSqlErrorCmd(SScript *script, char *rest); bool simExecuteSqlErrorCmd(SScript *script, char *rest);
bool simExecuteSqlSlowCmd(SScript *script, char *option); bool simExecuteSqlSlowCmd(SScript *script, char *option);
bool simExecuteRestfulCmd(SScript *script, char *rest); bool simExecuteRestfulCmd(SScript *script, char *rest);
void simVisuallizeOption(SScript *script, char *src, char *dst); void simVisuallizeOption(SScript *script, char *src, char *dst);
#endif #endif
\ No newline at end of file
...@@ -50,6 +50,6 @@ typedef struct { ...@@ -50,6 +50,6 @@ typedef struct {
char sexpLen[MAX_NUM_BLOCK]; /*switch expression length */ char sexpLen[MAX_NUM_BLOCK]; /*switch expression length */
} SBlock; } SBlock;
bool simParseExpression(char *token, int lineNum); bool simParseExpression(char *token, int32_t lineNum);
#endif #endif
\ No newline at end of file
此差异已折叠。
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tglobal.h" #include "tglobal.h"
#include "sim.h" #include "sim.h"
...@@ -20,15 +21,15 @@ ...@@ -20,15 +21,15 @@
bool simAsyncQuery = false; bool simAsyncQuery = false;
void simHandleSignal(int signo) { void simHandleSignal(int32_t signo) {
simSystemCleanUp(); simSystemCleanUp();
exit(1); 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"; 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) { if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
tstrncpy(configDir, argv[++i], MAX_FILE_NAME_LEN); tstrncpy(configDir, argv[++i], MAX_FILE_NAME_LEN);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) { } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
...@@ -37,8 +38,7 @@ int main(int argc, char *argv[]) { ...@@ -37,8 +38,7 @@ int main(int argc, char *argv[]) {
simAsyncQuery = true; simAsyncQuery = true;
} else { } else {
printf("usage: %s [options] \n", argv[0]); printf("usage: %s [options] \n", argv[0]);
printf(" [-c config]: config directory, default is: %s\n", printf(" [-c config]: config directory, default is: %s\n", configDir);
configDir);
printf(" [-f script]: script filename\n"); printf(" [-f script]: script filename\n");
exit(0); exit(0);
} }
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
* *
*/ */
#define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "simParse.h" #include "simParse.h"
...@@ -64,16 +65,16 @@ ...@@ -64,16 +65,16 @@
#undef TAOS_MEM_CHECK #undef TAOS_MEM_CHECK
static SCommand *cmdHashList[MAX_NUM_CMD]; static SCommand *cmdHashList[MAX_NUM_CMD];
static SCmdLine cmdLine[MAX_CMD_LINES]; static SCmdLine cmdLine[MAX_CMD_LINES];
static char parseErr[MAX_ERROR_LEN]; static char parseErr[MAX_ERROR_LEN];
static char optionBuffer[MAX_OPTION_BUFFER]; static char optionBuffer[MAX_OPTION_BUFFER];
static int numOfLines, optionOffset; static int32_t numOfLines, optionOffset;
static SLabel label, dest; static SLabel label, dest;
static SBlock block; static SBlock block;
int simHashCmd(char *token, int tokenLen) { int32_t simHashCmd(char *token, int32_t tokenLen) {
int i; int32_t i;
int hash = 0; int32_t hash = 0;
for (i = 0; i < tokenLen; ++i) hash += token[i]; for (i = 0; i < tokenLen; ++i) hash += token[i];
...@@ -82,8 +83,8 @@ int simHashCmd(char *token, int tokenLen) { ...@@ -82,8 +83,8 @@ int simHashCmd(char *token, int tokenLen) {
return hash; return hash;
} }
SCommand *simCheckCmd(char *token, int tokenLen) { SCommand *simCheckCmd(char *token, int32_t tokenLen) {
int hash; int32_t hash;
SCommand *node; SCommand *node;
hash = simHashCmd(token, tokenLen); hash = simHashCmd(token, tokenLen);
...@@ -102,10 +103,10 @@ SCommand *simCheckCmd(char *token, int tokenLen) { ...@@ -102,10 +103,10 @@ SCommand *simCheckCmd(char *token, int tokenLen) {
} }
void simAddCmdIntoHash(SCommand *pCmd) { void simAddCmdIntoHash(SCommand *pCmd) {
int hash; int32_t hash;
SCommand *node; SCommand *node;
hash = simHashCmd(pCmd->name, (int)strlen(pCmd->name)); hash = simHashCmd(pCmd->name, (int32_t)strlen(pCmd->name));
node = cmdHashList[hash]; node = cmdHashList[hash];
pCmd->next = node; pCmd->next = node;
cmdHashList[hash] = pCmd; cmdHashList[hash] = pCmd;
...@@ -122,7 +123,7 @@ void simResetParser() { ...@@ -122,7 +123,7 @@ void simResetParser() {
} }
SScript *simBuildScriptObj(char *fileName) { SScript *simBuildScriptObj(char *fileName) {
int i, destPos; int32_t i, destPos;
/* process labels */ /* process labels */
...@@ -176,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) { ...@@ -176,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
} }
SScript *simParseScript(char *fileName) { SScript *simParseScript(char *fileName) {
FILE *fd; FILE * fd;
int tokenLen, lineNum = 0; int32_t tokenLen, lineNum = 0;
char buffer[MAX_LINE_LEN], name[128], *token, *rest; char buffer[MAX_LINE_LEN], name[128], *token, *rest;
SCommand *pCmd; SCommand *pCmd;
SScript *script; SScript * script;
if ((fileName[0] == '.') || (fileName[0] == '/')) { if ((fileName[0] == '.') || (fileName[0] == '/')) {
strcpy(name, fileName); strcpy(name, fileName);
...@@ -199,12 +200,13 @@ SScript *simParseScript(char *fileName) { ...@@ -199,12 +200,13 @@ SScript *simParseScript(char *fileName) {
if (fgets(buffer, sizeof(buffer), fd) == NULL) continue; if (fgets(buffer, sizeof(buffer), fd) == NULL) continue;
lineNum++; lineNum++;
int cmdlen = (int)strlen(buffer); int32_t cmdlen = (int32_t)strlen(buffer);
if (buffer[cmdlen - 1] == '\r' || buffer[cmdlen - 1] == '\n') if (buffer[cmdlen - 1] == '\r' || buffer[cmdlen - 1] == '\n') {
buffer[cmdlen - 1] = 0; buffer[cmdlen - 1] = 0;
}
rest = buffer; rest = buffer;
for (int i = 0; i < cmdlen; ++i) { for (int32_t i = 0; i < cmdlen; ++i) {
if (buffer[i] == '\r' || buffer[i] == '\n') { if (buffer[i] == '\r' || buffer[i] == '\n') {
buffer[i] = ' '; buffer[i] = ' ';
} }
...@@ -249,9 +251,9 @@ SScript *simParseScript(char *fileName) { ...@@ -249,9 +251,9 @@ SScript *simParseScript(char *fileName) {
return script; return script;
} }
int simCheckExpression(char *exp) { int32_t simCheckExpression(char *exp) {
char *op1, *op2, *op, *rest; char * op1, *op2, *op, *rest;
int op1Len, op2Len, opLen; int32_t op1Len, op2Len, opLen;
rest = paGetToken(exp, &op1, &op1Len); rest = paGetToken(exp, &op1, &op1Len);
if (op1Len == 0) { if (op1Len == 0) {
...@@ -282,8 +284,7 @@ int simCheckExpression(char *exp) { ...@@ -282,8 +284,7 @@ int simCheckExpression(char *exp) {
return -1; return -1;
} }
} else if (opLen == 2) { } else if (opLen == 2) {
if (op[1] != '=' || if (op[1] != '=' || (op[0] != '=' && op[0] != '<' && op[0] != '>' && op[0] != '!')) {
(op[0] != '=' && op[0] != '<' && op[0] != '>' && op[0] != '!')) {
sprintf(parseErr, "left side of assignment must be variable"); sprintf(parseErr, "left side of assignment must be variable");
return -1; return -1;
} }
...@@ -294,10 +295,10 @@ int simCheckExpression(char *exp) { ...@@ -294,10 +295,10 @@ int simCheckExpression(char *exp) {
rest = paGetToken(rest, &op, &opLen); 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 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); rest = paGetToken(rest, &op2, &op2Len);
if (op2Len == 0) { if (op2Len == 0) {
...@@ -310,16 +311,15 @@ int simCheckExpression(char *exp) { ...@@ -310,16 +311,15 @@ int simCheckExpression(char *exp) {
return -1; return -1;
} }
if (op[0] == '+' || op[0] == '-' || op[0] == '*' || op[0] == '/' || if (op[0] == '+' || op[0] == '-' || op[0] == '*' || op[0] == '/' || op[0] == '.') {
op[0] == '.') { return (int32_t)(rest - exp);
return (int)(rest - exp);
} }
return -1; return -1;
} }
bool simParseExpression(char *token, int lineNum) { bool simParseExpression(char *token, int32_t lineNum) {
int expLen; int32_t expLen;
expLen = simCheckExpression(token); expLen = simCheckExpression(token);
if (expLen <= 0) return -1; if (expLen <= 0) return -1;
...@@ -335,9 +335,9 @@ bool simParseExpression(char *token, int lineNum) { ...@@ -335,9 +335,9 @@ bool simParseExpression(char *token, int lineNum) {
return true; return true;
} }
bool simParseIfCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *ret; char * ret;
int expLen; int32_t expLen;
expLen = simCheckExpression(rest); expLen = simCheckExpression(rest);
...@@ -364,8 +364,8 @@ bool simParseIfCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -364,8 +364,8 @@ bool simParseIfCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseElifCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int expLen; int32_t expLen;
expLen = simCheckExpression(rest); expLen = simCheckExpression(rest);
...@@ -382,8 +382,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -382,8 +382,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
} }
cmdLine[numOfLines].cmdno = SIM_CMD_GOTO; cmdLine[numOfLines].cmdno = SIM_CMD_GOTO;
block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = &(cmdLine[numOfLines].jump);
&(cmdLine[numOfLines].jump);
block.numJump[block.top - 1]++; block.numJump[block.top - 1]++;
numOfLines++; numOfLines++;
...@@ -402,7 +401,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -402,7 +401,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseElseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no matching if"); sprintf(parseErr, "no matching if");
return false; return false;
...@@ -414,8 +413,7 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -414,8 +413,7 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
} }
cmdLine[numOfLines].cmdno = SIM_CMD_GOTO; cmdLine[numOfLines].cmdno = SIM_CMD_GOTO;
block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = &(cmdLine[numOfLines].jump);
&(cmdLine[numOfLines].jump);
block.numJump[block.top - 1]++; block.numJump[block.top - 1]++;
numOfLines++; numOfLines++;
...@@ -426,8 +424,8 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -426,8 +424,8 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseEndiCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int i; int32_t i;
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no matching if"); sprintf(parseErr, "no matching if");
...@@ -441,8 +439,9 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -441,8 +439,9 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
if (block.pos[block.top - 1]) *(block.pos[block.top - 1]) = numOfLines; 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.jump[block.top - 1][i]) = numOfLines;
}
block.numJump[block.top - 1] = 0; block.numJump[block.top - 1] = 0;
block.top--; block.top--;
...@@ -450,8 +449,8 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -450,8 +449,8 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseWhileCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseWhileCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int expLen; int32_t expLen;
expLen = simCheckExpression(rest); expLen = simCheckExpression(rest);
...@@ -473,8 +472,8 @@ bool simParseWhileCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -473,8 +472,8 @@ bool simParseWhileCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseEndwCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int i; int32_t i;
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no matching while"); sprintf(parseErr, "no matching while");
...@@ -493,17 +492,18 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -493,17 +492,18 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int lineNum) {
*(block.pos[block.top - 1]) = numOfLines; *(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.jump[block.top - 1][i]) = numOfLines;
}
block.top--; block.top--;
return true; return true;
} }
bool simParseSwitchCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token; char * token;
int tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
if (tokenLen == 0) { if (tokenLen == 0) {
...@@ -524,9 +524,9 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -524,9 +524,9 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token; char * token;
int tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
if (tokenLen == 0) { if (tokenLen == 0) {
...@@ -544,16 +544,16 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -544,16 +544,16 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
return false; 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]) = numOfLines;
}
block.pos[block.top - 1] = &(cmdLine[numOfLines].jump); block.pos[block.top - 1] = &(cmdLine[numOfLines].jump);
cmdLine[numOfLines].cmdno = SIM_CMD_TEST; cmdLine[numOfLines].cmdno = SIM_CMD_TEST;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset; cmdLine[numOfLines].optionOffset = optionOffset;
memcpy(optionBuffer + optionOffset, block.sexp[block.top - 1], memcpy(optionBuffer + optionOffset, block.sexp[block.top - 1], block.sexpLen[block.top - 1]);
block.sexpLen[block.top - 1]);
optionOffset += block.sexpLen[block.top - 1]; optionOffset += block.sexpLen[block.top - 1];
*(optionBuffer + optionOffset++) = ' '; *(optionBuffer + optionOffset++) = ' ';
*(optionBuffer + optionOffset++) = '='; *(optionBuffer + optionOffset++) = '=';
...@@ -567,20 +567,18 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -567,20 +567,18 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseBreakCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseBreakCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no blcok exists"); sprintf(parseErr, "no blcok exists");
return false; return false;
} }
if (block.type[block.top - 1] != BLOCK_SWITCH && if (block.type[block.top - 1] != BLOCK_SWITCH && block.type[block.top - 1] != BLOCK_WHILE) {
block.type[block.top - 1] != BLOCK_WHILE) {
sprintf(parseErr, "not in switch or while block"); sprintf(parseErr, "not in switch or while block");
return false; return false;
} }
block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = block.jump[block.top - 1][(uint8_t)block.numJump[block.top - 1]] = &(cmdLine[numOfLines].jump);
&(cmdLine[numOfLines].jump);
block.numJump[block.top - 1]++; block.numJump[block.top - 1]++;
cmdLine[numOfLines].cmdno = SIM_CMD_GOTO; cmdLine[numOfLines].cmdno = SIM_CMD_GOTO;
...@@ -590,7 +588,7 @@ bool simParseBreakCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -590,7 +588,7 @@ bool simParseBreakCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseDefaultCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseDefaultCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no matching switch"); sprintf(parseErr, "no matching switch");
return false; return false;
...@@ -601,14 +599,15 @@ bool simParseDefaultCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -601,14 +599,15 @@ bool simParseDefaultCmd(char *rest, SCommand *pCmd, int lineNum) {
return false; 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]) = numOfLines;
}
return true; return true;
} }
bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseEndsCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int i; int32_t i;
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no matching switch"); sprintf(parseErr, "no matching switch");
...@@ -620,8 +619,9 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -620,8 +619,9 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
return false; 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.jump[block.top - 1][i]) = numOfLines;
}
block.numJump[block.top - 1] = 0; block.numJump[block.top - 1] = 0;
block.top--; block.top--;
...@@ -629,7 +629,7 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -629,7 +629,7 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseContinueCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseContinueCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
if (block.top < 1) { if (block.top < 1) {
sprintf(parseErr, "no matching while"); sprintf(parseErr, "no matching while");
return false; return false;
...@@ -648,14 +648,14 @@ bool simParseContinueCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -648,14 +648,14 @@ bool simParseContinueCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParsePrintCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int expLen; int32_t expLen;
rest++; rest++;
cmdLine[numOfLines].cmdno = SIM_CMD_PRINT; cmdLine[numOfLines].cmdno = SIM_CMD_PRINT;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset; cmdLine[numOfLines].optionOffset = optionOffset;
expLen = (int)strlen(rest); expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen); memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1; optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0; *(optionBuffer + optionOffset - 1) = 0;
...@@ -665,8 +665,8 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -665,8 +665,8 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int lineNum) {
} }
void simCheckSqlOption(char *rest) { void simCheckSqlOption(char *rest) {
int valueLen; int32_t valueLen;
char *value, *xpos; char * value, *xpos;
xpos = strstr(rest, " -x"); // need a blank xpos = strstr(rest, " -x"); // need a blank
if (xpos) { if (xpos) {
...@@ -682,15 +682,15 @@ void simCheckSqlOption(char *rest) { ...@@ -682,15 +682,15 @@ void simCheckSqlOption(char *rest) {
} }
} }
bool simParseSqlCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSqlCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int expLen; int32_t expLen;
rest++; rest++;
simCheckSqlOption(rest); simCheckSqlOption(rest);
cmdLine[numOfLines].cmdno = SIM_CMD_SQL; cmdLine[numOfLines].cmdno = SIM_CMD_SQL;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset; cmdLine[numOfLines].optionOffset = optionOffset;
expLen = (int)strlen(rest); expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen); memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1; optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0; *(optionBuffer + optionOffset - 1) = 0;
...@@ -699,14 +699,14 @@ bool simParseSqlCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -699,14 +699,14 @@ bool simParseSqlCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int expLen; int32_t expLen;
rest++; rest++;
cmdLine[numOfLines].cmdno = SIM_CMD_SQL_ERROR; cmdLine[numOfLines].cmdno = SIM_CMD_SQL_ERROR;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset; cmdLine[numOfLines].optionOffset = optionOffset;
expLen = (int)strlen(rest); expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen); memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1; optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0; *(optionBuffer + optionOffset - 1) = 0;
...@@ -715,26 +715,26 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -715,26 +715,26 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSqlCmd(rest, pCmd, lineNum); simParseSqlCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW; cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW;
return true; return true;
} }
bool simParseRestfulCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSqlCmd(rest, pCmd, lineNum); simParseSqlCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL; cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL;
return true; return true;
} }
bool simParseSystemCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int expLen; int32_t expLen;
rest++; rest++;
cmdLine[numOfLines].cmdno = SIM_CMD_SYSTEM; cmdLine[numOfLines].cmdno = SIM_CMD_SYSTEM;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
cmdLine[numOfLines].optionOffset = optionOffset; cmdLine[numOfLines].optionOffset = optionOffset;
expLen = (int)strlen(rest); expLen = (int32_t)strlen(rest);
memcpy(optionBuffer + optionOffset, rest, expLen); memcpy(optionBuffer + optionOffset, rest, expLen);
optionOffset += expLen + 1; optionOffset += expLen + 1;
*(optionBuffer + optionOffset - 1) = 0; *(optionBuffer + optionOffset - 1) = 0;
...@@ -743,15 +743,15 @@ bool simParseSystemCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -743,15 +743,15 @@ bool simParseSystemCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSystemCmd(rest, pCmd, lineNum); simParseSystemCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SYSTEM_CONTENT; cmdLine[numOfLines - 1].cmdno = SIM_CMD_SYSTEM_CONTENT;
return true; return true;
} }
bool simParseSleepCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token; char * token;
int tokenLen; int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP; cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
...@@ -768,9 +768,9 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -768,9 +768,9 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseReturnCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token; char * token;
int tokenLen; int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_RETURN; cmdLine[numOfLines].cmdno = SIM_CMD_RETURN;
cmdLine[numOfLines].lineNum = lineNum; cmdLine[numOfLines].lineNum = lineNum;
...@@ -787,9 +787,9 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -787,9 +787,9 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseGotoCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token; char * token;
int tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -810,9 +810,9 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -810,9 +810,9 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseRunCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token; char * token;
int tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -832,14 +832,14 @@ bool simParseRunCmd(char *rest, SCommand *pCmd, int lineNum) { ...@@ -832,14 +832,14 @@ bool simParseRunCmd(char *rest, SCommand *pCmd, int lineNum) {
return true; return true;
} }
bool simParseRunBackCmd(char *rest, SCommand *pCmd, int lineNum) { bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseRunCmd(rest, pCmd, lineNum); simParseRunCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RUN_BACK; cmdLine[numOfLines - 1].cmdno = SIM_CMD_RUN_BACK;
return true; return true;
} }
void simInitsimCmdList() { void simInitsimCmdList() {
int cmdno; int32_t cmdno;
memset(simCmdList, 0, SIM_CMD_END * sizeof(SCommand)); memset(simCmdList, 0, SIM_CMD_END * sizeof(SCommand));
/* internal command */ /* internal command */
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "taos.h" #include "taos.h"
...@@ -24,11 +25,11 @@ ...@@ -24,11 +25,11 @@
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM]; SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
SCommand simCmdList[SIM_CMD_END]; SCommand simCmdList[SIM_CMD_END];
int simScriptPos = -1; int32_t simScriptPos = -1;
int simScriptSucced = 0; int32_t simScriptSucced = 0;
int simDebugFlag = 135; int32_t simDebugFlag = 135;
void simCloseTaosdConnect(SScript *script); void simCloseTaosdConnect(SScript *script);
char simHostName[128]; char simHostName[128];
char *simParseArbitratorName(char *varName) { char *simParseArbitratorName(char *varName) {
static char hostName[140]; static char hostName[140];
...@@ -39,8 +40,8 @@ char *simParseArbitratorName(char *varName) { ...@@ -39,8 +40,8 @@ char *simParseArbitratorName(char *varName) {
char *simParseHostName(char *varName) { char *simParseHostName(char *varName) {
static char hostName[140]; static char hostName[140];
int index = atoi(varName + 8); int32_t index = atoi(varName + 8);
int port = 7100; int32_t port = 7100;
switch (index) { switch (index) {
case 1: case 1:
port = 7100; port = 7100;
...@@ -70,9 +71,9 @@ char *simParseHostName(char *varName) { ...@@ -70,9 +71,9 @@ char *simParseHostName(char *varName) {
port = 7900; port = 7900;
break; break;
} }
sprintf(hostName, "'%s:%d'", simHostName, port); sprintf(hostName, "'%s:%d'", simHostName, port);
//simInfo("hostName:%s", hostName); // simInfo("hostName:%s", hostName);
return hostName; return hostName;
} }
...@@ -88,12 +89,19 @@ void simSystemCleanUp() {} ...@@ -88,12 +89,19 @@ void simSystemCleanUp() {}
void simFreeScript(SScript *script) { void simFreeScript(SScript *script) {
if (script->type == SIM_SCRIPT_TYPE_MAIN) { 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]; SScript *bgScript = script->bgScripts[i];
simInfo("script:%s, set stop flag", script->fileName);
bgScript->killed = true; bgScript->killed = true;
if (bgScript->bgPid) {
pthread_join(bgScript->bgPid, NULL);
}
} }
} }
simDebug("script:%s, is freed", script->fileName);
taos_close(script->taos); taos_close(script->taos);
taosTFree(script->lines); taosTFree(script->lines);
taosTFree(script->optionBuffer); taosTFree(script->optionBuffer);
...@@ -103,25 +111,24 @@ void simFreeScript(SScript *script) { ...@@ -103,25 +111,24 @@ void simFreeScript(SScript *script) {
SScript *simProcessCallOver(SScript *script) { SScript *simProcessCallOver(SScript *script) {
if (script->type == SIM_SCRIPT_TYPE_MAIN) { if (script->type == SIM_SCRIPT_TYPE_MAIN) {
if (script->killed) { if (script->killed) {
simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s",
"failed" FAILED_POSTFIX ", error:%s", script->fileName, script->error);
script->fileName, script->error);
exit(-1); exit(-1);
} else { } else {
simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX,
"success" SUCCESS_POSTFIX, script->fileName);
script->fileName);
simCloseTaosdConnect(script); simCloseTaosdConnect(script);
simScriptSucced++; simScriptSucced++;
simScriptPos--; simScriptPos--;
simFreeScript(script);
if (simScriptPos == -1) { if (simScriptPos == -1) {
simInfo("----------------------------------------------------------------------"); simInfo("----------------------------------------------------------------------");
simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced); simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced);
exit(0); exit(0);
} }
simFreeScript(script); return NULL;
return simScriptList[simScriptPos];
} }
} else { } else {
simInfo("script:%s, is stopped by main script", script->fileName); simInfo("script:%s, is stopped by main script", script->fileName);
...@@ -143,11 +150,11 @@ void *simExecuteScript(void *inputScript) { ...@@ -143,11 +150,11 @@ void *simExecuteScript(void *inputScript) {
if (script == NULL) break; if (script == NULL) break;
} else { } else {
SCmdLine *line = &script->lines[script->linePos]; 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); simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
SCommand *cmd = &simCmdList[line->cmdno]; SCommand *cmd = &simCmdList[line->cmdno];
int ret = (*(cmd->executeCmd))(script, option); int32_t ret = (*(cmd->executeCmd))(script, option);
if (!ret) { if (!ret) {
script->killed = true; script->killed = true;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册