]> git.eshelyaron.com Git - emacs.git/commitdiff
; New function for executing Android tests in batch mode
authorPo Lu <luangruo@yahoo.com>
Wed, 26 Feb 2025 12:41:02 +0000 (20:41 +0800)
committerEshel Yaron <me@eshelyaron.com>
Fri, 28 Feb 2025 11:17:19 +0000 (12:17 +0100)
* test/infra/android/test-controller.el
(ats-execute-tests-batch): New function.

(cherry picked from commit 67b444e2907da1a27fc2db64aae9b4dcf299f2d9)

test/infra/android/test-controller.el

index d318c9a0d4b39a3a245657a1b1d621cc750329d0..f17d58e415e1c11ddae2e7d3ed8c71a30defb7e3 100644 (file)
@@ -2482,6 +2482,73 @@ subject to SELECTOR, as in `ert-run-tests'."
        "Running tests..."
       (ats-run-test process test selector))))
 
+\f
+
+;; Batch mode text execution.
+(defun ats-execute-tests-batch ()
+  "Execute tests in batch mode, in the manner of `test/Makefile'.
+Prompt for a device and execute tests on the same.  Save log
+files to a directory specified by the user.
+Call this function from the command line, with, for example:
+
+  $ emacs --batch -l test-controller.el -f ats-execute-tests-batch"
+  (let* ((ats-adb-host (getenv "ATS_ADB_HOST"))
+        (devices (ats-enumerate-devices
+                  (lambda (name state _)
+                    (and (equal state "device")
+                         (ignore-errors
+                           (ats-get-package-aid name "org.gnu.emacs")))))))
+    (message "These devices are presently available for test execution:")
+    (let ((nth 0))
+      (dolist (device devices)
+       (message "%2d. %-24s(API level %d, %s)"
+                (incf nth) (car device)
+                (ats-get-sdk-version (car device))
+                (ats-getprop (car device) "ro.product.cpu.abi"))))
+    (let* ((number (string-to-number
+                   (read-string
+                    "Select a device by typing its number, and Return: ")))
+          (device (if (or (< number 1) (> number (length devices)))
+                      (user-error "Invalid selection: %s" number)
+                    (car (nth (1- number) devices))))
+          (users (ats-list-users device)))
+      (setq nth 0)
+      (dolist (user users)
+       (message "%2d. %s (id=%d)" (incf nth)
+                (cadr user) (car user)))
+      (setq number (string-to-number
+                   (read-string
+                    "As which user should tests be executed? ")))
+      (when (or (< number 1) (> number (length users)))
+       (user-error "Invalid selection: %s" number))
+      (let* ((user (car (nth (1- number) users)))
+            (connection (ats-connect device user)))
+       (ats-upload-all-tests
+        connection
+        (or ats-emacs-test-directory
+            (read-directory-name "Test base directory: "
+                                 nil nil t)))
+       (let ((output-directory
+              (read-directory-name
+               "Where to save test log files? ")))
+         (mkdir output-directory t)
+         (let ((tests (ats-list-tests connection)))
+           (dolist (test tests)
+             (message "Generating `%s/%s-test.log'"
+                      output-directory test)
+             (ats-run-test connection test)
+             (let ((output-file
+                    (concat (file-name-as-directory
+                             output-directory)
+                            test "-test.log")))
+               (mkdir (file-name-directory output-file) t)
+               (with-current-buffer "*Test Output*"
+                 (write-region (point-min) (point-max)
+                               (concat (file-name-as-directory
+                                        output-directory)
+                                       test "-test.log"))
+                 (erase-buffer))))))))))
+
 (provide 'test-controller)
 
 ;;; test-controller.el ends here