Example #1
0
    def GetSuite(self, suite_id):
        """Return the 'Suite' for the suite named 'suite_id'.

        'suite_id' -- A label naming the suite.

        returns -- An instance of 'Suite' (or a derived class of
        'Suite') corresponding to 'suite_id'.
        
        raises -- 'NoSuchSuiteError' if there is no test in the database
        named 'test_id'.

        All databases must have an implicit suite called '' that
        contains all tests in the database.  More generally, for each
        directory in the database, there must be a corresponding suite
        that contains all tests in that directory and its
        subdirectories."""

        if suite_id == "":
            return DirectorySuite(self, "")

        if self._is_generic_database:
            suite = self.GetExtension(suite_id)
            if isinstance(suite, Suite):
                return suite
            
        raise NoSuchSuiteError(suite_id)
Example #2
0
    def GetExtension(self, id):

        if not id:
            return DirectorySuite(self, id)

        elif id == 'compiler_table':
            return CompilerTable({}, qmtest_id=id, qmtest_database=self)

        elif id == 'parallel_service':
            return ParallelService({}, qmtest_id=id, qmtest_database=self)

        resources = []  #['compiler_table', 'parallel_service']

        id_components = self.GetLabelComponents(id)

        dirname = os.path.join(self.srcdir, *id_components[:-1])
        basename = id_components[-1]
        src = os.path.join(self.srcdir, id)
        file_ext = os.path.splitext(src)[1]

        # This may be a compiled resource
        if file_ext:
            if file_ext in self.test_extensions and os.path.isfile(src):
                return BenchmarkExecutable(qmtest_id=id,
                                           qmtest_database=self,
                                           src=src,
                                           executable=os.path.splitext(id)[0])

        # It may be a directory
        elif os.path.isdir(src):
            if not basename in self.excluded_subdirs:
                return DirectorySuite(self, id)

        # If there is a corresponding source, it's a test.
        elif os.path.isfile(src + '.cpp'):
            resources = [id + '.cpp']
            return self._MakeBenchmark(id,
                                       Benchmark,
                                       program='./%s' % id,
                                       resources=resources)
        else:
            return None
Example #3
0
    def GetSuite(self, suite_id):
        """This method can be removed once QMTest 2.4 is out."""

        if suite_id == "":
            return DirectorySuite(self, "")

        s = self.GetExtension(suite_id)
        if isinstance(s, suite.Suite):
            return s

        raise database.NoSuchSuiteError(suite_id)
Example #4
0
    def GetExtension(self, id):

        if not id:
            return DirectorySuite(self, id)

        components = self.GetLabelComponents(id)
        path = os.path.join(self.GetRoot(), *components)

        if os.path.isdir(path):  # a directory
            return DirectorySuite(self, id)

        elif os.path.isfile(path):  # a test

            arguments = {}
            arguments['script'] = path
            arguments['topdir'] = self.GetRoot()

            return Test(arguments, qmtest_id=id, qmtest_database=self)

        else:  # nothing else to offer

            return None
Example #5
0
    def GetExtension(self, id):

        if not id:
            return DirectorySuite(self, id)

        elif id == 'compiler_table':
            return CompilerTable({}, qmtest_id=id, qmtest_database=self)

        elif id == 'parallel_service':
            return ParallelService({}, qmtest_id=id, qmtest_database=self)
        elif id == 'parallel_activator':
            return ParallelActivator({}, qmtest_id=id, qmtest_database=self)

        resources = ['compiler_table', 'parallel_service']

        id_components = self.GetLabelComponents(id)
        # 'data' subdirectories have special meaning, and so
        # are not allowed as label components.
        if 'data' in id_components:
            return None

        dirname = os.path.join(self.srcdir, *id_components[:-1])
        basename = id_components[-1]

        file_ext = os.path.splitext(basename)[1]

        # If <dirname>/data is an existing directory...
        if os.path.isdir(os.path.join(dirname, 'data')):

            if file_ext in self.test_extensions:

                executable = os.path.splitext(os.path.basename(id))[0]
                if sys.platform == 'win32':
                    executable += '.exe'

                # ...<dirname>/<basename> is a resource.
                src = os.path.abspath(os.path.join(self.srcdir, id))
                return self._MakeTest(id,
                                      CompiledResource,
                                      language=self.test_extensions[file_ext],
                                      source_files=[src],
                                      executable=executable,
                                      resources=resources)
            else:
                # ...<dirname>/<basename> is a test.
                path = os.path.join(dirname, 'data', basename)
                if not os.path.isfile(path):
                    return None

                src = [
                    f for f in dircache.listdir(dirname)
                    if os.path.splitext(f)[1] in self.test_extensions
                ]
                # There must be exactly one source file, which
                # is our resource.
                if len(src) > 1:
                    raise DatabaseError('multiple source files found in %s' %
                                        dirname)

                resources.append(self.JoinLabels(*(id_components[:-1] + src)))
                return self._MakeTest(id,
                                      DataTest,
                                      resources=resources,
                                      data_file=path)

        src = os.path.join(self.srcdir, id)
        if file_ext in self.test_extensions and os.path.isfile(src):
            if file_ext == '.py':
                return self._MakePythonTest(id, src)
            else:
                executable = os.path.splitext(os.path.basename(id))[0]
                if sys.platform == 'win32':
                    executable += '.exe'

                # all tests in parallel/ should be run in parallel.
                if id_components[0] in ('mpi', 'parallel'):
                    resources.append('parallel_activator')

                return self._MakeTest(id,
                                      CompilationTest,
                                      language=self.test_extensions[file_ext],
                                      source_files=[src],
                                      executable=executable,
                                      resources=resources)

        elif os.path.isfile(src + '.qms'):
            qms = src + '.qms'
            # Expose the flags to the suite file so it can exclude ids
            # the same way the database itself does in the constructor.
            context = dict(flags=self.flags,
                           excluded_subdirs=self.excluded_subdirs)
            try:
                content = open(qms).read()
                exec content in context
            except:
                print 'Error parsing', qms
            test_ids = context.get('test_ids', [])
            suite_ids = context.get('suite_ids', [])
            return ExplicitSuite(is_implicit=False,
                                 test_ids=test_ids,
                                 suite_ids=suite_ids,
                                 qmtest_id=id,
                                 qmtest_database=self)

        elif os.path.isdir(src):
            if not basename in self.excluded_subdirs:
                return DirectorySuite(self, id)

        else:
            return None