1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Alexandre Montplaisir - Initial implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.ust
.core
.tests
.trace
.callstack
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.fail
;
19 import java
.util
.List
;
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
;
34 * Common methods for LTTng-UST callstack trace tests.
36 * @author Alexandre Montplaisir
38 final class TestUtils
{
40 private TestUtils() {}
42 /** ID of the generated state systems */
43 static final String SSID
= CallStackStateProvider
.ID
;
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()) {
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();
61 /** Get the callstack for the given timestamp, for this particular trace */
62 static String
[] getCallStack(LttngUstTrace trace
, String processName
, long timestamp
) {
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();
69 int stackTop
= ss
.getQuarkRelative(stackAttribute
, String
.valueOf(depth
));
70 ITmfStateValue top
= state
.get(stackTop
).getStateValue();
71 assertEquals(top
, ss
.querySingleStackTop(timestamp
, stackAttribute
).getStateValue());
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();
80 } catch (AttributeNotFoundException e
) {
82 } catch (TimeRangeException e
) {
84 } catch (StateSystemDisposedException e
) {
86 } catch (StateValueTypeException e
) {