tests: posix: fs: add test suite for ftruncate

Add test suite support for posix ftruncate

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
This commit is contained in:
Karthikeyan Krishnasamy 2024-04-13 16:23:29 +05:30 committed by Chris Friedt
parent cd1ed1cdbf
commit 8c8868c51e
1 changed files with 32 additions and 0 deletions

View File

@ -159,6 +159,25 @@ static int test_file_fsync(void)
return res;
}
static int test_file_truncate(void)
{
int res = 0;
size_t truncate_size = sizeof(test_str) - 4;
if (file < 0)
return res;
res = ftruncate(file, truncate_size);
if (res) {
TC_PRINT("Error truncating file [%d]\n", res);
res = TC_FAIL;
}
close(file);
file = -1;
return res;
}
static int test_file_delete(void)
{
int res;
@ -232,6 +251,19 @@ ZTEST(posix_fs_file_test, test_fs_sync)
zassert_true(test_file_fsync() == TC_PASS);
}
/**
* @brief Test for POSIX ftruncate API
*
* @details Test truncate the file through POSIX ftruncate API.
*/
ZTEST(posix_fs_file_test, test_fs_truncate)
{
/* FIXME: restructure tests as per #46897 */
zassert_true(test_file_open() == TC_PASS);
zassert_true(test_file_write() == TC_PASS);
zassert_true(test_file_truncate() == TC_PASS);
}
/**
* @brief Test for POSIX close API
*