From 486428e8650cd2ce609d8cc4dce18ac59e94a581 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 23 May 2023 10:49:37 -0400 Subject: [PATCH] tests: re-format conds C++ files Run tools/format-cpp to format the new C++ files. Change-Id: Ia919658ed83e8ade0ade02709774caf57b1ee455 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10054 Tested-by: jenkins Reviewed-by: Philippe Proulx --- tests/lib/conds/conds-triggers.cpp | 68 ++++----- tests/lib/conds/utils.cpp | 229 ++++++++++++++--------------- tests/lib/conds/utils.hpp | 111 +++++++------- 3 files changed, 184 insertions(+), 224 deletions(-) diff --git a/tests/lib/conds/conds-triggers.cpp b/tests/lib/conds/conds-triggers.cpp index 4c10f380..abad4ed4 100644 --- a/tests/lib/conds/conds-triggers.cpp +++ b/tests/lib/conds/conds-triggers.cpp @@ -9,66 +9,50 @@ #include "common/assert.h" #include "utils.hpp" -static -void trigger_graph_mip_version(void) +static void trigger_graph_mip_version(void) { - bt_graph_create(292); + bt_graph_create(292); } -static -bt_field_class *get_uint_fc(bt_self_component *self_comp) +static bt_field_class *get_uint_fc(bt_self_component *self_comp) { - bt_trace_class *tc = bt_trace_class_create(self_comp); - bt_field_class *fc; + bt_trace_class *tc = bt_trace_class_create(self_comp); + bt_field_class *fc; - BT_ASSERT(tc); - fc = bt_field_class_integer_unsigned_create(tc); - BT_ASSERT(fc); - return fc; + BT_ASSERT(tc); + fc = bt_field_class_integer_unsigned_create(tc); + BT_ASSERT(fc); + return fc; } -static -void trigger_fc_int_set_field_value_range_n_0(bt_self_component *self_comp) +static void trigger_fc_int_set_field_value_range_n_0(bt_self_component *self_comp) { - bt_field_class_integer_set_field_value_range(get_uint_fc(self_comp), 0); + bt_field_class_integer_set_field_value_range(get_uint_fc(self_comp), 0); } -static -void trigger_fc_int_set_field_value_range_n_gt_64(bt_self_component *self_comp) +static void trigger_fc_int_set_field_value_range_n_gt_64(bt_self_component *self_comp) { - bt_field_class_integer_set_field_value_range(get_uint_fc(self_comp), - 65); + bt_field_class_integer_set_field_value_range(get_uint_fc(self_comp), 65); } -static -void trigger_fc_int_set_field_value_range_null(bt_self_component *self_comp) +static void trigger_fc_int_set_field_value_range_null(bt_self_component *self_comp) { - bt_field_class_integer_set_field_value_range(NULL, 23); + bt_field_class_integer_set_field_value_range(NULL, 23); } -static -const struct cond_trigger triggers[] = { - COND_TRIGGER_PRE_BASIC("pre:graph-create:valid-mip-version", NULL, - trigger_graph_mip_version), - COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT( - "pre:field-class-integer-set-field-value-range:valid-n", - "0", - trigger_fc_int_set_field_value_range_n_0 - ), - COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT( - "pre:field-class-integer-set-field-value-range:valid-n", - "gt-64", - trigger_fc_int_set_field_value_range_n_gt_64 - ), - COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT( - "pre:field-class-integer-set-field-value-range:not-null:field-class", - NULL, - trigger_fc_int_set_field_value_range_null - ), +static const struct cond_trigger triggers[] = { + COND_TRIGGER_PRE_BASIC("pre:graph-create:valid-mip-version", NULL, trigger_graph_mip_version), + COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT("pre:field-class-integer-set-field-value-range:valid-n", + "0", trigger_fc_int_set_field_value_range_n_0), + COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT("pre:field-class-integer-set-field-value-range:valid-n", + "gt-64", trigger_fc_int_set_field_value_range_n_gt_64), + COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT( + "pre:field-class-integer-set-field-value-range:not-null:field-class", NULL, + trigger_fc_int_set_field_value_range_null), }; int main(int argc, const char *argv[]) { - cond_main(argc, argv, triggers, sizeof(triggers) / sizeof(*triggers)); - return 0; + cond_main(argc, argv, triggers, sizeof(triggers) / sizeof(*triggers)); + return 0; } diff --git a/tests/lib/conds/utils.cpp b/tests/lib/conds/utils.cpp index 015e09bb..3ea99597 100644 --- a/tests/lib/conds/utils.cpp +++ b/tests/lib/conds/utils.cpp @@ -14,171 +14,156 @@ #include "common/assert.h" #include "utils.hpp" -typedef void (* run_in_comp_cls_init_func)( - bt_self_component *self_comp, void *user_data); +typedef void (*run_in_comp_cls_init_func)(bt_self_component *self_comp, void *user_data); -struct comp_cls_init_method_data { - run_in_comp_cls_init_func func; - void *user_data; +struct comp_cls_init_method_data +{ + run_in_comp_cls_init_func func; + void *user_data; }; -static -bt_component_class_initialize_method_status comp_cls_init( - bt_self_component_source *self_comp, - bt_self_component_source_configuration *conf, - const bt_value *params, void *init_method_data) +static bt_component_class_initialize_method_status +comp_cls_init(bt_self_component_source *self_comp, bt_self_component_source_configuration *conf, + const bt_value *params, void *init_method_data) { - comp_cls_init_method_data *data = - static_cast(init_method_data); + comp_cls_init_method_data *data = static_cast(init_method_data); - /* Call user function which is expected to abort */ - data->func(bt_self_component_source_as_self_component(self_comp), - data->user_data); + /* Call user function which is expected to abort */ + data->func(bt_self_component_source_as_self_component(self_comp), data->user_data); - /* Never reached! */ - return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; + /* Never reached! */ + return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; } -static -bt_message_iterator_class_next_method_status msg_iter_cls_next( - bt_self_message_iterator *self_msg_iter, - bt_message_array_const msgs, uint64_t capacity, - uint64_t *count) +static bt_message_iterator_class_next_method_status +msg_iter_cls_next(bt_self_message_iterator *self_msg_iter, bt_message_array_const msgs, + uint64_t capacity, uint64_t *count) { - /* Not used */ - return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; + /* Not used */ + return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; } -static -void run_in_comp_cls_init(run_in_comp_cls_init_func func, - void *user_data) +static void run_in_comp_cls_init(run_in_comp_cls_init_func func, void *user_data) { - bt_message_iterator_class *msg_iter_cls; - bt_component_class_source *comp_cls; - bt_component_class_set_method_status set_method_status; - bt_graph *graph; - struct comp_cls_init_method_data init_method_data = { - .func = func, - .user_data = user_data, - }; - - /* Create component class */ - msg_iter_cls = bt_message_iterator_class_create(msg_iter_cls_next); - BT_ASSERT(msg_iter_cls); - comp_cls = bt_component_class_source_create("yo", msg_iter_cls); - BT_ASSERT(comp_cls); - set_method_status = bt_component_class_source_set_initialize_method( - comp_cls, comp_cls_init); - BT_ASSERT(set_method_status == BT_COMPONENT_CLASS_SET_METHOD_STATUS_OK); - - /* Create graph */ - graph = bt_graph_create(0); - BT_ASSERT(graph); - - /* + bt_message_iterator_class *msg_iter_cls; + bt_component_class_source *comp_cls; + bt_component_class_set_method_status set_method_status; + bt_graph *graph; + struct comp_cls_init_method_data init_method_data = { + .func = func, + .user_data = user_data, + }; + + /* Create component class */ + msg_iter_cls = bt_message_iterator_class_create(msg_iter_cls_next); + BT_ASSERT(msg_iter_cls); + comp_cls = bt_component_class_source_create("yo", msg_iter_cls); + BT_ASSERT(comp_cls); + set_method_status = bt_component_class_source_set_initialize_method(comp_cls, comp_cls_init); + BT_ASSERT(set_method_status == BT_COMPONENT_CLASS_SET_METHOD_STATUS_OK); + + /* Create graph */ + graph = bt_graph_create(0); + BT_ASSERT(graph); + + /* * Add source component: this calls the initialization method, * calling `func`. */ - (void) bt_graph_add_source_component_with_initialize_method_data(graph, - comp_cls, "whatever", NULL, &init_method_data, - BT_LOGGING_LEVEL_NONE, NULL); + (void) bt_graph_add_source_component_with_initialize_method_data( + graph, comp_cls, "whatever", NULL, &init_method_data, BT_LOGGING_LEVEL_NONE, NULL); - /* + /* * This point is not expected to be reached as func() is * expected to abort. */ } -static -void run_in_comp_cls_init_defer(bt_self_component *self_comp, - void *user_data) +static void run_in_comp_cls_init_defer(bt_self_component *self_comp, void *user_data) { - cond_trigger_run_in_comp_cls_init_func user_func = - reinterpret_cast(user_data); + cond_trigger_run_in_comp_cls_init_func user_func = + reinterpret_cast(user_data); - user_func(self_comp); + user_func(self_comp); } -static -void run_trigger(const struct cond_trigger *trigger) +static void run_trigger(const struct cond_trigger *trigger) { - switch (trigger->func_type) { - case COND_TRIGGER_FUNC_TYPE_BASIC: - trigger->func.basic(); - break; - case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT: - run_in_comp_cls_init(run_in_comp_cls_init_defer, - reinterpret_cast(trigger->func.run_in_comp_cls_init)); - break; - default: - abort(); - } + switch (trigger->func_type) { + case COND_TRIGGER_FUNC_TYPE_BASIC: + trigger->func.basic(); + break; + case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT: + run_in_comp_cls_init(run_in_comp_cls_init_defer, + reinterpret_cast(trigger->func.run_in_comp_cls_init)); + break; + default: + abort(); + } } -static -void escape_json_string(const char *str, GString *escaped_str) +static void escape_json_string(const char *str, GString *escaped_str) { - g_string_assign(escaped_str, ""); + g_string_assign(escaped_str, ""); - for (const char *ch = str; *ch; ch++) { - if (*ch == '\\' || *ch == '"') { - g_string_append_c(escaped_str, '\\'); - } + for (const char *ch = str; *ch; ch++) { + if (*ch == '\\' || *ch == '"') { + g_string_append_c(escaped_str, '\\'); + } - g_string_append_c(escaped_str, *ch); - } + g_string_append_c(escaped_str, *ch); + } } -static -void list_triggers(const struct cond_trigger triggers[], size_t trigger_count) +static void list_triggers(const struct cond_trigger triggers[], size_t trigger_count) { - GString *escaped_str = g_string_new(NULL); - size_t i; + GString *escaped_str = g_string_new(NULL); + size_t i; - BT_ASSERT(escaped_str); - printf("["); + BT_ASSERT(escaped_str); + printf("["); - for (i = 0; i < trigger_count; i++) { - const struct cond_trigger *trigger = &triggers[i]; + for (i = 0; i < trigger_count; i++) { + const struct cond_trigger *trigger = &triggers[i]; - /* Condition ID */ - escape_json_string(trigger->cond_id, escaped_str); - printf("{\"cond-id\":\"%s\",", escaped_str->str); + /* Condition ID */ + escape_json_string(trigger->cond_id, escaped_str); + printf("{\"cond-id\":\"%s\",", escaped_str->str); - /* Name starts with condition ID */ - printf("\"name\":\"%s", escaped_str->str); + /* Name starts with condition ID */ + printf("\"name\":\"%s", escaped_str->str); - if (trigger->suffix) { - escape_json_string(trigger->suffix, escaped_str); - printf("-%s", escaped_str->str); - } + if (trigger->suffix) { + escape_json_string(trigger->suffix, escaped_str); + printf("-%s", escaped_str->str); + } - printf("\"}"); + printf("\"}"); - if (i < trigger_count - 1) { - /* Comma between objects */ - printf(","); - } - } + if (i < trigger_count - 1) { + /* Comma between objects */ + printf(","); + } + } - printf("]"); - g_string_free(escaped_str, TRUE); - fflush(stdout); + printf("]"); + g_string_free(escaped_str, TRUE); + fflush(stdout); } -void cond_main(int argc, const char *argv[], - const struct cond_trigger triggers[], size_t trigger_count) +void cond_main(int argc, const char *argv[], const struct cond_trigger triggers[], + size_t trigger_count) { - BT_ASSERT(argc >= 2); - - if (strcmp(argv[1], "list") == 0) { - list_triggers(triggers, trigger_count); - } else if (strcmp(argv[1], "run") == 0) { - int index; - - BT_ASSERT(argc >= 3); - index = atoi(argv[2]); - BT_ASSERT(index >= 0 && index < trigger_count); - run_trigger(&triggers[index]); - } + BT_ASSERT(argc >= 2); + + if (strcmp(argv[1], "list") == 0) { + list_triggers(triggers, trigger_count); + } else if (strcmp(argv[1], "run") == 0) { + int index; + + BT_ASSERT(argc >= 3); + index = atoi(argv[2]); + BT_ASSERT(index >= 0 && index < trigger_count); + run_trigger(&triggers[index]); + } } diff --git a/tests/lib/conds/utils.hpp b/tests/lib/conds/utils.hpp index 1a77bde5..bab8caea 100644 --- a/tests/lib/conds/utils.hpp +++ b/tests/lib/conds/utils.hpp @@ -7,76 +7,67 @@ #ifndef TESTS_LIB_CONDS_UTILS_H #define TESTS_LIB_CONDS_UTILS_H -enum cond_trigger_func_type { - COND_TRIGGER_FUNC_TYPE_BASIC, - COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, +enum cond_trigger_func_type +{ + COND_TRIGGER_FUNC_TYPE_BASIC, + COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, }; -enum cond_trigger_type { - COND_TRIGGER_TYPE_PRE, - COND_TRIGGER_TYPE_POST, +enum cond_trigger_type +{ + COND_TRIGGER_TYPE_PRE, + COND_TRIGGER_TYPE_POST, }; -typedef void (* cond_trigger_basic_func)(void); -typedef void (* cond_trigger_run_in_comp_cls_init_func)(bt_self_component *); +typedef void (*cond_trigger_basic_func)(void); +typedef void (*cond_trigger_run_in_comp_cls_init_func)(bt_self_component *); -struct cond_trigger { - enum cond_trigger_type type; - enum cond_trigger_func_type func_type; - const char *cond_id; - const char *suffix; - union { - cond_trigger_basic_func basic; - cond_trigger_run_in_comp_cls_init_func run_in_comp_cls_init; - } func; +struct cond_trigger +{ + enum cond_trigger_type type; + enum cond_trigger_func_type func_type; + const char *cond_id; + const char *suffix; + union + { + cond_trigger_basic_func basic; + cond_trigger_run_in_comp_cls_init_func run_in_comp_cls_init; + } func; }; -#define COND_TRIGGER_PRE_BASIC(_cond_id, _suffix, _func) \ - { \ - .type = COND_TRIGGER_TYPE_PRE, \ - .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ - .cond_id = _cond_id, \ - .suffix = _suffix, \ - .func = { \ - .basic = _func, \ - } \ - } +#define COND_TRIGGER_PRE_BASIC(_cond_id, _suffix, _func) \ + { \ + .type = COND_TRIGGER_TYPE_PRE, .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ + .cond_id = _cond_id, .suffix = _suffix, .func = { \ + .basic = _func, \ + } \ + } -#define COND_TRIGGER_POST_BASIC(_cond_id, _suffix, _func) \ - { \ - .type = COND_TRIGGER_TYPE_POST, \ - .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ - .cond_id = _cond_id, \ - .suffix = _suffix, \ - .func = { \ - .basic = _func, \ - } \ - } +#define COND_TRIGGER_POST_BASIC(_cond_id, _suffix, _func) \ + { \ + .type = COND_TRIGGER_TYPE_POST, .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ + .cond_id = _cond_id, .suffix = _suffix, .func = { \ + .basic = _func, \ + } \ + } -#define COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ - { \ - .type = COND_TRIGGER_TYPE_PRE, \ - .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ - .cond_id = _cond_id, \ - .suffix = _suffix, \ - .func = { \ - .run_in_comp_cls_init = _func, \ - } \ - } +#define COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ + { \ + .type = COND_TRIGGER_TYPE_PRE, .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ + .cond_id = _cond_id, .suffix = _suffix, .func = { \ + .run_in_comp_cls_init = _func, \ + } \ + } -#define COND_TRIGGER_POST_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ - { \ - .type = COND_TRIGGER_TYPE_POST, \ - .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ - .cond_id = _cond_id, \ - .suffix = _suffix, \ - .func = { \ - .run_in_comp_cls_init = _func, \ - } \ - } +#define COND_TRIGGER_POST_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ + { \ + .type = COND_TRIGGER_TYPE_POST, .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ + .cond_id = _cond_id, .suffix = _suffix, .func = { \ + .run_in_comp_cls_init = _func, \ + } \ + } -void cond_main(int argc, const char *argv[], - const struct cond_trigger triggers[], - size_t trigger_count); +void cond_main(int argc, const char *argv[], const struct cond_trigger triggers[], + size_t trigger_count); #endif /* TESTS_LIB_CONDS_UTILS_H */ -- 2.34.1