1#!/usr/bin/env python3 2# Copyright 2023 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Tests for ensure_pgo_is_a_win.""" 7 8from typing import Tuple 9import unittest 10 11import benchmark_pgo_profiles 12import ensure_pgo_is_a_win 13 14 15def synthesize_run_data( 16 no_profile_user_time: float, profile_user_time: float 17) -> Tuple[benchmark_pgo_profiles.RunData, benchmark_pgo_profiles.RunData]: 18 return ( 19 benchmark_pgo_profiles.RunData( 20 tag=str(ensure_pgo_is_a_win.NO_PROFILE), 21 user_time=no_profile_user_time, 22 system_time=1, 23 ), 24 benchmark_pgo_profiles.RunData( 25 tag=str(ensure_pgo_is_a_win.DEFAULT_PROFILE), 26 user_time=profile_user_time, 27 system_time=1, 28 ), 29 ) 30 31 32class Test(unittest.TestCase): 33 """Tests for ensure_pgo_is_a_win.""" 34 35 def test_speedup_calculation_works(self): 36 no_profile, profile = synthesize_run_data( 37 no_profile_user_time=1, profile_user_time=1 38 ) 39 self.assertEqual( 40 ensure_pgo_is_a_win.calculate_pgo_speedup(no_profile, profile), 1 41 ) 42 43 no_profile, profile = synthesize_run_data( 44 no_profile_user_time=3, profile_user_time=2 45 ) 46 self.assertEqual( 47 ensure_pgo_is_a_win.calculate_pgo_speedup(no_profile, profile), 1.5 48 ) 49 50 51if __name__ == "__main__": 52 unittest.main() 53