This is an archive of the discontinued LLVM Phabricator instance.

[TSan][libdispatch] Add RunLoop helper to ease porting tests
AbandonedPublic

Authored by yln on Apr 5 2019, 11:24 AM.

Details

Summary

Many existing libdispatch tests use CFRunLoop{Run,Stop} to setup the
test harness. Unfortunately, libdispatch only offers dispatch_main
which has no built-in functionality for stopping the run loop.

To emulate the Foundation behavior we schedule an "exit block" to the
main queue that exists when a flag is set. If the flag hasn't been set
yet, the block resubmits itself to to the queue.

I included one adapted example test to show how this would be used.
Let me know if you think this is a good approach and if it sufficiently retains
the original test semantics.

Event Timeline

yln created this revision.Apr 5 2019, 11:24 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 5 2019, 11:24 AM
Herald added subscribers: llvm-commits, Restricted Project, kubamracek. · View Herald Transcript
yln edited the summary of this revision. (Show Details)Apr 5 2019, 11:26 AM
yln added reviewers: kubamracek, dcoughlin, delcypher.

See the inline notes. Is there no better approach?

compiler-rt/test/tsan/Darwin/gcd-blocks.mm
27

Can we keep the print in main?

compiler-rt/test/tsan/Darwin/runloop.h
22

Can we somehow exit() from by returning from main instead? That would be much cleaner.

24

This keeps burning the CPU until we exit.

yln marked 3 inline comments as done.Apr 5 2019, 12:59 PM
yln added inline comments.
compiler-rt/test/tsan/Darwin/gcd-blocks.mm
27

We could pass a block that expresses "the rest of the program".

RunLoopRun(^{
  fprintf(stderr, "Done.\n");
});

I looked at all usages of CFRunLoopRun and that's what the block would ever be used for. I agree that having a CHECK: Done. line that has no obvious source in the test is ugly, but in this case I would prefer it over the block alternative.
We could also make the check lines more explicit, e.g., CHECK: RunLoopShutdown.

compiler-rt/test/tsan/Darwin/runloop.h
22

I don't know how to do this. The main crux here is that dispatch_main never returns, and doesn't provide a built-in means to stop the run loop. Do you have a suggestion?

24

Yes, we could introduce a short sleep for cases where we are waiting on something (i.e., a timer).

yln abandoned this revision.Apr 5 2019, 5:03 PM