]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | # |
2 | # Copyright(c) 2019 Intel Corporation | |
3 | # SPDX-License-Identifier: BSD-3-Clause-Clear | |
4 | # | |
5 | ||
9f95a23c | 6 | import logging |
f67539c2 TL |
7 | |
8 | import pytest | |
9 | ||
10 | from pyocf.types.cache import Cache, CacheMode, EvictionPolicy, MetadataLayout, PromotionPolicy | |
11 | from pyocf.types.shared import OcfError, CacheLineSize | |
9f95a23c TL |
12 | from pyocf.types.volume import Volume |
13 | from pyocf.utils import Size | |
f67539c2 | 14 | from tests.utils.random import RandomGenerator, DefaultRanges, Range |
9f95a23c TL |
15 | |
16 | logger = logging.getLogger(__name__) | |
17 | ||
18 | ||
19 | def try_start_cache(**config): | |
20 | cache_device = Volume(Size.from_MiB(30)) | |
21 | cache = Cache.start_on_device(cache_device, **config) | |
22 | cache.stop() | |
23 | ||
9f95a23c TL |
24 | @pytest.mark.security |
25 | @pytest.mark.parametrize("cls", CacheLineSize) | |
f67539c2 | 26 | def test_fuzzy_start_cache_mode(pyocf_ctx, cls, not_cache_mode_randomize): |
9f95a23c TL |
27 | """ |
28 | Test whether it is impossible to start cache with invalid cache mode value. | |
29 | :param pyocf_ctx: basic pyocf context fixture | |
30 | :param cls: cache line size value to start cache with | |
31 | :param c_uint32_randomize: cache mode enum value to start cache with | |
32 | """ | |
f67539c2 TL |
33 | with pytest.raises(OcfError, match="OCF_ERR_INVALID_CACHE_MODE"): |
34 | try_start_cache(cache_mode=not_cache_mode_randomize, cache_line_size=cls) | |
9f95a23c TL |
35 | |
36 | ||
37 | @pytest.mark.security | |
38 | @pytest.mark.parametrize("cm", CacheMode) | |
f67539c2 | 39 | def test_fuzzy_start_cache_line_size(pyocf_ctx, not_cache_line_size_randomize, cm): |
9f95a23c TL |
40 | """ |
41 | Test whether it is impossible to start cache with invalid cache line size value. | |
42 | :param pyocf_ctx: basic pyocf context fixture | |
43 | :param c_uint64_randomize: cache line size enum value to start cache with | |
44 | :param cm: cache mode value to start cache with | |
45 | """ | |
f67539c2 TL |
46 | with pytest.raises(OcfError, match="OCF_ERR_INVALID_CACHE_LINE_SIZE"): |
47 | try_start_cache(cache_mode=cm, cache_line_size=not_cache_line_size_randomize) | |
9f95a23c TL |
48 | |
49 | ||
50 | @pytest.mark.security | |
51 | @pytest.mark.parametrize("cm", CacheMode) | |
52 | @pytest.mark.parametrize("cls", CacheLineSize) | |
53 | def test_fuzzy_start_name(pyocf_ctx, string_randomize, cm, cls): | |
54 | """ | |
55 | Test whether it is possible to start cache with various cache name value. | |
56 | :param pyocf_ctx: basic pyocf context fixture | |
57 | :param string_randomize: fuzzed cache name value to start cache with | |
58 | :param cm: cache mode value to start cache with | |
59 | :param cls: cache line size value to start cache with | |
60 | """ | |
61 | cache_device = Volume(Size.from_MiB(30)) | |
f67539c2 | 62 | incorrect_values = [''] |
9f95a23c | 63 | try: |
f67539c2 TL |
64 | cache = Cache.start_on_device(cache_device, name=string_randomize, cache_mode=cm, |
65 | cache_line_size=cls) | |
66 | except OcfError: | |
67 | if string_randomize not in incorrect_values: | |
68 | logger.error( | |
69 | f"Cache did not start properly with correct name value: '{string_randomize}'") | |
70 | return | |
71 | if string_randomize in incorrect_values: | |
72 | logger.error(f"Cache started with incorrect name value: '{string_randomize}'") | |
9f95a23c TL |
73 | cache.stop() |
74 | ||
75 | ||
76 | @pytest.mark.security | |
77 | @pytest.mark.parametrize("cm", CacheMode) | |
78 | @pytest.mark.parametrize("cls", CacheLineSize) | |
f67539c2 | 79 | def test_fuzzy_start_eviction_policy(pyocf_ctx, not_eviction_policy_randomize, cm, cls): |
9f95a23c TL |
80 | """ |
81 | Test whether it is impossible to start cache with invalid eviction policy value. | |
82 | :param pyocf_ctx: basic pyocf context fixture | |
83 | :param c_uint32_randomize: eviction policy enum value to start cache with | |
84 | :param cm: cache mode value to start cache with | |
85 | :param cls: cache line size value to start cache with | |
86 | """ | |
f67539c2 TL |
87 | with pytest.raises(OcfError, match="OCF_ERR_INVAL"): |
88 | try_start_cache( | |
89 | eviction_policy=not_eviction_policy_randomize, | |
90 | cache_mode=cm, | |
91 | cache_line_size=cls | |
92 | ) | |
9f95a23c TL |
93 | |
94 | ||
95 | @pytest.mark.security | |
96 | @pytest.mark.parametrize("cm", CacheMode) | |
97 | @pytest.mark.parametrize("cls", CacheLineSize) | |
f67539c2 | 98 | def test_fuzzy_start_metadata_layout(pyocf_ctx, not_metadata_layout_randomize, cm, cls): |
9f95a23c TL |
99 | """ |
100 | Test whether it is impossible to start cache with invalid metadata layout value. | |
101 | :param pyocf_ctx: basic pyocf context fixture | |
102 | :param c_uint32_randomize: metadata layout enum value to start cache with | |
103 | :param cm: cache mode value to start cache with | |
104 | :param cls: cache line size value to start cache with | |
105 | """ | |
f67539c2 TL |
106 | with pytest.raises(OcfError, match="OCF_ERR_INVAL"): |
107 | try_start_cache( | |
108 | metadata_layout=not_metadata_layout_randomize, | |
109 | cache_mode=cm, | |
110 | cache_line_size=cls | |
111 | ) | |
9f95a23c TL |
112 | |
113 | ||
114 | @pytest.mark.security | |
115 | @pytest.mark.parametrize("cls", CacheLineSize) | |
f67539c2 | 116 | @pytest.mark.parametrize('max_wb_queue_size', RandomGenerator(DefaultRanges.UINT32, 10)) |
9f95a23c TL |
117 | def test_fuzzy_start_max_queue_size(pyocf_ctx, max_wb_queue_size, c_uint32_randomize, cls): |
118 | """ | |
f67539c2 TL |
119 | Test whether it is impossible to start cache with invalid dependence between max queue size |
120 | and queue unblock size. | |
9f95a23c TL |
121 | :param pyocf_ctx: basic pyocf context fixture |
122 | :param max_wb_queue_size: max queue size value to start cache with | |
123 | :param c_uint32_randomize: queue unblock size value to start cache with | |
124 | :param cls: cache line size value to start cache with | |
125 | """ | |
f67539c2 | 126 | if c_uint32_randomize > max_wb_queue_size: |
9f95a23c TL |
127 | with pytest.raises(OcfError, match="OCF_ERR_INVAL"): |
128 | try_start_cache( | |
129 | max_queue_size=max_wb_queue_size, | |
130 | queue_unblock_size=c_uint32_randomize, | |
131 | cache_mode=CacheMode.WB, | |
132 | cache_line_size=cls) | |
133 | else: | |
134 | logger.warning(f"Test skipped for valid values: " | |
f67539c2 TL |
135 | f"'max_queue_size={max_wb_queue_size}, " |
136 | f"queue_unblock_size={c_uint32_randomize}'.") | |
137 | ||
138 | ||
139 | @pytest.mark.security | |
140 | @pytest.mark.parametrize("cm", CacheMode) | |
141 | @pytest.mark.parametrize("cls", CacheLineSize) | |
142 | def test_fuzzy_start_promotion_policy(pyocf_ctx, not_promotion_policy_randomize, cm, cls): | |
143 | """ | |
144 | Test whether it is impossible to start cache with invalid promotion policy | |
145 | :param pyocf_ctx: basic pyocf context fixture | |
146 | :param c_uint32_randomize: promotion policy to start with | |
147 | :param cm: cache mode value to start cache with | |
148 | :param cls: cache line size to start cache with | |
149 | """ | |
150 | with pytest.raises(OcfError, match="OCF_ERR_INVAL"): | |
151 | try_start_cache( | |
152 | cache_mode=cm, | |
153 | cache_line_size=cls, | |
154 | promotion_policy=not_promotion_policy_randomize | |
155 | ) |