Search in sources :

Example 11 with LogRecord

use of org.eclipse.titan.log.viewer.parsers.data.LogRecord 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 12 with LogRecord

use of org.eclipse.titan.log.viewer.parsers.data.LogRecord 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)

Example 13 with LogRecord

use of org.eclipse.titan.log.viewer.parsers.data.LogRecord in project titan.EclipsePlug-ins by eclipse.

the class TextTableView method refreshTable.

/**
 * Refreshes the visible part of the table
 */
void refreshTable() {
    table.setItemCount(filteredLogReader.size());
    table.setTopIndex(0);
    table.setSelection(0);
    int topIndex = 0;
    int visibleItems = TextTableView.this.table.getClientArea().height / TextTableView.this.table.getItemHeight();
    int startPos = topIndex + visibleItems + TextTableView.CACHE_SIZE;
    if (startPos >= filteredLogReader.size()) {
        startPos = filteredLogReader.size() - 1;
    }
    if (clearingThread != null) {
        clearingThread.stop();
    }
    clearingThread = new ClearingRunnable(topIndex, visibleItems);
    Display.getDefault().asyncExec(clearingThread);
    try {
        cachedLogReader.cacheRecords(topIndex, startPos);
        for (int rowIndex = topIndex; rowIndex <= startPos; ++rowIndex) {
            final TableItem item = table.getItem(rowIndex);
            LogRecord record = getLogRecordAtRow(rowIndex);
            setTableItem(item, record);
        }
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("TextTableModel.6") + e.getMessage()));
    } catch (ParseException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("TextTableModel.7") + e.getMessage()));
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) TableItem(org.eclipse.swt.widgets.TableItem) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 14 with LogRecord

use of org.eclipse.titan.log.viewer.parsers.data.LogRecord in project titan.EclipsePlug-ins by eclipse.

the class TextTableView method updateSelection.

/**
 * Update the selection in the provided table
 *
 *  @param table to work on
 */
private void updateSelection(Table table1) {
    TableItem tableItem = table1.getItem(table1.getSelectionIndex());
    Object data = tableItem.getData();
    if (data instanceof LogRecord) {
        LogRecord logrecord = (LogRecord) data;
        TextTableView.this.selectedEventObject = createEventObject(logrecord);
        TextTableView.this.eventSelection = new EventSelection(TextTableView.this.selectedEventObject, "");
    } else {
        TextTableView.this.eventSelection = new EventSelection(null, null);
    }
    fireSelectionChangeEvent();
    silentOpenSourceViewMenuAction.delayedRun(eventSelection);
    silentOpenValueViewMenuAction.delayedRun(eventSelection);
}
Also used : LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) TableItem(org.eclipse.swt.widgets.TableItem) EventObject(org.eclipse.titan.log.viewer.views.msc.model.EventObject) EventSelection(org.eclipse.titan.log.viewer.views.msc.model.EventSelection)

Example 15 with LogRecord

use of org.eclipse.titan.log.viewer.parsers.data.LogRecord in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView method setData.

/**
 * Set data for Statistical View
 * @param statisticalDataVector the new data
 */
