summaryrefslogtreecommitdiffstats
path: root/src/test/crimson/gtest_seastar.cc
blob: abb1f88f2a06521ae3333db074d715a4a39e0abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include <cstdlib>
#include <iostream>

#include "include/ceph_assert.h"
#include "gtest_seastar.h"

#include "common/ceph_argparse.h"
#include "crimson/common/config_proxy.h"
#include "crimson/common/perf_counters_collection.h"

SeastarRunner seastar_test_suite_t::seastar_env;

int main(int argc, char **argv)
{
  // preprocess args
  std::vector<const char*> args;
  bool global_log_level_is_set = false;
  const char* prefix_log_level = "--default-log-level";
  for (int i = 0; i < argc; ++i) {
    if (std::strncmp(argv[i], prefix_log_level,
                     std::strlen(prefix_log_level)) == 0) {
      global_log_level_is_set = true;
    }
    args.push_back(argv[i]);
  }
  // HACK: differentiate between the `make check` bot and human user
  // for the sake of log flooding
  if (!global_log_level_is_set && !std::getenv("FOR_MAKE_CHECK")) {
    std::cout << "WARNING: set default seastar log level to debug" << std::endl;
    ++argc;
    args.push_back("--default-log-level=debug");
  }

  auto app_argv = const_cast<char**>(args.data());
  auto app_argc = static_cast<int>(args.size());
  ::testing::InitGoogleTest(&app_argc, app_argv);

  int ret = seastar_test_suite_t::seastar_env.init(app_argc, app_argv);
  if (ret != 0) {
    seastar_test_suite_t::seastar_env.stop();
    return ret;
  }

  seastar_test_suite_t::seastar_env.run([] {
    return crimson::common::sharded_conf().start(
      EntityName{}, std::string_view{"ceph"}
    ).then([] {
      return crimson::common::sharded_perf_coll().start();
    });
  });

  ret = RUN_ALL_TESTS();

  seastar_test_suite_t::seastar_env.run([] {
    return crimson::common::sharded_perf_coll().stop().then([] {
      return crimson::common::sharded_conf().stop();
    });
  });

  seastar_test_suite_t::seastar_env.stop();
  return ret;
}