| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from common.pipeline_wrapper import pipeline_handlers | 5 from common.pipeline_wrapper import pipeline_handlers |
| 6 from crash.stacktrace import StackFrame | 6 from crash.stacktrace import StackFrame |
| 7 from crash.stacktrace import CallStack | 7 from crash.stacktrace import CallStack |
| 8 from crash.component_classifier import Component | 8 from crash.component_classifier import Component |
| 9 from crash.component_classifier import ComponentClassifier | 9 from crash.component_classifier import ComponentClassifier |
| 10 from crash.results import Result | 10 from crash.suspect import Suspect |
| 11 from crash.test.predator_testcase import PredatorTestCase | 11 from crash.test.predator_testcase import PredatorTestCase |
| 12 from model.crash.crash_config import CrashConfig | 12 from model.crash.crash_config import CrashConfig |
| 13 from libs.gitiles.change_log import ChangeLog | 13 from libs.gitiles.change_log import ChangeLog |
| 14 from libs.gitiles.change_log import FileChangeInfo | 14 from libs.gitiles.change_log import FileChangeInfo |
| 15 | 15 |
| 16 | 16 |
| 17 # N.B., the call to Get() in CrashConfigComponentClassifier.__init__ | 17 # N.B., the call to Get() in CrashConfigComponentClassifier.__init__ |
| 18 # must only be executed from within the testFoo methods of | 18 # must only be executed from within the testFoo methods of |
| 19 # ComponentClassifierTest. That is, we can't just do this once and for all | 19 # ComponentClassifierTest. That is, we can't just do this once and for all |
| 20 # when doing ComponentClassifierTest.__init__, because that'll cause some | 20 # when doing ComponentClassifierTest.__init__, because that'll cause some |
| (...skipping 24 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 frame = StackFrame(0, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [32]) | 46 frame = StackFrame(0, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [32]) |
| 47 self.assertEqual(self.cccc.GetClassFromStackFrame(frame), 'Comp2>Dummy') | 47 self.assertEqual(self.cccc.GetClassFromStackFrame(frame), 'Comp2>Dummy') |
| 48 | 48 |
| 49 frame = StackFrame(0, 'src/', 'no_func', 'comp2.cc', 'src/comp2.cc', [32]) | 49 frame = StackFrame(0, 'src/', 'no_func', 'comp2.cc', 'src/comp2.cc', [32]) |
| 50 self.assertEqual(self.cccc.GetClassFromStackFrame(frame), '') | 50 self.assertEqual(self.cccc.GetClassFromStackFrame(frame), '') |
| 51 | 51 |
| 52 frame = StackFrame(0, 'src/', 'func2', 'a.cc', 'src/a.cc', [6]) | 52 frame = StackFrame(0, 'src/', 'func2', 'a.cc', 'src/a.cc', [6]) |
| 53 self.assertEqual(self.cccc.GetClassFromStackFrame(frame), '') | 53 self.assertEqual(self.cccc.GetClassFromStackFrame(frame), '') |
| 54 | 54 |
| 55 def testGetClassFromResult(self): | 55 def testGetClassFromSuspect(self): |
| 56 result = Result(self.GetDummyChangeLog(), 'src/') | 56 suspect = Suspect(self.GetDummyChangeLog(), 'src/') |
| 57 self.assertEqual(self.cccc.GetClassFromResult(result), '') | 57 self.assertEqual(self.cccc.GetClassFromSuspect(suspect), '') |
| 58 | 58 |
| 59 result.file_to_stack_infos = { | 59 suspect.file_to_stack_infos = { |
| 60 'comp1.cc': [ | 60 'comp1.cc': [ |
| 61 (StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0) | 61 (StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0) |
| 62 ] | 62 ] |
| 63 } | 63 } |
| 64 self.assertEqual(self.cccc.GetClassFromResult(result), 'Comp1>Dummy') | 64 self.assertEqual(self.cccc.GetClassFromSuspect(suspect), 'Comp1>Dummy') |
| 65 | 65 |
| 66 def testClassifyCrashStack(self): | 66 def testClassifyCrashStack(self): |
| 67 crash_stack = CallStack(0, frame_list=[ | 67 crash_stack = CallStack(0, frame_list=[ |
| 68 StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), | 68 StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), |
| 69 StackFrame(1, 'src/', 'ff', 'comp1.cc', 'src/comp1.cc', [21]), | 69 StackFrame(1, 'src/', 'ff', 'comp1.cc', 'src/comp1.cc', [21]), |
| 70 StackFrame(2, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [8])]) | 70 StackFrame(2, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [8])]) |
| 71 | 71 |
| 72 self.assertEqual(self.cccc.Classify([], crash_stack), | 72 self.assertEqual(self.cccc.Classify([], crash_stack), |
| 73 ['Comp1>Dummy', 'Comp2>Dummy']) | 73 ['Comp1>Dummy', 'Comp2>Dummy']) |
| 74 | 74 |
| 75 def testClassifyResults(self): | 75 def testClassifySuspects(self): |
| 76 result = Result(self.GetDummyChangeLog(), 'src/') | 76 suspect = Suspect(self.GetDummyChangeLog(), 'src/') |
| 77 result.file_to_stack_infos = { | 77 suspect.file_to_stack_infos = { |
| 78 'comp1.cc': [ | 78 'comp1.cc': [ |
| 79 (StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0) | 79 (StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0) |
| 80 ] | 80 ] |
| 81 } | 81 } |
| 82 | 82 |
| 83 self.assertEqual(self.cccc.Classify([result], CallStack(0)), | 83 self.assertEqual(self.cccc.Classify([suspect], CallStack(0)), |
| 84 ['Comp1>Dummy']) | 84 ['Comp1>Dummy']) |
| 85 | 85 |
| 86 def testClassifierDoNotHaveConfig(self): | 86 def testClassifierDoNotHaveConfig(self): |
| 87 crash_config = CrashConfig.Get() | 87 crash_config = CrashConfig.Get() |
| 88 crash_config.component_classifier = {} | 88 crash_config.component_classifier = {} |
| 89 # N.B., we must construct a new cccc here, becasue we changed CrashConfig. | 89 # N.B., we must construct a new cccc here, becasue we changed CrashConfig. |
| 90 self.cccc = CrashConfigComponentClassifier() | 90 self.cccc = CrashConfigComponentClassifier() |
| 91 | 91 |
| 92 crash_stack = CallStack(0, frame_list=[ | 92 crash_stack = CallStack(0, frame_list=[ |
| 93 StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), | 93 StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), |
| 94 StackFrame(1, 'src/', 'ff', 'comp1.cc', 'src/comp1.cc', [21]), | 94 StackFrame(1, 'src/', 'ff', 'comp1.cc', 'src/comp1.cc', [21]), |
| 95 StackFrame(2, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [8])]) | 95 StackFrame(2, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [8])]) |
| 96 | 96 |
| 97 result = Result(self.GetDummyChangeLog(), 'src/') | 97 suspect = Suspect(self.GetDummyChangeLog(), 'src/') |
| 98 result.file_to_stack_infos = { | 98 suspect.file_to_stack_infos = { |
| 99 'comp1.cc': [ | 99 'comp1.cc': [ |
| 100 (StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0) | 100 (StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0) |
| 101 ] | 101 ] |
| 102 } | 102 } |
| 103 | 103 |
| 104 self.assertEqual(self.cccc.Classify([result], crash_stack), []) | 104 self.assertEqual(self.cccc.Classify([suspect], crash_stack), []) |
| 105 | 105 |
| 106 def testGetClassFromFileChangeInfo(self): | 106 def testGetClassFromFileChangeInfo(self): |
| 107 self.assertEqual( | 107 self.assertEqual( |
| 108 CrashConfigComponentClassifier().GetClassFromFileChangeInfo( | 108 CrashConfigComponentClassifier().GetClassFromFileChangeInfo( |
| 109 FileChangeInfo.FromDict({'change_type': 'modify', | 109 FileChangeInfo.FromDict({'change_type': 'modify', |
| 110 'old_path': 'src/comp1.cc', | 110 'old_path': 'src/comp1.cc', |
| 111 'new_path': 'src/comp1.cc'})), | 111 'new_path': 'src/comp1.cc'})), |
| 112 'Comp1>Dummy') | 112 'Comp1>Dummy') |
| 113 | 113 |
| 114 def testGetClassFromFileChangeInfoOldPath(self): | 114 def testGetClassFromFileChangeInfoOldPath(self): |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 ], | 205 ], |
| 206 'message': 'blabla...', | 206 'message': 'blabla...', |
| 207 'commit_url': | 207 'commit_url': |
| 208 'https://chromium.googlesource.com/chromium/src/+/git_hash', | 208 'https://chromium.googlesource.com/chromium/src/+/git_hash', |
| 209 'code_review_url': 'https://codereview.chromium.org/2222', | 209 'code_review_url': 'https://codereview.chromium.org/2222', |
| 210 'reverted_revision': '8d4a4fa6s18raf3re12tg6r'}) | 210 'reverted_revision': '8d4a4fa6s18raf3re12tg6r'}) |
| 211 self.assertEqual( | 211 self.assertEqual( |
| 212 CrashConfigComponentClassifier().ClassifyChangeLog(change_log), | 212 CrashConfigComponentClassifier().ClassifyChangeLog(change_log), |
| 213 []) | 213 []) |
| OLD | NEW |