diff --git a/distribution/manifest b/distribution/manifest index 4ef3d1d..9e2eed7 100644 --- a/distribution/manifest +++ b/distribution/manifest @@ -208,6 +208,14 @@ tests/reverser/tags/1.1/reverser.scm tests/rev-app.scm tests/signal-tests.scm tests/version-tests.scm +tests/scheduler-fdset-2.scm +tests/scheduler-fdset-2a.scm +tests/scheduler-fdset-3.scm +tests/scheduler-fdset-4.scm +tests/scheduler-fdset.scm +tests/scheduler-test.scm +tests/cat.scm +tests/sink.c tweaks.scm utils.scm apply-hack.x86.S diff --git a/scheduler.scm b/scheduler.scm index e31f6c8..9538569 100644 --- a/scheduler.scm +++ b/scheduler.scm @@ -32,7 +32,8 @@ ##sys#update-thread-state-buffer ##sys#restore-thread-state-buffer remove-from-ready-queue ##sys#unblock-threads-for-i/o ##sys#force-primordial fdset-set fdset-test create-fdset stderr - ##sys#clear-i/o-state-for-thread! ##sys#abandon-mutexes) + ##sys#clear-i/o-state-for-thread! ##sys#abandon-mutexes + ##sys#interrupt-hook-continuation) (not inline ##sys#interrupt-hook) (unsafe) (foreign-declare #<number l) ls))))) + (close-i/o in out) + children)) + (else + (receive (in out pid) + (process "pgrep" `("-P" ,(number->string pid))) + (define line (read-line in)) + (define children '()) + (unless (eof-object? line) + (set! children + (map string->number (irregex-split " " line)))) + (close-i/o in out) + children)))) + +(define (interpret script #!optional (args '())) + (process-run "csi" (append `("-s" ,script) args))) + +(define (assert-good-exit*! pid normal code) + (if (not (and normal (= code 0))) + (exit code))) + +(define (assert-good-exit! pid) + (call-with-values (lambda () (process-wait pid)) assert-good-exit*!)) + +(define (assert-exited! pid) + (receive (pid normal code) + (process-wait pid #t) + (when (= pid 0) + (with-output-to-port (current-error-port) + (lambda () + (print "Process did not exit as expected.") + (exit 1)))) + (assert-good-exit*! pid normal code))) + +; scheduler-fdset.scm +(print "=== Test #1") +(let ((pid (interpret "scheduler-fdset.scm"))) + (sleep 1) + (process-signal pid signal/int) + (for-each (lambda (p) (process-signal p signal/int)) (process-children pid)) + (assert-good-exit! pid)) +(print "=== Test #1 passed!") + +; scheduler-fdset-2.scm +(print "=== Test #2") +(let ((pid (interpret "scheduler-fdset-2.scm"))) + (sleep 1) + (process-signal pid signal/int) + (sleep 2) + (assert-exited! pid)) +(print "=== Test #2 passed!") + +; scheduler-fdset-3.scm +(print "=== Test #3") +(receive (in out pid) + (process "csi" '("-s" "scheduler-fdset-3.scm")) + (sleep 1) + (process-signal pid signal/int) + (sleep 1) + (process-signal pid signal/int) + (sleep 1) + (write-line "a" out) + (write-line "b" out) + (write-line "c" out) + (assert (string=? "a" (read-line in))) + (assert (string=? "b" (read-line in))) + (assert (string=? "c" (read-line in))) + (read-line in) + (assert-exited! pid)) +(print "=== Test #3 passed!") + +; scheduler-fdset-4.scm +(print "=== Test #4") +(receive (in out pid) + (process "csi" '("-s" "scheduler-fdset-4.scm")) + (sleep 1) + (process-signal pid signal/int) + (sleep 1) + (write-line "a" out) + (write-line "b" out) + (assert (string=? "a" (read-line in))) + (assert (string=? "b" (read-line in))) + (read-line in) + (assert-exited! pid)) +(print "=== Test #4 passed!") diff --git a/tests/sink.c b/tests/sink.c new file mode 100644 index 0000000..6c1461b --- /dev/null +++ b/tests/sink.c @@ -0,0 +1,14 @@ +#include +#include + +void ignore(int signal) +{ +} + +int main(int argc, char** argv) +{ + signal(SIGINT, ignore); + + char in = getchar(); + return 0; +}