def compute_status(self) :
      'compute status'
      if self.first.isfail :
        return mdb.accessor(status='FAIL', reason='('+self.first.severity+') '+self.first.msg)
      if self.SUCCESS :
        if self.SUCCESS.count == 1 :
	  return mdb.accessor(status='PASS', reason=self.SUCCESS.msg)
        else :
          return mdb.accessor(status='FAIL', reason='Too many SUCCESSes (%d)' % self.SUCCESS.count)
      return mdb.accessor(status='FAIL', reason='No SUCCESS')
 def compute_status(self):
     'compute status'
     if self.first.isfail:
         return mdb.accessor(status='FAIL',
                             reason='(' + self.first.severity + ') ' +
                             self.first.msg)
     if self.SUCCESS:
         if self.SUCCESS.count == 1:
             return mdb.accessor(status='PASS', reason=self.SUCCESS.msg)
         else:
             return mdb.accessor(status='FAIL',
                                 reason='Too many SUCCESSes (%d)' %
                                 self.SUCCESS.count)
     return mdb.accessor(status='FAIL', reason='No SUCCESS')
 def __iter__(self) :
   self.reset()
   switched = False
   current = self.status()
   testlist = self.testlist()
   while testlist :
     log = testlist.pop(0)
     updates = self.increment(log.log_id)
     status  = self.status()
     yield mdb.accessor(log=log, last=current, updates=updates, status=status, hits=status.metric().hits-current.metric().hits)
     current = status
     # calculate incremental coverage of remaining tests
     with mdb.connection().row_cursor() as db :
       db.execute('DELETE FROM '+self.invs+' WHERE log_id = %s;', (log.log_id,))
       if status.metric().coverage() > self.threshold :
         if not switched :
           switched = True
           message.note('Switching to incremental selection at %(threshold)0.2f', threshold=self.threshold)
         # switch to incremental as coverage closes
         minexpr = '(status.goal+status.max_hits)-status.rhits' if self.robust else 'status.goal-status.hits'
         if self.robust :
           db.execute('SELECT invs.*, IFNULL(SUM(MIN((status.goal+status.max_hits)-status.rhits, hits.hits)), 0) AS hits FROM '+self.invs+' AS invs LEFT OUTER JOIN hits USING (log_id) JOIN '+self.covg+' AS status ON (hits.bucket_id = status.bucket_id AND status.goal > 0 AND status.hits < (status.goal+status.max_hits)) GROUP BY log_id ORDER BY hits DESC;')
         else :
           db.execute('SELECT invs.*, IFNULL(SUM(MIN(status.goal-status.hits, hits.hits)), 0) AS hits FROM '+self.invs+' AS invs LEFT OUTER JOIN hits USING (log_id) JOIN '+self.covg+' AS status ON (hits.bucket_id = status.bucket_id AND status.goal > 0 AND status.hits < status.goal) GROUP BY log_id ORDER BY hits DESC;')
         testlist = db.fetchall()
 def __iter__(self) :
   self.reset()
   current = self.status()
   for log in self.testlist() :
     updates = self.increment(log.log_id)
     status  = self.status()
     yield mdb.accessor(log=log, last=current, updates=updates, status=status, hits=status.metric().hits-current.metric().hits)
     current = status
 def __call__(self, grp) :
   row = grp.currvalue
   if row.testname in self.values :
     self.values[row.testname].hits += row.hits
   else :
     self.values[row.testname] = mdb.accessor(idx=len(self.values), hits=row.hits)
   row.testname = self.values[row.testname].idx
   return row
 def __call__(self, grp):
     row = grp.currvalue
     if row.testname in self.values:
         self.values[row.testname].hits += row.hits
     else:
         self.values[row.testname] = mdb.accessor(idx=len(self.values),
                                                  hits=row.hits)
     row.testname = self.values[row.testname].idx
     return row
 def grpfact(self):
     'group factory for grouping'
     return mdb.accessor(level=self.currvalue.level,
                         severity=self.currvalue.severity,
                         count=self.currvalue.count,
                         msg=self.currvalue.msg,
                         ident=self.currvalue.ident,
                         subident=self.currvalue.subident,
                         filename=self.currvalue.filename,
                         line=self.currvalue.line)
 def keyfact(self) :
   'key factory for grouping'
   testname = self.currvalue.test
   seed = None
   if self.currvalue.test :
     seed = index.testseed.search(self.currvalue.test)
     if seed :
       testname = self.currvalue.test[:seed.start()]
       seed = seed.group('seed')
   return [mdb.accessor(testname=testname, seed=seed, user=pwd.getpwuid(self.currvalue.uid).pw_name, **self.currvalue), self._grouper(self.tgtkey)]
 def status(self) :
   'calculate & return current coverage'
   with mdb.connection().cursor() as db :
     db.execute('SELECT SUM(MIN(goal, hits)) AS hits, SUM(goal) AS goal, SUM(MIN(goal+max_hits, rhits)) AS rhits, SUM(goal+max_hits) AS rgoal FROM '+self.covg+' WHERE goal > 0;')
     hits, goal, rhits, rgoal = db.fetchone()
     covrge=coverage.coverage(hits=hits, goal=goal)
     robust=coverage.coverage(hits=rhits, goal=rgoal)
     def metric() :
       'be clear instead of using lambda'
       return robust if self.robust else covrge
     return mdb.accessor(coverage=covrge, robust=robust, metric=metric)
 def __iter__(self):
     self.reset()
     current = self.status()
     for log in self.testlist():
         updates = self.increment(log.log_id)
         status = self.status()
         yield mdb.accessor(log=log,
                            last=current,
                            updates=updates,
                            status=status,
                            hits=status.metric().hits -
                            current.metric().hits)
         current = status
Beispiel #11
0
 def __init__(self, log_ids=[], test_ids=[], xml=None, threshold=0, robust=False, previous=None) :
   'log_ids is a list of regression roots'
   self.log_ids = log_ids
   s_log_ids = ','.join(map(str, log_ids))
   self.tests = mdb.connection().row_cursor()
   if log_ids :
     # create table of individual runs, but not root node as this may have already summarised coverage
     self.tests.execute('CREATE TEMPORARY TABLE '+self.invs+' AS SELECT l1.*, goal_id AS master FROM log AS l0 JOIN log AS l1 ON (l0.log_id = l1.root) LEFT OUTER JOIN master ON (l1.log_id = master.log_id) WHERE l1.root IN ('+s_log_ids+');')
     self.tests.execute('SELECT count(*) AS children FROM '+self.invs)
     children = self.tests.fetchone().children
     if children :
       message.information('%(log_ids)s %(has)s %(children)d children', log_ids=s_log_ids, children=children, has='have' if len(log_ids) > 1 else 'has')
   # append individual runs as given by test_ids
   if xml :
     xml_ids = xml.xml.xpath('/optimize/test/log_id/text()')
   else :
     xml_ids=[]
   if test_ids or xml_ids :
     s_test_ids = ','.join(map(str, test_ids+xml_ids))
     create = ('INSERT INTO '+self.invs) if log_ids else ('CREATE TEMPORARY TABLE '+self.invs+' AS')
     self.tests.execute(create+' SELECT log.*, IFNULL(goal_id, goal.log_id) AS master FROM log LEFT OUTER JOIN master ON (log.log_id = master.log_id) LEFT OUTER JOIN goal ON (log.log_id = goal.log_id) WHERE log.log_id IN ('+s_test_ids+') GROUP BY log_id;')
   self.tests.execute('SELECT count(*) AS tests FROM '+self.invs)
   tests = self.tests.fetchone().tests
   if tests < 1 :
     message.fatal('no tests')
   message.information('starting with %(count)d tests in table %(table)s', count=tests, table=self.invs)
   # check congruency
   self.cvg = mdb.connection().row_cursor()
   rows=self.cvg.execute("SELECT md5_self AS md5, 'md5_self' AS type, invs.master, invs.root FROM point JOIN "+self.invs+" AS invs ON (invs.master = point.log_id AND point.parent IS NULL) GROUP BY md5;")
   md5 = self.cvg.fetchall()
   if not md5 :
     message.fatal('no master')
   elif len(md5) > 1 :
     message.fatal('md5 of multiple masters do not match')
   else :
     message.debug('md5 query returns %(rows)d', rows=rows)
   self.master = mdb.accessor(md5=md5[0])
   self.cvg.execute("SELECT DISTINCT(md5_axes) AS md5, 'md5_axes' AS type, invs.master, invs.root FROM point JOIN "+self.invs+" AS invs ON (invs.master = point.log_id AND point.parent IS NULL) GROUP BY md5;")
   md5 = self.cvg.fetchall()
   if len(md5) > 1 :
     message.fatal('md5 of multiple axis masters do not match')
   self.master.axes = md5[0]
   # create status table, collating goal & hits
   self.cvg.execute('CREATE TEMPORARY TABLE '+self.covg+' (bucket_id INTEGER NOT NULL PRIMARY KEY, goal INTEGER, hits INTEGER, total_hits INTEGER, rhits INTEGER, max_hits INTEGER, tests INTEGER);')
   try :
     self.threshold = float(threshold)
   except :
     self.threshold = 0.0
     message.warning('cannot convert threshold value given "%(arg)s" to float because %(exception)s, using %(threshold)2.1f', arg=threshold, exception=sys.exc_info()[0], threshold=self.threshold)
   self.robust = robust
   self.previous = previous
    def status(self):
        'calculate & return current coverage'
        with mdb.connection().cursor() as db:
            db.execute(
                'SELECT SUM(MIN(goal, hits)) AS hits, SUM(goal) AS goal, SUM(MIN(goal+max_hits, rhits)) AS rhits, SUM(goal+max_hits) AS rgoal FROM '
                + self.covg + ' WHERE goal > 0;')
            hits, goal, rhits, rgoal = db.fetchone()
            covrge = coverage.coverage(hits=hits, goal=goal)
            robust = coverage.coverage(hits=rhits, goal=rgoal)

            def metric():
                'be clear instead of using lambda'
                return robust if self.robust else covrge

            return mdb.accessor(coverage=covrge, robust=robust, metric=metric)
 def keyfact(self):
     'key factory for grouping'
     testname = self.currvalue.test
     seed = None
     if self.currvalue.test:
         seed = index.testseed.search(self.currvalue.test)
         if seed:
             testname = self.currvalue.test[:seed.start()]
             seed = seed.group('seed')
     return [
         mdb.accessor(testname=testname,
                      seed=seed,
                      user=pwd.getpwuid(self.currvalue.uid).pw_name,
                      **self.currvalue),
         self._grouper(self.tgtkey)
     ]
 def __iter__(self):
     self.reset()
     switched = False
     current = self.status()
     testlist = self.testlist()
     while testlist:
         log = testlist.pop(0)
         updates = self.increment(log.log_id)
         status = self.status()
         yield mdb.accessor(log=log,
                            last=current,
                            updates=updates,
                            status=status,
                            hits=status.metric().hits -
                            current.metric().hits)
         current = status
         # calculate incremental coverage of remaining tests
         with mdb.connection().row_cursor() as db:
             db.execute('DELETE FROM ' + self.invs + ' WHERE log_id = %s;',
                        (log.log_id, ))
             if status.metric().coverage() > self.threshold:
                 if not switched:
                     switched = True
                     message.note(
                         'Switching to incremental selection at %(threshold)0.2f',
                         threshold=self.threshold)
                 # switch to incremental as coverage closes
                 minexpr = '(status.goal+status.max_hits)-status.rhits' if self.robust else 'status.goal-status.hits'
                 if self.robust:
                     db.execute(
                         'SELECT invs.*, IFNULL(SUM(MIN((status.goal+status.max_hits)-status.rhits, hits.hits)), 0) AS hits FROM '
                         + self.invs +
                         ' AS invs LEFT OUTER JOIN hits USING (log_id) JOIN '
                         + self.covg +
                         ' AS status ON (hits.bucket_id = status.bucket_id AND status.goal > 0 AND status.hits < (status.goal+status.max_hits)) GROUP BY log_id ORDER BY hits DESC;'
                     )
                 else:
                     db.execute(
                         'SELECT invs.*, IFNULL(SUM(MIN(status.goal-status.hits, hits.hits)), 0) AS hits FROM '
                         + self.invs +
                         ' AS invs LEFT OUTER JOIN hits USING (log_id) JOIN '
                         + self.covg +
                         ' AS status ON (hits.bucket_id = status.bucket_id AND status.goal > 0 AND status.hits < status.goal) GROUP BY log_id ORDER BY hits DESC;'
                     )
                 testlist = db.fetchall()
 def __init__(self,
              log_ids=[],
              test_ids=[],
              xml=None,
              threshold=0,
              robust=False,
              previous=None):
     'log_ids is a list of regression roots'
     self.log_ids = log_ids
     s_log_ids = ','.join(map(str, log_ids))
     self.tests = mdb.connection().row_cursor()
     if log_ids:
         # create table of individual runs, but not root node as this may have already summarised coverage
         self.tests.execute(
             'CREATE TEMPORARY TABLE ' + self.invs +
             ' AS SELECT l1.*, goal_id AS master FROM log AS l0 JOIN log AS l1 ON (l0.log_id = l1.root) LEFT OUTER JOIN master ON (l1.log_id = master.log_id) WHERE l1.root IN ('
             + s_log_ids + ');')
         self.tests.execute('SELECT count(*) AS children FROM ' + self.invs)
         children = self.tests.fetchone().children
         if children:
             message.information(
                 '%(log_ids)s %(has)s %(children)d children',
                 log_ids=s_log_ids,
                 children=children,
                 has='have' if len(log_ids) > 1 else 'has')
     # append individual runs as given by test_ids
     if xml:
         xml_ids = xml.xml.xpath('/optimize/test/log_id/text()')
     else:
         xml_ids = []
     if test_ids or xml_ids:
         s_test_ids = ','.join(map(str, test_ids + xml_ids))
         create = ('INSERT INTO ' +
                   self.invs) if log_ids else ('CREATE TEMPORARY TABLE ' +
                                               self.invs + ' AS')
         self.tests.execute(
             create +
             ' SELECT log.*, IFNULL(goal_id, goal.log_id) AS master FROM log LEFT OUTER JOIN master ON (log.log_id = master.log_id) LEFT OUTER JOIN goal ON (log.log_id = goal.log_id) WHERE log.log_id IN ('
             + s_test_ids + ') GROUP BY log_id;')
     self.tests.execute('SELECT count(*) AS tests FROM ' + self.invs)
     tests = self.tests.fetchone().tests
     if tests < 1:
         message.fatal('no tests')
     message.information('starting with %(count)d tests in table %(table)s',
                         count=tests,
                         table=self.invs)
     # check congruency
     self.cvg = mdb.connection().row_cursor()
     rows = self.cvg.execute(
         "SELECT md5_self AS md5, 'md5_self' AS type, invs.master, invs.root FROM point JOIN "
         + self.invs +
         " AS invs ON (invs.master = point.log_id AND point.parent IS NULL) GROUP BY md5;"
     )
     md5 = self.cvg.fetchall()
     if not md5:
         message.fatal('no master')
     elif len(md5) > 1:
         message.fatal('md5 of multiple masters do not match')
     else:
         message.debug('md5 query returns %(rows)d', rows=rows)
     self.master = mdb.accessor(md5=md5[0])
     self.cvg.execute(
         "SELECT DISTINCT(md5_axes) AS md5, 'md5_axes' AS type, invs.master, invs.root FROM point JOIN "
         + self.invs +
         " AS invs ON (invs.master = point.log_id AND point.parent IS NULL) GROUP BY md5;"
     )
     md5 = self.cvg.fetchall()
     if len(md5) > 1:
         message.fatal('md5 of multiple axis masters do not match')
     self.master.axes = md5[0]
     # create status table, collating goal & hits
     self.cvg.execute(
         'CREATE TEMPORARY TABLE ' + self.covg +
         ' (bucket_id INTEGER NOT NULL PRIMARY KEY, goal INTEGER, hits INTEGER, total_hits INTEGER, rhits INTEGER, max_hits INTEGER, tests INTEGER);'
     )
     try:
         self.threshold = float(threshold)
     except:
         self.threshold = 0.0
         message.warning(
             'cannot convert threshold value given "%(arg)s" to float because %(exception)s, using %(threshold)2.1f',
             arg=threshold,
             exception=sys.exc_info()[0],
             threshold=self.threshold)
     self.robust = robust
     self.previous = previous
Beispiel #16
0
 def grpfact(self) :
   'group factory for grouping'
   return mdb.accessor(level=self.currvalue.level, severity=self.currvalue.severity, count=self.currvalue.count, msg=self.currvalue.msg, ident=self.currvalue.ident, subident=self.currvalue.subident, filename=self.currvalue.filename, line=self.currvalue.line)