• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_bloat/bloat.gni")
18import("$dir_pw_build/module_config.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_toolchain/generate_toolchain.gni")
22import("$dir_pw_unit_test/test.gni")
23
24declare_args() {
25  # The build target that overrides the default configuration options for this
26  # module. This should point to a source set that provides defines through a
27  # public config (which may -include a file or add defines directly).
28  pw_kvs_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
29}
30
31config("public_include_path") {
32  include_dirs = [ "public" ]
33  visibility = [ ":*" ]
34}
35
36pw_source_set("pw_kvs") {
37  public_configs = [ ":public_include_path" ]
38  public = [
39    "public/pw_kvs/alignment.h",
40    "public/pw_kvs/checksum.h",
41    "public/pw_kvs/flash_memory.h",
42    "public/pw_kvs/flash_test_partition.h",
43    "public/pw_kvs/format.h",
44    "public/pw_kvs/io.h",
45    "public/pw_kvs/key.h",
46    "public/pw_kvs/key_value_store.h",
47  ]
48  sources = [
49    "alignment.cc",
50    "checksum.cc",
51    "entry.cc",
52    "entry_cache.cc",
53    "flash_memory.cc",
54    "format.cc",
55    "key_value_store.cc",
56    "public/pw_kvs/internal/entry.h",
57    "public/pw_kvs/internal/entry_cache.h",
58    "public/pw_kvs/internal/hash.h",
59    "public/pw_kvs/internal/key_descriptor.h",
60    "public/pw_kvs/internal/sectors.h",
61    "public/pw_kvs/internal/span_traits.h",
62    "sectors.cc",
63  ]
64  public_deps = [
65    "$dir_pw_bytes:alignment",
66    dir_pw_assert,
67    dir_pw_bytes,
68    dir_pw_containers,
69    dir_pw_span,
70    dir_pw_status,
71    dir_pw_stream,
72  ]
73  deps = [
74    ":config",
75    dir_pw_checksum,
76    dir_pw_log,
77  ]
78  friend = [ ":*" ]
79}
80
81pw_source_set("config") {
82  public_deps = [ pw_kvs_CONFIG ]
83  public = [ "pw_kvs_private/config.h" ]
84  visibility = [ ":*" ]
85}
86
87pw_source_set("crc16") {
88  public = [ "public/pw_kvs/crc16_checksum.h" ]
89  public_deps = [
90    ":pw_kvs",
91    dir_pw_checksum,
92    dir_pw_span,
93  ]
94}
95
96pw_source_set("flash_test_partition") {
97  public = [ "public/pw_kvs/flash_test_partition.h" ]
98  public_deps = [ ":pw_kvs" ]
99}
100
101pw_source_set("test_key_value_store") {
102  public = [ "public/pw_kvs/test_key_value_store.h" ]
103  public_deps = [
104    ":pw_kvs",
105    "$dir_pw_sync:borrow",
106  ]
107}
108
109pw_source_set("fake_flash") {
110  public_configs = [ ":public_include_path" ]
111  public = [ "public/pw_kvs/fake_flash_memory.h" ]
112  sources = [ "fake_flash_memory.cc" ]
113  public_deps = [
114    dir_pw_containers,
115    dir_pw_kvs,
116    dir_pw_status,
117  ]
118  deps = [
119    ":config",
120    dir_pw_log,
121  ]
122}
123
124pw_source_set("flash_partition_with_logical_sectors") {
125  public_configs = [ ":public_include_path" ]
126  public = [ "public/pw_kvs/flash_partition_with_logical_sectors.h" ]
127  public_deps = [ dir_pw_kvs ]
128  deps = [ ":config" ]
129}
130
131pw_source_set("fake_flash_12_byte_partition") {
132  public_configs = [ ":public_include_path" ]
133  public = [ "public/pw_kvs/flash_test_partition.h" ]
134  sources = [ "fake_flash_test_partition.cc" ]
135  public_deps = [ ":flash_test_partition" ]
136  deps = [
137    ":fake_flash",
138    dir_pw_kvs,
139  ]
140  defines = [
141    "PW_FLASH_TEST_SECTORS=3",
142    "PW_FLASH_TEST_SECTOR_SIZE=4",
143    "PW_FLASH_TEST_ALIGNMENT=4",
144  ]
145}
146
147pw_source_set("fake_flash_1_aligned_partition") {
148  public_configs = [ ":public_include_path" ]
149  public = [ "public/pw_kvs/flash_test_partition.h" ]
150  sources = [ "fake_flash_test_partition.cc" ]
151  public_deps = [ ":flash_test_partition" ]
152  deps = [
153    ":fake_flash",
154    dir_pw_kvs,
155  ]
156  defines = [
157    "PW_FLASH_TEST_SECTORS=6U",
158    "PW_FLASH_TEST_SECTOR_SIZE=4096U",
159    "PW_FLASH_TEST_ALIGNMENT=1U",
160  ]
161}
162
163pw_source_set("fake_flash_16_aligned_partition") {
164  public_configs = [ ":public_include_path" ]
165  public = [ "public/pw_kvs/flash_test_partition.h" ]
166  sources = [ "fake_flash_test_partition.cc" ]
167  public_deps = [ ":flash_test_partition" ]
168  deps = [
169    ":fake_flash",
170    dir_pw_kvs,
171  ]
172  defines = [
173    "PW_FLASH_TEST_SECTORS=6U",
174    "PW_FLASH_TEST_SECTOR_SIZE=4096U",
175    "PW_FLASH_TEST_ALIGNMENT=16U",
176  ]
177}
178
179pw_source_set("fake_flash_64_aligned_partition") {
180  public_configs = [ ":public_include_path" ]
181  public = [ "public/pw_kvs/flash_test_partition.h" ]
182  sources = [ "fake_flash_test_partition.cc" ]
183  public_deps = [ ":flash_test_partition" ]
184  deps = [
185    ":fake_flash",
186    dir_pw_kvs,
187  ]
188  defines = [
189    "PW_FLASH_TEST_SECTORS=6U",
190    "PW_FLASH_TEST_SECTOR_SIZE=4096U",
191    "PW_FLASH_TEST_ALIGNMENT=64U",
192  ]
193}
194
195pw_source_set("fake_flash_256_aligned_partition") {
196  public_configs = [ ":public_include_path" ]
197  public = [ "public/pw_kvs/flash_test_partition.h" ]
198  sources = [ "fake_flash_test_partition.cc" ]
199  public_deps = [ ":flash_test_partition" ]
200  deps = [
201    ":fake_flash",
202    dir_pw_kvs,
203  ]
204  defines = [
205    "PW_FLASH_TEST_SECTORS=6U",
206    "PW_FLASH_TEST_SECTOR_SIZE=4096U",
207    "PW_FLASH_TEST_ALIGNMENT=256U",
208  ]
209}
210
211pw_source_set("fake_flash_1_aligned_4_logical_partition") {
212  public_configs = [ ":public_include_path" ]
213  public = [ "public/pw_kvs/flash_test_partition.h" ]
214  sources = [ "fake_flash_test_logical_sector_partition.cc" ]
215  public_deps = [ ":flash_test_partition" ]
216  deps = [
217    ":fake_flash",
218    ":flash_partition_with_logical_sectors",
219    dir_pw_kvs,
220  ]
221  defines = [
222    "PW_FLASH_TEST_SECTORS=24U",
223    "PW_FLASH_TEST_SECTOR_SIZE=4096U",
224    "PW_FLASH_TEST_ALIGNMENT=1U",
225    "PW_FLASH_TEST_SECTORS_PER_LOGICAL_SECTOR=4U",
226  ]
227}
228
229pw_source_set("fake_flash_test_key_value_store") {
230  public_configs = [ ":public_include_path" ]
231  sources = [ "fake_flash_test_key_value_store.cc" ]
232  public_deps = [ ":test_key_value_store" ]
233  deps = [
234    ":crc16",
235    ":fake_flash",
236    dir_pw_kvs,
237  ]
238}
239
240pw_source_set("flash_partition_stream_test") {
241  public_configs = [ ":public_include_path" ]
242  public = [ "public/pw_kvs/flash_memory.h" ]
243  sources = [ "flash_partition_stream_test.cc" ]
244  public_deps = [
245    "$dir_pw_sync:borrow",
246    dir_pw_bytes,
247    dir_pw_kvs,
248    dir_pw_polyfill,
249    dir_pw_preprocessor,
250    dir_pw_status,
251    dir_pw_stream,
252  ]
253  deps = [
254    ":config",
255    ":fake_flash",
256    ":flash_test_partition",
257    dir_pw_kvs,
258    dir_pw_log,
259    dir_pw_random,
260    dir_pw_unit_test,
261  ]
262}
263
264pw_source_set("flash_partition_test_100_iterations") {
265  deps = [
266    ":config",
267    ":flash_test_partition",
268    dir_pw_kvs,
269    dir_pw_log,
270    dir_pw_unit_test,
271  ]
272  sources = [ "flash_partition_test.cc" ]
273  defines = [
274    "PW_FLASH_TEST_ITERATIONS=100",
275    "PW_FLASH_TEST_WRITE_SIZE=1",
276  ]
277}
278
279pw_source_set("flash_partition_test_2_iterations") {
280  deps = [
281    ":config",
282    ":flash_test_partition",
283    dir_pw_kvs,
284    dir_pw_log,
285    dir_pw_unit_test,
286  ]
287  sources = [ "flash_partition_test.cc" ]
288  defines = [
289    "PW_FLASH_TEST_ITERATIONS=2",
290    "PW_FLASH_TEST_WRITE_SIZE=1",
291  ]
292}
293
294pw_source_set("flash_partition_test_100_iterations_256_write") {
295  deps = [
296    ":config",
297    ":flash_test_partition",
298    dir_pw_kvs,
299    dir_pw_log,
300    dir_pw_unit_test,
301  ]
302  sources = [ "flash_partition_test.cc" ]
303  defines = [
304    "PW_FLASH_TEST_ITERATIONS=100",
305    "PW_FLASH_TEST_WRITE_SIZE=256",
306  ]
307}
308
309pw_source_set("flash_partition_test_2_iterations_256_write") {
310  deps = [
311    ":config",
312    ":flash_test_partition",
313    dir_pw_kvs,
314    dir_pw_log,
315    dir_pw_unit_test,
316  ]
317  sources = [ "flash_partition_test.cc" ]
318  defines = [
319    "PW_FLASH_TEST_ITERATIONS=2",
320    "PW_FLASH_TEST_WRITE_SIZE=256",
321  ]
322}
323
324pw_source_set("key_value_store_initialized_test") {
325  deps = [
326    ":crc16",
327    ":flash_test_partition",
328    ":pw_kvs",
329    "$dir_pw_string:builder",
330    dir_pw_bytes,
331    dir_pw_checksum,
332    dir_pw_log,
333    dir_pw_unit_test,
334  ]
335  sources = [ "key_value_store_initialized_test.cc" ]
336}
337
338pw_source_set("key_value_store_fuzz_test") {
339  deps = [
340    ":config",
341    ":crc16",
342    ":flash_test_partition",
343    ":pw_kvs",
344    "$dir_pw_string:builder",
345    dir_pw_bytes,
346    dir_pw_checksum,
347    dir_pw_log,
348    dir_pw_unit_test,
349  ]
350  sources = [ "key_value_store_fuzz_test.cc" ]
351}
352
353pw_source_set("test_key_value_store_test") {
354  deps = [
355    ":pw_kvs",
356    ":test_key_value_store",
357    "$dir_pw_string:builder",
358    "$dir_pw_sync:borrow",
359    dir_pw_unit_test,
360  ]
361  sources = [ "test_key_value_store_test.cc" ]
362}
363
364pw_source_set("test_partition") {
365  public_configs = [ ":public_include_path" ]
366  public = [ "public/pw_kvs/flash_partition_with_stats.h" ]
367  sources = [ "flash_partition_with_stats.cc" ]
368  visibility = [ ":*" ]
369  public_deps = [
370    dir_pw_kvs,
371    dir_pw_log,
372    dir_pw_status,
373  ]
374  deps = [ ":config" ]
375}
376
377pw_test_group("tests") {
378  tests = [
379    ":alignment_test",
380    ":checksum_test",
381    ":converts_to_span_test",
382    ":key_test",
383  ]
384
385  if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
386      pw_toolchain_SCOPE.is_host_toolchain) {
387    # TODO: b/234883746 - KVS tests are not compatible with device builds as they
388    # use features such as std::map and are computationally expensive. Solving
389    # this requires a more complex capabilities-based build and configuration
390    # system which allowing enabling specific tests for targets that support
391    # them and modifying test parameters for different targets.
392
393    tests += [
394      ":entry_test",
395      ":entry_cache_test",
396      ":flash_partition_1_stream_test",
397      ":flash_partition_4_logical_stream_test",
398      ":flash_partition_1_alignment_test",
399      ":flash_partition_1_alignment_4_logical_test",
400      ":flash_partition_16_alignment_test",
401      ":flash_partition_64_alignment_test",
402      ":flash_partition_256_alignment_test",
403      ":flash_partition_256_write_size_test",
404      ":flash_partition_4_logical_256_write_size_test",
405      ":key_value_store_test",
406      ":key_value_store_1_alignment_flash_test",
407      ":key_value_store_1_alignment_4_logical_flash_test",
408      ":key_value_store_16_alignment_flash_test",
409      ":key_value_store_64_alignment_flash_test",
410      ":key_value_store_256_alignment_flash_test",
411      ":key_value_store_fuzz_1_alignment_flash_test",
412      ":key_value_store_fuzz_64_alignment_flash_test",
413      ":key_value_store_binary_format_test",
414      ":key_value_store_put_test",
415      ":key_value_store_map_test",
416      ":key_value_store_wear_test",
417      ":fake_flash_test_key_value_store_test",
418      ":sectors_test",
419    ]
420  }
421}
422
423pw_test("alignment_test") {
424  deps = [ ":pw_kvs" ]
425  sources = [ "alignment_test.cc" ]
426}
427
428pw_test("checksum_test") {
429  deps = [
430    ":crc16",
431    ":pw_kvs",
432    dir_pw_log,
433  ]
434  sources = [ "checksum_test.cc" ]
435}
436
437pw_test("converts_to_span_test") {
438  deps = [ ":pw_kvs" ]
439  sources = [ "converts_to_span_test.cc" ]
440}
441
442pw_test("entry_test") {
443  deps = [
444    ":crc16",
445    ":fake_flash",
446    ":pw_kvs",
447    dir_pw_bytes,
448  ]
449  sources = [ "entry_test.cc" ]
450}
451
452pw_test("entry_cache_test") {
453  deps = [
454    ":fake_flash",
455    ":pw_kvs",
456    dir_pw_bytes,
457  ]
458  sources = [ "entry_cache_test.cc" ]
459}
460
461pw_test("flash_partition_1_stream_test") {
462  deps = [
463    ":fake_flash",
464    ":fake_flash_1_aligned_partition",
465    ":flash_partition_stream_test",
466    dir_pw_log,
467  ]
468}
469
470pw_test("flash_partition_4_logical_stream_test") {
471  deps = [
472    ":fake_flash",
473    ":fake_flash_1_aligned_4_logical_partition",
474    ":flash_partition_stream_test",
475    dir_pw_log,
476  ]
477}
478
479pw_test("flash_partition_1_alignment_test") {
480  deps = [
481    ":fake_flash",
482    ":fake_flash_1_aligned_partition",
483    ":flash_partition_test_100_iterations",
484    dir_pw_log,
485  ]
486}
487
488pw_test("flash_partition_1_alignment_4_logical_test") {
489  deps = [
490    ":fake_flash",
491    ":fake_flash_1_aligned_4_logical_partition",
492    ":flash_partition_test_2_iterations",
493    dir_pw_log,
494  ]
495}
496
497pw_test("flash_partition_16_alignment_test") {
498  deps = [
499    ":fake_flash",
500    ":fake_flash_16_aligned_partition",
501    ":flash_partition_test_100_iterations",
502    dir_pw_log,
503  ]
504}
505
506pw_test("flash_partition_64_alignment_test") {
507  deps = [
508    ":fake_flash",
509    ":fake_flash_64_aligned_partition",
510    ":flash_partition_test_100_iterations",
511    dir_pw_log,
512  ]
513}
514
515pw_test("flash_partition_256_alignment_test") {
516  deps = [
517    ":fake_flash",
518    ":fake_flash_256_aligned_partition",
519    ":flash_partition_test_100_iterations",
520    dir_pw_log,
521  ]
522}
523
524pw_test("flash_partition_256_write_size_test") {
525  deps = [
526    ":fake_flash",
527    ":fake_flash_1_aligned_partition",
528    ":flash_partition_test_100_iterations_256_write",
529    dir_pw_log,
530  ]
531}
532
533pw_test("flash_partition_4_logical_256_write_size_test") {
534  deps = [
535    ":fake_flash",
536    ":fake_flash_1_aligned_4_logical_partition",
537    ":flash_partition_test_2_iterations_256_write",
538    dir_pw_log,
539  ]
540}
541
542pw_test("key_value_store_test") {
543  deps = [
544    ":config",
545    ":crc16",
546    ":fake_flash",
547    ":pw_kvs",
548    "$dir_pw_string:builder",
549    dir_pw_bytes,
550    dir_pw_checksum,
551    dir_pw_log,
552  ]
553  sources = [ "key_value_store_test.cc" ]
554}
555
556pw_test("key_value_store_1_alignment_flash_test") {
557  deps = [
558    ":fake_flash_1_aligned_partition",
559    ":key_value_store_initialized_test",
560  ]
561}
562
563pw_test("key_value_store_1_alignment_4_logical_flash_test") {
564  deps = [
565    ":fake_flash_1_aligned_4_logical_partition",
566    ":key_value_store_initialized_test",
567  ]
568}
569
570pw_test("key_value_store_16_alignment_flash_test") {
571  deps = [
572    ":fake_flash_16_aligned_partition",
573    ":key_value_store_initialized_test",
574  ]
575}
576
577pw_test("key_value_store_64_alignment_flash_test") {
578  deps = [
579    ":fake_flash_64_aligned_partition",
580    ":key_value_store_initialized_test",
581  ]
582}
583
584pw_test("key_value_store_256_alignment_flash_test") {
585  deps = [
586    ":fake_flash_256_aligned_partition",
587    ":key_value_store_initialized_test",
588  ]
589}
590
591pw_test("key_value_store_fuzz_1_alignment_flash_test") {
592  deps = [
593    ":fake_flash_1_aligned_partition",
594    ":key_value_store_fuzz_test",
595  ]
596}
597
598pw_test("key_value_store_fuzz_64_alignment_flash_test") {
599  deps = [
600    ":fake_flash_64_aligned_partition",
601    ":key_value_store_fuzz_test",
602  ]
603}
604
605pw_test("key_value_store_binary_format_test") {
606  deps = [
607    ":crc16",
608    ":fake_flash",
609    ":pw_kvs",
610    dir_pw_bytes,
611    dir_pw_log,
612  ]
613  sources = [ "key_value_store_binary_format_test.cc" ]
614}
615
616pw_test("key_value_store_put_test") {
617  deps = [
618    ":crc16",
619    ":fake_flash",
620    ":pw_kvs",
621    ":test_partition",
622  ]
623  sources = [ "key_value_store_put_test.cc" ]
624}
625
626pw_test("fake_flash_test_key_value_store_test") {
627  deps = [
628    ":fake_flash_test_key_value_store",
629    ":test_key_value_store_test",
630    "$dir_pw_sync:borrow",
631  ]
632}
633
634pw_test("key_value_store_map_test") {
635  deps = [
636    ":crc16",
637    ":fake_flash",
638    ":pw_kvs",
639    ":test_partition",
640    "$dir_pw_string:builder",
641    dir_pw_checksum,
642  ]
643  sources = [ "key_value_store_map_test.cc" ]
644}
645
646pw_test("sectors_test") {
647  deps = [
648    ":fake_flash",
649    ":pw_kvs",
650  ]
651  sources = [ "sectors_test.cc" ]
652}
653
654pw_test("key_test") {
655  deps = [ ":pw_kvs" ]
656  sources = [ "key_test.cc" ]
657}
658
659pw_test("key_value_store_wear_test") {
660  deps = [
661    ":fake_flash",
662    ":pw_kvs",
663    ":test_partition",
664    dir_pw_log,
665  ]
666  sources = [ "key_value_store_wear_test.cc" ]
667}
668
669pw_doc_group("docs") {
670  sources = [ "docs.rst" ]
671  report_deps = [ ":kvs_size" ]
672}
673
674pw_size_diff("kvs_size") {
675  title = "Pigweed KVS size report"
676
677  binaries = [
678    {
679      target = "size_report:with_kvs"
680      base = "size_report:base_with_only_flash"
681      label = "KeyValueStore"
682    },
683  ]
684
685  binaries += [
686    {
687      target = "size_report:base_with_only_flash"
688      base = "size_report:base"
689      label = "FlashPartition"
690    },
691  ]
692}
693