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

taosdata / TDengine / #3814

01 Apr 2025 05:36AM UTC coverage: 30.169% (-3.6%) from 33.798%
#3814

push

travis-ci

happyguoxy
test:add build cmake

129680 of 592945 branches covered (21.87%)

Branch coverage included in aggregate %.

196213 of 487270 relevant lines covered (40.27%)

555639.42 hits per line

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

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

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

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

44
void simSystemCleanUp() {}
1✔
45

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

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

74
SScript *simProcessCallOver(SScript *script) {
×
75
  if (script->type == SIM_SCRIPT_TYPE_MAIN) {
×
76
    simDebug("script:%s, is main script, set stop flag", script->fileName);
×
77
    if (script->killed) {
×
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;
×
83
      simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX,
×
84
              script->fileName);
85
    }
86

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

92
    if (simScriptPos == -1 && simExecSuccess) {
×
93
      simInfo("----------------------------------------------------------------------");
×
94
      simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucceed);
×
95
      return NULL;
×
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) {
×
110
  SScript *script = (SScript *)inputScript;
×
111

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

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

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

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

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