1 /******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.integration
.swtbot
.tests
.projectexplorer
;
12 import static org
.junit
.Assert
.assertTrue
;
15 import java
.io
.FileNotFoundException
;
16 import java
.io
.FileOutputStream
;
17 import java
.io
.IOException
;
18 import java
.io
.PrintWriter
;
20 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.LttngTraceGenerator
;
23 * Util class to create directory structures detailed in chapter 3 of the
26 * @author Matthew Khouzam
28 public class TestDirectoryStructureUtil
{
30 private static final String CUSTOM_TEXT_PARSER_CONTENT
= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
31 + "<CustomTxtTraceDefinitionList>"
32 + "<Definition name=\"TmfGeneric\">"
33 + "<TimeStampOutputFormat>yyyy-MM-dd HH:mm:ss.SSS</TimeStampOutputFormat>"
34 + "<InputLine><Cardinality max=\"2147483647\" min=\"0\"/>"
35 + "<RegEx>\\s*\\[(\\d*\\.\\d*)\\]\\s*\\[TID=(\\d*)\\]\\s*\\[(SIG|CMP|EVT|REQ)\\]\\s*(.*)</RegEx>"
36 + "<InputData action=\"0\" format=\"ss.SSS\" name=\"Time Stamp\"/>"
37 + "<InputData action=\"0\" format=\"\" name=\"Thread ID\"/>"
38 + "<InputData action=\"0\" format=\"\" name=\"Type\"/>"
39 + "<InputData action=\"0\" format=\"\" name=\"Message\"/>"
40 + "</InputLine><OutputColumn name=\"Time Stamp\"/>"
41 + "<OutputColumn name=\"Thread ID\"/>"
42 + "<OutputColumn name=\"Type\"/>"
43 + "<OutputColumn name=\"Message\"/>"
45 + "</CustomTxtTraceDefinitionList>";
47 private static final String CUSTOM_XML_PARSER_CONTENT
= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
48 + "<CustomXMLTraceDefinitionList><Definition name=\"Custom XML Log\">"
49 + "<TimeStampOutputFormat>yyyy-MM-dd HH:mm:ss.SSS</TimeStampOutputFormat>"
50 + "<InputElement name=\"Log\"><InputElement logentry=\"true\" name=\"Record\">"
51 + "<InputData action=\"0\" format=\"\" name=\"Ignore\"/>"
52 + "<Attribute name=\"number\"><InputData action=\"0\" format=\"\" name=\"Rec Num\"/>"
53 + "</Attribute><InputElement name=\"Time\">"
54 + "<InputData action=\"0\" format=\"'year:'yyyy | 'month:'MM | 'day:'dd | 'hour:'HH | 'minute:'mm | 'second:'ss\" name=\"Time Stamp\"/></InputElement>"
55 + "<InputElement name=\"Content\"><InputData action=\"0\" format=\"\" name=\"Message\"/></InputElement>"
56 + "</InputElement></InputElement><OutputColumn name=\"Time Stamp\"/>"
57 + "<OutputColumn name=\"Rec Num\"/><OutputColumn name=\"Message\"/>"
58 + "</Definition></CustomXMLTraceDefinitionList>";
60 private static final String CUSTOM_TEXT_LAST_LINE
= "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(end)\n";
61 private static final String CUSTOM_TEXT_CONTENT
= "[1371742192.034] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(start)\n" +
62 "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(end)\n" +
63 "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(start)\n" +
64 "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(end)\n" +
65 "[1371742192.048] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(start)\n" +
66 "[1371742192.048] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(end)\n" +
67 "[1371742192.049] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(start)\n" +
68 "[1371742192.049] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(end)\n" +
69 "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(start)\n" +
70 CUSTOM_TEXT_LAST_LINE
;
72 private static final String CUSTOM_XML_PARSER_LAST_LINE
= ""
73 + "<Record number = \"6\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 18 </minute> <second> 32 </second>" + "</Time>" + "<Content>" + "<Message>This is the message</Message>"
74 + "<Level>The Log Level</Level>" + "</Content>" + "</Record>";
75 private static final String CUSTOM_XML_CONTENT
= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
76 + "<!DOCTYPE Log SYSTEM \"ExampleXMLLog.dtd\">\r\n\r\n<Log>" + "<LogCreated>" + "<LogName> Example XML Log </LogName>" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>"
77 + "<hour> 22 </hour> <minute> 0 </minute> <second> 25 </second>" + "</Time>" + "</LogCreated>"
79 + "<Record number = \"1\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 1 </minute> <second> 20 </second>" + "</Time>" + "<Content>" + "<Message>This is the message</Message>"
80 + "<Level>The Log Level</Level>" + "</Content>" + "</Record>"
82 + "<Record number = \"2\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 2 </minute> <second> 11 </second>" + "</Time>" + "<Content>" + "<Message>This is the message</Message>"
83 + "<Level>The Log Level</Level>" + "" + "</Content>" + "</Record>"
85 + "<Record number = \"3\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 3 </minute> <second> 17 </second>" + "</Time>" + "<Content>"
86 + "<Message>This is the message</Message>" + "<Level>The Log Level</Level>" + "</Content>" + "</Record>"
88 + "<Record number = \"4\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 4 </minute> <second> 30 </second>" + "</Time>"
89 + "<Content>" + "<Message>This is the message</Message>" + "<Level>The Log Level</Level>" + "</Content>" + "</Record>"
91 + "<Record number = \"5\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 5 </minute> <second> 17 </second>" + "</Time>" + "<Content>" + "<Message>This is the message</Message>"
92 + "<Level>The Log Level</Level>" + "</Content>" + "</Record>"
93 + CUSTOM_XML_PARSER_LAST_LINE
;
95 private static final String UNRECOGNIZED_LOG_CONTENT
= "Hi mom!";
97 private TestDirectoryStructureUtil() {
102 * Generate a directory structure as follows
107 * │ ├── ExampleCustomTxtParser.xml
108 * │ └── ExampleCustomXmlParser.xml
111 * │ ├── ExampleCustomTxt.log
112 * │ ├── ExampleCustomXml.xml
113 * │ ├── kernel-overlap-testing
116 * │ ├── simple_server-thread1
119 * │ ├── simple_server-thread2
122 * │ └── ust-overlap-testing
126 * ├── ExampleCustomTxt.log
127 * ├── ExampleCustomXml.xml
128 * ├── kernel-overlap-testing
131 * ├── simple_server-thread1
134 * ├── simple_server-thread2
137 * ├── unrecognized.log
138 * └── ust-overlap-testing
144 * the directory to use as the parent
145 * @return the structure detailed above
146 * @throws IOException
147 * out of space or permission problem
149 public static File
generateTraceStructure(File parentDir
) throws IOException
{
150 File parent
= (parentDir
== null) ? File
.createTempFile("Traces", "") : parentDir
;
151 if (!parent
.isDirectory()) {
155 File customParser
= createDir(parent
, "customParsers");
156 createFile(customParser
, "ExampleCustomTxtParser.xml", CUSTOM_TEXT_PARSER_CONTENT
);
157 createFile(customParser
, "ExampleCustomXmlParser.xml", CUSTOM_XML_PARSER_CONTENT
);
158 File importDir
= createDir(parent
, "import");
159 createDir(importDir
, "empty");
160 createFile(importDir
, "ExampleCustomTxt.log", CUSTOM_TEXT_CONTENT
);
161 createFile(importDir
, "ExampleCustomXml.xml", CUSTOM_XML_CONTENT
);
162 createFile(importDir
, "unrecognized.log", UNRECOGNIZED_LOG_CONTENT
);
163 // Using the z- prefix so that the traces in this folder are imported
164 // last by the import wizard
165 final String CLASHES_DIR_NAME
= "z-clashes";
166 File theClash
= createDir(importDir
, CLASHES_DIR_NAME
);
168 // We're making the clash version of each trace slightly different in content to help differentiate them
169 createFile(theClash
, "ExampleCustomTxt.log", CUSTOM_TEXT_CONTENT
+ CUSTOM_TEXT_LAST_LINE
);
170 createFile(theClash
, "ExampleCustomXml.xml", CUSTOM_XML_CONTENT
+ CUSTOM_XML_PARSER_LAST_LINE
);
172 LttngTraceGenerator kernelGenerator
= new LttngTraceGenerator(1000, 1000, 1);
173 LttngTraceGenerator ustGenerator
= new LttngTraceGenerator(1000, 1000, 1, false);
174 kernelGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ "kernel-overlap-testing"));
175 ustGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ "ust-overlap-testing"));
176 ustGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ "simple_server-thread1"));
177 ustGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ "simple_server-thread2"));
179 kernelGenerator
= new LttngTraceGenerator(1000, 1001, 1);
180 ustGenerator
= new LttngTraceGenerator(1000, 1001, 1, false);
181 kernelGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ CLASHES_DIR_NAME
+ File
.separator
+ "kernel-overlap-testing"));
182 ustGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ CLASHES_DIR_NAME
+ File
.separator
+ "ust-overlap-testing"));
183 ustGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ CLASHES_DIR_NAME
+ File
.separator
+ "simple_server-thread1"));
184 ustGenerator
.writeTrace(new File(importDir
.getAbsolutePath() + File
.separator
+ CLASHES_DIR_NAME
+ File
.separator
+ "simple_server-thread2"));
186 assertTrue(parent
.listFiles().length
> 0);
191 private static File
createDir(File parent
, String name
) {
192 File child
= new File(parent
.getAbsolutePath() + File
.separator
+ name
);
197 private static File
createFile(File parent
, String name
, String content
) throws FileNotFoundException
{
198 File child
= new File(parent
.getAbsolutePath() + File
.separator
+ name
);
199 try (PrintWriter pw
= new PrintWriter(new FileOutputStream(child
))) {