• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.9
/utils/tsim/src/simSystem.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "simInt.h"
18
#include "tconfig.h"
19

20
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
21
SCommand simCmdList[SIM_CMD_END];
22
int32_t  simScriptPos = -1;
23
int32_t  simScriptSucceed = 0;
24
void     simCloseTaosdConnect(SScript *script);
25
char     simScriptDir[PATH_MAX] = {0};
26

27
extern bool simExecSuccess;
28

29
int32_t simInitCfg() {
4✔
30
  taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1);
4✔
31
  taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1);
4✔
32

33
  SConfig *pCfg = taosGetCfg();
4✔
34
  tstrncpy(simScriptDir, cfgGetItem(pCfg, "scriptDir")->str, PATH_MAX);
4✔
35
  return 0;
4✔
36
}
37

38
void simSystemInit() {
4✔
39
  simInitCfg();
4✔
40
  simInitsimCmdList();
4✔
41
  memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
4✔
42
}
4✔
43

44
void simSystemCleanUp() {}
1✔
45

46
void simFreeScript(SScript *script) {
1✔
47
  if (script->type == SIM_SCRIPT_TYPE_MAIN) {
1!
48
    simInfo("script:%s, background script num:%d, stop them", script->fileName, script->bgScriptLen);
1!
49

50
    for (int32_t i = 0; i < script->bgScriptLen; ++i) {
1!
51
      SScript *bgScript = script->bgScripts[i];
×
52
      simDebug("script:%s, is background script, set stop flag", bgScript->fileName);
×
53
      bgScript->killed = true;
×
54
      if (taosCheckPthreadValid(bgScript->bgPid)) {
×
55
        taosThreadJoin(bgScript->bgPid, NULL);
×
56
        taosThreadClear(&bgScript->bgPid);
×
57
      }
58

59
      simDebug("script:%s, background thread joined", bgScript->fileName);
×
60
      taos_close(bgScript->taos);
×
61
      taosMemoryFreeClear(bgScript->lines);
×
62
      taosMemoryFreeClear(bgScript->optionBuffer);
×
63
      taosMemoryFreeClear(bgScript);
×
64
    }
65

66
    simDebug("script:%s, is cleaned", script->fileName);
1!
67
    taos_close(script->taos);
1✔
68
    taosMemoryFreeClear(script->lines);
1!
69
    taosMemoryFreeClear(script->optionBuffer);
1!
70
    taosMemoryFreeClear(script);
1!
71
  }
72
}
1✔
73

74
SScript *simProcessCallOver(SScript *script) {
1✔
75
  if (script->type == SIM_SCRIPT_TYPE_MAIN) {
1!
76
    simDebug("script:%s, is main script, set stop flag", script->fileName);
1!
77
    if (script->killed) {
1!
78
      simExecSuccess = false;
×
79
      simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s",
×
80
              script->fileName, script->error);
81
    } else {
82
      simExecSuccess = true;
1✔
83
      simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX,
1!
84
              script->fileName);
85
    }
86

87
    simCloseTaosdConnect(script);
1✔
88
    simScriptSucceed++;
1✔
89
    simScriptPos--;
1✔
90
    simFreeScript(script);
1✔
91

92
    if (simScriptPos == -1 && simExecSuccess) {
1!
93
      simInfo("----------------------------------------------------------------------");
1!
94
      simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucceed);
1!
95
      return NULL;
1✔
96
    }
97

98
    if (simScriptPos == -1) return NULL;
×
99
    if (!simExecSuccess) return NULL;
×
100

101
    return simScriptList[simScriptPos];
×
102
  } else {
103
    simDebug("script:%s,  is stopped", script->fileName);
×
104
    simFreeScript(script);
×
105
    return NULL;
×
106
  }
107
}
108

109
void *simExecuteScript(void *inputScript) {
1✔
110
  SScript *script = (SScript *)inputScript;
1✔
111

112
  while (1) {
113
    if (script->type == SIM_SCRIPT_TYPE_MAIN) {
108!
114
      script = simScriptList[simScriptPos];
108✔
115
    }
116

117
    if (abortExecution) {
108!
118
      script->killed = true;
×
119
    }
120

121
    if (script->killed || script->linePos >= script->numOfLines) {
108!
122
      script = simProcessCallOver(script);
1✔
123
      if (script == NULL) {
1!
124
        simDebug("sim test abort now!");
1!
125
        break;
1✔
126
      }
127
    } else {
128
      SCmdLine *line = &script->lines[script->linePos];
107✔
129
      char     *option = script->optionBuffer + line->optionOffset;
107✔
130
      simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
107!
131

132
      SCommand *cmd = &simCmdList[line->cmdno];
107✔
133
      int32_t   ret = (*(cmd->executeCmd))(script, option);
107✔
134
      if (!ret) {
107!
135
        script->killed = true;
×
136
      }
137
    }
138
  }
139

140
  simInfo("thread is stopped");
1!
141
  return NULL;
1✔
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc