[llvm-commits] CVS: llvm/test/QMTestDB/QMTest/llvm.py
John Criswell
criswell at cs.uiuc.edu
Tue Aug 19 22:08:08 PDT 2003
Changes in directory llvm/test/QMTestDB/QMTest:
llvm.py added (r1.1)
---
Log message:
Initial checking of QMTest.
---
Diffs of the changes:
Index: llvm/test/QMTestDB/QMTest/llvm.py
diff -c /dev/null llvm/test/QMTestDB/QMTest/llvm.py:1.1
*** /dev/null Tue Aug 19 22:07:04 2003
--- llvm/test/QMTestDB/QMTest/llvm.py Tue Aug 19 22:06:54 2003
***************
*** 0 ****
--- 1,1013 ----
+ ##############################################################################
+ #
+ # File: llvm.py
+ #
+ # Description:
+ # This file contains python classes that define resources and tests
+ # performed by the LLVM test suite.
+ #
+ ##############################################################################
+
+ import qm
+ import qm.test
+ import qm.test.test
+ import qm.fields
+
+ import os
+ import filecmp
+
+ ##############################################################################
+ #
+ # Class: AssembleTest
+ #
+ # Description:
+ # This class verifies that a specified LLVM assembly file can be
+ # assembled into bytecode using the LLVM as utility.
+ #
+ ##############################################################################
+ class AssembleTest(qm.test.test.Test):
+
+ #
+ # Description
+ #
+ description="Verifies that LLVM can assemble a file"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='assembly_file',
+ title='LLVM Assembly File',
+ description='LLVM Assembly File to Assemble'),
+ ]
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=srcroot + '/' + self.assembly_file
+ bcpath=tmpdir + '/' + 'temp.bc'
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ as = buildroot + '/tools/Debug/as'
+
+ #
+ # Assume we will succeed
+ #
+ fail = 0
+
+ #
+ # Use the LLVM assembler to assemble the program.
+ #
+ cmd = as + ' ' + srcfile + ' -d -f -o ' + bcpath + self.devnull
+ estatus=os.system (cmd)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ fail = 1
+ result.Fail()
+
+ #
+ # Cleanup the bytecode file.
+ #
+ if ((os.access(bcpath,os.F_OK)) == 1):
+ os.remove (bcpath)
+ else:
+ if (fail != 1):
+ result.Fail('Output file not generated')
+
+ return
+
+ ##############################################################################
+ #
+ # Class: ConvertToCTest
+ #
+ # Description:
+ # This test verifies that the specified bytecode file can be converted
+ # back into C code.
+ #
+ ##############################################################################
+ class ConvertToCTest(qm.test.test.Test):
+
+ description="Verifies that LLVM can convert a file into C code"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='bytecode_file',
+ title='LLVM Bytecode File',
+ description='LLVM Bytecode File to Convert to C'),
+ ]
+
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=tmpdir + '/' + self.bytecode_file
+ objfile=tmpdir + '/' + self.bytecode_file + '.tc'
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ dis = buildroot + '/tools/Debug/dis'
+
+ #
+ # Use the LLVM assembler to assemble the program.
+ #
+ cmd = dis + ' ' + srcfile + ' -c -o ' + objfile + self.devnull
+ estatus=os.system (cmd)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ fail = 1
+ result.Fail()
+ else:
+ fail = 0
+
+ #
+ # Cleanup the file.
+ #
+ if ((os.access(objfile,os.F_OK)) == 1):
+ os.remove (objfile)
+ else:
+ if (fail == 0):
+ result.Fail ('Object file not generated')
+
+ return
+
+ ##############################################################################
+ #
+ # Class: LLToCTest
+ #
+ # Description:
+ # This test verifies that the specified LLVM source file can be converted
+ # into C code which can then be compiled.
+ #
+ ##############################################################################
+ class LLToCTest(qm.test.test.Test):
+
+ description="Verifies that LLVM can convert a file into C code"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='srcfile',
+ title='LLVM Bytecode File',
+ description='LLVM Bytecode File to Convert to C'),
+ ]
+
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=srcroot + '/' + self.srcfile
+ csrcfile=tmpdir + '/' + os.path.basename (self.srcfile) + '.c'
+ cobjfile=tmpdir + '/' + os.path.basename (self.srcfile) + '.to'
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ cc = context['cc']
+ as = buildroot + '/tools/' + context['buildtype'] + '/as'
+ dis = buildroot + '/tools/' + context['buildtype'] + '/dis'
+
+ #
+ # Construct the command to generate the C source and object
+ # file.
+ #
+ ccmd = as + ' < ' + srcfile + ' | ' + dis + ' -f -c -o=' + csrcfile
+ lcmd = cc + ' -c -Werror ' + csrcfile + ' -o ' + cobjfile + ' > ' + tmpdir + '/' + os.path.basename (self.srcfile) + '.out 2>&1'
+
+ #
+ # Assemble the program into C code and then compile it.
+ #
+ estatus=os.system (ccmd)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ fail = 1
+ result.Fail('Converting to C code failed')
+ else:
+ estatus=os.system (lcmd)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ fail = 1
+ result.Fail('Compiling code failed')
+ else:
+ fail = 0
+
+ #
+ # Cleanup the files.
+ #
+ if ((os.access(cobjfile,os.F_OK)) == 1):
+ os.remove (cobjfile)
+ else:
+ if (fail == 0):
+ result.Fail ('Object file not generated')
+
+ if ((os.access(csrcfile,os.F_OK)) == 1):
+ os.remove (csrcfile)
+ else:
+ if (fail == 0):
+ result.Fail ('Source file not generated')
+
+ return
+
+ ##############################################################################
+ #
+ # Class: MachineCodeTest
+ #
+ # Description:
+ # This test verifies that the specified bytecode file can be converted
+ # into machine code.
+ #
+ ##############################################################################
+ class MachineCodeTest(qm.test.test.Test):
+
+ description="Verifies that LLVM can convert a file into machine code"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='bytecode_file',
+ title='LLVM Bytecode File',
+ description='LLVM Bytecode File to Convert to Machine Code'),
+ ]
+
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=tmpdir + '/' + self.bytecode_file
+ objfile=tmpdir + '/' + self.bytecode_file + '.mc'
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ llc = buildroot + '/tools/Debug/llc'
+
+ #
+ # Use the LLVM assembler to assemble the program.
+ #
+ cmd = llc + ' ' + srcfile + ' -f -o=' + objfile + self.devnull
+ estatus=os.system (cmd)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ fail = 1
+ result.Fail()
+ else:
+ fail = 0
+
+ #
+ # Cleanup the file if it exists.
+ #
+ if ((os.access(objfile,os.F_OK)) == 1):
+ os.remove (objfile)
+ else:
+ if (fail == 0):
+ result.Fail ('Object file not created')
+
+ return
+
+ ##############################################################################
+ #
+ # Class: AssemblyCodeTest
+ #
+ # Description:
+ # This test verifies that the specified bytecode file can be converted
+ # into assembly code.
+ #
+ ##############################################################################
+ class AssemblyCodeTest(qm.test.test.Test):
+
+ description="Verifies that LLVM can convert a file into assembly code"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='bytecode_file',
+ title='LLVM Bytecode File',
+ description='LLVM Bytecode File to Convert to Machine Code'),
+ ]
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=tmpdir + '/' + self.bytecode_file
+ objfile=tmpdir + '/' + self.bytecode_file + '.s'
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ llc = buildroot + '/tools/Debug/llc'
+
+ #
+ # Use the LLVM assembler to assemble the program.
+ #
+ exstatus=os.spawnl (os.P_WAIT, llc, llc, srcfile, '-f', '-o=' + objfile)
+ if (exstatus != 0):
+ result.Fail()
+
+ #
+ # Cleanup the file if it exists.
+ #
+ if ((os.access(objfile,os.F_OK)) == 1):
+ os.remove (objfile)
+
+ return
+
+ ##############################################################################
+ #
+ # Class: TestOptimizer
+ #
+ # Description:
+ # This class runs two optimizer tests on the specified program.
+ #
+ ##############################################################################
+ class TestOptimizer(qm.test.test.Test):
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='assembly_file',
+ title='LLVM Assembly File',
+ description='LLVM Assembly File to run through the Optimizer'),
+ ]
+
+ #
+ # LLVM Utilities
+ #
+ as='as'
+ dis='dis'
+ opt='opt'
+
+ #
+ # Method: Run
+ #
+ # Description:
+ # This method is called when the test case is invoked by QMTest.
+ #
+ def Run (self, context, result):
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+
+ #
+ # Construct the pathname of the source file.
+ #
+ sourcefile=srcroot + '/' + self.assembly_file
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ self.as = buildroot + '/tools/Debug/as'
+ self.dis = buildroot + '/tools/Debug/dis'
+ self.opt = buildroot + '/tools/Debug/opt'
+
+ #
+ # Run the optimizer.
+ #
+ flags = '-constprop -dce'
+ self.Opt (flags, sourcefile, result)
+ flags = '-sccp -dce'
+ self.Opt (flags, sourcefile, result)
+
+ return
+
+ #
+ # Method: Opt()
+ #
+ # Description:
+ # This method attempts to assemble and optimize the program
+ # with the specified flags. If the resultant program can be
+ # further reduced, then the optimization has failed.
+ #
+ # Inputs:
+ # flags - The list of optimizer flags to use.
+ # file - The assembly file to assemble and optimize.
+ # result - The result object used for the test.
+ #
+ # Notes:
+ # This function will probably not be portable the first time
+ # around.
+ #
+ def Opt(self, flags, file, result):
+ #
+ # Create local versions of the global class variables
+ #
+ as = self.as
+ dis=self.dis
+ opt=self.opt
+
+ #
+ # The pipe symbole
+ #
+ p=' | '
+
+ #
+ # Assemble and optimize the given program. Then, disassemble
+ # it and reassemble it again.
+ #
+ # This should provide a bytecode file that cannot be optimized
+ # any further.
+ #
+ estatus = os.system (as + ' < ' + file + p + opt + ' -q -inline -dce ' + flags + p + dis + p + as + ' > bc.1')
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ result.Fail()
+ return;
+
+ #
+ # Now, attempt to optimize the the program again.
+ #
+ estatus=os.system (opt + ' -q ' + flags + ' < bc.1 > bc.2')
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ result.Fail()
+ return
+
+ #
+ # If the two programs are identical, then we have failed!
+ #
+ status1 = os.spawnl (os.P_WAIT, dis, dis, 'bc.1', '-f', '-o=ll.1');
+ status2 = os.spawnl (os.P_WAIT, dis, dis, 'bc.2', '-f', '-o=ll.2');
+ if ((status1 != 0) or (status2 != 0)):
+ result.Fail()
+ return
+
+ status = filecmp.cmp ('ll.1', 'll.2', 'false');
+ if (status == 0):
+ result.Fail()
+ return
+
+ #
+ # Cleanup any temporary files.
+ #
+ os.remove ('bc.1')
+ os.remove ('bc.2')
+ os.remove ('ll.1')
+ os.remove ('ll.2')
+ return
+
+ ##############################################################################
+ #
+ # Class: TestAsmDisasm
+ #
+ # Description:
+ # This class defines a qmtest test class. It will assemble and
+ # disassemble a given LLVM assembly file to ensure that the assembler
+ # and disassembler work properly.
+ #
+ # Note:
+ # This class is restricted to running programs in llvm/test/Feature.
+ # Eventually it will be modified to run them from anywhere within the
+ # LLVM source tree.
+ #
+ ##############################################################################
+ class TestAsmDisasm(qm.test.test.Test):
+
+ # List of information that is passed into each test
+ arguments = [
+ # Name of the file to assemble and disassemble
+ qm.fields.TextField(name="assembly_file",
+ title="LLVM Assembly File",
+ description="Name of the LLVM Assembly language file to assemble and disassemble"),
+ ]
+
+ #
+ # Method: Run
+ #
+ # Description:
+ # This method is called by qmtest to start the test. It will
+ # complete two full cycles of assembling/disassembling since
+ # that is what is needed for bitwise stability.
+ #
+ def Run(self,context,result):
+ #
+ # Determine where the build directory is located.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ testdir=srcroot + '/test/Feature'
+
+ #
+ # Determine the path to the assembler and disassembler
+ #
+ as = buildroot + '/tools/Debug/as'
+ dis = buildroot + '/tools/Debug/dis'
+
+ #
+ # Find the name of the file to assemble.
+ #
+ input=testdir + '/' + self.assembly_file
+
+ #
+ # Assemble the file.
+ #
+ exit_status = os.spawnl (os.P_WAIT, as, as, input, '-f', '-o=bc.1')
+ if exit_status != 0:
+ result.Fail()
+
+ #
+ # Disassemble the output.
+ #
+ exit_status = os.spawnl (os.P_WAIT, dis, dis, 'bc.1', '-f', '-o=ll.1')
+ if exit_status != 0:
+ 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:
+ 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:
+ result.Fail()
+
+ #
+ # Compare the LLVM assembly output to see if it is the same.
+ #
+ exit_status = filecmp.cmp ('ll.1', 'll.2', 'false')
+ if exit_status == 0:
+ result.Fail()
+ return
+
+ #
+ # Cleanup the test.
+ #
+ os.remove ('bc.1')
+ os.remove ('bc.2')
+ os.remove ('ll.1')
+ os.remove ('ll.2')
+
+ return
+
+
+ ##############################################################################
+ #
+ # Class: VerifierTest
+ #
+ # Description:
+ # This class is designed to test the verifier pass of LLVM. It attempts
+ # to assemble the specified file.
+ #
+ ##############################################################################
+ class VerifierTest(qm.test.test.Test):
+
+ #
+ # Description
+ #
+ description="Verifies that LLVM can assemble a file"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='assembly_file',
+ title='LLVM Assembly File',
+ description='LLVM Assembly File to Verify'),
+ ]
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=srcroot + '/' + self.assembly_file
+ bcpath=tmpdir + '/' + 'temp.bc'
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ as = buildroot + '/tools/Debug/as'
+
+ #
+ # Use the LLVM assembler to assemble the program.
+ #
+ cmd = as + ' ' + srcfile + ' -f -o /dev/null ' + self.devnull
+ estatus=os.system (cmd)
+ if (os.WIFEXITED(estatus)):
+ if (os.WEXITSTATUS(estatus) == 0):
+ result.Fail(srcfile + ' assembled')
+ else:
+ result.Fail ('Assembler Terminated Abnormally')
+
+ #
+ # Cleanup the bytecode file.
+ #
+ if ((os.access(bcpath,os.F_OK)) == 1):
+ os.remove (bcpath)
+
+ return
+
+
+ ##############################################################################
+ #
+ # Class: LLITest
+ #
+ # Description:
+ # This test verifies that the specified bytecode file can be run through
+ # the JIT.
+ #
+ ##############################################################################
+ class LLITest(qm.test.test.Test):
+
+ description="Verifies that LLVM can use LLI on the specified program"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='bytecode_file',
+ title='LLVM Bytecode File',
+ description='LLVM Bytecode File to Convert to Machine Code'),
+ ]
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=tmpdir + '/' + self.bytecode_file
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ lli = buildroot + '/tools/Debug/lli'
+
+ #
+ # Execute the program.
+ #
+ estatus=os.system (lli + ' ' + srcfile + ' > /dev/null 2>&1')
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ result.Fail('LLI failed to execute bytecode')
+
+ return
+
+ ##############################################################################
+ #
+ # Class: AnalyzeTest
+ #
+ # Description:
+ # This class runs an LLVM assembly language program through the analyzer.
+ #
+ ##############################################################################
+ class AnalyzeTest(qm.test.test.Test):
+
+ #
+ # Description
+ #
+ description="Verifies that LLVM can analyze a file"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='assembly_file',
+ title='LLVM Assembly File',
+ description='LLVM Assembly File to Analyze'),
+ ]
+
+ devnull = ' > /dev/null 2>&1'
+
+ def Run (self, context, result):
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+
+ #
+ # Construct the pathname of the source file and object file.
+ #
+ srcfile=srcroot + '/' + self.assembly_file
+
+ #
+ # Construct the pathnames to the various utilities.
+ #
+ anal = buildroot + '/tools/Debug/analyze -tddatastructure'
+
+ #
+ # Use the LLVM assembler to assemble the program.
+ #
+ cmd = anal + ' ' + srcfile + self.devnull
+ estatus=os.system (cmd)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ result.Fail()
+
+ return
+
+
+ ##############################################################################
+ #
+ # Class: TestRunner
+ #
+ # Description:
+ # This test executes the specified program using the TestRunner script
+ # from days of yore.
+ #
+ ##############################################################################
+ class TestRunner(qm.test.test.Test):
+
+ description="Execute a test via the TestRunner Script"
+
+ #
+ # List of arguments that the objects accepts for test configuration.
+ #
+ arguments = [
+ qm.fields.TextField(name='srcfile',
+ title='TestRunner script file',
+ description='Name of script to execute via TestRunner'),
+ ]
+
+
+ def Run (self, context, result):
+
+ #
+ # Fetch the source and build root directories from the context.
+ #
+ srcroot=context['srcroot']
+ buildroot=context['buildroot']
+ tmpdir=context['tmpdir']
+ buildtype=context['buildtype']
+
+ #
+ # Construct the pathname of the source file and output script
+ # file.
+ #
+ srcfile=srcroot + '/' + self.srcfile
+ scriptfile = tmpdir + '/testscript.' + os.path.basename (srcfile)
+ outputfile = tmpdir + '/testscript.' + os.path.basename (srcfile) + '.out'
+
+ #
+ # Construct a new path that includes the LLVM tools.
+ #
+ environment=os.environ
+ oldpath=environment['PATH']
+ environment['PATH'] = buildroot + '/tools/' + buildtype + ':' + srcroot + '/test/Scripts:' + environment['PATH']
+
+ #
+ # 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',
+ 'w ' + scriptfile,
+ srcfile)
+
+ if (exstatus != 0):
+ result.Fail('The sed script failed')
+ environment['PATH'] = oldpath
+ return
+
+ #
+ # Execute the script using TestRunner.
+ #
+ command = '/bin/sh ' + scriptfile + ' > ' + outputfile + ' 2>&1'
+ estatus=os.system (command)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ result.Fail('Script: ' + scriptfile + '\n Output: ' + outputfile)
+
+ #
+ # Restore the PATH environment variable
+ #
+ environment['PATH'] = oldpath
+
+ #
+ # Return to the caller.
+ #
+ return
+
+
+ ##############################################################################
+ #
+ # Class: MakeResource
+ #
+ # Description:
+ # This resource builds the specified directory.
+ #
+ ##############################################################################
+ class MakeResource(qm.test.resource.Resource):
+ arguments = [
+ qm.fields.TextField(name='srcdir',
+ title='Source Directory',
+ description='Name of the source directory to build.'),
+ qm.fields.TextField(name='bcfilename',
+ title='Bytecode Filename',
+ description='Name of the bytecode file to be generated.'),
+ ]
+
+ srcroot=''
+ buildroot=''
+ tmpdir=''
+
+ #
+ # Method: SetUp()
+ #
+ # Description:
+ # This method creates an instance of this resource.
+ # Specifically, it will use make to build the specified
+ # directory.
+ #
+ def SetUp(self, context, result):
+ #
+ # Determine the pathnames to the source code and object code.
+ #
+ self.srcroot = context['srcroot']
+ self.buildroot = context['buildroot']
+ self.tmpdir = context['tmpdir']
+ self.make = make = context['make']
+
+ #
+ # Create the complete pathname of the source directory.
+ #
+ srcdir = self.srcroot + '/' + self.srcdir
+
+ #
+ # Get the current directory.
+ #
+ curdir = os.getcwd()
+
+ #
+ # Change to the directory where the makefile will be.
+ #
+ os.chdir (self.buildroot + '/' + self.srcdir)
+
+ #
+ # Execute make to build the programs.
+ #
+ estatus=os.system (make)
+ if ((os.WIFEXITED(estatus)) and (os.WEXITSTATUS(estatus) != 0)):
+ result.Fail()
+
+ #
+ # Change our working directory back to where we were.
+ #
+ os.chdir (curdir)
+
+ return
+
+ #
+ # Method: CleanUp()
+ #
+ # Description:
+ # This method removes the resource once it is no longer needed.
+ #
+ def CleanUp(self, result):
+ return
+
+
+ ##############################################################################
+ #
+ # Class: BytecodeResource
+ #
+ # Description:
+ # This resource takes the specified source file and builds a bytecode
+ # file from it.
+ #
+ ##############################################################################
+
+ class BytecodeResource(qm.test.resource.Resource):
+ arguments = [
+ qm.fields.TextField(name='srcfile',
+ title='Source File',
+ description='Name of the file to assemble into bytecode.'),
+ qm.fields.TextField(name='bcfilename',
+ title='Bytecode Filename',
+ description='Name of the bytecode file to be generated.'),
+ ]
+
+ srcroot=''
+ buildroot=''
+ tmpdir=''
+
+ #
+ # Method: SetUp()
+ #
+ # Description:
+ # This method creates an instance of this resource.
+ # Specifically, it will create the necessary bytecode file from
+ # the specified source file.
+ #
+ def SetUp(self, context, result):
+ #
+ # Determine the pathnames to the source code and object code.
+ #
+ self.srcroot = context['srcroot']
+ self.buildroot = context['buildroot']
+ self.tmpdir = context['tmpdir']
+
+ #
+ # Now create the source file pathname.
+ #
+ srcpath = self.srcroot + '/' + self.srcfile
+ bcpath = self.tmpdir + '/' + self.bcfilename
+
+ #
+ # Find the pathname of the assembler.
+ #
+ as = self.buildroot + '/tools/Debug/as'
+
+ #
+ # Use the LLVM assembler to create the bytecode file.
+ #
+ exstatus=os.spawnl (os.P_WAIT, as, as, srcpath, '-o=' + bcpath)
+ if (exstatus != 0):
+ result.Fail('Failed to assemble ' + srcpath)
+ return
+ return
+
+ #
+ # Method: CleanUp()
+ #
+ # Description:
+ # This method removes the resource once it is no longer needed.
+ #
+ def CleanUp(self, result):
+ os.remove (self.tmpdir + '/' + self.bcfilename)
+ return
+
More information about the llvm-commits
mailing list