ctf: Move CTF-testsuite tests to a separate file
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / ctftestsuite / CtfTestSuiteTest.java
1 /*******************************************************************************
2 * Copyright (c) 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 - Moved out of CTFTestTrace
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.ctf.core.tests.ctftestsuite;
14
15 import static org.junit.Assert.fail;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.io.File;
19
20 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
21 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
22 import org.junit.Test;
23
24 /**
25 * Test class running the CTF Test Suite
26 * (from https://github.com/efficios/ctf-testsuite).
27 *
28 * @author Matthew Khouzam
29 */
30 public class CtfTestSuiteTest {
31
32 private static final String TRACES_DIRECTORY = "../org.eclipse.linuxtools.ctf.core.tests/traces";
33 private static final String METADATA_FILENAME = "metadata";
34
35 private static final String CTF_VERSION_NUMBER = "1.8";
36 private static final String CTF_SUITE_TEST_DIRECTORY = "ctf-testsuite/tests/" + CTF_VERSION_NUMBER;
37
38 /**
39 * Open traces in specified directories and expect them to fail
40 *
41 * @throws CTFReaderException not expected
42 */
43 @Test
44 public void testFailedParse() throws CTFReaderException {
45 parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/fail"), true);
46 }
47
48 /**
49 * Open traces in specified directories and expect them to succeed
50 *
51 * @throws CTFReaderException not expected
52 */
53 @Test
54 public void testSuccessfulParse() throws CTFReaderException {
55 parseTracesInDirectory(getTestTracesSubDirectory("kernel"), false);
56 parseTracesInDirectory(getTestTracesSubDirectory("trace2"), false);
57 parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/pass"), false);
58 }
59
60
61 /**
62 * Get the File object for the subDir in the traces directory. If the sub directory doesn't exist, the test is skipped.
63 */
64 private static File getTestTracesSubDirectory(String subDir) {
65 File file = new File(TRACES_DIRECTORY + "/" + subDir);
66 assumeTrue(file.isDirectory());
67 return file;
68 }
69
70 /**
71 * Parse the traces in given directory recursively
72 *
73 * @param directory The directory to search in
74 * @param expectException Whether or not traces in this directory are expected to throw an exception when parsed
75 * @throws CTFReaderException
76 */
77 void parseTracesInDirectory(File directory, boolean expectException) throws CTFReaderException {
78 for (File file : directory.listFiles()) {
79 if (file.getName().equals(METADATA_FILENAME)) {
80 try {
81 new CTFTrace(directory);
82 if (expectException) {
83 fail("Trace was expected to fail parsing: " + directory);
84 }
85 } catch (RuntimeException e) {
86 if (!expectException) {
87 throw new CTFReaderException("Failed parsing " + directory, e);
88 }
89 } catch (CTFReaderException e) {
90 if (!expectException) {
91 throw new CTFReaderException("Failed parsing " + directory, e);
92 }
93 }
94 return;
95 }
96
97 if (file.isDirectory()) {
98 parseTracesInDirectory(file, expectException);
99 }
100 }
101 }
102 }
This page took 0.031785 seconds and 5 git commands to generate.