lwt icon indicating copy to clipboard operation
lwt copied to clipboard

Test the Unix binding

Open aantron opened this issue 7 years ago • 4 comments

NOTE: this will be much easier to work on after mirage/alcotest#177 and #701.

This is a big issue for lots of PRs. Some parts of it could be quite easy, but on the whole I'd say it is of medium difficulty.

Some care should be taken to run the tests properly sandboxed, i.e. files created in temporary directories, etc. For that, the test framework in test/test.ml will probably have to be extended with new helper functions. I'm not sure how to sandbox DNS and some of the other APIs. We should probably discuss that.

Besides correct behavior, we need really thorough tests for various error conditions. The typical system call has man pages on multiple systems, listing the various ways the system call can fail. We want to trigger as many of those as possible. See section Help below for links to man pages.


The work

To make this manageable, I would break the work into chunks, based on the current order of functions in the various .mli files of the Unix binding. These aren't listed necessarily in the order they should be tested in. We generally want simple and obvious things tested first, and more complex things that depend on them tested later.

There are a few tests already written, but I included all the functions in the category list, so make sure to check before choosing a category. I'll try to keep the check boxes up to date.

If you'd like to work on one of these items, please leave a comment, to avoid duplication of effort :)

I've left Lwt_io for a separate issue.


Help

Cheating off Unix

Some of the easiest ways to test some bindings would be to do something with Lwt_unix (or other Lwt module), and check the result using stdlib's Unix.

man pages

Here are some man page references:

  • Linux
  • ~~Mac~~ It seems Apple has archived their man pages and made them difficult to discover, so you have to do a web search for each system call.
  • BSD
  • For Windows, it's probably best to look at what Win32 API Lwt actually calls in src/unix/windows_c/*, and then look the API up in MSDN. A search is probably the easiest way.

Skipping tests

Many Lwt APIs aren't implemented on Windows. Tests for them can be skipped like this:

https://github.com/ocsigen/lwt/blob/4f0dabca5228b36a65ea7e49375a15d2070161fa/test/unix/test_lwt_process.ml#L27

Coverage analysis

Coverage analysis is enabled for the OCaml code of the Unix binding – run make coverage, then open _coverage/index.html. This can help to see what still needs testing, though some of the code is visited unintentionally because other code depends on it. We don't have coverage analysis for C code at the moment. That could be its own PR, but maybe it's not necessary.

Of course, high coverage doesn't imply thorough testing. Only low coverage implies insufficient testing.


cc @cedlemo

aantron avatar Jan 15 '18 17:01 aantron

@aantron I will work on Bigstrings.

cedlemo avatar May 05 '18 17:05 cedlemo

Now I will work on "sleeping and timeout".

cedlemo avatar Oct 13 '18 14:10 cedlemo

I continue with Lwt_throttle.

cedlemo avatar Oct 22 '18 20:10 cedlemo

@aantron i've added some tests for unix Users (#673 )

anuragsoni avatar Mar 15 '19 02:03 anuragsoni