parTestMain.cpp 2.9 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

 private:
  void initLog(const char* path) {
    int32_t logLevel = getLogLevel();
    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
    {"log", required_argument, NULL, 'l'},
90 91 92
    {0, 0, 0, 0}
  };
  // clang-format on
93 94 95
  while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
    switch (opt) {
      case 'd':
96 97 98
        g_dump = true;
        break;
      case 'a':
99 100 101 102
        setAsyncFlag(optarg);
        break;
      case 's':
        setSkipSqlNum(optarg);
103
        break;
104 105 106
      case 'l':
        setLogLevel(optarg);
        break;
107 108 109 110 111 112
      default:
        break;
    }
  }
}

113 114
}  // namespace ParserTest

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