提交 8940eb4d 编写于 作者: S Shengliang Guan

format sim scripts

上级 8e68fa6e
......@@ -102,18 +102,18 @@ typedef struct _cmd_t {
int16_t cmdno;
int16_t nlen;
char name[MAX_SIM_CMD_NAME_LEN];
bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
bool (*executeCmd)(struct _script_t *script, char *option);
bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
bool (*executeCmd)(struct _script_t *script, char *option);
struct _cmd_t *next;
} SCommand;
typedef struct {
int16_t cmdno;
int16_t jump; // jump position
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
int32_t optionOffset;// relative option offset
int16_t jump; // jump position
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
int32_t optionOffset; // relative option offset
} SCmdLine;
typedef struct _var_t {
......@@ -123,24 +123,24 @@ typedef struct _var_t {
} SVariable;
typedef struct _script_t {
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];
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];
} SScript;
......@@ -154,11 +154,11 @@ extern bool abortExecution;
SScript *simParseScript(char *fileName);
SScript *simProcessCallOver(SScript *script);
void * simExecuteScript(void *script);
void *simExecuteScript(void *script);
void simInitsimCmdList();
bool simSystemInit();
void simSystemCleanUp();
char * simGetVariable(SScript *script, char *varName, int32_t varLen);
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);
......
......@@ -40,10 +40,10 @@ typedef struct {
/* block definition */
typedef struct {
char top; /* the number of blocks stacked */
char type[MAX_NUM_BLOCK]; /* the block type */
int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */
int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */
char top; /* the number of blocks stacked */
char type[MAX_NUM_BLOCK]; /* the block type */
int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */
int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */
char numJump[MAX_NUM_BLOCK];
int16_t *jump[MAX_NUM_BLOCK][MAX_NUM_JUMP]; /* break or elif */
char sexp[MAX_NUM_BLOCK][40]; /*switch expression */
......
......@@ -14,18 +14,18 @@
*/
#define _DEFAULT_SOURCE
#include "taos.h"
#include "cJSON.h"
#include "os.h"
#include "sim.h"
#include "taos.h"
#include "taoserror.h"
#include "tglobal.h"
#include "tutil.h"
#include "ttypes.h"
#include "tutil.h"
void simLogSql(char *sql, bool useSharp) {
static FILE *fp = NULL;
char filename[256];
char filename[256];
sprintf(filename, "%s/sim.sql", tsScriptDir);
if (fp == NULL) {
fp = fopen(filename, "w");
......@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null";
}
char * keyName;
char *keyName;
int32_t keyLen;
paGetToken(varName + 6, &keyName, &keyLen);
......@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null";
}
char * keyName;
char *keyName;
int32_t keyLen;
paGetToken(varName + 7, &keyName, &keyLen);
......@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
}
int32_t simExecuteExpression(SScript *script, char *exp) {
char * op1, *op2, *var1, *var2, *var3, *rest;
char *op1, *op2, *var1, *var2, *var3, *rest;
int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1;
char t0[1024], t1[1024], t2[1024], t3[2048];
int32_t result;
......@@ -302,10 +302,10 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
}
void simReplaceShToBat(char *dst) {
char* sh = strstr(dst, ".sh");
char *sh = strstr(dst, ".sh");
if (sh != NULL) {
int32_t dstLen = (int32_t)strlen(dst);
char *end = dst + dstLen;
char *end = dst + dstLen;
*(end + 1) = 0;
for (char *p = end; p >= sh; p--) {
......@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
}
void simVisuallizeOption(SScript *script, char *src, char *dst) {
char * var, *token, *value;
char *var, *token, *value;
int32_t dstLen, srcLen, tokenLen;
dst[0] = 0, dstLen = 0;
......@@ -475,9 +475,7 @@ void simCloseNativeConnect(SScript *script) {
script->taos = NULL;
}
void simCloseTaosdConnect(SScript *script) {
simCloseNativeConnect(script);
}
void simCloseTaosdConnect(SScript *script) { simCloseNativeConnect(script); }
bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
simCloseTaosdConnect(script);
......@@ -512,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
bool simCreateTaosdConnect(SScript *script, char *rest) {
char * user = TSDB_DEFAULT_USER;
char * token;
char *user = TSDB_DEFAULT_USER;
char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
rest = paGetToken(rest, &token, &tokenLen);
......@@ -528,7 +526,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
char timeStr[30] = {0};
time_t tt;
struct tm *tp;
SCmdLine * line = &script->lines[script->linePos];
SCmdLine *line = &script->lines[script->linePos];
int32_t ret = -1;
TAOS_RES *pSql = NULL;
......@@ -589,7 +587,7 @@ 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);
int32_t * length = taos_fetch_lengths(pSql);
int32_t *length = taos_fetch_lengths(pSql);
for (int32_t i = 0; i < num_fields; i++) {
char *value = NULL;
......@@ -613,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
sprintf(value, "%d", *((int8_t *)row[i]));
break;
case TSDB_DATA_TYPE_UTINYINT:
sprintf(value, "%u", *((uint8_t*)row[i]));
sprintf(value, "%u", *((uint8_t *)row[i]));
break;
case TSDB_DATA_TYPE_SMALLINT:
sprintf(value, "%d", *((int16_t *)row[i]));
......@@ -679,7 +677,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
sprintf(value, "%s.%06d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000));
} else {
sprintf(value, "%s.%09d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000000));
sprintf(value, "%s.%09d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000000));
}
break;
......@@ -711,7 +709,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
}
bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
char buf[3000];
char buf[3000];
SCmdLine *line = &script->lines[script->linePos];
simVisuallizeOption(script, rest, buf);
......@@ -803,9 +801,8 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) {
return simExecuteSystemCmd(script, cmd);
}
bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
char buf[3000];
char buf[3000];
SCmdLine *line = &script->lines[script->linePos];
simVisuallizeOption(script, rest, buf);
......@@ -870,7 +867,7 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true);
char * lines[] = {rest};
char *lines[] = {rest};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
......@@ -881,8 +878,8 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) {
script->linePos++;
return true;
} else {
sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest,
ret & 0XFFFF, tstrerror(ret));
sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest, ret & 0XFFFF,
tstrerror(ret));
return false;
}
}
......@@ -897,19 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true);
char * lines[] = {rest};
char *lines[] = {rest};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t ret = 0;
#endif
if (ret == TSDB_CODE_SUCCESS) {
sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName, script->taos, rest);
sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName,
script->taos, rest);
script->linePos++;
return false;
} else {
simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest,
ret & 0XFFFF, tstrerror(ret));
simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest, ret & 0XFFFF,
tstrerror(ret));
return true;
}
}
......@@ -15,8 +15,8 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "sim.h"
#include "tglobal.h"
bool simExecSuccess = false;
bool abortExecution = false;
......@@ -24,8 +24,8 @@ bool abortExecution = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
simSystemCleanUp();
abortExecution = true;
// runningScript->killed = true;
// exit(1);
// runningScript->killed = true;
// exit(1);
}
int32_t main(int32_t argc, char *argv[]) {
......
......@@ -60,9 +60,10 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "simParse.h"
#include "tutil.h"
#include "simParse.h"
static SCommand *cmdHashList[MAX_NUM_CMD];
static SCmdLine cmdLine[MAX_CMD_LINES];
static char parseErr[MAX_ERROR_LEN];
......@@ -176,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
}
SScript *simParseScript(char *fileName) {
FILE * fd;
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);
......@@ -251,7 +252,7 @@ SScript *simParseScript(char *fileName) {
}
int32_t simCheckExpression(char *exp) {
char * op1, *op2, *op, *rest;
char *op1, *op2, *op, *rest;
int32_t op1Len, op2Len, opLen;
rest = paGetToken(exp, &op1, &op1Len);
......@@ -335,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) {
}
bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * ret;
char *ret;
int32_t expLen;
expLen = simCheckExpression(rest);
......@@ -501,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token;
char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
......@@ -524,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token;
char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
......@@ -665,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
void simCheckSqlOption(char *rest) {
int32_t valueLen;
char * value, *xpos;
char *value, *xpos;
xpos = strstr(rest, " -x"); // need a blank
if (xpos) {
......@@ -749,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token;
char *token;
int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP;
......@@ -768,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token;
char *token;
int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_RETURN;
......@@ -787,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token;
char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
......@@ -810,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token;
char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
......@@ -837,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true;
}
bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
bool simParseLineInsertCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
rest++;
......@@ -853,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
return true;
}
bool simParseLineInsertErrorCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
bool simParseLineInsertErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
rest++;
......
......@@ -14,9 +14,9 @@
*/
#define _DEFAULT_SOURCE
#include "taos.h"
#include "os.h"
#include "sim.h"
#include "taos.h"
#include "taoserror.h"
#include "tglobal.h"
#include "ttimer.h"
......@@ -166,7 +166,7 @@ void *simExecuteScript(void *inputScript) {
}
} 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];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册