• 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"""Testing of ResultsOrganizer
7
8   We create some labels, benchmark_runs and then create a ResultsOrganizer,
9   after that, we compare the result of ResultOrganizer.
10"""
11
12from __future__ import print_function
13
14import unittest
15
16from benchmark_run import BenchmarkRun
17from results_cache import Result
18from results_organizer import OrganizeResults
19
20import mock_instance
21
22result = {
23    'benchmark1': [[{
24        '': 'PASS',
25        'bool': 'True',
26        'milliseconds_1': '1',
27        'milliseconds_2': '8',
28        'milliseconds_3': '9.2',
29        'ms_1': '2.1',
30        'total': '5'
31    }, {
32        '': 'PASS',
33        'test': '2'
34    }, {
35        '': 'PASS',
36        'test': '4'
37    }, {
38        '': 'PASS',
39        'bool': 'FALSE',
40        'milliseconds_1': '3',
41        'milliseconds_2': '5',
42        'ms_1': '2.2',
43        'total': '6'
44    }, {
45        '': 'PASS',
46        'test': '3'
47    }, {
48        '': 'PASS',
49        'test': '4'
50    }], [{
51        '': 'PASS',
52        'bool': 'FALSE',
53        'milliseconds_4': '30',
54        'milliseconds_5': '50',
55        'ms_1': '2.23',
56        'total': '6'
57    }, {
58        '': 'PASS',
59        'test': '5'
60    }, {
61        '': 'PASS',
62        'test': '4'
63    }, {
64        '': 'PASS',
65        'bool': 'FALSE',
66        'milliseconds_1': '3',
67        'milliseconds_6': '7',
68        'ms_1': '2.3',
69        'total': '7'
70    }, {
71        '': 'PASS',
72        'test': '2'
73    }, {
74        '': 'PASS',
75        'test': '6'
76    }]],
77    'benchmark2': [[{
78        '': 'PASS',
79        'bool': 'TRUE',
80        'milliseconds_1': '3',
81        'milliseconds_8': '6',
82        'ms_1': '2.3',
83        'total': '7'
84    }, {
85        '': 'PASS',
86        'test': '2'
87    }, {
88        '': 'PASS',
89        'test': '6'
90    }, {
91        '': 'PASS',
92        'bool': 'TRUE',
93        'milliseconds_1': '3',
94        'milliseconds_8': '6',
95        'ms_1': '2.2',
96        'total': '7'
97    }, {
98        '': 'PASS',
99        'test': '2'
100    }, {
101        '': 'PASS',
102        'test': '2'
103    }], [{
104        '': 'PASS',
105        'bool': 'TRUE',
106        'milliseconds_1': '3',
107        'milliseconds_8': '6',
108        'ms_1': '2',
109        'total': '7'
110    }, {
111        '': 'PASS',
112        'test': '2'
113    }, {
114        '': 'PASS',
115        'test': '4'
116    }, {
117        '': 'PASS',
118        'bool': 'TRUE',
119        'milliseconds_1': '3',
120        'milliseconds_8': '6',
121        'ms_1': '1',
122        'total': '7'
123    }, {
124        '': 'PASS',
125        'test': '1'
126    }, {
127        '': 'PASS',
128        'test': '6'
129    }]]
130}
131
132
133class ResultOrganizerTest(unittest.TestCase):
134  """Test result organizer."""
135
136  def testResultOrganizer(self):
137    labels = [mock_instance.label1, mock_instance.label2]
138    benchmarks = [mock_instance.benchmark1, mock_instance.benchmark2]
139    benchmark_runs = [None] * 8
140    benchmark_runs[0] = BenchmarkRun('b1', benchmarks[0], labels[0], 1, '', '',
141                                     '', 'average', '')
142    benchmark_runs[1] = BenchmarkRun('b2', benchmarks[0], labels[0], 2, '', '',
143                                     '', 'average', '')
144    benchmark_runs[2] = BenchmarkRun('b3', benchmarks[0], labels[1], 1, '', '',
145                                     '', 'average', '')
146    benchmark_runs[3] = BenchmarkRun('b4', benchmarks[0], labels[1], 2, '', '',
147                                     '', 'average', '')
148    benchmark_runs[4] = BenchmarkRun('b5', benchmarks[1], labels[0], 1, '', '',
149                                     '', 'average', '')
150    benchmark_runs[5] = BenchmarkRun('b6', benchmarks[1], labels[0], 2, '', '',
151                                     '', 'average', '')
152    benchmark_runs[6] = BenchmarkRun('b7', benchmarks[1], labels[1], 1, '', '',
153                                     '', 'average', '')
154    benchmark_runs[7] = BenchmarkRun('b8', benchmarks[1], labels[1], 2, '', '',
155                                     '', 'average', '')
156
157    i = 0
158    for b in benchmark_runs:
159      b.result = Result('', b.label, 'average', 'machine')
160      b.result.keyvals = mock_instance.keyval[i]
161      i += 1
162
163    organized = OrganizeResults(benchmark_runs, labels, benchmarks)
164    self.assertEqual(organized, result)
165
166
167if __name__ == '__main__':
168  unittest.main()
169