]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/src/testing/entry_point.cc
9b82c62b9ad1eb41daca5d9a5d8796a54472a7fa
[ceph.git] / ceph / src / seastar / src / testing / entry_point.cc
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18
19 /*
20 * Copyright (C) 2018 ScyllaDB Ltd.
21 */
22
23 #include <seastar/testing/entry_point.hh>
24 #include <seastar/testing/seastar_test.hh>
25 #include <seastar/testing/test_runner.hh>
26
27 namespace seastar {
28
29 namespace testing {
30
31 static bool init_unit_test_suite() {
32 const auto& tests = known_tests();
33 auto&& ts = boost::unit_test::framework::master_test_suite();
34 ts.p_name.set(tests.size() ? (tests)[0]->get_test_file() : "seastar-tests");
35
36 for (seastar_test* test : tests) {
37 #if BOOST_VERSION > 105800
38 ts.add(boost::unit_test::make_test_case([test] { test->run(); }, test->get_name(),
39 test->get_test_file(), 0),
40 test->get_expected_failures(), 0);
41 #else
42 ts.add(boost::unit_test::make_test_case([test] { test->run(); }, test->get_name()),
43 test->get_expected_failures(), 0);
44 #endif
45 }
46
47 return global_test_runner().start(ts.argc, ts.argv);
48 }
49
50 static void dummy_handler(int) {
51 // This handler should have been replaced.
52 _exit(1);
53 }
54
55 static void install_dummy_handler(int sig) {
56 struct sigaction sa {};
57 sa.sa_handler = dummy_handler;
58 sigaction(sig, &sa, nullptr);
59 }
60
61 int entry_point(int argc, char** argv) {
62 #ifndef SEASTAR_ASAN_ENABLED
63 // Before we call into boost, install some dummy signal
64 // handlers. This seems to be the only way to stop boost from
65 // installing its own handlers, which disables our backtrace
66 // printer. The real handler will be installed when the reactor is
67 // constructed.
68 // If we are using ASAN, it has already installed a signal handler
69 // that does its own stack printing.
70 for (int sig : {SIGSEGV, SIGABRT}) {
71 install_dummy_handler(sig);
72 }
73 #else
74 (void)install_dummy_handler;
75 #endif
76
77 const int boost_exit_code = ::boost::unit_test::unit_test_main(&init_unit_test_suite, argc, argv);
78 const int seastar_exit_code = seastar::testing::global_test_runner().finalize();
79 if (boost_exit_code) {
80 return boost_exit_code;
81 }
82 return seastar_exit_code;
83 }
84
85 }
86
87 }