diff options
author | Gao, Liming <liming.gao@intel.com> | 2014-01-27 05:23:15 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2014-01-27 05:23:15 +0000 |
commit | f51461c829c124288a930829a78e2a5a799f4039 (patch) | |
tree | 1072993516da9d887f0e0fd876c9ac5630c19ae2 /BaseTools/Tests | |
parent | 7771be9fd0b9b3c7f5c0659c416535171de31191 (diff) | |
download | edk2-f51461c829c124288a930829a78e2a5a799f4039.zip edk2-f51461c829c124288a930829a78e2a5a799f4039.tar.gz edk2-f51461c829c124288a930829a78e2a5a799f4039.tar.bz2 |
Sync BaseTool trunk (version r2649) into EDKII BaseTools.
Signed-off-by: Gao, Liming <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15188 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Tests')
-rw-r--r-- | BaseTools/Tests/CToolsTests.py | 70 | ||||
-rw-r--r-- | BaseTools/Tests/CheckPythonSyntax.py | 148 | ||||
-rw-r--r-- | BaseTools/Tests/PythonToolsTests.py | 64 | ||||
-rw-r--r-- | BaseTools/Tests/RunTests.py | 80 | ||||
-rw-r--r-- | BaseTools/Tests/TestTools.py | 358 | ||||
-rw-r--r-- | BaseTools/Tests/TianoCompress.py | 148 |
6 files changed, 434 insertions, 434 deletions
diff --git a/BaseTools/Tests/CToolsTests.py b/BaseTools/Tests/CToolsTests.py index 67681ea..ab75d9a 100644 --- a/BaseTools/Tests/CToolsTests.py +++ b/BaseTools/Tests/CToolsTests.py @@ -1,35 +1,35 @@ -## @file -# Unit tests for C based BaseTools -# -# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR> -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -import os -import sys -import unittest - -import TianoCompress -modules = ( - TianoCompress, - ) - - -def TheTestSuite(): - suites = map(lambda module: module.TheTestSuite(), modules) - return unittest.TestSuite(suites) - -if __name__ == '__main__': - allTests = TheTestSuite() - unittest.TextTestRunner().run(allTests) - +## @file
+# Unit tests for C based BaseTools
+#
+# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+import sys
+import unittest
+
+import TianoCompress
+modules = (
+ TianoCompress,
+ )
+
+
+def TheTestSuite():
+ suites = map(lambda module: module.TheTestSuite(), modules)
+ return unittest.TestSuite(suites)
+
+if __name__ == '__main__':
+ allTests = TheTestSuite()
+ unittest.TextTestRunner().run(allTests)
+
diff --git a/BaseTools/Tests/CheckPythonSyntax.py b/BaseTools/Tests/CheckPythonSyntax.py index e27c341..61a048a 100644 --- a/BaseTools/Tests/CheckPythonSyntax.py +++ b/BaseTools/Tests/CheckPythonSyntax.py @@ -1,74 +1,74 @@ -## @file -# Unit tests for checking syntax of Python source code -# -# Copyright (c) 2009, Intel Corporation. All rights reserved.<BR> -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -import os -import unittest -import py_compile - -import TestTools - -class Tests(TestTools.BaseToolsTest): - - def setUp(self): - TestTools.BaseToolsTest.setUp(self) - - def SingleFileTest(self, filename): - try: - py_compile.compile(filename, doraise=True) - except Exception, e: - self.fail('syntax error: %s, Error is %s' % (filename, str(e))) - -def MakePythonSyntaxCheckTests(): - def GetAllPythonSourceFiles(): - pythonSourceFiles = [] - for (root, dirs, files) in os.walk(TestTools.PythonSourceDir): - for filename in files: - if filename.lower().endswith('.py'): - pythonSourceFiles.append( - os.path.join(root, filename) - ) - return pythonSourceFiles - - def MakeTestName(filename): - assert filename.lower().endswith('.py') - name = filename[:-3] - name = name.replace(TestTools.PythonSourceDir, '') - name = name.replace(os.path.sep, '_') - return 'test' + name - - def MakeNewTest(filename): - test = MakeTestName(filename) - newmethod = lambda self: self.SingleFileTest(filename) - setattr( - Tests, - test, - newmethod - ) - - for filename in GetAllPythonSourceFiles(): - MakeNewTest(filename) - -MakePythonSyntaxCheckTests() -del MakePythonSyntaxCheckTests - -TheTestSuite = TestTools.MakeTheTestSuite(locals()) - -if __name__ == '__main__': - allTests = TheTestSuite() - unittest.TextTestRunner().run(allTests) - - +## @file
+# Unit tests for checking syntax of Python source code
+#
+# Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+import unittest
+import py_compile
+
+import TestTools
+
+class Tests(TestTools.BaseToolsTest):
+
+ def setUp(self):
+ TestTools.BaseToolsTest.setUp(self)
+
+ def SingleFileTest(self, filename):
+ try:
+ py_compile.compile(filename, doraise=True)
+ except Exception, e:
+ self.fail('syntax error: %s, Error is %s' % (filename, str(e)))
+
+def MakePythonSyntaxCheckTests():
+ def GetAllPythonSourceFiles():
+ pythonSourceFiles = []
+ for (root, dirs, files) in os.walk(TestTools.PythonSourceDir):
+ for filename in files:
+ if filename.lower().endswith('.py'):
+ pythonSourceFiles.append(
+ os.path.join(root, filename)
+ )
+ return pythonSourceFiles
+
+ def MakeTestName(filename):
+ assert filename.lower().endswith('.py')
+ name = filename[:-3]
+ name = name.replace(TestTools.PythonSourceDir, '')
+ name = name.replace(os.path.sep, '_')
+ return 'test' + name
+
+ def MakeNewTest(filename):
+ test = MakeTestName(filename)
+ newmethod = lambda self: self.SingleFileTest(filename)
+ setattr(
+ Tests,
+ test,
+ newmethod
+ )
+
+ for filename in GetAllPythonSourceFiles():
+ MakeNewTest(filename)
+
+MakePythonSyntaxCheckTests()
+del MakePythonSyntaxCheckTests
+
+TheTestSuite = TestTools.MakeTheTestSuite(locals())
+
+if __name__ == '__main__':
+ allTests = TheTestSuite()
+ unittest.TextTestRunner().run(allTests)
+
+
diff --git a/BaseTools/Tests/PythonToolsTests.py b/BaseTools/Tests/PythonToolsTests.py index 7db5855..6096e21 100644 --- a/BaseTools/Tests/PythonToolsTests.py +++ b/BaseTools/Tests/PythonToolsTests.py @@ -1,32 +1,32 @@ -## @file -# Unit tests for Python based BaseTools -# -# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR> -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -import os -import sys -import unittest - - -def TheTestSuite(): - suites = [] - import CheckPythonSyntax - suites.append(CheckPythonSyntax.TheTestSuite()) - return unittest.TestSuite(suites) - -if __name__ == '__main__': - allTests = TheTestSuite() - unittest.TextTestRunner().run(allTests) - +## @file
+# Unit tests for Python based BaseTools
+#
+# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+import sys
+import unittest
+
+
+def TheTestSuite():
+ suites = []
+ import CheckPythonSyntax
+ suites.append(CheckPythonSyntax.TheTestSuite())
+ return unittest.TestSuite(suites)
+
+if __name__ == '__main__':
+ allTests = TheTestSuite()
+ unittest.TextTestRunner().run(allTests)
+
diff --git a/BaseTools/Tests/RunTests.py b/BaseTools/Tests/RunTests.py index 193bc60..e8ca2d0 100644 --- a/BaseTools/Tests/RunTests.py +++ b/BaseTools/Tests/RunTests.py @@ -1,40 +1,40 @@ -## @file -# Unit tests for BaseTools utilities -# -# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR> -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -import os -import sys -import unittest - -import TestTools - -sys.path.append(TestTools.PythonSourceDir) - -def GetCTestSuite(): - import CToolsTests - return CToolsTests.TheTestSuite() - -def GetPythonTestSuite(): - import PythonToolsTests - return PythonToolsTests.TheTestSuite() - -def GetAllTestsSuite(): - return unittest.TestSuite([GetCTestSuite(), GetPythonTestSuite()]) - -if __name__ == '__main__': - allTests = GetAllTestsSuite() - unittest.TextTestRunner(verbosity=2).run(allTests) - +## @file
+# Unit tests for BaseTools utilities
+#
+# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+import sys
+import unittest
+
+import TestTools
+
+sys.path.append(TestTools.PythonSourceDir)
+
+def GetCTestSuite():
+ import CToolsTests
+ return CToolsTests.TheTestSuite()
+
+def GetPythonTestSuite():
+ import PythonToolsTests
+ return PythonToolsTests.TheTestSuite()
+
+def GetAllTestsSuite():
+ return unittest.TestSuite([GetCTestSuite(), GetPythonTestSuite()])
+
+if __name__ == '__main__':
+ allTests = GetAllTestsSuite()
+ unittest.TextTestRunner(verbosity=2).run(allTests)
+
diff --git a/BaseTools/Tests/TestTools.py b/BaseTools/Tests/TestTools.py index e838ae4..ac009db 100644 --- a/BaseTools/Tests/TestTools.py +++ b/BaseTools/Tests/TestTools.py @@ -1,179 +1,179 @@ -## @file -# Utility functions and classes for BaseTools unit tests -# -# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR> -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -import base64 -import os -import os.path -import random -import shutil -import subprocess -import sys -import types -import unittest - -TestsDir = os.path.realpath(os.path.split(sys.argv[0])[0]) -BaseToolsDir = os.path.realpath(os.path.join(TestsDir, '..')) -CSourceDir = os.path.join(BaseToolsDir, 'Source', 'C') -PythonSourceDir = os.path.join(BaseToolsDir, 'Source', 'Python') -TestTempDir = os.path.join(TestsDir, 'TestTempDir') - -def MakeTheTestSuite(localItems): - tests = [] - for name, item in localItems.iteritems(): - if isinstance(item, types.TypeType): - if issubclass(item, unittest.TestCase): - tests.append(unittest.TestLoader().loadTestsFromTestCase(item)) - elif issubclass(item, unittest.TestSuite): - tests.append(item()) - return lambda: unittest.TestSuite(tests) - -def GetBaseToolsPaths(): - if sys.platform in ('win32', 'win64'): - return [ os.path.join(BaseToolsDir, 'Bin', sys.platform.title()) ] - else: - uname = os.popen('uname -sm').read().strip() - for char in (' ', '/'): - uname = uname.replace(char, '-') - return [ - os.path.join(BaseToolsDir, 'Bin', uname), - os.path.join(BaseToolsDir, 'BinWrappers', uname), - os.path.join(BaseToolsDir, 'BinWrappers', 'PosixLike') - ] - -BaseToolsBinPaths = GetBaseToolsPaths() - -class BaseToolsTest(unittest.TestCase): - - def cleanOutDir(self, dir): - for dirItem in os.listdir(dir): - if dirItem in ('.', '..'): continue - dirItem = os.path.join(dir, dirItem) - self.RemoveFileOrDir(dirItem) - - def CleanUpTmpDir(self): - if os.path.exists(self.testDir): - self.cleanOutDir(self.testDir) - - def HandleTreeDeleteError(self, function, path, excinfo): - os.chmod(path, stat.S_IWRITE) - function(path) - - def RemoveDir(self, dir): - shutil.rmtree(dir, False, self.HandleTreeDeleteError) - - def RemoveFileOrDir(self, path): - if not os.path.exists(path): - return - elif os.path.isdir(path): - self.RemoveDir(path) - else: - os.remove(path) - - def DisplayBinaryData(self, description, data): - print description, '(base64 encoded):' - b64data = base64.b64encode(data) - print b64data - - def DisplayFile(self, fileName): - sys.stdout.write(self.ReadTmpFile(fileName)) - sys.stdout.flush() - - def FindToolBin(self, toolName): - for binPath in BaseToolsBinPaths: - bin = os.path.join(binPath, toolName) - if os.path.exists(bin): - break - assert os.path.exists(bin) - return bin - - def RunTool(self, *args, **kwd): - if 'toolName' in kwd: toolName = kwd['toolName'] - else: toolName = None - if 'logFile' in kwd: logFile = kwd['logFile'] - else: logFile = None - - if toolName is None: toolName = self.toolName - bin = self.FindToolBin(toolName) - if logFile is not None: - logFile = open(os.path.join(self.testDir, logFile), 'w') - popenOut = logFile - else: - popenOut = subprocess.PIPE - - args = [toolName] + list(args) - - Proc = subprocess.Popen( - args, executable=bin, - stdout=popenOut, stderr=subprocess.STDOUT - ) - - if logFile is None: - Proc.stdout.read() - - return Proc.wait() - - def GetTmpFilePath(self, fileName): - return os.path.join(self.testDir, fileName) - - def OpenTmpFile(self, fileName, mode = 'r'): - return open(os.path.join(self.testDir, fileName), mode) - - def ReadTmpFile(self, fileName): - f = open(self.GetTmpFilePath(fileName), 'r') - data = f.read() - f.close() - return data - - def WriteTmpFile(self, fileName, data): - f = open(self.GetTmpFilePath(fileName), 'w') - f.write(data) - f.close() - - def GenRandomFileData(self, fileName, minlen = None, maxlen = None): - if maxlen is None: maxlen = minlen - f = self.OpenTmpFile(fileName, 'w') - f.write(self.GetRandomString(minlen, maxlen)) - f.close() - - def GetRandomString(self, minlen = None, maxlen = None): - if minlen is None: minlen = 1024 - if maxlen is None: maxlen = minlen - return ''.join( - [chr(random.randint(0,255)) - for x in xrange(random.randint(minlen, maxlen)) - ]) - - def setUp(self): - self.savedEnvPath = os.environ['PATH'] - self.savedSysPath = sys.path[:] - - for binPath in BaseToolsBinPaths: - os.environ['PATH'] = \ - os.path.pathsep.join((os.environ['PATH'], binPath)) - - self.testDir = TestTempDir - if not os.path.exists(self.testDir): - os.mkdir(self.testDir) - else: - self.cleanOutDir(self.testDir) - - def tearDown(self): - self.RemoveFileOrDir(self.testDir) - - os.environ['PATH'] = self.savedEnvPath - sys.path = self.savedSysPath - +## @file
+# Utility functions and classes for BaseTools unit tests
+#
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import base64
+import os
+import os.path
+import random
+import shutil
+import subprocess
+import sys
+import types
+import unittest
+
+TestsDir = os.path.realpath(os.path.split(sys.argv[0])[0])
+BaseToolsDir = os.path.realpath(os.path.join(TestsDir, '..'))
+CSourceDir = os.path.join(BaseToolsDir, 'Source', 'C')
+PythonSourceDir = os.path.join(BaseToolsDir, 'Source', 'Python')
+TestTempDir = os.path.join(TestsDir, 'TestTempDir')
+
+def MakeTheTestSuite(localItems):
+ tests = []
+ for name, item in localItems.iteritems():
+ if isinstance(item, types.TypeType):
+ if issubclass(item, unittest.TestCase):
+ tests.append(unittest.TestLoader().loadTestsFromTestCase(item))
+ elif issubclass(item, unittest.TestSuite):
+ tests.append(item())
+ return lambda: unittest.TestSuite(tests)
+
+def GetBaseToolsPaths():
+ if sys.platform in ('win32', 'win64'):
+ return [ os.path.join(BaseToolsDir, 'Bin', sys.platform.title()) ]
+ else:
+ uname = os.popen('uname -sm').read().strip()
+ for char in (' ', '/'):
+ uname = uname.replace(char, '-')
+ return [
+ os.path.join(BaseToolsDir, 'Bin', uname),
+ os.path.join(BaseToolsDir, 'BinWrappers', uname),
+ os.path.join(BaseToolsDir, 'BinWrappers', 'PosixLike')
+ ]
+
+BaseToolsBinPaths = GetBaseToolsPaths()
+
+class BaseToolsTest(unittest.TestCase):
+
+ def cleanOutDir(self, dir):
+ for dirItem in os.listdir(dir):
+ if dirItem in ('.', '..'): continue
+ dirItem = os.path.join(dir, dirItem)
+ self.RemoveFileOrDir(dirItem)
+
+ def CleanUpTmpDir(self):
+ if os.path.exists(self.testDir):
+ self.cleanOutDir(self.testDir)
+
+ def HandleTreeDeleteError(self, function, path, excinfo):
+ os.chmod(path, stat.S_IWRITE)
+ function(path)
+
+ def RemoveDir(self, dir):
+ shutil.rmtree(dir, False, self.HandleTreeDeleteError)
+
+ def RemoveFileOrDir(self, path):
+ if not os.path.exists(path):
+ return
+ elif os.path.isdir(path):
+ self.RemoveDir(path)
+ else:
+ os.remove(path)
+
+ def DisplayBinaryData(self, description, data):
+ print description, '(base64 encoded):'
+ b64data = base64.b64encode(data)
+ print b64data
+
+ def DisplayFile(self, fileName):
+ sys.stdout.write(self.ReadTmpFile(fileName))
+ sys.stdout.flush()
+
+ def FindToolBin(self, toolName):
+ for binPath in BaseToolsBinPaths:
+ bin = os.path.join(binPath, toolName)
+ if os.path.exists(bin):
+ break
+ assert os.path.exists(bin)
+ return bin
+
+ def RunTool(self, *args, **kwd):
+ if 'toolName' in kwd: toolName = kwd['toolName']
+ else: toolName = None
+ if 'logFile' in kwd: logFile = kwd['logFile']
+ else: logFile = None
+
+ if toolName is None: toolName = self.toolName
+ bin = self.FindToolBin(toolName)
+ if logFile is not None:
+ logFile = open(os.path.join(self.testDir, logFile), 'w')
+ popenOut = logFile
+ else:
+ popenOut = subprocess.PIPE
+
+ args = [toolName] + list(args)
+
+ Proc = subprocess.Popen(
+ args, executable=bin,
+ stdout=popenOut, stderr=subprocess.STDOUT
+ )
+
+ if logFile is None:
+ Proc.stdout.read()
+
+ return Proc.wait()
+
+ def GetTmpFilePath(self, fileName):
+ return os.path.join(self.testDir, fileName)
+
+ def OpenTmpFile(self, fileName, mode = 'r'):
+ return open(os.path.join(self.testDir, fileName), mode)
+
+ def ReadTmpFile(self, fileName):
+ f = open(self.GetTmpFilePath(fileName), 'r')
+ data = f.read()
+ f.close()
+ return data
+
+ def WriteTmpFile(self, fileName, data):
+ f = open(self.GetTmpFilePath(fileName), 'w')
+ f.write(data)
+ f.close()
+
+ def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
+ if maxlen is None: maxlen = minlen
+ f = self.OpenTmpFile(fileName, 'w')
+ f.write(self.GetRandomString(minlen, maxlen))
+ f.close()
+
+ def GetRandomString(self, minlen = None, maxlen = None):
+ if minlen is None: minlen = 1024
+ if maxlen is None: maxlen = minlen
+ return ''.join(
+ [chr(random.randint(0,255))
+ for x in xrange(random.randint(minlen, maxlen))
+ ])
+
+ def setUp(self):
+ self.savedEnvPath = os.environ['PATH']
+ self.savedSysPath = sys.path[:]
+
+ for binPath in BaseToolsBinPaths:
+ os.environ['PATH'] = \
+ os.path.pathsep.join((os.environ['PATH'], binPath))
+
+ self.testDir = TestTempDir
+ if not os.path.exists(self.testDir):
+ os.mkdir(self.testDir)
+ else:
+ self.cleanOutDir(self.testDir)
+
+ def tearDown(self):
+ self.RemoveFileOrDir(self.testDir)
+
+ os.environ['PATH'] = self.savedEnvPath
+ sys.path = self.savedSysPath
+
diff --git a/BaseTools/Tests/TianoCompress.py b/BaseTools/Tests/TianoCompress.py index 01cd975..e141364 100644 --- a/BaseTools/Tests/TianoCompress.py +++ b/BaseTools/Tests/TianoCompress.py @@ -1,74 +1,74 @@ -## @file -# Unit tests for TianoCompress utility -# -# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR> -# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -import os -import random -import sys -import unittest - -import TestTools - -class Tests(TestTools.BaseToolsTest): - - def setUp(self): - TestTools.BaseToolsTest.setUp(self) - self.toolName = 'TianoCompress' - - def testHelp(self): - result = self.RunTool('--help', logFile='help') - #self.DisplayFile('help') - self.assertTrue(result == 0) - - def compressionTestCycle(self, data): - path = self.GetTmpFilePath('input') - self.WriteTmpFile('input', data) - result = self.RunTool( - '-e', - '-o', self.GetTmpFilePath('output1'), - self.GetTmpFilePath('input') - ) - self.assertTrue(result == 0) - result = self.RunTool( - '-d', - '-o', self.GetTmpFilePath('output2'), - self.GetTmpFilePath('output1') - ) - self.assertTrue(result == 0) - start = self.ReadTmpFile('input') - finish = self.ReadTmpFile('output2') - startEqualsFinish = start == finish - if not startEqualsFinish: - print - print 'Original data did not match decompress(compress(data))' - self.DisplayBinaryData('original data', start) - self.DisplayBinaryData('after compression', self.ReadTmpFile('output1')) - self.DisplayBinaryData('after decomression', finish) - self.assertTrue(startEqualsFinish) - - def testRandomDataCycles(self): - for i in range(8): - data = self.GetRandomString(1024, 2048) - self.compressionTestCycle(data) - self.CleanUpTmpDir() - -TheTestSuite = TestTools.MakeTheTestSuite(locals()) - -if __name__ == '__main__': - allTests = TheTestSuite() - unittest.TextTestRunner().run(allTests) - - +## @file
+# Unit tests for TianoCompress utility
+#
+# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+##
+# Import Modules
+#
+import os
+import random
+import sys
+import unittest
+
+import TestTools
+
+class Tests(TestTools.BaseToolsTest):
+
+ def setUp(self):
+ TestTools.BaseToolsTest.setUp(self)
+ self.toolName = 'TianoCompress'
+
+ def testHelp(self):
+ result = self.RunTool('--help', logFile='help')
+ #self.DisplayFile('help')
+ self.assertTrue(result == 0)
+
+ def compressionTestCycle(self, data):
+ path = self.GetTmpFilePath('input')
+ self.WriteTmpFile('input', data)
+ result = self.RunTool(
+ '-e',
+ '-o', self.GetTmpFilePath('output1'),
+ self.GetTmpFilePath('input')
+ )
+ self.assertTrue(result == 0)
+ result = self.RunTool(
+ '-d',
+ '-o', self.GetTmpFilePath('output2'),
+ self.GetTmpFilePath('output1')
+ )
+ self.assertTrue(result == 0)
+ start = self.ReadTmpFile('input')
+ finish = self.ReadTmpFile('output2')
+ startEqualsFinish = start == finish
+ if not startEqualsFinish:
+ print
+ print 'Original data did not match decompress(compress(data))'
+ self.DisplayBinaryData('original data', start)
+ self.DisplayBinaryData('after compression', self.ReadTmpFile('output1'))
+ self.DisplayBinaryData('after decomression', finish)
+ self.assertTrue(startEqualsFinish)
+
+ def testRandomDataCycles(self):
+ for i in range(8):
+ data = self.GetRandomString(1024, 2048)
+ self.compressionTestCycle(data)
+ self.CleanUpTmpDir()
+
+TheTestSuite = TestTools.MakeTheTestSuite(locals())
+
+if __name__ == '__main__':
+ allTests = TheTestSuite()
+ unittest.TextTestRunner().run(allTests)
+
+
|