Bug 903606 - Use mozfile.TemporaryDirectory in cppunittest scripts;r=ted
--- a/testing/remotecppunittests.py
+++ b/testing/remotecppunittests.py
@@ -127,17 +127,17 @@ class RemoteCPPUnitTests(cppunittests.CP
"""
basename = os.path.basename(prog)
remote_bin = posixpath.join(self.remote_bin_dir, basename)
log.info("Running test %s", basename)
buf = StringIO.StringIO()
returncode = self.device.shell([remote_bin], buf, env=env, cwd=self.remote_home_dir,
timeout=cppunittests.CPPUnitTests.TEST_PROC_TIMEOUT)
print >> sys.stdout, buf.getvalue()
- with cppunittests.TemporaryDirectory() as tempdir:
+ with mozfile.TemporaryDirectory() as tempdir:
self.device.getDirectory(self.remote_home_dir, tempdir)
if mozcrash.check_for_crashes(tempdir, symbols_path,
test_name=basename):
log.testFail("%s | test crashed", basename)
return False
result = returncode == 0
if not result:
log.testFail("%s | test failed with return code %s",
--- a/testing/runcppunittests.py
+++ b/testing/runcppunittests.py
@@ -2,27 +2,21 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import with_statement
import sys, os, tempfile, shutil
from optparse import OptionParser
-import mozprocess, mozinfo, mozlog, mozcrash
+import mozprocess, mozinfo, mozlog, mozcrash, mozfile
from contextlib import contextmanager
log = mozlog.getLogger('cppunittests')
-@contextmanager
-def TemporaryDirectory():
- tempdir = tempfile.mkdtemp()
- yield tempdir
- shutil.rmtree(tempdir)
-
class CPPUnitTests(object):
# Time (seconds) to wait for test process to complete
TEST_PROC_TIMEOUT = 1200
# Time (seconds) in which process will be killed if it produces no output.
TEST_PROC_NO_OUTPUT_TIMEOUT = 300
def run_one_test(self, prog, env, symbols_path=None):
"""
@@ -33,17 +27,17 @@ class CPPUnitTests(object):
* env: The environment to use for running the program.
* symbols_path: A path to a directory containing Breakpad-formatted
symbol files for producing stack traces on crash.
Return True if the program exits with a zero status, False otherwise.
"""
basename = os.path.basename(prog)
log.info("Running test %s", basename)
- with TemporaryDirectory() as tempdir:
+ with mozfile.TemporaryDirectory() as tempdir:
proc = mozprocess.ProcessHandler([prog],
cwd=tempdir,
env=env)
#TODO: After bug 811320 is fixed, don't let .run() kill the process,
# instead use a timeout in .wait() and then kill to get a stack.
proc.run(timeout=CPPUnitTests.TEST_PROC_TIMEOUT,
outputTimeout=CPPUnitTests.TEST_PROC_NO_OUTPUT_TIMEOUT)
proc.wait()