diff options
| author | Stephen Gildea | 2018-07-31 22:34:35 -0700 |
|---|---|---|
| committer | Stephen Gildea | 2018-07-31 22:34:35 -0700 |
| commit | 1804fece02691798394c9e9bd519cd4a53776018 (patch) | |
| tree | 9d5d441db29404f04417332be3507ba968eec42f /test/src/thread-tests.el | |
| parent | 17205d361795eaaa8e09ae62875c7439bb57a078 (diff) | |
| parent | 82d6416a28dc5b4ab65b8081f035679bec4e3604 (diff) | |
| download | emacs-1804fece02691798394c9e9bd519cd4a53776018.tar.gz emacs-1804fece02691798394c9e9bd519cd4a53776018.zip | |
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs
Diffstat (limited to 'test/src/thread-tests.el')
| -rw-r--r-- | test/src/thread-tests.el | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el index a00a9c84bd6..364f6d61f05 100644 --- a/test/src/thread-tests.el +++ b/test/src/thread-tests.el | |||
| @@ -34,10 +34,11 @@ | |||
| 34 | (declare-function thread--blocker "thread.c" (thread)) | 34 | (declare-function thread--blocker "thread.c" (thread)) |
| 35 | (declare-function thread-alive-p "thread.c" (thread)) | 35 | (declare-function thread-alive-p "thread.c" (thread)) |
| 36 | (declare-function thread-join "thread.c" (thread)) | 36 | (declare-function thread-join "thread.c" (thread)) |
| 37 | (declare-function thread-last-error "thread.c" ()) | 37 | (declare-function thread-last-error "thread.c" (&optional cleanup)) |
| 38 | (declare-function thread-name "thread.c" (thread)) | 38 | (declare-function thread-name "thread.c" (thread)) |
| 39 | (declare-function thread-signal "thread.c" (thread error-symbol data)) | 39 | (declare-function thread-signal "thread.c" (thread error-symbol data)) |
| 40 | (declare-function thread-yield "thread.c" ()) | 40 | (declare-function thread-yield "thread.c" ()) |
| 41 | (defvar main-thread) | ||
| 41 | 42 | ||
| 42 | (ert-deftest threads-is-one () | 43 | (ert-deftest threads-is-one () |
| 43 | "Test for existence of a thread." | 44 | "Test for existence of a thread." |
| @@ -71,6 +72,11 @@ | |||
| 71 | (skip-unless (featurep 'threads)) | 72 | (skip-unless (featurep 'threads)) |
| 72 | (should (listp (all-threads)))) | 73 | (should (listp (all-threads)))) |
| 73 | 74 | ||
| 75 | (ert-deftest threads-main-thread () | ||
| 76 | "Simple test for all-threads." | ||
| 77 | (skip-unless (featurep 'threads)) | ||
| 78 | (should (eq main-thread (car (all-threads))))) | ||
| 79 | |||
| 74 | (defvar threads-test-global nil) | 80 | (defvar threads-test-global nil) |
| 75 | 81 | ||
| 76 | (defun threads-test-thread1 () | 82 | (defun threads-test-thread1 () |
| @@ -94,15 +100,24 @@ | |||
| 94 | (progn | 100 | (progn |
| 95 | (setq threads-test-global nil) | 101 | (setq threads-test-global nil) |
| 96 | (let ((thread (make-thread #'threads-test-thread1))) | 102 | (let ((thread (make-thread #'threads-test-thread1))) |
| 97 | (thread-join thread) | 103 | (and (= (thread-join thread) 23) |
| 98 | (and threads-test-global | 104 | (= threads-test-global 23) |
| 99 | (not (thread-alive-p thread))))))) | 105 | (not (thread-alive-p thread))))))) |
| 100 | 106 | ||
| 101 | (ert-deftest threads-join-self () | 107 | (ert-deftest threads-join-self () |
| 102 | "Cannot `thread-join' the current thread." | 108 | "Cannot `thread-join' the current thread." |
| 103 | (skip-unless (featurep 'threads)) | 109 | (skip-unless (featurep 'threads)) |
| 104 | (should-error (thread-join (current-thread)))) | 110 | (should-error (thread-join (current-thread)))) |
| 105 | 111 | ||
| 112 | (ert-deftest threads-join-error () | ||
| 113 | "Test of error signalling from `thread-join'." | ||
| 114 | :tags '(:unstable) | ||
| 115 | (skip-unless (featurep 'threads)) | ||
| 116 | (let ((thread (make-thread #'threads-call-error))) | ||
| 117 | (while (thread-alive-p thread) | ||
| 118 | (thread-yield)) | ||
| 119 | (should-error (thread-join thread)))) | ||
| 120 | |||
| 106 | (defvar threads-test-binding nil) | 121 | (defvar threads-test-binding nil) |
| 107 | 122 | ||
| 108 | (defun threads-test-thread2 () | 123 | (defun threads-test-thread2 () |
| @@ -191,7 +206,7 @@ | |||
| 191 | (ert-deftest threads-mutex-signal () | 206 | (ert-deftest threads-mutex-signal () |
| 192 | "Test signaling a blocked thread." | 207 | "Test signaling a blocked thread." |
| 193 | (skip-unless (featurep 'threads)) | 208 | (skip-unless (featurep 'threads)) |
| 194 | (should | 209 | (should-error |
| 195 | (progn | 210 | (progn |
| 196 | (setq threads-mutex (make-mutex)) | 211 | (setq threads-mutex (make-mutex)) |
| 197 | (setq threads-mutex-key nil) | 212 | (setq threads-mutex-key nil) |
| @@ -200,8 +215,10 @@ | |||
| 200 | (while (not threads-mutex-key) | 215 | (while (not threads-mutex-key) |
| 201 | (thread-yield)) | 216 | (thread-yield)) |
| 202 | (thread-signal thr 'quit nil) | 217 | (thread-signal thr 'quit nil) |
| 203 | (thread-join thr)) | 218 | ;; `quit' is not catched by `should-error'. We must indicate it. |
| 204 | t))) | 219 | (condition-case nil |
| 220 | (thread-join thr) | ||
| 221 | (quit (signal 'error nil))))))) | ||
| 205 | 222 | ||
| 206 | (defun threads-test-io-switch () | 223 | (defun threads-test-io-switch () |
| 207 | (setq threads-test-global 23)) | 224 | (setq threads-test-global 23)) |
| @@ -275,6 +292,9 @@ | |||
| 275 | (thread-yield)) | 292 | (thread-yield)) |
| 276 | (should (equal (thread-last-error) | 293 | (should (equal (thread-last-error) |
| 277 | '(error "Error is called"))) | 294 | '(error "Error is called"))) |
| 295 | (should (equal (thread-last-error 'cleanup) | ||
| 296 | '(error "Error is called"))) | ||
| 297 | (should-not (thread-last-error)) | ||
| 278 | (setq th2 (make-thread #'threads-custom "threads-custom")) | 298 | (setq th2 (make-thread #'threads-custom "threads-custom")) |
| 279 | (should (threadp th2)))) | 299 | (should (threadp th2)))) |
| 280 | 300 | ||