Commit | Line | Data |
---|---|---|
3b353afb AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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 API and implementation | |
11 | ******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.tests.statesystem; | |
14 | ||
15 | import java.io.File; | |
16 | import java.io.IOException; | |
17 | import java.util.List; | |
18 | ||
19 | import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder; | |
f9a76cac AM |
20 | import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; |
21 | import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree.HistoryTreeBackend; | |
3b353afb | 22 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; |
96345c5a | 23 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; |
3b353afb AM |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; |
25 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
a96cc6be | 26 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; |
f1f86dfb | 27 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
3b353afb AM |
28 | |
29 | /** | |
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. | |
33 | * | |
34 | * @author alexmont | |
35 | * | |
36 | */ | |
54a7a54c | 37 | @SuppressWarnings({"nls","javadoc"}) |
3b353afb AM |
38 | public class VerifyHistoryFile { |
39 | ||
7417cbb9 | 40 | // Enter the .ht file name to test here |
a96cc6be | 41 | public static final String pathToHistoryFile = ""; |
3b353afb AM |
42 | |
43 | private static File htFile; | |
44 | private static IStateHistoryBackend htBackend; | |
f1f86dfb | 45 | private static ITmfStateSystem ss; |
3b353afb AM |
46 | |
47 | private static long startTime; | |
48 | private static long endTime; | |
49 | private static int nbErrors; | |
50 | ||
51 | public static void main(String[] args) throws IOException, | |
96345c5a AM |
52 | TimeRangeException, AttributeNotFoundException, |
53 | StateSystemDisposedException { | |
3b353afb | 54 | htFile = new File(pathToHistoryFile); |
a96cc6be | 55 | htBackend = new HistoryTreeBackend(htFile, IStateChangeInput.IGNORE_PROVIDER_VERSION); |
3b353afb AM |
56 | ss = HistoryBuilder.openExistingHistory(htBackend); |
57 | ||
58 | startTime = ss.getStartTime(); | |
59 | endTime = ss.getCurrentEndTime(); | |
60 | nbErrors = 0; | |
61 | int total = ss.getNbAttributes(); | |
62 | ||
63 | System.out.println("Starting check of " + total + " attributes."); | |
64 | for (int i = 0; i < total; i++) { | |
65 | verifyAttribute(i); | |
66 | } | |
67 | System.out.println("Done, total number of errors: " + nbErrors); | |
68 | } | |
69 | ||
70 | private static void verifyAttribute(int attribute) | |
96345c5a AM |
71 | throws TimeRangeException, AttributeNotFoundException, |
72 | StateSystemDisposedException { | |
3b353afb AM |
73 | List<ITmfStateInterval> intervals; |
74 | ||
75 | System.out.print("Checking attribute " + attribute); | |
76 | System.out.print(' ' + ss.getFullAttributePath(attribute)); | |
77 | ||
78 | intervals = ss.queryHistoryRange(attribute, startTime, endTime); | |
79 | System.out.println(" (" + intervals.size() + " intervals)"); | |
80 | ||
81 | /* | |
82 | * Compare the start of the history with the start time of the first | |
83 | * interval | |
84 | */ | |
85 | verify(attribute, startTime, intervals.get(0).getStartTime()); | |
86 | ||
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()); | |
91 | } | |
92 | /* | |
93 | * Compare the end time of the last interval against the end time of the | |
94 | * history | |
95 | */ | |
96 | verify(attribute, intervals.get(intervals.size() - 1).getEndTime(), | |
97 | endTime); | |
98 | } | |
99 | ||
100 | private static void verify(int a, long t1, long t2) { | |
101 | if (t1 != t2) { | |
102 | nbErrors++; | |
103 | System.err.println("Check failed for attribute " + a + ": " + t1 | |
104 | + " vs " + t2); | |
105 | } | |
106 | } | |
107 | ||
108 | } |