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

John Criswell criswell at cs.uiuc.edu
Thu Sep 25 19:54:02 PDT 2003


Changes in directory llvm/test/QMTestDB/QMTest:

llvm.py updated: 1.7 -> 1.8

---
Log message:

Added the ExecProgram() function, which better handles the creation of
child processes to run LLVM programs.
Modified the assembler/disassembler tests to use the new ExecProgram()
function and to create output files in the temporary directory.


---
Diffs of the changes:

Index: llvm/test/QMTestDB/QMTest/llvm.py
diff -u llvm/test/QMTestDB/QMTest/llvm.py:1.7 llvm/test/QMTestDB/QMTest/llvm.py:1.8
--- llvm/test/QMTestDB/QMTest/llvm.py:1.7	Tue Sep 16 09:57:49 2003
+++ llvm/test/QMTestDB/QMTest/llvm.py	Thu Sep 25 19:52:59 2003
@@ -17,6 +17,61 @@
 import filecmp
 import resource
 
+#
+# Function: ExecProgram ()
+#
+# Description:
+#	Execute the specified program with the specified environment.
+#
+# Inputs:
+#	args - An array of arguments to the program.
+#	env  - The environment passed to the new program.
+#
+# Outputs:
+#	None.
+#
+# Return value:
+#	0 - The program executed successfully.
+#	1 - The program failed.
+#
+def ExecProgram (args, env = os.environ):
+
+	#
+	# Create a pipe to the new program.
+	#
+	(parent_in, child_out) = os.pipe ()
+
+	#
+	# Create a new child process.
+	#
+	child = os.fork()
+	if (child == 0):
+		#
+		# Construct new stdout, and stderr.
+		#
+		os.dup2 (1, child_out);
+		os.dup2 (2, child_out);
+
+		#
+		# Execute the specified program.
+		#
+		os.execvpe (args[0], args, env)
+
+		#
+		# Exit with failure if the exec failed for any reason.
+		#
+		os._exit (1)
+
+	#
+	# Parent process.
+	#
+
+	#
+	# Wait for the child process to exit.
+	#
+	(pid, status) = os.waitpid (child, 0)
+	return ((os.WIFEXITED(status)) and (os.WEXITSTATUS(status) != 0))
+
 ##############################################################################
 #
 # Class: AssembleTest
@@ -598,37 +653,41 @@
 		input=testdir + '/' + self.assembly_file
 
 		#
+		# Construct output filenames.
+		#
+		bc1 = context['tmpdir'] + '/bc.1'
+		bc2 = context['tmpdir'] + '/bc.2'
+		ll1 = context['tmpdir'] + '/ll.1'
+		ll2 = context['tmpdir'] + '/ll.2'
+
+		#
 		# Assemble the file.
 		#
-		exit_status = os.spawnl (os.P_WAIT, as, as, input, '-f', '-o=bc.1')
-		if exit_status != 0:
-			result.Fail()
+		if (ExecProgram ((as, input, '-f', '-o', bc1))):
+			result.Fail ()
 
 		#
 		# Disassemble the output.
 		#
-		exit_status = os.spawnl (os.P_WAIT, dis, dis, 'bc.1', '-f', '-o=ll.1')
-		if exit_status != 0:
+		if (ExecProgram ((dis, bc1, '-f', '-o', ll1))):
 			result.Fail()
 
 		#
 		# Assemble the program again.
 		#
-		exit_status = os.spawnl (os.P_WAIT, as, as, 'll.1', '-f', '-o=bc.2')
-		if exit_status != 0:
+		if (ExecProgram ((as, ll1, '-f', '-o', bc2))):
 			result.Fail()
 
 		#
 		# Disassemble the program one last time.
 		#
-		exit_status = os.spawnl (os.P_WAIT, dis, dis, 'bc.2', '-f', '-o=ll.2')
-		if exit_status != 0:
+		if (ExecProgram ((dis, bc2, '-f', '-o', ll2))):
 			result.Fail()
 
 		#
 		# Compare the LLVM assembly output to see if it is the same.
 		#
-		exit_status = filecmp.cmp ('ll.1', 'll.2', 'false')
+		exit_status = filecmp.cmp (ll1, ll2, 'false')
 		if exit_status == 0:
 			result.Fail()
 			return
@@ -636,10 +695,10 @@
 		#
 		# Cleanup the test.
 		#
-		os.remove ('bc.1')
-		os.remove ('bc.2')
-		os.remove ('ll.1')
-		os.remove ('ll.2')
+		os.remove (bc1)
+		os.remove (bc2)
+		os.remove (ll1)
+		os.remove (ll2)
 
 		return
 





More information about the llvm-commits mailing list