Created
February 29, 2012 10:15
-
-
Save xoyowade/1939623 to your computer and use it in GitHub Desktop.
regression case filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [[ $# -lt 3 ]]; then | |
echo "An example driver to make the usage of findcase easier" | |
echo "Usage: $0 pattern input_file output_prefix" | |
exit | |
fi | |
input=`readlink -f $2` | |
indir=`dirname $input` | |
out_chosen=$indir/$3-chosen | |
out_left=$indir/$3-left | |
cd `dirname $0` | |
./findcase.py $1 $input $out_chosen $out_left | |
echo There are `./findcase.sh $1 $input | wc -l` cases in pattern """$1""". | |
echo The results are dumped to | |
echo $out_chosen and | |
echo $out_left. | |
cd - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import string | |
import re | |
class Case: | |
def __init__(self, name): | |
self.name = name | |
self.diff = "" | |
def dump_name(self, file): | |
print >>file, self.name | |
def dump(self, file): | |
print >>file, self.name, "UNANALYZED" | |
print >>file, self.diff | |
class CaseFilter: | |
def __init__(self, pattern, input, out_chosen, out_left): | |
self.pattern = pattern | |
self.out_chosen = out_chosen | |
self.out_left = out_left | |
self.cases = [] | |
lines = input.readlines() | |
# omit the header | |
for i in range(len(lines)): | |
if re.search("HEADER-END", lines[i]): | |
i = i + 1 | |
break | |
# load cases | |
name_filter = re.compile(r"(unit_.*).*UNANALYZED.*") | |
while i < len(lines): | |
# begin of a case | |
if lines[i] == "\n": | |
if i+1 >= len(lines): | |
break | |
result = name_filter.match(lines[i+1]) | |
if result: | |
case = Case(result.group(0)) | |
self.cases.append(case) | |
i = i + 2 | |
while i < len(lines) and lines[i] != "\n": | |
if result: | |
case.diff = case.diff + lines[i] | |
i = i + 1 | |
def execute(self): | |
chosen = [] | |
left = [] | |
error_filter = re.compile(self.pattern) | |
for case in self.cases: | |
if error_filter.search(case.diff): | |
chosen.append(case) | |
else: | |
left.append(case) | |
# dump result | |
for case in chosen: | |
case.dump_name(out_chosen) | |
print >>out_left, "---------HEADER-END (%d cases)-----------\n" % len(left) | |
for case in left: | |
case.dump(out_left) | |
if __name__ == "__main__": | |
if len(sys.argv) < 5: | |
print "A script to grep cases out of regrun result, keeping the left cases as original format" | |
print "Usage: %s pattern input chosen_list left_cases" % sys.argv[0] | |
input = open(sys.argv[2]) | |
out_chosen = open(sys.argv[3], "w") | |
out_left = open(sys.argv[4], "w") | |
filter = CaseFilter(sys.argv[1], input, out_chosen, out_left) | |
filter.execute() | |
input.close() | |
out_chosen.close() | |
out_left.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [[ $# -lt 2 ]]; then | |
echo "A script to grep cases out of regrun result" | |
echo "Usage: $0 error_pattern input_file" | |
echo "the pattern cannot include blank space(" "), use dot(".") instead" | |
exit | |
fi | |
MAGIC_TOKEN=REG-ERROR-43592 | |
sed -n 's/\(unit_.*\) : UNANALYZED :.*/\1/p;s/'$1'/'${MAGIC_TOKEN}'/p' $2 | grep -B 1 ${MAGIC_TOKEN}| grep unit_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment