Page MenuHomeFreeBSD

tests: kqueue: add a basic test for CPONFORK
Needs ReviewPublic

Authored by kevans on Thu, Apr 2, 1:26 PM.
Tags
None
Referenced Files
F151018108: D56223.diff
Sun, Apr 5, 11:51 AM
F151018079: D56223.diff
Sun, Apr 5, 11:51 AM
F150923390: D56223.id174838.diff
Sat, Apr 4, 11:45 PM
F150922370: D56223.diff
Sat, Apr 4, 11:37 PM
Unknown Object (File)
Sat, Apr 4, 7:26 PM
Unknown Object (File)
Fri, Apr 3, 6:46 PM
Subscribers

Details

Reviewers
markj
kib
Summary

Just copy over a timer and a write-filter, be sure that we can observe
both in the child. Maybe the timer should check for a minimum time
passed, but I don't know that we'd be likely to get that wrong.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 71972
Build 68855: arc lint + arc unit

Event Timeline

kevans requested review of this revision.Thu, Apr 2, 1:26 PM
tests/sys/kqueue/kqueue_fork.c
112

I would went as far as adding a check that kq is a valid file descriptor in the child. E.g. you could use fcntl(F_KINFO) and check its succeeded and the fd type.

Before the fork support, kqueue fds were automatically closed in children.

117
133

And check the mask in the parent.

kevans marked 3 inline comments as done.

Address review feedback: sanity check the kq fd and push mask checking to parent

Additionally:

  • Switch to EVFILT_VNODE instead of EVFILT_WRITE, because the former is what I really wanted; an event that will always fire is less useful.
  • Actually check kevent() return in the child to be sure that we didn't hit call timeout
tests/sys/kqueue/kqueue_fork.c
123
133

I think err would not quite work in the child. Why not _exit(RECV_ERROR)?

kevans marked 2 inline comments as done.

Review feedback: push .kf_structsize into initializer, err(3) -> _exit(2)

tests/sys/kqueue/kqueue_fork.c
108

No error checking?

137

I think there is a small flaw. Since ts is not updated by kevent(2), any wakeup causes re-arm of the timeout. To be completely proof, you would check the absolute time after recording the received events.

But this is probably overkill.

kevans marked 2 inline comments as done.

Address review feedback, add missing error check

Arm a one-shot timer after the fork for the timeout, instead of using the
kevent() timeout mechanism. The potential delays were considered acceptable,
but we can easily arm a second timer after the fork to provide an absolute
timeout of 4 seconds.

This revision is now accepted and ready to land.Fri, Apr 3, 4:56 AM
markj added inline comments.
tests/sys/kqueue/kqueue_fork.c
168

Why close the kqueue here?

tests/sys/kqueue/kqueue_fork.c
168

I was thinking along the lines of demonstrating that the forked kqueue is completely independent from the parent copy / ensuring that notes are actually copied. It occurs to me that it could be useful to do this but also confirm that we actually see all of the expected events on both queues.

tests/sys/kqueue/kqueue_fork.c
168

That'd be a good extension, yeah. Making sure that forking doesn't somehow "steal" the knotes.

One last round of improvements:

  • Instead of closing kqueue in the parent, confirm that we get all of the events still
  • Also add in an EVFILT_READ with a close-on-fork fd (well, a kqueue) to show that it only goes away in the child
This revision now requires review to proceed.Fri, Apr 3, 7:43 PM

Hmm, The second kqueue might not be as useful as I've thought. It doesn't mean much because the filter needs to resolve the fd first, which will EBADF early.

Hmm, The second kqueue might not be as useful as I've thought. It doesn't mean much because the filter needs to resolve the fd first, which will EBADF early.

Then why playing with EV_DISABLE/EV_ENABLE at all? Add the normal event to the kqueue. After that, if knote is activated, you should get the event in the parent but not in the child. Basically, remove the EV_DISABLE flag, and the call to kqueue to activate in the child.

Fix the close-on-fork fd test: add an EVFILT_USER to the second kqueue and
trigger it, then confirm that the parent sees the read-event while the child
does not. This shouldn't be fragile because the EVFILT_READ will be readable
as of the very first scan in the child, so things would have to go pretty wrong
for it to appear but not beat the 3-second timer to being observed.

tests/sys/kqueue/kqueue_fork.c
167

This comment is no longer true for clofd, I believe.