raco test: create fresh user directory for each test in DrDr mode

This commit is contained in:
Matthew Flatt 2014-06-03 07:38:37 +01:00
parent 48ac219d6f
commit 2d3b856b71
2 changed files with 65 additions and 8 deletions

View File

@ -29,6 +29,8 @@
(define quiet-program? #f) (define quiet-program? #f)
(define check-stderr? #f) (define check-stderr? #f)
(define table? #f) (define table? #f)
(define fresh-user? #f)
(define empty-input? #f)
(define jobs 0) ; 0 mean "default" (define jobs 0) ; 0 mean "default"
(define task-sema (make-semaphore 1)) (define task-sema (make-semaphore 1))
@ -47,7 +49,8 @@
;; Stub for running a test in a process: ;; Stub for running a test in a process:
(module process racket/base (module process racket/base
(require rackunit/log) (require rackunit/log
racket/file)
;; Arguments are a temp file to hold test results, the module ;; Arguments are a temp file to hold test results, the module
;; path to run, and the `dynamic-require` second argument: ;; path to run, and the `dynamic-require` second argument:
(define argv (current-command-line-arguments)) (define argv (current-command-line-arguments))
@ -56,6 +59,12 @@
(define d (read (open-input-string (vector-ref argv 2)))) (define d (read (open-input-string (vector-ref argv 2))))
(define args (list-tail (vector->list argv) 3)) (define args (list-tail (vector->list argv) 3))
;; In case PLTUSERHOME is set, make sure relevant
;; directories exist:
(define (ready-dir d)
(make-directory* d))
(ready-dir (find-system-path 'doc-dir))
(parameterize ([current-command-line-arguments (list->vector args)]) (parameterize ([current-command-line-arguments (list->vector args)])
(dynamic-require test-module d) (dynamic-require test-module d)
((executable-yield-handler) 0)) ((executable-yield-handler) 0))
@ -125,6 +134,9 @@
(if check-stderr? (if check-stderr?
(tee-output-port (current-error-port) e) (tee-output-port (current-error-port) e)
(current-error-port)))) (current-error-port))))
(define stdin (if empty-input?
(open-input-bytes #"")
(current-input-port)))
(unless quiet? (unless quiet?
(when responsible (when responsible
@ -133,7 +145,11 @@
responsible)) responsible))
(when random? (when random?
(fprintf stdout "raco test:~a @(test-random #t)\n" (fprintf stdout "raco test:~a @(test-random #t)\n"
id))) id))
(when lock-name
(fprintf stdout "raco test:~a @(lock-name ~s)\n"
id
lock-name)))
(define-values (result-code test-results) (define-values (result-code test-results)
(case mode (case mode
@ -143,6 +159,7 @@
(define t (define t
(parameterize ([current-output-port stdout] (parameterize ([current-output-port stdout]
[current-error-port stderr] [current-error-port stderr]
[current-input-port stdin]
[current-command-line-arguments (list->vector args)]) [current-command-line-arguments (list->vector args)])
(thread (thread
(lambda () (lambda ()
@ -164,7 +181,7 @@
(parameterize ([current-custodian c]) (parameterize ([current-custodian c])
(dynamic-place* '(submod compiler/commands/test place) (dynamic-place* '(submod compiler/commands/test place)
'go 'go
#:in (current-input-port) #:in stdin
#:out stdout #:out stdout
#:err stderr))) #:err stderr)))
@ -181,14 +198,27 @@
(sync/timeout 0 pl))] (sync/timeout 0 pl))]
[(process) [(process)
(define tmp-file (make-temporary-file)) (define tmp-file (make-temporary-file))
(define tmp-dir (and fresh-user?
(make-temporary-file "home~a" 'directory)))
(define ps (define ps
(parameterize ([current-output-port stdout] (parameterize ([current-output-port stdout]
[current-error-port stderr] [current-error-port stderr]
[current-subprocess-custodian-mode 'kill] [current-subprocess-custodian-mode 'kill]
[current-custodian c]) [current-custodian c]
[current-environment-variables (environment-variables-copy
(current-environment-variables))])
(environment-variables-set! (current-environment-variables)
#"PLTUSERHOME"
(path->bytes tmp-dir))
(environment-variables-set! (current-environment-variables)
#"TMPDIR"
(path->bytes tmp-dir))
(environment-variables-set! (current-environment-variables)
#"PLTADDONDIR"
(path->bytes (find-system-path 'addon-dir)))
(apply process*/ports (apply process*/ports
stdout stdout
(current-input-port) stdin
stderr stderr
(find-exe) (find-exe)
"-l" "-l"
@ -209,6 +239,10 @@
(with-handlers ([exn:fail:read? (lambda () #f)]) (with-handlers ([exn:fail:read? (lambda () #f)])
(call-with-input-file* tmp-file read))) (call-with-input-file* tmp-file read)))
(delete-file tmp-file)
(when tmp-dir
(delete-directory/files tmp-dir))
(values (proc 'exit-code) (values (proc 'exit-code)
(and (pair? results) (and (pair? results)
(exact-positive-integer? (car results)) (exact-positive-integer? (car results))
@ -832,12 +866,14 @@
"Configure defaults to imitate DrDr" "Configure defaults to imitate DrDr"
(set! check-top-suffix? #t) (set! check-top-suffix? #t)
(set! first-avail? #t) (set! first-avail? #t)
(set! empty-input? #t)
(when (zero? jobs) (when (zero? jobs)
(set-jobs! (processor-count))) (set-jobs! (processor-count)))
(unless default-timeout (unless default-timeout
(set! default-timeout 90)) (set! default-timeout 90))
(set! check-stderr? #t) (set! check-stderr? #t)
(set! quiet-program? #t) (set! quiet-program? #t)
(set! fresh-user? #t)
(set! table? #t) (set! table? #t)
(unless default-mode (unless default-mode
(set! default-mode 'process))] (set! default-mode 'process))]
@ -874,12 +910,18 @@
[("--timeout") seconds [("--timeout") seconds
"Set default timeout to <seconds>" "Set default timeout to <seconds>"
(set! default-timeout (string->number* "timeout" seconds real?))] (set! default-timeout (string->number* "timeout" seconds real?))]
[("--fresh-user")
"Fresh PLTUSERHOME, etc., for each test"
(set! fresh-user? #t)]
[("--quiet-program" "-Q") [("--quiet-program" "-Q")
"Quiet the program" "Quiet the program"
(set! quiet-program? #t)] (set! quiet-program? #t)]
[("--check-stderr" "-e") [("--check-stderr" "-e")
"Treat stderr output as a test failure" "Treat stderr output as a test failure"
(set! check-stderr? #t)] (set! check-stderr? #t)]
[("--empty-stdin")
"Call program with an empty stdin"
(set! empty-input? #t)]
[("--quiet" "-q") [("--quiet" "-q")
"Suppress `raco test: ...' message" "Suppress `raco test: ...' message"
(set! quiet? #t)] (set! quiet? #t)]

View File

@ -54,9 +54,14 @@ The @exec{raco test} command accepts several flags:
@item{@DFlag{drdr} @item{@DFlag{drdr}
--- Configures defaults to imitate the DrDr continuous testing --- Configures defaults to imitate the DrDr continuous testing
system: ignore non-modules, use as many jobs as available processors, set the system: ignore non-modules, run tests in separate processes,
default timeout to 90 seconds, count stderr output as a test failure, use as many jobs as available processors,
quiet program output, and print a table of results.} set the default timeout to 90 seconds,
create a fresh @envvar{PLTUSERHOME} and @envvar{TMPDIR} for each test,
count stderr output as a test failure,
quiet program output,
provide program empty input,
and print a table of results.}
@item{@Flag{s} @nonterm{name} or @DFlag{submodule} @nonterm{name} @item{@Flag{s} @nonterm{name} or @DFlag{submodule} @nonterm{name}
--- Requires the submodule @nonterm{name} rather than @racket[test]. --- Requires the submodule @nonterm{name} rather than @racket[test].
@ -101,12 +106,22 @@ The @exec{raco test} command accepts several flags:
If any test fails due to a timeout, the exit status of @exec{raco test} If any test fails due to a timeout, the exit status of @exec{raco test}
is 2 (as opposed to 1 for only non-timeout failures or 0 for success).} is 2 (as opposed to 1 for only non-timeout failures or 0 for success).}
@item{@DFlag{fresh-user}
--- When running tests in a separate process, creates a fresh
directory and sets @envvar{PLTUSERHOME} and @envvar{TMPDIR}. The
@envvar{PLTADDONDIR} environment variable is also set so that
the add-on directory (which is where packages are installed, for
example), does @emph{not} change for each test process.}
@item{@Flag{Q} or @DFlag{quiet-program} @item{@Flag{Q} or @DFlag{quiet-program}
--- suppresses output from each test program.} --- suppresses output from each test program.}
@item{@Flag{e} or @DFlag{check-stderr} @item{@Flag{e} or @DFlag{check-stderr}
--- count any stderr output as a test failure.} --- count any stderr output as a test failure.}
@item{@DFlag{empty-stdin}
--- provide an empty stdin to each test program.}
@item{@Flag{q} or @DFlag{quiet} @item{@Flag{q} or @DFlag{quiet}
--- suppresses output of progress information, responsible --- suppresses output of progress information, responsible
parties, and varying output (see @secref["test-responsible"]).} parties, and varying output (see @secref["test-responsible"]).}