Skip to content

Commit

Permalink
Add unit tests for mss field_t and macro def
Browse files Browse the repository at this point in the history
mss::field get and set field API was missing
explicit unit tests. Added new mss macro
definitions for testing the most common
assertions that are counter intuitive to
the default provided from Catch.hpp when
testing ReturnCode information.

Change-Id: Ia340f901da293213257401c3e916b8dcdbef27aa
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/92715
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Louis Stermole <stermole@us.ibm.com>
Reviewed-by: Mark Pizzutillo <mark.pizzutillo@ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: PPE CI <ppe-ci+hostboot@us.ibm.com>
Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com>
Dev-Ready: ANDRE A MARIN <aamarin@us.ibm.com>
Reviewed-by: Jennifer A Stofer <stofer@us.ibm.com>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/92726
Reviewed-by: RAJA DAS <rajadas2@in.ibm.com>
  • Loading branch information
aamarin authored and RAJA DAS committed Mar 16, 2020
1 parent 2d51dbb commit 0a77603
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 48 deletions.
Expand Up @@ -40,7 +40,6 @@
#include <i2c_access.H>
#include <vector>

// reused TARGTIDFORMAT defined in generic/memory/lib/utils/mss_generic_check.H
#ifdef __PPE__
#include <exp_i2c_fields.H>
#include <endian_utils.H>
Expand All @@ -55,6 +54,8 @@
#define MSSTARGID mss::c_str(i_target)
#endif

// reused TARGTIDFORMAT defined in generic/memory/lib/utils/mss_generic_check.H

