-
Notifications
You must be signed in to change notification settings - Fork 9
Allow starting IOC without PVA #186
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason we shouldn't defer all dbd and lib loading until iocInit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR there is no longer any lib loading anywhere except in
iocInit().You must load the DBD files before creating records, otherwise epicsdbbuilder / EPICS itself doesn't know what to do with the record entries. So I believe we must do that as early as possible.
For research I tried moving the DBD loading into this function, and it results in a segmentation fault as soon as you try and create a record (presumably EPICS is attempting to call some kind of validation function related to the DBD and doesn't have proper null checks somewhere)