Commit 86e22b64 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

test: added hardware axis test.

Generic test for real axis test on beamline.
parent 88e0725f
......@@ -65,11 +65,17 @@ Equivalent to `--capture=no` => do not capture stdout
Hardware tests are ignored by continuous integration but can be run manualy
How ?
### Axis
The is a generic axis test for basic feature: position, velocity, acceleration and stop.
Example ?
Example:
pytest -s --axis-name rot tests/controllers_hw/test_axis.py
This will do a real test an *Beamline* axis named **rot**.
!!! warning
This test will do real movement on the specified axis
## Configuration in BLISS
......
......@@ -252,3 +252,4 @@ def session(beacon):
def pytest_addoption(parser):
parser.addoption("--pepu", help="pepu host name")
parser.addoption("--ct2", help="ct2 address")
parser.addoption("--axis-name", help="axis name")
......@@ -7,9 +7,29 @@
import pytest
from bliss.config.channels import clear_cache, Bus
from bliss.config import static
from bliss.config.conductor import client
from bliss.config.conductor.client import get_default_connection
@pytest.fixture
def beacon_beamline():
static.CONFIG = None
client._default_connection = None
config = static.get_config()
connection = get_default_connection()
yield config
clear_cache()
Bus.clear_cache()
config._clear_instances()
connection.close()
client._default_connection = None
static.CONFIG = None
def pytest_collection_modifyitems(config, items):
devices = ["pepu", "ct2"]
devices = ["pepu", "ct2", "axis"]
for name in devices:
try:
if config.getoption("--%s" % name):
......
"""Axis motor hardware tests.
Run with:
$ pytest --axis-name <axis-name>
"""
import pytest
import time
import gevent
@pytest.fixture
def axis(request, beacon_beamline):
axis_name = request.config.getoption("--axis-name")
axis = beacon_beamline.get(axis_name)
try:
yield axis
finally:
axis.close()
def test_hw_axis_init(axis):
axis.controller._initialize_axis(axis)
def test_hw_axis_move(axis):
start_position = axis.position()
axis.move(start_position + 1.0)
end_position = axis.position()
try:
assert start_position + 1.0 == pytest.approx(end_position, 0.01)
finally:
axis.move(start_position)
def test_hw_axis_velocity(axis):
start_position = axis.position()
start_velocity = axis.velocity()
delta_pos = 1.0 + 2.0 * axis.acceleration() * axis.acctime() ** 2
try:
start_time = time.time()
axis.move(start_position + delta_pos)
end_time = time.time()
move_time = end_time - start_time
axis.move(start_position)
test_velocity = start_velocity / 2.0
axis.velocity(test_velocity)
assert pytest.approx(axis.velocity(), test_velocity)
start_time = time.time()
axis.move(start_position + delta_pos)
end_time = time.time()
move_time_half_speed = end_time - start_time
assert move_time < move_time_half_speed
finally:
axis.velocity(start_velocity)
axis.move(start_position)
def test_hw_axis_acceleration_set_read(axis):
start_acceleration = axis.acceleration()
try:
axis.acceleration(start_acceleration / 2)
assert start_acceleration / 2 == pytest.approx(
axis.acceleration(), start_acceleration / 100.0
)
finally:
axis.acceleration(start_acceleration)
def test_hw_axis_stop(axis):
start_position = axis.position()
delta_pos = 1.0 + 2.0 * axis.acceleration() * axis.acctime() ** 2
delta_time = 2.0 * axis.acctime() + 1.0 / axis.velocity()
try:
axis.move(start_position + delta_pos, wait=False)
gevent.sleep(axis.acctime())
gevent.sleep(delta_time / 2.0)
axis.stop()
assert axis.position() < start_position + delta_pos
finally:
axis.move(start_position)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment