#include "metadata.hpp"
#include "../common/metadata/decoder.hpp"
-FILE *ctf_fs_metadata_open_file(const char *trace_path)
+FILE *ctf_fs_metadata_open_file(const char *trace_path, bt_logging_level log_level,
+ bt_self_component_class *comp_class)
{
GString *metadata_path;
FILE *fp = NULL;
g_string_append(metadata_path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
fp = fopen(metadata_path->str, "rb");
+ if (!fp) {
+ BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(comp_class, "Failed to open metadata file",
+ ": path=\"%s\"", metadata_path->str);
+ }
+
g_string_free(metadata_path, TRUE);
+
end:
return fp;
}
int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_trace *ctf_fs_trace,
struct ctf_fs_metadata_config *config);
-FILE *ctf_fs_metadata_open_file(const char *trace_path);
+FILE *ctf_fs_metadata_open_file(const char *trace_path, bt_logging_level log_level,
+ bt_self_component_class *comp_class);
bool ctf_metadata_is_packetized(FILE *fp, int *byte_order);
path = bt_value_string_get(path_value);
BT_ASSERT(path);
- metadata_fp = ctf_fs_metadata_open_file(path);
+ metadata_fp = ctf_fs_metadata_open_file(path, log_level, self_comp_class);
if (!metadata_fp) {
BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Cannot open trace metadata: path=\"%s\".",
path);
rm -f "$temp_stdout_output_file" "$temp_stderr_output_file"
}
-plan_tests 1
+test_non_existent_trace_dir() {
+ local empty_dir
+ local stdout_file
+ local stderr_file
+ local query
+
+ empty_dir=$(mktemp -d)
+ stdout_file="$(mktemp -t actual_stdout.XXXXXX)"
+ stderr_file="$(mktemp -t actual_stderr.XXXXXX)"
+ query=("query" "src.ctf.fs" "metadata-info" "--params" "path=\"$empty_dir\"")
+
+ bt_cli "$stdout_file" "$stderr_file" \
+ "${query[@]}"
+ isnt $? 0 "non existent trace dir: babeltrace exits with an error"
+
+ bt_diff "/dev/null" "${stdout_file}"
+ ok $? "non existent trace dir: babeltrace produces the expected stdout"
+
+ grep --silent "^CAUSED BY " "${stderr_file}"
+ ok $? "non existent trace dir: babeltrace produces an error stack"
+
+ grep --silent "Failed to open metadata file: No such file or directory: path=\".*metadata\"" \
+ "${stderr_file}"
+ ok $? "non existent trace dir: babeltrace produces the expected error message"
+
+ rm -f "${stdout_file}" "${stderr_file}"
+}
+
+plan_tests 5
test_query_metadata_info succeed1
+test_non_existent_trace_dir