Skip to content

Commit

Permalink
Merge pull request #759 from jphickey/fix-718-deprecate-bytesblocksfree
Browse files Browse the repository at this point in the history
Fix #718, deprecate OS_fsBlocksFree and OS_fsBytesFree
  • Loading branch information
astrogeco authored Jan 21, 2021
2 parents 2b1211a + 8c7535c commit ff42bfd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 298 deletions.
11 changes: 11 additions & 0 deletions src/os/inc/osapi-filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ int32 OS_rmfs(const char *devname);
*/
int32 OS_unmount(const char *mountpoint);

#ifndef OSAL_OMIT_DEPRECATED

/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtain number of blocks free
Expand All @@ -201,6 +203,10 @@ int32 OS_unmount(const char *mountpoint);
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_ERROR if the OS call failed
*
* @deprecated Replaced by OS_FileSysStatVolume() -
* Value can be obtained by reading the "blocks_free" struct member.
*
*/
int32 OS_fsBlocksFree(const char *name);

Expand All @@ -221,9 +227,14 @@ int32 OS_fsBlocksFree(const char *name);
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_ERROR if the OS call failed
*
* @deprecated Replaced by OS_FileSysStatVolume().
* Value can be obtained by multiplying the "blocks_free" by the "block_size" struct members.
*/
int32 OS_fsBytesFree(const char *name, uint64 *bytes_free);

#endif /* OSAL_OMIT_DEPRECATED */

/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtains information about size and free space in a volume
Expand Down
4 changes: 4 additions & 0 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ int32 OS_unmount(const char *mountpoint)
return return_code;
} /* end OS_unmount */

#ifndef OSAL_OMIT_DEPRECATED

/*----------------------------------------------------------------
*
* Function: OS_fsBlocksFree
Expand Down Expand Up @@ -616,6 +618,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free)

} /* end OS_fsBytesFree */

#endif /* OSAL_OMIT_DEPRECATED */

/*----------------------------------------------------------------
*
* Function: OS_FileSysStatVolume
Expand Down
77 changes: 0 additions & 77 deletions src/unit-test-coverage/shared/src/coveragetest-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,81 +253,6 @@ void Test_OS_unmount(void)
UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual);
}

void Test_OS_fsBlocksFree(void)
{
/*
* Test Case For:
* int32 OS_fsBlocksFree (const char *name)
*/
int32 expected = 1111;
int32 actual = ~OS_SUCCESS;
OS_statvfs_t statval;

statval.block_size = OSAL_SIZE_C(1024);
statval.blocks_free = OSAL_BLOCKCOUNT_C(1111);
statval.total_blocks = OSAL_BLOCKCOUNT_C(2222);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false);
OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM |
OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL;

actual = OS_fsBlocksFree("/cf");
UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == 1111", (long)actual);

expected = OS_INVALID_POINTER;
actual = OS_fsBlocksFree(NULL);
UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_INVALID_POINTER", (long)actual);

UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR);
expected = OS_FS_ERR_PATH_TOO_LONG;
actual = OS_fsBlocksFree("/cf");
UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual);
UT_ClearForceFail(UT_KEY(OCS_memchr));

UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND);
expected = OS_FS_ERR_PATH_INVALID;
actual = OS_fsBlocksFree("invalid");
UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual);
}

void Test_OS_fsBytesFree(void)
{
/*
* Test Case For:
* int32 OS_fsBytesFree (const char *name, uint64 *bytes_free)
*/
int32 expected = OS_SUCCESS;
int32 actual = ~OS_SUCCESS;
OS_statvfs_t statval;
uint64 bytes_free = 0;

statval.block_size = OSAL_SIZE_C(1024);
statval.blocks_free = OSAL_BLOCKCOUNT_C(1111);
statval.total_blocks = OSAL_BLOCKCOUNT_C(2222);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false);
OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM |
OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL;

actual = OS_fsBytesFree("/cf", &bytes_free);

UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_SUCCESS", (long)actual);
UtAssert_True(bytes_free == (1024 * 1111), "bytes_free (%lu) == (1024*1111)", (unsigned long)bytes_free);

expected = OS_INVALID_POINTER;
actual = OS_fsBytesFree(NULL, NULL);
UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_INVALID_POINTER", (long)actual);

UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR);
expected = OS_FS_ERR_PATH_TOO_LONG;
actual = OS_fsBytesFree("/cf", &bytes_free);
UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual);
UT_ClearForceFail(UT_KEY(OCS_memchr));

UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND);
expected = OS_FS_ERR_PATH_INVALID;
actual = OS_fsBytesFree("invalid", &bytes_free);
UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual);
}

void Test_OS_FileSysStatVolume(void)
{
/*
Expand Down Expand Up @@ -625,8 +550,6 @@ void UtTest_Setup(void)
ADD_TEST(OS_initfs);
ADD_TEST(OS_mount);
ADD_TEST(OS_unmount);
ADD_TEST(OS_fsBlocksFree);
ADD_TEST(OS_fsBytesFree);
ADD_TEST(OS_chkfs);
ADD_TEST(OS_FS_GetPhysDriveName);
ADD_TEST(OS_GetFsInfo);
Expand Down
217 changes: 0 additions & 217 deletions src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,223 +1053,6 @@ void UT_os_checkfs_test()
return;
}

/*--------------------------------------------------------------------------------*
** Syntax: int32 OS_fsBlocksFree(const char *name)
** Purpose: Returns the number of blocks free in a the file system
** Parameters: *name - a pointer to the name of the drive to check for free blocks
** Returns: OS_INVALID_POINTER if the pointer passed in is NULL
** OS_FS_ERR_PATH_TOO_LONG if the path passed in is too long
** OS_ERROR if the OS call failed
** Number of blocks free in a volume if succeeded
** OS_ERR_NOT_IMPLEMENTED if not implemented
** -----------------------------------------------------
** Test #0: Not-implemented condition
** 1) Call this routine
** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test
** 3) Otherwise, continue.
** -----------------------------------------------------
** Test #1: Null-pointer-arg condition
** 1) Call this routine with a null pointer as one of the arguments
** 2) Expect the returned value to be
** (a) OS_INVALID_POINTER
** -----------------------------------------------------
** Test #2: Path-too-long-arg condition
** 1) Call this routine with a path name of length greater than Volume table's
** name as argument
** 2) Expect the returned value to be
** (a) OS_FS_ERR_PATH_TOO_LONG
** -----------------------------------------------------
** Test #3: OS-call-failure condition
** 1) Setup the test to cause the OS call to fail inside this routine
** 2) Call this routine
** 3) Expect the returned value to be
** (a) OS_ERROR
** -----------------------------------------------------
** Test#4: Nominal condition
** 1) Make sure no file system has been previously created
** 2) Call OS_mkfs
** 3) Expect the returned value to be
** (a) OS_SUCCESS
** 4) Call OS_mount with device name used in #2
** 5) Expect the returned value to be
** (a) OS_SUCCESS
** 6) Call this routine with mount-point used in #4
** 7) Expect the returned value to be
** (a) greater than or equal to 0
** --------------------------------------------------------------------------------*/
void UT_os_fsblocksfree_test()
{
const char *testDesc;

/*-----------------------------------------------------*/
testDesc = "API not implemented";

if (OS_fsBlocksFree(NULL) == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_fsblocksfree_test_exit_tag;
}

/*-----------------------------------------------------*/
testDesc = "#1 Null-pointer-arg";

if (OS_fsBlocksFree(NULL) == OS_INVALID_POINTER)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#2 Path-too-long-arg";

if (OS_fsBlocksFree(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#3 OS-call-failure";

UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO);

/*-----------------------------------------------------*/
testDesc = "#4 Nominal";

if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS)
{
testDesc = "#4 Nominal - File-system-create failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
goto UT_os_fsblocksfree_test_exit_tag;
}

if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS)
{
testDesc = "#4 Nominal - File-system-mount failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
goto UT_os_fsblocksfree_test_exit_tag;
}

if (OS_fsBlocksFree(g_mntNames[4]) >= 0)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/* Reset test environment */
OS_unmount(g_mntNames[4]);
OS_rmfs(g_devNames[4]);

UT_os_fsblocksfree_test_exit_tag:
return;
}

