org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.autoboxing=warning
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
-org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
-org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
-org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
-org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
-org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
-org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
-org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
-org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
-org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
-org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
-org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
-org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
-org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
-org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
-org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
-org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=warning
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
-org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
-org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
-org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
-org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=disabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=disabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
-org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
-org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
-org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.8
import org.junit.Before;
import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark;
import org.lttng.ust.agent.jul.LttngLogHandler;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
public class LttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark {
+ private LttngSession session;
+
@Before
public void testSetup() throws IOException {
handler = new LttngLogHandler();
- assertTrue(LttngSessionControl.setupSession(null, Domain.JUL));
+ session = new LttngSession(null, Domain.JUL);
+ assertTrue(session.enableEvents("non-event"));
+ assertTrue(session.start());
}
@After
public void testTeardown() {
- assertTrue(LttngSessionControl.stopSession(null));
- assertTrue(LttngSessionControl.destroySession(null));
+ assertTrue(session.stop());
+ session.close();
}
}
import org.junit.Before;
import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark;
import org.lttng.ust.agent.jul.LttngLogHandler;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
public class LttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
+ private LttngSession session;
+
@Before
public void testSetup() throws IOException {
handler = new LttngLogHandler();
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, Domain.JUL));
+ session = new LttngSession(null, Domain.JUL);
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.start());
}
@After
public void testTeardown() {
- assertTrue(LttngSessionControl.stopSession(null));
- assertTrue(LttngSessionControl.destroySession(null));
+ assertTrue(session.stop());
+ session.close();
}
}
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-
import org.junit.After;
import org.junit.Before;
import org.lttng.ust.agent.LTTngAgent;
import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
@SuppressWarnings("deprecation")
public class OldLttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark {
+ private LttngSession session;
+
@Before
- public void testSetup() throws IOException {
+ public void testSetup() {
LTTngAgent.getLTTngAgent();
- assertTrue(LttngSessionControl.setupSession(null, Domain.JUL));
+ session = new LttngSession(null, Domain.JUL);
+ assertTrue(session.enableEvents("non-event"));
+ assertTrue(session.start());
}
@After
public void testTeardown() {
- assertTrue(LttngSessionControl.stopSession(null));
- assertTrue(LttngSessionControl.destroySession(null));
+ assertTrue(session.stop());
+ session.close();
LTTngAgent.dispose();
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.IOException;
import java.lang.reflect.Field;
import org.junit.After;
import org.lttng.ust.agent.LTTngAgent;
import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark;
import org.lttng.ust.agent.jul.LttngLogHandler;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
@SuppressWarnings("deprecation")
public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
+ private LttngSession session;
private LttngLogHandler agentHandler;
@Before
- public void testSetup() throws IOException {
+ public void testSetup() {
LTTngAgent agentInstance = LTTngAgent.getLTTngAgent();
/*
fail();
}
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, Domain.JUL));
+ session = new LttngSession(null, Domain.JUL);
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.start());
}
@After
public void testTeardown() {
- assertTrue(LttngSessionControl.stopSession(null));
- assertTrue(LttngSessionControl.destroySession(null));
+ assertTrue(session.stop());
+ session.close();
logger.removeHandler(agentHandler);
LTTngAgent.dispose();
import org.junit.Before;
import org.junit.Test;
import org.lttng.ust.agent.ILttngHandler;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
public abstract class EnabledEventsTest {
protected static final String EVENT_NAME_C = "EventABC";
protected static final String EVENT_NAME_D = "EventABCD";
+ private LttngSession session;
+
/* Fields defined by the sub-class */
protected ILttngHandler handlerA;
protected ILttngHandler handlerB;
@Before
public void testSetup() {
-
+ session = new LttngSession(null, getDomain());
}
@After
public void testTeardown() {
- /* In case the test fails before destroying the session */
- LttngSessionControl.tryDestroySession(null);
+ session.close();
handlerA.close();
handlerB.close();
*/
@Test
public void testNoEvents() {
- assertTrue(LttngSessionControl.setupSession(null, getDomain()));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertTrue(output.isEmpty());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(0, handlerA.getEventCount());
assertEquals(0, handlerB.getEventCount());
assertEquals(0, handlerC.getEventCount());
*/
@Test
public void testAllEvents() {
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain()));
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(30, output.size()); // loggerD has no handler attached
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(10, handlerA.getEventCount());
assertEquals(10, handlerB.getEventCount());
assertEquals(10, handlerC.getEventCount());
*/
@Test
public void testSomeEvents() {
- assertTrue(LttngSessionControl.setupSession(null, getDomain(),
- EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
+ assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(20, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(10, handlerA.getEventCount());
assertEquals(0, handlerB.getEventCount());
assertEquals(10, handlerC.getEventCount());
*/
@Test
public void testAllEventsAndSome() {
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain()));
- assertTrue(LttngSessionControl.enableEvents(null, getDomain(),
- EVENT_NAME_A, EVENT_NAME_B));
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_B));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(30, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(10, handlerA.getEventCount());
assertEquals(10, handlerB.getEventCount());
assertEquals(10, handlerC.getEventCount());
*/
@Test
public void testSomeEventsAfterDisabling() {
- assertTrue(LttngSessionControl.setupSession(null, getDomain(),
- EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
-
- assertTrue(LttngSessionControl.disableEvents(null, getDomain(),
- EVENT_NAME_C));
+ assertTrue(session.enableEvents(EVENT_NAME_A, EVENT_NAME_C, EVENT_NAME_D));
+ assertTrue(session.disableEvents(EVENT_NAME_C));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(10, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(10, handlerA.getEventCount());
assertEquals(0, handlerB.getEventCount());
assertEquals(0, handlerC.getEventCount());
*/
@Test
public void testEventPrefix() {
- assertTrue(LttngSessionControl.setupSession(null, getDomain(),
- "EventAB*")); // should match event/loggers B and C, but not A.
+ // should match event/loggers B and C, but not A.
+ assertTrue(session.enableEvents("EventAB*"));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(20, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(0, handlerA.getEventCount());
assertEquals(10, handlerB.getEventCount());
assertEquals(10, handlerC.getEventCount());
*/
@Test
public void testEventPrefixOverlapping() {
- assertTrue(LttngSessionControl.setupSession(null, getDomain(),
- "EventAB*", "EventABC*")); // should still match B and C
+ // should still match B and C
+ assertTrue(session.enableEvents("EventAB*", "EventABC*"));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(20, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(0, handlerA.getEventCount());
assertEquals(10, handlerB.getEventCount());
assertEquals(10, handlerC.getEventCount());
*/
@Test
public void testAllEventsAndPrefix() {
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, getDomain()));
- assertTrue(LttngSessionControl.enableEvents(null, getDomain(),
- "EventAB*")); // should match B and C
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.enableEvents("EventAB*"));
+ assertTrue(session.start());
sendEventsToLoggers();
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(30, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
assertEquals(10, handlerA.getEventCount());
assertEquals(10, handlerB.getEventCount());
assertEquals(10, handlerC.getEventCount());
import static org.junit.Assume.assumeTrue;
import java.io.IOException;
-import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.BeforeClass;
import org.lttng.ust.agent.integration.common.EnabledEventsTest;
import org.lttng.ust.agent.jul.LttngLogHandler;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
+import org.lttng.ust.agent.utils.TestUtils;
public class JulEnabledEventsTest extends EnabledEventsTest {
@BeforeClass
public static void julClassSetup() {
/* Skip tests if we can't find the JNI library or lttng-tools */
- try {
- LttngLogHandler testHandler = new LttngLogHandler();
- testHandler.close();
- } catch (SecurityException | IOException e) {
- assumeTrue(false);
- }
-
- boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
- boolean ret2 = LttngSessionControl.stopSession(null);
- /* "lttng view" also tests that Babeltrace is installed and working */
- List<String> contents = LttngSessionControl.viewSession(null);
- boolean ret3 = LttngSessionControl.destroySession(null);
- assumeTrue(ret1 && ret2 && ret3);
- assumeTrue(contents.isEmpty());
+ assumeTrue(TestUtils.checkForJulLibrary());
+ assumeTrue(TestUtils.checkForLttngTools(Domain.JUL));
}
@AfterClass
public static void julClassCleanup() {
- LttngSessionControl.deleteAllTracee();
+ LttngSession.deleteAllTracee();
}
@Before
@Override
protected void sendEventsToLoggers() {
- send10Events(loggerA);
- send10Events(loggerB);
- send10Events(loggerC);
- send10Events(loggerD);
- }
-
- static void send10Events(Logger logger) {
- String a = new String("a");
- Object[] params = { a, new String("b"), new Object() };
-
- // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING
- logger.fine("A fine level message");
- logger.finer("A finer level message");
- logger.finest("A finest level message");
- logger.info("A info level message");
- logger.severe("A severe level message");
- logger.warning("A warning level message");
- logger.warning("Another warning level message");
- logger.log(Level.WARNING, "A warning message using Logger.log()");
- logger.log(Level.INFO, "A message with one parameter", a);
- logger.log(Level.INFO, "A message with parameters", params);
+ JulTestUtils.send10EventsTo(loggerA);
+ JulTestUtils.send10EventsTo(loggerB);
+ JulTestUtils.send10EventsTo(loggerC);
+ JulTestUtils.send10EventsTo(loggerD);
}
}
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
-import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.logging.Level;
import org.junit.Test;
import org.lttng.ust.agent.ILttngHandler;
import org.lttng.ust.agent.LTTngAgent;
-import org.lttng.ust.agent.jul.LttngLogHandler;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
+import org.lttng.ust.agent.utils.TestUtils;
@SuppressWarnings("deprecation")
public class JulLegacyApiTest {
private static final String EVENT_NAME_A = "EventA";
private static final String EVENT_NAME_B = "EventB";
+ private LttngSession session;
+
private Logger loggerA;
private Logger loggerB;
@BeforeClass
public static void julClassSetup() {
/* Skip tests if we can't find the JNI library or lttng-tools */
- try {
- LttngLogHandler testHandler = new LttngLogHandler();
- testHandler.close();
- } catch (SecurityException | IOException e) {
- assumeTrue(false);
- }
-
- boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
- boolean ret2 = LttngSessionControl.stopSession(null);
- /* "lttng view" also tests that Babeltrace is installed and working */
- List<String> contents = LttngSessionControl.viewSession(null);
- boolean ret3 = LttngSessionControl.destroySession(null);
- assumeTrue(ret1 && ret2 && ret3);
- assumeTrue(contents.isEmpty());
+ assumeTrue(TestUtils.checkForJulLibrary());
+ assumeTrue(TestUtils.checkForLttngTools(Domain.JUL));
}
@AfterClass
public static void julClassCleanup() {
- LttngSessionControl.deleteAllTracee();
+ LttngSession.deleteAllTracee();
}
@Before
loggerA.setLevel(Level.ALL);
loggerB.setLevel(Level.ALL);
+
+ session = new LttngSession(null, DOMAIN);
}
@After
public void tearDown() {
- /* In case the test fails before destroying the session */
- LttngSessionControl.tryDestroySession(null);
+ session.close();
LTTngAgent.dispose();
@Test
public void testNoEvents() {
- assertTrue(LttngSessionControl.setupSession(null, DOMAIN));
+ assertTrue(session.start());
- JulEnabledEventsTest.send10Events(loggerA);
- JulEnabledEventsTest.send10Events(loggerB);
+ JulTestUtils.send10EventsTo(loggerA);
+ JulTestUtils.send10EventsTo(loggerB);
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertTrue(output.isEmpty());
- assertTrue(LttngSessionControl.destroySession(null));
-
ILttngHandler handler = getAgentHandler();
assertEquals(0, handler.getEventCount());
}
@Test
public void testAllEvents() {
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, DOMAIN));
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.start());
- JulEnabledEventsTest.send10Events(loggerA);
- JulEnabledEventsTest.send10Events(loggerB);
+ JulTestUtils.send10EventsTo(loggerA);
+ JulTestUtils.send10EventsTo(loggerB);
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(20, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
ILttngHandler handler = getAgentHandler();
assertEquals(20, handler.getEventCount());
}
@Test
public void testSomeEvents() {
- assertTrue(LttngSessionControl.setupSession(null, DOMAIN,
- EVENT_NAME_A));
+ assertTrue(session.enableEvents(EVENT_NAME_A));
+ assertTrue(session.start());
- JulEnabledEventsTest.send10Events(loggerA);
- JulEnabledEventsTest.send10Events(loggerB);
+ JulTestUtils.send10EventsTo(loggerA);
+ JulTestUtils.send10EventsTo(loggerB);
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(10, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
ILttngHandler handler = getAgentHandler();
assertEquals(10, handler.getEventCount());
}
*
* @return The agent's JUL handler
*/
- private ILttngHandler getAgentHandler() {
+ private static ILttngHandler getAgentHandler() {
try {
Field julHandlerField = LTTngAgent.class.getDeclaredField("julHandler");
julHandlerField.setAccessible(true);
--- /dev/null
+package org.lttng.ust.agent.integration.jul;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class JulTestUtils {
+
+ JulTestUtils() {
+ }
+
+ static void send10EventsTo(Logger logger) {
+ String a = new String("a");
+ Object[] params = { a, new String("b"), new Object() };
+
+ // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING
+ logger.fine("A fine level message");
+ logger.finer("A finer level message");
+ logger.finest("A finest level message");
+ logger.info("A info level message");
+ logger.severe("A severe level message");
+ logger.warning("A warning level message");
+ logger.warning("Another warning level message");
+ logger.log(Level.WARNING, "A warning message using Logger.log()");
+ logger.log(Level.INFO, "A message with one parameter", a);
+ logger.log(Level.INFO, "A message with parameters", params);
+ }
+}
import static org.junit.Assume.assumeTrue;
import java.io.IOException;
-import java.util.List;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.junit.BeforeClass;
import org.lttng.ust.agent.integration.common.EnabledEventsTest;
import org.lttng.ust.agent.log4j.LttngLogAppender;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
+import org.lttng.ust.agent.utils.TestUtils;
public class Log4jEnabledEventsTest extends EnabledEventsTest {
@BeforeClass
public static void julClassSetup() {
/* Skip tests if we can't find the JNI library or lttng-tools */
- try {
- LttngLogAppender testHandler = new LttngLogAppender();
- testHandler.close();
- } catch (SecurityException | IOException e) {
- assumeTrue(false);
- }
-
- boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
- boolean ret2 = LttngSessionControl.stopSession(null);
- /* "lttng view" also tests that Babeltrace is installed and working */
- List<String> contents = LttngSessionControl.viewSession(null);
- boolean ret3 = LttngSessionControl.destroySession(null);
- assumeTrue(ret1 && ret2 && ret3);
- assumeTrue(contents.isEmpty());
+ assumeTrue(TestUtils.checkForLog4jLibrary());
+ assumeTrue(TestUtils.checkForLttngTools(Domain.LOG4J));
}
@AfterClass
public static void julClassCleanup() {
- LttngSessionControl.deleteAllTracee();
+ LttngSession.deleteAllTracee();
}
@Before
@Override
protected void sendEventsToLoggers() {
- send10Events(loggerA);
- send10Events(loggerB);
- send10Events(loggerC);
- send10Events(loggerD);
- }
-
- static void send10Events(Logger logger) {
- // Levels/priorities are DEBUG, ERROR, FATAL, INFO, TRACE, WARN
- logger.debug("Debug message. Lost among so many.");
- logger.debug("Debug message with a throwable", new IOException());
- logger.error("Error messsage. This might be bad.");
- logger.error("Error message with a throwable", new IOException());
- logger.fatal("A fatal message. You are already dead.");
- logger.info("A info message. Lol, who cares.");
- logger.trace("A trace message. No, no *that* trace");
- logger.warn("A warn message. Yellow underline.");
- logger.log(Level.DEBUG, "A debug message using .log()");
- logger.log(Level.ERROR, "A error message using .log()");
+ Log4jTestUtils.send10Events(loggerA);
+ Log4jTestUtils.send10Events(loggerB);
+ Log4jTestUtils.send10Events(loggerC);
+ Log4jTestUtils.send10Events(loggerD);
}
}
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
-import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import org.junit.Test;
import org.lttng.ust.agent.ILttngHandler;
import org.lttng.ust.agent.LTTngAgent;
-import org.lttng.ust.agent.log4j.LttngLogAppender;
-import org.lttng.ust.agent.utils.LttngSessionControl;
-import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
+import org.lttng.ust.agent.utils.LttngSession;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
+import org.lttng.ust.agent.utils.TestUtils;
@SuppressWarnings("deprecation")
public class Log4jLegacyApiTest {
private static final String EVENT_NAME_A = "EventA";
private static final String EVENT_NAME_B = "EventB";
+ private LttngSession session;
+
private Logger loggerA;
private Logger loggerB;
@BeforeClass
public static void classSetup() {
/* Skip tests if we can't find the JNI library or lttng-tools */
- try {
- LttngLogAppender testAppender = new LttngLogAppender();
- testAppender.close();
- } catch (SecurityException | IOException e) {
- assumeTrue(false);
- }
-
- boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN);
- boolean ret2 = LttngSessionControl.stopSession(null);
- /* "lttng view" also tests that Babeltrace is installed and working */
- List<String> contents = LttngSessionControl.viewSession(null);
- boolean ret3 = LttngSessionControl.destroySession(null);
- assumeTrue(ret1 && ret2 && ret3);
- assumeTrue(contents.isEmpty());
+ assumeTrue(TestUtils.checkForLog4jLibrary());
+ assumeTrue(TestUtils.checkForLttngTools(Domain.LOG4J));
}
@AfterClass
public static void classCleanup() {
- LttngSessionControl.deleteAllTracee();
+ LttngSession.deleteAllTracee();
}
@Before
loggerA.setLevel(Level.ALL);
loggerB.setLevel(Level.ALL);
+
+ session = new LttngSession(null, DOMAIN);
}
@After
public void tearDown() {
- /* In case the test fails before destroying the session */
- LttngSessionControl.tryDestroySession(null);
+ session.close();
LTTngAgent.dispose();
@Test
public void testNoEvents() {
- assertTrue(LttngSessionControl.setupSession(null, DOMAIN));
+ assertTrue(session.start());
- Log4jEnabledEventsTest.send10Events(loggerA);
- Log4jEnabledEventsTest.send10Events(loggerB);
+ Log4jTestUtils.send10Events(loggerA);
+ Log4jTestUtils.send10Events(loggerB);
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertTrue(output.isEmpty());
- assertTrue(LttngSessionControl.destroySession(null));
-
ILttngHandler handler = getAgentHandler();
assertEquals(0, handler.getEventCount());
}
@Test
public void testAllEvents() {
- assertTrue(LttngSessionControl.setupSessionAllEvents(null, DOMAIN));
+ assertTrue(session.enableAllEvents());
+ assertTrue(session.start());
- Log4jEnabledEventsTest.send10Events(loggerA);
- Log4jEnabledEventsTest.send10Events(loggerB);
+ Log4jTestUtils.send10Events(loggerA);
+ Log4jTestUtils.send10Events(loggerB);
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(20, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
ILttngHandler handler = getAgentHandler();
assertEquals(20, handler.getEventCount());
}
@Test
public void testSomeEvents() {
- assertTrue(LttngSessionControl.setupSession(null, DOMAIN,
- EVENT_NAME_A));
+ assertTrue(session.enableEvents(EVENT_NAME_A));
+ assertTrue(session.start());
- Log4jEnabledEventsTest.send10Events(loggerA);
- Log4jEnabledEventsTest.send10Events(loggerB);
+ Log4jTestUtils.send10Events(loggerA);
+ Log4jTestUtils.send10Events(loggerB);
- assertTrue(LttngSessionControl.stopSession(null));
+ assertTrue(session.stop());
- List<String> output = LttngSessionControl.viewSession(null);
+ List<String> output = session.view();
assertNotNull(output);
assertEquals(10, output.size());
- assertTrue(LttngSessionControl.destroySession(null));
-
ILttngHandler handler = getAgentHandler();
assertEquals(10, handler.getEventCount());
}
*
* @return The agent's Log4j handler
*/
- private ILttngHandler getAgentHandler() {
+ private static ILttngHandler getAgentHandler() {
try {
Field log4jAppenderField = LTTngAgent.class.getDeclaredField("log4jAppender");
log4jAppenderField.setAccessible(true);
--- /dev/null
+package org.lttng.ust.agent.integration.log4j;
+
+import java.io.IOException;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+final class Log4jTestUtils {
+
+ private Log4jTestUtils() {
+ }
+
+ static void send10Events(Logger logger) {
+ // Levels/priorities are DEBUG, ERROR, FATAL, INFO, TRACE, WARN
+ logger.debug("Debug message. Lost among so many.");
+ logger.debug("Debug message with a throwable", new IOException());
+ logger.error("Error messsage. This might be bad.");
+ logger.error("Error message with a throwable", new IOException());
+ logger.fatal("A fatal message. You are already dead.");
+ logger.info("A info message. Lol, who cares.");
+ logger.trace("A trace message. No, no *that* trace");
+ logger.warn("A warn message. Yellow underline.");
+ logger.log(Level.DEBUG, "A debug message using .log()");
+ logger.log(Level.ERROR, "A error message using .log()");
+ }
+}
--- /dev/null
+package org.lttng.ust.agent.utils;
+
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+public class LttngSession implements AutoCloseable {
+
+ public enum Domain {
+ JUL("-j"),
+ LOG4J("-l");
+
+ private final String flag;
+
+ private Domain(String flag) {
+ this.flag = flag;
+ }
+
+ public String flag() {
+ return flag;
+ }
+ }
+
+ private final String sessionName;
+ private final Domain domain;
+
+ private volatile boolean channelCreated = false;
+
+ public LttngSession(String sessionName, Domain domain) {
+ if (sessionName != null) {
+ this.sessionName = sessionName;
+ } else {
+ this.sessionName = UUID.randomUUID().toString();
+ }
+ this.domain = domain;
+
+ /* Create the session in LTTng */
+ executeCommand(Arrays.asList("lttng", "create", this.sessionName));
+ }
+
+ @Override
+ public void close() {
+ /* Destroy the session */
+ executeCommand(Arrays.asList("lttng", "destroy", sessionName));
+ // FIXME also delete the trace we generated ?
+ }
+
+ // ------------------------------------------------------------------------
+ // Public methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Enable all events in the given session (enable-event -a)
+ *
+ * @return If the command executed successfully (return code = 0).
+ */
+ public boolean enableAllEvents() {
+ channelCreated = true;
+ return executeCommand(Arrays.asList(
+ "lttng", "enable-event", domain.flag(), "-a", "-s", sessionName));
+ }
+
+ /**
+ * Enable individual event(s).
+ *
+ * @param enabledEvents
+ * The list of events to enable. Should not be null or empty
+ * @return If the command executed successfully (return code = 0).
+ */
+ public boolean enableEvents(String... enabledEvents) {
+ if (enabledEvents == null || enabledEvents.length == 0) {
+ throw new IllegalArgumentException();
+ }
+ channelCreated = true;
+ return executeCommand(Arrays.asList(
+ "lttng", "enable-event", domain.flag(),
+ Arrays.stream(enabledEvents).collect(Collectors.joining(",")),
+ "-s", sessionName));
+ }
+
+ /**
+ * Send a disable-event command. Used to disable events that were previously
+ * enabled.
+ *
+ * @param disabledEvents
+ * The list of disabled events. Should not be null or empty
+ * @return If the command executed successfully (return code = 0).
+ */
+ public boolean disableEvents(String... disabledEvents) {
+ if (disabledEvents == null || disabledEvents.length == 0) {
+ throw new IllegalArgumentException();
+ }
+ return executeCommand(Arrays.asList(
+ "lttng", "disable-event", domain.flag(),
+ Arrays.stream(disabledEvents).collect(Collectors.joining(",")),
+ "-s", sessionName));
+ }
+
+ public boolean start() {
+ /*
+ * We have to enable a channel for 'lttng start' to work. However, we
+ * cannot enable a channel directly, see
+ * https://bugs.lttng.org/issues/894 . Instead we will enable an event
+ * we know does not exist
+ */
+ if (!channelCreated) {
+ enableEvents("non-event");
+ }
+ return executeCommand(Arrays.asList("lttng", "start", sessionName));
+ }
+
+ /**
+ * Stop the tracing session
+ *
+ * @return If the command executed successfully (return code = 0).
+ */
+ public boolean stop() {
+ return executeCommand(Arrays.asList("lttng", "stop", sessionName));
+ }
+
+ /**
+ * Issue a "lttng view" command on the session, and returns its output. This
+ * effectively returns the current content of the trace in text form.
+ *
+ * @return The output of Babeltrace on the session's current trace
+ */
+ public List<String> view() {
+ return TestUtils.getOutputFromCommand(Arrays.asList("lttng", "view", sessionName));
+ }
+
+ /**
+ * Outside of the scope of lttng-tools, but this utility method can be used
+ * to delete all traces currently under ~/lttng-traces/. This can be used by
+ * tests to cleanup a trace they have created.
+ *
+ * @return True if the command completes successfully, false if there was an
+ * error.
+ */
+ public static boolean deleteAllTracee() {
+ String tracesDir = new String(System.getProperty("user.home") + "/lttng-traces/");
+ return deleteDirectory(Paths.get(tracesDir));
+ }
+
+ // ------------------------------------------------------------------------
+ // Private helper methods
+ // ------------------------------------------------------------------------
+
+ private static boolean deleteDirectory(Path directory) {
+ try {
+ Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ } catch (IOException e) {
+ /* At least we tried... */
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Just to test the environment / stdout are working correctly
+ */
+ public static void main(String[] args) {
+ List<String> command = Arrays.asList("ls", "-l");
+ executeCommand(command);
+ }
+
+ private static boolean executeCommand(List<String> command) {
+ try {
+ ProcessBuilder builder = new ProcessBuilder(command);
+ builder.redirectErrorStream(true);
+ builder.redirectOutput(Redirect.INHERIT);
+
+ Process p = builder.start();
+ int ret = p.waitFor();
+ return (ret == 0);
+
+ } catch (IOException | InterruptedException e) {
+ return false;
+ }
+ }
+}
+++ /dev/null
-package org.lttng.ust.agent.utils;
-
-import java.io.IOException;
-import java.lang.ProcessBuilder.Redirect;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public final class LttngSessionControl {
-
- private LttngSessionControl() {}
-
- public enum Domain {
- JUL("-j"),
- LOG4J("-l");
-
- private final String flag;
-
- private Domain(String flag) {
- this.flag = flag;
- }
-
- public String flag() {
- return flag;
- }
- }
-
- // ------------------------------------------------------------------------
- // Public utility methods
- // ------------------------------------------------------------------------
-
- /**
- * Setup a LTTng session by enabling certain events (or none).
- *
- * @param sessionName
- * The name of the session to create. May be null to use the
- * default one from lttng-tools.
- * @param domain
- * The tracing domain
- * @param enabledEvents
- * The list of events to enable. May be null or empty, to not
- * enable any events.
- * @return If the command executed successfully (return code = 0).
- */
- public static boolean setupSession(String sessionName, Domain domain, String... enabledEvents) {
- String[] createCommand = (sessionName == null ?
- new String[] { "lttng", "create" } :
- new String[] { "lttng", "create", sessionName}
- );
-
- String eventsToEnable = (enabledEvents == null || enabledEvents.length == 0 ?
- /*
- * We have to enable a channel for 'lttng start' to work.
- * However, we cannot enable a channel directly, see
- * https://bugs.lttng.org/issues/894 . Instead we will enable an
- * event we know does not exist
- */
- "non-event" :
- Arrays.stream(enabledEvents).collect(Collectors.joining(","))
- );
-
- return executeCommands(new String[][] {
- createCommand,
- { "lttng", "enable-event", domain.flag(), eventsToEnable},
- { "lttng", "start" }
- });
- }
-
- /**
- * Setup a LTTng session with all events enabled (lttng enable-event -a).
- *
- * @param sessionName
- * The name of the session to create. May be null to use the
- * default one from lttng-tools.
- * @param domain
- * The tracing domain
- * @return If the command executed successfully (return code = 0).
- */
- public static boolean setupSessionAllEvents(String sessionName, Domain domain) {
- String[] createCommand = (sessionName == null ?
- new String[] { "lttng", "create" } :
- new String[] { "lttng", "create", sessionName}
- );
-
- return executeCommands(new String[][] {
- createCommand,
- { "lttng", "enable-event", domain.flag(), "-a" },
- { "lttng", "start" }
- });
- }
-
- /**
- * Send a separate enable-event command.
- *
- * @param sessionName
- * Name of the session in which to enable events. Use null for
- * current session.
- * @param domain
- * The tracing domain
- * @param enabledEvents
- * The list of events to enable. Should not be null or empty
- * @return If the command executed successfully (return code = 0).
- */
- public static boolean enableEvents(String sessionName, Domain domain, String... enabledEvents) {
- if (enabledEvents == null || enabledEvents.length == 0) {
- throw new IllegalArgumentException();
- }
- List<String> command = new ArrayList<String>();
- command.add("lttng");
- command.add("enable-event");
- command.add(domain.flag());
- command.add(Arrays.stream(enabledEvents).collect(Collectors.joining(",")));
- if (sessionName != null) {
- command.add("-s");
- command.add(sessionName);
- }
- return executeCommand(command.toArray(new String[0]));
- }
-
- /**
- * Send a disable-event command. Used to disable events that were previously
- * enabled.
- *
- * @param sessionName
- * Name of the session in which to disable events. Use null for
- * current session.
- * @param domain
- * The tracing domain
- * @param disabledEvents
- * The list of disabled events. Should not be null or empty
- * @return If the command executed successfully (return code = 0).
- */
- public static boolean disableEvents(String sessionName, Domain domain, String... disabledEvents) {
- if (disabledEvents == null || disabledEvents.length == 0) {
- throw new IllegalArgumentException();
- }
- List<String> command = new ArrayList<String>();
- command.add("lttng");
- command.add("disable-event");
- command.add(domain.flag());
- command.add(Arrays.stream(disabledEvents).collect(Collectors.joining(",")));
- if (sessionName != null) {
- command.add("-s");
- command.add(sessionName);
- }
- return executeCommand(command.toArray(new String[0]));
- }
-
- /**
- * Stop the current tracing session
- *
- * @param sessionName
- * The name of the session to stop. Use null for the current
- * session.
- * @return If the command executed successfully (return code = 0).
- */
- public static boolean stopSession(String sessionName) {
- List<String> command = new ArrayList<String>();
- command.add("lttng");
- command.add("stop");
- if (sessionName != null) {
- command.add(sessionName);
- }
- return executeCommand(command.toArray(new String[0]));
- }
-
- /**
- * Issue a "lttng view" command on the provided session, and returns its
- * output. This effectively returns the current content of the trace in text
- * form.
- *
- * @param sessionName
- * The name of the session to print. Use null for the current
- * session.
- * @return The output of Babeltrace on the session's current trace
- */
- public static List<String> viewSession(String sessionName) {
- List<String> command = new ArrayList<String>();
- command.add("lttng");
- command.add("view");
- if (sessionName != null) {
- command.add(sessionName);
- }
- return getOutputFromCommand(command.toArray(new String[0]));
- }
-
- /**
- * Destroy the current tracing session
- *
- * @param sessionName
- * The name of the session to destroy. Use null for the current
- * session.
- * @return If the command executed successfully (return code = 0).
- */
- public static boolean destroySession(String sessionName) {
- List<String> command = new ArrayList<String>();
- command.add("lttng");
- command.add("destroy");
- if (sessionName != null) {
- command.add(sessionName);
- }
- return executeCommand(command.toArray(new String[0]));
- }
-
- /**
- * Try destroying the given tracing session, fail silently if there is no
- * session.
- *
- * @param sessionName
- * The name of the session to destroy. Use null for the current
- * session.
- */
- public static void tryDestroySession(String sessionName) {
- getOutputFromCommand(false, new String[] { "lttng", "destroy" });
- }
-
- /**
- * Outside of the scope of lttng-tools, but this utility method can be used
- * to delete all traces currently under ~/lttng-traces/. This can be used by
- * tests to cleanup a trace they have created.
- *
- * @return True if the command completes successfully, false if there was an
- * error.
- */
- public static boolean deleteAllTracee() {
- String tracesDir = new String(System.getProperty("user.home") + "/lttng-traces/");
- return deleteDirectory(Paths.get(tracesDir));
- }
-
- private static boolean deleteDirectory(Path directory) {
- try {
- Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
- Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
- });
- } catch (IOException e) {
- /* At least we tried... */
- return false;
- }
- return true;
- }
-
- // ------------------------------------------------------------------------
- // Private helper methods
- // ------------------------------------------------------------------------
-
- private static boolean executeCommands(String [][] commands) {
- for (String[] command : commands) {
- if (executeCommand(command) == false) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Just to test the environment / stdout are working correctly
- */
- public static void main(String[] args) {
- executeCommand(new String[] {"ls", "-l"});
- }
-
- private static boolean executeCommand(String[] command) {
- try {
- ProcessBuilder builder = new ProcessBuilder(command);
- builder.redirectErrorStream(true);
- builder.redirectOutput(Redirect.INHERIT);
-
- Process p = builder.start();
- int ret = p.waitFor();
- return (ret == 0);
-
- } catch (IOException | InterruptedException e) {
- return false;
- }
- }
-
- private static List<String> getOutputFromCommand(String[] command) {
- return getOutputFromCommand(true, command);
- }
-
- private static List<String> getOutputFromCommand(boolean print, String[] command) {
- try {
- Path tempFile = Files.createTempFile("test-output", null);
-
- ProcessBuilder builder = new ProcessBuilder(command);
- builder.redirectErrorStream(true);
- builder.redirectOutput(Redirect.to(tempFile.toFile()));
-
- Process p = builder.start();
- p.waitFor();
-
- List<String> lines = Files.readAllLines(tempFile);
- Files.delete(tempFile);
-
- if (print) {
- /* Also print the output to the console */
- lines.stream().forEach(s -> System.out.println(s));
- }
-
- return lines;
-
- } catch (IOException | InterruptedException e) {
- return null;
- }
- }
-}
--- /dev/null
+package org.lttng.ust.agent.utils;
+
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+
+import org.lttng.ust.agent.jul.LttngLogHandler;
+import org.lttng.ust.agent.log4j.LttngLogAppender;
+import org.lttng.ust.agent.utils.LttngSession.Domain;
+
+/**
+ * Utility methods to help with UST-Java tests
+ */
+public final class TestUtils {
+
+ private TestUtils() {}
+
+ /**
+ * Check the the JUL native library is available, effectively allowing LTTng
+ * JUL handlers to be used.
+ *
+ * @return True if JUL works fine, false if it does not.
+ */
+ public static boolean checkForJulLibrary() {
+ try {
+ LttngLogHandler testHandler = new LttngLogHandler();
+ testHandler.close();
+ } catch (SecurityException | IOException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Check the the Log4j native library is available, effectively allowing
+ * LTTng Log4j appenders to be used.
+ *
+ * @return True if Log4j works fine, false if it does not.
+ */
+ public static boolean checkForLog4jLibrary() {
+ try {
+ LttngLogAppender testAppender = new LttngLogAppender();
+ testAppender.close();
+ } catch (SecurityException | IOException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Check that lttng-tools and babeltrace are installed on the system and
+ * working.
+ *
+ * @param domain
+ * The tracing domain to test for (we will try to setup a session
+ * with this domain)
+ * @return True if the environment should allow tracing fine, false if there
+ * was an error
+ */
+ public static boolean checkForLttngTools(Domain domain) {
+ try (LttngSession session = new LttngSession(null, domain)) {
+ boolean ret1 = session.enableAllEvents();
+ boolean ret2 = session.start();
+ boolean ret3 = session.stop();
+ /*
+ * "lttng view" also tests that Babeltrace is installed and working
+ */
+ List<String> contents = session.view();
+ return (ret1 && ret2 && ret3 && contents.isEmpty());
+ }
+ }
+
+ public static boolean checkForUserSessiond() {
+ String userName = System.getProperty("user.name");
+
+ /* The user name is truncated to 7 characters in "ps" */
+ String shortUserName = userName.substring(0, Math.min(userName.length(), 7));
+
+ List<String> command = Arrays.asList("ps", "-e", "u");
+ List<String> output = getOutputFromCommand(false, command);
+ return output.stream()
+ .filter(s -> s.contains("lttng-sessiond"))
+ .anyMatch(s -> s.startsWith(shortUserName));
+ }
+
+ public static boolean checkForRootSessiond() {
+ List<String> command = Arrays.asList("ps", "-e", "u");
+ List<String> output = getOutputFromCommand(false, command);
+ return output.stream()
+ .filter(s -> s.contains("lttng-sessiond"))
+ .anyMatch(s -> s.startsWith("root"));
+ }
+
+
+ static List<String> getOutputFromCommand(List<String> command) {
+ return TestUtils.getOutputFromCommand(true, command);
+ }
+
+ static List<String> getOutputFromCommand(boolean print, List<String> command) {
+ try {
+ Path tempFile = Files.createTempFile("test-output", null);
+
+ ProcessBuilder builder = new ProcessBuilder(command);
+ builder.redirectErrorStream(true);
+ builder.redirectOutput(Redirect.to(tempFile.toFile()));
+
+ Process p = builder.start();
+ p.waitFor();
+
+ List<String> lines = Files.readAllLines(tempFile);
+ Files.delete(tempFile);
+
+ if (print) {
+ /* Also print the output to the console */
+ lines.stream().forEach(s -> System.out.println(s));
+ }
+
+ return lines;
+
+ } catch (IOException | InterruptedException e) {
+ return null;
+ }
+ }
+}