Skip to content

Commit

Permalink
Modified the structure of member names to reflect the point made on t…
Browse files Browse the repository at this point in the history
…he thread below.

ros-infrastructure/rep#385 (comment)

Signed-off-by: Shoji Morita <[email protected]>
  • Loading branch information
smorita-esol committed Jan 26, 2024
1 parent d94fa54 commit 97ebc75
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions rcl/test/rcl/test_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TEST_F(CLASSNAME(TestArgumentsFixture, RMW_IMPLEMENTATION), check_known_vs_unkno
EXPECT_TRUE(
are_known_ros_args(
{"--ros-args", "--thread-attrs-value",
"[{priority: 10, scheduling_policy: FIFO, name: thread-1, core_affinity: [1,2,3]}]"}));
"[{priority: 10, scheduling_policy: FIFO, tag: attr-1, core_affinity: [1,2,3]}]"}));
}

bool
Expand Down Expand Up @@ -238,7 +238,7 @@ TEST_F(CLASSNAME(TestArgumentsFixture, RMW_IMPLEMENTATION), check_valid_vs_inval
"--params-file", parameters_filepath.c_str(), "--log-level", "INFO",
"--log-config-file", "file.config",
"--thread-attrs-value",
"[{priority: 10, scheduling_policy: IDLE, name: thread-1, core_affinity: [1]}]"
"[{priority: 10, scheduling_policy: IDLE, tag: attr-1, core_affinity: [1]}]"
}));

// ROS args unknown to rcl are not (necessarily) invalid
Expand Down
4 changes: 2 additions & 2 deletions rcl/test/resources/test_arguments/test_thread_attrs.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- name: thread-1
- tag: attr-1
priority: 10
scheduling_policy: FIFO
core_affinity: [1]
- name: thread-2
- tag: attr-2
priority: 20
scheduling_policy: RR
core_affinity: [2]
4 changes: 2 additions & 2 deletions rcl_yaml_param_parser/src/impl/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef enum thread_attr_key_type_e
THREAD_ATTR_KEY_CORE_AFFINITY = 1,
THREAD_ATTR_KEY_SCHEDULING_POLICY = 2,
THREAD_ATTR_KEY_PRIORITY = 4,
THREAD_ATTR_KEY_NAME = 8
THREAD_ATTR_KEY_TAG = 8
} thread_attr_key_type_t;

typedef enum thread_attr_key_bits_e
Expand All @@ -78,7 +78,7 @@ typedef enum thread_attr_key_bits_e
THREAD_ATTR_KEY_CORE_AFFINITY |
THREAD_ATTR_KEY_SCHEDULING_POLICY |
THREAD_ATTR_KEY_PRIORITY |
THREAD_ATTR_KEY_NAME
THREAD_ATTR_KEY_TAG
} thread_attr_key_bits_t;

