summaryrefslogtreecommitdiffstats
path: root/src/test/TestSignalHandlers.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/test/TestSignalHandlers.cc
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/TestSignalHandlers.cc')
-rw-r--r--src/test/TestSignalHandlers.cc114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/test/TestSignalHandlers.cc b/src/test/TestSignalHandlers.cc
new file mode 100644
index 000000000..74f819675
--- /dev/null
+++ b/src/test/TestSignalHandlers.cc
@@ -0,0 +1,114 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+/*
+ * TestSignalHandlers
+ *
+ * Test the Ceph signal handlers
+ */
+#include "common/ceph_argparse.h"
+#include "global/global_init.h"
+#include "common/errno.h"
+#include "common/debug.h"
+#include "common/config.h"
+
+#include <errno.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#define dout_context g_ceph_context
+using std::string;
+
+// avoid compiler warning about dereferencing NULL pointer
+static int* get_null()
+{
+ return 0;
+}
+
+static void simple_segv_test()
+{
+ generic_dout(-1) << "triggering SIGSEGV..." << dendl;
+ // cppcheck-suppress nullPointer
+ int i = *get_null();
+ std::cout << "i = " << i << std::endl;
+}
+
+// Given the name of the function, we can be pretty sure this is intentional.
+
+#pragma clang diagnostic push
+
+#pragma clang diagnostic ignored "-Winfinite-recursion"
+
+static void infinite_recursion_test_impl()
+{
+ infinite_recursion_test_impl();
+}
+
+#pragma clang diagnostic pop
+
+static void infinite_recursion_test()
+{
+ generic_dout(0) << "triggering SIGSEGV with infinite recursion..." << dendl;
+ infinite_recursion_test_impl();
+}
+
+static void usage()
+{
+ cout << "usage: TestSignalHandlers [test]" << std::endl;
+ cout << "--simple_segv: run simple_segv test" << std::endl;
+ cout << "--infinite_recursion: run infinite_recursion test" << std::endl;
+ generic_client_usage();
+}
+
+typedef void (*test_fn_t)(void);
+
+int main(int argc, const char **argv)
+{
+ vector<const char*> args;
+ argv_to_vec(argc, argv, args);
+ if (args.empty()) {
+ cerr << argv[0] << ": -h or --help for usage" << std::endl;
+ exit(1);
+ }
+ if (ceph_argparse_need_usage(args)) {
+ usage();
+ exit(0);
+ }
+
+ auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_UTILITY,
+ CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
+ common_init_finish(g_ceph_context);
+
+ test_fn_t fn = NULL;
+ for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
+ if (ceph_argparse_double_dash(args, i)) {
+ break;
+ } else if (ceph_argparse_flag(args, i, "--infinite_recursion", (char*)NULL)) {
+ fn = infinite_recursion_test;
+ } else if (ceph_argparse_flag(args, i, "-s", "--simple_segv", (char*)NULL)) {
+ fn = simple_segv_test;
+ } else {
+ cerr << "unrecognized argument: " << *i << std::endl;
+ exit(1);
+ }
+ }
+ if (!fn) {
+ std::cerr << "Please select a test to run. Type -h for help." << std::endl;
+ exit(1);
+ }
+ fn();
+ return 0;
+}