Page MenuHomeFreeBSD

closefrom_test: Convert to atf-c(3)
ClosedPublic

Authored by jhb on Sep 30 2025, 3:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 31, 8:23 AM
Unknown Object (File)
Fri, Oct 31, 8:22 AM
Unknown Object (File)
Thu, Oct 30, 2:11 PM
Unknown Object (File)
Mon, Oct 27, 12:12 AM
Unknown Object (File)
Sun, Oct 26, 10:49 PM
Unknown Object (File)
Sun, Oct 26, 10:41 PM
Unknown Object (File)
Sun, Oct 26, 10:31 PM
Unknown Object (File)
Sun, Oct 26, 5:23 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This seems ok to me. We are making some assumptions about the execution environment though; it might be good to somehow guarantee that there are no holes in the fd space when an ATF test starts.

tests/sys/file/closefrom_test.c
136

I'm not really sure why this assertion must be true when the test is running in under a framework it doesn't control.

This test also assumes that all fds up to 2 are open.

This revision is now accepted and ready to land.Oct 1 2025, 11:00 AM

I'll resume looking at this later. Need to get into the right mindset to make sure the conversion looks good.
Just some minor comments while here...

tests/sys/file/closefrom_test.c
94

__printflike(3, 4) could be added here too.

112–113
tests/sys/file/closefrom_test.c
136

Yeah. That doesn't seem terribly wise... seems better to get the highest fd to start with, then work off that.

tests/sys/file/closefrom_test.c
82

Here's a place we assume stderr is valid btw. Same in ptrace_test.

94

Hmm, I copied this over from ptrace_test and it should probably be fixed there I guess.

136

It is getting the highest fd before opening anything and working off of that. C and POSIX basically require 0/1/2 to be stdin/out/err and be open. That doesn't seem an unreasonable requirement that we are running in a valid POSIX environment?

tests/sys/file/closefrom_test.c
139

Mark points out that this is probably the more interesting assumption as this is assuming that any extra file descriptors opened by the testing framework are "dense". This is probably true normally as you have to go out of your way a bit to get non-dense fds due to POSIX's requirements.

I have tested this both standalone as well as under kyua test FWIW.

tests/sys/file/closefrom_test.c
193–195
196

Should this be _exit(..)?

213–217
220–224
229–230
294–295
296–326

Possibly the child processes should all use _exit(), yes.

tests/sys/file/closefrom_test.c
213–217

Shouldn't the strings be the empty strings? But also, I think this means I can perhaps avoid using CHILD_REQUIRE and just use ATF_REQUIRE directly in child processes?

This revision now requires review to proceed.Fri, Oct 24, 3:31 PM
jhb marked an inline comment as done.Fri, Oct 24, 3:36 PM
jhb added inline comments.
tests/sys/file/closefrom_test.c
68–70

I stopped using stderr here as when I inserted an intentionally false CHILD_REQUIRE I didn't actually get stderr output as closefrom() had closed stderr, so I ended up going back to using simple IPC via a shared page allocated before fork() to pass errors back to the parent. This does report errors nicely if a child requirement fails.

196

I believe that atf_utils_fork() flushes streams (certainly stdout and stderr) internally, so using exit() should be fine.

This revision is now accepted and ready to land.Sat, Oct 25, 11:51 PM
This revision was automatically updated to reflect the committed changes.