>From b47bae0a7015ed0eb0ad9ac7113741ea55770861 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 3 Aug 2016 16:03:57 +1200 Subject: [PATCH 1/4] blackbox tests: add timestamps for subunit tests There is the icky thing with sed because some kinds of `date` don't have sub-second resolution, which we really want. Another way to do it would be: python -c "import datetime; print datetime.datetime.utcnow().strftime('time: %Y-%m-%d %H:%M:%S.%fZ')" which should be universal, but is a little slower. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- testprogs/blackbox/subunit.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testprogs/blackbox/subunit.sh b/testprogs/blackbox/subunit.sh index db7fb05..70fe2d7 100755 --- a/testprogs/blackbox/subunit.sh +++ b/testprogs/blackbox/subunit.sh @@ -18,14 +18,23 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +timestamp() { + # mark the start time. With Gnu date, you get nanoseconds from %N + # (here truncated to microseconds with %6N), but not on BSDs, + # Solaris, etc, which will apparently leave either %N or N at the end. + date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/%\?NZ$/000000Z/' +} + subunit_start_test () { # emit the current protocol start-marker for test $1 + timestamp echo "test: $1" } subunit_pass_test () { # emit the current protocol test passed marker for test $1 + timestamp echo "success: $1" } @@ -38,6 +47,7 @@ subunit_fail_test () { # the error text. # we use stdin because the failure message can be arbitrarily long, and this # makes it convenient to write in scripts (using <From 317ae3c49fa28fdd4202dd0f493c582ee02b551f Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 29 Jul 2016 10:57:52 +1200 Subject: [PATCH 2/4] selftest: allow tests.py scripts to run independently These generate lists of test commands. Usually they are run in special environments, but they should work from the command line. This restores the intended behaviour. Signed-off-by: Douglas Bagnall --- selftest/tests.py | 1 + source3/selftest/tests.py | 1 + 2 files changed, 2 insertions(+) diff --git a/selftest/tests.py b/selftest/tests.py index e02f049..62dadab 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -23,6 +23,7 @@ from selftesthelpers import * try: config_h = os.environ["CONFIG_H"] except KeyError: + samba4bindir = bindir() config_h = os.path.join(samba4bindir, "default/include/config.h") # define here var to check what we support diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 0a0cb08..7cffdf1 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -205,6 +205,7 @@ for env in ["fileserver"]: try: config_h = os.environ["CONFIG_H"] except KeyError: + samba4bindir = bindir() config_h = os.path.join(samba4bindir, "default/include/config.h") # see if libarchive is supported -- 2.7.4 >From d2fb48a47aaab6dbb328dd321be83f1dc7815d41 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Tue, 2 Aug 2016 10:27:05 +1200 Subject: [PATCH 3/4] subunithelper: use set for efficient inclusion test Signed-off-by: Douglas Bagnall --- selftest/subunithelper.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/selftest/subunithelper.py b/selftest/subunithelper.py index 948256d..441bafa 100644 --- a/selftest/subunithelper.py +++ b/selftest/subunithelper.py @@ -24,7 +24,11 @@ from samba.subunit.run import TestProtocolClient from samba.subunit import iso8601 import unittest -VALID_RESULTS = ['success', 'successful', 'failure', 'fail', 'skip', 'knownfail', 'error', 'xfail', 'skip-testsuite', 'testsuite-failure', 'testsuite-xfail', 'testsuite-success', 'testsuite-error', 'uxsuccess', 'testsuite-uxsuccess'] +VALID_RESULTS = set(['success', 'successful', 'failure', 'fail', 'skip', + 'knownfail', 'error', 'xfail', 'skip-testsuite', + 'testsuite-failure', 'testsuite-xfail', + 'testsuite-success', 'testsuite-error', + 'uxsuccess', 'testsuite-uxsuccess']) class TestsuiteEnabledTestResult(unittest.TestResult): -- 2.7.4 >From 1983c357195798f72510609592fe3ed409c6f200 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Tue, 2 Aug 2016 11:00:27 +1200 Subject: [PATCH 4/4] filter-subunit: default to empty affixes, saving verbose checks Signed-off-by: Douglas Bagnall --- selftest/filter-subunit | 12 +++--------- selftest/subunithelper.py | 9 +-------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/selftest/filter-subunit b/selftest/filter-subunit index fe157a0..857b842 100755 --- a/selftest/filter-subunit +++ b/selftest/filter-subunit @@ -36,9 +36,9 @@ parser.add_option("--strip-passed-output", action="store_true", help="Whether to strip output from tests that passed") parser.add_option("--fail-immediately", action="store_true", help="Whether to stop on the first error", default=False) -parser.add_option("--prefix", type="string", +parser.add_option("--prefix", type="string", default='', help="Add prefix to all test names") -parser.add_option("--suffix", type="string", +parser.add_option("--suffix", type="string", default='', help="Add suffix to all test names") parser.add_option("--fail-on-empty", default=False, action="store_true", help="Fail if there was no subunit output") @@ -47,14 +47,8 @@ parser.add_option("--list", default=False, opts, args = parser.parse_args() if opts.list: - prefix = opts.prefix - suffix = opts.suffix - if not prefix: - prefix = "" - if not suffix: - suffix = "" for l in sys.stdin: - sys.stdout.write("%s%s%s\n" % (prefix, l.rstrip(), suffix)) + sys.stdout.write("%s%s%s\n" % (opts.prefix, l.rstrip(), opts.suffix)) sys.exit(0) if opts.expected_failures: diff --git a/selftest/subunithelper.py b/selftest/subunithelper.py index 441bafa..a3bb30b 100644 --- a/selftest/subunithelper.py +++ b/selftest/subunithelper.py @@ -287,14 +287,7 @@ class FilterOps(unittest.TestResult): self._ops.startTest(test) def _add_prefix(self, test): - prefix = "" - suffix = "" - if self.prefix is not None: - prefix = self.prefix - if self.suffix is not None: - suffix = self.suffix - - return subunit.RemotedTestCase(prefix + test.id() + suffix) + return subunit.RemotedTestCase(self.prefix + test.id() + self.suffix) def addError(self, test, err=None): test = self._add_prefix(test) -- 2.7.4