lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / service / LTTngControlServiceTest.java
index 6da6753e2871aeb03bc8095d08f25e60df6292bb..aebad3bc5673ed8c0dfba79136fa232c2b48d351 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,9 +8,16 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Alexandre Montplaisir - Port to JUnit4
  **********************************************************************/
+
 package org.eclipse.linuxtools.lttng2.ui.tests.control.service;
 
+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 java.util.ArrayList;
@@ -18,8 +25,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import junit.framework.TestCase;
-
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.NullProgressMonitor;
@@ -28,25 +33,37 @@ import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISnapshotInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BufferType;
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
 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;
+
 /**
- * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link  LTTngControlService}</code>.
+ * The class <code>LTTngControlServiceTest</code> contains test for the class
+ * <code>{@link  LTTngControlService}</code>.
  */
-@SuppressWarnings({"nls", "javadoc"})
-public class LTTngControlServiceTest extends TestCase {
+@SuppressWarnings("javadoc")
+public class LTTngControlServiceTest {
 
     private static final String DIRECTORY   = "testfiles";
     private static final String TEST_STREAM = "LTTngServiceTest.cfg";
@@ -59,46 +76,57 @@ public class LTTngControlServiceTest extends TestCase {
     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_LIST_WITH_NO_UST1 = "ListWithNoUst1";
+    private static final String SCEN_LIST_WITH_NO_UST2 = "ListWithNoUst2";
+    private static final String SCEN_LIST_WITH_NO_UST3 = "ListWithNoUst3";
+    private static final String SCEN_LIST_WITH_NO_UST_VERBOSE = "ListWithNoUstVerbose";
     private static final String SCEN_CREATE_SESSION1 = "CreateSession1";
     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";
+    private static final String SCEN_CREATE_SNAPSHOT_SESSION = "CreateSessionSnapshot";
+    private static final String SCEN_CREATE_STREAMED_SNAPSHOT_SESSION = "CreateSessionStreamedSnapshot";
+    private static final String SCEN_CREATE_SNAPSHOT_SESSION_ERRORS = "CreateSessionSnapshotErrors";
 
     // ------------------------------------------------------------------------
     // Test data
     // ------------------------------------------------------------------------
+
     private CommandShellFactory fShellFactory;
     private String fTestfile;
     private LTTngToolsFileShell fShell;
     private ILttngControlService fService;
 
-
-   // ------------------------------------------------------------------------
-    // Static methods
-    // ------------------------------------------------------------------------
-
     // ------------------------------------------------------------------------
     // Housekeeping
     // ------------------------------------------------------------------------
+
     /**
      * Perform pre-test initialization.
      *
-     * @throws Exception if the initialization fails for some reason
-     *
+     * @throws Exception
+     *             if the initialization fails for some reason
      */
-    @Override
+    @Before
     public void setUp() throws Exception {
-        super.setUp();
         fShellFactory = CommandShellFactory.getInstance();
 
         URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
@@ -108,33 +136,33 @@ public class LTTngControlServiceTest extends TestCase {
         fShell = fShellFactory.getFileShell();
         fShell.loadScenarioFile(fTestfile);
         fService = new LTTngControlService(fShell);
+
+        ControlPreferences.getInstance().init(Activator.getDefault().getPreferenceStore());
     }
 
-    /**
-     * Perform post-test clean-up.
-     *
-     * @throws Exception if the clean-up fails for some reason
-     *
-     */
-    @Override
-    public void tearDown() throws Exception {
+    @After
+    public void tearDown() {
+        disableVerbose();
+        ControlPreferences.getInstance().dispose();
     }
 
     // ------------------------------------------------------------------------
     // Test Cases
     // ------------------------------------------------------------------------
 
+    @Test
     public void testVersion() {
         try {
             fShell.setScenario(SCEN_LTTNG_VERSION);
             ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
             assertNotNull(service);
-            assertEquals("2.0.0", service.getVersion());
+            assertEquals("2.1.0", service.getVersion());
         } catch (ExecutionException e) {
             fail("Exeption thrown " + e);
         }
     }
 
+    @Test
     public void testVersionWithPrompt() {
         try {
             fShell.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT);
@@ -145,7 +173,8 @@ public class LTTngControlServiceTest extends TestCase {
             fail("Exeption thrown " + e);
         }
     }
-    
+
+    @Test
     public void testUnsupportedVersion() {
         try {
             fShell.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION);
@@ -156,6 +185,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testNoVersion() {
         try {
             fShell.setScenario(SCEN_LTTNG_NO_VERSION);
@@ -166,6 +196,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testLttngNotInstalled() {
         try {
             fShell.setScenario(SCEN_LTTNG_NOT_INSTALLED);
@@ -176,6 +207,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testGetSessionNames1() {
         try {
             fShell.setScenario(SCEN_NO_SESSION_AVAILABLE);
@@ -189,6 +221,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testGetSessionNames2() {
         try {
             fShell.setScenario(SCEN_GET_SESSION_NAMES1);
@@ -204,6 +237,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testGetSessionNotExist() {
         try {
             fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST);
@@ -215,6 +249,22 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @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 {
             fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT);
@@ -228,6 +278,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testGetSession1() {
         try {
             fShell.setScenario(SCEN_GET_SESSION1);
@@ -375,6 +426,55 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
+    public void testGetKernelProviderNoKernel1() {
+        try {
+            fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL1);
+            List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
+
+            // Verify event info
+            assertNotNull(events);
+            assertEquals(0, events.size());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @Test
+    public void testGetKernelProviderNoKernel2() {
+        try {
+            fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL2);
+            List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
+
+            // Verify event info
+            assertNotNull(events);
+            assertEquals(0, events.size());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @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 {
             fShell.setScenario(SCEN_GET_UST_PROVIDER1);
@@ -429,6 +529,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testUstProvider2() {
         try {
             fShell.setScenario(SCEN_GET_UST_PROVIDER2);
@@ -442,11 +543,176 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
+    public void testGetUstProvider3() {
+        try {
+            fShell.setScenario(SCEN_GET_UST_PROVIDER3);
+            // Set version
+            ((LTTngControlService)fService).setVersion("2.1.0");
+            List<IUstProviderInfo> providers = fService.getUstProvider();
+
+            // Check all providers
+            assertNotNull(providers);
+            assertEquals(2, providers.size());
+
+            //Verify first provider
+            assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
+            assertEquals(9379, providers.get(0).getPid());
+
+            // Verify event info
+            IBaseEventInfo[] events = providers.get(0).getEvents();
+            assertNotNull(events);
+            assertEquals(2, events.length);
+
+            IBaseEventInfo baseEventInfo = events[0];
+            assertNotNull(baseEventInfo);
+            IFieldInfo[] fields = baseEventInfo.getFields();
+            assertNotNull(fields);
+            assertEquals(0, fields.length);
+
+            baseEventInfo = events[1];
+            fields = baseEventInfo.getFields();
+            assertNotNull(fields);
+            assertEquals(3, fields.length);
+            assertEquals("doublefield", fields[0].getName());
+            assertEquals("float", fields[0].getFieldType());
+
+            assertEquals("floatfield", fields[1].getName());
+            assertEquals("float", fields[1].getFieldType());
+
+            assertEquals("stringfield", fields[2].getName());
+            assertEquals("string", fields[2].getFieldType());
+
+            //Verify second provider
+            assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
+            assertEquals(4852, providers.get(1).getPid());
+
+            // Verify event info
+            events = providers.get(1).getEvents();
+            assertNotNull(events);
+            assertEquals(2, events.length);
+
+            baseEventInfo = events[0];
+            assertNotNull(baseEventInfo);
+            fields = baseEventInfo.getFields();
+            assertNotNull(fields);
+            assertEquals(0, fields.length);
+
+            baseEventInfo = events[1];
+            fields = baseEventInfo.getFields();
+            assertNotNull(fields);
+            assertEquals(3, fields.length);
+
+            assertEquals("doublefield", fields[0].getName());
+            assertEquals("float", fields[0].getFieldType());
+
+            assertEquals("floatfield", fields[1].getName());
+            assertEquals("float", fields[1].getFieldType());
+
+            assertEquals("stringfield", fields[2].getName());
+            assertEquals("string", fields[2].getFieldType());
+
+            // Reset version
+            ((LTTngControlService)fService).setVersion("2.0.0");
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+
+    @Test
+    public void testGetKernelProviderNoUst1() {
+        try {
+            fShell.setScenario(SCEN_LIST_WITH_NO_UST1);
+            List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
+
+            // Verify Provider info
+            assertNotNull(providerList);
+            assertEquals(0, providerList.size());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+
+    @Test
+    public void testGetKernelProviderNoUst2() {
+        try {
+            // Set version
+            ((LTTngControlService)fService).setVersion("2.1.0");
+
+            fShell.setScenario(SCEN_LIST_WITH_NO_UST2);
+            List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
+
+            // Verify Provider info
+            assertNotNull(providerList);
+            assertEquals(0, providerList.size());
+
+            // Reset version
+            ((LTTngControlService)fService).setVersion("2.0.0");
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @Test
+    public void testGetKernelProviderNoUst3() {
+        try {
+
+            // Set version
+            ((LTTngControlService)fService).setVersion("2.1.0");
+
+            fShell.setScenario(SCEN_LIST_WITH_NO_UST3);
+            List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
+
+            // Verify provider info
+            assertNotNull(providerList);
+            assertEquals(0, providerList.size());
+
+            // Reset version
+            ((LTTngControlService)fService).setVersion("2.0.0");
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @Test
+    public void testGetKernelProviderNoUstVerbose() {
+        try {
+            enableVerbose();
+
+            // Set version
+            ((LTTngControlService)fService).setVersion("2.1.0");
+
+            fShell.setScenario(SCEN_LIST_WITH_NO_UST_VERBOSE);
+            List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
+
+            // Verify provider info
+            assertNotNull(providerList);
+            assertEquals(0, providerList.size());
+
+            // Reset version
+            ((LTTngControlService)fService).setVersion("2.0.0");
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        } finally {
+            disableVerbose();
+        }
+    }
+
+
+
+    @Test
     public void testCreateSession() {
         try {
             fShell.setScenario(SCEN_CREATE_SESSION1);
 
-            ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
+            ISessionInfo info = fService.createSession(new SessionInfo("mysession2"), new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession2", info.getName());
             assertNotNull(info.getSessionPath());
@@ -457,14 +723,15 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testCreateSessionWithPrompt() {
         try {
-            // First line has the shell prompt before the command output 
+            // First line has the shell prompt before the command output
             // This can happen in a real application if the command line is not echoed by the shell.
             fShell.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT);
 
             // First line has no shell prompt before the output
-            ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
+            ISessionInfo info = fService.createSession(new SessionInfo("mysession2"), new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession2", info.getName());
             assertNotNull(info.getSessionPath());
@@ -475,34 +742,36 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
-    
+    @Test
     public void testCreateSessionVariants() {
 
         fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS);
 
         try {
-            fService.createSession("alreadyExist", null, new NullProgressMonitor());
+            fService.createSession(new SessionInfo("alreadyExist"), new NullProgressMonitor());
             fail("No exeption thrown");
         } catch (ExecutionException e) {
             // success
         }
 
         try {
-            fService.createSession("wrongName", null, new NullProgressMonitor());
+            fService.createSession(new SessionInfo("wrongName"), new NullProgressMonitor());
             fail("No exeption thrown");
         } catch (ExecutionException e) {
             // success
         }
 
         try {
-            fService.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
+            ISessionInfo sessionInfo = new SessionInfo("withPath");
+            sessionInfo.setSessionPath("/home/user/hallo");
+            fService.createSession(sessionInfo, new NullProgressMonitor());
             fail("No exeption thrown");
         } catch (ExecutionException e) {
             // success
         }
 
         try {
-            ISessionInfo info = fService.createSession("session with spaces", null, new NullProgressMonitor());
+            ISessionInfo info = fService.createSession(new SessionInfo("session with spaces"), new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("session with spaces", info.getName());
             assertNotNull(info.getSessionPath());
@@ -514,7 +783,9 @@ public class LTTngControlServiceTest extends TestCase {
         }
 
         try {
-            ISessionInfo info = fService.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
+            ISessionInfo sessionInfo = new SessionInfo("pathWithSpaces");
+            sessionInfo.setSessionPath("/home/user/hallo user/here");
+            ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("pathWithSpaces", info.getName());
             assertNotNull(info.getSessionPath());
@@ -526,6 +797,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testDestroySession() {
         try {
             fShell.setScenario(SCEN_DESTROY_SESSION1);
@@ -535,11 +807,25 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
-    public void testCreateChannel() {
+    @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 {
+            ((LTTngControlService)fService).setVersion("2.2.0");
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String kernelChannel0 = "mychannel0";
             String kernelChannel1 = "mychannel1";
             list.add(kernelChannel0);
@@ -554,6 +840,8 @@ public class LTTngControlServiceTest extends TestCase {
             chanInfo.setReadTimer(100);
             chanInfo.setSwitchTimer(200);
             chanInfo.setNumberOfSubBuffers(2);
+            chanInfo.setMaxNumberTraceFiles(10);
+            chanInfo.setMaxSizeTraceFiles(0);
             fService.enableChannels(sessionName, list, true, chanInfo, new NullProgressMonitor());
 
             // Create/enable/configure 1 UST channel
@@ -566,18 +854,78 @@ public class LTTngControlServiceTest extends TestCase {
             chanInfo.setReadTimer(200);
             chanInfo.setSwitchTimer(100);
             chanInfo.setNumberOfSubBuffers(1);
+            chanInfo.setMaxNumberTraceFiles(20);
+            chanInfo.setMaxSizeTraceFiles(0);
+            fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
+            ((LTTngControlService)fService).setVersion("2.0.0");
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @Test
+    public void testCreateChannelUIDBuffer() {
+        try {
+            ((LTTngControlService)fService).setVersion("2.2.0");
+            String sessionName = "mysession2";
+            List<String> list = new ArrayList<>();
+            String USTChannel = "ustChannel";
+            list.add(USTChannel);
+            fShell.setScenario(SCEN_CHANNEL_HANDLING);
+
+            ChannelInfo chanInfo = new ChannelInfo("");
+            chanInfo.setOverwriteMode(true);
+            chanInfo.setSubBufferSize(32768);
+            chanInfo.setReadTimer(200);
+            chanInfo.setSwitchTimer(100);
+            chanInfo.setNumberOfSubBuffers(1);
+            chanInfo.setMaxNumberTraceFiles(20);
+            chanInfo.setMaxSizeTraceFiles(0);
+            chanInfo.setBufferType(BufferType.BUFFER_PER_UID);
+            fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
+            ((LTTngControlService)fService).setVersion("2.0.0");
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @Test
+    public void testCreateChannelPIDBuffer() {
+        try {
+            ((LTTngControlService)fService).setVersion("2.2.0");
+            String sessionName = "mysession2";
+            List<String> list = new ArrayList<>();
+            String USTChannel = "ustChannel";
+            list.add(USTChannel);
+            fShell.setScenario(SCEN_CHANNEL_HANDLING);
+
+
+            ChannelInfo chanInfo = new ChannelInfo("");
+            chanInfo.setOverwriteMode(true);
+            chanInfo.setSubBufferSize(-1);
+            chanInfo.setReadTimer(-1);
+            chanInfo.setSwitchTimer(-1);
+            chanInfo.setNumberOfSubBuffers(-1);
+            chanInfo.setMaxNumberTraceFiles(-1);
+            chanInfo.setMaxSizeTraceFiles(-1);
+            chanInfo.setBufferType(BufferType.BUFFER_PER_PID);
+
             fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
+            ((LTTngControlService)fService).setVersion("2.0.0");
 
         } catch (ExecutionException e) {
             fail(e.toString());
         }
     }
 
+    @Test
     public void testDisableChannel() {
         try {
 
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String kernelChannel0 = "mychannel0";
             String kernelChannel1 = "mychannel1";
             list.add(kernelChannel0);
@@ -595,11 +943,12 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testEnableChannel() {
         try {
 
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String kernelChannel0 = "mychannel0";
             String kernelChannel1 = "mychannel1";
             list.add(kernelChannel0);
@@ -619,22 +968,12 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
-//    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 {
             // 1) session name, channel = null, 3 event names, kernel
             String sessionName = "mysession2";
-            List<String> list = new ArrayList<String>();
+            List<String> list = new ArrayList<>();
             String eventName0 = "block_rq_remap";
             String eventName1 = "block_bio_remap";
             String eventName2 = "softirq_entry";
@@ -642,27 +981,33 @@ public class LTTngControlServiceTest extends TestCase {
             list.add(eventName1);
             list.add(eventName2);
             fShell.setScenario(SCEN_EVENT_HANDLING);
-            fService.enableEvents(sessionName, null, list, true, new NullProgressMonitor());
+            fService.enableEvents(sessionName, null, list, true, null, new NullProgressMonitor());
 
             // 2) session name, channel=mychannel, event name= null, kernel
             String channelName = "mychannel";
-            fService.enableEvents(sessionName, channelName, null, true, new NullProgressMonitor());
+            fService.enableEvents(sessionName, channelName, null, true, null, new NullProgressMonitor());
 
-            // 3) session name, channel=mychannel, 1 event name, ust
+            // 3) session name, channel=mychannel, 1 event name, ust, no filter
             String ustEventName = "ust_tests_hello:tptest_sighandler";
             list.clear();
             list.add(ustEventName);
-            fService.enableEvents(sessionName, channelName, list, false, new NullProgressMonitor());
+            fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
 
-            // 4) session name, channel = mychannel, no event name, ust
+            // 4) session name, channel = mychannel, no event name, ust, with filter
+            fService.enableEvents(sessionName, channelName, list, false, "intfield==10", new NullProgressMonitor());
+
+            // 5) session name, channel = mychannel, no event name, ust, no filter
             list.clear();
-            fService.enableEvents(sessionName, channelName, list, false, new NullProgressMonitor());
+            fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
+
+            // TODO add test with filters
 
         } catch (ExecutionException e) {
             fail(e.toString());
         }
     }
 
+    @Test
     public void testEnableSyscalls() {
         try {
             // 1) session name, channel = null, 3 event names, kernel
@@ -682,6 +1027,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testDynamicProbe() {
         try {
             // 1) session name, channel = null, 3 event names, kernel
@@ -705,6 +1051,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testEnableLogLevel() {
         try {
             // 1) session name, channel = null, 3 event names, kernel
@@ -716,23 +1063,26 @@ public class LTTngControlServiceTest extends TestCase {
             fShell.setScenario(SCEN_EVENT_HANDLING);
 
             // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
-            fService.enableLogLevel(sessionName, null, eventName4, LogLevelType.LOGLEVEL_ONLY, TraceLogLevel.TRACE_DEBUG, new NullProgressMonitor());
+            fService.enableLogLevel(sessionName, null, eventName4, LogLevelType.LOGLEVEL_ONLY, TraceLogLevel.TRACE_DEBUG, null, new NullProgressMonitor());
 
             // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
-            fService.enableLogLevel(sessionName, channelName, eventName5, LogLevelType.LOGLEVEL, TraceLogLevel.TRACE_DEBUG_FUNCTION, new NullProgressMonitor());
+            fService.enableLogLevel(sessionName, channelName, eventName5, LogLevelType.LOGLEVEL, TraceLogLevel.TRACE_DEBUG_FUNCTION, null, new NullProgressMonitor());
+
+            // TODO add test with filters
 
         } catch (ExecutionException e) {
             fail(e.toString());
         }
     }
 
+    @Test
     public void testAddContext() {
         try {
             // 1) session name, channel = null, 3 event names, kernel
             String sessionName = "mysession2";
             String channelName = "mychannel";
             String eventName = "ust_tests_hello:tptest_sighandler";
-            List<String> contexts = new ArrayList<String>();
+            List<String> contexts = new ArrayList<>();
             contexts.add("prio");
             contexts.add("pid");
 
@@ -743,7 +1093,7 @@ public class LTTngControlServiceTest extends TestCase {
             assertEquals(12, availContexts.size());
 
             // A very "hard-coded" way to verify but it works ...
-            Set<String> expectedContexts = new HashSet<String>();
+            Set<String> expectedContexts = new HashSet<>();
             expectedContexts.add("pid");
             expectedContexts.add("procname");
             expectedContexts.add("prio");
@@ -767,13 +1117,14 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testAddContextFailure() {
 
         // 1) session name, channel = null, 3 event names, kernel
         String sessionName = "mysession2";
         String channelName = "mychannel";
         String eventName = "ust_tests_hello:tptest_sighandler";
-        List<String> contexts = new ArrayList<String>();
+        List<String> contexts = new ArrayList<>();
         contexts.add("prio");
         contexts.add("pid");
         fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING);
@@ -792,6 +1143,7 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testCalibrate() {
         try {
             fShell.setScenario(SCEN_CALIBRATE_HANDLING);
@@ -802,8 +1154,8 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
     public void testCalibrateFailure() {
-
         try {
             fShell.setScenario(SCEN_CALIBRATE_HANDLING);
             fService.calibrate(false, new NullProgressMonitor());
@@ -813,4 +1165,224 @@ public class LTTngControlServiceTest extends TestCase {
         }
     }
 
+    @Test
+    public void testCreateSession2_1() {
+
+        try {
+            fShell.setScenario(SCEN_CREATE_SESSION_2_1);
+
+            ISessionInfo sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setNetworkUrl("net://172.0.0.1");
+            sessionInfo.setStreamedTrace(true);
+            ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("net://172.0.0.1", info.getSessionPath());
+            assertTrue(info.isStreamedTrace());
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("file:///tmp");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("file:///tmp", info.getSessionPath());
+            assertTrue(!info.isStreamedTrace());
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("file:///tmp");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("file:///tmp", info.getSessionPath());
+            assertTrue(!info.isStreamedTrace());
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setControlUrl("tcp://172.0.0.1");
+            sessionInfo.setDataUrl("tcp://172.0.0.1:5343");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("", info.getSessionPath()); // the complete network path is not available at this point
+            assertTrue(info.isStreamedTrace());
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("net://172.0.0.1:1234:2345");
+            info = fService.createSession(sessionInfo, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("net://172.0.0.1:1234:2345", info.getSessionPath());
+            assertTrue(info.isStreamedTrace());
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+            // verbose
+            enableVerbose();
+            sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("net://172.0.0.1");
+            info = fService.createSession(sessionInfo, 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 sessionInfo = new SessionInfo("mysession");
+            sessionInfo.setStreamedTrace(true);
+            sessionInfo.setNetworkUrl("net://172.0.0.1");
+            ISessionInfo info = fService.createSession(sessionInfo, 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();
+        }
+    }
+
+    @Test
+    public void testCreateSnapshotSession() {
+        try {
+            fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION);
+            ISessionInfo params = new SessionInfo("mysession");
+            params.setSnapshot(true);
+            ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
+            assertNotNull(sessionInfo);
+            assertEquals("mysession", sessionInfo.getName());
+            assertTrue(sessionInfo.isSnapshotSession());
+            assertEquals("", sessionInfo.getSessionPath());
+            assertTrue(!sessionInfo.isStreamedTrace());
+
+            assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
+
+            String[] names = fService.getSessionNames(new NullProgressMonitor());
+            assertEquals(names[0], "mysession");
+
+            ISnapshotInfo snapshotInfo = fService.getSnapshotInfo("mysession", new NullProgressMonitor());
+            assertNotNull(snapshotInfo);
+            assertEquals("snapshot-1", snapshotInfo.getName());
+            assertEquals("/home/user/lttng-traces/mysession-20130913-141651", snapshotInfo.getSnapshotPath());
+            assertEquals(1, snapshotInfo.getId());
+            assertTrue(!snapshotInfo.isStreamedSnapshot());
+
+            // we need to set the snapshotInfo to so that the session path is set correctly
+            sessionInfo.setSnapshotInfo(snapshotInfo);
+            assertEquals("/home/user/lttng-traces/mysession-20130913-141651", sessionInfo.getSessionPath());
+
+            fService.recordSnapshot("mysession", new NullProgressMonitor());
+
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    public void testCreateStreamedSnapshotSession() {
+        try {
+            fShell.setScenario(SCEN_CREATE_STREAMED_SNAPSHOT_SESSION);
+
+            ISessionInfo params = new SessionInfo("mysession");
+            params.setNetworkUrl("net://172.0.0.1");
+            ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
+            assertNotNull(sessionInfo);
+            assertEquals("mysession", sessionInfo.getName());
+            assertTrue(sessionInfo.isSnapshotSession());
+
+            assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
+            assertTrue(sessionInfo.isStreamedTrace());
+
+            String[] names = fService.getSessionNames(new NullProgressMonitor());
+            assertEquals(names[0], "mysession");
+
+
+            ISnapshotInfo snapshotInfo = sessionInfo.getSnapshotInfo();
+            assertNotNull(sessionInfo);
+            assertEquals("snapshot-2", snapshotInfo.getName());
+            assertEquals("net4://172.0.0.1:5342/", snapshotInfo.getSnapshotPath());
+            assertEquals(2, snapshotInfo.getId());
+            assertTrue(snapshotInfo.isStreamedSnapshot());
+
+            // we need to set the snapshotInfo to so that the session path is set correctly
+            sessionInfo.setSnapshotInfo(snapshotInfo);
+            assertEquals("net4://172.0.0.1:5342/", sessionInfo.getSessionPath());
+
+            fService.recordSnapshot("mysession", new NullProgressMonitor());
+
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+
+    @Test
+    public void testCreateSnapshotSessionErrors() {
+        try {
+            fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION_ERRORS);
+
+            String[] names = fService.getSessionNames(new NullProgressMonitor());
+            assertEquals(names[0], "mysession");
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+
+        try {
+            fService.getSnapshotInfo("blabla", new NullProgressMonitor());
+            fail("getSnapshoInfo() didn't fail");
+        } catch (ExecutionException e) {
+            // successful
+        }
+
+        try {
+            fService.recordSnapshot("blabla", new NullProgressMonitor());
+            fail("getSnapshoInfo() didn't fail");
+        } catch (ExecutionException e) {
+            // successful
+        }
+
+        try {
+            fService.recordSnapshot("mysession", new NullProgressMonitor());
+            fail("getSnapshoInfo() didn't fail");
+        } catch (ExecutionException e) {
+            // successful
+        }
+    }
+
+    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);
+    }
+
+
 }
This page took 0.040186 seconds and 5 git commands to generate.