redesign exiting SBCL
[sbcl.git] / tests / kill-non-lisp-thread.impure.lisp
1 ;;;; Testing signal handling in non-lisp threads.
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
13
14 #-sb-thread
15 (sb-ext:exit :code 104)
16
17 (use-package :sb-alien)
18
19 (defun run (program &rest arguments)
20   (let* ((proc nil)
21          (output
22           (with-output-to-string (s)
23             (setf proc (run-program program arguments
24                                     :environment (test-util::test-env)
25                                     :output s)))))
26     (unless (zerop (process-exit-code proc))
27       (error "Bad exit code: ~S~%Output:~% ~S"
28              (process-exit-code proc)
29              output))
30     output))
31
32 (run "/bin/sh" "run-compiler.sh" "-sbcl-pic" "-sbcl-shared"
33      "-O3" "-I" "../src/runtime/"
34      "kill-non-lisp-thread.c" "-o" "kill-non-lisp-thread.so")
35
36 (load-shared-object (truename "kill-non-lisp-thread.so"))
37
38 (define-alien-routine kill-non-lisp-thread void)
39
40 (with-test (:name :kill-non-lisp-thread)
41   (let ((receivedp nil))
42     (push (lambda ()
43             (setq receivedp t))
44           (sb-thread::thread-interruptions sb-thread:*current-thread*))
45     (kill-non-lisp-thread)
46     (sleep 1)
47     (assert receivedp)))
48
49 (delete-file "kill-non-lisp-thread.so")