Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Add more testcases that trigger crashes in various ways #538

Merged
merged 1 commit into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef NDEBUG
# undef NDEBUG
#endif
#include <assert.h>

#ifdef SENTRY_PLATFORM_WINDOWS
# include <synchapi.h>
# define sleep_s(SECONDS) Sleep((SECONDS)*1000)
#else
# include <signal.h>
# include <unistd.h>
# define sleep_s(SECONDS) sleep(SECONDS)
#endif
Expand Down Expand Up @@ -156,6 +161,20 @@ main(int argc, char **argv)
if (has_arg(argc, argv, "crash")) {
trigger_crash();
}
if (has_arg(argc, argv, "assert")) {
assert(0);
}
if (has_arg(argc, argv, "abort")) {
abort();
}
#ifdef SENTRY_PLATFORM_UNIX
if (has_arg(argc, argv, "raise")) {
raise(SIGSEGV);
}
if (has_arg(argc, argv, "kill")) {
kill(getpid(), SIGSEGV);
}
#endif

if (has_arg(argc, argv, "capture-event")) {
sentry_value_t event = sentry_value_new_message_event(
Expand All @@ -180,6 +199,7 @@ main(int argc, char **argv)

// make sure everything flushes
sentry_close();

if (has_arg(argc, argv, "sleep-after-shutdown")) {
sleep_s(1);
}
Expand Down