1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
15 #include "pw_kvs/crc16_checksum.h"
16 #include "pw_kvs/fake_flash_memory.h"
17 #include "pw_kvs/flash_memory.h"
18 #include "pw_kvs/key_value_store.h"
19 #include "pw_kvs/test_key_value_store.h"
25 #ifndef PW_FLASH_TEST_SECTORS
26 #define PW_FLASH_TEST_SECTORS 8U
27 #endif // PW_FLASH_TEST_SECTORS
29 #ifndef PW_FLASH_TEST_SECTOR_SIZE
30 #define PW_FLASH_TEST_SECTOR_SIZE (4 * 1024U)
31 #endif // PW_FLASH_TEST_SECTOR_SIZE
33 #ifndef PW_FLASH_TEST_ALIGNMENT
34 #define PW_FLASH_TEST_ALIGNMENT 16U
35 #endif // PW_FLASH_TEST_ALIGNMENT
37 #ifndef PW_KVS_TEST_MAX_ENTIRES
38 #define PW_KVS_TEST_MAX_ENTIRES 32U
39 #endif // PW_KVS_TEST_MAX_ENTIRES
41 #ifndef PW_KVS_TEST_REDUNDANCY
42 #define PW_KVS_TEST_REDUNDANCY 1U
43 #endif // PW_KVS_TEST_REDUNDANCY
45 constexpr size_t kFlashTestSectors = PW_FLASH_TEST_SECTORS;
46 constexpr size_t kFlashTestSectorSize = PW_FLASH_TEST_SECTOR_SIZE;
47 constexpr size_t kFlashTestAlignment = PW_FLASH_TEST_ALIGNMENT;
49 constexpr size_t kKvsTestMaxEntries = PW_KVS_TEST_MAX_ENTIRES;
50 constexpr size_t kKvsTestRedundancy = PW_KVS_TEST_REDUNDANCY;
52 // Default to 8 x 4k sectors, 16 byte alignment.
53 FakeFlashMemoryBuffer<kFlashTestSectorSize, kFlashTestSectors> test_flash(
55 FlashPartition test_partition(&test_flash);
57 ChecksumCrc16 kvs_checksum;
59 // For KVS magic value always use a random 32 bit integer rather than a human
60 // readable 4 bytes. See pw_kvs/format.h for more information.
61 constexpr EntryFormat kvs_format = {.magic = 0xc40fd8a8,
62 .checksum = &kvs_checksum};
64 KeyValueStoreBuffer<kKvsTestMaxEntries, kFlashTestSectors, kKvsTestRedundancy>
65 test_kvs(&test_partition, kvs_format);
69 KeyValueStore& TestKvs() {
70 if (!test_kvs.initialized()) {
76 } // namespace pw::kvs