aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/autodep/logfs/fstracer.py3
-rw-r--r--src/autodep/logfs/logger_fusefs.py2
-rw-r--r--src/autodep/logfs/logger_hooklib.py2
-rw-r--r--src/autodep/runtests.py8
-rw-r--r--src/autodep/test/1_access/Makefile6
-rw-r--r--src/autodep/test/1_access/accesser.c25
-rw-r--r--src/autodep/test/all_tests.py11
-rw-r--r--src/autodep/test/test_fusefs.py72
-rw-r--r--src/autodep/test/test_hookfs.py65
9 files changed, 191 insertions, 3 deletions
diff --git a/src/autodep/logfs/fstracer.py b/src/autodep/logfs/fstracer.py
index c724b61..7eca160 100644
--- a/src/autodep/logfs/fstracer.py
+++ b/src/autodep/logfs/fstracer.py
@@ -151,7 +151,8 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
print "Sending SIGKILL to child"
os.kill(pid,signal.SIGKILL)
os._exit(1)
- global signal
+ import signal # signal must to be in this scope
+ # global signal not works
signal.signal(signal.SIGINT, signal_handler)
epoll=select.epoll()
diff --git a/src/autodep/logfs/logger_fusefs.py b/src/autodep/logfs/logger_fusefs.py
index 6c135e8..7965d45 100644
--- a/src/autodep/logfs/logger_fusefs.py
+++ b/src/autodep/logfs/logger_fusefs.py
@@ -50,7 +50,7 @@ class logger:
os.environ["PARENT_PID"]=str(self.currpid)
# TODO: change
- ret=subprocess.call(['/home/bay/gsoc/logger/src/hook_fusefs/hookfs',self.rootmountpath,
+ ret=subprocess.call(['/home/bay/gsoc/src/hook_fusefs/hookfs',self.rootmountpath,
'-o','allow_other,suid'])
if ret!=0:
print "failed to launch FUSE logger. Check messages above"
diff --git a/src/autodep/logfs/logger_hooklib.py b/src/autodep/logfs/logger_hooklib.py
index 008fc56..1c72279 100644
--- a/src/autodep/logfs/logger_hooklib.py
+++ b/src/autodep/logfs/logger_hooklib.py
@@ -5,7 +5,7 @@ import sys
class logger:
socketname=''
- hooklibpath='/home/bay/gsoc/logger/src/hook_lib/file_hook.so' # TODO: change
+ hooklibpath='/home/bay/gsoc/src/hook_lib/file_hook.so' # TODO: change
def __init__(self,socketname):
self.socketname=socketname
diff --git a/src/autodep/runtests.py b/src/autodep/runtests.py
new file mode 100644
index 0000000..4605cfb
--- /dev/null
+++ b/src/autodep/runtests.py
@@ -0,0 +1,8 @@
+#!/usr/bin/env python2
+
+#import test.test_fstracer
+
+import unittest
+import test.all_tests
+testSuite = test.all_tests.create_test_suite()
+text_runner = unittest.TextTestRunner().run(testSuite) \ No newline at end of file
diff --git a/src/autodep/test/1_access/Makefile b/src/autodep/test/1_access/Makefile
new file mode 100644
index 0000000..b3ea345
--- /dev/null
+++ b/src/autodep/test/1_access/Makefile
@@ -0,0 +1,6 @@
+accesser: accesser.c
+
+all: accesser
+
+clean:
+ rm -f accesser \ No newline at end of file
diff --git a/src/autodep/test/1_access/accesser.c b/src/autodep/test/1_access/accesser.c
new file mode 100644
index 0000000..cdfe520
--- /dev/null
+++ b/src/autodep/test/1_access/accesser.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+int main(int argc, char **argv) {
+ if(argc<=1) {
+ printf("Usage: accesser.c <file1> [file2] [file3] ...\n");
+ return 1;
+ }
+ int i;
+ for(i=1;i<argc;i++) {
+ printf("Accessing %s: ",argv[i]);
+ int fh;
+ fh=open(argv[i], O_RDONLY);
+ if(fh!=-1)
+ printf("OK\n");
+ else
+ printf("ERR, %s\n", strerror(errno));
+ }
+
+ return 0;
+}
diff --git a/src/autodep/test/all_tests.py b/src/autodep/test/all_tests.py
new file mode 100644
index 0000000..9095742
--- /dev/null
+++ b/src/autodep/test/all_tests.py
@@ -0,0 +1,11 @@
+import glob
+import unittest
+
+def create_test_suite():
+ test_file_strings = glob.glob('test/test_fusefs.py')
+ module_strings = ['test.'+str[5:len(str)-3] for str in test_file_strings]
+ suites = [unittest.defaultTestLoader.loadTestsFromName(name) \
+ for name in module_strings]
+ testSuite = unittest.TestSuite(suites)
+ return testSuite
+
diff --git a/src/autodep/test/test_fusefs.py b/src/autodep/test/test_fusefs.py
new file mode 100644
index 0000000..fb57de7
--- /dev/null
+++ b/src/autodep/test/test_fusefs.py
@@ -0,0 +1,72 @@
+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 fusefs_simple_tests(unittest.TestCase):
+ def test_open_unexists(self):
+ eventslist=simple_getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="fusefs")
+ 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="fusefs")
+ 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="fusefs")
+ 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="fusefs")
+
+ 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="fusefs")
+ #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="fusefs")
+ for i in range(1,14):
+ self.assertTrue(eventslist.count(['/f'+str(i),"fail"])==1)
+
+#if __name__ == '__main__':
+ #unittest.main()
+ #suite = unittest.TestLoader().loadTestsFromTestCase(fusefs_simple_tests)
+# suite = unittest.TestLoader().loadTestsFromTestCase(hooklib_simple_tests)
+# unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file
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