Skip to content

Commit

Permalink
Merge pull request nasa#1050 from jphickey/fix-1049-fsblocksfree
Browse files Browse the repository at this point in the history
Fix nasa#1049, replace OS_fsBlocksFree
  • Loading branch information
astrogeco authored Jan 12, 2021
2 parents eb93d21 + 2988903 commit eaa850f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
31 changes: 9 additions & 22 deletions fsw/cfe-core/src/es/cfe_es_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,11 @@ void CFE_ES_SetupResetVariables(uint32 StartType, uint32 StartSubtype, uint32 Bo
*/
void CFE_ES_InitializeFileSystems(uint32 StartType)
{
int32 RetStatus;
cpuaddr RamDiskMemoryAddress;
uint32 RamDiskMemorySize;
int32 BlocksFree;
int32 PercentFree;
int32 RetStatus;
cpuaddr RamDiskMemoryAddress;
uint32 RamDiskMemorySize;
int32 PercentFree;
OS_statvfs_t StatBuf;

/*
** Get the memory area for the RAM disk
Expand Down Expand Up @@ -601,25 +601,13 @@ void CFE_ES_InitializeFileSystems(uint32 StartType)
/*
** See how many blocks are free in the RAM disk
*/
BlocksFree = OS_fsBlocksFree(CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING);
if ( BlocksFree >= 0 )
RetStatus = OS_FileSysStatVolume(CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING, &StatBuf);
if ( RetStatus == OS_SUCCESS && StatBuf.total_blocks > 0 )
{
/*
** Need a sanity check for the desktop systems.
** Because the desktop ports map the volatile disk to the host
** hard disk, it will report more free blocks than the defined number
** of sectors ( blocks ). Therefore it must be truncated.
*/
if ( BlocksFree > CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS )
{
BlocksFree = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS - 1;
}

/*
** Determine if the disk is too full
*/
BlocksFree = BlocksFree * 100;
PercentFree = BlocksFree / CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS;
PercentFree = (StatBuf.blocks_free * 100) / StatBuf.total_blocks;
CFE_ES_WriteToSysLog("Volatile Disk has %d Percent free space.\n",(int)PercentFree);

if ( PercentFree < CFE_PLATFORM_ES_RAM_DISK_PERCENT_RESERVED )
Expand Down Expand Up @@ -721,7 +709,7 @@ void CFE_ES_InitializeFileSystems(uint32 StartType)
else /* could not determine free blocks */
{
/* Log error message -- note that BlocksFree returns the error code in this case */
CFE_ES_WriteToSysLog("ES Startup: Error Determining Blocks Free on Volume. EC = 0x%08X\n",(unsigned int)BlocksFree);
CFE_ES_WriteToSysLog("ES Startup: Error Determining Blocks Free on Volume. EC = 0x%08X\n",(unsigned int)RetStatus);

/*
** Delay to allow the message to be read
Expand Down Expand Up @@ -983,4 +971,3 @@ int32 CFE_ES_MainTaskSyncDelay(uint32 AppStateId, uint32 TimeOutMilliseconds)

return Status;
}

27 changes: 13 additions & 14 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ void TestStartupErrorPaths(void)
ES_UT_SetAppStateHook_t StateHook;
uint32 PanicStatus;
uint32 ResetType;
OS_statvfs_t StatBuf;
CFE_ES_TaskRecord_t *TaskRecPtr;
CFE_ES_AppRecord_t *AppRecPtr;

Expand Down Expand Up @@ -886,13 +887,19 @@ void TestStartupErrorPaths(void)
"CFE_ES_InitializeFileSystems",
"Power on reset; error creating volatile (RAM) volume");

/* prepare the StatBuf to reflect a RAM disk that is 99% full */
StatBuf.block_size = 1024;
StatBuf.total_blocks = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS;
StatBuf.blocks_free = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS / 100;

/* Test initialization of the file systems specifying a processor reset
* following a failure to reformat the RAM volume
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_initfs), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mkfs), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&
Expand All @@ -909,31 +916,20 @@ void TestStartupErrorPaths(void)
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(CFE_PSP_GetVolatileDiskMem), CFE_PSP_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&
UT_GetStubCount(UT_KEY(OS_printf)) == 3,
"CFE_ES_InitializeFileSystems",
"Processor reset; cannot get memory for volatile disk");

/* Test initialization of the file systems where the number of free blocks
* reported is greater than the number of RAM disk sectors
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDeferredRetcode(UT_KEY(OS_fsBlocksFree), 1, CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS + 1);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_MOUNT_VOLATILE]) &&
UT_GetStubCount(UT_KEY(OS_printf)) == 2,
"CFE_ES_InitializeFileSystems",
"Processor reset; truncate free block count");

/* Test initialization of the file systems specifying a processor reset
* following a failure to remove the RAM volume
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_rmfs), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&
Expand All @@ -947,6 +943,7 @@ void TestStartupErrorPaths(void)
*/
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(OS_unmount), 1, -1);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&
Expand All @@ -968,6 +965,7 @@ void TestStartupErrorPaths(void)
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&
Expand All @@ -981,7 +979,7 @@ void TestStartupErrorPaths(void)
* number of blocks that are free on the volume
*/
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(OS_fsBlocksFree), 1, -1);
UT_SetDeferredRetcode(UT_KEY(OS_FileSysStatVolume), 1, -1);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_DETERMINE_BLOCKS]) &&
Expand Down Expand Up @@ -1106,6 +1104,7 @@ void TestStartupErrorPaths(void)
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_initfs), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&
Expand Down

0 comments on commit eaa850f

Please sign in to comment.