def main(): # Define the command cmd = os.path.join(os.path.dirname(KtsUtls.GetKratosMultiphysicsPath()), 'runkratos') verbose_values = [0, 1, 2] level_values = ['all', 'nightly', 'small', 'validation'] # Set default values applications = KtsUtls.GetListOfAvailableApplications() verbosity = 1 level = 'all' is_mpi = False # Keep the worst exit code exit_code = 0 # Parse Commandline try: opts, args = getopt.getopt(sys.argv[1:], 'ha:v:l:c:', [ 'help', 'applications=', 'verbose=', 'level=', 'command=', 'using-mpi' ]) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) for o, a in opts: if o in ('-v', '--verbose'): if int(a) in verbose_values: verbosity = int(a) else: print('Error: {} is not a valid verbose level.'.format(a)) Usage() sys.exit() elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-l', '--level'): if a in level_values: level = a else: print('Error: {} is not a valid level.'.format(a)) Usage() sys.exit() elif o in ('-a', '--applications'): try: parsedApps = a.split(':') except: print('Error: Cannot parse applications.') Usage() sys.exit() for a in parsedApps: if a not in applications + ['KratosCore']: print('Warning: Application {} does not exist'.format(a)) sys.exit() applications = parsedApps if 'KratosCore' in applications: applications.remove('KratosCore') elif o in ('-c', '--command'): try: cmd = str(a) except: print('Error: Cannot parse command name {0}.'.format(a)) Usage() sys.exit() elif o in ('--using-mpi'): is_mpi = True else: assert False, 'unhandled option' if is_mpi: level = "mpi_" + level # Set timeout of the different levels signalTime = None if level == 'small': signalTime = int(60) elif level == 'nightly': signalTime = int(900) # Create the commands commander = Commander() # KratosCore must always be runned print('Running tests for KratosCore', file=sys.stderr) with KtsUt.SupressConsoleOutput(): commander.RunTestSuitInTime( 'KratosCore', 'kratos', os.path.dirname(KtsUtls.GetKratosMultiphysicsPath()), level, verbosity, cmd, signalTime) exit_code = max(exit_code, commander.exitCode) # Run the tests for the rest of the Applications for application in applications: print('Running tests for {}'.format(application), file=sys.stderr) sys.stderr.flush() with KtsUt.SupressConsoleOutput(): commander.RunTestSuitInTime( application, application, KtsMp.KratosPaths.kratos_applications + '/', level, verbosity, cmd, signalTime) exit_code = max(exit_code, commander.exitCode) # Run the cpp tests (does the same as run_cpp_tests.py) print('Running cpp tests', file=sys.stderr) with KtsUt.SupressConsoleOutput(): commander.RunCppTests(applications) exit_code = max(exit_code, commander.exitCode) sys.exit(exit_code)
# Loading the Applications is needed bcs that is where the elements/conditions are! # reading the mdpa will fail if the mdpa contains elements/conditions that are defined # in applications that are not available try: __import__("KratosMultiphysics."+application_name) print("Sucessfully imported " + application_name) except: print(application_name + " is available but import failed") def PrintTime(label, start_time): print(label+": {0:.{1}f} [s]".format(time()-start_time,2)) import KratosMultiphysics as KM KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING) import KratosMultiphysics.kratos_utilities as kratos_utils for app_name in kratos_utils.GetListOfAvailableApplications(): TryImportApplication(app_name) mdpa_file_name = argv[1][:-5] # remove ".mdpa"-extension current_model = KM.Model() model_part = current_model.CreateModelPart(mdpa_file_name) import_flags = KM.ModelPartIO.READ | KM.ModelPartIO.IGNORE_VARIABLES_ERROR | KM.ModelPartIO.SKIP_TIMER start_time = time() model_part_io = KM.ModelPartIO(mdpa_file_name, import_flags).ReadModelPart(model_part) PrintTime("\nMdpa reading time", start_time) print() # ### GID ### # start_time = time()
def main(): # Set default values applications = kratos_utils.GetListOfAvailableApplications() # parse command line options parser = argparse.ArgumentParser() parser.add_argument('-c', '--command', default=testing_utils.GetPython3Command()) parser.add_argument('-l', '--level', default='all', choices=['all', 'nightly', 'small', 'validation']) parser.add_argument('-v', '--verbosity', default=1, type=int, choices=[0, 1, 2]) # parser.add_argument('-a', '--applications', default=applications, choices=applications) # TODO parser.add_argument('-n', '--processes', type=int, default=4) parser.add_argument('-m', '--mpi_command', default="mpiexec") parser.add_argument('-f', '--mpi_flags', default="") parser.add_argument('-p', '--num_processes_flag', default="-np") args = parser.parse_args() # Set timeout of the different levels signalTime = None if args.level == 'small': signalTime = 60 elif args.level == 'nightly': signalTime = 900 # Create the commands commander = testing_utils.Commander() exit_codes = {} testing_utils.PrintTestHeader("KratosMPICore") # KratosMPICore must always be executed with KratosUnittest.SupressConsoleOutput(): commander.RunMPITestSuit( 'KratosMPICore', Path(os.path.dirname(kratos_utils.GetKratosMultiphysicsPath()))/"kratos"/"mpi", args.mpi_command, args.mpi_flags, args.num_processes_flag, args.processes, args.level, args.verbosity, args.command, signalTime ) testing_utils.PrintTestFooter("KratosMPICore", commander.exitCode) exit_codes["KratosMPICore"] = commander.exitCode # Run the tests for the rest of the Applications for application in applications: testing_utils.PrintTestHeader(application) with KratosUnittest.SupressConsoleOutput(): commander.RunMPITestSuit( application+"_mpi", Path(KM.KratosPaths.kratos_applications) / application, args.mpi_command, args.mpi_flags, args.num_processes_flag, args.processes, args.level, args.verbosity, args.command, signalTime ) testing_utils.PrintTestFooter(application, commander.exitCode) exit_codes[application] = commander.exitCode testing_utils.PrintTestSummary(exit_codes) sys.exit(max(exit_codes.values()))