summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsbc@chromium.org <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 18:30:06 +0000
committersbc@chromium.org <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 18:30:06 +0000
commit2af672c30a59c63a7306250e46fab491b07b9341 (patch)
treee058afe81259bdcd2402143103d17b431453e299
parent42ec05efd0a3cd7601fa9a65afbadb8a10714eb6 (diff)
downloadchromium_src-2af672c30a59c63a7306250e46fab491b07b9341.zip
chromium_src-2af672c30a59c63a7306250e46fab491b07b9341.tar.gz
chromium_src-2af672c30a59c63a7306250e46fab491b07b9341.tar.bz2
Fix create_nmf tests so they are less dependent on checked in binaries.
Also, move test_all.py script to the top level, since it is the script that runs all tests, not just the ones in build_tools. BUG=172748 TEST=./test_all.py Review URL: https://codereview.chromium.org/12095024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179364 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xnative_client_sdk/src/build_tools/build_sdk.py2
-rwxr-xr-xnative_client_sdk/src/test_all.py (renamed from native_client_sdk/src/build_tools/tests/test_all.py)4
-rwxr-xr-xnative_client_sdk/src/tools/tests/create_nmf_test.py49
3 files changed, 47 insertions, 8 deletions
diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py
index 84b9a8e..320e468 100755
--- a/native_client_sdk/src/build_tools/build_sdk.py
+++ b/native_client_sdk/src/build_tools/build_sdk.py
@@ -793,7 +793,7 @@ def BuildStepTarBundle(pepper_ver, tarfile):
def BuildStepRunUnittests():
buildbot_common.BuildStep('Run unittests')
- test_all_py = os.path.join(SDK_SRC_DIR, 'build_tools', 'tests', 'test_all.py')
+ test_all_py = os.path.join(SDK_SRC_DIR, 'test_all.py')
buildbot_common.Run([sys.executable, test_all_py])
diff --git a/native_client_sdk/src/build_tools/tests/test_all.py b/native_client_sdk/src/test_all.py
index a364820..3077f88 100755
--- a/native_client_sdk/src/build_tools/tests/test_all.py
+++ b/native_client_sdk/src/test_all.py
@@ -9,8 +9,8 @@ import os
# add tools folder to sys.path
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
-SDK_DIR = os.path.dirname(os.path.dirname(SCRIPT_DIR))
-sys.path.append(os.path.join(SDK_DIR, 'tools', 'tests'))
+sys.path.append(os.path.join(SCRIPT_DIR, 'tools', 'tests'))
+sys.path.append(os.path.join(SCRIPT_DIR, 'build_tools', 'tests'))
TEST_MODULES = [
'oshelpers_test',
diff --git a/native_client_sdk/src/tools/tests/create_nmf_test.py b/native_client_sdk/src/tools/tests/create_nmf_test.py
index 05061a4..aee66e0 100755
--- a/native_client_sdk/src/tools/tests/create_nmf_test.py
+++ b/native_client_sdk/src/tools/tests/create_nmf_test.py
@@ -4,6 +4,7 @@
# found in the LICENSE file.
import os
import shutil
+import subprocess
import sys
import tempfile
import unittest
@@ -85,9 +86,30 @@ class TestNmfUtils(unittest.TestCase):
self.objdump = os.path.join(self.toolchain, 'bin', 'i686-nacl-objdump')
if os.name == 'nt':
self.objdump += '.exe'
- self.dyn_nexe = os.path.join(DATA_DIR, 'test_dynamic_x86_32.nexe')
- self.dyn_deps = set(['libc.so.51fe1ff9', 'runnable-ld.so',
- 'libgcc_s.so.1', 'libpthread.so.51fe1ff9'])
+ self.Mktemp()
+ self.dyn_nexe = self.createTestNexe('test_dynamic_x86_32.nexe', True,
+ 'i686')
+ self.dyn_deps = set(['libc.so', 'runnable-ld.so',
+ 'libgcc_s.so', 'libpthread.so'])
+
+ def createTestNexe(self, name, dynamic, arch):
+ """Create an empty test .nexe file for use in create_nmf tests.
+
+ This is used rather than checking in test binaries since the
+ checked in binaries depend on .so files that only exist in the
+ certain SDK that build them.
+ """
+ compiler = os.path.join(self.toolchain, 'bin', '%s-nacl-g++' % arch)
+ if os.name == 'nt':
+ compiler += '.exe'
+ os.environ['CYGWIN'] = 'nodosfilewarning'
+ program = 'int main() { return 0; }'
+ name = os.path.join(self.tempdir, name)
+ cmd = [compiler, '-pthread', '-x' , 'c', '-o', name, '-']
+ p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
+ p.communicate(input=program)
+ self.assertEqual(p.returncode, 0)
+ return name
def tearDown(self):
if self.tempdir:
@@ -115,6 +137,21 @@ class TestNmfUtils(unittest.TestCase):
archfile = needed.values()[0]
self.assertEqual(archfile.arch, 'x86-32')
+ def StripDependencies(self, deps):
+ """Strip the dirnames and version suffixs from
+ a list of nexe dependencies.
+
+ e.g:
+ /path/to/libpthread.so.1a2d3fsa -> libpthread.so
+ """
+ names = []
+ for name in deps:
+ name = os.path.basename(name)
+ if '.so.' in name:
+ name = name.rsplit('.', 1)[0]
+ names.append(name)
+ return names
+
def testGetNeededDynamic(self):
nmf = self.CreateNmfUtils()
needed = nmf.GetNeeded()
@@ -124,7 +161,7 @@ class TestNmfUtils(unittest.TestCase):
expected = set(self.dyn_deps)
expected.add(os.path.basename(self.dyn_nexe))
- basenames = set(os.path.basename(n) for n in names)
+ basenames = set(self.StripDependencies(names))
self.assertEqual(expected, basenames)
def testStageDependencies(self):
@@ -139,7 +176,9 @@ class TestNmfUtils(unittest.TestCase):
expectedContents = set((os.path.basename(self.dyn_nexe), 'lib32'))
self.assertEqual(contents, expectedContents)
- contents = set(os.listdir(os.path.join(self.tempdir, 'lib32')))
+ contents = os.listdir(os.path.join(self.tempdir, 'lib32'))
+ contents = self.StripDependencies(contents)
+ contents = set(contents)
expectedContents = self.dyn_deps
self.assertEqual(contents, expectedContents)