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; | |
20 | import org.eclipse.linuxtools.internal.tmf.core.statesystem.IStateHistoryBackend; | |
21 | import org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree.HistoryTreeBackend; | |
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; | |
f1f86dfb | 26 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
3b353afb AM |
27 | |
28 | /** | |
29 | * Small program to ensure a history file does not contain any "holes". | |
30 | * Null-state-values are fine, here we're looking for *real* null's that would | |
31 | * trigger NPE's elsewhere in the stack. | |
32 | * | |
33 | * @author alexmont | |
34 | * | |
35 | */ | |
54a7a54c | 36 | @SuppressWarnings({"nls","javadoc"}) |
3b353afb AM |
37 | public class VerifyHistoryFile { |
38 | ||
7417cbb9 AM |
39 | // Enter the .ht file name to test here |
40 | public final static String pathToHistoryFile = ""; | |
3b353afb AM |
41 | |
42 | private static File htFile; | |
43 | private static IStateHistoryBackend htBackend; | |
f1f86dfb | 44 | private static ITmfStateSystem ss; |
3b353afb AM |
45 | |
46 | private static long startTime; | |
47 | private static long endTime; | |
48 | private static int nbErrors; | |
49 | ||
50 | public static void main(String[] args) throws IOException, | |
96345c5a AM |
51 | TimeRangeException, AttributeNotFoundException, |
52 | StateSystemDisposedException { | |
3b353afb AM |
53 | htFile = new File(pathToHistoryFile); |
54 | htBackend = new HistoryTreeBackend(htFile); | |
55 | ss = HistoryBuilder.openExistingHistory(htBackend); | |
56 | ||
57 | startTime = ss.getStartTime(); | |
58 | endTime = ss.getCurrentEndTime(); | |
59 | nbErrors = 0; | |
60 | int total = ss.getNbAttributes(); | |
61 | ||
62 | System.out.println("Starting check of " + total + " attributes."); | |
63 | for (int i = 0; i < total; i++) { | |
64 | verifyAttribute(i); | |
65 | } | |
66 | System.out.println("Done, total number of errors: " + nbErrors); | |
67 | } | |
68 | ||
69 | private static void verifyAttribute(int attribute) | |
96345c5a AM |
70 | throws TimeRangeException, AttributeNotFoundException, |
71 | StateSystemDisposedException { | |
3b353afb AM |
72 | List<ITmfStateInterval> intervals; |
73 | ||
74 | System.out.print("Checking attribute " + attribute); | |
75 | System.out.print(' ' + ss.getFullAttributePath(attribute)); | |
76 | ||
77 | intervals = ss.queryHistoryRange(attribute, startTime, endTime); | |
78 | System.out.println(" (" + intervals.size() + " intervals)"); | |
79 | ||
80 | /* | |
81 | * Compare the start of the history with the start time of the first | |
82 | * interval | |
83 | */ | |
84 | verify(attribute, startTime, intervals.get(0).getStartTime()); | |
85 | ||
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()); | |
90 | } | |
91 | /* | |
92 | * Compare the end time of the last interval against the end time of the | |
93 | * history | |
94 | */ | |
95 | verify(attribute, intervals.get(intervals.size() - 1).getEndTime(), | |
96 | endTime); | |
97 | } | |
98 | ||
99 | private static void verify(int a, long t1, long t2) { | |
100 | if (t1 != t2) { | |
101 | nbErrors++; | |
102 | System.err.println("Check failed for attribute " + a + ": " + t1 | |
103 | + " vs " + t2); | |
104 | } | |
105 | } | |
106 | ||
107 | } |