summaryrefslogtreecommitdiff
path: root/extra/stack_analyzer
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2017-08-28 16:52:44 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-09-07 12:56:29 -0700
commit588320d4b840e4466775815496f266e003586f9d (patch)
tree0dbae960ab376c759211973678a2cf5c5129563b /extra/stack_analyzer
parent098bde322f5678a879bb8d181edfec9840f23e1c (diff)
downloadchrome-ec-588320d4b840e4466775815496f266e003586f9d.tar.gz
stack_analyzer: Use board/$BOARD/analyzestack.yaml by default
BRANCH=none BUG=chromium:648840 TEST=make BOARD=hammer analyzestack Change-Id: Id05fee7e085a02dd4c2d36880f6891c3eb86b404 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/637550 Reviewed-by: Che-yu Wu <cheyuw@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'extra/stack_analyzer')
-rw-r--r--extra/stack_analyzer/README.md3
-rwxr-xr-xextra/stack_analyzer/stack_analyzer.py13
-rwxr-xr-xextra/stack_analyzer/stack_analyzer_unittest.py50
3 files changed, 43 insertions, 23 deletions
diff --git a/extra/stack_analyzer/README.md b/extra/stack_analyzer/README.md
index b809ccc5a2..a13b3b66db 100644
--- a/extra/stack_analyzer/README.md
+++ b/extra/stack_analyzer/README.md
@@ -15,7 +15,8 @@ In `src/platform/ec`, run
make BOARD=${BOARD} SECTION=${SECTION} ANNOTATION=${ANNOTATION} analyzestack
```
The `${SECTION}` can be `RO` or `RW`. The `${ANNOTATION}` is a optional
-annotation file, see the example_annotation.yaml.
+annotation file, see the example_annotation.yaml, by default,
+board/$BOARD/analyzestack.yaml is used.
Output
------
diff --git a/extra/stack_analyzer/stack_analyzer.py b/extra/stack_analyzer/stack_analyzer.py
index f08470bafc..a839515b9e 100755
--- a/extra/stack_analyzer/stack_analyzer.py
+++ b/extra/stack_analyzer/stack_analyzer.py
@@ -1439,19 +1439,26 @@ def main():
# Load annotation config.
if options.annotation is None:
annotation = {}
+ elif not os.path.exists(options.annotation):
+ print('Warning: Annotation file {} does not exist.'
+ .format(options.annotation))
+ annotation = {}
else:
try:
with open(options.annotation, 'r') as annotation_file:
annotation = yaml.safe_load(annotation_file)
except yaml.YAMLError:
- raise StackAnalyzerError('Failed to parse annotation file.')
+ raise StackAnalyzerError('Failed to parse annotation file {}.'
+ .format(options.annotation))
except IOError:
- raise StackAnalyzerError('Failed to open annotation file.')
+ raise StackAnalyzerError('Failed to open annotation file {}.'
+ .format(options.annotation))
# TODO(cheyuw): Do complete annotation format verification.
if not isinstance(annotation, dict):
- raise StackAnalyzerError('Invalid annotation file.')
+ raise StackAnalyzerError('Invalid annotation file {}.'
+ .format(options.annotation))
# Generate and parse the symbols.
try:
diff --git a/extra/stack_analyzer/stack_analyzer_unittest.py b/extra/stack_analyzer/stack_analyzer_unittest.py
index cac4383906..1fe4944844 100755
--- a/extra/stack_analyzer/stack_analyzer_unittest.py
+++ b/extra/stack_analyzer/stack_analyzer_unittest.py
@@ -640,25 +640,37 @@ class StackAnalyzerTest(unittest.TestCase):
annotation='fake')
parseargs_mock.return_value = args
- with mock.patch('__builtin__.print') as print_mock:
- sa.main()
- print_mock.assert_called_once_with(
- 'Error: Failed to open annotation file.')
-
- with mock.patch('__builtin__.print') as print_mock:
- with mock.patch('__builtin__.open', mock.mock_open()) as open_mock:
- open_mock.return_value.read.side_effect = ['{', '']
- sa.main()
- open_mock.assert_called_once_with('fake', 'r')
- print_mock.assert_called_once_with(
- 'Error: Failed to parse annotation file.')
-
- with mock.patch('__builtin__.print') as print_mock:
- with mock.patch('__builtin__.open',
- mock.mock_open(read_data='')) as open_mock:
- sa.main()
- print_mock.assert_called_once_with(
- 'Error: Invalid annotation file.')
+ with mock.patch('os.path.exists') as path_mock:
+ path_mock.return_value = False
+ with mock.patch('__builtin__.print') as print_mock:
+ with mock.patch('__builtin__.open', mock.mock_open()) as open_mock:
+ sa.main()
+ print_mock.assert_any_call(
+ 'Warning: Annotation file fake does not exist.')
+
+ with mock.patch('os.path.exists') as path_mock:
+ path_mock.return_value = True
+ with mock.patch('__builtin__.print') as print_mock:
+ with mock.patch('__builtin__.open', mock.mock_open()) as open_mock:
+ open_mock.side_effect = IOError()
+ sa.main()
+ print_mock.assert_called_once_with(
+ 'Error: Failed to open annotation file fake.')
+
+ with mock.patch('__builtin__.print') as print_mock:
+ with mock.patch('__builtin__.open', mock.mock_open()) as open_mock:
+ open_mock.return_value.read.side_effect = ['{', '']
+ sa.main()
+ open_mock.assert_called_once_with('fake', 'r')
+ print_mock.assert_called_once_with(
+ 'Error: Failed to parse annotation file fake.')
+
+ with mock.patch('__builtin__.print') as print_mock:
+ with mock.patch('__builtin__.open',
+ mock.mock_open(read_data='')) as open_mock:
+ sa.main()
+ print_mock.assert_called_once_with(
+ 'Error: Invalid annotation file fake.')
args.annotation = None