• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
2
3# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Testing of ResultsOrganizer
8
9   We create some labels, benchmark_runs and then create a ResultsOrganizer,
10   after that, we compare the result of ResultOrganizer.
11   """
12
13from __future__ import print_function
14
15import unittest
16
17from benchmark_run import BenchmarkRun
18from results_cache import Result
19from results_organizer import OrganizeResults
20
21import mock_instance
22
23result = {'benchmark1': [[{'': 'PASS',
24                           'bool': 'True',
25                           'milliseconds_1': '1',
26                           'milliseconds_2': '8',
27                           'milliseconds_3': '9.2',
28                           'ms_1': '2.1',
29                           'total': '5'}, {'test': '2'}, {'test': '4'},
30                          {'': 'PASS',
31                           'bool': 'FALSE',
32                           'milliseconds_1': '3',
33                           'milliseconds_2': '5',
34                           'ms_1': '2.2',
35                           'total': '6'}, {'test': '3'}, {'test': '4'}],
36                         [{'': 'PASS',
37                           'bool': 'FALSE',
38                           'milliseconds_4': '30',
39                           'milliseconds_5': '50',
40                           'ms_1': '2.23',
41                           'total': '6'}, {'test': '5'}, {'test': '4'},
42                          {'': 'PASS',
43                           'bool': 'FALSE',
44                           'milliseconds_1': '3',
45                           'milliseconds_6': '7',
46                           'ms_1': '2.3',
47                           'total': '7'}, {'test': '2'}, {'test': '6'}]],
48          'benchmark2': [[{'': 'PASS',
49                           'bool': 'TRUE',
50                           'milliseconds_1': '3',
51                           'milliseconds_8': '6',
52                           'ms_1': '2.3',
53                           'total': '7'}, {'test': '2'}, {'test': '6'},
54                          {'': 'PASS',
55                           'bool': 'TRUE',
56                           'milliseconds_1': '3',
57                           'milliseconds_8': '6',
58                           'ms_1': '2.2',
59                           'total': '7'}, {'test': '2'}, {'test': '2'}],
60                         [{'': 'PASS',
61                           'bool': 'TRUE',
62                           'milliseconds_1': '3',
63                           'milliseconds_8': '6',
64                           'ms_1': '2',
65                           'total': '7'}, {'test': '2'}, {'test': '4'},
66                          {'': 'PASS',
67                           'bool': 'TRUE',
68                           'milliseconds_1': '3',
69                           'milliseconds_8': '6',
70                           'ms_1': '1',
71                           'total': '7'}, {'test': '1'}, {'test': '6'}]]}
72
73
74class ResultOrganizerTest(unittest.TestCase):
75  """Test result organizer."""
76
77  def testResultOrganizer(self):
78    labels = [mock_instance.label1, mock_instance.label2]
79    benchmarks = [mock_instance.benchmark1, mock_instance.benchmark2]
80    benchmark_runs = [None] * 8
81    benchmark_runs[0] = BenchmarkRun('b1', benchmarks[0], labels[0], 1, '', '',
82                                     '', 'average', '')
83    benchmark_runs[1] = BenchmarkRun('b2', benchmarks[0], labels[0], 2, '', '',
84                                     '', 'average', '')
85    benchmark_runs[2] = BenchmarkRun('b3', benchmarks[0], labels[1], 1, '', '',
86                                     '', 'average', '')
87    benchmark_runs[3] = BenchmarkRun('b4', benchmarks[0], labels[1], 2, '', '',
88                                     '', 'average', '')
89    benchmark_runs[4] = BenchmarkRun('b5', benchmarks[1], labels[0], 1, '', '',
90                                     '', 'average', '')
91    benchmark_runs[5] = BenchmarkRun('b6', benchmarks[1], labels[0], 2, '', '',
92                                     '', 'average', '')
93    benchmark_runs[6] = BenchmarkRun('b7', benchmarks[1], labels[1], 1, '', '',
94                                     '', 'average', '')
95    benchmark_runs[7] = BenchmarkRun('b8', benchmarks[1], labels[1], 2, '', '',
96                                     '', 'average', '')
97
98    i = 0
99    for b in benchmark_runs:
100      b.result = Result('', b.label, 'average', 'machine')
101      b.result.keyvals = mock_instance.keyval[i]
102      i += 1
103
104    organized = OrganizeResults(benchmark_runs, labels, benchmarks)
105    self.assertEqual(organized, result)
106
107
108if __name__ == '__main__':
109  unittest.main()
110