Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression test for sandboxed evaluation #173

Closed
wants to merge 8 commits into from
11 changes: 9 additions & 2 deletions qi-lib/flow/core/passes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
(provide (for-syntax define-and-register-pass
run-passes))

(begin-for-syntax
(module macro-debug racket/base
;; See tests/compiler/rules/full-cycle.rkt for an explanation
;; re: sandboxed evaluation, submodules and test coverage.
(provide my-emit-local-step)

(define my-emit-local-step
;; See "Breaking Out of the Sandbox"
Expand All @@ -15,7 +18,11 @@
(make-keyword-procedure
(lambda (kws kw-args . rest)
(void))))))
(dynamic-require 'macro-debugger/emit 'emit-local-step)))
(dynamic-require 'macro-debugger/emit 'emit-local-step))))

(require (for-syntax 'macro-debug))

(begin-for-syntax

;; Could be a list but for future extensibility a custom struct is
;; probably a better idea.
Expand Down
3 changes: 2 additions & 1 deletion qi-lib/flow/extended/forms.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
syntax/parse/define
"expander.rkt"
"../../macro.rkt"
"../space.rkt"
(only-in "../space.rkt"
define-for-qi)
"impl.rkt")

;;; Predicates
Expand Down
1 change: 1 addition & 0 deletions qi-test/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
(define build-deps '("rackunit-lib"
"adjutor"
"math-lib"
"sandbox-lib"
"qi-lib"))
(define clean '("compiled" "tests/compiled" "tests/private/compiled"))
55 changes: 50 additions & 5 deletions qi-test/tests/compiler/rules/full-cycle.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
rackunit/text-ui
syntax/macro-testing
qi/flow/core/deforest
qi/flow/core/compiler
racket/sandbox
"private/deforest-util.rkt"
(submod qi/flow/extended/expander invoke))

Expand All @@ -21,12 +23,17 @@

;; A macro that accepts surface syntax, expands it, and then applies the
;; indicated optimization passes.
(define-syntax-parser test-compile~>
(define-syntax-parser test-passes~>
[(_ stx)
#'(expand-flow stx)]
[(_ stx pass ... passN)
#'(passN
(test-compile~> stx pass ...))]))
(test-passes~> stx pass ...))])
benknoble marked this conversation as resolved.
Show resolved Hide resolved

;; A macro that expands and compiles surface syntax
(define-syntax-parse-rule (qi-compile stx)
(compile-flow
(expand-flow stx))))


(define tests
Expand All @@ -39,9 +46,47 @@
(test-true "normalize → deforest"
(deforested?
(phase1-eval
(test-compile~> #'(~>> (filter odd?) values (map sqr))
normalize-pass
deforest-pass)))))))
(qi-compile
#'(~>> (filter odd?) values (map sqr)))))))
(test-suite
"sandboxed evaluation"
(test-not-exn "Plays well with sandboxed evaluation"
benknoble marked this conversation as resolved.
Show resolved Hide resolved
;; This test reproduces the bug and the fix fixes it. Yet,
;; coverage does not show the lambda in `my-emit-local-step`
;; as being covered. This could be because the constructed
;; sandbox evaluator "covering" the code doesn't count as
;; coverage by the main evaluator running the test?
;; We address this by putting `my-emit-local-step` in a
;; submodule, which, by default, are ignored by coverage.
(lambda ()
(let ([eval (parameterize ([sandbox-output 'string]
[sandbox-error-output 'string]
[sandbox-memory-limit #f])
(make-evaluator
'racket/base
'(require (for-syntax racket/base)
;; necessary to recognize and expand core forms correctly
qi/flow/extended/expander
;; necessary to correctly expand the right-threading form
qi/flow/extended/forms
syntax/macro-testing
racket/list
qi/flow/core/compiler
(submod qi/flow/extended/expander invoke))
benknoble marked this conversation as resolved.
Show resolved Hide resolved

'(begin-for-syntax
(require syntax/parse/define
(for-template qi/flow/core/compiler)
(for-syntax racket/base))

;; A macro that expands and compiles surface syntax
(define-syntax-parse-rule (qi-compile stx)
(compile-flow
(expand-flow stx))))))])
benknoble marked this conversation as resolved.
Show resolved Hide resolved
(eval
'(phase1-eval
(qi-compile
#'sqr)))))))))

(module+ main
(void
Expand Down
Loading