def setUp(self): HelperMixin.setUp(self) self.srcdir = os.path.join(self.test_dir, 'src') os.mkdir(self.srcdir) self.objdir = os.path.join(self.test_dir, 'obj') os.mkdir(self.objdir) self.manifest = InstallManifest() self.canonical_mapping = {} for s in ['src1', 'src2']: srcfile = realpath(os.path.join(self.srcdir, s)) objfile = realpath(os.path.join(self.objdir, s)) self.canonical_mapping[objfile] = srcfile self.manifest.add_copy(srcfile, s) self.manifest_file = os.path.join(self.test_dir, 'install-manifest') self.manifest.write(self.manifest_file)
def test_realpath(self): # self.test_dir is going to be 8.3 paths... junk = os.path.join(self.test_dir, "x") with open(junk, "w") as o: o.write("x") fixed_dir = os.path.dirname(realpath(junk)) files = [ "one\\two.c", "three\\Four.d", "Five\\Six.e", "seven\\Eight\\nine.F", ] for rel_path in files: full_path = os.path.normpath(os.path.join(self.test_dir, rel_path)) self.make_dirs(full_path) with open(full_path, "w") as o: o.write("x") fixed_path = realpath(full_path.lower()) fixed_path = os.path.relpath(fixed_path, fixed_dir) self.assertEqual(rel_path, fixed_path)
def test_realpath(self): # self.test_dir is going to be 8.3 paths... junk = os.path.join(self.test_dir, 'x') with open(junk, 'wb') as o: o.write('x') fixed_dir = os.path.dirname(realpath(junk)) files = [ 'one\\two.c', 'three\\Four.d', 'Five\\Six.e', 'seven\\Eight\\nine.F', ] for rel_path in files: full_path = os.path.normpath( os.path.join(self.test_dir, rel_path)) self.make_dirs(full_path) with open(full_path, 'wb') as o: o.write('x') fixed_path = realpath(full_path.lower()) fixed_path = os.path.relpath(fixed_path, fixed_dir) self.assertEqual(rel_path, fixed_path)
def testFileMapping(self, mock_Popen): files = [('a/b', 'mozilla/b'), ('c/d', 'foo/d')] if os.sep != '/': files = [[f.replace('/', os.sep) for f in x] for x in files] file_mapping = {} dumped_files = [] expected_files = [] self.make_dirs(os.path.join(self.objdir, 'x', 'y')) for s, o in files: srcfile = os.path.join(self.srcdir, s) self.make_file(srcfile) expected_files.append(realpath(srcfile)) objfile = os.path.join(self.objdir, o) self.make_file(objfile) file_mapping[realpath(objfile)] = realpath(srcfile) dumped_files.append( os.path.join(self.objdir, 'x', 'y', '..', '..', o)) # mock the dump_syms output file_id = ("X" * 33, 'somefile') def mk_output(files): return iter(['MODULE os x86 %s %s\n' % file_id] + ['FILE %d %s\n' % (i, s) for i, s in enumerate(files)] + ['PUBLIC xyz 123\n']) mock_Popen.return_value.stdout = mk_output(dumped_files) mock_Popen.return_value.wait.return_value = 0 d = symbolstore.Dumper('dump_syms', self.symboldir, file_mapping=file_mapping) f = os.path.join(self.objdir, 'somefile') open(f, 'wb').write('blah') d.Process(f) expected_output = ''.join(mk_output(expected_files)) symbol_file = os.path.join(self.symboldir, file_id[1], file_id[0], file_id[1] + '.sym') self.assertEqual(open(symbol_file, 'r').read(), expected_output)
def testFileMapping(self, mock_Popen): files = [("a/b", "mozilla/b"), ("c/d", "foo/d")] if os.sep != "/": files = [[f.replace("/", os.sep) for f in x] for x in files] file_mapping = {} dumped_files = [] expected_files = [] self.make_dirs(os.path.join(self.objdir, "x", "y")) for s, o in files: srcfile = os.path.join(self.srcdir, s) self.make_file(srcfile) expected_files.append(realpath(srcfile)) objfile = os.path.join(self.objdir, o) self.make_file(objfile) file_mapping[realpath(objfile)] = realpath(srcfile) dumped_files.append( os.path.join(self.objdir, "x", "y", "..", "..", o)) # mock the dump_syms output file_id = ("X" * 33, "somefile") def mk_output(files): return iter(["MODULE os x86 %s %s\n" % file_id] + ["FILE %d %s\n" % (i, s) for i, s in enumerate(files)] + ["PUBLIC xyz 123\n"]) mock_Popen.return_value.stdout = mk_output(dumped_files) mock_Popen.return_value.wait.return_value = 0 d = symbolstore.Dumper("dump_syms", self.symboldir, file_mapping=file_mapping) f = os.path.join(self.objdir, "somefile") open(f, "w").write("blah") d.Process(f) expected_output = "".join(mk_output(expected_files)) symbol_file = os.path.join(self.symboldir, file_id[1], file_id[0], file_id[1] + ".sym") self.assertEqual(open(symbol_file, "r").read(), expected_output)