1 /*******************************************************************************
2 * Copyright (c) 2012, 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 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.
36 @SuppressWarnings({"nls","javadoc"})
37 public class VerifyHistoryFile
{
39 // Enter the .ht file name to test here
40 public static final String pathToHistoryFile
= "";
42 private static File htFile
;
43 private static IStateHistoryBackend htBackend
;
44 private static ITmfStateSystem ss
;
46 private static long startTime
;
47 private static long endTime
;
48 private static int nbErrors
;
50 public static void main(String
[] args
) throws IOException
,
51 TimeRangeException
, AttributeNotFoundException
,
52 StateSystemDisposedException
{
53 htFile
= new File(pathToHistoryFile
);
54 htBackend
= new HistoryTreeBackend(htFile
, IStateChangeInput
.IGNORE_PROVIDER_VERSION
);
55 ss
= HistoryBuilder
.openExistingHistory(htBackend
);
57 startTime
= ss
.getStartTime();
58 endTime
= ss
.getCurrentEndTime();
60 int total
= ss
.getNbAttributes();
62 System
.out
.println("Starting check of " + total
+ " attributes.");
63 for (int i
= 0; i
< total
; i
++) {
66 System
.out
.println("Done, total number of errors: " + nbErrors
);
69 private static void verifyAttribute(int attribute
)
70 throws TimeRangeException
, AttributeNotFoundException
,
71 StateSystemDisposedException
{
72 List
<ITmfStateInterval
> intervals
;
74 System
.out
.print("Checking attribute " + attribute
);
75 System
.out
.print(' ' + ss
.getFullAttributePath(attribute
));
77 intervals
= ss
.queryHistoryRange(attribute
, startTime
, endTime
);
78 System
.out
.println(" (" + intervals
.size() + " intervals)");
81 * Compare the start of the history with the start time of the first
84 verify(attribute
, startTime
, intervals
.get(0).getStartTime());
86 /* Compare the end time of each interval with the start of the next one */
87 for (int i
= 0; i
< intervals
.size() - 1; i
++) {
88 verify(attribute
, intervals
.get(i
).getEndTime() + 1,
89 intervals
.get(i
+ 1).getStartTime());
92 * Compare the end time of the last interval against the end time of the
95 verify(attribute
, intervals
.get(intervals
.size() - 1).getEndTime(),
99 private static void verify(int a
, long t1
, long t2
) {
102 System
.err
.println("Check failed for attribute " + a
+ ": " + t1