~ubuntu-branches/ubuntu/wily/eclipse-linuxtools/wily

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.ITmfStateProvider;
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, ITmfStateProvider.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
 
}