Skip to content

Commit 7f821e5

Browse files
Merge pull request #1716 from robertbaldyga/stat-inactive-fix
tests:test_print_statistics_inactive: Purge cache after adding cores
2 parents a2b9716 + 2cad5ec commit 7f821e5

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

test/functional/tests/incremental_load/test_incremental_load.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ def test_print_statistics_inactive(cache_mode):
591591
first_core = cache.add_core(first_core_dev)
592592
second_core = cache.add_core(second_core_dev)
593593
cache_mode_traits = CacheMode.get_traits(cache.get_cache_mode())
594+
cache.purge_cache() # purge cache to zero the initial kernel reads in stats
594595

595596
with TestRun.step("Disable cleaning and sequential cutoff policies."):
596597
cache.set_cleaning_policy(CleaningPolicy.nop)
@@ -639,6 +640,28 @@ def test_print_statistics_inactive(cache_mode):
639640
f"Actual state: {first_core_status}."
640641
)
641642

643+
def check_stat_zero(stat_before, stat_after, stat_name):
644+
if stat_before == Size.zero() and stat_after == Size.zero():
645+
TestRun.LOGGER.info(f"{stat_name} value before and after equals 0 as expected.")
646+
if stat_before != Size.zero():
647+
TestRun.LOGGER.error(f"{stat_name} ({stat_before}) value before does not equal 0.")
648+
if stat_after != Size.zero():
649+
TestRun.LOGGER.error(f"{stat_name} ({stat_after}) value after does not equal 0.")
650+
651+
def check_stat_lower(stat_before, stat_after, stat_name):
652+
if stat_after < stat_before:
653+
TestRun.LOGGER.info(f"{stat_name} is lower than before as expected.")
654+
else:
655+
TestRun.LOGGER.error(
656+
f"{stat_name} ({stat_after}) is not lower than before " f"({stat_before})."
657+
)
658+
659+
def check_stat(stat_before, stat_after, stat_name, should_be_zero):
660+
if should_be_zero:
661+
check_stat_zero(stat_before, stat_after, stat_name)
662+
else:
663+
check_stat_lower(stat_before, stat_after, stat_name)
664+
642665
with TestRun.step("Check cache statistics section of inactive devices."):
643666
inactive_stats_usage = get_stats_dict([StatsFilter.usage], cache.cache_id)
644667
check_if_inactive_section_exists(inactive_stats_usage)
@@ -649,19 +672,19 @@ def test_print_statistics_inactive(cache_mode):
649672
lazy_write_traits = CacheModeTrait.LazyWrites in cache_mode_traits
650673
lazy_writes_or_no_insert_write_traits = not insert_write_traits or lazy_write_traits
651674

652-
check_usage_stats(
675+
check_stat(
653676
inactive_stats_before.usage_stats.inactive_occupancy,
654677
inactive_stats_after.usage_stats.inactive_occupancy,
655678
"inactive occupancy",
656679
not insert_write_traits,
657680
)
658-
check_usage_stats(
681+
check_stat(
659682
inactive_stats_before.usage_stats.inactive_clean,
660683
inactive_stats_after.usage_stats.inactive_clean,
661684
"inactive clean",
662685
lazy_writes_or_no_insert_write_traits,
663686
)
664-
check_usage_stats(
687+
check_stat(
665688
inactive_stats_before.usage_stats.inactive_dirty,
666689
inactive_stats_after.usage_stats.inactive_dirty,
667690
"inactive dirty",
@@ -1000,17 +1023,6 @@ def try_stop_incomplete_cache(cache):
10001023
cli_messages.check_stderr_msg(e.output, cli_messages.stop_cache_incomplete)
10011024

10021025

1003-
def check_usage_stats(stats_before, stats_after, stat_name, should_be_zero):
1004-
if should_be_zero and stats_before == Size.zero() and stats_after == Size.zero():
1005-
TestRun.LOGGER.info(f"{stat_name} value before and after equals 0 as expected.")
1006-
elif not should_be_zero and stats_after < stats_before:
1007-
TestRun.LOGGER.info(f"{stat_name} is lower than before as expected.")
1008-
else:
1009-
TestRun.LOGGER.error(
1010-
f"{stat_name} ({stats_after}) is not lower than before " f"({stats_before})."
1011-
)
1012-
1013-
10141026
def check_number_of_inactive_devices(stats: CacheStats, expected_num):
10151027
inactive_core_num = stats.config_stats.inactive_core_devices
10161028
if inactive_core_num != expected_num:

0 commit comments

Comments
 (0)