tmf: Add support for versioning state input plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / statesystem / VerifyHistoryFile.java
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.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;
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 */
37 @SuppressWarnings({"nls","javadoc"})
38 public class VerifyHistoryFile {
39
40 // Enter the .ht file name to test here
41 public static final String pathToHistoryFile = "";
42
43 private static File htFile;
44 private static IStateHistoryBackend htBackend;
45 private static ITmfStateSystem ss;
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,
52 TimeRangeException, AttributeNotFoundException,
53 StateSystemDisposedException {
54 htFile = new File(pathToHistoryFile);
55 htBackend = new HistoryTreeBackend(htFile, IStateChangeInput.IGNORE_PROVIDER_VERSION);
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)
71 throws TimeRangeException, AttributeNotFoundException,
72 StateSystemDisposedException {
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 }
This page took 0.03289 seconds and 6 git commands to generate.