Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/gtest/common/test_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ bool is_inet_addr(const struct sockaddr* ifa_addr) {
(ifa_addr->sa_family == AF_INET6);
}

static bool netif_has_sysfs_file(const char *ifa_name, const char *file_name)
{
char path[PATH_MAX];
ucs_snprintf_safe(path, sizeof(path), "/sys/class/net/%s/%s", ifa_name,
file_name);

struct stat st;
return stat(path, &st) >= 0;
}

bool is_interface_usable(struct ifaddrs *ifa)
{
return ucs_netif_flags_is_active(ifa->ifa_flags) &&
ucs::is_inet_addr(ifa->ifa_addr) &&
!netif_has_sysfs_file(ifa->ifa_name, "bridge") &&
!netif_has_sysfs_file(ifa->ifa_name, "brport");
}

static std::vector<std::string> read_dir(const std::string& path)
{
std::vector<std::string> result;
Expand Down
9 changes: 8 additions & 1 deletion test/gtest/common/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/socket.h>
#include <dirent.h>
#include <stdint.h>
#include <ifaddrs.h>


#ifndef UINT16_MAX
Expand Down Expand Up @@ -304,11 +305,17 @@ void safe_usleep(double usec);


/**
* Check if the given interface has an IPv4 or an IPv6 address.
* Check if the given network interface has an IPv4 or an IPv6 address.
*/
bool is_inet_addr(const struct sockaddr* ifa_addr);


/**
* Check if the given network interface should be used for testing.
*/
bool is_interface_usable(struct ifaddrs *ifa);


/**
* Check if the given network device is supported by rdmacm.
*/
Expand Down
24 changes: 9 additions & 15 deletions test/gtest/ucp/test_ucp_sockaddr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <common/test_helpers.h>
#include <ucs/sys/sys.h>
#include <ifaddrs.h>
#include <atomic>
#include <memory>

Expand Down Expand Up @@ -183,21 +182,16 @@ class test_ucp_sockaddr : public ucp_test {
ASSERT_EQ(ret, 0);

for (struct ifaddrs *ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ucs_netif_flags_is_active(ifa->ifa_flags) &&
ucs::is_inet_addr(ifa->ifa_addr))
{
if (is_skip_interface(ifa)) {
continue;
}

saddrs.push_back(ucs::sock_addr_storage());
status = ucs_sockaddr_sizeof(ifa->ifa_addr, &size);
ASSERT_UCS_OK(status);
saddrs.back().set_sock_addr(*ifa->ifa_addr, size,
ucs::is_rdmacm_netdev(
ifa->ifa_name));
saddrs.back().set_port(0); /* listen on any port then update */
if (is_skip_interface(ifa) || !ucs::is_interface_usable(ifa)) {
continue;
}

saddrs.push_back(ucs::sock_addr_storage());
status = ucs_sockaddr_sizeof(ifa->ifa_addr, &size);
ASSERT_UCS_OK(status);
saddrs.back().set_sock_addr(*ifa->ifa_addr, size,
ucs::is_rdmacm_netdev(ifa->ifa_name));
saddrs.back().set_port(0); /* listen on any port then update */
}

freeifaddrs(ifaddrs);
Expand Down
20 changes: 10 additions & 10 deletions test/gtest/uct/test_md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,17 @@ UCS_TEST_P(test_md, sockaddr_accessibility) {
ASSERT_TRUE(getifaddrs(&ifaddr) != -1);
/* go through a linked list of available interfaces */
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ucs::is_inet_addr(ifa->ifa_addr) &&
ucs_netif_flags_is_active(ifa->ifa_flags)) {
sock_addr.addr = ifa->ifa_addr;

UCS_TEST_MESSAGE << "Testing " << ifa->ifa_name << " with "
<< ucs::sockaddr_to_str(ifa->ifa_addr);
ASSERT_FALSE(uct_md_is_sockaddr_accessible(md(), &sock_addr,
UCT_SOCKADDR_ACC_LOCAL));
ASSERT_FALSE(uct_md_is_sockaddr_accessible(md(), &sock_addr,
UCT_SOCKADDR_ACC_REMOTE));
if (!ucs::is_interface_usable(ifa)) {
continue;
}

sock_addr.addr = ifa->ifa_addr;
UCS_TEST_MESSAGE << "Testing " << ifa->ifa_name << " with "
<< ucs::sockaddr_to_str(ifa->ifa_addr);
ASSERT_FALSE(uct_md_is_sockaddr_accessible(md(), &sock_addr,
UCT_SOCKADDR_ACC_LOCAL));
ASSERT_FALSE(uct_md_is_sockaddr_accessible(md(), &sock_addr,
UCT_SOCKADDR_ACC_REMOTE));
}
freeifaddrs(ifaddr);
}
Expand Down
4 changes: 1 addition & 3 deletions test/gtest/uct/uct_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <ifaddrs.h>


std::string resource::name() const {
Expand Down Expand Up @@ -292,8 +291,7 @@ void uct_test::set_interface_rscs(uct_component_h cmpt, const char *cmpt_name,
}

bool uct_test::is_interface_usable(struct ifaddrs *ifa, const char *name) {
if (!(ucs_netif_flags_is_active(ifa->ifa_flags)) ||
!(ucs::is_inet_addr(ifa->ifa_addr))) {
if (!ucs::is_interface_usable(ifa)) {
return false;
}

Expand Down