Skip to content

Commit

Permalink
Add validation tests for binary FTrace parser
Browse files Browse the repository at this point in the history
This commit adds new unit tests that validate various sample test traces
using the new implementation of the binary FTrace parser that parses the
binary trace files directly without converting the files to text format.

The new tests detect an unhandled NumberFormatException while parsing
the trace version. Hence, this commit also includes a patch to handle
such exception.

Change-Id: Icaaa47d544f1a92cdc2eeabc7cfab3dcd3b51105
Signed-off-by: Hoang Thuan Pham <hoang.pham@calian.ca>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/190837
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
hoangphamEclipse authored and MatthewKhouzam committed Feb 23, 2022
1 parent b912f84 commit d7171d5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
@@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.incubator.ftrace.core.tests.trace;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.tracecompass.incubator.ftrace.core.tests.shared.FTraceUtils;
import org.eclipse.tracecompass.incubator.internal.ftrace.core.trace.BinaryFTrace;
import org.eclipse.tracecompass.testtraces.ftrace.FtraceTestTrace;
import org.junit.Test;

/**
* Tests for {@link BinaryFTrace}
*
* @author Hoang Thuan Pham
*/
public class BinaryFTraceTest {
private static final String NON_EXISTING_PATH = "/wrong/path/no_trace.dat";

/**
* Test validation of a valid trace
*
* @throws IOException
* If an error occurred while validating the file
*/
@Test
public void testValidTrace() throws IOException {
BinaryFTrace ftraceTrace = new BinaryFTrace();
String validTracePath = FTraceUtils.getTraceAbsolutePath(FtraceTestTrace.TEST_2_6_MULTIPLE_CPUS);
IStatus goodStatus = ftraceTrace.validate(null, validTracePath);
assertEquals(0, goodStatus.getSeverity());
ftraceTrace.dispose();
}

/**
* Test validation of an invalid trace
*
* @throws IOException
* If an error occurred while validating the file
*/
@Test
public void testInvalidTrace() throws IOException {
BinaryFTrace ftraceTrace = new BinaryFTrace();
String invalidTracePath = FTraceUtils.getTraceAbsolutePath(FtraceTestTrace.TEST_2_6_INVALID);
IStatus invalidStatus = ftraceTrace.validate(null, invalidTracePath);
assertEquals(0x04, invalidStatus.getSeverity());
ftraceTrace.dispose();
}

/**
* Test validation using file that does not exist
*/
@Test
public void testValidateFileDoesNotExist() {
BinaryFTrace ftraceTrace = new BinaryFTrace();
IStatus status = ftraceTrace.validate(null, NON_EXISTING_PATH);
assertEquals(0x04, status.getSeverity());
ftraceTrace.dispose();
}
}
Expand Up @@ -139,7 +139,7 @@ private static BinaryFTraceVersionHeader getMagicValuesAndFtraceVersion(BinaryFT
int ftraceVersionInt = Integer.parseInt(buffer.getNextString().trim());
BinaryFTraceVersion ftraceVersionEnum = BinaryFTraceVersion.getVersionAsEnum(ftraceVersionInt);
return new BinaryFTraceVersionHeader(bytes, ftraceVersionEnum);
} catch (IOException e) {
} catch (IOException | NumberFormatException e) {
throw new TmfTraceException("Cannot parse the magic values and FTrace version. Make sure you use trace-cmd v.2.9 and above.", e); //$NON-NLS-1$
}
}
Expand Down

0 comments on commit d7171d5

Please sign in to comment.