Esempio n. 1
0
    def to_workdir(self, wdir):
        """Switch to work directory WDIR, creating it if necessary. WDIR is
        expected to be either absolute or relative from the homedir."""

        self.to_homedir()
        mkdir(wdir)
        cd(wdir)
Esempio n. 2
0
    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
Esempio n. 3
0
 def to_subdir(self, dir):
     """
     Change the current directory to `dir` (a path relative to `self`'s home
     directory). Create it if needed.
     """
     self.to_homedir()
     mkdir(dir)
     cd(dir)
Esempio n. 4
0
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
Esempio n. 5
0
def setup():
    cd(TEST_DIR)
    for prj in glob('*.gpr'):
        with open(prj) as prj_orig:
            lines = [line for line in prj_orig]
            with open(prj + '.new', 'w') as prj_new:
                for line in lines:
                    line = line.replace(
                        '../common', os.path.join(ROOT_DIR, 'common'))
                    prj_new.write(line)
        mv(prj + '.new', prj)
Esempio n. 6
0
def setup():
    cd(TEST_DIR)
    for prj in glob('*.gpr'):
        with open(prj) as prj_orig:
            lines = [line for line in prj_orig]
            with open(prj + '.new', 'w') as prj_new:
                for line in lines:
                    line = line.replace('../common',
                                        os.path.join(ROOT_DIR, 'common'))
                    prj_new.write(line)
        mv(prj + '.new', prj)
Esempio n. 7
0
 def to_homedir(self):
     """
     Change the current directory to `self`'s home directory.
     """
     cd(self.homedir)
Esempio n. 8
0
 def to_homedir(self):
     cd(self.homedir)
Esempio n. 9
0
 def to_subdir(self, dir):
     self.to_homedir()
     mkdir(dir)
     cd(dir)
Esempio n. 10
0
 def to_homedir(self):
     """Switch to this test's homedir."""
     cd(self.homedir)
Esempio n. 11
0
def parse_scenario(filename):
    """Parse a scenario file and create the corresponding test directories"""
    scenario = open(filename)

    test_dict = {}
    current_section = SCENARIO_SECTION
    current_test = ""

    for line in scenario:
        if line.startswith('['):
            test_name = re.match(r'\[(.*) (.*)\]', line)
            if test_name:
                current_section = test_name.group(1)
                current_test = test_name.group(2)
                if current_section == TEST_SECTION:
                    test_dict[current_test] = {}

        elif current_section != SCENARIO_SECTION:
            # Do not parse scenario section.
            line_def = re.match(r'(.*)=(.*)', line)
            if line_def:
                left = line_def.group(1)
                right = line_def.group(2)
                if not current_section in test_dict[current_test]:
                    test_dict[current_test][current_section] = {}
                test_dict[current_test][current_section][left] = right

    scenario.close()
    full_name = os.path.basename(filename)
    sep = full_name.find('-')

    parent_dir = full_name[:sep]
    mkdir(parent_dir)

    scenario_dir = full_name[sep + 1:-5]
    mkdir(os.path.join(parent_dir, scenario_dir))
    cd(os.path.join(parent_dir, scenario_dir))

    for test_name in test_dict:
        test_type = test_dict[test_name][TEST_SECTION]['type']
        if test_type == 'client_server':
            mkdir(test_name)
            f = open(os.path.join(test_name, 'test.py'), 'w')
            f.write(
                CLIENT_SERVER_TEMPLATE % {
                    'client_cmd':
                    test_dict[test_name][CLIENT_SECTION]['command'],
                    'client_conf':
                    test_dict[test_name][CLIENT_SECTION].get(
                        'config_file', ''),
                    'server_cmd':
                    test_dict[test_name][SERVER_SECTION]['command'],
                    'server_conf':
                    test_dict[test_name][SERVER_SECTION].get(
                        'config_file', ''),
                })
            f.close()

            if 'expected_failure' in test_dict[test_name][TEST_SECTION]:
                f = open(os.path.join(test_name, 'test.opt'), 'w')
                f.write('ALL XFAIL\n')
                f.close()

        elif test_type == 'local':
            mkdir(test_name)
            f = open(os.path.join(test_name, 'test.py'), 'w')
            f.write(
                LOCAL_TEMPLATE % {
                    'command':
                    test_dict[test_name][TEST_SECTION]['command'],
                    'conf':
                    test_dict[test_name][TEST_SECTION].get('config_file', '')
                })
            f.close()

            if 'expected_failure' in test_dict[test_name][TEST_SECTION]:
                f = open(os.path.join(test_name, 'test.opt'), 'w')
                f.write('ALL XFAIL\n')
                f.close()
        else:
            print 'unknown type for test: ' + test_name