-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add test for forcetorque plugin #30
Conversation
Thanks @lucapa17, some preliminary comments:
so something is not working as expected. |
tests/forcetorque/CMakeLists.txt
Outdated
project(GTestSetup) | ||
|
||
# Find Gazebo | ||
find_package(gz-sim7 REQUIRED) | ||
set(GZ_SIM_VER ${gz-sim7_VERSION_MAJOR}) |
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.
These lines are not requested, and can be removed to reduce the noise in the code. project
is only required in the root CMakeLists.txt
of the project, and find_package
needs only to be invoked once.
project(GTestSetup) | |
# Find Gazebo | |
find_package(gz-sim7 REQUIRED) | |
set(GZ_SIM_VER ${gz-sim7_VERSION_MAJOR}) |
tests/forcetorque/CMakeLists.txt
Outdated
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
enable_testing() |
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 only works when called in the root CMakeLists.txt, so I suggest to remove it here and add it there.
enable_testing() |
tests/forcetorque/README.md
Outdated
## ForceTorque plugin Test | ||
|
||
~~~ | ||
cd build | ||
export GZ_SIM_SYSTEM_PLUGIN_PATH=`pwd` | ||
cd tests/forcetorque | ||
./ForceTorqueTest | ||
~~~ |
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.
As mentioned in the comment to the PR as an whole, I suggest to remove this and just document in the README how to run tests.
## ForceTorque plugin Test | |
~~~ | |
cd build | |
export GZ_SIM_SYSTEM_PLUGIN_PATH=`pwd` | |
cd tests/forcetorque | |
./ForceTorqueTest | |
~~~ |
CMakeLists.txt
Outdated
@@ -15,4 +15,5 @@ set(GZ_SIM_VER ${gz-sim7_VERSION_MAJOR}) | |||
|
|||
add_subdirectory(libraries) | |||
add_subdirectory(plugins) | |||
add_subdirectory(tests) |
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 suggest the following modification, based on the docs in https://cmake.org/cmake/help/book/mastering-cmake/chapter/Testing%20With%20CMake%20and%20CTest.html :
add_subdirectory(tests) | |
option(BUILD_TESTING "Create tests using CMake" OFF) | |
enable(CTest) | |
if(BUILD_TESTING) | |
add_subdirectory(tests) | |
endif() |
Explanation:
- Instead of calling enable_testing directly, the CMake docs suggest to just include the
CTest
module - The
CTest
module defines theBUILD_TESTING
variable, and if that variable is set toOFF
, no tests are enabled. For this reason, ifBUILD_TESTING
is OFF, we do not add thetests
subdirectory. Furthermore, tipically in our project we set the default value ofBUILD_TESTING
toOFF
, so that users that do not need to compile the tests do not spend time compiling them.
Can you check out the conflicts with the main branch? |
The test is failing, there are two errors: First Error
The problem is that the test is not finding the plugin, as no one is adding the folder in which the plugin can be found to the
this will ensure that all plugins are placed in
Second Error
Whenever you use yarp ports, you need to have somewhere a |
tests/forcetorque/ForceTorqueTest.cc
Outdated
gz::sim::TestFixture fixture("../../../tests/forcetorque/model.sdf"); | ||
|
||
int iterations = 1000; | ||
fixture.Server()->Run(true, iterations, false); |
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 is a bit difficult to read, see https://abseil.io/tips/94 for a description way.
fixture.Server()->Run(true, iterations, false); | |
fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); |
tests/forcetorque/ForceTorqueTest.cc
Outdated
p.open("/read"); | ||
yarp::os::Network::connect("/forcetorque/measures:o","/read"); | ||
yarp::os::Bottle b; | ||
p.read(b); |
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.
macOS and Windows tests are failing. Perhaps we should add a check that the read is successful, checking the return value of this function (see https://www.yarp.it/latest/classyarp_1_1os_1_1Port.html#a7b4eb018faba3837d50fffee0ea722ef). If it fails, it is possible that it is not able to read in time anything, as nothing is published between the connect and the read. Perhaps we can try to migrate this code to multipleanalogsensorsclient
and then look again at this code? Tryng to fix it now before migrating to multipleanalogsensorsclient
may be a waste of time.
tests/forcetorque/ForceTorqueTest.cc
Outdated
double timestamp; | ||
|
||
isixaxis->getSixAxisForceTorqueSensorName(0, sensorName); | ||
isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); |
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 suggest:
isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); | |
size_t maxNrOfReadingAttempts = 20; | |
bool readSuccessful = false; | |
for (size_t i=0; (i < maxNrOfReadingAttempts) && !readSuccessful ; i++) | |
{ | |
readSuccessful = isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); | |
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
} | |
ASSERT_TRUE(readSuccessful); |
if the failure continue, you can inspect also the value returned by getSixAxisForceTorqueSensorStatus
to understand why the output is not the expected one.
In 6697372 I added a fix for actually use the cache, this should speedup the execution of apt-based workflow. For what regards the failures, there are the following two failures: conda-windowsIt still fails with error:
It seems that you tried to fix this by increasting the delay. This is not ideal as it also slows down the tests that do not need to wait more. What I suggest instead is to check the return values of the aptIn here probably we just need to set the |
Done in 2864978, inspired by https://github.com/robotology/yarp-devices-ros2/blob/ecc88be70dac7fa3f44076b0f85bfca471754642/.github/workflows/conda-ci.yml#L103 . |
It worked fine, probably we can just remove the attemps to set |
Apparently also macOS sometimes fails. We can try to implement the logic in https://github.com/robotology/gz-yarp-plugins/pull/30/files#r1291112238 and see if that improves. |
tests/forcetorque/ForceTorqueTest.cc
Outdated
@@ -36,7 +36,15 @@ TEST(ForceTorqueTest, PluginTest) | |||
double timestamp; | |||
|
|||
isixaxis->getSixAxisForceTorqueSensorName(0, sensorName); | |||
isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); | |||
//isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); |
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.
//isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); |
If we are not using it, let's remove it.
tests/forcetorque/ForceTorqueTest.cc
Outdated
readSuccessful = isixaxis->getSixAxisForceTorqueSensorMeasure(0, measure, timestamp); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
} | ||
ASSERT_TRUE(readSuccessful); |
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.
Please avoid mixing tabs and spaces, as it may result in inconsistent rendring (the width of tabs is not constant).
ASSERT_TRUE(readSuccessful); | |
ASSERT_TRUE(readSuccessful); |
Ok, it seems fine. If Windows is the only missing platform, for now probably we can skip the test and open an issue to track the test failures on Windows. |
Ok, we added a new issue #31. So, can we merge? |
There are a few things we probably still need to fix before merging, to ensure that the main branch is a good step, basically:
After that, I think we are ready to Squash and merge (again, squash to avoid having a messy history). |
Fix #20