1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load(
16    "//pw_build:pigweed.bzl",
17    "pw_cc_library",
18    "pw_cc_test",
19)
20
21package(default_visibility = ["//visibility:public"])
22
23licenses(["notice"])  # Apache License 2.0
24
25pw_cc_library(
26    name = "pw_kvs",
27    srcs = [
28        "alignment.cc",
29        "checksum.cc",
30        "entry.cc",
31        "entry_cache.cc",
32        "flash_memory.cc",
33        "format.cc",
34        "key_value_store.cc",
35        "public/pw_kvs/internal/entry.h",
36        "public/pw_kvs/internal/entry_cache.h",
37        "public/pw_kvs/internal/hash.h",
38        "public/pw_kvs/internal/key_descriptor.h",
39        "public/pw_kvs/internal/sectors.h",
40        "public/pw_kvs/internal/span_traits.h",
41        "pw_kvs_private/config.h",
42        "sectors.cc",
43    ],
44    hdrs = [
45        "public/pw_kvs/alignment.h",
46        "public/pw_kvs/checksum.h",
47        "public/pw_kvs/crc16_checksum.h",
48        "public/pw_kvs/flash_memory.h",
49        "public/pw_kvs/format.h",
50        "public/pw_kvs/io.h",
51        "public/pw_kvs/key.h",
52        "public/pw_kvs/key_value_store.h",
53    ],
54    includes = ["public"],
55    deps = [
56        "//pw_assert",
57        "//pw_checksum",
58        "//pw_containers",
59        "//pw_log",
60        "//pw_log:facade",
61        "//pw_span",
62        "//pw_status",
63    ],
64)
65
66pw_cc_library(
67    name = "crc16",
68    hdrs = [
69        "public/pw_kvs/crc16_checksum.h",
70    ],
71    deps = [
72        ":pw_kvs",
73        "//pw_checksum",
74        "//pw_span",
75    ],
76)
77
78pw_cc_library(
79    name = "fake_flash",
80    srcs = [
81        "fake_flash_memory.cc",
82    ],
83    hdrs = [
84        "public/pw_kvs/fake_flash_memory.h",
85    ],
86    deps = [
87        ":pw_kvs",
88        "//pw_containers",
89        "//pw_log",
90        "//pw_log:facade",
91        "//pw_span",
92        "//pw_status",
93    ],
94)
95
96pw_cc_library(
97    name = "fake_flash_small_partition",
98    srcs = [
99        "fake_flash_test_partition.cc",
100    ],
101    hdrs = [
102        "public/pw_kvs/flash_test_partition.h",
103    ],
104    deps = [
105        ":fake_flash",
106        ":pw_kvs",
107    ],
108)
109
110pw_cc_library(
111    name = "fake_flash_64_aligned_partition",
112    srcs = [
113        "fake_flash_test_partition.cc",
114    ],
115    hdrs = [
116        "public/pw_kvs/flash_test_partition.h",
117    ],
118    defines = ["PW_FLASH_TEST_ALIGNMENT=64"],
119    deps = [
120        ":fake_flash",
121        ":pw_kvs",
122    ],
123)
124
125pw_cc_library(
126    name = "fake_flash_256_aligned_partition",
127    srcs = [
128        "fake_flash_test_partition.cc",
129    ],
130    hdrs = [
131        "public/pw_kvs/flash_test_partition.h",
132    ],
133    defines = ["PW_FLASH_TEST_ALIGNMENT=256"],
134    deps = [
135        ":fake_flash",
136        ":pw_kvs",
137    ],
138)
139
140pw_cc_library(
141    name = "fake_flash_test_key_value_store",
142    srcs = [
143        "fake_flash_test_key_value_store.cc",
144    ],
145    hdrs = [
146        "public/pw_kvs/test_key_value_store.h",
147    ],
148    deps = [
149        ":crc16",
150        ":fake_flash",
151        ":pw_kvs",
152    ],
153)
154
155pw_cc_library(
156    name = "test_utils",
157    hdrs = [
158        "pw_kvs_private/byte_utils.h",
159    ],
160    includes = ["public"],
161    visibility = ["//visibility:private"],
162)
163
164pw_cc_library(
165    name = "test_partition",
166    srcs = [
167        "flash_partition_with_stats.cc",
168    ],
169    hdrs = [
170        "public/pw_kvs/flash_partition_with_stats.h",
171    ],
172    includes = ["public"],
173    visibility = ["//visibility:private"],
174    deps = [
175        "//pw_containers",
176        "//pw_kvs",
177        "//pw_log",
178        "//pw_log:facade",
179        "//pw_status",
180    ],
181)
182
183pw_cc_test(
184    name = "alignment_test",
185    srcs = [
186        "alignment_test.cc",
187    ],
188    deps = [
189        ":pw_kvs",
190        "//pw_status",
191        "//pw_unit_test",
192    ],
193)
194
195pw_cc_test(
196    name = "checksum_test",
197    srcs = ["checksum_test.cc"],
198    deps = [
199        ":crc16",
200        ":pw_kvs",
201        "//pw_checksum",
202        "//pw_log",
203        "//pw_unit_test",
204    ],
205)
206
207pw_cc_test(
208    name = "converts_to_span_test",
209    srcs = ["converts_to_span_test.cc"],
210    deps = [":pw_kvs"],
211)
212
213pw_cc_test(
214    name = "entry_test",
215    srcs = [
216        "entry_test.cc",
217    ],
218    deps = [
219        ":pw_kvs",
220        ":test_utils",
221        "//pw_log:backend",
222        "//pw_span",
223        "//pw_unit_test",
224    ],
225)
226
227pw_cc_test(
228    name = "entry_cache_test",
229    srcs = ["entry_cache_test.cc"],
230    deps = [
231        ":pw_kvs",
232        ":test_utils",
233        "//pw_log:backend",
234        "//pw_unit_test",
235    ],
236)
237
238pw_cc_test(
239    name = "flash_partition_small_test",
240    srcs = ["flash_partition_test.cc"],
241    defines = ["PW_FLASH_TEST_ITERATIONS=100"],
242    deps = [
243        ":fake_flash_small_partition",
244        ":pw_kvs",
245        "//pw_log:backend",
246        "//pw_unit_test",
247    ],
248)
249
250pw_cc_test(
251    name = "flash_partition_64_alignment_test",
252    srcs = ["flash_partition_test.cc"],
253    defines = ["PW_FLASH_TEST_ITERATIONS=100"],
254    deps = [
255        ":fake_flash_64_aligned_partition",
256        ":pw_kvs",
257        "//pw_log:backend",
258        "//pw_unit_test",
259    ],
260)
261
262pw_cc_test(
263    name = "flash_partition_256_alignment_test",
264    srcs = ["flash_partition_test.cc"],
265    defines = ["PW_FLASH_TEST_ITERATIONS=100"],
266    deps = [
267        ":fake_flash_256_aligned_partition",
268        ":pw_kvs",
269        "//pw_log:backend",
270        "//pw_unit_test",
271    ],
272)
273
274pw_cc_test(
275    name = "key_test",
276    srcs = [
277        "key_test.cc",
278    ],
279    deps = [
280        ":pw_kvs",
281        "//pw_status",
282        "//pw_unit_test",
283    ],
284)
285
286pw_cc_test(
287    name = "key_value_store_test",
288    srcs = ["key_value_store_test.cc"],
289    deps = [
290        ":crc16",
291        ":pw_kvs",
292        ":test_utils",
293        "//pw_checksum",
294        "//pw_log:backend",
295        "//pw_log:facade",
296        "//pw_span",
297        "//pw_status",
298        "//pw_string",
299        "//pw_unit_test",
300    ],
301)
302
303pw_cc_test(
304    name = "key_value_store_small_flash_test",
305    srcs = ["key_value_store_initialized_test.cc"],
306    deps = [
307        ":crc16",
308        ":fake_flash_small_partition",
309        ":pw_kvs",
310        ":test_utils",
311        "//pw_checksum",
312        "//pw_log:backend",
313        "//pw_log:facade",
314        "//pw_span",
315        "//pw_status",
316        "//pw_string",
317        "//pw_unit_test",
318    ],
319)
320
321pw_cc_test(
322    name = "key_value_store_64_alignment_flash_test",
323    srcs = ["key_value_store_initialized_test.cc"],
324    deps = [
325        ":crc16",
326        ":fake_flash_64_aligned_partition",
327        ":pw_kvs",
328        ":test_utils",
329        "//pw_checksum",
330        "//pw_log:backend",
331        "//pw_log:facade",
332        "//pw_span",
333        "//pw_status",
334        "//pw_string",
335        "//pw_unit_test",
336    ],
337)
338
339pw_cc_test(
340    name = "key_value_store_256_alignment_flash_test",
341    srcs = ["key_value_store_initialized_test.cc"],
342    deps = [
343        ":crc16",
344        ":fake_flash_256_aligned_partition",
345        ":pw_kvs",
346        ":test_utils",
347        "//pw_checksum",
348        "//pw_log:backend",
349        "//pw_log:facade",
350        "//pw_span",
351        "//pw_status",
352        "//pw_string",
353        "//pw_unit_test",
354    ],
355)
356
357pw_cc_test(
358    name = "fake_flash_test_key_value_store_test",
359    srcs = ["test_key_value_store_test.cc"],
360    deps = [
361        ":crc16",
362        ":fake_flash_test_key_value_store",
363        ":pw_kvs",
364        "//pw_log:backend",
365        "//pw_status",
366        "//pw_unit_test",
367    ],
368)
369
370pw_cc_test(
371    name = "key_value_store_binary_format_test",
372    srcs = [
373        "key_value_store_binary_format_test.cc",
374    ],
375    deps = [
376        ":crc16",
377        ":pw_kvs",
378        ":test_utils",
379        "//pw_log:backend",
380        "//pw_unit_test",
381    ],
382)
383
384pw_cc_test(
385    name = "key_value_store_fuzz_test",
386    srcs = ["key_value_store_fuzz_test.cc"],
387    deps = [
388        ":crc16",
389        ":pw_kvs",
390        ":test_partition",
391        ":test_utils",
392        "//pw_checksum",
393        "//pw_log:backend",
394        "//pw_unit_test",
395    ],
396)
397
398pw_cc_test(
399    name = "key_value_store_map_test",
400    srcs = ["key_value_store_map_test.cc"],
401    deps = [
402        ":crc16",
403        ":pw_kvs",
404        ":test_partition",
405        ":test_utils",
406        "//pw_checksum",
407        "//pw_log:backend",
408        "//pw_log:facade",
409        "//pw_span",
410        "//pw_unit_test",
411    ],
412)
413
414pw_cc_test(
415    name = "sectors_test",
416    srcs = ["sectors_test.cc"],
417    deps = [
418        ":pw_kvs",
419        ":test_utils",
420        "//pw_log:backend",
421        "//pw_unit_test",
422    ],
423)
424
425pw_cc_test(
426    name = "key_value_store_wear_test",
427    srcs = [
428        "key_value_store_wear_test.cc",
429    ],
430    deps = [
431        ":pw_kvs",
432        ":test_partition",
433        ":test_utils",
434        "//pw_log:backend",
435        "//pw_unit_test",
436    ],
437)
438