-
Notifications
You must be signed in to change notification settings - Fork 207
/
fs_header_test.c
128 lines (104 loc) · 4.76 KB
/
fs_header_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*************************************************************************
**
** 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: fs_header_test.c
**
** Purpose:
** Functional test of basic FS Header APIs
**
** Demonstration of how to register and use the UT assert functions.
**
*************************************************************************/
/*
* Includes
*/
#include "cfe_test.h"
#define OS_TEST_HEADER_FILENAME "/drive0/header_test.txt"
char *fsAddrPtr = NULL;
static osal_id_t setup_file(void)
{
osal_id_t id;
OS_mkfs(fsAddrPtr, "/ramdev1", "RAM", 512, 20);
OS_mount("/ramdev1", "/drive0");
UtAssert_INT32_EQ(OS_OpenCreate(&id, OS_TEST_HEADER_FILENAME, OS_FILE_FLAG_CREATE, OS_READ_WRITE), OS_SUCCESS);
return id;
}
void TestCreateHeader(void)
{
CFE_FS_Header_t Header;
CFE_FS_Header_t HeaderFail;
const char * TestDescription = "TEST_HEADER";
osal_id_t fd = setup_file();
UtPrintf("Testing: CFE_FS_InitHeader, CFE_FS_WriteHeader");
UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, &Header), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(OS_lseek(fd, 0, OS_SEEK_CUR), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, NULL), CFE_FS_BAD_ARGUMENT);
CFE_UtAssert_STATUS_ERROR(CFE_FS_WriteHeader(OS_OBJECT_ID_UNDEFINED, &Header));
UtAssert_VOIDCALL(CFE_FS_InitHeader(NULL, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_VOIDCALL(CFE_FS_InitHeader(&HeaderFail, NULL, CFE_FS_SubType_ES_ERLOG));
UtAssert_VOIDCALL(CFE_FS_InitHeader(&HeaderFail, TestDescription, 256));
OS_close(fd);
OS_remove(OS_TEST_HEADER_FILENAME);
}
void TestReadHeader(void)
{
CFE_FS_Header_t Header;
CFE_FS_Header_t ReadHeader;
const char * TestDescription = "TEST_HEADER";
osal_id_t fd = setup_file();
UtPrintf("Testing: CFE_FS_ReadHeader");
UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, &Header), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(CFE_FS_ReadHeader(&ReadHeader, fd), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(OS_lseek(fd, 0, OS_SEEK_CUR), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(Header.ContentType, ReadHeader.ContentType);
UtAssert_INT32_EQ(Header.SubType, ReadHeader.SubType);
UtAssert_StrCmp(TestDescription, ReadHeader.Description, "ReadHeader.Description = %s", ReadHeader.Description);
UtAssert_INT32_EQ(CFE_FS_ReadHeader(NULL, fd), CFE_FS_BAD_ARGUMENT);
CFE_UtAssert_STATUS_ERROR(CFE_FS_ReadHeader(&ReadHeader, OS_OBJECT_ID_UNDEFINED));
OS_close(fd);
OS_remove(OS_TEST_HEADER_FILENAME);
}
void TestTimeStamp(void)
{
CFE_FS_Header_t Header;
CFE_FS_Header_t ReadHeader;
const char * TestDescription = "TEST_HEADER";
CFE_TIME_SysTime_t NewTimestamp = {0xFFFFFFFF, 0xFFFFFFFF};
osal_id_t fd = setup_file();
UtPrintf("Testing: CFE_FS_SetTimestamp");
UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, &Header), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(CFE_FS_SetTimestamp(fd, NewTimestamp), CFE_SUCCESS);
UtAssert_INT32_EQ(OS_lseek(fd, 0, OS_SEEK_CUR), (offsetof(CFE_FS_Header_t, TimeSeconds) + sizeof(NewTimestamp)));
UtAssert_INT32_EQ(CFE_FS_ReadHeader(&ReadHeader, fd), sizeof(CFE_FS_Header_t));
UtAssert_UINT32_EQ(0xFFFFFFFF, ReadHeader.TimeSeconds);
UtAssert_UINT32_EQ(0xFFFFFFFF, ReadHeader.TimeSubSeconds);
CFE_UtAssert_STATUS_ERROR(CFE_FS_SetTimestamp(OS_OBJECT_ID_UNDEFINED, NewTimestamp));
OS_close(fd);
OS_remove(OS_TEST_HEADER_FILENAME);
}
void FSHeaderTestSetup(void)
{
UtTest_Add(TestCreateHeader, NULL, NULL, "Test Create Header");
UtTest_Add(TestReadHeader, NULL, NULL, "Test Read Header");
UtTest_Add(TestTimeStamp, NULL, NULL, "Test Time Stamp");
}