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

tests: Add integration and acceptance tests for NI-Digital and NI-Switch drivers session management APIs #503

Merged
merged 19 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
707f2fb
tests: set platform to add integration & acceptance tests for nidigital
jayaseelan-james Nov 3, 2023
c4c4377
tests: set platform to add integration & acceptance test for niswitch
jayaseelan-james Nov 3, 2023
df7914e
fix: add pins and sites for nidigital pin map
jayaseelan-james Nov 3, 2023
bd701c8
tests: add assets to integration dir and add niswitch integration tests
jayaseelan-james Nov 3, 2023
9f7008b
tests: add integration tests for nidigital session APIs
jayaseelan-james Nov 3, 2023
bcba397
tests: add acceptance tests for niswitch driver session APIs
jayaseelan-james Nov 6, 2023
4347e38
tests: add acceptance tests for nidigital driver session APIs
jayaseelan-james Nov 6, 2023
6b896c3
fix: lint errors
jayaseelan-james Nov 6, 2023
f6a5685
fix: typo and discard unused attributes in pin map
jayaseelan-james Nov 6, 2023
0d90acf
fix: lint errors
jayaseelan-james Nov 6, 2023
1644c72
refactor: nidigital measurement private api name
jayaseelan-james Nov 6, 2023
d2ae52b
fix: add underscores between when and then clauses
jayaseelan-james Nov 6, 2023
4e80979
fix: remove unused files
jayaseelan-james Nov 7, 2023
5b4a0b2
fix: move digital pattern files to test measurement dir
jayaseelan-james Nov 7, 2023
7b7abee
tests: pass all the pins to the test measurement
jayaseelan-james Nov 7, 2023
a982e1e
style: import nims namespace for TypedSession
jayaseelan-james Nov 7, 2023
0175e3f
tests: remove wait logic & standardize terminology
jayaseelan-james Nov 8, 2023
9a065ac
fix: lint errors
jayaseelan-james Nov 8, 2023
2e5b9b7
fix: more inner method to private method due to mypy error
jayaseelan-james Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions tests/acceptance/test_nidigital_measurement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import pathlib
from typing import Generator, Iterable, NamedTuple

import pytest

from ni_measurementlink_service._internal.stubs.ni.measurementlink.measurement.v2.measurement_service_pb2 import (
MeasureRequest,
)
from ni_measurementlink_service._internal.stubs.ni.measurementlink.measurement.v2.measurement_service_pb2_grpc import (
MeasurementServiceStub,
)
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pin_map_context_pb2 import (
PinMapContext,
)
from ni_measurementlink_service.measurement.service import MeasurementService
from tests.assets.stubs.nidigital_measurement.types_pb2 import Configurations, Outputs
from tests.utilities import nidigital_measurement
from tests.utilities.pin_map_client import PinMapClient


def test___single_session___measure___returns_measured_values(
pin_map_id: str,
stub_v2: MeasurementServiceStub,
) -> None:
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=[0])
configurations = Configurations(pin_names=["CS", "SCLK", "MOSI", "MISO"], multi_session=False)

outputs = _measure(stub_v2, pin_map_context, configurations)

assert outputs.passing_sites == [0]
assert outputs.failing_sites == []


def test___single_session___measure___creates_single_session(
pin_map_id: str,
stub_v2: MeasurementServiceStub,
) -> None:
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=[0])
configurations = Configurations(pin_names=["CS", "SCLK", "MOSI", "MISO"], multi_session=False)

outputs = _measure(stub_v2, pin_map_context, configurations)

assert _get_output(outputs) == [
_MeasurementOutput(
"DigitalPattern1",
"DigitalPattern1",
"site0/CS, site0/SCLK, site0/MOSI, site0/MISO",
"site0/CS",
)
]


def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_id: str,
stub_v2: MeasurementServiceStub,
) -> None:
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=[0, 1])
configurations = Configurations(pin_names=["CS"], multi_session=True)
jayaseelan-james marked this conversation as resolved.
Show resolved Hide resolved

outputs = _measure(stub_v2, pin_map_context, configurations)

assert _get_output(outputs) == [
_MeasurementOutput(
"DigitalPattern1",
"DigitalPattern1",
"site0/CS",
"site0/CS",
),
_MeasurementOutput(
"DigitalPattern2",
"DigitalPattern2",
"site1/CS",
"site1/CS",
),
]


def _measure(
stub_v2: MeasurementServiceStub,
pin_map_context: PinMapContext,
configurations: Configurations,
) -> Outputs:
request = MeasureRequest(pin_map_context=pin_map_context)
request.configuration_parameters.Pack(configurations)
response_iterator = stub_v2.Measure(request)
responses = list(response_iterator)
assert len(responses) == 1
outputs = Outputs.FromString(responses[0].outputs.value)
return outputs


@pytest.fixture(scope="module")
def measurement_service() -> Generator[MeasurementService, None, None]:
"""Test fixture that creates and hosts a measurement service."""
with nidigital_measurement.measurement_service.host_service() as service:
yield service


@pytest.fixture
def pin_map_id(pin_map_client: PinMapClient, pin_map_directory: pathlib.Path) -> str:
pin_map_name = "2Digital2Group4Pin1Site.pinmap"
return pin_map_client.update_pin_map(pin_map_directory / pin_map_name)


class _MeasurementOutput(NamedTuple):
session_name: str
resource_name: str
channel_list: str
connected_channels: str


def _get_output(outputs: Outputs) -> Iterable[_MeasurementOutput]:
return [
_MeasurementOutput(session_name, resource_name, channel_list, connected_channels)
for session_name, resource_name, channel_list, connected_channels in zip(
outputs.session_names,
outputs.resource_names,
outputs.channel_lists,
outputs.connected_channels,
)
]
96 changes: 96 additions & 0 deletions tests/acceptance/test_niswitch_measurement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import pathlib
from typing import Generator, Iterable, NamedTuple

import pytest

from ni_measurementlink_service._internal.stubs.ni.measurementlink.measurement.v2.measurement_service_pb2 import (
MeasureRequest,
)
from ni_measurementlink_service._internal.stubs.ni.measurementlink.measurement.v2.measurement_service_pb2_grpc import (
MeasurementServiceStub,
)
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pin_map_context_pb2 import (
PinMapContext,
)
from ni_measurementlink_service.measurement.service import MeasurementService
from tests.assets.stubs.niswitch_measurement.types_pb2 import (
Configurations,
Outputs,
)
from tests.utilities import niswitch_measurement
from tests.utilities.pin_map_client import PinMapClient

_SITE = 0


