def _GetTarget(self, context): """Return a target instance suitable to run the test executable. The choice of implementations is determined from the current context. The global context may have provided a 'CompilationTest.target' variable to indicate the Host subclass to use. In addition, we consider the value of the 'ParallelActivator.num_processors' variable that may have been set by the ParallelActivator resource. If a value of num_processors > 1 is requested, we attempt to run the executable using a command determined from the 'par_service.run' variable. (This is typically 'mpirun'.) If the requested target is LocalHost, we replace it by CommandHost (which was designed precisely for such use-cases). If it is a CommandHost or any other host instance that is known to support injecting commands, we attempt to modify its arguments appropriately. Requesting num_processors > 1 with an unsupported host is an error and yields an exception.""" # We can't use a regular import for LocalHost, as that wouldn't # match the type found via 'get_extension_class'. local_host = get_extension_class('local_host.LocalHost', 'host', get_database()) target_desc = context.get('CompilationTest.target') if target_desc is None: host_class, arguments = local_host, {} else: f = lambda n: get_extension_class(n, 'host', get_database()) host_class, arguments = parse_descriptor(target_desc.strip(), f) num_processors = context.get('ParallelActivator.num_processors', 1) if num_processors > 1: if host_class is local_host: host_class = CommandHost arguments['command'] = context.get('par_service.run') arguments['command_args'] = ['-np', str(num_processors)] elif host_class is CommandHost: # Assume that the command is required to invoke any # executable on this machine. Prepend the mpirun command # simply as an argument in that case. arguments['command_args'] = [ context.get('par_service.run'), '-np', str(num_processors) ] elif host_class is RemoteHost: pass # ... else: raise Exception( 'target "%s" does not support parallel execution' % target_desc) path = context.get('par_service.run') return host_class(arguments)
def _GetTarget(self, context): """Return a target instance suitable to run the test executable. The choice of implementations is determined from the current context. The global context may have provided a 'CompilationTest.target' variable to indicate the Host subclass to use. In addition, we consider the value of the 'ParallelActivator.num_processors' variable that may have been set by the ParallelActivator resource. If a value of num_processors > 1 is requested, we attempt to run the executable using a command determined from the 'par_service.run' variable. (This is typically 'mpirun'.) If the requested target is LocalHost, we replace it by CommandHost (which was designed precisely for such use-cases). If it is a CommandHost or any other host instance that is known to support injecting commands, we attempt to modify its arguments appropriately. Requesting num_processors > 1 with an unsupported host is an error and yields an exception.""" # We can't use a regular import for LocalHost, as that wouldn't # match the type found via 'get_extension_class'. local_host = get_extension_class('local_host.LocalHost', 'host', get_database()) target_desc = context.get('CompilationTest.target') if target_desc is None: host_class, arguments = local_host, {} else: f = lambda n: get_extension_class(n, 'host', get_database()) host_class, arguments = parse_descriptor(target_desc.strip(), f) num_processors = context.get('ParallelActivator.num_processors', 1) if num_processors > 1: if host_class is local_host: host_class = CommandHost arguments['command'] = context.get('par_service.run') arguments['command_args'] = ['-np', str(num_processors)] elif host_class is CommandHost: # Assume that the command is required to invoke any # executable on this machine. Prepend the mpirun command # simply as an argument in that case. arguments['command_args'] = [context.get('par_service.run'), '-np', str(num_processors)] elif host_class is RemoteHost: pass # ... else: raise Exception('target "%s" does not support parallel execution'%target_desc) path = context.get('par_service.run') return host_class(arguments)
def SetUp(self, context, result): # There are no compilers yet. compilers = {} # See what programming languages are supported. languages = context["CompilerTable.languages"].split() # For each language, create a Compiler. for l in languages: # Retrieve information from the context. kind = context["CompilerTable." + l + "_kind"].strip() path = context["CompilerTable." + l + "_path"].strip() # Look for (optional) command-line options. opts = context.get("CompilerTable." + l + "_options", "").split() ldflags = context.get("CompilerTable." + l + "_ldflags", "").split() # Find the Python class corresponding to this compiler. compiler_class = compiler.__dict__[kind] # Instantiate the compiler. c = compiler_class(path, opts) c.SetLDFlags(ldflags) # Store it in the compilers map. compilers[l] = c # Make the table available to tests. context["CompilerTable.compilers"] = compilers # For backwards compatibility, we recognize this old # context variable here. interpreter = context.get("CompilerTest.interpreter") if interpreter: interpreter = interpreter.split() arguments = { simulator : interpreter[0], simulator_args : interpreter[1:] } target = qm.test.classes.Simulator(arguments) else: target_desc = context.get("CompilerTable.target") if target_desc is None: target = LocalHost({}) else: f = lambda n: qm.test.base.get_extension_class(n, "host", get_database()) host_class, arguments \ = qm.extension.parse_descriptor(target_desc.strip(), f) target = host_class(arguments) context["CompilerTable.target"] = target
def _get_host(context, variable): """Get a host instance according to a particular context variable. Return a default 'LocalHost' host if the variable is undefined. 'context' -- The context to read the host descriptor from. 'variable' -- The name to which the host descriptor is bound. returns -- A Host instance. """ target_desc = context.get(variable) if target_desc is None: target = LocalHost({}) else: f = lambda n: get_extension_class(n, "host", get_database()) host_class, arguments = parse_descriptor(target_desc.strip(), f) target = host_class(arguments) return target