diff options
Diffstat (limited to 'src/autodep/test/test_hookfs.py')
-rw-r--r-- | src/autodep/test/test_hookfs.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/autodep/test/test_hookfs.py b/src/autodep/test/test_hookfs.py new file mode 100644 index 0000000..fdab1f0 --- /dev/null +++ b/src/autodep/test/test_hookfs.py @@ -0,0 +1,65 @@ +import unittest +import logfs.fstracer + +def simple_getfsevents(prog,args,approach="hooklib"): + ret=[] + events = logfs.fstracer.getfsevents(prog,args,approach) + #print events + for stage in events: + for filename in events[stage][0]: + ret.append([filename,'success']) + for filename in events[stage][1]: + ret.append([filename,'fail']) + + return ret + +class hooklib_simple_tests(unittest.TestCase): + def test_open_unexists(self): + eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="hooklib") + print eventslist + self.assertTrue(eventslist.count(['/f1',"fail"])==1) + self.assertTrue(eventslist.count(['/f2',"fail"])==1) + + def test_open_exists(self): + eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/etc/passwd'],approach="hooklib") + self.assertTrue(eventslist.count(['/etc/passwd','success'])>=1) + + def test_open_many(self): + filesnum=200 + eventslist=simple_getfsevents('/bin/cat',['/bin/cat']+ + map(lambda x: '/file'+str(x),range(0,filesnum)), approach="hooklib") + for f in map(lambda x: ['/file'+str(x),'fail'],range(0,filesnum)): + self.assertTrue(f in eventslist) + + def test_parralel(self): + filesnum=400 + procnum=8 + + # create command + command="" + for p in xrange(0,procnum): + command+="/bin/cat " + for f in xrange(0,filesnum): + command+="/file_%d_%d " % (p,f) + command+="& " + command+=" 2>/dev/null" + #command+=" "+"A"*65536 + + resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c',command],approach="hooklib") + + for p in xrange(0,procnum): + for f in xrange(0,filesnum): + self.assertTrue(resultarray.count(['/file_%d_%d' % (p,f),"fail"])==1) + + def test_open_very_many(self): + resultarray=simple_getfsevents('/bin/sh', ['/bin/sh','-c', + "for i in `seq 1 1000`; do cat /testmany$i;done 2> /dev/null"],approach="hooklib") + #print resultarray + for i in range(1,1000): + self.assertTrue(resultarray.count(['/testmany'+str(i),'fail'])==1) + + def test_exec(self): + eventslist=simple_getfsevents('test/helpers/exec', ['test/helpers/exec'],approach="hooklib") + for i in range(1,14): + self.assertTrue(eventslist.count(['/f'+str(i),"fail"])==1) +
\ No newline at end of file |