Fix: tests: app unregistering is not guaranteed by app lifetime
[lttng-tools.git] / tests / utils / utils.sh
index 530a1062389a7f667fdf82732fd297ebf7bfcbdc..1e7d88b76c6a74aa373793003a1b56aca42642ab 100644 (file)
@@ -15,6 +15,14 @@ LTTNG_BIN="lttng"
 BABELTRACE_BIN="babeltrace"
 OUTPUT_DEST=/dev/null
 ERROR_OUTPUT_DEST=/dev/null
+MI_XSD_MAJOR_VERSION=4
+MI_XSD_MINOR_VERSION=1
+MI_XSD_PATH="$TESTDIR/../src/common/mi-lttng-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd"
+MI_VALIDATE="$TESTDIR/utils/xml-utils/validate_xml ${MI_XSD_PATH}"
+
+XML_PRETTY="$TESTDIR/utils/xml-utils/pretty_xml"
+XML_EXTRACT="$TESTDIR/utils/xml-utils/extract_xml"
+XML_NODE_CHECK="${XML_EXTRACT} -e"
 
 # To match 20201127-175802
 date_time_pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]"
@@ -718,7 +726,7 @@ function stop_lttng_sessiond_opt()
        fi
 
        if [ -z "$pids" ]; then
-               if [ "$is_cleanup" -eq 1 ]; then 
+               if [ "$is_cleanup" -eq 1 ]; then
                        :
                elif [ "$withtap" -eq "1" ]; then
                        fail "No session daemon to kill"
@@ -998,9 +1006,25 @@ function sigstop_lttng_consumerd_notap()
 
 function list_lttng_with_opts ()
 {
+       local ret
+       local withtap=$1
+       shift
        local opts=$1
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
-       ok $? "Lttng-tool list command with option $opts"
+       ret=$?
+       if [ $withtap -eq "1" ]; then
+               ok $ret "Lttng-tool list command with option $opts"
+       fi
+}
+
+function list_lttng_ok ()
+{
+       list_lttng_with_opts 1 "$@"
+}
+
+function list_lttng_notap ()
+{
+       list_lttng_with_opts 0 "$@"
 }
 
 function create_lttng_session_no_output ()
@@ -1857,7 +1881,7 @@ function validate_trace
                        pass "Validate trace for event $i, $traced events"
                else
                        fail "Validate trace for event $i"
-                       diag "Found $traced occurences of $i"
+                       diag "Found $traced occurrences of $i"
                fi
        done
        ret=$?
@@ -1885,7 +1909,7 @@ function validate_trace_count
                        pass "Validate trace for event $i, $traced events"
                else
                        fail "Validate trace for event $i"
-                       diag "Found $traced occurences of $i"
+                       diag "Found $traced occurrences of $i"
                fi
                cnt=$(($cnt + $traced))
        done
@@ -1915,7 +1939,7 @@ function validate_trace_count_range_incl_min_excl_max
                        pass "Validate trace for event $i, $traced events"
                else
                        fail "Validate trace for event $i"
-                       diag "Found $traced occurences of $i"
+                       diag "Found $traced occurrences of $i"
                fi
                cnt=$(($cnt + $traced))
        done
@@ -1949,7 +1973,7 @@ function validate_trace_exp()
                pass "Validate trace for expression '${event_exp}', $traced events"
        else
                fail "Validate trace for expression '${event_exp}'"
-               diag "Found $traced occurences of '${event_exp}'"
+               diag "Found $traced occurrences of '${event_exp}'"
        fi
        ret=$?
        return $ret
@@ -2249,8 +2273,8 @@ function lttng_remove_trigger_ok()
 
 function list_triggers_matches_ok ()
 {
-       local tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
-       local tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
+       local tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
+       local tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
 
        local test_name="$1"
        local expected_stdout_file="$2"
@@ -2270,6 +2294,41 @@ function list_triggers_matches_ok ()
        rm -f "${tmp_stderr}"
 }
 
+function list_triggers_matches_mi_ok ()
+{
+       local tmp_stdout
+       local tmp_stdout_raw
+       local tmp_stderr
+
+       local test_name="$1"
+       local expected_stdout_file="$2"
+
+       tmp_stdout_raw=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
+       tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
+       tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX")
+
+       diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers"
+
+       "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers > "${tmp_stdout_raw}" 2> "${tmp_stderr}"
+       ok $? "${test_name}: exit code is 0"
+
+       # Pretty-fy xml before further test.
+       $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
+
+       $MI_VALIDATE "${tmp_stdout}"
+       ok $? "list-trigger mi is valid"
+
+       diff -u "${expected_stdout_file}" "${tmp_stdout}"
+       ok $? "${test_name}: expected stdout"
+
+       diff -u /dev/null "${tmp_stderr}"
+       ok $? "${test_name}: expected stderr"
+
+       rm -f "${tmp_stdout}"
+       rm -f "${tmp_stdout_raw}"
+       rm -f "${tmp_stderr}"
+}
+
 function validate_path_pattern ()
 {
        local message=$1
This page took 0.027063 seconds and 4 git commands to generate.