def do_cd(self, args): "Move to directory" if args == '': print(common.get_cdir()) else: try: common.chdir(args) self.prompt = self.get_shortpath() + ' ' + self.prompt_sign self.directories = [] for name in os.listdir(common.get_cdir()): if os.path.isdir(os.path.join(common.get_cdir(), name)): self.directories.append(name) except FileNotFoundError as e: print(e)
def build_adapters(systest, tag, branch, local, force_rebuild): """ Builds a docker images for a preCICE adapter, participating in tests """ baseimage_name = "precice-{tag}-{branch}:latest".format(tag=tag, branch=branch) participants = get_test_participants(systest) docker_args = { 'tag': '', 'build_args': { "from": docker.get_namespace() + baseimage_name if local else 'precice/' + baseimage_name }, 'force_rebuild': force_rebuild, 'dockerfile': 'Dockerfile' } with common.chdir(os.path.join(os.getcwd(), 'adapters')): for participant in participants: docker_args['tag'] = '-'.join([participant, tag, branch]) docker_args['dockerfile'] = "Dockerfile." + participant # skip "light-adapters" (e.g. nutils ) if os.path.exists("Dockerfile.{}".format(participant)): try: docker.build_image(**docker_args) except CalledProcessError as e: print("BUILD FAILED WITH: {}".format(e)) raise STBuildException()
def build_run_compare(test, tag, branch, local_precice, force_rebuild, rm_all=False, verbose=False): """ Runs and compares test, using precice branch. """ compose_tests = [ "dealii-of", "of-of", "su2-ccx", "of-ccx", "of-of_np", "fe-fe", "nutils-of", "of-ccx_fsi", "1dtube_cxx", "1dtube_py", "of-ca" ] test_basename = test.split(".")[0] if local_precice: build_adapters(test_basename, tag, branch, local_precice, force_rebuild) if test_basename in compose_tests: run_compose(test, branch, local_precice, tag, force_rebuild, rm_all, verbose) else: # remaining, non-compose tests test_dirname = "Test_{systest}".format(systest=test) test_path = os.path.join(os.getcwd(), 'tests', test_dirname) with common.chdir(test_path): # Build build(test_basename, tag, branch, local_precice, force_rebuild) run(test_basename, tag, branch) # Preparing string for path pathToRef = os.path.join(os.getcwd(), "referenceOutput") pathToOutput = os.path.join(os.getcwd(), "Output") # Comparing comparison(pathToRef, pathToOutput)
def setUpClass(cls): super().setUpClass() for benchmarker in benchmarkers: benchmarker.prepare() fingerprint = [ 'ignoring compilation' if IGNORE_COMPILATION else 'including compilation', time.asctime() ] try: fingerprint.append('em: ' + run_process( ['git', 'show'], stdout=PIPE).stdout.splitlines()[0]) except Exception: pass try: with common.chdir(os.path.expanduser('~/Dev/mozilla-central')): fingerprint.append('sm: ' + [ line for line in run_process(['hg', 'tip'], stdout=PIPE). stdout.splitlines() if 'changeset' in line ][0]) except Exception: pass fingerprint.append('llvm: ' + config.LLVM_ROOT) print('Running Emscripten benchmarks... [ %s ]' % ' | '.join(fingerprint))
def build_run_compare(test, tag, branch, local_precice, force_rebuild): """ Runs and compares test, using precice branch. """ dirname = "/Test_" + test test_basename = test.split('.')[0] with common.chdir(os.getcwd() + dirname): # Build build(test_basename, tag, branch, local_precice, force_rebuild) run(test_basename, tag, branch) # Preparing string for path pathToRef = os.path.join(os.getcwd(), "referenceOutput") pathToOutput = os.path.join(os.getcwd(), "Output") # Comparing comparison(pathToRef, pathToOutput)
def run_compose(systest, branch, local, tag, force_rebuild, rm_all): """ Runs necessary systemtest with docker compose """ test_dirname = "TestCompose_{systest}".format(systest=systest) test_basename = systest.split('.')[0] adapter_base_name = "-".join([tag, branch]) # set up environment variables, to detect precice base image, that we # should run with and docker images location commands_main = ["""export PRECICE_BASE=-{base}; {extra_cmd} docker-compose config && bash ../../silent_compose.sh""".format(base = adapter_base_name, extra_cmd =\ "export SYSTEST_REMOTE={remote};".format( remote = docker.get_namespace()) if local else "" ), "docker cp tutorial-data:/Output ."] # rebuild tutorials image if needed if force_rebuild: commands_main.insert(0, "docker-compose build --no-cache") commands_cleanup = ["docker-compose down -v"] test_path = os.path.join(os.getcwd(), 'tests', test_dirname) with common.chdir(test_path): # cleanup previous results shutil.rmtree("Output", ignore_errors=True) try: for command in commands_main: ccall(command) #compare results path_to_ref = os.path.join(os.getcwd(), "referenceOutput") path_to_otp = os.path.join(os.getcwd(), "Output") comparison(path_to_ref, path_to_otp) if rm_all: for command in commands_cleanup: ccall(command) except (CalledProcessError, IncorrectOutput) as e: # cleanup in either case if rm_all: for command in commands_cleanup: ccall(command) # generate a report of failurs for local tests if local: raise e print("TESTS FAILED WITH: {}".format(e)) sys.exit(1)
def add_readme(job_path, type='test', output_enabled=False, output_missing=False, logs_missing=False, message=None): """ Create a README.md at the location specified by readme_path. """ job_link = os.environ["TRAVIS_JOB_WEB_URL"] job_name = os.environ["TRAVIS_JOB_NAME"] job_success = True if (os.environ["TRAVIS_TEST_RESULT"] == '0') else False branch = os.environ["TRAVIS_BRANCH"] pr_branch = os.environ["TRAVIS_PULL_REQUEST_BRANCH"] is_pr = False if (pr_branch == "") else True if (output_missing or logs_missing or message): additional_info = True else: additional_info = False with open(os.path.join('templates', 'readme_template', 'README.md')) as f: tmp = Template(f.read()) readme_rendered = tmp.render(type=type, job_name=job_name, job_success=job_success, branch=branch, pr_branch=pr_branch, is_pr=is_pr, job_link=job_link, output_enabled=output_enabled, output_missing=output_missing, additional_info=additional_info, logs_missing=logs_missing, message=message) with chdir(job_path): with open("README.md", "w") as f: f.write(readme_rendered) ccall("git add README.md")
def run_compose(systest, branch, local, tag, force_rebuild, rm_all=False, verbose=False): """ Runs necessary systemtest with docker compose """ test_dirname = "TestCompose_{systest}".format(systest=systest) test_basename = systest.split('.')[0] adapter_base_name = "-".join([tag, branch]) # set up environment variables, to detect precice base image, that we # should run with and docker images location export_cmd = "export PRECICE_BASE=-{}; ".format(adapter_base_name) extra_cmd = "export SYSTEST_REMOTE={}; ".format( docker.get_namespace()) if local else "" compose_config_cmd = "mkdir Logs; docker-compose config && " compose_exec_cmd = "bash ../../silent_compose.sh {}".format( 'debug' if verbose else "") copy_cmd = "docker cp tutorial-data:/Output ." log_cmd = "docker-compose logs > Logs/container.log" commands_main = [ export_cmd + extra_cmd + compose_config_cmd + compose_exec_cmd, copy_cmd, log_cmd ] # rebuild tutorials image if needed if force_rebuild: commands_main.insert(0, "docker-compose build --no-cache") commands_cleanup = ["docker-compose down -v"] test_path = os.path.join(os.getcwd(), 'tests', test_dirname) with common.chdir(test_path): # cleanup previous results shutil.rmtree("Output", ignore_errors=True) shutil.rmtree("Logs", ignore_errors=True) try: for command in commands_main: ccall(command) #compare results path_to_ref = os.path.join(os.getcwd(), "referenceOutput") path_to_otp = os.path.join(os.getcwd(), "Output") comparison(path_to_ref, path_to_otp) if rm_all: for command in commands_cleanup: ccall(command) except CalledProcessError as e: print("TEST FAILED WITH: {}".format(e)) raise STRunException() except IncorrectOutput as e: print("TEST FAILED WITH: {}".format(e)) raise STValidateException() finally: # cleanup in either case if rm_all: for command in commands_cleanup: ccall(command)
if args.petsc: test_dirname += ".PETSc" test_path = os.path.join(os.getcwd(), 'tests', test_dirname) ccall("cp -r {test_path}/Logs {job_path}".\ format(test_path=test_path, job_path=job_path)) # Check if Output is missing, given it is enabled if args.output: if not os.listdir(output_path): ccall( "echo '# Output was enabled, but no output files found!' > {path}" .format(path=os.path.join(output_path, "README.md"))) output_missing = True # create travis log with chdir(log_path): with open("travis.log", "w") as log: travis_log = get_travis_job_log(job_id) log.write(travis_log) # Check if Logs directory is empty. If yes, include a small README logs_missing = False if not os.listdir(log_path): ccall("echo '# No log files found!' > {path}".format( path=os.path.join(log_path, "README.md"))) logs_missing = True # create README add_readme(job_path, type=type, output_enabled=args.output, output_missing=output_missing,
def add_job_log(systest, failed, log_dir): with chdir(log_dir): log_name = "log_{test}.md".format(test = systest) with open(log_name, "w") as log: create_job_log(systest, log, failed) ccall("git add {log_name}".format(log_name = log_name))
lst2 = docker.get_containers() print(lst2) if lst2: print("Deleting following docker containers:", lst2) answer = input("\nOk? (yes/no)\n") if answer in ["yes", "y"]: for x in lst2: ccall("docker container rm -f " + x) else: print( "BE CAREFUL!: Not deleting previous containers can later lead to problems." ) # Building preCICE print("\n\nBuilding preCICE docker image with choosen branch\n\n") with common.chdir(os.path.join(os.getcwd(), 'precice')): docker.build_image("precice-" + args.dockerfile.lower() + "-" + args.branch, args.dockerfile, build_args={"branch": args.branch}, force_rebuild="precice" in args.force_rebuild) # Starting system tests failed = [] success = [] for test in tests: test_basename = determine_test_name(test) print("\n\nStarting system test %s\n\n" % test) try: build_run_compare(test, args.dockerfile.lower(), args.branch.lower(), True, "tests" in args.force_rebuild, not args.keep)