| OLD | NEW | 
|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import unittest | 5 import unittest | 
| 6 | 6 | 
| 7 from common.diff import ChangeType | 7 from common.diff import ChangeType | 
| 8 from waterfall import build_failure_analysis | 8 from waterfall import build_failure_analysis | 
| 9 from waterfall.failure_signal import FailureSignal | 9 from waterfall.failure_signal import FailureSignal | 
| 10 | 10 | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 106             }, | 106             }, | 
| 107             { | 107             { | 
| 108                 'change_type': ChangeType.RENAME, | 108                 'change_type': ChangeType.RENAME, | 
| 109                 'old_path': 't/y/x.cc', | 109                 'old_path': 't/y/x.cc', | 
| 110                 'new_path': 's/z/x.cc' | 110                 'new_path': 's/z/x.cc' | 
| 111             }, | 111             }, | 
| 112         ] | 112         ] | 
| 113     } | 113     } | 
| 114 | 114 | 
| 115     justification = build_failure_analysis._CheckFiles( | 115     justification = build_failure_analysis._CheckFiles( | 
| 116         FailureSignal.FromDict(failure_signal_json), change_log_json) | 116         FailureSignal.FromDict(failure_signal_json), change_log_json, {}) | 
| 117     self.assertIsNotNone(justification) | 117     self.assertIsNotNone(justification) | 
| 118     # The score is 14 because: | 118     # The score is 14 because: | 
| 119     # +5 added a/b/f1.cc (same file src/a/b/f1.cc in failure_signal log) | 119     # +5 added a/b/f1.cc (same file src/a/b/f1.cc in failure_signal log) | 
| 120     # +1 added d/e/a2.cc (related file a2_test.cc in failure_signal log) | 120     # +1 added d/e/a2.cc (related file a2_test.cc in failure_signal log) | 
| 121     # +1 modified b/c/f2.h (related file a/b/c/f2.cc in failure_signal log) | 121     # +1 modified b/c/f2.h (related file a/b/c/f2.cc in failure_signal log) | 
| 122     # +2 modified d/e/f3.h (same file d/e/f3.h in failure_signal log) | 122     # +2 modified d/e/f3.h (same file d/e/f3.h in failure_signal log) | 
| 123     # +5 deleted x/y/f4.py (same file x/y/f4.py in failure_signal log) | 123     # +5 deleted x/y/f4.py (same file x/y/f4.py in failure_signal log) | 
| 124     # +1 deleted h/f5.h (related file f5_impl.cc in failure_signal log) | 124     # +1 deleted h/f5.h (related file f5_impl.cc in failure_signal log) | 
| 125     # +0 renamed t/y/x.cc -> s/z/x.cc (no related file in failure_signal log) | 125     # +0 renamed t/y/x.cc -> s/z/x.cc (no related file in failure_signal log) | 
| 126     self.assertEqual(15, justification['score']) | 126     self.assertEqual(15, justification['score']) | 
| 127 | 127 | 
| 128   def testCheckFilesAgainstUnrelatedCL(self): | 128   def testCheckFilesAgainstUnrelatedCL(self): | 
| 129     failure_signal_json = { | 129     failure_signal_json = { | 
| 130         'files': { | 130         'files': { | 
| 131             'src/a/b/f.cc': [], | 131             'src/a/b/f.cc': [], | 
| 132         } | 132         } | 
| 133     } | 133     } | 
| 134     change_log_json = { | 134     change_log_json = { | 
| 135         'touched_files': [ | 135         'touched_files': [ | 
| 136             { | 136             { | 
| 137                 'change_type': ChangeType.ADD, | 137                 'change_type': ChangeType.ADD, | 
| 138                 'old_path': '/dev/null', | 138                 'old_path': '/dev/null', | 
| 139                 'new_path': 'a/d/f1.cc' | 139                 'new_path': 'a/d/f1.cc' | 
| 140             }, | 140             }, | 
| 141         ] | 141         ] | 
| 142     } | 142     } | 
| 143 | 143 | 
| 144     justification = build_failure_analysis._CheckFiles( | 144     justification = build_failure_analysis._CheckFiles( | 
| 145         FailureSignal.FromDict(failure_signal_json), change_log_json) | 145         FailureSignal.FromDict(failure_signal_json), change_log_json, {}) | 
| 146     self.assertIsNone(justification) | 146     self.assertIsNone(justification) | 
| 147 | 147 | 
| 148   def testAnalyzeSuccessfulBuild(self): | 148   def testAnalyzeSuccessfulBuild(self): | 
| 149     failure_info = { | 149     failure_info = { | 
| 150         'failed': False, | 150         'failed': False, | 
| 151     } | 151     } | 
| 152     result = build_failure_analysis.AnalyzeBuildFailure( | 152     result = build_failure_analysis.AnalyzeBuildFailure( | 
| 153         failure_info, None, None) | 153         failure_info, None, None, None) | 
| 154     self.assertEqual(0, len(result['failures'])) | 154     self.assertEqual(0, len(result['failures'])) | 
| 155 | 155 | 
| 156   def testAnalyzeBuildFailure(self): | 156   def testAnalyzeBuildFailure(self): | 
| 157     failure_info = { | 157     failure_info = { | 
| 158         'failed': True, | 158         'failed': True, | 
| 159         'failed_steps': { | 159         'failed_steps': { | 
| 160             'a': { | 160             'a': { | 
| 161                 'current_failure': 99, | 161                 'current_failure': 99, | 
| 162                 'first_failure': 98, | 162                 'first_failure': 98, | 
| 163             }, | 163             }, | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 232             'revision': 'r96_1', | 232             'revision': 'r96_1', | 
| 233             'touched_files': [ | 233             'touched_files': [ | 
| 234                 { | 234                 { | 
| 235                     'change_type': ChangeType.MODIFY, | 235                     'change_type': ChangeType.MODIFY, | 
| 236                     'old_path': 'a/b/f96_1.cc', | 236                     'old_path': 'a/b/f96_1.cc', | 
| 237                     'new_path': 'a/b/f96_1.cc' | 237                     'new_path': 'a/b/f96_1.cc' | 
| 238                 }, | 238                 }, | 
| 239             ], | 239             ], | 
| 240         }, | 240         }, | 
| 241     } | 241     } | 
|  | 242     deps_info = { | 
|  | 243       'deps_rolls': {}, | 
|  | 244       'current_deps': {}, | 
|  | 245     } | 
| 242     failure_signals_json = { | 246     failure_signals_json = { | 
| 243         'a': { | 247         'a': { | 
| 244           'files': { | 248           'files': { | 
| 245               'src/a/b/f99_2.cc': [], | 249               'src/a/b/f99_2.cc': [], | 
| 246           }, | 250           }, | 
| 247         }, | 251         }, | 
| 248         'b': { | 252         'b': { | 
| 249           'files': { | 253           'files': { | 
| 250               'x/y/f99_1.cc': [], | 254               'x/y/f99_1.cc': [], | 
| 251           }, | 255           }, | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 286                         'hints': { | 290                         'hints': { | 
| 287                             'added x/y/f99_1.cc (and it was in log)': 5, | 291                             'added x/y/f99_1.cc (and it was in log)': 5, | 
| 288                         }, | 292                         }, | 
| 289                     } | 293                     } | 
| 290                 ], | 294                 ], | 
| 291             } | 295             } | 
| 292         ] | 296         ] | 
| 293     } | 297     } | 
| 294 | 298 | 
| 295     analysis_result = build_failure_analysis.AnalyzeBuildFailure( | 299     analysis_result = build_failure_analysis.AnalyzeBuildFailure( | 
| 296         failure_info, change_logs, failure_signals_json) | 300         failure_info, change_logs, deps_info, failure_signals_json) | 
| 297     self.assertEqual(expected_analysis_result, analysis_result) | 301     self.assertEqual(expected_analysis_result, analysis_result) | 
| OLD | NEW | 
|---|