package org.eclipse.linuxtools.lttng2.ui.tests.control.service;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.net.URL;
import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory;
import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlService;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;
private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable";
private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1";
private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist";
+ private static final String SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE = "GetSessionNameNotExistVerbose";
private static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut";
private static final String SCEN_GET_SESSION1 = "GetSession1";
private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1";
private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1";
private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2";
+ private static final String SCEN_LIST_WITH_NO_KERNEL_VERBOSE = "ListWithNoKernelVerbose";
private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1";
private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2";
private static final String SCEN_GET_UST_PROVIDER3 = "GetUstProvider3";
private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt";
private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants";
private static final String SCEN_DESTROY_SESSION1 = "DestroySession1";
+ private static final String SCEN_DESTROY_SESSION_VERBOSE = "DestroySessionVerbose";
private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling";
private static final String SCEN_EVENT_HANDLING = "EventHandling";
private static final String SCEN_CONTEXT_HANDLING = "ContextHandling";
private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling";
private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
private static final String SCEN_CREATE_SESSION_2_1 = "CreateSessionLttng2.1";
+ private static final String SCEN_CREATE_SESSION_VERBOSE_2_1 = "CreateSessionLttngVerbose2.1";
// ------------------------------------------------------------------------
// Test data
fShell = fShellFactory.getFileShell();
fShell.loadScenarioFile(fTestfile);
fService = new LTTngControlService(fShell);
+
+ ControlPreferences.getInstance().init(Activator.getDefault().getPreferenceStore());
+ }
+
+ @After
+ public void tearDown() {
+ disableVerbose();
+ ControlPreferences.getInstance().dispose();
}
// ------------------------------------------------------------------------
}
}
+ @Test
+ public void testGetSessionNotExistVerbose() {
+ try {
+ enableVerbose();
+ fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE);
+ fService.getSessionNames(new NullProgressMonitor());
+ fail("No exeption thrown");
+
+ } catch (ExecutionException e) {
+ // success
+ } finally {
+ disableVerbose();
+ }
+ }
+
@Test
public void testGetSessionNameGarbage() {
try {
}
}
+ @Test
+ public void testGetKernelProviderNoKernelVerbose() {
+ try {
+ enableVerbose();
+ fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE);
+ List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
+
+ // Verify event info
+ assertNotNull(events);
+ assertEquals(0, events.size());
+
+ } catch (ExecutionException e) {
+ fail(e.toString());
+ } finally {
+ disableVerbose();
+ }
+ }
+
@Test
public void testGetUstProvider() {
try {
}
}
+ @Test
+ public void testDestroySessionVerbose() {
+ try {
+ enableVerbose();
+ fShell.setScenario(SCEN_DESTROY_SESSION_VERBOSE);
+ fService.destroySession("mysession2", new NullProgressMonitor());
+ } catch (ExecutionException e) {
+ fail(e.toString());
+ } finally {
+ disableVerbose();
+ }
+ }
+
@Test
public void testCreateChannel() {
try {
}
}
-// public void tesEnableChannelNoTracer() {
-// try {
-// ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer());
-// service.getSessionNames(new NullProgressMonitor());
-// fail("No exeption thrown");
-//
-// } catch (ExecutionException e) {
-// // success
-// }
-// }
-
@Test
public void testEnableEvents() {
try {
assertNotNull(info);
assertEquals("mysession", info.getName());
assertEquals("file:///tmp", info.getSessionPath());
- assertTrue(info.isStreamedTrace());
+ assertTrue(!info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
info = fService.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
assertNotNull(info);
assertEquals("mysession", info.getName());
assertEquals("file:///tmp", info.getSessionPath());
- assertTrue(info.isStreamedTrace());
+ assertTrue(!info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
info = fService.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
assertNotNull(info);
assertEquals("mysession", info.getName());
- assertEquals("", info.getSessionPath()); // TODO: currently there is a bug in LTTng tracer and it returns string null
+ assertEquals("", info.getSessionPath()); // the complete network path is not available at this point
assertTrue(info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
assertTrue(info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
+ // verbose
+ enableVerbose();
+ info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+ assertNotNull(info);
+ assertEquals("mysession", info.getName());
+ assertEquals("net://172.0.0.1", info.getSessionPath());
+ assertTrue(info.isStreamedTrace());
+ disableVerbose();
+ fService.destroySession("mysession", new NullProgressMonitor());
+
+
+ } catch (ExecutionException e) {
+ fail(e.toString());
+ }
+ }
+
+ @Test
+ public void testCreateSessionVerbose2_1() {
+ try {
+ fShell.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1);
+
+ enableVerbose();
+ ISessionInfo info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+ assertNotNull(info);
+ assertEquals("mysession", info.getName());
+ assertEquals("net://172.0.0.1", info.getSessionPath());
+ assertTrue(info.isStreamedTrace());
+ fService.destroySession("mysession", new NullProgressMonitor());
} catch (ExecutionException e) {
fail(e.toString());
+ } finally {
+ disableVerbose();
}
}
+
+ private static void enableVerbose() {
+ // verbose
+ ControlCommandLogger.init(ControlPreferences.getInstance().getLogfilePath(), false);
+ ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, true);
+ ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_PREF, ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE);
+ }
+
+ private static void disableVerbose() {
+ ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, false);
+ }
+
+
}
</COMMAND_OUTPUT>
</SCENARIO>
+####################################################################
+# Scenario: Test lttng -vvv list <name> where session doesn't exist
+####################################################################
+<SCENARIO>
+GetSessionNameNotExistVerbose
+<COMMAND_INPUT>
+lttng -vvv list test
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+1
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Session name: test [in cmd_list() at commands/list.c:618]
+DEBUG1: Session count 1 [in list_sessions() at commands/list.c:485]
+Error: Session 'test' not found
+Error: Command error
+DEBUG1: Clean exit [in clean_exit() at lttng.c:165]
+</COMMAND_OUTPUT>
+</SCENARIO>
+
####################################################################
# Scenario: Test lttng list with garbage output
####################################################################
</COMMAND_OUTPUT>
</SCENARIO>
+####################################################################
+# Scenario: Test "lttng list -k" with no kernel, with session daemon and verbose
+####################################################################
+<SCENARIO>
+ListWithNoKernelVerbose
+<COMMAND_INPUT>
+lttng -vvv list -k
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+1
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Session name: (null) [in cmd_list() at commands/list.c:618]
+DEBUG1: Getting kernel tracing events [in list_kernel_events() at commands/list.c:309]
+Error: Unable to list kernel events
+DEBUG1: Clean exit [in clean_exit() at lttng.c:165]
+</COMMAND_OUTPUT>
+</SCENARIO>
+
####################################################################
# Scenario: Test "lttng list -u" with sample output
####################################################################
</COMMAND_OUTPUT>
</SCENARIO>
+####################################################################
+# Scenario: Test "lttng -vvv destroy <session>"
+####################################################################
+
+<SCENARIO>
+DestroySessionVerbose
+<COMMAND_INPUT>
+lttng -vvv destroy mysession2
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Config file path found: /home/eedbhu [in get_session_name() at utils.c:98]
+DEBUG1: Session name found: mysession2 [in get_session_name() at utils.c:99]
+Session mysession2 destroyed at /home/eedbhu
+</COMMAND_OUTPUT>
+</SCENARIO>
+
+
####################################################################
# Scenario: Test "lttng enable-channel ..." with different inputs
####################################################################
Session mysession destroyed.
</COMMAND_OUTPUT>
+<COMMAND_INPUT>
+lttng -vvv create mysession -U net://172.0.0.1
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG3: URI string: net://172.0.0.1 [in uri_parse() at uri.c:253]
+DEBUG2: IP address resolved to 172.0.0.1 [in set_ip_address() at uri.c:132]
+DEBUG3: URI dtype: 1, proto: 1, host: 172.0.0.1, subdir: , ctrl: 0, data: 0 [in uri_parse() at uri.c:467]
+DEBUG1: LSM cmd type : 8 [in send_session_msg() at lttng-ctl.c:261]
+Session mysession created.
+Traces will be written in net://172.0.0.1
+DEBUG1: Init config session in /home/bernd [in config_init() at conf.c:294]
+</COMMAND_OUTPUT>
+
</SCENARIO>
+
+####################################################################
+# Scenario: Test "lttng -vvv create <session> with LTTng 2.1 options"
+####################################################################
+<SCENARIO>
+CreateSessionLttngVerbose2.1
+<COMMAND_INPUT>
+lttng -vvv create mysession -U net://172.0.0.1
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG3: URI string: net://172.0.0.1 [in uri_parse() at uri.c:253]
+DEBUG2: IP address resolved to 172.0.0.1 [in set_ip_address() at uri.c:132]
+DEBUG3: URI dtype: 1, proto: 1, host: 172.0.0.1, subdir: , ctrl: 0, data: 0 [in uri_parse() at uri.c:467]
+DEBUG1: LSM cmd type : 8 [in send_session_msg() at lttng-ctl.c:261]
+Session mysession created.
+Traces will be written in net://172.0.0.1
+DEBUG1: Init config session in /home/bernd [in config_init() at conf.c:294]
+</COMMAND_OUTPUT>
+
+<COMMAND_INPUT>
+lttng -vvv destroy mysession
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+Session mysession destroyed.
+</COMMAND_OUTPUT>
+
+</SCENARIO>
\ No newline at end of file
// or:
// Error: Unable to list kernel events
//
-
- if ((result.getOutput().length > 0) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[0]).matches()) ||
- ((result.getOutput().length > 1) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[1]).matches()))) {
- return events;
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return events;
+ }
+ index++;
}
}
//Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
String[] output = result.getOutput();
- // Get and verify session name
- Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+ // Get and session name and path
String name = null;
+ String path = null;
- if (matcher.matches()) {
- name = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+ Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+ if (nameMatcher.matches()) {
+ name = String.valueOf(nameMatcher.group(1).trim());
+ } else if (pathMatcher.matches()) {
+ path = String.valueOf(pathMatcher.group(1).trim());
+ }
+ index++;
}
+ // Verify session name
if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
// Unexpected name returned
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
SessionInfo sessionInfo = new SessionInfo(name);
- // Get and verify session path
- matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
- String path = null;
-
- if (matcher.matches()) {
- path = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
- }
-
+ // Verify session path
if ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath)))) {
// Unexpected path
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
}
+
sessionInfo.setSessionPath(path);
return sessionInfo;
ICommandResult result = executeCommand(command.toString(), monitor);
- //Session myssession2 created.
- //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
+ // Verify output
String[] output = result.getOutput();
- // Get and verify session name
- Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+ // Get and session name and path
String name = null;
+ String path = null;
- if (matcher.matches()) {
- name = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+ Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+
+ if (nameMatcher.matches()) {
+ name = String.valueOf(nameMatcher.group(1).trim());
+ } else if (pathMatcher.matches() && (networkUrl != null)) {
+ path = String.valueOf(pathMatcher.group(1).trim());
+ }
+ index++;
+ }
+
+ // Verify session name
+ if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
+ // Unexpected name returned
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
+ Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$
}
- // Get and verify session path
- matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
- String path = null;
SessionInfo sessionInfo = new SessionInfo(name);
- if (networkUrl != null) {
- if (matcher.matches()) {
- path = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
- }
+ sessionInfo.setStreamedTrace(true);
+
+ // Verify session path
+ if (networkUrl != null) {
if (path == null) {
// Unexpected path
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
}
+
sessionInfo.setSessionPath(path);
+
+ // Check file protocol
+ Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path);
+ if (matcher.matches()) {
+ sessionInfo.setStreamedTrace(false);
+ }
}
- sessionInfo.setStreamedTrace(true);
+ // When using controlUrl and dataUrl the full session path is not known yet
+ // and will be set later on when listing the session
return sessionInfo;
}
ICommandResult result = executeCommand(command.toString(), monitor, false);
String[] output = result.getOutput();
- if (isError(result) && ((output == null) || (!LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) {
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ boolean isError = isError(result);
+ if (isError && (output != null)) {
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher matcher = LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ // Don't treat this as an error
+ isError = false;
+ }
+ index++;
+ }
+ }
+
+ if (isError) {
+ throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
//Session <sessionName> destroyed
}
* @return true if error else false
*/
protected boolean isError(ICommandResult result) {
- if ((result.getResult()) != 0 || (result.getOutput().length < 1 || LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+ // Check return code and length of returned strings
+ if ((result.getResult()) != 0 || (result.getOutput().length < 1)) {
return true;
}
+
+ // Look for error pattern
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return true;
+ }
+ index++;
+ }
+
return false;
}
* Pattern to match session path for network tracing (lttng list <session>)
* Note: file for protocol is not considered as network trace since local consumer will be used.
*/
- public final static Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net6|tcp|tcp6|)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+ public final static Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net6|tcp|tcp6)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+ /**
+ * Sub-pattern to pattern TRACE_NETWORK_PATH_PATTERN to match file protocol
+ */
+ public final static Pattern TRACE_FILE_PROTOCOL_PATTERN = Pattern.compile("(file)\\:\\/\\/(.*)"); //$NON-NLS-1$
/**
* Pattern to match for kernel domain information (lttng list <session>)
*/
/**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012. 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
ControlCommandLogger.log(LTTngControlService.formatOutput(result));
}
- if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1) && (!LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+ if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1)) {
int index = 0;
while (index < result.getOutput().length) {
String line = result.getOutput()[index];