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