File: extracttests.py.in

package info (click to toggle)
heartbeat 1%3A3.0.6-11%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,908 kB
  • sloc: ansic: 42,220; sh: 3,499; python: 1,086; makefile: 917; tcl: 523
file content (102 lines) | stat: -rw-r--r-- 3,220 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!@PYTHON@

__copyright__='''
Copyright:    (C) 2005 International Business Machines, Inc.
Author:       Alan Robertson <alanr@unix.sh>
Support:      linux-ha-dev@lists.tummy.com
License:      GNU General Public License (GPL)
'''

#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


import sys
import re

#Numeric comparison sorting
def sorttestnum(lhs, rhs):
    return int(lhs) - int(rhs)


#
#	Compress sorted list of tests into runs (ranges) of sequential tests
#	So that (1,2,3,4) gets compressed down into (1,5)
#	We add one so we get the marker showing the beginning of the next test
#
#	
#
def testruns(list):
    if len(list) < 1:
        return None, None
    first=int(list.pop(0))
    last=first+1
    while len(list) >= 1 and list[0] == last:
        last=list.pop(0)+1
    return (int(first), int(last))
     
       

#
#	Scanning for particular tests...
#
class ExtractTests:
    def expandtestranges(self, testlist):
        outlist = []
        for j in range(len(testlist)):
            match = re.match("([0-9]+)[-:]([0-9]+)", testlist[j])
            if match:
                for k in range(int(match.groups()[0]),int(match.groups()[1])+1):
                    outlist.append(k)
            else:
                outlist.append(testlist[j])
        return outlist

    def __init__(self, filename, testlist):
        self.file = open(filename, "r")
        testlist = self.expandtestranges(testlist)
        testlist.sort(sorttestnum)
        self.testlist = testlist
        print(("Extracting tests ", self.testlist))
        self.regex=re.compile(" CTS: Running test .*\[([0-9]+)")
        self.CTSregex=re.compile(" CTS: ")

    def __call__(self):
        first, last = testruns(self.testlist)
        curtest=0
        while 1:
            line = self.file.readline()
            lineprinted=None
            if line == None or line == "":
                break
            regexmatchobj=self.regex.search(line)
            if regexmatchobj:
                curtest= int(regexmatchobj.groups()[0])
            if curtest == 0:
               if self.CTSregex.search(line):
                sys.stdout.write(line)
                lineprinted=1
            if curtest >= first and not lineprinted:
                sys.stdout.write(line)
            if curtest >= last:
                first, last = testruns(self.testlist)
                if first == None:
                    break

if len(sys.argv) < 3:
    print(("Usage:", sys.argv[0] , "logfilename testnumber ..."))
    sys.exit(1)
foo = ExtractTests (sys.argv[1], sys.argv[2:])
foo()