xref: /aosp_15_r20/external/webrtc/tools_webrtc/perf/process_perf_results_test.py (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1#!/usr/bin/env vpython3
2
3# Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
4#
5# Use of this source code is governed by a BSD-style license
6# that can be found in the LICENSE file in the root of the source
7# tree. An additional intellectual property rights grant can be found
8# in the file PATENTS.  All contributing project authors may
9# be found in the AUTHORS file in the root of the source tree.
10
11import os
12import sys
13
14import unittest
15from unittest import mock
16
17_SCRIPT_DIR = os.path.dirname(__file__)
18_SRC_DIR = os.path.normpath(os.path.join(_SCRIPT_DIR, '..', '..'))
19
20sys.path.insert(0, os.path.join(_SRC_DIR, 'third_party', 'protobuf', 'python'))
21import process_perf_results
22
23
24class ProcessPerfResultsTest(unittest.TestCase):
25  def testConfigurePythonPath(self):
26    # pylint: disable=protected-access
27    self.assertEqual(
28        0,
29        process_perf_results._ConfigurePythonPath(
30            os.path.join(_SRC_DIR, 'out/Default')))
31
32  def testUploadToDasboard(self):
33    outdir = os.path.join(_SRC_DIR, 'out/Default')
34    args = mock.Mock(
35        build_properties='{' + '"outdir":"' + outdir + '", ' +
36        '"perf_dashboard_machine_group":"mock_machine_group", ' +
37        '"bot":"mock_bot", ' + '"webrtc_git_hash":"mock_webrtc_git_hash", ' +
38        '"commit_position":"123456", ' +
39        '"build_page_url":"mock_build_page_url", ' +
40        '"dashboard_url":"mock_dashboard_url"' + '}',
41        summary_json='mock_sumary_json',
42        task_output_dir='mock_task_output_dir',
43        test_suite='mock_test_suite',
44    )
45    perftest_output = mock.Mock(
46        absolute=lambda: 'dummy_path/perftest-output.pb',
47        is_file=lambda: True,
48    )
49    with mock.patch('pathlib.Path.rglob') as mocked_rglob:
50      with mock.patch('catapult_uploader.UploadToDashboard') as mocked_upload:
51        mocked_rglob.return_value = [perftest_output]
52        mocked_upload.return_value = 0
53        # pylint: disable=protected-access
54        self.assertEqual(0, process_perf_results._UploadToDasboard(args))
55
56        import catapult_uploader
57        mocked_upload.assert_called_once_with(
58            catapult_uploader.UploaderOptions(
59                perf_dashboard_machine_group='mock_machine_group',
60                bot='mock_bot',
61                test_suite='mock_test_suite',
62                webrtc_git_hash='mock_webrtc_git_hash',
63                commit_position='123456',
64                build_page_url='mock_build_page_url',
65                dashboard_url='mock_dashboard_url',
66                input_results_file=perftest_output.absolute()))
67
68
69if (__name__) == '__main__':
70  unittest.main()
71