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 #345, Add CFE_PSP_StatusToString and CFE_PSP_STATUS_C #347

Merged
merged 1 commit into from
Jun 22, 2022
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
22 changes: 2 additions & 20 deletions fsw/inc/cfe_psp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,12 @@
#include "common_types.h"
#include "osapi.h"

#include "cfe_psp_error.h"

/*
** Macro Definitions
*/

/*
** Error and return codes
*/
#define CFE_PSP_SUCCESS (0)
#define CFE_PSP_ERROR (-1)
#define CFE_PSP_INVALID_POINTER (-2)
#define CFE_PSP_ERROR_ADDRESS_MISALIGNED (-3)
#define CFE_PSP_ERROR_TIMEOUT (-4)
#define CFE_PSP_INVALID_INT_NUM (-5)
#define CFE_PSP_INVALID_MEM_ADDR (-21)
#define CFE_PSP_INVALID_MEM_TYPE (-22)
#define CFE_PSP_INVALID_MEM_RANGE (-23)
#define CFE_PSP_INVALID_MEM_WORDSIZE (-24)
#define CFE_PSP_INVALID_MEM_SIZE (-25)
#define CFE_PSP_INVALID_MEM_ATTR (-26)
#define CFE_PSP_ERROR_NOT_IMPLEMENTED (-27)
#define CFE_PSP_INVALID_MODULE_NAME (-28)
#define CFE_PSP_INVALID_MODULE_ID (-29)
#define CFE_PSP_NO_EXCEPTION_DATA (-30)

/*
** Definitions for PSP PANIC types
*/
Expand Down
82 changes: 82 additions & 0 deletions fsw/inc/cfe_psp_error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/
#ifndef CFE_PSP_ERROR_H
#define CFE_PSP_ERROR_H

/**
* \file
* \brief cFE PSP Error header
*/

#include "common_types.h"

/**
* \brief PSP Status type for readability and potentially type safety
*/
typedef int32 CFE_PSP_Status_t;

/**
* \brief PSP Status macro for literal
*/
#define CFE_PSP_STATUS_C(X) ((CFE_PSP_Status_t)(X))

/**
* \brief PSP Status converted to string length limit
*
* Used for sizing CFE_PSP_StatusString_t intended for use in printing CFE_PSP_Status_t values
* Sized for %ld (LONG_MIN) including NULL
*/
#define CFE_PSP_STATUS_STRING_LENGTH 12

/**
* @brief For the @ref CFE_PSP_StatusToString() function, to ensure
* everyone is making an array of the same length.
*/
typedef char CFE_PSP_StatusString_t[CFE_PSP_STATUS_STRING_LENGTH];

/**
* @brief Convert status to a string
*
* @param[in] status Status value to convert
* @param[out] status_string Buffer to store status converted to string
*
* @return Passed in string pointer
*/
char *CFE_PSP_StatusToString(CFE_PSP_Status_t status, CFE_PSP_StatusString_t *status_string);

/*
* Error and return codes
*/
#define CFE_PSP_SUCCESS (CFE_PSP_STATUS_C(0))
#define CFE_PSP_ERROR (CFE_PSP_STATUS_C(-1))
#define CFE_PSP_INVALID_POINTER (CFE_PSP_STATUS_C(-2))
#define CFE_PSP_ERROR_ADDRESS_MISALIGNED (CFE_PSP_STATUS_C(-3))
#define CFE_PSP_ERROR_TIMEOUT (CFE_PSP_STATUS_C(-4))
#define CFE_PSP_INVALID_INT_NUM (CFE_PSP_STATUS_C(-5))
#define CFE_PSP_INVALID_MEM_ADDR (CFE_PSP_STATUS_C(-21))
#define CFE_PSP_INVALID_MEM_TYPE (CFE_PSP_STATUS_C(-22))
#define CFE_PSP_INVALID_MEM_RANGE (CFE_PSP_STATUS_C(-23))
#define CFE_PSP_INVALID_MEM_WORDSIZE (CFE_PSP_STATUS_C(-24))
#define CFE_PSP_INVALID_MEM_SIZE (CFE_PSP_STATUS_C(-25))
#define CFE_PSP_INVALID_MEM_ATTR (CFE_PSP_STATUS_C(-26))
#define CFE_PSP_ERROR_NOT_IMPLEMENTED (CFE_PSP_STATUS_C(-27))
#define CFE_PSP_INVALID_MODULE_NAME (CFE_PSP_STATUS_C(-28))
#define CFE_PSP_INVALID_MODULE_ID (CFE_PSP_STATUS_C(-29))
#define CFE_PSP_NO_EXCEPTION_DATA (CFE_PSP_STATUS_C(-30))

#endif /* CFE_PSP_ERROR_H */
1 change: 1 addition & 0 deletions fsw/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Build the shared implementation as a library
add_library(psp-${CFE_PSP_TARGETNAME}-shared OBJECT
src/cfe_psp_error.c
src/cfe_psp_exceptionstorage.c
src/cfe_psp_memrange.c
src/cfe_psp_memutils.c
Expand Down
46 changes: 46 additions & 0 deletions fsw/shared/src/cfe_psp_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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
*
* Implements error APIs
*/
#include <stdio.h>

#include "cfe_psp_error.h"

/*----------------------------------------------------------------
*
* Function: CFE_PSP_StatusToString
*
* Purpose: Implemented per public PSP API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
char *CFE_PSP_StatusToString(CFE_PSP_Status_t status, CFE_PSP_StatusString_t *status_string)

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

CFE_PSP_StatusToString uses the basic integral type char rather than a typedef with size and signedness.

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

status uses the basic integral type signed int rather than a typedef with size and signedness.

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

status_string uses the basic integral type char rather than a typedef with size and signedness.
{
char *string = NULL;

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

string uses the basic integral type char rather than a typedef with size and signedness.

if (status_string != NULL)
{
snprintf(*status_string, sizeof(*status_string), "%ld", (long)status);
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [snprintf](1) is not checked.

Check warning

Code scanning / CodeQL-coding-standard

Unchecked function argument

This use of parameter status has not been checked.
string = *status_string;
}
return string;
}
44 changes: 44 additions & 0 deletions ut-stubs/cfe_psp_error_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/
#define CFE_PSP_ERROR_H

/**
* @file
*
* Auto-Generated stub implementations for functions defined in cfe_psp_error header
*/

#include "cfe_psp_error.h"
#include "utgenstub.h"

/*
* ----------------------------------------------------
* Generated stub function for CFE_PSP_StatusToString()
* ----------------------------------------------------
*/
char *CFE_PSP_StatusToString(CFE_PSP_Status_t status, CFE_PSP_StatusString_t *status_string)
{
UT_GenStub_SetupReturnBuffer(CFE_PSP_StatusToString, char *);

UT_GenStub_AddParam(CFE_PSP_StatusToString, CFE_PSP_Status_t, status);
UT_GenStub_AddParam(CFE_PSP_StatusToString, CFE_PSP_StatusString_t *, status_string);

UT_GenStub_Execute(CFE_PSP_StatusToString, Basic, NULL);

return UT_GenStub_GetReturnValue(CFE_PSP_StatusToString, char *);
}