1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2010 Dreamhost
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.
18 * Test the Ceph signal handlers
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"
31 #define dout_context g_ceph_context
34 // avoid compiler warning about dereferencing NULL pointer
35 static int* get_null()
40 static void simple_segv_test()
42 generic_dout(-1) << "triggering SIGSEGV..." << dendl
;
43 // cppcheck-suppress nullPointer
45 std::cout
<< "i = " << i
<< std::endl
;
48 // Given the name of the function, we can be pretty sure this is intentional.
50 #pragma clang diagnostic push
52 #pragma clang diagnostic ignored "-Winfinite-recursion"
54 static void infinite_recursion_test_impl()
56 infinite_recursion_test_impl();
59 #pragma clang diagnostic pop
61 static void infinite_recursion_test()
63 generic_dout(0) << "triggering SIGSEGV with infinite recursion..." << dendl
;
64 infinite_recursion_test_impl();
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();
75 typedef void (*test_fn_t
)(void);
77 int main(int argc
, const char **argv
)
79 vector
<const char*> args
;
80 argv_to_vec(argc
, argv
, args
);
82 cerr
<< argv
[0] << ": -h or --help for usage" << std::endl
;
85 if (ceph_argparse_need_usage(args
)) {
90 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
91 CODE_ENVIRONMENT_UTILITY
,
92 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
93 common_init_finish(g_ceph_context
);
96 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
97 if (ceph_argparse_double_dash(args
, i
)) {
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
;
104 cerr
<< "unrecognized argument: " << *i
<< std::endl
;
109 std::cerr
<< "Please select a test to run. Type -h for help." << std::endl
;