Commits

Emanuele Rocca  committed e7eb4fa

Added dbaccess.check_seq_length_consistency() to spot config errors

  • Participants
  • Parent commits 69d07ba

Comments (0)

Files changed (6)

     reader = dbaccess.getdata()
     print "done"
 
+    dbaccess.check_seq_length_consistency(reader.sequence_lengths)
+
     print msg % "Updating"
 
     data = SetSyscallDataReader(input=sys.stdin, 
 
 # If you change sequence lengths remember to remove the database (stored in
 # $FILENAME) and allsequences.ko. Then re-create them running: ./createdb.sh
-SEQUENCE_LENGTHS=5
+SEQUENCE_LENGTHS=6
     dbf = open(config.FILENAME, 'wb')
     cPickle.dump(data, dbf)
     dbf.close()
+
+def check_seq_length_consistency(curlength):
+    MSG = """
+==============================================================================
+Your old database has been created with a sequence length=%s, but your current 
+configuration uses sequence length=%s.
+Please remove %s and allsequences.ko, then run createdb.sh again.
+
+Otherwise, if you're OK with sequence of length %s, just change the relevant 
+setting in config.py
+==============================================================================
+""" % (curlength, config.SEQUENCE_LENGTHS, config.FILENAME, curlength)
+
+    assert curlength == config.SEQUENCE_LENGTHS, MSG
 import sys
 import time
 
+import config
 import seqtree
 
 def line2data(input_line):
 
         self.starting = time.time()
         self.input = input
+
+        self.sequence_lengths = config.SEQUENCE_LENGTHS
         
         try:
             self.go()

File runtime_check.py

 if __name__ == "__main__":
     data = dbaccess.getdata()
 
+    dbaccess.check_seq_length_consistency(data.sequence_lengths)
+
     while True:
         sequence = sys.stdin.readline()
         if not sequence:
 class TestReader(unittest.TestCase):
     classname = None
 
-    known_seq = {
-        #'firefox': ('futex', 'gettimeofday', 'futex', 'write', 'gettimeofday' ),
-        'syslogd': ('timestat', 'rt_sigprocmask', 'recvfrom', 'futex', 'write'),
-    }
+    def __gen_sequence_from_seed(self, seed):
+        # seed is a tuple of syscalls
+        # eg: ('futex', 'gettimeofday', 'write', 'time' 'stat' )
+        return tuple([ seed[iteration % len(seed) ] 
+            for iteration in range(config.SEQUENCE_LENGTHS) ])
 
     def setUp(self):
         self.reader = self.classname(_testfd())
+        self.known_seq = {}
+
+        for executable in 'firefox', 'syslogd':
+            self.known_seq[executable] = tuple(self.reader.executables[executable])[0]
 
     def testKnownSeq(self):
         for execname, seq in self.known_seq.items():
 
     def testAddSeq(self):
         execname = 'mutt'
-        sequence = ('futex', 'gettimeofday', 'write', 'time' 'stat')
+        sequence = self.__gen_sequence_from_seed(
+            ('futex', 'gettimeofday', 'write', 'time' 'stat' ))
+        
         self.reader.addseq(execname, sequence)
-
+    """
     def testActualData(self):
         try:
             self.reader = self.classname(open("/var/tmp/rawdata.allsequences"))
 
         t = timeit.Timer(unknown)
         print t.timeit()
+    """
 
 class TestTreeSyscallDataReader(TestReader):
     classname = TreeSyscallDataReader