google / openhtf

The open-source hardware testing framework.
Apache License 2.0
530 stars 217 forks source link

monitors decorator does not fully copy the specification of the monitored phase #1100

Open glados-verma opened 1 year ago

glados-verma commented 1 year ago

monitor in monitors.py does not copy the specification of the phase being monitored, leading to bugs like #1096 . What's happening in that specific bug is that, monitored_phase_func calls the monitored phase using the test state, thus bypassing the plug registration scheme. So, if the phase needs a plug that isn't registered by another phase, the plug lookup will fail with a KeyError.

Repro example:

import openhtf as htf

class NoOpPlug(htf.plugs.BasePlug):
  """Does nothing."""

def monitor_one(test, *args, **kwargs):
  del test  # Unused.
  return 1

@htf.monitors('f_measurement', monitor_one, poll_interval_ms=100)
@htf.plug(noop=NoOpPlug)
def buggy_monitoring(test, *args, **kwargs):
  del test

def main():
  test = htf.Test(buggy_monitoring)
  test.execute(test_start=lambda: 'MyDutId')

if __name__ == '__main__':
  main()

This particular issue can be fixed by copying over the plugs e.g. in def monitors:

own_plugs = {p.name: p.cls for p in phase_desc.plugs}
...
@plugs.plug(update_kwargs=False, **monitor_plugs, **own_plugs)

But it's not addressing the root of the problem as described earlier.