コード例 #1
0
def test_neg_set_ioclass_cache_mode(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to add ioclass with invaild cache mode
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(cache_device,
                                  cache_mode=cm,
                                  cache_line_size=cls)

    # Set invalid cache mode and check if failed
    for i in RandomGenerator(DefaultRanges.INT):
        if i in list(CacheMode) + [CACHE_MODE_NONE]:
            continue
        with pytest.raises(OcfError, match="Error adding partition to cache"):
            cache.configure_partition(part_id=1,
                                      name="unclassified",
                                      max_size=100,
                                      priority=1,
                                      cache_mode=i)
            print(f"\n{i}")
コード例 #2
0
def test_neg_set_nhit_promotion_policy_param_threshold(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to set invalid promotion policy param INSERTION_THRESHOLD for
    nhit promotion policy
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(
        cache_device,
        cache_mode=cm,
        cache_line_size=cls,
        promotion_policy=PromotionPolicy.NHIT,
    )

    # Set to invalid promotion policy insertion threshold and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in ConfValidValues.promotion_nhit_insertion_threshold_range:
            continue
        with pytest.raises(OcfError,
                           match="Error setting promotion policy parameter"):
            cache.set_promotion_policy_param(PromotionPolicy.NHIT,
                                             NhitParams.INSERTION_THRESHOLD, i)
            print(f"\n{i}")
コード例 #3
0
def test_neg_set_acp_param_value(pyocf_ctx, cm, cls, param):
    """
    Test whether it is possible to set invalid value to any of acp cleaning policy params
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :param param: acp parameter to fuzz
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(cache_device,
                                  cache_mode=cm,
                                  cache_line_size=cls)

    cache.set_cleaning_policy(CleaningPolicy.ACP)

    # Set to invalid acp param value and check if failed
    valid_range = get_acp_param_valid_rage(param)
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in valid_range:
            continue
        with pytest.raises(OcfError,
                           match="Error setting cleaning policy param"):
            cache.set_cleaning_policy_param(CleaningPolicy.ACP, param, i)
            print(f"\n{i}")
コード例 #4
0
def test_neg_set_nhit_promotion_policy_param(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to set invalid promotion policy param id for nhit promotion policy
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(
        cache_device,
        cache_mode=cm,
        cache_line_size=cls,
        promotion_policy=PromotionPolicy.NHIT,
    )

    # Set invalid promotion policy param id and check if failed
    for i in RandomGenerator(DefaultRanges.UINT8):
        if i in [item.value for item in NhitParams]:
            continue
        with pytest.raises(OcfError,
                           match="Error setting promotion policy parameter"):
            cache.set_promotion_policy_param(PromotionPolicy.NHIT, i, 1)
            print(f"\n{i}")
コード例 #5
0
def test_neg_cache_set_seq_cut_off_threshold(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to change cache seq cut-off threshold to invalid value
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # 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, name="core1")
    core_device2 = Volume(S.from_MiB(10))
    core2 = Core.using_device(core_device2, name="core2")

    # Add cores
    cache.add_core(core1)
    cache.add_core(core2)

    # Change cache seq cut off policy to invalid one and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in ConfValidValues.seq_cutoff_threshold_rage:
            continue
        with pytest.raises(
                OcfError,
                match="Error setting cache seq cut off policy threshold"):
            cache.set_seq_cut_off_threshold(i)
            print(f"\n{i}")
コード例 #6
0
def test_neg_core_set_seq_cut_off_policy(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to change core seq cut-off policy to invalid value
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # 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 core device
    core_device = Volume(S.from_MiB(10))
    core = Core.using_device(core_device)

    # Add core
    cache.add_core(core)

    # Change core seq cut off policy to invalid one and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in [item.value for item in SeqCutOffPolicy]:
            continue
        with pytest.raises(OcfError,
                           match="Error setting core seq cut off policy"):
            core.set_seq_cut_off_policy(i)
            print(f"\n{i}")
コード例 #7
0
def test_neg_change_cache_mode(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to change cache mode to invalid value.
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(cache_device, cache_mode=cm, cache_line_size=cls)

    # Change cache mode to invalid one and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in [item.value for item in CacheMode]:
            continue
        with pytest.raises(OcfError, match="Error changing cache mode"):
            cache.change_cache_mode(i)
コード例 #8
0
def test_neg_set_promotion_policy(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to set invalid param for promotion policy
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(cache_device, cache_mode=cm, cache_line_size=cls)

    # Change to invalid promotion policy and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in [item.value for item in PromotionPolicy]:
            continue
        with pytest.raises(OcfError, match="Error setting promotion policy"):
            cache.set_promotion_policy(i)
コード例 #9
0
def test_neg_set_acp_param(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to set invalid param for acp cleaning policy
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(cache_device, cache_mode=cm, cache_line_size=cls)

    # Change invalid acp param and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in [item.value for item in AcpParams]:
            continue
        with pytest.raises(OcfError, match="Error setting cleaning policy param"):
            cache.set_cleaning_policy_param(CleaningPolicy.ALRU, i, 1)
コード例 #10
0
def test_neg_attach_cls(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to change cache line size to
    invalid value while attaching cache device
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache(owner=cache_device.owner, cache_mode=cm, cache_line_size=cls)
    cache.start_cache()

    # Check whether it is possible to attach cache device with invalid cache line size
    for i in RandomGenerator(DefaultRanges.UINT64):
        if i in [item.value for item in CacheLineSize]:
            continue
        with pytest.raises(OcfError, match="Attaching cache device failed"):
            cache.attach_device(cache_device, cache_line_size=i)
コード例 #11
0
def test_neg_set_cleaning_policy(pyocf_ctx, cm, cls):
    """
    Test whether it is possible to change cleaning policy to invalid value
    :param pyocf_ctx: basic pyocf context fixture
    :param cm: cache mode we start with
    :param cls: cache line size we start with
    :return:
    """
    # Start cache device
    cache_device = Volume(S.from_MiB(30))
    cache = Cache.start_on_device(cache_device,
                                  cache_mode=cm,
                                  cache_line_size=cls)

    # Set cleaning policy to invalid one and check if failed
    for i in RandomGenerator(DefaultRanges.UINT32):
        if i in [item.value for item in CleaningPolicy]:
            continue
        with pytest.raises(OcfError, match="Error changing cleaning policy"):
            cache.set_cleaning_policy(i)
            print(f"\n{i}")
コード例 #12
0
    Test whether it is impossible to start cache with invalid metadata layout value.
    :param pyocf_ctx: basic pyocf context fixture
    :param c_uint32_randomize: metadata layout enum value to start cache with
    :param cm: cache mode value to start cache with
    :param cls: cache line size value to start cache with
    """
    with pytest.raises(OcfError, match="OCF_ERR_INVAL"):
        try_start_cache(metadata_layout=not_metadata_layout_randomize,
                        cache_mode=cm,
                        cache_line_size=cls)


@pytest.mark.security
@pytest.mark.parametrize("cls", CacheLineSize)
@pytest.mark.parametrize('max_wb_queue_size',
                         RandomGenerator(DefaultRanges.UINT32, 10))
def test_fuzzy_start_max_queue_size(pyocf_ctx, max_wb_queue_size,
                                    c_uint32_randomize, cls):
    """
    Test whether it is impossible to start cache with invalid dependence between max queue size
    and queue unblock size.
    :param pyocf_ctx: basic pyocf context fixture
    :param max_wb_queue_size: max queue size value to start cache with
    :param c_uint32_randomize: queue unblock size value to start cache with
    :param cls: cache line size value to start cache with
    """
    if c_uint32_randomize > max_wb_queue_size:
        with pytest.raises(OcfError, match="OCF_ERR_INVAL"):
            try_start_cache(max_queue_size=max_wb_queue_size,
                            queue_unblock_size=c_uint32_randomize,
                            cache_mode=CacheMode.WB,
コード例 #13
0
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))


def enum_min(enum):
    return list(enum)[0].value


def enum_max(enum):
    return list(enum)[-1].value


def enum_range(enum):
    return Range(enum_min(enum), enum_max(enum))


@pytest.fixture(params=RandomGenerator(DefaultRanges.UINT16))
def c_uint16_randomize(request):
    return request.param


@pytest.fixture(params=RandomGenerator(DefaultRanges.UINT32))
def c_uint32_randomize(request):
    return request.param


@pytest.fixture(params=RandomGenerator(DefaultRanges.UINT64))
def c_uint64_randomize(request):
    return request.param


@pytest.fixture(params=RandomGenerator(DefaultRanges.INT))