Skip to content

Commit

Permalink
Add bounds check API to generic_check library
Browse files Browse the repository at this point in the history
Continuation of reducing macro expansion duplication
across template functions.  Expanded unit tests
to include missing integrity checks for mss_field_t API.

Change-Id: Ic733caf6f57897f8298c99bcc253bba736602d78
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/92974
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Louis Stermole <stermole@us.ibm.com>
Tested-by: PPE CI <ppe-ci+hostboot@us.ibm.com>
Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com>
Reviewed-by: Mark Pizzutillo <mark.pizzutillo@ibm.com>
Reviewed-by: Jennifer A Stofer <stofer@us.ibm.com>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/93000
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Reviewed-by: Christian R Geddes <crgeddes@us.ibm.com>
  • Loading branch information
aamarin authored and crgeddes committed Mar 25, 2020
1 parent bc4196f commit 0d474d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
29 changes: 3 additions & 26 deletions src/import/generic/memory/lib/utils/mss_field.H
Expand Up @@ -184,23 +184,14 @@ inline fapi2::ReturnCode get_field(const fapi2::Target<T>& i_target,
OT& o_value)
{
const size_t BYTE = F.get_byte(i_data);

FAPI_ASSERT( BYTE < i_data.size(),
fapi2::MSS_OUT_OF_BOUNDS_INDEXING()
.set_INDEX(BYTE)
.set_LIST_SIZE(i_data.size())
.set_FUNCTION(i_ffdc_codes)
.set_TARGET(i_target),
"Out of bounds indexing (with %d) on a list of size %d for " TARGTIDFORMAT,
BYTE,
i_data.size(),
TARGTID);
FAPI_TRY(check::index_within_bounds(i_target, BYTE, i_data, i_ffdc_codes));

{
// clear out stale state
o_value = 0;

// Extracting desired bits
// API enforces uint8_t vector data, so no conversion check needed to uint8_t buffer
fapi2::buffer<uint8_t>(i_data[BYTE]).extractToRight<F.get_start(), F.get_length()>(o_value);

FAPI_DBG(TARGTIDFORMAT " data[%d] = 0x%02x. Field with start bit %d, bit len %d, has data 0x%02x.",
Expand All @@ -212,8 +203,6 @@ inline fapi2::ReturnCode get_field(const fapi2::Target<T>& i_target,
o_value);
}

return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
return fapi2::current_err;
}
Expand Down Expand Up @@ -244,17 +233,7 @@ inline fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target,
{
const size_t BYTE = F.get_byte(io_data);

FAPI_ASSERT( BYTE < io_data.size(),
fapi2::MSS_OUT_OF_BOUNDS_INDEXING()
.set_INDEX(BYTE)
.set_LIST_SIZE(io_data.size())
.set_FUNCTION(i_ffdc_codes)
.set_TARGET(i_target),
"Out of bounds indexing (with %d) on a list of size %d for %s",
BYTE,
io_data.size(),
spd::c_str(i_target));

FAPI_TRY(check::index_within_bounds(i_target, BYTE, io_data, i_ffdc_codes));
FAPI_TRY(check::invalid_type_conversion<uint8_t>(i_target, i_setting, i_ffdc_codes));

{
Expand All @@ -274,8 +253,6 @@ inline fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target,
F.get_length(),
i_setting);

return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
return fapi2::current_err;
}
Expand Down
52 changes: 45 additions & 7 deletions src/import/generic/memory/lib/utils/mss_generic_check.H
Expand Up @@ -209,6 +209,7 @@ fapi2::ReturnCode fir_or_pll_fail( const fapi2::Target<T>& i_target,
}

#endif

///
/// @brief Checks conditional passes and implements traces & exits if it fails
/// @tparam T fapi2 target type
Expand Down Expand Up @@ -236,11 +237,8 @@ inline fapi2::ReturnCode invalid_value(const fapi2::Target<T>& i_target,
set_BYTE(i_byte_index).
set_TARGET(i_target).
set_FFDC_CODE(i_ffdc_codes),
"%s Byte %d, Data returned: %d for " TARGTIDFORMAT,
i_err_str,
i_byte_index,
i_data,
TARGTID);
"%s. Byte %d, Data returned: %d for " TARGTIDFORMAT,
i_err_str, i_byte_index, i_data, TARGTID );

return fapi2::FAPI2_RC_SUCCESS;

Expand All @@ -251,6 +249,7 @@ fapi_try_exit:

///
/// @brief Checks conditional passes and implements traces & exits if it fails
/// @tparam OT data type we want to check safe conversion against (explicit)
/// @tparam T fapi2 target type
/// @tparam IT input data type
/// @tparam FFDC error callout code type
Expand All @@ -276,15 +275,54 @@ inline fapi2::ReturnCode invalid_type_conversion(const fapi2::Target<T>& i_targe
.set_CONVERTED_VAL(l_temp)
.set_TARGET(i_target)
.set_FUNCTION(i_ffdc_codes),
"Conversion error between original %d to converted %d value for " TARGTIDFORMAT,
i_data, l_temp, TARGTID);
"%s. Conversion error between original %d to converted %d value for " TARGTIDFORMAT,
i_err_str, i_data, l_temp, TARGTID );

return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
return fapi2::current_err;

} // invalid_type_conversion

///
/// @brief Checks conditional passes and implements traces & exits if it fails
/// @tparam T fapi2 target type
/// @tparam IT index type
/// @tparam VT vector data type
/// @tparam FFDC error callout code type
/// @param[in] i_target fapi2 target
/// @param[in] i_index desired vector index
/// @param[in] i_data vector data
/// @param[in] i_ffdc_codes FFDC code
/// @param[in] i_err_str error string - defaulted to ""
/// @return FAPI2_RC_SUCCESS iff okay
///
template< fapi2::TargetType T, typename IT, typename VT, typename FFDC >
fapi2::ReturnCode index_within_bounds(const fapi2::Target<T>& i_target,
const IT i_index,
const std::vector<VT>& i_data,
const FFDC i_ffdc_codes,
const char* i_err_str = "")
{
const auto l_size = i_data.size();

FAPI_ASSERT( i_index < l_size,
fapi2::MSS_OUT_OF_BOUNDS_INDEXING()
.set_INDEX(i_index)
.set_LIST_SIZE(l_size)
.set_FUNCTION(i_ffdc_codes)
.set_TARGET(i_target),
"%s. Out of bounds indexing (with %d) on a list of size %d for " TARGTIDFORMAT,
i_err_str, i_index, l_size, TARGTID );

return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
return fapi2::current_err;

} // invalid_type_conversion

} // check
}// mss

Expand Down

0 comments on commit 0d474d6

Please sign in to comment.