parTestMain.cpp 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * 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.
 *
 * 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/>.
 */

X
Xiaoyu Wang 已提交
16
#include <getopt.h>
wafwerar's avatar
wafwerar 已提交
17 18
#include <stdio.h>
#include <stdlib.h>
X
Xiaoyu Wang 已提交
19
#include <string>
20 21 22

#include <gtest/gtest.h>

wafwerar's avatar
wafwerar 已提交
23 24 25
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
X
Xiaoyu Wang 已提交
26

X
Xiaoyu Wang 已提交
27
#include "functionMgt.h"
wafwerar's avatar
wafwerar 已提交
28
#include "mockCatalog.h"
X
Xiaoyu Wang 已提交
29
#include "os.h"
X
Xiaoyu Wang 已提交
30
#include "parTestUtil.h"
X
Xiaoyu Wang 已提交
31
#include "parToken.h"
32

33 34
namespace ParserTest {

35
class ParserEnv : public testing::Environment {
X
Xiaoyu Wang 已提交
36
 public:
37
  virtual void SetUp() {
H
Haojun Liao 已提交
38
    fmFuncMgtInit();
39 40
    initMetaDataEnv();
    generateMetaData();
41
    initLog(TD_TMP_DIR_PATH "td");
42 43 44
  }

  virtual void TearDown() {
45
    destroyMetaDataEnv();
X
Xiaoyu Wang 已提交
46 47
    taosCleanupKeywordsTable();
    fmFuncMgtDestroy();
48
    taosCloseLog();
49 50 51 52
  }

  ParserEnv() {}
  virtual ~ParserEnv() {}
53 54 55

 private:
  void initLog(const char* path) {
56
    int32_t logLevel = getLogLevel() | DEBUG_SCREEN;
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    dDebugFlag = logLevel;
    vDebugFlag = logLevel;
    mDebugFlag = logLevel;
    cDebugFlag = logLevel;
    jniDebugFlag = logLevel;
    tmrDebugFlag = logLevel;
    uDebugFlag = logLevel;
    rpcDebugFlag = logLevel;
    qDebugFlag = logLevel;
    wDebugFlag = logLevel;
    sDebugFlag = logLevel;
    tsdbDebugFlag = logLevel;
    tsLogEmbedded = 1;
    tsAsyncLog = 0;

    taosRemoveDir(path);
    taosMkDir(path);
    tstrncpy(tsLogDir, path, PATH_MAX);
    if (taosInitLog("taoslog", 1) != 0) {
      std::cout << "failed to init log file" << std::endl;
    }
  }
79 80
};

81
static void parseArg(int argc, char* argv[]) {
82 83 84
  int         opt = 0;
  const char* optstring = "";
  // clang-format off
85
  static struct option long_options[] = {
86 87 88
    {"dump", no_argument, NULL, 'd'},
    {"async", required_argument, NULL, 'a'},
    {"skipSql", required_argument, NULL, 's'},
89
    {"limitSql", required_argument, NULL, 'i'},
90
    {"log", required_argument, NULL, 'l'},
91 92 93
    {0, 0, 0, 0}
  };
  // clang-format on
94 95 96
  while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
    switch (opt) {
      case 'd':
97 98 99
        g_dump = true;
        break;
      case 'a':
100 101 102 103
        setAsyncFlag(optarg);
        break;
      case 's':
        setSkipSqlNum(optarg);
104
        break;
105 106 107
      case 'i':
        setLimitSqlNum(optarg);
        break;
108 109 110
      case 'l':
        setLogLevel(optarg);
        break;
111 112 113 114 115 116
      default:
        break;
    }
  }
}

117 118
}  // namespace ParserTest

119
int main(int argc, char* argv[]) {
120
  testing::AddGlobalTestEnvironment(new ParserTest::ParserEnv());
X
Xiaoyu Wang 已提交
121
  testing::InitGoogleTest(&argc, argv);
122
  ParserTest::parseArg(argc, argv);
X
Xiaoyu Wang 已提交
123
  return RUN_ALL_TESTS();
124
}