Tests: Consider lttng mi namespace in test_mi
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 2 Mar 2016 21:11:26 +0000 (16:11 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 3 Mar 2016 22:19:42 +0000 (17:19 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/defaults.h
src/common/mi-lttng.c
tests/regression/tools/mi/extract_xml.c
tests/regression/tools/mi/test_mi

index 6bf06becdde069ff04e26900c99013d8f62c4da1..f45c8f6f0fc33c247637a0bfbf7cb8aaa0224c8d 100644 (file)
 /* 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.
  *
index e2a5917e9c6a22fd09ddba5ba75c282c05112ff4..c15643737db517e8549a8f2bd310662976254b8e 100644 (file)
@@ -19,6 +19,7 @@
 
 #define _LGPL_SOURCE
 #include <common/config/session-config.h>
+#include <common/defaults.h>
 #include <lttng/snapshot-internal.h>
 #include "mi-lttng.h"
 
 
 /* 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;
        }
index 7edf1716eb979ad07da7ba35f48d8edddaa3b660..ddf8c16773331b9786b2018c4cbf2d7fb5a651e5 100644 (file)
@@ -43,6 +43,7 @@
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
 #include <libxml/xpathInternals.h>
+#include <common/defaults.h>
 
 #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) {
index cb0470bb76afcf91fa1097df13c19d4709625a70..cd18b58ddf0a12465b242ce58ee8a06704c6ef55 100755 (executable)
@@ -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"
This page took 0.047198 seconds and 4 git commands to generate.