def setUp(self): get_modules_system().searchpath_add(fixtures.TEST_MODULES) # Load a system configuration self.system, self.partition, self.progenv = fixtures.get_test_config() self.resourcesdir = tempfile.mkdtemp(dir='unittests') self.loader = RegressionCheckLoader(['unittests/resources']) self.resources = ResourcesManager(prefix=self.resourcesdir)
def _setup(self, partition, environ, **job_opts): if environ.name == 'PrgEnv-pgi': get_modules_system().searchpath_add( '/apps/common/UES/pgi/18.4/modulefiles') self.modules += ['pgi/18.4'] self.variables.update({'PGI_VERS_STR': '18.4.0'}) self.pre_run = ['module use /apps/common/UES/pgi/18.4/modulefiles'] super().setup(partition, environ, **job_opts)
def test_conflicting_environments(self): envfoo = renv.Environment(name='envfoo', modules=['testmod_foo', 'testmod_boo']) envbar = renv.Environment(name='envbar', modules=['testmod_bar']) envfoo.load() envbar.load() for m in envbar.modules: self.assertTrue(get_modules_system().is_module_loaded(m)) for m in envfoo.modules: self.assertFalse(get_modules_system().is_module_loaded(m))
def unload(self): if not self._loaded: return for k, v in self._variables.items(): if k in self._saved_variables: os.environ[k] = self._saved_variables[k] elif k in os.environ: del os.environ[k] # Unload modules in reverse order for m in reversed(self._modules): if m not in self._preloaded: get_modules_system().unload_module(m) # Reload the conflicted packages, previously removed for m in self._conflicted: get_modules_system().load_module(m) self._loaded = False
def load(self): # conflicted module list must be filled at the time of load for m in self._modules: if get_modules_system().is_module_loaded(m): self._preloaded.add(m) self._conflicted += get_modules_system().load_module(m, force=True) for conflict in self._conflicted: # FIXME: explicit modules system commands are no more portable self._load_stmts += ['module unload %s' % conflict] self._load_stmts += ['module load %s' % m] for k, v in self._variables.items(): if k in os.environ: self._saved_variables[k] = os.environ[k] os.environ[k] = os.path.expandvars(v) self._loaded = True
def load(self): # conflicted module list must be filled at the time of load for m in self._modules: if get_modules_system().is_module_loaded(m): self._preloaded.add(m) self._conflicted += get_modules_system().load_module(m, force=True) for conflict in self._conflicted: stmts = get_modules_system().emit_unload_commands(conflict) self._load_stmts += stmts self._load_stmts += get_modules_system().emit_load_commands(m) for k, v in self._variables.items(): if k in os.environ: self._saved_variables[k] = os.environ[k] os.environ[k] = os.path.expandvars(v) self._loaded = True
def setUp(self): get_modules_system().searchpath_add(fixtures.TEST_MODULES) # Always add a base module; this is a workaround for the modules # environment's inconsistent behaviour, that starts with an empty # LOADEDMODULES variable and ends up removing it completely if all # present modules are removed. get_modules_system().load_module('testmod_base') os.environ['_fookey1'] = 'origfoo' os.environ['_fookey1b'] = 'foovalue1' os.environ['_fookey2b'] = 'foovalue2' self.environ_save = renv.EnvironmentSnapshot() self.environ = renv.Environment(name='TestEnv1', modules=['testmod_foo']) self.environ.set_variable(name='_fookey1', value='value1') self.environ.set_variable(name='_fookey2', value='value2') self.environ.set_variable(name='_fookey1', value='value3') self.environ.set_variable(name='_fookey3b', value='$_fookey1b') self.environ.set_variable(name='_fookey4b', value='${_fookey2b}') self.environ_other = renv.Environment(name='TestEnv2', modules=['testmod_boo']) self.environ_other.set_variable(name='_fookey11', value='value11')
def test_load_restore(self): self.environ.load() self.assertEnvironmentVariable(name='_fookey1', value='value3') self.assertEnvironmentVariable(name='_fookey2', value='value2') self.assertEnvironmentVariable(name='_fookey3b', value='foovalue1') self.assertEnvironmentVariable(name='_fookey4b', value='foovalue2') self.assertTrue(self.environ.is_loaded) if fixtures.has_sane_modules_system(): self.assertModulesLoaded(self.environ.modules) self.environ.unload() self.assertEqual(self.environ_save, renv.EnvironmentSnapshot()) self.assertEnvironmentVariable(name='_fookey1', value='origfoo') if fixtures.has_sane_modules_system(): self.assertFalse( get_modules_system().is_module_loaded('testmod_foo'))
def test_environ_setup(self): test = self.loader.load_from_file('unittests/resources/hellocheck.py', system=self.system, resources=self.resources)[0] # Use test environment for the regression check test.valid_prog_environs = [self.progenv.name] test.modules = ['testmod_foo'] test.variables = {'_FOO_': '1', '_BAR_': '2'} test.local = True test.setup(self.partition, self.progenv) for m in test.modules: self.assertTrue(get_modules_system().is_module_loaded(m)) for k, v in test.variables.items(): self.assertEqual(os.environ[k], v) # Manually unload the environment self.progenv.unload()
def has_sane_modules_system(): return not isinstance(get_modules_system().backend, NoModImpl)
def tearDown(self): get_modules_system().searchpath_remove(fixtures.TEST_MODULES) self.environ_save.load()
def setUp(self): self.modules_system = modules.get_modules_system() self.environ_save = EnvironmentSnapshot() self.modules_system.searchpath_add(TEST_MODULES)
def assertModulesNotLoaded(self, modules): for m in modules: self.assertFalse(get_modules_system().is_module_loaded(m))
def assertModulesLoaded(self, modules): for m in modules: self.assertTrue(get_modules_system().is_module_loaded(m))
def test_conflict_environ_after_module_force_load(self): get_modules_system().load_module('testmod_foo') envbar = renv.Environment(name='envbar', modules=['testmod_bar']) envbar.load() envbar.unload() self.assertTrue(get_modules_system().is_module_loaded('testmod_foo'))
def main(): # Setup command line options argparser = ArgumentParser() output_options = argparser.add_argument_group( 'Options controlling regression directories') locate_options = argparser.add_argument_group( 'Options for locating checks') select_options = argparser.add_argument_group( 'Options for selecting checks') action_options = argparser.add_argument_group( 'Options controlling actions') run_options = argparser.add_argument_group( 'Options controlling execution of checks') misc_options = argparser.add_argument_group('Miscellaneous options') # Output directory options output_options.add_argument( '--prefix', action='store', metavar='DIR', help='Set regression prefix directory to DIR') output_options.add_argument( '-o', '--output', action='store', metavar='DIR', help='Set regression output directory to DIR') output_options.add_argument( '-s', '--stage', action='store', metavar='DIR', help='Set regression stage directory to DIR') output_options.add_argument( '--logdir', action='store', metavar='DIR', help='Set regression log directory to DIR') output_options.add_argument( '--keep-stage-files', action='store_true', help='Keep stage directory even if check is successful') output_options.add_argument( '--save-log-files', action='store_true', default=False, help='Copy the log file from the work dir to the output dir at the ' 'end of the program') # Check discovery options locate_options.add_argument( '-c', '--checkpath', action='append', metavar='DIR|FILE', help='Search for checks in DIR or FILE') locate_options.add_argument( '-R', '--recursive', action='store_true', help='Load checks recursively') # Select options select_options.add_argument( '-t', '--tag', action='append', dest='tags', default=[], help='Select checks matching TAG') select_options.add_argument( '-n', '--name', action='append', dest='names', default=[], metavar='NAME', help='Select checks with NAME') select_options.add_argument( '-x', '--exclude', action='append', dest='exclude_names', metavar='NAME', default=[], help='Exclude checks with NAME') select_options.add_argument( '-p', '--prgenv', action='append', default=[], help='Select tests for PRGENV programming environment only') select_options.add_argument( '--gpu-only', action='store_true', help='Select only GPU tests') select_options.add_argument( '--cpu-only', action='store_true', help='Select only CPU tests') # Action options action_options.add_argument( '-l', '--list', action='store_true', help='list matched regression checks') action_options.add_argument( '-r', '--run', action='store_true', help='Run regression with the selected checks') # Run options run_options.add_argument( '-A', '--account', action='store', help='Use ACCOUNT for submitting jobs') run_options.add_argument( '-P', '--partition', action='store', metavar='PART', help='Use PART for submitting jobs') run_options.add_argument( '--reservation', action='store', metavar='RES', help='Use RES for submitting jobs') run_options.add_argument( '--nodelist', action='store', help='Run checks on the selected list of nodes') run_options.add_argument( '--exclude-nodes', action='store', metavar='NODELIST', help='Exclude the list of nodes from runnning checks') run_options.add_argument( '--job-option', action='append', metavar='OPT', dest='job_options', default=[], help='Pass OPT to job scheduler') run_options.add_argument( '--force-local', action='store_true', help='Force local execution of checks') run_options.add_argument( '--skip-sanity-check', action='store_true', help='Skip sanity checking') run_options.add_argument( '--skip-performance-check', action='store_true', help='Skip performance checking') run_options.add_argument( '--strict', action='store_true', help='Force strict performance checking') run_options.add_argument( '--skip-system-check', action='store_true', help='Skip system check') run_options.add_argument( '--skip-prgenv-check', action='store_true', help='Skip prog. environment check') run_options.add_argument( '--exec-policy', metavar='POLICY', action='store', choices=['serial', 'async'], default='serial', help='Specify the execution policy for running the regression tests. ' 'Available policies: "serial" (default), "async"') run_options.add_argument( '--mode', action='store', help='Execution mode to use' ) misc_options.add_argument( '-m', '--module', action='append', default=[], metavar='MOD', dest='user_modules', help='Load module MOD before running the regression') misc_options.add_argument( '--nocolor', action='store_false', dest='colorize', default=True, help='Disable coloring of output') misc_options.add_argument( '--timestamp', action='store', nargs='?', const='%FT%T', metavar='TIMEFMT', help='Append a timestamp component to the regression directories' '(default format "%%FT%%T")' ) misc_options.add_argument( '--system', action='store', help='Load SYSTEM configuration explicitly') misc_options.add_argument('-V', '--version', action='version', version=settings.version) if len(sys.argv) == 1: argparser.print_help() sys.exit(1) # Parse command line options = argparser.parse_args() # Configure logging logging.configure_logging(settings.logging_config) # Setup printer printer = PrettyPrinter() printer.colorize = options.colorize # Load site configuration site_config = SiteConfiguration() site_config.load_from_dict(settings.site_configuration) if options.system: try: sysname, sep, partname = options.system.partition(':') system = site_config.systems[sysname] if partname: # Disable all partitions except partname for p in system.partitions: if p.name != partname: p.disable() if not system.partitions: raise KeyError(options.system) except KeyError: printer.error("unknown system specified: `%s'" % options.system) list_supported_systems(site_config.systems.values(), printer) sys.exit(1) else: # Try to autodetect system system = autodetect_system(site_config) if not system: printer.error("could not auto-detect system. Please specify " "it manually using the `--system' option.") list_supported_systems(site_config.systems.values(), printer) sys.exit(1) # Init modules system init_modules_system(system.modules_system) if options.mode: try: mode_args = site_config.modes[options.mode] # Parse the mode's options and reparse the command-line options = argparser.parse_args(mode_args) options = argparser.parse_args(namespace=options) except KeyError: printer.error("no such execution mode: `%s'" % (options.mode)) sys.exit(1) # Setup the check loader if options.checkpath: load_path = [] for d in options.checkpath: if not os.path.exists(d): printer.info("%s: path `%s' does not exist. Skipping...\n" % (argparser.prog, d)) continue load_path.append(d) loader = RegressionCheckLoader(load_path, recurse=options.recursive) else: loader = RegressionCheckLoader( load_path=settings.checks_path, prefix=os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..') ), recurse=settings.checks_path_recurse, ) # Adjust system directories if options.prefix: # if prefix is set, reset all other directories system.prefix = os.path.expandvars(options.prefix) system.outputdir = None system.stagedir = None system.logdir = None if options.output: system.outputdir = os.path.expandvars(options.output) if options.stage: system.stagedir = os.path.expandvars(options.stage) if options.logdir: system.logdir = os.path.expandvars(options.logdir) resources = ResourcesManager(prefix=system.prefix, output_prefix=system.outputdir, stage_prefix=system.stagedir, log_prefix=system.logdir, timestamp=options.timestamp) if (os_ext.samefile(resources.stage_prefix, resources.output_prefix) and not options.keep_stage_files): printer.error('stage and output refer to the same directory. ' 'If this is on purpose, please use also the ' "`--keep-stage-files' option.") sys.exit(1) printer.log_config(options) # Print command line printer.info('Command line: %s' % ' '.join(sys.argv)) printer.info('Reframe version: ' + settings.version) printer.info('Launched by user: '******'USER']) printer.info('Launched on host: ' + socket.gethostname()) # Print important paths printer.info('Reframe paths') printer.info('=============') printer.info(' Check prefix : %s' % loader.prefix) printer.info('%03s Check search path : %s' % ('(R)' if loader.recurse else '', "'%s'" % ':'.join(loader.load_path))) printer.info(' Stage dir prefix : %s' % resources.stage_prefix) printer.info(' Output dir prefix : %s' % resources.output_prefix) printer.info(' Logging dir : %s' % resources.log_prefix) try: # Locate and load checks checks_found = loader.load_all(system=system, resources=resources) # Filter checks by name checks_matched = filter( lambda c: c if c.name not in options.exclude_names else None, checks_found ) if options.names: checks_matched = filter( lambda c: c if c.name in options.names else None, checks_matched ) # Filter checks by tags user_tags = set(options.tags) checks_matched = filter( lambda c: c if user_tags.issubset(c.tags) else None, checks_matched ) # Filter checks by prgenv if not options.skip_prgenv_check: checks_matched = filter( lambda c: c if sum([c.supports_progenv(p) for p in options.prgenv]) == len(options.prgenv) else None, checks_matched ) # Filter checks further if options.gpu_only and options.cpu_only: printer.error("options `--gpu-only' and `--cpu-only' " "are mutually exclusive") sys.exit(1) if options.gpu_only: checks_matched = filter( lambda c: c if c.num_gpus_per_node > 0 else None, checks_matched ) elif options.cpu_only: checks_matched = filter( lambda c: c if c.num_gpus_per_node == 0 else None, checks_matched ) checks_matched = [c for c in checks_matched] # Act on checks # Unload regression's module and load user-specified modules get_modules_system().unload_module(settings.module_name) for m in options.user_modules: try: get_modules_system().load_module(m, force=True) except ModuleError: printer.info("Could not load module `%s': Skipping..." % m) success = True if options.list: # List matched checks list_checks(list(checks_matched), printer) elif options.run: # Setup the execution policy if options.exec_policy == 'serial': exec_policy = SerialExecutionPolicy() elif options.exec_policy == 'async': exec_policy = AsynchronousExecutionPolicy() else: # This should not happen, since choices are handled by # argparser printer.error("unknown execution policy `%s': Exiting...") sys.exit(1) exec_policy.skip_system_check = options.skip_system_check exec_policy.force_local = options.force_local exec_policy.strict_check = options.strict exec_policy.skip_environ_check = options.skip_prgenv_check exec_policy.skip_sanity_check = options.skip_sanity_check exec_policy.skip_performance_check = options.skip_performance_check exec_policy.only_environs = options.prgenv exec_policy.keep_stage_files = options.keep_stage_files exec_policy.sched_account = options.account exec_policy.sched_partition = options.partition exec_policy.sched_reservation = options.reservation exec_policy.sched_nodelist = options.nodelist exec_policy.sched_exclude_nodelist = options.exclude_nodes exec_policy.sched_options = options.job_options runner = Runner(exec_policy, printer) try: runner.runall(checks_matched, system) finally: # always print a report if runner.stats.num_failures(): printer.info(runner.stats.failure_report()) success = False else: printer.info('No action specified. Exiting...') printer.info("Try `%s -h' for a list of available actions." % argparser.prog) if not success: sys.exit(1) sys.exit(0) except KeyboardInterrupt: sys.exit(1) except OSError as e: printer.error("`%s': %s" % (e.filename, e.strerror)) sys.exit(1) except Exception as e: printer.error('fatal error: %s\n' % e) traceback.print_exc() sys.exit(1) finally: try: if options.save_log_files: logging.save_log_files(resources.output_prefix) except OSError as e: printer.error("`%s': %s" % (e.filename, e.strerror))
def test_load_already_present(self): get_modules_system().load_module('testmod_boo') self.environ.load() self.environ.unload() self.assertTrue(get_modules_system().is_module_loaded('testmod_boo'))
def check_sanity(self): return get_modules_system().is_module_loaded('PrgEnv-cray')
def check_sanity(self): return get_modules_system().is_module_loaded(self.current_environ.name)
def __init__(self, name='env_snapshot'): self._name = name self._modules = get_modules_system().loaded_modules() self._variables = dict(os.environ) self._conflicted = []