Pyocf test checking if default values are correct

Signed-off-by: Kamil Lepek <kamil.lepek94@gmail.com>
This commit is contained in:
Kamil Lepek 2019-05-22 15:54:15 +02:00
parent ecd492e562
commit 54c0e48fce
2 changed files with 48 additions and 26 deletions

View File

@ -39,13 +39,13 @@ def test_change_cleaning_policy(pyocf_ctx, cm, cls):
# Check all possible cleaning policy switches # Check all possible cleaning policy switches
for cp_from in CleaningPolicy: 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: for cp_to 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
cache.set_cleaning_policy(cp_to.value) cache.set_cleaning_policy(cp_to.value)
# Check if cleaning policy is correct # Check if cleaning policy is correct
@ -74,15 +74,15 @@ def test_cache_change_seq_cut_off_policy(pyocf_ctx, cm, cls):
# Check all possible seq cut off policy switches # Check all possible seq cut off policy switches
for seq_from in SeqCutOffPolicy: 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: for seq_to 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
cache.set_seq_cut_off_policy(seq_to.value) cache.set_seq_cut_off_policy(seq_to.value)
# Check if seq cut off policy is correct # Check if seq cut off policy is correct
@ -113,17 +113,17 @@ def test_core_change_seq_cut_off_policy(pyocf_ctx, cm, cls):
# Check all possible seq cut off policy switches for first core # Check all possible seq cut off policy switches for first core
for seq_from in SeqCutOffPolicy: 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: for seq_to 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
core1.set_seq_cut_off_policy(seq_to.value) core1.set_seq_cut_off_policy(seq_to.value)
# Check if seq cut off policy of the first core is correct # Check if seq cut off policy of the first core is correct

View File

@ -10,17 +10,39 @@ from random import randrange
import pytest import pytest
from pyocf.ocf import OcfLib from pyocf.ocf import OcfLib
from pyocf.types.cache import Cache, CacheMode, MetadataLayout, EvictionPolicy from pyocf.types.cache import Cache, CacheMode, MetadataLayout, EvictionPolicy, CleaningPolicy
from pyocf.types.core import Core from pyocf.types.core import Core
from pyocf.types.data import Data from pyocf.types.data import Data
from pyocf.types.io import IoDir from pyocf.types.io import IoDir
from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize, SeqCutOffPolicy
from pyocf.types.volume import Volume from pyocf.types.volume import Volume
from pyocf.utils import Size from pyocf.utils import Size
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def test_start_check_default(pyocf_ctx):
"""Test if default values are correct after start.
"""
cache_device = Volume(Size.from_MiB(40))
core_device = Volume(Size.from_MiB(10))
cache = Cache.start_on_device(cache_device)
core = Core.using_device(core_device)
cache.add_core(core)
# Check if values are default
stats = cache.get_stats()
assert stats["conf"]["cleaning_policy"] == CleaningPolicy.DEFAULT
assert stats["conf"]["cache_mode"] == CacheMode.DEFAULT
assert stats["conf"]["cache_line_size"] == CacheLineSize.DEFAULT
assert stats["conf"]["eviction_policy"] == EvictionPolicy.DEFAULT
core_stats = core.get_stats()
assert core_stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT
@pytest.mark.parametrize("cls", CacheLineSize) @pytest.mark.parametrize("cls", CacheLineSize)
@pytest.mark.parametrize("mode", CacheMode) @pytest.mark.parametrize("mode", CacheMode)
def test_start_write_first_and_check_mode(pyocf_ctx, mode: CacheMode, cls: CacheLineSize): def test_start_write_first_and_check_mode(pyocf_ctx, mode: CacheMode, cls: CacheLineSize):