tmf: Disable NLS warnings in tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / statesystem / VerifyHistoryFile.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 @SuppressWarnings("javadoc")
37 public class VerifyHistoryFile {
38
39 // Enter the .ht file name to test here
40 public static final String pathToHistoryFile = "";
41
42 private static File htFile;
43 private static IStateHistoryBackend htBackend;
44 private static ITmfStateSystem ss;
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,
51 TimeRangeException, AttributeNotFoundException,
52 StateSystemDisposedException {
53 htFile = new File(pathToHistoryFile);
54 htBackend = new HistoryTreeBackend(htFile, IStateChangeInput.IGNORE_PROVIDER_VERSION);
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)
70 throws TimeRangeException, AttributeNotFoundException,
71 StateSystemDisposedException {
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 }
This page took 0.034861 seconds and 6 git commands to generate.