Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/flashdb/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PKG_NAME=flashdb
PKG_URL=https://github.com/armink/FlashDB.git
# 2.1.1
PKG_VERSION=714d6159e7e6afb267a3953756abca445c350e61
# 2.1.1 +7 commits
PKG_VERSION=b1043ed10defdeec6f97c4099cb212a777a727fe
PKG_LICENSE=Apache-2.0

include $(RIOTBASE)/pkg/pkg.mk
Expand Down
69 changes: 0 additions & 69 deletions pkg/flashdb/patches/0001-remove-example-fdb_cfg.h.patch

This file was deleted.

2 changes: 1 addition & 1 deletion tests/pkg/flashdb_vfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ USEMODULE += libc_gettimeofday
USEMODULE += vfs_default
USEMODULE += vfs_auto_format

CFLAGS += -DTHREAD_STACKSIZE_MAIN=THREAD_STACKSIZE_LARGE
CFLAGS += -DTHREAD_STACKSIZE_MAIN=THREAD_STACKSIZE_LARGE*2
Copy link
Contributor

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?


include $(RIOTBASE)/Makefile.include
28 changes: 19 additions & 9 deletions tests/pkg/flashdb_vfs/kvdb_basic_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,21 +29,29 @@ 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 */
Copy link
Contributor

@mguetschow mguetschow Nov 21, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 (git diff --name-only b1043ed10defdeec6f97c4099cb212a777a727fe 2.1.1 tests samples in the FlashDB repo lists nothing). As I pointed out in the PR description in the long run it would probably be better to replace our tests with the the package tests instead of using the examples for testing. But the changes of this PR already grew bigger than I anticipated for a quick version bump ;)

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)));
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int res = fdb_kv_set_blob(kvdb, "boot_count",
fdb_err_t res = fdb_kv_set_blob(kvdb, "boot_count",

is the correct return type

fdb_blob_make(&blob, &boot_count, sizeof(boot_count)));
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int res = fdb_kv_get_blob(kvdb, "boot_count",
size_t res = fdb_kv_get_blob(kvdb, "boot_count",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(could also be its own function as this is basically duplicated from above)

fdb_blob_make(&blob, &boot_count, sizeof(boot_count)));
printf("get the 'boot_count' value is %d %s\n", boot_count,
resstr(res == sizeof(boot_count) && boot_count == expected));
}

printf("===========================================================\n");
Expand Down
65 changes: 32 additions & 33 deletions tests/pkg/flashdb_vfs/kvdb_type_blob_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,44 @@

#define FDB_LOG_TAG "[sample][kvdb][blob]"

extern const char *resstr(bool condition);

void kvdb_type_blob_sample(fdb_kvdb_t kvdb)
{
struct fdb_blob blob;

printf("================== kvdb_type_blob_sample ==================\n");

{ /* CREATE new Key-Value */
int temp_data = 36;

/* It will create new KV node when "temp" KV not in database.
* fdb_blob_make: It's a blob make function, and it will return the blob when make finish.
*/
fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
printf("create the 'temp' blob KV, value is: %d\n", temp_data);
}

{ /* GET the KV value */
int temp_data = 0;

/* get the "temp" KV value */
fdb_kv_get_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
/* the blob.saved.len is more than 0 when get the value successful */
if (blob.saved.len > 0) {
printf("get the 'temp' value is: %d\n", temp_data);
}
}

{ /* CHANGE the KV value */
int temp_data = 38;

/* change the "temp" KV's value to 38 */
fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
printf("set 'temp' value to %d\n", temp_data);
}

{ /* DELETE the KV by name */
fdb_kv_del(kvdb, "temp");
printf("delete the 'temp' finish\n");
}
/* CREATE new Key-Value */
int temp_data1 = 36;

/* It will create new KV node when "temp" KV not in database.
* fdb_blob_make: It's a blob make function, and it will return the blob when make finish.
*/
fdb_err_t res = fdb_kv_set_blob(kvdb, "temp",
fdb_blob_make(&blob, &temp_data1, sizeof(temp_data1)));
printf("create the 'temp' blob KV, value is: %d %s\n", temp_data1,
resstr(res == FDB_NO_ERR));

/* GET the KV value */
int temp_data2 = 0;

/* get the "temp" KV value */
size_t len = fdb_kv_get_blob(kvdb, "temp",
fdb_blob_make(&blob, &temp_data2, sizeof(temp_data2)));
printf("get the 'temp' value is: %d %s\n", temp_data2,
resstr(len == sizeof(temp_data2) && temp_data1 == temp_data2));

/* CHANGE the KV value */
int temp_data = 38;

/* change the "temp" KV's value to 38 */
res = fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
printf("set 'temp' value to %d %s\n", temp_data, resstr(res == FDB_NO_ERR));

/* DELETE the KV by name */
res = fdb_kv_del(kvdb, "temp");
printf("delete the 'temp' finish %s\n", resstr(res == FDB_NO_ERR));

printf("===========================================================\n");
}
Expand Down
58 changes: 30 additions & 28 deletions tests/pkg/flashdb_vfs/kvdb_type_string_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,46 @@

#define FDB_LOG_TAG "[sample][kvdb][string]"

extern const char *resstr(bool condition);

void kvdb_type_string_sample(fdb_kvdb_t kvdb)
{
printf("================= kvdb_type_string_sample =================\n");

{ /* CREATE new Key-Value */
char temp_data[10] = "36C";
/* CREATE new Key-Value */
char temp_data1[10] = "36C";

/* It will create new KV node when "temp" KV not in database. */
fdb_kv_set(kvdb, "temp", temp_data);
printf("create the 'temp' string KV, value is: %s\n", temp_data);
}
/* It will create new KV node when "temp" KV not in database. */
fdb_err_t res = fdb_kv_set(kvdb, "temp", temp_data1);
printf("create the 'temp' string KV, value is: %s %s\n", temp_data1,
resstr(res == FDB_NO_ERR));

/* GET the KV value */
char *return_value, temp_data2[10] = { 0 };

{ /* GET the KV value */
char *return_value, temp_data[10] = { 0 };

/* Get the "temp" KV value.
* NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible.
*/
return_value = fdb_kv_get(kvdb, "temp");
/* the return value is NULL when get the value failed */
if (return_value != NULL) {
strncpy(temp_data, return_value, sizeof(temp_data));
printf("get the 'temp' value is: %s\n", temp_data);
}
/* Get the "temp" KV value.
* NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible.
*/
return_value = fdb_kv_get(kvdb, "temp");
/* the return value is NULL when get the value failed */
if (return_value != NULL) {
strncpy(temp_data2, return_value, sizeof(temp_data2));
printf("get the 'temp' value is: %s %s\n", temp_data2,
resstr(memcmp(temp_data1, temp_data2, sizeof(temp_data1)) == 0));
} else {
printf("get the 'temp' value %s\n", resstr(false));
}

{ /* CHANGE the KV value */
char temp_data[10] = "38C";
/* CHANGE the KV value */
char temp_data3[10] = "38C";

/* change the "temp" KV's value to "38.1" */
fdb_kv_set(kvdb, "temp", temp_data);
printf("set 'temp' value to %s\n", temp_data);
}
/* change the "temp" KV's value to "38.1" */
res = fdb_kv_set(kvdb, "temp", temp_data3);
printf("set 'temp' value to %s %s\n", temp_data3, resstr(res == FDB_NO_ERR));

{ /* DELETE the KV by name */
fdb_kv_del(kvdb, "temp");
printf("delete the 'temp' finish\n");
}
/* DELETE the KV by name */
res = fdb_kv_del(kvdb, "temp");
printf("delete the 'temp' finish %s\n", resstr(res == FDB_NO_ERR));

printf("===========================================================\n");
}
Expand Down
37 changes: 32 additions & 5 deletions tests/pkg/flashdb_vfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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")

static mutex_t kv_locker, ts_locker;
static uint32_t boot_count = 0;
static time_t boot_time[10] = {0, 1, 2, 3};
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no static inline function in a header file that can be included in the c files instead of explicitly declaring extern resstr everywhere?


int main(void)
{
fdb_err_t result;
Expand All @@ -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));
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);
Expand All @@ -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;
Expand All @@ -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 */

Expand All @@ -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
*
Expand All @@ -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);

Expand All @@ -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 */

Expand Down
Loading
Loading