def test___single_session___measure___creates_single_session(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
bkeryan marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
configurations = Configurations(relay_names=["SiteRelay1"], multi_session=False)

outputs = _measure(stub_v2, pin_map_context, configurations)

assert _get_output(outputs) == [_MeasurementOutput("RelayDriver1", "RelayDriver1", "K0", "K0")]


def test___multiple_sessions___measure___creates_multiple_sessions(
pin_map_context: PinMapContext,
stub_v2: MeasurementServiceStub,
) -> None:
configurations = Configurations(relay_names=["SiteRelay1", "SiteRelay2"], multi_session=True)

outputs = _measure(stub_v2, pin_map_context, configurations)

assert _get_output(outputs) == [
_MeasurementOutput("RelayDriver1", "RelayDriver1", "K0", "K0"),
_MeasurementOutput("RelayDriver2", "RelayDriver2", "K1", "K1"),
]


def _measure(
stub_v2: MeasurementServiceStub,
pin_map_context: PinMapContext,
configurations: Configurations,
) -> Outputs:
request = MeasureRequest(pin_map_context=pin_map_context)
request.configuration_parameters.Pack(configurations)
response_iterator = stub_v2.Measure(request)
responses = list(response_iterator)
assert len(responses) == 1
outputs = Outputs.FromString(responses[0].outputs.value)
return outputs


@pytest.fixture(scope="module")
def measurement_service() -> Generator[MeasurementService, None, None]:
"""Test fixture that creates and hosts a measurement service."""
with niswitch_measurement.measurement_service.host_service() as service:
yield service


@pytest.fixture
def pin_map_context(pin_map_client: PinMapClient, pin_map_directory: pathlib.Path) -> PinMapContext:
pin_map_name = "2Switch2Relay1Site.pinmap"
pin_map_id = pin_map_client.update_pin_map(pin_map_directory / pin_map_name)

return PinMapContext(pin_map_id=pin_map_id, sites=[_SITE])


class _MeasurementOutput(NamedTuple):
session_name: str
resource_name: str
channel_list: str
connected_channels: str


def _get_output(outputs: Outputs) -> Iterable[_MeasurementOutput]:
return [
_MeasurementOutput(session_name, resource_name, channel_list, connected_channels)
for session_name, resource_name, channel_list, connected_channels in zip(
outputs.session_names,
outputs.resource_names,
outputs.channel_lists,
outputs.connected_channels,
)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<PinMap schemaVersion="1.5" xmlns="http://www.ni.com/TestStand/SemiconductorModule/PinMap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Instruments>
<NIDigitalPatternInstrument name="DigitalPattern1" numberOfChannels="32" group="Digital0" />
<NIDigitalPatternInstrument name="DigitalPattern2" numberOfChannels="32" group="Digital1" />
</Instruments>
<Pins>
<DUTPin name="CS" />
<DUTPin name="SCLK" />
<DUTPin name="MOSI" />
<DUTPin name="MISO" />
</Pins>
<PinGroups></PinGroups>
<Sites>
<Site siteNumber="0" />
<Site siteNumber="1" />
</Sites>
<Connections>
<Connection pin="CS" siteNumber="0" instrument="DigitalPattern1" channel="0" />
<Connection pin="SCLK" siteNumber="0" instrument="DigitalPattern1" channel="1" />
<Connection pin="MOSI" siteNumber="0" instrument="DigitalPattern1" channel="2" />
<Connection pin="MISO" siteNumber="0" instrument="DigitalPattern1" channel="3" />
<Connection pin="CS" siteNumber="1" instrument="DigitalPattern2" channel="0" />
<Connection pin="SCLK" siteNumber="1" instrument="DigitalPattern2" channel="1" />
<Connection pin="MOSI" siteNumber="1" instrument="DigitalPattern2" channel="2" />
<Connection pin="MISO" siteNumber="1" instrument="DigitalPattern2" channel="3" />
</Connections>
</PinMap>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<PinMap xmlns="http://www.ni.com/TestStand/SemiconductorModule/PinMap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.4">
<Instruments>
<NIRelayDriverModule name="RelayDriver1" numberOfControlLines="64" />
<NIRelayDriverModule name="RelayDriver2" numberOfControlLines="64" />
</Instruments>
<Pins></Pins>
<PinGroups></PinGroups>
<Relays>
<SiteRelay name="SiteRelay1" />
<SiteRelay name="SiteRelay2" />
</Relays>
<RelayGroups></RelayGroups>
<Sites>
<Site siteNumber="0" />
</Sites>
<Connections>
<RelayConnection relay="SiteRelay1" siteNumber="0" relayDriverModule="RelayDriver1" controlLine="K0" />
<RelayConnection relay="SiteRelay2" siteNumber="0" relayDriverModule="RelayDriver2" controlLine="K1" />
</Connections>
</PinMap>
Binary file not shown.
51 changes: 51 additions & 0 deletions tests/assets/acceptance/session_management/PinLevels.digilevels
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<PinLevelsFile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.0" xmlns="http://www.ni.com/Semiconductor/PinLevels">
<PinLevelsSheet>
<DigitalPinLevelSets>
<DigitalPinLevelSet pin="CS">
<Vil>dc.vcc * 0.7</Vil>
<Vih>0</Vih>
<Vol>2.5</Vol>
<Voh>0.5</Voh>
<Iol>1.5 m</Iol>
<Ioh>-1.5 m</Ioh>
<Vcom>0</Vcom>
<Vterm>0</Vterm>
<TerminationMode>HighZ</TerminationMode>
</DigitalPinLevelSet>
<DigitalPinLevelSet pin="SCLK">
<Vil>dc.vcc * 0.7</Vil>
<Vih>0</Vih>
<Vol>2.5</Vol>
<Voh>0.5</Voh>
<Iol>1.5 m</Iol>
<Ioh>-1.5 m</Ioh>
<Vcom>0</Vcom>
<Vterm>0</Vterm>
<TerminationMode>HighZ</TerminationMode>
</DigitalPinLevelSet>
<DigitalPinLevelSet pin="MOSI">
<Vil>dc.vcc * 0.7</Vil>
<Vih>0</Vih>
<Vol>2.5</Vol>
<Voh>0.5</Voh>
<Iol>1.5 m</Iol>
<Ioh>-1.5 m</Ioh>
<Vcom>0</Vcom>
<Vterm>0</Vterm>
<TerminationMode>HighZ</TerminationMode>
</DigitalPinLevelSet>
<DigitalPinLevelSet pin="MISO">
<Vil>dc.vcc * 0.7</Vil>
<Vih>0</Vih>
<Vol>2.5</Vol>
<Voh>0.5</Voh>
<Iol>1.5 m</Iol>
<Ioh>-1.5 m</Ioh>
<Vcom>0</Vcom>
<Vterm>0</Vterm>
<TerminationMode>HighZ</TerminationMode>
</DigitalPinLevelSet>
</DigitalPinLevelSets>
</PinLevelsSheet>
</PinLevelsFile>
16 changes: 16 additions & 0 deletions tests/assets/acceptance/session_management/Specifications.specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Specifications xmlns:f="http://www.ni.com/schemas/Semiconductor/Formula.xsd" schemaVersion="1.0" xmlns="http://www.ni.com/schemas/Semiconductor/Specifications.xsd">
<Section name="dc">
<f:Formula symbol="vcc">
<f:Definition>5</f:Definition>
<f:Description>V</f:Description>
</f:Formula>
</Section>
<Section name="ac">
<f:Formula symbol="period">
<f:Definition>1 / 1000000</f:Definition>
<f:Description>1 MHz</f:Description>
</f:Formula>
</Section>
<Description />
</Specifications>
Loading