core: add assert-signal

This commit is contained in:
hellerve 2018-05-23 15:13:13 +02:00
parent a55c953396
commit 99fb38de73
2 changed files with 32 additions and 2 deletions

View File

@ -18,5 +18,12 @@
(register fork (Fn [] Int) "fork")
(register wait (Fn [(Ptr Int)] Int) "wait")
(register get-exit-status (Fn [Int] Int) "WEXITSTATUS")
(register signal (Fn [Int (Fn [Int] ())] ()) "signal")
(register signal-abort Int "SIGABRT")
(register signal-fpe Int "SIGFPE")
(register signal-ill Int "SIGILL")
(register signal-int Int "SIGINT")
(register signal-segv Int "SIGSEGV")
(register signal-term Int "SIGTERM")
)

View File

@ -81,14 +81,37 @@
(let [pid (System.fork)
status 0]
(if (= pid 0)
(x)
(do
(x)
0)
(do
(ignore (System.wait (address status)))
(System.get-exit-status status)))))
(defn assert-fails [state exit-code x descr]
(defn handle-signal [x] (System.exit x))
(defn run-child-signals [x]
(let [pid (System.fork)
status 0]
(if (= pid 0)
(do
(System.signal System.signal-abort handle-signal)
(System.signal System.signal-fpe handle-signal)
(System.signal System.signal-ill handle-signal)
(System.signal System.signal-segv handle-signal)
(System.signal System.signal-term handle-signal)
(x)
0)
(do
(ignore (System.wait (address status)))
(System.get-exit-status status)))))
(defn assert-exit [state exit-code x descr]
(assert-equal state exit-code (run-child x) descr))
(defn assert-signal [state signal x descr]
(assert-equal state signal (run-child-signals x) descr))
(defn print-test-results [state]
(let [passed @(State.passed state)
failed @(State.failed state)]