Tests: add regression test for Java JUL support
authorDavid Goulet <dgoulet@efficios.com>
Tue, 10 Dec 2013 18:13:23 +0000 (13:13 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 10 Dec 2013 18:13:23 +0000 (13:13 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
.gitignore
configure.ac
tests/fast_regression
tests/regression/ust/Makefile.am
tests/regression/ust/java-jul/JTestLTTng.java [new file with mode: 0644]
tests/regression/ust/java-jul/Makefile.am [new file with mode: 0644]
tests/regression/ust/java-jul/test_java_jul [new file with mode: 0755]
tests/utils/utils.sh

index 74d01cbed7a770b657973b49893fcdd1a4d41acb..b11a8c3226c594b40494172ef03de62df71a4114 100644 (file)
@@ -15,6 +15,7 @@ Makefile.in
 *.info
 *.bz2
 *.tar
+*.class
 .dirstamp
 configure
 aclocal.m4
index 1ee6c5725139201580bab2edbea01444e83036b5..287c6d776568fc5332512bc7bdaa2c64dfb5f85a 100644 (file)
@@ -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
index 54707229d16dca321918b650e1991b8384fd0983..e969c3d768eb4e4828d3e82d2927d599d6a45ba3 100644 (file)
@@ -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
index e7b4cf71b8f27f0c8f8ead42074c13bcf42db409..a4e3455aec145744f1301732be1135fb9fcd082d 100644 (file)
@@ -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 (file)
index 0000000..5f15e14
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ *
+ * 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 (file)
index 0000000..7d713a9
--- /dev/null
@@ -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 (executable)
index 0000000..ed963aa
--- /dev/null
@@ -0,0 +1,120 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
+#
+# 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
+}
index 9e2c12d0be68de3cd2c8f6bd5d43a532bf6c3b78..968a6e61305ac92d1d633856027130f712584a5a 100644 (file)
@@ -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"
This page took 0.030844 seconds and 4 git commands to generate.