• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright 2014 The Chromium OS Authors. All rights reserved.
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""Unit tests for the Crosperf Benchmark class."""
9
10from __future__ import print_function
11
12import inspect
13import unittest
14
15from benchmark import Benchmark
16
17
18class BenchmarkTestCase(unittest.TestCase):
19  """Individual tests for the Benchmark class."""
20
21  def test_benchmark(self):
22    # Test creating a benchmark with all the fields filled out.
23    b1 = Benchmark(
24        'b1_test',  # name
25        'octane',  # test_name
26        '',  # test_args
27        3,  # iterations
28        False,  # rm_chroot_tmp
29        'record -e cycles',  # perf_args
30        'telemetry_Crosperf',  # suite
31        True)  # show_all_results
32    self.assertTrue(b1.suite, 'telemetry_Crosperf')
33
34    # Test creating a benchmark field with default fields left out.
35    b2 = Benchmark(
36        'b2_test',  # name
37        'octane',  # test_name
38        '',  # test_args
39        3,  # iterations
40        False,  # rm_chroot_tmp
41        'record -e cycles')  # perf_args
42    self.assertEqual(b2.suite, '')
43    self.assertFalse(b2.show_all_results)
44
45    # Test explicitly creating 'suite=Telemetry' and 'show_all_results=False"
46    # and see what happens.
47    b3 = Benchmark(
48        'b3_test',  # name
49        'octane',  # test_name
50        '',  # test_args
51        3,  # iterations
52        False,  # rm_chroot_tmp
53        'record -e cycles',  # perf_args
54        'telemetry',  # suite
55        False)  # show_all_results
56    self.assertTrue(b3.show_all_results)
57
58    # Check to see if the args to Benchmark have changed since the last time
59    # this test was updated.
60    args_list = [
61        'self', 'name', 'test_name', 'test_args', 'iterations', 'rm_chroot_tmp',
62        'perf_args', 'suite', 'show_all_results', 'retries', 'run_local',
63        'cwp_dso', 'weight'
64    ]
65    arg_spec = inspect.getfullargspec(Benchmark.__init__)
66    self.assertEqual(len(arg_spec.args), len(args_list))
67    for arg in args_list:
68      self.assertIn(arg, arg_spec.args)
69
70
71if __name__ == '__main__':
72  unittest.main()
73