Disable testKerasBidirectionalRNN test case when asan/tsan is enabled.

Add pybind for sanitizer constant to know if any of the sanitizers is enabled in python tests.

PiperOrigin-RevId: 334649266
Change-Id: I4aa55310519dc2d9b121d4e6c4f33216c782092e
This commit is contained in:
Karim Nosir 2020-09-30 12:03:08 -07:00 committed by TensorFlower Gardener
parent a7f8535480
commit e8ca24d4fe
4 changed files with 69 additions and 3 deletions
tensorflow/lite

View File

@ -159,18 +159,17 @@ py_test(
name = "lite_v2_test",
srcs = ["lite_v2_test.py"],
python_version = "PY3",
shard_count = 4,
shard_count = 6,
srcs_version = "PY2AND3",
tags = [
"no_mac", # TODO(b/148247402): flatbuffers import broken on Mac OS.
"no_windows",
"noasan", # b/168812578
"notsan", # b/168812578
],
deps = [
":lite",
":lite_v2_test_util",
"//tensorflow:tensorflow_py",
"//tensorflow/lite/tools/sanitizers:_pywrap_tensorflow_lite_sanitizers",
"//tensorflow/python:client_testlib",
"//tensorflow/python:framework_test_lib",
"@six_archive//:six",

View File

@ -20,6 +20,7 @@ from __future__ import division
from __future__ import print_function
import os
import unittest
from absl.testing import parameterized
import numpy as np
@ -32,6 +33,7 @@ from tensorflow.lite.python import lite_v2_test_util
from tensorflow.lite.python.convert import mlir_quantize
from tensorflow.lite.python.interpreter import Interpreter
from tensorflow.lite.toco import types_pb2 as _types_pb2
from tensorflow.lite.tools.sanitizers import _pywrap_tensorflow_lite_sanitizers as _lite_sanitizers
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.keras.layers import recurrent
@ -1019,6 +1021,9 @@ class ControlFlowTest(lite_v2_test_util.ModelTest):
self.assertAllClose(expected_value, actual_value, atol=1e-05)
@test_util.run_v2_only
@unittest.skipIf(
_lite_sanitizers.TSan_Enabled or _lite_sanitizers.ASan_Enabled,
'Conversion is too slow with sanitizers enabled b/169431195')
def testKerasBidirectionalRNN(self):
input_data = tf.constant(
np.array(np.random.random_sample((1, 10, 10)), dtype=np.float32))

View File

@ -0,0 +1,21 @@
load("//tensorflow:tensorflow.bzl", "pybind_extension")
package(
default_visibility = [
"//visibility:public",
],
licenses = ["notice"], # Apache 2.0
)
pybind_extension(
name = "_pywrap_tensorflow_lite_sanitizers",
srcs = [
"sanitizers_pybind11.cc",
],
link_in_framework = True,
module_name = "_pywrap_tensorflow_lite_sanitizers",
deps = [
"//tensorflow/python:pybind11_lib",
"@pybind11",
],
)

View File

@ -0,0 +1,41 @@
/* Copyright 2020 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.
==============================================================================*/
#include "pybind11/pybind11.h"
#include "tensorflow/python/lib/core/pybind11_lib.h"
PYBIND11_MODULE(_pywrap_tensorflow_lite_sanitizers, m) {
m.def("TSan_Enabled", []() -> bool {
#ifdef THREAD_SANITIZER
return true;
#else
return false;
#endif
});
m.def("MSan_Enabled", []() -> bool {
#ifdef MEMORY_SANITIZER
return true;
#else
return false;
#endif
});
m.def("ASan_Enabled", []() -> bool {
#ifdef ADDRESS_SANITIZER
return true;
#else
return false;
#endif
});
}