google / google/openhtf

Provide a method to add dynamic measurements to Phases

Open
#821 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
722
Forks
237
Avg merge
11h 31m
Merged PRs (30d)
4

Description

Currently we can declare measurements mostly using @openhtf.measures decorator. However, there are cases where we need to add measurements on the fly based on some other measurements in the phase. For example, based on the version of FW read back there might be some extra measurements that can be recorded in that phase.

I was toying with that idea and here's an example that I came up with:

"""Example on adding Dynamic Measurement in Phase."""

import openhtf
from openhtf.util import validators
from openhtf.util import units
from openhtf.plugs import user_input

TEST_NAME = 'DYNAMIC_MEASUREMENT_TESTER'

@openhtf.measures('hello_world_measurement')
@openhtf.PhaseOptions(requires_state=True)
def dynamic_measurement(test):
"""Dynamic measurement phase."""
test.logger.info('Experimenting with dynamic measurements!')

test.running_phase_state.measurements.update({'abc': openhtf.Measurement('abc')})
test.test_api.measurements.abc = '34'
test.test_api.measurements.hello_world_measurement = '12'

@openhtf.PhaseOptions(requires_state=True)
def dynamic_meas_with_limits(test):
"""Dynamic measurement phase."""
test.running_phase_state.measurements.update({'vbat': openhtf.Measurement('vbat').in_range(
1, 10).with_units(units.VOLT)})
test.test_api.measurements.vbat = 5

v_sleep = openhtf.Measurement('v_sleep', validators=[validators.in_range(0, 2)], units=units.VOLT)
test.running_phase_state.measurements.update({'v_sleep': v_sleep})
test.test_api.measurements.v_sleep = 0.5

test_phases = (
dynamic_measurement,
dynamic_meas_with_limits
)

if __name__ == '__main__':
test = openhtf.Test(*test_phases, test_name=TEST_NAME)
test.execute(test_start=user_input.prompt_for_test_start('Enter Serial: '))

If we can add a method to expose the _measurement dictionary one can do this more directly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.