From 11e4be4eba651db34843bf82fe94158b6d4bb3b4 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Sun, 17 Nov 2013 13:28:14 -0500 Subject: [PATCH] ctf: Move CTF-testsuite tests to a separate file Change-Id: I0ebbe99f577430c16388ee6619d7a4d3a98044ae Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/18478 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Tested-by: Matthew Khouzam --- .../META-INF/MANIFEST.MF | 1 + .../ctf/core/tests/AllCtfCoreTests.java | 1 + .../tests/ctftestsuite/CtfTestSuiteTest.java | 102 ++++++++++++++++++ .../ctf/core/tests/ctftestsuite/TestAll.java | 31 ++++++ .../ctf/core/tests/trace/CTFTraceTest.java | 71 ------------ 5 files changed, 135 insertions(+), 71 deletions(-) create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/CtfTestSuiteTest.java create mode 100644 org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/TestAll.java diff --git a/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF index e478054115..c4f571e94e 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.ctf.core.tests/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Require-Bundle: org.junit;bundle-version="4.0.0", org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.linuxtools.ctf.core;bundle-version="3.0.0" Export-Package: org.eclipse.linuxtools.ctf.core.tests;x-friends:="org.eclipse.linuxtools.lttng.alltests", + org.eclipse.linuxtools.ctf.core.tests.ctftestsuite;x-internal:=true, org.eclipse.linuxtools.ctf.core.tests.event;x-internal:=true, org.eclipse.linuxtools.ctf.core.tests.headless;x-internal:=true, org.eclipse.linuxtools.ctf.core.tests.io;x-internal:=true, diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java index 83a31536cb..b4867d9eba 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java @@ -25,6 +25,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ CtfCorePluginTest.class, + org.eclipse.linuxtools.ctf.core.tests.ctftestsuite.TestAll.class, org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class, org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class, org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class, diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/CtfTestSuiteTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/CtfTestSuiteTest.java new file mode 100644 index 0000000000..e9b076091c --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/CtfTestSuiteTest.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2013 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 - Moved out of CTFTestTrace + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.tests.ctftestsuite; + +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.io.File; + +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.junit.Test; + +/** + * Test class running the CTF Test Suite + * (from https://github.com/efficios/ctf-testsuite). + * + * @author Matthew Khouzam + */ +public class CtfTestSuiteTest { + + private static final String TRACES_DIRECTORY = "../org.eclipse.linuxtools.ctf.core.tests/traces"; + private static final String METADATA_FILENAME = "metadata"; + + private static final String CTF_VERSION_NUMBER = "1.8"; + private static final String CTF_SUITE_TEST_DIRECTORY = "ctf-testsuite/tests/" + CTF_VERSION_NUMBER; + + /** + * Open traces in specified directories and expect them to fail + * + * @throws CTFReaderException not expected + */ + @Test + public void testFailedParse() throws CTFReaderException { + parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/fail"), true); + } + + /** + * Open traces in specified directories and expect them to succeed + * + * @throws CTFReaderException not expected + */ + @Test + public void testSuccessfulParse() throws CTFReaderException { + parseTracesInDirectory(getTestTracesSubDirectory("kernel"), false); + parseTracesInDirectory(getTestTracesSubDirectory("trace2"), false); + parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/pass"), false); + } + + + /** + * Get the File object for the subDir in the traces directory. If the sub directory doesn't exist, the test is skipped. + */ + private static File getTestTracesSubDirectory(String subDir) { + File file = new File(TRACES_DIRECTORY + "/" + subDir); + assumeTrue(file.isDirectory()); + return file; + } + + /** + * Parse the traces in given directory recursively + * + * @param directory The directory to search in + * @param expectException Whether or not traces in this directory are expected to throw an exception when parsed + * @throws CTFReaderException + */ + void parseTracesInDirectory(File directory, boolean expectException) throws CTFReaderException { + for (File file : directory.listFiles()) { + if (file.getName().equals(METADATA_FILENAME)) { + try { + new CTFTrace(directory); + if (expectException) { + fail("Trace was expected to fail parsing: " + directory); + } + } catch (RuntimeException e) { + if (!expectException) { + throw new CTFReaderException("Failed parsing " + directory, e); + } + } catch (CTFReaderException e) { + if (!expectException) { + throw new CTFReaderException("Failed parsing " + directory, e); + } + } + return; + } + + if (file.isDirectory()) { + parseTracesInDirectory(file, expectException); + } + } + } +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/TestAll.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/TestAll.java new file mode 100644 index 0000000000..032f53257a --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/ctftestsuite/TestAll.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2013 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.ctf.core.tests.ctftestsuite; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The class TestAll builds a suite that can be used to run all of + * the tests within its package as well as within any subpackages of its + * package. + * + * @author ematkho + * @version $Revision: 1.0 $ + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CtfTestSuiteTest.class +}) +public class TestAll { + +} diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java index 0fd73cb3ed..aebf35ea24 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java @@ -45,15 +45,8 @@ import org.junit.Test; */ public class CTFTraceTest { - private static final String TRACES_DIRECTORY = "../org.eclipse.linuxtools.ctf.core.tests/traces"; - - private static final String METADATA_FILENAME = "metadata"; - private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; - private static final String CTF_VERSION_NUMBER = "1.8"; - private static final String CTF_SUITE_TEST_DIRECTORY = "ctf-testsuite/tests/" + CTF_VERSION_NUMBER; - private CTFTrace fixture; /** @@ -401,70 +394,6 @@ public class CTFTraceTest { assertNotNull(result); } - /** - * Open traces in specified directories and expect them to fail - * - * @throws CTFReaderException not expected - */ - @Test - public void testFailedParse() throws CTFReaderException { - parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/fail"), true); - } - - /** - * Open traces in specified directories and expect them to succeed - * - * @throws CTFReaderException not expected - */ - @Test - public void testSuccessfulParse() throws CTFReaderException { - parseTracesInDirectory(getTestTracesSubDirectory("kernel"), false); - parseTracesInDirectory(getTestTracesSubDirectory("trace2"), false); - parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/pass"), false); - } - - /** - * Get the File object for the subDir in the traces directory. If the sub directory doesn't exist, the test is skipped. - */ - private static File getTestTracesSubDirectory(String subDir) { - File file = new File(TRACES_DIRECTORY + "/" + subDir); - assumeTrue(file.isDirectory()); - return file; - } - - /** - * Parse the traces in given directory recursively - * - * @param directory The directory to search in - * @param expectException Whether or not traces in this directory are expected to throw an exception when parsed - * @throws CTFReaderException - */ - void parseTracesInDirectory(File directory, boolean expectException) throws CTFReaderException { - for (File file : directory.listFiles()) { - if (file.getName().equals(METADATA_FILENAME)) { - try { - new CTFTrace(directory); - if (expectException) { - fail("Trace was expected to fail parsing: " + directory); - } - } catch (RuntimeException e) { - if (!expectException) { - throw new CTFReaderException("Failed parsing " + directory, e); - } - } catch (CTFReaderException e) { - if (!expectException) { - throw new CTFReaderException("Failed parsing " + directory, e); - } - } - return; - } - - if (file.isDirectory()) { - parseTracesInDirectory(file, expectException); - } - } - } - /** * Test for getCallsite(eventName, ip) * @throws CTFReaderException not expected -- 2.34.1