Skip to content

Commit

Permalink
Automatically power on the dut
Browse files Browse the repository at this point in the history
  • Loading branch information
sreckamp committed Feb 2, 2024
1 parent a5330c9 commit 0d1f36d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
30 changes: 18 additions & 12 deletions benchmark/runner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from power_manager import PowerManager
from io_manager import IOManager

from contextlib import nullcontext
from serial.tools import list_ports
import yaml

Expand All @@ -28,8 +29,10 @@ def run_dut_test():
dut passthrough: profile
"""

def test_dut(device):
with device as dut:
def test_dut(dut_def):
if dut_def and "instance" in dut_def:
with dut_def.get("power") if "power" in dut_def else nullcontext:
with dut_def["instance"] as dut:
print(dut.get_name())
print(dut.get_model())
print(dut.get_profile())
Expand Down Expand Up @@ -79,23 +82,26 @@ def scan_devices(devices=None):
if found: break


def init_dut(dut_def):
if dut_def and "instance" in dut_def:
with dut_def.get("power") if "power" in dut_def else nullcontext:
with dut_def["instance"] as dut:
dut.get_name()
dut.get_model()
dut.get_profile()

def identify_dut(tools):
interface = tools.get("interface", {}).get("instance")
power = tools.get("power", {}).get("instance")
if not tools.get("dut") and interface and power:
dut = DUT(interface)
tools["dut"] = {
"instance": dut
"instance": dut,
"power": power
}
# power.on()
else:
dut = tools.get("dut", {}).get("instance")
if dut:
with dut:
dut.get_name()
dut.get_model()
dut.get_profile()

init_dut(tools.get("dut"))


def instantiate(device):
Expand Down Expand Up @@ -131,15 +137,15 @@ def run_test(device_list, dut, test_script):
devices = yaml.load(dev_file, Loader=yaml.CLoader)
tools = build_tools(devices)
identify_dut(tools)
for i in (t.get("instance") for t in tools.values() if t and t.get("instance")):
for _def, i in ((t, t.get("instance")) for t in tools.values() if t and t.get("instance")):
if isinstance(i, PowerManager):
test_power(i)
elif isinstance(i, IOManagerEnhanced):
test_io_manager_enhanced(i)
elif isinstance(i, IOManager):
test_io_manager(i)
elif isinstance(i, DUT):
test_dut(i)
test_dut(_def)


if __name__ == '__main__':
Expand Down
11 changes: 9 additions & 2 deletions benchmark/runner/power_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _read_loop(self):
line = self._port.read_line(timeout=250)
if line is None:
continue
# print(f"RX: {line}")
if line.startswith("TimeStamp"):
print(line, file=sys.stderr)
self._data_queue.put(line)
Expand All @@ -47,6 +48,7 @@ def _read_loop(self):
self._message_queue.put(line)

def _start_read_thread(self):
self._running = True
self._read_thread = Thread(target=self._read_loop)
self._read_thread.start()

Expand All @@ -68,6 +70,7 @@ def _setup(self):
self.configure_trigger(0, 0, 'd7', 'fal')
self.configure_output('energy', 'ascii_dec', 1000)
self.set_voltage(3000)
self.power_on()

def _tear_down(self):
self._send_command("hrc")
Expand Down Expand Up @@ -110,8 +113,11 @@ def configure_output(self, output_type, output_format, samples_per_second):
self._send_command(f"freq {samples_per_second}",
err_message=f"Error setting samples_per_second to {samples_per_second}")

def power_on(self, show_status=False):
self._send_command(f"pwr on {'' if show_status else 'no'}status", err_message=f"Error turning on power")

def power_off(self):
self._send_command("targrst 0", err_message=f"Error turning off power")
self._send_command("pwr off", err_message=f"Error turning off power")

def set_voltage(self, millivolts):
self._send_command(f"volt {millivolts}m", err_message=f"Error setting voltage to {millivolts}mV")
Expand Down Expand Up @@ -154,6 +160,7 @@ def _read_response(self, command):
out_lines = []
while True:
line = self._message_queue.get()
# print(f"RES: {line}")
temp = line.replace(PowerManager.PROMPT, "").strip()
if temp and command in temp and (temp.startswith('ack') or temp.startswith('error')):
out_lines.extend(r for r in temp.replace(command, "").split(" ", 2) if r)
Expand All @@ -172,7 +179,7 @@ def _read_error_output(self):
def _read_output(self):
while True:
line = self._message_queue.get()
print(f"RX: {line}")
# print(f"OUT: {line}")
if line == PowerManager.PROMPT:
return
line = line.replace(PowerManager.PROMPT, "").strip()
Expand Down

0 comments on commit 0d1f36d

Please sign in to comment.