Internal change.
PiperOrigin-RevId: 200543448
This commit is contained in:
parent
03dd231669
commit
915b1383f8
@ -51,6 +51,15 @@ py_library(
|
||||
],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "xla_test_test",
|
||||
size = "small",
|
||||
srcs = ["xla_test_test.py"],
|
||||
deps = [
|
||||
":xla_test",
|
||||
],
|
||||
)
|
||||
|
||||
tf_xla_py_test(
|
||||
name = "adagrad_test",
|
||||
size = "small",
|
||||
|
@ -49,6 +49,32 @@ flags.DEFINE_string('tf_xla_flags', None,
|
||||
'Value to set the TF_XLA_FLAGS environment variable to')
|
||||
|
||||
|
||||
def parse_disabled_manifest(manifest_content):
|
||||
comments_re = re.compile('#.*$')
|
||||
disabled_tests = []
|
||||
disabled_method_types = []
|
||||
for l in manifest_content.splitlines():
|
||||
stripped = comments_re.sub('', l).strip()
|
||||
if not stripped:
|
||||
continue
|
||||
entry = stripped.split(' ')
|
||||
if len(entry) == 1:
|
||||
disabled_tests.append(entry[0])
|
||||
elif len(entry) == 2:
|
||||
disabled_method_types.append((entry[0], entry[1].strip().split(',')))
|
||||
else:
|
||||
raise ValueError('Bad entry in manifest file.')
|
||||
|
||||
disabled_regex = '|'.join(disabled_tests)
|
||||
method_types_filter = dict()
|
||||
for method, types in disabled_method_types:
|
||||
method_types_filter[method] = set([
|
||||
dtypes.as_dtype(types_pb2.DataType.Value(name)).as_numpy_dtype
|
||||
for name in types
|
||||
])
|
||||
return disabled_regex, method_types_filter
|
||||
|
||||
|
||||
class XLATestCase(test.TestCase):
|
||||
"""XLA test cases are parameterized test cases."""
|
||||
|
||||
@ -85,38 +111,21 @@ class XLATestCase(test.TestCase):
|
||||
|
||||
# Parse the manifest file, if any, into a regex identifying tests to
|
||||
# disable
|
||||
self.disabled_regex = None
|
||||
self._method_types_filter = dict()
|
||||
# TODO(xpan): Make it text proto if it doesn't scale.
|
||||
# Each line of the manifest file specifies an entry. The entry can be
|
||||
# 1) TestNameRegex // E.g. CumprodTest.* Or
|
||||
# 2) TestName TypeName // E.g. AdamOptimizerTest.testSharing DT_BFLOAT16
|
||||
# The 1) disables the entire test. While 2) only filter some numeric types
|
||||
# so that they are not used in those tests.
|
||||
self.disabled_regex = None
|
||||
self._method_types_filter = {}
|
||||
|
||||
if FLAGS.disabled_manifest is not None:
|
||||
comments_re = re.compile('#.*$')
|
||||
manifest_file = open(FLAGS.disabled_manifest, 'r')
|
||||
disabled_tests = []
|
||||
disabled_method_types = []
|
||||
for l in manifest_file.read().splitlines():
|
||||
if not l:
|
||||
continue
|
||||
entry = comments_re.sub('', l).strip().split(' ')
|
||||
if len(entry) == 1:
|
||||
disabled_tests.append(entry[0])
|
||||
elif len(entry) == 2:
|
||||
disabled_method_types.append(
|
||||
(entry[0], entry[1].strip().split(',')))
|
||||
else:
|
||||
raise ValueError('Bad entry in manifest file.')
|
||||
|
||||
self.disabled_regex = re.compile('|'.join(disabled_tests))
|
||||
for method, types in disabled_method_types:
|
||||
self._method_types_filter[method] = set([
|
||||
dtypes.as_dtype(types_pb2.DataType.Value(name)).as_numpy_dtype
|
||||
for name in types])
|
||||
manifest_file.close()
|
||||
with open(FLAGS.disabled_manifest, 'r') as manifest_file:
|
||||
disabled_regex, self._method_types_filter = (
|
||||
parse_disabled_manifest(manifest_file.read()))
|
||||
if disabled_regex:
|
||||
self.disabled_regex = re.compile(disabled_regex)
|
||||
|
||||
if FLAGS.tf_xla_flags is not None:
|
||||
os.environ['TF_XLA_FLAGS'] = FLAGS.tf_xla_flags
|
||||
|
44
tensorflow/compiler/tests/xla_test_test.py
Normal file
44
tensorflow/compiler/tests/xla_test_test.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""Tests for the XLATestCase test fixture base class."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
from tensorflow.compiler.tests import xla_test
|
||||
from tensorflow.python.platform import test
|
||||
|
||||
|
||||
class XlaTestCaseTestCase(test.TestCase):
|
||||
|
||||
def testManifestEmptyLineDoesNotCatchAll(self):
|
||||
manifest = """
|
||||
testCaseOne
|
||||
"""
|
||||
disabled_regex, _ = xla_test.parse_disabled_manifest(manifest)
|
||||
self.assertEqual(disabled_regex, "testCaseOne")
|
||||
|
||||
def testManifestWholeLineCommentDoesNotCatchAll(self):
|
||||
manifest = """# I am a comment
|
||||
testCaseOne
|
||||
testCaseTwo
|
||||
"""
|
||||
disabled_regex, _ = xla_test.parse_disabled_manifest(manifest)
|
||||
self.assertEqual(disabled_regex, "testCaseOne|testCaseTwo")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test.main()
|
Loading…
Reference in New Issue
Block a user