Skip to content

Commit 42a000a

Browse files
authored
Merge pull request #465 from nasa/integration-candidate
PSP Integration candidate: Equuleus-rc1+dev33
2 parents 02c776e + b983cea commit 42a000a

19 files changed

Lines changed: 87 additions & 102 deletions

‎.github/pull_request_template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A clear and concise description of what the contribution is.
1010
**Testing performed**
1111
Steps taken to test the contribution:
1212
1. Build steps '...'
13-
1. Execution steps '...'
13+
2. Execution steps '...'
1414

1515
**Expected behavior changes**
1616
A clear and concise description of how this contribution will change behavior and level of impact.

‎.github/workflows/codeql-build.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: "CodeQL Analysis"
33
on:
44
push:
55
pull_request:
6-
6+
77
jobs:
88
codeql:
99
name: Codeql
1010
uses: nasa/cFS/.github/workflows/codeql-reusable.yml@main
11-
with:
11+
with:
1212
component-path: psp
1313
make: 'make -C build/native/default_cpu1/psp'

‎.github/workflows/icbundle.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ jobs:
5959
done
6060
changelog_entry="${changelog_entry}\n${see_entry}\n"
6161
sed -ir "s|# Changelog|$changelog_entry|" CHANGELOG.md
62-
62+
6363
buildnumber_entry=$'#define CFE_PSP_IMPL_BUILD_NUMBER '${rev_num}
6464
sed -ir "s|#define CFE_PSP_IMPL_BUILD_NUMBER.*|$buildnumber_entry|" fsw/mcp750-vxworks/inc/psp_version.h
65-
65+
6666
buildnumber_entry=$'#define CFE_PSP_IMPL_BUILD_NUMBER '${rev_num}
6767
sed -ir "s|#define CFE_PSP_IMPL_BUILD_NUMBER.*|$buildnumber_entry|" fsw/pc-linux/inc/psp_version.h
68-
68+
6969
buildnumber_entry=$'#define CFE_PSP_IMPL_BUILD_NUMBER '${rev_num}
7070
sed -ir "s|#define CFE_PSP_IMPL_BUILD_NUMBER.*|$buildnumber_entry|" fsw/pc-rtems/inc/psp_version.h
7171
- name: Commit and Push Updates to IC Branch

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Development Build: equuleus-rc1+dev85
4+
- 'Fix #458, Correct minor logic bug in UT_DefaultHandler_PCS_read'
5+
- See: <https://github.com/nasa/PSP/pull/459>
6+
7+
38
## Development Build: equuleus-rc1+dev77
49
- 'Fix #461, set stdout to unbuffered on pc-linux'
510
- See: <https://github.com/nasa/PSP/pull/462>

‎fsw/mcp750-vxworks/src/cfe_psp_memory.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ int32 CFE_PSP_GetCFETextSegmentInfo(cpuaddr *PtrToCFESegment, uint32 *SizeOfCFES
530530
}
531531
else
532532
{
533-
return_code = CFE_PSP_SUCCESS;
533+
return_code = CFE_PSP_ERROR;
534534
}
535535
}
536536
}

‎fsw/modules/eeprom_mmap_file/cfe_psp_eeprom_mmap_file.c‎

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <unistd.h>
3030
#include <fcntl.h>
31+
#include <errno.h>
3132
#include <sys/mman.h>
3233
#include <sys/stat.h>
3334

