Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Conversation

@kubkon
Copy link
Member

@kubkon kubkon commented Oct 23, 2019

This commit adds a test case for poll_oneoff syscall. In particular,
it builds on the excellent test use case provided by @dunnock in their
repo poll_oneoff_tests (thanks!), and tests:

  • simple timeout
  • stdin read with timeout
  • fd read and fd write polls

@kubkon kubkon requested a review from sunfishcode October 23, 2019 18:41
@kubkon
Copy link
Member Author

kubkon commented Oct 23, 2019

r? @dunnock

@kubkon
Copy link
Member Author

kubkon commented Oct 24, 2019

BTW, note for the future - it appears subscription_t clock.identifier field seems to be considered deprecated WebAssembly/WASI#125 and it's value is not used anywhere, will try to add comment in your tests source.

Good catch, thanks! It probably makes sense to add comments in this PR as it's a minor change, and I can do it without much hassle. Anyhow, if you have any more comments about this PR, please do let me know and shall fix it ASAP :-)

);
}

unsafe fn test_stdin_read() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parent process closes stdin, it will not be inherited by the child process. As far as I understand, in such case, fd 1 should be closed and poll should return POLLERR.

Even if we don't support closed stdin, this needs a comment at the very least. We could probably try to write to stdin (if an error occurs, the stdin is definitely closed), try polling it (poll should return immediately), read the whole data from stdin, poll again (expecting a timeout)

We could also consider checking if the behavior for stdout and stderr is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is tricky. We don't actually store a raw host fd to the stdin/out/err. It is true though it is possible to remove a WASI fds pointing at the stdin/out/err, it will not close the raw host fds for the process running Wasm.

I'm trying to figure out if a case where a raw host fd to the stdin could be closed for the process running Wasm. Perhaps for now a comment would suffice? @sunfishcode thoughts?

Good idea about testing stdout and stderr. I'll see how difficult it will be to add it to the test case here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shell script executing may have closed the stdin or stdout, for instance. I guess some CIs do it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something that the wasi-misc-tests framework isn't well equipped to handle. There are a variety of things we'd like to test for involving stdin/stdout/stderr, such as what if they're attached to special things like /dev/random, or fifos, or other things, that we can't do from within WASI itself. So while wasi-misc-tests is nice and simple, we may also need support for a test harness like Lucet's, which can set up a custom WasiCtx, run a WASI program with it, and test it from the outside.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's a good point. How about we compromise a little bit here, and for the moment, test the positive route for stdin/out/err (NB I've already added a smoke test for the latter two), and in the future, when we figure out a better test harness, etc., we'll either augment this test case or create an additional one testing for ill conditions such as if the descriptors are attached to special things, fifos, etc.?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds okay, but please add a comment that we're assuming that stdin/stdout/stderr are open during the testsuite and state it in the README too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've now added the comment in the test case.

kubkon and others added 2 commits October 25, 2019 12:45
This commit adds a test case for `poll_oneoff` syscall. In particular,
it builds on the excellent test use case provided by @dunnock in their
repo [poll_oneoff_tests] (thanks!), and tests:
* simple timeout
* stdin read with timeout
* fd read and fd write polls

[poll_oneoff_tests]: https://github.com/dunnock/poll_oneoff_tests
},
},
];
let out = poll_oneoff_impl(&in_, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdout and stderr should be writable, so as far as I understand, poll should return immediately with both fds. Did you run the tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's correct. You were probably looking at the initial draft commit which included by mistake an EVENTTYPE_FD_READ on stdout/err instead of an EVENTTYPE_FD_WRITE. This has now been fixed.

@kubkon kubkon merged commit 39cfd6c into CraneStation:master Oct 27, 2019
@kubkon kubkon deleted the poll_oneoff branch October 27, 2019 20:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants