Displays must not be shared across tet_fork
Submitted by Jamey Sharp
Assigned to Stuart Anderson
The XCloseDisplay purpose #6 (closed), XGrabDisplay, and XUngrabDisplay tests all open an extra connection and then tet_fork off a new process to do stuff with that connection. After forking these tests also manipulate the extra connection from the parent.
Since the Display structure has a lot of state that has to be kept in sync with the server, it isn't reasonable to expect Xlib to deal with having the same Display used in two separate processes. Xlib/XCB has assertions that sanity check the sequence number stream, and that stream is corrupted by this bug in the test suite; the absence of these assertions in the reference implementation of Xlib presumably explains why this bug hasn't been noticed before.
All three tests open these extra displays with the XTS function opendisplay, which queues the Display to be closed at the end of the test. That doesn't work since the XCloseDisplay call is made in the parent after the fork. The minimal fix replaces the opendisplay() call with a call to XOpenDisplay(config.display), which means that XCloseDisplay will not be automatically called. It can't be called from the child in any of these cases, because that would make the child hang until the server is ungrabbed; but of course it can't be called from the parent either. For the XGrabServer and XUngrabServer tests I've chosen to let the connection leak, because there's only one test purpose. For XCloseDisplay, I get the file descriptor from the child's Display, and call close(2) on it in the parent after the child exits. This leaks memory but ensures that all connections to the server are closed at the end of the test, so the server can reset.
In addition, the XCloseDisplay test uses the "client2" connection in both parent and child as part of the test procedure. The minimal fix for this opens a third connection for use by the child, and allows the parent to continue using client2. I discussed this part of the bug with Keith, who recommended this fix.
I have a patch that fixes all three tests.