2006-10-15 15:04:27 -04:00
|
|
|
#! /usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
|
|
|
|
#
|
|
|
|
# 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
|
2007-12-10 23:55:22 -05:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
import os
|
2007-02-26 03:19:02 -05:00
|
|
|
import os.path
|
2006-10-15 15:04:27 -04:00
|
|
|
import time
|
|
|
|
|
|
|
|
import pmtest
|
|
|
|
|
|
|
|
|
|
|
|
class pmenv:
|
2007-02-21 01:33:13 -05:00
|
|
|
"""Environment object
|
|
|
|
"""
|
|
|
|
|
2008-07-24 23:14:27 -04:00
|
|
|
testcases = []
|
|
|
|
passed = 0
|
|
|
|
failed = 0
|
|
|
|
expectedfail = 0
|
|
|
|
unexpectedpass = 0
|
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
def __init__(self, root = "root"):
|
|
|
|
self.root = os.path.abspath(root)
|
|
|
|
self.pacman = {
|
|
|
|
"bin": "pacman",
|
|
|
|
"debug": 0,
|
|
|
|
"gdb": 0,
|
|
|
|
"valgrind": 0,
|
|
|
|
"nolog": 0
|
|
|
|
}
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "root = %s\n" \
|
|
|
|
"pacman = %s" \
|
|
|
|
% (self.root, self.pacman)
|
|
|
|
|
|
|
|
def addtest(self, testcase):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if not os.path.isfile(testcase):
|
2008-07-24 23:14:27 -04:00
|
|
|
raise IOError("test file %s not found" % testcase)
|
2007-02-21 01:33:13 -05:00
|
|
|
test = pmtest.pmtest(testcase, self.root)
|
|
|
|
self.testcases.append(test)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
for t in self.testcases:
|
|
|
|
print "=========="*8
|
2007-02-26 03:19:02 -05:00
|
|
|
print "Running '%s'" % t.testname
|
2007-02-21 01:33:13 -05:00
|
|
|
|
|
|
|
t.load()
|
|
|
|
print t.description
|
|
|
|
print "----------"*8
|
|
|
|
|
|
|
|
t.generate()
|
|
|
|
# Hack for mtimes consistency
|
|
|
|
for i in t.rules:
|
2008-07-31 22:16:30 -04:00
|
|
|
if i.rule.find("FILE_MODIFIED") != -1:
|
|
|
|
[test, arg] = i.rule.split("=")
|
|
|
|
for f in t.files:
|
|
|
|
if f.name == arg:
|
|
|
|
f.resettimes()
|
2007-02-21 01:33:13 -05:00
|
|
|
|
|
|
|
t.run(self.pacman)
|
|
|
|
|
|
|
|
t.check()
|
|
|
|
print "==> Test result"
|
|
|
|
if t.result["fail"] == 0:
|
2007-03-01 14:07:38 -05:00
|
|
|
print "\tPASS"
|
2007-02-21 01:33:13 -05:00
|
|
|
else:
|
2007-03-01 14:07:38 -05:00
|
|
|
print "\tFAIL"
|
2007-02-21 01:33:13 -05:00
|
|
|
print
|
|
|
|
|
|
|
|
def results(self):
|
|
|
|
"""
|
|
|
|
"""
|
2007-02-26 03:19:02 -05:00
|
|
|
tpassed = []
|
|
|
|
tfailed = []
|
2008-07-24 22:42:27 -04:00
|
|
|
texpectedfail = []
|
|
|
|
tunexpectedpass = []
|
2007-02-21 01:33:13 -05:00
|
|
|
for test in self.testcases:
|
2007-02-26 03:19:02 -05:00
|
|
|
fail = test.result["fail"]
|
2008-07-24 22:42:27 -04:00
|
|
|
if fail == 0 and not test.expectfailure:
|
2008-07-24 23:14:27 -04:00
|
|
|
self.passed += 1
|
2007-02-26 03:19:02 -05:00
|
|
|
tpassed.append(test)
|
2008-07-24 22:42:27 -04:00
|
|
|
elif fail != 0 and test.expectfailure:
|
2008-07-24 23:14:27 -04:00
|
|
|
self.expectedfail += 1
|
2008-07-24 22:42:27 -04:00
|
|
|
texpectedfail.append(test)
|
|
|
|
elif fail == 0: # and not test.expectfail
|
2008-07-24 23:14:27 -04:00
|
|
|
self.unexpectedpass += 1
|
2008-07-24 22:42:27 -04:00
|
|
|
tunexpectedpass.append(test)
|
2007-02-26 03:19:02 -05:00
|
|
|
else:
|
2008-07-24 23:14:27 -04:00
|
|
|
self.failed += 1
|
2007-02-26 03:19:02 -05:00
|
|
|
tfailed.append(test)
|
|
|
|
|
|
|
|
def _printtest(t):
|
2007-02-21 01:33:13 -05:00
|
|
|
success = test.result["success"]
|
|
|
|
fail = test.result["fail"]
|
|
|
|
rules = len(test.rules)
|
|
|
|
if fail == 0:
|
2007-03-01 14:07:38 -05:00
|
|
|
result = "[PASS]"
|
2007-02-21 01:33:13 -05:00
|
|
|
else:
|
2007-03-01 14:07:38 -05:00
|
|
|
result = "[FAIL]"
|
2007-02-28 11:37:24 -05:00
|
|
|
print result,
|
2007-02-27 14:44:45 -05:00
|
|
|
print "%s Rules: OK = %2u FAIL = %2u SKIP = %2u" \
|
2007-03-01 14:07:38 -05:00
|
|
|
% (test.testname.ljust(34), success, fail, \
|
2007-02-28 11:37:24 -05:00
|
|
|
rules - (success + fail))
|
|
|
|
if fail != 0:
|
|
|
|
# print test description if test failed
|
2007-03-01 14:07:38 -05:00
|
|
|
print " ", test.description
|
2007-02-26 03:19:02 -05:00
|
|
|
|
|
|
|
print "=========="*8
|
|
|
|
print "Results"
|
2007-02-21 01:33:13 -05:00
|
|
|
print "----------"*8
|
2008-07-24 22:42:27 -04:00
|
|
|
print " Passed:"
|
2007-02-26 03:19:02 -05:00
|
|
|
for test in tpassed: _printtest(test)
|
|
|
|
print "----------"*8
|
2008-07-24 22:42:27 -04:00
|
|
|
print " Expected Failures:"
|
|
|
|
for test in texpectedfail: _printtest(test)
|
|
|
|
print "----------"*8
|
|
|
|
print " Unexpected Passes:"
|
|
|
|
for test in tunexpectedpass: _printtest(test)
|
|
|
|
print "----------"*8
|
|
|
|
print " Failed:"
|
2007-02-26 03:19:02 -05:00
|
|
|
for test in tfailed: _printtest(test)
|
|
|
|
print "----------"*8
|
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
total = len(self.testcases)
|
2008-07-24 22:42:27 -04:00
|
|
|
print "Total = %3u" % total
|
2007-02-21 01:33:13 -05:00
|
|
|
if total:
|
2008-07-24 23:14:27 -04:00
|
|
|
print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total)
|
|
|
|
print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total)
|
|
|
|
print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total)
|
|
|
|
print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total)
|
2007-02-26 03:19:02 -05:00
|
|
|
print ""
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2008-07-24 23:14:27 -04:00
|
|
|
pass
|
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
# vim: set ts=4 sw=4 et:
|