• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 
15 #include <cstring>
16 
17 #include "pw_assert/check.h"
18 #include "pw_bloat/bloat_this_binary.h"
19 #include "pw_kvs/flash_test_partition.h"
20 #include "pw_kvs/key_value_store.h"
21 #include "pw_log/log.h"
22 
23 char working_buffer[256];
24 volatile bool is_set;
25 
26 constexpr size_t kMaxSectorCount = 64;
27 constexpr size_t kKvsMaxEntries = 32;
28 
29 // For KVS magic value always use a random 32 bit integer rather than a human
30 // readable 4 bytes. See pw_kvs/format.h for more information.
31 static constexpr pw::kvs::EntryFormat kvs_format = {.magic = 0x22d3f8a0,
32                                                     .checksum = nullptr};
33 
34 volatile size_t kvs_entry_count;
35 
36 pw::kvs::KeyValueStoreBuffer<kKvsMaxEntries, kMaxSectorCount> kvs(
37     &pw::kvs::FlashTestPartition(), kvs_format);
38 
39 int volatile* unoptimizable;
40 
main()41 int main() {
42   pw::bloat::BloatThisBinary();
43 
44   // Ensure we are paying the cost for log and assert.
45   PW_CHECK_INT_GE(*unoptimizable, 0, "Ensure this CHECK logic stays");
46   PW_LOG_INFO("We care about optimizing: %d", *unoptimizable);
47 
48   void* result =
49       std::memset((void*)working_buffer, 0x55, sizeof(working_buffer));
50   is_set = (result != nullptr);
51 
52   kvs.Init().IgnoreError();  // TODO: b/242598609 - Handle Status properly
53 
54   unsigned kvs_value = 42;
55   kvs.Put("example_key", kvs_value)
56       .IgnoreError();  // TODO: b/242598609 - Handle Status properly
57 
58   kvs_entry_count = kvs.size();
59 
60   unsigned read_value = 0;
61   kvs.Get("example_key", &read_value)
62       .IgnoreError();  // TODO: b/242598609 - Handle Status properly
63 
64   return 0;
65 }
66