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

Implementation assumptions in table functional test #2506

Open
jphickey opened this issue Jan 29, 2024 · 1 comment
Open

Implementation assumptions in table functional test #2506

jphickey opened this issue Jan 29, 2024 · 1 comment
Assignees

Comments

@jphickey
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The table functional test creates additional table files for its own use in testing. The problem is, that all of this code relies on an assumed definition/implementation of the table file structure.

In CFE there is only one "proper" source of loadable table files, and that is the build-time table generation tool (elf2cfetbl, or equivalent)

The "dump" function of table services also can create a table file, although I believe this uses a different file type so it cannot be directly loaded.

Describe the solution you'd like
At least for the test cases where the intent is to create a "good" table file but with different content, only the table generation tool should be used for this purpose. The CMake scripts have the ability to invoke the tool to produce different/alternate versions of the same table file, so this can be used.

To produce a "bad" table file where the target is a specific header, the elf2cfetbl tool should include extra debug options to force it to create a table with a bad value in that header. For other cases of bad values where it can corrupt data more indiscriminately, then it should work across the entire header equally.

Additional context
The "bad" table tests may still pass the functional tests but could pass for the wrong reason. That is, its not guaranteed they corrupted the field they were supposed to corrupt.

Requester Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey
Copy link
Contributor Author

jphickey commented Jan 29, 2024

Function that generates tables starts here in the testcase code:

void TblTest_GenerateTblFiles(void)
{
osal_id_t fh1 = OS_OBJECT_ID_UNDEFINED;
osal_id_t fh2 = OS_OBJECT_ID_UNDEFINED;
uint32 PartialOffset;
uint32 PartialSize;
union
{
uint8 u8;
uint16 u16;
uint32 u32;
CFE_FS_Header_t FsHdr;
CFE_TBL_File_Hdr_t TblHdr;
CFE_TEST_TestTable_t Content;
} buf;
/* Open the original (correct) table image file for reference */
UtAssert_INT32_EQ(OS_OpenCreate(&fh1, TESTTBL_NOMINAL_FILE, 0, OS_READ_ONLY), OS_SUCCESS);
/* create a file which does not have a valid FS header */
UtAssert_INT32_EQ(
OS_OpenCreate(&fh2, TESTTBL_BAD_STDHDR_FILE, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY),
OS_SUCCESS);
buf.u32 = 0x12345678;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.u32)), sizeof(buf.u32));
UtAssert_INT32_EQ(OS_close(fh2), OS_SUCCESS);
/* create a file which has an FS header but not a valid TBL header */
OS_lseek(fh1, 0, OS_SEEK_SET);
UtAssert_INT32_EQ(
OS_OpenCreate(&fh2, TESTTBL_BAD_TBLHDR_FILE, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY),
OS_SUCCESS);
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
buf.u32 = 0x12345678;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.u32)), sizeof(buf.u32));
UtAssert_INT32_EQ(OS_close(fh2), OS_SUCCESS);
/* Create a tbl image that has the wrong content ID field */
OS_lseek(fh1, 0, OS_SEEK_SET);
UtAssert_INT32_EQ(
OS_OpenCreate(&fh2, TESTTBL_BAD_CONTENT_FILE, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY),
OS_SUCCESS);
/* copy headers and modify */
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
buf.FsHdr.ContentType = 0x09abcdef;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.TblHdr)), sizeof(buf.TblHdr));
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.TblHdr)), sizeof(buf.TblHdr));
/* Identifiable content, different from original */
buf.Content.Int1 = 0x7777;
buf.Content.Int2 = 0x8888;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.Content)), sizeof(buf.Content));
UtAssert_INT32_EQ(OS_close(fh2), OS_SUCCESS);
/* Create a tbl image that has the wrong content ID field */
OS_lseek(fh1, 0, OS_SEEK_SET);
UtAssert_INT32_EQ(
OS_OpenCreate(&fh2, TESTTBL_BAD_SUBTYPE_FILE, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY),
OS_SUCCESS);
/* copy headers as-is */
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
buf.FsHdr.SubType = 0x09abcdef;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.TblHdr)), sizeof(buf.TblHdr));
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.TblHdr)), sizeof(buf.TblHdr));
/* Identifiable content, different from original */
buf.Content.Int1 = 0x9999;
buf.Content.Int2 = 0xaaaa;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.Content)), sizeof(buf.Content));
UtAssert_INT32_EQ(OS_close(fh2), OS_SUCCESS);
/* Create a tbl image that is complete but with different content */
OS_lseek(fh1, 0, OS_SEEK_SET);
UtAssert_INT32_EQ(
OS_OpenCreate(&fh2, TESTTBL_ALTERNATE_FILE, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY),
OS_SUCCESS);
/* copy headers as-is */
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.FsHdr)), sizeof(buf.FsHdr));
UtAssert_INT32_EQ(OS_read(fh1, &buf, sizeof(buf.TblHdr)), sizeof(buf.TblHdr));
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.TblHdr)), sizeof(buf.TblHdr));
/* Identifiable content, different from original */
buf.Content.Int1 = 0xdead;
buf.Content.Int2 = 0xbeef;
UtAssert_INT32_EQ(OS_write(fh2, &buf, sizeof(buf.Content)), sizeof(buf.Content));
UtAssert_INT32_EQ(OS_close(fh2), OS_SUCCESS);
/* Create a tbl image that is complete but for the OTHER table (also different content) */
OS_lseek(fh1, 0, OS_SEEK_SET);
UtAssert_INT32_EQ(

The main issue is that it assumes a simple OS_write(fh2, &buf, sizeof(buf.Content)) will adequately write the table file content. But it may not be that simple.

@jphickey jphickey self-assigned this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant