Skip to content

Add Windows support to Catch2Tests

Thomas Ives requested to merge catch2-add-win32 into release/10.0.0

Here I am implementing impl_win32.cpp so that the Catch2Tests can run on Windows. There were a couple of tests which didn't work straight away which I have added a commit to get work (in catch2_alarm_event.cpp because I wasn't initialising some bools properly), and there were a couple of test files which don't work and I have just disabled on Windows for now:

  • catch2_filedatabase.cpp: I was getting a segfault inside the "as_any" function, I think there it is inside an Any::Any copy constructor that might be being ellided by gcc, but not msvc. Not sure what is going wrong.
  • catch2_jpeg_decode.cpp: Hitting a NT breakpoint inside free. I think the buffer is allocated by libjpeg so I suspect the memory wasn't allocated by the standard libc allocator or something like this. This might be an issue with how I am building/linking things.

It wasn't immediately obvious to me what the problem was and I didn't want to get bogged down in debugging these. So I have left them for later. If people agree I will create an issue.

In terms on the implementation of the platform layer, some things didn't go to plan:

  1. I wasn't getting any events from FindFirstChangeNotification (which I had thought we could use to know when the redirect file had new data). I believe this is because it only sends events when the data has actually hit the disk, and I suspect these redirect files only ever exist in the FS cache because the tests are so quick. Unfortunately, then I have had to settle with polling the file to wait for the ready string.
  2. On Windows I seem to be able to start two device servers with the same port without a problem. I believe this is because omniORB is setting SO_REUSEADDR on the port which has "different" behaviour on Windows compared to other BSD socket implementations. On Linux SO_REUSEADDR doesn't let you bind to a port if the addresses are exactly the same, but on Windows it does. Microsoft say that all bets are off when this happens and you shouldn't use this feature. There is something called SO_EXCLUSIVEADDRUSE on Windows which I think might do what we want, but I don't think omniORB let's us set this. Maybe we can ask for a fix for this from omniORB, but until then I think we just have to live with not being able to detect this happening. A single Catch2Tests.exe process will never use the same port twice, so I think for now we should just avoid running to tests in parallel on Windows so that we don't get the occasional failure. This is shame because:
  3. The tests are dead slow on Windows. I think most of it is because the TestServer ORB takes forever to stop if a client has connected to it for some reason. At first this was causing the TestServer::wait_for_stop() function to timeout, but I have set the "ORBscanGranularity=1" environment variable which seems to speed things up a bit. However, it still takes my machine much longer to run the tests on Windows rather than Linux (I think, I haven't actually measured).

TODO:

  • Create an issue about reenabling the catch2_filedatabase.cpp and catch2_jpeg_encoding.cpp tests on Windows. #1296
  • Email omniORB mailing list about adding an option so that we can set SO_EXCLUSIVEADDRUSE on Windows, create an issue in cppTango to track it. #1297

This needs !1296 (merged) to be merged first, as I started from there.

Closes #1223 (closed).

Edited by Thomas Ives

Merge request reports