github / libprojfs

Linux projected filesystem library
GNU Lesser General Public License v2.1
93 stars 14 forks source link

Add custom logging and revise tests to avoid races with daemons #76

Closed chrisd8088 closed 5 years ago

chrisd8088 commented 5 years ago

On systems where any new mount point may be probed by active daemons (such as gvfs-udisks2-volume-monitor), our test scripts may not be the first processes to trigger projection on the top-level directory of their test mount points; thus, the t300-args-initial.t test script would fail.

Therefore, in order to reliably test that the --initial mount option is respected, we add a new --log option to capture a record of successful projection requests, and then parse those logs (after ensuring at least one directory projection request occurs) to validate the functionality of the --initial flag.

Having the log file capability in the library allows us to fix a long-standing problem whereby event handler failures in send_event() were logged directly to stderr, which is not really appropriate for a library that will be included into larger applications. However, changing this to output event handler errors into the log file (if any) then breaks the t201-event-err.t test script, as it expects to capture the output that was previously sent to stderr and compare it to a generated set of expected error messages.

Hence, we add support for the --initial and --log options to our common test library, which allows us to continue to use the test_handlers helper program in the t201 script, as well as the test_simple helper program in t300 script, and thus removes the need for a dedicated test_args helper.

Having three potential logs (from stderr, stdout, and the optional log generated by --log) to juggle in our test programs, we revise some of the internal terminology and comments to help clarify which is which.

Finally, we can replace all the calls to fprintf() in our library with a log_printf() which logs to the specified log file (if any) and/or to stderr, according to an enum option specified by the caller and whether a log file exists and is open. This also makes the individual log message format strings more readable, as we can eliminate common elements like the projfs: prefix and trailing newline from each.