Search in sources :

Example 1 with TestFileReader

use of org.eclipse.titan.log.viewer.readers.TestFileReader in project titan.EclipsePlug-ins by eclipse.

the class Parser method parseRegion.

/**
 * Parses a given region from the log file and returns the contents as a list of events.
 * The SUT, MTC and System components are always added.
 *
 * @param startIndex the index of the event to be displayed.
 * @param endIndex the index of the last event to be displayed.
 * @param monitor the monitor to be used to report progress on.
 *
 * @return the events parsed from the given region.
 */
public List<EventObject> parseRegion(final int startIndex, final int endIndex, final IProgressMonitor monitor) throws IOException, ParseException {
    IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
    TestFileReader reader = null;
    wasCanceled = false;
    List<EventObject> result = new ArrayList<EventObject>(endIndex - startIndex + 6 + 1);
    final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
    // needed for memento of MSC view
    final TestCase testCase = this.executionModel.getTestCase();
    // The SUT element object always exists at all times, to make sure
    // it becomes visible before any test starts.
    EventObject sut = createEventObject(null, EventType.SYSTEM_CREATE);
    sut.setName(preferences.getSutName());
    result.add(sut);
    EventObject hc = createEventObject(null, EventType.HC_CREATE);
    result.add(hc);
    EventObject mtc = createEventObject(null, EventType.MTC_CREATE);
    result.add(mtc);
    if (Constants.DEBUG) {
        // $NON-NLS-1$
        TITANDebugConsole.getConsole().newMessageStream().println("Message type = " + this.messageAnalyser.getType());
    }
    this.tcRecords = logRecordIndexes.length;
    try {
        reader = new TestFileReader(this.logFileMetaData.getFilePath(), logRecordIndexes);
        internalMonitor.beginTask("Loading...", reader.size());
        for (int i = startIndex; i <= endIndex && i < eventVector.size() && !internalMonitor.isCanceled(); i++) {
            try {
                int actualIndex = eventVector.get(i) - testCase.getStartRecordNumber();
                reader.setCurrentLogRecord(actualIndex);
                LogRecord logRecord = reader.getNextRecord();
                // Add test case record number offset to record
                logRecord.setRecordNumber(testCase.getStartRecordNumber() + logRecord.getRecordNumber());
                EventObject event = parseLogRecord(logRecord, i);
                if (event != null) {
                    result.add(event);
                }
                internalMonitor.worked(1);
            } catch (ParseException e) {
                ErrorReporter.logExceptionStackTrace(e);
                ParseException throwable = new ParseException(e.getMessage(), 0);
                throwable.initCause(e);
                throw throwable;
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
    wasCanceled = internalMonitor.isCanceled();
    internalMonitor.done();
    for (String compRef : currentlyLivingComponents) {
        EventObject event = new EventObject(EventType.PTC_TERMINATE);
        event.setReference(compRef);
        event.setName(compRef);
        result.add(event);
    }
    // if no mtc termination is made, do it here
    if (!mtcTerminated) {
        mtc = eventObjectFactory.createEventObject(EventType.MTC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
        result.add(mtc);
    }
    hc = eventObjectFactory.createEventObject(EventType.HC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
    result.add(hc);
    // The last thing that "dies" in a log is the SUT, that still exists
    // after the test case is over. Still add a marker for this in the
    // log.
    sut = eventObjectFactory.createEventObject(EventType.SYSTEM_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
    result.add(sut);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PreferencesHolder(org.eclipse.titan.log.viewer.preferences.PreferencesHolder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) ArrayList(java.util.ArrayList) TestFileReader(org.eclipse.titan.log.viewer.readers.TestFileReader) ParseException(java.text.ParseException) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject)

Example 2 with TestFileReader

use of org.eclipse.titan.log.viewer.readers.TestFileReader in project titan.EclipsePlug-ins by eclipse.

the class Parser method preParse.

/**
 * This function will parse eventObject from the log file
 *
 * @param testCase
 *            test case, PreferenceHolder preferences
 * @return ExecutionModel throws IOException
 */
// FIXME signals, send, receive and silent events must be delayed.
// TODO Preferences could be calculated
public ExecutionModel preParse(final TestCase testCase, final LogRecordIndex[] logRecordIndexes, final PreferencesHolder preferences, final FilterPattern filterPattern, final IProgressMonitor monitor) throws IOException, ParseException, TechnicalException {
    IProgressMonitor internalMonitor = monitor == null ? new NullProgressMonitor() : monitor;
    wasCanceled = false;
    this.logRecordIndexes = logRecordIndexes;
    this.executionModel = new ExecutionModel(this);
    this.executionModel.setFilterPattern(filterPattern);
    // Add ignored components
    this.executionModel.addIgnoredComponent(preferences.getIgnoredComponents());
    this.executionModel.setSutName(preferences.getSutName());
    // Add ignored signals
    this.executionModel.addIgnoredSignals(preferences.getIgnoredSignals());
    // Add ignored functions
    this.executionModel.addIgnoredFunctions(preferences.getIgnoredFunctions());
    // needed for memento of MSC view
    this.executionModel.setContainedTestCase(testCase);
    this.executionModel.getTestCase().setTestCaseName(testCase.getTestCaseName());
    this.executionModel.getTestCase().setVerdict(testCase.getVerdict());
    // The SUT element object always exists at all times, to make sure
    // it becomes visible before any test starts.
    EventObject sut = createEventObject(null, EventType.SYSTEM_CREATE);
    sut.setName(preferences.getSutName());
    sut.setEventNumber(0);
    this.executionModel.addComponent(sut);
    executionModel.addLifeLineInfo(sut);
    EventObject hc = createEventObject(null, EventType.HC_CREATE);
    hc.setEventNumber(1);
    this.executionModel.addComponent(hc);
    executionModel.addLifeLineInfo(hc);
    EventObject mtc = createEventObject(null, EventType.MTC_CREATE);
    mtc.setEventNumber(2);
    this.executionModel.addComponent(mtc);
    executionModel.addLifeLineInfo(mtc);
    components = this.executionModel.getComponents();
    this.messageAnalyser = MessageAnalyserFactory.createMessageAnalyser(this.logFileMetaData);
    setUpFromPreferences(preferences, filterPattern);
    if (Constants.DEBUG) {
        // $NON-NLS-1$
        TITANDebugConsole.getConsole().newMessageStream().println("Message type = " + this.messageAnalyser.getType());
    }
    this.tcRecords = logRecordIndexes.length;
    TestFileReader reader = null;
    try {
        reader = new TestFileReader(this.logFileMetaData.getFilePath(), logRecordIndexes);
        eventVector = new ArrayList<Integer>();
        internalMonitor.beginTask("Loading...", reader.size());
        /**
         * Stores the components that was not terminated before the given log record.
         * It can be used for partial log files.
         */
        currentlyLivingComponents = new HashSet<String>();
        while (reader.hasNextRecord() && !internalMonitor.isCanceled()) {
            try {
                LogRecord logRecord = reader.getNextRecord();
                // Add test case record number offset to record
                logRecord.setRecordNumber(testCase.getStartRecordNumber() + logRecord.getRecordNumber());
                preParseLogRecord(logRecord, currentlyLivingComponents);
                internalMonitor.worked(1);
            } catch (ParseException e) {
                ErrorReporter.logExceptionStackTrace(e);
                ParseException throwable = new ParseException(e.getMessage(), 0);
                throwable.initCause(e);
                throw throwable;
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
    // remove some of those components that are part of the surrounding system
    currentlyLivingComponents.remove(Constants.MTC_REFERENCE);
    currentlyLivingComponents.remove(Constants.HC_REFERENCE);
    currentlyLivingComponents.remove(Constants.SUT_REFERENCE);
    // The components which were not terminated
    int additionalIndex = 3;
    for (String compRef : currentlyLivingComponents) {
        EventObject event = new EventObject(EventType.PTC_TERMINATE);
        event.setEventNumber(eventVector.size() + additionalIndex);
        additionalIndex++;
        event.setReference(compRef);
        event.setName(compRef);
        executionModel.addLifeLineInfo(event);
    }
    wasCanceled = internalMonitor.isCanceled();
    internalMonitor.done();
    // if no mtc termination is made, do it here
    if (!mtcTerminated) {
        mtc = eventObjectFactory.createEventObject(EventType.MTC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
        mtc.setEventNumber(eventVector.size() + additionalIndex);
        additionalIndex++;
        executionModel.addLifeLineInfo(mtc);
    }
    hc = eventObjectFactory.createEventObject(EventType.HC_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
    hc.setEventNumber(eventVector.size() + additionalIndex);
    additionalIndex++;
    executionModel.addLifeLineInfo(hc);
    // The last thing that "dies" in a log is the SUT, that still exists
    // after the test case is over. Still add a marker for this in the
    // log.
    sut = eventObjectFactory.createEventObject(EventType.SYSTEM_TERMINATE, null, this.messageAnalyser, this.logFileMetaData.getTimeStampConstant());
    sut.setEventNumber(eventVector.size() + additionalIndex);
    executionModel.addLifeLineInfo(sut);
    setVerdict();
    return this.executionModel;
}
Also used : ExecutionModel(org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) TestFileReader(org.eclipse.titan.log.viewer.readers.TestFileReader) ParseException(java.text.ParseException) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject)

Aggregations

ParseException (java.text.ParseException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)2 TestFileReader (org.eclipse.titan.log.viewer.readers.TestFileReader)2 EventObject (org.eclipse.titan.log.viewer.views.msc.model.EventObject)2 ArrayList (java.util.ArrayList)1 TestCase (org.eclipse.titan.log.viewer.parsers.data.TestCase)1 PreferencesHolder (org.eclipse.titan.log.viewer.preferences.PreferencesHolder)1 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)1