diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d48a1692..96148c1b 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,7 +10,7 @@ A clear and concise description of what the contribution is. **Testing performed** Steps taken to test the contribution: 1. Build steps '...' -1. Execution steps '...' +2. Execution steps '...' **Expected behavior changes** A clear and concise description of how this contribution will change behavior and level of impact. diff --git a/.github/workflows/codeql-build.yml b/.github/workflows/codeql-build.yml index 69a424f7..7a1e14b7 100644 --- a/.github/workflows/codeql-build.yml +++ b/.github/workflows/codeql-build.yml @@ -3,11 +3,11 @@ name: "CodeQL Analysis" on: push: pull_request: - + jobs: codeql: name: Codeql uses: nasa/cFS/.github/workflows/codeql-reusable.yml@main - with: + with: component-path: psp make: 'make -C build/native/default_cpu1/psp' diff --git a/.github/workflows/icbundle.yml b/.github/workflows/icbundle.yml index e4501110..e1da057b 100644 --- a/.github/workflows/icbundle.yml +++ b/.github/workflows/icbundle.yml @@ -59,13 +59,13 @@ jobs: done changelog_entry="${changelog_entry}\n${see_entry}\n" sed -ir "s|# Changelog|$changelog_entry|" CHANGELOG.md - + buildnumber_entry=$'#define CFE_PSP_IMPL_BUILD_NUMBER '${rev_num} sed -ir "s|#define CFE_PSP_IMPL_BUILD_NUMBER.*|$buildnumber_entry|" fsw/mcp750-vxworks/inc/psp_version.h - + buildnumber_entry=$'#define CFE_PSP_IMPL_BUILD_NUMBER '${rev_num} sed -ir "s|#define CFE_PSP_IMPL_BUILD_NUMBER.*|$buildnumber_entry|" fsw/pc-linux/inc/psp_version.h - + buildnumber_entry=$'#define CFE_PSP_IMPL_BUILD_NUMBER '${rev_num} sed -ir "s|#define CFE_PSP_IMPL_BUILD_NUMBER.*|$buildnumber_entry|" fsw/pc-rtems/inc/psp_version.h - name: Commit and Push Updates to IC Branch diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c1fd59..8ab283c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Development Build: equuleus-rc1+dev85 +- 'Fix #458, Correct minor logic bug in UT_DefaultHandler_PCS_read' +- See: + + ## Development Build: equuleus-rc1+dev77 - 'Fix #461, set stdout to unbuffered on pc-linux' - See: diff --git a/fsw/mcp750-vxworks/src/cfe_psp_memory.c b/fsw/mcp750-vxworks/src/cfe_psp_memory.c index 911c4d6a..9bb4cd44 100644 --- a/fsw/mcp750-vxworks/src/cfe_psp_memory.c +++ b/fsw/mcp750-vxworks/src/cfe_psp_memory.c @@ -530,7 +530,7 @@ int32 CFE_PSP_GetCFETextSegmentInfo(cpuaddr *PtrToCFESegment, uint32 *SizeOfCFES } else { - return_code = CFE_PSP_SUCCESS; + return_code = CFE_PSP_ERROR; } } } diff --git a/fsw/modules/eeprom_mmap_file/cfe_psp_eeprom_mmap_file.c b/fsw/modules/eeprom_mmap_file/cfe_psp_eeprom_mmap_file.c index 85cd2707..39880c6d 100644 --- a/fsw/modules/eeprom_mmap_file/cfe_psp_eeprom_mmap_file.c +++ b/fsw/modules/eeprom_mmap_file/cfe_psp_eeprom_mmap_file.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -46,81 +47,57 @@ CFE_PSP_MODULE_DECLARE_SIMPLE(eeprom_mmap_file); */ int32 CFE_PSP_SetupEEPROM(uint32 EEPROMSize, cpuaddr *EEPROMAddress) { - int FileDescriptor; - int ReturnStatus; - char * DataBuffer; - struct stat StatBuf; + int FileDescriptor; + int ReturnStatus; + void *DataBuffer; - /* - ** Check to see if the file has been created. - ** If not, create it. - ** If so, then open it for read/write - */ - ReturnStatus = stat(EEPROM_FILE, &StatBuf); - if (ReturnStatus == -1) + DataBuffer = NULL; + FileDescriptor = open(EEPROM_FILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (FileDescriptor < 0) { - /* - ** File does not exist, create it. - */ - FileDescriptor = open(EEPROM_FILE, O_RDWR | O_CREAT, S_IRWXU); - if (FileDescriptor == -1) - { - OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE); - return -1; - } - else - { - /* - ** Need to seek to the desired EEPROM size - */ - if (lseek(FileDescriptor, EEPROMSize - 1, SEEK_SET) == -1) - { - OS_printf("CFE_PSP: Cannot Seek to end of EEPROM file.\n"); - close(FileDescriptor); - return -1; - } - - /* - ** Write a byte at the end of the File - */ - if (write(FileDescriptor, "", 1) != 1) - { - OS_printf("CFE_PSP: Cannot write to EEPROM file\n"); - close(FileDescriptor); - return -1; - } - } + OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE); + perror("CFE_PSP: open"); + ReturnStatus = CFE_PSP_ERROR; + } + else if (ftruncate(FileDescriptor, EEPROMSize) < 0) + { + OS_printf("CFE_PSP: ftruncate(%s) error: %s\n", EEPROM_FILE, strerror(errno)); + ReturnStatus = CFE_PSP_ERROR; } else { - /* - ** File exists - */ - FileDescriptor = open(EEPROM_FILE, O_RDWR); - if (FileDescriptor == -1) + DataBuffer = mmap(NULL, EEPROMSize, PROT_READ | PROT_WRITE, MAP_SHARED, FileDescriptor, 0); + if (DataBuffer == (void *)(-1)) + { + OS_printf("CFE_PSP: mmap to EEPROM File failed: %s\n", strerror(errno)); + ReturnStatus = CFE_PSP_ERROR; + } + else { - OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE); - perror("CFE_PSP: open"); - return -1; + ReturnStatus = CFE_PSP_SUCCESS; } } - /* - ** Map the file to a memory space - */ - if ((DataBuffer = mmap(NULL, EEPROMSize, PROT_READ | PROT_WRITE, MAP_SHARED, FileDescriptor, 0)) == (void *)(-1)) + /* POSIX says that a mapped pointer counts as a file ref, so the FD + * can be safely closed in all cases, success or failure */ + if (FileDescriptor >= 0) { - OS_printf("CFE_PSP: mmap to EEPROM File failed\n"); close(FileDescriptor); - return -1; } /* ** Return the address to the caller */ - *EEPROMAddress = (cpuaddr)DataBuffer; + if (ReturnStatus == CFE_PSP_SUCCESS) + { + *EEPROMAddress = (cpuaddr)DataBuffer; + } + else + { + *EEPROMAddress = 0; + } - return 0; + return ReturnStatus; } /* For read/write - As this is mmap'ed we dereference the pointer directly. diff --git a/unit-test-coverage/modules/eeprom_mmap_file/coveragetest-eeprom_mmap_file.c b/unit-test-coverage/modules/eeprom_mmap_file/coveragetest-eeprom_mmap_file.c index ac6d679e..5aef5ac8 100644 --- a/unit-test-coverage/modules/eeprom_mmap_file/coveragetest-eeprom_mmap_file.c +++ b/unit-test-coverage/modules/eeprom_mmap_file/coveragetest-eeprom_mmap_file.c @@ -71,28 +71,12 @@ void Test_eeprom_mmap_file_Init(void) UT_SetDeferredRetcode(UT_KEY(PCS_mmap), 1, -1); UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); - /* fail to create new file file */ + /* fail to open file */ UT_SetDeferredRetcode(UT_KEY(PCS_open), 1, -1); UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); - /* file exists */ - UT_SetDefaultReturnValue(UT_KEY(PCS_stat), -1); - UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); - - /* fail to open existing file */ - UT_SetDeferredRetcode(UT_KEY(PCS_open), 1, -1); - UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); - - /* fail to seek in existing file */ - UT_SetDeferredRetcode(UT_KEY(PCS_lseek), 1, -1); - UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); - - /* write success in existing file */ - UT_SetDeferredRetcode(UT_KEY(PCS_write), 1, 1); - UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); - - /* fail to write a byte in existing file */ - UT_SetDeferredRetcode(UT_KEY(PCS_write), 1, -1); + /* fail to resize file */ + UT_SetDeferredRetcode(UT_KEY(PCS_ftruncate), 1, -1); UtAssert_VOIDCALL(eeprom_mmap_file_Init(1)); } diff --git a/unit-test-coverage/ut-stubs/inc/PCS_unistd.h b/unit-test-coverage/ut-stubs/inc/PCS_unistd.h index 4804eee8..d953b2bf 100644 --- a/unit-test-coverage/ut-stubs/inc/PCS_unistd.h +++ b/unit-test-coverage/ut-stubs/inc/PCS_unistd.h @@ -43,6 +43,7 @@ /* ----------------------------------------- */ extern int PCS_close(int fd); +extern int PCS_ftruncate(int fd, PCS_off_t len); extern PCS_gid_t PCS_getegid(void); extern PCS_uid_t PCS_geteuid(void); extern long int PCS_gethostid(void); diff --git a/unit-test-coverage/ut-stubs/override_inc/unistd.h b/unit-test-coverage/ut-stubs/override_inc/unistd.h index 163deb61..bc9b1ff9 100644 --- a/unit-test-coverage/ut-stubs/override_inc/unistd.h +++ b/unit-test-coverage/ut-stubs/override_inc/unistd.h @@ -34,6 +34,7 @@ #define STDERR_FILENO PCS_STDERR_FILENO #define close PCS_close +#define ftruncate PCS_ftruncate #define getegid PCS_getegid #define geteuid PCS_geteuid #define gethostid PCS_gethostid diff --git a/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c b/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c index 09464655..34a9dfb9 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c +++ b/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c @@ -165,17 +165,17 @@ void UT_DefaultHandler_PCS_strcat(void *UserObj, UT_EntryKey_t FuncKey, const UT void UT_DefaultHandler_PCS_strncat(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - /* char *PCS_strncat(char *dest, const char *src, size_t size) */ + /* char *PCS_strncat(char *dest, const char *src, size_t n) */ void * dest = UT_Hook_GetArgValueByName(Context, "dest", void *); const void *src = UT_Hook_GetArgValueByName(Context, "src", const void *); - size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t); + size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t); char *Result; if (!UT_Stub_GetInt32StatusCode(Context, NULL)) { /* Perform the real operation */ - Result = strncat(dest, src, size); + Result = strncat(dest, src, n); UT_Stub_SetReturnValue(FuncKey, Result); } } @@ -215,8 +215,8 @@ void UT_DefaultHandler_PCS_strcmp(void *UserObj, UT_EntryKey_t FuncKey, const UT void UT_DefaultHandler_PCS_strcpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - /* char *PCS_strcpy(char *dst, const char *src) */ - char * dst = UT_Hook_GetArgValueByName(Context, "dst", char *); + /* char *PCS_strcpy(char *dest, const char *src) */ + char * dest = UT_Hook_GetArgValueByName(Context, "dest", char *); const char *src = UT_Hook_GetArgValueByName(Context, "src", const char *); char *Result; @@ -224,24 +224,24 @@ void UT_DefaultHandler_PCS_strcpy(void *UserObj, UT_EntryKey_t FuncKey, const UT if (!UT_Stub_GetInt32StatusCode(Context, NULL)) { /* Perform the real operation */ - Result = strcpy(dst, src); + Result = strcpy(dest, src); UT_Stub_SetReturnValue(FuncKey, Result); } } void UT_DefaultHandler_PCS_strncpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - /* char *PCS_strncpy(char *dst, const char *src, size_t size) */ - char * dst = UT_Hook_GetArgValueByName(Context, "dst", char *); + /* char *PCS_strncpy(char *dest, const char *src, size_t n) */ + char * dest = UT_Hook_GetArgValueByName(Context, "dest", char *); const char *src = UT_Hook_GetArgValueByName(Context, "src", const char *); - size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t); + size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t); char *Result; if (!UT_Stub_GetInt32StatusCode(Context, NULL)) { /* Perform the real operation */ - Result = strncpy(dst, src, size); + Result = strncpy(dest, src, n); UT_Stub_SetReturnValue(FuncKey, Result); } } diff --git a/unit-test-coverage/ut-stubs/src/PCS_unistd_handlers.c b/unit-test-coverage/ut-stubs/src/PCS_unistd_handlers.c index adcbaf81..a0871aac 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_unistd_handlers.c +++ b/unit-test-coverage/ut-stubs/src/PCS_unistd_handlers.c @@ -99,7 +99,7 @@ void UT_DefaultHandler_PCS_read(void *UserObj, UT_EntryKey_t FuncKey, const UT_S memset(buf, 'r', Status); retval = Status; } - else if (UT_GetStubCount(FuncKey < 4)) + else if (UT_GetStubCount(FuncKey) < 4) { memset(buf, 'r', nbytes); retval = nbytes; diff --git a/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c index 5b046f90..a53dfa32 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c @@ -45,6 +45,23 @@ int PCS_close(int fd) return UT_GenStub_GetReturnValue(PCS_close, int); } +/* + * ---------------------------------------------------- + * Generated stub function for PCS_ftruncate() + * ---------------------------------------------------- + */ +int PCS_ftruncate(int fd, PCS_off_t len) +{ + UT_GenStub_SetupReturnBuffer(PCS_ftruncate, int); + + UT_GenStub_AddParam(PCS_ftruncate, int, fd); + UT_GenStub_AddParam(PCS_ftruncate, PCS_off_t, len); + + UT_GenStub_Execute(PCS_ftruncate, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_ftruncate, int); +} + /* * ---------------------------------------------------- * Generated stub function for PCS_getegid() diff --git a/ut-stubs/src/cfe_psp_cds_api_handlers.c b/ut-stubs/src/cfe_psp_cds_api_handlers.c index 696723c3..eaf66b0f 100644 --- a/ut-stubs/src/cfe_psp_cds_api_handlers.c +++ b/ut-stubs/src/cfe_psp_cds_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_cds_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines diff --git a/ut-stubs/src/cfe_psp_exception_api_handlers.c b/ut-stubs/src/cfe_psp_exception_api_handlers.c index e7e10ba1..8b87de2f 100644 --- a/ut-stubs/src/cfe_psp_exception_api_handlers.c +++ b/ut-stubs/src/cfe_psp_exception_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_exception_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines diff --git a/ut-stubs/src/cfe_psp_id_api_handlers.c b/ut-stubs/src/cfe_psp_id_api_handlers.c index d57f1be1..441bfc72 100644 --- a/ut-stubs/src/cfe_psp_id_api_handlers.c +++ b/ut-stubs/src/cfe_psp_id_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_id_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines diff --git a/ut-stubs/src/cfe_psp_memrange_api_handlers.c b/ut-stubs/src/cfe_psp_memrange_api_handlers.c index 0c679db3..93feae7b 100644 --- a/ut-stubs/src/cfe_psp_memrange_api_handlers.c +++ b/ut-stubs/src/cfe_psp_memrange_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_memrange_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines diff --git a/ut-stubs/src/cfe_psp_timertick_api_handlers.c b/ut-stubs/src/cfe_psp_timertick_api_handlers.c index c52bd5f4..06d84a2c 100644 --- a/ut-stubs/src/cfe_psp_timertick_api_handlers.c +++ b/ut-stubs/src/cfe_psp_timertick_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_timertick_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines diff --git a/ut-stubs/src/cfe_psp_version_api_handlers.c b/ut-stubs/src/cfe_psp_version_api_handlers.c index 07700ce0..4685457d 100644 --- a/ut-stubs/src/cfe_psp_version_api_handlers.c +++ b/ut-stubs/src/cfe_psp_version_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_version_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines diff --git a/ut-stubs/src/cfe_psp_watchdog_api_handlers.c b/ut-stubs/src/cfe_psp_watchdog_api_handlers.c index 501e1e23..65cdf2b9 100644 --- a/ut-stubs/src/cfe_psp_watchdog_api_handlers.c +++ b/ut-stubs/src/cfe_psp_watchdog_api_handlers.c @@ -17,7 +17,7 @@ ************************************************************************/ /* -** File: ut_bsp_stubs.c +** File: cfe_psp_watchdog_api_handlers.c ** ** Purpose: ** Unit test stubs for BSP routines