| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com> |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify it under |
| 6 | # the terms of the GNU General Public License, version 2 only, as published by |
| 7 | # the Free Software Foundation. |
| 8 | # |
| 9 | # This program 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 General Public License for more |
| 12 | # details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License along with |
| 15 | # this program; if not, write to the Free Software Foundation, Inc., 51 |
| 16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | |
| 18 | TEST_DESC="Java JUL support" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../../.. |
| 22 | NR_ITER=6 |
| 23 | NR_MSEC_WAIT=1000 |
| 24 | TESTAPP_NAME="JTestLTTng" |
| 25 | TESTAPP_BIN="$TESTAPP_NAME.java" |
| 26 | TESTAPP_PATH="$CURDIR/$TESTAPP_NAME" |
| 27 | SESSION_NAME="jul" |
| 28 | EVENT_NAME="JTestLTTng" |
| 29 | JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar" |
| 30 | |
| 31 | TRACE_PATH=$(mktemp -d) |
| 32 | |
| 33 | NUM_TESTS=16 |
| 34 | |
| 35 | source $TESTDIR/utils/utils.sh |
| 36 | |
| 37 | function run_app |
| 38 | { |
| 39 | java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT >/dev/null 2>&1 & |
| 40 | } |
| 41 | |
| 42 | function wait_apps |
| 43 | { |
| 44 | while [ -n "$(pidof java)" ]; do |
| 45 | sleep 0.5 |
| 46 | done |
| 47 | pass "Wait for applications to end" |
| 48 | } |
| 49 | |
| 50 | # MUST set TESTDIR before calling those functions |
| 51 | |
| 52 | function test_jul_before_start () |
| 53 | { |
| 54 | diag "Test JUL application BEFORE tracing starts" |
| 55 | create_lttng_session $SESSION_NAME $TRACE_PATH |
| 56 | enable_jul_lttng_event $SESSION_NAME $EVENT_NAME |
| 57 | |
| 58 | # Run 5 times with a 1 second delay |
| 59 | run_app |
| 60 | |
| 61 | start_lttng_tracing $SESSION_NAME |
| 62 | |
| 63 | wait_apps |
| 64 | |
| 65 | stop_lttng_tracing $SESSION_NAME |
| 66 | destroy_lttng_session $SESSION_NAME |
| 67 | } |
| 68 | |
| 69 | function test_jul_after_start () |
| 70 | { |
| 71 | diag "Test JUL application AFTER tracing starts" |
| 72 | |
| 73 | create_lttng_session $SESSION_NAME $TRACE_PATH |
| 74 | enable_jul_lttng_event $SESSION_NAME $EVENT_NAME |
| 75 | start_lttng_tracing $SESSION_NAME |
| 76 | |
| 77 | # Run 5 times with a 1 second delay |
| 78 | run_app |
| 79 | |
| 80 | wait_apps |
| 81 | |
| 82 | stop_lttng_tracing $SESSION_NAME |
| 83 | destroy_lttng_session $SESSION_NAME |
| 84 | } |
| 85 | |
| 86 | plan_tests $NUM_TESTS |
| 87 | |
| 88 | print_test_banner "$TEST_DESC" |
| 89 | |
| 90 | if [ ! -f "$TESTAPP_PATH.class" ]; then |
| 91 | withapp=0 |
| 92 | else |
| 93 | withapp=1 |
| 94 | fi |
| 95 | |
| 96 | skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS || |
| 97 | { |
| 98 | start_lttng_sessiond |
| 99 | |
| 100 | tests=( |
| 101 | test_jul_before_start |
| 102 | test_jul_after_start |
| 103 | ) |
| 104 | |
| 105 | for fct_test in ${tests[@]}; |
| 106 | do |
| 107 | ${fct_test} |
| 108 | |
| 109 | # Validate test |
| 110 | validate_trace $EVENT_NAME $TRACE_PATH |
| 111 | if [ $? -eq 0 ]; then |
| 112 | # Only delete if successful |
| 113 | rm -rf $TRACE_PATH |
| 114 | else |
| 115 | break |
| 116 | fi |
| 117 | done |
| 118 | |
| 119 | stop_lttng_sessiond |
| 120 | } |