Skip to content

Commit edaf7af

Browse files
committed
test: make test runner multi-arch/mode compatible
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 <fedor@indutny.com>
1 parent 5ec2b3f commit edaf7af

File tree

5 files changed

+56
-134
lines changed

5 files changed

+56
-134
lines changed

test/message/testcfg.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434

3535
class MessageTestCase(test.TestCase):
3636

37-
def __init__(self, path, file, expected, mode, context, config):
38-
super(MessageTestCase, self).__init__(context, path, mode)
37+
def __init__(self, path, file, expected, arch, mode, context, config):
38+
super(MessageTestCase, self).__init__(context, path, arch, mode)
3939
self.file = file
4040
self.expected = expected
4141
self.config = config
42+
self.arch = arch
4243
self.mode = mode
4344

4445
def IgnoreLine(self, str):
@@ -92,7 +93,7 @@ def GetName(self):
9293
return self.path[-1]
9394

9495
def GetCommand(self):
95-
result = [self.config.context.GetVm(self.mode)]
96+
result = [self.config.context.GetVm(self.arch, self.mode)]
9697
source = open(self.file).read()
9798
flags_match = FLAGS_PATTERN.search(source)
9899
if flags_match:
@@ -117,7 +118,7 @@ def Ls(self, path):
117118
else:
118119
return []
119120

120-
def ListTests(self, current_path, path, mode):
121+
def ListTests(self, current_path, path, arch, mode):
121122
all_tests = [current_path + [t] for t in self.Ls(self.root)]
122123
result = []
123124
for test in all_tests:
@@ -128,8 +129,8 @@ def ListTests(self, current_path, path, mode):
128129
if not exists(output_path):
129130
print "Could not find %s" % output_path
130131
continue
131-
result.append(MessageTestCase(test, file_path, output_path, mode,
132-
self.context, self))
132+
result.append(MessageTestCase(test, file_path, output_path,
133+
arch, mode, self.context, self))
133134
return result
134135

135136
def GetBuildRequirements(self):

test/simple/test-executable-path.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/testpy/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141

4242
class SimpleTestCase(test.TestCase):
4343

44-
def __init__(self, path, file, mode, context, config, additional=[]):
45-
super(SimpleTestCase, self).__init__(context, path, mode)
44+
def __init__(self, path, file, arch, mode, context, config, additional=[]):
45+
super(SimpleTestCase, self).__init__(context, path, arch, mode)
4646
self.file = file
4747
self.config = config
48+
self.arch = arch
4849
self.mode = mode
4950
self.tmpdir = join(dirname(self.config.root), 'tmp')
5051
self.additional_flags = additional
@@ -82,7 +83,7 @@ def GetName(self):
8283
return self.path[-1]
8384

8485
def GetCommand(self):
85-
result = [self.config.context.GetVm(self.mode)]
86+
result = [self.config.context.GetVm(self.arch, self.mode)]
8687
source = open(self.file).read()
8788
flags_match = FLAGS_PATTERN.search(source)
8889
if flags_match:
@@ -117,14 +118,14 @@ def SelectTest(name):
117118
return name.startswith('test-') and name.endswith('.js')
118119
return [f[:-3] for f in os.listdir(path) if SelectTest(f)]
119120

120-
def ListTests(self, current_path, path, mode):
121+
def ListTests(self, current_path, path, arch, mode):
121122
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
122123
result = []
123124
for test in all_tests:
124125
if self.Contains(path, test):
125126
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
126-
result.append(SimpleTestCase(test, file_path, mode, self.context, self,
127-
self.additional_flags))
127+
result.append(SimpleTestCase(test, file_path, arch, mode, self.context,
128+
self, self.additional_flags))
128129
return result
129130

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

154-
def ListTests(self, current_path, path, mode):
155+
def ListTests(self, current_path, path, arch, mode):
155156
all_tests = [current_path + t for t in self.Ls(join(self.root))]
156157
result = []
157158
for test in all_tests:

test/timers/testcfg.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040

4141
class TimersTestCase(test.TestCase):
4242

43-
def __init__(self, path, file, mode, context, config):
44-
super(TimersTestCase, self).__init__(context, path, mode)
43+
def __init__(self, path, file, arch, mode, context, config):
44+
super(TimersTestCase, self).__init__(context, path, arch, mode)
4545
self.file = file
4646
self.config = config
47+
self.arch = arch
4748
self.mode = mode
4849

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

63-
result += [self.config.context.GetVm(self.mode)]
64+
result += [self.config.context.GetVm(self.arch, self.mode)]
6465
result += [self.file]
6566

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

82-
def ListTests(self, current_path, path, mode):
83+
def ListTests(self, current_path, path, arch, mode):
8384
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
8485
result = []
8586
for test in all_tests:
8687
if self.Contains(path, test):
8788
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
88-
result.append(TimersTestCase(test, file_path, mode, self.context, self))
89+
result.append(TimersTestCase(test, file_path, arch, mode,
90+
self.context, self))
8991
return result
9092

9193
def GetBuildRequirements(self):

tools/test.py

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,11 @@ def __init__(self, exit_code, timed_out, stdout, stderr):
368368

369369
class TestCase(object):
370370

371-
def __init__(self, context, path, mode):
371+
def __init__(self, context, path, arch, mode):
372372
self.path = path
373373
self.context = context
374374
self.duration = None
375+
self.arch = arch
375376
self.mode = mode
376377

377378
def IsNegative(self):
@@ -644,9 +645,10 @@ def GetConfiguration(self, context):
644645
def GetBuildRequirements(self, path, context):
645646
return self.GetConfiguration(context).GetBuildRequirements()
646647

647-
def AddTestsToList(self, result, current_path, path, context, mode):
648+
def AddTestsToList(self, result, current_path, path, context, arch, mode):
648649
for v in VARIANT_FLAGS:
649-
tests = self.GetConfiguration(context).ListTests(current_path, path, mode)
650+
tests = self.GetConfiguration(context).ListTests(current_path, path,
651+
arch, mode)
650652
for t in tests: t.variant_flags = v
651653
result += tests
652654

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

672-
def ListTests(self, current_path, path, context, mode):
674+
def ListTests(self, current_path, path, context, arch, mode):
673675
(name, rest) = CarCdr(path)
674676
result = [ ]
675677
for test in self.tests:
676678
test_name = test.GetName()
677679
if not name or name.match(test_name):
678680
full_path = current_path + [test_name]
679-
test.AddTestsToList(result, full_path, path, context, mode)
681+
test.AddTestsToList(result, full_path, path, context, arch, mode)
680682
result.sort(cmp=lambda a, b: cmp(a.GetName(), b.GetName()))
681683
return result
682684

@@ -708,11 +710,11 @@ def __init__(self, workspace, buildspace, verbose, vm, timeout, processor, suppr
708710
self.suppress_dialogs = suppress_dialogs
709711
self.store_unexpected_output = store_unexpected_output
710712

711-
def GetVm(self, mode):
712-
if mode == 'debug':
713-
name = 'out/Debug/node'
713+
def GetVm(self, arch, mode):
714+
if arch == 'none':
715+
name = 'out/Debug/node' if mode == 'debug' else 'out/Release/node'
714716
else:
715-
name = 'out/Release/node'
717+
name = 'out/%s.%s/node' % (arch, mode)
716718

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

730732
return name
731733

732-
def GetVmCommand(self, testcase, mode):
733-
return [self.GetVm(mode)] + self.GetVmFlags(testcase, mode)
734-
735734
def GetVmFlags(self, testcase, mode):
736735
return testcase.variant_flags + FLAGS[mode]
737736

@@ -1203,8 +1202,6 @@ def BuildOptions():
12031202
default='none')
12041203
result.add_option("--snapshot", help="Run the tests with snapshot turned on",
12051204
default=False, action="store_true")
1206-
result.add_option("--simulator", help="Run tests with architecture simulator",
1207-
default='none')
12081205
result.add_option("--special-command", default=None)
12091206
result.add_option("--use-http1", help="Pass --use-http1 switch to node",
12101207
default=False, action="store_true")
@@ -1235,29 +1232,8 @@ def BuildOptions():
12351232
def ProcessOptions(options):
12361233
global VERBOSE
12371234
VERBOSE = options.verbose
1235+
options.arch = options.arch.split(',')
12381236
options.mode = options.mode.split(',')
1239-
for mode in options.mode:
1240-
if not mode in ['debug', 'release']:
1241-
print "Unknown mode %s" % mode
1242-
return False
1243-
if options.simulator != 'none':
1244-
# Simulator argument was set. Make sure arch and simulator agree.
1245-
if options.simulator != options.arch:
1246-
if options.arch == 'none':
1247-
options.arch = options.simulator
1248-
else:
1249-
print "Architecture %s does not match sim %s" %(options.arch, options.simulator)
1250-
return False
1251-
# Ensure that the simulator argument is handed down to scons.
1252-
options.scons_flags.append("simulator=" + options.simulator)
1253-
else:
1254-
# If options.arch is not set by the command line and no simulator setting
1255-
# was found, set the arch to the guess.
1256-
if options.arch == 'none':
1257-
options.arch = ARCH_GUESS
1258-
options.scons_flags.append("arch=" + options.arch)
1259-
if options.snapshot:
1260-
options.scons_flags.append("snapshot=on")
12611237
return True
12621238

12631239

@@ -1415,25 +1391,28 @@ def wrap(processor):
14151391
unclassified_tests = [ ]
14161392
globally_unused_rules = None
14171393
for path in paths:
1418-
for mode in options.mode:
1419-
if not exists(context.GetVm(mode)):
1420-
print "Can't find shell executable: '%s'" % context.GetVm(mode)
1421-
continue
1422-
env = {
1423-
'mode': mode,
1424-
'system': utils.GuessOS(),
1425-
'arch': options.arch,
1426-
'simulator': options.simulator
1427-
}
1428-
test_list = root.ListTests([], path, context, mode)
1429-
unclassified_tests += test_list
1430-
(cases, unused_rules, all_outcomes) = config.ClassifyTests(test_list, env)
1431-
if globally_unused_rules is None:
1432-
globally_unused_rules = set(unused_rules)
1433-
else:
1434-
globally_unused_rules = globally_unused_rules.intersection(unused_rules)
1435-
all_cases += cases
1436-
all_unused.append(unused_rules)
1394+
for arch in options.arch:
1395+
for mode in options.mode:
1396+
vm = context.GetVm(arch, mode)
1397+
if not exists(vm):
1398+
print "Can't find shell executable: '%s'" % vm
1399+
continue
1400+
env = {
1401+
'mode': mode,
1402+
'system': utils.GuessOS(),
1403+
'arch': arch,
1404+
}
1405+
test_list = root.ListTests([], path, context, arch, mode)
1406+
unclassified_tests += test_list
1407+
(cases, unused_rules, all_outcomes) = (
1408+
config.ClassifyTests(test_list, env))
1409+
if globally_unused_rules is None:
1410+
globally_unused_rules = set(unused_rules)
1411+
else:
1412+
globally_unused_rules = (
1413+
globally_unused_rules.intersection(unused_rules))
1414+
all_cases += cases
1415+
all_unused.append(unused_rules)
14371416

14381417
if options.cat:
14391418
visited = set()

0 commit comments

Comments
 (0)