def test_good_stacktrace(self): """Tests functionality when the stacktrace matches""" self.mock.get_crash_signature.side_effect = [ common.CrashSignature('wrong type', ['incorrect', 'state2']), common.CrashSignature('wrong type', ['incorrect', 'state2']), common.CrashSignature('original_type', ['original', 'state']) ] self.assertTrue(self.reproducer.reproduce_normal(10)) self.assert_exact_calls(self.mock.reproduce_crash, [ mock.call(self.reproducer), mock.call(self.reproducer), mock.call(self.reproducer) ])
def test_different_stacktrace(self): """Tests system exit when the stacktrace doesn't match.""" self.mock.get_crash_signature.return_value = common.CrashSignature( 'wrong type', ['incorrect', 'state2']) with self.assertRaises(error.DifferentStacktraceError): self.reproducer.reproduce_normal(2)
def test_get(self): """Test getting crash signature.""" self.mock.get_crash_signature.return_value = common.CrashSignature('t', []) self.reproducer = create_reproducer(reproducers.LinuxChromeJobReproducer) self.assertEqual(self.mock.get_crash_signature.return_value, self.reproducer.get_crash_signature()) self.mock.get_crash_signature.assert_called_once_with( self.reproducer.testcase.job_type, 'line')
def test_similar(self): """Test similar.""" self.assertTrue( reproducers.is_similar(common.CrashSignature('t', ['a']), common.CrashSignature('z', ['a']))) self.assertTrue( reproducers.is_similar(common.CrashSignature('t', ['a', 'b']), common.CrashSignature('t', ['a', 'c']))) self.assertTrue( reproducers.is_similar(common.CrashSignature('t', ['a']), common.CrashSignature('t', ['a', 'c']))) self.assertTrue( reproducers.is_similar(common.CrashSignature('t', ['a', 'b', 'd']), common.CrashSignature('t', ['a', 'b', 'c']))) self.assertTrue( reproducers.is_similar(common.CrashSignature('t', ['a', 'b']), common.CrashSignature('t', ['a', 'b', 'c'])))
def setUp(self): self.reproducer = create_reproducer(reproducers.LinuxChromeJobReproducer) helpers.patch(self, [ 'clusterfuzz.reproducers.LinuxChromeJobReproducer.reproduce_crash', 'clusterfuzz.reproducers.symbolize', 'clusterfuzz.reproducers.get_crash_signature', 'time.sleep' ]) self.mock.reproduce_crash.return_value = (0, 'stuff') self.mock.symbolize.return_value = 'stuff' self.reproducer.get_crash_signature = lambda: common.CrashSignature( 'original', ['state']) self.reproducer.job_type = 'linux_ubsan_chrome'
def get_crash_signature(job_type, raw_stacktrace): """Get crash signature from raw_stacktrace by asking ClusterFuzz.""" response = common.post(url='https://clusterfuzz.com/parse_stacktrace', data=json.dumps({ 'job': job_type, 'stacktrace': raw_stacktrace })) response = json.loads(response.text) crash_state_lines = tuple( [x for x in response['crash_state'].split('\n') if x]) crash_type = response['crash_type'].replace('\n', ' ') return common.CrashSignature(crash_type, crash_state_lines)
def get_stacktrace_info(self, trace): """Post a stacktrace, return (crash_state, crash_type).""" response = common.post( url=('https://clusterfuzz.com/v2/parse_stacktrace'), data=json.dumps({ 'job': self.job_type, 'stacktrace': trace })) response = json.loads(response.text) crash_state_lines = tuple( [x for x in response['crash_state'].split('\n') if x]) crash_type = response['crash_type'].replace('\n', ' ') return common.CrashSignature(crash_type, crash_state_lines)
def test_get(self): """Test get.""" self.mock.post.return_value = mock.Mock( text=json.dumps({ 'crash_state': 'original\nstate', 'crash_type': 'original_type' })) self.assertEqual( common.CrashSignature('original_type', ['original', 'state']), reproducers.get_crash_signature('job', 'raw_stacktrace')) self.mock.post.assert_called_once_with( url='https://clusterfuzz.com/v2/parse_stacktrace', data=json.dumps({ 'job': 'job', 'stacktrace': 'raw_stacktrace' }))
def test_no_stacktrace(self): """Tests system exit when the stacktrace doesn't match.""" self.mock.get_crash_signature.return_value = common.CrashSignature('', []) with self.assertRaises(error.UnreproducibleError): self.reproducer.reproduce_normal(2)