From 3b353afb343f01bd2a6041c7b55ad7ff2b91dac7 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Tue, 5 Jun 2012 18:22:00 -0400 Subject: [PATCH] tmf: Add the verifyHistory test program Signed-off-by: Alexandre Montplaisir --- .../tests/statesystem/VerifyHistoryFile.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java new file mode 100644 index 0000000000..7add8728a4 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + ******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.tests.statesystem; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder; +import org.eclipse.linuxtools.internal.tmf.core.statesystem.IStateHistoryBackend; +import org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree.HistoryTreeBackend; +import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; +import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; +import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; +import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier; + +/** + * Small program to ensure a history file does not contain any "holes". + * Null-state-values are fine, here we're looking for *real* null's that would + * trigger NPE's elsewhere in the stack. + * + * @author alexmont + * + */ +@SuppressWarnings("nls") +public class VerifyHistoryFile { + + public final static String pathToHistoryFile = "/home/alexandre/bin/eclipse-4.2/runtime-EclipseApplication/myproject/.tracing/trace2/stateHistory.ht"; + + private static File htFile; + private static IStateHistoryBackend htBackend; + private static IStateSystemQuerier ss; + + private static long startTime; + private static long endTime; + private static int nbErrors; + + public static void main(String[] args) throws IOException, + TimeRangeException, AttributeNotFoundException { + htFile = new File(pathToHistoryFile); + htBackend = new HistoryTreeBackend(htFile); + ss = HistoryBuilder.openExistingHistory(htBackend); + + startTime = ss.getStartTime(); + endTime = ss.getCurrentEndTime(); + nbErrors = 0; + int total = ss.getNbAttributes(); + + System.out.println("Starting check of " + total + " attributes."); + for (int i = 0; i < total; i++) { + verifyAttribute(i); + } + System.out.println("Done, total number of errors: " + nbErrors); + } + + private static void verifyAttribute(int attribute) + throws TimeRangeException, AttributeNotFoundException { + List intervals; + + System.out.print("Checking attribute " + attribute); + System.out.print(' ' + ss.getFullAttributePath(attribute)); + + intervals = ss.queryHistoryRange(attribute, startTime, endTime); + System.out.println(" (" + intervals.size() + " intervals)"); + + /* + * Compare the start of the history with the start time of the first + * interval + */ + verify(attribute, startTime, intervals.get(0).getStartTime()); + + /* Compare the end time of each interval with the start of the next one */ + for (int i = 0; i < intervals.size() - 1; i++) { + verify(attribute, intervals.get(i).getEndTime() + 1, + intervals.get(i + 1).getStartTime()); + } + /* + * Compare the end time of the last interval against the end time of the + * history + */ + verify(attribute, intervals.get(intervals.size() - 1).getEndTime(), + endTime); + } + + private static void verify(int a, long t1, long t2) { + if (t1 != t2) { + nbErrors++; + System.err.println("Check failed for attribute " + a + ": " + t1 + + " vs " + t2); + } + } + +} -- 2.34.1