Skip to content

Commit

Permalink
test: make test runner multi-arch/mode compatible
Browse files Browse the repository at this point in the history
Make `python tools/test.py --arch=ia32,x64 --mode=debug,release` work.
The test runner looks for the `node` binary in `out/${arch}.${mode}/`.

Running tools/test.py without --arch makes it use `out/Release/node` or
`out/Debug/node` like before.

This commit removes `test/simple/test-executable-path.js` because the
assumptions it makes about the locations of the debug and release
binaries are now outdated.

PR-URL: node-forward/node#24
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
bnoordhuis committed Oct 16, 2014
1 parent 5ec2b3f commit edaf7af
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 134 deletions.
13 changes: 7 additions & 6 deletions test/message/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@

class MessageTestCase(test.TestCase):

def __init__(self, path, file, expected, mode, context, config):
super(MessageTestCase, self).__init__(context, path, mode)
def __init__(self, path, file, expected, arch, mode, context, config):
super(MessageTestCase, self).__init__(context, path, arch, mode)
self.file = file
self.expected = expected
self.config = config
self.arch = arch
self.mode = mode

def IgnoreLine(self, str):
Expand Down Expand Up @@ -92,7 +93,7 @@ def GetName(self):
return self.path[-1]

def GetCommand(self):
result = [self.config.context.GetVm(self.mode)]
result = [self.config.context.GetVm(self.arch, self.mode)]
source = open(self.file).read()
flags_match = FLAGS_PATTERN.search(source)
if flags_match:
Expand All @@ -117,7 +118,7 @@ def Ls(self, path):
else:
return []

def ListTests(self, current_path, path, mode):
def ListTests(self, current_path, path, arch, mode):
all_tests = [current_path + [t] for t in self.Ls(self.root)]
result = []
for test in all_tests:
Expand All @@ -128,8 +129,8 @@ def ListTests(self, current_path, path, mode):
if not exists(output_path):
print "Could not find %s" % output_path
continue
result.append(MessageTestCase(test, file_path, output_path, mode,
self.context, self))
result.append(MessageTestCase(test, file_path, output_path,
arch, mode, self.context, self))
return result

def GetBuildRequirements(self):
Expand Down
61 changes: 0 additions & 61 deletions test/simple/test-executable-path.js

This file was deleted.

15 changes: 8 additions & 7 deletions test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@

class SimpleTestCase(test.TestCase):

def __init__(self, path, file, mode, context, config, additional=[]):
super(SimpleTestCase, self).__init__(context, path, mode)
def __init__(self, path, file, arch, mode, context, config, additional=[]):
super(SimpleTestCase, self).__init__(context, path, arch, mode)
self.file = file
self.config = config
self.arch = arch
self.mode = mode
self.tmpdir = join(dirname(self.config.root), 'tmp')
self.additional_flags = additional
Expand Down Expand Up @@ -82,7 +83,7 @@ def GetName(self):
return self.path[-1]

def GetCommand(self):
result = [self.config.context.GetVm(self.mode)]
result = [self.config.context.GetVm(self.arch, self.mode)]
source = open(self.file).read()
flags_match = FLAGS_PATTERN.search(source)
if flags_match:
Expand Down Expand Up @@ -117,14 +118,14 @@ def SelectTest(name):
return name.startswith('test-') and name.endswith('.js')
return [f[:-3] for f in os.listdir(path) if SelectTest(f)]

def ListTests(self, current_path, path, mode):
def ListTests(self, current_path, path, arch, mode):
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
result = []
for test in all_tests:
if self.Contains(path, test):
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
result.append(SimpleTestCase(test, file_path, mode, self.context, self,
self.additional_flags))
result.append(SimpleTestCase(test, file_path, arch, mode, self.context,
self, self.additional_flags))
return result

def GetBuildRequirements(self):
Expand All @@ -151,7 +152,7 @@ def SelectTest(name):
result.append([subpath, f[:-3]])
return result

def ListTests(self, current_path, path, mode):
def ListTests(self, current_path, path, arch, mode):
all_tests = [current_path + t for t in self.Ls(join(self.root))]
result = []
for test in all_tests:
Expand Down
12 changes: 7 additions & 5 deletions test/timers/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@

class TimersTestCase(test.TestCase):

def __init__(self, path, file, mode, context, config):
super(TimersTestCase, self).__init__(context, path, mode)
def __init__(self, path, file, arch, mode, context, config):
super(TimersTestCase, self).__init__(context, path, arch, mode)
self.file = file
self.config = config
self.arch = arch
self.mode = mode

def GetLabel(self):
Expand All @@ -60,7 +61,7 @@ def GetCommand(self):
if faketime_flags_match:
result += shlex.split(faketime_flags_match.group(1).strip())

result += [self.config.context.GetVm(self.mode)]
result += [self.config.context.GetVm(self.arch, self.mode)]
result += [self.file]

return result
Expand All @@ -79,13 +80,14 @@ def SelectTest(name):
return name.startswith('test-') and name.endswith('.js')
return [f[:-3] for f in os.listdir(path) if SelectTest(f)]

def ListTests(self, current_path, path, mode):
def ListTests(self, current_path, path, arch, mode):
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
result = []
for test in all_tests:
if self.Contains(path, test):
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
result.append(TimersTestCase(test, file_path, mode, self.context, self))
result.append(TimersTestCase(test, file_path, arch, mode,
self.context, self))
return result

def GetBuildRequirements(self):
Expand Down
89 changes: 34 additions & 55 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,11 @@ def __init__(self, exit_code, timed_out, stdout, stderr):

