def merge_file_buffer(self): """Merge all files in this worker's buffer and clear them. This method makes a copy of the working merge progress, then calls llvm-cov merge with up to 10 filenames, plus the current in-progress merge. """ if not self.filename_buffer: self.report("no files to merge...") return if os.path.exists(self.profdata_path): os.rename(self.profdata_path, self.profdata_tmp_path) self.filename_buffer.append(self.profdata_tmp_path) cleaned_files = [pipes.quote(f) for f in self.filename_buffer] llvm_cmd = [LLVM_PROFDATA_PATH, "merge", "-o", self.profdata_path] if LLVM_PROFDATA_SUPPORTS_SPARSE: llvm_cmd.append("-sparse") llvm_cmd += cleaned_files self.report(llvm_cmd) try: shell.call(llvm_cmd, echo=False) except SystemExit as e: self.report("llvm profdata command failed: %s" % e, level=logging.ERROR) if self.config.remove_files: for f in self.filename_buffer: if os.path.exists(f): os.remove(f) self.filename_buffer = []
def test_dry_run(self): shell.dry_run = True basedir = os.getcwd() foobar_dir = os.path.join(self.tmpdir, 'foo', 'bar') shell.makedirs(foobar_dir) self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'foo'))) self.assertFalse(os.path.exists(foobar_dir)) with shell.pushd(foobar_dir): self.assertEqual(os.getcwd(), basedir) shell.call(['touch', 'testfile']) self.assertFalse( os.path.exists(os.path.join(foobar_dir, 'testfile'))) self.assertEqual(os.getcwd(), basedir) shell.rmtree(self.tmpdir) self.assertTrue(os.path.exists(self.tmpdir)) self.assertEqual( self.stdout.getvalue(), '''\ + mkdir -p {foobar_dir} + pushd {foobar_dir} + touch testfile + popd + rm -rf {tmpdir} '''.format(foobar_dir=foobar_dir, tmpdir=self.tmpdir)) self.assertEqual(self.stderr.getvalue(), "") self.dry_run = False
def test_dry_run(self): shell.dry_run = True basedir = os.getcwd() foobar_dir = os.path.join(self.tmpdir, "foo", "bar") shell.makedirs(foobar_dir) self.assertFalse(os.path.exists(os.path.join(self.tmpdir, "foo"))) self.assertFalse(os.path.exists(foobar_dir)) with shell.pushd(foobar_dir): self.assertEqual(os.getcwd(), basedir) shell.call(["touch", "testfile"]) self.assertFalse(os.path.exists(os.path.join(foobar_dir, "testfile"))) self.assertEqual(os.getcwd(), basedir) shell.rmtree(self.tmpdir) self.assertTrue(os.path.exists(self.tmpdir)) self.assertEqual( self.stdout.getvalue(), """\ + mkdir -p {foobar_dir} + pushd {foobar_dir} + touch testfile + popd + rm -rf {tmpdir} """.format( foobar_dir=foobar_dir, tmpdir=self.tmpdir ), ) self.assertEqual(self.stderr.getvalue(), "") self.dry_run = False
def test_dry_run(self): shell.dry_run = True basedir = os.getcwd() foobar_dir = os.path.join(self.tmpdir, 'foo', 'bar') shell.makedirs(foobar_dir) self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'foo'))) self.assertFalse(os.path.exists(foobar_dir)) with shell.pushd(foobar_dir): self.assertEqual(os.getcwd(), basedir) shell.call(['touch', 'testfile']) self.assertFalse(os.path.exists( os.path.join(foobar_dir, 'testfile'))) self.assertEqual(os.getcwd(), basedir) shell.rmtree(self.tmpdir) self.assertTrue(os.path.exists(self.tmpdir)) self.assertEqual(self.stdout.getvalue(), '''\ + mkdir -p {foobar_dir} + pushd {foobar_dir} + touch testfile + popd + rm -rf {tmpdir} '''.format(foobar_dir=foobar_dir, tmpdir=self.tmpdir)) self.assertEqual(self.stderr.getvalue(), "") self.dry_run = False
def merge_file_buffer(self): """Merge all files in this worker's buffer and clear them. This method makes a copy of the working merge progress, then calls llvm-cov merge with up to 10 filenames, plus the current in-progress merge. """ if not self.filename_buffer: self.report("no files to merge...") return if os.path.exists(self.profdata_path): os.rename(self.profdata_path, self.profdata_tmp_path) self.filename_buffer.append(self.profdata_tmp_path) cleaned_files = [pipes.quote(f) for f in self.filename_buffer] llvm_cmd = [LLVM_PROFDATA_PATH, "merge", "-o", self.profdata_path] if LLVM_PROFDATA_SUPPORTS_SPARSE: llvm_cmd.append("-sparse") llvm_cmd += cleaned_files self.report(llvm_cmd) ret = shell.call(llvm_cmd, echo=False) if ret != 0: self.report("llvm profdata command failed -- Exited with code %d" % ret, level=logging.ERROR) if self.config.remove_files: for f in self.filename_buffer: if os.path.exists(f): os.remove(f) self.filename_buffer = []
def test_call(self): shell.dry_run = False foo_file = os.path.join(self.tmpdir, 'foo.txt') bar_file = os.path.join(self.tmpdir, 'bar.txt') with open(foo_file, 'w') as f: f.write("Hello Swift") shell.call(['cp', foo_file, bar_file]) with open(bar_file, 'r') as f: self.assertEqual(f.read(), "Hello Swift") self.assertEqual(self.stdout.getvalue(), "") self.assertEqual(self.stderr.getvalue(), '''\ + cp {foo_file} {bar_file} '''.format(foo_file=foo_file, bar_file=bar_file))
def test_call(self): shell.dry_run = False foo_file = os.path.join(self.tmpdir, 'foo.txt') bar_file = os.path.join(self.tmpdir, 'bar.txt') with open(foo_file, 'w') as f: f.write("Hello Swift") shell.call(['cp', foo_file, bar_file]) with open(bar_file, 'r') as f: self.assertEqual(f.read(), "Hello Swift") self.assertEqual(self.stdout.getvalue(), "") self.assertEqual( self.stderr.getvalue(), '''\ + cp {foo_file} {bar_file} '''.format(foo_file=foo_file, bar_file=bar_file))
def test_call(self): shell.dry_run = False foo_file = os.path.join(self.tmpdir, "foo.txt") bar_file = os.path.join(self.tmpdir, "bar.txt") with open(foo_file, "w") as f: f.write("Hello Swift") shell.call(["cp", foo_file, bar_file]) with open(bar_file, "r") as f: self.assertEqual(f.read(), "Hello Swift") self.assertEqual(self.stdout.getvalue(), "") self.assertEqual( self.stderr.getvalue(), """\ + cp {foo_file} {bar_file} """.format( foo_file=foo_file, bar_file=bar_file ), )
def merge_file_buffer(self): """Merge all files in this worker's buffer and clear them. This method makes a copy of the working merge progress, then calls llvm-cov merge with up to 10 filenames, plus the current in-progress merge. """ if not self.filename_buffer: self.report("no files to merge...") return if os.path.exists(self.profdata_path): os.rename(self.profdata_path, self.profdata_tmp_path) self.filename_buffer.append(self.profdata_tmp_path) cleaned_files = [pipes.quote(f) for f in self.filename_buffer] llvm_cmd = [LLVM_PROFDATA_PATH, "merge", "-o", self.profdata_path] if LLVM_PROFDATA_SUPPORTS_SPARSE: llvm_cmd.append("-sparse") llvm_cmd += cleaned_files self.report(llvm_cmd) try: start = time.time() shell.call(llvm_cmd, echo=False) end = time.time() self.report("elapsed time for llvm-profdata: %s" % timedelta(seconds=(end - start))) except SystemExit as e: self.report("llvm profdata command failed: %s" % e, level=logging.ERROR) if self.config.remove_files: for f in self.filename_buffer: if os.path.exists(f): self.report("removing '%s'" % f) os.remove(f) else: self.report("not removing '%s' because it does not exist" % f) else: self.report("not removing %d files because --no-remove is set" % len(self.filename_buffer)) self.filename_buffer = []
def merge_file_buffer(self): """Merge all files in this worker's buffer and clear them. This method makes a copy of the working merge progress, then calls llvm-cov merge with up to 10 filenames, plus the current in-progress merge. """ if not self.filename_buffer: self.report("no files to merge...") return if os.path.exists(self.profdata_path): os.rename(self.profdata_path, self.profdata_tmp_path) self.filename_buffer.append(self.profdata_tmp_path) cleaned_files = [pipes.quote(f) for f in self.filename_buffer] llvm_cmd = [LLVM_PROFDATA_PATH, "merge", "-o", self.profdata_path] if LLVM_PROFDATA_SUPPORTS_SPARSE: llvm_cmd.append("-sparse") llvm_cmd += cleaned_files self.report(llvm_cmd) try: start = time.time() shell.call(llvm_cmd, echo=False) end = time.time() self.report("elapsed time for llvm-profdata: %s" % timedelta(seconds=(end-start))) except SystemExit as e: self.report("llvm profdata command failed: %s" % e, level=logging.ERROR) if self.config.remove_files: for f in self.filename_buffer: if os.path.exists(f): self.report("removing '%s'" % f) os.remove(f) else: self.report("not removing '%s' because it does not exist" % f) else: self.report("not removing %d files because --no-remove is set" % len(self.filename_buffer)) self.filename_buffer = []