Added a few management tests (changing configuration after start and checking statistics)

Fixed core/cache stats pyocf API

Signed-off-by: Kamil Lepek <kamil.lepek94@gmail.com>
This commit is contained in:
Kamil Lepek
2019-05-16 10:23:17 +02:00
parent a9d07917a1
commit ecd492e562
4 changed files with 149 additions and 36 deletions

View File

@@ -1,31 +0,0 @@
#
# Copyright(c) 2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import pytest
from pyocf.types.cache import Cache, CacheMode
from pyocf.types.volume import Volume
from pyocf.utils import Size as S
from pyocf.types.shared import CacheLineSize
@pytest.mark.parametrize("from_cm", CacheMode)
@pytest.mark.parametrize("to_cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cache_mode(pyocf_ctx, from_cm, to_cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=from_cm, cache_line_size=cls
)
# Check if started with correct cache mode
stats = cache.get_stats()
assert stats["conf"]["cache_mode"] == from_cm
# Change cache mode and check if stats are as expected
cache.change_cache_mode(to_cm)
stats_after = cache.get_stats()
assert stats_after["conf"]["cache_mode"] == to_cm

View File

@@ -0,0 +1,135 @@
#
# Copyright(c) 2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import pytest
from pyocf.types.cache import Cache, CacheMode, CleaningPolicy, SeqCutOffPolicy
from pyocf.types.core import Core
from pyocf.types.volume import Volume
from pyocf.utils import Size as S
from pyocf.types.shared import CacheLineSize
@pytest.mark.parametrize("from_cm", CacheMode)
@pytest.mark.parametrize("to_cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cache_mode(pyocf_ctx, from_cm, to_cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=from_cm, cache_line_size=cls
)
# Change cache mode and check if stats are as expected
cache.change_cache_mode(to_cm)
stats_after = cache.get_stats()
assert stats_after["conf"]["cache_mode"] == to_cm
@pytest.mark.parametrize("cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cleaning_policy(pyocf_ctx, cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cm, cache_line_size=cls
)
# Check all possible cleaning policy switches
for cp_from in CleaningPolicy:
cache.set_cleaning_policy(cp_from.value)
# Check if cleaning policy is correct
stats = cache.get_stats()
assert stats["conf"]["cleaning_policy"] == cp_from.value
for cp_to in CleaningPolicy:
cache.set_cleaning_policy(cp_to.value)
# Check if cleaning policy is correct
stats = cache.get_stats()
assert stats["conf"]["cleaning_policy"] == cp_to.value
@pytest.mark.parametrize("cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_cache_change_seq_cut_off_policy(pyocf_ctx, cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cm, cache_line_size=cls
)
# Create 2 core devices
core_device1 = Volume(S.from_MiB(10))
core1 = Core.using_device(core_device1)
core_device2 = Volume(S.from_MiB(10))
core2 = Core.using_device(core_device2)
# Add cores
cache.add_core(core1)
cache.add_core(core2)
# Check all possible seq cut off policy switches
for seq_from in SeqCutOffPolicy:
cache.set_seq_cut_off_policy(seq_from.value)
# Check if seq cut off policy is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_from.value
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == seq_from.value
for seq_to in SeqCutOffPolicy:
cache.set_seq_cut_off_policy(seq_to.value)
# Check if seq cut off policy is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_to.value
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == seq_to.value
@pytest.mark.parametrize("cm", CacheMode)
@pytest.mark.parametrize("cls", CacheLineSize)
def test_core_change_seq_cut_off_policy(pyocf_ctx, cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cm, cache_line_size=cls
)
# Create 2 core devices
core_device1 = Volume(S.from_MiB(10))
core1 = Core.using_device(core_device1)
core_device2 = Volume(S.from_MiB(10))
core2 = Core.using_device(core_device2)
# Add cores
cache.add_core(core1)
cache.add_core(core2)
# Check all possible seq cut off policy switches for first core
for seq_from in SeqCutOffPolicy:
core1.set_seq_cut_off_policy(seq_from.value)
# Check if seq cut off policy of the first core is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_from.value
# Check if seq cut off policy of the second core did not change
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT
for seq_to in SeqCutOffPolicy:
core1.set_seq_cut_off_policy(seq_to.value)
# Check if seq cut off policy of the first core is correct
stats = core1.get_stats()
assert stats["seq_cutoff_policy"] == seq_to.value
# Check if seq cut off policy of the second core did not change
stats = core2.get_stats()
assert stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT