def env_protect(request): """Protection against environment change. The fixture is enabled for all tests and does the following: * store/restore env between each tests * create a temporary directory and do a cd to it before each test. The directory is automatically removed when test ends """ Env().store() tempd = tempfile.mkdtemp() cd(tempd) project_marker = request.node.get_closest_marker("data_dir") if project_marker is not None: project_dir = os.path.join(ROOT_DIR, "projects", project_marker.args[0]) logging.debug(f"use project dir {project_dir}") sync_tree(project_dir, tempd) def restore_env(): Env().restore() rm(tempd, True) request.addfinalizer(restore_env)
def to_subdir(self, dir): """ Change the current directory to `dir`, relative to `self`'s home directory. Create it if needed, after first removing it. """ self.to_homedir() if os.path.exists(dir): shutil.rmtree(dir) mkdir(dir) cd(dir)
def to_subdir(self, dir, clean=True): """ Change the current directory to `dir`, relative to `self`'s home directory. Create it if needed, after first removing it if requested to be `clean`. """ self.to_homedir() if clean and os.path.exists(dir): shutil.rmtree(dir) mkdir(dir) cd(dir)
def output_of(cmd, dir=None): """ Execute CMD and return it's output, switching to DIR before if not None, and switching back to the original cwd as needed. """ cwd = os.getcwd() if dir is not None: cd(dir) output = Run(cmd.split()).out cd(cwd) return output
def run(self): try: rm(self.data.anod_instance.build_space.build_dir, recursive=True) mkdir(self.data.anod_instance.build_space.build_dir) rm(self.data.anod_instance.build_space.install_dir, recursive=True) mkdir(self.data.anod_instance.build_space.install_dir) Env().store() cd(self.data.anod_instance.build_space.build_dir) self.data.anod_instance.jobs = Env().build.cpu.cores self.data.anod_instance.build() Env().restore() self.run_status = ReturnValue.success except Exception: logging.exception("got exception while building") self.run_status = ReturnValue.failure
def env_protect(request): """Protection against environment change. The fixture is enabled for all tests and does the following: * store/restore env between each tests * create a temporary directory and do a cd to it before each test. The directory is automatically removed when test ends """ Env().store() tempd = tempfile.mkdtemp() cd(tempd) def restore_env(): Env().restore() rm(tempd, True) request.addfinalizer(restore_env)
def env_protect(request): """Protection against environment change. The fixture is enabled for all tests and does the following: * store/restore env between each tests * create a temporary directory and do a cd to it before each test. The directory is automatically removed when test ends """ Env().store() tempd = tempfile.mkdtemp() cd(tempd) e3.log.activate(level=logging.DEBUG, e3_debug=True) def restore_env(): Env().restore() rm(tempd, True) request.addfinalizer(restore_env)
def __init__(self): """ Initialize the instance: switch to the test subdirectory, parse command line options, reset the failures counter and precompute gprbuild options we'll have to pass on every call to convey config options. """ # Shortcut for SUITE.control.env self.env = env self.start_time = time.time() # Compute this test's home directory, absolute dir where test.py # is located, then the position relative to testsuite.py. Note that # .__file__ might be an absolute path, which os.path.join handles # just fine (join("/foo", "/foo/bar") yields "/foo/bar"). testsuite_py_dir = ROOT_DIR test_py_dir = os.path.dirname(sys.modules['__main__'].__file__) self.homedir = os.path.join(testsuite_py_dir, test_py_dir) self.reldir = os.path.relpath(self.homedir, start=testsuite_py_dir) # Perform a simple canonicalization of the relative dir to simplify # related computations/assumptions in other parts of the testsuite. self.reldir = self.reldir.replace('\\', '/') # Compute the depth of this test wrt testsuite root. self.depth = ndirs_in(os.path.relpath(self.homedir, ROOT_DIR)) cd(self.homedir) self.options = self.__cmdline_options() self.n_failed = 0 self.report = _ReportOutput(self.options.report_file) self.current_test_index = 0 self.gprconfoptions = [ # verbose mode for verifiability in qualif mode. # quiet mode for performance (less io) otherwise. '-v' if self.options.qualif_level else '-q', # gprconfig base, selecting runtime '--config=%s' % os.path.join(ROOT_DIR, BUILDER.SUITE_CGPR) ] self.gprvaroptions = ['-XTARGET=%s' % env.target.triplet] if self.options.board: self.gprvaroptions.append('-XBOARD=%s' % self.options.board) # Workaround a desynchronization between default build configuration # for TMS570 and GNATemulator's settings: see O519-032. We may get rid # of this kludge one day adapting GNATemulator. if self.options.RTS and self.options.RTS.endswith('-tms570'): self.gprvaroptions.append('-XLOADER=LORAM') # For trace32 runs where the test is executed on a real board, we # choose to have both the code and data in RAM. The default is to run # from flash which would take more time for the probe to program. It # would also wear out the flash memory. if self.options.gnatcov_run and 'trace32' in self.options.gnatcov_run: self.gprvaroptions.append('-XLOADER=RAM') # Whether this test will be using project files to locate SCOs when # running gnatcov. This is decided on a per gnatcov invocation basis. # self.options.gnatcov states whether we're queried to do this for # SCOV driven tests. self.gprmode = False # Callgrind may be invoked more than once for each test. Memorize the # number of times it has been used in order to generate multiple logs. self.callgrind_count = 0 # By default, hide the warning that says that non-instrumented native # coverage is deprecated, as it would make all tests fail. Testcases # that check the presence of this warning can just remove this # environment variable. os.environ['GNATCOV_NO_NATIVE_WARNING'] = '1'
def to_homedir(self): """ Change the current directory to `self`'s home directory. """ cd(self.homedir)
def run(self, args): if args.api_version != "1.5": raise SandBoxError("Only 1.5 is supported for now") cd(args.spec_dir) migrate_v1_5()
def __init__(self): """ Initialize the instance: switch to the test subdirectory, parse command line options, reset the failures counter and precompute gprbuild options we'll have to pass on every call to convey config options. """ self.start_time = time.time() # Compute the depth of this test wrt testsuite root. We join ROOT and # TEST dirs then compute the length of the relative path, instead of # just counting the number of components in TEST_DIR, to prevent # inacuracies from possible "./" components that don't really increase # the depth. self.reldir = TEST_DIR self.homedir = os.path.join(ROOT_DIR, TEST_DIR) self.depth = ndirs_in(os.path.relpath(self.homedir, ROOT_DIR)) cd(TEST_DIR) self.options = self.__cmdline_options() self.n_failed = 0 self.report = _ReportOutput(self.options.report_file) self.current_test_index = 0 self.gprconfoptions = [ # verbose mode for verifiability in qualif mode. # quiet mode for performance (less io) otherwise. '-v' if self.options.qualif_level else '-q', # gprconfig base, selecting runtime '--config=%s' % os.path.join(ROOT_DIR, BUILDER.SUITE_CGPR)] self.gprvaroptions = ['-XTARGET=%s' % env.target.triplet] if self.options.board: self.gprvaroptions.append('-XBOARD=%s' % self.options.board) # Workaround a desynchronization between default build configuration # for TMS570 and GNATemulator's settings: see O519-032. We may get rid # of this kludge one day adapting GNATemulator. if self.options.RTS and self.options.RTS.endswith('-tms570'): self.gprvaroptions.append('-XLOADER=LORAM') # For trace32 runs where the test is executed on a real board, we # choose to have both the code and data in RAM. The default is to run # from flash which would take more time for the probe to program. It # would also wear out the flash memory. if self.options.gnatcov_run and 'trace32' in self.options.gnatcov_run: self.gprvaroptions.append('-XLOADER=RAM') # Whether this test will be using project files to locate SCOs when # running gnatcov. This is decided on a per gnatcov invocation basis. # self.options.gnatcov states whether we're queried to do this for # SCOV driven tests. self.gprmode = False # Callgrind may be invoked more than once for each test. Memorize the # number of times it has been used in order to generate multiple logs. self.callgrind_count = 0 # By default, hide the warning that says that non-instrumented native # coverage is deprecated, as it would make all tests fail. Testcases # that check the presence of this warning can just remove this # environment variable. os.environ['GNATCOV_NO_NATIVE_WARNING'] = '1'