#!/bin/bash # # Copyright (C) 2014 David Goulet # # SPDX-License-Identifier: LGPL-2.1-only TEST_DESC="Save session(s)" CURDIR=$(dirname $0)/ TESTDIR=$CURDIR/../../../ SESSION_NAME="save-42" CHANNEL_NAME="chan-save" EVENT_NAME="tp:tptest" MAP_32_NAME="ze-map-32" MAP_64_NAME="ze-map-64" DIR=$(readlink -f $TESTDIR) NUM_TESTS=46 source $TESTDIR/utils/utils.sh FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" # MUST set TESTDIR before calling those functions plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" # Expected to fail function save_lttng_fail() { local sess_name=$1 local opts=$2 $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >/dev/null 2>&1 if [ $? -ne 0 ]; then ok 0 "Session failed to be saved. Expected!" else ok 1 "Session has been saved. NOT expected!" fi } function is_session_saved() { local path=$1 local name=$2 [ -f "$path/$name.lttng" ]; ok $? "Session $name.lttng file found!" } function test_basic_save() { diag "Test basic save" create_lttng_session_ok $SESSION_NAME $TRACE_PATH enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME lttng_add_map_ok $MAP_32_NAME $SESSION_NAME -u 32 "" "" lttng_add_map_ok $MAP_64_NAME $SESSION_NAME -u 64 "" "" lttng_track_ok "-p 666 -u -s $SESSION_NAME" lttng_save $SESSION_NAME "-o $TRACE_PATH" is_session_saved $TRACE_PATH $SESSION_NAME local session_file="$TRACE_PATH/$SESSION_NAME.lttng" local map_count=$(xmllint --xpath 'count(/sessions/session[1]/domains/domain[./type = "UST"]/maps/map)' "$session_file") is "$map_count" 2 local bitness_32=$(xmllint --xpath '/sessions/session[1]/domains/domain[./type = "UST"]/maps/map[./name = "ze-map-32"]/bitness/text()' "$session_file") is "$bitness_32" 32 local bitness_64=$(xmllint --xpath '/sessions/session[1]/domains/domain[./type = "UST"]/maps/map[./name = "ze-map-64"]/bitness/text()' "$session_file") is "$bitness_64" 64 destroy_lttng_session_ok $SESSION_NAME } function test_basic_save_all() { diag "Test basic save all" create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH create_lttng_session_ok $SESSION_NAME-3 $TRACE_PATH enable_ust_lttng_channel_ok $SESSION_NAME-1 $CHANNEL_NAME enable_ust_lttng_channel_ok $SESSION_NAME-2 $CHANNEL_NAME enable_ust_lttng_channel_ok $SESSION_NAME-3 $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME-1 $EVENT_NAME $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME-2 $EVENT_NAME $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME-3 $EVENT_NAME $CHANNEL_NAME lttng_track_ok "-p 666 -u -s $SESSION_NAME-1" lttng_track_ok "-p 666 -u -s $SESSION_NAME-2" lttng_track_ok "-p 666 -u -s $SESSION_NAME-3" lttng_save "" "-a -o $TRACE_PATH" is_session_saved $TRACE_PATH $SESSION_NAME-1 is_session_saved $TRACE_PATH $SESSION_NAME-2 is_session_saved $TRACE_PATH $SESSION_NAME-3 destroy_lttng_session_ok $SESSION_NAME-1 destroy_lttng_session_ok $SESSION_NAME-2 destroy_lttng_session_ok $SESSION_NAME-3 } function test_overwrite() { diag "Test overwrite session file" create_lttng_session_ok $SESSION_NAME $TRACE_PATH enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME lttng_save $SESSION_NAME "-o $TRACE_PATH" is_session_saved $TRACE_PATH $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME # Create a new session with same name so we can force the overwrite create_lttng_session_ok $SESSION_NAME $TRACE_PATH enable_ust_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME # This one MUST fail save_lttng_fail $SESSION_NAME "-o $TRACE_PATH" # This one MUST succeed lttng_save $SESSION_NAME "-f -o $TRACE_PATH" is_session_saved $TRACE_PATH $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME } start_lttng_sessiond TESTS=( test_basic_save test_basic_save_all test_overwrite ) for fct_test in ${TESTS[@]}; do TRACE_PATH=$(mktemp -d) ${fct_test} if [ $? -ne 0 ]; then break; fi # Only delete if successful rm -rf $TRACE_PATH done stop_lttng_sessiond