[llvm-commits] CVS: llvm/test/QMTest/llvm.py

Brian Gaeke gaeke at cs.uiuc.edu
Thu Nov 20 13:56:01 PST 2003


Changes in directory llvm/test/QMTest:

llvm.py updated: 1.21 -> 1.22

---
Log message:

In the TestRunner class, don't call "sed", and get rid of extra blanks.


---
Diffs of the changes:  (+43 -57)

Index: llvm/test/QMTest/llvm.py
diff -u llvm/test/QMTest/llvm.py:1.21 llvm/test/QMTest/llvm.py:1.22
--- llvm/test/QMTest/llvm.py:1.21	Tue Oct 21 17:56:07 2003
+++ llvm/test/QMTest/llvm.py	Thu Nov 20 13:55:40 2003
@@ -21,6 +21,8 @@
 import qm.fields
 
 import os
+import string
+import re
 import filecmp
 import resource
 
@@ -818,26 +820,38 @@
 		                    description='Name of script to execute via TestRunner'),
 	]
 
+        # extractScript - Extract RUN: lines from file named
+        # inputFilename, and write them into outputFilename, making
+        # substitutions specified by extractEnv.
+        #
+        def extractScript (self, inputFilename, outputFilename, extractEnv):
+                inFile = file (inputFilename)
+                outFile = file (outputFilename, 'w')
+                pat = re.compile ("^.*RUN:(.*)$")
+                for inLine in inFile.readlines ():
+                        mat = pat.match (inLine)
+                        if mat:
+                                outLine = mat.group (1)
+                                for var, val in extractEnv.items ():
+                                        outLine = re.sub ('%' + var, val, \
+                                                          outLine)
+                                outFile.write (outLine + "\n")
+                outFile.close ()
+                inFile.close ()
 
-	def Run (self, context, result):
 
-		#
+	def Run (self, context, result):
 		# Set the core dump size
-		#
-		coresize=int(context['coresize'])
+		coresize = int(context['coresize'])
 		resource.setrlimit (resource.RLIMIT_CORE, (coresize,coresize))
 
-		#
 		# Fetch the source and build root directories from the context.
-		#
-		srcroot=context['srcroot']
-		buildroot=context['buildroot']
-		tmpdir=context['tmpdir']
-		buildtype=context['buildtype']
+		srcroot = context['srcroot']
+		buildroot = context['buildroot']
+		tmpdir = context['tmpdir']
+		buildtype = context['buildtype']
 
-		#
 		# Create a new directory based upon the test's name.
-		#
 		tmpdir = tmpdir + '/tr' + os.path.basename (self.srcfile)
 		if ((os.access(tmpdir,os.F_OK)) == 0):
 			try:
@@ -846,52 +860,30 @@
 				result.Fail ('Failed to make ' + tmpdir)
 				return
 
-		#
-		# Construct the pathname of the source file and output script
-		# file.
-		#
-		srcfile=srcroot + '/' + self.srcfile
+		# Construct the pathnames of the source, output, and
+		# script files.
+		srcfile = srcroot + '/' + self.srcfile
 		scriptfile = tmpdir + '/testscript.' + os.path.basename (srcfile)
-		outputfile = tmpdir + '/testscript.' + os.path.basename (srcfile) + '.out'
+		outputfile = scriptfile + '.out'
 
-		#
 		# Construct a new path that includes the LLVM tools.
-		#
-		environment=os.environ
-		oldpath=environment['PATH']
+		environment = os.environ
+		oldpath = environment['PATH']
 		environment['PATH'] = buildroot + '/tools/' + buildtype + ':' + srcroot + '/test/Scripts:' + environment['PATH']
 		environment['QMV_llvmgcc'] = context['llvmgcc']
 
-		#
-		# Create the script that will run the test.
-		#
-		exstatus=os.spawnlp (os.P_WAIT, 'sed',
-		                                'sed',
-		                                '-n',
-		                                '-e',
-		                                '/RUN:/!d;',
-		                                '-e',
-		                                '/RUN:/s|^.*RUN:\(.*\)$|\\1|g;',
-		                                '-e',
-		                                's|%s|' + srcfile + '|g;',
-		                                '-e',
-		                                's|%t|' + scriptfile + '.tmp|g;',
-		                                '-e',
-		                                's|%llvmgcc|' + context['llvmgcc'] + '|g;',
-		                                '-e',
-		                                's|%llvmgxx|' + context['llvmgxx'] + '|g;',
-		                                '-e',
-		                                'w ' + scriptfile,
-		                                srcfile)
-
-		if (exstatus != 0):
-			result.Fail('The sed script failed')
-			environment['PATH'] = oldpath
-			return
+                # Extract the RUN: script (making the following substitutions:)
+                extractEnv = { 's': srcfile,
+                               't': scriptfile + '.tmp',
+                               'llvmgcc': context['llvmgcc'],
+                               'llvmgxx': context['llvmgxx'] }
+                try:
+                        self.extractScript (srcfile, scriptfile, extractEnv)
+                except EnvironmentError:
+                        result.Fail ('Failed to extract script from ' + srcfile)
+                        return
 
-		#
 		# Execute the script using TestRunner.
-		#
 		mypath = os.getcwd ()
 		os.chdir (tmpdir)
 		if (ExecProgram (('/bin/sh', scriptfile), environment, outputfile)):
@@ -899,14 +891,8 @@
 
 		os.chdir (mypath)
 
-		#
-		# Restore the PATH environment variable
-		#
+		# Restore the PATH environment variable and return.
 		environment['PATH'] = oldpath
-
-		#
-		# Return to the caller.
-		#
 		return
 
 





More information about the llvm-commits mailing list