1 /*******************************************************************************
2 * Copyright (c) 2012 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 API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.tests
.stateprovider
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.stateprovider
.CtfKernelStateInput
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.IStateChangeInput
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.StateSystemManager
;
25 import org
.junit
.AfterClass
;
26 import org
.junit
.BeforeClass
;
27 import org
.junit
.Test
;
30 * State system tests using a full history back-end and the LTTng kernel state
33 * @author Alexandre Montplaisir
35 public class StateSystemFullHistoryTest
extends StateSystemTest
{
37 private static File stateFile
;
38 private static File stateFileBenchmark
;
41 * Initialize the test cases (build the history file once for all tests).
44 public static void initialize() {
46 stateFile
= File
.createTempFile("test", ".ht"); //$NON-NLS-1$ //$NON-NLS-2$
47 stateFileBenchmark
= File
.createTempFile("test", ".ht.benchmark"); //$NON-NLS-1$ //$NON-NLS-2$
49 input
= new CtfKernelStateInput(CtfTestFiles
.getTestTrace());
50 ssq
= StateSystemManager
.loadStateHistory(stateFile
, input
, true);
51 } catch (Exception e
) {
57 * Delete the temp files after we're done
60 public static void cleanup() {
62 ret1
= stateFile
.delete();
63 ret2
= stateFileBenchmark
.delete();
64 if ( !(ret1
&& ret2
) ) {
65 System
.err
.println("Error cleaning up during unit testing, " + //$NON-NLS-1$
66 "you might have leftovers state history files in /tmp"); //$NON-NLS-1$
70 // ------------------------------------------------------------------------
71 // Tests specific to a full-history
72 // ------------------------------------------------------------------------
75 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
76 * us to @Test the @BeforeClass...
78 * @throws TmfTraceException
82 public void testBuild() throws TmfTraceException
{
83 IStateChangeInput input2
;
86 input2
= new CtfKernelStateInput(CtfTestFiles
.getTestTrace());
87 ssb2
= StateSystemManager
.loadStateHistory(stateFileBenchmark
, input2
, true);
89 assertEquals(CtfTestFiles
.startTime
, ssb2
.getStartTime());
90 assertEquals(CtfTestFiles
.endTime
, ssb2
.getCurrentEndTime());
94 * Test re-opening the existing file.
96 * @throws TmfTraceException
100 public void testOpenExistingStateFile() throws TmfTraceException
{
101 ITmfStateSystem ssb2
;
103 /* 'newStateFile' should have already been created */
104 ssb2
= StateSystemManager
.loadStateHistory(stateFile
, null, true);
107 assertEquals(CtfTestFiles
.startTime
, ssb2
.getStartTime());
108 assertEquals(CtfTestFiles
.endTime
, ssb2
.getCurrentEndTime());