Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
d6f527d8
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d6f527d8
编写于
11月 08, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-1952]<fix>: tsim crash while run background scripts
上级
855ecf59
变更
6
展开全部
显示空白变更内容
内联
并排
Showing
6 changed file
with
292 addition
and
287 deletion
+292
-287
tests/tsim/inc/sim.h
tests/tsim/inc/sim.h
+43
-46
tests/tsim/inc/simParse.h
tests/tsim/inc/simParse.h
+1
-1
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+114
-113
tests/tsim/src/simMain.c
tests/tsim/src/simMain.c
+5
-5
tests/tsim/src/simParse.c
tests/tsim/src/simParse.c
+102
-102
tests/tsim/src/simSystem.c
tests/tsim/src/simSystem.c
+27
-20
未找到文件。
tests/tsim/inc/sim.h
浏览文件 @
d6f527d8
...
...
@@ -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
*
,
int
32_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
int
32_t
optionOffset
;
// relative option offset
}
SCmdLine
;
typedef
struct
_var_t
{
...
...
@@ -121,45 +121,42 @@ typedef struct _var_t {
}
SVariable
;
typedef
struct
_script_t
{
int
type
;
int
32_t
type
;
bool
killed
;
void
*
taos
;
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
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
;
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
;
char
*
optionBuffer
;
SCmdLine
*
lines
;
// command list
SVariable
variables
[
MAX_VAR_LEN
];
struct
_script_t
*
bgScripts
[
MAX_BACKGROUND_SCRIPT_NUM
]
;
pthread_t
bgPid
;
char
auth
[
128
];
struct
_script_t
*
bgScripts
[
MAX_BACKGROUND_SCRIPT_NUM
];
}
SScript
;
extern
SScript
*
simScriptList
[
MAX_MAIN_SCRIPT_NUM
];
extern
SCommand
simCmdList
[];
extern
int
simScriptPos
;
extern
int
simScriptSucced
;
extern
int
simDebugFlag
;
extern
int
32_t
simScriptPos
;
extern
int
32_t
simScriptSucced
;
extern
int
32_t
simDebugFlag
;
extern
char
tsScriptDir
[];
extern
bool
simAsyncQuery
;
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
,
in
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
);
...
...
tests/tsim/inc/simParse.h
浏览文件 @
d6f527d8
...
...
@@ -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
,
int
32_t
lineNum
);
#endif
\ No newline at end of file
tests/tsim/src/simExe.c
浏览文件 @
d6f527d8
此差异已折叠。
点击以展开。
tests/tsim/src/simMain.c
浏览文件 @
d6f527d8
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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
(
int
32_t
signo
)
{
simSystemCleanUp
();
exit
(
1
);
}
int
main
(
in
t
argc
,
char
*
argv
[])
{
int
32_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
(
int
32_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
);
}
...
...
tests/tsim/src/simParse.c
浏览文件 @
d6f527d8
...
...
@@ -57,6 +57,7 @@
*
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "simParse.h"
...
...
@@ -67,13 +68,13 @@ 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
int
32_t
numOfLines
,
optionOffset
;
static
SLabel
label
,
dest
;
static
SBlock
block
;
int
simHashCmd
(
char
*
token
,
in
t
tokenLen
)
{
int
i
;
int
hash
=
0
;
int
32_t
simHashCmd
(
char
*
token
,
int32_
t
tokenLen
)
{
int
32_t
i
;
int
32_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
,
int
32_t
tokenLen
)
{
int
32_t
hash
;
SCommand
*
node
;
hash
=
simHashCmd
(
token
,
tokenLen
);
...
...
@@ -102,10 +103,10 @@ SCommand *simCheckCmd(char *token, int tokenLen) {
}
void
simAddCmdIntoHash
(
SCommand
*
pCmd
)
{
int
hash
;
int
32_t
hash
;
SCommand
*
node
;
hash
=
simHashCmd
(
pCmd
->
name
,
(
int
)
strlen
(
pCmd
->
name
));
hash
=
simHashCmd
(
pCmd
->
name
,
(
int
32_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
;
int
32_t
i
,
destPos
;
/* process labels */
...
...
@@ -176,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
}
SScript
*
simParseScript
(
char
*
fileName
)
{
FILE
*
fd
;
int
tokenLen
,
lineNum
=
0
;
FILE
*
fd
;
int
32_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
=
(
in
t
)
strlen
(
buffer
);
if
(
buffer
[
cmdlen
-
1
]
==
'\r'
||
buffer
[
cmdlen
-
1
]
==
'\n'
)
int
32_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
(
int
32_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
;
int
32_t
simCheckExpression
(
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
op
,
*
rest
;
int
32_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
(
int
32_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
(
int
32_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
,
int
32_t
lineNum
)
{
int
32_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
,
int
32_t
lineNum
)
{
char
*
ret
;
int
32_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
,
int
32_t
lineNum
)
{
int
32_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
,
int
32_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
,
int
32_t
lineNum
)
{
int
32_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
,
int
32_t
lineNum
)
{
int
32_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
,
int
32_t
lineNum
)
{
int
32_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
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_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
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_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
,
int
32_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
,
int
32_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
,
int
32_t
lineNum
)
{
int
32_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
,
int
32_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
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_PRINT
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_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
;
int
32_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
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
simCheckSqlOption
(
rest
);
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SQL
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_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
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SQL_ERROR
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_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
,
int
32_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
,
int
32_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
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SYSTEM
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_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
,
int
32_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
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_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
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_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
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_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
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_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
,
int
32_t
lineNum
)
{
simParseRunCmd
(
rest
,
pCmd
,
lineNum
);
cmdLine
[
numOfLines
-
1
].
cmdno
=
SIM_CMD_RUN_BACK
;
return
true
;
}
void
simInitsimCmdList
()
{
int
cmdno
;
int
32_t
cmdno
;
memset
(
simCmdList
,
0
,
SIM_CMD_END
*
sizeof
(
SCommand
));
/* internal command */
...
...
tests/tsim/src/simSystem.c
浏览文件 @
d6f527d8
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "taos.h"
...
...
@@ -24,9 +25,9 @@
SScript
*
simScriptList
[
MAX_MAIN_SCRIPT_NUM
];
SCommand
simCmdList
[
SIM_CMD_END
];
int
simScriptPos
=
-
1
;
int
simScriptSucced
=
0
;
int
simDebugFlag
=
135
;
int
32_t
simScriptPos
=
-
1
;
int
32_t
simScriptSucced
=
0
;
int
32_t
simDebugFlag
=
135
;
void
simCloseTaosdConnect
(
SScript
*
script
);
char
simHostName
[
128
];
...
...
@@ -39,8 +40,8 @@ char *simParseArbitratorName(char *varName) {
char
*
simParseHostName
(
char
*
varName
)
{
static
char
hostName
[
140
];
int
index
=
atoi
(
varName
+
8
);
int
port
=
7100
;
int
32_t
index
=
atoi
(
varName
+
8
);
int
32_t
port
=
7100
;
switch
(
index
)
{
case
1
:
port
=
7100
;
...
...
@@ -72,7 +73,7 @@ char *simParseHostName(char *varName) {
}
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
(
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"
,
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
,
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
);
int
32_t
ret
=
(
*
(
cmd
->
executeCmd
))(
script
,
option
);
if
(
!
ret
)
{
script
->
killed
=
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录