diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 1fc6b84a5..2ff84524f 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -424,18 +424,19 @@ void TestReadWriteLseek(void) ---------------------------------------------------------------------------------------*/ void TestMkRmDirFreeBytes(void) { - int32 status; - char filename1[OS_MAX_PATH_LEN]; - char filename2[OS_MAX_PATH_LEN]; - char dir1[OS_MAX_PATH_LEN]; - char dir2[OS_MAX_PATH_LEN]; - char buffer1[OS_MAX_PATH_LEN]; - char buffer2[OS_MAX_PATH_LEN]; - char copybuffer1[OS_MAX_PATH_LEN]; - char copybuffer2[OS_MAX_PATH_LEN]; - osal_id_t fd1; - osal_id_t fd2; - size_t size; + int32 status; + char filename1[OS_MAX_PATH_LEN]; + char filename2[OS_MAX_PATH_LEN]; + char dir1[OS_MAX_PATH_LEN]; + char dir2[OS_MAX_PATH_LEN]; + char buffer1[OS_MAX_PATH_LEN]; + char buffer2[OS_MAX_PATH_LEN]; + char copybuffer1[OS_MAX_PATH_LEN]; + char copybuffer2[OS_MAX_PATH_LEN]; + osal_id_t fd1; + osal_id_t fd2; + size_t size; + OS_statvfs_t statbuf; /* make the directory names for testing, as well as the filenames and the buffers * to put in the files */ @@ -450,8 +451,9 @@ void TestMkRmDirFreeBytes(void) /* NOTE: The blocks free call is not necessarily implemented on all filesystems. * So the response of OS_ERR_NOT_IMPLEMENTED is acceptable. */ - status = OS_fsBlocksFree("/drive0"); - UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); + status = OS_FileSysStatVolume("/drive0", &statbuf); + UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status == OS_SUCCESS, "Checking Free Blocks: status=%d blocks=%lu", + (int)status, (unsigned long)statbuf.blocks_free); /* make the two directories */ status = OS_mkdir(dir1, 0); @@ -486,8 +488,9 @@ void TestMkRmDirFreeBytes(void) memset(buffer1, 0, sizeof(buffer1)); memset(buffer2, 0, sizeof(buffer2)); - status = OS_fsBlocksFree("/drive0"); - UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); + status = OS_FileSysStatVolume("/drive0", &statbuf); + UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status == OS_SUCCESS, "Checking Free Blocks: status=%d blocks=%lu", + (int)status, (unsigned long)statbuf.blocks_free); /* read back out of the files what we wrote into them */ size = strlen(copybuffer1); @@ -526,8 +529,9 @@ void TestMkRmDirFreeBytes(void) status = OS_rmdir(dir2); UtAssert_True(status == OS_SUCCESS, "status after rmdir 2 = %d", (int)status); - status = OS_fsBlocksFree("/drive0"); - UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status >= OS_SUCCESS, "Checking Free Blocks: %d", (int)status); + status = OS_FileSysStatVolume("/drive0", &statbuf); + UtAssert_True(status == OS_ERR_NOT_IMPLEMENTED || status == OS_SUCCESS, "Checking Free Blocks: status=%d blocks=%lu", + (int)status, (unsigned long)statbuf.blocks_free); } /*--------------------------------------------------------------------------------------- diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 7cb4235da..d8cdf1b38 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -336,13 +336,28 @@ void Test_OS_FileSysStatVolume(void) */ OS_statvfs_t statbuf; + OS_statvfs_t statref; int32 expected; int32 actual; + statref.block_size = OSAL_SIZE_C(1024); + statref.blocks_free = OSAL_BLOCKCOUNT_C(1111); + statref.total_blocks = OSAL_BLOCKCOUNT_C(2222); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statref, sizeof(statref), false); + OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | + OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + expected = OS_SUCCESS; actual = OS_FileSysStatVolume("/cf", &statbuf); UtAssert_True(actual == expected, "OS_FileSysStatVolume() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(statbuf.block_size == statref.block_size, "blocks_size (%lu) == %lu", (unsigned long)statbuf.block_size, + (unsigned long)statref.block_size); + UtAssert_True(statbuf.total_blocks == statref.total_blocks, "total_blocks (%lu) == %lu", + (unsigned long)statbuf.total_blocks, (unsigned long)statref.total_blocks); + UtAssert_True(statbuf.blocks_free == statref.blocks_free, "blocks_free (%lu) == %lu", (unsigned long)statbuf.blocks_free, + (unsigned long)statref.blocks_free); + /* validate error checking */ expected = OS_INVALID_POINTER; actual = OS_FileSysStatVolume(NULL, &statbuf); diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c index ebbc668b8..410e1efbf 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -1271,6 +1271,123 @@ void UT_os_fsbytesfree_test() return; } +/*--------------------------------------------------------------------------------* +** Syntax: int32 OS_fsstatvolume(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_fsstatvolume_test(void) +{ + const char * testDesc; + OS_statvfs_t statbuf; + + /*-----------------------------------------------------*/ + testDesc = "API not implemented"; + + if (OS_FileSysStatVolume("/cf", &statbuf) == OS_ERR_NOT_IMPLEMENTED) + { + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); + goto UT_os_fsstatvolume_test_exit_tag; + } + + /*-----------------------------------------------------*/ + testDesc = "#1a Null-pointer-arg"; + + if (OS_FileSysStatVolume(NULL, &statbuf) == OS_INVALID_POINTER) + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + else + UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + + /*-----------------------------------------------------*/ + testDesc = "#1b Null-pointer-arg"; + + if (OS_FileSysStatVolume("/cf", 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_FileSysStatVolume(g_fsLongName, &statbuf) == 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_fsstatvolume_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_fsstatvolume_test_exit_tag; + } + + if (OS_FileSysStatVolume(g_mntNames[4], &statbuf) >= 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_fsstatvolume_test_exit_tag: + return; +} + /*================================================================================* ** End of File: ut_osfilesys_diskio_test.c **================================================================================*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h index c6ab2dd2a..f1420c68c 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h @@ -71,6 +71,7 @@ void UT_os_checkfs_test(void); void UT_os_fsblocksfree_test(void); void UT_os_fsbytesfree_test(void); +void UT_os_fsstatvolume_test(void); /*--------------------------------------------------------------------------------*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c index 16a147d97..3850eff52 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -137,6 +137,7 @@ void UtTest_Setup(void) 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"); } /*================================================================================* diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c index 02188510c..f188d34e7 100644 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ b/src/ut-stubs/osapi-utstub-filesys.c @@ -192,6 +192,28 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) return status; } +/***************************************************************************** + * + * Stub function for OS_fsBytesFree() + * + *****************************************************************************/ +int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) +{ + UT_Stub_RegisterContext(UT_KEY(OS_FileSysStatVolume), name); + UT_Stub_RegisterContext(UT_KEY(OS_FileSysStatVolume), statbuf); + + int32 status; + + status = UT_DEFAULT_IMPL(OS_FileSysStatVolume); + + if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume), statbuf, sizeof(*statbuf)) < sizeof(*statbuf)) + { + memset(statbuf, 0, sizeof(*statbuf)); + } + + return status; +} + /***************************************************************************** * * Stub function for OS_chkfs()