Skip to content

Commit c90182a

Browse files
author
David Saada
committed
NVStore: add the allocate_key API (instead of set_alloc_key)
Add the allocate_key API. This replaces the previously added set_alloc_key API (which allocates a key and sets the value at the same time). Reason for the change: Key allocation will typically be used by other storage features (like StorageLite), keeping the allocated keys in another location. Previous API created problems in the case key allocation and value setting couldn't be done at the same time (for instance, if the set value was derived from the allocated key, such as hash or CMAC).
1 parent 9fd04c4 commit c90182a

File tree

3 files changed

+167
-63
lines changed

3 files changed

+167
-63
lines changed

features/nvstore/TESTS/nvstore/functionality/main.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,17 @@ static void nvstore_basic_functionality_test()
133133
result = nvstore.set(19, 10, &(nvstore_testing_buf_set[3]));
134134
TEST_ASSERT_EQUAL(NVSTORE_ALREADY_EXISTS, result);
135135

136-
result = nvstore.set_alloc_key(key, 17, &(nvstore_testing_buf_set[3]));
136+
result = nvstore.allocate_key(key, 3);
137137
TEST_ASSERT_EQUAL(NVSTORE_NUM_PREDEFINED_KEYS, key);
138138
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
139+
result = nvstore.set(NVSTORE_NUM_PREDEFINED_KEYS, 17, &(nvstore_testing_buf_set[3]));
140+
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
141+
142+
result = nvstore.allocate_key(key, 3);
143+
TEST_ASSERT_EQUAL(NVSTORE_NUM_PREDEFINED_KEYS + 1, key);
144+
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
145+
result = nvstore.set(NVSTORE_NUM_PREDEFINED_KEYS + 1, 17, &(nvstore_testing_buf_set[3]));
146+
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
139147

140148
// Make sure set items are also gotten OK after reset
141149
result = nvstore.deinit();
@@ -168,6 +176,20 @@ static void nvstore_basic_functionality_test()
168176
TEST_ASSERT_EQUAL(17, actual_len_bytes);
169177
TEST_ASSERT_EQUAL_UINT8_ARRAY(&nvstore_testing_buf_set[3], nvstore_testing_buf_get, 17);
170178

179+
result = nvstore.get(NVSTORE_NUM_PREDEFINED_KEYS + 1, 64, nvstore_testing_buf_get, actual_len_bytes);
180+
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
181+
TEST_ASSERT_EQUAL(17, actual_len_bytes);
182+
TEST_ASSERT_EQUAL_UINT8_ARRAY(&nvstore_testing_buf_set[3], nvstore_testing_buf_get, 17);
183+
184+
result = nvstore.free_all_keys_by_owner(3);
185+
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
186+
187+
result = nvstore.get(NVSTORE_NUM_PREDEFINED_KEYS, 64, nvstore_testing_buf_get, actual_len_bytes);
188+
TEST_ASSERT_EQUAL(NVSTORE_NOT_FOUND, result);
189+
190+
result = nvstore.get(NVSTORE_NUM_PREDEFINED_KEYS + 1, 64, nvstore_testing_buf_get, actual_len_bytes);
191+
TEST_ASSERT_EQUAL(NVSTORE_NOT_FOUND, result);
192+
171193
result = nvstore.get(10, 65, nvstore_testing_buf_get, actual_len_bytes);
172194
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
173195
TEST_ASSERT_EQUAL(64, actual_len_bytes);
@@ -346,6 +368,12 @@ static void nvstore_basic_functionality_test()
346368
TEST_ASSERT_EQUAL(53, actual_len_bytes);
347369
TEST_ASSERT_EQUAL_UINT8_ARRAY(&(nvstore_testing_buf_set[10]), nvstore_testing_buf_get, 53);
348370

371+
result = nvstore.get(NVSTORE_NUM_PREDEFINED_KEYS, 64, nvstore_testing_buf_get, actual_len_bytes);
372+
TEST_ASSERT_EQUAL(NVSTORE_NOT_FOUND, result);
373+
374+
result = nvstore.get(NVSTORE_NUM_PREDEFINED_KEYS + 1, 64, nvstore_testing_buf_get, actual_len_bytes);
375+
TEST_ASSERT_EQUAL(NVSTORE_NOT_FOUND, result);
376+
349377
delete[] nvstore_testing_buf_set;
350378
delete[] nvstore_testing_buf_get;
351379
}

0 commit comments

Comments
 (0)