Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1650, Add File Utility Functional Tests. #1673

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_cfe_app(cfe_testcase
src/es_misc_test.c
src/es_mempool_test.c
src/fs_header_test.c
src/fs_util_test.c
src/sb_pipe_mang_test.c
src/time_current_test.c
)
Expand Down
7 changes: 4 additions & 3 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ void CFE_TestMain(void)
/*
* Register test cases in UtAssert
*/
ESInfoTestSetup();
ESTaskTestSetup();
ESCDSTestSetup();
ESMiscTestSetup();
ESInfoTestSetup();
ESMemPoolTestSetup();
ESMiscTestSetup();
ESTaskTestSetup();
FSHeaderTestSetup();
FSUtilTestSetup();
SBPipeMangSetup();
TimeCurrentTestSetup();

Expand Down
12 changes: 9 additions & 3 deletions modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
#include "uttest.h"
#include "utassert.h"

typedef struct
{
CFE_FS_FileWriteMetaData_t FuncTestState;
} CFE_FT_Global_t;

/**
* Name of log file to write
*
Expand Down Expand Up @@ -73,12 +78,13 @@
#define cFE_FTAssert_VOIDCALL(func) (func, UtAssert(true, #func, __FILE__, __LINE__))

void CFE_TestMain(void);
void ESInfoTestSetup(void);
void ESTaskTestSetup(void);
void ESCDSTestSetup(void);
void ESMiscTestSetup(void);
void ESInfoTestSetup(void);
void ESMemPoolTestSetup(void);
void ESMiscTestSetup(void);
void ESTaskTestSetup(void);
void FSHeaderTestSetup(void);
void FSUtilTestSetup(void);
void SBPipeMangSetup(void);
void TimeCurrentTestSetup(void);

Expand Down
162 changes: 162 additions & 0 deletions modules/cfe_testcase/src/fs_util_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** File: es_info_test.c
**
** Purpose:
** Functional test of FS File Utility APIs
**
** Demonstration of how to register and use the UT assert functions.
**
*************************************************************************/

/*
* Includes
*/

#include "cfe_test.h"

CFE_FT_Global_t CFE_FT_Global;

void TestFileCategory(void)
{
UtPrintf("Testing: CFE_FS_GetDefaultMountPoint, CFE_FS_GetDefaultExtension");

UtAssert_NULL(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_UNKNOWN));
UtAssert_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_UNKNOWN));
}

void TestInputFile(void)
{
char NameBuf[OS_MAX_PATH_LEN];
char OutNameBuf[OS_MAX_PATH_LEN];
const char Name[] = "FileName";
char InNameBuf[] = "BufferName";
const char Path[] = "/func";
const char Ext[] = ".test";
const char ExpectedName[] = "/func/FileName.test";
const char ExpectedBuf[] = "/func/BufferName.test";

UtPrintf("Testing: CFE_FS_ParseInputFileName, CFE_FS_ParseInputFileNameEX");

UtAssert_INT32_EQ(CFE_FS_ParseInputFileName(NameBuf, Name, sizeof(NameBuf), CFE_FS_FileCategory_SCRIPT),
CFE_SUCCESS);
UtAssert_NOT_NULL(strstr(NameBuf, Name));

UtAssert_INT32_EQ(CFE_FS_ParseInputFileName(NULL, Name, sizeof(NameBuf), CFE_FS_FileCategory_SCRIPT),
CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_FS_ParseInputFileName(NameBuf, NULL, sizeof(NameBuf), CFE_FS_FileCategory_SCRIPT),
CFE_FS_INVALID_PATH);
UtAssert_INT32_EQ(CFE_FS_ParseInputFileName(NameBuf, Name, 0, CFE_FS_FileCategory_SCRIPT), CFE_FS_BAD_ARGUMENT);

UtAssert_INT32_EQ(
CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, sizeof(OutNameBuf), sizeof(InNameBuf), Name, Path, Ext),
CFE_SUCCESS);
UtAssert_StrCmp(ExpectedBuf, OutNameBuf, "Parse Input EX: %s", OutNameBuf);
UtAssert_INT32_EQ(
CFE_FS_ParseInputFileNameEx(OutNameBuf, NULL, sizeof(OutNameBuf), sizeof(InNameBuf), Name, Path, Ext),
CFE_SUCCESS);
UtAssert_StrCmp(ExpectedName, OutNameBuf, "Parse Input EX: %s", OutNameBuf);
UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, sizeof(OutNameBuf), 0, Name, Path, Ext),
CFE_SUCCESS);
UtAssert_StrCmp(ExpectedName, OutNameBuf, "Parse Input EX: %s", OutNameBuf);
UtAssert_INT32_EQ(
CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, sizeof(OutNameBuf), sizeof(InNameBuf), NULL, Path, Ext),
CFE_SUCCESS);
UtAssert_StrCmp(ExpectedBuf, OutNameBuf, "Parse Input EX: %s", OutNameBuf);

UtAssert_INT32_EQ(
CFE_FS_ParseInputFileNameEx(NULL, InNameBuf, sizeof(OutNameBuf), sizeof(InNameBuf), Name, Path, Ext),
CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, 0, sizeof(InNameBuf), Name, Path, Ext),
CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(
CFE_FS_ParseInputFileNameEx(OutNameBuf, NULL, sizeof(OutNameBuf), sizeof(InNameBuf), NULL, Path, Ext),
CFE_FS_INVALID_PATH);
UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, sizeof(OutNameBuf), 0, NULL, Path, Ext),
CFE_FS_INVALID_PATH);
}

void TestFileName(void)
{
const char Path[] = "/func/FileName.test";
char Name[OS_MAX_FILE_NAME];
const char ExpectedName[] = "FileName.test";

UtPrintf("Testing: CFE_FS_ExtractFilenameFromPath");

UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Path, Name), CFE_SUCCESS);
UtAssert_StrCmp(Name, ExpectedName, "Extract Filename: %s", Name);

UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(NULL, Name), CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Path, NULL), CFE_FS_BAD_ARGUMENT);
}

/* FT helper stub compatible with background file write DataGetter */
bool FS_DataGetter(void *Meta, uint32 RecordNum, void **Buffer, size_t *BufSize)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When these two functions exists it causes CFE_FS_InitHeader to stall, and then the test timeout detection kicks in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug or an issue w/ the test?

{
*Buffer = NULL;
*BufSize = 0;
return true;
}

/* FT helper stub compatible with background file write OnEvent */
void FS_OnEvent(void *Meta, CFE_FS_FileWriteEvent_t Event, int32 Status, uint32 RecordNum, size_t BlockSize,
size_t Position)
{
}

void TestFileDump(void)
{
memset(&CFE_FT_Global.FuncTestState, 0, sizeof(CFE_FT_Global.FuncTestState));
CFE_FT_Global.FuncTestState.FileSubType = 2;
CFE_FT_Global.FuncTestState.GetData = FS_DataGetter;
CFE_FT_Global.FuncTestState.OnEvent = FS_OnEvent;
strncpy(CFE_FT_Global.FuncTestState.FileName, "/ram/FT.bin", sizeof(CFE_FT_Global.FuncTestState.FileName));
strncpy(CFE_FT_Global.FuncTestState.Description, "FT", sizeof(CFE_FT_Global.FuncTestState.Description));
int count = 0;
int MaxWait = 20;

UtPrintf("Testing: CFE_FS_BackgroundFileDumpRequest, CFE_FS_BackgroundFileDumpIsPending");

UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState), false);
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState), true);

/* Wait for background task to complete */
while (CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState) && count < MaxWait)
{
OS_TaskDelay(100);
count++;
}

zanzaben marked this conversation as resolved.
Show resolved Hide resolved
UtAssert_True(count < MaxWait, "count (%i) < MaxWait (%i)", count, MaxWait);

UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(NULL), CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(NULL), false);
}

void FSUtilTestSetup(void)
{
UtTest_Add(TestFileCategory, NULL, NULL, "Test File Category");
UtTest_Add(TestInputFile, NULL, NULL, "Test Input File");
UtTest_Add(TestFileName, NULL, NULL, "Test File Name");
UtTest_Add(TestFileDump, NULL, NULL, "Test File Dump");
}