<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Running lit tests under windows can fail due to race conditions"
   href="http://llvm.org/bugs/show_bug.cgi?id=19790">19790</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Running lit tests under windows can fail due to race conditions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Test Suite
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>lit
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dan@su-root.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>daniel@zuster.org, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12540" name="attach_12540" title="Example output from lit under Windows">attachment 12540</a> <a href="attachment.cgi?id=12540&action=edit" title="Example output from lit under Windows">[details]</a></span>
Example output from lit under Windows

OS: Windows 8.1
Python: Python 3.4

It seems that when running with the default ``--use-threads`` under Windows 8
with multiple threads tests can randomly fail. Which looks like a race
condition.

What it looks like is happening is that commands in the test are being executed
on files before those files are closed.

Steps to reproduce

Here is a randomly generated test suite that uses lit and which appears on
Windows to randomly fail (the number of tests and which tests fail is not
consistent) when using --use-threads and thread count is greater than 1.

<span class="quote">> git clone <a href="https://github.com/delcypher/lit-concurrency-windows-bug.git">https://github.com/delcypher/lit-concurrency-windows-bug.git</a>
> cd lit-concurrency-windows-bug
> lit --use-threads -vs .</span >

The tests have the following format

# RUN: python %s > %t
# RUN: %diff %s.expect %t

``%s.expect`` is a text file containing the expected output of running the
first command.

When I run I randomly see messages like this...
```
Command 1: "fc" "/W"
"C:\Users\Daniel\Desktop\lit-windows-concurrency-bug\testdi
r-1\test-11.py.expect"
"C:\Users\Daniel\Desktop\lit-windows-concurrency-bug\test
dir-1\Output\test-11.py.tmp"
Command 1 Result: 1
Command 1 Output:
Comparing files
C:\USERS\DANIEL\DESKTOP\LIT-WINDOWS-CONCURRENCY-BUG\TESTDIR-1\te
st-11.py.expect and
C:\USERS\DANIEL\DESKTOP\LIT-WINDOWS-CONCURRENCY-BUG\TESTDIR-
1\OUTPUT\TEST-11.PY.TMP
Resync Failed.  Files are too different.
*****
C:\USERS\DANIEL\DESKTOP\LIT-WINDOWS-CONCURRENCY-BUG\TESTDIR-1\test-11.py.e
xpect
FOO 0x44dcda6a797d76de
FOO 0x598b88dbaa99e079
FOO 0x61b339ff248174e5
FOO 0x7b87a9e25fefe911
...
...
FOO 0x4bca2f3e6eb5568b
FOO 0x258dc101eb3a8082
*****
C:\USERS\DANIEL\DESKTOP\LIT-WINDOWS-CONCURRENCY-BUG\TESTDIR-1\OUTPUT\TEST-
11.PY.TMP
*****



Command 1 Stderr:



--

********************
```

The output shown above (truncated) from the ``fc`` tool (the Windows version of
the diff tool) seems to suggest that the temporary file created by the first
command in the tests (%t) is empty when ``fc`` was executed which suggests to
me that the temporary file isn't closed properly before executing the next
command.

It appears if I use the ``--use-processes`` flag instead then these random test
failures do not occur. Attached is an example of the output seen when executing
under Windows.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>