def testLocalNoBreakpadExtracted(self): # Unmock breakpad extraction function. breakpad_file_extractor.ExtractBreakpadFiles = self.ExtractBreakpadFiles # Set up option arguments to run extract breakpad on local build directory. self.options.breakpad_output_dir = tempfile.mkdtemp() self.options.local_build_dir = tempfile.mkdtemp() trace_file_override = None dump_syms_dir = tempfile.mkdtemp() self.options.dump_syms_path = os.path.join(dump_syms_dir, 'dump_syms') with open(self.options.dump_syms_path, 'w') as _: pass unstripped_dir = os.path.join(self.options.local_build_dir, 'lib.unstripped') exception_msg = ( 'No breakpad symbols could be extracted from files in: %s xor %s' % (self.options.local_build_dir, unstripped_dir)) # Test when there is no 'lib.unstripped' subdirectory. with self.assertRaises(Exception) as e: symbolize_trace.SymbolizeTrace(trace_file_override, self.options) self.assertIn(exception_msg, str(e.exception)) # Test when there is a 'lib.unstripped' subdirectory. os.mkdir(unstripped_dir) with self.assertRaises(Exception): symbolize_trace.SymbolizeTrace(trace_file_override, self.options) # Remove files and temp directory. shutil.rmtree(self.options.local_build_dir) shutil.rmtree(dump_syms_dir) shutil.rmtree(self.options.breakpad_output_dir)
def testInvalidLocalBreakpadDir(self): self.options.local_breakpad_dir = 'fake/directory' exception_msg = 'Local breakpad directory is not valid.' with self.assertRaises(Exception) as e: symbolize_trace.SymbolizeTrace(self.trace_file, self.options) self.assertIn(exception_msg, str(e.exception))
def testValidLocalBuildAndBreakpadDir(self): self.options.local_build_dir = tempfile.mkdtemp() self.options.local_breakpad_dir = tempfile.mkdtemp() symbolize_trace.SymbolizeTrace(self.trace_file, self.options) metadata_extractor.MetadataExtractor.assert_not_called() symbol_fetcher.GetTraceBreakpadSymbols.assert_not_called() breakpad_file_extractor.ExtractBreakpadFiles.assert_not_called() symbolize_trace._RunSymbolizer.assert_called_once() # Check that symbolized trace file was written correctly. self.assertEqual( self.options.output_file, os.path.join( os.path.dirname(self.trace_file), os.path.basename(self.trace_file) + '_symbolized_trace')) with open(self.options.output_file, 'r') as f: symbolized_trace_data = f.read() self.assertEqual(symbolized_trace_data, 'Trace data.Symbol data.') # Remove files and temp directory. os.remove(self.options.output_file) shutil.rmtree(self.options.local_build_dir) shutil.rmtree(self.options.local_breakpad_dir)
def testNoLocalBreakpadDirAndNonEmptyBreakpadOutputDir(self): self.options.breakpad_output_dir = tempfile.mkdtemp() # Check that exception is thrown for non-empty breakpad output directory. exception_msg = 'Breakpad output directory is not empty:' with tempfile.NamedTemporaryFile(dir=self.options.breakpad_output_dir): with self.assertRaises(Exception) as e: symbolize_trace.SymbolizeTrace(self.trace_file, self.options) self.assertIn(exception_msg, str(e.exception)) # Remove files and temp directory. shutil.rmtree(self.options.breakpad_output_dir)
def testNoLocalOrOutputBreakpadDir(self): # Test the case with no breakpad output directory specified. symbolize_trace.SymbolizeTrace(self.trace_file, self.options) metadata_extractor.MetadataExtractor.assert_called_once() symbol_fetcher.GetTraceBreakpadSymbols.assert_called_once() breakpad_file_extractor.ExtractBreakpadFiles.assert_not_called() symbolize_trace._RunSymbolizer.assert_called_once() # Check that symbolized trace file was written correctly. self.assertEqual( self.options.output_file, os.path.join( os.path.dirname(self.trace_file), os.path.basename(self.trace_file) + '_symbolized_trace')) with open(self.options.output_file, 'r') as f: symbolized_trace_data = f.read() self.assertEqual(symbolized_trace_data, 'Trace data.Symbol data.') # Remove files. os.remove(self.options.output_file)