Commit | Line | Data |
---|---|---|
b71189e0 MAL |
1 | /****************************************************************************** |
2 | * Copyright (c) 2016 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 | ||
10 | package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer; | |
11 | ||
12 | import static org.junit.Assert.assertTrue; | |
13 | ||
14 | import java.io.File; | |
15 | import java.io.FileNotFoundException; | |
16 | import java.io.FileOutputStream; | |
17 | import java.io.IOException; | |
18 | import java.io.PrintWriter; | |
19 | ||
20 | import org.eclipse.tracecompass.ctf.core.tests.shared.LttngTraceGenerator; | |
21 | ||
22 | /** | |
23 | * Util class to create directory structures detailed in chapter 3 of the | |
24 | * projectView test | |
25 | * | |
26 | * @author Matthew Khouzam | |
27 | */ | |
28 | public class TestDirectoryStructureUtil { | |
29 | ||
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\"/>" | |
44 | + "</Definition>" | |
45 | + "</CustomTxtTraceDefinitionList>"; | |
46 | ||
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>"; | |
59 | ||
ab18f69a | 60 | private static final String CUSTOM_TEXT_LAST_LINE = "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(end)\n"; |
b71189e0 MAL |
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" + | |
ab18f69a | 70 | CUSTOM_TEXT_LAST_LINE; |
b71189e0 | 71 | |
ab18f69a MAL |
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>"; | |
b71189e0 MAL |
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>" | |
78 | + "" | |
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>" | |
81 | + "" | |
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>" | |
84 | + "" | |
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>" | |
87 | + "" | |
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>" | |
90 | + "" | |
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>" | |
ab18f69a | 93 | + CUSTOM_XML_PARSER_LAST_LINE; |
b71189e0 MAL |
94 | |
95 | private static final String UNRECOGNIZED_LOG_CONTENT = "Hi mom!"; | |
96 | ||
97 | private TestDirectoryStructureUtil() { | |
98 | // do nothing | |
99 | } | |
100 | ||
101 | /** | |
102 | * Generate a directory structure as follows | |
103 | * | |
104 | * <pre> | |
105 | * parentDir | |
106 | * ├── customParsers | |
107 | * │ ├── ExampleCustomTxtParser.xml | |
108 | * │ └── ExampleCustomXmlParser.xml | |
109 | * └── import | |
ab18f69a | 110 | * ├── z-clashes |
b71189e0 MAL |
111 | * │ ├── ExampleCustomTxt.log |
112 | * │ ├── ExampleCustomXml.xml | |
113 | * │ ├── kernel-overlap-testing | |
114 | * │ │ ├── stream | |
115 | * │ │ └── metadata | |
116 | * │ ├── simple_server-thread1 | |
117 | * │ │ ├── stream | |
118 | * │ │ └── metadata | |
119 | * │ ├── simple_server-thread2 | |
120 | * │ │ ├── stream | |
121 | * │ │ └── metadata | |
122 | * │ └── ust-overlap-testing | |
123 | * │ ├── stream | |
124 | * │ └── metadata | |
125 | * ├── empty | |
126 | * ├── ExampleCustomTxt.log | |
127 | * ├── ExampleCustomXml.xml | |
128 | * ├── kernel-overlap-testing | |
129 | * │ ├── stream | |
130 | * │ └── metadata | |
131 | * ├── simple_server-thread1 | |
132 | * │ ├── metadata | |
133 | * │ └── stream | |
134 | * ├── simple_server-thread2 | |
135 | * │ ├── metadata | |
136 | * │ └── stream | |
137 | * ├── unrecognized.log | |
138 | * └── ust-overlap-testing | |
139 | * ├── stream | |
140 | * └── metadata | |
141 | * </pre> | |
142 | * | |
143 | * @param parentDir | |
144 | * the directory to use as the parent | |
145 | * @return the structure detailed above | |
146 | * @throws IOException | |
147 | * out of space or permission problem | |
148 | */ | |
149 | public static File generateTraceStructure(File parentDir) throws IOException { | |
150 | File parent = (parentDir == null) ? File.createTempFile("Traces", "") : parentDir; | |
151 | if (!parent.isDirectory()) { | |
152 | parent.delete(); | |
153 | parent.mkdir(); | |
154 | } | |
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); | |
ab18f69a MAL |
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); | |
167 | ||
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); | |
b71189e0 MAL |
171 | |
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")); | |
178 | ||
ab18f69a MAL |
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")); | |
b71189e0 MAL |
185 | |
186 | assertTrue(parent.listFiles().length > 0); | |
187 | ||
188 | return parent; | |
189 | } | |
190 | ||
191 | private static File createDir(File parent, String name) { | |
192 | File child = new File(parent.getAbsolutePath() + File.separator + name); | |
193 | child.mkdir(); | |
194 | return child; | |
195 | } | |
196 | ||
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))) { | |
200 | pw.write(content); | |
201 | } | |
202 | return child; | |
203 | } | |
204 | } |