Skip to content

Commit

Permalink
Bug 578738: Add unit test to verify the server workspace for traces
Browse files Browse the repository at this point in the history
This verifies that the workspace of the trace server is compatible with
the workspace created by Trace Compass Eclipse.

Change-Id: Id855a2a2558f86f19ad6fcf76d9c200979e424c6
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/191161
Tested-by: Marco Miller <marco.miller@ericsson.com>
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Marco Miller <marco.miller@ericsson.com>
  • Loading branch information
bhufmann committed Feb 25, 2022
1 parent 0429681 commit 4e0a51e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.services;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
Expand All @@ -20,9 +21,22 @@
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.TraceManagerService;
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.TraceModelStub;
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils.RestServerTest;
import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
import org.eclipse.tracecompass.tmf.core.TmfProjectNature;
import org.eclipse.tracecompass.tmf.core.io.ResourceUtil;
import org.junit.Test;

import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -91,4 +105,54 @@ public void testConflictingTraces() throws IOException {
assertPost(traces, ARM_64_KERNEL_STUB);
assertEquals(ImmutableSet.of(CONTEXT_SWITCHES_KERNEL_STUB, ARM_64_KERNEL_STUB), getTraces(traces));
}

/**
* Test workspace structure for traces
*
* @throws CoreException
* when a CoreException occurs
* @throws IOException
* Exception thrown by getting trace path
*/
@Test
public void testWorkspaceStructure() throws CoreException, IOException {
WebTarget traces = getApplicationEndpoint().path(TRACES);

assertPost(traces, CONTEXT_SWITCHES_KERNEL_STUB);
assertPost(traces, CONTEXT_SWITCHES_UST_STUB);

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

// Make sure that workspace is refreshed
root.refreshLocal(IResource.DEPTH_INFINITE, null);

// Check for Tracing project with name "Tracing"
IProject tracingProject = root.getProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME);
assertTrue(tracingProject.exists());
assertTrue(tracingProject.isNatureEnabled(TmfProjectNature.ID));

IFolder tracesFolder = tracingProject.getFolder("Traces");
assertTrue(tracesFolder.exists());

String contextSwitchesKernelPath = FileLocator.toFileURL(CtfTestTrace.CONTEXT_SWITCHES_KERNEL.getTraceURL()).getPath().replaceAll("/$", "");
IPath path = Path.fromOSString(contextSwitchesKernelPath);

// Check if trace parent folder was created
IFolder traceParent = tracesFolder.getFolder(path.removeLastSegments(1));
assertTrue(traceParent.exists());

// Check for trace with name kernel under the trace parent directory
IFolder trace = traceParent.getFolder(CONTEXT_SWITCHES_KERNEL_NAME);
assertTrue(trace.exists());

// Make sure it's a symbolic link and not file copy
assertTrue(ResourceUtil.isSymbolicLink(trace));

// Verify that trace type is set as persistent property
String traceType = trace.getPersistentProperty(TmfCommonConstants.TRACETYPE);
assertNotNull(traceType);

// Verify that the trace type is the kernel trace type
assertEquals("org.eclipse.linuxtools.lttng2.kernel.tracetype", traceType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,33 @@ public abstract class RestServerTest {
*/
protected static TraceModelStub CONTEXT_SWITCHES_UST_STUB;

/**
* The name used when posting the trace.
*/
protected static final String CONTEXT_SWITCHES_UST_NAME = "ust";

/**
* {@link TraceModelStub} to represent the object returned by the server for
* {@link CtfTestTrace#CONTEXT_SWITCHES_KERNEL}.
*/
protected static TraceModelStub CONTEXT_SWITCHES_KERNEL_STUB;

/**
* The name used when posting the trace.
*/
protected static final String CONTEXT_SWITCHES_KERNEL_NAME = "kernel";

/**
* {@link TraceModelStub} to represent the object returned by the server for
* {@link CtfTestTrace#ARM_64_BIT_HEADER}, with the same name as {@link #CONTEXT_SWITCHES_KERNEL_STUB}
*/
protected static TraceModelStub ARM_64_KERNEL_STUB;

/**
* The name used when posting the trace.
*/
protected static final String ARM_64_KERNEL_NAME = "kernel";

/**
* Expected toString() of all data providers for this experiment
*/
Expand All @@ -162,13 +177,13 @@ public abstract class RestServerTest {
@BeforeClass
public static void beforeTest() throws IOException {
String contextSwitchesUstPath = FileLocator.toFileURL(CtfTestTrace.CONTEXT_SWITCHES_UST.getTraceURL()).getPath().replaceAll("/$", "");
CONTEXT_SWITCHES_UST_STUB = new TraceModelStub("ust", contextSwitchesUstPath);
CONTEXT_SWITCHES_UST_STUB = new TraceModelStub(CONTEXT_SWITCHES_UST_NAME, contextSwitchesUstPath);

String contextSwitchesKernelPath = FileLocator.toFileURL(CtfTestTrace.CONTEXT_SWITCHES_KERNEL.getTraceURL()).getPath().replaceAll("/$", "");
CONTEXT_SWITCHES_KERNEL_STUB = new TraceModelStub("kernel", contextSwitchesKernelPath);
CONTEXT_SWITCHES_KERNEL_STUB = new TraceModelStub(CONTEXT_SWITCHES_KERNEL_NAME, contextSwitchesKernelPath);

String arm64Path = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath().replaceAll("/$", "");
ARM_64_KERNEL_STUB = new TraceModelStub("kernel", arm64Path);
ARM_64_KERNEL_STUB = new TraceModelStub(ARM_64_KERNEL_NAME, arm64Path);

ImmutableList.Builder<DataProviderDescriptorStub> b = ImmutableList.builder();
b.add(new DataProviderDescriptorStub("org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.scatter.dataprovider:org.eclipse.linuxtools.lttng2.ust.analysis.callstack",
Expand Down

0 comments on commit 4e0a51e

Please sign in to comment.