[GHC] #12725: T7037 is broken on Windows
#12725: T7037 is broken on Windows --------------------------------------+--------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Keywords: | Operating System: Windows Architecture: x86_64 (amd64) | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: --------------------------------------+--------------------------------- `T7037` appears to fail on Windows. Namely, `stdout` appears to be empty, whereas the expected output is `"ok"`. I had suspected that the issue was the `execv` call failing but this doesn't seem to be thew case; no code after `execv` is executed. A problem for another day... -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by bgamari): I forgot to mention that stdout is only empty when the test is run via the testsuite driver (e.g. `make test TEST=T7037`). Running `make T3037`directly produces `"ok"` as expected. Presumably there is something funny going on with the testsuite driver's redirection of stdout. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by bgamari): It looks like Phab:D1234 is relevant here. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by bgamari): Unfortunately my naive attempt at a minimal reproduction case failed, {{{#!bash $ cat >test.py <<EOF import subprocess while True: p = subprocess.Popen('./test.exe', stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out,err) = p.communicate() assert p.wait() == 0 assert out == 'hi\r\n' assert err == '' EOF $ cat >test.c <<EOF #include <stdio.h> int main() { printf("hi\n"); return 0; } EOF $ gcc -o test.exe test.c $ python test.py }}} Never seems to fail. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by bgamari): Adapting the above to call the `T7037_main.exe` executable produced by the testsuite also fails to replicate the failure. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"c5c6d80d2129b259809606387d0ca9dbb16dcfc5/ghc" c5c6d80/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="c5c6d80d2129b259809606387d0ca9dbb16dcfc5" testsuite: Mark T7037 as broken on Windows Due to #12725. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by thomie): The version or type (msys2/mingw) of `gcc` seems to have something to do with it. I can reproduce the problem with the following version of `gcc`: {{{ "C:\msys64\opt\ghc\8.0.0.20160421\lib/../mingw/bin/gcc.exe" -v Using built-in specs. COLLECT_GCC=C:\msys64\opt\ghc\8.0.0.20160421\mingw\bin/realgcc.exe COLLECT_LTO_WRAPPER=C:/msys64/opt/ghc/8.0.0.20160421/mingw/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0 /lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-5.2.0/configure --prefix=/mingw64 --with-local- prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header- dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --with- gxx-include-dir=/mingw64/include/c++/5.2.0 --enable-bootstrap --with- arch=x86-64 --with-tune=generic --enable- languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable- static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable- libstdcxx-pch --disable-libstdcxx-debug --enable-version-specific-runtime- libs --disable-isl-version-check --enable-lto --enable-libgomp --disable- multilib --enable-checking=release --disable-rpath --disable- win32-registry --disable-nls --disable-werror --disable-symvers --with- libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project' --with-bugurl=http://sourceforge.net/projects/msys2 --with- gnu-as --with-gnu-ld Thread model: posix gcc version 5.2.0 (Rev3, Built by MSYS2 project) }}} ok.c: {{{ #include <stdio.h> int main() { printf("ok\n"); return 0; } }}} main.c: {{{ #include <unistd.h> int main(int argc, char *argv[]) { char * args[2] = {"ok", NULL}; execv("./ok", args); } }}} test.py: {{{ import subprocess import time stdout='test.out' def test(f): with open(stdout, 'w') as fout: subprocess.call([f], stdout=fout) with open(stdout, 'r') as fin: print('1:', fin.read().strip()) time.sleep(0.1) with open(stdout, 'r') as fin: print('2:', fin.read().strip()) test('./main') }}} run: {{{ $ "C:\msys64\opt\ghc\8.0.0.20160421\lib/../mingw/bin/gcc.exe" -o main main.c $ "C:\msys64\opt\ghc\8.0.0.20160421\lib/../mingw/bin/gcc.exe" -o ok ok.c $ python test.py ('1:', '') # expected: ok ('2:', 'ok') }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Comment (by Phyx-): This is a good testcase and it illustrates the problem nicely. I don't think it's GCC, I think ultimately, it's some emulation layer somewhere. `execv` is emulated somewhere, not by calling Windows's `CreateProcess` but probably some other posix function. I suspect it's somewhere in https://github.com/mirror/newlib-cygwin but that wouldn't explain the mingw version of GCC. If you replace `execv` with `CreateProcess` the example works correctly in all compilers {{{ #include <unistd.h> #include <windows.h> int main(int argc, char *argv[]) { TCHAR * args[2] = {"ok", NULL}; STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); // Start the child process. if (!CreateProcess("ok.exe", // No module name (use command line) args[0], // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi) // Pointer to PROCESS_INFORMATION structure ) { return 1; } // Wait until child process exits. WaitForSingleObject(pi.hProcess, INFINITE); // Close process and thread handles. CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 0; } }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+-------------------------------------- Changes (by RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows ---------------------------------+-------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2684 Wiki Page: | ---------------------------------+-------------------------------------- Changes (by Phyx-): * status: new => patch * differential: => Phab:D2684 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2684 Wiki Page: | Phab:D2759 -------------------------------------+------------------------------------- Changes (by Phyx-): * differential: Phab:D2684 => Phab:D2684 Phab:D2759 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2684 Wiki Page: | Phab:D2759 -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"0ce59be3a2723f814a3e929fd32a44ff4e890a49/ghc" 0ce59be/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="0ce59be3a2723f814a3e929fd32a44ff4e890a49" Fix testsuite threading, timeout, encoding and performance issues on Windows In a land far far away, a project called Cygwin was born. Cygwin used newlib as it's standard C library implementation. But Cygwin wanted to emulate POSIX systems as closely as possible. So it implemented `execv` using the Windows function `spawnve`. Specifically ``` spawnve (_P_OVERLAY, path, argv, cur_environ ()) ``` `_P_OVERLAY` is crucial, as it makes the function behave *sort of* like execv on linux. the child process replaces the original process. With one major difference because of the difference in process models on Windows: the original process signals the caller that it's done. this is why the file is still locked. because it's still running, control was returned because the parent process was destroyed, but the child is still running. I think it's just pure dumb luck, that the older runtimes are slow enough to give the process time to terminate before we tried deleting the file. Which explains why you do have sporadic failures even on older runtimes like 2.5.0, of a test or two (like T7307). So this patch fixes a couple of things. I leverage the existing `timeout.exe` to implement a workaround for this issue. a) The old timeout used to start the process then assign it to the job. This is slightly faulty since child processes are only assigned to a job is their parent were assigned at the time they started. So this was a race condition. I now create the process suspended, assign it to the job and then resume it. Which means all child processes are not running under the same job. b) First things, Is to prevent dangling child processes. I mark the job with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` so when the last process in the job is done, it insures all processes under the job are killed. c) Secondly, I change the way we wait for results. Instead of waiting for the parent process to terminate, I wait for the job itself to terminate. There's a slight subtlety there, we can't wait on the job itself. Instead we have to create an I/O Completion port and wait for signals on it. See https://blogs.msdn.microsoft.com/oldnewthing/20130405-00/?p=4743 This fixes the issues on all runtimes for me and makes T7307 pass consistenly. The threading was also simplified by hiding all the locking in a single semaphore and a completion class. Futhermore some additional error reporting was added. For encoding the testsuite now no longer passes a file handle to the subprocess since on windows, sh.exe seems to acquire a lock on the file that is not released in a timely fashion. I suspect this because cygwin seems to emulate console handles by creating file handles and using those for std handles. So when we give it an existing file handle it just locks the file. I what's happening is that it's not releasing the handle until all shared cygwin processes are dead. Which explains why it worked in single threaded mode. So now instead we pass a pipe and do not interpret the resulting data. Any bytes written to stdin or read out of stdout/stderr are done so in binary mode and we do not interpret the data. The reason for this is that we have encoding tests in GHC which pass invalid utf-8. If we try to handle the data as text then python will throw an exception instead of a test comparison failing. Also I have fixed the ability to override `PYTHON` when calling `make tests`. This now works the same as with `.\validate`. Finally, after cleaning up the locks I was able to make the abort behavior work correctly as I believe it was intended: when you press Ctrl+C and send an interrupt signal, the testsuite finishes the active tests and then gracefully exits showing you a report of the progress it did make. So using Ctrl+C will not just *die* as it did before. These changes lift the restriction on which python version you use (msys/mingw) or which runtime or python 3 or python 2. All combinations should now be supported. Test Plan: PATH=/usr/local/bin:/mingw64/bin:$APPDATA/cabal/bin:$PATH && PYTHON=/usr/bin/python THREADS=9 make test THREADS=9 make test PATH=/usr/local/bin:/mingw64/bin:$APPDATA/cabal/bin:$PATH && PYTHON=/usr/bin/python ./validate --quiet --testsuite-only Reviewers: erikd, RyanGlScott, bgamari, austin Subscribers: jrtc27, mpickering, thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2684 GHC Trac Issues: #12725, #12554, #12661, #12004 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2684 Wiki Page: | Phab:D2759 -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"dd9ba503bd4a2b3851098a7fa69e15682ab1c536/ghc" dd9ba50/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="dd9ba503bd4a2b3851098a7fa69e15682ab1c536" Update test output for Windows Following D2684 these two tests need to be updated: * T7037: timeout.exe now waits until all processes are finished. this makes T7037 reliable. So enabled. * T876: Unknown reason, allocations are much lower than before. Test Plan: ./validate Reviewers: austin, simonmar, bgamari Reviewed By: bgamari Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2759 GHC Trac Issues: #12725, #12004 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12725: T7037 is broken on Windows -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2684 Wiki Page: | Phab:D2759 -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed @@ -3,1 +3,1 @@ - the `execv` call failing but this doesn't seem to be thew case; no code + the `execv` call failing but this doesn't seem to be the case; no code New description: `T7037` appears to fail on Windows. Namely, `stdout` appears to be empty, whereas the expected output is `"ok"`. I had suspected that the issue was the `execv` call failing but this doesn't seem to be the case; no code after `execv` is executed. A problem for another day... -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12725#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC