cornell-brg / pymtl

Python-based hardware modeling framework
BSD 3-Clause "New" or "Revised" License
234 stars 83 forks source link

Add file lock to support xdist -n options #155

Open jsn1993 opened 7 years ago

jsn1993 commented 7 years ago

Previously the reason why verilog import with -n option fails is that creating and checking the tmp file is not atomic. It is possible for two threads to create the tmp file at the same time (but only one file) and after one thread deletes the tmp file the other thread cannot find it.

Basically I wrap the code fragment that manipulates files with a fcntl file lock for verilog import and systemc import.

I also add -n option to Travis CI to show the performance difference.

cbatten commented 7 years ago

We probably need to fix the tests that are failing TravisCI before merging this pull request, right? This can probably wait until next week while we get lab1 out.

jsn1993 commented 7 years ago

Interesting, it didn't fail locally. I need to reproduce that failure ...

dmlockhart commented 7 years ago

I think you might want to try pytest fixtures: http://doc.pytest.org/en/latest/fixture.html

They ensure a test suite that has shared resources only creates that resource once at test collection time and then all the tests could use the same generated Verilog. This will be especially helpful for large blocks that take a long time to verilate/compile.

Might be good to try pytest fixtures combined with some checking logic in verilator_sim.py that has better Exception checking if when accessing the file in an unexpected state.