posix: fs: implement fdatasync()
`fdatasync()` is basically equivalent to `fsync()` according to the standards. Added test for it. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
11bd1dae33
commit
91abf0e329
5 changed files with 50 additions and 2 deletions
|
@ -159,6 +159,26 @@ static int test_file_fsync(void)
|
|||
return res;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
|
||||
static int test_file_fdatasync(void)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (file < 0)
|
||||
return res;
|
||||
|
||||
res = fdatasync(file);
|
||||
if (res < 0) {
|
||||
TC_ERROR("Failed to sync file: %d, errno = %d\n", res, errno);
|
||||
res = TC_FAIL;
|
||||
}
|
||||
|
||||
close(file);
|
||||
file = -1;
|
||||
return res;
|
||||
}
|
||||
#endif /* CONFIG_POSIX_SYNCHRONIZED_IO */
|
||||
|
||||
static int test_file_truncate(void)
|
||||
{
|
||||
int res = 0;
|
||||
|
@ -251,6 +271,23 @@ ZTEST(posix_fs_file_test, test_fs_sync)
|
|||
zassert_true(test_file_fsync() == TC_PASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test for POSIX fdatasync API
|
||||
*
|
||||
* @details Test sync the file through POSIX fdatasync API.
|
||||
*/
|
||||
ZTEST(posix_fs_file_test, test_fs_datasync)
|
||||
{
|
||||
#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
|
||||
/* FIXME: restructure tests as per #46897 */
|
||||
zassert_true(test_file_open() == TC_PASS);
|
||||
zassert_true(test_file_write() == TC_PASS);
|
||||
zassert_true(test_file_fdatasync() == TC_PASS);
|
||||
#else
|
||||
ztest_test_skip();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test for POSIX ftruncate API
|
||||
*
|
||||
|
|
|
@ -230,7 +230,7 @@ ZTEST(posix_headers, test_unistd_h)
|
|||
/* zassert_not_null(fchdir); */ /* not implemented */
|
||||
/* zassert_not_null(fchown); */ /* not implemented */
|
||||
/* zassert_not_null(fchownat); */ /* not implemented */
|
||||
/* zassert_not_null(fdatasync); */ /* not implemented */
|
||||
zassert_not_null(fdatasync);
|
||||
/* zassert_not_null(fexecve); */ /* not implemented */
|
||||
/* zassert_not_null(fork); */ /* not implemented */
|
||||
/* zassert_not_null(fpathconf); */ /* not implemented */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue