flt.lttng-utils.debug-info: validate parameters using param-validation
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 5 Oct 2019 05:14:21 +0000 (01:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 17 Oct 2019 16:13:26 +0000 (12:13 -0400)
This patch makes sink.ctf.fs validate its parameters using the
param-validation utility, instead of doing it by hand.

Change-Id: Iaa8cc02bd82ad7e1af2d18e1f1f7b73c5c5c8f19
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2142
CI-Build: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/lttng-utils/Makefile.am
src/plugins/lttng-utils/debug-info/debug-info.c

index b4322c480b2761568144c8cd5965b850fc234afe..52939803eec550f7ed393d0b5ea55c9ff19bc815 100644 (file)
@@ -23,5 +23,6 @@ if !ENABLE_BUILT_IN_PLUGINS
 babeltrace_plugin_lttng_utils_la_LIBADD += \
        $(top_builddir)/src/lib/libbabeltrace2.la \
        $(top_builddir)/src/common/libbabeltrace2-common.la \
-       $(top_builddir)/src/logging/libbabeltrace2-logging.la
+       $(top_builddir)/src/logging/libbabeltrace2-logging.la \
+       $(top_builddir)/src/plugins/common/param-validation/libbabeltrace2-param-validation.la
 endif
index 426f50c65bbeab30aed559e19eb1b4e30e050860..044d4f245124cbaf1c13821733cdc18b5a09b9c1 100644 (file)
@@ -43,6 +43,7 @@
 #include "trace-ir-mapping.h"
 #include "trace-ir-metadata-copy.h"
 #include "utils.h"
+#include "plugins/common/param-validation/param-validation.h"
 
 #define DEFAULT_DEBUG_INFO_FIELD_NAME  "debug_info"
 #define LTTNG_UST_STATEDUMP_PREFIX     "lttng_ust"
@@ -1683,6 +1684,14 @@ const bt_message *handle_message(struct debug_info_msg_iter *debug_it,
        return out_message;
 }
 
+struct bt_param_validation_map_value_entry_descr debug_info_params[] = {
+       { "debug-info-field-name", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } },
+       { "debug-info-dir", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } },
+       { "target-prefix", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } },
+       { "full-path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } },
+       BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
+};
+
 static
 bt_component_class_initialize_method_status init_from_params(
                struct debug_info_component *debug_info_component,
@@ -1690,6 +1699,21 @@ bt_component_class_initialize_method_status init_from_params(
 {
        const bt_value *value;
        bt_component_class_initialize_method_status status;
+       bt_logging_level log_level = debug_info_component->log_level;
+       enum bt_param_validation_status validation_status;
+       gchar *validate_error = NULL;
+
+       validation_status = bt_param_validation_validate(params,
+               debug_info_params, &validate_error);
+       if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
+               status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
+               goto end;
+       } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
+               status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
+               BT_COMP_LOGE_APPEND_CAUSE(debug_info_component->self_comp,
+                       "%s", validate_error);
+               goto end;
+       }
 
        BT_ASSERT(params);
 
@@ -1729,6 +1753,9 @@ bt_component_class_initialize_method_status init_from_params(
 
        status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
 
+end:
+       g_free(validate_error);
+
        return status;
 }
 
This page took 0.026164 seconds and 4 git commands to generate.