aboutsummaryrefslogtreecommitdiff
path: root/crosperf/benchmark_unittest.py
blob: bb23bdbb9dbbe5921ab1f7575a8a69982f386d1b (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2014 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Unit tests for the Crosperf Benchmark class."""


import inspect
import unittest

from benchmark import Benchmark


class BenchmarkTestCase(unittest.TestCase):
    """Individual tests for the Benchmark class."""

    def test_benchmark(self):
        # Test creating a benchmark with all the fields filled out.
        b1 = Benchmark(
            "b1_test",  # name
            "octane",  # test_name
            "",  # test_args
            3,  # iterations
            False,  # rm_chroot_tmp
            "record -e cycles",  # perf_args
            "telemetry_Crosperf",  # suite
            True,
        )  # show_all_results
        self.assertTrue(b1.suite, "telemetry_Crosperf")

        # Test creating a benchmark field with default fields left out.
        b2 = Benchmark(
            "b2_test",  # name
            "octane",  # test_name
            "",  # test_args
            3,  # iterations
            False,  # rm_chroot_tmp
            "record -e cycles",
        )  # perf_args
        self.assertEqual(b2.suite, "")
        self.assertFalse(b2.show_all_results)

        # Test explicitly creating 'suite=Telemetry' and 'show_all_results=False"
        # and see what happens.
        b3 = Benchmark(
            "b3_test",  # name
            "octane",  # test_name
            "",  # test_args
            3,  # iterations
            False,  # rm_chroot_tmp
            "record -e cycles",  # perf_args
            "telemetry",  # suite
            False,
        )  # show_all_results
        self.assertTrue(b3.show_all_results)

        # Check to see if the args to Benchmark have changed since the last time
        # this test was updated.
        args_list = [
            "self",
            "name",
            "test_name",
            "test_args",
            "iterations",
            "rm_chroot_tmp",
            "perf_args",
            "suite",
            "show_all_results",
            "retries",
            "run_local",
            "cwp_dso",
            "weight",
        ]
        arg_spec = inspect.getfullargspec(Benchmark.__init__)
        self.assertEqual(len(arg_spec.args), len(args_list))
        for arg in args_list:
            self.assertIn(arg, arg_spec.args)


if __name__ == "__main__":
    unittest.main()