| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com> |
| 4 | # |
| 5 | # This library is free software; you can redistribute it and/or modify it under |
| 6 | # the terms of the GNU Lesser General Public License as published by the Free |
| 7 | # Software Foundation; version 2.1 of the License. |
| 8 | # |
| 9 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 12 | # details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU Lesser General Public License |
| 15 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | |
| 18 | CURDIR=$(dirname $0)/ |
| 19 | TESTDIR=$CURDIR/../.. |
| 20 | EVENT_NAME="sched_switch" |
| 21 | PID_RELAYD=0 |
| 22 | SESSION_NAME="" |
| 23 | |
| 24 | source $TESTDIR/utils.sh |
| 25 | |
| 26 | echo -e "\n---------------------------" |
| 27 | echo -e " Streaming - Kernel tracing " |
| 28 | echo -e "----------------------------" |
| 29 | |
| 30 | if [ "$(id -u)" != "0" ]; then |
| 31 | echo "This test must be running as root. Aborting" |
| 32 | # Exit status 0 so the tests can continue |
| 33 | exit 0 |
| 34 | fi |
| 35 | |
| 36 | # LTTng kernel modules check |
| 37 | out=`ls /lib/modules/$(uname -r)/extra | grep lttng` |
| 38 | if [ -z "$out" ]; then |
| 39 | echo "LTTng modules not detected. Aborting kernel tests!" |
| 40 | echo "" |
| 41 | # Exit status 0 so the tests can continue |
| 42 | exit 0 |
| 43 | fi |
| 44 | |
| 45 | function lttng_create_session |
| 46 | { |
| 47 | echo -n "Creating session $SESSION_NAME... " |
| 48 | # Create session with default path |
| 49 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME >/dev/null 2>&1 |
| 50 | if [ $? -eq 1 ]; then |
| 51 | echo -e '\e[1;31mFAILED\e[0m' |
| 52 | return 1 |
| 53 | else |
| 54 | echo -e "\e[1;32mOK\e[0m" |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | function lttng_enable_consumer_localhost |
| 59 | { |
| 60 | echo -n "Enabling network consumer... " |
| 61 | # Create session with default path |
| 62 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -k net://localhost >/dev/null 2>&1 |
| 63 | if [ $? -eq 1 ]; then |
| 64 | echo -e '\e[1;31mFAILED\e[0m' |
| 65 | return 1 |
| 66 | else |
| 67 | echo -e "\e[1;32mOK\e[0m" |
| 68 | fi |
| 69 | } |
| 70 | |
| 71 | function test_kernel_before_start () |
| 72 | { |
| 73 | echo -e "\n=== Testing kernel streaming with event enable BEFORE start\n" |
| 74 | lttng_create_session |
| 75 | lttng_enable_consumer_localhost |
| 76 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME |
| 77 | start_tracing $SESSION_NAME |
| 78 | # Give a second |
| 79 | sleep 1 |
| 80 | stop_tracing $SESSION_NAME |
| 81 | destroy_lttng_session $SESSION_NAME |
| 82 | } |
| 83 | |
| 84 | function test_kernel_after_start () |
| 85 | { |
| 86 | echo -e "\n=== Testing kernel streaming with event enable AFTER start\n" |
| 87 | lttng_create_session |
| 88 | lttng_enable_consumer_localhost |
| 89 | start_tracing $SESSION_NAME |
| 90 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME |
| 91 | # Give a second |
| 92 | sleep 1 |
| 93 | stop_tracing $SESSION_NAME |
| 94 | destroy_lttng_session $SESSION_NAME |
| 95 | } |
| 96 | |
| 97 | start_sessiond |
| 98 | lttng_start_relayd |
| 99 | |
| 100 | tests=( test_kernel_before_start test_kernel_after_start ) |
| 101 | |
| 102 | for fct_test in ${tests[@]}; |
| 103 | do |
| 104 | SESSION_NAME=$(randstring 16 0) |
| 105 | ${fct_test} |
| 106 | |
| 107 | # Validate test |
| 108 | validate_trace $EVENT_NAME ~/lttng-traces/$HOSTNAME/$SESSION_NAME* |
| 109 | if [ $? -eq 0 ]; then |
| 110 | # Only delete if successful |
| 111 | rm -rf ~/lttng-traces/$HOSTNAME/$SESSION_NAME* |
| 112 | rm -rf ~/lttng-traces/$SESSION_NAME* |
| 113 | else |
| 114 | break |
| 115 | fi |
| 116 | done |
| 117 | |
| 118 | echo "" |
| 119 | stop_sessiond |
| 120 | lttng_stop_relayd |
| 121 | |
| 122 | |
| 123 | exit $out |