diff options
author | 2016-12-29 22:46:24 -0800 | |
---|---|---|
committer | 2016-12-29 23:06:59 -0800 | |
commit | e121667dc609de978a223c56ee906368d2c4ceef (patch) | |
tree | 7d4e1f1e1b4fd469487872c0cd34ddace5ac570c /tensorflow/tools/test | |
parent | 7815fcba7767aa1eb3196c5861e174f8b3c43bab (diff) |
Remove so many more hourglass imports
Change: 143230429
Diffstat (limited to 'tensorflow/tools/test')
-rw-r--r-- | tensorflow/tools/test/BUILD | 9 | ||||
-rw-r--r-- | tensorflow/tools/test/gpu_info_lib.py | 20 | ||||
-rw-r--r-- | tensorflow/tools/test/run_and_gather_logs.py | 57 | ||||
-rw-r--r-- | tensorflow/tools/test/run_and_gather_logs_lib.py | 39 | ||||
-rw-r--r-- | tensorflow/tools/test/system_info.py | 6 | ||||
-rw-r--r-- | tensorflow/tools/test/system_info_lib.py | 13 |
6 files changed, 66 insertions, 78 deletions
diff --git a/tensorflow/tools/test/BUILD b/tensorflow/tools/test/BUILD index cb2644c670..9b04d62385 100644 --- a/tensorflow/tools/test/BUILD +++ b/tensorflow/tools/test/BUILD @@ -21,9 +21,9 @@ py_library( ], srcs_version = "PY2AND3", deps = [ - "//tensorflow:tensorflow_py", "//tensorflow/python:client", "//tensorflow/python:errors", + "//tensorflow/python:platform", ], ) @@ -33,7 +33,7 @@ py_binary( srcs_version = "PY2AND3", deps = [ ":system_info_lib", - "//tensorflow:tensorflow_py", + "//tensorflow/python:platform", ], ) @@ -45,7 +45,7 @@ py_library( srcs_version = "PY2AND3", deps = [ ":system_info_lib", - "//tensorflow:tensorflow_py", + "//tensorflow/python:platform", ], ) @@ -55,7 +55,8 @@ py_binary( srcs_version = "PY2AND3", deps = [ ":run_and_gather_logs_lib", - "//tensorflow:tensorflow_py", + "//tensorflow/python:client_testlib", + "//tensorflow/python:platform", ], ) diff --git a/tensorflow/tools/test/gpu_info_lib.py b/tensorflow/tools/test/gpu_info_lib.py index f29ff9af24..3a4ff4fdff 100644 --- a/tensorflow/tools/test/gpu_info_lib.py +++ b/tensorflow/tools/test/gpu_info_lib.py @@ -12,34 +12,29 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== - """Library for getting system information during TensorFlow tests.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function - import ctypes as ct import platform -import tensorflow as tf - from tensorflow.core.util import test_log_pb2 from tensorflow.python.framework import errors +from tensorflow.python.platform import gfile def _gather_gpu_devices_proc(): """Try to gather NVidia GPU device information via /proc/driver.""" dev_info = [] - for f in tf.gfile.Glob("/proc/driver/nvidia/gpus/*/information"): + for f in gfile.Glob("/proc/driver/nvidia/gpus/*/information"): bus_id = f.split("/")[5] - key_values = dict( - line.rstrip().replace("\t", "").split(":", 1) - for line in tf.gfile.GFile(f, "r")) - key_values = dict( - (k.lower(), v.strip(" ").rstrip(" ")) - for (k, v) in key_values.items()) + key_values = dict(line.rstrip().replace("\t", "").split(":", 1) + for line in gfile.GFile(f, "r")) + key_values = dict((k.lower(), v.strip(" ").rstrip(" ")) + for (k, v) in key_values.items()) info = test_log_pb2.GPUInfo() info.model = key_values.get("model", "Unknown") info.uuid = key_values.get("gpu uuid", "Unknown") @@ -116,7 +111,8 @@ class CUDADeviceProperties(ct.Structure): ("multiGpuBoardGroupID", ct.c_int), # Pad with extra space to avoid dereference crashes if future # versions of CUDA extend the size of this struct. - ("__future_buffer", ct.c_char * 4096)] + ("__future_buffer", ct.c_char * 4096) + ] def _gather_gpu_devices_cudart(): diff --git a/tensorflow/tools/test/run_and_gather_logs.py b/tensorflow/tools/test/run_and_gather_logs.py index a72dac0abb..9ec62dd1fc 100644 --- a/tensorflow/tools/test/run_and_gather_logs.py +++ b/tensorflow/tools/test/run_and_gather_logs.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== - """Test runner for TensorFlow tests.""" from __future__ import absolute_import @@ -23,7 +22,14 @@ import os import shlex import sys -import tensorflow as tf +from google.protobuf import text_format +from tensorflow.core.util import test_log_pb2 +from tensorflow.python.platform import app +from tensorflow.python.platform import flags +from tensorflow.python.platform import gfile +from tensorflow.python.platform import test +from tensorflow.python.platform import tf_logging +from tensorflow.tools.test import run_and_gather_logs_lib # pylint: disable=g-import-not-at-top # pylint: disable=g-bad-import-order @@ -34,32 +40,23 @@ try: import cpuinfo import psutil except ImportError as e: - tf.logging.error("\n\n\nERROR: Unable to import necessary library: {}. " + tf_logging.error("\n\n\nERROR: Unable to import necessary library: {}. " "Issuing a soft exit.\n\n\n".format(e)) sys.exit(0) # pylint: enable=g-bad-import-order # pylint: enable=unused-import -from google.protobuf import text_format -from tensorflow.core.util import test_log_pb2 -from tensorflow.tools.test import run_and_gather_logs_lib - - -FLAGS = tf.app.flags.FLAGS +FLAGS = flags.FLAGS -tf.app.flags.DEFINE_string("name", "", """Benchmark target identifier.""") -tf.app.flags.DEFINE_string("test_name", "", """Test target to run.""") -tf.app.flags.DEFINE_string( - "test_args", "", """Test arguments, space separated.""") -tf.app.flags.DEFINE_string( - "test_log_output", "", """Filename to write logs.""") -tf.app.flags.DEFINE_bool( - "test_log_output_use_tmpdir", False, - """Store the log output into tmpdir?.""") -tf.app.flags.DEFINE_string( - "compilation_mode", "", """Mode used during this build (e.g. opt, dbg).""") -tf.app.flags.DEFINE_string( - "cc_flags", "", """CC flags used during this build.""") +flags.DEFINE_string("name", "", """Benchmark target identifier.""") +flags.DEFINE_string("test_name", "", """Test target to run.""") +flags.DEFINE_string("test_args", "", """Test arguments, space separated.""") +flags.DEFINE_string("test_log_output", "", """Filename to write logs.""") +flags.DEFINE_bool("test_log_output_use_tmpdir", False, + """Store the log output into tmpdir?.""") +flags.DEFINE_string("compilation_mode", "", + """Mode used during this build (e.g. opt, dbg).""") +flags.DEFINE_string("cc_flags", "", """CC flags used during this build.""") def gather_build_configuration(): @@ -67,8 +64,8 @@ def gather_build_configuration(): build_config.mode = FLAGS.compilation_mode # Include all flags except includes cc_flags = [ - flag for flag in shlex.split(FLAGS.cc_flags) - if not flag.startswith("-i")] + flag for flag in shlex.split(FLAGS.cc_flags) if not flag.startswith("-i") + ] build_config.cc_flags.extend(cc_flags) return build_config @@ -77,8 +74,8 @@ def main(unused_args): name = FLAGS.name test_name = FLAGS.test_name test_args = FLAGS.test_args - test_results, _ = run_and_gather_logs_lib.run_and_gather_logs( - name, test_name, test_args) + test_results, _ = run_and_gather_logs_lib.run_and_gather_logs(name, test_name, + test_args) # Additional bits we receive from bazel test_results.build_configuration.CopyFrom(gather_build_configuration()) @@ -90,13 +87,13 @@ def main(unused_args): return if FLAGS.test_log_output_use_tmpdir: - tmpdir = tf.test.get_temp_dir() + tmpdir = test.get_temp_dir() output_path = os.path.join(tmpdir, FLAGS.test_log_output) else: output_path = os.path.abspath(FLAGS.test_log_output) - tf.gfile.GFile(output_path, "w").write(serialized_test_results) - tf.logging.info("Test results written to: %s" % output_path) + gfile.GFile(output_path, "w").write(serialized_test_results) + tf_logging.info("Test results written to: %s" % output_path) if __name__ == "__main__": - tf.app.run() + app.run() diff --git a/tensorflow/tools/test/run_and_gather_logs_lib.py b/tensorflow/tools/test/run_and_gather_logs_lib.py index f787eea1ef..0d78cd9da9 100644 --- a/tensorflow/tools/test/run_and_gather_logs_lib.py +++ b/tensorflow/tools/test/run_and_gather_logs_lib.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== - """Library for getting system information during TensorFlow tests.""" from __future__ import absolute_import @@ -25,9 +24,8 @@ import subprocess import tempfile import time -import tensorflow as tf - from tensorflow.core.util import test_log_pb2 +from tensorflow.python.platform import gfile from tensorflow.tools.test import system_info_lib @@ -44,8 +42,8 @@ def get_git_commit_sha(): return os.getenv("GIT_COMMIT") -def process_test_logs( - name, test_name, test_args, start_time, run_time, log_files): +def process_test_logs(name, test_name, test_args, start_time, run_time, + log_files): """Gather test information and put it in a TestResults proto. Args: @@ -82,7 +80,7 @@ def process_test_logs( def process_benchmarks(log_files): benchmarks = test_log_pb2.BenchmarkEntries() for f in log_files: - content = tf.gfile.GFile(f, "rb").read() + content = gfile.GFile(f, "rb").read() if benchmarks.MergeFromString(content) != len(content): raise Exception("Failed parsing benchmark entry from %s" % f) return benchmarks @@ -106,18 +104,14 @@ def run_and_gather_logs(name, test_name, test_args): subprocess.CalledProcessError: If the target itself fails. IOError: If there are problems gathering test log output from the test. """ - if not (test_name - and test_name.startswith("//") - and ".." not in test_name - and not test_name.endswith(":") - and not test_name.endswith(":all") - and not test_name.endswith("...") - and len(test_name.split(":")) == 2): + if not (test_name and test_name.startswith("//") and ".." not in test_name and + not test_name.endswith(":") and not test_name.endswith(":all") and + not test_name.endswith("...") and len(test_name.split(":")) == 2): raise ValueError("Expected test_name parameter with a unique test, e.g.: " "--test_name=//path/to:test") test_executable = test_name.rstrip().strip("/").replace(":", "/") - if tf.gfile.Exists(os.path.join("bazel-bin", test_executable)): + if gfile.Exists(os.path.join("bazel-bin", test_executable)): # Running in standalone mode from core of the repository test_executable = os.path.join("bazel-bin", test_executable) else: @@ -130,7 +124,7 @@ def run_and_gather_logs(name, test_name, test_args): test_file_prefix = "%s." % test_file_prefix try: - if not tf.gfile.Exists(test_executable): + if not gfile.Exists(test_executable): raise ValueError("Executable does not exist: %s" % test_executable) test_args = shlex.split(test_args) @@ -140,15 +134,18 @@ def run_and_gather_logs(name, test_name, test_args): start_time = time.time() subprocess.check_call([test_executable] + test_args) run_time = time.time() - start_time - log_files = tf.gfile.Glob("{}*".format(test_file_prefix)) + log_files = gfile.Glob("{}*".format(test_file_prefix)) - return (process_test_logs(name, test_name, test_args, - start_time=int(start_time), - run_time=run_time, log_files=log_files), - mangled_test_name) + return (process_test_logs( + name, + test_name, + test_args, + start_time=int(start_time), + run_time=run_time, + log_files=log_files), mangled_test_name) finally: try: - tf.gfile.DeleteRecursively(temp_directory) + gfile.DeleteRecursively(temp_directory) except OSError: pass diff --git a/tensorflow/tools/test/system_info.py b/tensorflow/tools/test/system_info.py index 9678971d57..0980b713da 100644 --- a/tensorflow/tools/test/system_info.py +++ b/tensorflow/tools/test/system_info.py @@ -12,15 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== - """Library for getting system information during TensorFlow tests.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function -import tensorflow as tf - +from tensorflow.python.platform import app from tensorflow.tools.test import system_info_lib @@ -30,4 +28,4 @@ def main(unused_args): if __name__ == "__main__": - tf.app.run() + app.run() diff --git a/tensorflow/tools/test/system_info_lib.py b/tensorflow/tools/test/system_info_lib.py index 0ef108faea..69d71b3a6f 100644 --- a/tensorflow/tools/test/system_info_lib.py +++ b/tensorflow/tools/test/system_info_lib.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== - """Library for getting system information during TensorFlow tests.""" from __future__ import absolute_import @@ -24,8 +23,6 @@ import platform import re import socket -import tensorflow as tf - # pylint: disable=g-bad-import-order # Note: cpuinfo and psutil are not installed for you in the TensorFlow # OSS tree. They are installable via pip. @@ -36,6 +33,7 @@ import psutil from tensorflow.core.util import test_log_pb2 from tensorflow.python.client import device_lib from tensorflow.python.framework import errors +from tensorflow.python.platform import gfile from tensorflow.tools.test import gpu_info_lib @@ -81,7 +79,7 @@ def gather_cpu_info(): # Gather num_cores_allowed try: - with tf.gfile.GFile('/proc/self/status') as fh: + with gfile.GFile('/proc/self/status') as fh: nc = re.search(r'(?m)^Cpus_allowed:\s*(.*)$', fh.read()) if nc: # e.g. 'ff' => 8, 'fff' => 12 cpu_info.num_cores_allowed = ( @@ -105,9 +103,10 @@ def gather_cpu_info(): # Try to get the CPU governor try: cpu_governors = set([ - tf.gfile.GFile(f, 'r').readline().rstrip() - for f in tf.gfile.Glob( - '/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor')]) + gfile.GFile(f, 'r').readline().rstrip() + for f in gfile.Glob( + '/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor') + ]) if cpu_governors: if len(cpu_governors) > 1: cpu_info.cpu_governor = 'mixed' |