Skip to content

Commit

Permalink
Fix tool crash on empty simulink annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
florianschanda committed May 26, 2023
1 parent 803a8b5 commit a3d97b8
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Not quite compatible with Octave yet. See #43 [octave support](https://github.co

### 0.9.40-dev


* Fix tool crash when encountering a Simulink area annotation with no
text. These annotations are now properly supported and you can even
add tracing text to them.

### 0.9.39

Expand Down
Binary file added docs/area_annotation_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion docs/trace.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h3>Annotating code</h3>
</div>

<h3>Annotating models</h3>
<h4>With annotations</h4>
<h4>With text annotations</h4>
<div>
Simply place an annotation anywhere in your block. If the text
contains a line that starts with <tt>lobster-trace:</tt> then
Expand All @@ -141,6 +141,26 @@ <h4>With annotations</h4>
ignored.
</div>

<h4>With area annotations</h4>
<div>
You may also use area annotations. Note however that the
grouping is irrelevant, the traceable item that these tags
relate to are the enclosing system or sub-system; similar to a
text annotation.
<figure>
<img src="area_annotation_example.png" height="150">
<figcaption>
Example showing usage of area annotations for tracing
</figcaption>
</figure>

The point of these is to make it easier for the human to see
what is going on in larger systems. If you want a more
fine-grained tracing you still need to chop up your larger
system into several smaller sub-systems; similar to a large
spaghetti MATLAB function.
</div>

<h4>With block properties</h4>
<div>
Another option is to
Expand Down
20 changes: 17 additions & 3 deletions miss_hit_core/s_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,34 @@ def parse_block(self, et_block):
def parse_annotation(self, et_anno):
assert isinstance(et_anno, ET.Element)
assert et_anno.tag == "Annotation"
# https://uk.mathworks.com/help/simulink/slref/simulink.annotation.html

content = None
annotation_type = None
for et_item in et_anno:
if et_item.tag == "P" and et_item.attrib["Name"] == "Name":
content = et_item.text
assert content is not None

if content.startswith("<!DOCTYPE HTML"):
annotation_type = "note_annotation"
break
elif et_item.tag == "P" and \
et_item.attrib["Name"] == "AnnotationType":
annotation_type = et_item.text
assert annotation_type in ("note_annotation",
"area_annotation",
"image_annotation"), \
"unexpected %s annotation in %s" % (annotation_type,
self.filename)

if content is None:
content = ""
elif content.startswith("<!DOCTYPE HTML"):
html_parser = HTML_Text_Extractor()
html_parser.feed(content)
content = html_parser.text.strip()

n_anno = Annotation(et_anno.attrib["SID"],
content)

return n_anno

def parse_system(self, et_system):
Expand Down
Binary file added tests/simulink_parser/annotations/areas.slx
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/simulink_parser/annotations/areas.slx.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== Parsing areas.slx ===
Model
System
Block Inport ('Inport')
Block Outport ('Outport')
Block Inport ('Inport1')
Block Outport ('Outport1')
Annotation ()
Annotation (stuff in here)
Annotation (lobster-trace: potato.kitten)
Annotation (This is my potato)

=== Summary of misc. children ===
Children in Inport
Children in Outport
MISS_HIT Debug Summary: 1 file(s) analysed, everything seems fine
Binary file added tests/trace/simulink-area-anno/area.slx
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/trace/simulink-area-anno/mh_act_trace.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": [],
"generator": "MH Trace",
"schema": "lobster-act-trace",
"version": 3
}
26 changes: 26 additions & 0 deletions tests/trace/simulink-area-anno/mh_imp_trace.lobster
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"data": [
{
"just_down": [],
"just_global": [],
"just_up": [],
"kind": "Block",
"language": "Simulink",
"location": {
"column": null,
"file": "area.slx",
"kind": "file",
"line": null
},
"name": "area",
"refs": [
"req example.do_nothing"
],
"shared": false,
"tag": "simulink area"
}
],
"generator": "MH Trace",
"schema": "lobster-imp-trace",
"version": 3
}
1 change: 1 addition & 0 deletions tests/trace/simulink-area-anno/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MISS_HIT Trace Summary: 1 file(s) analysed, everything seems fine

0 comments on commit a3d97b8

Please sign in to comment.