namespace mss
{
namespace exp
Expand Down
76 changes: 30 additions & 46 deletions src/import/generic/memory/lib/utils/mss_field.H
Expand Up @@ -165,8 +165,7 @@ inline bool conditional(const T i_field,
/// @tparam E endian type
/// @tparam F the field to extract
/// @tparam T the fapi2 target type
/// @tparam IT data input type
/// @tparam OT data output type
/// @tparam OT output type
/// @tparam FFDC ffdc code type
/// @param[in] i_target the fapi2 target
/// @param[in] i_data the data
Expand All @@ -177,17 +176,13 @@ inline bool conditional(const T i_field,
template< mss::endian E,
const mss::field_t<E>& F,
fapi2::TargetType T,
typename IT,
typename OT,
typename FFDC >
inline fapi2::ReturnCode get_field(const fapi2::Target<T>& i_target,
const std::vector<IT>& i_data,
const std::vector<uint8_t>& i_data,
const FFDC i_ffdc_codes,
OT& o_value)
{
// Initializes the output value to 0, that way, we won't have any stale data in o_value
o_value = 0;

const size_t BYTE = F.get_byte(i_data);

FAPI_ASSERT( BYTE < i_data.size(),
Expand All @@ -202,9 +197,11 @@ inline fapi2::ReturnCode get_field(const fapi2::Target<T>& i_target,
TARGTID);

{
// clear out stale state
o_value = 0;

// Extracting desired bits
const fapi2::buffer<OT> l_buffer(i_data[BYTE]);
l_buffer.template extractToRight<F.get_start(), F.get_length()>(o_value);
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.",
TARGTID,
Expand All @@ -227,8 +224,7 @@ fapi_try_exit:
/// @tparam E endian type
/// @tparam F the field to extract
/// @tparam T the fapi2 target type
/// @tparam IT data input type
/// @tparam OT data output type
/// @tparam IT input type
/// @tparam FFDC ffdc code type
/// @param[in] i_target the fapi2 target
/// @param[in] i_setting the setting to set
Expand All @@ -240,12 +236,11 @@ template< mss::endian E,
const mss::field_t<E>& F,
fapi2::TargetType T,
typename IT,
typename OT,
typename FFDC >
inline fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target,
const IT i_setting,
const FFDC i_ffdc_codes,
std::vector<OT>& io_data)
std::vector<uint8_t>& io_data)
{
const size_t BYTE = F.get_byte(io_data);

Expand All @@ -260,37 +255,37 @@ inline fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target,
io_data.size(),
spd::c_str(i_target));

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

{
// Insert desired setting
fapi2::buffer<OT> l_buffer(io_data[BYTE]);
fapi2::buffer<uint8_t> l_buffer(io_data[BYTE]);
l_buffer.template insertFromRight<F.get_start(), F.get_length()>(i_setting);

io_data[BYTE] = static_cast<OT>(l_buffer);

FAPI_DBG("%s data[%d] = 0x%02x. Field with start bit %d, bit len %d, has data 0x%02x.",
spd::c_str(i_target),
BYTE,
io_data[BYTE],
F.get_start(),
F.get_length(),
i_setting);
// Safe to set since no implicit conversion errors will occur here
io_data[BYTE] = l_buffer;
}

FAPI_DBG("%s data[%d] = 0x%02x. Field with start bit %d, bit len %d, has data 0x%02x.",
spd::c_str(i_target),
BYTE,
io_data[BYTE],
F.get_start(),
F.get_length(),
i_setting);

return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
return fapi2::current_err;
}
#endif

///
/// @brief byte field reader
/// @tparam E endian type
/// @tparam F the byte field to read
/// @tparam TT traits associated with F - required
/// @tparam T the fapi2 target type
/// @tparam IT data input type
/// @tparam OT data output type
/// @param[in] i_target the dimm target
/// @param[in] i_data the data
/// @param[in] i_ffdc_codes FFDC code
Expand All @@ -301,40 +296,31 @@ template< mss::endian E,
const mss::field_t<E>& F,
typename TT,
fapi2::TargetType T,
typename IT,
typename OT,
typename FFDC >
inline fapi2::ReturnCode get_field( const fapi2::Target<T>& i_target,
const std::vector<IT>& i_data,
const std::vector<uint8_t>& i_data,
const FFDC i_ffdc_codes,
OT& o_value )
{
IT l_temp = 0;
uint8_t l_temp = 0;
FAPI_TRY( (get_field<E, F>(i_target, i_data, i_ffdc_codes, l_temp)),
"Failed get_field() for " TARGTIDFORMAT, TARGTID );

// Test if retrieved data seems valid
FAPI_TRY( check::invalid_value(i_target,
conditional( l_temp,
TT::COMPARISON_VAL,
typename TT::template COMPARISON_OP<IT>() ),
typename TT::template COMPARISON_OP<uint8_t>() ),
F.get_byte(i_data),
l_temp,
i_ffdc_codes,
TT::FIELD_STR),
"%s failed check::invalid_value() for %s",
TT::FIELD_STR, spd::c_str(i_target) );

// Output should only change if data check passes
// Implicit (possible) promotion during conversion is safe
o_value = static_cast<OT>(l_temp);
FAPI_ASSERT( o_value == l_temp,
fapi2::MSS_CONVERSION_ERROR()
.set_ORIGINAL_VAL(l_temp)
.set_CONVERTED_VAL(o_value)
.set_TARGET(i_target)
.set_FUNCTION(i_ffdc_codes),
"Conversion error between original %d to converted %d value for " TARGTIDFORMAT,
l_temp, o_value, TARGTID);

FAPI_DBG("%s: 0x%02x for %s",
TT::FIELD_STR,
Expand All @@ -346,15 +332,13 @@ fapi_try_exit:
return fapi2::current_err;
}

#ifndef __PPE__
///
/// @brief byte field writer
/// @tparam E endian type
/// @tparam F the byte field to read
/// @tparam TT traits associated with writer
/// @tparam T the fapi2 target type
/// @tparam IT data input type
/// @tparam OT data output type
/// @tparam IT input type
/// @tparam FFDC ffdc code type
/// @param[in] i_target the dimm target
/// @param[in] i_setting value to set for field
Expand All @@ -367,12 +351,11 @@ template< mss::endian E,
typename TT,
fapi2::TargetType T,
typename IT,
typename OT,
typename FFDC >
inline fapi2::ReturnCode set_field( const fapi2::Target<T>& i_target,
const IT i_setting,
const FFDC i_ffdc_codes,
std::vector<OT>& io_data )
std::vector<uint8_t>& io_data )
{
const size_t BYTE = F.get_byte(io_data);

Expand All @@ -399,8 +382,9 @@ inline fapi2::ReturnCode set_field( const fapi2::Target<T>& i_target,
fapi_try_exit:
return fapi2::current_err;
}
#endif

#endif // PPE

}// mss

#endif
#endif // include guard
38 changes: 37 additions & 1 deletion src/import/generic/memory/lib/utils/mss_generic_check.H
Expand Up @@ -247,8 +247,44 @@ inline fapi2::ReturnCode invalid_value(const fapi2::Target<T>& i_target,
fapi_try_exit:
return fapi2::current_err;

} // fail_for_invalid_value
} // invalid_value

///
/// @brief Checks conditional passes and implements traces & exits if it fails
/// @tparam T fapi2 target type
/// @tparam IT input data type
/// @tparam FFDC error callout code type
/// @param[in] i_target fapi2 target
/// @param[in] i_conditional conditional that we are testing against
/// @param[in] i_byte_index byte index
/// @param[in] i_data debug data
/// @param[in] i_ffdc_codes FFDC code
/// @param[in] i_err_str error string - defaulted to ""
/// @return FAPI2_RC_SUCCESS iff okay
///
template< typename OT, fapi2::TargetType T, typename IT, typename FFDC >
inline fapi2::ReturnCode invalid_type_conversion(const fapi2::Target<T>& i_target,
const IT& i_data,
const FFDC i_ffdc_codes,
const char* i_err_str = "")
{
OT l_temp = static_cast<OT>(i_data);

FAPI_ASSERT( i_data == l_temp,
fapi2::MSS_CONVERSION_ERROR()
.set_ORIGINAL_VAL(i_data)
.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);

return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
return fapi2::current_err;

} // invalid_type_conversion
} // check
}// mss

Expand Down

0 comments on commit 0a77603

Please sign in to comment.