Skip to content

Commit

Permalink
change assert_range schema to include 'comparisons' keyword as a subp…
Browse files Browse the repository at this point in the history
…roperty. The 'mode' is also present for logical OR/AND
  • Loading branch information
shahzebsiddiqui committed Oct 30, 2023
1 parent 0f6757d commit 56392e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
10 changes: 7 additions & 3 deletions buildtest/buildsystem/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ def assert_range_check(builder):
metric_names = list(builder.metadata["metrics"].keys())

# iterate over each metric in buildspec and determine reference check for each metric
for metric in builder.status["assert_range"]:
for metric in builder.status["assert_range"]["comparisons"]:
name = metric["name"]
lower_bound = metric["lower"]
upper_bound = metric["upper"]
Expand Down Expand Up @@ -948,8 +948,12 @@ def assert_range_check(builder):
console.print(
f"[blue]{builder}[/]: testing metric: {name} if {lower_bound} <= {conv_value} <= {upper_bound} - Check: {bool_check}"
)
# perform a logical AND on the list and return the boolean result
range_check = all(assert_check)

# perform logical OR if mode is set to 'or' or 'OR' otherwise do logical AND
if builder.status["assert_range"].get("mode") in ["or", "OR"]:
range_check = any(assert_check)
else:
range_check = all(assert_check)

console.print(f"[blue]{builder}[/]: Range Check: {range_check}")
return range_check
Expand Down
56 changes: 32 additions & 24 deletions buildtest/schemas/definitions.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,32 +315,40 @@
"description": "Perform assertion of not equal (!=) with reference value",
"$ref": "#/definitions/status_check_eq_ne"
},
"assert_range":
{
"assert_range": {
"type": "object",
"description": "Perform assertion based on lower and upper bound",
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"name",
"lower",
"upper"
],
"properties": {
"name": {
"type": "string",
"description": "Name of metric to use for comparison"
},
"lower": {
"description": "Specify reference value for lower bound",
"type": "number"
},
"upper": {
"description": "Specify reference value for upper bound",
"type": "number"
"additionalProperties": false,
"required": ["comparisons"],
"properties": {
"mode": {
"$ref": "#/definitions/mode"
},
"comparisons": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"name",
"lower",
"upper"
],
"properties": {
"name": {
"type": "string",
"description": "Name of metric to use for comparison"
},
"lower": {
"description": "Specify reference value for lower bound",
"type": "number"
},
"upper": {
"description": "Specify reference value for upper bound",
"type": "number"
}
}
}

}
}
},
Expand Down
1 change: 1 addition & 0 deletions tutorials/perf_checks/assert_range.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ buildspecs:
item: 1
status:
assert_range:
comparisons:
- name: copy
lower: 5000
upper: 20000
Expand Down

0 comments on commit 56392e9

Please sign in to comment.