diff options
| author | Gemini Lasswell | 2018-08-11 19:19:23 -0700 |
|---|---|---|
| committer | Gemini Lasswell | 2018-09-09 07:41:50 -0700 |
| commit | 2f5a65a7691060adfc50bc34f5a12e33358fe19a (patch) | |
| tree | 0323a7cbcaa60b4cbc6c8ec97ec6091a73f69b3a | |
| parent | 703b1cf9e232061648af11e9772d86895735158d (diff) | |
| download | emacs-2f5a65a7691060adfc50bc34f5a12e33358fe19a.tar.gz emacs-2f5a65a7691060adfc50bc34f5a12e33358fe19a.zip | |
Add tests for list-threads and the *Threads* buffer
* test/lisp/thread-tests.el: New file.
| -rw-r--r-- | test/lisp/thread-tests.el | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/test/lisp/thread-tests.el b/test/lisp/thread-tests.el new file mode 100644 index 00000000000..0d57d38779f --- /dev/null +++ b/test/lisp/thread-tests.el | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | ;;; thread-tests.el --- Test suite for thread.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2018 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Gemini Lasswell <gazally@runbox.com> | ||
| 6 | ;; Keywords: threads | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | |||
| 26 | ;;; Code: | ||
| 27 | |||
| 28 | (require 'ert) | ||
| 29 | (require 'thread) | ||
| 30 | |||
| 31 | ;; Declare the functions used here in case Emacs has been configured | ||
| 32 | ;; --without-threads. | ||
| 33 | (declare-function make-mutex "thread.c" (&optional name)) | ||
| 34 | (declare-function mutex-lock "thread.c" (mutex)) | ||
| 35 | (declare-function mutex-unlock "thread.c" (mutex)) | ||
| 36 | (declare-function make-thread "thread.c" (function &optional name)) | ||
| 37 | (declare-function thread-join "thread.c" (thread)) | ||
| 38 | (declare-function thread-yield "thread.c" ()) | ||
| 39 | |||
| 40 | (defvar thread-tests-flag) | ||
| 41 | (defvar thread-tests-mutex (when (featurep 'threads) (make-mutex "mutex1"))) | ||
| 42 | |||
| 43 | (defun thread-tests--thread-function () | ||
| 44 | (setq thread-tests-flag t) | ||
| 45 | (with-mutex thread-tests-mutex | ||
| 46 | (sleep-for 0.01))) | ||
| 47 | |||
| 48 | (ert-deftest thread-tests-thread-list-send-error () | ||
| 49 | "A thread can be sent an error signal from the *Thread List* buffer." | ||
| 50 | (skip-unless (featurep 'threads)) | ||
| 51 | (cl-letf (((symbol-function 'y-or-n-p) (lambda (_prompt) t))) | ||
| 52 | (with-mutex thread-tests-mutex | ||
| 53 | (setq thread-tests-flag nil) | ||
| 54 | (let ((thread (make-thread #'thread-tests--thread-function | ||
| 55 | "thread-tests-wait"))) | ||
| 56 | (while (not thread-tests-flag) | ||
| 57 | (thread-yield)) | ||
| 58 | (list-threads) | ||
| 59 | (goto-char (point-min)) | ||
| 60 | (re-search-forward | ||
| 61 | "^thread-tests.+[[:blank:]]+Blocked[[:blank:]]+.+mutex1.+?") | ||
| 62 | (thread-list-send-error-signal) | ||
| 63 | (should-error (thread-join thread)) | ||
| 64 | (list-threads) | ||
| 65 | (goto-char (point-min)) | ||
| 66 | (should-error (re-search-forward "thread-tests")))))) | ||
| 67 | |||
| 68 | (ert-deftest thread-tests-thread-list-show-backtrace () | ||
| 69 | "Show a backtrace for another thread from the *Thread List* buffer." | ||
| 70 | (skip-unless (featurep 'threads)) | ||
| 71 | (let (thread) | ||
| 72 | (with-mutex thread-tests-mutex | ||
| 73 | (setq thread-tests-flag nil) | ||
| 74 | (setq thread | ||
| 75 | (make-thread #'thread-tests--thread-function "thread-tests-back")) | ||
| 76 | (while (not thread-tests-flag) | ||
| 77 | (thread-yield)) | ||
| 78 | (list-threads) | ||
| 79 | (goto-char (point-min)) | ||
| 80 | (re-search-forward | ||
| 81 | "^thread-tests.+[[:blank:]]+Blocked[[:blank:]]+.+mutex1.+?") | ||
| 82 | (thread-list-pop-to-backtrace) | ||
| 83 | (goto-char (point-min)) | ||
| 84 | (re-search-forward "thread-tests-back") | ||
| 85 | (re-search-forward "mutex-lock") | ||
| 86 | (re-search-forward "thread-tests--thread-function")) | ||
| 87 | (thread-join thread))) | ||
| 88 | |||
| 89 | (ert-deftest thread-tests-list-threads-error-when-not-configured () | ||
| 90 | "Signal an error running `list-threads' if threads are not configured." | ||
| 91 | (skip-unless (not (featurep 'threads))) | ||
| 92 | (should-error (list-threads))) | ||
| 93 | |||
| 94 | (provide 'thread-tests) | ||
| 95 | |||
| 96 | ;;; thread-tests.el ends here | ||