Skip to content

Commit

Permalink
Add skeleton of E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Mar 5, 2024
1 parent edd930b commit 817892f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ if(CATKIN_ENABLE_TESTING)
find_package(rosunit REQUIRED)
find_package(roslint REQUIRED)
set(ROSLINT_CPP_OPTS "--filter=-runtime/references,-build/c++11")
roslint_cpp()
roslint_add_test()
#roslint_cpp()
#roslint_add_test()

add_subdirectory(test)
endif()
Expand Down
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if (FALSE)
catkin_add_gtest(test_decode src/test_decode.cpp)
target_link_libraries(test_decode ${catkin_LIBRARIES} ${Boost_LIBRARIES})

Expand All @@ -15,3 +16,15 @@ target_link_libraries(test_timestamp_outlier_remover ${catkin_LIBRARIES} ${Boost

catkin_add_gtest(test_walltime src/test_walltime.cpp ../src/scip2/logger.cpp)
target_link_libraries(test_walltime ${catkin_LIBRARIES} ${Boost_LIBRARIES})

endif()

add_rostest_gtest(e2e tests/e2e.test
src/e2e.cpp
../src/urg_sim/encode.cpp
../src/urg_sim/urg_sim.cpp
../src/urg_stamped.cpp
../src/scip2/logger.cpp
../src/ros_logger.cpp
)
target_link_libraries(e2e ${catkin_LIBRARIES} ${Boost_LIBRARIES})
95 changes: 95 additions & 0 deletions test/src/e2e.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2024 The urg_stamped Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
#include <vector>

#include <boost/asio/ip/tcp.hpp>

#include <ros/ros.h>

#include <urg_stamped/urg_stamped.h>
#include <urg_sim/urg_sim.h>

#include <gtest/gtest.h>

class E2E : public ::testing::Test
{
public:
E2E()
: pnh_("~")
{
}

void SetUp()
{
const urg_sim::URGSimulator::Params params =
{
.model = urg_sim::URGSimulator::Model::UTM,
.boot_duration = 5.0,
.comm_delay_base = 0.001,
.comm_delay_sigma = 0.0002,
.scan_interval = 0.025,
.clock_rate = 1.0,
.hex_ii_timestamp = false,
.angle_resolution = 1440,
.angle_min = 0,
.angle_max = 1080,
.angle_front = 540,
};
sim_ = new urg_sim::URGSimulator(
boost::asio::ip::tcp::endpoint(
boost::asio::ip::tcp::v4(),
0),
params);
th_sim_ = std::thread(std::bind(&urg_sim::URGSimulator::spin, sim_));

pnh_.setParam("ip_address", "127.0.0.1");
pnh_.setParam("ip_port", std::to_string(sim_->getLocalEndpoint().port()));

node_ = new urg_stamped::UrgStampedNode();
th_node_ = std::thread(std::bind(&urg_stamped::UrgStampedNode::spin, node_));
}

void TearDown()
{
sim_->kill();
th_sim_.join();
th_node_.join();
}

private:
ros::NodeHandle pnh_;
urg_sim::URGSimulator* sim_;
urg_stamped::UrgStampedNode* node_;
std::thread th_sim_;
std::thread th_node_;
};

TEST_F(E2E, Dummy)
{
ASSERT_TRUE(true);
}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "urg_stamped_e2e");
ros::NodeHandle nh; // workaround to keep the test node during the process life time

return RUN_ALL_TESTS();
}

6 changes: 6 additions & 0 deletions test/tests/e2e.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<launch>
<env name="GCOV_PREFIX" value="/tmp/gcov/e2e" />

<test test-name="e2e" pkg="urg_stamped" type="e2e" />
</launch>

0 comments on commit 817892f

Please sign in to comment.