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