diff options
author | Brian Stegmiller <bjs@us.ibm.com> | 2016-01-21 09:44:19 -0600 |
---|---|---|
committer | Stephen Cprek <smcprek@us.ibm.com> | 2016-04-21 13:51:28 -0500 |
commit | a993a6782df71f0bab8726d85cf9c3af99a9da92 (patch) | |
tree | 57dc3ac28c2a2469e08b4ac2d1b8e40741afe8d4 /src/usr/fapi2 | |
parent | ba9a5a32868b6785db0ecef0becdd6ae84dcebbd (diff) | |
download | talos-hostboot-a993a6782df71f0bab8726d85cf9c3af99a9da92.tar.gz talos-hostboot-a993a6782df71f0bab8726d85cf9c3af99a9da92.zip |
Test basic FAPI TRY and ASSERT
Change-Id: Ie84e10b61d6575adc341cc33c15c9ea608587211
RTC: 143123
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/756
Tested-by: Jenkins Server
Tested-by: FSP CI Jenkins
Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Reviewed-by: William G. Hoffa <wghoffa@us.ibm.com>
Diffstat (limited to 'src/usr/fapi2')
-rw-r--r-- | src/usr/fapi2/test/fapi2Test.H | 9 | ||||
-rw-r--r-- | src/usr/fapi2/test/p9_basicTry.C | 185 |
2 files changed, 194 insertions, 0 deletions
diff --git a/src/usr/fapi2/test/fapi2Test.H b/src/usr/fapi2/test/fapi2Test.H index 1b7b142ec..1d2897bc9 100644 --- a/src/usr/fapi2/test/fapi2Test.H +++ b/src/usr/fapi2/test/fapi2Test.H @@ -48,6 +48,7 @@ #include "fapi2HwpTest.C" #include "fapi2GetChildrenTest.C" #include "fapi2GetOtherEnd.C" +#include "p9_basicTry.C" using namespace fapi2; @@ -81,7 +82,15 @@ void test_fapi2Test(void) //FAPI_INF(">>fapi2GetOtherEnd starting..."); //fapi2GetOtherEnd(); //FAPI_INF(">>fapi2GetOtherEnd exiting..."); + + FAPI_INF(">>test fapi2basicTry starting..."); + fapi2basicTry(); + FAPI_INF(">>test fapi2basicTry exiting..."); + + FAPI_INF("<<<<<<test_fapi2Test exiting..."); } + + }; #endif diff --git a/src/usr/fapi2/test/p9_basicTry.C b/src/usr/fapi2/test/p9_basicTry.C new file mode 100644 index 000000000..f95fe4a59 --- /dev/null +++ b/src/usr/fapi2/test/p9_basicTry.C @@ -0,0 +1,185 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/fapi2/test/p9_basicTry.C $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2016 */ +/* [+] International Business Machines Corp. */ +/* */ +/* */ +/* 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. */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include <fapi2.H> +// #include <plat_attribute_service.H> + +//-------------------------------------------------------------------------- +/// @file p9_basicTry.C +/// +/// @brief This does tests of the FAPI try and FAPI assert MACROs without +/// needing full ReturnCode support. +//-------------------------------------------------------------------------- + +namespace fapi2 +{ + +// This is the basic function that allows us to set a return code +// that we can use for FAPI_TRY macro testing. +uint32_t p9_forceTestUsingRc( uint32_t i_rc ) +{ + FAPI_INF("p9_forceTestUsingRc with RC = %d", i_rc ); + + return(i_rc); +} + + +// Force a bad RC and see if FAPI_TRY will do the goto exit +fapi2::ReturnCode p9_fapi_tryFailure( ) +{ + + FAPI_INF("Go for BAD TEST "); + FAPI_TRY( p9_forceTestUsingRc(0xFF) ); + + // Should never get here since we failed routine above + // Hence, I want to fail testcase if we do + FAPI_ERR("Completed BAD TEST --Should never get here"); + fapi2::current_err = 0xDEAD; + return fapi2::current_err; + +fapi_try_exit: + // We failed as expected + FAPI_INF( "Had RC %d but will exit cleanly", + (uint64_t)(fapi2::current_err) ); + fapi2::current_err = 0; + + return fapi2::current_err; +} + + +// Force the FAPI_ASSERT to fail and verify it will goto exit +fapi2::ReturnCode p9_fapi_assertFailure( ) +{ + + + uint32_t l_var1 = 5, l_var2 = 25; + FAPI_INF("Running ASSERT test that will fail"); + FAPI_ASSERT( l_var1 == l_var2, + fapi2::FAPI2_SAMPLE(), + "Verify ASSERT that WILL ASSERT" ); + + // Shouldn't get here so fail if we do + FAPI_ERR("Completed BAD TEST with ASSERT -- Should never get here"); + fapi2::current_err = 0xABAD; + return fapi2::current_err; + +fapi_try_exit: + // We detected the fail which is expected + FAPI_INF( "FAILURE as expected though: %d", + (uint64_t)(fapi2::current_err) ); + fapi2::current_err = 0; + + return fapi2::current_err; +} + +// FAPI_TRY with good RC so we should run thru all code. +// If it doesn't work, we should have non-zero RC which +// forces testcase failure. +fapi2::ReturnCode p9_fapi_trySuccess( ) +{ + fapi2::current_err = 0xFFFF; + + FAPI_INF("Go for GOOD TEST "); + FAPI_TRY( p9_forceTestUsingRc(0) ); + FAPI_INF("Completed GOOD TEST with CURRENT_ERROR: %d", + (uint64_t)(fapi2::current_err) ); + fapi2::current_err = 0; + +fapi_try_exit: + FAPI_INF("Exiting with %d", (uint64_t)(fapi2::current_err) ); + + return fapi2::current_err; +} + + +// FAPI_ASSERT should succeed and run thru all code. +// If it doesn't work, we should have non-zero RC which +// forces testcase failure. +fapi2::ReturnCode p9_fapi_assertSuccess( ) +{ + fapi2::current_err = 0xFFFF; + + uint32_t l_var1 = 5, l_var2 = 5; + FAPI_ASSERT( l_var1 == l_var2, + fapi2::FAPI2_SAMPLE(), + "Verify ASSERT that doesn't assert" ); + FAPI_INF("Completed GOOD TEST with ASSERT"); + fapi2::current_err = 0; + + +fapi_try_exit: + FAPI_INF("SUCCESS Exiting with %d", (uint64_t)(fapi2::current_err) ); + + return fapi2::current_err; +} + + + +void fapi2basicTry() +{ + int numTests = 0; + int numFails = 0; + fapi2::ReturnCode l_rc; + + + FAPI_INF("fapi2basicTry starting ... "); + + numTests++; + l_rc = p9_fapi_tryFailure(); + if ( true == (bool)l_rc ) + { + numFails++; + TS_FAIL(" p9_fapi_tryFailure returned error"); + } + + numTests++; + l_rc = p9_fapi_assertFailure(); + if ( true == (bool)l_rc ) + { + numFails++; + TS_FAIL(" p9_fapi_assertFailure returned error"); + } + + numTests++; + l_rc = p9_fapi_trySuccess(); + if ( true == (bool)l_rc ) + { + numFails++; + TS_FAIL(" p9_fapi_trySuccess returned error"); + } + + numTests++; + l_rc = p9_fapi_assertSuccess(); + if ( true == (bool)l_rc ) + { + numFails++; + TS_FAIL(" p9_fapi_assertSuccess returned error"); + } + + FAPI_INF("fapi2basicTry:: Test Complete. %d/%d fails", numFails, numTests); + + return; +} // end main testcase driver + +} // end namespace fapi2 |