Test: template on create session
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 8 Jun 2016 01:46:42 +0000 (21:46 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 4 Jul 2016 19:42:28 +0000 (15:42 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
19 files changed:
configure.ac
tests/regression/Makefile.am
tests/regression/tools/Makefile.am
tests/regression/tools/templates/Makefile.am [new file with mode: 0644]
tests/regression/tools/templates/sessions/Makefile.am [new file with mode: 0644]
tests/regression/tools/templates/sessions/full_load.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/live.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/live_output_generation.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/name_generation.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/normal_local.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/normal_net.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/normal_no_output.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/normal_output_generation.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/shm_path.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/snapshot_local.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/snapshot_net.lttng [new file with mode: 0644]
tests/regression/tools/templates/sessions/snapshot_output_generation.lttng [new file with mode: 0644]
tests/regression/tools/templates/test_create [new file with mode: 0755]
tests/utils/utils.sh

index fb2b0136f0dd0d5b0345783e26778e26383f5ea7..633ceef8ab152aaa71b3bc4e8307840b04c7a0df 100644 (file)
@@ -981,6 +981,8 @@ AC_CONFIG_FILES([
        tests/regression/tools/wildcard/Makefile
        tests/regression/tools/crash/Makefile
        tests/regression/tools/metadata-regen/Makefile
+       tests/regression/tools/templates/Makefile
+       tests/regression/tools/templates/sessions/Makefile
        tests/regression/ust/Makefile
        tests/regression/ust/nprocesses/Makefile
        tests/regression/ust/high-throughput/Makefile
index 6a2d24c7bf3cab9b2a57bf1c58f33e9e1d3fb05e..d1c19e6b4eed8430371bac7cfc3328f3acfddecf 100644 (file)
@@ -22,7 +22,8 @@ TESTS = tools/filtering/test_invalid_filter \
        tools/mi/test_mi \
        tools/wildcard/test_event_wildcard \
        tools/crash/test_crash \
-       tools/metadata-regen/test_ust
+       tools/metadata-regen/test_ust \
+       tools/templates/test_create
 
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS += ust
index 6c39c9f18c68c5f783177bac2e04f8e745c0927f..5c4207d94bb48f1f26a9c3bd985ccf0d9540058c 100644 (file)
@@ -1,2 +1,2 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
-               wildcard crash metadata-regen
+               wildcard crash metadata-regen templates
diff --git a/tests/regression/tools/templates/Makefile.am b/tests/regression/tools/templates/Makefile.am
new file mode 100644 (file)
index 0000000..8fe5b19
--- /dev/null
@@ -0,0 +1,17 @@
+noinst_SCRIPTS = test_create
+EXTRA_DIST = $(noinst_SCRIPTS) sessions
+SUBDIRS= sessions
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/templates/sessions/Makefile.am b/tests/regression/tools/templates/sessions/Makefile.am
new file mode 100644 (file)
index 0000000..484426b
--- /dev/null
@@ -0,0 +1,18 @@
+EXTRA_DIST = live.lttng live_output_generation.lttng name_generation.lttng \
+            normal_local.lttng normal_net.lttng normal_no_output.lttng \
+            normal_output_generation.lttng shm_path.lttng snapshot_local.lttng \
+            snapshot_net.lttng snapshot_output_generation.lttng full_load.lttng
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/templates/sessions/full_load.lttng b/tests/regression/tools/templates/sessions/full_load.lttng
new file mode 100644 (file)
index 0000000..938f3d7
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>full_load</name>
+               <domains>
+                       <domain>
+                               <type>UST</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels>
+                                       <channel>
+                                               <name>channel0</name>
+                                               <enabled>true</enabled>
+                                               <overwrite_mode>DISCARD</overwrite_mode>
+                                               <subbuffer_size>131072</subbuffer_size>
+                                               <subbuffer_count>4</subbuffer_count>
+                                               <switch_timer_interval>0</switch_timer_interval>
+                                               <read_timer_interval>0</read_timer_interval>
+                                               <output_type>MMAP</output_type>
+                                               <tracefile_size>0</tracefile_size>
+                                               <tracefile_count>0</tracefile_count>
+                                               <live_timer_interval>0</live_timer_interval>
+                                               <events/>
+                                               <contexts/>
+                                       </channel>
+                               </channels>
+                               <trackers/>
+                       </domain>
+                       <domain>
+                               <type>JUL</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>LOG4J</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>PYTHON</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+               </domains>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/home/jonathan/lttng-traces/full_load-20160607-021349</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/live.lttng b/tests/regression/tools/templates/sessions/live.lttng
new file mode 100644 (file)
index 0000000..2061275
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>live</name>
+               <started>false</started>
+               <attributes>
+                       <live_timer_interval>1000000</live_timer_interval>
+               </attributes>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <net_output>
+                                               <control_uri>tcp4://127.0.0.1:5342/</control_uri>
+                                               
+                                       </net_output>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/live_output_generation.lttng b/tests/regression/tools/templates/sessions/live_output_generation.lttng
new file mode 100644 (file)
index 0000000..ccc038b
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>live_output_generation</name>
+               <started>false</started>
+               <attributes>
+                       <live_timer_interval>1000000</live_timer_interval>
+               </attributes>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/name_generation.lttng b/tests/regression/tools/templates/sessions/name_generation.lttng
new file mode 100644 (file)
index 0000000..f2c44c9
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/home/jonathan/lttng-traces/normal_local-20160606-132532</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/normal_local.lttng b/tests/regression/tools/templates/sessions/normal_local.lttng
new file mode 100644 (file)
index 0000000..fe55111
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>normal_local</name>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/home/jonathan/lttng-traces/normal_local-20160606-132532</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/normal_net.lttng b/tests/regression/tools/templates/sessions/normal_net.lttng
new file mode 100644 (file)
index 0000000..3e875a7
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>normal_net</name>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <net_output>
+                                               <control_uri>tcp4://127.0.0.1:5342/normal_net-20160606-132620</control_uri>
+                                               
+                                       </net_output>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/normal_no_output.lttng b/tests/regression/tools/templates/sessions/normal_no_output.lttng
new file mode 100644 (file)
index 0000000..85eacb8
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>normal_no_output</name>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path></path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/normal_output_generation.lttng b/tests/regression/tools/templates/sessions/normal_output_generation.lttng
new file mode 100644 (file)
index 0000000..683f17e
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>normal_output_generation</name>
+               <started>false</started>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/shm_path.lttng b/tests/regression/tools/templates/sessions/shm_path.lttng
new file mode 100644 (file)
index 0000000..17bf2a3
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>shm_path</name>
+               <shared_memory_path>/tmp/shm_path-20160606-161801</shared_memory_path>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/home/jonathan/lttng-traces/shm_path-20160606-161801</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/snapshot_local.lttng b/tests/regression/tools/templates/sessions/snapshot_local.lttng
new file mode 100644 (file)
index 0000000..58a8ab4
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>snapshot_local</name>
+               <started>false</started>
+               <attributes>
+                       <snapshot_mode>true</snapshot_mode>
+               </attributes>
+               <output>
+                       <snapshot_outputs>
+                               <output>
+                                       <name>snapshot-1</name>
+                                       <max_size>0</max_size>
+                                       <consumer_output>
+                                               <enabled>true</enabled>
+                                               <destination>
+                                                       <path>/home/jonathan/lttng-traces/snapshot_local-20160606-132651</path>
+                                               </destination>
+                                       </consumer_output>
+                               </output>
+                       </snapshot_outputs>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/snapshot_net.lttng b/tests/regression/tools/templates/sessions/snapshot_net.lttng
new file mode 100644 (file)
index 0000000..8a068f6
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>snapshot_net</name>
+               <started>false</started>
+               <attributes>
+                       <snapshot_mode>true</snapshot_mode>
+               </attributes>
+               <output>
+                       <snapshot_outputs>
+                               <output>
+                                       <name>snapshot-1</name>
+                                       <max_size>0</max_size>
+                                       <consumer_output>
+                                               <enabled>true</enabled>
+                                               <destination>
+                                                       <net_output>
+                                                               <control_uri>tcp4://127.0.0.1:5342/</control_uri>
+                                                               
+                                                       </net_output>
+                                               </destination>
+                                       </consumer_output>
+                               </output>
+                       </snapshot_outputs>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/sessions/snapshot_output_generation.lttng b/tests/regression/tools/templates/sessions/snapshot_output_generation.lttng
new file mode 100644 (file)
index 0000000..35ea4e0
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>snapshot_output_generation</name>
+               <started>false</started>
+               <attributes>
+                       <snapshot_mode>true</snapshot_mode>
+               </attributes>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/templates/test_create b/tests/regression/tools/templates/test_create
new file mode 100755 (executable)
index 0000000..b16b00e
--- /dev/null
@@ -0,0 +1,718 @@
+#!/bin/bash
+#
+# Copyright (C) - 2016 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Session creation based on template"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
+
+export LTTNG_SESSION_CONFIG_XSD_PATH=$(readlink -m ${TESTDIR}../src/common/config/)
+
+SESSION_NAME="load-42"
+
+DIR=$(readlink -f $TESTDIR)
+
+NUM_TESTS=89
+
+source $TESTDIR/utils/utils.sh
+
+LTTNG_BIN="lttng --mi xml"
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+#Test related data
+
+XPATH_SESSION_NAME="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:name/text()"
+XPATH_SESSION_PATH="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path/text()"
+XPATH_SESSION_SNAPSHOT_MODE="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:snapshot_mode/text()"
+XPATH_SESSION_SNAPSHOT_CTRL_URL="//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url/text()"
+XPATH_SESSION_SNAPSHOT_DATA_URL="//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:data_url/text()"
+XPATH_SESSION_LIVE_TIMER_INTERVAL="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:live_timer_interval/text()"
+XPATH_SAVE_SESSION_SHM_PATH="//sessions/session/shared_memory_path/text()"
+
+TEMPLATE_DIR="$CURDIR/sessions"
+
+# TODO: note: most of these fuctions could have been tested via lttng save and
+# diffing the original and the saved one. Might want to go this way...
+
+function test_normal_local()
+{
+       diag "Load from template a normal session with local consumer output"
+       local template_name="normal_local.lttng"
+       local session_name="normal_local"
+       local output_path="/home/jonathan/lttng-traces/normal_local-20160606-132532"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate name
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_NAME}")
+       if [[ $mi_result = "$session_name" ]]; then
+           ok 0 "Session names are the same"
+       else
+           fail "Session names should be $session_name but value is $mi_result"
+       fi
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be $output_path but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_normal_no_output()
+{
+       diag "Load from template a normal session with no output (--no-output)"
+       local template_name="normal_no_output.lttng"
+       local session_name="normal_no_output"
+       local output_path=""
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate name
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_NAME}")
+       if [[ $mi_result = "$session_name" ]]; then
+           ok 0 "Session names are the same"
+       else
+           fail "Session names should be $session_name but value is $mi_result"
+       fi
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_normal_net()
+{
+       diag "Load from template a normal session with net output"
+       local template_name="normal_net.lttng"
+       local session_name="normal_net"
+       local output_path="tcp4://127.0.0.1:5342/normal_net-20160606-132620 [data: 5343]"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate name
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_NAME}")
+       if [[ $mi_result = "$session_name" ]]; then
+           ok 0 "Session names are the same"
+       else
+           fail "Session names should be $session_name but value is $mi_result"
+       fi
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_snapshot_local()
+{
+       diag "Load from template a snapshot session with local output"
+       local template_name="snapshot_local.lttng"
+       local session_name="snapshot_local"
+       local output_path=""
+       local snapshot_ctrl_url="/home/jonathan/lttng-traces/snapshot_local-20160606-132651"
+       local snapshot_data_url=""
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate name
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_MODE}")
+       if [[ $mi_result = "1" ]]; then
+           ok 0 "Session snapshot mode is enabled"
+       else
+           fail "Session snapshot mode is invalid value is $mi_result"
+       fi
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       OUTPUT_DEST="$mi_output_file" lttng_snapshot_list $session_name
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
+       if [[ $mi_result = "$snapshot_ctrl_url" ]]; then
+           ok 0 "Ctrl urls for snapshot are the same"
+       else
+           fail "Ctrl urls should be $snapshot_ctrl_url but value is $mi_result"
+       fi
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
+       if [[ $mi_result = "$snapshot_data_url" ]]; then
+               ok 0 "Data urls for snapshot are the same"
+       else
+               fail "Data urls should be $snapshot_data_url but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_snapshot_net()
+{
+       diag "Load from template a snapshot session with net output"
+       local template_name="snapshot_net.lttng"
+       local session_name="snapshot_net"
+       local output_path=""
+       local snapshot_ctrl_url="tcp4://127.0.0.1:5342/"
+       local snapshot_data_url="tcp4://127.0.0.1:5343/"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate name
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_MODE}")
+       if [[ $mi_result = "1" ]]; then
+           ok 0 "Session snapshot mode is enabled"
+       else
+           fail "Session snapshot mode is invalid value is $mi_result"
+       fi
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       OUTPUT_DEST="$mi_output_file" lttng_snapshot_list $session_name
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
+       if [[ $mi_result = "$snapshot_ctrl_url" ]]; then
+           ok 0 "Ctrl urls for snapshot are the same"
+       else
+           fail "Ctrl urls should be $snapshot_ctrl_url but value is $mi_result"
+       fi
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
+       if [[ $mi_result = "$snapshot_data_url" ]]; then
+               ok 0 "Data urls for snapshot are the same"
+       else
+               fail "Data urls should be $snapshot_data_url but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_live()
+{
+       diag "Load from template a live session"
+       local template_name="live.lttng"
+       local session_name="live"
+       local output_path="tcp4://127.0.0.1:5342/ [data: 5343]"
+       local live_timer_interval="1000000"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate name
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_NAME}")
+       if [[ $mi_result = "$session_name" ]]; then
+           ok 0 "Session names are the same"
+       else
+           fail "Session names should be $session_name but value is $mi_result"
+       fi
+
+       # Validate live timer
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_LIVE_TIMER_INTERVAL}")
+       if [[ $mi_result = "$live_timer_interval" ]]; then
+               ok 0 "Session live timer intervals are the same"
+       else
+               fail "Session live timer should be $live_timer_interval but value is $mi_result"
+       fi
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_shm_path()
+{
+       # Since lttng list do not expose the shm path save the session and check
+       # for the shm path.
+       diag "Load from template a session with a shared memory path"
+       local template_name="shm_path.lttng"
+       local session_name="shm_path"
+       local shared_memory_path="/tmp/shm_path-20160606-161801"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local save_output_path=$(mktemp -d)
+       local save_output_file="${save_output_path}/$session_name.lttng"
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path"
+
+       lttng_save $session_name "-o ${save_output_path}"
+
+       # Validate name
+       save_result=$($CURDIR/../mi/extract_xml $save_output_file "${XPATH_SAVE_SESSION_SHM_PATH}")
+       if [[ $save_result = "$shared_memory_path" ]]; then
+           ok 0 "Session shared memory paths are the same"
+       else
+           fail "Session shared memory path should be $shared_memory_path but value is $save_result"
+       fi
+
+       rm $save_output_file
+       rmdir $save_output_path
+       destroy_lttng_session_ok $session_name
+}
+
+# Default data generation
+function test_name_generation()
+{
+       diag "Load from template a session with no name"
+       local template_name="name_generation.lttng"
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       # On session creation success a name must have been generated.
+       create_lttng_session_template_ok "$template_path"
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_normal_output_generation()
+{
+       diag "Load from template a normal session with no consumer output defined"
+       local template_name="normal_output_generation.lttng"
+       local session_name="normal_output_generation"
+       local output_path="/home/jonathan/lttng-traces/normal_local-20160606-132532"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [ ! -z "$mi_result" ]; then
+           ok 0 "Output path was generated"
+       else
+           fail "Output path should not be empty $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_snapshot_output_generation()
+{
+       diag "Load from template a snapshot session with no local output defined"
+       local template_name="snapshot_output_generation.lttng"
+       local session_name="snapshot_output_generation"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" lttng_snapshot_list $session_name
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
+       if [ ! -z "${mi_result}" ]; then
+           ok 0 "Local snapshot output was generated"
+       else
+           fail "Local snapshot output is null"
+       fi
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
+       if [ -z "${mi_result}" ]; then
+               ok 0 "Data url is empty as planned"
+       else
+               fail "Data url should be null but value is : $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_live_output_generation()
+{
+       diag "Load from template a live session with no consumer output defined"
+       local template_name="live_output_generation.lttng"
+       local session_name="live_output_generation"
+       local output_path="tcp4://127.0.0.1:5342/ [data: 5343]"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output path was generated and value is good: $mi_result"
+       else
+           fail "Output path default is invalid: $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+# Override
+function test_overwrite_live_timer()
+{
+       diag "Load from template a live session - Overwrite live timer"
+       local template_name="live.lttng"
+       local session_name="live"
+       local output_path="tcp4://127.0.0.1:5342/ [data: 5343]"
+       local live_timer_interval="123456"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path" "--live=${live_timer_interval}"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate live timer
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_LIVE_TIMER_INTERVAL}")
+       if [[ $mi_result = "$live_timer_interval" ]]; then
+               ok 0 "Session live timer intervals are the same: $mi_result == $live_timer_interval"
+       else
+               fail "Session live timer should be $live_timer_interval but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_overwrite_shm_path()
+{
+       # Since lttng list do not expose the shm path save the session and check
+       # for the shm path.
+       diag "Load from template a session with a shared memory path - Overwrite shm path"
+       local template_name="shm_path.lttng"
+       local session_name="shm_path"
+       local shared_memory_path="/tmp/beer-run"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local save_output_path=$(mktemp -d)
+       local save_output_file="${save_output_path}/$session_name.lttng"
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path" "--shm-path=${shared_memory_path}"
+
+       lttng_save $session_name "-o ${save_output_path}"
+
+       # Validate name
+       save_result=$($CURDIR/../mi/extract_xml $save_output_file "${XPATH_SAVE_SESSION_SHM_PATH}")
+       if [[ $(dirname $save_result) = "$shared_memory_path" ]]; then
+           ok 0 "Session shared memory paths are the same"
+       else
+           fail "Session shared memory path should be $shared_memory_path but value is $save_result"
+       fi
+
+       rm $save_output_file
+       rmdir $save_output_path
+       destroy_lttng_session_ok $session_name
+}
+
+function test_overwrite_normal_net_to_local()
+{
+       diag "Load from template a normal session with net output - Overwrite to local output"
+       local template_name="normal_net.lttng"
+       local session_name="normal_net"
+       local output_path="/tmp/beer-run"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path" "--set-url=file://${output_path}"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+
+       create_lttng_session_template_ok "$template_path" "--output=${output_path}"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+
+}
+
+function test_overwrite_snapshot_local_to_net()
+{
+       diag "Load from template a snapshot session with local output"
+       local template_name="snapshot_local.lttng"
+       local session_name="snapshot_local"
+       local output_path=""
+       local snapshot_ctrl_url="tcp4://127.0.0.1:5342/"
+       local snapshot_data_url="tcp4://127.0.0.1:5343/"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path" "--ctrl-url=${snapshot_ctrl_url} --data-url=${snapshot_data_url}"
+
+       OUTPUT_DEST="$mi_output_file" lttng_snapshot_list $session_name
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
+       if [[ $mi_result = "$snapshot_ctrl_url" ]]; then
+           ok 0 "Ctrl urls for snapshot are the same"
+       else
+           fail "Ctrl urls should be $snapshot_ctrl_url but value is $mi_result"
+       fi
+
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
+       if [[ $mi_result = "$snapshot_data_url" ]]; then
+               ok 0 "Data urls for snapshot are the same"
+       else
+               fail "Data urls should be $snapshot_data_url but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+function test_overwrite_live_net()
+{
+       diag "Load from template a live session - Overwrite net output"
+       local template_name="live.lttng"
+       local session_name="live"
+       local ctrl_url="tcp4://127.0.0.1:1000/"
+       local data_url="tcp4://127.0.0.1:1001/"
+       local output_path="tcp4://127.0.0.1:1000/ [data: 1001]"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local mi_output_file=$(mktemp)
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path" "--ctrl-url=${ctrl_url} --data-url=${data_url}"
+
+       OUTPUT_DEST="$mi_output_file" list_lttng_with_opts $session_name
+
+       # Validate output
+       mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "${XPATH_SESSION_PATH}")
+       if [[ $mi_result = "$output_path" ]]; then
+           ok 0 "Output paths are the same"
+       else
+           fail "Output paths should be empty but value is $mi_result"
+       fi
+
+       destroy_lttng_session_ok $session_name
+}
+
+# With subchild data
+function test_full_load()
+{
+       # Since lttng list do not expose the shm path save the session and check
+       # for the shm path.
+       diag "Load from template a complex session with henabled channel and events"
+       local template_name="full_load.lttng"
+       local session_name="full_load"
+
+       local template_path="$TEMPLATE_DIR/$template_name"
+
+       local save_output_path=$(mktemp -d)
+       local save_output_file="${save_output_path}/$session_name.lttng"
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+
+       create_lttng_session_template_ok "$template_path"
+
+       lttng_save $session_name "-o ${save_output_path}"
+
+       # Validate name
+       save_result=$($CURDIR/../mi/extract_xml $save_output_file "${XPATH_SAVE_SESSION_SHM_PATH}")
+       if diff $template_path $save_output_path ; then
+           ok 0 "Session complex load"
+       else
+           fail "Sessions results are different"
+       fi
+
+       rm $save_output_file
+       rmdir $save_output_path
+       destroy_lttng_session_ok $session_name
+}
+
+TESTS=(
+       test_normal_local
+       test_normal_no_output
+       test_normal_net
+       test_snapshot_local
+       test_snapshot_net
+       test_live
+       test_shm_path
+       # Default data generation
+       test_name_generation
+       test_normal_output_generation
+       test_snapshot_output_generation
+       test_live_output_generation
+       # Override
+       test_overwrite_live_timer
+       test_overwrite_shm_path
+       test_overwrite_normal_net_to_local
+       test_overwrite_snapshot_local_to_net
+       test_overwrite_live_net
+       # With subchild data
+       test_full_load
+)
+
+start_lttng_relayd
+start_lttng_sessiond
+
+for fct_test in ${TESTS[@]};
+do
+       ${fct_test}
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+       # Only delete if successful
+done
+
+stop_lttng_sessiond
+stop_lttng_relayd
+
+
index da2efe91a72264b93cd5c67b8d46cf28c53408d2..d4ba4d0606cab9e4b93bae958266fd33d87c8a30 100644 (file)
@@ -689,6 +689,29 @@ function create_lttng_session_fail ()
        create_lttng_session 1 "$@"
 }
 
+function create_lttng_session_template ()
+{
+       local expected_to_fail=$1
+       local template_path=$2
+       local opt=$3
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create --template-path="$template_path" $opt > $OUTPUT_DEST
+       ret=$?
+       if [[ $expected_to_fail -eq "1" ]]; then
+               test "$ret" -ne "0"
+               ok $? "Create session from template $template_path failed as expected"
+       else
+               ok $ret "Create session from template $template_path"
+       fi
+}
+
+function create_lttng_session_template_ok () {
+       create_lttng_session_template 0 "$@"
+}
+
+function create_lttng_session_template_fail () {
+       create_lttng_session_template 1 "$@"
+}
 
 function enable_ust_lttng_channel ()
 {
This page took 0.042123 seconds and 5 git commands to generate.