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

16
#define _DEFAULT_SOURCE
S
slguan 已提交
17
#include "os.h"
S
slguan 已提交
18
#include "sim.h"
S
Shengliang Guan 已提交
19
#include "tglobal.h"
S
slguan 已提交
20

S
TD-2808  
Shengliang Guan 已提交
21
bool simExecSuccess = false;
22
bool abortExecution = false;
S
slguan 已提交
23

S
TD-1207  
Shengliang Guan 已提交
24
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
S
slguan 已提交
25
  simSystemCleanUp();
26
  abortExecution = true;
S
Shengliang Guan 已提交
27 28
  //  runningScript->killed = true;
  //  exit(1);
S
slguan 已提交
29 30
}

31
int32_t main(int32_t argc, char *argv[]) {
S
slguan 已提交
32 33
  char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";

34
  for (int32_t i = 1; i < argc; ++i) {
S
slguan 已提交
35
    if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
C
cpwu 已提交
36
      tstrncpy(configDir, argv[++i], 128);
S
slguan 已提交
37 38 39 40
    } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
      strcpy(scriptFile, argv[++i]);
    } else {
      printf("usage: %s [options] \n", argv[0]);
41
      printf("       [-c config]: config directory, default is: %s\n", configDir);
S
slguan 已提交
42
      printf("       [-f script]: script filename\n");
43
      return 0;
S
slguan 已提交
44 45 46 47 48 49
    }
  }

  if (!simSystemInit()) {
    simError("failed to initialize the system");
    simSystemCleanUp();
50
    return -1;
S
slguan 已提交
51 52
  }

S
Shengliang Guan 已提交
53
  simInfo("simulator is running ...");
S
TD-1207  
Shengliang Guan 已提交
54
  taosSetSignal(SIGINT, simHandleSignal);
S
slguan 已提交
55 56 57 58

  SScript *script = simParseScript(scriptFile);
  if (script == NULL) {
    simError("parse script file:%s failed", scriptFile);
59
    return -1;
S
slguan 已提交
60 61
  }

62 63 64 65 66
  if (abortExecution) {
    simError("execute abort");
    return -1;
  }

S
slguan 已提交
67 68 69
  simScriptList[++simScriptPos] = script;
  simExecuteScript(script);

S
TD-2808  
Shengliang Guan 已提交
70
  int32_t ret = simExecSuccess ? 0 : -1;
S
TD-1207  
Shengliang Guan 已提交
71
  simInfo("execute result %d", ret);
S
TD-2808  
Shengliang Guan 已提交
72 73

  return ret;
C
cpwu 已提交
74
}