<div dir="ltr">Merged, thanks!<div><br></div><div>Jérémie</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 4, 2015 at 6:21 PM, Michael Jeanson <span dir="ltr"><<a href="mailto:mjeanson@efficios.com" target="_blank">mjeanson@efficios.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch fixes the Java agent tests which were impossible to run since<br>
the Jar files have been renamed. It also overhauls the java part of the<br>
configure script to match what's in UST and replace some hardcoded path<br>
with configurable values.<br>
<br>
The tests are now enabled when corresponding classes are found in the<br>
CLASSPATH during configure.<br>
<br>
Signed-off-by: Michael Jeanson <<a href="mailto:mjeanson@efficios.com">mjeanson@efficios.com</a>><br>
---<br>
.gitignore | 2 +<br>
config/ax_check_class.m4 | 2 +-<br>
<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 80 +++++++++----------------<br>
tests/regression/ust/java-jul/JTestLTTng.java | 34 ++++++++---<br>
tests/regression/ust/java-jul/Makefile.am | 21 ++-----<br>
tests/regression/ust/java-jul/test_java_jul | 4 +-<br>
tests/regression/ust/java-log4j/JTestLTTng.java | 38 +++++++++---<br>
tests/regression/ust/java-log4j/Makefile.am | 17 +-----<br>
tests/regression/ust/java-log4j/test_java_log4j | 4 +-<br>
9 files changed, 99 insertions(+), 103 deletions(-)<br>
<br>
diff --git a/.gitignore b/.gitignore<br>
index ff19c8d..5d24bec 100644<br>
--- a/.gitignore<br>
+++ b/.gitignore<br>
@@ -93,3 +93,5 @@ health_check<br>
/benchmark/<br>
<br>
/include/version.h<br>
+<br>
+classnoinst.stamp<br>
diff --git a/config/ax_check_class.m4 b/config/ax_check_class.m4<br>
index 098aa77..42b51d7 100644<br>
--- a/config/ax_check_class.m4<br>
+++ b/config/ax_check_class.m4<br>
@@ -118,7 +118,7 @@ EOF<br>
ac_cv_prog_uudecode_base64=no<br>
fi<br>
rm -f Test.uue<br>
- if AC_TRY_COMMAND($JAVA $JAVAFLAGS Test $1) >/dev/null 2>&1; then<br>
+ if AC_TRY_COMMAND($JAVA -classpath ".:$CLASSPATH" $JAVAFLAGS Test $1) >/dev/null 2>&1; then<br>
eval "ac_cv_class_$ac_var_name=yes"<br>
else<br>
eval "ac_cv_class_$ac_var_name=no"<br>
diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index 2fc6e53..bfef178 100644<br>
--- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -355,65 +355,43 @@ AX_CONFIG_FEATURE(<br>
)<br>
AM_CONDITIONAL([COMPAT_EPOLL], [ test "$enable_epoll" = "yes" ])<br>
<br>
-# Set compile flags to java include files if given. This is only used to<br>
-# compile java agent tests.<br>
-AC_ARG_WITH([java-jdk],<br>
- [AS_HELP_STRING([--with-java-jdk=DIR],[use the Java JDK in DIR. Ex : $JAVA_HOME.])],<br>
- [JAVA_JDK=$withval],<br>
- [JAVA_JDK=""]<br>
-)<br>
-AM_CONDITIONAL([HAVE_JAVA_JDK], [test $JAVA_JDK], [Java JDK path])<br>
-AC_SUBST([JAVA_JDK])<br>
+AX_JAVA_OPTIONS<br>
+AX_PROG_JAVAC<br>
+AX_PROG_JAVA<br>
+AX_PROG_JAR<br>
<br>
-AS_IF([test $JAVA_JDK],[<br>
- AS_IF([test -d $JAVA_JDK],<br>
- [<br>
- AC_MSG_RESULT([using Java includes in $JAVA_SDK])<br>
- SUBDIRS=`find $JAVA_JDK/include -type d`<br>
- CPPFLAGS+=" "<br>
- CPPFLAGS+=`for x in $SUBDIRS; do echo -n "-I$x "; done`<br>
- CPPFLAGS+=" "<br>
- ],[AC_MSG_ERROR(Unable to find Java include files in $JAVA_JDK)]<br>
- )<br>
-])<br>
+AX_CHECK_CLASSPATH<br>
<br>
-# Check for the UST agent jar file in the system. Hardcoded path is added here<br>
-# since we have *no* idea where this could be installed. Note that this is only<br>
-# used for agent testing.<br>
-AC_MSG_CHECKING(Java UST agent jar file)<br>
-java_agent_jar_path="${prefix}/share/java/liblttng-ust-agent.jar"<br>
-if test -f $java_agent_jar_path; then<br>
- build_java_agent=yes<br>
- AC_MSG_RESULT(found)<br>
+# Check for Java UST agent common class first<br>
+AX_CHECK_CLASS(org.lttng.ust.agent.AbstractLttngAgent)<br>
+if test "x$ac_cv_class_org_lttng_ust_agent_AbstractLttngAgent" = "xyes"; then<br>
+ java_agent_common=yes<br>
else<br>
- build_java_agent=no<br>
- AC_MSG_RESULT(not found)<br>
+ java_agent_common=no<br>
fi<br>
-AM_CONDITIONAL([BUILD_JAVA_AGENT], [test "x$build_java_agent" = "xyes"])<br>
-AC_SUBST([java_agent_jar_path])<br>
-<br>
-# Check for log4j support on the system to know if we can build or not the<br>
-# log4j tests.<br>
-if test "x$build_java_agent" = "xyes"; then<br>
- AC_MSG_CHECKING(Java agent support for log4j)<br>
- AX_JAVA_OPTIONS<br>
- AX_PROG_JAR<br>
- AX_PROG_JAVA<br>
- AX_PROG_JAVAC<br>
-<br>
- # By default, use a commonly used classpath on the system to ease things up<br>
- # for the Java testing in this directory.<br>
- LOG4J_CLASSPATH="$java_agent_jar_path:$CLASSPATH:.:/usr/share/java/*"<br>
- JAVAFLAGS="-cp $LOG4J_CLASSPATH"<br>
- JAVACFLAGS="$JAVAFLAGS"<br>
+<br>
+# If the common class is available, test for each agent<br>
+if test "x$java_agent_common" = "xyes"; then<br>
+ # Check for JUL<br>
+ AX_CHECK_CLASS(org.lttng.ust.agent.jul.LttngLogHandler)<br>
+ AX_CHECK_CLASS(org.lttng.ust.agent.log4j.LttngLogAppender)<br>
AX_CHECK_CLASS(org.apache.log4j.Logger)<br>
<br>
- if test "x$ac_cv_class_org_apache_log4j_Logger" = "xno"; then<br>
- build_java_log4j_agent=no<br>
- else<br>
- build_java_log4j_agent=yes<br>
+ build_java_jul_agent=no<br>
+ if test "x$ac_cv_class_org_lttng_ust_agent_jul_LttngLogHandler" = "xyes"; then<br>
+ build_java_jul_agent=yes<br>
fi<br>
+<br>
+ build_java_log4j_agent=no<br>
+ if test "x$ac_cv_class_org_lttng_ust_agent_log4j_LttngLogAppender" = "xyes"; then<br>
+ if test "x$ac_cv_class_org_apache_log4j_Logger" = "xyes"; then<br>
+ build_java_log4j_agent=yes<br>
+ fi<br>
+ fi<br>
+<br>
fi<br>
+<br>
+AM_CONDITIONAL([BUILD_JAVA_JUL_AGENT], [test "x$build_java_jul_agent" = "xyes"])<br>
AM_CONDITIONAL([BUILD_JAVA_LOG4J_AGENT], [test "x$build_java_log4j_agent" = "xyes"])<br>
<br>
AC_SYS_LARGEFILE<br>
diff --git a/tests/regression/ust/java-jul/JTestLTTng.java b/tests/regression/ust/java-jul/JTestLTTng.java<br>
index 9431551..741d820 100644<br>
--- a/tests/regression/ust/java-jul/JTestLTTng.java<br>
+++ b/tests/regression/ust/java-jul/JTestLTTng.java<br>
@@ -1,4 +1,5 @@<br>
/*<br>
+ * Copyright (C) 2015 - Michael Jeanson <<a href="mailto:mjeanson@efficios.com">mjeanson@efficios.com</a>><br>
* Copyright (C) 2013 - David Goulet <<a href="mailto:dgoulet@efficios.com">dgoulet@efficios.com</a>><br>
*<br>
* This program is free software; you can redistribute it and/or modify it<br>
@@ -15,20 +16,29 @@<br>
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.<br>
*/<br>
<br>
+import java.io.IOException;<br>
import java.lang.Integer;<br>
+import java.util.logging.Handler;<br>
import java.util.logging.Logger;<br>
import java.util.logging.Level;<br>
<br>
-import org.lttng.ust.agent.LTTngAgent;<br>
+import org.lttng.ust.agent.jul.LttngLogHandler;<br>
<br>
-public class JTestLTTng<br>
-{<br>
- private static LTTngAgent lttngAgent;<br>
+public class JTestLTTng {<br>
+<br>
+ /**<br>
+ * Application start<br>
+ *<br>
+ * @param args<br>
+ * Command-line arguments<br>
+ * @throws IOException<br>
+ * @throws InterruptedException<br>
+ */<br>
+ public static void main(String args[]) throws IOException, InterruptedException {<br>
<br>
- public static void main(String args[]) throws Exception<br>
- {<br>
Logger lttng = Logger.getLogger("JTestLTTng");<br>
Logger lttng2 = Logger.getLogger("JTestLTTng2");<br>
+<br>
int nrIter = Integer.parseInt(args[0]);<br>
int waitTime = Integer.parseInt(args[1]);<br>
int fire_finest_tp = 0;<br>
@@ -41,7 +51,11 @@ public class JTestLTTng<br>
fire_second_tp = Integer.parseInt(args[3]);<br>
}<br>
<br>
- lttngAgent = LTTngAgent.getLTTngAgent();<br>
+ /* Instantiate a LTTngLogHandler object, and attach it to our loggers */<br>
+ Handler lttngHandler = new LttngLogHandler();<br>
+ lttng.addHandler(lttngHandler);<br>
+ lttng2.addHandler(lttngHandler);<br>
+<br>
lttng.setLevel(Level.FINEST);<br>
<br>
for (int iter = 0; iter < nrIter; iter++) {<br>
@@ -57,6 +71,10 @@ public class JTestLTTng<br>
<a href="http://lttng2.info" rel="noreferrer" target="_blank">lttng2.info</a>("JUL second logger fired");<br>
}<br>
<br>
- lttngAgent.dispose();<br>
+ /*<br>
+ * Do not forget to close() all handlers so that the agent can shutdown<br>
+ * and the session daemon socket gets cleaned up explicitly.<br>
+ */<br>
+ lttngHandler.close();<br>
}<br>
}<br>
diff --git a/tests/regression/ust/java-jul/Makefile.am b/tests/regression/ust/java-jul/Makefile.am<br>
index 286e3df..877237f 100644<br>
--- a/tests/regression/ust/java-jul/Makefile.am<br>
+++ b/tests/regression/ust/java-jul/Makefile.am<br>
@@ -1,25 +1,13 @@<br>
+JAVAROOT = .<br>
<br>
noinst_SCRIPTS = test_java_jul JTestLTTng.java<br>
EXTRA_DIST = test_java_jul JTestLTTng.java<br>
<br>
-if HAVE_JAVA_JDK<br>
-JCC=$(JAVA_JDK)/bin/javac<br>
-else<br>
-JCC=javac<br>
-endif<br>
+if BUILD_JAVA_JUL_AGENT<br>
+dist_noinst_JAVA = JTestLTTng.java<br>
+endif # BUILD_JAVA_JUL_AGENT<br>
<br>
-AGENT_JAR_FILE=$(java_agent_jar_path)<br>
-<br>
-<br>
-# Still need to copy test files in case of out of tree build<br>
-if BUILD_JAVA_AGENT<br>
-all-local: static_file JTestLTTng.class<br>
-%.class: %.java<br>
- $(JCC) -d "$(builddir)" -cp "$(AGENT_JAR_FILE):." $<<br>
-else<br>
all-local: static_file<br>
-endif # BUILD_JAVA_AGENT<br>
-<br>
<br>
static_file:<br>
@if [ x"$(srcdir)" != x"$(builddir)" ]; then \<br>
@@ -28,7 +16,6 @@ static_file:<br>
done; \<br>
fi<br>
<br>
-<br>
clean-local:<br>
rm -f *.class<br>
@if [ x"$(srcdir)" != x"$(builddir)" ]; then \<br>
diff --git a/tests/regression/ust/java-jul/test_java_jul b/tests/regression/ust/java-jul/test_java_jul<br>
index 48c8b74..f9f244b 100755<br>
--- a/tests/regression/ust/java-jul/test_java_jul<br>
+++ b/tests/regression/ust/java-jul/test_java_jul<br>
@@ -27,7 +27,7 @@ TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"<br>
SESSION_NAME="jul"<br>
EVENT_NAME="JTestLTTng"<br>
EVENT_NAME2="JTestLTTng2"<br>
-JAVA_CP="$CURDIR:/usr/local/share/java/liblttng-ust-agent.jar:/usr/share/java/liblttng-ust-agent.jar"<br>
+JAVA_CP="$CURDIR:$CLASSPATH"<br>
<br>
NUM_TESTS=155<br>
<br>
@@ -39,7 +39,7 @@ function run_app<br>
local fire_second_tp=$2<br>
<br>
#FIXME: app should have synchro.<br>
- java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1<br>
+ java -cp $JAVA_CP -Djava.library.path="$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1<br>
}<br>
<br>
function run_app_background<br>
diff --git a/tests/regression/ust/java-log4j/JTestLTTng.java b/tests/regression/ust/java-log4j/JTestLTTng.java<br>
index 0019cb8..64a471b 100644<br>
--- a/tests/regression/ust/java-log4j/JTestLTTng.java<br>
+++ b/tests/regression/ust/java-log4j/JTestLTTng.java<br>
@@ -1,4 +1,5 @@<br>
/*<br>
+ * Copyright (C) 2015 - Michael Jeanson <<a href="mailto:dgoulet@efficios.com">dgoulet@efficios.com</a>><br>
* Copyright (C) 2014 - David Goulet <<a href="mailto:dgoulet@efficios.com">dgoulet@efficios.com</a>><br>
* Christian Babeux <<a href="mailto:christian.babeux@efficios.com">christian.babeux@efficios.com</a>><br>
*<br>
@@ -19,19 +20,26 @@<br>
import java.io.IOException;<br>
import java.lang.Integer;<br>
<br>
-import org.apache.log4j.Logger;<br>
+import org.apache.log4j.Appender;<br>
import org.apache.log4j.BasicConfigurator;<br>
+import org.apache.log4j.Logger;<br>
+import org.lttng.ust.agent.log4j.LttngLogAppender;<br>
<br>
-import org.lttng.ust.agent.LTTngAgent;<br>
+public class JTestLTTng {<br>
<br>
-public class JTestLTTng<br>
-{<br>
- private static LTTngAgent lttngAgent;<br>
+ /**<br>
+ * Application start<br>
+ *<br>
+ * @param args<br>
+ * Command-line arguments<br>
+ * @throws IOException<br>
+ * @throws InterruptedException<br>
+ */<br>
+ public static void main(String args[]) throws IOException, InterruptedException {<br>
<br>
- public static void main(String args[]) throws Exception<br>
- {<br>
Logger lttng = Logger.getLogger("log4j-event");<br>
Logger lttng2 = Logger.getLogger("log4j-event-2");<br>
+<br>
int nrIter = Integer.parseInt(args[0]);<br>
int waitTime = Integer.parseInt(args[1]);<br>
int fire_debug_tp = 0;<br>
@@ -44,8 +52,16 @@ public class JTestLTTng<br>
fire_second_tp = Integer.parseInt(args[3]);<br>
}<br>
<br>
+ /* Start with the default Log4j configuration, which logs to console */<br>
BasicConfigurator.configure();<br>
- lttngAgent = LTTngAgent.getLTTngAgent();<br>
+<br>
+ /*<br>
+ * Add a LTTng log appender to both loggers, which will also send the<br>
+ * logged events to UST.<br>
+ */<br>
+ Appender lttngAppender = new LttngLogAppender();<br>
+ lttng.addAppender(lttngAppender);<br>
+ lttng2.addAppender(lttngAppender);<br>
<br>
for (int iter = 0; iter < nrIter; iter++) {<br>
<a href="http://lttng.info" rel="noreferrer" target="_blank">lttng.info</a>("LOG4J tp fired!");<br>
@@ -59,5 +75,11 @@ public class JTestLTTng<br>
if (fire_second_tp == 1) {<br>
<a href="http://lttng2.info" rel="noreferrer" target="_blank">lttng2.info</a>("LOG4J second logger fired");<br>
}<br>
+<br>
+ /*<br>
+ * Do not forget to close() all handlers so that the agent can shutdown<br>
+ * and the session daemon socket gets cleaned up explicitly.<br>
+ */<br>
+ lttngAppender.close();<br>
}<br>
}<br>
diff --git a/tests/regression/ust/java-log4j/Makefile.am b/tests/regression/ust/java-log4j/Makefile.am<br>
index 7d6c048..42daab8 100644<br>
--- a/tests/regression/ust/java-log4j/Makefile.am<br>
+++ b/tests/regression/ust/java-log4j/Makefile.am<br>
@@ -1,24 +1,13 @@<br>
+JAVAROOT = .<br>
<br>
noinst_SCRIPTS = test_java_log4j JTestLTTng.java<br>
EXTRA_DIST = test_java_log4j JTestLTTng.java<br>
<br>
-if HAVE_JAVA_JDK<br>
-JCC=$(JAVA_JDK)/bin/javac<br>
-else<br>
-JCC=javac<br>
-endif<br>
-<br>
-# We still need to copy static files for out of tree and dist build<br>
if BUILD_JAVA_LOG4J_AGENT<br>
-all-local: static_file JTestLTTng.class<br>
-<br>
-%.class: %.java<br>
- $(JCC) -d "$(builddir)" $(JAVACFLAGS) $<<br>
-else<br>
-all-local: static_file<br>
+dist_noinst_JAVA = JTestLTTng.java<br>
endif # BUILD_JAVA_LOG4J_AGENT<br>
<br>
-JTestLTTng.class: JTestLTTng.java<br>
+all-local: static_file<br>
<br>
static_file:<br>
@if [ x"$(srcdir)" != x"$(builddir)" ]; then \<br>
diff --git a/tests/regression/ust/java-log4j/test_java_log4j b/tests/regression/ust/java-log4j/test_java_log4j<br>
index cdc0c4c..d5c6621 100755<br>
--- a/tests/regression/ust/java-log4j/test_java_log4j<br>
+++ b/tests/regression/ust/java-log4j/test_java_log4j<br>
@@ -27,7 +27,7 @@ TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"<br>
SESSION_NAME="log4j"<br>
EVENT_NAME="log4j-event"<br>
EVENT_NAME2="log4j-event-2"<br>
-JAVA_CP="$CURDIR:/usr/local/share/java/liblttng-ust-agent.jar:/usr/share/java/*"<br>
+JAVA_CP="$CURDIR:$CLASSPATH"<br>
OUTPUT_DEST="/dev/null"<br>
<br>
NUM_TESTS=155<br>
@@ -40,7 +40,7 @@ function run_app<br>
local fire_second_tp=$2<br>
<br>
# FIXME: test app should have synchro.<br>
- java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev/null 2>&1<br>
+ java -cp $JAVA_CP -Djava.library.path="$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev/null 2>&1<br>
}<br>
<br>
function run_app_background<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Jérémie Galarneau<br>EfficiOS Inc.<br><a href="http://www.efficios.com" target="_blank">http://www.efficios.com</a></div>
</div>