-
Notifications
You must be signed in to change notification settings - Fork 210
Improved tests #3296
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
base: yarp-3.12
Are you sure you want to change the base?
Improved tests #3296
Conversation
|
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would update the release notes by adding a file in |
Summary of ChangesHello @randaz81, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly strengthens the testing framework for YARP device drivers by introducing a dedicated mechanism to verify the handling of unimplemented methods. It ensures that both local and network-wrapped fake devices can correctly signal and respond to calls for non-existent functionalities, thereby improving the robustness and predictability of device interactions within the YARP ecosystem. Additionally, it expands the RPC capabilities of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a new method doSomethingUnimplemented to test the handling of unimplemented functions in device drivers, and also adds RPC capabilities to FakeDeviceWrapper. The changes for doSomethingUnimplemented are well-implemented across the different device types (unwrapped, nwc, nws).
My review focuses on the new RPC implementation in FakeDeviceWrapper, where I've identified and suggested fixes for a few issues, including a hardcoded value, a missing return value in the reply, and lack of input validation. I've also suggested a couple of minor refactorings to improve code clarity and maintainability.
| if (command.get(0).asString() == "testSetValue") | ||
| { | ||
| retval = testSetValue(1); | ||
| if (retval) {reply.addVocab32(VOCAB_OK);} | ||
| else {reply.addVocab32(VOCAB_ERR);} | ||
| } | ||
| else | ||
| if (command.get(0).asString() == "testGetValue") | ||
| { | ||
| int val=0; | ||
| retval = testGetValue(val); | ||
| if (retval) { | ||
| reply.addVocab32(VOCAB_OK); | ||
| } | ||
| else { | ||
| reply.addVocab32(VOCAB_ERR); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| reply.addVocab32(VOCAB_ERR); | ||
| } |
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.
The RPC command handler in the read method has several issues that should be addressed:
- Hardcoded value: The
testSetValuecommand uses a hardcoded value of1instead of parsing it from the command bottle. - Missing return value: The
testGetValuecommand does not include the retrieved value in the reply bottle. - Lack of validation: There are no checks for the number of arguments or their types, which can lead to runtime errors.
- Code style: The
else ifformatting is unconventional.
I suggest refactoring this block to make it more robust, correct, and readable.
if (command.get(0).asString() == "testSetValue")
{
if (command.size() >= 2 && command.get(1).isInt32()) {
retval = testSetValue(command.get(1).asInt32());
reply.addVocab32(retval ? VOCAB_OK : VOCAB_ERR);
} else {
yCError(FAKEDEVICEWRAPPER) << "testSetValue command requires an integer argument.";
reply.addVocab32(VOCAB_ERR);
}
}
else if (command.get(0).asString() == "testGetValue")
{
int val = 0;
retval = testGetValue(val);
if (retval) {
reply.addVocab32(VOCAB_OK);
reply.addInt32(val);
} else {
reply.addVocab32(VOCAB_ERR);
}
}
else
{
yCWarning(FAKEDEVICEWRAPPER) << "Unknown command:" << command.toString();
reply.addVocab32(VOCAB_ERR);
}| #include <yarp/os/Log.h> | ||
| #include <yarp/os/LogComponent.h> | ||
| #include <yarp/os/LogStream.h> | ||
| #include <yarp/dev/ControlBoardInterfaces.h> |
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.
| yarp::dev::ReturnValue ret = m_iFake->doSomethingUnimplemented(); | ||
| if (!ret) | ||
| { | ||
| yCError(FAKEDEVICESERVER, "doSomethingUnimplemented() failed"); | ||
| return ret; | ||
| } | ||
|
|
||
| return yarp::dev::ReturnValue_ok; |
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.
The implementation of doSomethingUnimplementedRPC is functionally correct, but it can be simplified for better readability and maintainability. The logic of checking the return value and then returning can be made more concise. Also, the error message could be more informative by including the reason for failure.
| yarp::dev::ReturnValue ret = m_iFake->doSomethingUnimplemented(); | |
| if (!ret) | |
| { | |
| yCError(FAKEDEVICESERVER, "doSomethingUnimplemented() failed"); | |
| return ret; | |
| } | |
| return yarp::dev::ReturnValue_ok; | |
| yarp::dev::ReturnValue ret = m_iFake->doSomethingUnimplemented(); | |
| if (!ret) | |
| { | |
| yCError(FAKEDEVICESERVER) << "doSomethingUnimplemented() failed with error:" << ret.toString(); | |
| } | |
| return ret; |
cb7abd6 to
790352c
Compare
improved tests to check unimplemented methods in device drivers