Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
signals_tests.cpp File Reference
#include <sysio/vm/signals.hpp>
#include <chrono>
#include <csignal>
#include <thread>
#include <iostream>
#include <catch2/catch.hpp>
Include dependency graph for signals_tests.cpp:

Go to the source code of this file.

Classes

struct  test_exception
 

Functions

 TEST_CASE ("Testing signals", "[invoke_with_signal_handler]")
 
 TEST_CASE ("Testing throw", "[signal_handler_throw]")
 
 TEST_CASE ("Test signal handler forwarding", "[signal_handler_forward]")
 

Function Documentation

◆ TEST_CASE() [1/3]

TEST_CASE ( "Test signal handler forwarding" ,
"" [signal_handler_forward] )

Definition at line 41 of file signals_tests.cpp.

41 {
42 // reset backup signal handlers
43 auto guard = sysio::vm::scope_guard{[]{
44 std::signal(SIGSEGV, SIG_DFL);
45 std::signal(SIGBUS, SIG_DFL);
46 std::signal(SIGFPE, SIG_DFL);
47 sysio::vm::setup_signal_handler_impl(); // This is normally only called once
48 }};
49 {
50 std::signal(SIGSEGV, &handle_signal);
51 std::signal(SIGBUS, &handle_signal);
52 std::signal(SIGFPE, &handle_signal);
54 sig_handled = 0;
55 std::raise(SIGSEGV);
56 CHECK(sig_handled == 42 + SIGSEGV);
57 sig_handled = 0;
58 std::raise(SIGBUS);
59 CHECK(sig_handled == 42 + SIGBUS);
60 sig_handled = 0;
61 std::raise(SIGFPE);
62 CHECK(sig_handled == 42 + SIGFPE);
63 }
64 {
65 struct sigaction sa;
66 sa.sa_sigaction = &handle_signal_sigaction;
67 sigemptyset(&sa.sa_mask);
68 sa.sa_flags = SA_NODEFER | SA_SIGINFO;
69 sigaction(SIGSEGV, &sa, nullptr);
70 sigaction(SIGBUS, &sa, nullptr);
71 sigaction(SIGFPE, &sa, nullptr);
73 sig_handled = 0;
74 std::raise(SIGSEGV);
75 CHECK(sig_handled == 142 + SIGSEGV);
76 sig_handled = 0;
77 std::raise(SIGBUS);
78 CHECK(sig_handled == 142 + SIGBUS);
79 sig_handled = 0;
80 std::raise(SIGFPE);
81 CHECK(sig_handled == 142 + SIGFPE);
82 }
83}
#define CHECK(cond)
Definition util.h:80
void setup_signal_handler_impl()
Definition signals.hpp:94
Here is the call graph for this function:

◆ TEST_CASE() [2/3]

TEST_CASE ( "Testing signals" ,
"" [invoke_with_signal_handler] )

Definition at line 11 of file signals_tests.cpp.

11 {
12 bool okay = false;
13 try {
15 std::raise(SIGSEGV);
16 }, [](int sig) {
17 throw test_exception{};
18 });
19 } catch(test_exception&) {
20 okay = true;
21 }
22 CHECK(okay);
23}
auto invoke_with_signal_handler(F &&f, E &&e)
Definition signals.hpp:123
Here is the call graph for this function:

◆ TEST_CASE() [3/3]

TEST_CASE ( "Testing throw" ,
"" [signal_handler_throw] )

Definition at line 25 of file signals_tests.cpp.

25 {
28 }, [](int){}), sysio::vm::wasm_exit_exception);
29}
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
void throw_(const char *msg)
Definition signals.hpp:84
Here is the call graph for this function: