]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/tests/functional/tests/security/test_management_fuzzy.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / ocf / tests / functional / tests / security / test_management_fuzzy.py
1 #
2 # Copyright(c) 2019 Intel Corporation
3 # SPDX-License-Identifier: BSD-3-Clause-Clear
4 #
5
6 import pytest
7
8 from pyocf.types.cache import Cache, CacheMode, CleaningPolicy, AlruParams, AcpParams
9 from pyocf.types.core import Core
10 from pyocf.types.volume import Volume
11 from pyocf.utils import Size as S
12 from tests.utils import generate_random_numbers
13 from pyocf.types.shared import OcfError, CacheLineSize, SeqCutOffPolicy
14 from ctypes import (
15 c_uint64,
16 c_uint32
17 )
18
19
20 @pytest.mark.parametrize("cm", CacheMode)
21 @pytest.mark.parametrize("cls", CacheLineSize)
22 @pytest.mark.security
23 def test_neg_change_cache_mode(pyocf_ctx, cm, cls):
24 """
25 Test whether it is possible to change cache mode to invalid value.
26 :param pyocf_ctx: basic pyocf context fixture
27 :param cm: cache mode we start with
28 :param cls: cache line size we start with
29 """
30 # Start cache device
31 cache_device = Volume(S.from_MiB(30))
32 cache = Cache.start_on_device(
33 cache_device, cache_mode=cm, cache_line_size=cls
34 )
35
36 # Change cache mode to invalid one and check if failed
37 for i in generate_random_numbers(c_uint32):
38 if i in [item.value for item in CacheMode]:
39 continue
40 with pytest.raises(OcfError, match="Error changing cache mode"):
41 cache.change_cache_mode(i)
42
43
44 @pytest.mark.parametrize("cm", CacheMode)
45 @pytest.mark.parametrize("cls", CacheLineSize)
46 @pytest.mark.security
47 def test_neg_set_cleaning_policy(pyocf_ctx, cm, cls):
48 """
49 Test whether it is possible to change cleaning policy to invalid value
50 :param pyocf_ctx: basic pyocf context fixture
51 :param cm: cache mode we start with
52 :param cls: cache line size we start with
53 :return:
54 """
55 # Start cache device
56 cache_device = Volume(S.from_MiB(30))
57 cache = Cache.start_on_device(
58 cache_device, cache_mode=cm, cache_line_size=cls
59 )
60
61 # Set cleaning policy to invalid one and check if failed
62 for i in generate_random_numbers(c_uint32):
63 if i in [item.value for item in CleaningPolicy]:
64 continue
65 with pytest.raises(OcfError, match="Error changing cleaning policy"):
66 cache.set_cleaning_policy(i)
67
68
69 @pytest.mark.parametrize("cm", CacheMode)
70 @pytest.mark.parametrize("cls", CacheLineSize)
71 @pytest.mark.security
72 def test_neg_attach_cls(pyocf_ctx, cm, cls):
73 """
74 Test whether it is possible to change cache line size to
75 invalid value while attaching cache device
76 :param pyocf_ctx: basic pyocf context fixture
77 :param cm: cache mode we start with
78 :param cls: cache line size we start with
79 :return:
80 """
81 # Start cache device
82 cache_device = Volume(S.from_MiB(30))
83 cache = Cache(owner=cache_device.owner, cache_mode=cm, cache_line_size=cls)
84 cache.start_cache()
85
86 # Check whether it is possible to attach cache device with invalid cache line size
87 for i in generate_random_numbers(c_uint64):
88 if i in [item.value for item in CacheLineSize]:
89 continue
90 with pytest.raises(OcfError, match="Attaching cache device failed"):
91 cache.attach_device(cache_device, cache_line_size=i)
92
93
94 @pytest.mark.parametrize("cm", CacheMode)
95 @pytest.mark.parametrize("cls", CacheLineSize)
96 @pytest.mark.security
97 def test_neg_cache_set_seq_cut_off_policy(pyocf_ctx, cm, cls):
98 """
99 Test whether it is possible to change cache seq cut-off policy to invalid value
100 :param pyocf_ctx: basic pyocf context fixture
101 :param cm: cache mode we start with
102 :param cls: cache line size we start with
103 :return:
104 """
105 # Start cache device
106 cache_device = Volume(S.from_MiB(30))
107 cache = Cache.start_on_device(
108 cache_device, cache_mode=cm, cache_line_size=cls
109 )
110
111 # Create 2 core devices
112 core_device1 = Volume(S.from_MiB(10))
113 core1 = Core.using_device(core_device1)
114 core_device2 = Volume(S.from_MiB(10))
115 core2 = Core.using_device(core_device2)
116
117 # Add cores
118 cache.add_core(core1)
119 cache.add_core(core2)
120
121 # Change cache seq cut off policy to invalid one and check if failed
122 for i in generate_random_numbers(c_uint32):
123 if i in [item.value for item in SeqCutOffPolicy]:
124 continue
125 with pytest.raises(OcfError, match="Error setting cache seq cut off policy"):
126 cache.set_seq_cut_off_policy(i)
127
128
129 @pytest.mark.parametrize("cm", CacheMode)
130 @pytest.mark.parametrize("cls", CacheLineSize)
131 @pytest.mark.security
132 def test_neg_core_set_seq_cut_off_policy(pyocf_ctx, cm, cls):
133 """
134 Test whether it is possible to change core seq cut-off policy to invalid value
135 :param pyocf_ctx: basic pyocf context fixture
136 :param cm: cache mode we start with
137 :param cls: cache line size we start with
138 :return:
139 """
140 # Start cache device
141 cache_device = Volume(S.from_MiB(30))
142 cache = Cache.start_on_device(
143 cache_device, cache_mode=cm, cache_line_size=cls
144 )
145
146 # Create core device
147 core_device = Volume(S.from_MiB(10))
148 core = Core.using_device(core_device)
149
150 # Add core
151 cache.add_core(core)
152
153 # Change core seq cut off policy to invalid one and check if failed
154 for i in generate_random_numbers(c_uint32):
155 if i in [item.value for item in SeqCutOffPolicy]:
156 continue
157 with pytest.raises(OcfError, match="Error setting core seq cut off policy"):
158 core.set_seq_cut_off_policy(i)
159
160
161 @pytest.mark.parametrize("cm", CacheMode)
162 @pytest.mark.parametrize("cls", CacheLineSize)
163 @pytest.mark.security
164 def test_neg_set_alru_param(pyocf_ctx, cm, cls):
165 """
166 Test whether it is possible to set invalid param for alru cleaning policy
167 :param pyocf_ctx: basic pyocf context fixture
168 :param cm: cache mode we start with
169 :param cls: cache line size we start with
170 :return:
171 """
172 # Start cache device
173 cache_device = Volume(S.from_MiB(30))
174 cache = Cache.start_on_device(
175 cache_device, cache_mode=cm, cache_line_size=cls
176 )
177
178 # Change invalid alru param and check if failed
179 for i in generate_random_numbers(c_uint32):
180 if i in [item.value for item in AlruParams]:
181 continue
182 with pytest.raises(OcfError, match="Error setting cleaning policy param"):
183 cache.set_cleaning_policy_param(CleaningPolicy.ALRU, i, 1)
184
185
186 @pytest.mark.parametrize("cm", CacheMode)
187 @pytest.mark.parametrize("cls", CacheLineSize)
188 @pytest.mark.security
189 def test_neg_set_acp_param(pyocf_ctx, cm, cls):
190 """
191 Test whether it is possible to set invalid param for acp cleaning policy
192 :param pyocf_ctx: basic pyocf context fixture
193 :param cm: cache mode we start with
194 :param cls: cache line size we start with
195 :return:
196 """
197 # Start cache device
198 cache_device = Volume(S.from_MiB(30))
199 cache = Cache.start_on_device(
200 cache_device, cache_mode=cm, cache_line_size=cls
201 )
202
203 # Change invalid acp param and check if failed
204 for i in generate_random_numbers(c_uint32):
205 if i in [item.value for item in AcpParams]:
206 continue
207 with pytest.raises(OcfError, match="Error setting cleaning policy param"):
208 cache.set_cleaning_policy_param(CleaningPolicy.ALRU, i, 1)