diff options
author | David Rogers <davidrogers@google.com> | 2020-08-03 08:44:10 -0700 |
---|---|---|
committer | CQ Bot Account <commit-bot@chromium.org> | 2020-08-03 16:54:45 +0000 |
commit | 436b3aa926a030f40bfc7124e2c65907a748ff67 (patch) | |
tree | 4713640af9311d24603fc25eb966b55944474c65 /pw_kvs/key_value_store_test.cc | |
parent | 795fecf5a2a174adbc391e9d143c02995780d6ef (diff) | |
download | pigweed-436b3aa926a030f40bfc7124e2c65907a748ff67.tar.gz |
pw_kvs: Update all KVS magics to be random numbers
To set the proper example for KVS users, update all KVS tests to use
random numbers for the magic. Add comments to each magic use to explain
use of random number.
Change-Id: I76a4012cf7848cc800705fa129a2aca49bd1cd72
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/15241
Reviewed-by: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: David Rogers <davidrogers@google.com>
Diffstat (limited to 'pw_kvs/key_value_store_test.cc')
-rw-r--r-- | pw_kvs/key_value_store_test.cc | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/pw_kvs/key_value_store_test.cc b/pw_kvs/key_value_store_test.cc index 4479c5699..af981f1a3 100644 --- a/pw_kvs/key_value_store_test.cc +++ b/pw_kvs/key_value_store_test.cc @@ -158,7 +158,9 @@ FlashPartition large_test_partition(&large_test_flash, constexpr std::array<const char*, 3> keys{"TestKey1", "Key2", "TestKey3"}; ChecksumCrc16 checksum; -constexpr EntryFormat default_format{.magic = 0xBAD'C0D3, +// For KVS magic value always use a random 32 bit integer rather than a +// human readable 4 bytes. See pw_kvs/format.h for more information. +constexpr EntryFormat default_format{.magic = 0xa6cb3c16, .checksum = &checksum}; } // namespace @@ -168,7 +170,9 @@ TEST(InitCheck, TooFewSectors) { FakeFlashMemoryBuffer<4 * 1024, 1> test_flash(16); FlashPartition test_partition(&test_flash, 0, test_flash.sector_count()); - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // For KVS magic value always use a random 32 bit integer rather than a + // human readable 4 bytes. See pw_kvs/format.h for more information. + constexpr EntryFormat format{.magic = 0x89bb14d2, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs(&test_partition, format); @@ -182,7 +186,9 @@ TEST(InitCheck, ZeroSectors) { // Set FlashPartition to have 0 sectors. FlashPartition test_partition(&test_flash, 0, 0); - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // For KVS magic value always use a random 32 bit integer rather than a + // human readable 4 bytes. See pw_kvs/format.h for more information. + constexpr EntryFormat format{.magic = 0xd1da57c1, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs(&test_partition, format); @@ -196,7 +202,9 @@ TEST(InitCheck, TooManySectors) { // Set FlashPartition to have 0 sectors. FlashPartition test_partition(&test_flash, 0, test_flash.sector_count()); - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // For KVS magic value always use a random 32 bit integer rather than a + // human readable 4 bytes. See pw_kvs/format.h for more information. + constexpr EntryFormat format{.magic = 0x610f6d17, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, 2> kvs(&test_partition, format); EXPECT_EQ(kvs.Init(), Status::FAILED_PRECONDITION); @@ -218,8 +226,10 @@ TEST(InMemoryKvs, WriteOneKeyMultipleTimes) { DBG("xxx xxxx"); DBG("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - // Create and initialize the KVS. - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // Create and initialize the KVS. For KVS magic value always use a random 32 + // bit integer rather than a human readable 4 bytes. See pw_kvs/format.h for + // more information. + constexpr EntryFormat format{.magic = 0x83a9257, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs(&flash.partition, format); ASSERT_OK(kvs.Init()); @@ -257,8 +267,10 @@ TEST(InMemoryKvs, WritingMultipleKeysIncreasesSize) { Flash flash; ASSERT_OK(flash.partition.Erase()); - // Create and initialize the KVS. - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // Create and initialize the KVS. For KVS magic value always use a random 32 + // bit integer rather than a human readable 4 bytes. See pw_kvs/format.h for + // more information. + constexpr EntryFormat format{.magic = 0x2ed3a058, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs(&flash.partition, format); ASSERT_OK(kvs.Init()); @@ -284,7 +296,9 @@ TEST(InMemoryKvs, WriteAndReadOneKey) { ASSERT_OK(flash.partition.Erase()); // Create and initialize the KVS. - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // For KVS magic value always use a random 32 bit integer rather than a + // human readable 4 bytes. See pw_kvs/format.h for more information. + constexpr EntryFormat format{.magic = 0x5d70896, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs(&flash.partition, format); ASSERT_OK(kvs.Init()); @@ -344,7 +358,9 @@ TEST(InMemoryKvs, Basic) { ASSERT_EQ(Status::OK, flash.partition.Erase()); // Create and initialize the KVS. - constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = nullptr}; + // For KVS magic value always use a random 32 bit integer rather than a + // human readable 4 bytes. See pw_kvs/format.h for more information. + constexpr EntryFormat format{.magic = 0x7bf19895, .checksum = nullptr}; KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs(&flash.partition, format); ASSERT_OK(kvs.Init()); |