Commit Graph

27 Commits

Author SHA1 Message Date
Wyatt Hepler
06b1b0b924 pw_kvs: Rename output.h to io.h
Prepare for introducing an Input interface.

Change-Id: I6582adbf139577cc1e81110ac952508fa767fa9e
2020-03-09 16:02:51 +00:00
Wyatt Hepler
22d0d9fcb0 pw_kvs: Support multiple entry formats
Change-Id: If25ea00210178b8495585a651d3df6ad8347ee82
2020-03-05 17:36:45 -08:00
Wyatt Hepler
8e94ed61e8 pw_kvs: Rename key_value_store_error_handling_test
Rename key_value_store_error_handling_test.cc to
key_value_store_binary_format_test.cc.

Change-Id: I81b55b4eaded6c21886e43f0d10d04303d6fa264
2020-03-06 01:32:51 +00:00
Rob Mohr
a0ba54f648 Roll GN to 239533d
This caused gn format to flag many things which were also fixed.

Change-Id: Ie1d9081a1b08047bec52c60f54d2a94366be1ba6
2020-02-28 01:33:18 +00:00
Wyatt Hepler
118fc3c5f0 pw_kvs: Expand tests for error handling
- Add error injection features to InMemoryFakeFlash. Reads or Writes can
  be programmed to fail.
- Introduce key_value_store_error_handling_test.cc, which focuses on
  corruption and read/write failure cases.
- Add functions for creating binary KVS entries at compile time.

Change-Id: Ie52ba5eb13eb60244835ef43314282beacc3a659
2020-02-24 10:08:27 -08:00
Keir Mierle
0dd24a83d7 pw_kvs: Move span traits outside of public header
Change-Id: I1cabd7b8121cf227189d8aa4d86e8a036866c7ed
2020-02-22 00:56:24 +00:00
Wyatt Hepler
88adfe8b91 pw_kvs: Move EntryHeaderFormat to pw_kvs/format.h
- Move EntryHeaderFormat and the EntryHeader struct to pw_kvs/format.h.
- Rename EntryHeaderFormat to EntryFormat.

Change-Id: Ic5e53c688cd3a483101c7985def6e4bef9c3cbaf
2020-02-21 09:34:31 -08:00
Wyatt Hepler
bdd8e5a77b pw_kvs: Move entry.h to public/pw_kvs/internal
Move entry.h so that the KeyValueStore class can reference it in the
header.

Change-Id: Ib5a7f194db8dd9af1e8f3d8c9c7c25b8409acfe0
2020-02-20 19:30:47 -08:00
Wyatt Hepler
1fc1104cb5 pw_kvs: Transcation ID and key descriptor refactor
- Switch from per-key versions to a monotonically increasing KVS-global
  transcation ID.
- Move KeyDescriptor and the hash function to their own files.

Change-Id: I05287137579d4fe2d72c6e176969d46006c2aae6
2020-02-20 16:26:27 -08:00
Wyatt Hepler
2c7eca0952 pw_kvs: Move SectorDescriptor to its own header
- Move SectorDescriptor to internal/sector_descriptor.h.
- Make SectorDescriptor a class and move functions that don't reference
  the sector descriptor map to it.

Change-Id: I342d89e844c4a97be8e186aea91bf9ac52b03445
2020-02-20 19:23:48 +00:00
Wyatt Hepler
a00d1ef82c pw_kvs: Expand Entry tests; fix issues
- Expand the tests for the KVS entry class.
- Fix a few minor issues found by the tests.

Change-Id: I92b5dd614d2a726c912b7b1bf1f9ebd47a702be4
2020-02-19 11:12:01 -08:00
Wyatt Hepler
cdd6dfcfc6 pw_kvs: FlashMemory updates; test utilities
- Update comments for FlashMemory class.
- Split InMemoryFakeFlash to move the fixed-size buffer into the
  derived FakeFlashBuffer class.
- Support initializing FakeFlashBuffer to data provided at construction.
- Allow direct access to the underlying fake flash buffer for testing.
- Create utilities for working with byte arrays in byte_utils.h.

Change-Id: I90d33621cb91da079d7213fe7d33823494120e48
2020-02-19 19:10:32 +00:00
Wyatt Hepler
e541e075d4 pw_kvs: Move reading and writing to Entry class
- Add the FlashPartition and address to the Entry class.
- Move functions for reading or writing the entry header, key, and value
  to the Entry class.

Change-Id: I0af3c140a519c8b050fcef81eca4f3b45560f75c
2020-02-14 16:21:29 -08:00
Wyatt Hepler
d31d97070f pw_kvs: Rename format.h to entry.h
Change-Id: Iad7148cad736d57a9ff5d23772a002c40508b6d4
2020-02-14 18:08:50 +00:00
Wyatt Hepler
495b6ee5ce pw_kvs: Map-backed tests
Introduce a system for writing tests against flash memories with
different parameters. The tests use a std::unordered_map as an oracle,
and all operations are checked against it. Invalid inputs and the KVS
filling up are handled.

