1 |
commit: 84111f67a1a516fb202f620dbe3fe61ef3943875 |
2 |
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru> |
3 |
AuthorDate: Wed Jul 13 19:43:18 2011 +0000 |
4 |
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru> |
5 |
CommitDate: Wed Jul 13 19:43:18 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=84111f67 |
7 |
|
8 |
tests |
9 |
|
10 |
--- |
11 |
src/autodep/logfs/fstracer.py | 3 +- |
12 |
src/autodep/logfs/logger_fusefs.py | 2 +- |
13 |
src/autodep/logfs/logger_hooklib.py | 2 +- |
14 |
src/autodep/runtests.py | 8 ++ |
15 |
{test => src/autodep/test}/1_access/Makefile | 0 |
16 |
{test => src/autodep/test}/1_access/accesser.c | 0 |
17 |
src/autodep/test/all_tests.py | 11 +++ |
18 |
src/autodep/test/test_fusefs.py | 72 +++++++++++++++ |
19 |
src/autodep/test/test_hookfs.py | 65 ++++++++++++++ |
20 |
test/logger/test_fstracer.py | 112 ------------------------ |
21 |
10 files changed, 160 insertions(+), 115 deletions(-) |
22 |
|
23 |
diff --git a/src/autodep/logfs/fstracer.py b/src/autodep/logfs/fstracer.py |
24 |
index c724b61..7eca160 100644 |
25 |
--- a/src/autodep/logfs/fstracer.py |
26 |
+++ b/src/autodep/logfs/fstracer.py |
27 |
@@ -151,7 +151,8 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter) |
28 |
print "Sending SIGKILL to child" |
29 |
os.kill(pid,signal.SIGKILL) |
30 |
os._exit(1) |
31 |
- global signal |
32 |
+ import signal # signal must to be in this scope |
33 |
+ # global signal not works |
34 |
signal.signal(signal.SIGINT, signal_handler) |
35 |
|
36 |
epoll=select.epoll() |
37 |
|
38 |
diff --git a/src/autodep/logfs/logger_fusefs.py b/src/autodep/logfs/logger_fusefs.py |
39 |
index 6c135e8..7965d45 100644 |
40 |
--- a/src/autodep/logfs/logger_fusefs.py |
41 |
+++ b/src/autodep/logfs/logger_fusefs.py |
42 |
@@ -50,7 +50,7 @@ class logger: |
43 |
os.environ["PARENT_PID"]=str(self.currpid) |
44 |
|
45 |
# TODO: change |
46 |
- ret=subprocess.call(['/home/bay/gsoc/logger/src/hook_fusefs/hookfs',self.rootmountpath, |
47 |
+ ret=subprocess.call(['/home/bay/gsoc/src/hook_fusefs/hookfs',self.rootmountpath, |
48 |
'-o','allow_other,suid']) |
49 |
if ret!=0: |
50 |
print "failed to launch FUSE logger. Check messages above" |
51 |
|
52 |
diff --git a/src/autodep/logfs/logger_hooklib.py b/src/autodep/logfs/logger_hooklib.py |
53 |
index 008fc56..1c72279 100644 |
54 |
--- a/src/autodep/logfs/logger_hooklib.py |
55 |
+++ b/src/autodep/logfs/logger_hooklib.py |
56 |
@@ -5,7 +5,7 @@ import sys |
57 |
|
58 |
class logger: |
59 |
socketname='' |
60 |
- hooklibpath='/home/bay/gsoc/logger/src/hook_lib/file_hook.so' # TODO: change |
61 |
+ hooklibpath='/home/bay/gsoc/src/hook_lib/file_hook.so' # TODO: change |
62 |
|
63 |
def __init__(self,socketname): |
64 |
self.socketname=socketname |
65 |
|
66 |
diff --git a/src/autodep/runtests.py b/src/autodep/runtests.py |
67 |
new file mode 100644 |
68 |
index 0000000..4605cfb |
69 |
--- /dev/null |
70 |
+++ b/src/autodep/runtests.py |
71 |
@@ -0,0 +1,8 @@ |
72 |
+#!/usr/bin/env python2 |
73 |
+ |
74 |
+#import test.test_fstracer |
75 |
+ |
76 |
+import unittest |
77 |
+import test.all_tests |
78 |
+testSuite = test.all_tests.create_test_suite() |
79 |
+text_runner = unittest.TextTestRunner().run(testSuite) |
80 |
\ No newline at end of file |
81 |
|
82 |
diff --git a/test/1_access/Makefile b/src/autodep/test/1_access/Makefile |
83 |
similarity index 100% |
84 |
rename from test/1_access/Makefile |
85 |
rename to src/autodep/test/1_access/Makefile |
86 |
|
87 |
diff --git a/test/1_access/accesser.c b/src/autodep/test/1_access/accesser.c |
88 |
similarity index 100% |
89 |
rename from test/1_access/accesser.c |
90 |
rename to src/autodep/test/1_access/accesser.c |
91 |
|
92 |
diff --git a/src/autodep/test/all_tests.py b/src/autodep/test/all_tests.py |
93 |
new file mode 100644 |
94 |
index 0000000..9095742 |
95 |
--- /dev/null |
96 |
+++ b/src/autodep/test/all_tests.py |
97 |
@@ -0,0 +1,11 @@ |
98 |
+import glob |
99 |
+import unittest |
100 |
+ |
101 |
+def create_test_suite(): |
102 |
+ test_file_strings = glob.glob('test/test_fusefs.py') |
103 |
+ module_strings = ['test.'+str[5:len(str)-3] for str in test_file_strings] |
104 |
+ suites = [unittest.defaultTestLoader.loadTestsFromName(name) \ |
105 |
+ for name in module_strings] |
106 |
+ testSuite = unittest.TestSuite(suites) |
107 |
+ return testSuite |
108 |
+ |
109 |
|
110 |
diff --git a/src/autodep/test/test_fusefs.py b/src/autodep/test/test_fusefs.py |
111 |
new file mode 100644 |
112 |
index 0000000..fb57de7 |
113 |
--- /dev/null |
114 |
+++ b/src/autodep/test/test_fusefs.py |
115 |
@@ -0,0 +1,72 @@ |
116 |
+import unittest |
117 |
+import logfs.fstracer |
118 |
+ |
119 |
+def simple_getfsevents(prog,args,approach="hooklib"): |
120 |
+ ret=[] |
121 |
+ events = logfs.fstracer.getfsevents(prog,args,approach) |
122 |
+ #print events |
123 |
+ for stage in events: |
124 |
+ for filename in events[stage][0]: |
125 |
+ ret.append([filename,'success']) |
126 |
+ for filename in events[stage][1]: |
127 |
+ ret.append([filename,'fail']) |
128 |
+ |
129 |
+ return ret |
130 |
+ |
131 |
+ |
132 |
+ |
133 |
+class fusefs_simple_tests(unittest.TestCase): |
134 |
+ def test_open_unexists(self): |
135 |
+ eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="fusefs") |
136 |
+ print eventslist |
137 |
+ self.assertTrue(eventslist.count(['/f1',"fail"])==1) |
138 |
+ self.assertTrue(eventslist.count(['/f2',"fail"])==1) |
139 |
+ |
140 |
+ def test_open_exists(self): |
141 |
+ eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/etc/passwd'],approach="fusefs") |
142 |
+ self.assertTrue(eventslist.count(['/etc/passwd','success'])>=1) |
143 |
+ |
144 |
+ def test_open_many(self): |
145 |
+ filesnum=200 |
146 |
+ eventslist=simple_getfsevents('/bin/cat',['/bin/cat']+ |
147 |
+ map(lambda x: '/file'+str(x),range(0,filesnum)), approach="fusefs") |
148 |
+ for f in map(lambda x: ['/file'+str(x),'fail'],range(0,filesnum)): |
149 |
+ self.assertTrue(f in eventslist) |
150 |
+ |
151 |
+ def test_parralel(self): |
152 |
+ filesnum=400 |
153 |
+ procnum=8 |
154 |
+ |
155 |
+ # create command |
156 |
+ command="" |
157 |
+ for p in xrange(0,procnum): |
158 |
+ command+="/bin/cat " |
159 |
+ for f in xrange(0,filesnum): |
160 |
+ command+="/file_%d_%d " % (p,f) |
161 |
+ command+="& " |
162 |
+ command+=" 2>/dev/null" |
163 |
+ #command+=" "+"A"*65536 |
164 |
+ |
165 |
+ resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c',command],approach="fusefs") |
166 |
+ |
167 |
+ for p in xrange(0,procnum): |
168 |
+ for f in xrange(0,filesnum): |
169 |
+ self.assertTrue(resultarray.count(['/file_%d_%d' % (p,f),"fail"])==1) |
170 |
+ |
171 |
+ def test_open_very_many(self): |
172 |
+ resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c', |
173 |
+ "for i in `seq 1 1000`; do cat /testmany$i;done 2> /dev/null"],approach="fusefs") |
174 |
+ #print resultarray |
175 |
+ for i in range(1,1000): |
176 |
+ self.assertTrue(resultarray.count(['/testmany'+str(i),'fail'])==1) |
177 |
+ |
178 |
+ def test_exec(self): |
179 |
+ eventslist=simple_getfsevents('test/helpers/exec', ['test/helpers/exec'],approach="fusefs") |
180 |
+ for i in range(1,14): |
181 |
+ self.assertTrue(eventslist.count(['/f'+str(i),"fail"])==1) |
182 |
+ |
183 |
+#if __name__ == '__main__': |
184 |
+ #unittest.main() |
185 |
+ #suite = unittest.TestLoader().loadTestsFromTestCase(fusefs_simple_tests) |
186 |
+# suite = unittest.TestLoader().loadTestsFromTestCase(hooklib_simple_tests) |
187 |
+# unittest.TextTestRunner(verbosity=2).run(suite) |
188 |
\ No newline at end of file |
189 |
|
190 |
diff --git a/src/autodep/test/test_hookfs.py b/src/autodep/test/test_hookfs.py |
191 |
new file mode 100644 |
192 |
index 0000000..fdab1f0 |
193 |
--- /dev/null |
194 |
+++ b/src/autodep/test/test_hookfs.py |
195 |
@@ -0,0 +1,65 @@ |
196 |
+import unittest |
197 |
+import logfs.fstracer |
198 |
+ |
199 |
+def simple_getfsevents(prog,args,approach="hooklib"): |
200 |
+ ret=[] |
201 |
+ events = logfs.fstracer.getfsevents(prog,args,approach) |
202 |
+ #print events |
203 |
+ for stage in events: |
204 |
+ for filename in events[stage][0]: |
205 |
+ ret.append([filename,'success']) |
206 |
+ for filename in events[stage][1]: |
207 |
+ ret.append([filename,'fail']) |
208 |
+ |
209 |
+ return ret |
210 |
+ |
211 |
+class hooklib_simple_tests(unittest.TestCase): |
212 |
+ def test_open_unexists(self): |
213 |
+ eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="hooklib") |
214 |
+ print eventslist |
215 |
+ self.assertTrue(eventslist.count(['/f1',"fail"])==1) |
216 |
+ self.assertTrue(eventslist.count(['/f2',"fail"])==1) |
217 |
+ |
218 |
+ def test_open_exists(self): |
219 |
+ eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/etc/passwd'],approach="hooklib") |
220 |
+ self.assertTrue(eventslist.count(['/etc/passwd','success'])>=1) |
221 |
+ |
222 |
+ def test_open_many(self): |
223 |
+ filesnum=200 |
224 |
+ eventslist=simple_getfsevents('/bin/cat',['/bin/cat']+ |
225 |
+ map(lambda x: '/file'+str(x),range(0,filesnum)), approach="hooklib") |
226 |
+ for f in map(lambda x: ['/file'+str(x),'fail'],range(0,filesnum)): |
227 |
+ self.assertTrue(f in eventslist) |
228 |
+ |
229 |
+ def test_parralel(self): |
230 |
+ filesnum=400 |
231 |
+ procnum=8 |
232 |
+ |
233 |
+ # create command |
234 |
+ command="" |
235 |
+ for p in xrange(0,procnum): |
236 |
+ command+="/bin/cat " |
237 |
+ for f in xrange(0,filesnum): |
238 |
+ command+="/file_%d_%d " % (p,f) |
239 |
+ command+="& " |
240 |
+ command+=" 2>/dev/null" |
241 |
+ #command+=" "+"A"*65536 |
242 |
+ |
243 |
+ resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c',command],approach="hooklib") |
244 |
+ |
245 |
+ for p in xrange(0,procnum): |
246 |
+ for f in xrange(0,filesnum): |
247 |
+ self.assertTrue(resultarray.count(['/file_%d_%d' % (p,f),"fail"])==1) |
248 |
+ |
249 |
+ def test_open_very_many(self): |
250 |
+ resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c', |
251 |
+ "for i in `seq 1 1000`; do cat /testmany$i;done 2> /dev/null"],approach="hooklib") |
252 |
+ #print resultarray |
253 |
+ for i in range(1,1000): |
254 |
+ self.assertTrue(resultarray.count(['/testmany'+str(i),'fail'])==1) |
255 |
+ |
256 |
+ def test_exec(self): |
257 |
+ eventslist=simple_getfsevents('test/helpers/exec', ['test/helpers/exec'],approach="hooklib") |
258 |
+ for i in range(1,14): |
259 |
+ self.assertTrue(eventslist.count(['/f'+str(i),"fail"])==1) |
260 |
+ |
261 |
\ No newline at end of file |
262 |
|
263 |
diff --git a/test/logger/test_fstracer.py b/test/logger/test_fstracer.py |
264 |
deleted file mode 100644 |
265 |
index 15d4c27..0000000 |
266 |
--- a/test/logger/test_fstracer.py |
267 |
+++ /dev/null |
268 |
@@ -1,112 +0,0 @@ |
269 |
-import unittest |
270 |
- |
271 |
-import fstracer |
272 |
- |
273 |
-def simple_getfsevents(prog,args,approach="hooklib"): |
274 |
- ret=[] |
275 |
- events = fstracer.getfsevents(prog,args,approach) |
276 |
- #print events |
277 |
- for stage in events: |
278 |
- for filename in events[stage][0]: |
279 |
- ret.append([filename,'success']) |
280 |
- for filename in events[stage][1]: |
281 |
- ret.append([filename,'fail']) |
282 |
- |
283 |
- return ret |
284 |
- |
285 |
-class hooklib_simple_tests(unittest.TestCase): |
286 |
- def test_open_unexists(self): |
287 |
- eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="hooklib") |
288 |
- print eventslist |
289 |
- self.assertTrue(eventslist.count(['/f1',"fail"])==1) |
290 |
- self.assertTrue(eventslist.count(['/f2',"fail"])==1) |
291 |
- |
292 |
- def test_open_exists(self): |
293 |
- eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/etc/passwd'],approach="hooklib") |
294 |
- self.assertTrue(eventslist.count(['/etc/passwd','success'])>=1) |
295 |
- |
296 |
- def test_open_many(self): |
297 |
- filesnum=200 |
298 |
- eventslist=simple_getfsevents('/bin/cat',['/bin/cat']+ |
299 |
- map(lambda x: '/file'+str(x),range(0,filesnum)), approach="hooklib") |
300 |
- for f in map(lambda x: ['/file'+str(x),'fail'],range(0,filesnum)): |
301 |
- self.assertTrue(f in eventslist) |
302 |
- |
303 |
- def test_parralel(self): |
304 |
- filesnum=400 |
305 |
- procnum=8 |
306 |
- |
307 |
- # create command |
308 |
- command="" |
309 |
- for p in xrange(0,procnum): |
310 |
- command+="/bin/cat " |
311 |
- for f in xrange(0,filesnum): |
312 |
- command+="/file_%d_%d " % (p,f) |
313 |
- command+="& " |
314 |
- command+=" 2>/dev/null" |
315 |
- #command+=" "+"A"*65536 |
316 |
- |
317 |
- resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c',command],approach="hooklib") |
318 |
- |
319 |
- for p in xrange(0,procnum): |
320 |
- for f in xrange(0,filesnum): |
321 |
- self.assertTrue(resultarray.count(['/file_%d_%d' % (p,f),"fail"])==1) |
322 |
- |
323 |
- def test_open_very_many(self): |
324 |
- resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c', |
325 |
- "for i in `seq 1 1000`; do cat /testmany$i;done 2> /dev/null"],approach="hooklib") |
326 |
- #print resultarray |
327 |
- for i in range(1,1000): |
328 |
- self.assertTrue(resultarray.count(['/testmany'+str(i),'fail'])==1) |
329 |
- |
330 |
- |
331 |
-class fusefs_simple_tests(unittest.TestCase): |
332 |
- def test_open_unexists(self): |
333 |
- eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="fusefs") |
334 |
- print eventslist |
335 |
- self.assertTrue(eventslist.count(['/f1',"fail"])==1) |
336 |
- self.assertTrue(eventslist.count(['/f2',"fail"])==1) |
337 |
- |
338 |
- def test_open_exists(self): |
339 |
- eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/etc/passwd'],approach="fusefs") |
340 |
- self.assertTrue(eventslist.count(['/etc/passwd','success'])>=1) |
341 |
- |
342 |
- def test_open_many(self): |
343 |
- filesnum=200 |
344 |
- eventslist=simple_getfsevents('/bin/cat',['/bin/cat']+ |
345 |
- map(lambda x: '/file'+str(x),range(0,filesnum)), approach="fusefs") |
346 |
- for f in map(lambda x: ['/file'+str(x),'fail'],range(0,filesnum)): |
347 |
- self.assertTrue(f in eventslist) |
348 |
- |
349 |
- def test_parralel(self): |
350 |
- filesnum=400 |
351 |
- procnum=8 |
352 |
- |
353 |
- # create command |
354 |
- command="" |
355 |
- for p in xrange(0,procnum): |
356 |
- command+="/bin/cat " |
357 |
- for f in xrange(0,filesnum): |
358 |
- command+="/file_%d_%d " % (p,f) |
359 |
- command+="& " |
360 |
- command+=" 2>/dev/null" |
361 |
- #command+=" "+"A"*65536 |
362 |
- |
363 |
- resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c',command],approach="fusefs") |
364 |
- |
365 |
- for p in xrange(0,procnum): |
366 |
- for f in xrange(0,filesnum): |
367 |
- self.assertTrue(resultarray.count(['/file_%d_%d' % (p,f),"fail"])==1) |
368 |
- |
369 |
- def test_open_very_many(self): |
370 |
- resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c', |
371 |
- "for i in `seq 1 1000`; do cat /testmany$i;done 2> /dev/null"],approach="fusefs") |
372 |
- #print resultarray |
373 |
- for i in range(1,1000): |
374 |
- self.assertTrue(resultarray.count(['/testmany'+str(i),'fail'])==1) |
375 |
- |
376 |
-if __name__ == '__main__': |
377 |
- #unittest.main() |
378 |
- #suite = unittest.TestLoader().loadTestsFromTestCase(fusefs_simple_tests) |
379 |
- suite = unittest.TestLoader().loadTestsFromTestCase(hooklib_simple_tests) |
380 |
- unittest.TextTestRunner(verbosity=2).run(suite) |
381 |
\ No newline at end of file |