@@ -46,81 +47,57 @@ CFE_PSP_MODULE_DECLARE_SIMPLE(eeprom_mmap_file);
4647
*/
4748
int32 CFE_PSP_SetupEEPROM(uint32 EEPROMSize, cpuaddr *EEPROMAddress)
4849
{
49-
int FileDescriptor;
50-
int ReturnStatus;
51-
char * DataBuffer;
52-
struct stat StatBuf;
50+
int FileDescriptor;
51+
int ReturnStatus;
52+
void *DataBuffer;
5353

54-
/*
55-
** Check to see if the file has been created.
56-
** If not, create it.
57-
** If so, then open it for read/write
58-
*/
59-
ReturnStatus = stat(EEPROM_FILE, &StatBuf);
60-
if (ReturnStatus == -1)
54+
DataBuffer = NULL;
55+
FileDescriptor = open(EEPROM_FILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
56+
if (FileDescriptor < 0)
6157
{
62-
/*
63-
** File does not exist, create it.
64-
*/
65-
FileDescriptor = open(EEPROM_FILE, O_RDWR | O_CREAT, S_IRWXU);
66-
if (FileDescriptor == -1)
67-
{
68-
OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE);
69-
return -1;
70-
}
71-
else
72-
{
73-
/*
74-
** Need to seek to the desired EEPROM size
75-
*/
76-
if (lseek(FileDescriptor, EEPROMSize - 1, SEEK_SET) == -1)
77-
{
78-
OS_printf("CFE_PSP: Cannot Seek to end of EEPROM file.\n");
79-
close(FileDescriptor);
80-
return -1;
81-
}
82-
83-
/*
84-
** Write a byte at the end of the File
85-
*/
86-
if (write(FileDescriptor, "", 1) != 1)
87-
{
88-
OS_printf("CFE_PSP: Cannot write to EEPROM file\n");
89-
close(FileDescriptor);
90-
return -1;
91-
}
92-
}
58+
OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE);
59+
perror("CFE_PSP: open");
60+
ReturnStatus = CFE_PSP_ERROR;
61+
}
62+
else if (ftruncate(FileDescriptor, EEPROMSize) < 0)
63+
{
64+
OS_printf("CFE_PSP: ftruncate(%s) error: %s\n", EEPROM_FILE, strerror(errno));
65+
ReturnStatus = CFE_PSP_ERROR;
9366
}
9467
else
9568
{
96-
/*
97-
** File exists
98-
*/
99-
FileDescriptor = open(EEPROM_FILE, O_RDWR);
100-
if (FileDescriptor == -1)
69+
DataBuffer = mmap(NULL, EEPROMSize, PROT_READ | PROT_WRITE, MAP_SHARED, FileDescriptor, 0);
70+
if (DataBuffer == (void *)(-1))
71+
{
72+
OS_printf("CFE_PSP: mmap to EEPROM File failed: %s\n", strerror(errno));
73+
ReturnStatus = CFE_PSP_ERROR;
74+
}
75+
else
10176
{
102-
OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE);
103-
perror("CFE_PSP: open");
104-
return -1;
77+
ReturnStatus = CFE_PSP_SUCCESS;
10578
}
10679
}
10780

108-
/*
109-
** Map the file to a memory space
110-
*/
111-
if ((DataBuffer = mmap(NULL, EEPROMSize, PROT_READ | PROT_WRITE, MAP_SHARED, FileDescriptor, 0)) == (void *)(-1))
81+
/* POSIX says that a mapped pointer counts as a file ref, so the FD
82+
* can be safely closed in all cases, success or failure */
83+
if (FileDescriptor >= 0)
11284
{
113-
OS_printf("CFE_PSP: mmap to EEPROM File failed\n");
11485
close(FileDescriptor);
115-
return -1;
11686
}
11787

11888
/*
11989
** Return the address to the caller
12090
*/
121-
*EEPROMAddress = (cpuaddr)DataBuffer;
91+
if (ReturnStatus == CFE_PSP_SUCCESS)
92+
{
93+
*EEPROMAddress = (cpuaddr)DataBuffer;
94+
}
95+
else
96+
{
97+
*EEPROMAddress = 0;
98+
}
12299

123-
return 0;
100+
return ReturnStatus;
124101
}
125102

126103
/* For read/write - As this is mmap'ed we dereference the pointer directly.

‎unit-test-coverage/modules/eeprom_mmap_file/coveragetest-eeprom_mmap_file.c‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,12 @@ void Test_eeprom_mmap_file_Init(void)
7171
UT_SetDeferredRetcode(UT_KEY(PCS_mmap), 1, -1);
7272
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
7373

74-
/* fail to create new file file */
74+
/* fail to open file */
7575
UT_SetDeferredRetcode(UT_KEY(PCS_open), 1, -1);
7676
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
7777

