From 6f2597123e2ec03a3cfbf3c4e7e82b86b453d782 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Sat, 28 Mar 2015 18:00:09 -0400 Subject: [PATCH] Test: mi: track/untrack feature MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- tests/regression/tools/mi/test_mi | 185 +++++++++++++++++++++++++++++- tests/utils/utils.sh | 48 ++++++++ 2 files changed, 231 insertions(+), 2 deletions(-) diff --git a/tests/regression/tools/mi/test_mi b/tests/regression/tools/mi/test_mi index 5bd29ed4d..5e8a31d91 100755 --- a/tests/regression/tools/mi/test_mi +++ b/tests/regression/tools/mi/test_mi @@ -38,6 +38,7 @@ OUTPUT_FILE="default.xml" #Path to custom xml utilities XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH" XML_EXTRACT="$CURDIR/extract_xml" +XML_NODE_CHECK="$CURDIR/extract_xml -e" XPATH_CMD_OUTPUT="//command/output" XPATH_COMMAND_SUCCESS="/command/success/text()" @@ -47,16 +48,18 @@ XPATH_ENABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/events/event/success/text()" XPATH_DISABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/channel/events/event/success/text()" XPATH_LIST_DOMAIN="$XPATH_CMD_OUTPUT/sessions/session/domains/domain" XPATH_LIST_CHANNEL="$XPATH_CMD_OUTPUT/sessions/session/domains/domain/channels/channel" -XPATH_LIST_UST_EVENT="$XPATH_CMD_OUTPUT/domains/domain[./type = 'UST']/pids/pid/events/event" +XPATH_LIST_UST_EVENT="$XPATH_CMD_OUTPUT/domains/domain[./type ='UST']/processes/process/events/event" XPATH_SNAPSHOT_ADD_SNAPSHOT="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'add-output']/output" XPATH_SNAPSHOT_LIST="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'list-output']/output" XPATH_SNAPSHOT_DEL="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'del-output']/output" +XPATH_TRACK_UNTRACK_PID="$XPATH_CMD_OUTPUT/targets/pid_target" +XPATH_PID_TRACKER="$XPATH_CMD_OUTPUT/sessions/session/domains/domain/trackers/pid_tracker" DEVNULL=/dev/null 2>&1 DIR=$(readlink -f $TESTDIR) -NUM_TESTS=178 +NUM_TESTS=234 source $TESTDIR/utils/utils.sh @@ -84,6 +87,17 @@ function extract_xml () eval $__result="'$output'" } +function node_check_xml () +{ + local xml=$1 + local xpath=$2 + local __result=$3 + local output + output=$($XML_NODE_CHECK $xml "$xpath") + ok $? "Check of node existence with xpath $xpath" + eval $__result="'$output'" +} + # Arg1 is path to xml file # Arg2: # is true if we expected the success element to be false @@ -701,6 +715,172 @@ function test_snapshot () { destroy_lttng_sessions } +function test_track_untrack () +{ + diag "Test track/untrack pid" + + local session_name="testTrack" + local snapshot_path="$OUTPUT_DIR/trackoutput" + local pid="1,2,3" + OUTPUT_FILE="track.xml" + + #Test buid up + OUTPUT_DEST=$DEVNULL + create_lttng_session_no_output $session_name + + OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE + lttng_track_ok "-p $pid -u" + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: track pid xsd validation" + + #Expect a true element + extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result + test "$result" = "true" + ok $? "Mi test: track pid is a success" + + #Verify that there is 3 process + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "3" + ok $? "Mi test: track pid expecting 3 processes got $num" + + #Retry to enable and look for fail + lttng_track_fail "-p $pid -u" + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: fail track pid xsd validation" + + #Expect a false element + extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result + test "$result" = "false" + ok $? "Mi test: track pid expected false got $result" + + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"[./success='false']/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "3" + ok $? "Mi test: track pid expecting 3 failed process got $num" + + #Test the pid_tracker listing + list_lttng_with_opts $session_name + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: session list with pid_tracker validate" + + #Check the good count + extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/targets/pid_target/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "3" + ok $? "Mi test: tracker pid listing expecting 3 target got $num" + + #Untrack pid 2,3 + lttng_untrack_ok "-p 2,3 -u" + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: untrack pid xsd validation" + + #Expect a true element + extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result + test "$result" = "true" + ok $? "Mi test: untrack pid is a success" + + #Verify that there is 2 untracked pids + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "2" + ok $? "Mi test: untrack pid expecting 2 process got $num" + + #Retry to untrack and look for fail + lttng_untrack_fail "-p 2,3 -u" + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: fail untrack pid xsd validation" + + #Expect a false element + extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result + test "$result" = "false" + ok $? "Mi test: untrack pid expected false got $result" + + #Expect 2 failed attempt at untracking + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"[./success='false']/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "2" + ok $? "Mi test: untrack pid expecting 2 failed process got $num" + + #Check pid_tracker listing + list_lttng_with_opts $session_name + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: session list with pid_tracker validate" + + #Check the good count + extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/targets/pid_target/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "1" + ok $? "Mi test: tracker pid listing expecting 1 process got $num" + + #Untrack all + lttng_untrack_ok "-p -u -a" + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: untrack pid xsd validation" + + #Expect a true element + extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result + test "$result" = "true" + ok $? "Mi test: untrack all pid is a success" + + #Verify that there is 1 untracked pid + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "1" + ok $? "Mi test: untrack pid expecting 1 process got $num" + + #Test if the id is * which represent the all argument + test "$result" = "*" + ok $? "Mi test: pid expected is * got $result" + + #Test if pid_tracker is enabled as definied by pid_tracker + #behavior. If all pid are untrack than the pid_tracker is still + #enabled (pid_tracker node is present). + list_lttng_with_opts $session_name + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: session list with pid_tracker validate" + + #Check the good count + extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/targets/pid_target/pid" result + num=$(echo -n "$result" | wc -l) + test "$num" -eq "0" + ok $? "Mi test: tracker pid listing expecting 0 process got $num" + + #Test track all + lttng_track_ok "-p -u -a" + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: track pid xsd validation" + + #Expect a true element + extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result + test "$result" = "true" + ok $? "Mi test: track all pid is a success" + + #Verify that there is 1 tracked process + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/pid" result + num=$(echo "$result" | wc -l) + test "$num" -eq "1" + ok $? "Mi test: track pid expecting 1 process got $num" + + #Test if the id is * wich represent the all argument + test "$result" = "*" + ok $? "Mi test: pid expected is * got $result" + + #Test if pid_tracker is enabled as definied by pid_tracker + #behavior. If all pid are untrack thant the pid_tracker is + #disabled (node pid_tracker do not exist) + list_lttng_with_opts $session_name + $XML_VALIDATE $OUTPUT_DEST + ok $? "Mi test: session list with pid_tracker validate" + + node_check_xml $OUTPUT_DEST $XPATH_PID_TRACKER result + test "$result" = "" + ok $? "Mi test: Pid_tracker node is absent as defined" + + OUTPUT_DEST=$DEVNULL + destroy_lttng_sessions +} + start_lttng_sessiond $FOO_LOAD_DIR TESTS=( test_version @@ -715,6 +895,7 @@ TESTS=( test_list_ust_event test_start_stop test_snapshot + test_track_untrack ) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 4282fbb69..afd8a74ed 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -827,6 +827,54 @@ function lttng_load() ok $? "Load command successful" } +function lttng_track() +{ + local expected_to_fail=$1 + local opts=$2 + $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test $ret -ne "0" + ok $? "Track command failed as expected with opts: $opts" + else + ok $ret "Track command success as expected with opts: $opts" + fi +} + +function lttng_track_ok() +{ + lttng_track 0 "$@" +} + +function lttng_track_fail() +{ + lttng_track 1 "$@" +} + +function lttng_untrack() +{ + local expected_to_fail=$1 + local opts=$2 + $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test $ret -ne "0" + ok $? "Untrack command failed as expected with opts: $opts" + else + ok $ret "Untrack command success as expected with opts: $opts" + fi +} + +function lttng_untrack_ok() +{ + lttng_untrack 0 "$@" +} + +function lttng_untrack_fail() +{ + lttng_untrack 1 "$@" +} + function trace_matches () { local event_name=$1 -- 2.34.1