From 6375b9429f8332f3eacc2ec795aa1924c73d9cc8 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 9 Sep 2021 23:25:19 -0400 Subject: [PATCH] common: move bt_component_class_type_string here, use it more I spotted some messages in the CLI code that could print the component class type as a string rather than an integer. bt_component_class_type_string is not accessible to the CLI code, because it's in a lib header. Move it to common/common.h, and rename it accordingly. Adjust all existing callers, and use it in cli/babeltrace2.c. Before: $ ./src/cli/babeltrace2 query src.ctf.fs foo ... Failed to query component class: unknown query object: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1 object="foo" After: $ ./src/cli/babeltrace2 query src.ctf.fs foo ... Failed to query component class: unknown query object: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=SOURCE object="foo" Change-Id: I88f01ac7cae9723ce11dbf2ec0843a06d761abb6 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/6273 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/cli/babeltrace2.c | 39 +++++++++++-------- src/common/common.h | 16 ++++++++ src/lib/graph/component-class.c | 2 +- src/lib/graph/component-class.h | 15 ------- src/lib/lib-logging.c | 4 +- src/lib/plugin/plugin-so.c | 6 +-- .../python-plugin-provider.c | 2 +- tests/cli/query/test_query | 2 +- tests/cli/test_help | 2 +- 9 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index c0acce97..bf6c49d5 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -636,10 +636,11 @@ enum bt_cmd_status cmd_query(struct bt_config *cfg) if (!comp_cls) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", + "comp-cls-name=\"%s\", comp-cls-type=%s", cfg->cmd_data.query.cfg_component->plugin_name->str, cfg->cmd_data.query.cfg_component->comp_cls_name->str, - cfg->cmd_data.query.cfg_component->type); + bt_common_component_class_type_string( + cfg->cmd_data.query.cfg_component->type)); goto error; } @@ -649,11 +650,12 @@ enum bt_cmd_status cmd_query(struct bt_config *cfg) if (ret) { BT_CLI_LOGE_APPEND_CAUSE( "Failed to query component class: %s: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d " + "comp-cls-name=\"%s\", comp-cls-type=%s " "object=\"%s\"", fail_reason, cfg->cmd_data.query.cfg_component->plugin_name->str, cfg->cmd_data.query.cfg_component->comp_cls_name->str, - cfg->cmd_data.query.cfg_component->type, + bt_common_component_class_type_string( + cfg->cmd_data.query.cfg_component->type), cfg->cmd_data.query.object->str); goto error; } @@ -743,10 +745,11 @@ enum bt_cmd_status cmd_help(struct bt_config *cfg) if (!needed_comp_cls) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", + "comp-cls-name=\"%s\", comp-cls-type=%s", cfg->cmd_data.help.cfg_component->plugin_name->str, cfg->cmd_data.help.cfg_component->comp_cls_name->str, - cfg->cmd_data.help.cfg_component->type); + bt_common_component_class_type_string( + cfg->cmd_data.help.cfg_component->type)); goto error; } @@ -904,9 +907,10 @@ enum bt_cmd_status cmd_print_lttng_live_sessions(struct bt_config *cfg) if (!comp_cls) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", + "comp-cls-name=\"%s\", comp-cls-type=%s", plugin_name, comp_cls_name, - BT_COMPONENT_CLASS_TYPE_SOURCE); + bt_common_component_class_type_string( + BT_COMPONENT_CLASS_TYPE_SOURCE)); goto error; } @@ -1043,9 +1047,10 @@ enum bt_cmd_status cmd_print_ctf_metadata(struct bt_config *cfg) if (!comp_cls) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", + "comp-cls-name=\"%s\", comp-cls-type=%s", plugin_name, comp_cls_name, - BT_COMPONENT_CLASS_TYPE_SOURCE); + bt_common_component_class_type_string( + BT_COMPONENT_CLASS_TYPE_SOURCE)); goto error; } @@ -1702,8 +1707,9 @@ int add_descriptor_to_component_descriptor_set( if (!comp_cls) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", - plugin_name, comp_cls_name, comp_cls_type); + "comp-cls-name=\"%s\", comp-cls-type=%s", + plugin_name, comp_cls_name, + bt_common_component_class_type_string(comp_cls_type)); status = -1; goto end; } @@ -2239,10 +2245,10 @@ int cmd_run_ctx_create_components_from_config_components( if (!comp_cls) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", + "comp-cls-name=\"%s\", comp-cls-type=%s", cfg_comp->plugin_name->str, cfg_comp->comp_cls_name->str, - cfg_comp->type); + bt_common_component_class_type_string(cfg_comp->type)); goto error; } @@ -2277,11 +2283,12 @@ int cmd_run_ctx_create_components_from_config_components( if (ret) { BT_CLI_LOGE_APPEND_CAUSE( "Cannot create component: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d, " + "comp-cls-name=\"%s\", comp-cls-type=%s, " "comp-name=\"%s\"", cfg_comp->plugin_name->str, cfg_comp->comp_cls_name->str, - cfg_comp->type, cfg_comp->instance_name->str); + bt_common_component_class_type_string(cfg_comp->type), + cfg_comp->instance_name->str); goto error; } diff --git a/src/common/common.h b/src/common/common.h index 5266404c..19f4c128 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -853,6 +853,22 @@ void bt_common_g_string_append_c(GString *str, char c) str->str[len + 1] = '\0'; } +static inline +const char *bt_common_component_class_type_string( + enum bt_component_class_type type) +{ + switch (type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + return "SOURCE"; + case BT_COMPONENT_CLASS_TYPE_SINK: + return "SINK"; + case BT_COMPONENT_CLASS_TYPE_FILTER: + return "FILTER"; + default: + return "(unknown)"; + } +} + #ifdef __cplusplus } #endif diff --git a/src/lib/graph/component-class.c b/src/lib/graph/component-class.c index dcdd8e7d..c3a47291 100644 --- a/src/lib/graph/component-class.c +++ b/src/lib/graph/component-class.c @@ -540,7 +540,7 @@ bt_component_class_set_description( "addr=%p, name=\"%s\", type=%s", comp_cls, bt_component_class_get_name(comp_cls), - bt_component_class_type_string(comp_cls->type)); + bt_common_component_class_type_string(comp_cls->type)); return BT_FUNC_STATUS_OK; } diff --git a/src/lib/graph/component-class.h b/src/lib/graph/component-class.h index ac51bcfb..17000909 100644 --- a/src/lib/graph/component-class.h +++ b/src/lib/graph/component-class.h @@ -98,21 +98,6 @@ void _bt_component_class_freeze( # define bt_component_class_freeze(_cc) #endif -static inline -const char *bt_component_class_type_string(enum bt_component_class_type type) -{ - switch (type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - return "SOURCE"; - case BT_COMPONENT_CLASS_TYPE_SINK: - return "SINK"; - case BT_COMPONENT_CLASS_TYPE_FILTER: - return "FILTER"; - default: - return "(unknown)"; - } -} - static inline bool bt_component_class_has_message_iterator_class( struct bt_component_class *component_class) diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 4085cd26..8766e446 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -1057,7 +1057,7 @@ static inline void format_component_class(char **buf_ch, bool extended, char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s, %sname=\"%s\"", - PRFIELD(bt_component_class_type_string(comp_class->type)), + PRFIELD(bt_common_component_class_type_string(comp_class->type)), PRFIELD_GSTRING(comp_class->name)); if (comp_class->description) { @@ -1335,7 +1335,7 @@ static inline void format_error_cause(char **buf_ch, bool extended, if (comp_class_id) { BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", " "%splugin-name=\"%s\"", - PRFIELD(bt_component_class_type_string( + PRFIELD(bt_common_component_class_type_string( comp_class_id->type)), PRFIELD_GSTRING(comp_class_id->name), PRFIELD_GSTRING(comp_class_id->plugin_name)); diff --git a/src/lib/plugin/plugin-so.c b/src/lib/plugin/plugin-so.c index 02428c2a..3017e6c0 100644 --- a/src/lib/plugin/plugin-so.c +++ b/src/lib/plugin/plugin-so.c @@ -686,7 +686,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, NULL, descriptor->name, cur_cc_descr_attr->comp_class_descriptor->name, - bt_component_class_type_string( + bt_common_component_class_type_string( cur_cc_descr_attr->comp_class_descriptor->type), cur_cc_descr_attr->type_name, cur_cc_descr_attr->type); @@ -706,7 +706,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, NULL, descriptor->name, cur_cc_descr_attr->comp_class_descriptor->name, - bt_component_class_type_string( + bt_common_component_class_type_string( cur_cc_descr_attr->comp_class_descriptor->type), cur_cc_descr_attr->type_name, cur_cc_descr_attr->type); @@ -766,7 +766,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, NULL, descriptor->name, cc_full_descr->descriptor->name, - bt_component_class_type_string( + bt_common_component_class_type_string( cc_full_descr->descriptor->type)); if (cc_full_descr->descriptor->type == BT_COMPONENT_CLASS_TYPE_SOURCE || diff --git a/src/python-plugin-provider/python-plugin-provider.c b/src/python-plugin-provider/python-plugin-provider.c index 78026d6a..e6e31099 100644 --- a/src/python-plugin-provider/python-plugin-provider.c +++ b/src/python-plugin-provider/python-plugin-provider.c @@ -571,7 +571,7 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, bt_plugin_get_name(*plugin_out), comp_class, bt_component_class_get_name(comp_class), - bt_component_class_type_string( + bt_common_component_class_type_string( bt_component_class_get_type(comp_class))); goto error; } diff --git a/tests/cli/query/test_query b/tests/cli/query/test_query index 3227650b..21a35467 100755 --- a/tests/cli/query/test_query +++ b/tests/cli/query/test_query @@ -79,7 +79,7 @@ expect_failure "ValueError: catastrophic failure" \ 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2' # Non-existent component class. -expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=1' \ +expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=SOURCE' \ 'src.query.NonExistentSource' 'the-object' '-p' 'a=2' # Wrong parameter syntax. diff --git a/tests/cli/test_help b/tests/cli/test_help index 3445269b..fb7cb598 100755 --- a/tests/cli/test_help +++ b/tests/cli/test_help @@ -82,7 +82,7 @@ ok $? "help with unknown plugin name produces no output" bt_cli "${stdout}" "${stderr}" help src.ctf.bob isnt $? 0 "help with unknown component class name" -grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=1' "${stderr}" +grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' "${stderr}" ok $? "help with unknown component class name produces expected error" grep --silent 'Description: CTF input and output' "${stdout}" -- 2.34.1