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
.tmf
.core
.tests
.statesystem
;
16 import java
.io
.IOException
;
17 import java
.util
.List
;
19 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.HistoryBuilder
;
20 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.backends
.IStateHistoryBackend
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.backends
.historytree
.HistoryTreeBackend
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.IStateChangeInput
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
30 * Small program to ensure a history file does not contain any "holes".
31 * Null-state-values are fine, here we're looking for *real* null's that would
32 * trigger NPE's elsewhere in the stack.
37 @SuppressWarnings({"nls","javadoc"})
38 public class VerifyHistoryFile
{
40 // Enter the .ht file name to test here
41 public static final String pathToHistoryFile
= "";
43 private static File htFile
;
44 private static IStateHistoryBackend htBackend
;
45 private static ITmfStateSystem ss
;
47 private static long startTime
;
48 private static long endTime
;
49 private static int nbErrors
;
51 public static void main(String
[] args
) throws IOException
,
52 TimeRangeException
, AttributeNotFoundException
,
53 StateSystemDisposedException
{
54 htFile
= new File(pathToHistoryFile
);
55 htBackend
= new HistoryTreeBackend(htFile
, IStateChangeInput
.IGNORE_PROVIDER_VERSION
);
56 ss
= HistoryBuilder
.openExistingHistory(htBackend
);
58 startTime
= ss
.getStartTime();
59 endTime
= ss
.getCurrentEndTime();
61 int total
= ss
.getNbAttributes();
63 System
.out
.println("Starting check of " + total
+ " attributes.");
64 for (int i
= 0; i
< total
; i
++) {
67 System
.out
.println("Done, total number of errors: " + nbErrors
);
70 private static void verifyAttribute(int attribute
)
71 throws TimeRangeException
, AttributeNotFoundException
,
72 StateSystemDisposedException
{
73 List
<ITmfStateInterval
> intervals
;
75 System
.out
.print("Checking attribute " + attribute
);
76 System
.out
.print(' ' + ss
.getFullAttributePath(attribute
));
78 intervals
= ss
.queryHistoryRange(attribute
, startTime
, endTime
);
79 System
.out
.println(" (" + intervals
.size() + " intervals)");
82 * Compare the start of the history with the start time of the first
85 verify(attribute
, startTime
, intervals
.get(0).getStartTime());
87 /* Compare the end time of each interval with the start of the next one */
88 for (int i
= 0; i
< intervals
.size() - 1; i
++) {
89 verify(attribute
, intervals
.get(i
).getEndTime() + 1,
90 intervals
.get(i
+ 1).getStartTime());
93 * Compare the end time of the last interval against the end time of the
96 verify(attribute
, intervals
.get(intervals
.size() - 1).getEndTime(),
100 private static void verify(int a
, long t1
, long t2
) {
103 System
.err
.println("Check failed for attribute " + a
+ ": " + t1