public void setData(final List<StatisticalData> statisticalDataVector) {
    this.statisticalDataVector = statisticalDataVector;
    if (this.statisticalDataVector.size() > 1) {
        Set<String> keys = cachedSections.keySet();
        for (String currentKey : keys) {
            Section tmpSection = cachedSections.get(currentKey);
            if (tmpSection != null && !tmpSection.isDisposed()) {
                tmpSection.dispose();
            }
        }
        cachedSections.clear();
    }
    for (StatisticalData statisticalData : this.statisticalDataVector) {
        this.logFileMetaData = statisticalData.getLogFileMetaData();
        List<TestCase> tmpTestCases = statisticalData.getTestCaseVector();
        this.reader = statisticalData.getCachedLogFileReader();
        String projectRelativePath = this.logFileMetaData.getProjectRelativePath();
        Section tmpSection = cachedSections.get(projectRelativePath);
        if (tmpSection == null) {
            createSection();
        }
        // Clear all tables before setting the data
        this.amountTable.removeAll();
        this.errorTestCasesTable.removeAll();
        this.failTestCasesTable.removeAll();
        this.testCases.removeAll();
        int noOfPass = 0;
        int noOfFail = 0;
        int noOfInconc = 0;
        int noOfNone = 0;
        int noOfError = 0;
        int noOfCrash = 0;
        // If input is null
        if (tmpTestCases == null) {
            continue;
        }
        int noTotal = tmpTestCases.size();
        for (TestCase tc : tmpTestCases) {
            TableItem tcItem = new TableItem(this.testCases, SWT.BORDER);
            LogRecord record = getLogRecordAtRow(tc.getStartRecordNumber());
            String start = record.getTimestamp();
            record = getLogRecordAtRow(tc.getEndRecordNumber());
            String stop = record.getTimestamp();
            Image image;
            switch(tc.getVerdict()) {
                case Constants.VERDICT_PASS:
                    image = Activator.getDefault().getIcon(Constants.ICONS_PASS);
                    noOfPass++;
                    break;
                case Constants.VERDICT_ERROR:
                    image = Activator.getDefault().getIcon(Constants.ICONS_ERROR);
                    TableItem tcErrorItem = new TableItem(this.errorTestCasesTable, SWT.BORDER);
                    tcErrorItem.setImage(1, image);
                    tcErrorItem.setText(2, tc.getTestCaseName());
                    tcErrorItem.setText(3, start);
                    tcErrorItem.setText(4, stop);
                    tcErrorItem.setData(tc);
                    noOfError++;
                    break;
                case Constants.VERDICT_FAIL:
                    image = Activator.getDefault().getIcon(Constants.ICONS_FAIL);
                    TableItem tcFailItem = new TableItem(this.failTestCasesTable, SWT.BORDER);
                    tcFailItem.setImage(1, image);
                    tcFailItem.setText(2, tc.getTestCaseName());
                    tcFailItem.setText(3, start);
                    tcFailItem.setText(4, stop);
                    tcFailItem.setData(tc);
                    noOfFail++;
                    break;
                case Constants.VERDICT_INCONCLUSIVE:
                    image = Activator.getDefault().getIcon(Constants.ICONS_INCONCLUSIVE);
                    noOfInconc++;
                    break;
                case Constants.VERDICT_NONE:
                    image = Activator.getDefault().getIcon(Constants.ICONS_NONE);
                    noOfNone++;
                    break;
                case Constants.VERDICT_CRASHED:
                    image = Activator.getDefault().getIcon(Constants.ICONS_CRASHED);
                    noOfCrash++;
                    break;
                default:
                    // Could not find image return null
                    image = null;
                    break;
            }
            tcItem.setImage(1, image);
            tcItem.setText(2, tc.getTestCaseName());
            tcItem.setText(3, start);
            tcItem.setText(4, stop);
            tcItem.setData(tc);
        }
        if (this.errorTestCasesTable.getItems().length < 1) {
            this.errorTestCasesTable.setLinesVisible(false);
        } else {
            this.errorTestCasesTable.redraw();
            ecError.setExpanded(true);
        }
        if (this.failTestCasesTable.getItems().length < 1) {
            this.failTestCasesTable.setLinesVisible(false);
        } else {
            this.failTestCasesTable.redraw();
            ecFail.setExpanded(true);
        }
        // Create the statistical row
        TableItem item = new TableItem(this.amountTable, SWT.BORDER);
        item.setText(0, String.valueOf(noTotal));
        item.setText(1, String.valueOf(noOfPass + getPercent(noOfPass, noTotal)));
        item.setText(2, String.valueOf(noOfFail + getPercent(noOfFail, noTotal)));
        item.setText(3, String.valueOf(noOfInconc + getPercent(noOfInconc, noTotal)));
        item.setText(4, String.valueOf(noOfNone + getPercent(noOfNone, noTotal)));
        item.setText(5, String.valueOf(noOfError + getPercent(noOfError, noTotal)));
        item.setText(6, String.valueOf(noOfCrash + getPercent(noOfCrash, noTotal)));
    }
    if (statisticalDataVector.size() > 1) {
        // $NON-NLS-1$
        setPartName("Statistics");
        // $NON-NLS-1$
        setContentDescription("");
    } else if (this.logFileMetaData != null) {
        File file = new File(this.logFileMetaData.getFilePath());
        String fileName = file.getName();
        // Set the name of the part
        setPartName(fileName);
        setContentDescription(this.logFileMetaData.getProjectRelativePath());
    }
    // Finally redraw form
    form.reflow(true);
    form.setRedraw(true);
}
Also used : StatisticalData(org.eclipse.titan.log.viewer.views.details.StatisticalData) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) LogRecord(org.eclipse.titan.log.viewer.parsers.data.LogRecord) TableItem(org.eclipse.swt.widgets.TableItem) Image(org.eclipse.swt.graphics.Image) Section(org.eclipse.ui.forms.widgets.Section) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

LogRecord (org.eclipse.titan.log.viewer.parsers.data.LogRecord)21 ParseException (java.text.ParseException)9 EventObject (org.eclipse.titan.log.viewer.views.msc.model.EventObject)9 IFile (org.eclipse.core.resources.IFile)6 TableItem (org.eclipse.swt.widgets.TableItem)5 IOException (java.io.IOException)4 IProject (org.eclipse.core.resources.IProject)4 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)4 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)4 LogFileMetaData (org.eclipse.titan.log.viewer.models.LogFileMetaData)4 IViewReference (org.eclipse.ui.IViewReference)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 File (java.io.File)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 RecordParser (org.eclipse.titan.log.viewer.parsers.RecordParser)3 ExecutionModel (org.eclipse.titan.log.viewer.views.msc.model.ExecutionModel)3 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2