Skip to content

Commit e3be8e9

Browse files
UCP/CORE: Fix PR comments
1 parent 77411b4 commit e3be8e9

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

src/ucp/core/ucp_context.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@
7575
#define UCP_MLX_PREFIX "mlx"
7676
#define UCP_MLX_DEFAULT_PORT "1"
7777

78-
#define UCP_IS_RESOURCE_MLX_DEFAULT_PORT(_dev_name, _dev_name_suffix) \
79-
((!strncmp(_dev_name, UCP_MLX_PREFIX, strlen(UCP_MLX_PREFIX))) && \
80-
(!strcmp(_dev_name_suffix, UCP_MLX_DEFAULT_PORT)))
81-
8278
typedef enum ucp_transports_list_search_result {
8379
UCP_TRANSPORTS_LIST_SEARCH_RESULT_PRIMARY = UCS_BIT(0),
8480
UCP_TRANSPORTS_LIST_SEARCH_RESULT_AUX_IN_MAIN = UCS_BIT(1),
@@ -1029,8 +1025,8 @@ static uint64_t ucp_str_array_search_in_ranges(const char **array,
10291025
}
10301026

10311027
n = 0;
1032-
if (sscanf(p, "[%lu-%lu]%n", &range_start, &range_end, &n) != 2 ||
1033-
n == 0 || p[n] != '\0' || range_start > range_end) {
1028+
if ((sscanf(p, "[%lu-%lu]%n", &range_start, &range_end, &n) != 2) ||
1029+
(n == 0) || (p[n] != '\0') || (range_start > range_end)) {
10341030
continue; /* Invalid range */
10351031
}
10361032

@@ -1095,6 +1091,13 @@ static const char *ucp_get_dev_name_suffix(const char *dev_name)
10951091
return colon + 1;
10961092
}
10971093

1094+
static inline int
1095+
ucp_is_dev_mlx_default_port(const char *dev_name, const char *dev_name_suffix)
1096+
{
1097+
return (!strncmp(dev_name, UCP_MLX_PREFIX, strlen(UCP_MLX_PREFIX))) &&
1098+
(!strcmp(dev_name_suffix, UCP_MLX_DEFAULT_PORT));
1099+
}
1100+
10981101
static int ucp_is_resource_in_device_list(const uct_tl_resource_desc_t *resource,
10991102
const ucs_config_names_array_t *devices,
11001103
uint64_t *dev_cfg_mask,
@@ -1113,10 +1116,8 @@ static int ucp_is_resource_in_device_list(const uct_tl_resource_desc_t *resource
11131116

11141117
if (dev_type == UCT_DEVICE_TYPE_NET) {
11151118
dev_name_suffix = ucp_get_dev_name_suffix(resource->dev_name);
1116-
ucs_assert(dev_name_suffix > resource->dev_name &&
1117-
dev_name_suffix <= resource->dev_name + strlen(resource->dev_name));
11181119

1119-
if (UCP_IS_RESOURCE_MLX_DEFAULT_PORT(resource->dev_name, dev_name_suffix)) {
1120+
if (ucp_is_dev_mlx_default_port(resource->dev_name, dev_name_suffix)) {
11201121
ucs_strncpy_zero(dev_name_base, resource->dev_name,
11211122
(size_t)(dev_name_suffix - resource->dev_name));
11221123

@@ -1132,8 +1133,8 @@ static int ucp_is_resource_in_device_list(const uct_tl_resource_desc_t *resource
11321133
}
11331134
}
11341135

1135-
/* if the user's list is 'all', use all the available resources */
11361136
if (!mask) {
1137+
/* if the user's list is 'all', use all the available resources */
11371138
mask = ucp_str_array_search((const char**)devices[dev_type].names,
11381139
devices[dev_type].count, UCP_RSC_CONFIG_ALL,
11391140
NULL);

test/gtest/ucp/test_ucp_context.cc

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ UCS_TEST_P(test_ucp_net_devices_config, base_name_selects_default_port)
206206
}
207207

208208
std::set<std::string> base_names = get_mlx5_base_names(mlx5_devices);
209-
if (base_names.empty()) {
210-
UCS_TEST_SKIP_R("No mlx5 devices with port suffix found");
211-
}
209+
ASSERT_FALSE(base_names.empty());
212210

213211
/* Pick the first base name for testing */
214212
std::string test_base_name = *base_names.begin();
@@ -222,8 +220,9 @@ UCS_TEST_P(test_ucp_net_devices_config, base_name_selects_default_port)
222220
/* Verify that devices matching the base name were selected */
223221
std::set<std::string> selected_devices = get_mlx5_device_names(*e);
224222
size_t count = count_mlx5_resources_with_prefix(selected_devices, test_base_name);
225-
EXPECT_GT(count, 0) << "Expected at least one device with base name '"
226-
<< test_base_name << "' to be selected";
223+
EXPECT_EQ(count, 1) << "Expected exactly one device with base name '"
224+
<< test_base_name << "' to be selected, found: "
225+
<< testing::PrintToString(selected_devices);
227226

228227
std::string expected_dev = test_base_name + ":1";
229228
EXPECT_TRUE(has_device(selected_devices, expected_dev))
@@ -341,6 +340,42 @@ UCS_TEST_P(test_ucp_net_devices_config, duplicate_device_warning)
341340
<< test_base_name << "'";
342341
}
343342

343+
/*
344+
* Test that a range not covering all devices only selects matching devices.
345+
* E.g., "mlx5_[1-2]" should match mlx5_1 and mlx5_2, but not mlx5_0.
346+
*/
347+
UCS_TEST_P(test_ucp_net_devices_config, partial_range_selection)
348+
{
349+
entity *e = create_entity();
350+
351+
std::set<std::string> mlx5_devices = get_mlx5_device_names(*e);
352+
if (mlx5_devices.empty()) {
353+
UCS_TEST_SKIP_R("No mlx5 network device available");
354+
}
355+
356+
std::set<std::string> base_names = get_mlx5_base_names(mlx5_devices);
357+
358+
if (!has_device(base_names, "mlx5_0") ||
359+
!has_device(base_names, "mlx5_1") ||
360+
!has_device(base_names, "mlx5_2")) {
361+
UCS_TEST_SKIP_R(
362+
"Need mlx5_0, mlx5_1, and mlx5_2 devices for this test");
363+
}
364+
365+
m_entities.clear();
366+
367+
modify_config("NET_DEVICES", "mlx5_[1-2]");
368+
e = create_entity();
369+
370+
std::set<std::string> selected_devices = get_mlx5_device_names(*e);
371+
372+
std::set<std::string> selected_base_names = get_mlx5_base_names(
373+
selected_devices);
374+
375+
std::set<std::string> expected_base_names = {"mlx5_1", "mlx5_2"};
376+
EXPECT_EQ(selected_base_names, expected_base_names);
377+
}
378+
344379
/*
345380
* Test that non-mlx devices are not affected by the mlx default port logic.
346381
*/

0 commit comments

Comments
 (0)