2016-09-14 08:22:07 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Copyright (C) 2016 g10 Code GmbH
|
|
|
|
#
|
|
|
|
# This file is part of GPGME.
|
|
|
|
#
|
|
|
|
# GPGME 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.
|
|
|
|
#
|
|
|
|
# GPGME 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 Lesser General
|
|
|
|
# Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
2018-10-18 03:56:27 +00:00
|
|
|
# License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2016-09-14 08:22:07 +00:00
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
from __future__ import absolute_import, division
|
|
|
|
from __future__ import print_function, unicode_literals
|
2016-09-14 08:22:07 +00:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
del absolute_import, division, print_function, unicode_literals
|
|
|
|
|
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
class SplitAndAccumulate(argparse.Action):
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
current = getattr(namespace, self.dest, list())
|
|
|
|
current.extend(values.split())
|
|
|
|
setattr(namespace, self.dest, current)
|
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
parser = argparse.ArgumentParser(description='Run tests.')
|
2018-08-18 10:29:14 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'tests', metavar='TEST', type=str, nargs='+', help='A test to run')
|
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose', action="store_true", default=False, help='Be verbose.')
|
|
|
|
parser.add_argument(
|
|
|
|
'-q', '--quiet', action="store_true", default=False, help='Be quiet.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--interpreters',
|
|
|
|
metavar='PYTHON',
|
|
|
|
type=str,
|
|
|
|
default=[],
|
|
|
|
action=SplitAndAccumulate,
|
|
|
|
help='Use these interpreters to run the tests, ' + 'separated by spaces.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--srcdir',
|
|
|
|
type=str,
|
|
|
|
default=os.environ.get("srcdir", ""),
|
|
|
|
help='Location of the tests.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--builddir',
|
|
|
|
type=str,
|
|
|
|
default=os.environ.get("abs_builddir", ""),
|
|
|
|
help='Location of the tests.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--python-libdir',
|
|
|
|
type=str,
|
|
|
|
default=None,
|
|
|
|
help='Optional location of the in-tree module lib directory.')
|
|
|
|
parser.add_argument(
|
|
|
|
'--parallel',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help='Ignored. For compatibility with run-tests.scm.')
|
2016-09-14 08:22:07 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
if not args.interpreters:
|
|
|
|
args.interpreters = [sys.executable]
|
|
|
|
|
|
|
|
out = sys.stdout if args.verbose else None
|
|
|
|
err = sys.stderr if args.verbose else None
|
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
def status_to_str(code):
|
|
|
|
return {0: "PASS", 77: "SKIP", 99: "ERROR"}.get(code, "FAIL")
|
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
results = list()
|
|
|
|
for interpreter in args.interpreters:
|
2018-08-18 10:29:14 +00:00
|
|
|
version = subprocess.check_output([
|
|
|
|
interpreter, "-c",
|
|
|
|
"import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"
|
|
|
|
]).strip().decode()
|
2016-09-14 08:22:07 +00:00
|
|
|
|
2017-04-10 22:55:13 +00:00
|
|
|
if args.python_libdir:
|
|
|
|
python_libdir = args.python_libdir
|
|
|
|
else:
|
2018-08-18 10:29:14 +00:00
|
|
|
pattern = os.path.join(args.builddir, "..", "{0}-gpg".format(
|
|
|
|
os.path.basename(interpreter)), "lib*")
|
2017-04-08 13:34:33 +00:00
|
|
|
libdirs = glob.glob(pattern)
|
|
|
|
if len(libdirs) == 0:
|
2018-08-18 10:29:14 +00:00
|
|
|
sys.exit(
|
|
|
|
"Build directory matching {0!r} not found.".format(pattern))
|
2017-04-08 13:34:33 +00:00
|
|
|
elif len(libdirs) > 1:
|
2018-08-18 10:29:14 +00:00
|
|
|
sys.exit(
|
|
|
|
"Multiple build directories matching {0!r} found: {1}".format(
|
|
|
|
pattern, libdirs))
|
2017-04-08 13:34:33 +00:00
|
|
|
python_libdir = libdirs[0]
|
2017-03-14 10:10:21 +00:00
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
env = dict(os.environ)
|
2017-04-08 13:34:33 +00:00
|
|
|
env["PYTHONPATH"] = python_libdir
|
2016-09-14 08:22:07 +00:00
|
|
|
|
2016-11-30 09:39:25 +00:00
|
|
|
if not args.quiet:
|
|
|
|
print("Running tests using {0} ({1})...".format(interpreter, version))
|
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
for test in args.tests:
|
|
|
|
status = subprocess.call(
|
|
|
|
[interpreter, os.path.join(args.srcdir, test)],
|
2018-08-18 10:29:14 +00:00
|
|
|
env=env,
|
|
|
|
stdout=out,
|
|
|
|
stderr=err)
|
2016-11-30 09:39:25 +00:00
|
|
|
if not args.quiet:
|
|
|
|
print("{0}: {1}".format(status_to_str(status), test))
|
2016-09-14 08:22:07 +00:00
|
|
|
results.append(status)
|
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
def count(status):
|
|
|
|
return len(list(filter(lambda x: x == status, results)))
|
2018-08-18 10:29:14 +00:00
|
|
|
|
|
|
|
|
2016-09-14 08:22:07 +00:00
|
|
|
def failed():
|
|
|
|
return len(list(filter(lambda x: x not in (0, 77, 99), results)))
|
|
|
|
|
2018-08-18 10:29:14 +00:00
|
|
|
|
2016-11-30 09:39:25 +00:00
|
|
|
if not args.quiet:
|
|
|
|
print("{0} tests run, {1} succeeded, {2} failed, {3} skipped.".format(
|
|
|
|
len(results), count(0), failed(), count(77)))
|
2017-03-30 14:22:20 +00:00
|
|
|
sys.exit(len(results) - count(0) - count(77))
|
2016-11-30 09:39:25 +00:00
|
|
|
sys.exit(results[0])
|