tests: use -z / -n to test for string empty / non-empty
[babeltrace.git] / tests / plugins / src.ctf.fs / succeed / test_succeed
... / ...
CommitLineData
1#!/bin/bash
2#
3# SPDX-License-Identifier: GPL-2.0-only
4#
5# Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
6#
7
8# This test validates that a `src.ctf.fs` component successfully reads
9# specific CTF traces and creates the expected messages.
10#
11# Such CTF traces to open either exist (in `tests/ctf-traces/succeed`)
12# or are generated by this test using local trace generators.
13
14SH_TAP=1
15
16if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
17 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
18else
19 UTILSSH="$(dirname "$0")/../../../utils/utils.sh"
20fi
21
22# shellcheck source=../../../utils/utils.sh
23source "$UTILSSH"
24
25this_dir_relative="plugins/src.ctf.fs/succeed"
26this_dir_build="$BT_TESTS_BUILDDIR/$this_dir_relative"
27succeed_trace_dir="$BT_CTF_TRACES_PATH/succeed"
28expect_dir="$BT_TESTS_DATADIR/$this_dir_relative"
29
30test_ctf_common_details_args=("-p" "with-trace-name=no,with-stream-name=no")
31
32test_ctf_gen_single() {
33 name="$1"
34
35 diag "Generating trace '$name'"
36 bt_diff_details_ctf_gen_single "$this_dir_build/gen-trace-$name" \
37 "$expect_dir/trace-$name.expect" \
38 "${test_ctf_common_details_args[@]}" "-p" "with-uuid=no"
39 ok $? "Generated trace '$name' gives the expected output"
40}
41
42test_ctf_single() {
43 name="$1"
44
45 bt_diff_details_ctf_single "$expect_dir/trace-$name.expect" \
46 "$succeed_trace_dir/$name" "${test_ctf_common_details_args[@]}"
47 ok $? "Trace '$name' gives the expected output"
48}
49
50test_packet_end() {
51 local name="$1"
52 local expected_stdout="$expect_dir/trace-$name.expect"
53 local ret=0
54 local ret_stdout
55 local ret_stderr
56 local details_comp=("-c" "sink.text.details")
57 local details_args=("-p" "with-trace-name=no,with-stream-name=no,with-metadata=no,compact=yes")
58 local temp_stdout_output_file
59 local temp_greped_stdout_output_file
60 local temp_stderr_output_file
61
62 temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
63 temp_greped_stdout_output_file="$(mktemp -t greped_stdout.XXXXXX)"
64 temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
65
66 bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" \
67 "$succeed_trace_dir/$name" "${details_comp[@]}" \
68 "${details_args[@]}"
69
70 "$BT_TESTS_GREP_BIN" "Packet end" "$temp_stdout_output_file" > "$temp_greped_stdout_output_file"
71
72 bt_diff "$expected_stdout" "$temp_greped_stdout_output_file"
73 ret_stdout=$?
74
75 bt_diff /dev/null "$temp_stderr_output_file"
76 ret_stderr=$?
77
78 if ((ret_stdout != 0 || ret_stderr != 0)); then
79 ret=1
80 fi
81
82 ok $ret "Trace '$name' gives the expected output"
83 rm -f "$temp_stdout_output_file" "$temp_stderr_output_file" "$temp_greped_stdout_output_file"
84}
85
86test_force_origin_unix_epoch() {
87 local name1="$1"
88 local name2="$2"
89 local expected_stdout="$expect_dir/trace-$name1-$name2.expect"
90 local ret=0
91 local ret_stdout
92 local ret_stderr
93 local src_ctf_fs_args=("-p" "force-clock-class-origin-unix-epoch=true")
94 local details_comp=("-c" "sink.text.details")
95 local details_args=("-p" "with-trace-name=no,with-stream-name=no,with-metadata=yes,compact=yes")
96 local temp_stdout_output_file
97 local temp_stderr_output_file
98
99 temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
100 temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
101
102 bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" \
103 "$succeed_trace_dir/$name1" "${src_ctf_fs_args[@]}" \
104 "$succeed_trace_dir/$name2" "${src_ctf_fs_args[@]}" \
105 "${details_comp[@]}" "${details_args[@]}"
106
107 bt_diff "$expected_stdout" "$temp_stdout_output_file"
108 ret_stdout=$?
109
110 if ((ret_stdout != 0)); then
111 ret=1
112 fi
113
114 ok $ret "Trace '$name1' and '$name2' give the expected stdout"
115
116 bt_diff /dev/null "$temp_stderr_output_file"
117 ret_stderr=$?
118
119 if ((ret_stderr != 0)); then
120 ret=1
121 fi
122
123 ok $ret "Trace '$name1' and '$name2' give the expected stderr"
124
125 rm -f "$temp_stdout_output_file" "$temp_stderr_output_file"
126}
127
128plan_tests 13
129
130test_force_origin_unix_epoch 2packets barectf-event-before-packet
131test_ctf_gen_single simple
132test_ctf_single smalltrace
133test_ctf_single 2packets
134test_ctf_single barectf-event-before-packet
135test_ctf_single session-rotation
136test_ctf_single lttng-tracefile-rotation
137test_ctf_single array-align-elem
138test_ctf_single struct-array-align-elem
139test_ctf_single meta-ctx-sequence
140test_packet_end lttng-event-after-packet
141test_packet_end lttng-crash
This page took 0.022606 seconds and 4 git commands to generate.