From 8940eb4d1af0d7b5d6d58644e2c9a9843ff89bf8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 17 Dec 2021 17:16:39 +0800 Subject: [PATCH] format sim scripts --- tests/tsim/inc/sim.h | 54 +++++++++++++++++++------------------- tests/tsim/inc/simParse.h | 8 +++--- tests/tsim/src/simExe.c | 54 ++++++++++++++++++-------------------- tests/tsim/src/simMain.c | 6 ++--- tests/tsim/src/simParse.c | 29 ++++++++++---------- tests/tsim/src/simSystem.c | 4 +-- 6 files changed, 77 insertions(+), 78 deletions(-) diff --git a/tests/tsim/inc/sim.h b/tests/tsim/inc/sim.h index 4cb08d6401..4aa3c62a80 100644 --- a/tests/tsim/inc/sim.h +++ b/tests/tsim/inc/sim.h @@ -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); diff --git a/tests/tsim/inc/simParse.h b/tests/tsim/inc/simParse.h index addd74bf80..56ee90aadb 100644 --- a/tests/tsim/inc/simParse.h +++ b/tests/tsim/inc/simParse.h @@ -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 */ diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 4f64564404..453d653919 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -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; } } diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index 438bd41910..19d23daace 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -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[]) { diff --git a/tests/tsim/src/simParse.c b/tests/tsim/src/simParse.c index 246d0d3829..0dfd5f4f3e 100644 --- a/tests/tsim/src/simParse.c +++ b/tests/tsim/src/simParse.c @@ -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++; diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 283e84c7a8..db32354616 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -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]; -- GitLab