Skip to content

Commit 9d62994

Browse files
authored
Merge pull request #94 from diodeinc/fix/voltage-within-check
Fix voltage_within voltage attr check
2 parents 961911b + 132b426 commit 9d62994

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

checks.zen

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ def voltage_within(
1212
# drop nominal in within:
1313
within = VoltageRange(min=within.min, max=within.max)
1414
# ensure voltage is within within
15-
min_valid = voltage.min >= within.min
16-
max_valid = voltage.max <= within.max
1715
err_msg = "Voltage range " + str(voltage) + " of " + net_name + " is not within " + str(within)
18-
check(min_valid and max_valid, err_msg)
16+
check(voltage in within, err_msg)
1917

2018
def check_gen(power: Power, severity: Severity = severity, name: str = name):
2119
check_name = power.NET.name + "_" + name
22-
if not power.voltage:
20+
if not hasattr(power, "voltage"):
2321
return
2422
builtin.add_electrical_check(
2523
name=check_name,

test/test_checks.zen

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load("../checks.zen", "voltage_within")
2+
load("../interfaces.zen", "Power", "VoltageRange")
3+
4+
# Test 3.3V rail with tolerance
5+
v3v3 = Power("3V3", voltage=VoltageRange("3.3V 1%"))
6+
# Check if 3.3V +/- 1% is within 3.3V +/- 5%
7+
check_3v3 = voltage_within("3.3V 5%")
8+
check_3v3(v3v3)
9+
10+
# Test 5V rail with explicit range
11+
v5 = Power("5V", voltage=VoltageRange("5V"))
12+
# Check if 5V is within 4.5V to 5.5V (using +/- 10% notation)
13+
check_5v = voltage_within("5V 10%")
14+
check_5v(v5)
15+
16+
# Test with tighter tolerance on the rail than the check
17+
v1v8 = Power("1V8", voltage=VoltageRange("1.8V 1%"))
18+
check_1v8 = voltage_within("1.8V 5%")
19+
check_1v8(v1v8)
20+
21+
# Test rail with no voltage set (should be ignored)
22+
v_unknown = Power("UNKNOWN")
23+
check_unknown = voltage_within("5V 10%")
24+
check_unknown(v_unknown)

0 commit comments

Comments
 (0)