xref: /aosp_15_r20/external/toolchain-utils/crosperf/benchmark_unittest.py (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright 2014 The ChromiumOS Authors
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
10
11import inspect
12import unittest
13
14from benchmark import Benchmark
15
16
17class BenchmarkTestCase(unittest.TestCase):
18    """Individual tests for the Benchmark class."""
19
20    def test_benchmark(self):
21        # Test creating a benchmark with all the fields filled out.
22        b1 = Benchmark(
23            "b1_test",  # name
24            "octane",  # test_name
25            "",  # test_args
26            3,  # iterations
27            False,  # rm_chroot_tmp
28            "record -e cycles",  # perf_args
29            "telemetry_Crosperf",  # suite
30            True,
31        )  # 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",
42        )  # perf_args
43        self.assertEqual(b2.suite, "")
44        self.assertFalse(b2.show_all_results)
45
46        # Test explicitly creating 'suite=Telemetry' and 'show_all_results=False"
47        # and see what happens.
48        b3 = Benchmark(
49            "b3_test",  # name
50            "octane",  # test_name
51            "",  # test_args
52            3,  # iterations
53            False,  # rm_chroot_tmp
54            "record -e cycles",  # perf_args
55            "telemetry",  # suite
56            False,
57        )  # show_all_results
58        self.assertTrue(b3.show_all_results)
59
60        # Check to see if the args to Benchmark have changed since the last time
61        # this test was updated.
62        args_list = [
63            "self",
64            "name",
65            "test_name",
66            "test_args",
67            "iterations",
68            "rm_chroot_tmp",
69            "perf_args",
70            "suite",
71            "show_all_results",
72            "retries",
73            "run_local",
74            "cwp_dso",
75            "weight",
76        ]
77        arg_spec = inspect.getfullargspec(Benchmark.__init__)
78        self.assertEqual(len(arg_spec.args), len(args_list))
79        for arg in args_list:
80            self.assertIn(arg, arg_spec.args)
81
82
83if __name__ == "__main__":
84    unittest.main()
85