#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import multiprocessing
import os
import sys
# We need cwd to be the same dir as our program.
import subprocess
#
# Some modules we use are located in our own proto area. So before doing
# any more imports, setup the environment we need.
#
# Make sure current directory is in the path
# Create a temporary directory for storing coverage data.
import tempfile
import six
import getopt
import pkg5testenv
import warnings
cov = None
def usage():
print("Usage: {0} [-ghptv] [-c format] [-b filename] "\
print(" {0} [-hptvx] [-c format] [-b filename] "\
print("""\
-a <dir> Archive failed test cases to <dir>/$pid/$testcasename
-b <filename> Baseline filename
-c <format> Collect code coverage data in xml or html format
-d Show debug output, including commands run, and outputs
-g Generate result baseline
-h This help message
-j Parallelism
-l Run tests against live system
-o <regexp> Run only tests that match regexp
-p Parseable output format
-q Quiet output
-s <regexp> Run tests starting at regexp
-t Generate timing info file
-v Verbose output
-x Stop after the first baseline mismatch
-z <port> Lowest port the test suite should use
if __name__ == "__main__":
#
# Start coverage before proceeding so that reports are accurate.
#
if covdir:
import coverage
# Make all warnings be errors.
# These warnings only happen in the test suite when importing
# pkg5unittest. It may be because of circular import inside pkg5unittest.
# Suppress the warning.
'renamed to CRLEntryExtensionOID',
# Suppress ResourceWarning: unclosed file.
try:
#
# !!! WARNING !!!
#
# If you add options here, you need to also update setup.py's
# test_func to include said options.
#
["generate-baseline", "parseable", "port", "timing",
"verbose", "baseline-file", "only"])
except getopt.GetoptError as e:
onlyval = []
output = ""
startattest = ""
archive_dir = None
port = 12001
jobs = 1
if opt == "-v":
output = "v"
elif opt == "-p":
output = "p"
elif opt == "-c":
elif opt == "-d":
elif opt == "-f":
elif opt == "-g":
elif opt == "-b":
elif opt == "-o":
elif opt == "-x":
elif opt == "-t":
elif opt == "-s":
elif opt == "-a":
elif opt == "-z":
try:
except ValueError:
print("The provided port must be an integer.",
usage()
elif opt == "-h":
usage()
elif opt == "-j":
elif opt == "-q":
elif opt == "-l":
print("Running tests on live system.")
import baseline
import platform
import re
import shutil
import subprocess
import types
import unittest
import pkg5unittest
# Verify that CLIENT_API_VERSION is compatible.
print("Test suite needs to be syned with the pkg bits.")
if osname == 'sunos':
elif osname == 'linux':
elif osname == 'windows':
elif osname == 'darwin':
elif osname == "aix":
if ostype == '':
time_estimates=None):
# Test pattern to match against
return True
return False
return True
# There is no unbound methods in Python 3, instead they
# simply become functions.
return True
return False
loader = Pkg5TestLoader()
testclasses = []
# "testdir" will be "api", "cli", etc., so find all the files in that
# directory that match the pattern "t_*.py".
curlinepos = 0
if curlinepos == 0:
_vprint("# ")
curlinepos += 9
continue
# "api.t_filter" -> ["api", "t_filter"]
try:
except ImportError as e:
continue
_vprint("\n# ")
curlinepos = 9
# file object (t_filter, etc)
# Get all the classes from the file
# Get the actual class object
# Make sure it's a test case
continue
# We tack this in for pretty-printing.
# Make sure its a test method
continue
# Skip some test cases for Python 3.
# test_bootenv requires boot-environment-utilities
# Python 3.x package
attrname in ["test_bootenv"]):
continue
# Remove this function from our class obj if
# it doesn't match the test pattern
if not seen:
else:
continue
None)
if not found:
_vprint("\n#\n")
testclasses = [
]
if time_estimates is None:
def __key(c):
return c.test_count()
else:
def __key(c):
if testdir not in time_estimates:
return c.test_count()
if not c.tests:
return 0
res = 0
return res
suite_list = []
if t.test_count():
suite_list.append(t)
return suite_list
if cov_format == "html":
cov_option = "-d"
elif cov_format == "xml":
cov_option = "-o"
else:
raise Exception("Unsupported coverage format")
raise Exception("Failed to generate coverage report!")
# The coverage data file and report are most likely owned by
# root, if a true test run was performed. Make the files owned
# by the owner of the test directory, so they can be easily
# removed.
try:
if cov_format == "html":
except EnvironmentError:
pass
if __name__ == "__main__":
usage()
usage()
if output != OUTPUT_DOTS:
if not onlyval:
# If coverage wasn't requested, stop it and delete the temporary data.
if not do_coverage:
cov = None
usage()
# Allow relative archive dir, but first convert it to abs. paths.
if archive_dir is not None:
print("WARNING: You don't seem to be root."
else:
# One of the tests actually calls unlink() on a directory,
# and expects it to fail as it does on ZFS, but on tmpfs
# it scarily succeeds.
])
time_estimates = {}
suites = []
if ostype == "posix":
# This is primarily of interest to developers altering the test suite,
# so don't enable it for now. The testsuite suite tends to emit a bunch
# of harmless but noisy errors to the screen due to the way it exercises
# various corner cases.
#testsuite_suite = find_tests("testsuite", onlyval, startattest, output)
#suites.append(testsuite_suite)
# Initialize the baseline results and load them
# Make sure we capture stdout
if timing_file:
# Set up coverage for cli tests
if do_coverage:
cov_env = {
}
else:
cov_env = {}
# Set the task id for this process so that we can cleanly kill
# all processes started.
if ret != 0:
print("Couldn't find the 'newtask' command. " \
"Please ensure it's in your path before running the test " \
# Run the python test suites
for suite_list in suites:
try:
break
except pkg5unittest.TestStopException as e:
break
if res.mismatches:
# Update baseline results and display mismatches (failures)
# Stop and save coverage data for API tests, and combine coverage data
# from all processes.
if do_coverage:
omits = [
# These mako templates fail.
"*etc_pkg_*mako", "_depot_conf_mako",
# Complex use of module importer makes this fail.
"*sysrepo_p5p.py",
]
try:
omits, "cov_pkg_path")
generate_coverage(coverage_format, None,
except Exception as e:
# The coverage data file and report are most likely owned by
# root, if a true test run was performed. Make the files owned
# by the owner of the test directory, so they can be easily
# removed.
try:
except EnvironmentError:
pass