<div dir="ltr">After your changes the ./dotest.py leaves crashinfo.lock file in test dir. Could you fix it?<div><br></div><div>Thanks,</div><div>Ilia</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 13, 2015 at 8:00 AM, Vince Harron <span dir="ltr"><<a href="mailto:vince@nethacker.com" target="_blank">vince@nethacker.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: vharron<br>
Date: Wed May 13 00:00:23 2015<br>
New Revision: 237230<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=237230&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237230&view=rev</a><br>
Log:<br>
Darwin - fix intermitent crashes in import crashinfo<br>
<br>
Summary:<br>
"import crashinfo" was probably failing because multiple dotest invocations<br>
are all trying to compile crashinfo.so at the same time.<br>
<br>
I've put a mutex around the compile step to prevent this.<br>
<br>
Reviewers: clayborg, chying<br>
<br>
Subscribers: lldb-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D9732" target="_blank">http://reviews.llvm.org/D9732</a><br>
<br>
<br>
Added:<br>
lldb/trunk/test/lock.py<br>
Modified:<br>
lldb/trunk/test/dotest.py<br>
<br>
Modified: lldb/trunk/test/dotest.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=237230&r1=237229&r2=237230&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=237230&r1=237229&r2=237230&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/test/dotest.py (original)<br>
+++ lldb/trunk/test/dotest.py Wed May 13 00:00:23 2015<br>
@@ -23,6 +23,7 @@ for available options.<br>
import commands<br>
import os<br>
import errno<br>
+import lock<br>
import platform<br>
import progress<br>
import signal<br>
@@ -441,11 +442,23 @@ def setupCrashInfoHook():<br>
test_dir = os.environ['LLDB_TEST']<br>
if not test_dir or not os.path.exists(test_dir):<br>
return<br>
+ dylib_lock = os.path.join(test_dir,"crashinfo.lock")<br>
dylib_src = os.path.join(test_dir,"crashinfo.c")<br>
dylib_dst = os.path.join(test_dir,"crashinfo.so")<br>
- cmd = "SDKROOT= xcrun clang %s -o %s -framework Python -Xlinker -dylib -iframework /System/Library/Frameworks/ -Xlinker -F /System/Library/Frameworks/" % (dylib_src,dylib_dst)<br>
- if subprocess.call(cmd,shell=True) == 0 and os.path.exists(dylib_dst):<br>
- setCrashInfoHook = setCrashInfoHook_Mac<br>
+ try:<br>
+ compile_lock = lock.Lock(dylib_lock)<br>
+ compile_lock.acquire()<br>
+ if not os.path.isfile(dylib_dst) or os.path.getmtime(dylib_dst) < os.path.getmtime(dylib_src):<br>
+ # we need to compile<br>
+ cmd = "SDKROOT= xcrun clang %s -o %s -framework Python -Xlinker -dylib -iframework /System/Library/Frameworks/ -Xlinker -F /System/Library/Frameworks/" % (dylib_src,dylib_dst)<br>
+ if subprocess.call(cmd,shell=True) != 0 or not os.path.isfile(dylib_dst):<br>
+ raise Exception('command failed: "{}"'.format(cmd))<br>
+ finally:<br>
+ compile_lock.release()<br>
+ del compile_lock<br>
+<br>
+ setCrashInfoHook = setCrashInfoHook_Mac<br>
+<br>
else:<br>
pass<br>
<br>
<br>
Added: lldb/trunk/test/lock.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lock.py?rev=237230&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lock.py?rev=237230&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/test/lock.py (added)<br>
+++ lldb/trunk/test/lock.py Wed May 13 00:00:23 2015<br>
@@ -0,0 +1,23 @@<br>
+"""<br>
+Interprocess mutex based on file locks<br>
+"""<br>
+<br>
+import fcntl<br>
+import os<br>
+<br>
+class Lock:<br>
+<br>
+ def __init__(self, filename):<br>
+ self.filename = filename<br>
+ # This will create it if it does not exist already<br>
+ self.handle = open(filename, 'w')<br>
+<br>
+ # Bitwise OR fcntl.LOCK_NB if you need a non-blocking lock<br>
+ def acquire(self):<br>
+ fcntl.flock(self.handle, fcntl.LOCK_EX)<br>
+<br>
+ def release(self):<br>
+ fcntl.flock(self.handle, fcntl.LOCK_UN)<br>
+<br>
+ def __del__(self):<br>
+ self.handle.close()<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>