aboutsummaryrefslogtreecommitdiff
path: root/pgo_tools/benchmark_pgo_profiles_test.py
blob: 7e71c78c8779886533d1724c4acbfce2f71c11e7 (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
#!/usr/bin/env python3
# Copyright 2023 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests for benchmark_pgo_profiles."""

import io
import json
import unittest

import benchmark_pgo_profiles


class Test(unittest.TestCase):
    """Tests for benchmark_pgo_profiles."""

    def test_run_data_parsing_succeeds(self):
        run_data = benchmark_pgo_profiles.RunData.from_json(
            "foo",
            io.StringIO(
                json.dumps(
                    {
                        "results": [
                            {
                                "user": 1.2,
                                "system": 1.3,
                            },
                        ],
                    }
                )
            ),
        )

        self.assertEqual(
            run_data,
            benchmark_pgo_profiles.RunData(
                tag="foo",
                user_time=1.2,
                system_time=1.3,
            ),
        )

    def test_special_profile_parsing_succeeds(self):
        for profile in benchmark_pgo_profiles.SpecialProfile:
            self.assertIs(
                profile, benchmark_pgo_profiles.parse_profile_path(str(profile))
            )


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