2019-02-12 00:30:40 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2019-02-11 18:48:53 +08:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import getopt
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
from pprint import pprint as ppr
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
def Usage(s):
|
|
|
|
print 'Usage: {} -t <cstest_path> [-f <file_name.cs>] [-d <directory>]'.format(s)
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2019-02-12 13:58:46 +08:00
|
|
|
def get_report_file(toolpath, filepath, getDetails):
|
2019-02-11 18:48:53 +08:00
|
|
|
cmd = [toolpath, '-f', filepath]
|
|
|
|
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
|
|
|
stdout, stderr = process.communicate()
|
|
|
|
|
|
|
|
# stdout
|
|
|
|
failed_tests = []
|
2019-02-12 13:58:46 +08:00
|
|
|
# print '---> stdout\n', stdout
|
|
|
|
# print '---> stderr\n', stderr
|
2019-02-11 18:48:53 +08:00
|
|
|
matches = re.finditer(r'\[\s+RUN\s+\]\s+(.*)\n\[\s+FAILED\s+\]', stdout)
|
|
|
|
for match in matches:
|
|
|
|
failed_tests.append(match.group(1))
|
|
|
|
# stderr
|
|
|
|
counter = 0
|
|
|
|
details = []
|
|
|
|
for line in stderr.split('\n'):
|
|
|
|
if '[ PASSED ] 0 test(s).' in line:
|
|
|
|
break
|
|
|
|
elif 'LINE' in line:
|
|
|
|
continue
|
2019-02-12 13:58:46 +08:00
|
|
|
elif 'ERROR' in line and ' --- ' in line:
|
|
|
|
try:
|
|
|
|
details.append((failed_tests[counter], line.split(' --- ')[1]))
|
|
|
|
except IndexError:
|
|
|
|
details.append(('Unknown test', line.split(' --- ')[1]))
|
2019-02-11 18:48:53 +08:00
|
|
|
counter += 1
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
print '\n[-] There are/is {} failed test(s)'.format(len(details))
|
2019-02-12 13:58:46 +08:00
|
|
|
if len(details) > 0 and getDetails:
|
2019-02-11 18:48:53 +08:00
|
|
|
print '[-] Detailed report for {}:\n'.format(filepath)
|
|
|
|
for f, d in details:
|
|
|
|
print '\t[+] {}:\n\t\t{}\n'.format(f, d)
|
|
|
|
print '\n'
|
|
|
|
|
2019-02-12 13:58:46 +08:00
|
|
|
def get_report_folder(toolpath, folderpath, details):
|
|
|
|
for root, dirs, files in os.walk(folderpath):
|
|
|
|
path = root.split(os.sep)
|
|
|
|
for f in files:
|
|
|
|
if f.split('.')[-1] == 'cs':
|
|
|
|
print '[-] Target:', f,
|
2019-02-12 15:01:16 +08:00
|
|
|
get_report_file(toolpath, os.sep.join(x for x in path) + os.sep + f, details)
|
2019-02-11 18:48:53 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
Done = False
|
2019-02-12 13:58:46 +08:00
|
|
|
details = False
|
2019-02-11 18:48:53 +08:00
|
|
|
toolpath = ''
|
|
|
|
try:
|
2019-02-12 13:58:46 +08:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "t:f:d:D")
|
2019-02-11 18:48:53 +08:00
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == '-f':
|
2019-02-12 13:58:46 +08:00
|
|
|
get_report_file(toolpath, arg, details)
|
2019-02-11 18:48:53 +08:00
|
|
|
Done = True
|
|
|
|
elif opt == '-d':
|
2019-02-12 13:58:46 +08:00
|
|
|
get_report_folder(toolpath, arg, details)
|
2019-02-11 18:48:53 +08:00
|
|
|
Done = True
|
|
|
|
elif opt == '-t':
|
|
|
|
toolpath = arg
|
2019-02-12 13:58:46 +08:00
|
|
|
elif opt == '-D':
|
2019-02-12 15:01:16 +08:00
|
|
|
details = True
|
2019-02-11 18:48:53 +08:00
|
|
|
except getopt.GetoptError:
|
|
|
|
Usage(sys.argv[0])
|
|
|
|
|
|
|
|
if Done is False:
|
|
|
|
Usage(sys.argv[0])
|