Skip to content

Commit

Permalink
[test] update the autotest bsp and testcase to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
armink committed Sep 17, 2024
1 parent fd08d7f commit 8e8fc16
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 26 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: AutoTestCI
on: push
on: [push, pull_request]
jobs:
test:
name: AutoTest
runs-on: ubuntu-latest
env:
TEST_BSP_ROOT: ../AutoTestBsp
UTEST_RUNNER_PATH: ../UtestRunner
RTT_EXEC_PATH: /opt/gcc-arm-none-eabi-6-2017-q2-update/bin
RTT_EXEC_PATH: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin
steps:
- uses: actions/checkout@v1
- name: Prepare env
run: |
sudo apt-get update
sudo apt-get -yqq install scons qemu-system git
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/arm-2017q2-v6/gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2
sudo tar xjf gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 -C /opt
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
git clone https://github.com/armink/UtestRunner.git $UTEST_RUNNER_PATH
git clone https://github.com/armink/FlashDBAutoTestBSP.git $TEST_BSP_ROOT
- name: Build bsp
Expand All @@ -25,7 +25,7 @@ jobs:
cp -rf inc/fdb_def.h $TEST_BSP_ROOT/packages/FlashDB/inc/fdb_def.h
cp -rf inc/fdb_low_lvl.h $TEST_BSP_ROOT/packages/FlashDB/inc/fdb_low_lvl.h
cp -rf inc/flashdb.h $TEST_BSP_ROOT/packages/FlashDB/inc/flashdb.h
/opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-gcc --version
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
scons -j$(nproc) -C $TEST_BSP_ROOT
- name: Start test
run: |
Expand Down
16 changes: 12 additions & 4 deletions tests/fdb_kvdb_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ static void test_fdb_create_kv_blob(void)
static void test_fdb_change_kv_blob(void)
{
fdb_err_t result = FDB_NO_ERR;
rt_tick_t tick = rt_tick_get(), read_tick;
rt_tick_t tick = 0, read_tick;
size_t read_len;
struct fdb_blob blob_obj, *blob = &blob_obj;

read_len = fdb_kv_get_blob(&test_kvdb, TEST_KV_BLOB_NAME, fdb_blob_make(&blob_obj, &read_tick, sizeof(read_tick)));
uassert_int_equal(blob->saved.len, sizeof(read_tick));
uassert_int_equal(blob->saved.len, read_len);
rt_thread_mdelay(1);
tick = rt_tick_get();
uassert_int_not_equal(tick, read_tick);

result = fdb_kv_set_blob(&test_kvdb, TEST_KV_BLOB_NAME, fdb_blob_make(&blob_obj, &tick, sizeof(tick)));
Expand All @@ -200,13 +202,15 @@ static void test_fdb_change_kv_blob(void)
static void test_fdb_del_kv_blob(void)
{
fdb_err_t result = FDB_NO_ERR;
rt_tick_t tick = rt_tick_get(), read_tick;
rt_tick_t tick = 0, read_tick;
size_t read_len;
struct fdb_blob blob;

read_len = fdb_kv_get_blob(&test_kvdb, TEST_KV_BLOB_NAME, fdb_blob_make(&blob, &read_tick, sizeof(read_tick)));
uassert_int_equal(blob.saved.len, sizeof(read_tick));
uassert_int_equal(blob.saved.len, read_len);
rt_thread_mdelay(1);
tick = rt_tick_get();
uassert_int_not_equal(tick, read_tick);

result = fdb_kv_set_blob(&test_kvdb, TEST_KV_BLOB_NAME, fdb_blob_make(&blob, NULL, 0));
Expand Down Expand Up @@ -236,12 +240,14 @@ static void test_fdb_create_kv(void)
static void test_fdb_change_kv(void)
{
fdb_err_t result = FDB_NO_ERR;
rt_tick_t tick = rt_tick_get(), read_tick;
rt_tick_t tick = 0, read_tick;
char value_buf[14], *read_value;

read_value = fdb_kv_get(&test_kvdb, TEST_KV_NAME);
uassert_not_null(read_value);
read_tick = atoi(read_value);
rt_thread_mdelay(1);
tick = rt_tick_get();
uassert_int_not_equal(tick, read_tick);

snprintf(value_buf, sizeof(value_buf), "%" PRIu32, tick);
Expand All @@ -264,12 +270,14 @@ static void fdb_reboot(void)
static void test_fdb_del_kv(void)
{
fdb_err_t result = FDB_NO_ERR;
rt_tick_t tick = rt_tick_get(), read_tick;
rt_tick_t tick = 0, read_tick;
char *read_value;

read_value = fdb_kv_get(&test_kvdb, TEST_KV_NAME);
uassert_not_null(read_value);
read_tick = atoi(read_value);
rt_thread_mdelay(1);
tick = rt_tick_get();
uassert_int_not_equal(tick, read_tick);

result = fdb_kv_del(&test_kvdb, TEST_KV_NAME);
Expand Down
124 changes: 107 additions & 17 deletions tests/fdb_tsdb_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,27 @@ static void test_fdb_tsdb_init_ex(void)

uint32_t sec_size = TEST_SECTOR_SIZE, db_size = sec_size * 16;
rt_bool_t file_mode = true;
fdb_kvdb_control((fdb_kvdb_t)&(test_tsdb), FDB_TSDB_CTRL_SET_SEC_SIZE, &sec_size);
fdb_kvdb_control((fdb_kvdb_t)&(test_tsdb), FDB_TSDB_CTRL_SET_FILE_MODE, &file_mode);
fdb_kvdb_control((fdb_kvdb_t)&(test_tsdb), FDB_TSDB_CTRL_SET_MAX_SIZE, &db_size);

memset(&test_tsdb, 0, sizeof(struct fdb_tsdb));
fdb_tsdb_control((fdb_tsdb_t)&(test_tsdb), FDB_TSDB_CTRL_SET_SEC_SIZE, &sec_size);
fdb_tsdb_control((fdb_tsdb_t)&(test_tsdb), FDB_TSDB_CTRL_SET_FILE_MODE, &file_mode);
fdb_tsdb_control((fdb_tsdb_t)&(test_tsdb), FDB_TSDB_CTRL_SET_MAX_SIZE, &db_size);

uassert_true(fdb_tsdb_init(&test_tsdb, "test_ts", TEST_TS_PART_NAME, get_time, 128, NULL) == FDB_NO_ERR);
}

static void test_fdb_tsdb_deinit(void)
{
uassert_true(fdb_tsdb_deinit(&test_tsdb) == FDB_NO_ERR);
}

/* check reboot status */
static void fdb_reboot(void)
{
test_fdb_tsdb_deinit();
test_fdb_tsdb_init_ex();
}

static void test_fdb_tsl_append(void)
{
struct fdb_blob blob;
Expand Down Expand Up @@ -101,13 +115,15 @@ static bool test_fdb_tsl_iter_cb(fdb_tsl_t tsl, void *arg)

static void test_fdb_tsl_iter(void)
{
fdb_reboot();
fdb_tsl_iter(&test_tsdb, test_fdb_tsl_iter_cb, NULL);
}

static void test_fdb_tsl_iter_by_time(void)
{
fdb_time_t from = 0, to = TEST_TS_COUNT * TEST_TIME_STEP - 1;

fdb_reboot();
for (fdb_time_t cur = from; cur <= to; cur += TEST_TIME_STEP) {
fdb_tsl_iter_by_time(&test_tsdb, cur, cur, test_fdb_tsl_iter_cb, &cur);
}
Expand All @@ -118,6 +134,7 @@ static void test_fdb_tsl_query_count(void)
{
fdb_time_t from = 0, to = TEST_TS_COUNT * TEST_TIME_STEP;

fdb_reboot();
uassert_true(fdb_tsl_query_count(&test_tsdb, from, to, FDB_TSL_WRITE) == TEST_TS_COUNT);
}

Expand All @@ -138,6 +155,7 @@ static void test_fdb_tsl_set_status(void)
{
fdb_time_t from = 0, to = TEST_TS_COUNT * TEST_TIME_STEP;

fdb_reboot();
fdb_tsl_iter_by_time(&test_tsdb, from, to, est_fdb_tsl_set_status_cb, &test_tsdb);

uassert_true(fdb_tsl_query_count(&test_tsdb, from, to, FDB_TSL_USER_STATUS1) == TEST_TS_USER_STATUS1_COUNT);
Expand All @@ -158,8 +176,13 @@ static void test_fdb_tsl_clean(void)
size_t count = 0;

cur_times = 0;

fdb_reboot();
fdb_tsl_clean(&test_tsdb);
fdb_tsl_iter(&test_tsdb, test_fdb_tsl_clean_cb, &count);
uassert_true(count == 0);

fdb_reboot();
fdb_tsl_iter(&test_tsdb, test_fdb_tsl_clean_cb, &count);

uassert_true(count == 0);
Expand Down Expand Up @@ -286,6 +309,29 @@ static void test_tsdb_data_by_time(fdb_time_t from, fdb_time_t to)
}
}

static void test_fdb_tsl_sector_bound_test(int start_sec_index, int end_sec_index)
{
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time - 1, test_secs_info[end_sec_index].end_time + 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time - 1, test_secs_info[end_sec_index].end_time + 0);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time - 1, test_secs_info[end_sec_index].end_time - 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time + 0, test_secs_info[end_sec_index].end_time + 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time + 0, test_secs_info[end_sec_index].end_time + 0);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time + 0, test_secs_info[end_sec_index].end_time - 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time + 1, test_secs_info[end_sec_index].end_time + 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time + 1, test_secs_info[end_sec_index].end_time + 0);
test_tsdb_data_by_time(test_secs_info[start_sec_index].start_time + 1, test_secs_info[end_sec_index].end_time - 1);

test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time - 1, test_secs_info[end_sec_index].start_time + 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time - 1, test_secs_info[end_sec_index].start_time + 0);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time - 1, test_secs_info[end_sec_index].start_time - 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time + 0, test_secs_info[end_sec_index].start_time + 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time + 0, test_secs_info[end_sec_index].start_time + 0);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time + 0, test_secs_info[end_sec_index].start_time - 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time + 1, test_secs_info[end_sec_index].start_time + 1);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time + 1, test_secs_info[end_sec_index].start_time + 0);
test_tsdb_data_by_time(test_secs_info[start_sec_index].end_time + 1, test_secs_info[end_sec_index].start_time - 1);
}

static void test_fdb_tsl_iter_by_time_1(void)
{
struct fdb_blob blob;
Expand All @@ -296,6 +342,9 @@ static void test_fdb_tsl_iter_by_time_1(void)
for (data = 0; data < 800; data++) {
fdb_tsl_append(&test_tsdb, fdb_blob_make(&blob, &data, sizeof(data)));
}

fdb_reboot();

/* init all test sectors info */
for (i = 0; i < sizeof(test_secs_info) / sizeof(test_secs_info[0]); i++) {
test_secs_info[i].addr = TEST_SECTOR_SIZE * i;
Expand Down Expand Up @@ -347,25 +396,64 @@ static void test_fdb_tsl_iter_by_time_1(void)
test_tsdb_data_by_time(test_secs_info[0].end_time, test_secs_info[0].start_time);

/* check 1~2 sector */
test_tsdb_data_by_time(test_secs_info[0].start_time - 1, test_secs_info[1].end_time);
test_tsdb_data_by_time(test_secs_info[0].start_time + 1, test_secs_info[1].end_time);
test_tsdb_data_by_time(test_secs_info[0].end_time + 1, test_secs_info[1].end_time);
test_tsdb_data_by_time(test_secs_info[1].end_time + 1, test_secs_info[0].start_time);
test_tsdb_data_by_time(test_secs_info[1].end_time - 1, test_secs_info[0].start_time);
test_tsdb_data_by_time(test_secs_info[1].start_time - 1, test_secs_info[0].start_time);
test_fdb_tsl_sector_bound_test(0, 0);
test_fdb_tsl_sector_bound_test(0, 1);
test_fdb_tsl_sector_bound_test(1, 0);
test_fdb_tsl_sector_bound_test(1, 1);

/* check more than 2 sectors */
test_tsdb_data_by_time(test_secs_info[0].start_time - 1, test_secs_info[2].end_time);
test_tsdb_data_by_time(test_secs_info[0].start_time + 1, test_secs_info[2].end_time);
test_tsdb_data_by_time(test_secs_info[0].end_time + 1, test_secs_info[2].end_time);
test_tsdb_data_by_time(test_secs_info[2].end_time + 1, test_secs_info[0].start_time);
test_tsdb_data_by_time(test_secs_info[2].end_time - 1, test_secs_info[0].start_time);
test_tsdb_data_by_time(test_secs_info[2].start_time - 1, test_secs_info[0].start_time);
test_fdb_tsl_sector_bound_test(0, 2);
test_fdb_tsl_sector_bound_test(2, 0);
test_fdb_tsl_sector_bound_test(2, 2);
}

static void test_fdb_tsdb_deinit(void)
static void test_fdb_github_issue_249(void)
{
uassert_true(fdb_tsdb_deinit(&test_tsdb) == FDB_NO_ERR);
if (access("storage_tsdb", 0) < 0)
{
mkdir("storage_tsdb", 0);
}

uint32_t sec_size = 16 * 1024, db_size = 512 * 1024, test_data_size = 0;
rt_bool_t file_mode = true, flag_not_format = false;
struct fdb_blob blob;
uint8_t *data = NULL;

memset(&test_tsdb, 0, sizeof(struct fdb_tsdb));
fdb_tsdb_control((fdb_tsdb_t) & (test_tsdb), FDB_TSDB_CTRL_SET_SEC_SIZE, &sec_size);
fdb_tsdb_control((fdb_tsdb_t) & (test_tsdb), FDB_TSDB_CTRL_SET_FILE_MODE, &file_mode);
fdb_tsdb_control((fdb_tsdb_t) & (test_tsdb), FDB_TSDB_CTRL_SET_NOT_FORMAT, &flag_not_format);
fdb_tsdb_control((fdb_tsdb_t) & (test_tsdb), FDB_TSDB_CTRL_SET_MAX_SIZE, &db_size);

uassert_true(fdb_tsdb_init(&test_tsdb, "storage_tsdb", "storage_tsdb", get_time, 10*1024, NULL) == FDB_NO_ERR);
/* clean status */
fdb_tsl_clean(&test_tsdb);
cur_times = 0;

test_data_size = 7 * 1024;
data = rt_malloc(test_data_size);
uassert_true(data != NULL);
uassert_true(fdb_tsl_append(&test_tsdb, fdb_blob_make(&blob, data, test_data_size)) == FDB_NO_ERR);
rt_free(data);

test_data_size = 8 * 1024;
data = rt_malloc(test_data_size);
uassert_true(data != NULL);
uassert_true(fdb_tsl_append(&test_tsdb, fdb_blob_make(&blob, data, test_data_size)) == FDB_NO_ERR);
rt_free(data);

test_data_size = 9 * 1024;
data = rt_malloc(test_data_size);
uassert_true(data != NULL);
uassert_true(fdb_tsl_append(&test_tsdb, fdb_blob_make(&blob, data, test_data_size)) == FDB_NO_ERR);
rt_free(data);

{ /* reboot simulation */
uassert_true(fdb_tsdb_deinit(&test_tsdb) == FDB_NO_ERR);
uassert_true(fdb_tsdb_init(&test_tsdb, "storage_tsdb", "storage_tsdb", get_time, 10 * 1024, NULL) == FDB_NO_ERR);
}
uassert_true(fdb_tsl_query_count(&test_tsdb, 2, 6, FDB_TSL_WRITE) == 3);
uassert_true(fdb_tsl_query_count(&test_tsdb, 0, INT32_MAX, FDB_TSL_WRITE) == 3);
}

static void testcase(void)
Expand All @@ -380,6 +468,8 @@ static void testcase(void)
UTEST_UNIT_RUN(test_fdb_tsl_clean);
UTEST_UNIT_RUN(test_fdb_tsl_iter_by_time_1);
UTEST_UNIT_RUN(test_fdb_tsdb_deinit);

UTEST_UNIT_RUN(test_fdb_github_issue_249);
}

UTEST_TC_EXPORT(testcase, "packages.system.flashdb.tsdb", utest_tc_init, utest_tc_cleanup, 20);
Expand Down

0 comments on commit 8e8fc16

Please sign in to comment.