-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,563 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <gtest/gtest.h> | ||
#include <Client.hpp> | ||
#include <thread> | ||
|
||
#include "ClientAgentCan.hpp" | ||
|
||
TEST_P(ClientAgentCan, PingFromClientToAgent) | ||
{ | ||
ASSERT_NO_FATAL_FAILURE(client_can_.ping_agent()); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P( | ||
CanTransports, | ||
ClientAgentCan, | ||
::testing::Values(MiddlewareKind::FASTDDS)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#ifndef IN_TEST_CLIENTCAN_INT_HPP | ||
#define IN_TEST_CLIENTCAN_INT_HPP | ||
|
||
#include <uxr/agent/transport/can/CanAgentLinux.hpp> | ||
#include <ClientCan.hpp> | ||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <sys/ioctl.h> | ||
#include <net/if.h> | ||
|
||
class AgentCan | ||
{ | ||
public: | ||
const char * dev = "vcan0"; | ||
const uint32_t can_id = 0x00000001; // TODO: test different can_id | ||
|
||
AgentCan(MiddlewareKind middleware) | ||
: middleware_{} | ||
{ | ||
switch (middleware) | ||
{ | ||
case MiddlewareKind::FASTDDS: | ||
middleware_ = eprosima::uxr::Middleware::Kind::FASTDDS; | ||
break; | ||
case MiddlewareKind::FASTRTPS: | ||
middleware_ = eprosima::uxr::Middleware::Kind::FASTRTPS; | ||
break; | ||
case MiddlewareKind::CED: | ||
middleware_ = eprosima::uxr::Middleware::Kind::CED; | ||
break; | ||
} | ||
} | ||
|
||
~AgentCan() | ||
{} | ||
|
||
bool is_interface_up(const char * interface) | ||
{ | ||
struct ifreq ifr; | ||
int sock = socket(PF_CAN, SOCK_RAW, CAN_RAW); | ||
memset(&ifr, 0, sizeof(ifr)); | ||
strcpy(ifr.ifr_name, interface); | ||
ioctl(sock, SIOCGIFFLAGS, &ifr); | ||
close(sock); | ||
return !!(ifr.ifr_flags & IFF_UP); | ||
} | ||
|
||
void start() | ||
{ | ||
if (!is_interface_up(dev)) | ||
{ | ||
ASSERT_TRUE(0 == system("ip link add dev vcan0 type vcan && ip link set vcan0 mtu 72 && ip link set dev vcan0 up")); | ||
} | ||
|
||
agent_can_.reset(new eprosima::uxr::CanAgent(dev, can_id, middleware_)); | ||
agent_can_->set_verbose_level(6); | ||
ASSERT_TRUE(agent_can_->start()); | ||
} | ||
|
||
void stop() | ||
{ | ||
ASSERT_TRUE(agent_can_->stop()); | ||
} | ||
|
||
private: | ||
std::unique_ptr<eprosima::uxr::CanAgent> agent_can_; | ||
eprosima::uxr::Middleware::Kind middleware_; | ||
}; | ||
|
||
class ClientAgentCan : public ::testing::TestWithParam<MiddlewareKind> | ||
{ | ||
public: | ||
ClientAgentCan() | ||
: client_can_(0.0f, 8) | ||
, agent_(GetParam()) | ||
{} | ||
|
||
~ClientAgentCan() | ||
{} | ||
|
||
void SetUp() override | ||
{ | ||
agent_.start(); | ||
ASSERT_NO_FATAL_FAILURE(client_can_.init_transport(agent_.dev, agent_.can_id + 1)); | ||
} | ||
|
||
void TearDown() override | ||
{ | ||
ASSERT_NO_FATAL_FAILURE(client_can_.close_transport()); | ||
agent_.stop(); | ||
} | ||
|
||
protected: | ||
ClientCan client_can_; | ||
AgentCan agent_; | ||
}; | ||
|
||
#endif // ifndef IN_TEST_CLIENTCAN_INT_HPP |
Oops, something went wrong.