Skip to content

Commit

Permalink
adds tracing for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
christophkloeffel committed Oct 9, 2023
1 parent e2518b9 commit b12214a
Show file tree
Hide file tree
Showing 58 changed files with 299 additions and 4 deletions.
3 changes: 2 additions & 1 deletion language-reference-manual/lrm.trlc
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ section "Checks" {
order.'''
}

Dynamic_Semantics Check_Evaluation_Order_Across_Blocks {
Note Check_Evaluation_Order_Across_Blocks {
text = '''If multiple check blocks are declared for the same type,
then the order of evaluation of each check
block is unspecified.'''
Expand Down Expand Up @@ -1001,6 +1001,7 @@ section "Checks" {
error "CB Version must be positive", version
}
"""
untraced_reason = "Example code"
}

}
Expand Down
10 changes: 10 additions & 0 deletions tests-system/checks-10/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Foo

type T {
a String
b String
}

checks T {
len(c) > 10, "c is too short", c
}
3 changes: 3 additions & 0 deletions tests-system/checks-10/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
len(c) > 10, "c is too short", c
^ checks-10/foo.rsl:9: error: unknown symbol c
Processed 1 model(s), 0 check(s) and 0 requirement file(s) and found 1 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-10/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks-10/foo.rsl:9:9: trlc error: unknown symbol c
3 changes: 3 additions & 0 deletions tests-system/checks-10/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
len(c) > 10, "c is too short", c
^ checks-10/foo.rsl:9: error: unknown symbol c
Processed 1 model(s), 0 check(s) and 0 requirement file(s) and found 1 error(s)
3 changes: 3 additions & 0 deletions tests-system/checks-10/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
len(c) > 10, "c is too short", c
^ checks-10/foo.rsl:9: error: unknown symbol c
Processed 1 model(s), 0 check(s) and 0 requirement file(s) and found 1 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-10/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LRM.Applicable_Components
12 changes: 12 additions & 0 deletions tests-system/checks-11/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Foo

type T {
a Integer
b Integer
}

checks T {
a < 0, warning "First warning: a is positive", a
b > 0, warning "Second warning: b is negative", b
a < b, warning "Third warning: a is greater than b"
}
6 changes: 6 additions & 0 deletions tests-system/checks-11/foo.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Foo

T Bar {
a = 1
b = -1
}
7 changes: 7 additions & 0 deletions tests-system/checks-11/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = 1
^ checks-11/foo.trlc:4: check warning: First warning: a is positive
b = -1
^ checks-11/foo.trlc:5: check warning: Second warning: b is negative
T Bar {
^^^ checks-11/foo.trlc:3: check warning: Third warning: a is greater than b
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 warning(s)
3 changes: 3 additions & 0 deletions tests-system/checks-11/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
checks-11/foo.trlc:4:7: trlc check warning: First warning: a is positive
checks-11/foo.trlc:5:7: trlc check warning: Second warning: b is negative
checks-11/foo.trlc:3:3: trlc check warning: Third warning: a is greater than b
13 changes: 13 additions & 0 deletions tests-system/checks-11/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
a = 1
^ checks-11/foo.trlc:4: check warning: First warning: a is positive
b = -1
^ checks-11/foo.trlc:5: check warning: Second warning: b is negative
T Bar {
^^^ checks-11/foo.trlc:3: check warning: Third warning: a is greater than b
{
"Bar": {
"a": 1,
"b": -1
}
}
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 warning(s)
7 changes: 7 additions & 0 deletions tests-system/checks-11/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = 1
^ checks-11/foo.trlc:4: check warning: First warning: a is positive
b = -1
^ checks-11/foo.trlc:5: check warning: Second warning: b is negative
T Bar {
^^^ checks-11/foo.trlc:3: check warning: Third warning: a is greater than b
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 warning(s)
1 change: 1 addition & 0 deletions tests-system/checks-11/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LRM.Check_Evaluation_Order
11 changes: 11 additions & 0 deletions tests-system/checks-12/bar.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package Bar
import Foo

type T extends Foo.T {
b String
}

checks T {
len(a) > 10, "a has to be more than 10 chars", a
len(b) > 10, "b has to be more than 10 chars", b
}
6 changes: 6 additions & 0 deletions tests-system/checks-12/bar.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Bar

T Test {
a = "potato"
b = "more potatoes"
}
9 changes: 9 additions & 0 deletions tests-system/checks-12/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Foo

type T {
a String
}

checks T {
len(a) > 10, warning "a has to be more than 7 chars", a
}
5 changes: 5 additions & 0 deletions tests-system/checks-12/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = "potato"
^^^^^^^^ checks-12/bar.trlc:4: check warning: a has to be more than 7 chars
a = "potato"
^^^^^^^^ checks-12/bar.trlc:4: check error: a has to be more than 10 chars
Processed 2 model(s), 0 check(s) and 1 requirement file(s) and found 1 warning(s) and 1 error(s)
2 changes: 2 additions & 0 deletions tests-system/checks-12/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
checks-12/bar.trlc:4:9: trlc check warning: a has to be more than 7 chars
checks-12/bar.trlc:4:9: trlc check error: a has to be more than 10 chars
5 changes: 5 additions & 0 deletions tests-system/checks-12/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = "potato"
^^^^^^^^ checks-12/bar.trlc:4: check warning: a has to be more than 7 chars
a = "potato"
^^^^^^^^ checks-12/bar.trlc:4: check error: a has to be more than 10 chars
Processed 2 model(s), 0 check(s) and 1 requirement file(s) and found 1 warning(s) and 1 error(s)
5 changes: 5 additions & 0 deletions tests-system/checks-12/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = "potato"
^^^^^^^^ checks-12/bar.trlc:4: check warning: a has to be more than 7 chars
a = "potato"
^^^^^^^^ checks-12/bar.trlc:4: check error: a has to be more than 10 chars
Processed 2 model(s), 0 check(s) and 1 requirement file(s) and found 1 warning(s) and 1 error(s)
2 changes: 2 additions & 0 deletions tests-system/checks-12/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LRM.Check_Evaluation_Order_For_Extensions
LRM.Check_Messages
5 changes: 5 additions & 0 deletions tests-system/checks-9/bar.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Bar

type B {
a String
}
10 changes: 10 additions & 0 deletions tests-system/checks-9/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Foo
import Bar

type T {
a String
}

checks B {
len(a) > 10, "a is too short", a
}
3 changes: 3 additions & 0 deletions tests-system/checks-9/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
checks B {
^ checks-9/foo.rsl:8: error: unknown symbol B
Processed 2 model(s), 0 check(s) and 0 requirement file(s) and found 1 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-9/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks-9/foo.rsl:8:8: trlc error: unknown symbol B
3 changes: 3 additions & 0 deletions tests-system/checks-9/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
checks B {
^ checks-9/foo.rsl:8: error: unknown symbol B
Processed 2 model(s), 0 check(s) and 0 requirement file(s) and found 1 error(s)
3 changes: 3 additions & 0 deletions tests-system/checks-9/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
checks B {
^ checks-9/foo.rsl:8: error: unknown symbol B
Processed 2 model(s), 0 check(s) and 0 requirement file(s) and found 1 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-9/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LRM.Applicable_Types
13 changes: 13 additions & 0 deletions tests-system/checks-error/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Foo

type T {
a String
b String
c String
}

checks T {
len(a) > 3, error "a must be longer than 3", a
len(b) > 7, "b must be longer than 7", b
len(c) > 10, "c must be longer than 10", c
}
7 changes: 7 additions & 0 deletions tests-system/checks-error/foo.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Foo

T Test {
a = "po"
b = "potato"
c = "potatoes"
}
7 changes: 7 additions & 0 deletions tests-system/checks-error/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = "po"
^^^^ checks-error/foo.trlc:4: check error: a must be longer than 3
b = "potato"
^^^^^^^^ checks-error/foo.trlc:5: check error: b must be longer than 7
c = "potatoes"
^^^^^^^^^^ checks-error/foo.trlc:6: check error: c must be longer than 10
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 error(s)
3 changes: 3 additions & 0 deletions tests-system/checks-error/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
checks-error/foo.trlc:4:9: trlc check error: a must be longer than 3
checks-error/foo.trlc:5:9: trlc check error: b must be longer than 7
checks-error/foo.trlc:6:9: trlc check error: c must be longer than 10
7 changes: 7 additions & 0 deletions tests-system/checks-error/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = "po"
^^^^ checks-error/foo.trlc:4: check error: a must be longer than 3
b = "potato"
^^^^^^^^ checks-error/foo.trlc:5: check error: b must be longer than 7
c = "potatoes"
^^^^^^^^^^ checks-error/foo.trlc:6: check error: c must be longer than 10
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 error(s)
7 changes: 7 additions & 0 deletions tests-system/checks-error/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = "po"
^^^^ checks-error/foo.trlc:4: check error: a must be longer than 3
b = "potato"
^^^^^^^^ checks-error/foo.trlc:5: check error: b must be longer than 7
c = "potatoes"
^^^^^^^^^^ checks-error/foo.trlc:6: check error: c must be longer than 10
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-error/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LRM.Check_Severity
13 changes: 13 additions & 0 deletions tests-system/checks-fatal/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Foo

type T {
a String
b String
c String
}

checks T {
len(a) > 3, fatal "a must be longer than 3", a
len(b) > 7, "b must be longer than 7", b
len(c) > 10, "c must be longer than 10", c
}
7 changes: 7 additions & 0 deletions tests-system/checks-fatal/foo.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Foo

T Test {
a = "po"
b = "potato"
c = "potatoes"
}
3 changes: 3 additions & 0 deletions tests-system/checks-fatal/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = "po"
^^^^ checks-fatal/foo.trlc:4: check error: a must be longer than 3
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 1 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-fatal/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks-fatal/foo.trlc:4:9: trlc check error: a must be longer than 3
3 changes: 3 additions & 0 deletions tests-system/checks-fatal/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = "po"
^^^^ checks-fatal/foo.trlc:4: check error: a must be longer than 3
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 1 error(s)
3 changes: 3 additions & 0 deletions tests-system/checks-fatal/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = "po"
^^^^ checks-fatal/foo.trlc:4: check error: a must be longer than 3
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 1 error(s)
1 change: 1 addition & 0 deletions tests-system/checks-fatal/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LRM.Check_Severity
13 changes: 13 additions & 0 deletions tests-system/checks-warning/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Foo

type T {
a String
b String
c String
}

checks T {
len(a) > 3, warning "a must be longer than 3", a
len(b) > 7, warning "b must be longer than 7", b
len(c) > 10, warning "c must be longer than 10", c
}
7 changes: 7 additions & 0 deletions tests-system/checks-warning/foo.trlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Foo

T Test {
a = "po"
b = "potato"
c = "potatoes"
}
7 changes: 7 additions & 0 deletions tests-system/checks-warning/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = "po"
^^^^ checks-warning/foo.trlc:4: check warning: a must be longer than 3
b = "potato"
^^^^^^^^ checks-warning/foo.trlc:5: check warning: b must be longer than 7
c = "potatoes"
^^^^^^^^^^ checks-warning/foo.trlc:6: check warning: c must be longer than 10
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 warning(s)
3 changes: 3 additions & 0 deletions tests-system/checks-warning/output.brief
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
checks-warning/foo.trlc:4:9: trlc check warning: a must be longer than 3
checks-warning/foo.trlc:5:9: trlc check warning: b must be longer than 7
checks-warning/foo.trlc:6:9: trlc check warning: c must be longer than 10
14 changes: 14 additions & 0 deletions tests-system/checks-warning/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
a = "po"
^^^^ checks-warning/foo.trlc:4: check warning: a must be longer than 3
b = "potato"
^^^^^^^^ checks-warning/foo.trlc:5: check warning: b must be longer than 7
c = "potatoes"
^^^^^^^^^^ checks-warning/foo.trlc:6: check warning: c must be longer than 10
{
"Test": {
"a": "po",
"b": "potato",
"c": "potatoes"
}
}
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 warning(s)
7 changes: 7 additions & 0 deletions tests-system/checks-warning/output.smtlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = "po"
^^^^ checks-warning/foo.trlc:4: check warning: a must be longer than 3
b = "potato"
^^^^^^^^ checks-warning/foo.trlc:5: check warning: b must be longer than 7
c = "potatoes"
^^^^^^^^^^ checks-warning/foo.trlc:6: check warning: c must be longer than 10
Processed 1 model(s), 0 check(s) and 1 requirement file(s) and found 3 warning(s)
1 change: 1 addition & 0 deletions tests-system/checks-warning/tracing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LRM.Check_Severity
9 changes: 9 additions & 0 deletions tests-system/simple/foo.rsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package foo

type MyType {
name String
}

checks MyType {
len(name) > 10, warning "name is too short", name
}
5 changes: 5 additions & 0 deletions tests-system/simple/instances.trlc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package instances
import bar
import foo

bar.MyType SomeThing {
name = "Qbert" // does start with Q
}

foo.MyType OtherThing {
name = "long enough"
}
2 changes: 1 addition & 1 deletion tests-system/simple/output
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
checks MyType {
^^^^^^ simple/checks.check:3: issue: move this check block into bar.rsl:1 [deprecated_feature]
Processed 1 model(s), 1 check(s) and 1 requirement file(s) and found 1 warning(s)
Processed 2 model(s), 1 check(s) and 1 requirement file(s) and found 1 warning(s)
5 changes: 4 additions & 1 deletion tests-system/simple/output.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"OtherThing": {
"name": "long enough"
},
"SomeThing": {
"name": "Qbert"
}
}
Processed 1 model(s), 1 check(s) and 1 requirement file(s) and found no issues
Processed 2 model(s), 1 check(s) and 1 requirement file(s) and found no issues
2 changes: 1 addition & 1 deletion tests-system/simple/output.smtlib
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
checks MyType {
^^^^^^ simple/checks.check:3: issue: move this check block into bar.rsl:1 [deprecated_feature]
Processed 1 model(s), 1 check(s) and 1 requirement file(s) and found 1 warning(s)
Processed 2 model(s), 1 check(s) and 1 requirement file(s) and found 1 warning(s)
1 change: 1 addition & 0 deletions tests-system/simple/tracing
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ LRM.Layout
LRM.File_Parsing_Order
LRM.Preamble
LRM.RSL_File
LRM.Check_Block
3 changes: 3 additions & 0 deletions trlc/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def __init__(self, location, n_typ):
self.checks = []

def add_check(self, n_check):
# lobster-trace: LRM.Check_Evaluation_Order
assert isinstance(n_check, Check)
self.checks.append(n_check)

Expand Down Expand Up @@ -363,6 +364,8 @@ def get_real_location(self, composite_object):
return fields[self.n_anchor.name].location

def perform(self, mh, composite_object):
# lobster-trace: LRM.Check_Messages
# lobster-trace: LRM.Check_Severity
assert isinstance(mh, Message_Handler)
assert isinstance(composite_object, (Record_Object,
Tuple_Aggregate))
Expand Down
Loading

0 comments on commit b12214a

Please sign in to comment.