Skip to content

Commit

Permalink
Fix #5, Use OS_stat instead of OS_OpenCreate to verify file existence
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Mar 21, 2023
1 parent 487169b commit fae737a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions fsw/src/sc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ int32 SC_GetLoadTablePointers(void)

void SC_LoadDefaultTables(void)
{
char TableName[OS_MAX_PATH_LEN];
osal_id_t FileDesc = OS_OBJECT_ID_UNDEFINED;
int32 RtsIndex;
int32 NotLoadedCount = 0;
int32 Status = OS_SUCCESS;
char TableName[OS_MAX_PATH_LEN];
os_fstat_t FileStatus;
int32 RtsIndex;
int32 NotLoadedCount = 0;
int32 Status;

/*
** Currently, only RTS tables are loaded during initialization.
Expand All @@ -539,12 +539,10 @@ void SC_LoadDefaultTables(void)
{
/* Example filename: /cf/apps/sc_rts001.tbl */
snprintf(TableName, sizeof(TableName), "%s%03d.tbl", SC_RTS_FILE_NAME, (int)(RtsIndex + 1));
Status = OS_OpenCreate(&FileDesc, TableName, OS_FILE_FLAG_NONE, OS_READ_ONLY);
Status = OS_stat(TableName, &FileStatus);

if (Status == OS_SUCCESS)
{
OS_close(FileDesc);

/* Only try to load table files that can be opened */
Status = CFE_TBL_Load(SC_OperData.RtsTblHandle[RtsIndex], CFE_TBL_SRC_FILE, TableName);
if (Status != CFE_SUCCESS)
Expand Down
6 changes: 3 additions & 3 deletions unit-test/sc_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,14 +1291,14 @@ void SC_GetLoadTablePointers_Test_ErrorGetAddressLoadableRTS(void)

void SC_LoadDefaultTables_Test(void)
{
/* Set OS_open to return 1, in order to enter if-block "if (FileDesc >= 0)" */
UT_SetDeferredRetcode(UT_KEY(OS_OpenCreate), 1, OS_SUCCESS);
/* Set OS_stat to return OS_SUCCESS, in order to enter "if (Status == OS_SUCCESS)" block */
UT_SetDeferredRetcode(UT_KEY(OS_stat), 1, OS_SUCCESS);

/* Cover branch for - Only try to load table files that can be opened */
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Load), 1, -1);

/* Cover branch for - send an event for each failed open */
UT_SetDeferredRetcode(UT_KEY(OS_OpenCreate), 1, -1);
UT_SetDeferredRetcode(UT_KEY(OS_stat), 1, OS_ERROR);

/* Execute the function being tested */
UtAssert_VOIDCALL(SC_LoadDefaultTables());
Expand Down

0 comments on commit fae737a

Please sign in to comment.