78-
/* file exists */
79-
UT_SetDefaultReturnValue(UT_KEY(PCS_stat), -1);
80-
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
81-
82-
/* fail to open existing file */
83-
UT_SetDeferredRetcode(UT_KEY(PCS_open), 1, -1);
84-
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
85-
86-
/* fail to seek in existing file */
87-
UT_SetDeferredRetcode(UT_KEY(PCS_lseek), 1, -1);
88-
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
89-
90-
/* write success in existing file */
91-
UT_SetDeferredRetcode(UT_KEY(PCS_write), 1, 1);
92-
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
93-
94-
/* fail to write a byte in existing file */
95-
UT_SetDeferredRetcode(UT_KEY(PCS_write), 1, -1);
78+
/* fail to resize file */
79+
UT_SetDeferredRetcode(UT_KEY(PCS_ftruncate), 1, -1);
9680
UtAssert_VOIDCALL(eeprom_mmap_file_Init(1));
9781
}
9882

‎unit-test-coverage/ut-stubs/inc/PCS_unistd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
/* ----------------------------------------- */
4444

4545
extern int PCS_close(int fd);
46+
extern int PCS_ftruncate(int fd, PCS_off_t len);
4647
extern PCS_gid_t PCS_getegid(void);
4748
extern PCS_uid_t PCS_geteuid(void);
4849
extern long int PCS_gethostid(void);

‎unit-test-coverage/ut-stubs/override_inc/unistd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define STDERR_FILENO PCS_STDERR_FILENO
3535

3636
#define close PCS_close
37+
#define ftruncate PCS_ftruncate
3738
#define getegid PCS_getegid
3839
#define geteuid PCS_geteuid
3940
#define gethostid PCS_gethostid

‎unit-test-coverage/ut-stubs/src/PCS_string_handlers.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ void UT_DefaultHandler_PCS_strcat(void *UserObj, UT_EntryKey_t FuncKey, const UT
165165

166166
void UT_DefaultHandler_PCS_strncat(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
167167
{
168-
/* char *PCS_strncat(char *dest, const char *src, size_t size) */
168+
/* char *PCS_strncat(char *dest, const char *src, size_t n) */
169169
void * dest = UT_Hook_GetArgValueByName(Context, "dest", void *);
170170
const void *src = UT_Hook_GetArgValueByName(Context, "src", const void *);
171-
size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t);
171+
size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t);
172172

173173
char *Result;
174174

175175
if (!UT_Stub_GetInt32StatusCode(Context, NULL))
176176
{
177177
/* Perform the real operation */
178-
Result = strncat(dest, src, size);
178+
Result = strncat(dest, src, n);
179179
UT_Stub_SetReturnValue(FuncKey, Result);
180180
}
181181
}
@@ -215,33 +215,33 @@ void UT_DefaultHandler_PCS_strcmp(void *UserObj, UT_EntryKey_t FuncKey, const UT
215215

216216
void UT_DefaultHandler_PCS_strcpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
217217
{
218-
/* char *PCS_strcpy(char *dst, const char *src) */
219-
char * dst = UT_Hook_GetArgValueByName(Context, "dst", char *);
218+
/* char *PCS_strcpy(char *dest, const char *src) */
219+
char * dest = UT_Hook_GetArgValueByName(Context, "dest", char *);
220220
const char *src = UT_Hook_GetArgValueByName(Context, "src", const char *);
221221

222222
char *Result;
223223

224224
if (!UT_Stub_GetInt32StatusCode(Context, NULL))
225225
{
226226
/* Perform the real operation */
227-
Result = strcpy(dst, src);
227+
Result = strcpy(dest, src);
228228
UT_Stub_SetReturnValue(FuncKey, Result);
229229
}
230230
}
231231

232232
void UT_DefaultHandler_PCS_strncpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
233233
{
234-
/* char *PCS_strncpy(char *dst, const char *src, size_t size) */
235-
char * dst = UT_Hook_GetArgValueByName(Context, "dst", char *);
234+
/* char *PCS_strncpy(char *dest, const char *src, size_t n) */
235+
char * dest = UT_Hook_GetArgValueByName(Context, "dest", char *);
236236
const char *src = UT_Hook_GetArgValueByName(Context, "src", const char *);
237-
size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t);
237+
size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t);
238238

239239
char *Result;
240240

241241
if (!UT_Stub_GetInt32StatusCode(Context, NULL))
242242
{
243243
/* Perform the real operation */
244-
Result = strncpy(dst, src, size);
244+
Result = strncpy(dest, src, n);
245245
UT_Stub_SetReturnValue(FuncKey, Result);
246246
}
247247
}

0 commit comments

Comments
 (0)