diff --git a/ut_assert/inc/utstubs.h b/ut_assert/inc/utstubs.h index ad7601218..6f15cd3e9 100644 --- a/ut_assert/inc/utstubs.h +++ b/ut_assert/inc/utstubs.h @@ -117,6 +117,15 @@ typedef int32 (*UT_VaHookFunc_t)(void *UserObj, int32 StubRetcode, uint32 CallCo */ void UT_ResetState(UT_EntryKey_t FuncKey); +/** + * A value to indicate if the currently running stub's behavior after + * a hook call should be run or not. + * + * \param Retcode The boolean value indicating the override. When 'true' + * indicates remaining stub code should not be run, it is in override. + */ +bool UT_StubIsOveridden(void); + /** * Add a deferred return code entry for the given stub function * @@ -239,6 +248,18 @@ void UT_ClearForceFail(UT_EntryKey_t FuncKey); */ void UT_SetHookFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *UserObj); +/** + * Set a Hook function for a particular call, but override any remaining stub functionality + * + * This triggers a callback to a user-defined function when the stub is invoked. + * Upon return to the original stub the OverrideStub will be true and any remaining + * code lines in stub (that are purposefully bypassed by the stub) will not be executed. + * + * \param FuncKey The stub function to add the hook to. + * \param HookFunc User defined hook function. Set NULL to delete/clear an entry. + * \param UserObj Arbitrary user data object to pass to the hook function + */void UT_SetHookOverrideStubFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *UserObj); + /** * Set a variable-argument Hook function for a particular call * diff --git a/ut_assert/src/utstubs.c b/ut_assert/src/utstubs.c index a4376b444..5c18f8544 100644 --- a/ut_assert/src/utstubs.c +++ b/ut_assert/src/utstubs.c @@ -109,6 +109,7 @@ typedef struct static UT_StubTableEntry_t UT_StubTable[UT_MAX_FUNC_STUBS] = {{0}}; static uint32 UT_MaxStubSearchLen = 0; +static bool StubIsOveridden = false; /** * Helper function to clear an entry in the stub table. @@ -201,6 +202,8 @@ void UT_ResetState(UT_EntryKey_t FuncKey) { UT_MaxStubSearchLen = 0; } + + StubIsOveridden = false; /* Override is ONLY on demand */ } void UT_Stub_CallOnce(void (*Func)(void)) @@ -602,6 +605,12 @@ void UT_SetHookFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *Use UT_DoSetHookFunction(FuncKey, Value, UserObj, false); } +void UT_SetHookOverrideStubFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *UserObj) +{ + StubIsOveridden = true; + UT_SetHookFunction(FuncKey, HookFunc, UserObj); +} + void UT_SetVaHookFunction(UT_EntryKey_t FuncKey, UT_VaHookFunc_t HookFunc, void *UserObj) { UT_HookFuncPtr_t Value; @@ -853,3 +862,8 @@ int32 UT_DefaultStubImpl(const char *FunctionName, UT_EntryKey_t FuncKey, int32 return Retcode; } + +bool UT_StubIsOveridden() +{ + return StubIsOveridden; +}