ROS_Test - RicoJia/notes GitHub Wiki
========================================================================
========================================================================
-
testing: you have three levels of testing:
- rosunit (unit test, same functionality as gtest)
- google gtest
- rostest (launch file that launches multiple nodes)
-
- Basic procedure:
- In test.cpp
TEST(TestSuite, testCase2) { const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1,2,3), ros::Time(5), "test"); tf2::Stamped<Eigen::Vector3d> v1; geometry_msgs::PointStamped p1; tf2::convert(v, p1); tf2::convert(p1, v1); EXPECT_EQ(v, v1); } int main(int argc, char **argv){ testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
- In CMakelist.txt
if(CATKIN_ENABLE_TESTING) catkin_add_gtest(tf2_eigen-test test/tf2_eigen-test.cpp) target_link_libraries(tf2_eigen-test ${catkin_LIBRARIES} ${GTEST_LIBRARIES}) endif()
- In package.xml
<test_depend>rosunit</test_depend>
- Run test with
- catkin_make
./bin/test/utest
- or ```catkin_make run_tests``, or
- or
catkin_make run_tests<TAB><TAB>
to find the package to run.
- catkin build
catkin build -v -i --make-args tests -- PKG_NAME catkin build -v -i --make-args test -- PKG_NAME catkin_test_results --verbose build #(need this to view results)
- catkin_make
-
TestSuite is CamelCased testFunction is camelCased.
-
std::cout should work!
-
Test expressions Use ASSERT when we stop the test when a test fail. Use EXPECT so we can still get values out and continue the test.
- add custom message
ASSERT_EQ(ans.x, vec.x)<< "Talker add x's failed"<<.ans.x;
- string comparison
EXPECT_STREQ(str1,str2);
- near
EXPECT_NEAR(val1, val2, abs_error);
Internal Working: Print from rostest node: rostest is running on a randomly assigned port, and you don't know which port they're running. A: so after catkin_make run_all_tests, which compiles and launches the rostest. test, you can do $rostest test_file -r, then use rosconsole
========================================================================
======================================================================== https://web.eecs.umich.edu/~sugih/pointers/gdbQS.html
Basic procedure:
-
catkin_make -DCMAKE_BUILD_TYPE=Debug
- if there's no extra compile mode, use this to debug. (in gdb, it should be g++ -g something.cc -o something)
-
rosrun --prefix 'gdb --args' nuslam landmarks
-
rosparam load dump.yaml
namespace for loading the yaml file. -
if your hit run, the program will stop at where it crashes. or hit ctrl+c, where it will stop somewhere.
-
if you see some system function, turn on tui: tui enable, hit up
- Debugging: GDB https://u.osu.edu/cstutorials/2018/09/28/how-to-debug-c-program-using-gdb-in-6-simple-steps/
- compile your code, get a.out
- gdb
- Debugging: GDB https://u.osu.edu/cstutorials/2018/09/28/how-to-debug-c-program-using-gdb-in-6-simple-steps/
-
Keep Gazebo and Rviz running, and run the launch file separately.
-
Use a launchfile. add launch-prefix="gdb --args" output="screen"
-
GDB commands
-
bt: backtrace.
-
p is print a. print eigen vectors and values. print *X.data()@Length_X where X is the eigen variable and Length_X is the product of its rows and columns
-
you can do p mu.operator(something) you can run an operation.
-
n is next line, it will skip an entire function!!
-
b linenum: sets break point. in ros, do b namespace::class::function:linenum
-
info b: see breakpoints
-
delete breakpoint_num: delete a breakpoint
-
s is step
-
c is continue
-
牛逼: f is frame, which is the level of the function stack you're in. so you can go back to the previous frame and print the variables there!!!!
-
========================================================================
========================================================================
-
rostest
is 100% compatible with roslaunch- One difference is all nodes are shutdown automatically, once tests are done
- are tests launched one at a time?