aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/dist_test/python/benchmark_util_test.py
blob: e8a71f3153620ecf1e46736bc0ad3844dc908231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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 tensorflow.tools.dist_test.python.benchmark_util."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import datetime
import json
import os

from tensorflow.python.platform import googletest
from tensorflow.python.platform import test
from tensorflow.tools.dist_test.python import benchmark_util


class BenchmarkUtilTest(googletest.TestCase):

  def testStoreDataWithNoEntries(self):
    output_file = os.path.join(test.get_temp_dir(), 'test_output1.json')
    timing_entries = []
    benchmark_util.store_data_in_json(
        timing_entries, datetime.date(2017, 1, 1), output_file)
    json_output = json.loads(open(output_file, 'r').read())
    self.assertEquals('TestBenchmark', json_output['name'])
    self.assertEquals(u'1483228800', json_output['startTime'])

  def testStoreDataWithEntries(self):
    output_file = os.path.join(test.get_temp_dir(), 'test_output2.json')
    timing_entries = [
        benchmark_util.TimingEntry('test', 0.1, 1)]
    benchmark_util.store_data_in_json(
        timing_entries, datetime.date(2017, 1, 1), output_file)
    json_output = json.loads(open(output_file, 'r').read())

    self.assertEquals(1, len(json_output['entries']['entry']))
    self.assertEquals('test', json_output['entries']['entry'][0]['name'])
    self.assertEquals(0.1, json_output['entries']['entry'][0]['wallTime'])
    self.assertEquals(u'1', json_output['entries']['entry'][0]['iters'])
    self.assertEquals(u'1483228800', json_output['startTime'])
    self.assertEquals('TestBenchmark', json_output['name'])


if __name__ == '__main__':
  googletest.main()