Disable most of the tests because they are currently failing.

Change-Id: Ib817e30a199c81b3146823252be91e0db016c9b3
2020-02-13 21:50:30 +00:00
Wyatt Hepler
1927c2868b pw_kvs: Split out aligned write functionality
- Define the Output interface.
- Create AlignedWriter class, which handles writing aligned and padded
  data to a buffer.
- Define AlignedWriterBuffer, which provides a buffer to an
  AlignedWriter.

Change-Id: I791c5fc2d47617b0866fa779a506cb977905f245
2020-02-12 17:00:09 -08:00
Wyatt Hepler
1c329ca293 pw_kvs: Use pw::Vector for descriptor lists
The pw::Vector class is similar to std::vector but is backed by a
fixed-size array. Using pw::Vector for descriptor lists cleans up the
code and makes iterating over these lists less error-prone. It also
opens the possibility of working with descriptor types that are not
default constructible.

Change-Id: I3ad05dacef1cc77108a9d35128aa2100535048b2
2020-02-10 16:53:16 -08:00
Wyatt Hepler
16b04521dd pw_kvs: Move test; disable dumping to file
- Move long-running Put test to a separate file.
- Do not dump the KVS state to file by default to prevent files from
  showing up when the tests run.

Change-Id: Ie466d06aa3e22819cad03713e866afae5c63cbe6
2020-02-07 16:03:02 -08:00
Wyatt Hepler
97fc794536 pw_kvs: Introduce alignment to the entry header
- Add an 8-bit alignment field to the entry header. This makes the
  entry header a complete description of the entry's representation in
  flash (assuming the checksum algorithm is implied by the magic).
- Write basic tests for the EntryHeader class.

Change-Id: I7e48d5c16451ceb81f7c191d2f261e0a9bef14b7
2020-02-07 00:34:58 +00:00
Wyatt Hepler
d621682fe5 pw_kvs: Simple debug command line interface
Add the pw_kvs:debug_cli executable for performing very basic manual
testing locally.

Change-Id: Ifab6eb237f92a1b09ed7e3797485f9889e6cec64
2020-02-04 17:42:23 -08:00
Wyatt Hepler
ad684a1897 pw_kvs: Make in_memory_fake_flash.h library
- Make in_memory_fake_flash.h a separate library that is only visible
  within pw_kvs (for now).
- Have the fake flash use PW_LOG_ERROR instead of the short names, since
  it's logging from the header.

Change-Id: I686024bad1e532632d0c9e6eefe74207fdc1f22e
2020-02-04 17:41:49 -08:00
Wyatt Hepler
6e3a83b61f pw_kvs: Get checksums working; enable test
- Allow checksums to verify data larger than their internal state. This
  facilitates using a CRC16 in a uint32_t.
- Move checksum functions to the EntryHeader class, since it ultimately
  stores the checksums and is included with it.
- Enable one checksum test. Further tests are needed.
- Make some tweaks to the Get overload for objects.

Change-Id: I989b72905e140794f75c8f8619aaab1623f6f195
2020-02-04 16:35:40 -08:00
Wyatt Hepler
ec4b9351de pw_kvs: Implement CRC16 checksum for KVS
- Create CRC16 implementation of pw::kvs::ChecksumAlgorithm.
- Add tests for the ChecksumAlgorithm class.

Change-Id: I3d7268e49c4eec06d61e113602ce24c05a3b0fa0
2020-02-04 01:22:49 +00:00
Wyatt Hepler
4da1fcb4b2 pw_kvs: Initial commit of new KVS design
Builds, but lots more work needed.

Fun fact: this code was written collaboratively in a Google Doc.

Change-Id: I8a89c5d0fdc71ec28cf432350e65d17e24a6f25c
2020-01-31 14:38:37 -08:00
Wyatt Hepler
acaacf9a4f pw_kvs: Initial API changes
- Use std::string_view for keys to avoid the need for null termination.
- Use std::span and std::byte for data.
- Use StatusWithSize and size_t.
- Other minor adjustments.

Change-Id: I10d2f0f47b386071ed4ecf81586decfcc99244cd
2020-01-29 16:20:50 -08:00
Wyatt Hepler
d6b384aba0 pw_kvs: Remove the sub-sector interface
Change-Id: Id9d2984220b6aa28e6dc1bd87e8da0e39b3131ea
2020-01-28 01:18:28 +00:00
Wyatt Hepler
2ad6067478 pw_kvs: Add to build; get tests passing
Change-Id: Idfd357beaf60b94ebaf9b4b1f8cd1b3d712e9b10
2020-01-27 19:13:05 +00:00