Commit | Line | Data |
---|---|---|
6e4358bd AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.fail; | |
17 | ||
18 | import java.io.File; | |
19 | import java.util.List; | |
20 | ||
21 | import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace; | |
22 | import org.eclipse.linuxtools.tmf.core.callstack.CallStackStateProvider; | |
23 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; | |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; | |
25 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; | |
26 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
27 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
28 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
29 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
30 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; | |
31 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; | |
32 | ||
33 | /** | |
34 | * Common methods for LTTng-UST callstack trace tests. | |
35 | * | |
36 | * @author Alexandre Montplaisir | |
37 | */ | |
38 | final class TestUtils { | |
39 | ||
40 | private TestUtils() {} | |
41 | ||
42 | /** ID of the generated state systems */ | |
43 | static final String SSID = CallStackStateProvider.ID; | |
44 | ||
45 | /** Empty and delete a directory */ | |
46 | static void deleteDirectory(File dir) { | |
47 | /* Assuming the dir only contains file or empty directories */ | |
48 | for (File file : dir.listFiles()) { | |
49 | file.delete(); | |
50 | } | |
51 | dir.delete(); | |
52 | } | |
53 | ||
54 | /** Simulate a trace being opened (which triggers building the state system) */ | |
55 | static void openTrace(LttngUstTrace trace) { | |
56 | trace.indexTrace(true); | |
57 | TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(trace, trace, null)); | |
58 | trace.getStateSystems().get(SSID).waitUntilBuilt(); | |
59 | } | |
60 | ||
61 | /** Get the callstack for the given timestamp, for this particular trace */ | |
62 | static String[] getCallStack(LttngUstTrace trace, String processName, long timestamp) { | |
63 | try { | |
64 | ITmfStateSystem ss = trace.getStateSystems().get(SSID); | |
65 | int stackAttribute = ss.getQuarkAbsolute("Threads", processName, "CallStack"); | |
66 | List<ITmfStateInterval> state = ss.queryFullState(timestamp); | |
67 | int depth = state.get(stackAttribute).getStateValue().unboxInt(); | |
68 | ||
69 | int stackTop = ss.getQuarkRelative(stackAttribute, String.valueOf(depth)); | |
70 | ITmfStateValue top = state.get(stackTop).getStateValue(); | |
71 | assertEquals(top, ss.querySingleStackTop(timestamp, stackAttribute).getStateValue()); | |
72 | ||
73 | String[] ret = new String[depth]; | |
74 | for (int i = 0; i < depth; i++) { | |
75 | int quark = ss.getQuarkRelative(stackAttribute, String.valueOf(i + 1)); | |
76 | ret[i] = state.get(quark).getStateValue().unboxStr(); | |
77 | } | |
78 | return ret; | |
79 | ||
80 | } catch (AttributeNotFoundException e) { | |
81 | fail(e.getMessage()); | |
82 | } catch (TimeRangeException e) { | |
83 | fail(e.getMessage()); | |
84 | } catch (StateSystemDisposedException e) { | |
85 | fail(e.getMessage()); | |
86 | } catch (StateValueTypeException e) { | |
87 | fail(e.getMessage()); | |
88 | } | |
89 | fail(); | |
90 | return null; | |
91 | } | |
92 | ||
93 | } |