tests: subsys: storage: move stream to new ztest API
Move test stream to use new ztest API. Signed-off-by: Yinfang Wang <yinfang.wang@intel.com>
This commit is contained in:
parent
28608d158e
commit
1ce5b4c037
2 changed files with 22 additions and 38 deletions
|
@ -14,3 +14,4 @@ CONFIG_SETTINGS=y
|
||||||
CONFIG_STREAM_FLASH=y
|
CONFIG_STREAM_FLASH=y
|
||||||
CONFIG_STREAM_FLASH_ERASE=y
|
CONFIG_STREAM_FLASH_ERASE=y
|
||||||
CONFIG_STREAM_FLASH_PROGRESS=y
|
CONFIG_STREAM_FLASH_PROGRESS=y
|
||||||
|
CONFIG_ZTEST_NEW_API=y
|
||||||
|
|
|
@ -98,7 +98,7 @@ static void init_target(void)
|
||||||
zassert_equal(rc, 0, "expected success");
|
zassert_equal(rc, 0, "expected success");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_init(void)
|
ZTEST(lib_stream_flash, test_stream_flash_init)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ static void test_stream_flash_init(void)
|
||||||
zassert_equal(FLASH_AVAILABLE, ctx.available, "Wrong size");
|
zassert_equal(FLASH_AVAILABLE, ctx.available, "Wrong size");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buffered_write(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ static void test_stream_flash_buffered_write(void)
|
||||||
VERIFY_WRITTEN(0, BUF_LEN);
|
VERIFY_WRITTEN(0, BUF_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buffered_write_cross_buf_border(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write_cross_buf_border)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ static void test_stream_flash_buffered_write_cross_buf_border(void)
|
||||||
VERIFY_WRITTEN(0, BUF_LEN * 2 + BUF_LEN / 2);
|
VERIFY_WRITTEN(0, BUF_LEN * 2 + BUF_LEN / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buffered_write_unaligned(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write_unaligned)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ static void test_stream_flash_buffered_write_unaligned(void)
|
||||||
VERIFY_WRITTEN(BUF_LEN, BUF_LEN - 1);
|
VERIFY_WRITTEN(BUF_LEN, BUF_LEN - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buffered_write_multi_page(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write_multi_page)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int num_pages = MAX_NUM_PAGES - 1;
|
int num_pages = MAX_NUM_PAGES - 1;
|
||||||
|
@ -232,7 +232,7 @@ static void test_stream_flash_buffered_write_multi_page(void)
|
||||||
VERIFY_WRITTEN(0, BUF_LEN * (num_pages + 1));
|
VERIFY_WRITTEN(0, BUF_LEN * (num_pages + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_bytes_written(void)
|
ZTEST(lib_stream_flash, test_stream_flash_bytes_written)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
|
@ -258,7 +258,7 @@ static void test_stream_flash_bytes_written(void)
|
||||||
VERIFY_WRITTEN(BUF_LEN, BUF_LEN);
|
VERIFY_WRITTEN(BUF_LEN, BUF_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buf_size_greater_than_page_size(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buf_size_greater_than_page_size)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ static int bad_write(const struct device *dev, off_t off, const void *data, size
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buffered_write_callback(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write_callback)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ static void test_stream_flash_buffered_write_callback(void)
|
||||||
"Expected %d bytes added to buffer", tow);
|
"Expected %d bytes added to buffer", tow);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_flush(void)
|
ZTEST(lib_stream_flash, test_stream_flash_flush)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ static void test_stream_flash_flush(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_STREAM_FLASH_ERASE
|
#ifdef CONFIG_STREAM_FLASH_ERASE
|
||||||
static void test_stream_flash_buffered_write_whole_page(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write_whole_page)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ static int bad_erase(const struct device *dev, off_t offset, size_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_erase_page(void)
|
ZTEST(lib_stream_flash, test_stream_flash_erase_page)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -452,12 +452,12 @@ static void test_stream_flash_erase_page(void)
|
||||||
zassert_equal(rc, -EINVAL, "Expected failure");
|
zassert_equal(rc, -EINVAL, "Expected failure");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void test_stream_flash_erase_page(void)
|
ZTEST(lib_stream_flash, test_stream_flash_erase_page)
|
||||||
{
|
{
|
||||||
ztest_test_skip();
|
ztest_test_skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_buffered_write_whole_page(void)
|
ZTEST(lib_stream_flash, test_stream_flash_buffered_write_whole_page)
|
||||||
{
|
{
|
||||||
ztest_test_skip();
|
ztest_test_skip();
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ static size_t load_progress(const char *load_key)
|
||||||
return stream_flash_bytes_written(&ctx);
|
return stream_flash_bytes_written(&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_progress_api(void)
|
ZTEST(lib_stream_flash, test_stream_flash_progress_api)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ static void test_stream_flash_progress_api(void)
|
||||||
zassert_equal(rc, 0, "expected success");
|
zassert_equal(rc, 0, "expected success");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_progress_resume(void)
|
ZTEST(lib_stream_flash, test_stream_flash_progress_resume)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
size_t bytes_written_old;
|
size_t bytes_written_old;
|
||||||
|
@ -603,7 +603,7 @@ static void test_stream_flash_progress_resume(void)
|
||||||
"expected bytes_written to not be overwritten");
|
"expected bytes_written to not be overwritten");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_stream_flash_progress_clear(void)
|
ZTEST(lib_stream_flash, test_stream_flash_progress_clear)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
size_t bytes_written_old;
|
size_t bytes_written_old;
|
||||||
|
@ -643,32 +643,15 @@ static void test_stream_flash_progress_clear(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_main(void)
|
void lib_stream_flash_before(void *data)
|
||||||
{
|
{
|
||||||
__ASSERT_NO_MSG(device_is_ready(fdev));
|
zassume_true(device_is_ready(fdev), "Device is not ready");
|
||||||
|
|
||||||
api = fdev->api;
|
api = fdev->api;
|
||||||
api->page_layout(fdev, &layout, &layout_size);
|
api->page_layout(fdev, &layout, &layout_size);
|
||||||
|
|
||||||
page_size = layout->pages_size;
|
page_size = layout->pages_size;
|
||||||
__ASSERT_NO_MSG(page_size > BUF_LEN);
|
zassume_true((page_size > BUF_LEN), "page size is not enough");
|
||||||
|
|
||||||
ztest_test_suite(lib_stream_flash_test,
|
|
||||||
ztest_unit_test(test_stream_flash_init),
|
|
||||||
ztest_unit_test(test_stream_flash_buffered_write),
|
|
||||||
ztest_unit_test(test_stream_flash_buffered_write_cross_buf_border),
|
|
||||||
ztest_unit_test(test_stream_flash_buffered_write_unaligned),
|
|
||||||
ztest_unit_test(test_stream_flash_buffered_write_multi_page),
|
|
||||||
ztest_unit_test(test_stream_flash_buf_size_greater_than_page_size),
|
|
||||||
ztest_unit_test(test_stream_flash_buffered_write_callback),
|
|
||||||
ztest_unit_test(test_stream_flash_flush),
|
|
||||||
ztest_unit_test(test_stream_flash_buffered_write_whole_page),
|
|
||||||
ztest_unit_test(test_stream_flash_erase_page),
|
|
||||||
ztest_unit_test(test_stream_flash_bytes_written),
|
|
||||||
ztest_unit_test(test_stream_flash_progress_api),
|
|
||||||
ztest_unit_test(test_stream_flash_progress_resume),
|
|
||||||
ztest_unit_test(test_stream_flash_progress_clear)
|
|
||||||
);
|
|
||||||
|
|
||||||
ztest_run_test_suite(lib_stream_flash_test);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZTEST_SUITE(lib_stream_flash, NULL, NULL, lib_stream_flash_before, NULL, NULL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue