-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_pvaccess.py
More file actions
95 lines (73 loc) · 2.78 KB
/
test_pvaccess.py
File metadata and controls
95 lines (73 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import asyncio
from contextlib import nullcontext
import pytest
from conftest import (
aioca_cleanup,
log,
create_random_prefix,
TIMEOUT,
select_and_recv,
get_multiprocessing_context,
)
from softioc import asyncio_dispatcher, builder, softioc
class TestPVAccess:
"""Tests related to PVAccess"""
record_name = "PVA_AOut"
record_value = 10
def pva_test_func(self, device_name, conn, use_pva):
builder.SetDeviceName(device_name)
builder.aOut(self.record_name, initial_value=self.record_value)
dispatcher = asyncio_dispatcher.AsyncioDispatcher()
builder.LoadDatabase()
softioc.iocInit(dispatcher=dispatcher, enable_pva=use_pva)
conn.send("R") # "Ready"
log("CHILD: Sent R over Connection to Parent")
# Keep process alive while main thread works.
while (True):
if conn.poll(TIMEOUT):
val = conn.recv()
if val == "D": # "Done"
break
@pytest.mark.asyncio
@pytest.mark.parametrize(
"use_pva,expectation",
[
(True, nullcontext()),
(False, pytest.raises(asyncio.TimeoutError))
]
)
async def test_pva_enable_disable(self, use_pva, expectation):
"""Test that we can enable and disable PVA, perform PVAccess requests
when enabled, and that we can always do Channel Access requests"""
ctx = get_multiprocessing_context()
parent_conn, child_conn = ctx.Pipe()
device_name = create_random_prefix()
process = ctx.Process(
target=self.pva_test_func,
args=(device_name, child_conn, use_pva),
)
process.start()
from aioca import caget
from p4p.client.asyncio import Context
try:
# Wait for message that IOC has started
select_and_recv(parent_conn, "R")
record_full_name = device_name + ":" + self.record_name
ret_val = await caget(record_full_name, timeout=TIMEOUT)
assert ret_val == self.record_value
with expectation as _:
with Context("pva") as ctx:
# Short timeout as, if the above CA connection has happened
# there's no need to wait a very long time for the PVA
# connection
pva_val = await asyncio.wait_for(
ctx.get(record_full_name),
timeout=2
)
assert pva_val == self.record_value
finally:
# Clear the cache before stopping the IOC stops
# "channel disconnected" error messages
aioca_cleanup()
parent_conn.send("D") # "Done"
process.join(timeout=TIMEOUT)