]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | using std::string; | |
33 | ||
34 | // avoid compiler warning about dereferencing NULL pointer | |
35 | static int* get_null() | |
36 | { | |
37 | return 0; | |
38 | } | |
39 | ||
40 | static void simple_segv_test() | |
41 | { | |
42 | generic_dout(-1) << "triggering SIGSEGV..." << dendl; | |
43 | // cppcheck-suppress nullPointer | |
44 | int i = *get_null(); | |
45 | std::cout << "i = " << i << std::endl; | |
46 | } | |
47 | ||
48 | // Given the name of the function, we can be pretty sure this is intentional. | |
49 | ||
50 | #pragma clang diagnostic push | |
51 | ||
52 | #pragma clang diagnostic ignored "-Winfinite-recursion" | |
53 | ||
54 | static void infinite_recursion_test_impl() | |
55 | { | |
56 | infinite_recursion_test_impl(); | |
57 | } | |
58 | ||
59 | #pragma clang diagnostic pop | |
60 | ||
61 | static void infinite_recursion_test() | |
62 | { | |
63 | generic_dout(0) << "triggering SIGSEGV with infinite recursion..." << dendl; | |
64 | infinite_recursion_test_impl(); | |
65 | } | |
66 | ||
67 | static void usage() | |
68 | { | |
11fdf7f2 TL |
69 | cout << "usage: TestSignalHandlers [test]" << std::endl; |
70 | cout << "--simple_segv: run simple_segv test" << std::endl; | |
71 | cout << "--infinite_recursion: run infinite_recursion test" << std::endl; | |
72 | generic_client_usage(); | |
7c673cae FG |
73 | } |
74 | ||
75 | typedef void (*test_fn_t)(void); | |
76 | ||
77 | int main(int argc, const char **argv) | |
78 | { | |
79 | vector<const char*> args; | |
80 | argv_to_vec(argc, argv, args); | |
11fdf7f2 TL |
81 | if (args.empty()) { |
82 | cerr << argv[0] << ": -h or --help for usage" << std::endl; | |
83 | exit(1); | |
84 | } | |
85 | if (ceph_argparse_need_usage(args)) { | |
86 | usage(); | |
87 | exit(0); | |
88 | } | |
7c673cae FG |
89 | |
90 | auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, | |
11fdf7f2 TL |
91 | CODE_ENVIRONMENT_UTILITY, |
92 | CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); | |
7c673cae FG |
93 | common_init_finish(g_ceph_context); |
94 | ||
95 | test_fn_t fn = NULL; | |
96 | for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) { | |
97 | if (ceph_argparse_double_dash(args, i)) { | |
98 | break; | |
7c673cae FG |
99 | } else if (ceph_argparse_flag(args, i, "--infinite_recursion", (char*)NULL)) { |
100 | fn = infinite_recursion_test; | |
101 | } else if (ceph_argparse_flag(args, i, "-s", "--simple_segv", (char*)NULL)) { | |
102 | fn = simple_segv_test; | |
103 | } else { | |
11fdf7f2 TL |
104 | cerr << "unrecognized argument: " << *i << std::endl; |
105 | exit(1); | |
7c673cae FG |
106 | } |
107 | } | |
108 | if (!fn) { | |
109 | std::cerr << "Please select a test to run. Type -h for help." << std::endl; | |
11fdf7f2 | 110 | exit(1); |
7c673cae FG |
111 | } |
112 | fn(); | |
113 | return 0; | |
114 | } |