aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2025-03-02 20:54:36 +0800
committerPo Lu2025-03-02 21:02:10 +0800
commit749e33bb481eedbefe0fd24124b446f9c47728d5 (patch)
tree773b78d0dd920288ae0dbe4bf2ed04b7e95d3ebb
parente4d8095c3dccc4f37be54b083d8b511fac0142b3 (diff)
downloademacs-749e33bb481eedbefe0fd24124b446f9c47728d5.tar.gz
emacs-749e33bb481eedbefe0fd24124b446f9c47728d5.zip
Specifically report attempts to exit Emacs during test execution
* test/infra/android/test-driver.el (ats-in-eval): Fix typo in doc string. (ats-eval-as-printed, ats-eval-serial, ats-eval-do-decode): Render buffer-local. (ats-executing-form): New variable. (ats-process-filter): Bind the same around `eval'. (ats-kill-emacs-function): New function; register it to execute when Emacs exits.
-rw-r--r--test/infra/android/test-driver.el55
1 files changed, 48 insertions, 7 deletions
diff --git a/test/infra/android/test-driver.el b/test/infra/android/test-driver.el
index 5afbb78cdcd..ff9590d8d9f 100644
--- a/test/infra/android/test-driver.el
+++ b/test/infra/android/test-driver.el
@@ -1,5 +1,5 @@
1;;; Receive and execute Lisp code submitted by a test controller. -*- lexical-binding: t; -*- 1;;; Receive and execute Lisp code submitted by a test controller. -*- lexical-binding: t; -*-
2;;; $Id: ats-driver.el,v 1.8 2025/03/02 11:11:56 jw Exp $ 2;;; $Id: ats-driver.el,v 1.9 2025/03/02 12:52:57 jw Exp $
3 3
4;; Copyright (C) 2025 Free Software Foundation, Inc. 4;; Copyright (C) 2025 Free Software Foundation, Inc.
5 5
@@ -43,18 +43,21 @@
43 :inherit variable-pitch)) 43 :inherit variable-pitch))
44 "Face of ATS header elements.") 44 "Face of ATS header elements.")
45 45
46(defvar-local ats-in-eval nil 46(defvar ats-in-eval nil
47 "Whether an `-eval' command is being processed and form's size.") 47 "Whether an `-eval' command is being processed and the form's size.")
48 48
49(defvar-local ats-eval-as-printed nil 49(defvar ats-eval-as-printed nil
50 "Whether to return the values of the submitted form as a string.") 50 "Whether to return the values of the submitted form as a string.")
51 51
52(defvar-local ats-eval-serial nil 52(defvar ats-eval-serial nil
53 "Serial number identifying this result.") 53 "Serial number identifying this result.")
54 54
55(defvar-local ats-eval-do-decode nil 55(defvar ats-eval-do-decode nil
56 "Whether to decode the form provided as utf-8-emacs.") 56 "Whether to decode the form provided as utf-8-emacs.")
57 57
58(defvar ats-executing-form nil
59 "Bound to `true' when executing a submitted form.")
60
58(defun ats-process-filter (process string) 61(defun ats-process-filter (process string)
59 "Filter input from `ats-process'. 62 "Filter input from `ats-process'.
60Insert STRING into the connection buffer, till a full command is 63Insert STRING into the connection buffer, till a full command is
@@ -126,7 +129,8 @@ read."
126 str 'utf-8-emacs t) 129 str 'utf-8-emacs t)
127 str)) 130 str))
128 (expr (car (read-from-string str))) 131 (expr (car (read-from-string str)))
129 (value (eval expr))) 132 (value (let ((ats-executing-form t))
133 (eval expr))))
130 (cons 'ok value))) 134 (cons 'ok value)))
131 (t (cons 'error err)))))) 135 (t (cons 'error err))))))
132 (let* ((print-escape-control-characters t) 136 (let* ((print-escape-control-characters t)
@@ -212,6 +216,43 @@ the controller."
212 (message "; Listening for connection from controller at localhost:%d" 216 (message "; Listening for connection from controller at localhost:%d"
213 service))) 217 service)))
214 218
219
220
221;; `kill-emacs' interception.
222
223(defun ats-kill-emacs-function ()
224 "Print a message announcing that Emacs is exiting.
225Also, if executing a Lisp form, reply to the controller with the
226backtrace of the exit before really exiting."
227 (when-let* ((standard-output #'external-debugging-output)
228 (process ats-process))
229 (princ (if ats-executing-form
230 "Emacs is attempting to exit while evaluating a form...\n"
231 "Emacs is exiting...\n"))
232 (backtrace)
233 (when ats-in-eval
234 (with-temp-buffer
235 (let ((standard-output (current-buffer)))
236 (backtrace)
237 (let ((err (cons 'exit (buffer-string))))
238 (let* ((print-escape-control-characters t)
239 (print-escape-newlines t)
240 (str (encode-coding-string
241 (prin1-to-string err) 'utf-8-emacs t)))
242 (if ats-eval-as-printed
243 (let* ((quoted (prin1-to-string str)))
244 (process-send-string
245 process (format "\fats-request:%d %d\n"
246 ats-eval-serial
247 (length quoted)))
248 (process-send-string process quoted))
249 (process-send-string
250 process (format "\fats-request:%d %d\n"
251 ats-eval-serial
252 (length str)))
253 (process-send-string process str)))))))))
254(add-hook 'kill-emacs-hook #'ats-kill-emacs-function)
255
215(provide 'test-driver) 256(provide 'test-driver)
216 257
217;;; test-driver.el ends here 258;;; test-driver.el ends here