+function test_mi ()
+{
+ local tmp_stdout_raw
+ local tmp_expected_stdout
+
+ # Concretely the code used to serialize a trigger object is the same as
+ # the one used by the list command. Here we simply validate that a
+ # simple trigger is correctly generated.
+
+ tmp_stdout_raw=$(mktemp -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
+ tmp_expected_stdout=$(mktemp -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX")
+
+ diag "${FULL_LTTNG_BIN} --mi=xml add-trigger"
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ <?xml version="1.0" encoding="UTF-8"?>
+ <command xmlns="https://lttng.org/xml/ns/lttng-mi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://lttng.org/xml/ns/lttng-mi https://lttng.org/xml/schemas/lttng-mi/${MI_XSD_MAJOR_VERSION}/lttng-mi-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd" schemaVersion="${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}">
+ <name>add-trigger</name>
+ <output>
+ <trigger>
+ <name>mi_hohoho</name>
+ <owner_uid>${UID}</owner_uid>
+ <condition>
+ <condition_event_rule_matches>
+ <event_rule>
+ <event_rule_user_tracepoint>
+ <name_pattern>some-event-id</name_pattern>
+ </event_rule_user_tracepoint>
+ </event_rule>
+ <capture_descriptors/>
+ </condition_event_rule_matches>
+ </condition>
+ <action>
+ <action_list>
+ <action>
+ <action_notify>
+ <rate_policy>
+ <rate_policy_every_n>
+ <interval>1</interval>
+ </rate_policy_every_n>
+ </rate_policy>
+ </action_notify>
+ </action>
+ </action_list>
+ </action>
+ </trigger>
+ </output>
+ <success>true</success>
+ </command>
+ EOF
+
+ "${FULL_LTTNG_BIN}" --mi xml add-trigger --name mi_hohoho \
+ --condition event-rule-matches --name=some-event-id --type=user \
+ --action notify > "${tmp_stdout_raw}" 2> "${tmp_stderr}"
+
+ ok $? "add-trigger mi: exit code is 0"
+
+ # Pretty-fy xml before further test.
+ $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
+
+ $MI_VALIDATE "${tmp_stdout}"
+ ok $? "add-trigger mi is valid"
+
+ diff -u "${tmp_expected_stdout}" "${tmp_stdout}"
+ ok $? "mi: expected stdout"
+
+ diff -u "${tmp_stderr}" /dev/null
+ ok $? "mi: expected stderr"
+
+ rm -f "${tmp_stdout_raw}"
+}
+