Coverage for mlos_bench/mlos_bench/tests/tunables/tunable_group_update_test.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-07 01:52 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Tests for checking the is_updated flag for tunable groups.""" 

6 

7from mlos_bench.tunables.tunable_groups import TunableGroups 

8 

9_TUNABLE_VALUES = { 

10 "kernel_sched_migration_cost_ns": 8888, 

11 "kernel_sched_latency_ns": 9999, 

12} 

13 

14 

15def test_tunable_group_update(tunable_groups: TunableGroups) -> None: 

16 """Test that updating a tunable group raises the is_updated flag.""" 

17 tunable_groups.assign(_TUNABLE_VALUES) 

18 assert tunable_groups.is_updated() 

19 

20 

21def test_tunable_group_update_twice(tunable_groups: TunableGroups) -> None: 

22 """Test that updating a tunable group with the same values do *NOT* raises the 

23 is_updated flag. 

24 """ 

25 tunable_groups.assign(_TUNABLE_VALUES) 

26 assert tunable_groups.is_updated() 

27 

28 tunable_groups.reset() 

29 assert not tunable_groups.is_updated() 

30 

31 tunable_groups.assign(_TUNABLE_VALUES) 

32 assert not tunable_groups.is_updated() 

33 

34 

35def test_tunable_group_update_kernel(tunable_groups: TunableGroups) -> None: 

36 """Test that the is_updated flag is set only for the affected covariant group.""" 

37 tunable_groups.assign(_TUNABLE_VALUES) 

38 assert tunable_groups.is_updated() 

39 assert tunable_groups.is_updated(["kernel"]) 

40 assert not tunable_groups.is_updated(["boot", "provision"]) 

41 

42 

43def test_tunable_group_update_boot(tunable_groups: TunableGroups) -> None: 

44 """Test that the is_updated flag is set only for the affected covariant group.""" 

45 tunable_groups.assign(_TUNABLE_VALUES) 

46 assert tunable_groups.is_updated() 

47 assert not tunable_groups.is_updated(["boot"]) 

48 

49 tunable_groups.reset() 

50 tunable_groups["idle"] = "mwait" 

51 assert tunable_groups.is_updated() 

52 assert tunable_groups.is_updated(["boot"]) 

53 assert not tunable_groups.is_updated(["kernel"])