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 | ||
60 | private static final String CUSTOM_TEXT_CONTENT = "[1371742192.034] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(start)\n" + | |
61 | "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(end)\n" + | |
62 | "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(start)\n" + | |
63 | "[1371742192.048] [TID=001] [SIG] Sig=TmfStartSynchSignal Target=(end)\n" + | |
64 | "[1371742192.048] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(start)\n" + | |
65 | "[1371742192.048] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(end)\n" + | |
66 | "[1371742192.049] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(start)\n" + | |
67 | "[1371742192.049] [TID=001] [SIG] Sig=TmfTimestampFormatUpdateSignal Target=(end)\n" + | |
68 | "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(start)\n" + | |
69 | "[1371742192.049] [TID=001] [SIG] Sig=TmfEndSynchSignal Target=(end)\n"; | |
70 | ||
71 | private static final String CUSTOM_XML_CONTENT = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" | |
72 | + "<!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>" | |
73 | + "<hour> 22 </hour> <minute> 0 </minute> <second> 25 </second>" + "</Time>" + "</LogCreated>" | |
74 | + "" | |
75 | + "<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>" | |
76 | + "<Level>The Log Level</Level>" + "</Content>" + "</Record>" | |
77 | + "" | |
78 | + "<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>" | |
79 | + "<Level>The Log Level</Level>" + "" + "</Content>" + "</Record>" | |
80 | + "" | |
81 | + "<Record number = \"3\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 3 </minute> <second> 17 </second>" + "</Time>" + "<Content>" | |
82 | + "<Message>This is the message</Message>" + "<Level>The Log Level</Level>" + "</Content>" + "</Record>" | |
83 | + "" | |
84 | + "<Record number = \"4\">" + "<Time>" + "<year> 2011 </year> <month> 10 </month> <day> 26 </day>" + "<hour> 22 </hour> <minute> 4 </minute> <second> 30 </second>" + "</Time>" | |
85 | + "<Content>" + "<Message>This is the message</Message>" + "<Level>The Log Level</Level>" + "</Content>" + "</Record>" | |
86 | + "" | |
87 | + "<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>" | |
88 | + "<Level>The Log Level</Level>" + "</Content>" + "</Record>" | |
89 | + "" | |
90 | + "<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>" | |
91 | + "<Level>The Log Level</Level>" + "</Content>" + "</Record>"; | |
92 | ||
93 | private static final String UNRECOGNIZED_LOG_CONTENT = "Hi mom!"; | |
94 | ||
95 | private TestDirectoryStructureUtil() { | |
96 | // do nothing | |
97 | } | |
98 | ||
99 | /** | |
100 | * Generate a directory structure as follows | |
101 | * | |
102 | * <pre> | |
103 | * parentDir | |
104 | * ├── customParsers | |
105 | * │ ├── ExampleCustomTxtParser.xml | |
106 | * │ └── ExampleCustomXmlParser.xml | |
107 | * └── import | |
108 | * ├── clashes | |
109 | * │ ├── ExampleCustomTxt.log | |
110 | * │ ├── ExampleCustomXml.xml | |
111 | * │ ├── kernel-overlap-testing | |
112 | * │ │ ├── stream | |
113 | * │ │ └── metadata | |
114 | * │ ├── simple_server-thread1 | |
115 | * │ │ ├── stream | |
116 | * │ │ └── metadata | |
117 | * │ ├── simple_server-thread2 | |
118 | * │ │ ├── stream | |
119 | * │ │ └── metadata | |
120 | * │ └── ust-overlap-testing | |
121 | * │ ├── stream | |
122 | * │ └── metadata | |
123 | * ├── empty | |
124 | * ├── ExampleCustomTxt.log | |
125 | * ├── ExampleCustomXml.xml | |
126 | * ├── kernel-overlap-testing | |
127 | * │ ├── stream | |
128 | * │ └── metadata | |
129 | * ├── simple_server-thread1 | |
130 | * │ ├── metadata | |
131 | * │ └── stream | |
132 | * ├── simple_server-thread2 | |
133 | * │ ├── metadata | |
134 | * │ └── stream | |
135 | * ├── unrecognized.log | |
136 | * └── ust-overlap-testing | |
137 | * ├── stream | |
138 | * └── metadata | |
139 | * </pre> | |
140 | * | |
141 | * @param parentDir | |
142 | * the directory to use as the parent | |
143 | * @return the structure detailed above | |
144 | * @throws IOException | |
145 | * out of space or permission problem | |
146 | */ | |
147 | public static File generateTraceStructure(File parentDir) throws IOException { | |
148 | File parent = (parentDir == null) ? File.createTempFile("Traces", "") : parentDir; | |
149 | if (!parent.isDirectory()) { | |
150 | parent.delete(); | |
151 | parent.mkdir(); | |
152 | } | |
153 | File customParser = createDir(parent, "customParsers"); | |
154 | createFile(customParser, "ExampleCustomTxtParser.xml", CUSTOM_TEXT_PARSER_CONTENT); | |
155 | createFile(customParser, "ExampleCustomXmlParser.xml", CUSTOM_XML_PARSER_CONTENT); | |
156 | File importDir = createDir(parent, "import"); | |
157 | createDir(importDir, "empty"); | |
158 | createFile(importDir, "ExampleCustomTxt.log", CUSTOM_TEXT_CONTENT); | |
159 | createFile(importDir, "ExampleCustomXml.xml", CUSTOM_XML_CONTENT); | |
160 | createFile(importDir, "unrecognized.log", UNRECOGNIZED_LOG_CONTENT); | |
161 | File theClash = createDir(importDir, "clashes"); | |
162 | createFile(theClash, "ExampleCustomTxt.log", CUSTOM_TEXT_CONTENT); | |
163 | createFile(theClash, "ExampleCustomXml.xml", CUSTOM_XML_CONTENT); | |
164 | ||
165 | LttngTraceGenerator kernelGenerator = new LttngTraceGenerator(1000, 1000, 1); | |
166 | LttngTraceGenerator ustGenerator = new LttngTraceGenerator(1000, 1000, 1, false); | |
167 | kernelGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "kernel-overlap-testing")); | |
168 | ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "ust-overlap-testing")); | |
169 | ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "simple_server-thread1")); | |
170 | ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "simple_server-thread2")); | |
171 | ||
172 | kernelGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "kernel-overlap-testing")); | |
173 | ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "ust-overlap-testing")); | |
174 | ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "simple_server-thread1")); | |
175 | ustGenerator.writeTrace(new File(importDir.getAbsolutePath() + File.separator + "clashes" + File.separator + "simple_server-thread2")); | |
176 | ||
177 | assertTrue(parent.listFiles().length > 0); | |
178 | ||
179 | return parent; | |
180 | } | |
181 | ||
182 | private static File createDir(File parent, String name) { | |
183 | File child = new File(parent.getAbsolutePath() + File.separator + name); | |
184 | child.mkdir(); | |
185 | return child; | |
186 | } | |
187 | ||
188 | private static File createFile(File parent, String name, String content) throws FileNotFoundException { | |
189 | File child = new File(parent.getAbsolutePath() + File.separator + name); | |
190 | try (PrintWriter pw = new PrintWriter(new FileOutputStream(child))) { | |
191 | pw.write(content); | |
192 | } | |
193 | return child; | |
194 | } | |
195 | } |