Runtime Parameterized Validators #1234
-
I've gotten OpenHTF working with a plug and with a validator. However, everything in the examples is written with decorators, which are fixed at runtime. I need to develop a dynamic test, say Voltage, where at runtime, for an arbitrary number of voltage measurements, I can specify the minimum and maximum voltage for each phase node. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
Can you clarify whether:
If the former, you can modify measurements and phases at runtime before passing them to the If the latter, OpenHTF doesn't allow mutating measurement definitions once the test has started (this includes changing the validator). One pattern that people use is to not set a validator on the numeric measurement itself - just using it to record the value - and use a separate bool measurement to capture pass/fail. |
Beta Was this translation helpful? Give feedback.
-
Thank you for replying so quickly. It's #1: set everything up then execute. I will try to implement what you described.
Best regards, Bill
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: glados-verma ***@***.***>
Sent: Thursday, July 10, 2025 8:03:48 PM
To: google/openhtf ***@***.***>
Cc: William Tribley ***@***.***>; Author ***@***.***>
Subject: Re: [google/openhtf] Runtime Parameterized Validators (Discussion #1234)
Can you clarify whether:
1. You need to determine the measurement min and max values at runtime, but before starting the OpenHTF test execution?
2. Or this determination happens after test execution starts?
If the former, you can modify measurements and phases at runtime before passing them to the Test class for execution. For example, the with_args method can be used to parameterize measurements and phases.
If the latter, OpenHTF doesn't allow mutating measurement definitions once the test has started (this includes changing the validator). One pattern that people use is to not set a validator on the numeric measurement itself - just using it to record the value - and use a separate bool measurement to capture pass/fail.
—
Reply to this email directly, view it on GitHub<#1234 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AR6TVWTRFTEGAASXS6P55YL3H4EPJAVCNFSM6AAAAACBHRXPGKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNZSGY3DMMA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Perfect. I didn't know this. Thanks again for the help, I will post my results. Have a good day!
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: glados-verma ***@***.***>
Sent: Thursday, July 10, 2025 9:15:35 PM
To: google/openhtf ***@***.***>
Cc: William Tribley ***@***.***>; Author ***@***.***>
Subject: Re: [google/openhtf] Runtime Parameterized Validators (Discussion #1234)
Okay that's good. Then you might find it useful that Python decorators are also callables. So instead of doing a decorated phase:
@htf.measures(
htf.Measurement('resistance')
.with_units('ohm')
.in_range(minimum=5, maximum=17)
)
def MyPhaseFunction(test_api):
...
you can instead define the phase function first, and convert it into a phase later:
def MyPhaseFunction(test_api, ...):
"""Define the function, don't put any htf decorators that you need to change at runtime"""
# Later, once you have the validator limits etc.
min_ohms = 5
max_ohms = 17 # Fixed in example; you got these dynamically at runtime instead.
my_measurement = htf.Measurement('resistance').with_units('ohm').in_range(minimum=min_ohms, maximum=max_ohms)
# This call returns an OpenHTF phase, with the measurement defined on it.
my_phase = htf.measures(my_measurement)(MyPhaseFunction)
my_test = htf.Test([my_phase, ...])
You can do the same thing with other decorators that you need to define using values determined at runtime (but before creating the htf.Test).
—
Reply to this email directly, view it on GitHub<#1234 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AR6TVWXONAYPKQDREFQIZID3H4M4PAVCNFSM6AAAAACBHRXPGKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNZSG4YDAMI>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
It works, see code below. This will allow me to define a handful of phase functions, read through a list of function and limit specs to make an array of phases then execute. Now I can flesh the whole system out with DUT ID, logging and reporting. This is going to save me weeks of time!
Normally there's one measurement per phase which is sufficient for this project. Out of curiosity, can you pass an array of htf.Measurement objects to htf.measures? In the code below, pmeasurement would be an array instead of a single measurement.
Best regards,
Bill
def main():
# Add measurements to predefined phases
minByteCt=78
pmeasurement=(htf.Measurement('bytes').with_precision(0).
with_units('byte').in_range(minimum=minByteCt))
dynamicTestPhases=[]
# Loop through all the dynamic test specs choosing the phase and measurement
dynamicTestPhases.append(htf.measures(pmeasurement)(byteCountTest))
test = htf.Test(
htf.PhaseGroup(
setup=[setup_phase],
main=dynamicTestPhases
#teardown=[td_phase]
)
)
test.execute()
…________________________________
From: glados-verma ***@***.***>
Sent: Thursday, July 10, 2025 9:15 PM
To: google/openhtf ***@***.***>
Cc: William Tribley ***@***.***>; Author ***@***.***>
Subject: Re: [google/openhtf] Runtime Parameterized Validators (Discussion #1234)
Okay that's good. Then you might find it useful that Python decorators are also callables. So instead of doing a decorated phase:
@htf.measures(
htf.Measurement('resistance')
.with_units('ohm')
.in_range(minimum=5, maximum=17)
)
def MyPhaseFunction(test_api):
...
you can instead define the phase function first, and convert it into a phase later:
def MyPhaseFunction(test_api, ...):
"""Define the function, don't put any htf decorators that you need to change at runtime"""
# Later, once you have the validator limits etc.
min_ohms = 5
max_ohms = 17 # Fixed in example; you got these dynamically at runtime instead.
my_measurement = htf.Measurement('resistance').with_units('ohm').in_range(minimum=min_ohms, maximum=max_ohms)
# This call returns an OpenHTF phase, with the measurement defined on it.
my_phase = htf.measures(my_measurement)(MyPhaseFunction)
my_test = htf.Test([my_phase, ...])
You can do the same thing with other decorators that you need to define using values determined at runtime (but before creating the htf.Test).
—
Reply to this email directly, view it on GitHub<#1234 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AR6TVWXONAYPKQDREFQIZID3H4M4PAVCNFSM6AAAAACBHRXPGKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNZSG4YDAMI>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
Yes, you can pass multiple You could also use |
Beta Was this translation helpful? Give feedback.
-
Thanks!
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: glados-verma ***@***.***>
Sent: Friday, July 11, 2025 4:35:50 PM
To: google/openhtf ***@***.***>
Cc: William Tribley ***@***.***>; Author ***@***.***>
Subject: Re: [google/openhtf] Runtime Parameterized Validators (Discussion #1234)
Yes, you can pass multiple Measurement instances to measures, for example<https://github.com/google/openhtf/blob/4749612f990a20fded3a07e0fc1fe6551c99cd18/examples/all_the_things.py#L41>
You could also use measures multiple times on a phase.
—
Reply to this email directly, view it on GitHub<#1234 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AR6TVWSE3PPP57R37QWIZKL3IAU3NAVCNFSM6AAAAACBHRXPGKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNZTGU3TSNY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Okay that's good. Then you might find it useful that Python decorators are also callables. So instead of doing a decorated phase:
you can instead define the phase function first, and convert it into a phase later: