From: David Goulet Date: Tue, 10 Dec 2013 18:13:23 +0000 (-0500) Subject: Tests: add regression test for Java JUL support X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=37175ce4620a721d90235d7c906e49ecc14f62e3;hp=98f595d4c5972c980b6e5882ca199b4cc6c84abc Tests: add regression test for Java JUL support Signed-off-by: David Goulet --- diff --git a/.gitignore b/.gitignore index 74d01cbed..b11a8c322 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ Makefile.in *.info *.bz2 *.tar +*.class .dirstamp configure aclocal.m4 diff --git a/configure.ac b/configure.ac index 1ee6c5725..287c6d776 100644 --- a/configure.ac +++ b/configure.ac @@ -301,6 +301,43 @@ AX_CONFIG_FEATURE( ) AM_CONDITIONAL([COMPAT_EPOLL], [ test "$enable_epoll" = "yes" ]) +# Set compile flags to java include files if given. This is only used to +# compile JUL tests. +AC_ARG_WITH([java-jdk], + [AS_HELP_STRING([--with-java-jdk=DIR],[use the Java JDK in DIR. Ex : $JAVA_HOME.])], + [JAVA_JDK=$withval], + [JAVA_JDK=""] +) +AM_CONDITIONAL([HAVE_JAVA_JDK], [test $JAVA_JDK], [Java JDK path]) +AC_SUBST([JAVA_JDK]) + +AS_IF([test $JAVA_JDK],[ + AS_IF([test -d $JAVA_JDK], + [ + AC_MSG_RESULT([using Java includes in $JAVA_SDK]) + SUBDIRS=`find $JAVA_JDK/include -type d` + CPPFLAGS+=" " + CPPFLAGS+=`for x in $SUBDIRS; do echo -n "-I$x "; done` + CPPFLAGS+=" " + ],[AC_MSG_ERROR(Unable to find Java include files in $JAVA_JDK)] + ) +]) + +# Check for the UST JUL jar file in the system. Hardcoded path is added here +# since we have *no* idea where this could be installed. Note that this is only +# used for JUL testing. +AC_MSG_CHECKING(Java JUL UST jar file) +java_jul_jar_path="/usr/local/lib/lttng/java/liblttng-ust-jul.jar" +if test -f $java_jul_jar_path; then + build_java_jul=yes + AC_MSG_RESULT(found) +else + build_java_jul=no + AC_MSG_RESULT(not found) +fi +AM_CONDITIONAL([BUILD_JAVA_JUL], [test "x$build_java_jul" = "xyes"]) +AC_SUBST([java_jul_jar_path]) + AC_SYS_LARGEFILE AC_PROG_CC LT_INIT @@ -390,6 +427,7 @@ AC_CONFIG_FILES([ tests/regression/ust/exit-fast/Makefile tests/regression/ust/fork/Makefile tests/regression/ust/libc-wrapper/Makefile + tests/regression/ust/java-jul/Makefile tests/stress/Makefile tests/unit/Makefile tests/utils/Makefile diff --git a/tests/fast_regression b/tests/fast_regression index 54707229d..e969c3d76 100644 --- a/tests/fast_regression +++ b/tests/fast_regression @@ -15,5 +15,6 @@ regression/ust/buffers-pid/test_buffers_pid regression/ust/multi-session/test_multi_session regression/ust/nprocesses/test_nprocesses regression/ust/overlap/test_overlap +regression/ust/java-jul/test_java_jul regression/ust/test_event_basic regression/ust/test_event_wildcard diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am index e7b4cf71b..a4e3455ae 100644 --- a/tests/regression/ust/Makefile.am +++ b/tests/regression/ust/Makefile.am @@ -1,7 +1,7 @@ if HAVE_LIBLTTNG_UST_CTL SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \ overlap buffers-pid linking daemon exit-fast fork libc-wrapper \ - periodical-metadata-flush + periodical-metadata-flush java-jul EXTRA_DIST = test_event_basic test_event_wildcard diff --git a/tests/regression/ust/java-jul/JTestLTTng.java b/tests/regression/ust/java-jul/JTestLTTng.java new file mode 100644 index 000000000..5f15e1438 --- /dev/null +++ b/tests/regression/ust/java-jul/JTestLTTng.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2013 - David Goulet + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * This program 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +import java.lang.Integer; +import java.util.logging.Logger; + +import org.lttng.ust.jul.LTTngAgent; + +public class JTestLTTng +{ + private static LTTngAgent lttngAgent; + + public static void main(String args[]) throws Exception + { + Logger lttng = Logger.getLogger("JTestLTTng"); + int nrIter = Integer.parseInt(args[0]); + int waitTime = Integer.parseInt(args[1]); + + lttngAgent = LTTngAgent.getLTTngAgent(); + + for (int iter = 0; iter < nrIter; iter++) { + lttng.info("JUL tp fired!"); + Thread.sleep(waitTime); + } + + lttngAgent.dispose(); + } +} diff --git a/tests/regression/ust/java-jul/Makefile.am b/tests/regression/ust/java-jul/Makefile.am new file mode 100644 index 000000000..7d713a9a5 --- /dev/null +++ b/tests/regression/ust/java-jul/Makefile.am @@ -0,0 +1,36 @@ +if BUILD_JAVA_JUL + +noinst_SCRIPTS = test_java_jul +EXTRA_DIST = test_java_jul + +if HAVE_JAVA_JDK +JCC=$(JAVA_JDK)/bin/javac +else +JCC=javac +endif + +JUL_JAR_FILE=$(java_jul_jar_path) + +all-local: JTestLTTng.class + +%.class: %.java + $(JCC) -d "$(builddir)" -cp "$(JUL_JAR_FILE):." $< + +JTestLTTng.class: JTestLTTng.java + +all-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + cp -f $(srcdir)/$$script $(builddir); \ + done; \ + fi + +clean-local: + rm -f *.class + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + rm -f $(builddir)/$$script; \ + done; \ + fi + +endif # BUILD_JAVA_JUL diff --git a/tests/regression/ust/java-jul/test_java_jul b/tests/regression/ust/java-jul/test_java_jul new file mode 100755 index 000000000..ed963aa57 --- /dev/null +++ b/tests/regression/ust/java-jul/test_java_jul @@ -0,0 +1,120 @@ +#!/bin/bash +# +# Copyright (C) - 2013 David Goulet +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License, version 2 only, as published by +# the Free Software Foundation. +# +# This program 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 General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +TEST_DESC="Java JUL support" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +NR_ITER=6 +NR_MSEC_WAIT=1000 +TESTAPP_NAME="JTestLTTng" +TESTAPP_BIN="$TESTAPP_NAME.java" +TESTAPP_PATH="$CURDIR/$TESTAPP_NAME" +SESSION_NAME="jul" +EVENT_NAME="JTestLTTng" +JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar" + +TRACE_PATH=$(mktemp -d) + +NUM_TESTS=16 + +source $TESTDIR/utils/utils.sh + +function run_app +{ + java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT >/dev/null 2>&1 & +} + +function wait_apps +{ + while [ -n "$(pidof java)" ]; do + sleep 0.5 + done + pass "Wait for applications to end" +} + +# MUST set TESTDIR before calling those functions + +function test_jul_before_start () +{ + diag "Test JUL application BEFORE tracing starts" + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_jul_lttng_event $SESSION_NAME $EVENT_NAME + + # Run 5 times with a 1 second delay + run_app + + start_lttng_tracing $SESSION_NAME + + wait_apps + + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME +} + +function test_jul_after_start () +{ + diag "Test JUL application AFTER tracing starts" + + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_jul_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + + # Run 5 times with a 1 second delay + run_app + + wait_apps + + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME +} + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +if [ ! -f "$TESTAPP_PATH.class" ]; then + withapp=0 +else + withapp=1 +fi + +skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS || +{ + start_lttng_sessiond + + tests=( + test_jul_before_start + test_jul_after_start + ) + + for fct_test in ${tests[@]}; + do + ${fct_test} + + # Validate test + validate_trace $EVENT_NAME $TRACE_PATH + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $TRACE_PATH + else + break + fi + done + + stop_lttng_sessiond +} diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 9e2c12d0b..968a6e613 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -257,6 +257,23 @@ function enable_ust_lttng_event () ok $? "Enable event $event_name for session $sess_name" } +function enable_jul_lttng_event() +{ + sess_name=$1 + event_name="$2" + channel_name=$3 + + if [ -z $channel_name ]; then + # default channel if none specified + chan="" + else + chan="-c $channel_name" + fi + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j >/dev/null 2>&1 + ok $? "Enable JUL event $event_name for session $sess_name" +} + function enable_ust_lttng_event_filter() { sess_name="$1"