]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/TestSignalHandlers.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / test / TestSignalHandlers.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2010 Dreamhost
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 /*
16 * TestSignalHandlers
17 *
18 * Test the Ceph signal handlers
19 */
20 #include "common/ceph_argparse.h"
21 #include "global/global_init.h"
22 #include "common/errno.h"
23 #include "common/debug.h"
24 #include "common/config.h"
25
26 #include <errno.h>
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30
31 #define dout_context g_ceph_context
32
33 using namespace std;
34
35 // avoid compiler warning about dereferencing NULL pointer
36 static int* get_null()
37 {
38 return 0;
39 }
40
41 static void simple_segv_test()
42 {
43 generic_dout(-1) << "triggering SIGSEGV..." << dendl;
44 // cppcheck-suppress nullPointer
45 int i = *get_null();
46 std::cout << "i = " << i << std::endl;
47 }
48
49 // Given the name of the function, we can be pretty sure this is intentional.
50
51 #pragma GCC diagnostic push
52 #pragma GCC diagnostic ignored "-Winfinite-recursion"
53
54 #pragma clang diagnostic push
55 #pragma clang diagnostic ignored "-Winfinite-recursion"
56
57 static void infinite_recursion_test_impl()
58 {
59 infinite_recursion_test_impl();
60 }
61
62 #pragma GCC diagnostic pop
63 #pragma clang diagnostic pop
64
65 static void infinite_recursion_test()
66 {
67 generic_dout(0) << "triggering SIGSEGV with infinite recursion..." << dendl;
68 infinite_recursion_test_impl();
69 }
70
71 static void usage()
72 {
73 cout << "usage: TestSignalHandlers [test]" << std::endl;
74 cout << "--simple_segv: run simple_segv test" << std::endl;
75 cout << "--infinite_recursion: run infinite_recursion test" << std::endl;
76 generic_client_usage();
77 }
78
79 typedef void (*test_fn_t)(void);
80
81 int main(int argc, const char **argv)
82 {
83 auto args = argv_to_vec(argc, argv);
84 if (args.empty()) {
85 cerr << argv[0] << ": -h or --help for usage" << std::endl;
86 exit(1);
87 }
88 if (ceph_argparse_need_usage(args)) {
89 usage();
90 exit(0);
91 }
92
93 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
94 CODE_ENVIRONMENT_UTILITY,
95 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
96 common_init_finish(g_ceph_context);
97
98 test_fn_t fn = NULL;
99 for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
100 if (ceph_argparse_double_dash(args, i)) {
101 break;
102 } else if (ceph_argparse_flag(args, i, "--infinite_recursion", (char*)NULL)) {
103 fn = infinite_recursion_test;
104 } else if (ceph_argparse_flag(args, i, "-s", "--simple_segv", (char*)NULL)) {
105 fn = simple_segv_test;
106 } else {
107 cerr << "unrecognized argument: " << *i << std::endl;
108 exit(1);
109 }
110 }
111 if (!fn) {
112 std::cerr << "Please select a test to run. Type -h for help." << std::endl;
113 exit(1);
114 }
115 fn();
116 return 0;
117 }