1 '''
2 Peach Logging System
3
4 This is the Peach logging sub-system. To implement a new logging method
5 extend from Logger.
6
7 @author: Michael Eddington
8 @version: $Id: logger.py 1051 2008-07-17 04:52:54Z meddingt $
9 '''
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 from Engine.engine import EngineWatcher
39
41 '''
42 Parent class for all logger implementations.
43 '''
44
46 '''
47 Called when a run is starting.
48 '''
49 pass
50
52 '''
53 Called when a run is finished.
54 '''
55 pass
56
58 '''
59 Called on start of a test. Each test has multiple variations.
60 '''
61 pass
62
64 '''
65 Called on completion of a test.
66 '''
67 pass
68
70 '''
71 Called on start of a test case.
72 '''
73 pass
74
76 '''
77 Called when data is received from test case.
78 '''
79 pass
80
82 '''
83 Called when an exception occurs during a test case.
84 '''
85 pass
86
88 '''
89 Called when a test case has completed.
90 '''
91 pass
92
93 - def OnFault(self, run, test, variationCount, monitorData, value):
95
96 - def OnStopRun(self, run, test, variationCount, monitorData, value):
98
99 import os,uuid
100 from time import *
101
103 '''
104 A file system logger.
105 '''
106
108 self.name = str(uuid.uuid1())
109 self.elementType = 'logger'
110 self.params = params
111 self.heartBeat = 512
112
114 self.file.write(asctime() + ": " + line + "\n")
115 self.file.flush()
116
118 suppliedPath = eval(str(self.params['path']))
119
120 self.path = os.path.join(suppliedPath, run.name + "_" + strftime("%Y_%b_%d_%H_%M_%S", gmtime()))
121 self.faultPath = os.path.join(self.path, "Faults")
122 try:
123 os.mkdir(suppliedPath)
124 except:
125 pass
126 try:
127 os.mkdir(self.path)
128 except:
129 pass
130
131 self.file = open(os.path.join(self.path,"status.txt"), "w")
132
133 self.file.write("Peach 2.0 Fuzzer Run\n")
134 self.file.write("====================\n\n")
135 self.file.write("Date of run: " + asctime() + "\n")
136 self.file.write("Run name: " + run.name + "\n\n")
137
139 self.file.write("\n\n== Run completed ==\n" + asctime() + "\n")
140 self.file.close()
141 self.file = None
142
148
153
156
157 - def OnFault(self, run, test, variationCount, monitorData, actionValues):
158 self._writeMsg("Fault was detected on test %d" % variationCount)
159
160 path = os.path.join(self.faultPath,str(variationCount))
161 try:
162 os.mkdir(self.faultPath)
163 except:
164 pass
165 try:
166 os.mkdir(path)
167 except:
168 pass
169
170
171
172 for i in range(len(actionValues)):
173 fileName = os.path.join(path, "data_%d_%s_%s.txt" % (i, actionValues[i][1], actionValues[i][0]))
174
175 if len(actionValues[i]) > 2:
176 fout = open(fileName, "w+b")
177 fout.write(actionValues[i][2])
178
179 if len(actionValues[i]) > 3:
180 fout.write(repr(actionValues[i][3]))
181
182 fout.close()
183
184 for key in monitorData.keys():
185 fout = open(path + key, "wb")
186 fout.write(monitorData[key])
187 fout.close()
188
189 - def OnStopRun(self, run, test, variationCount, monitorData, value):
190 self._writeMsg("")
191 self._writeMsg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
192 self._writeMsg("!!!! TEST ABORTING AT %d" % variationCount)
193 self._writeMsg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
194 self._writeMsg("")
195
196
198 '''
199 Called on start of a test case.
200 '''
201 if variationCount % self.heartBeat == 0:
202 self._writeMsg("On test variation # %d" % variationCount)
203
204
205