From: Jérémie Galarneau Date: Wed, 2 Mar 2016 21:11:26 +0000 (-0500) Subject: Tests: Consider lttng mi namespace in test_mi X-Git-Tag: v2.8.0-rc1~129 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=41af1adf5100627c2e11565e7d9e4b9c5a8b9fac;p=lttng-tools.git Tests: Consider lttng mi namespace in test_mi Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/defaults.h b/src/common/defaults.h index 6bf06becd..f45c8f6f0 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -306,6 +306,9 @@ /* Default runas worker name */ #define DEFAULT_RUN_AS_WORKER_NAME "lttng-runas" +/* Default LTTng MI XML namespace. */ +#define DEFAULT_LTTNG_MI_NAMESPACE "http://lttng.org/xml/ns/lttng-mi" + /* * Returns the default subbuf size. * diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index e2a5917e9..c15643737 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -19,6 +19,7 @@ #define _LGPL_SOURCE #include +#include #include #include "mi-lttng.h" @@ -29,12 +30,11 @@ /* Machine interface namespace URI */ const char * const mi_lttng_xmlns = "xmlns"; -const char * const mi_lttng_ns_uri = "http://lttng.org/xml/ns/lttng-mi"; const char * const mi_lttng_xmlns_xsi = "xmlns:xsi"; const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance"; const char * const mi_lttng_schema_location = "xsi:schemaLocation"; const char * const mi_lttng_schema_location_uri = - "http://lttng.org/xml/ns/lttng-mi" " " + DEFAULT_LTTNG_MI_NAMESPACE " " "http://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION) "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION) "." XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd"; @@ -506,7 +506,7 @@ int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command) } ret = config_writer_write_attribute(writer->writer, - mi_lttng_xmlns, mi_lttng_ns_uri); + mi_lttng_xmlns, DEFAULT_LTTNG_MI_NAMESPACE); if (ret) { goto end; } diff --git a/tests/regression/tools/mi/extract_xml.c b/tests/regression/tools/mi/extract_xml.c index 7edf1716e..ddf8c1677 100644 --- a/tests/regression/tools/mi/extract_xml.c +++ b/tests/regression/tools/mi/extract_xml.c @@ -43,6 +43,7 @@ #include #include #include +#include #if defined(LIBXML_XPATH_ENABLED) @@ -135,6 +136,31 @@ end: return ret; } +static int register_lttng_namespace(xmlXPathContextPtr xpathCtx) +{ + int ret; + xmlChar *prefix; + xmlChar *ns = NULL; + + prefix = xmlCharStrdup("lttng"); + if (!prefix) { + ret = -1; + goto end; + } + + ns = xmlCharStrdup(DEFAULT_LTTNG_MI_NAMESPACE); + if (!ns) { + ret = -1; + goto end; + } + + ret = xmlXPathRegisterNs(xpathCtx, prefix, ns); + xmlFree(prefix); +end: + xmlFree(ns); + return ret; +} + /* * Extract element corresponding to xpath * xml_path The path to the xml file @@ -147,6 +173,7 @@ end: */ static int extract_xpath(const char *xml_path, const xmlChar *xpath) { + int ret; xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtx = NULL; xmlXPathObjectPtr xpathObj = NULL; @@ -169,6 +196,15 @@ static int extract_xpath(const char *xml_path, const xmlChar *xpath) return -1; } + /* Register the LTTng MI namespace */ + ret = register_lttng_namespace(xpathCtx); + if (ret) { + fprintf(stderr, "ERR: Could not register lttng namespace\n"); + xmlXPathFreeContext(xpathCtx); + xmlFreeDoc(doc); + return -1; + } + /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression(xpath, xpathCtx); if (!xpathObj) { diff --git a/tests/regression/tools/mi/test_mi b/tests/regression/tools/mi/test_mi index cb0470bb7..cd18b58dd 100755 --- a/tests/regression/tools/mi/test_mi +++ b/tests/regression/tools/mi/test_mi @@ -40,20 +40,20 @@ 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()" -XPATH_SESSION="$XPATH_CMD_OUTPUT/sessions/session" -XPATH_ENABLE_CHANNEL_NAME="$XPATH_CMD_OUTPUT/channels/channel/name/text()" -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_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" +XPATH_CMD_OUTPUT="//lttng:command/lttng:output" +XPATH_COMMAND_SUCCESS="/lttng:command/lttng:success/text()" +XPATH_SESSION="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session" +XPATH_ENABLE_CHANNEL_NAME="$XPATH_CMD_OUTPUT/lttng:channels/lttng:channel/lttng:name/text()" +XPATH_ENABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/lttng:events/lttng:event/lttng:success/text()" +XPATH_DISABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/lttng:channel/lttng:events/lttng:event/lttng:success/text()" +XPATH_LIST_DOMAIN="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain" +XPATH_LIST_CHANNEL="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:channels/lttng:channel" +XPATH_LIST_UST_EVENT="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type ='UST']/lttng:pids/lttng:pid/lttng:events/lttng:event" +XPATH_SNAPSHOT_ADD_SNAPSHOT="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'add-output']/lttng:output" +XPATH_SNAPSHOT_LIST="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'list-output']/lttng:output" +XPATH_SNAPSHOT_DEL="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'del-output']/lttng:output" +XPATH_TRACK_UNTRACK_PID="$XPATH_CMD_OUTPUT/lttng:targets/lttng:pid_target" +XPATH_PID_TRACKER="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:trackers/lttng:pid_tracker" DEVNULL=/dev/null 2>&1 @@ -111,6 +111,7 @@ function is_command_success () local xpath=$XPATH_COMMAND_SUCCESS + echo $xml #Extract the success element #expect false extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result @@ -189,7 +190,7 @@ function test_destroy_session () ok $? "MI test: destroy session ${session_name[0]} xsd validation" #Verify that we destroyed the good session - extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result test "$result" = "${session_name[0]}" ok $? "Mi test: deleted session: $result expected: ${session_name[0]}" @@ -199,7 +200,7 @@ function test_destroy_session () ok $? "MI test: destroy all session xsd validation" #Verify that we destroyed 2 sessions - extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "2" ok $? "Mi test: $num / 2 sessions discovered" @@ -235,7 +236,7 @@ function test_list_sessions () ok $? "Mi test: list sessions xsd validation" #We should have 3 session - extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "3" ok $? "Mi test: $num / 3 sessions discovered" @@ -400,13 +401,13 @@ function test_list_channel () ok $? "Mi test: list channel xsd validation" #Expect 1 domain: UST - extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/type/text()" result + extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "1" ok $? "Mi test: $num / 1 domains discovered" #Expect 1 channel: test - extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "1" ok $? "Mi test: $num / 1 channel discovered" @@ -448,7 +449,7 @@ function test_list_domain () ok $? "Mi test: list domain xsd validation" #Expect 2 domain: Jul and UST - extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/type/text()" result + extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "2" ok $? "Mi test: $num / 2 domains discovered" @@ -496,13 +497,13 @@ function test_list_session () ok $? "Mi test: list session xsd validation" #Expect 2 domain: Jul and UST - extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/type/text()" result + extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "2" ok $? "Mi test: $num / 2 domains discovered" #Expect 2 channel: test and lttng_jul_event - extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result num=$(echo "$result" | wc -l) test "$num" -eq "2" ok $? "Mi test: $num / 2 channel discovered" @@ -537,7 +538,7 @@ function test_list_ust_event () ok $? "Mi test: list ust event xsd validation" #Extract events - extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/name/text()" result + extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/lttng:name/text()" result num=$(echo "$result" | wc -l) #Since the number of events is prone to change we only look for >= from a @@ -548,7 +549,7 @@ function test_list_ust_event () #Extract field from tp:tptest event. Expect >= to 12 because number of #field is prone to change. - extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./name = 'tp:tptest']/event_fields/event_field/name/text()" result + extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./lttng:name = 'tp:tptest']/lttng:event_fields/lttng:event_field/lttng:name/text()" result num=$(echo "$result" | wc -l) test "$num" -ge "12" ok $? "Mi test: $num / 12 ust event fields discovered" @@ -598,12 +599,12 @@ function test_start_stop () { ok $? "Mi test: mi report success on start command as expected" #Extract session name from xml - extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result test "$result" = "$session_name" ok $? "Mi test: started $session_name" #Extract enabled expect true - extract_xml $OUTPUT_DEST $XPATH_SESSION"/enabled/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result test "$result" = "true" ok $? "Mi test: enabled element : $result expected: true" @@ -613,12 +614,12 @@ function test_start_stop () { ok $? "Mi test: stop xsd validation" #Extract session name from xml - extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result test "$result" = "$session_name" ok $? "Mi test: stoped $session_name" #Extract enabled expect false - extract_xml $OUTPUT_DEST $XPATH_SESSION"/enabled/text()" result + extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result test "$result" = "false" ok $? "Mi test: enabled element : $result expected: false" @@ -660,13 +661,13 @@ function test_snapshot () { ok $? "Mi test: add snapshot is a success" #Get data - extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/snapshot/session_name/text()" result + extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:session_name/text()" result test "$result" = "$session_name" ok $? "Mi test: added snapshot for: $result expected $session_name" #Get name of generated output and id - extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/snapshot/name/text()" snapshot_name - extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/snapshot/id/text()" snapshot_id + extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:name/text()" snapshot_name + extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:id/text()" snapshot_id #Test list output lttng_snapshot_list $session_name @@ -678,7 +679,7 @@ function test_snapshot () { test "$result" = "true" ok $? "Mi test: add snapshot is a success" - extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/session[./name ='$session_name']/snapshots/snapshot/name/text()" result + extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/lttng:session[./lttng:name ='$session_name']/lttng:snapshots/lttng:snapshot/lttng:name/text()" result test "$result" = "$snapshot_name" ok $? "Mi test: snapshot list extracted snapshot: $result expected: $snapshot_name" @@ -693,11 +694,11 @@ function test_snapshot () { ok $? "Mi test: del snapshot is a success" #Test data - extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/snapshot/id/text()" result + extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:id/text()" result test "$result" = "$snapshot_id" ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $snapshot_id" - extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/snapshot/session_name/text()" result + extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:session_name/text()" result test "$result" = "$session_name" ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $session_name" @@ -739,7 +740,7 @@ function test_track_untrack () ok $? "Mi test: track pid is a success" #Verify that there is 3 process - extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/pid" result + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result num=$(echo "$result" | wc -l) test "$num" -eq "3" ok $? "Mi test: track pid expecting 3 processes got $num" @@ -750,7 +751,7 @@ function test_track_untrack () 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 + extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result num=$(echo "$result" | wc -l) test "$num" -eq "3" ok $? "Mi test: tracker pid listing expecting 3 target got $num" @@ -766,7 +767,7 @@ function test_track_untrack () 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 + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result num=$(echo "$result" | wc -l) test "$num" -eq "2" ok $? "Mi test: untrack pid expecting 2 process got $num" @@ -777,7 +778,7 @@ function test_track_untrack () 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 + extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result num=$(echo "$result" | wc -l) test "$num" -eq "1" ok $? "Mi test: tracker pid listing expecting 1 process got $num" @@ -793,7 +794,7 @@ function test_track_untrack () 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 + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result num=$(echo "$result" | wc -l) test "$num" -eq "1" ok $? "Mi test: untrack pid expecting 1 process got $num" @@ -810,7 +811,7 @@ function test_track_untrack () 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 + extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result num=$(echo -n "$result" | wc -l) test "$num" -eq "0" ok $? "Mi test: tracker pid listing expecting 0 process got $num" @@ -826,7 +827,7 @@ function test_track_untrack () 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 + extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result num=$(echo "$result" | wc -l) test "$num" -eq "1" ok $? "Mi test: track pid expecting 1 process got $num"