class TestCase(object):

def __init__(self, context, path, mode):
def __init__(self, context, path, arch, mode):
self.path = path
self.context = context
self.duration = None
self.arch = arch
self.mode = mode

def IsNegative(self):
Expand Down Expand Up @@ -644,9 +645,10 @@ def GetConfiguration(self, context):
def GetBuildRequirements(self, path, context):
return self.GetConfiguration(context).GetBuildRequirements()

def AddTestsToList(self, result, current_path, path, context, mode):
def AddTestsToList(self, result, current_path, path, context, arch, mode):
for v in VARIANT_FLAGS:
tests = self.GetConfiguration(context).ListTests(current_path, path, mode)
tests = self.GetConfiguration(context).ListTests(current_path, path,
arch, mode)
for t in tests: t.variant_flags = v
result += tests

Expand All @@ -669,14 +671,14 @@ def GetBuildRequirements(self, path, context):
result += test.GetBuildRequirements(rest, context)
return result

def ListTests(self, current_path, path, context, mode):
def ListTests(self, current_path, path, context, arch, mode):
(name, rest) = CarCdr(path)
result = [ ]
for test in self.tests:
test_name = test.GetName()
if not name or name.match(test_name):
full_path = current_path + [test_name]
test.AddTestsToList(result, full_path, path, context, mode)
test.AddTestsToList(result, full_path, path, context, arch, mode)
result.sort(cmp=lambda a, b: cmp(a.GetName(), b.GetName()))
return result

Expand Down Expand Up @@ -708,11 +710,11 @@ def __init__(self, workspace, buildspace, verbose, vm, timeout, processor, suppr
self.suppress_dialogs = suppress_dialogs
self.store_unexpected_output = store_unexpected_output

def GetVm(self, mode):
if mode == 'debug':
name = 'out/Debug/node'
def GetVm(self, arch, mode):
if arch == 'none':
name = 'out/Debug/node' if mode == 'debug' else 'out/Release/node'
else:
name = 'out/Release/node'
name = 'out/%s.%s/node' % (arch, mode)

# Currently GYP does not support output_dir for MSVS.
# http://code.google.com/p/gyp/issues/detail?id=40
Expand All @@ -729,9 +731,6 @@ def GetVm(self, mode):

return name

def GetVmCommand(self, testcase, mode):
return [self.GetVm(mode)] + self.GetVmFlags(testcase, mode)

def GetVmFlags(self, testcase, mode):
return testcase.variant_flags + FLAGS[mode]

Expand Down Expand Up @@ -1203,8 +1202,6 @@ def BuildOptions():
default='none')
result.add_option("--snapshot", help="Run the tests with snapshot turned on",
default=False, action="store_true")
result.add_option("--simulator", help="Run tests with architecture simulator",
default='none')
result.add_option("--special-command", default=None)
result.add_option("--use-http1", help="Pass --use-http1 switch to node",
default=False, action="store_true")
Expand Down Expand Up @@ -1235,29 +1232,8 @@ def BuildOptions():
def ProcessOptions(options):
global VERBOSE
VERBOSE = options.verbose
options.arch = options.arch.split(',')
options.mode = options.mode.split(',')
for mode in options.mode:
if not mode in ['debug', 'release']:
print "Unknown mode %s" % mode
return False
if options.simulator != 'none':
# Simulator argument was set. Make sure arch and simulator agree.
if options.simulator != options.arch:
if options.arch == 'none':
options.arch = options.simulator
else:
print "Architecture %s does not match sim %s" %(options.arch, options.simulator)
return False
# Ensure that the simulator argument is handed down to scons.
options.scons_flags.append("simulator=" + options.simulator)
else:
# If options.arch is not set by the command line and no simulator setting
# was found, set the arch to the guess.
if options.arch == 'none':
options.arch = ARCH_GUESS
options.scons_flags.append("arch=" + options.arch)
if options.snapshot:
options.scons_flags.append("snapshot=on")
return True


Expand Down Expand Up @@ -1415,25 +1391,28 @@ def wrap(processor):
unclassified_tests = [ ]
globally_unused_rules = None
for path in paths:
for mode in options.mode:
if not exists(context.GetVm(mode)):
print "Can't find shell executable: '%s'" % context.GetVm(mode)
continue
env = {
'mode': mode,
'system': utils.GuessOS(),
'arch': options.arch,
'simulator': options.simulator
}
test_list = root.ListTests([], path, context, mode)
unclassified_tests += test_list
(cases, unused_rules, all_outcomes) = config.ClassifyTests(test_list, env)
if globally_unused_rules is None:
globally_unused_rules = set(unused_rules)
else:
globally_unused_rules = globally_unused_rules.intersection(unused_rules)
all_cases += cases
all_unused.append(unused_rules)
for arch in options.arch:
for mode in options.mode:
vm = context.GetVm(arch, mode)
if not exists(vm):
print "Can't find shell executable: '%s'" % vm
continue
env = {
'mode': mode,
'system': utils.GuessOS(),
'arch': arch,
}
test_list = root.ListTests([], path, context, arch, mode)
unclassified_tests += test_list
(cases, unused_rules, all_outcomes) = (
config.ClassifyTests(test_list, env))
if globally_unused_rules is None:
globally_unused_rules = set(unused_rules)
else:
globally_unused_rules = (
globally_unused_rules.intersection(unused_rules))
all_cases += cases
all_unused.append(unused_rules)

if options.cat:
visited = set()
Expand Down

0 comments on commit edaf7af

Please sign in to comment.