diff options
| -rw-r--r-- | test/infra/android/test-controller.el | 230 |
1 files changed, 154 insertions, 76 deletions
diff --git a/test/infra/android/test-controller.el b/test/infra/android/test-controller.el index 711deca7d29..999f66399e4 100644 --- a/test/infra/android/test-controller.el +++ b/test/infra/android/test-controller.el | |||
| @@ -2196,7 +2196,9 @@ Once uploaded, tests defined in the file may be loaded and | |||
| 2196 | executed by means of `ats-exec-tests'." | 2196 | executed by means of `ats-exec-tests'." |
| 2197 | (interactive | 2197 | (interactive |
| 2198 | (let* ((connection (ats-read-connection "Connection: ")) | 2198 | (let* ((connection (ats-read-connection "Connection: ")) |
| 2199 | (dir ats-emacs-test-directory) | 2199 | (dir (or ats-emacs-test-directory |
| 2200 | (read-directory-name "Test base directory: " | ||
| 2201 | nil nil t))) | ||
| 2200 | (test (completing-read "Test to upload: " | 2202 | (test (completing-read "Test to upload: " |
| 2201 | (ats-list-tests-locally dir) | 2203 | (ats-list-tests-locally dir) |
| 2202 | nil t nil | 2204 | nil t nil |
| @@ -2206,64 +2208,113 @@ executed by means of `ats-exec-tests'." | |||
| 2206 | (expand-file-name dir))) | 2208 | (expand-file-name dir))) |
| 2207 | (test-file | 2209 | (test-file |
| 2208 | (concat dir-name test-name "-tests.el")) | 2210 | (concat dir-name test-name "-tests.el")) |
| 2211 | (internal-resource-directory | ||
| 2212 | (concat dir-name (file-name-directory test-name) | ||
| 2213 | "resources")) | ||
| 2209 | (resources-directory | 2214 | (resources-directory |
| 2210 | (concat dir-name test-name "-resources")) | 2215 | (if (file-directory-p internal-resource-directory) |
| 2216 | internal-resource-directory | ||
| 2217 | (concat dir-name test-name "-resources"))) | ||
| 2211 | ;; Strip all directories from the test name. | 2218 | ;; Strip all directories from the test name. |
| 2212 | (default-directory (file-name-directory test-file))) | 2219 | (default-directory (file-name-directory test-file))) |
| 2213 | (unless (file-regular-p test-file) | 2220 | (unless (file-regular-p test-file) |
| 2214 | (error "Not a regular file: %s" test-file)) | 2221 | (error "Not a regular file: %s" test-file)) |
| 2215 | ;; Create a compressed tar file. Though a cpio implementation | 2222 | (if (file-directory-p resources-directory) |
| 2216 | ;; exists in the sources for Android 2.2's command line tools, yet | 2223 | ;; Create a compressed tar file. Though a cpio implementation |
| 2217 | ;; it is often deleted in release builds of the OS to reduce storage | 2224 | ;; exists in the sources for Android 2.2's command line tools, |
| 2218 | ;; utilization, so it is best to resort to tar and gzip, which Emacs | 2225 | ;; yet it is often deleted in release builds of the OS to reduce |
| 2219 | ;; is able to decompress without command line utilities. | 2226 | ;; storage utilization, so it is best to resort to tar and gzip, |
| 2220 | (let ((temp-file (make-temp-file "ats-" nil ".tar"))) | 2227 | ;; which Emacs is able to decompress without command line |
| 2221 | (unwind-protect | 2228 | ;; utilities. |
| 2222 | (progn | 2229 | (let ((temp-file (make-temp-file "ats-" nil ".tar")) |
| 2223 | (let ((bare-test-file (file-name-nondirectory test-file)) | 2230 | (bare-test-file (file-name-nondirectory test-file)) |
| 2224 | (bare-test-resources (file-name-nondirectory test-file))) | 2231 | (bare-test-resources |
| 2225 | (let ((rc (if (file-directory-p resources-directory) | 2232 | (file-name-nondirectory resources-directory))) |
| 2226 | (call-process "tar" nil nil nil "cf" temp-file | 2233 | (unwind-protect |
| 2227 | bare-test-file bare-test-resources) | 2234 | (progn |
| 2228 | (call-process "tar" nil nil nil "cf" temp-file | 2235 | (let ((rc (call-process |
| 2229 | bare-test-file)))) | 2236 | "tar" nil nil nil "cfh" temp-file |
| 2230 | (unless (eq 0 rc) | 2237 | bare-test-file bare-test-resources))) |
| 2231 | (error "tar exited with code: %d" rc))) | ||
| 2232 | ;; Compress this file. | ||
| 2233 | (with-temp-buffer | ||
| 2234 | (set-buffer-multibyte nil) | ||
| 2235 | (let ((rc (call-process "gzip" temp-file '(t nil) nil | ||
| 2236 | "-c" temp-file))) | ||
| 2237 | (unless (eq 0 rc) | 2238 | (unless (eq 0 rc) |
| 2238 | (error "gzip -c exited with code: %d" rc)) | 2239 | (error "tar exited with code: %d" rc))) |
| 2239 | ;; Write this compressed data to the destination and | 2240 | ;; Compress this file. |
| 2240 | ;; decompress it there. | 2241 | (with-temp-buffer |
| 2241 | (let ((rc (ats-eval | 2242 | (set-buffer-multibyte nil) |
| 2242 | process | 2243 | (let ((rc (call-process "gzip" nil '(t nil) nil |
| 2243 | `(with-temp-buffer | 2244 | "-c" temp-file))) |
| 2244 | (set-buffer-multibyte nil) | 2245 | (unless (eq 0 rc) |
| 2245 | (insert ,(buffer-string)) | 2246 | (error "gzip -c exited with code: %d" rc)) |
| 2246 | (zlib-decompress-region (point-min) | 2247 | ;; Write this compressed data to the destination and |
| 2247 | (point-max)) | 2248 | ;; decompress it there. |
| 2248 | (let ((dir | 2249 | (let ((rc (ats-eval |
| 2249 | (concat (file-name-as-directory | 2250 | process |
| 2250 | temporary-file-directory) | 2251 | `(with-temp-buffer |
| 2251 | "ats-tests/" ,test-name))) | 2252 | (set-buffer-multibyte nil) |
| 2252 | (if (file-directory-p dir) | 2253 | (insert ,(buffer-string)) |
| 2253 | (let ((files (directory-files-recursively | 2254 | (zlib-decompress-region (point-min) |
| 2254 | dir "")) | 2255 | (point-max)) |
| 2255 | (default-directory dir)) | 2256 | (let ((dir |
| 2256 | (mapc #'delete-file files)) | 2257 | (concat (file-name-as-directory |
| 2257 | (make-directory dir t)) | 2258 | temporary-file-directory) |
| 2258 | (let ((default-directory dir)) | 2259 | "ats-tests/" ,test-name))) |
| 2259 | (require 'tar-mode) | 2260 | (if (file-directory-p dir) |
| 2260 | (tar-mode) | 2261 | (let ((files |
| 2261 | (tar-untar-buffer))))))) | 2262 | (directory-files-recursively |
| 2262 | (when (eq (car rc) 'error) | 2263 | dir "")) |
| 2263 | (error "Remote error: %S" (cdr rc))) | 2264 | (default-directory dir)) |
| 2264 | (message "Uploaded test `%s'" test-name)))))) | 2265 | (mapc #'delete-file files)) |
| 2265 | (with-demoted-errors "Removing temporary file: %S" | 2266 | (make-directory dir t)) |
| 2266 | (delete-file temp-file)))))) | 2267 | (let ((default-directory dir) |
| 2268 | ;; Otherwise file name handlers | ||
| 2269 | ;; such as `epa-file-handler' | ||
| 2270 | ;; are liable to interfere with | ||
| 2271 | ;; the extraction process. | ||
| 2272 | (file-name-handler-alist nil)) | ||
| 2273 | (require 'tar-mode) | ||
| 2274 | (tar-mode) | ||
| 2275 | (tar-untar-buffer)))) | ||
| 2276 | nil t))) | ||
| 2277 | (when (eq (car rc) 'error) | ||
| 2278 | (error "Remote error: %S" (cdr rc))) | ||
| 2279 | (message "Uploaded test `%s'" test-name))))) | ||
| 2280 | (with-demoted-errors "Removing temporary file: %S" | ||
| 2281 | (delete-file temp-file)))) | ||
| 2282 | ;; Just compress and transfer the file alone. | ||
| 2283 | (with-temp-buffer | ||
| 2284 | (set-buffer-multibyte nil) | ||
| 2285 | (let ((rc (call-process "gzip" nil '(t nil) nil | ||
| 2286 | "-c" test-file))) | ||
| 2287 | (unless (eq 0 rc) | ||
| 2288 | (error "gzip -c exited with code: %d" rc)) | ||
| 2289 | ;; Write this compressed data to the destination and | ||
| 2290 | ;; decompress it there. | ||
| 2291 | (let ((rc (ats-eval | ||
| 2292 | process | ||
| 2293 | `(with-temp-buffer | ||
| 2294 | (set-buffer-multibyte nil) | ||
| 2295 | (insert ,(buffer-string)) | ||
| 2296 | (zlib-decompress-region (point-min) | ||
| 2297 | (point-max)) | ||
| 2298 | (let* ((dir | ||
| 2299 | (concat (file-name-as-directory | ||
| 2300 | temporary-file-directory) | ||
| 2301 | "ats-tests/" ,test-name)) | ||
| 2302 | (dir-1 (file-name-as-directory dir))) | ||
| 2303 | (if (file-directory-p dir) | ||
| 2304 | (let ((files | ||
| 2305 | (directory-files-recursively | ||
| 2306 | dir "")) | ||
| 2307 | (default-directory dir)) | ||
| 2308 | (mapc #'delete-file files)) | ||
| 2309 | (make-directory dir t)) | ||
| 2310 | (write-region | ||
| 2311 | (point-min) (point-max) | ||
| 2312 | (concat dir-1 ,(file-name-nondirectory | ||
| 2313 | test-file))))) | ||
| 2314 | nil t))) | ||
| 2315 | (when (eq (car rc) 'error) | ||
| 2316 | (error "Remote error: %S" (cdr rc))) | ||
| 2317 | (message "Uploaded test `%s'" test-name))))))) | ||
| 2267 | 2318 | ||
| 2268 | (defun ats-list-tests-locally (dir) | 2319 | (defun ats-list-tests-locally (dir) |
| 2269 | "Return a list of tests defined in DIR. | 2320 | "Return a list of tests defined in DIR. |
| @@ -2272,7 +2323,13 @@ a likewise structured directory tree." | |||
| 2272 | (let* ((default-directory (expand-file-name dir)) | 2323 | (let* ((default-directory (expand-file-name dir)) |
| 2273 | (start (length default-directory))) | 2324 | (start (length default-directory))) |
| 2274 | (let ((dirs (directory-files-recursively | 2325 | (let ((dirs (directory-files-recursively |
| 2275 | dir "^[[:alnum:]-]+-tests\\.el$")) | 2326 | dir "^[[:alnum:]-]+-tests\\.el$" |
| 2327 | ;; Do not recurse into resource directories, as ERC's | ||
| 2328 | ;; contain several files that resemble tests. | ||
| 2329 | nil (lambda (dir-name) | ||
| 2330 | (and (not (equal (file-name-nondirectory dir-name) | ||
| 2331 | "resources")) | ||
| 2332 | (not (string-suffix-p "-resources" dir-name)))))) | ||
| 2276 | tests) | 2333 | tests) |
| 2277 | (dolist (dir dirs) | 2334 | (dolist (dir dirs) |
| 2278 | (let ((len (length dir))) | 2335 | (let ((len (length dir))) |
| @@ -2304,6 +2361,7 @@ uploaded to the remote device represented by PROCESS, as by | |||
| 2304 | (lambda (dir) | 2361 | (lambda (dir) |
| 2305 | (let* ((name (file-name-nondirectory dir))) | 2362 | (let* ((name (file-name-nondirectory dir))) |
| 2306 | (and (not (funcall is-test-directory name dir)) | 2363 | (and (not (funcall is-test-directory name dir)) |
| 2364 | (not (equal name "resources")) | ||
| 2307 | (not (string-suffix-p name "-resources"))))))) | 2365 | (not (string-suffix-p name "-resources"))))))) |
| 2308 | (tests nil)) | 2366 | (tests nil)) |
| 2309 | (dolist (dir dirs) | 2367 | (dolist (dir dirs) |
| @@ -2361,28 +2419,48 @@ Display the output of the tests executed in a buffer." | |||
| 2361 | (t (setq file-name (cdr rc)))) | 2419 | (t (setq file-name (cdr rc)))) |
| 2362 | ;; Delete all tests, load the byte-compiled test file, and execute | 2420 | ;; Delete all tests, load the byte-compiled test file, and execute |
| 2363 | ;; those tests just defined subject to SELECTOR. | 2421 | ;; those tests just defined subject to SELECTOR. |
| 2364 | (setq rc (ats-eval process | 2422 | (with-current-buffer (get-buffer-create "*Test Output*") |
| 2365 | `(progn | 2423 | (insert (format "=== Executing %s on %s ===\n" test device)) |
| 2366 | (require 'ert) | 2424 | (redisplay) |
| 2367 | (ert-delete-all-tests) | 2425 | (setq rc (ats-eval process |
| 2368 | (load ,file-name) | 2426 | `(progn |
| 2369 | (with-temp-buffer | 2427 | (require 'ert) |
| 2370 | (let ((standard-output (current-buffer)) | 2428 | (ert-delete-all-tests) |
| 2371 | (set-message-function | 2429 | (load ,file-name) |
| 2372 | (lambda (message) | 2430 | (with-temp-buffer |
| 2373 | (insert message "\n")))) | 2431 | (let ((standard-output (current-buffer)) |
| 2374 | (insert ,(format "=== Executing %s on %s ===\n" | 2432 | (set-message-function |
| 2375 | test device)) | 2433 | (lambda (message) |
| 2376 | (let ((noninteractive t)) | 2434 | (insert message "\n")))) |
| 2377 | (ert-run-tests-batch ',selector)) | 2435 | (let ((noninteractive t)) |
| 2378 | (insert "=== Test execution complete ===\n") | 2436 | (ert-run-tests-batch ',selector)) |
| 2379 | (buffer-string)))))) | 2437 | (insert "=== Test execution complete ===\n") |
| 2380 | (cond ((eq (car rc) 'error) | 2438 | (buffer-string)))))) |
| 2381 | (error "Error executing `%s-tests.el': %S" test (cdr rc))) | 2439 | (cond ((eq (car rc) 'error) |
| 2382 | (t (with-current-buffer (get-buffer-create "*Test Output*") | 2440 | (error "Error executing `%s-tests.el': %S" test (cdr rc))) |
| 2383 | (goto-char (point-max)) | 2441 | (t (progn |
| 2384 | (insert (cdr rc)) | 2442 | (goto-char (point-max)) |
| 2385 | (pop-to-buffer (current-buffer))))))) | 2443 | (insert (cdr rc)) |
| 2444 | (pop-to-buffer (current-buffer)))))))) | ||
| 2445 | |||
| 2446 | (defun ats-run-all-tests (process dir) | ||
| 2447 | "Run all Emacs tests defined in DIR on the device represented by PROCESS. | ||
| 2448 | Upload each and every test defined in DIR to the said device, | ||
| 2449 | and execute them in sequence. With a prefix argument, just run | ||
| 2450 | the tests without uploading them." | ||
| 2451 | (interactive | ||
| 2452 | (list (ats-read-connection "Connection: ") | ||
| 2453 | (or ats-emacs-test-directory | ||
| 2454 | (read-directory-name "Test base directory: " | ||
| 2455 | nil nil t)))) | ||
| 2456 | (let ((tests (ats-list-tests-locally dir))) | ||
| 2457 | (unless current-prefix-arg | ||
| 2458 | (dolist-with-progress-reporter (test tests) | ||
| 2459 | "Uploading tests to device..." | ||
| 2460 | (ats-upload-test process dir test))) | ||
| 2461 | (dolist-with-progress-reporter (test tests) | ||
| 2462 | "Running tests..." | ||
| 2463 | (ats-run-test process test)))) | ||
| 2386 | 2464 | ||
| 2387 | (provide 'test-controller) | 2465 | (provide 'test-controller) |
| 2388 | 2466 | ||