#ifdef __cplusplus
Expand Down
32 changes: 16 additions & 16 deletions rcl_yaml_param_parser/src/parse_thread_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ parse_thread_attr_key(
*key_type = THREAD_ATTR_KEY_PRIORITY;
} else if (strcmp(str, "scheduling_policy") == 0) {
*key_type = THREAD_ATTR_KEY_SCHEDULING_POLICY;
} else if (strcmp(str, "name") == 0) {
*key_type = THREAD_ATTR_KEY_NAME;
} else if (strcmp(str, "tag") == 0) {
*key_type = THREAD_ATTR_KEY_TAG;
} else if (*str == '\0') {
RCUTILS_SET_ERROR_MSG("empty name for a thread attribute");
RCUTILS_SET_ERROR_MSG("empty tag for a thread attribute");
ret = RCUTILS_RET_ERROR;
goto error;
} else {
Expand Down Expand Up @@ -122,7 +122,7 @@ rcutils_ret_t parse_thread_attr(
rcutils_thread_core_affinity_t core_affinity =
rcutils_get_zero_initialized_thread_core_affinity();
int priority;
char const * name = NULL;
char const * tag = NULL;
rcutils_allocator_t allocator = attrs->allocator;
void * ret_val = NULL;

Expand Down Expand Up @@ -154,7 +154,7 @@ rcutils_ret_t parse_thread_attr(

const char * value = (char *)event.data.scalar.value;
yaml_scalar_style_t style = event.data.scalar.style;
const yaml_char_t * tag = event.data.scalar.tag;
const yaml_char_t * yaml_tag = event.data.scalar.tag;
data_types_t val_type;

switch (key_type) {
Expand All @@ -174,8 +174,8 @@ rcutils_ret_t parse_thread_attr(
}
value = (char *)event.data.scalar.value;
style = event.data.scalar.style;
tag = event.data.scalar.tag;
ret_val = get_value(value, style, tag, &val_type, allocator);
yaml_tag = event.data.scalar.tag;
ret_val = get_value(value, style, yaml_tag, &val_type, allocator);
if (DATA_TYPE_INT64 != val_type) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Unrecognized value for thread core affinity: %s", value);
Expand All @@ -195,7 +195,7 @@ rcutils_ret_t parse_thread_attr(
if (event.type != YAML_SCALAR_EVENT) {
goto error;
}
ret_val = get_value(value, style, tag, &val_type, allocator);
ret_val = get_value(value, style, yaml_tag, &val_type, allocator);
if (DATA_TYPE_INT64 != val_type) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Unrecognized value for thread priority: %s", value);
Expand All @@ -210,17 +210,17 @@ rcutils_ret_t parse_thread_attr(
}
sched_policy = parse_thread_attr_scheduling_policy(value);
break;
case THREAD_ATTR_KEY_NAME:
case THREAD_ATTR_KEY_TAG:
if (event.type != YAML_SCALAR_EVENT) {
goto error;
}
if (*value == '\0') {
RCUTILS_SET_ERROR_MSG("Empty thread name");
RCUTILS_SET_ERROR_MSG("Empty thread attribute tag");
ret = RCUTILS_RET_ERROR;
goto error;
}
name = rcutils_strdup(value, allocator);
if (NULL == name) {
tag = rcutils_strdup(value, allocator);
if (NULL == tag) {
ret = RCUTILS_RET_BAD_ALLOC;
goto error;
}
Expand All @@ -241,18 +241,18 @@ rcutils_ret_t parse_thread_attr(
goto error;
}

ret = rcutils_thread_attrs_add_attr(attrs, sched_policy, &core_affinity, priority, name);
ret = rcutils_thread_attrs_add_attr(attrs, sched_policy, &core_affinity, priority, tag);
if (RCUTILS_RET_OK != ret) {
goto error;
}

allocator.deallocate((char *)name, allocator.state);
allocator.deallocate((char *)tag, allocator.state);

return RCUTILS_RET_OK;

error:
if (NULL != name) {
allocator.deallocate((char *)name, allocator.state);
if (NULL != tag) {
allocator.deallocate((char *)tag, allocator.state);
}
if (NULL != ret_val) {
allocator.deallocate(ret_val, allocator.state);
Expand Down
18 changes: 9 additions & 9 deletions rcl_yaml_param_parser/test/test_parse_thread_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ TEST_F(TestParseThreadAttr, success) {
yaml_event_t event;

prepare_yaml_parser(
"{ priority: 10, name: thread-1, core_affinity: [1], scheduling_policy: FIFO }");
"{ priority: 10, tag: attr-1, core_affinity: [1], scheduling_policy: FIFO }");

ret = parse_thread_attr(&parser, &attrs);
EXPECT_EQ(RCUTILS_RET_OK, ret);

EXPECT_EQ(1, attrs.num_attributes);
EXPECT_EQ(10, attrs.attributes[0].priority);
EXPECT_STREQ("thread-1", attrs.attributes[0].name);
EXPECT_STREQ("attr-1", attrs.attributes[0].tag);
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[0].core_affinity, 1));
EXPECT_EQ(RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, attrs.attributes[0].scheduling_policy);

Expand All @@ -102,7 +102,7 @@ TEST_F(TestParseThreadAttr, unknown_key) {
rcutils_ret_t ret;

prepare_yaml_parser(
"{ priority: 10, name: thread-1, core_affinity: [1], unknown_key: FIFO }");
"{ priority: 10, tag: attr-1, core_affinity: [1], unknown_key: FIFO }");

ret = parse_thread_attr(&parser, &attrs);
EXPECT_EQ(RCUTILS_RET_ERROR, ret);
Expand All @@ -112,7 +112,7 @@ TEST_F(TestParseThreadAttr, all_valid_keys_with_unknown_key) {
rcutils_ret_t ret;

prepare_yaml_parser(
"{ priority: 10, name: thread-1, core_affinity: [1], "
"{ priority: 10, tag: attr-1, core_affinity: [1], "
"scheduling_policy: FIFO, unknown_key: RR }");

ret = parse_thread_attr(&parser, &attrs);
Expand All @@ -122,7 +122,7 @@ TEST_F(TestParseThreadAttr, all_valid_keys_with_unknown_key) {
TEST_F(TestParseThreadAttr, missing_key_value) {
rcutils_ret_t ret;
prepare_yaml_parser(
"{ priority: 10, name: thread-1 }");
"{ priority: 10, tag: attr-1 }");

ret = parse_thread_attr(&parser, &attrs);
EXPECT_EQ(RCUTILS_RET_ERROR, ret);
Expand All @@ -135,7 +135,7 @@ TEST_F(TestParseThreadAttrs, success) {
ss << "[";
for (std::size_t i = 0; i < 100; ++i) {
ss << "{ priority: " << i * 10;
ss << ", name: thread-" << i;
ss << ", tag: attr-" << i;
ss << ", core_affinity: [" << i << "]";
ss << ", scheduling_policy: FIFO },";
}
Expand All @@ -151,9 +151,9 @@ TEST_F(TestParseThreadAttrs, success) {
for (std::size_t i = 0; i < 100; ++i) {
EXPECT_EQ(i * 10, attrs.attributes[i].priority);
ss.str("");
ss << "thread-" << i;
ss << "attr-" << i;
buf = ss.str();
EXPECT_STREQ(buf.c_str(), attrs.attributes[i].name);
EXPECT_STREQ(buf.c_str(), attrs.attributes[i].tag);
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i));
EXPECT_EQ(RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, attrs.attributes[i].scheduling_policy);
}
Expand All @@ -162,7 +162,7 @@ TEST_F(TestParseThreadAttrs, success) {
TEST_F(TestParseThreadAttr, affinity_multiple_core) {
rcutils_ret_t ret;
prepare_yaml_parser(
"{ priority: 10, name: thread-1, core_affinity: [1,2,3], scheduling_policy: FIFO }");
"{ priority: 10, tag: attr-1, core_affinity: [1,2,3], scheduling_policy: FIFO }");

ret = parse_thread_attr(&parser, &attrs);
EXPECT_EQ(RCUTILS_RET_OK, ret);
Expand Down
8 changes: 4 additions & 4 deletions rcl_yaml_param_parser/test/test_parser_thread_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ TEST_F(TestParserThreadAttr, success_file) {
for (size_t i = 0; i < 10; ++i) {
EXPECT_EQ(attrs.attributes[i].priority, i * 10);
char buf[32];
snprintf(buf, sizeof(buf), "thread-%lu", i);
EXPECT_STREQ(buf, attrs.attributes[i].name);
snprintf(buf, sizeof(buf), "attr-%lu", i);
EXPECT_STREQ(buf, attrs.attributes[i].tag);
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i));
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i + 10));
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i * i));
Expand All @@ -114,8 +114,8 @@ TEST_F(TestParserThreadAttr, success_value) {
for (size_t i = 0; i < 10; ++i) {
EXPECT_EQ(attrs.attributes[i].priority, i * 10);
char buf[32];
snprintf(buf, sizeof(buf), "thread-%lu", i);
EXPECT_STREQ(buf, attrs.attributes[i].name);
snprintf(buf, sizeof(buf), "attr-%lu", i);
EXPECT_STREQ(buf, attrs.attributes[i].tag);
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i));
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i + 10));
EXPECT_TRUE(rcutils_thread_core_affinity_is_set(&attrs.attributes[i].core_affinity, i * i));
Expand Down
20 changes: 10 additions & 10 deletions rcl_yaml_param_parser/test/thread_attr_success.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
- priority: 0
name: thread-0
tag: attr-0
core_affinity: [0,10,0]
scheduling_policy: BADSCHEDPOLICY1
- priority: 10
name: thread-1
tag: attr-1
core_affinity: [1,11,1]
scheduling_policy: FIFO
- priority: 20
name: thread-2
tag: attr-2
core_affinity: [2,12,4]
scheduling_policy: RR
- priority: 30
name: thread-3
tag: attr-3
core_affinity: [3,13,9]
scheduling_policy: SPORADIC
- priority: 40
name: thread-4
tag: attr-4
core_affinity: [4,14,16]
scheduling_policy: OTHER
- priority: 50
name: thread-5
tag: attr-5
core_affinity: [5,15,25]
scheduling_policy: IDLE
- priority: 60
name: thread-6
tag: attr-6
core_affinity: [6,16,36]
scheduling_policy: BATCH
- priority: 70
name: thread-7
tag: attr-7
core_affinity: [7,17,49]
scheduling_policy: DEADLINE
- priority: 80
name: thread-8
tag: attr-8
core_affinity: [8,18,64]
scheduling_policy: BADSCHEDPOLICY2
- priority: 90
name: thread-9
tag: attr-9
core_affinity: [9,19,81]
scheduling_policy: FIFO

0 comments on commit 97ebc75

Please sign in to comment.