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

taosdata / TDengine / #3561

19 Dec 2024 03:15AM UTC coverage: 58.812% (-1.3%) from 60.124%
#3561

push

travis-ci

web-flow
Merge pull request #29213 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

130770 of 287658 branches covered (45.46%)

Branch coverage included in aggregate %.

32 of 78 new or added lines in 4 files covered. (41.03%)

7347 existing lines in 166 files now uncovered.

205356 of 283866 relevant lines covered (72.34%)

7187865.64 hits per line

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

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

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

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

44
void simSystemCleanUp() {}
1✔
45

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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