[llvm-commits] CVS: llvm/test/QMTest/llvmdb.py
John Criswell
criswell at cs.uiuc.edu
Fri Oct 3 15:52:01 PDT 2003
Changes in directory llvm/test/QMTest:
llvmdb.py updated: 1.2 -> 1.3
---
Log message:
Removed old code.
Refactored code to use the new GetDirsAndFiles() method. This method
provides a central point for manipulating the test tree hierarchy and makes
the code much cleaner.
---
Diffs of the changes:
Index: llvm/test/QMTest/llvmdb.py
diff -u llvm/test/QMTest/llvmdb.py:1.2 llvm/test/QMTest/llvmdb.py:1.3
--- llvm/test/QMTest/llvmdb.py:1.2 Fri Oct 3 14:21:02 2003
+++ llvm/test/QMTest/llvmdb.py Fri Oct 3 15:51:17 2003
@@ -60,20 +60,6 @@
#
def GetTest (self, test_id):
#
- # Split the test into its name and set of suffixes and
- # convert the test ID into a pathname.
- #
- #(baselabel, suffix1) = self.SplitLabel (test_id)
- #if (suffix1 == 'tr'):
- #(baselabel, suffix2) = self.SplitLabel (baselabel)
- #testpath=self.LabelToPath(baselabel) + '.' + suffix2 + '.' + suffix1
- #else:
- #testpath=self.LabelToPath(baselabel) + '.' + suffix1
-#
- #testpath = 'test/' + testpath
-
-
- #
# Try to figure out whether this test exists or not.
#
exts=['ll', 'llx', 'c', 'cpp', 'td', 'c.tr', 'cpp.tr']
@@ -109,6 +95,69 @@
return qm.test.database.TestDescriptor(self, test_id, testtype, testargs)
#
+ # Method: GetDirsAndFiles
+ #
+ # Description:
+ # This method will take a given directory and find all of the test
+ # directories and tests inside of it.
+ #
+ # Inputs:
+ # dirpath - The pathname to the directory.
+ #
+ # Return value:
+ # (dirs, files)
+ # dirs = A list of directories inside this directory.
+ # files = A list of files within this directory.
+ #
+ def GetDirsAndFiles (self, dirpath):
+ #
+ # Get a list of the tests located in this directory.
+ #
+ tests=os.listdir (dirpath)
+
+ #
+ # Record names of invalid directories and files.
+ #
+ invalid_dirs = ['CVS', 'QMTest', 'QMTestDB', 'Scripts', 'Programs',
+ 'Feature', 'Fragments']
+
+ invalid_files = ['Makefile', 'README.txt', '.cvsignore']
+
+ #
+ # Start with an empty list of files and directories.
+ #
+ dirs = []
+ files = []
+
+ #
+ # Process each file inside the directory.
+ #
+ for path in tests:
+ #
+ # Determine the file's type.
+ #
+ fileinfo = os.stat (dirpath + '/' + path)
+
+ #
+ # If the file is a directory, add it to the directory list, unless
+ # it is one of the ignored directories.
+ #
+ if (stat.S_ISDIR(fileinfo.st_mode)):
+ for x in invalid_dirs:
+ if (x == path):
+ break
+ else:
+ dirs = dirs + [path]
+ else:
+ for x in invalid_files:
+ if (x == path):
+ break
+ else:
+ files = files + [path]
+
+ return (dirs, files)
+
+ #
# Method: GetSuite ()
#
# Description:
@@ -116,59 +165,59 @@
#
def GetSuite (self, suite_id):
#
- # If the empty suite ID is given, default to whatever suite is in
- # the current directory.
- #
- # Otherwise, convert the suite name into a pathname.
+ # Determine what we should prepend to every suite and test ID we
+ # return.
#
if (suite_id == ''):
- suitepath=self.dbpath
- suite_header = ''
+ suite_prefix = ''
else:
- suitepath=self.LabelToPath (suite_id)
- suite_header = suite_id + '.'
+ suite_prefix = suite_id + '.'
+ #
+ # Convert the suite name into a pathname.
+ #
suitepath = self.dbpath + '/' + self.LabelToPath (suite_id)
#
# Get a list of the tests located in this directory.
#
- tests=os.listdir (suitepath)
- dirs = []
- files = []
- for path in tests:
- fileinfo = os.stat (suitepath + '/' + path)
- if (stat.S_ISDIR(fileinfo.st_mode)):
- if ((path != 'CVS') and (path != 'QMTest') and (path != 'QMTestDB') and (path != 'newdb') and (path != 'Scripts') and (path != 'Programs') and (path != 'Feature') and (path != 'Fragments')):
- dirs = dirs + [suite_header + path]
- else:
- if ((suite_id != '') and (path != 'Makefile') and (path != 'README.txt') and (path != '.cvsignore')):
- (filebase, fileext) = os.path.splitext(path)
- if (fileext == '.tr'):
- (filebase, fileext) = os.path.splitext(filebase)
- files = files + [suite_header + filebase]
+ (dirs, files) = self.GetDirsAndFiles (suitepath)
+
+ #
+ # Convert the list of directories and files into labels.
+ #
+ dirlabels = []
+ filelabels = []
+ for path in dirs:
+ dirlabels = dirlabels + [suite_prefix + path]
+
+ if (suite_id != ''):
+ for path in files:
+ (filebase, fileext) = os.path.splitext(path)
+ if (fileext == '.tr'):
+ (filebase, fileext) = os.path.splitext(filebase)
+ filelabels = filelabels + [suite_prefix + filebase]
#
# Load this suite
#
- suite = qm.test.suite.Suite (self, suite_id, 0, files, dirs)
+ suite = qm.test.suite.Suite (self, suite_id, 0, filelabels, dirlabels)
return suite
#raise qm.test.database.NoSuchSuiteError (suite_id)
def GetAttachmentStore (self):
return qm.attachment.FileAttachmentStore (self)
- def GetSubdirectories (self, pathname):
- pathname = self.dbpath + '/' + self.LabelToPath (pathname)
-
- tests=os.listdir (pathname)
- dirs = []
- for path in tests:
- fileinfo = os.stat (pathname + '/' + path)
- if (stat.S_ISDIR(fileinfo.st_mode)):
- if ((path != 'CVS') and (path != 'QMTest') and (path != 'QMTestDB') and (path != 'newdb') and (path != 'Scripts') and (path != 'Programs') and (path != 'Feature') and (path != 'Fragments')):
- dirs = dirs + [path]
+ def GetSubdirectories (self, pathlabel):
+ #
+ # Convert the directory label into a full pathname.
+ #
+ pathname = self.dbpath + '/' + self.LabelToPath (pathlabel)
+ #
+ # Retrieve all of the directories within this directory.
+ #
+ (dirs, files) = self.GetDirsAndFiles (pathname)
return dirs
def GetResourceIds(self, directory="", scan_subdirs=1):
@@ -176,7 +225,7 @@
def GetSuiteIds(self, directory="", scan_subdirs=1):
#
- # Adjust the directory name.
+ # Convert the directory label into a full pathname.
#
if (directory == ''):
dirpath = self.dbpath
@@ -186,26 +235,32 @@
#
# Get a list of the tests located in this directory.
#
- tests=os.listdir (dirpath)
- dirs = [directory]
- files = []
- for path in tests:
- fileinfo = os.stat (dirpath + '/' + path)
- if (stat.S_ISDIR(fileinfo.st_mode)):
- if ((path != 'CVS') and (path != 'QMTest') and (path != 'QMTestDB') and (path != 'newdb') and (path != 'Scripts') and (path != 'Programs') and (path != 'Feature') and (path != 'Fragments')):
- if (directory == ''):
- dirs = dirs + [path]
- else:
- dirs = dirs + [directory + '.' + path]
+ (dirs, files) = self.GetDirsAndFiles (dirpath)
+
+ #
+ # Add the top suite to the list of suites in this directory, and then
+ # convert the rest of the directories into suite ID labels.
+ #
+ dirlabels = [directory]
+
+ for path in dirs:
+ if (directory == ''):
+ dirlabels = dirlabels + [path]
+ else:
+ dirlabels = dirlabels + [directory + '.' + path]
+ #
+ # If we're asked to scan subdirectories, recurse on ourselves.
+ #
if (scan_subdirs == 1):
- for dirlabel in dirs:
- dirs = dirs + self.GetTestIds (dirlabel, 1)
- return dirs
+ for label in dirlabels:
+ dirlabels = dirlabels + self.GetTestIds (label, 1)
+
+ return dirlabels
def GetTestIds(self, directory="", scan_subdirs=1):
#
- # Adjust the directory name.
+ # Convert the directory label into a directory name.
#
if (directory == ''):
dirpath = self.dbpath
@@ -215,29 +270,36 @@
#
# Get a list of the tests located in this directory.
#
- tests=os.listdir (dirpath)
- dirs = [directory]
- files = []
- for path in tests:
- fileinfo = os.stat (dirpath + '/' + path)
- if (stat.S_ISDIR(fileinfo.st_mode)):
- if ((path != 'CVS') and (path != 'QMTest') and (path != 'QMTestDB') and (path != 'newdb') and (path != 'Scripts') and (path != 'Programs') and (path != 'Feature') and (path != 'Fragments')):
- if (directory == ''):
- dirs = dirs + [path]
- else:
- dirs = dirs + [directory + '.' + path]
+ (dirs, files) = self.GetDirsAndFiles (dirpath)
+
+ #
+ # Convert all of the directories into labels.
+ #
+ for path in dirs:
+ if (directory == ''):
+ dirlabels = dirlabels + [path]
+ else:
+ dirlabels = dirlabels + [directory + '.' + path]
+
+
+ #
+ # Convert all of the file names into labels.
+ #
+ for path in files:
+ if (directory == ''):
+ filelabels = filelabels + [path]
else:
- if ((directory != '') and (path != 'Makefile')):
- if (directory == ''):
- files = files + [path]
- else:
- (filebase, fileext) = os.path.splitext(path)
- if (fileext == '.tr'):
- (filebase, fileext) = os.path.splitext(filebase)
- files = files + [directory + '.' + filebase]
+ (filebase, fileext) = os.path.splitext(path)
+ if (fileext == '.tr'):
+ (filebase, fileext) = os.path.splitext(filebase)
+ filelabels = filelabels + [directory + '.' + filebase]
+ #
+ # Recurse through subdirectories using recursion if necessary.
+ #
if (scan_subdirs == 1):
- for dirlabel in dirs:
- files = files + self.GetTestIds (dirlabel, 1)
- return files
+ for label in dirlabels:
+ filelabels = filelabels + self.GetTestIds (label, 1)
+
+ return filelabels
More information about the llvm-commits
mailing list