/*--------------------------------------------------------------------------------*
** Syntax: int32 OS_fsBytesFree(const char *name, uint64 *bytes_free)
** Purpose: Returns the number of bytes free in a the file system
** Parameters: *name - a pointer to the name of the drive to check for free bytes
** *bytes_free - a pointer that will hold the number of bytes free
** Returns: OS_INVALID_POINTER if the pointer passed in is NULL
** OS_ERROR if the OS call failed
** OS_SUCCESS if succeeded
** OS_ERR_NOT_IMPLEMENTED if not implemented
** -----------------------------------------------------
** Test #0: Not-implemented condition
** 1) Call this routine
** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test
** 3) Otherwise, continue.
** -----------------------------------------------------
** Test #1: Null-pointer-arg condition
** 1) Call this routine with a null pointer as one of the arguments
** 2) Expect the returned value to be
** (a) OS_INVALID_POINTER
** -----------------------------------------------------
** Test #2: Path-too-long-arg condition
** 1) Call this routine with a path name of length greater than Volume table's
** name as argument
** 2) Expect the returned value to be
** (a) OS_FS_ERR_PATH_TOO_LONG
** -----------------------------------------------------
** Test #3: OS-call-failure condition
** 1) Setup the test to cause the OS call to fail inside this routine
** 2) Call this routine
** 3) Expect the returned value to be
** (a) OS_ERROR
** -----------------------------------------------------
** Test#4: Nominal condition
** 1) Make sure no file system has been previously created
** 2) Call OS_mkfs
** 3) Expect the returned value to be
** (a) OS_SUCCESS
** 4) Call OS_mount with device name used in #2
** 5) Expect the returned value to be
** (a) OS_SUCCESS
** 6) Call this routine with mount-point used in #4
** 7) Expect the returned value to be
** (a) greater than or equal to 0
** --------------------------------------------------------------------------------*/
void UT_os_fsbytesfree_test()
{
uint64 retBytes = 0;
const char *testDesc;

/*-----------------------------------------------------*/
testDesc = "API not implemented";

if (OS_fsBytesFree(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_fsbytesfree_test_exit_tag;
}

/*-----------------------------------------------------*/
testDesc = "#1 Null-pointer-arg";

if ((OS_fsBytesFree(NULL, &retBytes) == OS_INVALID_POINTER) &&
(OS_fsBytesFree(g_mntNames[1], NULL) == OS_INVALID_POINTER))
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#2 Path-too-long-arg";

if (OS_fsBytesFree(g_fsLongName, &retBytes) == OS_FS_ERR_PATH_TOO_LONG)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#3 OS-call-failure";

UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO);

/*-----------------------------------------------------*/
testDesc = "#4 Nominal";

if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS)
{
testDesc = "#4 Nominal - File-system-create failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
goto UT_os_fsbytesfree_test_exit_tag;
}

if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS)
{
testDesc = "#4 Nominal - File-system-mount failed";
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF);
goto UT_os_fsbytesfree_test_exit_tag;
}

if (OS_fsBytesFree(g_mntNames[4], &retBytes) == OS_SUCCESS)
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS);
else
UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE);

/* Reset test environment */
OS_unmount(g_mntNames[4]);
OS_rmfs(g_devNames[4]);

UT_os_fsbytesfree_test_exit_tag:
return;
}

/*--------------------------------------------------------------------------------*
** Syntax: int32 OS_fsstatvolume(const char *name)
Expand Down
2 changes: 0 additions & 2 deletions src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void UT_os_translatepath_test(void);

void UT_os_checkfs_test(void);

void UT_os_fsblocksfree_test(void);
void UT_os_fsbytesfree_test(void);
void UT_os_fsstatvolume_test(void);

/*--------------------------------------------------------------------------------*/
Expand Down
2 changes: 0 additions & 2 deletions src/unit-tests/osfilesys-test/ut_osfilesys_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ void UtTest_Setup(void)
UtTest_Add(UT_os_translatepath_test, NULL, NULL, "OS_TranslatePath (internal)");

UtTest_Add(UT_os_checkfs_test, NULL, NULL, "OS_chkfs");
UtTest_Add(UT_os_fsblocksfree_test, NULL, NULL, "OS_fsBlocksFree");
UtTest_Add(UT_os_fsbytesfree_test, NULL, NULL, "OS_fsBytesFree");
UtTest_Add(UT_os_fsstatvolume_test, NULL, NULL, "OS_FileSysStatVolume");
}

Expand Down
Loading

0 comments on commit ff42bfd

Please sign in to comment.