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

taosdata / TDengine / #4661

08 Aug 2025 08:36AM UTC coverage: 59.883% (-0.2%) from 60.053%
#4661

push

travis-ci

web-flow
test: update cases desc (#32498)

137331 of 291923 branches covered (47.04%)

Branch coverage included in aggregate %.

207730 of 284307 relevant lines covered (73.07%)

4552406.61 hits per line

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

60.48
/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() {
523✔
30
  taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1);
523✔
31
  taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1);
523✔
32

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

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

44
void simSystemCleanUp() {}
1✔
45

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

50
    for (int32_t i = 0; i < script->bgScriptLen; ++i) {
422!
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);
422!
67
    taos_close(script->taos);
422✔
68
    taosMemoryFreeClear(script->lines);
422!
69
    taosMemoryFreeClear(script->optionBuffer);
422!
70
    taosMemoryFreeClear(script);
422!
71
  }
72
}
422✔
73

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

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

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

98
    if (simScriptPos == -1) return NULL;
113✔
99
    if (!simExecSuccess) return NULL;
109!
100

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

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

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

117
    if (abortExecution) {
6,657,311!
118
      script->killed = true;
×
119
    }
120

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

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

140
  simInfo("thread is stopped");
313!
141
  return NULL;
313✔
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