-
Notifications
You must be signed in to change notification settings - Fork 51
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
RFC: Add SetRuntimeEnvironment call for NI-DCPower #962
RFC: Add SetRuntimeEnvironment call for NI-DCPower #962
Conversation
TODO: update tests? Maybe testing should be done with nifake? |
@@ -44,6 +45,10 @@ ${service_class_prefix}Library::${service_class_prefix}Library() : shared_librar | |||
%>\ | |||
function_pointers_.${method_name} = reinterpret_cast<${method_name}Ptr>(shared_library_.get_function_pointer("${c_name}")); | |||
% endfor | |||
% if 'SetRuntimeEnvironment' in service_helpers.filter_api_functions(functions, only_mockable_functions=False): | |||
|
|||
this->SetRuntimeEnvironment(nidevice_grpc::NIDEVICE_GRPC_ORIGINALFILENAME.c_str(), nidevice_grpc::NIDEVICE_GRPC_FILEVERSION.c_str(), "", ""); |
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.
Maybe I need to do a try, catch in case this errors?
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.
Rather than adding specific logic for a specific function, it might be better to define this requirement in the metadata and use that to add any extra "initialization functions" so that this is extensible to other functions in the future. I'll defer to @reckenro or @astarche on that since they know more about the code generation, though.
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.
This isn't Python where you ask for forgiveness, not for permission :)
Best not to throw unless an error truly happened.
I think ideally, you have a well documented function that only calls into the driver if the function is indeed present. That means you don't rely on the codegenerated wrapper as-is.
I don't know how accessible the things you would need are. If they aren't then maybe it's fine to try/catch, not the end of the world.
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.
Like Marcos, I was expecting something like:
if (function_pointers_.SetRuntimeEnvironment) {
function_pointers_.SetRuntimeEnvironment(environment, environmentVersion, reserved1, reserved2);
}
But I agree that try/catch is not the end of the world.
I'm always a fan of adding metadata conventions. But I think there's already a strong convention in the drivers to implement/use SetRuntimeEnvironment
in this way and that it's implemented similarly in nimi-python
so I'm happy for the team to use their judgement on it.
Is it possible that we'd want to automatically add SetRuntimeEnvironment
even if drivers don't declare it in their metadata? If the convention is strong enough, it can be better to have it be global.
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.
I actually just added that check.
Let me know if you think I need to document the reason for the call.
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.
Rather than adding specific logic for a specific function, it might be better to define this requirement in the metadata and use that to add any extra "initialization functions" so that this is extensible to other functions in the future. I'll defer to @reckenro or @astarche on that since they know more about the code generation, though.
I'll stick with the YAGNI (You Ain't Gonna Need It) principle and avoid overcomplicating it, since I haven't been told other wise.
I'm not sure why the validate_python check failed. I don't think it's related to my changes. |
@@ -44,6 +45,10 @@ ${service_class_prefix}Library::${service_class_prefix}Library() : shared_librar | |||
%>\ | |||
function_pointers_.${method_name} = reinterpret_cast<${method_name}Ptr>(shared_library_.get_function_pointer("${c_name}")); | |||
% endfor | |||
% if 'SetRuntimeEnvironment' in service_helpers.filter_api_functions(functions, only_mockable_functions=False): | |||
|
|||
this->SetRuntimeEnvironment(nidevice_grpc::NIDEVICE_GRPC_ORIGINALFILENAME.c_str(), nidevice_grpc::NIDEVICE_GRPC_FILEVERSION.c_str(), "", ""); |
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.
Rather than adding specific logic for a specific function, it might be better to define this requirement in the metadata and use that to add any extra "initialization functions" so that this is extensible to other functions in the future. I'll defer to @reckenro or @astarche on that since they know more about the code generation, though.
black 23.7 was released a week ago and it dropped Python 3.7 support. validate_examples.py generates temporary Poetry projects on the fly, which is kind of unusual. It sounds like Cc: @mshafer-NI |
@@ -44,6 +45,10 @@ ${service_class_prefix}Library::${service_class_prefix}Library() : shared_librar | |||
%>\ | |||
function_pointers_.${method_name} = reinterpret_cast<${method_name}Ptr>(shared_library_.get_function_pointer("${c_name}")); | |||
% endfor | |||
% if 'SetRuntimeEnvironment' in service_helpers.filter_api_functions(functions, only_mockable_functions=False): | |||
|
|||
this->SetRuntimeEnvironment(nidevice_grpc::NIDEVICE_GRPC_ORIGINALFILENAME.c_str(), nidevice_grpc::NIDEVICE_GRPC_FILEVERSION.c_str(), "", ""); |
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.
This isn't Python where you ask for forgiveness, not for permission :)
Best not to throw unless an error truly happened.
I think ideally, you have a well documented function that only calls into the driver if the function is indeed present. That means you don't rely on the codegenerated wrapper as-is.
I don't know how accessible the things you would need are. If they aren't then maybe it's fine to try/catch, not the end of the world.
Created #963 to address the issue. |
* Use constexpr to avoid codebloat * Follow naming conventions * Eliminate unused constants * Add comment to CMakeLists.txt
I've been thinking about how to test that SetRuntimeEnvironment is called when it should be and not called when it shouldn't be.
@reckenro @astarche How would you feel about me tweaking the Library classes to have the SharedLibrary type passed to the constructor (so that a test could pass a mock or fake)? |
@ni-jfitzger @reckenro Passing in the shared library sounds alright to me. I believe you could make it a Seems more likely that this code would fail because So overall: sounds good. |
This PR is being abandonded in favor of #973 |
Note that the
With mocking, you don't need a dummy DLL. You can set up the
Is it hard to write a C++ test that logs ETW events? In C#, we have test utilities for writing tests that capture ETW events for CEIP or whatever. |
What does this Pull Request accomplish?
Add an NiDCPowerLibrary::SetRuntimeEnvironment call upon library load, before init is called.
Implemented via the following changes:
source/codegen/metadata/nidcpower/functions_addon.py
to privately add the SetRuntimeEnvironment functionsource/codegen/metadata/nidcpower/__init__.py
so that the new metadata will be merged. I merged metadata for attributes, functions and enums. I didn't mess with config_addon.py, though.Why should this Pull Request be merged?
As developers, we want to know how much nigrpc_device_server is used and which versions.
What testing has been done?
TODOs: