2014-01-13 17:09:12 -08:00
|
|
|
# Copyright 2008 the V8 project authors. All rights reserved.
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
|
# met:
|
|
|
|
|
#
|
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
|
# with the distribution.
|
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
|
#
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
import test
|
|
|
|
|
import os
|
|
|
|
|
import re
|
2019-04-13 18:09:45 -04:00
|
|
|
from functools import reduce
|
2019-10-18 11:56:21 +02:00
|
|
|
from io import open
|
test: from functools import reduce in test/testpy/__init__.py
$ __make lint-py__ # When run on Python 3
```
PYTHONPATH=tools/pip python -m flake8 . \
--count --show-source --statistics --select=E901,E999,F821,F822,F823 \
--exclude=.git,deps,lib,src,tools/*_macros.py,tools/gyp,tools/inspector_protocol,tools/jinja2,tools/markupsafe,tools/pip
./test/testpy/__init__.py:119:37: F821 undefined name 'reduce'
file_path = join(self.root, reduce(join, test[1:], ""))
^
./test/testpy/__init__.py:161:37: F821 undefined name 'reduce'
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
^
2 F821 undefined name 'reduce'
2
make: *** [lint-py] Error 1
```
PR-URL: https://github.com/nodejs/node/pull/24954
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-12-11 12:38:09 +01:00
|
|
|
|
2014-01-13 17:09:12 -08:00
|
|
|
|
|
|
|
|
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
|
2019-04-13 18:09:45 -04:00
|
|
|
LS_RE = re.compile(r'^test-.*\.m?js$')
|
2025-05-11 19:54:56 +02:00
|
|
|
ENV_PATTERN = re.compile(r"//\s+Env:(.*)")
|
2025-11-04 16:34:35 +01:00
|
|
|
NODE_TEST_PATTERN = re.compile(r"('|`|\")node:test\1")
|
2014-01-13 17:09:12 -08:00
|
|
|
|
|
|
|
|
class SimpleTestCase(test.TestCase):
|
|
|
|
|
|
2015-08-26 15:22:43 +05:30
|
|
|
def __init__(self, path, file, arch, mode, context, config, additional=None):
|
2014-10-16 18:43:13 +02:00
|
|
|
super(SimpleTestCase, self).__init__(context, path, arch, mode)
|
2014-01-13 17:09:12 -08:00
|
|
|
self.file = file
|
|
|
|
|
self.config = config
|
2014-10-16 18:43:13 +02:00
|
|
|
self.arch = arch
|
2014-01-13 17:09:12 -08:00
|
|
|
self.mode = mode
|
2015-08-26 15:22:43 +05:30
|
|
|
if additional is not None:
|
|
|
|
|
self.additional_flags = additional
|
|
|
|
|
else:
|
|
|
|
|
self.additional_flags = []
|
|
|
|
|
|
2025-05-11 19:54:56 +02:00
|
|
|
def _parse_source_env(self, source):
|
|
|
|
|
env_match = ENV_PATTERN.search(source)
|
|
|
|
|
env = {}
|
|
|
|
|
if env_match:
|
|
|
|
|
for env_pair in env_match.group(1).strip().split():
|
|
|
|
|
var, value = env_pair.split('=')
|
|
|
|
|
env[var] = value
|
|
|
|
|
return env
|
2014-12-17 20:34:21 +07:00
|
|
|
|
2014-01-13 17:09:12 -08:00
|
|
|
def GetLabel(self):
|
|
|
|
|
return "%s %s" % (self.mode, self.GetName())
|
|
|
|
|
|
|
|
|
|
def GetName(self):
|
|
|
|
|
return self.path[-1]
|
|
|
|
|
|
2025-05-11 19:54:56 +02:00
|
|
|
def GetRunConfiguration(self):
|
2014-10-16 18:43:13 +02:00
|
|
|
result = [self.config.context.GetVm(self.arch, self.mode)]
|
2019-10-18 11:56:21 +02:00
|
|
|
source = open(self.file, encoding='utf8').read()
|
2014-01-13 17:09:12 -08:00
|
|
|
flags_match = FLAGS_PATTERN.search(source)
|
2025-05-11 19:54:56 +02:00
|
|
|
envs = self._parse_source_env(source)
|
2014-01-13 17:09:12 -08:00
|
|
|
if flags_match:
|
2018-11-15 05:37:55 +01:00
|
|
|
flags = flags_match.group(1).strip().split()
|
2017-03-01 08:16:48 +01:00
|
|
|
# The following block reads config.gypi to extract the v8_enable_inspector
|
|
|
|
|
# value. This is done to check if the inspector is disabled in which case
|
|
|
|
|
# the '--inspect' flag cannot be passed to the node process as it will
|
|
|
|
|
# cause node to exit and report the test as failed. The use case
|
|
|
|
|
# is currently when Node is configured --without-ssl and the tests should
|
|
|
|
|
# still be runnable but skip any tests that require ssl (which includes the
|
2017-04-18 15:16:00 +02:00
|
|
|
# inspector related tests). Also, if there is no ssl support the options
|
2025-03-06 18:16:27 +01:00
|
|
|
# '--use-bundled-ca', '--use-system-ca' and '--use-openssl-ca' will also
|
|
|
|
|
# cause a similar failure so such tests are also skipped.
|
2018-11-15 05:37:55 +01:00
|
|
|
if (any(flag.startswith('--inspect') for flag in flags) and
|
|
|
|
|
not self.context.v8_enable_inspector):
|
2018-12-13 12:10:34 +01:00
|
|
|
print(': Skipping as node was compiled without inspector support')
|
2018-11-15 05:37:55 +01:00
|
|
|
elif (('--use-bundled-ca' in flags or
|
|
|
|
|
'--use-openssl-ca' in flags or
|
2025-03-06 18:16:27 +01:00
|
|
|
'--use-system-ca' in flags or
|
|
|
|
|
'--no-use-bundled-ca' in flags or
|
|
|
|
|
'--no-use-openssl-ca' in flags or
|
|
|
|
|
'--no-use-system-ca' in flags or
|
2018-11-15 05:37:55 +01:00
|
|
|
'--tls-v1.0' in flags or
|
|
|
|
|
'--tls-v1.1' in flags) and
|
|
|
|
|
not self.context.node_has_crypto):
|
2025-03-06 18:16:27 +01:00
|
|
|
# TODO(joyeecheung): add this to the status file variables so that we can
|
|
|
|
|
# list the crypto dependency in the status files explicitly instead.
|
2018-12-13 12:10:34 +01:00
|
|
|
print(': Skipping as node was compiled without crypto support')
|
2017-03-01 08:16:48 +01:00
|
|
|
else:
|
2018-11-15 05:37:55 +01:00
|
|
|
result += flags
|
2014-01-13 17:09:12 -08:00
|
|
|
|
2025-11-04 16:34:35 +01:00
|
|
|
if self.context.use_error_reporter and NODE_TEST_PATTERN.search(source):
|
|
|
|
|
result += ['--test-reporter=./test/common/test-error-reporter.js',
|
|
|
|
|
'--test-reporter-destination=stdout']
|
|
|
|
|
|
2014-01-13 17:09:12 -08:00
|
|
|
if self.additional_flags:
|
|
|
|
|
result += self.additional_flags
|
|
|
|
|
|
|
|
|
|
result += [self.file]
|
|
|
|
|
|
2025-05-11 19:54:56 +02:00
|
|
|
return {
|
|
|
|
|
'command': result,
|
|
|
|
|
'envs': envs
|
|
|
|
|
}
|
2014-01-13 17:09:12 -08:00
|
|
|
|
|
|
|
|
def GetSource(self):
|
|
|
|
|
return open(self.file).read()
|
|
|
|
|
|
|
|
|
|
|
2018-10-03 18:50:21 -04:00
|
|
|
class SimpleTestConfiguration(test.TestConfiguration):
|
2015-08-26 15:22:43 +05:30
|
|
|
def __init__(self, context, root, section, additional=None):
|
2018-10-03 18:50:21 -04:00
|
|
|
super(SimpleTestConfiguration, self).__init__(context, root, section)
|
2015-08-26 15:22:43 +05:30
|
|
|
if additional is not None:
|
|
|
|
|
self.additional_flags = additional
|
|
|
|
|
else:
|
|
|
|
|
self.additional_flags = []
|
2014-01-13 17:09:12 -08:00
|
|
|
|
|
|
|
|
def Ls(self, path):
|
2019-04-13 18:09:45 -04:00
|
|
|
return [f for f in os.listdir(path) if LS_RE.match(f)]
|
2014-01-13 17:09:12 -08:00
|
|
|
|
2014-10-16 18:43:13 +02:00
|
|
|
def ListTests(self, current_path, path, arch, mode):
|
2019-04-13 18:09:45 -04:00
|
|
|
all_tests = [current_path + [t] for t in self.Ls(os.path.join(self.root))]
|
2014-01-13 17:09:12 -08:00
|
|
|
result = []
|
2019-04-13 18:09:45 -04:00
|
|
|
for tst in all_tests:
|
|
|
|
|
if self.Contains(path, tst):
|
|
|
|
|
file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], ""))
|
|
|
|
|
test_name = tst[:-1] + [os.path.splitext(tst[-1])[0]]
|
2017-06-05 19:44:56 -05:00
|
|
|
result.append(SimpleTestCase(test_name, file_path, arch, mode,
|
|
|
|
|
self.context, self, self.additional_flags))
|
2014-01-13 17:09:12 -08:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def GetBuildRequirements(self):
|
|
|
|
|
return ['sample', 'sample=shell']
|
|
|
|
|
|
2014-12-17 20:34:21 +07:00
|
|
|
class ParallelTestConfiguration(SimpleTestConfiguration):
|
2015-08-26 15:22:43 +05:30
|
|
|
def __init__(self, context, root, section, additional=None):
|
2014-12-17 20:34:21 +07:00
|
|
|
super(ParallelTestConfiguration, self).__init__(context, root, section,
|
|
|
|
|
additional)
|
|
|
|
|
|
|
|
|
|
def ListTests(self, current_path, path, arch, mode):
|
|
|
|
|
result = super(ParallelTestConfiguration, self).ListTests(
|
|
|
|
|
current_path, path, arch, mode)
|
2019-04-13 18:09:45 -04:00
|
|
|
for tst in result:
|
|
|
|
|
tst.parallel = True
|
2014-12-17 20:34:21 +07:00
|
|
|
return result
|
|
|
|
|
|
2014-01-18 22:49:18 +00:00
|
|
|
class AddonTestConfiguration(SimpleTestConfiguration):
|
2015-08-26 15:22:43 +05:30
|
|
|
def __init__(self, context, root, section, additional=None):
|
|
|
|
|
super(AddonTestConfiguration, self).__init__(context, root, section, additional)
|
2014-01-18 22:49:18 +00:00
|
|
|
|
|
|
|
|
def Ls(self, path):
|
|
|
|
|
def SelectTest(name):
|
|
|
|
|
return name.endswith('.js')
|
|
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
for subpath in os.listdir(path):
|
2019-04-13 18:09:45 -04:00
|
|
|
if os.path.isdir(os.path.join(path, subpath)):
|
2025-10-08 09:37:31 +02:00
|
|
|
result.extend([subpath, f[:-3]] for f in os.listdir(os.path.join(path, subpath)) if SelectTest(f))
|
2014-01-18 22:49:18 +00:00
|
|
|
return result
|
|
|
|
|
|
2014-10-16 18:43:13 +02:00
|
|
|
def ListTests(self, current_path, path, arch, mode):
|
2019-04-13 18:09:45 -04:00
|
|
|
all_tests = [current_path + t for t in self.Ls(os.path.join(self.root))]
|
2014-01-18 22:49:18 +00:00
|
|
|
result = []
|
2019-04-13 18:09:45 -04:00
|
|
|
for tst in all_tests:
|
|
|
|
|
if self.Contains(path, tst):
|
|
|
|
|
file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "") + ".js")
|
test: fix `make test-addons` target
I broke the python script in commit edaf7af but because test-all does
not run test-addons, it slipped under the radar. Mea culpa.
Fixes the following test runner error:
Traceback (most recent call last):
File "tools/test.py", line 1522, in <module>
sys.exit(Main())
File "tools/test.py", line 1454, in Main
test_list = root.ListTests([], path, context, arch, mode)
File "tools/test.py", line 720, in ListTests
test.AddTestsToList(result, full_path, path, context, arch, mode)
File "tools/test.py", line 690, in AddTestsToList
arch, mode)
File "/home/bnoordhuis/src/v1.x/test/gc/../testpy/__init__.py", line 176, in ListTests
result.append(SimpleTestCase(test, file_path, mode, self.context, self))
TypeError: __init__() takes at least 7 arguments (6 given)
PR-URL: https://github.com/iojs/io.js/pull/313
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-01-12 23:10:34 +01:00
|
|
|
result.append(
|
2019-04-13 18:09:45 -04:00
|
|
|
SimpleTestCase(tst, file_path, arch, mode, self.context, self, self.additional_flags))
|
2014-01-18 22:49:18 +00:00
|
|
|
return result
|
2016-11-22 13:13:44 -03:00
|
|
|
|
2017-06-30 13:14:04 -07:00
|
|
|
class AbortTestConfiguration(SimpleTestConfiguration):
|
|
|
|
|
def __init__(self, context, root, section, additional=None):
|
|
|
|
|
super(AbortTestConfiguration, self).__init__(context, root, section,
|
|
|
|
|
additional)
|
|
|
|
|
|
|
|
|
|
def ListTests(self, current_path, path, arch, mode):
|
|
|
|
|
result = super(AbortTestConfiguration, self).ListTests(
|
|
|
|
|
current_path, path, arch, mode)
|
2019-04-13 18:09:45 -04:00
|
|
|
for tst in result:
|
|
|
|
|
tst.disable_core_files = True
|
2017-06-30 13:14:04 -07:00
|
|
|
return result
|
2024-04-19 21:35:20 +02:00
|
|
|
|
|
|
|
|
class WasmAllocationTestConfiguration(SimpleTestConfiguration):
|
|
|
|
|
def __init__(self, context, root, section, additional=None):
|
|
|
|
|
super(WasmAllocationTestConfiguration, self).__init__(context, root, section,
|
|
|
|
|
additional)
|
|
|
|
|
|
|
|
|
|
def ListTests(self, current_path, path, arch, mode):
|
|
|
|
|
result = super(WasmAllocationTestConfiguration, self).ListTests(
|
|
|
|
|
current_path, path, arch, mode)
|
|
|
|
|
for tst in result:
|
|
|
|
|
tst.max_virtual_memory = 5 * 1024 * 1024 * 1024 # 5GB
|
|
|
|
|
return result
|