chibi-scheme/lib/chibi/process-test.sld
Kris Katterjohn 3da3f3cab3 (chibi process): fix process-running? on OpenBSD, NetBSD and DragonFly
tl;dr process-running? would always return #f on OpenBSD and
NetBSD, and in the one-argument case it would always return #t
on DragonFly.

To get the process information from the process table on OpenBSD
and NetBSD, we need to pass 6 level names to sysctl instead of 4.
Passing the wrong number of level names to sysctl has caused it
to always fail, which in turn caused process-running? to always
return #f:

  (process-running? 1)                        =>  #f
  (process-running? (current-process-id))     =>  #f

and so on.

After the above fix, we also need to check the amount of data
actually filled in by sysctl.  It appears that on OpenBSD, NetBSD
and DragonFly, if the requested process doesn't exist then sysctl
will return with a return value of 0 and just not actually fill in
the given structure.  This caused process-running? to return #t
when no process with the given PID existed:

  (process-running? -1)                       =>  #t
  (process-running? <other nonexistent pid>)  =>  #t

and so on.

I have tested on OpenBSD, NetBSD, DragonFly BSD and FreeBSD, and
process-running? now behaves as expected on all of them.
2019-08-30 13:05:32 -05:00

26 lines
1.2 KiB
Scheme

(define-library (chibi process-test)
(export run-tests)
(import (chibi) (chibi process) (only (chibi test) test-begin test test-end))
(begin
(define (run-tests)
(test-begin "processes")
(test #t (process-running? (current-process-id)))
(test #t (process-running? (parent-process-id)))
(test #f (process-running? -1))
(test #f (signal-set-contains? (current-signal-mask) signal/alarm))
(test #t (signal-set? (make-signal-set)))
(test #t (signal-set? (current-signal-mask)))
(test #f (signal-set? #f))
(test #f (signal-set? '(#f)))
(test #f (signal-set-contains? (make-signal-set) signal/interrupt))
(test #t (let ((sset (make-signal-set)))
(signal-set-fill! sset)
(signal-set-contains? sset signal/interrupt)))
(test #t (let ((sset (make-signal-set)))
(signal-set-add! sset signal/interrupt)
(signal-set-contains? sset signal/interrupt)))
(test #f (let ((sset (make-signal-set)))
(signal-set-fill! sset)
(signal-set-delete! sset signal/interrupt)
(signal-set-contains? sset signal/interrupt)))
(test-end))))