• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Tests for the SWIG-wrapped device lib."""
16
17from tensorflow.core.protobuf import config_pb2
18from tensorflow.python.client import device_lib
19from tensorflow.python.framework import test_util
20from tensorflow.python.platform import googletest
21from tensorflow.python.platform import test
22
23
24class DeviceLibTest(test_util.TensorFlowTestCase):
25
26  def testListLocalDevices(self):
27    devices = device_lib.list_local_devices()
28    self.assertGreater(len(devices), 0)
29    self.assertEqual(devices[0].device_type, "CPU")
30
31    devices = device_lib.list_local_devices(config_pb2.ConfigProto())
32    self.assertGreater(len(devices), 0)
33    self.assertEqual(devices[0].device_type, "CPU")
34
35    # GPU test
36    if test.is_gpu_available():
37      self.assertGreater(len(devices), 1)
38      self.assertIn("GPU", [d.device_type for d in devices])
39
40
41if __name__ == "__main__":
42  googletest.main()
43