-
Notifications
You must be signed in to change notification settings - Fork 2.1k
pkg/flashdb: bump version and improve test #21900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
c12a00f
960dab2
4da5d6e
6703233
bc0e5d1
0b1f8b8
693b1bb
f85002b
a0c4319
5a489d9
367d796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
|
|
||
| #define FDB_LOG_TAG "[sample][kvdb][basic]" | ||
|
|
||
| extern const char *resstr(bool condition); | ||
|
|
||
| void kvdb_basic_sample(fdb_kvdb_t kvdb) | ||
| { | ||
| struct fdb_blob blob; | ||
|
|
@@ -27,21 +29,26 @@ void kvdb_basic_sample(fdb_kvdb_t kvdb) | |
|
|
||
| { /* GET the KV value */ | ||
| /* get the "boot_count" KV value */ | ||
| fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); | ||
| /* the blob.saved.len is more than 0 when get the value successful */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression most (all?) the tests were taken from their docs: https://armink.github.io/FlashDB/#/sample-kvdb-basic I haven't done so yet, but maybe you could double-check if they have changed in the meantime. Nevertheless, it definitely makes sense to catch return values. Will try to have a closer look at it today or beginning of next week.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, makes sense to check that. And yes, the tests look like a straight copy of the package examples. Maybe it makes sense to also upstream that later. The FlashDB repo has no changes compared to the version currently used in RIOT ( |
||
| if (blob.saved.len > 0) { | ||
| printf("get the 'boot_count' value is %d\n", boot_count); | ||
| } else { | ||
| printf("get the 'boot_count' failed\n"); | ||
| } | ||
| size_t res = fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); | ||
crasbe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| printf("get the 'boot_count' value is %d %s\n", boot_count, | ||
| resstr(res == sizeof(boot_count))); | ||
| } | ||
|
|
||
| { /* CHANGE the KV value */ | ||
| /* increase the boot count */ | ||
| boot_count ++; | ||
| /* change the "boot_count" KV's value */ | ||
| fdb_kv_set_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); | ||
| printf("set the 'boot_count' value to %d\n", boot_count); | ||
| int res = fdb_kv_set_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); | ||
crasbe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| printf("set the 'boot_count' value to %d %s\n", boot_count, | ||
| resstr(res == FDB_NO_ERR)); | ||
| } | ||
|
|
||
| { /* GET the KV value */ | ||
| int expected = boot_count; | ||
| /* get the "boot_count" KV value */ | ||
| int res = fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); | ||
crasbe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| printf("get the 'boot_count' value is %d %s\n", boot_count, | ||
| resstr(res == sizeof(boot_count) && boot_count == expected)); | ||
| } | ||
|
|
||
| printf("===========================================================\n"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <errno.h> | ||
| #include <stdio.h> | ||
| #include <sys/stat.h> | ||
| #include <sys/types.h> | ||
|
|
@@ -33,6 +34,9 @@ | |
| #define FDB_DIR VFS_DEFAULT_DATA | ||
| #endif | ||
|
|
||
| #define KVDB_DIR (FDB_DIR "/fdb_kvdb1") | ||
| #define TSDB_DIR (FDB_DIR "/fdb_tsdb1") | ||
|
|
||
MichelRottleuthner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static mutex_t kv_locker, ts_locker; | ||
| static uint32_t boot_count = 0; | ||
| static time_t boot_time[10] = {0, 1, 2, 3}; | ||
|
|
@@ -72,6 +76,12 @@ static fdb_time_t get_time(void) | |
| return time(NULL); | ||
| } | ||
|
|
||
| /* converts a test condition to a human readable string */ | ||
| const char *resstr(bool condition) | ||
| { | ||
| return condition ? "[OK]" : "[FAILED]"; | ||
| } | ||
|
Comment on lines
+79
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why no |
||
|
|
||
| int main(void) | ||
| { | ||
| fdb_err_t result; | ||
|
|
@@ -96,10 +106,14 @@ int main(void) | |
| bool file_mode = true; | ||
| fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_FILE_MODE, &file_mode); | ||
| /* create database directory */ | ||
| vfs_mkdir(FDB_DIR "/fdb_kvdb1", 0777); | ||
| int res = vfs_mkdir(KVDB_DIR, 0777); | ||
| printf("mkdir '%s' %s\n", KVDB_DIR, resstr(res == 0 || res == -EEXIST)); | ||
MichelRottleuthner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!(res == 0 || res == -EEXIST)) { | ||
| return -1; | ||
| } | ||
| #endif | ||
| default_kv.kvs = default_kv_table; | ||
| default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]); | ||
| default_kv.num = ARRAY_SIZE(default_kv_table); | ||
| /* set the lock and unlock function if you want */ | ||
| mutex_init(&kv_locker); | ||
| fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_LOCK, (void *)(uintptr_t)lock); | ||
|
|
@@ -116,7 +130,8 @@ int main(void) | |
| * &default_kv: The default KV nodes. It will auto add to KVDB when first initialize successfully. | ||
| * &kv_locker: The locker object. | ||
| */ | ||
| result = fdb_kvdb_init(&kvdb, "env", FDB_DIR "/fdb_kvdb1", &default_kv, &kv_locker); | ||
| result = fdb_kvdb_init(&kvdb, "env", KVDB_DIR, &default_kv, &kv_locker); | ||
| printf("fdb_kvdb_init %s\n", resstr(result == FDB_NO_ERR)); | ||
|
|
||
| if (result != FDB_NO_ERR) { | ||
| return -1; | ||
|
|
@@ -128,6 +143,10 @@ int main(void) | |
| kvdb_type_string_sample(&kvdb); | ||
| /* run blob KV samples */ | ||
| kvdb_type_blob_sample(&kvdb); | ||
|
|
||
| /* deinit the kvdb to make sure all open files are properly closed */ | ||
| fdb_err_t dres = fdb_kvdb_deinit(&kvdb); | ||
| printf("kvdb deinit %s\n", resstr(dres == FDB_NO_ERR)); | ||
| } | ||
| #endif /* FDB_USING_KVDB */ | ||
|
|
||
|
|
@@ -145,7 +164,11 @@ int main(void) | |
| bool file_mode = true; | ||
| fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_FILE_MODE, &file_mode); | ||
| /* create database directory */ | ||
| vfs_mkdir(FDB_DIR "/fdb_tsdb1", 0777); | ||
| int res = vfs_mkdir(TSDB_DIR, 0777); | ||
| printf("mkdir '%s' %s\n", TSDB_DIR, resstr(res == 0 || res == -EEXIST)); | ||
| if (!(res == 0 || res == -EEXIST)) { | ||
| return -1; | ||
| } | ||
| #endif | ||
| /* Time series database initialization | ||
| * | ||
|
|
@@ -157,7 +180,7 @@ int main(void) | |
| * 128: maximum length of each log | ||
| * ts_locker: The locker object. | ||
| */ | ||
| result = fdb_tsdb_init(&tsdb, "log", FDB_DIR "/fdb_tsdb1", get_time, 128, &ts_locker); | ||
| result = fdb_tsdb_init(&tsdb, "log", TSDB_DIR, get_time, 128, &ts_locker); | ||
| /* read last saved time for simulated timestamp */ | ||
| fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_GET_LAST_TIME, &counts); | ||
|
|
||
|
|
@@ -167,6 +190,10 @@ int main(void) | |
|
|
||
| /* run TSDB sample */ | ||
| tsdb_sample(&tsdb); | ||
|
|
||
| /* deinit the tsdb to make sure all open files are properly closed */ | ||
| fdb_err_t dres = fdb_tsdb_deinit(&tsdb); | ||
| printf("tsdb deinit %s\n", resstr(dres == FDB_NO_ERR)); | ||
| } | ||
| #endif /* FDB_USING_TSDB */ | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this a new requirement?