Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event and Timeout Tests for select #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Event and Timeout Tests for select #9

wants to merge 1 commit into from

Conversation

zeroem
Copy link

@zeroem zeroem commented Nov 30, 2014

Pretty simple test just to get some coverage of libc-utils/select. Working on figuring out how to generate file system events so I can test the non-timeout behavior.

@zeroem
Copy link
Author

zeroem commented Nov 30, 2014

So, one thing I'm not comfortable about is open/close vs fopen/fclose. Open is lower level and I'm relatively certain I'm not using it correctly. However, when trying to import fopen/fclose, the JVM segfaults. So going to look into that as well.

@zeroem
Copy link
Author

zeroem commented Nov 30, 2014

OK, so the test is just broken in general. open/close return a file descriptor whereas fopen/fclose return a file pointer. the select call is likely segfaulting when I use fopen/fclose because of the filepointer. And the use of open is definitely just plain wrong.

@Chouser
Copy link
Owner

Chouser commented Nov 30, 2014

Thanks for working on this!

Your patch looks about right to me. You're using open/close which return integer file handles, and that's exactly what select expects. The test succeeded for me several times, though I occasionally do get a test fail because select actually detects an event on the "project.clj" file handle.

On the other hand, I had to mess with leiningen project settings a bit to get anything to work. I don't know if it's recent versions of leiningen itself, or Ubuntu, or the JVM or what, but I had to add to project.clj:

:jvm-opts ["-Djna.nosys=true"]
...and in the :dependencies, added: [org.clojure/tools.nrepl "0.2.5"]

Did you have to do any of that?

@zeroem
Copy link
Author

zeroem commented Nov 30, 2014

I had to do the :jvm-opts, but I did it from the command line, I assumed it was something wrong with my environment and not a project level issue. I did not need the additional nrepl dependency.

My problem with the open call is that according to man 2 open, the second argument to open should be bit flags, not the fopen style string indicator. Additionally, the value I'm getting back from the open call is alternating between 0 and -1. Given that the return value is described as:

A call to open() creates a new open file description, an entry in the system-wide table of open files.

and

A file descriptor is a reference to one of these entries;

I have a hard time believing that 0 or -1 is a valid result.

@zeroem zeroem changed the title Simple timeout test for 'select' Event and Timeout Tests for select Dec 3, 2014
@zeroem
Copy link
Author

zeroem commented Dec 3, 2014

Alrighty, figured out why the fopen call was puking and got everything working nicely (I think).

@zeroem
Copy link
Author

zeroem commented Dec 3, 2014

Interestingly, with the tools I added just to do the tests for select, it would be possible to allow it to take strings or File objects instead of just the low level file descriptors making clojure access significantly simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants