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 cerr << "usage: TestSignalHandlers [test]" << std::endl;
70 cerr << "--simple_segv: run simple_segv test" << std::endl;
71 cerr << "--infinite_recursion: run infinite_recursion test" << std::endl;
72 generic_client_usage(); // Will exit()
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);
83 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
84 CODE_ENVIRONMENT_UTILITY, 0);
85 common_init_finish(g_ceph_context);
88 for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
89 if (ceph_argparse_double_dash(args, i)) {
91 } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
93 } else if (ceph_argparse_flag(args, i, "--infinite_recursion", (char*)NULL)) {
94 fn = infinite_recursion_test;
95 } else if (ceph_argparse_flag(args, i, "-s", "--simple_segv", (char*)NULL)) {
96 fn = simple_segv_test;
98 cerr << "Garbage at end of command line." << std::endl;
103 std::cerr << "Please select a test to run. Type -h for help." << std::endl;