Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push sams changes from station-4 #6

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions openhtf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""The main OpenHTF entry point."""

import signal
import sys
import typing

from openhtf.core import phase_executor
Expand Down Expand Up @@ -112,6 +113,7 @@
Subtest = openhtf.core.phase_collections.Subtest

diagnose = openhtf.core.phase_descriptor.diagnose

measures = openhtf.core.phase_descriptor.measures
PhaseDescriptor = openhtf.core.phase_descriptor.PhaseDescriptor
PhaseNameCase = openhtf.core.phase_descriptor.PhaseNameCase
Expand Down Expand Up @@ -147,3 +149,7 @@ def get_version():

# Register signal handler to stop all tests on SIGINT.
Test.DEFAULT_SIGINT_HANDLER = signal.signal(signal.SIGINT, Test.handle_sig_int)

if sys.version_info.major == 3 and sys.version_info.minor >= 10:
import collections
setattr(collections, "MutableMapping", collections.abc.MutableMapping)
15 changes: 15 additions & 0 deletions openhtf/core/dut_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dataclasses import dataclass
from typing import Optional
from dataclasses import dataclass


@dataclass
class DutIdentifier:
halter_serial_number: Optional [str] = None
mac_address: Optional[str] = None
part_number: Optional[str] = None
additional: Optional[dict] = None

@property
def test_id(self) -> str:
return self.halter_serial_number
15 changes: 12 additions & 3 deletions openhtf/core/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from openhtf.core import test_executor
from openhtf.core import test_record as htf_test_record
from openhtf.core import test_state
from openhtf.core.dut_id import DutIdentifier

from openhtf.util import configuration
from openhtf.util import console_output
Expand Down Expand Up @@ -276,7 +277,9 @@ def abort_from_sig_int(self) -> None:

def execute(self,
test_start: Optional[Union[phase_descriptor.PhaseT,
Callable[[], str]]] = None,
Callable[[], str],
Callable[[], DutIdentifier],
]] = None,
profile_filename: Optional[Text] = None) -> bool:
"""Starts the framework and executes the given test.

Expand All @@ -300,7 +303,7 @@ def execute(self,
self._test_desc.phase_sequence)
# Lock this section so we don't .stop() the executor between instantiating
# it and .Start()'ing it, doing so does weird things to the executor state.
with self._lock:
with (self._lock):
# Sanity check to make sure someone isn't doing something weird like
# trying to Execute() the same test twice in two separate threads. We
# hold the lock between here and Start()'ing the executor to guarantee
Expand All @@ -317,7 +320,13 @@ def execute(self,

@phase_descriptor.PhaseOptions()
def trigger_phase(test):
test.test_record.dut_id = typing.cast(types.LambdaType, test_start)()
dut_id = typing.cast(types.LambdaType, test_start)()
if isinstance(dut_id, DutIdentifier):
test.test_record.dut_id = dut_id.test_id
test.test_record.dut_extended_id = dut_id
else:
test.test_record.dut_id = dut_id
test.test_record.dut_extended_id = DutIdentifier()

trigger = trigger_phase
else:
Expand Down
4 changes: 4 additions & 0 deletions openhtf/core/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import enum
import hashlib
import inspect
import json
import logging
import os
import tempfile
Expand All @@ -24,6 +25,7 @@
import attr

from openhtf import util
from openhtf.core.dut_id import DutIdentifier
from openhtf.util import configuration
from openhtf.util import data
from openhtf.util import logs
Expand Down Expand Up @@ -167,6 +169,7 @@ class TestRecord(object):
"""The record of a single run of a test."""

dut_id = attr.ib(type=Optional[Text])
dut_extended_id = attr.ib(type=Optional[DutIdentifier])
station_id = attr.ib(type=Text)
start_time_millis = attr.ib(type=int, default=0)
end_time_millis = attr.ib(type=Optional[int], default=None)
Expand Down Expand Up @@ -250,6 +253,7 @@ def as_base_types(self) -> Dict[Text, Any]:
metadata['config'] = self._cached_config_from_metadata
ret = {
'dut_id': data.convert_to_base_types(self.dut_id),
#'dut_extended_id': data.convert_to_base_types (self.dut_extended_id),
'start_time_millis': self.start_time_millis,
'end_time_millis': self.end_time_millis,
'outcome': data.convert_to_base_types(self.outcome),
Expand Down
1 change: 1 addition & 0 deletions openhtf/core/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def __init__(self, test_desc: 'test_descriptor.TestDescriptor',

self.test_record = test_record.TestRecord(
dut_id=None,
dut_extended_id=None,
station_id=CONF.station_id,
code_info=test_desc.code_info,
start_time_millis=0,
Expand Down