Deny multiple session with the same name
[lttng-tools.git] / tests / ltt-sessiond / run.sh
CommitLineData
6e0ca3c2
DG
1#!/bin/bash
2#
3# Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version 2
8# of the License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18#
19
20PWD=$(dirname $0)
21
22SESSIOND_CLIENT_SOCK_PATH="/tmp/.test-sessiond-client"
23SESSIOND_APPS_SOCK_PATH="/tmp/.test-sessiond-apps"
24SESSIOND_BIN="$PWD/../../ltt-sessiond/ltt-sessiond"
25LTTNG_BIN="$PWD/../../lttng/lttng"
26#SESSIOND_ARGS="-c $SESSIOND_CLIENT_SOCK_PATH -a $SESSIOND_APPS_SOCK_PATH"
27SESSIOND_ARGS=""
28SESSION_ID_REGEX="[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}"
29
30function clean_exit()
31{
32 echo "[+] Shuting down session daemon..."
33 kill -s SIGTERM $pid
34 exit $1
35}
36
37# Exec $1, check error code.
38# If 0, return output, else, stop execution
39# and return and error.
40function check_ret_code()
41{
42 if [ $1 -ne 0 ]; then
43 printf "\n!STOPPING!\n"
44 clean_exit 1
45 fi
46}
47
48# Create session with $1 and return output.
49function lttng_create_session()
50{
51 local command="$LTTNG_BIN -c $1"
52 local ret=$($command)
53 LTTNG_RET_CODE=$?
54
55 # Extract session UUID
56 if [[ "$ret" =~ $SESSION_ID_REGEX ]]; then
57 LTTNG_SESSION_ID="$BASH_REMATCH"
58 fi
59}
60
61# List sessions and return output.
62function lttng_list_session()
63{
64 local command="$LTTNG_BIN --list-sessions"
65 local ret=$(lttng_command "$command")
66
67 if [[ "$result" =~ $session_id ]]; then
68 printf "SUCCESS!\n"
69 else
70 printf "FAIL!\n"
71 printf "Missing $session_id!\n"
72 exit 1
73 fi
74 echo "$ret"
75}
76
77function test_destroy_session()
78{
79 local command="$LTTNG_BIN -d $LTTNG_SESSION_ID"
80 local ret=$($command)
81 check_ret_code $LTTNG_RET_CODE
82 echo "[+] Destroy session: PASSED!"
83}
84
85function test_one_session()
86{
87 lttng_create_session "test1"
88 check_ret_code $LTTNG_RET_CODE
89 echo "[+] Session creation: PASSED!"
90}
91
92function test_session_same_name()
93{
94 lttng_create_session "test-same"
95 lttng_create_session "test-same"
27673bb6 96 if [ $LTTNG_RET_CODE -ne 0 ]; then
6e0ca3c2
DG
97 echo "[-] Session with the same name: FAILED!"
98 printf "Two session having the same name NOT ALLOWED\n"
99 clean_exit 1
100 fi
101 echo "[+] Session with the same name: PASSED!"
102}
103
104if [ ! -x $SESSIOND_BIN ]; then
105 echo "Please use make before test execution"
106 exit 1
107fi
108
109# Daemonized by the -d
110./$SESSIOND_BIN $SESSIOND_ARGS -d
111echo "[+] Session daemon started"
112
113pid=$(pidof lt-ltt-sessiond)
114if [ -z "$pid" ]; then
115 echo "[-] Can't found session daemon"
116 ./$SESSIOND_BIN $SESSIOND_ARGS
117 exit 1
118fi
119echo "[+] Got the session daemon pid $pid"
120
121printf "=== Starting tests ===\n"
122
123test_one_session
124
125test_destroy_session
126
127test_session_same_name
128
129clean_exit 0
130
This page took 0.026589 seconds and 4 git commands to generate.