From b71189e03c0c31311991183d2c0607e420bef4fc Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Thu, 25 Aug 2016 22:53:20 -0400 Subject: [PATCH] Add file util to create dummy structures This will help with section 3 of the tests for the project view Change-Id: I3274efa67838296228e7a810eedd84c4a470ec9b Signed-off-by: Matthew Khouzam Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/78568 Reviewed-by: Hudson CI --- .../META-INF/MANIFEST.MF | 3 + .../TestDirectoryStructureUtil.java | 195 ++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF b/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF index d2f5851d2b..f9311a08dd 100644 --- a/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF @@ -7,3 +7,6 @@ Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.tracecompass.integration.swtbot.tests;singleton:=true Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer +Require-Bundle: org.eclipse.tracecompass.ctf.core.tests, + org.junit diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java new file mode 100644 index 0000000000..aa3c7d314c --- /dev/null +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java @@ -0,0 +1,195 @@ +/****************************************************************************** + * Copyright (c) 2016 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 + *******************************************************************************/ + +package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.eclipse.tracecompass.ctf.core.tests.shared.LttngTraceGenerator; + +/** + * Util class to create directory structures detailed in chapter 3 of the + * projectView test + * + * @author Matthew Khouzam + */ +public class TestDirectoryStructureUtil { + + private static final String CUSTOM_TEXT_PARSER_CONTENT = "" + + "" + + "" + + "yyyy-MM-dd HH:mm:ss.SSS" + + "" + + "\\s*\\[(\\d*\\.\\d*)\\]\\s*\\[TID=(\\d*)\\]\\s*\\[(SIG|CMP|EVT|REQ)\\]\\s*(.*)" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String CUSTOM_XML_PARSER_CONTENT = "" + + "" + + "yyyy-MM-dd HH:mm:ss.SSS" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String CUSTOM_TEXT_CONTENT = "[1371742192.034] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(start)\n" + + "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(end)\n" + + "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(start)\n" + + "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(end)\n" + + "[1371742192.048] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(start)\n" + + "[1371742192.048] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(end)\n" + + "[1371742192.049] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(start)\n" + + "[1371742192.049] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(end)\n" + + "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(start)\n" + + "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(end)\n"; + + private static final String CUSTOM_XML_CONTENT = "" + + "\r\n\r\n" + "" + " Example XML Log " + "" + "" + + "" + + "" + "" + "" + "This is the message" + + "The Log Level" + "" + "" + + "" + + "" + "" + "" + "This is the message" + + "The Log Level" + "" + "" + "" + + "" + + "" + "" + "" + + "This is the message" + "The Log Level" + "" + "" + + "" + + "" + "" + + "" + "This is the message" + "The Log Level" + "" + "" + + "" + + "" + "" + "" + "This is the message" + + "The Log Level" + "" + "" + + "" + + "" + "" + "" + "This is the message" + + "The Log Level" + "" + ""; + + private static final String UNRECOGNIZED_LOG_CONTENT = "Hi mom!"; + + private TestDirectoryStructureUtil() { + // do nothing + } + + /** + * Generate a directory structure as follows + * + *
+     * parentDir
+     *  ├── customParsers
+     *  │   ├── ExampleCustomTxtParser.xml
+     *  │   └── ExampleCustomXmlParser.xml
+     *  └── import
+     *      ├── clashes
+     *      │   ├── ExampleCustomTxt.log
+     *      │   ├── ExampleCustomXml.xml
+     *      │   ├── kernel-overlap-testing
+     *      │   │   ├── stream
+     *      │   │   └── metadata
+     *      │   ├── simple_server-thread1
+     *      │   │   ├── stream
+     *      │   │   └── metadata
+     *      │   ├── simple_server-thread2
+     *      │   │   ├── stream
+     *      │   │   └── metadata
+     *      │   └── ust-overlap-testing
+     *      │       ├── stream
+     *      │       └── metadata
+     *      ├── empty
+     *      ├── ExampleCustomTxt.log
+     *      ├── ExampleCustomXml.xml
+     *      ├── kernel-overlap-testing
+     *      │   ├── stream
+     *      │   └── metadata
+     *      ├── simple_server-thread1
+     *      │   ├── metadata
+     *      │   └── stream
+     *      ├── simple_server-thread2
+     *      │   ├── metadata
+     *      │   └── stream
+     *      ├── unrecognized.log
+     *      └── ust-overlap-testing
+     *          ├── stream
+     *          └── metadata
+     * 
+ * + * @param parentDir + * the directory to use as the parent + * @return the structure detailed above + * @throws IOException + * out of space or permission problem + */ + public static File generateTraceStructure(File parentDir) throws IOException { + File parent = (parentDir == null) ? File.createTempFile("Traces", "") : parentDir; + if (!parent.isDirectory()) { + parent.delete(); + parent.mkdir(); + } + File customParser = createDir(parent, "customParsers"); + createFile(customParser, "ExampleCustomTxtParser.xml", CUSTOM_TEXT_PARSER_CONTENT); + createFile(customParser, "ExampleCustomXmlParser.xml", CUSTOM_XML_PARSER_CONTENT); + File importDir = createDir(parent, "import"); + createDir(importDir, "empty"); + createFile(importDir, "ExampleCustomTxt.log", CUSTOM_TEXT_CONTENT); + createFile(importDir, "ExampleCustomXml.xml", CUSTOM_XML_CONTENT); + createFile(importDir, "unrecognized.log", UNRECOGNIZED_LOG_CONTENT); + File theClash = createDir(importDir, "clashes"); + createFile(theClash, "ExampleCustomTxt.log", CUSTOM_TEXT_CONTENT); + createFile(theClash, "ExampleCustomXml.xml", CUSTOM_XML_CONTENT); + + LttngTraceGenerator kernelGenerator = new LttngTraceGenerator(1000, 1000, 1); + LttngTraceGenerator ustGenerator = new LttngTraceGenerator(1000, 1000, 1, false); + kernelGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "kernel-overlap-testing")); + ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "ust-overlap-testing")); + ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "simple_server-thread1")); + ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "simple_server-thread2")); + + kernelGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "kernel-overlap-testing")); + ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "ust-overlap-testing")); + ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "simple_server-thread1")); + ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "simple_server-thread2")); + + assertTrue(parent.listFiles().length > 0); + + return parent; + } + + private static File createDir(File parent, String name) { + File child = new File(parent.getAbsolutePath() + File.separator + name); + child.mkdir(); + return child; + } + + private static File createFile(File parent, String name, String content) throws FileNotFoundException { + File child = new File(parent.getAbsolutePath() + File.separator + name); + try (PrintWriter pw = new PrintWriter(new FileOutputStream(child))) { + pw.write(content); + } + return child; + } +} -- 2.34.1