diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py index e5945bda9c3bd32a4fa0de2ade4c25fed8724a34..e5c4c0dde8ff71e2ffb23c44722e875500f15258 100644 --- a/lib/spack/spack/cmd/common/arguments.py +++ b/lib/spack/spack/cmd/common/arguments.py @@ -275,3 +275,53 @@ def no_checksum(): return Args( '-n', '--no-checksum', action='store_true', default=False, help="do not use checksums to verify downloaded files (unsafe)") + + +def add_cdash_args(subparser, add_help): + cdash_help = {} + if add_help: + cdash_help['upload-url'] = "CDash URL where reports will be uploaded" + cdash_help['build'] = """The name of the build that will be reported to CDash. +Defaults to spec of the package to operate on.""" + cdash_help['site'] = """The site name that will be reported to CDash. +Defaults to current system hostname.""" + cdash_help['track'] = """Results will be reported to this group on CDash. +Defaults to Experimental.""" + cdash_help['buildstamp'] = """Instead of letting the CDash reporter prepare the +buildstamp which, when combined with build name, site and project, +uniquely identifies the build, provide this argument to identify +the build yourself. Format: %%Y%%m%%d-%%H%%M-[cdash-track]""" + else: + cdash_help['upload-url'] = argparse.SUPPRESS + cdash_help['build'] = argparse.SUPPRESS + cdash_help['site'] = argparse.SUPPRESS + cdash_help['track'] = argparse.SUPPRESS + cdash_help['buildstamp'] = argparse.SUPPRESS + + subparser.add_argument( + '--cdash-upload-url', + default=None, + help=cdash_help['upload-url'] + ) + subparser.add_argument( + '--cdash-build', + default=None, + help=cdash_help['build'] + ) + subparser.add_argument( + '--cdash-site', + default=None, + help=cdash_help['site'] + ) + + cdash_subgroup = subparser.add_mutually_exclusive_group() + cdash_subgroup.add_argument( + '--cdash-track', + default='Experimental', + help=cdash_help['track'] + ) + cdash_subgroup.add_argument( + '--cdash-buildstamp', + default=None, + help=cdash_help['buildstamp'] + ) diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index 39bcc96ce52587b5ea2d83d639dc9bcf1dd2d3fe..1028bbb7daa2403871a1cc21eddd3332a3a009dd 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -160,58 +160,8 @@ def setup_parser(subparser): action='store_true', help="Show usage instructions for CDash reporting" ) - add_cdash_args(subparser, False) - arguments.add_common_arguments(subparser, ['yes_to_all', 'spec']) - - -def add_cdash_args(subparser, add_help): - cdash_help = {} - if add_help: - cdash_help['upload-url'] = "CDash URL where reports will be uploaded" - cdash_help['build'] = """The name of the build that will be reported to CDash. -Defaults to spec of the package to install.""" - cdash_help['site'] = """The site name that will be reported to CDash. -Defaults to current system hostname.""" - cdash_help['track'] = """Results will be reported to this group on CDash. -Defaults to Experimental.""" - cdash_help['buildstamp'] = """Instead of letting the CDash reporter prepare the -buildstamp which, when combined with build name, site and project, -uniquely identifies the build, provide this argument to identify -the build yourself. Format: %%Y%%m%%d-%%H%%M-[cdash-track]""" - else: - cdash_help['upload-url'] = argparse.SUPPRESS - cdash_help['build'] = argparse.SUPPRESS - cdash_help['site'] = argparse.SUPPRESS - cdash_help['track'] = argparse.SUPPRESS - cdash_help['buildstamp'] = argparse.SUPPRESS - - subparser.add_argument( - '--cdash-upload-url', - default=None, - help=cdash_help['upload-url'] - ) - subparser.add_argument( - '--cdash-build', - default=None, - help=cdash_help['build'] - ) - subparser.add_argument( - '--cdash-site', - default=None, - help=cdash_help['site'] - ) - - cdash_subgroup = subparser.add_mutually_exclusive_group() - cdash_subgroup.add_argument( - '--cdash-track', - default='Experimental', - help=cdash_help['track'] - ) - cdash_subgroup.add_argument( - '--cdash-buildstamp', - default=None, - help=cdash_help['buildstamp'] - ) + arguments.add_cdash_args(subparser, False) + arguments.add_common_arguments(subparser, ['yes_to_all']) def default_log_file(spec): @@ -263,7 +213,7 @@ def install(parser, args, **kwargs): SPACK_CDASH_AUTH_TOKEN authentication token to present to CDash ''')) - add_cdash_args(parser, True) + arguments.add_cdash_args(parser, True) parser.print_help() return diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py index 5dddd8c676244dc77f521b1d02fe7c11d3ab87a2..759cbb000a5b0344c2855a67e14c35dc0b853838 100644 --- a/lib/spack/spack/cmd/test.py +++ b/lib/spack/spack/cmd/test.py @@ -6,11 +6,14 @@ from __future__ import print_function import os import argparse +import textwrap import llnl.util.tty as tty import spack.environment as ev import spack.cmd +import spack.cmd.common.arguments as arguments +import spack.report description = "run spack's tests for an install" section = "administrator" @@ -18,50 +21,24 @@ def setup_parser(subparser): -# subparser.add_argument( -# '--log-format', -# default=None, -# choices=spack.report.valid_formats, -# help="format to be used for log files" -# ) -# subparser.add_argument( -# '--output-file', -# default=None, -# help="filename for the log file. if not passed a default will be used" -# ) -# subparser.add_argument( -# '--cdash-upload-url', -# default=None, -# help="CDash URL where reports will be uploaded" -# ) -# subparser.add_argument( -# '--cdash-build', -# default=None, -# help="""The name of the build that will be reported to CDash. -# Defaults to spec of the package to install.""" -# ) -# subparser.add_argument( -# '--cdash-site', -# default=None, -# help="""The site name that will be reported to CDash. -# Defaults to current system hostname.""" -# ) -# cdash_subgroup = subparser.add_mutually_exclusive_group() -# cdash_subgroup.add_argument( -# '--cdash-track', -# default='Experimental', -# help="""Results will be reported to this group on CDash. -# Defaults to Experimental.""" -# ) -# cdash_subgroup.add_argument( -# '--cdash-buildstamp', -# default=None, -# help="""Instead of letting the CDash reporter prepare the -# buildstamp which, when combined with build name, site and project, -# uniquely identifies the build, provide this argument to identify -# the build yourself. Format: %%Y%%m%%d-%%H%%M-[cdash-track]""" -# ) -# arguments.add_common_arguments(subparser, ['yes_to_all']) + subparser.add_argument( + '--log-format', + default=None, + choices=spack.report.valid_formats, + help="format to be used for log files" + ) + subparser.add_argument( + '--log-file', + default=None, + help="filename for the log file. if not passed a default will be used" + ) + arguments.add_cdash_args(subparser, False) + subparser.add_argument( + '--help-cdash', + action='store_true', + help="Show usage instructions for CDash reporting" + ) + length_group = subparser.add_mutually_exclusive_group() length_group.add_argument( '--smoke', action='store_true', dest='smoke_test', default=True, @@ -76,6 +53,20 @@ def setup_parser(subparser): def test(parser, args): + # cdash help option + if args.help_cdash: + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=textwrap.dedent('''\ +environment variables: + SPACK_CDASH_AUTH_TOKEN + authentication token to present to CDash + ''')) + arguments.add_cdash_args(parser, True) + parser.print_help() + return + + # Get specs to test env = ev.get_env(args, 'test') hashes = env.all_hashes() if env else None @@ -87,11 +78,25 @@ def test(parser, args): tty.warn("No installed packages match spec %s" % spec) specs_to_test.extend(matching) - log_dir = os.getcwd() + # Set up reporter + setattr(args, 'package', [s.format() for s in specs_to_test]) + reporter = spack.report.collect_info(args.log_format, args) + if not reporter.filename: + if args.log_file: + if os.path.isabs(args.log_file): + log_file = args.log_file + else: + log_dir = os.getcwd() + log_file = os.path.join(log_dir, args.log_file) + else: + log_file = os.path.join(os.getcwd(), + 'test-%s' % specs_to_test[0].dag_hash()) + reporter.filename = log_file + reporter.specs = specs_to_test - if args.smoke_test: - for spec in specs_to_test: - log_file = os.path.join(log_dir, 'test-%s' % spec.dag_hash()) - spec.package.do_test(log_file) - else: - raise NotImplementedError + with reporter: + if args.smoke_test: + for spec in specs_to_test: + spec.package.do_test() + else: + raise NotImplementedError diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index b571769cf37c7f5c0ed8a9abf3792377ab1bca8d..b04b41942152d54ff6e3d30337a014fb58e0ba61 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1576,9 +1576,11 @@ def do_install(self, **kwargs): do_install.__doc__ += install_args_docstring - def do_test(self, log_file, dirty=False): + def do_test(self, dirty=False): def test_process(): - with log_output(log_file) as logger: + test_log_file = os.path.join( + os.getcwd(), 'test-%s' % self.spec.format('{name}-{hash:7}')) + with log_output(test_log_file) as logger: with logger.force_echo(): tty.msg('Testing package %s' % self.spec.format('{name}-{hash:7}'))